2021-10-08 16:02:51 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Iframe widget (WebComponent)
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Hadi Nategh
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-13 19:55:33 +02:00
|
|
|
import {css, html, LitElement} from "lit";
|
2021-10-08 16:02:51 +02:00
|
|
|
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
|
|
|
|
2024-05-07 22:46:44 +02:00
|
|
|
export class Et2Iframe extends Et2Widget(LitElement)
|
2021-10-08 16:02:51 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
2021-10-13 12:17:07 +02:00
|
|
|
:host {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
:host > iframe {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
2021-10-08 16:02:51 +02:00
|
|
|
/* Custom CSS */
|
|
|
|
`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
label: {type: String},
|
|
|
|
seamless: {type: Boolean},
|
|
|
|
name: {type: String},
|
|
|
|
fullscreen: {type: Boolean},
|
|
|
|
needed: {type: Boolean},
|
|
|
|
src: {type:String},
|
|
|
|
allow: {type: String}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(...args : any[])
|
|
|
|
{
|
|
|
|
super(...args);
|
|
|
|
}
|
2021-10-13 12:17:07 +02:00
|
|
|
get slots()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.slots
|
|
|
|
};
|
|
|
|
}
|
2021-10-08 16:02:51 +02:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-10-13 12:17:07 +02:00
|
|
|
return html`
|
2022-03-02 00:56:58 +01:00
|
|
|
<iframe ${this.id ? html`id="${this.id}"` : ''} allowfullscreen="${this.fullscreen}"
|
|
|
|
seamless="${this.seamless}" name="${this.name}" allow="${this.allow}"></iframe>
|
|
|
|
<slot>${this.label}</slot>
|
2021-10-13 12:17:07 +02:00
|
|
|
`;
|
2021-10-08 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__getIframeNode()
|
|
|
|
{
|
|
|
|
return this.shadowRoot.querySelector('iframe');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the URL for the iframe
|
|
|
|
*
|
|
|
|
* Sets the src attribute to the given value
|
|
|
|
*
|
|
|
|
* @param _value String URL
|
|
|
|
*/
|
|
|
|
set_src(_value)
|
|
|
|
{
|
|
|
|
if(_value.trim() != "")
|
|
|
|
{
|
|
|
|
if(_value.trim() == 'about:blank')
|
|
|
|
{
|
|
|
|
this.__getIframeNode().src = _value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Load the new page, but display a loader
|
|
|
|
let loader = jQuery('<div class="et2_iframe loading"/>');
|
|
|
|
this.__getIframeNode().before(loader);
|
|
|
|
window.setTimeout(function() {
|
|
|
|
this.__getIframeNode().src = _value;
|
|
|
|
this.__getIframeNode().addEventListener('load',function() {
|
|
|
|
loader.remove();
|
|
|
|
});
|
|
|
|
}.bind(this),0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set name of iframe (to be used as target for links)
|
|
|
|
*
|
|
|
|
* @param _name
|
|
|
|
*/
|
|
|
|
set_name(_name)
|
|
|
|
{
|
|
|
|
this.options.name = _name;
|
|
|
|
this.__getIframeNode().attribute('name', _name);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_allow (_allow)
|
|
|
|
{
|
|
|
|
this.options.allow = _allow;
|
|
|
|
this.__getIframeNode().attribute('allow', _allow);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Make it look like part of the containing document
|
|
|
|
*
|
|
|
|
* @param _seamless boolean
|
|
|
|
*/
|
|
|
|
set_seamless(_seamless)
|
|
|
|
{
|
|
|
|
this.options.seamless = _seamless;
|
|
|
|
this.__getIframeNode().attribute("seamless", _seamless);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_value(_value)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the content of the iframe
|
|
|
|
*
|
|
|
|
* Sets the srcdoc attribute to the given value
|
|
|
|
*
|
|
|
|
* @param _value String Content of a document
|
|
|
|
*/
|
|
|
|
set_srcdoc(_value)
|
|
|
|
{
|
|
|
|
this.__getIframeNode().attribute("srcdoc", _value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that Et2Iframe is a LitElement
|
|
|
|
customElements.define("et2-iframe", Et2Iframe);
|