diff --git a/_config.php b/_config.php new file mode 100644 index 0000000..64387dd --- /dev/null +++ b/_config.php @@ -0,0 +1,5 @@ + diff --git a/code/IFramePage.php b/code/IFramePage.php new file mode 100644 index 0000000..ce95570 --- /dev/null +++ b/code/IFramePage.php @@ -0,0 +1,34 @@ + 'Text', + 'DynamicHeight' => 'Boolean', + 'FixedHeight' => 'Int' + ); + + function getCMSFields() { + $fields = parent::getCMSFields(); + + $fields->removeFieldFromTab('Root.Content.Main', 'Content'); + $fields->addFieldToTab('Root.Content.Main', new TextField('IFrameUrl', 'IFrame URL')); + $fields->addFieldToTab('Root.Content.Main', new CheckboxField('DynamicHeight', 'Dynamically resize the IFrame height (this doesn\'t work if IFrame URL is on a different domain)')); + $fields->addFieldToTab('Root.Content.Main', new NumericField('FixedHeight', 'Fixed Height (in pixels)')); + $fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('Content', 'Alternate Content')); + + return $fields; + } +} + +class IFramePage_Controller extends Page_Controller { + function Height() { + if($this->DynamicHeight) { + return 'class="iframeautosize"'; + } else { + return 'style="height: ' . $this->FixedHeight . 'px;"'; + } + } +} + + +?> diff --git a/css/IFramePage.css b/css/IFramePage.css new file mode 100644 index 0000000..013017b --- /dev/null +++ b/css/IFramePage.css @@ -0,0 +1,4 @@ +#IFramePageIFrame { + width: 100%; + border: none; +} diff --git a/javascript/IFramePage.js b/javascript/IFramePage.js new file mode 100644 index 0000000..8026dfa --- /dev/null +++ b/javascript/IFramePage.js @@ -0,0 +1,46 @@ +$(document).ready(function() + { + // Set specific variable to represent all iframe tags. + var iFrames = document.getElementsByTagName('iframe'); + + // Resize heights. + function iResize() + { + // Iterate through all iframes in the page. + for (var i = 0, j = iFrames.length; i < j; i++) + { + // Set inline style to equal the body height of the iframed content. + iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px'; + } + } + + // Check if browser is Safari or Opera. + if (jquery.browser.safari || $.browser.opera) + { + // Start timer when loaded. + $('iframe').load(function() + { + setTimeout(iResize, 0); + } + ); + + // Safari and Opera need a kick-start. + for (var i = 0, j = iFrames.length; i < j; i++) + { + var iSource = iFrames[i].src; + iFrames[i].src = ''; + iFrames[i].src = iSource; + } + } + else + { + // For other good browsers. + $('iframe').load(function() + { + // Set inline style to equal the body height of the iframed content. + this.style.height = this.contentWindow.document.body.offsetHeight + 'px'; + } + ); + } + } +); diff --git a/templates/Layout/IFramePage.ss b/templates/Layout/IFramePage.ss new file mode 100644 index 0000000..d44ea93 --- /dev/null +++ b/templates/Layout/IFramePage.ss @@ -0,0 +1,11 @@ +<% require ThemedCSS(IFramePage) %> +<% require javascript(jsparty/jquery/jquery.js) %> +<% require javascript(iframe/javascript/IFramePage.js) %> + +
+

$Title

+ + +