Better handling of doLoadingFinished and firing load event:

- don't fire while still loading
- prevent trying to load children before template is actually loaded from file
This commit is contained in:
Nathan Gray 2013-10-09 14:10:33 +00:00
parent daf55af475
commit df660bea3c

View File

@ -76,6 +76,9 @@ var et2_template = et2_DOMWidget.extend(
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.div = document.createElement("div"); this.div = document.createElement("div");
// Flag to indicate that loading is finished
this.loading = false;
if (this.id != "" || this.options.template) if (this.id != "" || this.options.template)
{ {
@ -105,6 +108,8 @@ var et2_template = et2_DOMWidget.extend(
if(splitted.length) if(splitted.length)
{ {
// Still loading, don't fire loading finished
this.loading = true;
et2_loadXMLFromURL(path, function(_xmldoc) { et2_loadXMLFromURL(path, function(_xmldoc) {
var templates = {}; var templates = {};
// Scan for templates and store them // Scan for templates and store them
@ -116,9 +121,18 @@ var et2_template = et2_DOMWidget.extend(
// Read the XML structure of the requested template // Read the XML structure of the requested template
this.loadFromXML(templates[template_name]); this.loadFromXML(templates[template_name]);
// Inform the widget tree that it has been successfully loaded. // Update flag
this.loadingFinished(); this.loading = false;
// If the parent is already attached, it has already
// finished loading. This template and its children
// were left out, so they need processing
if(!this.isAttached() && this._parent.isAttached())
{
this.loadingFinished();
}
}, this); }, this);
} }
return; return;
@ -161,11 +175,15 @@ var et2_template = et2_DOMWidget.extend(
* Override to trigger a load event, to facilitate processing when the xml file * Override to trigger a load event, to facilitate processing when the xml file
* is loaded asyncronously * is loaded asyncronously
*/ */
doLoadingFinished: function() { doLoadingFinished: function() {
this._super.apply(this, arguments); if(this.loading) return false;
$j(this.getDOMNode()).trigger('load'); this._super.apply(this, arguments);
return true; var self = this;
} window.setTimeout(function() {
$j(self.getDOMNode()).trigger('load');
},0);
return true;
}
}); });
et2_register_widget(et2_template, ["template"]); et2_register_widget(et2_template, ["template"]);