reframe.js
Version:
Reframe.js: responsive iframes for embedded content
2 lines (1 loc) • 899 B
JavaScript
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";var e;"undefined"!=typeof window&&(e=window.$||window.jQuery||window.Zepto)&&(e.fn.reframe=function(e){var t=this,i="string"==typeof t?document.querySelectorAll(t):t,n=e||"js-reframe";"length"in i||(i=[i]);for(var o=0;o<i.length;o+=1){var r=i[o];if(-1!==r.className.split(" ").indexOf(n)||-1<r.style.width.indexOf("%"))return;var d=r.getAttribute("height")||r.offsetHeight,f=r.getAttribute("width")||r.offsetWidth,d=("string"==typeof d?parseInt(d):d)/("string"==typeof f?parseInt(f):f)*100,f=document.createElement("div"),s=(f.className=n,f.style),s=(s.position="relative",s.width="100%",s.paddingTop="".concat(d,"%"),r.style);s.position="absolute",s.width="100%",s.height="100%",s.left="0",s.top="0",null!=(d=r.parentNode)&&d.insertBefore(f,r),null!=(s=r.parentNode)&&s.removeChild(r),f.appendChild(r)}})});