Thiemo Mättig (WMDE) has submitted this change and it was merged.

Change subject: Changed $.fn.applyTemplate mechanics
......................................................................


Changed $.fn.applyTemplate mechanics

applyTemplate() expects a template to have a single root node. Appending the 
root node to the single
node applied to the function creates a unnecessarily nested structure. In 
addition, this removes
the possibility to add nested DOM nodes, like a table content structure, to a 
<table/> node.
With the change, instead of the whole template, only the template root node's 
children are appended
to the element the template is applied to. Consequently, now, a template 
definition may have a DOM
structure that completely represents an HTML segment.

Change-Id: Idfa84a66b4d3b6c0305bb89ebba26b16388fe56d
---
M lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
M lib/resources/templates.js
M lib/resources/templates.php
3 files changed, 31 insertions(+), 21 deletions(-)

Approvals:
  WikidataJenkins: Verified
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Checked



diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
index d367f16..7caea2b 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.sitelinkgroupview.js
@@ -37,14 +37,18 @@
                ],
                templateShortCuts: {
                        '$h': 'h2',
-                       '$counter': '.wikibase-sitelinkgroupview-counter',
-                       '$sitelinklistview': 
'.wikibase-sitelinkgroupview-sitelinklistview'
+                       '$counter': '.wikibase-sitelinkgroupview-counter'
                },
                value: null,
                entityId: null,
                api: null,
                entityStore: null
        },
+
+       /**
+        * @type {jQuery}
+        */
+       $sitelinklistview: null,
 
        /**
         * @see jQuery.ui.TemplatedWidget._create
@@ -63,6 +67,12 @@
                // TODO: Remove scraping
                this.__headingText = this.$h.text();
 
+               this.$sitelinklistview = this.element.find( 
'.wikibase-sitelinklistview' );
+
+               if( !this.$sitelinklistview.length ) {
+                       this.$sitelinklistview = $( '<table/>' ).appendTo( 
this.element );
+               }
+
                this.$sitelinklistview.sitelinklistview( {
                        value: this._getSiteLinksOfGroup(),
                        allowedSiteIds: this.options.value
diff --git a/lib/resources/templates.js b/lib/resources/templates.js
index cf42343..c06d19b 100644
--- a/lib/resources/templates.js
+++ b/lib/resources/templates.js
@@ -151,7 +151,7 @@
                        this.prop( 'dir', $template.prop( 'dir' ) );
                }
 
-               $template.children().appendTo( this.empty() );
+               this.empty().append( $template.children() );
 
                return this;
        };
diff --git a/lib/resources/templates.php b/lib/resources/templates.php
index 2dbc89b..33b4b89 100644
--- a/lib/resources/templates.php
+++ b/lib/resources/templates.php
@@ -269,29 +269,29 @@
        <h2 class="wb-section-heading wikibase-sitelinkgroupview-heading" 
dir="auto" id="$1">
                $2<span class="wikibase-sitelinkgroupview-counter">$3</span>
        </h2>
-       <table class="wikibase-sitelinkgroupview-sitelinklistview">
-               <!-- wikibase-sitelinklistview -->$4
-       </table>
+       <!-- wikibase-sitelinklistview -->$4
 </div>
 HTML;
 
        $templates['wikibase-sitelinklistview'] =
 <<<HTML
-<colgroup>
-       <col class="wikibase-sitelinklistview-sitename" />
-       <col class="wikibase-sitelinklistview-siteid" />
-       <col class="wikibase-sitelinklistview-link" />
-       <col class="wb-editsection" />
-</colgroup>
-<thead>
-       $1 <!-- wikibase-sitelinklist-thead -->
-</thead>
-<tbody>
-       $2 <!-- [0,*] wikibase-sitelinkview -->
-</tbody>
-<tfoot>
-       $3 <!-- wikibase-sitelinklistview-tfoot -->
-</tfoot>
+<table class="wikibase-sitelinklistview">
+       <colgroup>
+               <col class="wikibase-sitelinklistview-sitename" />
+               <col class="wikibase-sitelinklistview-siteid" />
+               <col class="wikibase-sitelinklistview-link" />
+               <col class="wb-editsection" />
+       </colgroup>
+       <thead>
+               <!-- wikibase-sitelinklist-thead -->$1
+       </thead>
+       <tbody>
+               <!-- [0,*] wikibase-sitelinkview -->$2
+       </tbody>
+       <tfoot>
+               <!-- wikibase-sitelinklistview-tfoot -->$3
+       </tfoot>
+</table>
 HTML;
 
        $templates['wikibase-sitelinklistview-thead'] =

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idfa84a66b4d3b6c0305bb89ebba26b16388fe56d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to