diff --git a/js/jquery.mobile.dialog.js b/js/jquery.mobile.dialog.js index 9e3589f1..c288c4bc 100644 --- a/js/jquery.mobile.dialog.js +++ b/js/jquery.mobile.dialog.js @@ -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 = $('Close'); 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 ); } diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 076ad55a..d96a6f65 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -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