2013-02-20 21:53:15 +01:00
/ * *
2013-04-13 21:00:13 +02:00
* EGroupware eTemplate2 - JS widget class for an iframe
2013-02-20 21:53:15 +01:00
*
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ package etemplate
* @ subpackage api
2021-06-07 17:33:53 +02:00
* @ link https : //www.egroupware.org
2013-02-20 21:53:15 +01:00
* @ author Nathan Gray
* @ copyright Nathan Gray 2013
* /
/ * e g w : u s e s
et2 _core _valueWidget ;
* /
2021-06-07 17:33:53 +02:00
import { et2 _valueWidget } from "./et2_core_valueWidget" ;
import { et2 _register _widget } from "./et2_core_widget" ;
import { ClassWithAttributes } from "./et2_core_inheritance" ;
2013-04-13 21:00:13 +02:00
/ * *
* @ augments et2 _valueWidget
* /
2021-06-07 17:33:53 +02:00
export class et2 _iframe extends et2 _valueWidget {
2020-02-10 14:50:57 +01:00
/ * *
* Constructor
*
* @ memberOf et2 _iframe
* /
2021-06-07 17:33:53 +02:00
constructor ( _parent , _attrs , _child ) {
2020-02-10 14:50:57 +01:00
// Call the inherited constructor
2021-06-07 17:33:53 +02:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2 _iframe . _attributes , _child || { } ) ) ;
this . htmlNode = null ;
2020-02-10 14:50:57 +01:00
// Allow no child widgets
2021-06-07 17:33:53 +02:00
this . supportedWidgetClasses = [ ] ;
this . htmlNode = jQuery ( document . createElement ( "iframe" ) ) ;
if ( this . options . label ) {
this . htmlNode . append ( '<span class="et2_label">' + this . options . label + '</span>' ) ;
2020-02-10 14:50:57 +01:00
}
2021-06-07 17:33:53 +02:00
if ( this . options . fullscreen ) {
this . htmlNode . attr ( 'allowfullscreen' , 1 ) ;
2020-02-10 14:50:57 +01:00
}
2021-06-07 17:33:53 +02:00
this . setDOMNode ( this . htmlNode [ 0 ] ) ;
2020-02-10 14:50:57 +01:00
}
/ * *
* Set name of iframe ( to be used as target for links )
*
* @ param _name
* /
2021-06-07 17:33:53 +02:00
set _name ( _name ) {
2020-02-10 14:50:57 +01:00
this . options . name = _name ;
this . htmlNode . attr ( 'name' , _name ) ;
2021-06-07 17:33:53 +02:00
}
set _allow ( _allow ) {
2020-04-29 12:29:35 +02:00
this . options . allow = _allow ;
this . htmlNode . attr ( 'allow' , _allow ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-10 14:50:57 +01:00
/ * *
* Make it look like part of the containing document
*
* @ param _seamless boolean
* /
2021-06-07 17:33:53 +02:00
set _seamless ( _seamless ) {
2020-02-10 14:50:57 +01:00
this . options . seamless = _seamless ;
this . htmlNode . attr ( "seamless" , _seamless ) ;
2021-06-07 17:33:53 +02:00
}
set _value ( _value ) {
2020-02-10 14:50:57 +01:00
if ( typeof _value == "undefined" )
_value = "" ;
if ( _value . trim ( ) . indexOf ( "http" ) == 0 || _value . indexOf ( 'about:' ) == 0 || _value [ 0 ] == '/' ) {
// Value is a URL
this . set _src ( _value ) ;
}
else {
// Value is content
this . set _srcdoc ( _value ) ;
}
2021-06-07 17:33:53 +02:00
}
2020-02-10 14:50:57 +01:00
/ * *
* Set the URL for the iframe
*
* Sets the src attribute to the given value
*
* @ param _value String URL
* /
2021-06-07 17:33:53 +02:00
set _src ( _value ) {
2020-02-10 14:50:57 +01:00
if ( _value . trim ( ) != "" ) {
if ( _value . trim ( ) == 'about:blank' ) {
this . htmlNode . attr ( "src" , _value ) ;
}
else {
// Load the new page, but display a loader
2021-06-07 17:33:53 +02:00
let loader = jQuery ( '<div class="et2_iframe loading"/>' ) ;
2020-02-10 14:50:57 +01:00
this . htmlNode
2021-06-07 17:33:53 +02:00
. before ( loader ) ;
2020-02-10 14:50:57 +01:00
window . setTimeout ( jQuery . proxy ( function ( ) {
this . htmlNode . attr ( "src" , _value )
. one ( 'load' , function ( ) {
2021-06-07 17:33:53 +02:00
loader . remove ( ) ;
2020-02-10 14:50:57 +01:00
} ) ;
} , this ) , 0 ) ;
}
}
2021-06-07 17:33:53 +02:00
}
2020-02-10 14:50:57 +01:00
/ * *
* Sets the content of the iframe
*
* Sets the srcdoc attribute to the given value
*
* @ param _value String Content of a document
* /
2021-06-07 17:33:53 +02:00
set _srcdoc ( _value ) {
2020-02-10 14:50:57 +01:00
this . htmlNode . attr ( "srcdoc" , _value ) ;
2021-06-07 17:33:53 +02:00
}
}
et2 _iframe . _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"
} ,
"name" : {
name : "Name" ,
"default" : "" ,
description : "Specifies name of frame, to be used as target for links" ,
type : "string"
} ,
fullscreen : {
name : "Fullscreen" ,
"default" : false ,
description : "Make the iframe compatible to be a fullscreen video player mode" ,
type : "boolean"
} ,
src : {
name : "Source" ,
"default" : "" ,
description : "Specifies URL for the iframe" ,
type : "string"
} ,
allow : {
name : "Allow" ,
"default" : "" ,
description : "Specifies list of allow features, e.g. camera" ,
type : "string"
}
} ;
et2 _register _widget ( et2 _iframe , [ "iframe" ] ) ;
2020-02-10 14:50:57 +01:00
//# sourceMappingURL=et2_widget_iframe.js.map