Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/202053
Change subject: Hygiene: ContentOverlay is in mobile.overlays module ...................................................................... Hygiene: ContentOverlay is in mobile.overlays module Based on reuse in Gather: Various methods on the content overlay shouldn't be there. Move those to PageActionOverlay Update documentation Change-Id: I67f899554f69f657c3c48a12e3261af71323b639 --- M includes/Resources.php A javascripts/ContentOverlay.js D javascripts/modules/tutorials/ContentOverlay.js M javascripts/modules/tutorials/PageActionOverlay.js 4 files changed, 101 insertions(+), 98 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/53/202053/1 diff --git a/includes/Resources.php b/includes/Resources.php index 98e83f0..a11053d 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -783,6 +783,7 @@ ), 'scripts' => array( 'javascripts/Overlay.js', + 'javascripts/ContentOverlay.js', 'javascripts/LoadingOverlay.js', 'javascripts/moduleLoader.js', ), @@ -933,7 +934,6 @@ 'less/modules/tutorials.less', ), 'scripts' => array( - 'javascripts/modules/tutorials/ContentOverlay.js', 'javascripts/modules/tutorials/PageActionOverlay.js', ), 'templates' => array( diff --git a/javascripts/ContentOverlay.js b/javascripts/ContentOverlay.js new file mode 100644 index 0000000..e34c10f --- /dev/null +++ b/javascripts/ContentOverlay.js @@ -0,0 +1,34 @@ +( function ( M, $ ) { + + var ContentOverlay, + skin = M.require( 'skin' ), + Overlay = M.require( 'Overlay' ); + + /** + * An {@link Overlay} that is loaded as a modal within the content and that does + * not take up the full screen. + * @class ContentOverlay + * @extends Overlay + */ + ContentOverlay = Overlay.extend( { + /** @inheritdoc */ + templatePartials: {}, + className: 'overlay content-overlay', + /** + * @inheritdoc + */ + fullScreen: false, + /** + * @inheritdoc + */ + closeOnContentTap: true, + /** + * @inheritdoc + */ + appendToElement: '#mw-mf-page-center' + } ); + // FIXME: Here for backwards compatibility. Remove when fully deprecated + M.define( 'modules/tutorials/ContentOverlay', ContentOverlay ); + M.define( 'ContentOverlay', ContentOverlay ); + +}( mw.mobileFrontend, jQuery ) ); diff --git a/javascripts/modules/tutorials/ContentOverlay.js b/javascripts/modules/tutorials/ContentOverlay.js deleted file mode 100644 index 754ac76..0000000 --- a/javascripts/modules/tutorials/ContentOverlay.js +++ /dev/null @@ -1,96 +0,0 @@ -( function ( M, $ ) { - - var ContentOverlay, - context = M.require( 'context' ), - skin = M.require( 'skin' ), - Overlay = M.require( 'Overlay' ); - - /** - * An {@link Overlay} that points at an element on the page. - * @class ContentOverlay - * @extends Overlay - */ - ContentOverlay = Overlay.extend( { - /** @inheritdoc */ - templatePartials: {}, - className: 'overlay content-overlay', - /** - * @inheritdoc - */ - fullScreen: false, - /** - * @inheritdoc - */ - closeOnContentTap: true, - /** - * @inheritdoc - */ - appendToElement: '#mw-mf-page-center', - /** @inheritdoc */ - postRender: function ( options ) { - var $target, - self = this; - - Overlay.prototype.postRender.apply( this, arguments ); - if ( options.target ) { - $target = $( options.target ); - // Ensure we position the overlay correctly but do not show the arrow - self._position( $target ); - this.addPointerArrow( $target ); - } - }, - /** - * Refreshes the pointer arrow. - * @method - * @param {String} target jQuery selector - */ - refreshPointerArrow: function ( target ) { - this.$pointer.remove(); - this.addPointerArrow( $( target ) ); - }, - /** - * Position the overlay under a specified element - * @private - * @param {jQuery.Object} $pa An element that should be pointed at by the overlay - */ - _position: function ( $pa ) { - var paOffset = $pa.offset(), - h = $pa.outerHeight( true ), - y = paOffset.top; - - // We only care about this in a border-box world which is disabled in alpha. - if ( !context.isAlphaGroupMember() ) { - y += h; - } - - this.$el.css( 'top', y ); - }, - /** - * Position overlay and add pointer arrow that points at specified element - * @method - * @param {jQuery.Object} $pa An element that should be pointed at by the overlay - */ - addPointerArrow: function ( $pa ) { - var tb = 'solid 10px transparent', - paOffset = $pa.offset(), - overlayOffset = this.$el.offset(), - center = $pa.width() / 2; - - this._position( $pa ); - this.$pointer = $( '<div>' ).css( { - 'border-bottom': 'solid 10px #2E76FF', - 'border-right': tb, - 'border-left': tb, - position: 'absolute', - top: -10, - // Add half of the element width and subtract 10px for half of the arrow - // remove the left offset of the overlay as margin auto may be applied to it - left: paOffset.left + center - 10 - overlayOffset.left - } ).appendTo( this.$el ); - skin.on( 'changed', $.proxy( this, 'refreshPointerArrow', this.options.target ) ); - M.on( 'resize', $.proxy( this, 'refreshPointerArrow', this.options.target ) ); - } - } ); - M.define( 'modules/tutorials/ContentOverlay', ContentOverlay ); - -}( mw.mobileFrontend, jQuery ) ); diff --git a/javascripts/modules/tutorials/PageActionOverlay.js b/javascripts/modules/tutorials/PageActionOverlay.js index 6feef5c..b02c0e4 100644 --- a/javascripts/modules/tutorials/PageActionOverlay.js +++ b/javascripts/modules/tutorials/PageActionOverlay.js @@ -1,5 +1,6 @@ ( function ( M ) { - var ContentOverlay = M.require( 'modules/tutorials/ContentOverlay' ), + var ContentOverlay = M.require( 'ContentOverlay' ), + context = M.require( 'context' ), PageActionOverlay; /** @@ -23,6 +24,70 @@ */ events: { 'click .cancel': 'hide' + }, + /** @inheritdoc */ + postRender: function ( options ) { + var $target, + self = this; + + ContentOverlay.prototype.postRender.apply( this, arguments ); + if ( options.target ) { + $target = $( options.target ); + // Ensure we position the overlay correctly but do not show the arrow + self._position( $target ); + this.addPointerArrow( $target ); + } + }, + /** + * Refreshes the pointer arrow. + * @method + * @param {String} target jQuery selector + */ + refreshPointerArrow: function ( target ) { + this.$pointer.remove(); + this.addPointerArrow( $( target ) ); + }, + /** + * Position the overlay under a specified element + * @private + * @param {jQuery.Object} $pa An element that should be pointed at by the overlay + */ + _position: function ( $pa ) { + var paOffset = $pa.offset(), + h = $pa.outerHeight( true ), + y = paOffset.top; + + // We only care about this in a border-box world which is disabled in alpha. + if ( !context.isAlphaGroupMember() ) { + y += h; + } + + this.$el.css( 'top', y ); + }, + /** + * Position overlay and add pointer arrow that points at specified element + * @method + * @param {jQuery.Object} $pa An element that should be pointed at by the overlay + */ + addPointerArrow: function ( $pa ) { + var tb = 'solid 10px transparent', + paOffset = $pa.offset(), + overlayOffset = this.$el.offset(), + center = $pa.width() / 2; + + this._position( $pa ); + this.$pointer = $( '<div>' ).css( { + 'border-bottom': 'solid 10px #2E76FF', + 'border-right': tb, + 'border-left': tb, + position: 'absolute', + top: -10, + // Add half of the element width and subtract 10px for half of the arrow + // remove the left offset of the overlay as margin auto may be applied to it + left: paOffset.left + center - 10 - overlayOffset.left + } ).appendTo( this.$el ); + skin.on( 'changed', $.proxy( this, 'refreshPointerArrow', this.options.target ) ); + M.on( 'resize', $.proxy( this, 'refreshPointerArrow', this.options.target ) ); } } ); -- To view, visit https://gerrit.wikimedia.org/r/202053 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I67f899554f69f657c3c48a12e3261af71323b639 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend 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