fixed issue with dialog click handler breaking transitions on external links Fixes #642

This commit is contained in:
John Bender 2011-01-19 23:48:30 -08:00
parent dcf9a19c31
commit 8a5060de13
2 changed files with 26 additions and 9 deletions

View file

@ -2,29 +2,40 @@
* 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
* Note: Code is in draft form and is subject to change
*/
(function($, undefined ) {
$.widget( "mobile.dialog", $.mobile.widget, {
options: {},
_create: function(){
_create: function(){
var self = this,
$el = self.element,
$prevPage = $.mobile.activePage,
$closeBtn = $('<a href="#" data-icon="delete" data-iconpos="notext">Close</a>');
var dialogClickHandler = function(e){
var $target = $(e.target);
// fixes issues with target links in dialogs breaking
// page transitions by reseting the active page below
if( $target.attr('target') || $.mobile.isExternalLink($target) ) {
return;
}
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;
};
// NOTE avoid click handler in the case of an external resource
// TODO add function in navigation to handle external check
$el.delegate("a", "click", dialogClickHandler);
$el.delegate("form", "submit", dialogClickHandler);
this.element
.bind("pageshow",function(){
return false;
@ -38,11 +49,11 @@ $.widget( "mobile.dialog", $.mobile.widget, {
.end()
.find('.ui-content:not([class*="ui-body-"])')
.addClass('ui-body-c')
.end()
.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();
@ -50,10 +61,10 @@ $.widget( "mobile.dialog", $.mobile.widget, {
$.mobile.updateHash( $prevPage.attr('data-url'), true);
});
}
});
});
},
close: function(){
$.mobile.changePage([this.element, $.mobile.activePage], undefined, true, true );
}

View file

@ -163,6 +163,12 @@
//url stack, useful when plugins need to be aware of previous pages viewed
$.mobile.urlStack = urlStack;
//check for an external resource
$.mobile.isExternalLink = function(anchor){
var $anchor = $(anchor);
return /^(:?\w+:)/.test( $anchor.attr('href') ) || $anchor.is( "[rel=external]" );
},
// changepage function
$.mobile.changePage = function( to, transition, back, changeHash){
@ -446,7 +452,7 @@
//if target attr is specified, it's external, and we mimic _blank... for now
target = $this.is( "[target]" ),
//if it still starts with a protocol, it's external, or could be :mailto, etc
external = target || /^(:?\w+:)/.test( href ) || $this.is( "[rel=external]" );
external = target || $.mobile.isExternalLink(this);
if( href === '#' ){
//for links created purely for interaction - ignore