1if (document.readyState != 'loading') { 2 ISCready(); 3} else { 4 // DOMContentLoaded fires after the content is loaded, but before scripts and images. 5 document.addEventListener( 'DOMContentLoaded', ISCready ); 6} 7 8/** 9 * Initialize ISC after the DOM was loaded 10 */ 11function ISCready(){ 12 /** 13 * Move caption into image with a short delay to way for the images to load 14 */ 15 setTimeout( function(){ 16 var captions = document.querySelectorAll( '.isc-source .isc-source-text' ); 17 var l = captions.length; 18 for ( var i = 0; i < l; i++ ) { 19 captions[i].setAttribute( "style", "position: absolute; font-size: 0.9em; background-color: #333; color: #fff; opacity: 0.70; padding: 0 0.15em; text-shadow: none; display: block" ); 20 // Some themes handle the bottom padding of the attachment's div with the caption text (which is in between 21 // the image and the bottom border) not with the div itself. The following line set the padding on the bottom equal to the top. 22 captions[i].style.paddingBottom = window.getComputedStyle( captions[i] )['padding-top']; 23 // position the parent element (.isc-source) 24 isc_update_caption_position( captions[i].parentNode ); 25 } 26 }, 100 ); 27 28 /** 29 * Load image source positions after the page â including images â loaded completely 30 * this resolves occasionally misplaced sources 31 */ 32 window.addEventListener( 'load', function() { 33 // the additional timeout seems needed to make it work reliably on Firefox 34 setTimeout( function(){ 35 isc_update_captions_positions(); 36 }, 100 ); 37 } ); 38 /** 39 * Register resize event to check caption positions 40 */ 41 window.addEventListener( 'resize', function() { 42 isc_update_captions_positions(); 43 } ); 44}; 45 46/** 47 * Iterate through image source captions and set their position on the screen 48 */ 49function isc_update_captions_positions() { 50 var captions = document.querySelectorAll( '.isc-source' ); 51 var l = captions.length; 52 for ( var i = 0; i < l; i++ ) { 53 isc_update_caption_position( captions[i] ); 54 } 55} 56 57/** 58 * Position a single image source caption 59 * 60 * @param el image source caption that needs positioning 61 */ 62function isc_update_caption_position( el ) { 63 var main_id = el.id; 64 65 // attachment ID. unused 66 var att_id = main_id.split( '_' )[2]; 67 68 var att = el.querySelector( 'img' ); 69 var attw = att.width; 70 var atth = att.height; 71 72 // relative position 73 var l = att.offsetLeft; 74 var t = att.offsetTop; 75 76 var caption = el.querySelector( '.isc-source-text' ); 77 78 // caption width + padding & margin (after moving onto image) 79 var tw = ISCouterWidth( caption ); 80 // caption height + padding (idem) 81 var th = ISCouterHeight( caption ); 82 83 var attpl = parseInt( window.getComputedStyle( att )[ 'padding-left' ].substring( 0, window.getComputedStyle( att )[ 'padding-left' ].indexOf( 'px' ) ) ); 84 var attpt = parseInt( window.getComputedStyle( att )[ 'padding-top' ].substring( 0, window.getComputedStyle( att )[ 'padding-top' ].indexOf( 'px' ) ) ); 85 var attml = parseInt( window.getComputedStyle( att )[ 'margin-left' ].substring( 0, window.getComputedStyle( att )[ 'margin-left' ].indexOf( 'px' ) ) ); 86 var attmt = parseInt( window.getComputedStyle( att )[ 'margin-top' ].substring( 0, window.getComputedStyle( att )[ 'margin-top' ].indexOf( 'px' ) ) ); 87 88 // caption horizontal margin 89 var tml = 5; 90 // caption vertical margin 91 var tmt = 5; 92 93 var pos = isc_front_data.caption_position; 94 var posl = 0; 95 var post = 0; 96 switch (pos) { 97 case 'top-left': 98 posl = l + attpl + attml + tml; 99 post = t + attpt + attmt + tmt; 100 break; 101 case 'top-center': 102 posl = l + (Math.round( attw / 2 ) - (Math.round( tw / 2 ))) + attpl + attml; 103 post = t + attpt + attmt + tmt; 104 break; 105 case 'top-right': 106 posl = l - attpl + attml - tml + attw - tw; 107 post = t + attpt + attmt + tmt; 108 break; 109 case 'center': 110 posl = l + (Math.round( attw / 2 ) - (Math.round( tw / 2 ))) + attpl + attml; 111 post = t + (Math.round( atth / 2 ) - (Math.round( th / 2 ))) + attpt + attmt; 112 break; 113 case 'bottom-left': 114 posl = l + attpl + attml + tml; 115 post = t - attpt + attmt - tmt - th + atth; 116 break; 117 case 'bottom-center': 118 posl = l + (Math.round( attw / 2 ) - (Math.round( tw / 2 ))) + attpl + attml; 119 post = t + attpt + attmt - tmt - th + atth; 120 break; 121 case 'bottom-right':
122 posl = l - attpl + attml - tml + attw - tw; 123 post = t + attpt + attmt - tmt - th + atth; 124 break; 125 } 126 caption.style.left = posl + 'px'; 127 caption.style.top = post + 'px'; 128 caption.style.zIndex = '9999'; 129} 130 131/** 132 * Polyfills to work on IE 8 133 * 134 * Note: there are a couple of holes, e.g., with missing addEventListener; I am not yet decided on adding full IE 8 support 135 */ 136// source: https://gist.github.com/abbotto/19a6680bf052e8c64f6e 137if ( ! window.getComputedStyle) { 138 /** 139 * Implement getComputedStyle() for browsers that donât support it, e.g., IE 8 140 * 141 * @param {(Element|null)} e 142 * @param {(null|string)=} t 143 * @return {(CSSStyleDeclaration|null)} 144 */ 145 window.getComputedStyle = function(e, t) { 146 return this.el = e, this.getPropertyValue = function(t) { 147 // @type {RegExp} 148 var n = /(\-([a-z]){1})/g; 149 return t == "float" && (t = "styleFloat"), n.test( t ) && (t = t.replace( n, function() { 150 return arguments[2].toUpperCase(); 151 } )), e.currentStyle[t] ? e.currentStyle[t] : null; 152 }, this; 153 }; 154} 155// mimics `outerWidth(true)` which includes margins 156// source http://youmightnotneedjquery.com/ 157function ISCouterWidth(el) { 158 var width = el.offsetWidth; 159 var style = getComputedStyle( el ); 160 161 width += parseInt( style.marginLeft ) + parseInt( style.marginRight ); 162 return width; 163} 164// mimics `outerHeight(true)` which includes margins 165// source http://youmightnotneedjquery.com/ 166function ISCouterHeight(el) { 167 var height = el.offsetHeight; 168 var style = getComputedStyle( el ); 169 170 height += parseInt( style.marginTop ) + parseInt( style.marginBottom ); 171 return height; 172}
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.