1/*! 2 * jQuery Cover plugin - v1.0.0 (https://github.com/greenish/jquery-cover) 3 * 4 * Copyright (c) 2011 Philipp Adrian (www.philippadrian.com) 5 * 6 * The MIT Licence (http://opensource.org/licenses/MIT) 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 */ 26 27(function($) { 28//////////////////////////////////////////////////////////////////////////////// 29var cover=$.fn.cover = function (method){ 30 var call, args; 31 if(typeof(method) === 'object' || !method) { 32 args=arguments; 33 call="_init"; 34 } 35 else if(cover[method]) { 36 args=Array.prototype.slice.call(arguments,1); 37 call=method; 38 } 39 else throw "Error: The method \""+method+"\" doesn't exist in jQuery Cover"; 40 41 return $(this).each(function(){ 42// Make sure to select the image (and not a wrapper) 43 var img=$(this).is("img") ? $(this) : $("img", this), 44 data = img.data("data"); 45 46// IF already initialized -> update options. 47 if(call == "_init" && data) { 48 cover._opts(data, method, true); 49 return; 50 } 51 data = data || { 52 self:$(this), 53 callbacks : [] 54 }; 55 56 if(call=="_init") { 57 data.opts=method=="_init"?Array.prototype.slice.call(arguments,1):method; 58 args=[data]; 59 } 60 else args=[data].concat(args); 61 img.data("data", data); 62 if(call=="_triggerCallback") return cover[call].apply(img, args); 63 else try { 64 cover[call].apply(img, args); 65 } 66 catch(err){ 67 if(err!="callbackReturnedFalse") throw err; 68 } 69 }); 70}; 71$.extend(cover, { 72 interval:false, 73//////////////////////////////////////////////////////////////////////////////// 74 _init : function (data) { 75 76// Extends defaults into opts. 77 var opts=cover._opts(data, data.opts, true); 78 data.img = new Image(); 79 80// binding callbacks to make them available. 81 for(var callbacks in opts.callbacks) cover.bindCallback(data,callbacks,opts.callbacks[callbacks]); 82 83 data.img.src = data.self.attr("src"); 84 data.self.wrap($("<div class=\"greenishCover height\"\><div\>")); 85 data.wrapper=data.self.parent().parent(); 86 87 if(opts.backgroundPosition) { 88 if(opts.backgroundPosition.search(/top/i) >= 0) data.wrapper.addClass("top"); 89 else if(opts.backgroundPosition.search(/bottom/i) >= 0) data.wrapper.addClass("bottom"); 90 if(opts.backgroundPosition.search(/left/i) >= 0) data.wrapper.addClass("left"); 91 else if(opts.backgroundPosition.search(/right/i) >= 0) data.wrapper.addClass("right"); 92 } 93 94 if(opts.loadHidden) data.self.css({visibility:"hidden"}); 95 data.self.cover("_triggerCallback","preLoading"); // #CALLBACK 96 if(!cover.interval) cover.interval=setInterval(cover._loading, 100); 97 98 data.opts.checkWindowResize && $(window) 99 .unbind("resize.cover") 100 .bind("resize.cover", function(){$(".greenishCover").cover("update")}); 101 }, 102//////////////////////////////////////////////////////////////////////////////// 103 update : function() { 104 var that = $(this), 105 img=that.is("img") ? that : that.find("img"), 106 data = img.data("data"), 107 wrapper = data.wrapper,
108 current = wrapper.hasClass("height") ? "height":"width", 109 newRatio = wrapper.height()/wrapper.width() >= data.ratio ? "height":"width"; 110 111 if(current !== newRatio) { 112 wrapper.addClass(newRatio).removeClass(current); 113 img.cover("_triggerCallback","ratioSwitch"); // #CALLBACK 114 } 115 }, 116//////////////////////////////////////////////////////////////////////////////// 117 _loading : function () { 118 cover.complete=true; 119 $(".greenishCover").each(function (){ 120 var data = $("img", this).data("data"), 121 image= data.img; 122 if(!image || !image.complete || image.height <= 0 || image.width <= 0) { 123 cover.complete=false; 124 return; 125 } 126 data.ratio=image.height/image.width; 127 var marginTop=50/image.width*image.height; // Based on the fact that (marginTop 100% == width). 128 data.self.css({"marginTop":-marginTop+"%"}); 129 if(data.opts.loadHidden) data.self.css({visibility:"visible"}); 130 data.self.cover("_triggerCallback","postLoading"); // #CALLBACK 131 data.wrapper.cover("update"); 132 }); 133 if(cover.complete) { 134 clearInterval(cover.interval); 135 cover.interval=false; 136 } 137 }, 138//////////////////////////////////////////////////////////////////////////////// 139 bindCallback : function (data, callback, func) { 140 func=typeof(func)=="function"?[func]:func; 141 data.callbacks[callback]=data.callbacks[callback]||[]; 142 for(var key in func) data.callbacks[callback].push(func[key]); 143 }, 144//////////////////////////////////////////////////////////////////////////////// 145 _triggerCallback : function (data, callback, param) { 146 if(!data.callbacks[callback] || data.callbacks[callback].length <= 0) return param; 147 for(var key in data.callbacks[callback]) 148 if((param=data.callbacks[callback][key].apply(this, [data,param])) !== false) continue; 149 else throw "callbackReturnedFalse"; 150 return param; 151 }, 152//////////////////////////////////////////////////////////////////////////////// 153 _opts : function (data, opts, save) { 154 opts=$.extend(true,{},this.defaults, data.opts||{}, opts||{}); 155 if(save) data.opts=opts; 156 return opts; 157 }, 158//////////////////////////////////////////////////////////////////////////////// 159 defaults : { 160 backgroundPosition:false, 161 callbacks: {}, 162 checkWindowResize:true, 163 loadHidden : true 164 } 165}); 166})(jQuery); 167
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.