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

@ -77,6 +77,9 @@ var et2_template = et2_DOMWidget.extend(
this.div = document.createElement("div");
// Flag to indicate that loading is finished
this.loading = false;
if (this.id != "" || this.options.template)
{
var template_name = this.options.template || this.id;
@ -105,6 +108,8 @@ var et2_template = et2_DOMWidget.extend(
if(splitted.length)
{
// Still loading, don't fire loading finished
this.loading = true;
et2_loadXMLFromURL(path, function(_xmldoc) {
var templates = {};
// Scan for templates and store them
@ -117,8 +122,17 @@ var et2_template = et2_DOMWidget.extend(
// Read the XML structure of the requested template
this.loadFromXML(templates[template_name]);
// Inform the widget tree that it has been successfully loaded.
this.loadingFinished();
// Update flag
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);
}
return;
@ -161,11 +175,15 @@ var et2_template = et2_DOMWidget.extend(
* Override to trigger a load event, to facilitate processing when the xml file
* is loaded asyncronously
*/
doLoadingFinished: function() {
this._super.apply(this, arguments);
$j(this.getDOMNode()).trigger('load');
return true;
}
doLoadingFinished: function() {
if(this.loading) return false;
this._super.apply(this, arguments);
var self = this;
window.setTimeout(function() {
$j(self.getDOMNode()).trigger('load');
},0);
return true;
}
});
et2_register_widget(et2_template, ["template"]);