Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first pass at disabling history with an option in popup

  • Loading branch information...
commit 5af122fa8532ee34177af7813ddaba6824ece795 1 parent 8416315
@johnbender johnbender authored
View
32 js/widgets/popup.js
@@ -46,7 +46,8 @@ define( [ "jquery",
transition: "none",
positionTo: "origin",
tolerance: null,
- initSelector: ":jqmData(role='popup')"
+ initSelector: ":jqmData(role='popup')",
+ history: true
},
_eatEventAndClose: function( e ) {
@@ -547,6 +548,9 @@ define( [ "jquery",
_closePrereqsDone: function() {
this._ui.container.removeAttr( "tabindex" );
+ // remove nav bindings if they are still present
+ $.mobile.pageContainer.unbind( "navigate.popup pagebeforechange.popup" );
+
// remove the global mutex for popups
$.mobile.popup.active = undefined;
@@ -595,19 +599,31 @@ define( [ "jquery",
});
},
-
// TODO no clear deliniation of what should be here and
// what should be in _open. Seems to be "visual" vs "history" for now
open: function( options ) {
var hashkey = $.mobile.dialogHashKey,
- activePage = $.mobile.activePage;
+ activePage = $.mobile.activePage,
+ self = this;
// make sure open is idempotent
if( $.mobile.popup.active ) {
return;
}
- var self = this, url = activePage.jqmData( "url" );
+ // if history alteration is disabled close on navigate events
+ // and don't modify the url
+ if( !this.options.history ) {
+ this._open( options );
+
+ $.mobile.pageContainer.one( "navigate.popup pagebeforechange.popup", function() {
+ self._close();
+ });
+
+ return;
+ }
+
+ var url = activePage.jqmData( "url" );
// if the current url has no dialog hash key proceed as normal
// otherwise, if the page is a dialog simply tack on the hash key
@@ -641,8 +657,14 @@ define( [ "jquery",
close: function() {
// make sure close is idempotent
- if( $.mobile.popup.active ){
+ if( !$.mobile.popup.active ){
+ return;
+ }
+
+ if( this.options.history ) {
window.history.back();
+ } else {
+ this._close();
}
}
});
View
8 tests/unit/popup/index.html
@@ -53,7 +53,15 @@ <h2 id="qunit-userAgent"></h2>
<div data-nstest-role="popup" id="popup-sequence-test">
<a id="popup-sequence-test-open-dialog" href="popup-sequence-test-dialog.html">Dialog</a>
</div>
+
+ <div data-nstest-role="popup" id="test-history-popup" data-nstest-history="false">
+ <p>This is the test popup</p>
+ </div>
</div>
</div>
+
+ <div data-nstest-role="page" id="no-popups">
+ Page that is not the popup page
+ </div>
</body>
</html>
View
36 tests/unit/popup/popup_core.js
@@ -417,7 +417,7 @@
});
asyncTest( "Popup focused after open", function() {
- var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" ), eventCount = 0;
+ var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" );
expect( 2 );
@@ -433,4 +433,38 @@
});
});
});
+
+ test( "Popup doesn't alter the url when the history option is disabled", function() {
+ var $popup = $( "#test-history-popup" ), hash = $.mobile.path.parseLocation().hash;
+
+ $popup.popup( "open" );
+
+ equal( hash, $.mobile.path.parseLocation().hash, "the hash remains the same" );
+
+ ok( $popup.is( ":visible" ), "popup is indeed visible" );
+
+ $popup.popup( "close" );
+ });
+
+ asyncTest( "Navigating away from the popup page closes the popup without history enabled", function() {
+ var $popup = $( "#test-history-popup" );
+
+ expect( 2 );
+
+ $popup.bind( "popupafterclose", function() {
+ // TODO would be nice to verify that it happens
+ // right after the first page goes away
+ ok( true, "popup was closed" );
+ });
+
+ $.testHelper.pageSequence([
+ function() {
+ $popup.popup( "open" );
+ ok( $popup.is( ":visible" ), "popup is indeed visible" );
+ $.mobile.changePage( "#no-popups" );
+ },
+
+ start
+ ]);
+ });
})( jQuery );

0 comments on commit 5af122f

Please sign in to comment.
Something went wrong with that request. Please try again.