1jQuery(document).ready(function () { 2 class ResponsiveIframePatrick { 3 constructor(){ 4 5 6 //setup class variables 7 this.initVariables(); 8 9 //setup only when responsive iframe elements present 10 let classSelector = '.'.concat(this.className); 11 if(jQuery(classSelector).length > 0){ 12 //do first time resize 13 this.updateIframe(); 14 this.updateIframe = this.updateIframe.bind(this); 15 16 //setUpEventHandler 17 jQuery(window).on('resize',this.updateIframe); 18 } 19 20 } 21 22 //initiates this variables 23 initVariables(){ 24 this.className = RESPONSIVE_IFRAME_CONSTANTS.CLASS_NAME; 25 this.id=RESPONSIVE_IFRAME_CONSTANTS.ID_NAME; 26 this.styleID = RESPONSIVE_IFRAME_CONSTANTS.STYLE_ID; 27 } 28 29 //build a css element to put onto the document, necessary to ensure !important is used and takes precedence over anything else 30 buildCSS(cssAttributes){ 31 //initiate variables 32 let styleID = '#'.concat(this.styleID); 33 let className = '.'.concat(this.className); 34 let css = ''; 35 let newLine = '\n'; 36 let tab = '\t'; 37 38 //create the inline style element,ensures it only runs once 39 if(jQuery(styleID).length === 0 && jQuery(className).length > 0){ 40 jQuery('head:eq(0)').append('<style id="'+ this.styleID + '" type="text/css">' + '' + '</style>'); 41 } 42 43 //ensure the appended style is empty 44 jQuery(styleID).empty(); 45 46 //build the css elements 47 for(let i = 0; i < cssAttributes.length;i++){ 48 css += cssAttributes[i].id + '{' + newLine; //#ID{ 49 css += tab + 'max-width: ' + cssAttributes[i].maxWidth + newLine; //disables max width 50 css += tab + 'max-height: ' + cssAttributes[i].maxWidth + newLine; //disables max height 51 css += tab + 'width: ' + cssAttributes[i].width + newLine; //sets width 52 css += tab + 'height: ' + cssAttributes[i].height + newLine; //sets height 53 //The Scales 54 css += tab + 'transform: ' + cssAttributes[i].scale + newLine; //sets scale 55 css += tab + '-ms-transform: ' + cssAttributes[i].scale + newLine; //sets scale 56 css += tab + '-moz-transform : ' + cssAttributes[i].scale + newLine; //sets scale 57 css += tab + '-o-transform: ' + cssAttributes[i].scale + newLine; //sets scale 58 css += tab + '-webkit-transform: ' + cssAttributes[i].scale + newLine; //sets scale 59 60 //The scale Origins 61 css += tab + 'transform-origin: ' + cssAttributes[i].scaleOrigin + newLine; //sets origin 62 css += tab + '-ms-transform-origin: ' + cssAttributes[i].scaleOrigin + newLine; //sets origin 63 css += tab + '-moz-transform-origin: ' + cssAttributes[i].scaleOrigin + newLine; //sets origin 64 css += tab + '-o-transform-origin: ' + cssAttributes[i].scaleOrigin + newLine; //sets origin 65 css += tab + '-webkit-transform-origin: ' + cssAttributes[i].scaleOrigin + newLine; //sets origin 66 67 //finish the CSS 68 css += tab + 'margin-bottom: ' + cssAttributes[i].marginBottom + newLine; //sets bottom margin 69 css += tab + 'margin-right: ' + cssAttributes[i].marginRight + newLine; //sets margin-right 70 css += '} ' + newLine; //Close up 71 } 72 //place the css into the style element 73 jQuery(styleID).append(css); 74 } 75 76 setWidth(selector){ 77 //initialize variables 78 let width; 79 const breakPoints = jQuery(selector).data('break-points'); 80 81 if(breakPoints.length > 0){ 82 let validBreakPoints = breakPoints.filter((bp)=>{return window.innerWidth <= bp.breakPointW}); 83 84 //sort to determine the lowest width valid breakPoint 85 validBreakPoints.sort(function(a, b){return b.breakPointW - a.breakPointW}); 86 87 if(validBreakPoints.length > 0){ 88 const activeBreakPoint = validBreakPoints[validBreakPoints.length-1]; 89 const siteW = activeBreakPoint.siteW; 90 width = siteW; 91 }else{ 92 width = jQuery(selector).data('width-iframe'); 93 } 94 }else{ 95 width = jQuery(selector).data('width-iframe'); 96 } 97 98 return width; 99 } 100 101 updateIframe(){ 102 //initiate variables 103 let defaultScaleVal=RESPONSIVE_IFRAME_CONSTANTS.DEFAULT_SCALE_VAL; 104 let scale = defaultScaleVal; 105 let className = '.'.concat(this.className); 106 let cssAttributes = []; 107 108 //loop thru each classElement 109 for(let i = 0; i < jQuery(className).length;i++){ 110 //initiate variables 111 let marginBottom; 112 let marginRight; 113 114 //create a selector for jQuery, and then grab some attributes from some elements 115 let selector = className.concat(':eq(' +i+ ')'); 116 let id = jQuery(selector).attr('id'); 117 let width = this.setWidth(selector); 118 let height = jQuery(selector).data('height-iframe'); 119 let parentWidth = jQuery(selector).parent().width(); 120 121 //set the scale and margins, which ensure the makes the iframe responsive 122 scale = parentWidth/width; 123 marginBottom =-1 * height * (defaultScaleVal - scale); 124 marginRight = -1 * width * (defaultScaleVal - scale); 125 126 //Ensure the parent div does not have a larger height than the iframe 127 jQuery(selector).parent().css({'max-height':height*scale}); 128 129 //build an array of cssAttribute objects 130 cssAttributes.push(new RESPONSIVE_IFRAME_CONSTANTS.CSS.attributes(id,width,height,scale,marginBottom,marginRight)); 131 132 } 133 //This builds and assigns the css style to the document itself 134 this.buildCSS(cssAttributes); 135 } 136 } 137 138 //initiates the ResponsiveiFrame class 139 let responsiveIframePatrick = new ResponsiveIframePatrick(); 140 141 142 143});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.