From c46777826f5897173b61bfddf2fb69b57a7b1558 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 20 Feb 2013 20:53:15 +0000 Subject: [PATCH] Add iframe widget --- etemplate/js/et2_widget_iframe.js | 106 ++++++++++++++++++++++++++++++ etemplate/js/et2_widget_vfs.js | 1 + etemplate/js/etemplate2.js | 1 + 3 files changed, 108 insertions(+) create mode 100644 etemplate/js/et2_widget_iframe.js diff --git a/etemplate/js/et2_widget_iframe.js b/etemplate/js/et2_widget_iframe.js new file mode 100644 index 0000000000..f4558c5995 --- /dev/null +++ b/etemplate/js/et2_widget_iframe.js @@ -0,0 +1,106 @@ +/** + * eGroupWare eTemplate2 - JS widget class for an iframe + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Nathan Gray + * @copyright Nathan Gray 2013 + * @version $Id$ + */ + +"use strict"; + +/*egw:uses + et2_core_valueWidget; +*/ + +var et2_iframe = et2_valueWidget.extend({ + + attributes: { + 'label': { + default: "", + description: "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables).", + ignore: false, + name: "Label", + translate: true, + type: "string", + }, + "needed": { + "ignore": true + }, + "seamless": { + name: "Seamless", + default: true, + description: "Specifies that the iframe should be rendered in a manner that makes it appear to be part of the containing document", + translate: false, + type: "boolean" + }, + }, + + init: function() { + this._super.apply(this, arguments); + + // Allow no child widgets + this.supportedWidgetClasses = []; + + this.htmlNode = $j(document.createElement("iframe")); + if(this.options.label) + { + this.htmlNode.append(''+this.options.label+''); + } + this.setDOMNode(this.htmlNode[0]); + }, + + /** + * Make it look like part of the containing document + * + * @param _seamless boolean + */ + set_seamless: function(_seamless) { + this.options.seamless = _seamless + this.htmlNode.attr("seamless", _seamless); + }, + + set_value: function(_value) { + if(typeof _value == "undefined") _value = ""; + + if(_value.trim().indexOf("http") == 0) + { + // Value is a URL + this.set_src(_value); + } + else + { + // Value is content + this.set_srcdoc(_value); + } + }, + + /** + * Set the URL for the iframe + * + * Sets the src attribute to the given value + * + * @param _value String URL + */ + set_src: function(_value) { + if(_value.trim() != "") + { + this.htmlNode.attr("src", _value); + } + }, + + /** + * Sets the content of the iframe + * + * Sets the srcdoc attribute to the given value + * + * @param _value String Content of a document + */ + set_srcdoc: function(_value) { + this.htmlNode.attr("srcdoc", _value); + } +}); +et2_register_widget(et2_iframe, ["iframe"]); diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index bd67e253e6..2c46d16e95 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -17,6 +17,7 @@ et2_core_inputWidget; et2_core_valueWidget; et2_widget_description; + et2_widget_file; */ /** diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index c7f2ef22c3..d9e940cc06 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -36,6 +36,7 @@ et2_widget_historylog; et2_widget_hrule; et2_widget_image; + et2_widget_iframe; et2_widget_file; et2_widget_link; et2_widget_progress;