jenkins-bot has submitted this change and it was merged.
Change subject: Rename View#initialize to View#postRender
......................................................................
Rename View#initialize to View#postRender
View#initialize no longer was a constructor and the name was extremely
misleading. Renamed to #postRender as it runs every time the View is
rendered. Also, readded proper #initialize for one time initializations.
Change-Id: I979a36e6bc3246d44e9ce8d17dcd10f3ec02a1a0
---
M javascripts/common/Drawer.js
M javascripts/common/Overlay.js
M javascripts/common/mf-view.js
M javascripts/modules/editor/EditorOverlay.js
M javascripts/modules/editor/PreviewOverlay.js
M javascripts/modules/mf-languages.js
M javascripts/modules/mf-photo.js
M javascripts/modules/search-2.js
M javascripts/modules/talk.js
M javascripts/specials/nearby-watchstar.js
M javascripts/specials/nearby.js
M javascripts/specials/overlays/preview.js
M javascripts/widgets/carousel.js
M tests/javascripts/common/test_mf-view.js
14 files changed, 65 insertions(+), 47 deletions(-)
Approvals:
Jdlrobson: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/common/Drawer.js b/javascripts/common/Drawer.js
index 858f826..67ebf89 100644
--- a/javascripts/common/Drawer.js
+++ b/javascripts/common/Drawer.js
@@ -7,7 +7,7 @@
},
className: 'drawer position-fixed',
- initialize: function() {
+ postRender: function() {
var self = this;
this.$( '.close' ).click( function( ev ) {
ev.preventDefault();
diff --git a/javascripts/common/Overlay.js b/javascripts/common/Overlay.js
index 2ccd89e..21f3df6 100644
--- a/javascripts/common/Overlay.js
+++ b/javascripts/common/Overlay.js
@@ -10,9 +10,11 @@
template: M.template.get( 'overlay' ),
className: 'mw-mf-overlay',
initialize: function( options ) {
- var self = this;
this.parent = options.parent;
this.isOpened = false;
+ },
+ postRender: function() {
+ var self = this;
this.$( '.cancel,.confirm' ).click( function( ev ) {
ev.preventDefault();
self.hide();
diff --git a/javascripts/common/mf-view.js b/javascripts/common/mf-view.js
index 5214acd..03c906f 100644
--- a/javascripts/common/mf-view.js
+++ b/javascripts/common/mf-view.js
@@ -65,27 +65,35 @@
}
this.options = options;
+ this.initialize( options );
this.render( options );
}
View.prototype = new EventEmitter();
+ // FIXME: make Api and View inherit from an abstract Class object
/**
- * Function called before the view is constructed. Can be redefined in
+ * Constructor that can be overriden.
+ *
+ * @param {Object} options Object passed to the constructor.
+ */
+ View.prototype.initialize = function() {};
+
+ /**
+ * Function called before the view is rendered. Can be redefined in
* objects that extend View.
*
* @param {Object} options Object passed to the constructor.
*/
View.prototype.preRender = function() {};
- // FIXME: rename to postRender
/**
- * Function called after the view is constructed. Can be redefined in
+ * Function called after the view is rendered. Can be redefined in
* objects that extend View.
*
* @param {Object} options Object passed to the constructor.
*/
- View.prototype.initialize = function() {};
+ View.prototype.postRender = function() {};
/**
* Fill this.$el with template rendered using data if template is set.
@@ -98,7 +106,7 @@
if ( this.template ) {
this.$el.html( this.template.render( data ) );
}
- this.initialize( data );
+ this.postRender( data );
};
/**
diff --git a/javascripts/modules/editor/EditorOverlay.js
b/javascripts/modules/editor/EditorOverlay.js
index 289e6b5..dc71101 100644
--- a/javascripts/modules/editor/EditorOverlay.js
+++ b/javascripts/modules/editor/EditorOverlay.js
@@ -40,10 +40,14 @@
},
initialize: function( options ) {
+ this.api = new EditorApi( { title: options.title,
isNew: options.isNew } );
+ this.sectionCount = options.sectionCount;
+ },
+
+ postRender: function( options ) {
var self = this;
this._super( options );
- this.api = new EditorApi( { title: options.title,
isNew: options.isNew } );
this.$( '.preview' ).on( 'click', function() {
var overlay = new PreviewOverlay( {
parent: self,
@@ -53,7 +57,6 @@
self.previewClicked = true;
overlay.show();
} );
- this.sectionCount = options.sectionCount;
this.$spinner = this.$( '.spinner' );
this.$content = this.$( 'textarea' ).
// can't use $.proxy because self.section
changes
diff --git a/javascripts/modules/editor/PreviewOverlay.js
b/javascripts/modules/editor/PreviewOverlay.js
index f7c8178..7c321b5 100644
--- a/javascripts/modules/editor/PreviewOverlay.js
+++ b/javascripts/modules/editor/PreviewOverlay.js
@@ -13,7 +13,7 @@
template: M.template.get( 'overlays/editPreview' ),
className: 'mw-mf-overlay editor-overlay',
- initialize: function( options ) {
+ postRender: function( options ) {
this._super( options );
var self = this,
d = $.Deferred(),
diff --git a/javascripts/modules/mf-languages.js
b/javascripts/modules/mf-languages.js
index f42479b..dd8be24 100644
--- a/javascripts/modules/mf-languages.js
+++ b/javascripts/modules/mf-languages.js
@@ -42,7 +42,7 @@
LanguageOverlay = Overlay.extend( {
template: M.template.get( 'overlays/languages' ),
- initialize: function( options ) {
+ postRender: function( options ) {
var $footer, $lists;
this._super( options );
diff --git a/javascripts/modules/mf-photo.js b/javascripts/modules/mf-photo.js
index dbfbf59..7c0b84f 100644
--- a/javascripts/modules/mf-photo.js
+++ b/javascripts/modules/mf-photo.js
@@ -259,9 +259,20 @@
template: M.template.get( 'photoNag' ),
- initialize: function( options ) {
- var self = this, $checkboxes = this.$(
'input[type=checkbox]' ),
- learnMoreOverlay;
+ initialize: function() {
+ this.learnMoreOverlay = new LearnMoreOverlay( {
+ parent: this,
+ heading: mw.msg(
'mobile-frontend-photo-nag-learn-more-heading' ),
+ bulletPoints: [
+ mw.msg(
'mobile-frontend-photo-nag-learn-more-1' ),
+ mw.msg(
'mobile-frontend-photo-nag-learn-more-2' ),
+ mw.msg(
'mobile-frontend-photo-nag-learn-more-3' )
+ ]
+ } );
+ },
+
+ postRender: function( options ) {
+ var self = this, $checkboxes = this.$(
'input[type=checkbox]' );
this._super( options );
@@ -275,16 +286,7 @@
$checkbox.parent().addClass( 'active' );
}
- learnMoreOverlay = new LearnMoreOverlay( {
- parent: self,
- heading: mw.msg(
'mobile-frontend-photo-nag-learn-more-heading' ),
- bulletPoints: [
- mw.msg(
'mobile-frontend-photo-nag-learn-more-1' ),
- mw.msg(
'mobile-frontend-photo-nag-learn-more-2' ),
- mw.msg(
'mobile-frontend-photo-nag-learn-more-3' )
- ]
- } );
- self.$( 'li button' ).on( 'click', $.proxy(
learnMoreOverlay, 'show' ) );
+ self.$( 'li button' ).on( 'click', $.proxy(
self.learnMoreOverlay, 'show' ) );
disable( $checkboxes.not( ':first' ) );
enable( $checkboxes.eq( 0 ) );
@@ -323,10 +325,13 @@
template: M.template.get( 'photoUploadPreview' ),
initialize: function( options ) {
+ this.log = options.log;
+ },
+
+ postRender: function() {
var self = this,
$overlay, $description, $submitButton;
- this.log = options.log;
this.overlay = new Overlay( {
content: $( '<div>' ).html( this.$el ).html()
} );
@@ -402,7 +407,7 @@
'<p class="cancel">{{{cancelMessage}}}</p>'
),
- initialize: function( options ) {
+ postRender: function( options ) {
var self = this, longMessage = false;
this.$( 'a' ).on( 'click', function() {
@@ -487,10 +492,11 @@
PhotoUploader = View.extend( {
initialize: function( options ) {
- var self = this, $input = this.$( 'input' ), ctaDrawer;
-
- this.options = options;
this.log = getLog( options.funnel );
+ },
+
+ postRender: function() {
+ var self = this, $input = this.$( 'input' ), ctaDrawer;
// show CTA instead if not logged in
if ( !M.isLoggedIn() ) {
diff --git a/javascripts/modules/search-2.js b/javascripts/modules/search-2.js
index 5703c13..5d0c2c6 100644
--- a/javascripts/modules/search-2.js
+++ b/javascripts/modules/search-2.js
@@ -2,8 +2,7 @@
var Overlay = M.require( 'Overlay' ), SearchOverlay,
api = M.require( 'api' ),
- searchOverlay,
- overlayInitialize = Overlay.prototype.initialize;
+ searchOverlay;
/**
* Escapes regular expression wildcards (metacharacters) by adding a \\ prefix
@@ -38,10 +37,11 @@
noresults: mw.msg( 'mobile-frontend-search-noresults' ),
action: mw.config.get( 'wgScript' )
},
- initialize: function() {
- overlayInitialize.apply( this, arguments );
+ postRender: function( options ) {
var self = this;
+ this._super( options );
+
this.data = this.defaults;
this.$( 'input' ).on( 'keyup', function( ev ) {
diff --git a/javascripts/modules/talk.js b/javascripts/modules/talk.js
index 66ece3d..a4c861a 100644
--- a/javascripts/modules/talk.js
+++ b/javascripts/modules/talk.js
@@ -15,13 +15,12 @@
},
template: M.template.get( 'overlays/talkSectionAdd' ),
initialize: function( options ) {
- var self = this;
- this._super( options );
this.talkOverlay = options.parent;
this.title = 'Talk:' + mw.config.get( 'wgTitle'
);
- this.$( 'button.confirm-save' ).click(
function() {
- self.save();
- } );
+ },
+ postRender: function( options ) {
+ this._super( options );
+ this.$( 'button.confirm-save' ).click( $.proxy(
this, 'save' ) );
},
save: function() {
var $subject = this.$( 'input' ),
@@ -77,7 +76,7 @@
options.explanation = explanation;
this._super( options );
},
- initialize: function( options ) {
+ postRender: function( options ) {
var self = this,
$add = this.$( 'button.add' ),
page = options.page;
diff --git a/javascripts/specials/nearby-watchstar.js
b/javascripts/specials/nearby-watchstar.js
index 2067217..c559a72 100644
--- a/javascripts/specials/nearby-watchstar.js
+++ b/javascripts/specials/nearby-watchstar.js
@@ -2,7 +2,7 @@
var nearby = M.require( 'nearby' ),
watchstar = M.require( 'watchstar' );
-nearby.getOverlay().on( 'postRender', function( $el ) {
+nearby.getOverlay().on( 'rendered', function( $el ) {
watchstar.initWatchListIconList( $el.find( 'ul' ) );
} );
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index 3233584..a6cd810 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -75,14 +75,14 @@
window.location.hash = '#' + $(
ev.currentTarget ).attr( 'name' );
window.location = $( ev.currentTarget ).attr(
'href' );
},
- initialize: function() {
+ postRender: function() {
var self = this;
this.$( 'a' ).on( 'mousedown', function( ev ) {
// name funnel for watchlists to catch
subsequent uploads
$.cookie( 'mwUploadsFunnel', 'nearby',
{ expires: new Date( new Date().getTime() + 60000) } );
self.openPage( ev );
} );
- self.emit( 'postRender', this.$el );
+ self.emit( 'rendered', this.$el );
}
} ),
pendingQuery = false, btn, menu;
diff --git a/javascripts/specials/overlays/preview.js
b/javascripts/specials/overlays/preview.js
index 3ea30ff..7589fc9 100644
--- a/javascripts/specials/overlays/preview.js
+++ b/javascripts/specials/overlays/preview.js
@@ -15,7 +15,7 @@
options.url = M.history.getArticleUrl(
options.heading );
options.readMoreLink = mw.msg(
'mobile-frontend-nearby-link' );
},
- initialize: function( options ) {
+ postRender: function( options ) {
var $preview, nodes;
this._super( options );
$preview = this.$( '.preview' );
diff --git a/javascripts/widgets/carousel.js b/javascripts/widgets/carousel.js
index 8d4eae5..f54e5a6 100644
--- a/javascripts/widgets/carousel.js
+++ b/javascripts/widgets/carousel.js
@@ -4,7 +4,7 @@
Carousel = View.extend( {
template: M.template.get( 'specials/uploads/carousel' ),
- initialize: function() {
+ postRender: function() {
var self = this, $pages;
$pages = this.$( '.page' );
this.page = 0;
diff --git a/tests/javascripts/common/test_mf-view.js
b/tests/javascripts/common/test_mf-view.js
index e3b2d91..95cfa7b 100644
--- a/tests/javascripts/common/test_mf-view.js
+++ b/tests/javascripts/common/test_mf-view.js
@@ -78,16 +78,16 @@
strictEqual( view.$el.html(), '<p>hello</p>', 'manipulate template
data' );
} );
-QUnit.test( 'View#initialize', 1, function() {
+QUnit.test( 'View#postRender', 1, function() {
var ChildView, view, spy = sinon.spy();
ChildView = View.extend( {
- initialize: function() {
+ postRender: function() {
spy();
}
} );
view = new ChildView();
- ok( spy.calledOnce, 'invoke initialize' );
+ ok( spy.calledOnce, 'invoke postRender' );
} );
}( mw.mobileFrontend, jQuery) );
--
To view, visit https://gerrit.wikimedia.org/r/67217
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I979a36e6bc3246d44e9ce8d17dcd10f3ec02a1a0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits