jenkins-bot has submitted this change and it was merged.
Change subject: Make editor disappear after a successful save
......................................................................
Make editor disappear after a successful save
After changing the back button behavior, the editor would reappear after
saving an edit. This prevents it.
Also make Router use an object for routes so that subsequent Router#route()
calls don't add duplicate entries.
Change-Id: I85c3613c789f65883b7ad470d15571a11b0b14d0
---
M javascripts/common/Router.js
M javascripts/modules/editor/EditorOverlay.js
M tests/javascripts/common/test_Router.js
3 files changed, 21 insertions(+), 8 deletions(-)
Approvals:
Jdlrobson: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/common/Router.js b/javascripts/common/Router.js
index 2643a4c..bfbd310 100644
--- a/javascripts/common/Router.js
+++ b/javascripts/common/Router.js
@@ -2,10 +2,10 @@
var EventEmitter = M.require( 'eventemitter' );
- function matchRoute( hash, route ) {
- var match = hash.match( route.path );
+ function matchRoute( hash, entry ) {
+ var match = hash.match( entry.path );
if ( match ) {
- route.callback.apply( this, match.slice( 1 ) );
+ entry.callback.apply( this, match.slice( 1 ) );
return true;
}
return false;
@@ -18,7 +18,9 @@
function Router() {
var self = this;
- this.routes = [];
+ // use an object instead of an array for routes so that we don't
+ // duplicate entries that already exist
+ this.routes = {};
this._enabled = true;
$( window ).on( 'hashchange', function( ev ) {
@@ -33,7 +35,7 @@
self.emit( 'route', routeEv );
if ( !routeEv.isDefaultPrevented() ) {
- $.each( self.routes, function( i, entry ) {
+ $.each( self.routes, function( id, entry ) {
return !matchRoute( hash, entry );
} );
} else {
@@ -60,13 +62,23 @@
*/
Router.prototype.route = function( path, callback ) {
var entry = {
- path: path instanceof RegExp ? path : new RegExp( '^' +
path + '$' ),
+ path: typeof path === 'string' ? new RegExp( '^' + path
+ '$' ) : path,
callback: callback
};
- this.routes.push( entry );
+ this.routes[entry.path] = entry;
matchRoute( window.location.hash.slice( 1 ), entry );
};
+ /**
+ * Navigate to a specific route. This is only a wrapper for changing the
+ * hash now.
+ *
+ * @param {string} path String with a route (hash without #).
+ */
+ Router.prototype.navigate = function( path ) {
+ window.location.hash = path;
+ };
+
Router.prototype.isSupported = function() {
return 'onhashchange' in window;
};
diff --git a/javascripts/modules/editor/EditorOverlay.js
b/javascripts/modules/editor/EditorOverlay.js
index 649730b..a7a9364 100644
--- a/javascripts/modules/editor/EditorOverlay.js
+++ b/javascripts/modules/editor/EditorOverlay.js
@@ -175,6 +175,7 @@
self.log( 'success' );
M.history.invalidateCachedPage( title );
new Page( { title: title, el: $(
'#content' ) } );
+ M.router.navigate( '' );
self.hide();
popup.show(
mw.msg(
'mobile-frontend-editor-success' ),
diff --git a/tests/javascripts/common/test_Router.js
b/tests/javascripts/common/test_Router.js
index 6082f5d..09ba082 100644
--- a/tests/javascripts/common/test_Router.js
+++ b/tests/javascripts/common/test_Router.js
@@ -26,7 +26,7 @@
} );
QUnit.asyncTest( '#route, RegExp', 1, function( assert ) {
- router.route( /testre-(\d+)/, function( param ) {
+ router.route( /^testre-(\d+)$/, function( param ) {
assert.strictEqual( param, '123', 'run callback for
route with correct params' );
QUnit.start();
} );
--
To view, visit https://gerrit.wikimedia.org/r/68721
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I85c3613c789f65883b7ad470d15571a11b0b14d0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits