kajgana

AA iFrame dynamic height resize code

Mar 16th, 2022 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <iframe scrolling="auto" src="https://www.booking-manager.com/wbm2/page.html?companyid=5524&amp;setlang=en&amp;view=Lastminute" allowtransparency="true" width="100%" height="1000" frameborder="0"></iframe><br>
  2.  
  3. <a href="https://www.booking-manager.com" style="color:#9999;text-decoration:none;font-size:10px;font-family:arial">Yacht charter availability powered by booking-manager.com</a>
  4.  
  5. <script type="text/javascript">
  6. !function(){"use strict";function a(a,b,c)
  7.  
  8. {"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}
  9. function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!window.requestAnimationFrame;a+=1)window.requestAnimationFrame=window[b[a]+"RequestAnimationFrame"];window.requestAnimationFrame||(c(" RequestAnimationFrame not supported"),window.requestAnimationFrame=function(a)
  10.  
  11. {a()}
  12. )}function c(a)
  13.  
  14. {k.log&&"console"in window&&console.log(i+"[Host page]"+a)}
  15. function d(a){function b(){function a(a){window.requestAnimationFrame(function()
  16.  
  17. {n.iframe.style[a]=n[a]+"px",c(" IFrame ("+n.iframe.id+") "+a+" set to "+n[a]+"px")}
  18. )}k.sizeHeight&&a("height"),k.sizeWidth&&a("width")}function d(a)
  19.  
  20. {c(" iFrame "+a.id+" removed."),a.parentNode.removeChild(a)}
  21. function e(){var a=m.substr(j).split(":");return{iframe:document.getElementById(a[0]),height:a[1],width:a[2],type:a[3]}}function f()
  22.  
  23. {"close"===n.type?d(n.iframe):b(),k.resizedCallback(n)}
  24. function g()
  25.  
  26. {var b=a.origin,d=n.iframe.src.split("/").slice(0,3).join("/");if(k.checkOrigin&&(c(" Checking conection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+n.iframe.id+". Message was: "+a.data);return!0}
  27. function h()
  28.  
  29. {return i===(""+m).substr(0,j)}
  30. function l(){var a=m.substr(m.lastIndexOf(":")1);c(' Received message "'+a'" from '+n.iframe.id),k.messageCallback(
  31.  
  32. {iframe:n.iframe,message:a}
  33. )}var m=a.data,n={};h()&&(n=e(),g()&&("message"!==n.type?f():l()))}function e(){function b(a)
  34.  
  35. {return""===a&&(l.id=a="iFrameResizer"+h++,c(" Added missing iframe ID: "+a)),a}
  36. function d()
  37.  
  38. {c(" IFrame scrolling "+(k.scrolling?"enabled":"disabled")+" for "+m),l.style.overflow=!1===k.scrolling?"hidden":"auto",l.scrolling=!1===k.scrolling?"no":"yes"}
  39. function e()
  40.  
  41. {("number"==typeof k.bodyMargin||"0"===k.bodyMargin)&&(k.bodyMarginV1=k.bodyMargin,k.bodyMargin=""+k.bodyMargin+"px")}
  42. function f()
  43.  
  44. {return m+":"+k.bodyMarginV1+":"+k.sizeWidth+":"+k.log+":"+k.interval+":"+k.enablePublicMethods+":"+k.autoResize+":"+k.bodyMargin+":"+k.heightCalculationMethod+":"+k.bodyBackground+":"+k.bodyPadding}
  45. function g(a,b)
  46.  
  47. {c("["+a+"] Sending init msg to iframe ("+b+")"),l.contentWindow.postMessage(i+b,"*")}
  48. function j(b){a(l,"load",function()
  49.  
  50. {g("iFrame.onload",b)}
  51. ),g("init",b)}var l=this,m=b(l.id);d(),e(),j(f())}function f(){function a(a)
  52.  
  53. {if("IFRAME"!==a.tagName)throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");e.call(a)}
  54. function b(a){if(a=a||{},"object"!=typeof a)throw new TypeError("Options is not an object.");for(var b in l)l.hasOwnProperty(b)&&(k[b]=a.hasOwnProperty(b)?a[b]:l[b])}window.iFrameResize=function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function g(a){a.fn.iFrameResize=function(b){return k=a.extend({},l,b),this.filter("iframe").each(e).end()}}var h=0,i="[iFrameSizer]",j=i.length,k={},l={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,messageCallback:function(){},resizedCallback:function(){},scrolling:!1,sizeHeight:!0,sizeWidth:!1};b(),a(window,"message",d),f(),"jQuery"in window&&g(jQuery)}();
  55. //# sourceMappingURL=../src/iframeResizer.map
  56. </script>
  57. <script type="text/javascript">
  58. iFrameResize({
  59. log : true, // Enable console logging
  60. enablePublicMethods : true, // Enable methods within iframe hosted page
  61. sizeHeight : true,
  62. resizedCallback : function(messageData)
  63.  
  64. { // Callback fn when message is received $('p#callback').html( '<b>Frame ID:</b> ' + messageData.iframe.id + ' <b>Height:</b> ' + messageData.height + ' <b>Width:</b> ' + messageData.width + ' <b>Event type:</b> ' + messageData.type ); }
  65. });
  66. </script>
Advertisement
Add Comment
Please, Sign In to add comment