jenkins-bot has submitted this change and it was merged.
Change subject: Make View's defaults inheritable and extendable
......................................................................
Make View's defaults inheritable and extendable
Now when children of View define the `defaults` property, properties of
`defaults` of the parent are preserved if the child doesn't override
them.
Previous behaviour led to missing close button message in most overlays,
which suggests that extending defaults in this new way may be more
intuitive, if slightly more magical.
Change-Id: Id6bb5a89dea33200ea9cf35535644bde54d8820e
---
M javascripts/common/Class.js
M javascripts/common/CtaDrawer.js
M javascripts/common/View.js
M javascripts/modules/editor/EditorOverlay.js
M javascripts/modules/mediaViewer.js
M javascripts/modules/talk/TalkSectionOverlay.js
M javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js
M tests/javascripts/common/test_Class.js
M tests/javascripts/common/test_View.js
9 files changed, 29 insertions(+), 8 deletions(-)
Approvals:
JGonera: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/common/Class.js b/javascripts/common/Class.js
index cc5e604..27adfa5 100644
--- a/javascripts/common/Class.js
+++ b/javascripts/common/Class.js
@@ -9,6 +9,7 @@
function Surrogate() {}
Surrogate.prototype = Parent.prototype;
Child.prototype = new Surrogate();
+ Child.prototype._parent = Parent.prototype;
// http://ejohn.org/blog/simple-javascript-inheritance
// Copy the properties over onto the new prototype
diff --git a/javascripts/common/CtaDrawer.js b/javascripts/common/CtaDrawer.js
index 37ce407..ee336ce 100644
--- a/javascripts/common/CtaDrawer.js
+++ b/javascripts/common/CtaDrawer.js
@@ -8,8 +8,7 @@
CtaDrawer = Drawer.extend( {
defaults: {
loginCaption: mw.msg(
'mobile-frontend-watchlist-cta-button-login' ),
- signupCaption: mw.msg(
'mobile-frontend-watchlist-cta-button-signup' ),
- cancelMessage: mw.msg( 'mobile-frontend-drawer-cancel' )
+ signupCaption: mw.msg(
'mobile-frontend-watchlist-cta-button-signup' )
},
template: M.template.get( 'ctaDrawer' ),
diff --git a/javascripts/common/View.js b/javascripts/common/View.js
index 4b21240..24c071e 100644
--- a/javascripts/common/View.js
+++ b/javascripts/common/View.js
@@ -57,6 +57,7 @@
*/
initialize: function( options ) {
this._super();
+ this.defaults = $.extend( {}, this._parent.defaults,
this.defaults );
options = $.extend( {}, this.defaults, options );
if ( options.el ) {
this.$el = $( options.el );
diff --git a/javascripts/modules/editor/EditorOverlay.js
b/javascripts/modules/editor/EditorOverlay.js
index a200cc9..5ade764 100644
--- a/javascripts/modules/editor/EditorOverlay.js
+++ b/javascripts/modules/editor/EditorOverlay.js
@@ -15,7 +15,6 @@
EditorOverlay = Overlay.extend( {
defaults: {
- closeMsg: mw.msg( 'mobile-frontend-overlay-escape' ),
continueMsg: mw.msg( 'mobile-frontend-editor-continue'
),
saveMsg: mw.msg( 'mobile-frontend-editor-save' ),
cancelMsg: mw.msg( 'mobile-frontend-editor-cancel' ),
diff --git a/javascripts/modules/mediaViewer.js
b/javascripts/modules/mediaViewer.js
index 2c34b1b..ddf31ac 100644
--- a/javascripts/modules/mediaViewer.js
+++ b/javascripts/modules/mediaViewer.js
@@ -47,7 +47,6 @@
closeOnBack: true,
defaults: {
- closeMsg: mw.msg( 'mobile-frontend-overlay-escape' ),
detailsMsg: mw.msg( 'mobile-frontend-media-details' )
},
diff --git a/javascripts/modules/talk/TalkSectionOverlay.js
b/javascripts/modules/talk/TalkSectionOverlay.js
index f7fdefd..c00572f 100644
--- a/javascripts/modules/talk/TalkSectionOverlay.js
+++ b/javascripts/modules/talk/TalkSectionOverlay.js
@@ -7,7 +7,6 @@
TalkSectionOverlay = Overlay.extend( {
template: M.template.get( 'talkSection' ),
defaults: {
- closeMsg: mw.msg( 'mobile-frontend-overlay-escape' ),
reply: mw.msg( 'mobile-frontend-talk-reply' ),
confirmMsg: mw.msg( 'mobile-frontend-editor-save' ),
licenseMsg: mw.msg( 'mobile-frontend-editor-license' ),
diff --git a/javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js
b/javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js
index ef9527a..deed37d 100644
--- a/javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js
+++ b/javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js
@@ -6,8 +6,7 @@
LeadPhotoTutorialOverlay = PageActionOverlay.extend( {
defaults: {
className: 'slide active photo-upload',
- summary: mw.msg(
'mobile-frontend-lead-image-tutorial-summary' ),
- cancelMsg: mw.msg( 'cancel' )
+ summary: mw.msg(
'mobile-frontend-lead-image-tutorial-summary' )
},
postRender: function( options ) {
this._super( options );
diff --git a/tests/javascripts/common/test_Class.js
b/tests/javascripts/common/test_Class.js
index a7ea225..b236988 100644
--- a/tests/javascripts/common/test_Class.js
+++ b/tests/javascripts/common/test_Class.js
@@ -4,10 +4,11 @@
QUnit.module( 'MobileFrontend Class' );
- QUnit.test( '.extend', 5, function( assert ) {
+ QUnit.test( '.extend', 6, function( assert ) {
var Parent, Child, child;
Parent = Class.extend( {
+ prop: 'parent',
parent: function() {
return 'parent';
},
@@ -20,6 +21,7 @@
} );
Child = Parent.extend( {
+ prop: 'child',
override: function() {
return 'overriden';
},
@@ -36,6 +38,7 @@
assert.strictEqual( child.override(), 'overriden', 'override
parent properties' );
assert.strictEqual( child.child(), 'child', 'add new
properties' );
assert.strictEqual( child.callSuper(), 'super duper', "call
parent's functions" );
+ assert.strictEqual( child._parent.prop, 'parent', "access
parent's prototype through _parent" );
assert.strictEqual( Child.extend, Class.extend, 'make Child
extendeable' );
} );
diff --git a/tests/javascripts/common/test_View.js
b/tests/javascripts/common/test_View.js
index 95cfa7b..ad3f744 100644
--- a/tests/javascripts/common/test_View.js
+++ b/tests/javascripts/common/test_View.js
@@ -65,6 +65,27 @@
strictEqual( view.content(), 'Some content', 'fill template with data
from options' );
} );
+QUnit.test( 'View.extend, extending defaults', 1, function( assert ) {
+ var ParentView, ChildView, view;
+
+ ParentView = View.extend( {
+ defaults: {
+ a: 1,
+ b: 2
+ }
+ } );
+
+ ChildView = ParentView.extend( {
+ defaults: {
+ b: 3,
+ c: 4
+ }
+ } );
+
+ view = new ChildView( { c: 5 } );
+ assert.deepEqual( view.options, { a: 1, b: 3, c: 5 } );
+} );
+
QUnit.test( 'View#preRender', 1, function() {
var ChildView, view;
ChildView = View.extend( {
--
To view, visit https://gerrit.wikimedia.org/r/90685
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id6bb5a89dea33200ea9cf35535644bde54d8820e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Robmoen <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits