Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/208137

Change subject: Allow view to be the template
......................................................................

Allow view to be the template

Provide a different mode to allow views to be the template itself.
In future we may want to remove className and tagName but we'll see how this
goes.

Bug: T97663
Change-Id: Icd77e47d2a741064284ae1b80f6dde19c22624f0
---
M resources/mobile.startup/Anchor.js
M resources/mobile.startup/Button.js
M resources/mobile.startup/Icon.js
M resources/mobile.view/View.js
4 files changed, 19 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/37/208137/1

diff --git a/resources/mobile.startup/Anchor.js 
b/resources/mobile.startup/Anchor.js
index 2f167c3..68b9711 100644
--- a/resources/mobile.startup/Anchor.js
+++ b/resources/mobile.startup/Anchor.js
@@ -9,6 +9,8 @@
         * @extends View
         */
        Anchor = View.extend( {
+               /** @inheritdoc */
+               isTemplateMode: true,
                /**
                 * @cfg {Object} defaults Default options hash.
                 * @cfg {Boolean} defaults.progressive is progressive action
@@ -25,11 +27,6 @@
                        additionalClassNames: '',
                        href: undefined,
                        label: undefined
-               },
-               /** @inheritdoc */
-               postRender: function () {
-                       View.prototype.postRender.apply( this );
-                       this.$el = this.$el.children( 0 );
                },
                template: mw.template.get( 'mobile.startup', 'anchor.hogan' )
        } );
diff --git a/resources/mobile.startup/Button.js 
b/resources/mobile.startup/Button.js
index f285a06..ec55756 100644
--- a/resources/mobile.startup/Button.js
+++ b/resources/mobile.startup/Button.js
@@ -9,6 +9,8 @@
         * @extends View
         */
        Button = View.extend( {
+               /** @inheritdoc */
+               isTemplateMode: true,
                /**
                 * @cfg {Object} defaults Default options hash.
                 * @cfg {String} defaults.tagName The name of the tag in which 
the button is wrapped.
@@ -27,10 +29,6 @@
                        additionalClassNames: '',
                        href: undefined,
                        label: undefined
-               },
-               /** @inheritdoc */
-               postRender: function () {
-                       this.$el = this.$el.children( 0 );
                },
                template: mw.template.get( 'mobile.startup', 'button.hogan' )
        } );
diff --git a/resources/mobile.startup/Icon.js b/resources/mobile.startup/Icon.js
index f1b8fcf..c52ffdd 100644
--- a/resources/mobile.startup/Icon.js
+++ b/resources/mobile.startup/Icon.js
@@ -9,6 +9,8 @@
         * @extends View
         */
        Icon = View.extend( {
+               /** @inheritdoc */
+               isTemplateMode: true,
                /**
                 * @cfg {Object} defaults Default options hash.
                 * @cfg {Boolean} defaults.hasText Whether the icon has text.
@@ -50,10 +52,6 @@
                                options.modifier = 'mw-ui-icon-before';
                        }
                        View.prototype.initialize.call( this, options );
-               },
-               /** @inheritdoc */
-               postRender: function () {
-                       this.$el = this.$el.children( 0 );
                },
                /**
                 * Return the HTML representation of this view
diff --git a/resources/mobile.view/View.js b/resources/mobile.view/View.js
index 41e2979..dd343e9 100644
--- a/resources/mobile.view/View.js
+++ b/resources/mobile.view/View.js
@@ -92,6 +92,12 @@
                 * @property String
                 */
                tagName: 'div',
+               /**
+                * Tells the View to ignore tagName and className when 
constructing the element
+                * and to rely soley on the template
+                * @property Boolean
+                */
+               isTemplateMode: false,
 
                /**
                 * Whether border box box sizing model should be used
@@ -195,7 +201,7 @@
                 * options
                 */
                render: function ( data ) {
-                       var optionsClone, key;
+                       var optionsClone, key, html;
                        $.extend( this.options, data );
                        optionsClone = $.extend( {}, this.options );
                        // if someone accesses the optionsClone tell them they 
are doing it wrong.
@@ -209,7 +215,12 @@
                        // FIXME: don't pass optionsClone in the next version 
(see mobile.startup.init.js)
                        this.preRender( optionsClone );
                        if ( this.template ) {
-                               this.$el.html( this.template.render( 
this.options, this.templatePartials ) );
+                               html = this.template.render( this.options, 
this.templatePartials );
+                               if ( this.isTemplateMode ) {
+                                       this.$el = $( html );
+                               } else {
+                                       this.$el.html( html );
+                               }
                        }
                        // FIXME: don't pass optionsClone in the next version 
(see mobile.startup.init.js)
                        this.postRender( optionsClone );

-- 
To view, visit https://gerrit.wikimedia.org/r/208137
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd77e47d2a741064284ae1b80f6dde19c22624f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to