1(function( $ ){ 2 3 var defaults = { 4 stream: 'img', 5 onLoad : function() {} 6 } 7 8 var methods = { 9 10 init : function( options ) { 11 12 if(window[plugin] === undefined) { 13 window[plugin] = new Array(); 14 } 15 16 var pi = window[plugin].length; 17 18 window[plugin].push(pi); 19 20 window[plugin][pi] = $.extend({}, defaults, options); 21 window[plugin][pi].element = $(this); 22 23 window[plugin][pi].element.each(function() { 24 25 window[plugin][pi].width = window[plugin][pi].element.outerWidth(true); 26 window[plugin][pi].height = window[plugin][pi].element.outerHeight(true); 27 28 }); 29 30 $(window).resize(function() { methods.resize(pi); }); 31 32 methods.construct(pi); 33 34 }, 35 construct : function(pi) { 36 37 window[plugin][pi].images = []; 38 window[plugin][pi].rap = new Array(); 39 window[plugin][pi].streams = window[plugin][pi].element.find(window[plugin][pi].stream); 40 window[plugin][pi].count = window[plugin][pi].streams.length; 41 42 window[plugin][pi].streams.each(function(p) { 43 var _self = $(this); 44 window[plugin][pi].images[p] = new Image(); 45 window[plugin][pi].images[p].onload = function() { 46 47 window[plugin][pi].rap[p] = this.width / this.height; 48 49 if(window[plugin][pi].height > window[plugin][pi].width) { // format portrait 50 51 window[plugin][pi]._h = window[plugin][pi].height; 52 window[plugin][pi]._mt = -window[plugin][pi]._h/2; 53 window[plugin][pi]._w = window[plugin][pi]._h * window[plugin][pi].rap[p]; 54 window[plugin][pi]._ml = -window[plugin][pi]._w/2; 55 56 } else { // format landscape 57 58 window[plugin][pi]._w = window[plugin][pi].width; 59 window[plugin][pi]._ml = -window[plugin][pi]._w/2; 60 window[plugin][pi]._h = window[plugin][pi]._w / window[plugin][pi].rap[p]; 61 window[plugin][pi]._mt = -window[plugin][pi]._h/2; 62 63 } 64 65 if(window[plugin][pi]._h < window[plugin][pi].height) { 66 67 window[plugin][pi]._h = window[plugin][pi].height; 68 window[plugin][pi]._mt = -window[plugin][pi]._h/2; 69 window[plugin][pi]._w = window[plugin][pi]._h * window[plugin][pi].rap[p]; 70 window[plugin][pi]._ml = -window[plugin][pi]._w/2; 71 72 } 73 74 _self.css({ 75 'width': window[plugin][pi]._w, 76 'height': window[plugin][pi]._h, 77 'margin': window[plugin][pi]._mt + 'px 0 0 '+ window[plugin][pi]._ml +'px' 78 }).attr('data-width', this.width).attr('data-height', this.height); 79 80 if(!--window[plugin][pi].count) { window[plugin][pi].onLoad(); } 81 }; 82 //Handle srcset 83 var singleImg = $(this)[0]; 84 var src = $(this).attr('src'); 85 if (typeof singleImg.currentSrc !== 'undefined' && singleImg.currentSrc !== '') { 86 src = singleImg.currentSrc; 87 } 88 window[plugin][pi].images[p].src = src; 89 }); 90 91 }, 92 resize : function(pi) { 93 94 if( window[plugin][pi] != undefined ) { 95 96 window[plugin][pi].width = window[plugin][pi].element.outerWidth(true); 97 window[plugin][pi].height = window[plugin][pi].element.outerHeight(true); 98 99 window[plugin][pi].streams.each(function(p) { 100 var _self = $(this); 101 102 if(window[plugin][pi].height > window[plugin][pi].width) { // format portrait 103 104 var _h = window[plugin][pi].height; 105 var _mt = -_h/2; 106 var _w = _h * window[plugin][pi].rap[p]; 107 var _ml = -_w/2; 108 109 } else { // format landscape 110 111 var _w = window[plugin][pi].width; 112 var _ml = -_w/2; 113 var _h = _w / window[plugin][pi].rap[p]; 114 var _mt = -_h/2; 115 116 } 117 118 if(_h < window[plugin][pi].height) { 119 var _h = window[plugin][pi].height; 120 var _mt = -_h/2; 121 var _w = _h * window[plugin][pi].rap[p]; 122 var _ml = -_w/2; 123 } 124 125 _self.css({ 126 'width': _w, 127 'height': _h, 128 'margin': _mt + 'px 0 0 '+ _ml +'px' 129 }); 130 131 }); 132 133 } 134 135 } 136 137 }; 138 139 var plugin = 'resizeCenter'; 140 141 $.fn.resizeCenter = function( method ) { 142 143 if ( methods[method] ) { 144 return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); 145 } else if ( typeof method === 'object' || ! method ) { 146 return methods.init.apply( this, arguments ); 147 } else { 148 $.error( 'Method ' + method + ' does not exist on jQuery.resizeCenter' ); 149 } 150 151 }; 152 153})( jQuery );
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.