Popup Widget


Popup Widgetversion added: 1.2

Description: Opens content in a Popup.

QuickNavExamples

To create a popup, add the data-role="popup" attribute to a div with the popup contents. Then create a link with the href set to the id of the popup div, and add the attribute data-rel="popup" to tell the framework to open the popup when the link is tapped. This is a similar markup pattern to the dialog widget. A popup div has to be nested inside the same page as the link.

1
2
3
4
5
<a href="#popupBasic" data-rel="popup">Open Popup</a>
<div data-role="popup" id="popupBasic">
<p>This is a completely basic popup, no options set.</p>
</div>

This will result in the following popup:

The popup consists of two elements: the screen, which is a transparent or translucent element that covers the entire document, and the container, which is the popup itself. If your original element had an id attribute, the screen and the container will each receive an id attribute based on it. The screen's id will be suffixed with "-screen", and the container's id will be suffixed with "-popup" (in the above example, id="popupBasic-screen" and id="popupBasic-popup", respectively).

The framework adds a small amount of margin to text elements, but it's really just a container with rounded corners and a shadow which serves as a blank slate for your designs (even these features can be disabled via options).

This simple styling makes it easy to add in widgets to create a variety of different interactions. Here are a few real-world examples that combine the various settings and styles you can achieve out of the box with popups:

Scaling images: Lightbox examples

The framework CSS contains rules that make images that are immediate children of the popup scale to fit the screen. Because of the absolute positioning of the popup container and screen, the height is not adjusted to screen height on all browsers. You can prevent vertical scrolling with a simple script that sets the max-height of the image.

In the two examples below the divs with data-role="popup" have a class of photopopup.

The handler is bound to the popupbeforeposition event, which ensures the image is not only scaled before it is shown but also when the window is resized (e.g. orientation change). In this code example the height is reduced by 60 to take a top and bottom tolerance of 30 pixels into account.

1
2
3
4
5
6
7
8
$( document ).on( "pageinit", function() {
$( ".photopopup" ).on({
popupbeforeposition: function() {
var maxHeight = $( window ).height() - 60 + "px";
$( ".photopopup img" ).css( "max-height", maxHeight );
}
});
});

Working with iframes in popups

You may need to embed an iframe into a popup to use a 3rd party widget. Here, we'll walk through a few real-world examples of working with iframes: videos and maps.

Video example

Here is an example of a 3rd party video player embedded in a popup:

The markup is an iframe inside a popup container. The popup will have a 15 pixels padding because of class ui-content and a one pixel border because the framework will add class ui-body-d to the popup.

1
2
3
4
5
<div data-role="popup" id="popupVideo" data-overlay-theme="a" data-theme="d" data-tolerance="15,15" class="ui-content">
<iframe src="http://player.vimeo.com/video/41135183" width="497" height="298" seamless></iframe>
</div>

When using an iframe inside a popup it is important to initially set the width and height attributes to 0. This prevents the page to breaking on platforms like Android 2.3. Note that you have to set the attributes, because setting the width and height with CSS is not sufficient. You can leave the actual width and height in the markup for browsers that have JavaScript disabled and use attr() to set the zero values upon the pageinit event.

Next, bind to the popupbeforeposition event to set the desired size of the iframe when the popup is shown or when the window is resized (e.g. orientation change). For the iframe examples on this page a custom function scale() is used to scale down the iframe to fit smaller screens. Expand the section below to view the code of this function.

scale()

The window width and height are decreased by 30 to take the tolerance of 15 pixels at each side into account.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function scale( width, height, padding, border ) {
var scrWidth = $( window ).width() - 30,
scrHeight = $( window ).height() - 30,
ifrPadding = 2 * padding,
ifrBorder = 2 * border,
ifrWidth = width + ifrPadding + ifrBorder,
ifrHeight = height + ifrPadding + ifrBorder,
h, w;
if ( ifrWidth < scrWidth && ifrHeight < scrHeight ) {
w = ifrWidth;
h = ifrHeight;
} else if ( ( ifrWidth / scrWidth ) > ( ifrHeight / scrHeight ) ) {
w = scrWidth;
h = ( scrWidth / ifrWidth ) * ifrHeight;
} else {
h = scrHeight;
w = ( scrHeight / ifrHeight ) * ifrWidth;
}
return {
'width': w - ( ifrPadding + ifrBorder ),
'height': h - ( ifrPadding + ifrBorder )
};
};

Note: This function is not part of the framework. Copy the code into your script to use it.

When the popup is closed the width and height should be set back to 0. You can do this by binding to the popupafterclose event.

This is the complete script and the link to open the video popup:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$( document ).on( "pageinit", function() {
$( "#popupVideo iframe" )
.attr( "width", 0 )
.attr( "height", 0 );
$( "#popupVideo" ).on({
popupbeforeposition: function() {
var size = scale( 497, 298, 15, 1 ),
w = size.width,
h = size.height;
$( "#popupVideo iframe" )
.attr( "width", w )
.attr( "height", h );
},
popupafterclose: function() {
$( "#popupVideo iframe" )
.attr( "width", 0 )
.attr( "height", 0 );
}
});
});

Note that the video will still be playing in the iframe when the popup is closed. If available you can use the 3rd party API to stop the video on the popupafterclose event. Another way is to create the iframe when the popup is opened and destroy it when the popup is closed, but this would drop support for browsers that have JavaScript disabled.

Map example

In the second example, an iframe is used to display Google Maps API. Using an iframe prevents issues with the controls of the map.

This is the markup of the popup including a right close button:

1
2
3
4
5
6
7
<div data-role="popup" id="popupMap" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<iframe src="map.html" width="480" height="320" seamless></iframe>
</div>

Expand the section below to view the source of the iframe.

map.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Map</title>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng( 51.520838, -0.140261 );
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map( document.getElementById( "map_canvas" ), myOptions );
}
</script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<style>
html {
height: 100%;
overflow: hidden;
}
body {
margin: 0;
padding: 0;
height: 100%;
}
#map_canvas {
height: 100%;
}
</style>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>

Setting the size of the iframe is done exactly the same as for the video example, with one exception. You should also set the width and height of the div that contains the map to prevent the page to break on platforms like Android 2.3. In this example the ID of this div is #map_canvas.

This is the complete script and the link to open the map popup:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$( document ).on( "pageinit", function() {
$( "#popupMap iframe" )
.attr( "width", 0 )
.attr( "height", 0 );
$( "#popupMap iframe" ).contents().find( "#map_canvas" )
.css( { "width" : 0, "height" : 0 } );
$( "#popupMap" ).on({
popupbeforeposition: function() {
var size = scale( 480, 320, 0, 1 ),
w = size.width,
h = size.height;
$( "#popupMap iframe" )
.attr( "width", w )
.attr( "height", h );
$( "#popupMap iframe" ).contents().find( "#map_canvas" )
.css( { "width": w, "height" : h } );
},
popupafterclose: function() {
$( "#popupMap iframe" )
.attr( "width", 0 )
.attr( "height", 0 );
$( "#popupMap iframe" ).contents().find( "#map_canvas" )
.css( { "width": 0, "height" : 0 } );
}
});
});

Overlay panels

Taking customization further, here is an example of a popup that has been customized to look like a vertical panel with three mini buttons:

Here is the HTML markup for the button and panel:

1
2
3
4
5
6
7
8
9
<a href="#popupPanel" data-rel="popup" data-transition="slide" data-position-to="window" data-role="button">Open panel</a>
<div data-role="popup" id="popupPanel" data-corners="false" data-theme="none" data-shadow="false" data-tolerance="0,0">
<button data-theme="a" data-icon="back" data-mini="true">Back</button>
<button data-theme="a" data-icon="grid" data-mini="true">Menu</button>
<button data-theme="a" data-icon="search" data-mini="true">Search</button>
</div>

To style the panel, and attach it to the right edge, the following CSS is used. Note that #popupPanel-popup is the ID of the container div generated by the framework.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#popupPanel-popup {
right: 0 !important;
left: auto !important;
}
#popupPanel {
width: 200px;
border: 1px solid #000;
border-right: none;
background: rgba(0,0,0,.5);
margin: -1px 0;
}
#popupPanel .ui-btn {
margin: 2em 15px;
}

Because the popup container is positioned absolute, you can't make the panel full height with height:100%;. This small script sets the height of the popup to the actual screen height.

1
2
3
4
5
6
7
$( "#popupPanel" ).on({
popupbeforeposition: function() {
var h = $( window ).height();
$( "#popupPanel" ).css( "height", h );
}
});

Calling the popup plugin

This plugin will autoinitialize on any page that contains a div with the attribute data-role="popup". However, if needed you can directly call the popup plugin on any selector, just like any jQuery plugin and programmatically work with the popup options, methods, and events API:

1
$( "#myPopupDiv" ).popup();

Opening popups

Using the markup-based configuration, when a link with the data-rel="popup" is tapped, the corresponding popup container with the id referenced in the href of the link will be shown. To open a popup programmatically, call popup with the open method on the popup container:

1
$( "#myPopupDiv" ).popup( "open" )

Closing popups

By default popups can be closed either by clicking outside the popup widget or by pressing the Esc key. To prevent this, the data-dismissible="false" attribute can be added to the popup. Popups can also be closed via the close method:

1
$( "#myPopupDiv" ).popup( "close" )

To add an explicit close button to a popup, add a link with the role of button into the popup container with a data-rel="back" attribute which will close the popup when tapped. We have created helper classes to position buttons in the upper left (ui-btn-left) or upper right (ui-btn-right) of the popup but you may need to tweak these or add custom positioning styles depending on your design. We recommend adding standard content padding to the popup to make room for the buttons (see next section).

1
2
3
4
<div data-role="popup">
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
...popup contents go here...
</div>

Adding padding

For popups with formatted text, padding is needed. We recommend adding the ui-content class to the popup container which adds the standard 15px of padding, just like the page content container. Write your own styles to create a more customized design if needed.

1
2
3
4
5
<a href="#popupPadded" data-rel="popup" data-role="button">Popup with padding</a>
<div data-role="popup" id="popupPadded" class="ui-content">
<p>This is a popup with the <code>ui-content</code> class added to the popup container.</p>
</div>

This will result in the following popup with content padding:

When padding is added, we apply a few style rules to negate the top margin for the first heading or paragraph in the popup and do the same for the last element's bottom margin. This keep the popups from having too much vertical space when the content padding and element margins combine.

Positioning options

By default, popups open centered vertically and horizontally over the thing you clicked (the origin) which is good for popups used as tooltips or menus. The framework also applies some basic collision detection rules to ensure that the popup will appear on-screen so the ultimate position may not always be centered over the origin.

For situations like a dialog or lightbox where the popup should appear centered within the window instead of over the origin, add the data-position-to attribute to the link and specify a value of window.

It's also possible to specify any valid selector as the value of position-to in addition to origin and window. For example, if you add data-position-to="#myElement" the popup will be positioned over the element with the id myElement.

A few examples:

The popup's placement constraints, which may cause the popup not to appear centered as desired, are as follow:

  1. The width of the popup will be limited using CSS max-width to the width of the window minus a tolerance of 15px on either side.
  2. A tolerance from the edges of the window (15px from each of the sides and 30px from the top and the bottom) will be observed when the popup fits inside the window. Tall popups are allowed to overflow the top and bottom edges of the window. Those parts of the popup can be viewed by manually scrolling the document. This tolerance is a configurable option.
  3. The top coordinate of the popup will never be negative. This ensures that the top of the popup will not be cut off.
  4. If centering the popup over an element would cause the overall height of the document to increase, the popup is shifted upwards at most until its top coordinate becomes 0.

Also note that a popup is currently always placed at the center of the window after an orientation change or window resize event.

See methods for information about setting the popup position programmatically, including the option to specify x and y coordinates.

Setting transitions

By default, popups have no transition to make them open as quickly as possible. To set the transition used for a popup, add the data-transition attribute to the link that references the popup. The reverse version of the transition will be used when closing the popup.

1
2
3
<a href="#transitionExample" data-transition="flip" data-rel="popup">
Flip transition
</a>

For performance reasons on mobile devices, we recommend using simpler transitions like pop, fade or none for smooth and fast popup animations, especially with larger or complex widgets within a popup. To view all transition types, you must be on a browser that supports 3D transforms. By default, devices that lack 3D support (such as Android 2.x) will fallback to "fade" for all transition types. See the transitions page for detailed information on the transition system.

When you launch the popup from any of the buttons, the data-transition set on the button will be used. However, if you launch the popup programmatically, such as via $( "#transitionExample" ).popup( "open" ), the data-transition attribute specified in the definition of the popup will be used if present.

Theming the popup and overlay

The popup plugin provides two theme-related options: data-theme and data-overlay-theme. The data-theme option refers to the theme of the popup itself, whereas data-overlay-theme refers to the theme of the popup's background, which covers the entire window behind the popup.

data-theme will be inherited from the page, and will always have a valid value when the popup opens, unless you explicitly specify data-theme="none", in which case the popup will have a transparent background.

The data-overlay-theme will never be set, and the popup's background, although always present when the popup is shown, will be completely transparent, unless explicitly set using for example data-overlay-theme="a". In this case, the background will fade in, partially obscuring the rest of the window, to further direct attention to the popup. Here is an example of an explicitly themed popup:

1
2
3
<div id="both" data-role="popup" data-theme="e" data-overlay-theme="a" class="ui-content">
...Popup contents...
</div>

Note: Chaining of popups not allowed

The framework does not currently support chaining of popups so it's not possible to embed a link from one popup to another popup. All links with a data-rel="popup" inside a popup will not do anything at all.

This also means that custom select menus will not work inside popups, because they are themselves implemented using popups. If you place a select menu inside a popup, it will be rendered as a native select menu, even if you specify data-native-menu="false".

A workaround to get chained popups working is the use of a timeout for example in the popupafterclose event bound to the invoking popup. In the following example, when the first popup is closed, the second will be opened by a delayed call to the open method:

1
2
3
4
5
6
7
$( document ).on( "pageinit", function() {
$( ".popupParent" ).on({
popupafterclose: function() {
setTimeout(function() { $( ".popupChild" ).popup( "open" ) }, 100 );
}
});
});

Options

corners 

Type: Boolean
Default: true

Sets whether to draw the popup with rounded corners.

This option is also exposed as a data attribute: data-corners="false".

Code examples:

Initialize the popup with the corners option specified:

1
2
3
$( ".selector" ).popup({
corners: false
});

Get or set the corners option, after initialization:

1
2
3
4
5
// Getter
var corners = $( ".selector" ).popup( "option", "corners" );
// Setter
$( ".selector" ).popup( "option", "corners", false );

dismissible 

Type: Boolean
Default: true

Sets whether clicking outside the popup or pressing Escape while the popup is open will close the popup.

Note: When history support is turned on, pressing the browser's "Back" button will dismiss the popup even if this option is set to false.

This option is also exposed as a data attribute: data-dismissible="false".

Code examples:

Initialize the popup with the dismissible option specified:

1
2
3
$( ".selector" ).popup({
dismissible: false
});

Get or set the dismissible option, after initialization:

1
2
3
4
5
// Getter
var dismissible = $( ".selector" ).popup( "option", "dismissible" );
// Setter
$( ".selector" ).popup( "option", "dismissible", false );

history 

Type: Boolean
Default: true

Sets whether to alter the url when a popup is open to support the back button.

This option is also exposed as a data attribute: data-history="false".

Code examples:

Initialize the popup with the history option specified:

1
2
3
$( ".selector" ).popup({
history: false
});

Get or set the history option, after initialization:

1
2
3
4
5
// Getter
var history = $( ".selector" ).popup( "option", "history" );
// Setter
$( ".selector" ).popup( "option", "history", false );

initSelector 

Default: ":jqmData(role='popup')"

This is used to define the selectors (element types, data roles, etc.) that will automatically be initialized as popups. To change which elements are initialized, bind this option to the mobileinit event:

1
2
3
$( document ).on( "mobileinit", function() {
$.mobile.popup.prototype.options.initSelector = ".mypopup";
});

overlayTheme 

Type: String
Default: null

Sets the color scheme (swatch) for the popup background, which covers the entire window. If not explicitly set, the background will be transparent.

This option is also exposed as a data attribute: data-overlay-theme="a".

Code examples:

Initialize the popup with the overlayTheme option specified:

1
2
3
$( ".selector" ).popup({
overlayTheme: "a"
});

Get or set the overlayTheme option, after initialization:

1
2
3
4
5
// Getter
var overlayTheme = $( ".selector" ).popup( "option", "overlayTheme" );
// Setter
$( ".selector" ).popup( "option", "overlayTheme", "a" );

positionTo 

Type: String
Default: "origin"

Sets the element relative to which the popup will be centered. It has the following values:

"origin" When the popup opens, center over the coordinates passed to the open() call (see details on this method).
"window" When the popup opens, center in the window.
jQuery selector When the popup opens, create a jQuery object based on the selector, and center over it. The selector is filtered for elements that are visible with ":visible". If the result is empty, the popup will be centered in the window.

This option is also exposed as a data attribute: data-position-to="window".

Code examples:

Initialize the popup with the positionTo option specified:

1
2
3
$( ".selector" ).popup({
positionTo: "window"
});

Get or set the positionTo option, after initialization:

1
2
3
4
5
// Getter
var positionTo = $( ".selector" ).popup( "option", "positionTo" );
// Setter
$( ".selector" ).popup( "option", "positionTo", "window" );

shadow 

Type: Boolean
Default: true

Sets whether to draw a shadow around the popup.

This option is also exposed as a data attribute: data-shadow="false".

Code examples:

Initialize the popup with the shadow option specified:

1
2
3
$( ".selector" ).popup({
shadow: false
});

Get or set the shadow option, after initialization:

1
2
3
4
5
// Getter
var shadow = $( ".selector" ).popup( "option", "shadow" );
// Setter
$( ".selector" ).popup( "option", "shadow", false );

theme 

Type: String
Default: null, inherited from parent

Sets the color scheme (swatch) for the popup contents. Unless explicitly set to 'none', the theme for the popup will be assigned the first time the popup is shown by inheriting the page theme or, failing that, by the hard-coded value 'c'. If you set it to 'none', the popup will not have any theme at all, and will be transparent.

Possible values: swatch letter (a-z).

This option is also exposed as a data attribute: data-theme="a".

Code examples:

Initialize the popup with the theme option specified:

1
2
3
$( ".selector" ).popup({
theme: "a"
});

Get or set the theme option, after initialization:

1
2
3
4
5
// Getter
var theme = $( ".selector" ).popup( "option", "theme" );
// Setter
$( ".selector" ).popup( "option", "theme", "a" );

tolerance 

Type: String
Default: "30,15,30,15"

Sets the minimum distance from the edge of the window for the corresponding edge of the popup. By default, the values above will be used for the distance from the top, right, bottom, and left edge of the window, respectively.

You can specify a value for this option in one of four ways:

  1. Empty string, null, or some other falsey value. This will cause the popup to revert to the above default values.
  2. A single number. This number will be used for all four edge tolerances.
  3. Two numbers separated by a comma. The first number will be used for tolerances from the top and bottom edge of the window, and the second number will be used for tolerances from the left and right edge of the window.
  4. Four comma-separated numbers. The first will be used for tolerance from the top edge, the second for tolerance from the right edge, the third for tolerance from the bottom edge, and the fourth for tolerance from the left edge.

Code examples:

Initialize the popup with the tolerance option specified:

1
2
3
$( ".selector" ).popup({
tolerance: "0,0"
});

Get or set the tolerance option, after initialization:

1
2
3
4
5
// Getter
var tolerance = $( ".selector" ).popup( "option", "tolerance" );
// Setter
$( ".selector" ).popup( "option", "tolerance", "0,0" );

transition 

Type: String
Default: none

Sets the default transition for the popup. The default value will result in no transition.

If the popup is opened from a link, and the link has the data-transition attribute set, the value specified therein will override the value of this option at the time the popup is opened from the link.

Code examples:

Initialize the popup with the transition option specified:

1
2
3
$( ".selector" ).popup({
transition: "pop"
});

Get or set the transition option, after initialization:

1
2
3
4
5
// Getter
var transition = $( ".selector" ).popup( "option", "transition" );
// Setter
$( ".selector" ).popup( "option", "transition", "pop" );

Methods

close()Returns: jQuery (plugin only)

Closes the popup.
  • This method does not accept any arguments.
Code examples:

Invoke the close method:

1
$( ".selector" ).popup( "close" );

open( options )Returns: jQuery (plugin only)

display the popup using the specified options.

If x or y is missing, and no jQuery selector is given as the value of positionTo, the middle of the window will be used.

transition can be used to override the popup's own transition option. This will result in the popup opening via the transition specified in the call, but the popup's transition option will not be updated.

Similarly, data-position-to can be used to override the popup's default positioning without modifying the value of the popup's positionTo option. The values available for positionTo are the same as those for the popup's positionTo option.

  • options
    Type: Object
    • x (default: )
      Type: String
      The x-coordinate where the popup is to be displayed.
    • y (default: )
      Type: String
      The y-coordinate where the popup is to be displayed.
    • transition (default: "none")
      Type: String
      The transition to use during the opening sequence.
    • positionTo (default: "origin")
      Type: String
      The positioning to use.
Code examples:

Invoke the open method:

1
$( ".selector" ).popup( "open", options );

reposition( options )Returns: jQuery (plugin only)

Change the on-screen position of the popup. See the open() method for a description of the keys recognized from the options object.
  • options
    Type: Object
    • x (default: )
      Type: Integer
      The x-coordinate where the popup is to be displayed.
    • y (default: )
      Type: Integer
      The y-coordinate where the popup is to be displayed.
    • positionTo (default: "origin")
      Type: String
      The positioning to use.
Code examples:

Invoke the reposition method:

1
$( ".selector" ).popup( "reposition", options );

Events

afterclose( event )Type: popupafterclose

Triggered when a popup has completely closed

This event is triggered when the popup has completely disappeared from the screen, meaning that all associated animations have completed.

Note: The ui object is empty but included for consistency with other events.

Code examples:

Initialize the popup with the afterclose callback specified:

1
2
3
$( ".selector" ).popup({
afterclose: function( event, ui ) {}
});

Bind an event listener to the popupafterclose event:

1
$( ".selector" ).on( "popupafterclose", function( event, ui ) {} );

afteropen( event )Type: popupafteropen

Triggered after a popup has completely opened

This event is triggered when the popup has completely appeared on the screen, meaning that all associated animations have completed.

Note: The ui object is empty but included for consistency with other events.

Code examples:

Initialize the popup with the afteropen callback specified:

1
2
3
$( ".selector" ).popup({
afteropen: function( event, ui ) {}
});

Bind an event listener to the popupafteropen event:

1
$( ".selector" ).on( "popupafteropen", function( event, ui ) {} );

beforeposition( event, ui )Type: popupbeforeposition

Triggered before a popup computes the coordinates where it will appear

This event is triggered when the popup has completed preparations for appearing on the screen, when the document is resized and the popup needs to move to another location, or when the reposition() method is called. At this point the popup has not yet started the opening animations and it has not yet calculated the coordinates where it will appear on the screen. Handling this event gives an opportunity to modify the content of the popup before it appears on the screen. For example, the content can be scaled or parts of it can be hidden or removed if it is too wide or too tall. You can also modify the options parameter to affect the popup's placement. The properties inside the options object available for modification are the same as those used by the reposition method.

Note: The ui object is empty but included for consistency with other events.

Code examples:

Initialize the popup with the beforeposition callback specified:

1
2
3
$( ".selector" ).popup({
beforeposition: function( event, ui ) {}
});

Bind an event listener to the popupbeforeposition event:

1
$( ".selector" ).on( "popupbeforeposition", function( event, ui ) {} );

create( event, ui )Type: popupcreate

triggered when a popup is created

Note: The ui object is empty but included for consistency with other events.

Code examples:

Initialize the popup with the create callback specified:

1
2
3
$( ".selector" ).popup({
create: function( event, ui ) {}
});

Bind an event listener to the popupcreate event:

1
$( ".selector" ).on( "popupcreate", function( event, ui ) {} );

Example:

A basic example of a Popup.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>popup demo</title>
<link rel="stylesheet" href="//code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header">
<h1>jQuery Mobile Example</h1>
</div>
<div data-role="content">
<a href="#popupBasic" data-rel="popup" data-role="button">Open Popup</a>
<div data-role="popup" id="popupBasic">
<p>This is a completely basic popup, no options set.</p>
</div>
</div>
</div>
</body>
</html>

Demo: