JGonera has uploaded a new change for review.
https://gerrit.wikimedia.org/r/87629
Change subject: Regression: Fix section toggling when URL contains a hash
......................................................................
Regression: Fix section toggling when URL contains a hash
Also, clean up mf-toggle.js and fix section edit tutorial popup that
appears after a CTA.
Change-Id: Ia56cb0f4492ccf599be191123287e93c50415ced
---
M javascripts/modules/mf-toggle.js
M javascripts/modules/tutorials/newbie.js
2 files changed, 36 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/29/87629/1
diff --git a/javascripts/modules/mf-toggle.js b/javascripts/modules/mf-toggle.js
index 2f93781..bf9060b 100644
--- a/javascripts/modules/mf-toggle.js
+++ b/javascripts/modules/mf-toggle.js
@@ -1,6 +1,16 @@
( function( M, $ ) {
-var toggle = ( function() {
+ /**
+ * Escape dots and colons in a hash, jQuery doesn't like them beause
they
+ * look like CSS classes and pseudoclasses. See
+ * http://bugs.jquery.com/ticket/5241
+ *
http://stackoverflow.com/questions/350292/how-do-i-get-jquery-to-select-elements-with-a-period-in-their-id
+ *
+ * @param {String} hash A hash to escape
+ */
+ function escapeHash( hash ) {
+ return hash.replace( /(:|\.)/g, '\\$1' );
+ }
/**
* Given a heading, toggle it and any of its children
@@ -24,7 +34,7 @@
// jQuery will throw for hashes containing certain characters
which can break toggling
try {
- $target = $( selector );
+ $target = $( escapeHash( selector ) );
$heading = $target.closest( '.section_heading' ).eq( 0
);
if ( $heading.length > 0 && !$heading.hasClass(
'openSection' ) ) {
@@ -50,6 +60,7 @@
$( '.section_heading' ).on( M.tapEvent( 'mouseup' ), function()
{
toggle( $( this ) );
} );
+ // FIXME: remove when this class is no longer in cached pages
$( '.section_anchors' ).remove();
function checkHash() {
@@ -67,29 +78,29 @@
init();
}
- return {
+ M.on( 'page-loaded', function( page ) {
+ if ( !page.isMainPage() ) {
+ init();
+ }
+ } );
+
+ // FIXME: Temporary workaround while toggle-dynamic is not in stable
+ // (needed for dynamic section loading after editing)
+ if ( mw.config.get( 'wgMFMode' ) === 'stable' ) {
+ M.on( 'section-toggle', function( $section ) {
+ var $content = $section.next(),
+ content = $content.data( 'content' );
+ if ( content ) {
+ $content.html( content ).data( 'content', false
);
+ }
+ } );
+ }
+
+ M.define( 'toggle', {
+ escapeHash: escapeHash,
reveal: reveal,
toggle: toggle,
enable: init
- };
-
-}());
-
-M.define( 'toggle', toggle );
-M.on( 'page-loaded', function( page ) {
- if ( !page.isMainPage() ) {
- toggle.enable();
- }
-} );
-// FIXME: Temporary workaround while toggle-dynamic is not in stable
-if ( mw.config.get( 'wgMFMode' ) === 'stable' ) {
- M.on( 'section-toggle', function( $section ) {
- var $content = $section.next(),
- content = $content.data( 'content' );
- if ( content ) {
- $content.html( content ).data( 'content', false );
- }
} );
-}
}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/tutorials/newbie.js
b/javascripts/modules/tutorials/newbie.js
index 0685d71..affc665 100644
--- a/javascripts/modules/tutorials/newbie.js
+++ b/javascripts/modules/tutorials/newbie.js
@@ -1,6 +1,7 @@
( function( M, $ ) {
var LeadPhotoTutorialOverlay = M.require(
'tutorials/LeadPhotoTutorialOverlay' ),
- PageActionOverlay = M.require( 'tutorials/PageActionOverlay' );
+ PageActionOverlay = M.require( 'tutorials/PageActionOverlay' ),
+ escapeHash = M.require( 'toggle' ).escapeHash;
function shouldShowUploadTutorial() {
// FIXME: Limit audience to only users with low edit count
@@ -21,7 +22,7 @@
return;
} else if ( shouldShowEditTutorial() ) {
if ( window.location.hash ) {
- target = window.location.hash + ' ~ .edit-page';
+ target = escapeHash( window.location.hash ) + '
~ .edit-page';
} else {
target = '#ca-edit .edit-page';
}
--
To view, visit https://gerrit.wikimedia.org/r/87629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia56cb0f4492ccf599be191123287e93c50415ced
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits