Skip to content

Instantly share code, notes, and snippets.

@mrpollo
Created December 20, 2011 19:51
Show Gist options
  • Select an option

  • Save mrpollo/1502971 to your computer and use it in GitHub Desktop.

Select an option

Save mrpollo/1502971 to your computer and use it in GitHub Desktop.
MooTools 1.12 and Earlier iFrame resize, mainly used for Joomla compatibility
window.addEvent('domready', function(){
function resizeIframe( iframe ){
var innerDoc = $( ( iframe.contentWindow ) ? iframe.contentWindow.document.body : iframe.contentDocument.body ) );
var objToResize = (iframe.style) ? iframe.style : iframe;
var sizes = innerDoc.getSize();
var offsetHeight = sizes.scrollSize.y + 50;
objToResize.height = offsetHeight + 'px';
}
if( $('iframe') != null ){
var iframe = $('iframe');
iframe.addEvent('load', function(){
resizeIframe( this );
});
if( window.webkit || window.opera ){
var source = iframe.src;
iframe.src = '';
iframe.src = source;
}else{
resizeIframe( iframe );
}
}
});
window.addEvent('domready', function(){
function resizeIframe( iframe ){
var innerDoc = $( ( iframe.contentWindow ) ? iframe.contentWindow.document.body : iframe.contentDocument.body ) );
var objToResize = (iframe.style) ? iframe.style : iframe;
var sizes = innerDoc.getSize();
var offsetHeight = sizes.scrollSize.y + 50;
objToResize.height = offsetHeight + 'px';
}
if( $('iframe') != null ){
var iframe = $('iframe');
iframe.addEvent('load', function(){
resizeIframe( this );
});
if( window.webkit || window.opera ){
var source = iframe.src;
iframe.src = '';
iframe.src = source;
}else{
resizeIframe( iframe );
}
}
});
@mrpollo

mrpollo commented Dec 20, 2011

Copy link
Copy Markdown
Author

$('iframe') refers to all the elements marked with class iframe, this suits my needs change accordingly

@WillieWalker

Copy link
Copy Markdown

this sounds like the perfect solution to my problem, please can you tell a newbie where I must put this code to that it works ... I am using Jommla 1.7.
Thanks in advance!

@mrpollo

mrpollo commented Jan 5, 2012

Copy link
Copy Markdown
Author

I'm glad this can help you, What I did is a file called iframe.js and added that to my template, It's always looking for an iframe with an id called "iframe" <iframe id="iframe" .....></iframe> and the script will just expand it, It has only 1 restriction the iframe must be on the same domain!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment