Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/202060
Change subject: Hygiene: Create separate module for initialisation ...................................................................... Hygiene: Create separate module for initialisation Allow reuse of watchstar without side effects Change-Id: I0926d72cd6e42534bc76b1dd5ff5a5b20ebd96a2 --- M includes/Gather.hooks.php M resources/Resources.php M resources/ext.gather.init/init.js D resources/ext.gather.watchstar/init.js 4 files changed, 17 insertions(+), 110 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather refs/changes/60/202060/1 diff --git a/includes/Gather.hooks.php b/includes/Gather.hooks.php index 87b8bc0..fc8df04 100644 --- a/includes/Gather.hooks.php +++ b/includes/Gather.hooks.php @@ -82,7 +82,7 @@ */ public static function onSkinMinervaDefaultModules( $skin, &$modules ) { if ( MobileContext::singleton()->isBetaGroupMember() ) { - $modules['watch'] = array( 'ext.gather.watchstar' ); + $modules['watch'] = array( 'ext.gather.init' ); } // FIXME: abuse of the hook. $skin->getOutput()->addModules( 'ext.gather.icons' ); diff --git a/resources/Resources.php b/resources/Resources.php index 3a37cf9..dad06ff 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -117,8 +117,7 @@ 'ext.gather.watchstar' => $wgGatherResourceFileModuleBoilerplate + array( 'dependencies' => array( 'mediawiki.util', - 'mobile.watchstar', - 'mobile.settings', + 'mobile.user', 'ext.gather.api', 'ext.gather.collection.base', 'mobile.settings', @@ -156,7 +155,15 @@ 'ext.gather.watchstar/CollectionsContentOverlay.js', 'ext.gather.watchstar/CollectionsWatchstar.js', 'ext.gather.watchstar/WatchstarPageActionOverlay.js', - 'ext.gather.watchstar/init.js', + ), + ), + + 'ext.gather.init' => $wgGatherResourceFileModuleBoilerplate + array( + 'dependencies' => array( + 'ext.gather.watchstar', + ), + 'scripts' => array( + 'ext.gather.init/init.js', ), ), diff --git a/resources/ext.gather.init/init.js b/resources/ext.gather.init/init.js index e0e7353..0938872 100644 --- a/resources/ext.gather.init/init.js +++ b/resources/ext.gather.init/init.js @@ -48,9 +48,11 @@ * @ignore */ function showPointer( watchstar ) { - var actionOverlay = new WatchstarPageActionOverlay( { - target: watchstar.$el - } ); + var $star = watchstar.$el, + actionOverlay = new WatchstarPageActionOverlay( { + target: $star + } ); + // Dismiss when watchstar is clicked $star.on( 'click', function () { actionOverlay.hide(); @@ -86,7 +88,7 @@ isNewlyAuthenticatedUser: mw.util.getParamValue( 'article_action' ) === 'add_to_collection' } ); - watchstar.insertBefore( $star ) + watchstar.insertBefore( $star ); $star.remove(); if ( shouldShow ) { showPointer( watchstar ); diff --git a/resources/ext.gather.watchstar/init.js b/resources/ext.gather.watchstar/init.js deleted file mode 100644 index 0938872..0000000 --- a/resources/ext.gather.watchstar/init.js +++ /dev/null @@ -1,102 +0,0 @@ -// jscs:disable requireCamelCaseOrUpperCaseIdentifiers -( function ( M, $ ) { - - var CollectionsWatchstar = M.require( 'ext.gather.watchstar/CollectionsWatchstar' ), - WatchstarPageActionOverlay = M.require( 'ext.gather.watchstar/WatchstarPageActionOverlay' ), - settings = M.require( 'settings' ), - settingOverlayWasDismissed = 'gather-has-dismissed-tutorial', - user = M.require( 'user' ), - page = M.getCurrentPage(); - - /** - * Determines if collection tutorial should be shown - * - * @method - * @ignore - * @returns {Boolean} - */ - function shouldShowCollectionTutorial() { - if ( - mw.config.get( 'wgNamespaceNumber' ) === 0 && - // Don't show this when mobile is showing edit tutorial - mw.util.getParamValue( 'article_action' ) !== 'signup-edit' && - // Don't show if the overlay is open as user could have clicked watchstar - !$( 'html' ).hasClass( 'gather-overlay-enabled' ) && - // Tutorial has never been dismissed - !settings.get( settingOverlayWasDismissed ) && - // Feature flag is enabled - mw.config.get( 'wgGatherShouldShowTutorial' ) - ) { - return true; - } - return false; - } - - /** - * Overlay was dismissed. - * @method - * @ignore - */ - function overlayDismissed() { - settings.save( settingOverlayWasDismissed, true ); - } - - /** - * Show a pointer that points to the collection feature. - * @method - * @param {Watchstar} watchstar to react when actionable - * @ignore - */ - function showPointer( watchstar ) { - var $star = watchstar.$el, - actionOverlay = new WatchstarPageActionOverlay( { - target: $star - } ); - - // Dismiss when watchstar is clicked - $star.on( 'click', function () { - actionOverlay.hide(); - overlayDismissed(); - } ); - // Dismiss when 'No thanks' button is clicked - actionOverlay.on( 'cancel', overlayDismissed ); - // Toggle WatstarOverlay and dismiss - actionOverlay.on( 'action', function ( ev ) { - watchstar.onStatusToggle( ev ); - overlayDismissed(); - } ); - actionOverlay.show(); - // Refresh pointer otherwise it is not positioned - // FIXME: Remove when ContentOverlay is fixed - actionOverlay.refreshPointerArrow( $star ); - } - - /** - * Swap out the default watchstar for our link - * @method - * @param {Page} page - * @ignore - */ - function init( page ) { - var $star = $( '#ca-watch' ), - shouldShow = shouldShowCollectionTutorial(), - watchstar = new CollectionsWatchstar( { - page: page, - isAnon: user.isAnon(), - isWatched: $star.hasClass( 'watched' ), - wasUserPrompted: shouldShow, - isNewlyAuthenticatedUser: mw.util.getParamValue( 'article_action' ) === 'add_to_collection' - } ); - - watchstar.insertBefore( $star ); - $star.remove(); - if ( shouldShow ) { - showPointer( watchstar ); - } - } - // Only init when current page is an article - if ( !page.inNamespace( 'special' ) ) { - init( page ); - } - -}( mw.mobileFrontend, jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/202060 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0926d72cd6e42534bc76b1dd5ff5a5b20ebd96a2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Gather Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits