-
-
Notifications
You must be signed in to change notification settings - Fork 285
/
editor.6386bd9d.js
8 lines (8 loc) 路 13.1 KB
/
editor.6386bd9d.js
1
2
3
4
5
6
7
8
/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v4.2.11 - 2020-06-02
* Desc: Include this file in any page being loaded into an iframe
* to force the iframe to resize to the content size.
* Requires: iframeResizer.min.js on host page.
* Copyright: (c) 2020 David J. Bradshaw - dave@bradshaw.net
* License: MIT
*/
!function(e){if("undefined"!=typeof window){var t=!0,n=10,o="",i=0,r="",a=null,u="",c=!1,s={resize:1,click:1},d=128,l=!0,f=1,m="bodyOffset",h=m,g=!0,p="",v={},y=32,b=null,w=!1,T="[iFrameSizer]",E=T.length,O="",S={max:1,min:1,bodyScroll:1,documentElementScroll:1},M="child",I=!0,N=window.parent,A="*",C=0,z=!1,k=null,R=16,x=1,L="scroll",F=L,P=window,D=function(){re("onMessage function not defined")},j=function(){},q=function(){},H={height:function(){return re("Custom height calculation function not defined"),document.documentElement.offsetHeight},width:function(){return re("Custom width calculation function not defined"),document.body.scrollWidth}},W={},B=!1;try{var J=Object.create({},{passive:{get:function(){B=!0}}});window.addEventListener("test",ee,J),window.removeEventListener("test",ee,J)}catch(e){}var U,V,K,Q,X,Y,G=Date.now||function(){return(new Date).getTime()},Z={bodyOffset:function(){return document.body.offsetHeight+pe("marginTop")+pe("marginBottom")},offset:function(){return Z.bodyOffset()},bodyScroll:function(){return document.body.scrollHeight},custom:function(){return H.height()},documentElementOffset:function(){return document.documentElement.offsetHeight},documentElementScroll:function(){return document.documentElement.scrollHeight},max:function(){return Math.max.apply(null,ye(Z))},min:function(){return Math.min.apply(null,ye(Z))},grow:function(){return Z.max()},lowestElement:function(){return Math.max(Z.bodyOffset()||Z.documentElementOffset(),ve("bottom",we()))},taggedElement:function(){return be("bottom","data-iframe-height")}},$={bodyScroll:function(){return document.body.scrollWidth},bodyOffset:function(){return document.body.offsetWidth},custom:function(){return H.width()},documentElementScroll:function(){return document.documentElement.scrollWidth},documentElementOffset:function(){return document.documentElement.offsetWidth},scroll:function(){return Math.max($.bodyScroll(),$.documentElementScroll())},max:function(){return Math.max.apply(null,ye($))},min:function(){return Math.min.apply(null,ye($))},rightMostElement:function(){return ve("right",we())},taggedElement:function(){return be("right","data-iframe-width")}},_=(U=Te,X=null,Y=0,function(){var e=G(),t=R-(e-(Y=Y||e));return V=this,K=arguments,t<=0||R<t?(X&&(clearTimeout(X),X=null),Y=e,Q=U.apply(V,K),X||(V=K=null)):X=X||setTimeout(Ee,t),Q});te(window,"message",(function(e){var t={init:function(){p=e.data,N=e.source,ae(),l=!1,setTimeout((function(){g=!1}),d)},reset:function(){g?ie("Page reset ignored by init"):(ie("Page size reset by host page"),Me("resetPage"))},resize:function(){Oe("resizeParent","Parent window requested size check")},moveToAnchor:function(){v.findTarget(o())},inPageLink:function(){this.moveToAnchor()},pageInfo:function(){var e=o();ie("PageInfoFromParent called from parent: "+e),q(JSON.parse(e)),ie(" --")},message:function(){var e=o();ie("onMessage called from parent: "+e),D(JSON.parse(e)),ie(" --")}};function n(){return e.data.split("]")[1].split(":")[0]}function o(){return e.data.substr(e.data.indexOf(":")+1)}function i(){return e.data.split(":")[2]in{true:1,false:1}}T===(""+e.data).substr(0,E)&&(!1===l?function(){var o=n();o in t?t[o]():("undefined"==typeof module||!module.exports)&&"iFrameResize"in window||"jQuery"in window&&"iFrameResize"in window.jQuery.prototype||i()||re("Unexpected message ("+e.data+")")}():i()?t.init():ie('Ignored message of type "'+n()+'". Received before initialization.'))})),te(window,"readystatechange",Ae),Ae()}function ee(){}function te(e,t,n,o){e.addEventListener(t,n,!!B&&(o||{}))}function ne(e){return e.charAt(0).toUpperCase()+e.slice(1)}function oe(e){return T+"["+O+"] "+e}function ie(e){w&&"object"==typeof window.console&&console.log(oe(e))}function re(e){"object"==typeof window.console&&console.warn(oe(e))}function ae(){!function(){function n(e){return"true"===e}var a=p.substr(E).split(":");O=a[0],i=e!==a[1]?Number(a[1]):i,c=e!==a[2]?n(a[2]):c,w=e!==a[3]?n(a[3]):w,y=e!==a[4]?Number(a[4]):y,t=e!==a[6]?n(a[6]):t,r=a[7],h=e!==a[8]?a[8]:h,o=a[9],u=a[10],C=e!==a[11]?Number(a[11]):C,v.enable=e!==a[12]&&n(a[12]),M=e!==a[13]?a[13]:M,F=e!==a[14]?a[14]:F}(),ie("Initialising iFrame ("+location.href+")"),function(){function e(e,t){return"function"==typeof e&&(ie("Setup custom "+t+"CalcMethod"),H[t]=e,e="custom"),e}"iFrameResizer"in window&&Object===window.iFrameResizer.constructor&&(function(){var e=window.iFrameResizer;ie("Reading data from page: "+JSON.stringify(e)),Object.keys(e).forEach(ue,e),D="onMessage"in e?e.onMessage:D,j="onReady"in e?e.onReady:j,A="targetOrigin"in e?e.targetOrigin:A,h="heightCalculationMethod"in e?e.heightCalculationMethod:h,F="widthCalculationMethod"in e?e.widthCalculationMethod:F}(),h=e(h,"height"),F=e(F,"width")),ie("TargetOrigin for parent set to: "+A)}(),e===r&&(r=i+"px"),ce("margin",function(e,t){return-1!==t.indexOf("-")&&(re("Negative CSS value ignored for margin"),t=""),t}(0,r)),ce("background",o),ce("padding",u),function(){var e=document.createElement("div");e.style.clear="both",e.style.display="block",e.style.height="0",document.body.appendChild(e)}(),fe(),me(),document.documentElement.style.height="",document.body.style.height="",ie('HTML & body height set to "auto"'),ie("Enable public methods"),P.parentIFrame={autoResize:function(e){return!0===e&&!1===t?(t=!0,he()):!1===e&&!0===t&&(t=!1,de("remove"),null!==a&&a.disconnect(),clearInterval(b)),Ne(0,0,"autoResize",JSON.stringify(t)),t},close:function(){Ne(0,0,"close")},getId:function(){return O},getPageInfo:function(e){"function"==typeof e?(q=e,Ne(0,0,"pageInfo")):(q=function(){},Ne(0,0,"pageInfoStop"))},moveToAnchor:function(e){v.findTarget(e)},reset:function(){Ie("parentIFrame.reset")},scrollTo:function(e,t){Ne(t,e,"scrollTo")},scrollToOffset:function(e,t){Ne(t,e,"scrollToOffset")},sendMessage:function(e,t){Ne(0,0,"message",JSON.stringify(e),t)},setHeightCalculationMethod:function(e){h=e,fe()},setWidthCalculationMethod:function(e){F=e,me()},setTargetOrigin:function(e){ie("Set targetOrigin: "+e),A=e},size:function(e,t){Oe("size","parentIFrame.size("+(e||"")+(t?","+t:"")+")",e,t)}},he(),v=function(){function t(t){var n,o=t.split("#")[1]||t,i=decodeURIComponent(o),r=document.getElementById(i)||document.getElementsByName(i)[0];e!==r?(n=function(t){var n=t.getBoundingClientRect(),o={x:window.pageXOffset!==e?window.pageXOffset:document.documentElement.scrollLeft,y:window.pageYOffset!==e?window.pageYOffset:document.documentElement.scrollTop};return{x:parseInt(n.left,10)+parseInt(o.x,10),y:parseInt(n.top,10)+parseInt(o.y,10)}}(r),ie("Moving to in page link (#"+o+") at x: "+n.x+" y: "+n.y),Ne(n.y,n.x,"scrollToOffset")):(ie("In page link (#"+o+") not found in iFrame, so sending to parent"),Ne(0,0,"inPageLink","#"+o))}function n(){""!==location.hash&&"#"!==location.hash&&t(location.href)}return v.enable?Array.prototype.forEach&&document.querySelectorAll?(ie("Setting up location.hash handlers"),Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'),(function(e){"#"!==e.getAttribute("href")&&te(e,"click",(function(e){e.preventDefault(),t(this.getAttribute("href"))}))})),te(window,"hashchange",n),setTimeout(n,d)):re("In page linking not fully supported in this browser! (See README.md for IE8 workaround)"):ie("In page linking not enabled"),{findTarget:t}}(),Oe("init","Init message from host page"),j()}function ue(e){var t=e.split("Callback");if(2===t.length){var n="on"+t[0].charAt(0).toUpperCase()+t[0].slice(1);this[n]=this[e],delete this[e],re("Deprecated: '"+e+"' has been renamed '"+n+"'. The old method will be removed in the next major version.")}}function ce(t,n){e!==n&&""!==n&&"null"!==n&&ie("Body "+t+' set to "'+(document.body.style[t]=n)+'"')}function se(e){var t={add:function(t){function n(){Oe(e.eventName,e.eventType)}W[t]=n,te(window,t,n,{passive:!0})},remove:function(e){var t=W[e];delete W[e],function(e,t,n){e.removeEventListener(t,n,!1)}(window,e,t)}};e.eventNames&&Array.prototype.map?(e.eventName=e.eventNames[0],e.eventNames.map(t[e.method])):t[e.method](e.eventName),ie(ne(e.method)+" event listener: "+e.eventType)}function de(e){se({method:e,eventType:"Animation Start",eventNames:["animationstart","webkitAnimationStart"]}),se({method:e,eventType:"Animation Iteration",eventNames:["animationiteration","webkitAnimationIteration"]}),se({method:e,eventType:"Animation End",eventNames:["animationend","webkitAnimationEnd"]}),se({method:e,eventType:"Input",eventName:"input"}),se({method:e,eventType:"Mouse Up",eventName:"mouseup"}),se({method:e,eventType:"Mouse Down",eventName:"mousedown"}),se({method:e,eventType:"Orientation Change",eventName:"orientationchange"}),se({method:e,eventType:"Print",eventName:["afterprint","beforeprint"]}),se({method:e,eventType:"Ready State Change",eventName:"readystatechange"}),se({method:e,eventType:"Touch Start",eventName:"touchstart"}),se({method:e,eventType:"Touch End",eventName:"touchend"}),se({method:e,eventType:"Touch Cancel",eventName:"touchcancel"}),se({method:e,eventType:"Transition Start",eventNames:["transitionstart","webkitTransitionStart","MSTransitionStart","oTransitionStart","otransitionstart"]}),se({method:e,eventType:"Transition Iteration",eventNames:["transitioniteration","webkitTransitionIteration","MSTransitionIteration","oTransitionIteration","otransitioniteration"]}),se({method:e,eventType:"Transition End",eventNames:["transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend"]}),"child"===M&&se({method:e,eventType:"IFrame Resized",eventName:"resize"})}function le(e,t,n,o){return t!==e&&(e in n||(re(e+" is not a valid option for "+o+"CalculationMethod."),e=t),ie(o+' calculation method set to "'+e+'"')),e}function fe(){h=le(h,m,Z,"height")}function me(){F=le(F,L,$,"width")}function he(){!0===t?(de("add"),function(){var t=y<0;window.MutationObserver||window.WebKitMutationObserver?t?ge():a=function(){function t(e){function t(e){!1===e.complete&&(ie("Attach listeners to "+e.src),e.addEventListener("load",i,!1),e.addEventListener("error",r,!1),u.push(e))}"attributes"===e.type&&"src"===e.attributeName?t(e.target):"childList"===e.type&&Array.prototype.forEach.call(e.target.querySelectorAll("img"),t)}function n(e){ie("Remove listeners from "+e.src),e.removeEventListener("load",i,!1),e.removeEventListener("error",r,!1),function(e){u.splice(u.indexOf(e),1)}(e)}function o(t,o,i){n(t.target),Oe(o,i+": "+t.target.src,e,e)}function i(e){o(e,"imageLoad","Image loaded")}function r(e){o(e,"imageLoadFailed","Image load failed")}function a(e){Oe("mutationObserver","mutationObserver: "+e[0].target+" "+e[0].type),e.forEach(t)}var u=[],c=window.MutationObserver||window.WebKitMutationObserver,s=function(){var e=document.querySelector("body");return s=new c(a),ie("Create body MutationObserver"),s.observe(e,{attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0}),s}();return{disconnect:function(){"disconnect"in s&&(ie("Disconnect body MutationObserver"),s.disconnect(),u.forEach(n))}}}():(ie("MutationObserver not supported in this browser!"),ge())}()):ie("Auto Resize disabled")}function ge(){0!==y&&(ie("setInterval: "+y+"ms"),b=setInterval((function(){Oe("interval","setInterval: "+y)}),Math.abs(y)))}function pe(e,t){var o=0;return t=t||document.body,o=null!==(o=document.defaultView.getComputedStyle(t,null))?o[e]:0,parseInt(o,n)}function ve(e,t){for(var n=t.length,o=0,i=0,r=ne(e),a=G(),u=0;u<n;u++)i<(o=t[u].getBoundingClientRect()[e]+pe("margin"+r,t[u]))&&(i=o);return a=G()-a,ie("Parsed "+n+" HTML elements"),ie("Element position calculated in "+a+"ms"),function(e){R/2<e&&ie("Event throttle increased to "+(R=2*e)+"ms")}(a),i}function ye(e){return[e.bodyOffset(),e.bodyScroll(),e.documentElementOffset(),e.documentElementScroll()]}function be(e,t){var n=document.querySelectorAll("["+t+"]");return 0===n.length&&(re("No tagged elements ("+t+") found on page"),document.querySelectorAll("body *")),ve(e,n)}function we(){return document.querySelectorAll("body *")}function Te(t,n,o,i){var r,a;function u(e,t){return!(Math.abs(e-t)<=C)}r=e!==o?o:Z[h](),a=e!==i?i:$[F](),u(f,r)||c&&u(x,a)||"init"===t?(Se(),Ne(f=r,x=a,t)):t in{init:1,interval:1,size:1}||!(h in S||c&&F in S)?t in{interval:1}||ie("No change in size detected"):Ie(n)}function Ee(){Y=G(),X=null,Q=U.apply(V,K),X||(V=K=null)}function Oe(e,t,n,o){z&&e in s?ie("Trigger event cancelled: "+e):(e in{reset:1,resetPage:1,init:1}||ie("Trigger event: "+t),"init"===e?Te(e,t,n,o):_(e,t,n,o))}function Se(){z||(z=!0,ie("Trigger event lock on")),clearTimeout(k),k=setTimeout((function(){z=!1,ie("Trigger event lock off"),ie("--")}),d)}function Me(e){f=Z[h](),x=$[F](),Ne(f,x,e)}function Ie(e){var t=h;h=m,ie("Reset trigger event: "+e),Se(),Me("reset"),h=t}function Ne(t,n,o,i,r){var a;!0===I&&(e===r?r=A:ie("Message targetOrigin: "+r),ie("Sending message to host page ("+(a=O+":"+t+":"+n+":"+o+(e!==i?":"+i:""))+")"),N.postMessage(T+a,r))}function Ae(){"loading"!==document.readyState&&window.parent.postMessage("[iFrameResizerChild]Ready","*")}}();