egroupware/api/js/etemplate/et2_widget_script.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* EGroupware eTemplate2 - JS widget class containing javascript
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link https://www.egroupware.org
* @author Ralf Becker
*/
/*egw:uses
2020-02-13 10:25:00 +01:00
et2_core_widget;
*/
import { et2_register_widget } from "./et2_core_widget";
import { et2_widget } from "./et2_core_widget";
/**
* Function which executes the encapsulated script data.
*
* This should only be used for customization and NOT for regular EGroupware code!
*
* We can NOT create a script tag containing the content, as this violates our CSP policy!
*
* We use new Function(_content) instead. Therefore you have to use window to address global context:
*
* window.some_func = function() {...}
*
* instead of not working
*
* function some_funct() {...}
*
* @augments et2_widget
*/
export class et2_script extends et2_widget {
constructor(_parent, _attrs, _child) {
super();
2020-02-13 10:25:00 +01:00
// Allow no child widgets
this.supportedWidgetClasses = [];
2020-02-13 10:25:00 +01:00
}
;
/**
* We can NOT create a script tag containing the content, as this violoates our CSP policy!
*
* @param {string} _content
*/
loadContent(_content) {
2020-02-13 10:25:00 +01:00
try {
var func = new Function(_content);
func.call(window);
}
catch (e) {
this.egw.debug('error', 'Error while executing script: ', _content, e);
}
}
}
et2_register_widget(et2_script, ["script"]);
2020-02-13 10:25:00 +01:00
//# sourceMappingURL=et2_widget_script.js.map