mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
new script widget to allow to include javascript in (customizied) templates, also adding an id to style widget
This commit is contained in:
parent
ad6f33d78b
commit
4578d849f5
69
etemplate/js/et2_widget_script.js
Normal file
69
etemplate/js/et2_widget_script.js
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 http://www.egroupware.org
|
||||
* @author Ralf Becker
|
||||
* @copyright Stylite 2015
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/*egw:uses
|
||||
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 violoates 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
|
||||
*/
|
||||
var et2_script = et2_widget.extend(
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @memberOf et2_script
|
||||
*/
|
||||
init: function()
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// Allow no child widgets
|
||||
this.supportedWidgetClasses = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* We can NOT create a script tag containing the content, as this violoates our CSP policy!
|
||||
*
|
||||
* @param {string} _content
|
||||
*/
|
||||
loadContent: function(_content)
|
||||
{
|
||||
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"]);
|
@ -23,14 +23,14 @@
|
||||
* TODO: The style data could be parsed for rules and appended using the JS
|
||||
* stylesheet interface, allowing the style only to modifiy nodes of the current
|
||||
* template.
|
||||
*
|
||||
*
|
||||
* @augments et2_widget
|
||||
*/
|
||||
var et2_styles = et2_widget.extend(
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @memberOf et2_styles
|
||||
*/
|
||||
init: function() {
|
||||
@ -64,8 +64,32 @@ var et2_styles = et2_widget.extend(
|
||||
{
|
||||
this.styleNode.appendChild(document.createTextNode(_content));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the id of the DOM-Node.
|
||||
*
|
||||
* DOM id's have dots "." replaced with dashes "-"
|
||||
*
|
||||
* @param {string} _value id to set
|
||||
*/
|
||||
set_id: function(_value) {
|
||||
|
||||
this.id = _value;
|
||||
this.dom_id = _value ? this.getInstanceManager().uniqueId+'_'+_value.replace(/\./g, '-') : _value;
|
||||
|
||||
if (this.styleNode)
|
||||
{
|
||||
if (_value != "")
|
||||
{
|
||||
this.styleNode.setAttribute("id", this.dom_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.styleNode.removeAttribute("id");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
et2_register_widget(et2_styles, ["styles"]);
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
et2_widget_vfs;
|
||||
et2_widget_video;
|
||||
et2_widget_itempicker;
|
||||
et2_widget_script;
|
||||
|
||||
et2_extension_nextmatch;
|
||||
et2_extension_customfields;
|
||||
|
Loading…
Reference in New Issue
Block a user