1// JavaScript Document 2// Copyright c2011 Aaron Vanderzwan, by Aaron Vanderzwan 3// Thanks to Skye Giordano for the suggestion of the resizeMsg option. 4// 5// LICENSE 6// This program is free software: you can redistribute it and/or modify 7// it under the terms of the GNU General Public License as published by 8// the Free Software Foundation, either version 3 of the License, or 9// (at your option) any later version. 10// 11// This program is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15// 16// You should have received a copy of the GNU General Public License 17// along with this program. If not, see <http://www.gnu.org/licenses/>. 18// 19// VERSION: 1.1.8 20 21 22 23 24(function($) { 25// The maxImages plugin resizes an image dynamically, according to the width of the browser. 26jQuery.fn.maxImage = function(options) { 27 28 var resizeMsgDefaults = {show: false, location: 'before', message: 'Original: ([w]w x [h]h)'}; 29 30 // var opts = $.extend({}, $.fn.maxImage.defaults, options); 31 var opts = jQuery.extend({ 32 wait: true, 33 imageArray: [], 34 maxFollows: 'both', // Options: width, height, both 35 verticalOffset: 0, 36 horizontalOffset: 0, 37 leftSpace: 0, 38 topSpace: 0, 39 rightSpace: 0, 40 bottomSpace: 0, 41 overflow: 'hidden', 42 position: 'absolute', 43 isBackground: false, 44 zIndex: -1, 45 verticalAlign: 'center', 46 horizontalAlign: 'center', 47 maxAtOrigImageSize: false, 48 slideShow: false, 49 slideDelay: 5, 50 slideShowTitle: true, 51 loaderClass: 'loader', 52 resizeMsg: resizeMsgDefaults, 53 onImageShow: function(){} 54 }, options); 55 56 // var resizeDefaults = {show: false, location: 'before', message: '(resized)'}; 57 opts.resizeMsg = jQuery.extend(resizeMsgDefaults, options.resizeMsg) 58 59 // Cache jQuery object 60 var jQueryMatchedObj = this; 61 62 function _initialize() { 63 _start(this,jQueryMatchedObj); 64 return false; 65 } 66 67 function _start(image,jQueryMatchedObj) { 68 if( opts.slideShow ){ 69 _setup_slideshow(jQueryMatchedObj); 70 } else if ( opts.isBackground ){ 71 Background._setup_background(image); 72 } else { 73 Others._setup_others(image,opts); 74 } 75 } 76 77 Others = { 78 _setup_others: function(image,opts){ 79 $this = $(image); 80 $this.hide(); 81 82 Others._configure_css(image,opts); 83 $(window).load(function(){ 84 _get_orig_data($this); 85 _size_image($this); 86 _center_image($this); 87 $this.show(); 88 $('.'+opts.loaderClass).hide(); 89 opts.onImageShow.call(this); 90 $(window).resize(function(){ 91 _size_image($this); 92 _center_image($this); 93 }); 94 }); 95 }, 96 _configure_css: function(image,opts){ 97 if(opts.position == 'absolute') { 98 99 $(image).css({ 100 'overflow': 'hidden', 101 'left': opts.leftSpace, 102 'top': opts.topSpace, 103 'position': 'absolute' 104 }); 105 106 if(opts.verticalAlign == 'bottom'){ 107 $(image).css({'bottom':opts.bottomSpace,'top':'auto'}); 108 } 109 if(opts.horizontalAlign == 'right'){ 110 $(image).css({'right':opts.rightSpace,'left':'auto'}); 111 } 112 } else { 113 $(image).css({ 114 'margin-top': opts.topSpace, 115 'margin-right': opts.rightSpace, 116 'margin-bottom': opts.bottomSpace, 117 'margin-left': opts.leftSpace, 118 'position': opts.position 119 }); 120 } 121 } 122 } 123 124 Background = { 125 _setup_background: function(image){ 126 $this = $(image); 127 $this.hide(); 128 129 Background._configure_css(image); 130 $(window).load(function(){ 131 _get_orig_data($this); 132 _size_image($this); 133 _center_image($this); 134 $this.show(); 135 $('.'+opts.loaderClass).hide(); 136 opts.onImageShow.call(this); 137 $(window).resize(function(){ 138 _size_image($this); 139 _center_image($this) 140 }); 141 }); 142 143 }, 144 _configure_css: function(image){
145 // If position is set to absolute (or if isBackground) 146 $(image).css({ 147 'z-index': opts.zIndex 148 }); 149 if(opts.position == 'absolute') { 150 $(image).css({ 151 'overflow': 'hidden', 152 'left': opts.leftSpace, 153 'top': opts.topSpace, 154 'position': 'absolute' 155 }); 156 157 $('html').css({'overflow-y':opts.overflow}); 158 159 if(opts.verticalAlign == 'bottom'){ 160 $(image).css({'bottom':opts.bottomSpace,'top':'auto'}); 161 } 162 if(opts.horizontalAlign == 'right'){ 163 $(image).css({'right':opts.rightSpace}); 164 } 165 } else { 166 $(image).css({ 167 'margin-top': opts.topSpace, 168 'margin-right': opts.rightSpace, 169 'margin-bottom': opts.bottomSpace, 170 'margin-left': opts.leftSpace, 171 'position': opts.position 172 }); 173 } 174 } 175 } 176 177 178 // SLIDESHOW FUNCTIONS 179 function _setup_slideshow (jQueryMatchedObj){ 180 _build_slideshow_structure(jQueryMatchedObj); 181 182 opts.imageArray.length = 0; 183 184 if( jQueryMatchedObj.length == 1){ 185 objClicked = jQueryMatchedObj[0]; 186 opts.imageArray.push(new Array(objClicked.getAttribute('src'),objClicked.getAttribute('title'))); 187 } else { 188 for ( var i = 0; i < jQueryMatchedObj.length; i++ ) { 189 opts.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('src'),jQueryMatchedObj[i].getAttribute('title'))); 190 $(jQueryMatchedObj[i]).attr('original',$(jQueryMatchedObj[i]).attr('src')).attr('src',''); 191 } 192 } 193 _configure_css(); 194 _loads_image(0); 195 } 196 197 function _build_slideshow_structure() { 198 for ( var i = 0; i < jQueryMatchedObj.length; i++ ) { 199 $(jQueryMatchedObj[i]).addClass('slides slide-'+i).after('<div class="slideTitle">'+$(jQueryMatchedObj[i]).attr('title')+'</div>'); 200 } 201 $('.slideTitle').hide().css({ 202 'padding':'10px', 203 'background':'#e0e0e0', 204 'position':'absolute', 205 'bottom':'0', 206 'right':'5%', 207 'opacity':'0.8' 208 }); 209 } 210 211 212 function _loads_image(nums){ 213 var currentImage = nums; 214 215 var objImagePreloader = new Image(); 216 objImagePreloader.onload = function() { 217 $('.slide-'+currentImage).attr('src',opts.imageArray[currentImage][0]); 218 _get_orig_data($('.slide-'+currentImage)); 219 _size_image($('.slide-'+currentImage)); 220 _center_image($('.slide-'+currentImage)); 221 if(currentImage==0) opts.onImageShow.call(this); 222 $(window).resize(function(){ 223 _size_image($('.slide-'+currentImage)); 224 _center_image($('.slide-'+currentImage)); 225 }); 226 227 if(currentImage==0){ 228 _start_timer(); 229 } 230 231 if(currentImage < opts.imageArray.length-1){ 232 _loads_image(currentImage+1); 233 } 234 } 235 objImagePreloader.src = opts.imageArray[currentImage][0]; 236 } 237 238 function _start_timer() { 239 var currentSlide = 0; 240 241 // Hide the loading graphic 242 $('.'+opts.loaderClass).hide(); 243 244 // Fade in first image 245 $('.slide-'+currentSlide).css({'z-index':opts.zIndex}).fadeIn(); 246 247 // If user wants to show titles, use this option 248 if(opts.slideShowTitle){ 249 $('.slide-'+currentSlide).next('.slideTitle').css({'z-index':opts.zIndex+1}).fadeIn(); 250 } 251 252 // Start timer for slideshow 253 setTimeout(function(){runSlideChange(currentSlide)}, (to_i(opts.slideDelay)*1000)); 254 } 255 function runSlideChange(currentSlide){ 256 if(currentSlide < opts.imageArray.length-1){ 257 currentSlide++; 258 lastSlide = currentSlide-1; 259 } else { 260 currentSlide=0; 261 lastSlide = opts.imageArray.length-1; 262 } 263 264 $('.slide-'+lastSlide).css({'z-index':opts.zIndex-1}).fadeOut('slow'); 265 $('.slide-'+currentSlide).css({'z-index':opts.zIndex}).fadeIn('slow'); 266 if(opts.slideShowTitle){ 267 next_title(currentSlide,lastSlide); 268 } 269 270 setTimeout(function(){runSlideChange(currentSlide)}, (to_i(opts.slideDelay)*1000)); 271 } 272 273 function _configure_css(){ 274 for(i=0;i<opts.imageArray.length;i++){ 275 // Style the slide 276 if(opts.position == 'absolute') { 277 $('.slide-'+i).css({ 278 'position': 'absolute', 279 'overflow': 'hidden' 280 }); 281 282 $('html').css({'overflow-y':opts.overflow}); 283 284 if(opts.verticalAlign == 'bottom'){ 285 $('.slide-'+i).css({'bottom':opts.bottomSpace}); 286 }else{ 287 $('.slide-'+i).css({'top':opts.topSpace}); 288 } 289 290 if(opts.horizontalAlign == 'right'){ 291 $('.slide-'+i).css({'right':opts.rightSpace}); 292 }else{ 293 $('.slide-'+i).css({'left':opts.leftSpace}); 294 } 295 } else { 296 $('.slide-'+i).css({ 297 'margin-top': opts.topSpace, 298 'margin-right': opts.rightSpace, 299 'margin-bottom': opts.bottomSpace, 300 'margin-left': opts.leftSpace, 301 'position': opts.position 302 }); 303 } 304 305 306 // Style the title 307 $('.slide-'+i).next('.slideTitle').css({ 308 'position':'absolute', 309 'bottom':0, 310 'right':'5%' 311 }); 312 } 313 } 314 315
316 function next_title(currentSlide,lastSlide){ 317 $('.slide-'+lastSlide).next('.slideTitle').fadeOut(); 318 $('.slide-'+currentSlide).next('.slideTitle').fadeIn(); 319 } 320 321 322 // BROAD FUNCTIONS - FOR EACH SECTION 323 function _center_image(image){ 324 $this = image; 325 326 if(opts.horizontalAlign == 'center'){ 327 var pageWidth = $(window).width() - opts.horizontalOffset; 328 var newWidth = -1*($this.width() - pageWidth)/2; 329 $(image).css({'left':newWidth}); 330 } 331 332 if(opts.verticalAlign == 'center'){ 333 var pageHeight = $(window).height() - opts.verticalOffset; 334 var newHeight = -1*($this.height() - pageHeight)/2; 335 $(image).css({'top':newHeight}); 336 } 337 } 338 339 function _get_orig_data(image){ 340 $this = image; 341 342 $this.attr('origWidth', $this.width()); 343 $this.attr('origHeight', $this.height()); 344 $this.attr('ratio', find_ratio($this.width(),$this.height())); 345 } 346 347 function _size_image(image){ 348 $this = image; 349 350 var originalWidth = to_i($this.attr('origWidth')); 351 var originalHeight = to_i($this.attr('origHeight')); 352 var ratio = $this.attr('ratio'); 353 354 if(originalWidth == 0 || originalHeight == 0){ 355 setTimeout(function(){ 356 _get_orig_data(image); 357 _size_image(image); 358 }, 100); 359 return; 360 } 361 362 var width_and_height = []; 363 width_and_height = find_width_and_height(originalWidth,originalHeight,ratio); 364 365 $this.width( width_and_height[0] ); 366 $this.height( width_and_height[1] ); 367 368 _show_resize_message(originalWidth,originalHeight,image); 369 } 370 371 function _show_resize_message(originalWidth,originalHeight,image){ 372 if( (to_i($this.width()) != originalWidth || to_i($this.height()) != originalHeight) && opts.resizeMsg.show){ 373 $(".maximage_resized").remove(); 374 375 // Replace [w] and [h] with their respective width or height 376 opts.resizeMsg.message = opts.resizeMsg.message.replace('[w]',originalWidth).replace('[h]',originalHeight); 377 378 var insertStr = '<div class="maximage_resized">' + opts.resizeMsg.message + '</div>'; 379 if(opts.resizeMsg.location.toLowerCase() == "before"){ 380 $this.before(insertStr); 381 } else { 382 $this.after(insertStr); 383 } 384 } 385 } 386 387 function find_width_and_height(originalWidth,originalHeight,ratio) { 388 var pageWidth = $(window).width() - opts.horizontalOffset; 389 var pageHeight = $(window).height() - opts.verticalOffset; 390 391 if(!opts.isBackground){ 392 if(opts.maxFollows=='both'){ 393 max_follows_width(pageWidth,ratio); 394 395 if( height > pageHeight ){ 396 max_follows_height(pageHeight,ratio); 397 } 398 } else if (opts.maxFollows == 'width'){ 399 max_follows_width(pageWidth,ratio); 400 } else if (opts.maxFollows == 'height'){ 401 max_follows_height(pageHeight,ratio); 402 } 403 }else{ 404 width = pageWidth + 40; 405 height = width/ratio; 406 407 if( height < pageHeight ){ 408 height = pageHeight - (opts.topSpace + opts.bottomSpace); 409 width = height*ratio; 410 } 411 } 412 413 // If maxAtRatio == true and your new width is larger than originalWidth, size to originalWidth 414 if ( opts.maxAtOrigImageSize && width > originalWidth){ 415 arrayImageSize = new Array(originalWidth,originalHeight); 416 }else{ 417 arrayImageSize = new Array(width,height); 418 } 419 return arrayImageSize; 420 } 421 422 function max_follows_height(pageHeight,ratio){ 423 height = pageHeight - (opts.topSpace + opts.bottomSpace); // Page Height minus topSpace and bottomSpace 424 width = height*ratio; 425 } 426 427 function max_follows_width(pageWidth,ratio){ 428 width = pageWidth - (opts.leftSpace + opts.rightSpace); // Page Width minus leftSpace and rightSpace 429 height = width/ratio; 430 } 431 432 function find_ratio(width,height) { 433 width = to_i(width); 434 height = to_i(height); 435 var ratio = width/height; 436 ratio = ratio.toFixed(2); 437 return ratio; 438 } 439 440 function to_i(i){ 441 last = parseInt(i); 442 return last; 443 } 444 445 // private function for debugging 446 function debug($obj) { 447 if (window.console && window.console.log) { 448 window.console.log($obj); 449 } 450 } 451 452 return this.each(_initialize); 453}; 454 455 456})(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.