-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathseamless.min.js
1 lines (1 loc) · 1.57 KB
/
seamless.min.js
1
(function(win,doc){"use strict";var allowed_domains=["*"];var allowed_domains_length=allowed_domains.length;var target_origin="*";var frames={};var setOptions=function(options){if(options.allowed_domains){allowed_domains=options.allowed_domains;allowed_domains_length=allowed_domains.length}if(options.target_origin){target_origin=options.target_origin}};var checkDomain=function(origin){var i;for(i=0;i<allowed_domains_length;i++){if(allowed_domains[i]===origin||allowed_domains[i]==="*"){return true}}return false};var sendHeight=function(){win.parent.postMessage(JSON.stringify({height:doc.body.scrollHeight,href:win.location.href}),target_origin)};var heightListener=function(evt){if(!checkDomain(evt.origin)){return}var data=JSON.parse(evt.data);if(data.request&&data.request==="height"){sendHeight()}};var setFrameHeight=function(evt){if(!checkDomain(evt.origin)){return}var data=JSON.parse(evt.data),frame;if(data.height&&data.href){frame=frames[data.href];if(frame){frame.style.height=parseInt(data.height,10||0)+"px"}}};var frame=function(options){setOptions(options);win.onmessage=heightListener;win.onload=sendHeight};var parent=function(options){setOptions(options);var elements=doc.querySelectorAll("iframe[seamless]"),len=elements.length,i;for(i=0;i<len;i++){frames[elements[i].src]=elements[i]}window.addEventListener("message",setFrameHeight)};var seamless={frame:frame,parent:parent};if(typeof define==="function"&&define.amd){define([],function(){return seamless})}else if(typeof module!=="undefined"&&module!==null){module.exports=seamless}else{window.seamless=seamless}})(window,document);