Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

enable close button when history is disabled

  • Loading branch information...
commit d2361b5424f3fdbd446182267914de55e2432abe 1 parent 45f2492
@johnbender johnbender authored
View
27 js/widgets/popup.js
@@ -49,7 +49,7 @@ define( [ "jquery",
initSelector: ":jqmData(role='popup')",
navigateEvents: "navigate.popup",
closeEvents: "navigate.popup pagebeforechange.popup",
- history: true
+ history: false
},
_eatEventAndClose: function( e ) {
@@ -552,16 +552,21 @@ define( [ "jquery",
},
_closePrereqsDone: function() {
- this._ui.container.removeAttr( "tabindex" );
+ var self = this;
+
+ self._ui.container.removeAttr( "tabindex" );
// remove nav bindings if they are still present
- $.mobile.pageContainer.unbind( this.options.closeEvents );
+ self.options.container.unbind( self.options.closeEvents );
+
+ // unbind click handlers added when history is disabled
+ self.options.container.undelegate( "a:jqmData(rel='back')", "click.popup" );
// remove the global mutex for popups
$.mobile.popup.active = undefined;
// alert users that the popup is closed
- this._trigger( "afterclose" );
+ self._trigger( "afterclose" );
},
_close: function() {
@@ -632,6 +637,20 @@ define( [ "jquery",
// and leave the url as is
if( !self.options.history ) {
self._bindContainerClose();
+
+ // When histoy is disabled we have to grab the data-rel
+ // back link clicks so we can close the popup instead of
+ // relying on history to do it for us
+ self.options.container
+ .delegate( "a:jqmData(rel='back')", "click.popup", function( e ) {
+ self._close();
+
+ // NOTE prevent the browser and navigation handlers from
+ // working with the link's rel=back. This may cause
+ // issues for developers expecting the event to bubble
+ return false;
+ });
+
return;
}
View
1  tests/unit/popup/index.html
@@ -56,6 +56,7 @@ <h2 id="qunit-userAgent"></h2>
<div data-nstest-role="popup" id="test-history-popup" data-nstest-history="false">
<p>This is the test popup</p>
+ <a href="#" data-nstest-rel="back" data-nstest-role="button" data-nstest-theme="a" data-nstest-icon="delete" data-nstest-iconpos="notext" class="ui-btn-right">Close</a>
</div>
</div>
</div>
View
12 tests/unit/popup/popup_core.js
@@ -467,4 +467,16 @@
start
]);
});
+
+ test( "Close links work on a history disabled popup", function() {
+ var $popup = $( "#test-history-popup" );
+
+ expect( 2 );
+
+ $popup.popup( 'open' );
+ ok( $.mobile.popup.active, "popup is shown on link click" );
+
+ $popup.find( "a" ).click();
+ ok( !$.mobile.popup.active, "popup is hidden on link click" );
+ });
})( jQuery );
Please sign in to comment.
Something went wrong with that request. Please try again.