1/*jslint white: true, indent: 2, onevar: false, browser: true, undef: true, nomen: false, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, strict: false, newcap: true, immed: true */ 2/*global window, console, jQuery, setTimeout */ 3 4/* 5 Plugin: iframe autoheight jQuery Plugin 6 Version: 1.9.5 7 Author and Contributors 8 ======================================== 9 NATHAN SMITH (http://sonspring.com/) 10 Jesse House (https://github.com/house9) 11 aaron manela (https://github.com/aaronmanela) 12 Hideki Abe (https://github.com/hideki-a) 13 Patrick Clark (https://github.com/hellopat) 14 ChristineP2 (https://github.com/ChristineP2) 15 Mmjavellana (https://github.com/Mmjavellana) 16 yiqing-95 (https://github.com/yiqing-95) 17 jcaspian (https://github.com/jcaspian) 18 adamjgray (https://github.com/adamjgray) 19 Jens Bissinger (https://github.com/dpree) 20 jbreton (https://github.com/jbreton) 21 mindmelting (https://github.com/mindmelting) 22 23 File: jquery.iframe-auto-height.plugin.js 24 Remarks: original code from http://sonspring.com/journal/jquery-iframe-sizing 25 Description: when the page loads set the height of an iframe based on the height of its contents 26 see README: http://github.com/house9/jquery-iframe-auto-height 27 28*/ 29(function( jQuery ) { 30 var matched, 31 userAgent = navigator.userAgent || ""; 32 33 // Use of jQuery.browser is frowned upon. 34 // More details: http://api.jquery.com/jQuery.browser 35 // jQuery.uaMatch maintained for back-compat 36 jQuery.uaMatch = function( ua ) { 37 ua = ua.toLowerCase(); 38 39 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || 40 /(webkit)[ \/]([\w.]+)/.exec( ua ) || 41 /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || 42 /(msie) ([\w.]+)/.exec( ua ) || 43 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || 44 []; 45 46 return { 47 browser: match[ 1 ] || "", 48 version: match[ 2 ] || "0" 49 }; 50 }; 51 52 matched = jQuery.uaMatch( userAgent ); 53 54 jQuery.browser = {}; 55 56 if ( matched.browser ) { 57 jQuery.browser[ matched.browser ] = true; 58 jQuery.browser.version = matched.version; 59 } 60 61 // Deprecated, use jQuery.browser.webkit instead 62 // Maintained for back-compat only 63 if ( jQuery.browser.webkit ) { 64 jQuery.browser.safari = true; 65 } 66 67}( jQuery )); 68 69(function ($) { 70 $.fn.iframeAutoHeight = function (spec) { 71 72 var undef; 73 if ($.browser === undef) { 74 var message = []; 75 message.push("WARNING: you appear to be using a newer version of jquery which does not support the $.browser variable."); 76 message.push("The jQuery iframe auto height plugin relies heavly on the $.browser features."); 77 message.push("Install jquery-browser: https://raw.github.com/house9/jquery-iframe-auto-height/master/release/jquery.browser.js"); 78 alert(message.join("\n")); 79 return $; 80 } 81 82 // set default option values 83 var options = $.extend({ 84 heightOffset: 0, 85 minHeight: 0, 86 maxHeight: 0, 87 callback: function (newHeight) {}, 88 animate: false, 89 debug: false, 90 diagnostics: false, // used for development only 91 resetToMinHeight: false, 92 triggerFunctions: [], 93 heightCalculationOverrides: [] 94 }, spec); 95 96 // logging 97 function debug(message) { 98 if (options.debug && options.debug === true && window.console) { 99 console.log(message); 100 } 101 } 102 103 // not used by production code 104 function showDiagnostics(iframe, calledFrom) { 105 debug("Diagnostics from '" + calledFrom + "'"); 106 try { 107 debug(" " + $(iframe, window.top.document).contents().find('body')[0].scrollHeight + " for ...find('body')[0].scrollHeight"); 108 debug(" " + $(iframe.contentWindow.document).height() + " for ...contentWindow.document).height()"); 109 debug(" " + $(iframe.contentWindow.document.body).height() + " for ...contentWindow.document.body).height()"); 110 } catch (ex) { 111 // ie fails when called during for each, ok later on 112 // probably not an issue if called in a document ready block 113 debug(" unable to check in this state"); 114 } 115 debug("End diagnostics -> results vary by browser and when diagnostics are requested"); 116 } 117 118 // show all option values 119 debug(options); 120 121 // ****************************************************** 122 // iterate over the matched elements passed to the plugin ; return will make it chainable 123 return this.each(function () { 124 125 // ****************************************************** 126 // http://api.jquery.com/jQuery.browser/ 127 var strategyKeys = ['webkit', 'mozilla', 'msie', 'opera']; 128 var strategies = {}; 129 strategies['default'] = function (iframe, $iframeBody, options, browser) { 130 // NOTE: this is how the plugin determines the iframe height, override if you need custom 131 return $iframeBody[0].scrollHeight + options.heightOffset; 132 }; 133 134 jQuery.each(strategyKeys, function (index, value) { 135 // use the default strategy for all browsers, can be overridden if desired 136 strategies[value] = strategies['default']; 137 }); 138 139 // override strategies if registered in options 140 jQuery.each(options.heightCalculationOverrides, function (index, value) { 141 strategies[value.browser] = value.calculation; 142 }); 143 144 function findStrategy(browser) { 145 var strategy = null; 146 147 jQuery.each(strategyKeys, function (index, value) { 148 if (browser[value]) { 149 strategy = strategies[value]; 150 return false;
151 } 152 }); 153 154 if (strategy === null) { 155 strategy = strategies['default']; 156 } 157 158 return strategy; 159 } 160 // ****************************************************** 161 162 // for use by webkit only 163 var loadCounter = 0; 164 165 var iframeDoc; 166 try { 167 iframeDoc = this.contentDocument || this.contentWindow.document; 168 } catch (e) { 169 iframeDoc = null; 170 } 171 172 // resizeHeight 173 function resizeHeight(iframe) { 174 if (options.diagnostics) { 175 showDiagnostics(iframe, "resizeHeight"); 176 } 177 178 // set the iframe size to minHeight so it'll get smaller on resizes in FF and IE 179 if (options.resetToMinHeight && options.resetToMinHeight === true) { 180 iframe.style.height = options.minHeight + 'px'; 181 } 182 183 // get the iframe body height and set inline style to that plus a little 184 var $body = $(iframe, window.top.document).contents().find('body'); 185 var strategy = findStrategy($.browser); 186 var newHeight = strategy(iframe, $body, options, $.browser); 187 debug(newHeight); 188 189 if (newHeight < options.minHeight) { 190 debug("new height is less than minHeight"); 191 newHeight = options.minHeight; 192 } 193 194 if (options.maxHeight > 0 && newHeight > options.maxHeight) { 195 debug("new height is greater than maxHeight"); 196 newHeight = options.maxHeight; 197 } 198 199 newHeight += options.heightOffset; 200 201 debug("New Height: " + newHeight); 202 if (options.animate) { 203 $(iframe).animate({height: newHeight + 'px'}, {duration: 500}); 204 } else { 205 iframe.style.height = newHeight + 'px'; 206 } 207 208 options.callback.apply($(iframe), [{newFrameHeight: newHeight}]); 209 } // END resizeHeight 210 211 // debug me 212 debug(this); 213 if (options.diagnostics) { 214 showDiagnostics(this, "each iframe"); 215 } 216 217 // if trigger functions are registered, invoke them 218 if (options.triggerFunctions.length > 0) { 219 debug(options.triggerFunctions.length + " trigger Functions"); 220 for (var i = 0; i < options.triggerFunctions.length; i++) { 221 options.triggerFunctions[i](resizeHeight, this); 222 } 223 } 224 225 // Bind load event for all browsers (use .on for broader compatibility) 226 var iframeEl = this; 227 $(this).on('load', function () { 228 if ($.browser.webkit || $.browser.opera || $.browser.chrome) { 229 var delay = 0; 230 231 var delayedResize = function () { 232 resizeHeight(iframeEl); 233 }; 234 235 if (loadCounter === 0) { 236 // delay the first one 237 delay = 500; 238 } else { 239 // Reset iframe height to 0 to force new frame size to fit window properly 240 // this is only an issue when going from large to small iframe, not executed on page load 241 iframeEl.style.height = options.minHeight + 'px'; 242 } 243 244 debug("load delay: " + delay); 245 setTimeout(delayedResize, delay); 246 loadCounter++; 247 } else { 248 // Firefox, IE, and other browsers 249 resizeHeight(iframeEl); 250 } 251 }); 252 253 // Safari and Opera need a kick-start. 254 if ($.browser.webkit || $.browser.opera || $.browser.chrome) { 255 debug("browser is webkit or opera"); 256 var source = $(this).attr('src'); 257 $(this).attr('src', ''); 258 $(this).attr('src', source); 259 } else if (iframeDoc && iframeDoc.readyState === 'complete') { 260 // For already loaded iframes, also resize immediately 261 resizeHeight(this); 262 } // if browser 263 264 }); // $(this).each(function () { 265 }; // $.fn.iframeAutoHeight = function (options) { 266}(jQuery)); // (function ($) {
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.