1/* 2==================================================================================================== 3@name jQuery imgCenter 4@description This Plug-In will center images inside of it's parent element 5@uri http://code.drewwilson.com/entry/imgcenter-jquery-plugin 6@version 1.0 7@author Drew Wilson 8@author-uri www.drewwilson.com 9@copyright 2009 Drew Wilson 10==================================================================================================== 11*/ 12 13(function($){ 14 $.fn.imgCenter = function(options) { 15 16 var defaults = { 17 parentSteps: 0, 18 scaleToFit: true, 19 centerVertical: true, 20 complete: function(){}, 21 start: function(){}, 22 end: function(){} 23 }; 24 var opts = $.extend(defaults, options); 25 26 opts.start.call(this); 27 28 // Get total number of items. 29 var len = this.length - 1; 30 31 return this.each(function(i){ 32 var current = i; 33 34 // Declare the current Image as a variable. 35 var org_image = $(this); 36 37 org_image.hide(); 38 39 // Move up Parents until the spcified limit has been met. 40 var theParent = org_image; 41 for (var i=0; i <= opts.parentSteps; i++){ 42 theParent = theParent.parent(); 43 } 44 var parWidth = parseInt(theParent.width()); 45 var parHeight = parseInt(theParent.height()); 46 var parAspect = parWidth / parHeight; 47 48 if(org_image[0].complete){ 49 imgMath(org_image); 50 } else { 51 var loadWatch = setInterval(watch, 500); 52 } 53 54 function watch(){ 55 if(org_image[0].complete){ 56 clearInterval(loadWatch); 57 imgMath(org_image); 58 } 59 } 60 61 function imgMath(org_image) { 62 // Get image properties. 63 var imgWidth = parseInt(org_image.width()); 64 var imgHeight = parseInt(org_image.height()); 65 var imgAspect = imgWidth / imgHeight; 66 67 // Center the image. 68 if(parWidth != imgWidth || parHeight != imgHeight){ 69 theParent.css("overflow","hidden"); 70 71 if(opts.scaleToFit){ 72 if(parAspect >= 1){ 73 org_image.css({"width": parWidth +"px"}); 74 imgWidth = parWidth; 75 imgHeight = Math.round(imgWidth / imgAspect); 76 77 if((parWidth / imgAspect) < parHeight){ 78 org_image.css({"height": parHeight +"px","width":"auto"}); 79 imgHeight = parHeight; 80 imgWidth = Math.round(imgHeight * imgAspect); 81 } 82 } else { 83 org_image.css({"height": parHeight +"px"}); 84 imgHeight = parHeight; 85 imgWidth = Math.round(imgHeight * imgAspect); 86 if((parHeight * imgAspect) < parWidth){ 87 org_image.css({"width": parWidth +"px","height":"auto"}); 88 imgWidth = parWidth; 89 imgHeight = Math.round(imgWidth / imgAspect); 90 } 91 } 92 if(imgWidth > parWidth){ 93 org_image.css({"margin-left":"-"+ Math.round((imgWidth - parWidth) / 2) +"px"}); 94 } 95 if(imgHeight > parHeight && opts.centerVertical){ 96 org_image.css({"margin-top":"-"+ Math.round((imgHeight - parHeight) / 2) +"px"}); 97 } 98 } else { 99 if(imgWidth > parWidth){ 100 org_image.css({"margin-left":"-"+ Math.round((imgWidth - parWidth) / 2) +"px"}); 101 } else if(imgWidth < parWidth){ 102 org_image.css({"margin-left": Math.round((parWidth -imgWidth) / 2) +"px"}); 103 } 104 if(imgHeight > parHeight && opts.centerVertical){ 105 org_image.css({"margin-top":"-"+ Math.round((imgHeight - parHeight) / 2) +"px"}); 106 } else if(imgHeight < parHeight && opts.centerVertical){ 107 org_image.css({"margin-top": Math.round((parHeight - imgHeight) / 2) +"px"}); 108 } 109 } 110 opts.complete.call(this); 111 if(current == len){ 112 opts.end.call(this); 113 } 114 } 115 org_image.show(); 116 } 117 118 }); 119 } 120})(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.