1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Displays a page as a modal dialog with inset appearance and overlay background
5 //>>css.structure: ../css/structure/jquery.mobile.dialog.css
6 //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
8 define( [ "jquery", "../jquery.mobile.widget" ], function( $ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, window, undefined ) {
12 $.widget( "mobile.dialog", $.mobile.widget, {
14 closeBtnText: "Close",
16 initSelector: ":jqmData(role='dialog')"
21 headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" ),
22 dialogWrap = $( "<div/>", {
24 "class" : "ui-dialog-contain ui-corner-all ui-overlay-shadow"
27 $el.addClass( "ui-dialog ui-overlay-" + this.options.overlayTheme );
29 // Class the markup for dialog styling
32 .wrapInner( dialogWrap )
34 .find( ":jqmData(role='header')" )
35 .prepend( headerCloseButton )
37 .children( ':first-child')
38 .addClass( "ui-corner-top" )
40 .children( ":last-child" )
41 .addClass( "ui-corner-bottom" );
43 // this must be an anonymous function so that select menu dialogs can replace
44 // the close method. This is a change from previously just defining data-rel=back
45 // on the button and letting nav handle it
47 // Use click rather than vclick in order to prevent the possibility of unintentionally
48 // reopening the dialog if the dialog opening item was directly under the close button.
49 headerCloseButton.bind( "click", function() {
54 - clicks and submits should use the closing transition that the dialog opened with
55 unless a data-transition is specified on the link/form
56 - if the click was on the close button, or the link has a data-rel="back" it'll go back in history naturally
58 $el.bind( "vclick submit", function( event ) {
59 var $target = $( event.target ).closest( event.type === "vclick" ? "a" : "form" ),
62 if ( $target.length && !$target.jqmData( "transition" ) ) {
64 active = $.mobile.urlHistory.getActive() || {};
66 $target.attr( "data-" + $.mobile.ns + "transition", ( active.transition || $.mobile.defaultDialogTransition ) )
67 .attr( "data-" + $.mobile.ns + "direction", "reverse" );
70 .bind( "pagehide", function( e, ui ) {
71 $( this ).find( "." + $.mobile.activeBtnClass ).not( ".ui-slider-bg" ).removeClass( $.mobile.activeBtnClass );
73 // Override the theme set by the page plugin on pageshow
74 .bind( "pagebeforeshow", function() {
75 self._isCloseable = true;
76 if ( self.options.overlayTheme ) {
78 .page( "removeContainerBackground" )
79 .page( "setContainerBackground", self.options.overlayTheme );
84 // Close method goes back in history
88 if ( this._isCloseable ) {
89 this._isCloseable = false;
90 if ( $.mobile.hashListeningEnabled ) {
93 dst = $.mobile.urlHistory.getPrev().url;
94 if ( !$.mobile.path.isPath( dst ) ) {
95 dst = $.mobile.path.makeUrlAbsolute( "#" + dst );
98 $.mobile.changePage( dst, { changeHash: false, fromHashChange: true } );
104 //auto self-init widgets
105 $( document ).delegate( $.mobile.dialog.prototype.options.initSelector, "pagecreate", function() {
106 $.mobile.dialog.prototype.enhance( this );
110 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
112 //>>excludeEnd("jqmBuildExclude");