Intial implementation

This commit is contained in:
Andrew O'Neil 2009-02-27 02:41:21 +00:00
parent a113d81acf
commit 0f2de8f7ed
5 changed files with 100 additions and 0 deletions

5
_config.php Normal file
View File

@ -0,0 +1,5 @@
<?php
?>

34
code/IFramePage.php Normal file
View File

@ -0,0 +1,34 @@
<?php
class IFramePage extends Page {
static $db = array(
'IFrameUrl' => '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;"';
}
}
}
?>

4
css/IFramePage.css Normal file
View File

@ -0,0 +1,4 @@
#IFramePageIFrame {
width: 100%;
border: none;
}

46
javascript/IFramePage.js Normal file
View File

@ -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';
}
);
}
}
);

View File

@ -0,0 +1,11 @@
<% require ThemedCSS(IFramePage) %>
<% require javascript(jsparty/jquery/jquery.js) %>
<% require javascript(iframe/javascript/IFramePage.js) %>
<div class="typography">
<h2>$Title</h2>
<iframe id="IFramePageIFrame" src="$IFrameUrl" $Height>
$Content
</iframe>
</div>