<!--
  ~ Copyright (C) 2023 Xibo Signage Ltd
  ~
  ~ Xibo - Digital Signage - https://xibosignage.com
  ~
  ~ This file is part of Xibo.
  ~
  ~ Xibo is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU Affero General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ any later version.
  ~
  ~ Xibo is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU Affero General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Affero General Public License
  ~ along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
  -->
<module>
    <id>core-webpage</id>
    <name>Webpage</name>
    <author>Core</author>
    <description>Embed a Webpage</description>
    <icon>fa fa-sitemap</icon>
    <class></class>
    <type>webpage</type>
    <dataType></dataType>
    <schemaVersion>1</schemaVersion>
    <assignable>1</assignable>
    <regionSpecific>1</regionSpecific>
    <renderAs>native</renderAs>
    <defaultDuration>60</defaultDuration>
    <settings></settings>
    <properties>
        <property id="uri" type="text" variant="uri">
            <title>Link</title>
            <helpText>The Location (URL) of the webpage</helpText>
            <default></default>
            <rule>
                <test>
                    <condition type="required"></condition>
                </test>
            </rule>
        </property>
        <property id="transparency" type="checkbox">
            <title>Background transparent?</title>
            <helpText>Should the Widget be shown with a transparent background? Also requires the embedded content to have a transparent background.</helpText>
            <default></default>
        </property>
        <property id="isPreNavigate" type="checkbox">
            <title>Preload?</title>
            <helpText>Should this Widget be loaded entirely off screen so that it is ready when shown? Dynamic content will start running off screen.</helpText>
            <default></default>
        </property>
        <property id="modeid" type="dropdown" mode="single">
            <title>Options</title>
            <helpText>How should this web page be embedded?</helpText>
            <default>1</default>
            <options>
                <option name="1">Open Natively</option>
                <option name="2">Manual Position</option>
                <option name="3">Best Fit</option>
            </options>
            <rule>
                <test type="and">
                    <condition type="required"></condition>
                </test>
            </rule>
        </property>
        <property id="pageWidth" type="number">
            <title>Page Width</title>
            <helpText>The width of the page. Leave empty to use the region width.</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="neq">1</condition>
                </test>
            </visibility>
        </property>
        <property id="pageHeight" type="number">
            <title>Page Height</title>
            <helpText>The height of the page. Leave empty to use the region height.</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="neq">1</condition>
                </test>
            </visibility>
        </property>
        <property id="offsetTop" type="number">
            <title>Offset Top</title>
            <helpText>The starting point from the top in pixels</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="eq">2</condition>
                </test>
            </visibility>
        </property>
        <property id="offsetLeft" type="number">
            <title>Offset Left</title>
            <helpText>The starting point from the left in pixels</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="eq">2</condition>
                </test>
            </visibility>
        </property>
        <property id="scaling" type="number">
            <title>Scale Percentage</title>
            <helpText>The Percentage to Scale this Webpage (0 - 100)</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="eq">2</condition>
                </test>
            </visibility>
        </property>
        <property id="pageLoadErrorTrigger" type="text">
            <title>Trigger on page load error</title>
            <helpText>Code to be triggered when the page to be loaded returns an error, e.g. a 404 not found.</helpText>
            <default></default>
            <visibility>
                <test>
                    <condition field="modeid" type="eq">1</condition>
                </test>
            </visibility>
        </property>
    </properties>
    <preview></preview>
    <stencil>
        <hbs><![CDATA[
<iframe id="iframe" scrolling="no" frameborder="0" src=" {{ uri  }}"></iframe>
         ]]></hbs>
        <style><![CDATA[
#iframe { border:0; }
        ]]></style>
    </stencil>
    <onRender><![CDATA[
// Scale the layout
$(target).xiboLayoutScaler(properties);

// Set dimensions based on the properties
properties.iframeWidth = properties.pageWidth ? properties.pageWidth : globalOptions.originalWidth;
properties.iframeHeight = properties.pageHeight ? properties.pageHeight : globalOptions.originalHeight;
properties.iframeTop = properties.offsetTop ? properties.offsetTop : 0;
properties.iframeLeft = properties.offsetLeft ? properties.offsetLeft : 0;
properties.scale = properties.scaling ? (properties.scaling/ 100) : 1;

// Scale the iframe
$(target).find('#iframe').xiboIframeScaler(properties);
    ]]></onRender>
</module>
