Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/202059
Change subject: Hygiene: Correction to ext.gather.api module ...................................................................... Hygiene: Correction to ext.gather.api module * Update dependency now we don't use JSON page storage * Put in correct folder. Change-Id: I701d7b3ca1fb56a8fb899ee5d924e453f3ec8f46 --- M resources/Resources.php R resources/ext.gather.api/CollectionsApi.js A resources/ext.gather.init/init.js 3 files changed, 103 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather refs/changes/59/202059/1 diff --git a/resources/Resources.php b/resources/Resources.php index d0cc636..3a37cf9 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -93,10 +93,11 @@ 'ext.gather.api' => $wgGatherResourceFileModuleBoilerplate + array( 'dependencies' => array( - 'mobile.editor.api', + // FIXME: All we need is Api.js ... + 'mobile.startup', ), 'scripts' => array( - 'ext.gather.watchstar/CollectionsApi.js', + 'ext.gather.api/CollectionsApi.js', ), ), diff --git a/resources/ext.gather.watchstar/CollectionsApi.js b/resources/ext.gather.api/CollectionsApi.js similarity index 100% rename from resources/ext.gather.watchstar/CollectionsApi.js rename to resources/ext.gather.api/CollectionsApi.js diff --git a/resources/ext.gather.init/init.js b/resources/ext.gather.init/init.js new file mode 100644 index 0000000..e0e7353 --- /dev/null +++ b/resources/ext.gather.init/init.js @@ -0,0 +1,100 @@ +// 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 actionOverlay = new WatchstarPageActionOverlay( { + target: watchstar.$el + } ); + // 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/202059 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I701d7b3ca1fb56a8fb899ee5d924e453f3ec8f46 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