jquery-mobile/js/jquery.mobile.dialog.js
scottjehl 80d56e655b Changed page navigation scripting to use data-url attributes instead of IDs for storing page URLs. This fixes a number of issues, most importantly #477, which exposed a conflict between jQuery's selector engine that would result in un-enhanced pages whenever linking between two pages in the same directory.
The shift away from interal ID attribute usage also allows users to bind page events (pagecreate, pagebeforecreate) to a page div by its ID, which was a frequent cause of confusion when it didn't work as expected in former versions of the framework.

Seemingly unrelated: these commits allow you to specify data-role="dialog" in multipage and single page templates. In multipage templates, the role must be on the page (a link with data-rel alone will not work in multi-page). This addresses issue number 464, but may need further testing for obscure scenarios.

Fixes #477 (Pages are not enhanced when linking to a filename without a path)
Fixes #493 (Click the same link twice -> blank page)
Fixes #513 (closing dialog + returning to the same dialog)
Fixes #550 (changePage() not updating hash for internal pages - breaks )
Fixes #464 (Dialogs don't work within multi-pages)
Fixes #633 (Recent change to prevent same-page requests breaks select menu close button)
Fixes #599 (Page ids & page specific events)
Fixes #634 (After a bad page request, base url is not reset to current path)

booya.
2010-12-07 12:05:10 -05:00

58 lines
No EOL
1.6 KiB
JavaScript

/*
* jQuery Mobile Framework : "dialog" plugin.
* Copyright (c) jQuery Project
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
* Note: Code is in draft form and is subject to change
*/
(function($, undefined ) {
$.widget( "mobile.dialog", $.mobile.widget, {
options: {},
_create: function(){
var self = this,
$el = self.element,
$prevPage = $.mobile.activePage,
$closeBtn = $('<a href="#" data-icon="delete" data-iconpos="notext">Close</a>');
$el.delegate("a, form", "click submit", function(e){
if( e.type == "click" && ( $(e.target).closest('[data-back]')[0] || this==$closeBtn[0] ) ){
self.close();
return false;
}
//otherwise, assume we're headed somewhere new. set activepage to dialog so the transition will work
$.mobile.activePage = self.element;
});
this.element
.bind("pageshow",function(){
return false;
})
//add ARIA role
.attr("role","dialog")
.addClass('ui-page ui-dialog ui-body-a')
.find('[data-role=header]')
.addClass('ui-corner-top ui-overlay-shadow')
.prepend( $closeBtn )
.end()
.find('.ui-content:not([class*="ui-body-"])')
.addClass('ui-body-c')
.end()
.find('.ui-content,[data-role=footer]')
.last()
.addClass('ui-corner-bottom ui-overlay-shadow');
$(window).bind('hashchange',function(){
if( $el.is('.ui-page-active') ){
self.close();
$el.bind('pagehide',function(){
$.mobile.updateHash( $prevPage.attr('data-url'), true);
});
}
});
},
close: function(){
$.mobile.changePage([this.element, $.mobile.activePage], undefined, true, true );
}
});
})( jQuery );