mirror of
https://github.com/silverstripe/silverstripe-iframe
synced 2024-10-22 11:05:51 +02:00
Intial implementation
This commit is contained in:
parent
a113d81acf
commit
0f2de8f7ed
5
_config.php
Normal file
5
_config.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
?>
|
34
code/IFramePage.php
Normal file
34
code/IFramePage.php
Normal 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
4
css/IFramePage.css
Normal file
@ -0,0 +1,4 @@
|
||||
#IFramePageIFrame {
|
||||
width: 100%;
|
||||
border: none;
|
||||
}
|
46
javascript/IFramePage.js
Normal file
46
javascript/IFramePage.js
Normal 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';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
11
templates/Layout/IFramePage.ss
Normal file
11
templates/Layout/IFramePage.ss
Normal 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>
|
Loading…
Reference in New Issue
Block a user