Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/188984
Change subject: itemview/propertyview: Split off initialization from creation
......................................................................
itemview/propertyview: Split off initialization from creation
The change splits off the initialization from the creation routine in itemview
and propertyview.
_create should be used to only create DOM structure for TemplatedWidget can
initialize template
short-cuts. Initialization of sub-widgets is to be done in _init. > 88699
Change-Id: Ie3b09bb780c28198ccf534239ae48323395a39ab
---
M lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
M lib/resources/jquery.wikibase/jquery.wikibase.itemview.js
M lib/resources/jquery.wikibase/jquery.wikibase.propertyview.js
M repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
4 files changed, 52 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/84/188984/1
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
index db89d4c..782960b 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
@@ -107,13 +107,12 @@
},
/**
- * Main initialization actually calling parent's _create().
- * @see jQuery.ui.TemplatedWidget._create
+ * @inheritdoc
* @protected
*
* @throws {Error} if a required options is missing.
*/
- _initEntityview: function() {
+ _init: function() {
if(
!this.options.value
|| !this.options.languages
@@ -130,7 +129,7 @@
this._initEntityTerms();
- PARENT.prototype._create.call( this );
+ PARENT.prototype._init.call( this );
this._attachEventHandlers();
},
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.itemview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.itemview.js
index 3a8999c..a0fbb0a 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.itemview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.itemview.js
@@ -34,20 +34,32 @@
* @protected
*/
_create: function() {
+ this.$statements = $( '.wikibase-statementgrouplistview',
this.element ).first();
+ if( this.$statements.length === 0 ) {
+ this.$statements = $( '<div/>' ).appendTo( this.element
);
+ }
+
+ this.$siteLinks = $( '.wikibase-sitelinkgrouplistview',
this.element );
+
+ if( !this.$siteLinks.length ) {
+ this.$siteLinks = $( '<div/>' ).appendTo( this.element
);
+ }
+ },
+
+ /**
+ * @inheritdoc
+ * @protected
+ */
+ _init: function() {
this._initStatements();
this._initSiteLinks();
- this._initEntityview();
+ PARENT.prototype._init.call( this );
},
/**
* @protected
*/
_initStatements: function() {
- this.$statements = $( '.wikibase-statementgrouplistview',
this.element ).first();
- if( this.$statements.length === 0 ) {
- this.$statements = $( '<div/>' ).appendTo( this.element
);
- }
-
this.$statements
.statementgrouplistview( {
value: this.options.value.getStatements(),
@@ -71,16 +83,9 @@
*/
_initSiteLinks: function() {
var self = this,
- value = [];
-
- this.$siteLinks = $( '.wikibase-sitelinkgrouplistview',
this.element );
-
- if( this.$siteLinks.length ) {
- value = scrapeSiteLinks( this.$siteLinks,
this.options.value.getSiteLinks() );
- } else {
- this.$siteLinks = $( '<div/>' ).appendTo( this.element
);
- value = orderSiteLinksByGroup(
this.options.value.getSiteLinks() );
- }
+ value = $( '.wikibase-sitelinkgrouplistview',
this.element ).length
+ ? scrapeSiteLinks( this.$siteLinks,
this.options.value.getSiteLinks() )
+ : orderSiteLinksByGroup(
this.options.value.getSiteLinks() );
this.$siteLinks.sitelinkgrouplistview( {
value: value,
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.propertyview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.propertyview.js
index a00207b..1f90858 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.propertyview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.propertyview.js
@@ -39,15 +39,27 @@
* @protected
*/
_create: function() {
- this._initDataType();
+ this.$statements = $( '.wikibase-statementgrouplistview',
this.element ).first();
+ if( this.$statements.length === 0 ) {
+ this.$statements = $( '<div/>' ).appendTo( this.element
);
+ }
+
+ this._createDataType();
+ },
+
+ /**
+ * @inheritdoc
+ * @protected
+ */
+ _init: function() {
this._initStatements();
- this._initEntityview();
+ PARENT.prototype._init.call( this );
},
/**
* @protected
*/
- _initDataType: function() {
+ _createDataType: function() {
// TODO: Implement propertyview template to have static HTML
rendered by the back-end match
// the HTML rendered here without having to invoke templating
mechanism here.
@@ -68,11 +80,6 @@
* @protected
*/
_initStatements: function() {
- this.$statements = $( '.wikibase-statementgrouplistview',
this.element ).first();
- if( this.$statements.length === 0 ) {
- this.$statements = $( '<div/>' ).appendTo( this.element
);
- }
-
this.$statements
.statementgrouplistview( {
value: this.options.value.getStatements(),
diff --git a/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
b/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
index 0d19c56..c180977 100644
--- a/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
+++ b/repo/resources/jquery.ui/jquery.ui.TemplatedWidget.js
@@ -52,6 +52,10 @@
* - {jQuery.Event}
* - {boolean} Whether widget has been dis- oder enabled.
*
+ * @event init
+ * Triggered after the widget is fully initialized.
(`jQuery.Widget` native "create"
+ * event is triggered after the DOM is ready and template
short-cuts are assigned.)
+ * - {jQuery.Event}
*/
$.widget( 'ui.TemplatedWidget', PARENT, {
/**
@@ -84,6 +88,15 @@
PARENT.prototype._create.apply( this );
},
+ /**
+ * @see jQuery.Widget._init
+ * @protected
+ */
+ _init: function() {
+ PARENT.prototype._init.call( this );
+ this._trigger( 'init' );
+ },
+
_applyTemplate: function() {
var templateParams = [],
self = this;
--
To view, visit https://gerrit.wikimedia.org/r/188984
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3b09bb780c28198ccf534239ae48323395a39ab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits