Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/332927 )
Change subject: Hygiene: icons moved to build_resources ...................................................................... Hygiene: icons moved to build_resources Change-Id: I7ed4985786fd3fb2546e0d7b5abb8972d8565337 --- R build_resources/mobile.frontend/icons.js M build_resources/mobile.frontend/index.js M extension.json M resources/mobile.categories.overlays/CategoryAddOverlay.js M resources/mobile.frontend/index.js M resources/mobile.gallery/PhotoList.js M resources/mobile.nearby/Nearby.js M resources/mobile.overlays/Overlay.js M resources/mobile.references/ReferencesDrawer.js M resources/mobile.startup/Section.js M resources/mobile.startup/Skin.js M resources/skins.minerva.notifications/init.js 12 files changed, 261 insertions(+), 214 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/27/332927/1 diff --git a/resources/mobile.startup/icons.js b/build_resources/mobile.frontend/icons.js similarity index 91% rename from resources/mobile.startup/icons.js rename to build_resources/mobile.frontend/icons.js index 3ee54b9..bd98a80 100644 --- a/resources/mobile.startup/icons.js +++ b/build_resources/mobile.frontend/icons.js @@ -1,6 +1,6 @@ ( function ( M, $ ) { - var Icon = mw.mf.Icon; + var Icon = require( './Icon' ); /** * A set of shared icons. @@ -13,7 +13,7 @@ * @singleton * @uses Icon */ - M.define( 'mobile.startup/icons', { + module.exports = { /** * Gets a spinner icon. @@ -33,6 +33,6 @@ additionalClassNames: 'spinner loading' } ) ); } - } ); + }; }( mw.mobileFrontend, jQuery ) ); diff --git a/build_resources/mobile.frontend/index.js b/build_resources/mobile.frontend/index.js index d99043d..5d3dfc3 100644 --- a/build_resources/mobile.frontend/index.js +++ b/build_resources/mobile.frontend/index.js @@ -1,4 +1,5 @@ module.exports = mediaWiki.mf = { + icons: require( './icons' ), Browser: require( './Browser' ), Icon: require( './Icon' ), View: require( './View' ), diff --git a/extension.json b/extension.json index f95320f..e1b8ea2 100644 --- a/extension.json +++ b/extension.json @@ -534,6 +534,9 @@ "dependencies": [ "mobile.oo" ], + "messages": [ + "mobile-frontend-loading-message" + ], "scripts": [ "resources/mobile.frontend/index.js" ] @@ -561,7 +564,6 @@ "button.hogan": "resources/mobile.startup/button.hogan" }, "messages": [ - "mobile-frontend-loading-message", "mobile-frontend-editor-licensing", "mobile-frontend-editor-licensing-with-terms", "mobile-frontend-editor-terms-link" @@ -573,7 +575,6 @@ "resources/mobile.startup/PageGateway.js", "resources/mobile.startup/Anchor.js", "resources/mobile.startup/Button.js", - "resources/mobile.startup/icons.js", "resources/mobile.startup/Panel.js", "resources/mobile.startup/Section.js", "resources/mobile.startup/Thumbnail.js", diff --git a/resources/mobile.categories.overlays/CategoryAddOverlay.js b/resources/mobile.categories.overlays/CategoryAddOverlay.js index 13a4b66..a6f4d2d 100644 --- a/resources/mobile.categories.overlays/CategoryAddOverlay.js +++ b/resources/mobile.categories.overlays/CategoryAddOverlay.js @@ -3,7 +3,7 @@ var Overlay = M.require( 'mobile.overlays/Overlay' ), CategoryGateway = M.require( 'mobile.categories.overlays/CategoryGateway' ), CategoryLookupInputWidget = M.require( 'mobile.categories.overlays/CategoryLookupInputWidget' ), - icons = M.require( 'mobile.startup/icons' ), + icons = mw.mf.icons, toast = M.require( 'mobile.toast/toast' ); /** diff --git a/resources/mobile.frontend/index.js b/resources/mobile.frontend/index.js index e7641f8..99fe584 100644 --- a/resources/mobile.frontend/index.js +++ b/resources/mobile.frontend/index.js @@ -45,225 +45,55 @@ /***/ function(module, exports, __webpack_require__) { module.exports = mediaWiki.mf = { - Browser: __webpack_require__( 1 ), + icons: __webpack_require__( 1 ), + Browser: __webpack_require__( 8 ), Icon: __webpack_require__( 2 ), View: __webpack_require__( 3 ), - util: __webpack_require__( 8 ) + util: __webpack_require__( 9 ) }; /***/ }, /* 1 */ -/***/ function(module, exports) { +/***/ function(module, exports, __webpack_require__) { ( function ( M, $ ) { - var browser; + + var Icon = __webpack_require__( 2 ); /** - * Memoize a class method. Caches the result of the method based on the - * arguments. Instances do not share a cache. - * @ignore - * @param {Function} method Method to be memoized - * @return {Function} + * A set of shared icons. + * + * Factory methods are used to keep separate features that use the same icons + * from accidentally manipulating one another's DOM when calling methods like + * `remove`. + * + * @class icons + * @singleton + * @uses Icon */ - function memoize( method ) { + module.exports = { + /** - * Memoized version of the method - * @ignore - * @return {Function} + * Gets a spinner icon. + * + * The icon should be used to inform the user that the front-end is + * communicating with the back-end. + * + * @param {Object} [options] See `Icon` for more details + * @return {Icon} */ - var memoized = function () { - var cache = this[ '__cache' + memoized.cacheId ] || - ( this[ '__cache' + memoized.cacheId ] = {} ), - key = [].join.call( arguments, '|' ); - if ( cache.hasOwnProperty( key ) ) { - return cache[ key ]; - } - return ( cache[ key ] = method.apply( this, arguments ) ); - }; - memoized.cacheId = Date.now().toString() + Math.random().toString(); - return memoized; - } + spinner: function ( options ) { + options = options || {}; - /** - * Representation of user's current browser - * @class Browser - * @param {string} ua the user agent of the current browser - * @param {jQuery.Object} $container an element to associate with the Browser object - */ - function Browser( ua, $container ) { - this.userAgent = ua; - this.$el = $container; - if ( this.isAndroid2() ) { - this.lockViewport(); + return new Icon( $.extend( options, { + name: 'spinner', + label: mw.msg( 'mobile-frontend-loading-message' ), + additionalClassNames: 'spinner loading' + } ) ); } - this._fixIosLandscapeBug(); - } - - Browser.prototype = { - /** - * When rotating to landscape stop page zooming on ios 4 and 5. - * @private - */ - _fixIosLandscapeBug: function () { - var self = this, - viewport = this.$el.find( 'meta[name="viewport"]' )[0]; - - // see http://adactio.com/journal/4470/ (fixed in ios 6) - if ( viewport && ( this.isIos( 4 ) || this.isIos( 5 ) ) ) { - this.lockViewport(); - document.addEventListener( 'gesturestart', function () { - self.lockViewport(); - }, false ); - } - }, - /** - * Returns whether the current browser is an ios device. - * FIXME: jquery.client does not support iPad detection so we cannot use it. - * @param {number} [version] integer describing a specific version you want to test against. - * @return {boolean} - */ - isIos: memoize( function ( version ) { - var ua = this.userAgent, - ios = /ipad|iphone|ipod/i.test( ua ); - - if ( ios && version ) { - switch ( version ) { - case 8: - // Test UA for iOS8. Or for simulator look for Version 8 - // In the iOS simulator the OS is the host machine OS version - // This makes testing in iOS8 simulator work as expected - return /OS 8_/.test( ua ) || /Version\/8/.test( ua ); - case 4: - return /OS 4_/.test( ua ); - case 5: - return /OS 5_/.test( ua ); - default: - return false; - } - } else { - return ios; - } - } ), - /** - * Locks the viewport so that pinch zooming is disabled - */ - lockViewport: function () { - if ( this.$el ) { - this.$el.find( 'meta[name="viewport"]' ) - .attr( 'content', 'initial-scale=1.0, maximum-scale=1.0, user-scalable=no' ); - } - }, - /** - * Determine if a device is Android 2. - * @method - * @return {boolean} - */ - isAndroid2: memoize( function () { - return /Android 2/.test( this.userAgent ); - } ), - /** - * Determine if a device has a widescreen. - * @method - * @return {boolean} - */ - isWideScreen: memoize( function () { - var val = parseInt( mw.config.get( 'wgMFDeviceWidthTablet' ), 10 ); - // Check portrait and landscape mode to be consistent - return window.innerWidth >= val || window.innerHeight >= val; - } ), - /** - * Checks browser support for a given CSS property - * @param {string} [property] the name of the property being tested - * @return {boolean} - */ - supportsCSSProperty: memoize( function ( property ) { - var elem = document.createElement( 'foo' ); - - // We only test webkit because that's the only prefix needed at the moment by - // supportsAnimations. If usage of supportsCSSProperty is expanded, the list of prefixes - // will need to be as well - return elem.style[ property ] !== undefined || - elem.style[ 'webkit' + property.charAt( 0 ).toUpperCase() + property.slice( 1 ) ] !== undefined; - } ), - /** - * Checks browser support for CSS transforms, transitions - * and CSS animation. - * Currently assumes support for the latter 2 in the case of the - * former. - * See http://stackoverflow.com/a/12621264/365238 - * - * @return {boolean} - */ - supportsAnimations: memoize( function () { - // don't trust Android 2.x, really - // animations cause textareas to misbehave on it - // (http://stackoverflow.com/a/5734984/365238) - if ( this.isAndroid2() ) { - return false; - } - - return this.supportsCSSProperty( 'animationName' ) && - this.supportsCSSProperty( 'transform' ) && - this.supportsCSSProperty( 'transition' ); - } ), - /** - * Whether touchstart and other touch events are supported by the current browser. - * - * @method - * @return {boolean} - */ - supportsTouchEvents: memoize( function () { - return 'ontouchstart' in window; - } ), - /** - * Detect if browser supports geolocation - * @method - * @return {boolean} - */ - supportsGeoLocation: memoize( function () { - return 'geolocation' in navigator; - } ), - /** - * Detect if we support file input uploads - * @return {boolean} - */ - supportsFileUploads: memoize( function () { - var browserSupported; - // If already calculated, just return it - if ( this._fileUploads !== undefined ) { - return this._fileUploads; - } - - // deal with known false positives which don't support file input (bug 47374) - if ( this.userAgent.match( /Windows Phone (OS 7|8.0)/ ) ) { - this._fileUploads = false; - } else { - browserSupported = ( - typeof FileReader !== 'undefined' && - typeof FormData !== 'undefined' && - // Firefox OS 1.0 turns <input type="file"> into <input type="text"> - ( $( '<input type="file"/>' ).prop( 'type' ) === 'file' ) - ); - this._fileUploads = browserSupported && - !mw.config.get( 'wgImagesDisabled', false ); - } - return this._fileUploads; - } ) }; - /** - * @static - * @return {Browser} - */ - Browser.getSingleton = function () { - if ( !browser ) { - browser = new Browser( window.navigator.userAgent, $( 'html' ) ); - } - return browser; - }; - - module.exports = Browser; }( mw.mobileFrontend, jQuery ) ); @@ -1528,6 +1358,221 @@ /* 8 */ /***/ function(module, exports) { + ( function ( M, $ ) { + var browser; + + /** + * Memoize a class method. Caches the result of the method based on the + * arguments. Instances do not share a cache. + * @ignore + * @param {Function} method Method to be memoized + * @return {Function} + */ + function memoize( method ) { + /** + * Memoized version of the method + * @ignore + * @return {Function} + */ + var memoized = function () { + var cache = this[ '__cache' + memoized.cacheId ] || + ( this[ '__cache' + memoized.cacheId ] = {} ), + key = [].join.call( arguments, '|' ); + if ( cache.hasOwnProperty( key ) ) { + return cache[ key ]; + } + return ( cache[ key ] = method.apply( this, arguments ) ); + }; + memoized.cacheId = Date.now().toString() + Math.random().toString(); + return memoized; + } + + /** + * Representation of user's current browser + * @class Browser + * @param {string} ua the user agent of the current browser + * @param {jQuery.Object} $container an element to associate with the Browser object + */ + function Browser( ua, $container ) { + this.userAgent = ua; + this.$el = $container; + if ( this.isAndroid2() ) { + this.lockViewport(); + } + this._fixIosLandscapeBug(); + } + + Browser.prototype = { + /** + * When rotating to landscape stop page zooming on ios 4 and 5. + * @private + */ + _fixIosLandscapeBug: function () { + var self = this, + viewport = this.$el.find( 'meta[name="viewport"]' )[0]; + + // see http://adactio.com/journal/4470/ (fixed in ios 6) + if ( viewport && ( this.isIos( 4 ) || this.isIos( 5 ) ) ) { + this.lockViewport(); + document.addEventListener( 'gesturestart', function () { + self.lockViewport(); + }, false ); + } + }, + /** + * Returns whether the current browser is an ios device. + * FIXME: jquery.client does not support iPad detection so we cannot use it. + * @param {number} [version] integer describing a specific version you want to test against. + * @return {boolean} + */ + isIos: memoize( function ( version ) { + var ua = this.userAgent, + ios = /ipad|iphone|ipod/i.test( ua ); + + if ( ios && version ) { + switch ( version ) { + case 8: + // Test UA for iOS8. Or for simulator look for Version 8 + // In the iOS simulator the OS is the host machine OS version + // This makes testing in iOS8 simulator work as expected + return /OS 8_/.test( ua ) || /Version\/8/.test( ua ); + case 4: + return /OS 4_/.test( ua ); + case 5: + return /OS 5_/.test( ua ); + default: + return false; + } + } else { + return ios; + } + } ), + /** + * Locks the viewport so that pinch zooming is disabled + */ + lockViewport: function () { + if ( this.$el ) { + this.$el.find( 'meta[name="viewport"]' ) + .attr( 'content', 'initial-scale=1.0, maximum-scale=1.0, user-scalable=no' ); + } + }, + /** + * Determine if a device is Android 2. + * @method + * @return {boolean} + */ + isAndroid2: memoize( function () { + return /Android 2/.test( this.userAgent ); + } ), + /** + * Determine if a device has a widescreen. + * @method + * @return {boolean} + */ + isWideScreen: memoize( function () { + var val = parseInt( mw.config.get( 'wgMFDeviceWidthTablet' ), 10 ); + // Check portrait and landscape mode to be consistent + return window.innerWidth >= val || window.innerHeight >= val; + } ), + /** + * Checks browser support for a given CSS property + * @param {string} [property] the name of the property being tested + * @return {boolean} + */ + supportsCSSProperty: memoize( function ( property ) { + var elem = document.createElement( 'foo' ); + + // We only test webkit because that's the only prefix needed at the moment by + // supportsAnimations. If usage of supportsCSSProperty is expanded, the list of prefixes + // will need to be as well + return elem.style[ property ] !== undefined || + elem.style[ 'webkit' + property.charAt( 0 ).toUpperCase() + property.slice( 1 ) ] !== undefined; + } ), + /** + * Checks browser support for CSS transforms, transitions + * and CSS animation. + * Currently assumes support for the latter 2 in the case of the + * former. + * See http://stackoverflow.com/a/12621264/365238 + * + * @return {boolean} + */ + supportsAnimations: memoize( function () { + // don't trust Android 2.x, really + // animations cause textareas to misbehave on it + // (http://stackoverflow.com/a/5734984/365238) + if ( this.isAndroid2() ) { + return false; + } + + return this.supportsCSSProperty( 'animationName' ) && + this.supportsCSSProperty( 'transform' ) && + this.supportsCSSProperty( 'transition' ); + } ), + /** + * Whether touchstart and other touch events are supported by the current browser. + * + * @method + * @return {boolean} + */ + supportsTouchEvents: memoize( function () { + return 'ontouchstart' in window; + } ), + /** + * Detect if browser supports geolocation + * @method + * @return {boolean} + */ + supportsGeoLocation: memoize( function () { + return 'geolocation' in navigator; + } ), + /** + * Detect if we support file input uploads + * @return {boolean} + */ + supportsFileUploads: memoize( function () { + var browserSupported; + // If already calculated, just return it + if ( this._fileUploads !== undefined ) { + return this._fileUploads; + } + + // deal with known false positives which don't support file input (bug 47374) + if ( this.userAgent.match( /Windows Phone (OS 7|8.0)/ ) ) { + this._fileUploads = false; + } else { + browserSupported = ( + typeof FileReader !== 'undefined' && + typeof FormData !== 'undefined' && + // Firefox OS 1.0 turns <input type="file"> into <input type="text"> + ( $( '<input type="file"/>' ).prop( 'type' ) === 'file' ) + ); + this._fileUploads = browserSupported && + !mw.config.get( 'wgImagesDisabled', false ); + } + return this._fileUploads; + } ) + }; + + /** + * @static + * @return {Browser} + */ + Browser.getSingleton = function () { + if ( !browser ) { + browser = new Browser( window.navigator.userAgent, $( 'html' ) ); + } + return browser; + }; + + module.exports = Browser; + }( mw.mobileFrontend, jQuery ) ); + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + var util; /** diff --git a/resources/mobile.gallery/PhotoList.js b/resources/mobile.gallery/PhotoList.js index fa7f5c6..436a937 100644 --- a/resources/mobile.gallery/PhotoList.js +++ b/resources/mobile.gallery/PhotoList.js @@ -1,5 +1,5 @@ ( function ( M, $ ) { - var icons = M.require( 'mobile.startup/icons' ), + var icons = mw.mf.icons, PhotoListGateway = M.require( 'mobile.gallery/PhotoListGateway' ), PhotoItem = M.require( 'mobile.gallery/PhotoItem' ), InfiniteScroll = M.require( 'mobile.infiniteScroll/InfiniteScroll' ), diff --git a/resources/mobile.nearby/Nearby.js b/resources/mobile.nearby/Nearby.js index 156d0e7..8778c7d 100644 --- a/resources/mobile.nearby/Nearby.js +++ b/resources/mobile.nearby/Nearby.js @@ -3,7 +3,7 @@ NearbyGateway = M.require( 'mobile.nearby/NearbyGateway' ), WatchstarPageList = M.require( 'mobile.pagelist.scripts/WatchstarPageList' ), browser = mw.mf.Browser.getSingleton(), - icons = M.require( 'mobile.startup/icons' ); + icons = mw.mf.icons; /** * List of nearby pages diff --git a/resources/mobile.overlays/Overlay.js b/resources/mobile.overlays/Overlay.js index 784fe86..4b2c797 100644 --- a/resources/mobile.overlays/Overlay.js +++ b/resources/mobile.overlays/Overlay.js @@ -4,7 +4,7 @@ Icon = mw.mf.Icon, Button = M.require( 'mobile.startup/Button' ), Anchor = M.require( 'mobile.startup/Anchor' ), - icons = M.require( 'mobile.startup/icons' ), + icons = mw.mf.icons, browser = mw.mf.Browser.getSingleton(), $window = $( window ); diff --git a/resources/mobile.references/ReferencesDrawer.js b/resources/mobile.references/ReferencesDrawer.js index 9382c83..45a2d03 100644 --- a/resources/mobile.references/ReferencesDrawer.js +++ b/resources/mobile.references/ReferencesDrawer.js @@ -1,6 +1,6 @@ ( function ( M, $ ) { var Drawer = M.require( 'mobile.drawers/Drawer' ), - icons = M.require( 'mobile.startup/icons' ), + icons = mw.mf.icons, Icon = mw.mf.Icon; /** diff --git a/resources/mobile.startup/Section.js b/resources/mobile.startup/Section.js index d0eb419..984be5d 100644 --- a/resources/mobile.startup/Section.js +++ b/resources/mobile.startup/Section.js @@ -1,7 +1,7 @@ ( function ( M, $ ) { var View = mw.mf.View, - icons = M.require( 'mobile.startup/icons' ); + icons = mw.mf.icons; /** * Builds a section of a page diff --git a/resources/mobile.startup/Skin.js b/resources/mobile.startup/Skin.js index 37205d5..7b4579d 100644 --- a/resources/mobile.startup/Skin.js +++ b/resources/mobile.startup/Skin.js @@ -2,7 +2,7 @@ var browser = mw.mf.Browser.getSingleton(), View = mw.mf.View, - icons = M.require( 'mobile.startup/icons' ); + icons = mw.mf.icons; /** * Get the id of the section $el belongs to. diff --git a/resources/skins.minerva.notifications/init.js b/resources/skins.minerva.notifications/init.js index 4b285f1..48e650f 100644 --- a/resources/skins.minerva.notifications/init.js +++ b/resources/skins.minerva.notifications/init.js @@ -7,7 +7,7 @@ $btn = $( '#secondary-button.user-button' ).parent(), router = require( 'mediawiki.router' ), overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ), - icons = M.require( 'mobile.startup/icons' ); + icons = mw.mf.icons; /** * Loads a ResourceLoader module script. Shows ajax loader whilst loading. -- To view, visit https://gerrit.wikimedia.org/r/332927 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7ed4985786fd3fb2546e0d7b5abb8972d8565337 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: mfui Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits