Skip to content

Commit

Permalink
Allow function to be called with iFrame object instead of selector #138
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Jan 19, 2015
1 parent 0215470 commit 81a0502
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion js/iframeResizer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions src/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@

function createNativePublicFunction(){
function init(element){
if('IFRAME' !== element.tagName.toUpperCase()) {
if(element.tagName && 'IFRAME' !== element.tagName.toUpperCase()) {
throw new TypeError('Expected <IFRAME> tag, found <'+element.tagName+'>.');
} else {
setupIFrame.call(element);
Expand All @@ -520,9 +520,29 @@
}
}

return function iFrameResizeF(options,selecter){
function getIframes(target){
Array.prototype.forEach.call( document.querySelectorAll( target ), init );
}

return function iFrameResizeF(options,target){
processOptions(options);
Array.prototype.forEach.call( document.querySelectorAll( selecter || 'iframe' ), init );
switch (typeof(target)){
case 'undefined':
log(' Attaching to all iFrames');
getIframes('iframe');
break;
case 'string':
log(' Attaching via selector ('+target+')');
getIframes(target);
break;
case 'object':
log(' Attaching to passed in iFrame object');
init(target);
break;
default:
throw new TypeError('Unexpected data type ('+typeof(target)+').');
}

};
}

Expand All @@ -531,6 +551,7 @@
options = options || {};
checkOptions(options);
settings = $.extend( {}, defaults, options );
log(' Attaching via jQuery');
return this.filter('iframe').each( setupIFrame ).end();
};
}
Expand Down
Loading

0 comments on commit 81a0502

Please sign in to comment.