mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-29 03:13:40 +01:00
Etemplate - allow customisable onload for templates
This commit is contained in:
parent
ad1778be9c
commit
0b3e4f048e
@ -58,6 +58,12 @@ var et2_template = (function(){ "use strict"; return et2_DOMWidget.extend(
|
||||
name: "URL of template",
|
||||
type: "string",
|
||||
description: "full URL to load template incl. cache-buster"
|
||||
},
|
||||
"onload": {
|
||||
"name": "onload",
|
||||
"type": "js",
|
||||
"default": et2_no_init,
|
||||
"description": "JS code which is executed after the template is loaded."
|
||||
}
|
||||
},
|
||||
|
||||
@ -187,6 +193,33 @@ var et2_template = (function(){ "use strict"; return et2_DOMWidget.extend(
|
||||
return this.div;
|
||||
},
|
||||
|
||||
attachToDOM: function() {
|
||||
if (this.div)
|
||||
{
|
||||
jQuery(this.div)
|
||||
.off('.et2_template')
|
||||
.bind("load.et2_template", this, function(e) {
|
||||
e.data.load.call(e.data, this);
|
||||
});
|
||||
}
|
||||
|
||||
this._super.apply(this,arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called after the template is fully loaded to handle any onload handlers
|
||||
*/
|
||||
load: function() {
|
||||
if(typeof this.options.onload == 'function')
|
||||
{
|
||||
// Make sure function gets a reference to the widget
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if(args.indexOf(this) == -1) args.push(this);
|
||||
|
||||
return this.options.onload.apply(this, args);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Override to return the promise for deferred loading
|
||||
*/
|
||||
|
@ -543,6 +543,16 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback, _app, _no_et
|
||||
|
||||
jQuery(this.DOMContainer).trigger('load', this);
|
||||
|
||||
if(this.templates[this.name].attributes.onload)
|
||||
{
|
||||
var onload = et2_checkType(this.templates[this.name].attributes.onload.value,'js','onload');
|
||||
if (typeof onload === 'string')
|
||||
{
|
||||
onload = et2_compileLegacyJS(onload, this, this.widgetContainer, this.widgetContainer);
|
||||
}
|
||||
onload.call(this.widgetContainer);
|
||||
}
|
||||
|
||||
// Profiling
|
||||
if(egw.debug_level() >= 4)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user