Popup
Beautiful, modern overlay windows for presenting various types of media
You can include this functionality in your element with the following:
There are two main styles of coding when using Popup. Each of these styles has advantages and disadvantages, and you can combine the two.
Add a data-beae-popup
attribute to any element to enable Popup
If you wish to customize options, simply overwrite default click handler:
You can choose any CSS selector here to attach click handler to the currently selected set of elements as well as all future matching elements.
NOTE
Galleries are created by adding the same attribute
data-beae-popup
value to multiple elements.Use
data-src
orhref
attribute to specify the source of the content.Optionally, add a
data-caption
attribute to show a caption under the content.
Media types
Popup itself only displays HTML content. Additional media type support is provided by plugins that are included by default:
Image for images;
HTML for inline content, iframes, videos (HTML5, Youtube and Vimeo), Google maps, and Ajax.
A frequent question is - "Does it support PDF?". First, you have to understand that PDF is a complex file format. Parsing and rendering PDFs is outside the scope of this project.
However, there are two options:
Simply link to a PDF file (optionally, use
data-type="pdf"
attribute):
Copy
Popup will then create iframe
element and will use file URL as src
attribute. It will work very well on computers with modern browsers.
If you're concerned about users using outdated browsers or using mobile devices, you can use PDF.js. Download and extract files on the root directory of your project. Then create links like this:
API
Initialization
Popup an be launched via standard constructor interface:
It is also possible to launch Popup using static method BeaePopup.show()
:
If you wish to launch Popup when user clicks or taps on HTML elements, add default data-beae-popup
attribute or use API bind()
method to attach click handler to the selected items, as well as all future matching elements. You will then be able to retrieve instance object from any event callback. Example:
Instance methods are available after Popup's initialization.
Instance Methods
close([event: ClickEvent]): void#
Start closing the current instance.
next(): void#
Slide carousel to next page.
prev(): void#
Slide carousel to previous page.
jumpTo([args: any]): void#
Slide carousel to selected page with optional parameters. Examples:
getSlide(): Object|null#
Get the active slide. This will be the first slide from the current page of the main carousel.
focus([event: FocusEvent]): void#
Place focus on the first focusable element inside current slide.
hideScrollbar(): void#
Hide vertical page scrollbar and adjust body
right padding value to prevent content from shifting
(otherwise the body
element may become wider and the content may expand horizontally).
revealScrollbar(): void#
Stop hiding vertical page scrollbar.
clearContent(slide: Object): void#
Remove content for given slide.
setContent(slide: Object, html: HTMLElement|String[, options: Object]): void#
Set new content for given slide.
showLoading(slide: Object): void#
Create loading indicator inside given slide.
hideLoading(slide: Object): void#
Remove loading indicator from given slide.
Static Methods
bind(selector: String[, options: Object]): void#
Attach a click handler function that starts Popup to the selected items, as well as to all future matching elements.
unbind(selector: String): void#
Remove the click handler that was attached with bind()
show(items: Object[, options: Object]): BeaePopup#
Create new BeaePopup instance with provided options.
getInstance([id: String|Numeric]): BeaePopup|null#
Retrieve instance by identifier or the top most instance, if identifier is not provided.
close([all: Boolean]): void#
Close all or topmost currently active instance.
destroy(): void#
Immediately destroy all instances (without closing animation) and clean up all bindings.
Options
The following are the default options set by the core of the BeaePopup component.
startIndex {Number}#
Index of active slide on the start. Default: 0
preload {Number}#
Number of slides to preload before and after active slide. Default: 1
infinite {Boolean}#
Should navigation be infinite. Default: true
showClass {String|false}#
Class name to be applied to the content to reveal it. Default: beae-popup-zoomInUp
Possible values: beae-popup-fadeIn
, beae-beae-popup-zoomInUp
or false
.
hideClass {String|false}#
Class name to be applied to the content to hide it. Default: beae-popup-fadeOut
Possible values: beae-popup-fadeOut
, beae-popup-zoomOutDown
or false
.
animated {Boolean}#
Should backdrop and UI elements fade in/out on start/close. Default: true
hideScrollbar {Boolean}#
If browser scrollbar should be hidden. Default: true
parentEl {HTMLElement|null}#
Element containing main structure. Default: null
Note: If no element is specified, the container will be added to the end of the list of children of document.body
.
mainClass {String|null}#
Custom class name or multiple space-separated class names for the container. Default: null
autoFocus {Boolean}#
Set focus on first focusable element after displaying content. Default: true
trapFocus {Boolean}#
Trap focus inside BeaePopup. Default: true
placeFocusBack {Boolean}#
Set focus back to trigger element after closing BeaePopup. Default: true
click {String|function}#
Action to take when the user clicks on the backdrop. Default: close
Possible values: close
, next
or custom function.
closeButton {String}#
Position of the close button. Default: inside
Possible values: inside
(over the content) or outside
(at top right corner of viewport).
dragToClose {Boolean}#
Allow user to drag content up/down to close instance. Default: true
keyboard {Object|false}#
Enable keyboard navigation. Default:
Note: Use KeyboardEvent.code as object keys and any API instance method as value.
template {Object}#
HTML templates for various elements. Default:
Note: If the template.main
option is not provided, the structure is generated as follows by default:
l10n {Object}#
Localization of strings. Default:
Events
You can listen for events using your BeaePopup instance. You can use the on()
or once()
API methods, it is also possible to use on
or once
options to set event callbacks when initialing BeaePopup.
The first argument received by each callback is a reference to the current BeaePopup instance, except for the wildcard *
event, where the event name is the first.
By default, BeaePopup preloads the next and previous slides, which means that content will be loaded on all these slides, and all lifecycle events will be called for each slide.
#1 Example#
#2 Example#
#3 Example#
Name
Description
init
Initialization has started, plugins have been attached
initLayout
Layout has been initialized
initCarousel
Main carousel has been initialized
ready
Initialization has been completed
load
One of the slides has content loaded, but it's not ready yet
reveal
Content is ready to be revealed on one of the slides
done
Content has been revealed on one of the slides
keydown
A key is pressed
shouldClose
Closing has begun and can be prevented; cancelable
closing
Closing has not been prevented is proceeding
destroy
Closing has completed
Last updated