2010-09-17 20:24:12 +00:00
|
|
|
/*
|
2010-11-10 00:55:52 +00:00
|
|
|
* jQuery Mobile Framework : "dialog" plugin.
|
2010-09-17 20:24:12 +00:00
|
|
|
* Copyright (c) jQuery Project
|
|
|
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
|
|
|
|
|
*/
|
2011-06-28 23:29:48 +00:00
|
|
|
|
|
|
|
|
(function( $, window, undefined ) {
|
|
|
|
|
|
2010-10-21 20:29:05 +00:00
|
|
|
$.widget( "mobile.dialog", $.mobile.widget, {
|
2011-03-27 18:10:16 +00:00
|
|
|
options: {
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
closeBtnText : "Close",
|
2011-07-26 18:22:08 +00:00
|
|
|
theme : "a",
|
2011-07-27 22:42:16 +00:00
|
|
|
initSelector : ":jqmData(role='dialog')"
|
2011-03-27 18:10:16 +00:00
|
|
|
},
|
2011-05-26 14:01:39 +00:00
|
|
|
_create: function() {
|
2011-09-23 16:55:17 +00:00
|
|
|
var self = this,
|
|
|
|
|
$el = this.element,
|
|
|
|
|
pageTheme = $el.attr( "class" ).match( /ui-body-[a-z]/ ),
|
|
|
|
|
headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" );
|
|
|
|
|
|
2011-07-20 16:40:46 +00:00
|
|
|
if( pageTheme.length ){
|
|
|
|
|
$el.removeClass( pageTheme[ 0 ] );
|
2011-09-23 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-20 16:40:46 +00:00
|
|
|
$el.addClass( "ui-body-" + this.options.theme );
|
2011-09-23 16:55:17 +00:00
|
|
|
|
2011-06-28 23:29:48 +00:00
|
|
|
// Class the markup for dialog styling
|
|
|
|
|
// Set aria role
|
|
|
|
|
$el.attr( "role", "dialog" )
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
.addClass( "ui-dialog" )
|
|
|
|
|
.find( ":jqmData(role='header')" )
|
2011-05-26 14:01:39 +00:00
|
|
|
.addClass( "ui-corner-top ui-overlay-shadow" )
|
2011-09-23 16:55:17 +00:00
|
|
|
.prepend( headerCloseButton )
|
2010-09-17 20:55:30 +00:00
|
|
|
.end()
|
This commit decouples all widgets from the page plugin so that they can be used ad-hoc.
- Internally, each plugin self-initializes by binding to the pagecreate event.
- Unit tests have been added and adjusted to support some internal changes involved in this commit.
- In the process, the portions of the page plugin that were used to enhance the header,content,and footer sections of a native-app style page layout are now located in jquery.mobile.page.sections.js.
- No public API options have changed, except that the page plugin no longer has options for keepNative, and degradeInputs, as plugins now handle these internally (keepNative was never documented, and degradeInputs only affected slider, so it lives there now. Page options related to the page sections are now located in the page.sections script, but they are still configurable via the page plugin's options api.
- Make, Ant, and index files are updated with a new load order for all JS files.
2011-07-19 23:05:35 +00:00
|
|
|
.find( ":jqmData(role='content'),:jqmData(role='footer')" )
|
2010-09-17 20:55:30 +00:00
|
|
|
.last()
|
2011-05-26 14:01:39 +00:00
|
|
|
.addClass( "ui-corner-bottom ui-overlay-shadow" );
|
2011-06-28 23:29:48 +00:00
|
|
|
|
2011-09-23 16:55:17 +00:00
|
|
|
// this must be an anonymous function so that select menu dialogs can replace
|
|
|
|
|
// the close method. This is a change from previously just defining data-rel=back
|
|
|
|
|
// on the button and letting nav handle it
|
|
|
|
|
headerCloseButton.bind( "vclick", function() {
|
|
|
|
|
self.close();
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-28 23:29:48 +00:00
|
|
|
/* bind events
|
2011-01-26 00:36:42 +00:00
|
|
|
- clicks and submits should use the closing transition that the dialog opened with
|
|
|
|
|
unless a data-transition is specified on the link/form
|
|
|
|
|
- if the click was on the close button, or the link has a data-rel="back" it'll go back in history naturally
|
|
|
|
|
*/
|
2011-06-28 23:29:48 +00:00
|
|
|
$el.bind( "vclick submit", function( event ) {
|
|
|
|
|
var $target = $( event.target ).closest( event.type === "vclick" ? "a" : "form" ),
|
|
|
|
|
active;
|
|
|
|
|
|
|
|
|
|
if ( $target.length && !$target.jqmData( "transition" ) ) {
|
|
|
|
|
|
|
|
|
|
active = $.mobile.urlHistory.getActive() || {};
|
|
|
|
|
|
|
|
|
|
$target.attr( "data-" + $.mobile.ns + "transition", ( active.transition || $.mobile.defaultDialogTransition ) )
|
|
|
|
|
.attr( "data-" + $.mobile.ns + "direction", "reverse" );
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.bind( "pagehide", function() {
|
|
|
|
|
$( this ).find( "." + $.mobile.activeBtnClass ).removeClass( $.mobile.activeBtnClass );
|
|
|
|
|
});
|
2010-11-05 02:49:28 +00:00
|
|
|
},
|
2011-06-28 23:29:48 +00:00
|
|
|
|
|
|
|
|
// Close method goes back in history
|
2011-05-26 14:01:39 +00:00
|
|
|
close: function() {
|
2011-01-26 00:36:42 +00:00
|
|
|
window.history.back();
|
2010-10-21 20:29:05 +00:00
|
|
|
}
|
|
|
|
|
});
|
2011-07-27 22:42:16 +00:00
|
|
|
|
|
|
|
|
//auto self-init widgets
|
|
|
|
|
$( $.mobile.dialog.prototype.options.initSelector ).live( "pagecreate", function(){
|
|
|
|
|
$( this ).dialog();
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-28 23:29:48 +00:00
|
|
|
})( jQuery, this );
|