iframe-resizer
Advanced tools
Comparing version 2.8.10 to 3.0.0
{ | ||
"name": "iframe-resizer", | ||
"version": "2.8.10", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/davidjbradshaw/iframe-resizer", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -77,2 +77,10 @@ /*global module:false*/ | ||
dest: 'js/iframeResizer.contentWindow.min.js', | ||
}, | ||
polyfil: { | ||
options: { | ||
banner:'// IE8 polyfils for iframeResizer.js\n', | ||
sourceMapName: 'js/ie8.polyfils.map' | ||
}, | ||
src: ['src/ie8.polyfils.js'], | ||
dest: 'js/ie8.polyfils.min.js', | ||
} | ||
@@ -79,0 +87,0 @@ }, |
@@ -20,3 +20,3 @@ { | ||
], | ||
"version": "2.8.10", | ||
"version": "3.0.0", | ||
"author": { | ||
@@ -23,0 +23,0 @@ "name": "David J. Bradshaw", |
@@ -1,2 +0,2 @@ | ||
/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v2.8.10 - 2015-06-21 | ||
/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v3.0.0 - 2015-08-04 | ||
* Desc: Include this file in any page being loaded into an iframe | ||
@@ -9,3 +9,3 @@ * to force the iframe to resize to the content size. | ||
!function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(a){return aa+"["+ca+"] "+a}function c(a){_&&"object"==typeof window.console&&console.log(b(a))}function d(a){"object"==typeof window.console&&console.warn(b(a))}function e(){c("Initialising iFrame"),f(),i(),h("background",M),h("padding",P),o(),m(),j(),q(),n(),Z=p(),E("init","Init message from host page")}function f(){function a(a){return"true"===a?!0:!1}var b=Y.substr(ba).split(":");ca=b[0],N=void 0!==b[1]?Number(b[1]):N,Q=void 0!==b[2]?a(b[2]):Q,_=void 0!==b[3]?a(b[3]):_,$=void 0!==b[4]?Number(b[4]):$,da=void 0!==b[5]?a(b[5]):da,K=void 0!==b[6]?a(b[6]):K,O=b[7],W=void 0!==b[8]?b[8]:W,M=b[9],P=b[10],ia=void 0!==b[11]?Number(b[11]):ia,Z.enable=void 0!==b[12]?a(b[12]):!1,fa=void 0!==b[13]?b[13]:fa}function g(a,b){return-1!==b.indexOf("-")&&(d("Negative CSS value ignored for "+a),b=""),b}function h(a,b){void 0!==b&&""!==b&&"null"!==b&&(document.body.style[a]=b,c("Body "+a+' set to "'+b+'"'))}function i(){void 0===O&&(O=N+"px"),g("margin",O),h("margin",O)}function j(){document.documentElement.style.height="",document.body.style.height="",c('HTML & body height set to "auto"')}function k(b){function d(c){a(window,c,function(){E(b.eventName,b.eventType)})}b.eventNames&&Array.prototype.map?(b.eventName=b.eventNames[0],b.eventNames.map(d)):d(b.eventName),c("Added event listener: "+b.eventType)}function l(){k({eventType:"Animation Start",eventNames:["animationstart","webkitAnimationStart"]}),k({eventType:"Animation Iteration",eventNames:["animationiteration","webkitAnimationIteration"]}),k({eventType:"Animation End",eventNames:["animationend","webkitAnimationEnd"]}),k({eventType:"Device Orientation Change",eventName:"orientationchange"}),k({eventType:"Transition End",eventNames:["transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend"]}),k({eventType:"Window Clicked",eventName:"click"}),"child"===fa&&k({eventType:"IFrame Resized",eventName:"resize"})}function m(){V!==W&&(W in ma||(d(W+" is not a valid option for heightCalculationMethod."),W="bodyScroll"),c('Height calculation method set to "'+W+'"'))}function n(){!0===K?(l(),t()):c("Auto Resize disabled")}function o(){var a=document.createElement("div");a.style.clear="both",a.style.display="block",document.body.appendChild(a)}function p(){function b(){return{x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop}}function e(a){var c=a.getBoundingClientRect(),d=b();return{x:parseInt(c.left,10)+parseInt(d.x,10),y:parseInt(c.top,10)+parseInt(d.y,10)}}function f(a){function b(a){var b=e(a);c("Moving to in page link (#"+d+") at x: "+b.x+" y: "+b.y),I(b.y,b.x,"scrollToOffset")}var d=a.split("#")[1]||"",f=decodeURIComponent(d),g=document.getElementById(f)||document.getElementsByName(f)[0];g?b(g):(c("In page link (#"+d+") not found in iFrame, so sending to parent"),I(0,0,"inPageLink","#"+d))}function g(){""!==location.hash&&"#"!==location.hash&&f(location.href)}function h(){function b(b){function c(a){a.preventDefault(),f(this.getAttribute("href"))}"#"!==b.getAttribute("href")&&a(b,"click",c)}Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'),b)}function i(){a(window,"hashchange",g)}function j(){setTimeout(g,S)}function k(){Array.prototype.forEach&&document.querySelectorAll?(c("Setting up location.hash handlers"),h(),i(),j()):d("In page linking not fully supported in this browser! (See README.md for IE8 workaround)")}return Z.enable?k():c("In page linking not enabled"),{findTarget:f}}function q(){da&&(c("Enable public methods"),window.parentIFrame={close:function(){I(0,0,"close")},getId:function(){return ca},moveToAnchor:function(a){Z.findTarget(a)},reset:function(){H("parentIFrame.reset")},scrollTo:function(a,b){I(b,a,"scrollTo")},scrollToOffset:function(a,b){I(b,a,"scrollToOffset")},sendMessage:function(a,b){I(0,0,"message",JSON.stringify(a),b)},setHeightCalculationMethod:function(a){W=a,m()},setTargetOrigin:function(a){c("Set targetOrigin: "+a),ga=a},size:function(a,b){var c=""+(a?a:"")+(b?","+b:"");F(),E("size","parentIFrame.size("+c+")",a,b)}})}function r(){0!==$&&(c("setInterval: "+$+"ms"),setInterval(function(){E("interval","setInterval: "+$)},Math.abs($)))}function s(b){function d(b){(void 0===b.height||void 0===b.width||0===b.height||0===b.width)&&(c("Attach listerner to "+b.src),a(b,"load",function(){E("imageLoad","Image loaded")}))}b.forEach(function(a){if("attributes"===a.type&&"src"===a.attributeName)d(a.target);else if("childList"===a.type){var b=a.target.querySelectorAll("img");Array.prototype.forEach.call(b,function(a){d(a)})}})}function t(){function a(){var a=document.querySelector("body"),d={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0},e=new b(function(a){E("mutationObserver","mutationObserver: "+a[0].target+" "+a[0].type),s(a)});c("Enable MutationObserver"),e.observe(a,d)}var b=window.MutationObserver||window.WebKitMutationObserver;b?0>$?r():a():(d("MutationObserver not supported in this browser!"),r())}function u(){function a(a){function b(a){var b=/^\d+(px)?$/i;if(b.test(a))return parseInt(a,L);var d=c.style.left,e=c.runtimeStyle.left;return c.runtimeStyle.left=c.currentStyle.left,c.style.left=a||0,a=c.style.pixelLeft,c.style.left=d,c.runtimeStyle.left=e,a}var c=document.body,d=0;return"defaultView"in document&&"getComputedStyle"in document.defaultView?(d=document.defaultView.getComputedStyle(c,null),d=null!==d?d[a]:0):d=b(c.currentStyle[a]),parseInt(d,L)}return document.body.offsetHeight+a("marginTop")+a("marginBottom")}function v(){return document.body.scrollHeight}function w(){return document.documentElement.offsetHeight}function x(){return document.documentElement.scrollHeight}function y(){for(var a=document.querySelectorAll("body *"),b=a.length,d=0,e=(new Date).getTime(),f=0;b>f;f++)a[f].getBoundingClientRect().bottom>d&&(d=a[f].getBoundingClientRect().bottom);return e=(new Date).getTime()-e,c("Parsed "+b+" HTML elements"),c("LowestElement bottom position calculated in "+e+"ms"),d}function z(){return[u(),v(),w(),x()]}function A(){return Math.max.apply(null,z())}function B(){return Math.min.apply(null,z())}function C(){return Math.max(u(),y())}function D(){return Math.max(document.documentElement.scrollWidth,document.body.scrollWidth)}function E(a,b,d,e){function f(){a in{reset:1,resetPage:1,init:1}||c("Trigger event: "+b)}function g(){U=n,la=o,I(U,la,a)}function h(){return ja&&a in R}function i(){function a(a,b){var c=Math.abs(a-b)<=ia;return!c}return n=void 0!==d?d:ma[W](),o=void 0!==e?e:D(),a(U,n)||Q&&a(la,o)}function j(){return!(a in{init:1,interval:1,size:1})}function k(){return W in ea}function l(){c("No change in size detected")}function m(){j()&&k()?H(b):a in{interval:1}||(f(),l())}var n,o;h()?c("Trigger event cancelled: "+a):i()||"init"===a?(f(),F(),g()):m()}function F(){ja||(ja=!0,c("Trigger event lock on")),clearTimeout(ka),ka=setTimeout(function(){ja=!1,c("Trigger event lock off"),c("--")},S)}function G(a){U=ma[W](),la=D(),I(U,la,a)}function H(a){var b=W;W=V,c("Reset trigger event: "+a),F(),G("reset"),W=b}function I(a,b,d,e,f){function g(){void 0===f?f=ga:c("Message targetOrigin: "+f)}function h(){var g=a+":"+b,h=ca+":"+g+":"+d+(void 0!==e?":"+e:"");c("Sending message to host page ("+h+")"),ha.postMessage(aa+h,f)}g(),h()}function J(a){function b(){return aa===(""+a.data).substr(0,ba)}function f(){Y=a.data,ha=a.source,e(),T=!1,setTimeout(function(){X=!1},S)}function g(){X?c("Page reset ignored by init"):(c("Page size reset by host page"),G("resetPage"))}function h(){E("resizeParent","Parent window resized")}function i(){return a.data.split("]")[1]}function j(){return"iFrameResize"in window}function k(){return a.data.split(":")[2]in{"true":1,"false":1}}if(b())if(!1===T)switch(i()){case"reset":g();break;case"resize":h();break;default:j()||d("Unexpected message ("+a.data+")")}else k()?f():c('Ignored message of type "'+i()+'". Received before initialization.')}var K=!0,L=10,M="",N=0,O="",P="",Q=!1,R={resize:1,click:1},S=128,T=!0,U=1,V="offset",W=V,X=!0,Y="",Z={},$=32,_=!1,aa="[iFrameSizer]",ba=aa.length,ca="",da=!1,ea={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},fa="child",ga="*",ha=window.parent,ia=0,ja=!1,ka=null,la=1,ma={offset:u,bodyOffset:u,bodyScroll:v,documentElementOffset:w,scroll:x,documentElementScroll:x,max:A,min:B,grow:A,lowestElement:C};a(window,"message",J)}(); | ||
!function(a){"use strict";function b(b,c,d){"addEventListener"in a?b.addEventListener(c,d,!1):"attachEvent"in a&&b.attachEvent("on"+c,d)}function c(a){return _+"["+bb+"] "+a}function d(b){$&&"object"==typeof a.console&&console.log(c(b))}function e(b){"object"==typeof a.console&&console.warn(c(b))}function f(){g(),d("Initialising iFrame ("+location.href+")"),h(),k(),j("background",L),j("padding",O),s(),p(),q(),l(),u(),r(),Y=t(),D("init","Init message from host page")}function g(){function a(a){return"true"===a?!0:!1}var b=X.substr(ab).split(":");bb=b[0],M=void 0!==b[1]?Number(b[1]):M,P=void 0!==b[2]?a(b[2]):P,$=void 0!==b[3]?a(b[3]):$,Z=void 0!==b[4]?Number(b[4]):Z,J=void 0!==b[6]?a(b[6]):J,N=b[7],V=void 0!==b[8]?b[8]:V,L=b[9],O=b[10],gb=void 0!==b[11]?Number(b[11]):gb,Y.enable=void 0!==b[12]?a(b[12]):!1,db=void 0!==b[13]?b[13]:db,lb=void 0!==b[14]?b[14]:lb}function h(){function b(){var b=a.iFrameResizer;d("Reading data from page: "+JSON.stringify(b)),mb=void 0!==b.messageCallback?b.messageCallback:mb,eb=void 0!==b.targetOrigin?b.targetOrigin:eb,V=void 0!==b.heightCalculationMethod?b.heightCalculationMethod:V,lb=void 0!==b.widthCalculationMethod?b.widthCalculationMethod:lb}"iFrameResizer"in a&&Object===a.iFrameResizer.constructor&&b()}function i(a,b){return-1!==b.indexOf("-")&&(e("Negative CSS value ignored for "+a),b=""),b}function j(a,b){void 0!==b&&""!==b&&"null"!==b&&(document.body.style[a]=b,d("Body "+a+' set to "'+b+'"'))}function k(){void 0===N&&(N=M+"px"),i("margin",N),j("margin",N)}function l(){document.documentElement.style.height="",document.body.style.height="",d('HTML & body height set to "auto"')}function m(c){function e(d){function e(){D(c.eventName,c.eventType)}b(a,d,e)}c.eventNames&&Array.prototype.map?(c.eventName=c.eventNames[0],c.eventNames.map(e)):e(c.eventName),d("Added event listener: "+c.eventType)}function n(){m({eventType:"Animation Start",eventNames:["animationstart","webkitAnimationStart"]}),m({eventType:"Animation Iteration",eventNames:["animationiteration","webkitAnimationIteration"]}),m({eventType:"Animation End",eventNames:["animationend","webkitAnimationEnd"]}),m({eventType:"Orientation Change",eventName:"orientationchange"}),m({eventType:"Input",eventName:"input"}),m({eventType:"Print",eventName:["afterprint","beforeprint"]}),m({eventType:"Transition End",eventNames:["transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend"]}),m({eventType:"Mouse Up",eventName:"mouseup"}),"child"===db&&m({eventType:"IFrame Resized",eventName:"resize"})}function o(a,b,c,f){b!==a&&(a in c||(e(a+" is not a valid option for "+f+"CalculationMethod."),a=b),d(f+' calculation method set to "'+a+'"'))}function p(){o(V,U,nb,"height")}function q(){o(lb,kb,ob,"width")}function r(){!0===J?(n(),x()):d("Auto Resize disabled")}function s(){var a=document.createElement("div");a.style.clear="both",a.style.display="block",document.body.appendChild(a)}function t(){function c(){return{x:void 0!==a.pageXOffset?a.pageXOffset:document.documentElement.scrollLeft,y:void 0!==a.pageYOffset?a.pageYOffset:document.documentElement.scrollTop}}function f(a){var b=a.getBoundingClientRect(),d=c();return{x:parseInt(b.left,10)+parseInt(d.x,10),y:parseInt(b.top,10)+parseInt(d.y,10)}}function g(a){function b(a){var b=f(a);d("Moving to in page link (#"+c+") at x: "+b.x+" y: "+b.y),H(b.y,b.x,"scrollToOffset")}var c=a.split("#")[1]||a,e=decodeURIComponent(c),g=document.getElementById(e)||document.getElementsByName(e)[0];g?b(g):(d("In page link (#"+c+") not found in iFrame, so sending to parent"),H(0,0,"inPageLink","#"+c))}function h(){""!==location.hash&&"#"!==location.hash&&g(location.href)}function i(){function a(a){function c(a){a.preventDefault(),g(this.getAttribute("href"))}"#"!==a.getAttribute("href")&&b(a,"click",c)}Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'),a)}function j(){b(a,"hashchange",h)}function k(){setTimeout(h,R)}function l(){Array.prototype.forEach&&document.querySelectorAll?(d("Setting up location.hash handlers"),i(),j(),k()):e("In page linking not fully supported in this browser! (See README.md for IE8 workaround)")}return Y.enable?l():d("In page linking not enabled"),{findTarget:g}}function u(){d("Enable public methods"),a.parentIFrame={close:function(){H(0,0,"close")},getId:function(){return bb},moveToAnchor:function(a){Y.findTarget(a)},reset:function(){G("parentIFrame.reset")},scrollTo:function(a,b){H(b,a,"scrollTo")},scrollToOffset:function(a,b){H(b,a,"scrollToOffset")},sendMessage:function(a,b){H(0,0,"message",JSON.stringify(a),b)},setHeightCalculationMethod:function(a){V=a,p()},setWidthCalculationMethod:function(a){lb=a,q()},setTargetOrigin:function(a){d("Set targetOrigin: "+a),eb=a},size:function(a,b){var c=""+(a?a:"")+(b?","+b:"");E(),D("size","parentIFrame.size("+c+")",a,b)}}}function v(){0!==Z&&(d("setInterval: "+Z+"ms"),setInterval(function(){D("interval","setInterval: "+Z)},Math.abs(Z)))}function w(a){return void 0===a||0===a}function x(){function b(a){function b(a){var b=D.bind(null,"imageLoad","Image loaded",void 0,void 0);(w(a.height)||w(a.width))&&(d("Attach listerner to "+a.src),a.addEventListener("load",b,!1))}"attributes"===a.type&&"src"===a.attributeName?b(a.target):"childList"===a.type&&Array.prototype.forEach.call(a.target.querySelectorAll("img"),b)}function c(a){D("mutationObserver","mutationObserver: "+a[0].target+" "+a[0].type),b(a[0])}function f(){var a=document.querySelector("body"),b={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0},e=new h(c);d("Enable MutationObserver"),e.observe(a,b)}var g=0>Z,h=a.MutationObserver||a.WebKitMutationObserver;h?g?v():f():(e("MutationObserver not supported in this browser!"),v())}function y(a){function b(a){var b=/^\d+(px)?$/i;if(b.test(a))return parseInt(a,K);var d=c.style.left,e=c.runtimeStyle.left;return c.runtimeStyle.left=c.currentStyle.left,c.style.left=a||0,a=c.style.pixelLeft,c.style.left=d,c.runtimeStyle.left=e,a}var c=document.body,d=0;return"defaultView"in document&&"getComputedStyle"in document.defaultView?(d=document.defaultView.getComputedStyle(c,null),d=null!==d?d[a]:0):d=b(c.currentStyle[a]),parseInt(d,K)}function z(a,b){for(var c=b.length,e=0,f=(new Date).getTime(),g=0;c>g;g++)b[g].getBoundingClientRect()[a]>e&&(e=b[g].getBoundingClientRect()[a]);return f=(new Date).getTime()-f,d("Parsed "+c+" HTML elements"),d("Element position calculated in "+f+"ms"),e}function A(a){return[a.bodyOffset(),a.bodyScroll(),a.documentElementOffset(),a.documentElementScroll()]}function B(a,b){function c(){return e("No tagged elements ("+b+") found on page"),T}var d=document.querySelectorAll("["+b+"]");return 0===d.length?c():z(a,d)}function C(){return document.querySelectorAll("body *")}function D(a,b,c,e){function f(){a in{reset:1,resetPage:1,init:1}||d("Trigger event: "+b)}function g(){T=n,jb=o,H(T,jb,a)}function h(){return hb&&a in Q}function i(){function a(a,b){var c=Math.abs(a-b)<=gb;return!c}return n=void 0!==c?c:nb[V](),o=void 0!==e?e:ob[lb](),a(T,n)||P&&a(jb,o)}function j(){return!(a in{init:1,interval:1,size:1})}function k(){return V in cb||P&&lb in cb}function l(){d("No change in size detected")}function m(){j()&&k()?G(b):a in{interval:1}||(f(),l())}var n,o;h()?d("Trigger event cancelled: "+a):i()||"init"===a?(f(),E(),g()):m()}function E(){hb||(hb=!0,d("Trigger event lock on")),clearTimeout(ib),ib=setTimeout(function(){hb=!1,d("Trigger event lock off"),d("--")},R)}function F(a){T=nb[V](),jb=ob[lb](),H(T,jb,a)}function G(a){var b=V;V=U,d("Reset trigger event: "+a),E(),F("reset"),V=b}function H(a,b,c,e,f){function g(){void 0===f?f=eb:d("Message targetOrigin: "+f)}function h(){var g=a+":"+b,h=bb+":"+g+":"+c+(void 0!==e?":"+e:"");d("Sending message to host page ("+h+")"),fb.postMessage(_+h,f)}g(),h()}function I(b){function c(){return _===(""+b.data).substr(0,ab)}function g(){X=b.data,fb=b.source,f(),S=!1,setTimeout(function(){W=!1},R)}function h(){W?d("Page reset ignored by init"):(d("Page size reset by host page"),F("resetPage"))}function i(){D("resizeParent","Parent window requested size check")}function j(){var a=l();Y.findTarget(a)}function k(){return b.data.split("]")[1].split(":")[0]}function l(){return b.data.split(":")[1]}function m(){return"iFrameResize"in a}function n(){var a=l();d("MessageCallback called from parent: "+a),mb(JSON.parse(a)),d(" --")}function o(){return b.data.split(":")[2]in{"true":1,"false":1}}function p(){switch(k()){case"reset":h();break;case"resize":i();break;case"moveToAnchor":j();break;case"message":n();break;default:m()||o()||e("Unexpected message ("+b.data+")")}}function q(){!1===S?p():o()?g():d('Ignored message of type "'+k()+'". Received before initialization.')}c()&&q()}var J=!0,K=10,L="",M=0,N="",O="",P=!1,Q={resize:1,click:1},R=128,S=!0,T=1,U="bodyOffset",V=U,W=!0,X="",Y={},Z=32,$=!1,_="[iFrameSizer]",ab=_.length,bb="",cb={max:1,min:1,bodyScroll:1,documentElementScroll:1},db="child",eb="*",fb=a.parent,gb=0,hb=!1,ib=null,jb=1,kb="max",lb=kb,mb=function(){e("MessageCallback function not defined")},nb={bodyOffset:function(){return document.body.offsetHeight+y("marginTop")+y("marginBottom")},offset:function(){return nb.bodyOffset()},bodyScroll:function(){return document.body.scrollHeight},documentElementOffset:function(){return document.documentElement.offsetHeight},documentElementScroll:function(){return document.documentElement.scrollHeight},max:function(){return Math.max.apply(null,A(nb))},min:function(){return Math.min.apply(null,A(nb))},grow:function(){return nb.max()},lowestElement:function(){return Math.max(nb.bodyOffset(),z("bottom",C()))},taggedElement:function(){return B("bottom","data-iframe-height")}},ob={bodyScroll:function(){return document.body.scrollWidth},bodyOffset:function(){return document.body.offsetWidth},documentElementScroll:function(){return document.documentElement.scrollWidth},documentElementOffset:function(){return document.documentElement.offsetWidth},scroll:function(){return Math.max(ob.bodyScroll(),ob.documentElementScroll())},max:function(){return Math.max.apply(null,A(ob))},min:function(){return Math.min.apply(null,A(ob))},leftMostElement:function(){return z("left",C())},taggedElement:function(){return B("left","data-iframe-width")}};b(a,"message",I)}(window||{}); | ||
//# sourceMappingURL=iframeResizer.contentWindow.map |
@@ -1,2 +0,2 @@ | ||
/*! iFrame Resizer (iframeSizer.min.js ) - v2.8.10 - 2015-06-21 | ||
/*! iFrame Resizer (iframeSizer.min.js ) - v3.0.0 - 2015-08-04 | ||
* Desc: Force cross domain iframes to size to content. | ||
@@ -8,3 +8,3 @@ * Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame. | ||
!function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!z;a+=1)z=window[b[a]+"RequestAnimationFrame"];z||e(" RequestAnimationFrame not supported")}function c(){var a="Host page";return window.top!==window.self&&(a=window.parentIFrame?window.parentIFrame.getId():"Nested host page"),a}function d(a){return w+"["+c()+"]"+a}function e(a){t&&"object"==typeof window.console&&console.log(d(a))}function f(a){"object"==typeof window.console&&console.warn(d(a))}function g(a){function b(){function a(){k(F),i(),B[G].resizedCallback(F)}g("Height"),g("Width"),l(a,F,"resetPage")}function c(a){var b=a.id;e(" Removing iFrame: "+b),a.parentNode.removeChild(a),B[b].closedCallback(b),delete B[b],e(" --")}function d(){var a=E.substr(x).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function g(a){var b=Number(B[G]["max"+a]),c=Number(B[G]["min"+a]),d=a.toLowerCase(),f=Number(F[d]);if(c>b)throw new Error("Value for min"+a+" can not be greater than max"+a);e(" Checking "+d+" is in range "+c+"-"+b),c>f&&(f=c,e(" Set "+d+" to min value")),f>b&&(f=b,e(" Set "+d+" to max value")),F[d]=""+f}function m(){function b(){function a(){e(" Checking connection is from allowed list of origins: "+d);var a;for(a=0;a<d.length;a++)if(d[a]===c)return!0;return!1}function b(){return e(" Checking connection is from: "+f),c===f}return d.constructor===Array?a():b()}var c=a.origin,d=B[G].checkOrigin,f=F.iframe.src.split("/").slice(0,3).join("/");if(d&&""+c!="null"&&!b())throw new Error("Unexpected message received from: "+c+" for "+F.iframe.id+". Message was: "+a.data+". This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.");return!0}function n(){return w===(""+E).substr(0,x)}function o(){var a=F.type in{"true":1,"false":1,undefined:1};return a&&e(" Ignoring init message from meta parent page"),a}function p(a){return E.substr(E.indexOf(":")+v+a)}function q(a){e(" MessageCallback passed: {iframe: "+F.iframe.id+", message: "+a+"}"),B[G].messageCallback({iframe:F.iframe,message:JSON.parse(a)}),e(" --")}function r(){return null===F.iframe?(f(" IFrame ("+F.id+") not found"),!1):!0}function s(a){var b=a.getBoundingClientRect();return h(),{x:parseInt(b.left,10)+parseInt(y.x,10),y:parseInt(b.top,10)+parseInt(y.y,10)}}function u(a){function b(){y=g,z(),e(" --")}function c(){return{x:Number(F.width)+d.x,y:Number(F.height)+d.y}}var d=a?s(F.iframe):{x:0,y:0},g=c();e(" Reposition requested from iFrame (offset x:"+d.x+" y:"+d.y+")"),window.top!==window.self?window.parentIFrame?a?window.parentIFrame.scrollToOffset(g.x,g.y):window.parentIFrame.scrollTo(F.width,F.height):f(" Unable to scroll to requested position, window.parentIFrame not found"):b()}function z(){!1!==B[G].scrollCallback(y)&&i()}function A(a){function b(a){var b=s(a);e(" Moving to in page link (#"+c+") at x: "+b.x+" y: "+b.y),y={x:b.x,y:b.y},z(),e(" --")}var c=a.split("#")[1]||"",d=decodeURIComponent(c),f=document.getElementById(d)||document.getElementsByName(d)[0];window.top!==window.self?window.parentIFrame?window.parentIFrame.moveToAnchor(c):e(" In page link #"+c+" not found and window.parentIFrame not found"):f?b(f):e(" In page link #"+c+" not found")}function C(){switch(F.type){case"close":c(F.iframe);break;case"message":q(p(6));break;case"scrollTo":u(!1);break;case"scrollToOffset":u(!0);break;case"inPageLink":A(p(9));break;case"reset":j(F);break;case"init":b(),B[G].initCallback(F.iframe);break;default:b()}}function D(a){var b=!0;return B[a]||(b=!1,f(F.type+" No settings for "+a+". Message was: "+E)),b}var E=a.data,F={},G=null;n()&&(F=d(),G=F.id,!o()&&D(G)&&(t=B[G].log,e(" Received: "+E),r()&&m()&&(B[G].firstRun=!1,C())))}function h(){null===y&&(y={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},e(" Get page position: "+y.x+","+y.y))}function i(){null!==y&&(window.scrollTo(y.x,y.y),e(" Set page position: "+y.x+","+y.y),y=null)}function j(a){function b(){k(a),m("reset","reset",a.iframe,a.id)}e(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),h(),l(b,a,"init")}function k(a){function b(b){a.iframe.style[b]=a[b]+"px",e(" IFrame ("+c+") "+b+" set to "+a[b]+"px")}var c=a.iframe.id;B[c].sizeHeight&&b("height"),B[c].sizeWidth&&b("width")}function l(a,b,c){c!==b.type&&z?(e(" Requesting animation frame"),z(a)):a()}function m(a,b,c,d){c&&c.contentWindow?(e("["+a+"] Sending msg to iframe ("+b+")"),c.contentWindow.postMessage(w+b,"*")):(f("["+a+"] IFrame not found"),B[d]&&delete B[d])}function n(b){function c(){function a(a){1/0!==B[o][a]&&0!==B[o][a]&&(n.style[a]=B[o][a]+"px",e(" Set "+a+" = "+B[o][a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(n.id=a="iFrameResizer"+s++,t=(b||{}).log,e(" Added missing iframe ID: "+a+" ("+n.src+")")),a}function f(){e(" IFrame scrolling "+(B[o].scrolling?"enabled":"disabled")+" for "+o),n.style.overflow=!1===B[o].scrolling?"hidden":"auto",n.scrolling=!1===B[o].scrolling?"no":"yes"}function g(){("number"==typeof B[o].bodyMargin||"0"===B[o].bodyMargin)&&(B[o].bodyMarginV1=B[o].bodyMargin,B[o].bodyMargin=""+B[o].bodyMargin+"px")}function h(){return o+":"+B[o].bodyMarginV1+":"+B[o].sizeWidth+":"+B[o].log+":"+B[o].interval+":"+B[o].enablePublicMethods+":"+B[o].autoResize+":"+B[o].bodyMargin+":"+B[o].heightCalculationMethod+":"+B[o].bodyBackground+":"+B[o].bodyPadding+":"+B[o].tolerance+":"+B[o].enableInPageLinks+":"+B[o].resizeFrom}function i(b){a(n,"load",function(){var a=B[o].firstRun;m("iFrame.onload",b,n),!a&&B[o].heightCalculationMethod in A&&j({iframe:n,height:0,width:0,type:"init"})}),m("init",b,n)}function k(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function l(a){a=a||{},B[o]={firstRun:!0},k(a);for(var b in D)D.hasOwnProperty(b)&&(B[o][b]=a.hasOwnProperty(b)?a[b]:D[b]);t=B[o].log}var n=this,o=d(n.id);l(b),f(),c(),g(),i(h())}function o(a,b){null===C&&(C=setTimeout(function(){C=null,a()},b))}function p(){function a(a){return"parent"===B[a].resizeFrom&&B[a].autoResize&&!B[a].firstRun}o(function(){for(var b in B)a(b)&&m("Window resize","resize",document.getElementById(b),b)},66)}function q(){function c(a,b){if(!a.tagName)throw new TypeError("Object is not a valid DOM element");if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");n.call(a,b)}return b(),a(window,"message",g),a(window,"resize",p),function(a,b){switch(typeof b){case"undefined":case"string":Array.prototype.forEach.call(document.querySelectorAll(b||"iframe"),function(b){c(b,a)});break;case"object":c(b,a);break;default:throw new TypeError("Unexpected data type ("+typeof b+").")}}}function r(a){a.fn.iFrameResize=function(a){return this.filter("iframe").each(function(b,c){n.call(c,a)}).end()}}var s=0,t=!1,u="message",v=u.length,w="[iFrameSizer]",x=w.length,y=null,z=window.requestAnimationFrame,A={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},B={},C=null,D={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enableInPageLinks:!1,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,resizeFrom:"parent",scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){},scrollCallback:function(){return!0}};window.jQuery&&r(jQuery),"function"==typeof define&&define.amd?define([],q):"object"==typeof module&&"object"==typeof module.exports?module.exports=q():window.iFrameResize=window.iFrameResize||q()}(); | ||
!function(a){"use strict";function b(b,c,d){"addEventListener"in a?b.addEventListener(c,d,!1):"attachEvent"in a&&b.attachEvent("on"+c,d)}function c(){var b,c=["moz","webkit","o","ms"];for(b=0;b<c.length&&!A;b+=1)A=a[c[b]+"RequestAnimationFrame"];A||f(" RequestAnimationFrame not supported")}function d(){var b="Host page";return a.top!==a.self&&(b=a.parentIFrame?a.parentIFrame.getId():"Nested host page"),b}function e(a){return x+"["+d()+"]"+a}function f(b){u&&"object"==typeof a.console&&console.log(e(b))}function g(b){"object"==typeof a.console&&console.warn(e(b))}function h(b){function c(){function a(){l(I),j()}h("Height"),h("Width"),m(a,I,"resetPage")}function d(a){var b=a.id;f(" Removing iFrame: "+b),a.parentNode.removeChild(a),C[b].closedCallback(b),delete C[b],f(" --")}function e(){var a=H.substr(y).split(":");return{iframe:C[a[0]].iframe,id:a[0],height:a[1],width:a[2],type:a[3]}}function h(a){var b=Number(C[J]["max"+a]),c=Number(C[J]["min"+a]),d=a.toLowerCase(),e=Number(I[d]);if(c>b)throw new Error("Value for min"+a+" can not be greater than max"+a);f(" Checking "+d+" is in range "+c+"-"+b),c>e&&(e=c,f(" Set "+d+" to min value")),e>b&&(e=b,f(" Set "+d+" to max value")),I[d]=""+e}function o(){function a(){function a(){f(" Checking connection is from allowed list of origins: "+d);var a;for(a=0;a<d.length;a++)if(d[a]===c)return!0;return!1}function b(){var a=C[J].remoteHost;return f(" Checking connection is from: "+a),c===a}return d.constructor===Array?a():b()}var c=b.origin,d=C[J].checkOrigin;if(d&&""+c!="null"&&!a())throw new Error("Unexpected message received from: "+c+" for "+I.iframe.id+". Message was: "+b.data+". This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.");return!0}function p(){return x===(""+H).substr(0,y)&&H.substr(y).split(":")[0]in C}function q(){var a=I.type in{"true":1,"false":1,undefined:1};return a&&f(" Ignoring init message from meta parent page"),a}function r(a){return H.substr(H.indexOf(":")+w+a)}function s(a){f(" MessageCallback passed: {iframe: "+I.iframe.id+", message: "+a+"}"),C[J].messageCallback({iframe:I.iframe,message:JSON.parse(a)}),f(" --")}function t(){return null===I.iframe?(g(" IFrame ("+I.id+") not found"),!1):!0}function v(a){var b=a.getBoundingClientRect();return i(),{x:parseInt(b.left,10)+parseInt(z.x,10),y:parseInt(b.top,10)+parseInt(z.y,10)}}function A(b){function c(){z=h,B(),f(" --")}function d(){return{x:Number(I.width)+e.x,y:Number(I.height)+e.y}}var e=b?v(I.iframe):{x:0,y:0},h=d();f(" Reposition requested from iFrame (offset x:"+e.x+" y:"+e.y+")"),a.top!==a.self?a.parentIFrame?a.parentIFrame["scrollTo"+(b?"Offset":"")](h.x,h.y):g(" Unable to scroll to requested position, window.parentIFrame not found"):c()}function B(){!1!==C[J].scrollCallback(z)&&j()}function D(b){function c(a){var b=v(a);f(" Moving to in page link (#"+d+") at x: "+b.x+" y: "+b.y),z={x:b.x,y:b.y},B(),f(" --")}var d=b.split("#")[1]||"",e=decodeURIComponent(d),g=document.getElementById(e)||document.getElementsByName(e)[0];a.top!==a.self?a.parentIFrame?a.parentIFrame.moveToAnchor(d):f(" In page link #"+d+" not found and window.parentIFrame not found"):g?c(g):f(" In page link #"+d+" not found")}function E(){switch(C[J].firstRun&&G(),I.type){case"close":d(I.iframe);break;case"message":s(r(6));break;case"scrollTo":A(!1);break;case"scrollToOffset":A(!0);break;case"inPageLink":D(r(9));break;case"reset":k(I);break;case"init":c(),C[J].initCallback(I.iframe),C[J].resizedCallback(I);break;default:c(),C[J].resizedCallback(I)}}function F(a){var b=!0;return C[a]||(b=!1,g(I.type+" No settings for "+a+". Message was: "+H)),b}function G(){C[J].firstRun=!1,Function.prototype.bind&&(C[J].iframe.iFrameResizer={close:d.bind(null,C[J].iframe),resize:n.bind(null,"Window resize","resize",C[J].iframe),moveToAnchor:function(a){n("Move to anchor","inPageLink:"+a,C[J].iframe,J)},sendMessage:function(a){a=JSON.stringify(a),n("Send Message","message:"+a,C[J].iframe,J)}})}var H=b.data,I={},J=null;p()?(I=e(),J=I.id,!q()&&F(J)&&(u=C[J].log,f(" Received: "+H),t()&&o()&&E())):f(" Ignored: "+H)}function i(){null===z&&(z={x:void 0!==a.pageXOffset?a.pageXOffset:document.documentElement.scrollLeft,y:void 0!==a.pageYOffset?a.pageYOffset:document.documentElement.scrollTop},f(" Get page position: "+z.x+","+z.y))}function j(){null!==z&&(a.scrollTo(z.x,z.y),f(" Set page position: "+z.x+","+z.y),z=null)}function k(a){function b(){l(a),n("reset","reset",a.iframe,a.id)}f(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),i(),m(b,a,"init")}function l(a){function b(b){a.iframe.style[b]=a[b]+"px",f(" IFrame ("+c+") "+b+" set to "+a[b]+"px")}var c=a.iframe.id;C[c].sizeHeight&&b("height"),C[c].sizeWidth&&b("width")}function m(a,b,c){c!==b.type&&A?(f(" Requesting animation frame"),A(a)):a()}function n(a,b,c,d){c&&c.contentWindow?(f("["+a+"] Sending msg to iframe ("+b+")"),c.contentWindow.postMessage(x+b,C[d||c.id].targetOrigin)):(g("["+a+"] IFrame not found"),C[d]&&delete C[d])}function o(a,c){function d(){function b(b){1/0!==C[v][b]&&0!==C[v][b]&&(a.style[b]=C[v][b]+"px",f(" Set "+b+" = "+C[v][b]+"px"))}b("maxHeight"),b("minHeight"),b("maxWidth"),b("minWidth")}function e(b){return""===b&&(a.id=b="iFrameResizer"+t++,u=(c||{}).log,f(" Added missing iframe ID: "+b+" ("+a.src+")")),b}function h(){f(" IFrame scrolling "+(C[v].scrolling?"enabled":"disabled")+" for "+v),a.style.overflow=!1===C[v].scrolling?"hidden":"auto",a.scrolling=!1===C[v].scrolling?"no":"yes"}function i(){("number"==typeof C[v].bodyMargin||"0"===C[v].bodyMargin)&&(C[v].bodyMarginV1=C[v].bodyMargin,C[v].bodyMargin=""+C[v].bodyMargin+"px")}function j(){return v+":"+C[v].bodyMarginV1+":"+C[v].sizeWidth+":"+C[v].log+":"+C[v].interval+":"+C[v].enablePublicMethods+":"+C[v].autoResize+":"+C[v].bodyMargin+":"+C[v].heightCalculationMethod+":"+C[v].bodyBackground+":"+C[v].bodyPadding+":"+C[v].tolerance+":"+C[v].inPageLinks+":"+C[v].resizeFrom+":"+C[v].widthCalculationMethod}function l(){var b=C[v].firstRun,c=C[v].heightCalculationMethod in B;!b&&c&&k({iframe:a,height:0,width:0,type:"init"})}function m(c){function d(){n("iFrame.onload",c,a),l()}b(a,"load",d),n("init",c,a)}function o(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function p(a){for(var b in E)E.hasOwnProperty(b)&&(C[v][b]=a.hasOwnProperty(b)?a[b]:E[b])}function q(a){return"file://"===a?"*":a}function r(b){b=b||{},C[v]={firstRun:!0,iframe:a,remoteHost:a.src.split("/").slice(0,3).join("/")},o(b),p(b),C[v].targetOrigin=!0===C[v].checkOrigin?q(C[v].remoteHost):"*",u=C[v].log}function s(){return v in C}var v=e(a.id);s()?g(" Ignored iFrame, already setup."):(r(c),h(),d(),i(),m(j()))}function p(a,b){null===D&&(D=setTimeout(function(){D=null,a()},b))}function q(){function c(a){p(function(){e("Window "+a,"resize")},66)}function d(){"hidden"!==document.visibilityState&&e("Tab Visable","resize")}function e(a,b){function c(a){return"parent"===C[a].resizeFrom&&C[a].autoResize&&!C[a].firstRun}for(var d in C)c(d)&&n(a,b,document.getElementById(d),d)}b(a,"message",h),b(a,"resize",function(){c("resize")}),b(document,"visibilitychange",d),b(document,"-webkit-visibilitychange",d),b(a,"focusin",function(){c("focus")})}function r(){function a(a,b){if(!b.tagName)throw new TypeError("Object is not a valid DOM element");if("IFRAME"!==b.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+b.tagName+">.");o(b,a)}return c(),q(),function(b,c){switch(typeof c){case"undefined":case"string":Array.prototype.forEach.call(document.querySelectorAll(c||"iframe"),a.bind(void 0,b));break;case"object":a(b,c);break;default:throw new TypeError("Unexpected data type ("+typeof c+").")}}}function s(a){a.fn.iFrameResize=function(a){return this.filter("iframe").each(function(b,c){o(c,a)}).end()}}var t=0,u=!1,v="message",w=v.length,x="[iFrameSizer]",y=x.length,z=null,A=a.requestAnimationFrame,B={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},C={},D=null,E={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,inPageLinks:!1,enablePublicMethods:!0,heightCalculationMethod:"bodyOffset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,resizeFrom:"parent",scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,widthCalculationMethod:"scroll",closedCallback:function(){},initCallback:function(){},messageCallback:function(){g("MessageCallback function not defined")},resizedCallback:function(){},scrollCallback:function(){return!0}};a.jQuery&&s(jQuery),"function"==typeof define&&define.amd?define([],r):"object"==typeof module&&"object"==typeof module.exports?module.exports=r():a.iFrameResize=a.iFrameResize||r()}(window||{}); | ||
//# sourceMappingURL=iframeResizer.map |
{ | ||
"name": "iframe-resizer", | ||
"version": "2.8.10", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/davidjbradshaw/iframe-resizer", | ||
@@ -5,0 +5,0 @@ "authors": [ |
177
README.md
@@ -15,4 +15,4 @@ # iFrame Resizer | ||
* Detects events that can cause the page to resize (Window Resize, CSS Animation and Transition, Device Orientation and Mouse events). | ||
* Simplified messaging from iFrame to host page via [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage). | ||
* Fixes in page links in iFrame and supports links from the iFrame to the parent page. | ||
* Simplified messaging between iFrame abd host page via [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage). | ||
* Fixes in page links in iFrame and supports links between the iFrame and parent page. | ||
* Provides custom sizing and scrolling methods. | ||
@@ -42,3 +42,4 @@ * Works with [ViewerJS](http://viewerjs.org/) to support PDF and ODF documents. | ||
```html | ||
<iframe src="http://anotherdomain.com/iframe.html" width="100%" scrolling="no"></iframe> | ||
<style>iframe{width:100%}</style> | ||
<iframe src="http://anotherdomain.com/iframe.html" scrolling="no"></iframe> | ||
<script>iFrameResize({log:true})</script> | ||
@@ -91,3 +92,3 @@ ``` | ||
### enableInPageLinks | ||
### inPageLinks | ||
@@ -99,9 +100,2 @@ default: false | ||
### enablePublicMethods | ||
default: false | ||
type: boolean | ||
If enabled, a `window.parentIFrame` object is created in the iFrame that contains methods outlined [below](#iframe-methods). | ||
### interval | ||
@@ -120,5 +114,5 @@ | ||
default: 'bodyOffset' | ||
values: 'bodyOffset' | 'bodyScroll' | 'documentElementOffset' | 'documentElementScroll' | | ||
'max' | 'min' | 'grow' | 'lowestElement' | ||
default: 'bodyOffset' | ||
values: 'bodyOffset' | 'bodyScroll' | 'documentElementOffset' | 'documentElementScroll' | | ||
'max' | 'min' | 'grow' | 'lowestElement' | 'taggedElement' | ||
@@ -136,6 +130,7 @@ By default the height of the iFrame is calculated by converting the margin of the `body` to <i>px</i> and then adding the top and bottom figures to the offsetHeight of the `body` tag. | ||
* **lowestElement** Loops though every element in the the DOM and finds the lowest bottom point <sup>†</sup> | ||
* **taggedElement** Finds the bottom of the lowest element with a `data-iframe-height` attribute | ||
<i>Notes:</i> | ||
<i>**If the default option doesn't work then the best solution is often to use** lowestElement **in modern browsers and** max **in IE10 downwards.**</i> | ||
<i>**If the default option doesn't work then the best solutions is to either to use** taggedElement, **or to use** lowestElement **in modern browsers and** max **in IE10 downwards.**</i> | ||
@@ -150,3 +145,3 @@ ```js | ||
<sup> † </sup> <i>The **lowestElement** option is the most reliable way of determining the page height. However, it does have a performance impact in older versions of IE. In one screen refresh (16ms) Chrome can calculate the position of around 10,000 html nodes, whereas IE 8 can calculate approximately 50. It is recommend to fallback to **max** or **grow** in IE10 and below.</i> | ||
<sup> † </sup> <i>The **lowestElement** option is the most reliable way of determining the page height. However, it does have a performance impact in older versions of IE. In one screen refresh (16ms) Chrome can calculate the position of around 10,000 html nodes, whereas IE 8 can calculate approximately 50. The **taggedElement** option provides much greater performance by limiting the number of elements that need their position checked.</i> | ||
@@ -173,3 +168,3 @@ <sup> * </sup><i>The **bodyScroll**, **documentElementScroll**, **max** and **min** options can cause screen flicker and will prevent the [interval](#interval) trigger downsizing the iFrame when the content shrinks. This is mainly an issue in IE 10 and below, where the [mutationObserver](https://developer.mozilla.org/en/docs/Web/API/MutationObserver) event is not supported. To overcome this you need to manually trigger a page resize by calling the [parentIFrame.size()](#size-customheight-customwidth) method when you remove content from the page.</i> | ||
default: 'parent' | ||
values: 'parent', 'child' | ||
values: 'parent', 'child' | ||
@@ -207,3 +202,28 @@ Listen for resize events from the parent page, or the iFrame. Select the 'child' value if the iFrame can be resized independently of the browser window. <i>Selecting this value can cause issues with some height calculation methods on mobile devices</i>. | ||
### widthCalculationMethod | ||
default: 'scroll' | ||
values: 'bodyOffset' | 'bodyScroll' | 'documentElementOffset' | 'documentElementScroll' | | ||
'max' | 'min' | 'scroll' | 'leftMostElement' | 'taggedElement' | ||
By default the width of the page is worked out by taking the greater of the **documentElement** and **body** scrollWidth values. | ||
Some CSS technics may require you to change this setting to one of the following options. Each can give different values depending on how CSS is used in the page and each has varying side-effects. You will need to experiment to see which is best for any particular circumstance. | ||
* **bodyOffset** uses `document.body.offsetWidth` | ||
* **bodyScroll** uses `document.body.scrollWidth` <sup>*</sup> | ||
* **documentElementOffset** uses `document.documentElement.offsetWidth` | ||
* **documentElementScroll** uses `document.documentElement.scrollWidth` <sup>*</sup> | ||
* **scroll** takes the largest value of the two scroll options | ||
* **max** takes the largest value of the main four options <sup>*</sup> | ||
* **min** takes the smallest value of the main four options <sup>*</sup> | ||
* **leftMostElement** Loops though every element in the the DOM and finds the left most point <sup>†</sup> | ||
* **taggedElement** Finds the left most element with a `data-iframe-width` attribute | ||
<sup> † </sup> <i>The **leftMostElement** option is the most reliable way of determining the page width. However, it does have a performance impact in older versions of IE. In one screen refresh (16ms) Chrome can calculate the position of around 10,000 html nodes, whereas IE 8 can calculate approximately 50. The **taggedElement** option provides much greater performance by limiting the number of elements that need their position checked.</i> | ||
<sup> * </sup><i>The **bodyScroll**, **documentElementScroll**, **max** and **min** options can cause screen flicker and will prevent the [interval](#interval) trigger downsizing the iFrame when the content shrinks. This is mainly an issue in IE 10 and below, where the [mutationObserver](https://developer.mozilla.org/en/docs/Web/API/MutationObserver) event is not supported. To overcome this you need to manually trigger a page resize by calling the [parentIFrame.size()](#size-customheight-customwidth) method when you remove content from the page.</i> | ||
## Callback Methods | ||
@@ -242,6 +262,42 @@ | ||
## IFrame Methods | ||
To enable these methods you must set [enablePublicMethods](#enablepublicmethods) to **true**. This creates the `window.parentIFrame` object in the iFrame. These method should be contained by a test for the `window.parentIFrame` object, in case the page is not loaded inside an iFrame. For example: | ||
## IFrame Page Options | ||
The following options can be set from within the iFrame page by creating a `window.iFrameResizer` object before the JavaScript file is loaded into the page. | ||
```html | ||
<script> | ||
window.iFrameResizer = { | ||
targetOrigin: 'http://mydomain.com' | ||
} | ||
</script> | ||
<script src="js/iframeresizer.contentwindow.js"></script> | ||
``` | ||
### targetOrigin | ||
default: '*' | ||
type: string | ||
This option allows you to restrict the domain of the parent page, to prevent other sites mimicing your parent page. | ||
### messageCallback | ||
type: function (message) | ||
Receive message posted from the parent page with the `iframe.iFrameResizer.sendMessage()` method (See below for details). | ||
### heightCalculationMethod / widthCalculationMethod | ||
default: null | ||
type: string | ||
These options can be used to override the option set in the parent page (See above for details on available values). This can be useful when moving between pages in the iFrame that require different values for these options. | ||
## IFrame Page Methods | ||
These methods are available in the iFrame via the `window.parentIFrame` object. These method should be contained by a test for the `window.parentIFrame` object, in case the page is not loaded inside an iFrame. For example: | ||
```js | ||
@@ -298,2 +354,25 @@ if ('parentIFrame' in window) { | ||
##IFrame Object Methods | ||
Once the iFrame has been initialized, an `iFrameResizer` object is bound to it. This has the following methods available. | ||
### close() | ||
Remove the iFrame from the page. | ||
### moveToAnchor(anchor) | ||
Move to anchor in iFrame. | ||
### resize() | ||
Tell the iFrame to resize itself. | ||
### sendMessage(message,[targetOrigin]) | ||
Send data to the containing page, `message` can be any data type that can be serialized into JSON. The `targetOrigin` option is used to restrict where the message is sent to, in case you iFrame navigates away to another domain. | ||
## Troubleshooting | ||
@@ -312,3 +391,3 @@ | ||
### IFrame not downsizing | ||
The most likely cause of this problem is having set the height of an element to be 100% of the page somewhere in your CSS. This is normally on the `html` or `body` elements, but it could be on any element in the page. | ||
The most likely cause of this problem is having set the height of an element to be 100% of the page somewhere in your CSS. This is normally on the `html` or `body` elements, but it could be on any element in the page. This can sometimes be got around by using the `taggedElement` height calculation method and added a `data-iframe-height` attribute to the element that you want to define the bottom position of the page. You may find it useful to use `position: relative` on this element to define a bottom margin or allow space for a floating footer. | ||
@@ -325,3 +404,3 @@ Not having a valid [HTML document type](http://en.wikipedia.org/wiki/Document_type_declaration) in the iFrame can also sometimes prevent downsizing. At it's most simplest this can be the following. | ||
### IFrame not detecting CSS :hover events | ||
If your page resizes via CSS `:hover` events, these won't be detected by default. It is however possible to create `mouseover` and `mouseout` event listeners on the elements that are resized via CSS and have these events call the [parentIFrame.size()](##parentiframesize-customheight-customwidth) method. With jQuery this can be done as follows, once you have set the [enablePublicMethods](#enablepublicmethods) option to **true**. | ||
If your page resizes via CSS `:hover` events, these won't be detected by default. It is however possible to create `mouseover` and `mouseout` event listeners on the elements that are resized via CSS and have these events call the [parentIFrame.size()](##parentiframesize-customheight-customwidth) method. With jQuery this can be done as follows | ||
@@ -339,2 +418,22 @@ ```js | ||
### IFrame not detecting textarea resizes | ||
Both FireFox and the WebKit based browsers allow the user to resize `textarea` input boxes. Unfortunately the WebKit browsers don't trigger the mutation event when this happens. This can be worked around to some extent with the following code. | ||
```js | ||
function store(){ | ||
this.x = this.offsetWidth; | ||
this.y = this.offsetHeight; | ||
} | ||
$('textarea').each(store).on('mouseover mouseout',function(){ | ||
if (this.offsetWidth !== this.x || this.offsetHeight !== this.y){ | ||
store.call(this); | ||
if ('parentIFrame' in window){ | ||
parentIFrame.size(); | ||
} | ||
} | ||
}); | ||
``` | ||
### IFrame flickers | ||
@@ -349,3 +448,3 @@ | ||
iFrameResize( { | ||
iFrameResize({ | ||
heightCalculationMethod: isOldIE ? 'max' : 'lowestElement', | ||
@@ -358,3 +457,3 @@ minSize:100 | ||
### ParentIFrame not found errors | ||
To call methods in the iFrame, you need to set the [enablePublicMethods](#enablepublicmethods) option to **true**. The `parentIFrame` object then becomes available once the iFrame has been initially resized. If you wish to use it during page load you will need to poll for it becoming available. | ||
The `parentIFrame` object becomes is created once the iFrame has been initially resized. If you wish to use it during page load you will need to poll for it becoming available. | ||
@@ -382,37 +481,21 @@ ```js | ||
Works with all browsers which support [window.postMessage](http://caniuse.com/#feat=x-doc-messaging) (IE8+). | ||
Basic support works with all browsers which support [window.postMessage](http://caniuse.com/#feat=x-doc-messaging) (IE8+). Some advanced features require the native version polyfil to work in IE8. | ||
### Native version | ||
Additionally requires support for [Array.prototype.forEach](http://kangax.github.io/es5-compat-table/#Array.prototype.forEach) (IE9+) and [document.querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document.querySelectorAll) (IE8 Standards Mode). For **IE8** force [Standards Mode](http://en.wikipedia.org/wiki/Internet_Explorer_8#Standards_mode), | ||
Additionally requires support for [Array.prototype.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) and [Function.prototype.bind](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind) (IE9+), plus [document.querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document.querySelectorAll) (IE8 Standards Mode). For **IE8** force [Standards Mode](http://en.wikipedia.org/wiki/Internet_Explorer_8#Standards_mode) and include the [IE8 PolyFils](https://github.com/davidjbradshaw/iframe-resizer/blob/master/src/ie8.polyfils.js) on the host page. | ||
```html | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<!--[if lte IE 8]> | ||
<script type="text/javascript" src="../js/ie8.polyfils.min.js"></script> | ||
<![endif]--> | ||
``` | ||
and use the [MDN PolyFill](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) on the host page. | ||
```js | ||
if (!Array.prototype.forEach){ | ||
Array.prototype.forEach = function(fun /*, thisArg */){ | ||
"use strict"; | ||
if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError(); | ||
var | ||
t = Object(this), | ||
len = t.length >>> 0, | ||
thisArg = arguments.length >= 2 ? arguments[1] : void 0; | ||
for (var i = 0; i < len; i++) | ||
if (i in t) | ||
fun.call(thisArg, t[i], i, t); | ||
}; | ||
} | ||
``` | ||
## Version History | ||
* v3.0.0 Added *taggedElement* size calculation method. [#199](https://github.com/davidjbradshaw/iframe-resizer/issues/199) Added in page options to iFrame. [#70](https://github.com/davidjbradshaw/iframe-resizer/issues/70) Added width calculation method options. Added methods to bound iFrames to comunicate from parent to iFrame. Ignore calls to setup an already bound iFrame. Improved event handling. Refactored MutationObserver functions. Moved IE8 polyfil from docs to own JS file and added *Funtion.prototype.bind()*. Added detection for tab focus. Fixed bug with nested inPageLinks. Public methods in iFrame now always enabled and option removed. Renamed enableInPageLinks to inPageLinks. Added double iFrame example. | ||
* v2.8.10 Fixed bug with resizeFrom option not having default value in iFrame, if called from old version in parent page. | ||
* v2.8.9 [#220](https://github.com/davidjbradshaw/iframe-resizer/issues/220) Switched from using deviceorientation to orientationchange event listner [[Brandon Kobel](https://github.com/kobelb)]. | ||
* v2.8.9 [#220](https://github.com/davidjbradshaw/iframe-resizer/issues/220) Switched from using *deviceorientation* to *orientationchange* event listner [[Brandon Kobel](https://github.com/kobelb)]. | ||
* v2.8.8 [#213](https://github.com/davidjbradshaw/iframe-resizer/issues/213) Ensure initCallback fires when iFrame not sized during initialisation. Check autoResize option before resizing from parent. Lower message about resize before initialisation from 'warn' to 'log'. Updated hover example. | ||
@@ -443,3 +526,3 @@ * v2.8.7 [#205](https://github.com/davidjbradshaw/iframe-resizer/issues/205) Fix race condition when page resized during page init [[Ian Caunce](https://github.com/IanCaunce)]. [#203](https://github.com/davidjbradshaw/iframe-resizer/issues/203) Added option for *checkOrigin* to have list of allowed domains for the iFrame [[Andrej Golcov](https://github.com/andrej2k)]. [#202](https://github.com/davidjbradshaw/iframe-resizer/issues/202) Handle script being loaded more than once [[Nickolay Ribal](https://github.com/elektronik2k5)]. | ||
* v2.4.5 [#41](https://github.com/davidjbradshaw/iframe-resizer/issues/41) Prevent error in FireFox when body is hidden by CSS [[Scott Otis](/Scotis)]. | ||
* v2.4.4 Enable nested iFrames ([#31](https://github.com/davidjbradshaw/iframe-resizer/issues/31) Filter incoming iFrame message in host-page script. [#33](https://github.com/davidjbradshaw/iframe-resizer/issues/33) Squash unexpected message warning when using nested iFrames. Improved logging for nested iFrames). [#38](https://github.com/davidjbradshaw/iframe-resizer/issues/38) Detect late image loads that cause a resize due to async image loading in WebKit [[Yassin](/ynh)]. Fixed :Hover example in FireFox. Increased trigger timeout lock to 64ms. | ||
* v2.4.4 Enable nested iFrames ([#31](https://github.com/davidjbradshaw/iframe-resizer/issues/31) Filter incoming iFrame message in host-page script. [#33](https://github.com/davidjbradshaw/iframe-resizer/issues/33) Squash unexpected message warning when using nested iFrames. Improved logging for nested iFrames). [#38](https://github.com/davidjbradshaw/iframe-resizer/issues/38) Detect late image loads that cause a resize due to async image loading in WebKit [[Yassin](/ynh)]. Fixed :Hover example in FireFox. Increased trigger timeout lock to 64ms. | ||
* v2.4.3 Simplified handling of double fired events. Fixed test coverage. | ||
@@ -446,0 +529,0 @@ * v2.4.2 Fix missing 'px' unit when resetting height. |
@@ -12,3 +12,3 @@ /* | ||
;(function() { | ||
;(function(window) { | ||
'use strict'; | ||
@@ -28,3 +28,3 @@ | ||
height = 1, | ||
heightCalcModeDefault = 'offset', | ||
heightCalcModeDefault = 'bodyOffset', | ||
heightCalcMode = heightCalcModeDefault, | ||
@@ -39,4 +39,4 @@ initLock = true, | ||
myID = '', | ||
publicMethods = false, | ||
resetRequiredMethods = {max:1,scroll:1,bodyScroll:1,documentElementScroll:1}, | ||
//publicMethods = true, | ||
resetRequiredMethods = {max:1,min:1,bodyScroll:1,documentElementScroll:1}, | ||
resizeFrom = 'child', | ||
@@ -48,3 +48,6 @@ targetOriginDefault = '*', | ||
triggerLockedTimer = null, | ||
width = 1; | ||
width = 1, | ||
widthCalcModeDefault = 'max', | ||
widthCalcMode = widthCalcModeDefault, | ||
messageCallback = function(){warn('MessageCallback function not defined');}; | ||
@@ -78,4 +81,5 @@ | ||
function init(){ | ||
log('Initialising iFrame'); | ||
readData(); | ||
readDataFromParent(); | ||
log('Initialising iFrame ('+location.href+')'); | ||
readDataFromPage(); | ||
setMargin(); | ||
@@ -86,2 +90,3 @@ setBodyStyle('background',bodyBackground); | ||
checkHeightMode(); | ||
checkWidthMode(); | ||
stopInfiniteResizingOfIFrame(); | ||
@@ -94,6 +99,4 @@ setupPublicMethods(); | ||
function readData(){ | ||
function readDataFromParent(){ | ||
var data = initMsg.substr(msgIdLen).split(':'); | ||
function strBool(str){ | ||
@@ -103,2 +106,4 @@ return 'true' === str ? true : false; | ||
var data = initMsg.substr(msgIdLen).split(':'); | ||
myID = data[0]; | ||
@@ -109,3 +114,3 @@ bodyMargin = (undefined !== data[1]) ? Number(data[1]) : bodyMargin; //For V1 compatibility | ||
interval = (undefined !== data[4]) ? Number(data[4]) : interval; | ||
publicMethods = (undefined !== data[5]) ? strBool(data[5]) : publicMethods; | ||
//publicMethods = (undefined !== data[5]) ? strBool(data[5]) : publicMethods; | ||
autoResize = (undefined !== data[6]) ? strBool(data[6]) : autoResize; | ||
@@ -119,4 +124,23 @@ bodyMarginStr = data[7]; | ||
resizeFrom = (undefined !== data[13]) ? data[13] : resizeFrom; | ||
widthCalcMode = (undefined !== data[14]) ? data[14] : widthCalcMode; | ||
} | ||
function readDataFromPage(){ | ||
function readData(){ | ||
var data = window.iFrameResizer; | ||
log('Reading data from page: ' + JSON.stringify(data)); | ||
messageCallback = (undefined !== data.messageCallback ) ? data.messageCallback : messageCallback; | ||
targetOriginDefault = (undefined !== data.targetOrigin ) ? data.targetOrigin : targetOriginDefault; | ||
heightCalcMode = (undefined !== data.heightCalculationMethod ) ? data.heightCalculationMethod : heightCalcMode; | ||
widthCalcMode = (undefined !== data.widthCalculationMethod ) ? data.widthCalculationMethod : widthCalcMode; | ||
} | ||
if(('iFrameResizer' in window) && (Object === window.iFrameResizer.constructor)) { | ||
readData(); | ||
} | ||
} | ||
function chkCSS(attr,value){ | ||
@@ -155,5 +179,7 @@ if (-1 !== value.indexOf('-')){ | ||
function addListener(eventName){ | ||
addEventListener(window,eventName,function(){ | ||
function handleEvent(){ | ||
sendSize(options.eventName,options.eventType); | ||
}); | ||
} | ||
addEventListener(window,eventName,handleEvent); | ||
} | ||
@@ -175,7 +201,9 @@ | ||
addTriggerEvent({ eventType: 'Animation End', eventNames: ['animationend','webkitAnimationEnd'] }); | ||
addTriggerEvent({ eventType: 'Device Orientation Change', eventName: 'orientationchange' }); | ||
addTriggerEvent({ eventType: 'Orientation Change', eventName: 'orientationchange' }); | ||
addTriggerEvent({ eventType: 'Input', eventName: 'input' }); | ||
//addTriggerEvent({ eventType: 'Drag', eventName: 'drag' }); | ||
addTriggerEvent({ eventType: 'Print', eventName: ['afterprint', 'beforeprint'] }); | ||
addTriggerEvent({ eventType: 'Transition End', eventNames: ['transitionend','webkitTransitionEnd','MSTransitionEnd','oTransitionEnd','otransitionend'] }); | ||
addTriggerEvent({ eventType: 'Window Clicked', eventName: 'click' }); | ||
//addTriggerEvent({ eventType: 'Window Mouse Down', eventName: 'mousedown' }); | ||
//addTriggerEvent({ eventType: 'Window Mouse Up', eventName: 'mouseup' }); | ||
//addTriggerEvent({ eventType: 'Window Clicked', eventName: 'click' }); | ||
addTriggerEvent({ eventType: 'Mouse Up', eventName: 'mouseup' }); | ||
if('child' === resizeFrom){ | ||
@@ -186,12 +214,20 @@ addTriggerEvent({ eventType: 'IFrame Resized', eventName: 'resize' }); | ||
function checkHeightMode(){ | ||
if (heightCalcModeDefault !== heightCalcMode){ | ||
if (!(heightCalcMode in getHeight)){ | ||
warn(heightCalcMode + ' is not a valid option for heightCalculationMethod.'); | ||
heightCalcMode='bodyScroll'; | ||
function checkCalcMode(calcMode,calcModeDefault,modes,type){ | ||
if (calcModeDefault !== calcMode){ | ||
if (!(calcMode in modes)){ | ||
warn(calcMode + ' is not a valid option for '+type+'CalculationMethod.'); | ||
calcMode=calcModeDefault; | ||
} | ||
log('Height calculation method set to "'+heightCalcMode+'"'); | ||
log(type+' calculation method set to "'+calcMode+'"'); | ||
} | ||
} | ||
function checkHeightMode(){ | ||
checkCalcMode(heightCalcMode,heightCalcModeDefault,getHeight,'height'); | ||
} | ||
function checkWidthMode(){ | ||
checkCalcMode(widthCalcMode,widthCalcModeDefault,getWidth,'width'); | ||
} | ||
function startEventListeners(){ | ||
@@ -209,3 +245,3 @@ if ( true === autoResize ) { | ||
var clearFix = document.createElement('div'); | ||
clearFix.style.clear = 'both'; | ||
clearFix.style.clear = 'both'; | ||
clearFix.style.display = 'block'; //Guard against this having been globally redefined in CSS. | ||
@@ -236,5 +272,2 @@ document.body.appendChild(clearFix); | ||
function findTarget(location){ | ||
var hash = location.split("#")[1] || ""; | ||
var hashData = decodeURIComponent(hash); | ||
function jumpToTarget(target){ | ||
@@ -247,3 +280,6 @@ var jumpPosition = getElementPosition(target); | ||
var target = document.getElementById(hashData) || document.getElementsByName(hashData)[0]; | ||
var | ||
hash = location.split('#')[1] || location, //Remove # if present | ||
hashData = decodeURIComponent(hash), | ||
target = document.getElementById(hashData) || document.getElementsByName(hashData)[0]; | ||
@@ -312,3 +348,3 @@ if (target){ | ||
function setupPublicMethods(){ | ||
if (publicMethods) { | ||
//if (publicMethods) { | ||
log('Enable public methods'); | ||
@@ -350,2 +386,7 @@ | ||
setWidthCalculationMethod: function setWidthCalculationMethodF(widthCalculationMethod){ | ||
widthCalcMode = widthCalculationMethod; | ||
checkWidthMode(); | ||
}, | ||
setTargetOrigin: function setTargetOriginF(targetOrigin){ | ||
@@ -362,3 +403,3 @@ log('Set targetOrigin: '+targetOrigin); | ||
}; | ||
} | ||
//} | ||
} | ||
@@ -375,27 +416,33 @@ | ||
function setupInjectElementLoadListners(mutations){ | ||
function addLoadListener(element){ | ||
if (element.height === undefined || element.width === undefined || 0 === element.height || 0 === element.width){ | ||
log('Attach listerner to '+element.src); | ||
addEventListener(element,'load', function imageLoaded(){ | ||
sendSize('imageLoad','Image loaded'); | ||
}); | ||
function isNotSet(item){ | ||
return undefined === item || 0 === item; | ||
} | ||
function setupMutationObserver(){ | ||
function addImageLoadListners(mutation) { | ||
function addImageLoadListener(element){ | ||
var imageLoaded = sendSize.bind(null,'imageLoad','Image loaded',undefined,undefined); | ||
if (isNotSet(element.height) || isNotSet(element.width)) { | ||
log('Attach listerner to ' + element.src); | ||
element.addEventListener('load', imageLoaded, false); | ||
} | ||
} | ||
} | ||
mutations.forEach(function (mutation) { | ||
if (mutation.type === 'attributes' && mutation.attributeName === 'src'){ | ||
addLoadListener(mutation.target); | ||
addImageLoadListener(mutation.target); | ||
} else if (mutation.type === 'childList'){ | ||
var images = mutation.target.querySelectorAll('img'); | ||
Array.prototype.forEach.call(images,function (image) { | ||
addLoadListener(image); | ||
}); | ||
Array.prototype.forEach.call( | ||
mutation.target.querySelectorAll('img'), | ||
addImageLoadListener | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
function setupMutationObserver(){ | ||
function mutationObserved(mutations) { | ||
sendSize('mutationObserver','mutationObserver: ' + mutations[0].target + ' ' + mutations[0].type); | ||
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | ||
//Deal with WebKit asyncing image loading when tags are injected into the page | ||
addImageLoadListners(mutations[0]); | ||
} | ||
@@ -415,6 +462,3 @@ function createMutationObserver(){ | ||
observer = new MutationObserver(function(mutations) { | ||
sendSize('mutationObserver','mutationObserver: ' + mutations[0].target + ' ' + mutations[0].type); | ||
setupInjectElementLoadListners(mutations); //Deal with WebKit asyncing image loading when tags are injected into the page | ||
}); | ||
observer = new MutationObserver(mutationObserved); | ||
@@ -425,4 +469,8 @@ log('Enable MutationObserver'); | ||
var | ||
forceIntervalTimer = 0 > interval, | ||
MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | ||
if (MutationObserver){ | ||
if (0 > interval) { | ||
if (forceIntervalTimer) { | ||
initInterval(); | ||
@@ -442,66 +490,47 @@ } else { | ||
// we have to jump through hoops to get a better value. | ||
function getBodyOffsetHeight(){ | ||
function getComputedBodyStyle(prop) { | ||
function convertUnitsToPxForIE8(value) { | ||
var PIXEL = /^\d+(px)?$/i; | ||
function getComputedBodyStyle(prop) { | ||
function convertUnitsToPxForIE8(value) { | ||
var PIXEL = /^\d+(px)?$/i; | ||
if (PIXEL.test(value)) { | ||
return parseInt(value,base); | ||
} | ||
var | ||
style = el.style.left, | ||
runtimeStyle = el.runtimeStyle.left; | ||
el.runtimeStyle.left = el.currentStyle.left; | ||
el.style.left = value || 0; | ||
value = el.style.pixelLeft; | ||
el.style.left = style; | ||
el.runtimeStyle.left = runtimeStyle; | ||
return value; | ||
if (PIXEL.test(value)) { | ||
return parseInt(value,base); | ||
} | ||
var | ||
el = document.body, | ||
retVal = 0; | ||
style = el.style.left, | ||
runtimeStyle = el.runtimeStyle.left; | ||
if (('defaultView' in document) && ('getComputedStyle' in document.defaultView)) { | ||
retVal = document.defaultView.getComputedStyle(el, null); | ||
retVal = (null !== retVal) ? retVal[prop] : 0; | ||
} else {//IE8 | ||
retVal = convertUnitsToPxForIE8(el.currentStyle[prop]); | ||
} | ||
el.runtimeStyle.left = el.currentStyle.left; | ||
el.style.left = value || 0; | ||
value = el.style.pixelLeft; | ||
el.style.left = style; | ||
el.runtimeStyle.left = runtimeStyle; | ||
return parseInt(retVal,base); | ||
return value; | ||
} | ||
return document.body.offsetHeight + | ||
getComputedBodyStyle('marginTop') + | ||
getComputedBodyStyle('marginBottom'); | ||
} | ||
var | ||
el = document.body, | ||
retVal = 0; | ||
function getBodyScrollHeight(){ | ||
return document.body.scrollHeight; | ||
} | ||
if (('defaultView' in document) && ('getComputedStyle' in document.defaultView)) { | ||
retVal = document.defaultView.getComputedStyle(el, null); | ||
retVal = (null !== retVal) ? retVal[prop] : 0; | ||
} else {//IE8 | ||
retVal = convertUnitsToPxForIE8(el.currentStyle[prop]); | ||
} | ||
function getDEOffsetHeight(){ | ||
return document.documentElement.offsetHeight; | ||
return parseInt(retVal,base); | ||
} | ||
function getDEScrollHeight(){ | ||
return document.documentElement.scrollHeight; | ||
} | ||
//From https://github.com/guardian/iframe-messenger | ||
function getLowestElementHeight() { | ||
//Idea from https://github.com/guardian/iframe-messenger | ||
function getMaxElement(side,elements) { | ||
var | ||
allElements = document.querySelectorAll('body *'), | ||
allElementsLength = allElements.length, | ||
maxBottomVal = 0, | ||
timer = new Date().getTime(); | ||
elementsLength = elements.length, | ||
maxVal = 0, | ||
timer = new Date().getTime(); | ||
for (var i = 0; i < allElementsLength; i++) { | ||
if (allElements[i].getBoundingClientRect().bottom > maxBottomVal) { | ||
maxBottomVal = allElements[i].getBoundingClientRect().bottom; | ||
for (var i = 0; i < elementsLength; i++) { | ||
if (elements[i].getBoundingClientRect()[side] > maxVal) { | ||
maxVal = elements[i].getBoundingClientRect()[side]; | ||
} | ||
@@ -512,53 +541,116 @@ } | ||
log('Parsed '+allElementsLength+' HTML elements'); | ||
log('LowestElement bottom position calculated in ' + timer + 'ms'); | ||
log('Parsed '+elementsLength+' HTML elements'); | ||
log('Element position calculated in ' + timer + 'ms'); | ||
return maxBottomVal; | ||
return maxVal; | ||
} | ||
function getAllHeights(){ | ||
function getAllMeasurements(dimention){ | ||
return [ | ||
getBodyOffsetHeight(), | ||
getBodyScrollHeight(), | ||
getDEOffsetHeight(), | ||
getDEScrollHeight() | ||
dimention.bodyOffset(), | ||
dimention.bodyScroll(), | ||
dimention.documentElementOffset(), | ||
dimention.documentElementScroll() | ||
]; | ||
} | ||
function getMaxHeight(){ | ||
return Math.max.apply(null,getAllHeights()); | ||
} | ||
function getTaggedElements(side,tag){ | ||
function noTaggedElementsFound(){ | ||
warn('No tagged elements ('+tag+') found on page'); | ||
return height; //current height | ||
} | ||
function getMinHeight(){ | ||
return Math.min.apply(null,getAllHeights()); | ||
var elements = document.querySelectorAll('['+tag+']'); | ||
return 0 === elements.length ? noTaggedElementsFound() : getMaxElement(side,elements); | ||
} | ||
function getBestHeight(){ | ||
return Math.max(getBodyOffsetHeight(),getLowestElementHeight()); | ||
function getAllElements(){ | ||
return document.querySelectorAll('body *'); | ||
} | ||
var getHeight = { | ||
offset : getBodyOffsetHeight, //Backward compatability | ||
bodyOffset : getBodyOffsetHeight, | ||
bodyScroll : getBodyScrollHeight, | ||
documentElementOffset : getDEOffsetHeight, | ||
scroll : getDEScrollHeight, //Backward compatability | ||
documentElementScroll : getDEScrollHeight, | ||
max : getMaxHeight, | ||
min : getMinHeight, | ||
grow : getMaxHeight, | ||
lowestElement : getBestHeight | ||
}; | ||
var | ||
getHeight = { | ||
bodyOffset: function getBodyOffsetHeight(){ | ||
return document.body.offsetHeight + getComputedBodyStyle('marginTop') + getComputedBodyStyle('marginBottom'); | ||
}, | ||
function getWidth(){ | ||
return Math.max( | ||
document.documentElement.scrollWidth, | ||
document.body.scrollWidth | ||
); | ||
} | ||
offset: function(){ | ||
return getHeight.bodyOffset(); //Backwards compatability | ||
}, | ||
bodyScroll: function getBodyScrollHeight(){ | ||
return document.body.scrollHeight; | ||
}, | ||
documentElementOffset: function getDEOffsetHeight(){ | ||
return document.documentElement.offsetHeight; | ||
}, | ||
documentElementScroll: function getDEScrollHeight(){ | ||
return document.documentElement.scrollHeight; | ||
}, | ||
max: function getMaxHeight(){ | ||
return Math.max.apply(null,getAllMeasurements(getHeight)); | ||
}, | ||
min: function getMinHeight(){ | ||
return Math.min.apply(null,getAllMeasurements(getHeight)); | ||
}, | ||
grow: function growHeight(){ | ||
return getHeight.max(); //Run max without the forced downsizing | ||
}, | ||
lowestElement: function getBestHeight(){ | ||
return Math.max(getHeight.bodyOffset(), getMaxElement('bottom',getAllElements())); | ||
}, | ||
taggedElement: function getTaggedElementsHeight(){ | ||
return getTaggedElements('bottom','data-iframe-height'); | ||
} | ||
}, | ||
getWidth = { | ||
bodyScroll: function getBodyScrollWidth(){ | ||
return document.body.scrollWidth; | ||
}, | ||
bodyOffset: function getBodyOffsetWidth(){ | ||
return document.body.offsetWidth; | ||
}, | ||
documentElementScroll: function getDEScrollWidth(){ | ||
return document.documentElement.scrollWidth; | ||
}, | ||
documentElementOffset: function getDEOffsetWidth(){ | ||
return document.documentElement.offsetWidth; | ||
}, | ||
scroll: function getMaxWidth(){ | ||
return Math.max(getWidth.bodyScroll(), getWidth.documentElementScroll()); | ||
}, | ||
max: function getMaxWidth(){ | ||
return Math.max.apply(null,getAllMeasurements(getWidth)); | ||
}, | ||
min: function getMinWidth(){ | ||
return Math.min.apply(null,getAllMeasurements(getWidth)); | ||
}, | ||
leftMostElement: function getLeftMostElement(){ | ||
return getMaxElement('left', getAllElements()); | ||
}, | ||
taggedElement: function getTaggedElementsWidth(){ | ||
return getTaggedElements('left', 'data-iframe-width'); | ||
} | ||
}; | ||
function sendSize(triggerEvent, triggerEventDesc, customHeight, customWidth){ | ||
var currentHeight,currentWidth; | ||
function recordTrigger(){ | ||
@@ -588,3 +680,3 @@ if (!(triggerEvent in {'reset':1,'resetPage':1,'init':1})){ | ||
currentHeight = (undefined !== customHeight) ? customHeight : getHeight[heightCalcMode](); | ||
currentWidth = (undefined !== customWidth ) ? customWidth : getWidth(); | ||
currentWidth = (undefined !== customWidth ) ? customWidth : getWidth[widthCalcMode](); | ||
@@ -598,4 +690,4 @@ return checkTolarance(height,currentHeight) || (calculateWidth && checkTolarance(width,currentWidth)); | ||
function isForceResizableHeightCalcMode(){ | ||
return (heightCalcMode in resetRequiredMethods); | ||
function isForceResizableCalcMode(){ | ||
return (heightCalcMode in resetRequiredMethods) || (calculateWidth && widthCalcMode in resetRequiredMethods); | ||
} | ||
@@ -608,3 +700,3 @@ | ||
function checkDownSizing(){ | ||
if (isForceResizableEvent() && isForceResizableHeightCalcMode()){ | ||
if (isForceResizableEvent() && isForceResizableCalcMode()){ | ||
resetIFrame(triggerEventDesc); | ||
@@ -617,2 +709,4 @@ } else if (!(triggerEvent in {'interval':1})){ | ||
var currentHeight,currentWidth; | ||
if (!isDoubleFiredEvent()){ | ||
@@ -646,3 +740,3 @@ if (isSizeChangeDetected() || 'init' === triggerEvent){ | ||
height = getHeight[heightCalcMode](); | ||
width = getWidth(); | ||
width = getWidth[widthCalcMode](); | ||
@@ -709,9 +803,18 @@ sendMsg(height,width,triggerEvent); | ||
function resizeFromParent(){ | ||
sendSize('resizeParent','Parent window resized'); | ||
sendSize('resizeParent','Parent window requested size check'); | ||
} | ||
function moveToAnchor(){ | ||
var anchor = getData(); | ||
inPageLinks.findTarget(anchor); | ||
} | ||
function getMessageType(){ | ||
return event.data.split(']')[1]; | ||
return event.data.split(']')[1].split(':')[0]; | ||
} | ||
function getData(){ | ||
return event.data.split(':')[1]; | ||
} | ||
function isMiddleTier(){ | ||
@@ -721,2 +824,10 @@ return ('iFrameResize' in window); | ||
function messageFromParent(){ | ||
var msgBody = getData(); | ||
log('MessageCallback called from parent: ' + msgBody ); | ||
messageCallback(JSON.parse(msgBody)); | ||
log(' --'); | ||
} | ||
function isInitMsg(){ | ||
@@ -728,16 +839,26 @@ //Test if this message is from a child below us. This is an ugly test, however, updating | ||
if (isMessageForUs()){ | ||
function callFromParent(){ | ||
switch (getMessageType()){ | ||
case 'reset': | ||
resetFromParent(); | ||
break; | ||
case 'resize': | ||
resizeFromParent(); | ||
break; | ||
case 'moveToAnchor': | ||
moveToAnchor(); | ||
break; | ||
case 'message': | ||
messageFromParent(); | ||
break; | ||
default: | ||
if (!isMiddleTier() && !isInitMsg()){ | ||
warn('Unexpected message ('+event.data+')'); | ||
} | ||
} | ||
} | ||
function processMessage(){ | ||
if (false === firstRun) { | ||
switch (getMessageType()){ | ||
case 'reset': | ||
resetFromParent(); | ||
break; | ||
case 'resize': | ||
resizeFromParent(); | ||
break; | ||
default: | ||
if (!isMiddleTier()){ | ||
warn('Unexpected message ('+event.data+')'); | ||
} | ||
} | ||
callFromParent(); | ||
} else if (isInitMsg()) { | ||
@@ -749,2 +870,6 @@ initFromParent(); | ||
} | ||
if (isMessageForUs()){ | ||
processMessage(); | ||
} | ||
} | ||
@@ -754,2 +879,2 @@ | ||
})(); | ||
})(window || {}); |
@@ -10,3 +10,3 @@ /* | ||
*/ | ||
;(function() { | ||
;(function(window) { | ||
'use strict'; | ||
@@ -34,5 +34,5 @@ | ||
checkOrigin : true, | ||
enableInPageLinks : false, | ||
enablePublicMethods : false, | ||
heightCalculationMethod : 'offset', | ||
inPageLinks : false, | ||
enablePublicMethods : true, | ||
heightCalculationMethod : 'bodyOffset', | ||
interval : 32, | ||
@@ -49,5 +49,6 @@ log : false, | ||
tolerance : 0, | ||
widthCalculationMethod : 'scroll', | ||
closedCallback : function(){}, | ||
initCallback : function(){}, | ||
messageCallback : function(){}, | ||
messageCallback : function(){warn('MessageCallback function not defined');}, | ||
resizedCallback : function(){}, | ||
@@ -115,3 +116,2 @@ scrollCallback : function(){return true;} | ||
setPagePosition(); | ||
settings[iframeId].resizedCallback(messageData); | ||
} | ||
@@ -139,3 +139,3 @@ | ||
return { | ||
iframe: document.getElementById(data[0]), | ||
iframe: settings[data[0]].iframe, | ||
id: data[0], | ||
@@ -189,2 +189,3 @@ height: data[1], | ||
function checkSingle(){ | ||
var remoteHost = settings[iframeId].remoteHost; | ||
log(' Checking connection is from: '+remoteHost); | ||
@@ -199,4 +200,3 @@ return origin === remoteHost; | ||
origin = event.origin, | ||
checkOrigin = settings[iframeId].checkOrigin, | ||
remoteHost = messageData.iframe.src.split('/').slice(0,3).join('/'); | ||
checkOrigin = settings[iframeId].checkOrigin; | ||
@@ -218,3 +218,3 @@ if (checkOrigin) { | ||
function isMessageForUs(){ | ||
return msgId === ('' + msg).substr(0,msgIdLen); //''+Protects against non-string msg | ||
return msgId === (('' + msg).substr(0,msgIdLen)) && (msg.substr(msgIdLen).split(':')[0] in settings); //''+Protects against non-string msg | ||
} | ||
@@ -256,4 +256,3 @@ | ||
function getElementPosition(target){ | ||
var | ||
iFramePosition = target.getBoundingClientRect(); | ||
var iFramePosition = target.getBoundingClientRect(); | ||
@@ -271,5 +270,3 @@ getPagePosition(); | ||
pagePosition = newPosition; | ||
scrollTo(); | ||
log(' --'); | ||
@@ -293,7 +290,3 @@ } | ||
if (window.parentIFrame){ | ||
if (addOffset){ | ||
window.parentIFrame.scrollToOffset(newPosition.x,newPosition.y); | ||
} else { | ||
window.parentIFrame.scrollTo(messageData.width,messageData.height); | ||
} | ||
window.parentIFrame['scrollTo'+(addOffset?'Offset':'')](newPosition.x,newPosition.y); | ||
} else { | ||
@@ -347,27 +340,32 @@ warn(' Unable to scroll to requested position, window.parentIFrame not found'); | ||
function actionMsg(){ | ||
if(settings[iframeId].firstRun) firstRun(); | ||
switch(messageData.type){ | ||
case 'close': | ||
closeIFrame(messageData.iframe); | ||
break; | ||
case 'message': | ||
forwardMsgFromIFrame(getMsgBody(6)); | ||
break; | ||
case 'scrollTo': | ||
scrollRequestFromChild(false); | ||
break; | ||
case 'scrollToOffset': | ||
scrollRequestFromChild(true); | ||
break; | ||
case 'inPageLink': | ||
findTarget(getMsgBody(9)); | ||
break; | ||
case 'reset': | ||
resetIFrame(messageData); | ||
break; | ||
case 'init': | ||
resizeIFrame(); | ||
settings[iframeId].initCallback(messageData.iframe); | ||
break; | ||
default: | ||
resizeIFrame(); | ||
case 'close': | ||
closeIFrame(messageData.iframe); | ||
break; | ||
case 'message': | ||
forwardMsgFromIFrame(getMsgBody(6)); | ||
break; | ||
case 'scrollTo': | ||
scrollRequestFromChild(false); | ||
break; | ||
case 'scrollToOffset': | ||
scrollRequestFromChild(true); | ||
break; | ||
case 'inPageLink': | ||
findTarget(getMsgBody(9)); | ||
break; | ||
case 'reset': | ||
resetIFrame(messageData); | ||
break; | ||
case 'init': | ||
resizeIFrame(); | ||
settings[iframeId].initCallback(messageData.iframe); | ||
settings[iframeId].resizedCallback(messageData); | ||
break; | ||
default: | ||
resizeIFrame(); | ||
settings[iframeId].resizedCallback(messageData); | ||
} | ||
@@ -387,2 +385,24 @@ } | ||
function firstRun() { | ||
settings[iframeId].firstRun = false; | ||
if(Function.prototype.bind){ //Ignore unpolyfilled IE8. | ||
settings[iframeId].iframe.iFrameResizer = { | ||
close : closeIFrame.bind(null,settings[iframeId].iframe), | ||
resize : trigger.bind(null,'Window resize', 'resize', settings[iframeId].iframe), | ||
moveToAnchor : function(anchor){ | ||
trigger('Move to anchor','inPageLink:'+anchor, settings[iframeId].iframe,iframeId); | ||
}, | ||
sendMessage : function(message){ | ||
message = JSON.stringify(message); | ||
trigger('Send Message','message:'+message, settings[iframeId].iframe,iframeId); | ||
} | ||
}; | ||
} | ||
} | ||
var | ||
@@ -402,7 +422,9 @@ msg = event.data, | ||
if ( checkIFrameExists() && isMessageFromIFrame() ){ | ||
settings[iframeId].firstRun = false; | ||
actionMsg(); | ||
} | ||
} | ||
} else { | ||
log(' Ignored: '+msg); | ||
} | ||
} | ||
@@ -466,3 +488,3 @@ | ||
log('[' + calleeMsg + '] Sending msg to iframe ('+msg+')'); | ||
iframe.contentWindow.postMessage( msgId + msg, '*' ); | ||
iframe.contentWindow.postMessage( msgId + msg, settings[id || iframe.id].targetOrigin ); | ||
} else { | ||
@@ -477,3 +499,3 @@ warn('[' + calleeMsg + '] IFrame not found'); | ||
function setupIFrame(options){ | ||
function setupIFrame(iframe,options){ | ||
function setLimits(){ | ||
@@ -532,24 +554,31 @@ function addStyle(style){ | ||
':' + settings[iframeId].tolerance + | ||
':' + settings[iframeId].enableInPageLinks + | ||
':' + settings[iframeId].resizeFrom; | ||
':' + settings[iframeId].inPageLinks + | ||
':' + settings[iframeId].resizeFrom + | ||
':' + settings[iframeId].widthCalculationMethod; | ||
} | ||
function checkReset(){ | ||
// Reduce scope of firstRun to function, because IE8's JS execution | ||
// context stack is borked and this value gets externally | ||
// changed midway through running this function!!! | ||
var | ||
firstRun = settings[iframeId].firstRun, | ||
restRequertMethod = settings[iframeId].heightCalculationMethod in resetRequiredMethods; | ||
if (!firstRun && restRequertMethod){ | ||
resetIFrame({iframe:iframe, height:0, width:0, type:'init'}); | ||
} | ||
} | ||
//We have to call trigger twice, as we can not be sure if all | ||
//iframes have completed loading when this code runs. The | ||
//event listener also catches the page changing in the iFrame. | ||
function init(msg){ | ||
//We have to call trigger twice, as we can not be sure if all | ||
//iframes have completed loading when this code runs. The | ||
//event listener also catches the page changing in the iFrame. | ||
addEventListener(iframe,'load',function(){ | ||
var fr = settings[iframeId].firstRun; // Reduce scope of var to function, because IE8's JS execution | ||
// context stack is borked and this value gets externally | ||
// changed midway through running this function. | ||
function iFrameLoaded(){ | ||
trigger('iFrame.onload',msg,iframe); | ||
if (!fr && settings[iframeId].heightCalculationMethod in resetRequiredMethods){ | ||
resetIFrame({ | ||
iframe:iframe, | ||
height:0, | ||
width:0, | ||
type:'init' | ||
}); | ||
} | ||
}); | ||
checkReset(); | ||
} | ||
addEventListener(iframe,'load',iFrameLoaded); | ||
trigger('init',msg,iframe); | ||
@@ -564,15 +593,26 @@ } | ||
function copyOptions(options){ | ||
for (var option in defaults) { | ||
if (defaults.hasOwnProperty(option)){ | ||
settings[iframeId][option] = options.hasOwnProperty(option) ? options[option] : defaults[option]; | ||
} | ||
} | ||
} | ||
function getTargetOrigin (remoteHost){ | ||
return 'file://' === remoteHost ? '*' : remoteHost; //Deal with Chrome wierdness. | ||
} | ||
function processOptions(options){ | ||
options = options || {}; | ||
settings[iframeId] = { | ||
firstRun: true | ||
firstRun : true, | ||
iframe : iframe, | ||
remoteHost : iframe.src.split('/').slice(0,3).join('/') | ||
}; | ||
checkOptions(options); | ||
copyOptions(options); | ||
for (var option in defaults) { | ||
if (defaults.hasOwnProperty(option)){ | ||
settings[iframeId][option] = options.hasOwnProperty(option) ? options[option] : defaults[option]; | ||
} | ||
} | ||
settings[iframeId].targetOrigin = true === settings[iframeId].checkOrigin ? getTargetOrigin(settings[iframeId].remoteHost) : '*'; | ||
@@ -582,12 +622,17 @@ logEnabled = settings[iframeId].log; | ||
var | ||
/*jshint validthis:true */ | ||
iframe = this, | ||
iframeId = ensureHasId(iframe.id); | ||
function beenHere(){ | ||
return (iframeId in settings); | ||
} | ||
processOptions(options); | ||
setScrolling(); | ||
setLimits(); | ||
setupBodyMarginValues(); | ||
init(createOutgoingMsg()); | ||
var iframeId = ensureHasId(iframe.id); | ||
if (!beenHere()){ | ||
processOptions(options); | ||
setScrolling(); | ||
setLimits(); | ||
setupBodyMarginValues(); | ||
init(createOutgoingMsg()); | ||
} else { | ||
warn(' Ignored iFrame, already setup.'); | ||
} | ||
} | ||
@@ -604,20 +649,41 @@ | ||
function winResize(){ | ||
function isIFrameResizeEnabled(iframeId) { | ||
return 'parent' === settings[iframeId].resizeFrom && | ||
settings[iframeId].autoResize && | ||
!settings[iframeId].firstRun; | ||
function setupEventListeners(){ | ||
function resizeIFrames(event){ | ||
throttle(function(){ | ||
sendTriggerMsg('Window '+event,'resize'); | ||
},66); | ||
} | ||
throttle(function(){ | ||
function tabVisible() { | ||
if('hidden' !== document.visibilityState) { | ||
sendTriggerMsg('Tab Visable','resize'); | ||
} | ||
} | ||
function sendTriggerMsg(eventName,event){ | ||
function isIFrameResizeEnabled(iframeId) { | ||
return 'parent' === settings[iframeId].resizeFrom && | ||
settings[iframeId].autoResize && | ||
!settings[iframeId].firstRun; | ||
} | ||
for (var iframeId in settings){ | ||
if(isIFrameResizeEnabled(iframeId)){ | ||
trigger('Window resize','resize',document.getElementById(iframeId),iframeId); | ||
trigger(eventName,event,document.getElementById(iframeId),iframeId); | ||
} | ||
} | ||
},66); | ||
} | ||
addEventListener(window,'message',iFrameListener); | ||
addEventListener(window,'resize', function(){resizeIFrames('resize');}); | ||
addEventListener(document,'visibilitychange',tabVisible); | ||
addEventListener(document,'-webkit-visibilitychange',tabVisible); //Andriod 4.4 | ||
addEventListener(window,'focusin',function(){resizeIFrames('focus');}); //IE8-9 | ||
} | ||
function factory(){ | ||
function init(element, options){ | ||
function init(options,element){ | ||
if(!element.tagName) { | ||
@@ -628,3 +694,3 @@ throw new TypeError('Object is not a valid DOM element'); | ||
} else { | ||
setupIFrame.call(element, options); | ||
setupIFrame(element, options); | ||
} | ||
@@ -634,4 +700,3 @@ } | ||
setupRequestAnimationFrame(); | ||
addEventListener(window,'message',iFrameListener); | ||
addEventListener(window,'resize', winResize); | ||
setupEventListeners(); | ||
@@ -642,8 +707,9 @@ return function iFrameResizeF(options,target){ | ||
case 'string': | ||
Array.prototype.forEach.call( document.querySelectorAll( target || 'iframe' ), function (element) { | ||
init(element, options); | ||
}); | ||
Array.prototype.forEach.call( | ||
document.querySelectorAll( target || 'iframe' ), | ||
init.bind(undefined, options) | ||
); | ||
break; | ||
case 'object': | ||
init(target, options); | ||
init(options,target); | ||
break; | ||
@@ -659,3 +725,3 @@ default: | ||
return this.filter('iframe').each(function (index, element) { | ||
setupIFrame.call(element, options); | ||
setupIFrame(element, options); | ||
}).end(); | ||
@@ -675,2 +741,2 @@ }; | ||
})(); | ||
})(window || {}); |
function sendMessage(msg){ | ||
'use strict'; | ||
var msgId = '[iFrameSizerTest]:'; | ||
//var msgId = '[iFrameSizerTest]:'; | ||
document.getElementsByTagName('iframe')[0].contentWindow.postMessage( msgId + msg, '*' ); | ||
//document.getElementsByTagName('iframe')[0].contentWindow.postMessage( msgId + msg, '*' ); | ||
console.log('Sending '+msg); | ||
document.getElementsByTagName('iframe')[0].iFrameResizer.sendMessage(msg); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
469386
55
4123
546