1(function($){ 2 $.fn.GBgallery = function(options){ 3 var main_this = this, The_img, Old_img, HideMath, MathLength, mainTime, effectTimer , gb_slider, gb_preview, next_click, preview_space, current_this, settings; 4 var more = false, loop_num = 1, total_loop_num, image_load = 0, font_size; 5 var defaultSettings = { 6 width : 900, 7 height : 500, 8 ImgTime : 6000, 9 EffectTime : 1500, 10 Resolution : 10, 11 Effect : 'bounce', 12 SpecialEffect : false, 13 FontSize : 'gb_mid', 14 AutoResize : true, 15 MobileSize : '280X154', 16 TabletSize : '700X390' 17 } 18 return main_this.each(function(){ 19 current_this = $(this); 20 if(options){ 21 if(typeof(options)=='string'){ 22 eval('var obj='+options); 23 settings = $.extend(true, {}, defaultSettings, obj); 24 }else{ 25 settings = $.extend(true, {}, defaultSettings, options); 26 } 27 } 28 29 30 settings.MobileSize = '280X154'; 31 settings.TabletSize = '700X390'; 32 var gb_gallery_device = current_this.find('.GB_helper').find('.gb_gallery_device'); 33 if(gb_gallery_device.width() == 1){ 34 settings.width = settings.MobileSize.substring(0,settings.MobileSize.indexOf('X')); 35 settings.height = settings.MobileSize.substring(settings.MobileSize.indexOf('X')+1); 36 settings.height = Math.round(settings.height / 10) * 10; 37 }else if(gb_gallery_device.width() == 2){ 38 settings.width = settings.TabletSize.substring(0,settings.TabletSize.indexOf('X')); 39 settings.height = settings.TabletSize.substring(settings.TabletSize.indexOf('X')+1); 40 settings.height = Math.round(settings.height / 10) * 10; 41 }else if(gb_gallery_device.width() == 3){ 42 settings.width = settings.TabletSize.substring(0,settings.TabletSize.indexOf('X')); 43 settings.height = settings.TabletSize.substring(settings.TabletSize.indexOf('X')+1); 44 settings.height = Math.round(settings.height / 10) * 10; 45 } 46
47 font_size = get_font_size(settings.width,settings.height); 48 gb_slider = current_this.find('.GB_gallery_slider'); 49 gb_preview = current_this.find('div[id^="GB_preview-"]'); 50 if(!current_this.find('.GB_helper').find('.GB_img_con').find('div').length){ 51 console.log('No images found'); 52 return false; 53 } 54 pre_load(current_this.find('.GB_helper').find('.GB_img_con')); 55 gb_loader(); 56 if(mainTime == true) 57 gb_loader(); 58 Old_img = The_img = current_this.find('.GB_helper').find('.GB_img_con').find('div[id^="GB_img_div"]:first-child'); 59 MathLength = settings.Resolution * settings.Resolution; 60 setMainSlider(); 61 //if there is more then 10 images 62 if(gb_preview.find('.GB_total').length){ 63 more = true; 64 //number of all the preview row's 65 total_loop_num = gb_preview.find('.GB_total').attr('row'); 66 } 67 gb_preview.find('.GB_preview_item').on('click',function(){getNext($(this).attr('id'));}); 68 gb_preview.find('.GB_gallery_preview_more_btn p').on('click',function(){seeMore();}); 69 //check if all images in the preview are loaded 70 //if not load again 1 more time 71 window.onload= function(){ 72 setTimeout(function(){ 73 jQuery('div[id^="gb_gallery-"]').each(function(){ 74 if(jQuery(this).find('.GB_gallery_slider').find('.GB_gallery_loader').css('display') == 'block'){ 75 console.log('Preview error '+jQuery(this).attr('id')); 76 force_load_gb_gallery(jQuery(this)); 77 } 78 }); 79 },3000); 80 }; 81 }); 82 83 //Set the divs (class^="GB_gallery_slider-) in please 84 function setMainSlider(){ 85 //set the width and height of the slider 86 gb_slider.width(settings.width); 87 gb_slider.height(settings.height); 88 //set the font-size of the slider 89 gb_slider.addClass(font_size); 90 gb_preview.addClass(font_size); 91 92 //set the first image to show 93 gb_slider.css({ 94 backgroundSize : settings.width+'px '+settings.height+'px', 95 backgroundImage : "url("+The_img.find('img').attr('src')+")" 96 }); 97 build_divs(); 98 //PREVIEW 99 //Set preview_space to the spaces between the preview divs depending on the GB gallery size 100 switch (true){ 101 case font_size.indexOf('gb_big5') >= 0: 102 if(font_size.indexOf('wide') > 0){ 103 preview_space = 1.31; 104 break; 105 }else{ 106 preview_space = 1.55; 107 break; 108 } 109 case font_size.indexOf('gb_big4') >= 0: 110 if(font_size.indexOf('wide') > 0){ 111 preview_space = 1.3; 112 break; 113 }else{ 114 preview_space = 1.50; 115 break; 116 } 117 case font_size.indexOf('gb_big3') >= 0: 118 if(font_size.indexOf('wide') > 0){ 119 preview_space = 1.33; 120 break; 121 }else{ 122 preview_space = 1.43; 123 break; 124 } 125 case font_size.indexOf('gb_big2') >= 0: 126 if(font_size.indexOf('wide') > 0){ 127 preview_space = 1.33; 128 break; 129 }else{ 130 preview_space = 1.4; 131 break; 132 } 133 case font_size.indexOf('gb_big1') >= 0: 134 if(font_size.indexOf('wide') > 0){ 135 preview_space = 1.3; 136 break; 137 }else{ 138 preview_space = 1.38; 139 break; 140 } 141 case font_size.indexOf('gb_small5') >= 0: 142 if(font_size.indexOf('wide') > 0){ 143 preview_space = 1.13; 144 break; 145 }else{ 146 preview_space = 1.15; 147 break; 148 } 149 case font_size.indexOf('gb_small4') >= 0: 150 if(font_size.indexOf('wide') > 0){ 151 preview_space = 0.95; 152 break; 153 }else{ 154 preview_space = 0.94; 155 break; 156 } 157 case font_size.indexOf('gb_small3') >= 0: 158 if(font_size.indexOf('wide') > 0){ 159 preview_space = 0.5; 160 break; 161 }else{ 162 preview_space = 0.5; 163 break; 164 } 165 case font_size.indexOf('gb_small2') >= 0: 166 if(font_size.indexOf('wide') > 0){ 167 preview_space = 0.5; 168 break; 169 }else{ 170 preview_space = 0.5; 171 break; 172 } 173 case font_size.indexOf('gb_small1') >= 0: 174 preview_space = 1; 175 break; 176 default: 177 if(font_size.indexOf('wide') > 0){ 178 preview_space = 1.23; 179 break; 180 }else{ 181 preview_space = 1.26; 182 break; 183 } 184 } 185 // set the width and height of one div.GB_gallery_slider in the slider 186 var factorH = settings.height / settings.Resolution; 187 188 gb_preview.width(settings.width); 189 190 //set the width and height of the preview ul 191 gb_preview.find('ul.GB_preview_items').width(settings.width); 192 gb_preview.find('ul.GB_preview_items').height((Math.ceil((factorH*1.5) / 10) * 10)+10); 193 194 195 //Preview height 196 if(font_size.indexOf('wide')>0){ 197 var Preview_height = Math.round(factorH*preview_space); 198 var Preview_width = Math.round(factorH*preview_space)*1.8; 199 }else{ 200 var Preview_height = Math.round(factorH*preview_space); 201 var Preview_width = Math.round(factorH*preview_space); 202 } 203 //set the first preview li's width and height 204 gb_preview.find('ul.GB_preview_items li').width(Preview_width); 205 gb_preview.find('ul.GB_preview_items li').height(Preview_height); 206 207 //if there is more then 10 images 208 if(gb_preview.find('ul.GB_preview_more_items').length){ 209 //set the maxHeight to 3 rows only, 37 = css spacing 210 gb_preview.find('.GB_gallery_preview_more').css({ 211 maxHeight : (Preview_height*3)+37 212 }); 213 214 //set the rest of the preview li's width and height 215 gb_preview.find('ul.GB_preview_more_items li').width(Preview_width * .85); 216 gb_preview.find('ul.GB_preview_more_items li').height(Preview_height * .85); 217 } 218 219 //show the first description div 220 gb_slider.find('.GB_gallery_desc_con').append(The_img.find('.GB_gallery_desc').clone()); 221 } 222 223 //Start the GB gallery loop 224 function startGBgallery(my_this){ 225 //console.log('Start: '+main_this.attr('id')); 226 if(mainTime != "pause"){ 227 mainTime= ""; 228 //The main Interval/loop start 229 mainTime = setInterval(function(){ 230 if(more && mainTime != "pause"){ 231 //set 10 preview for a row 232 if(loop_num == gb_preview.find('.GB_preview_items li').length){ 233 get_next_preview(loop_num); 234 } 235 if((loop_num / 10) >= total_loop_num) 236 loop_num = 0; 237 loop_num++; 238 } 239 //Because of the timer, need to check every step of the way is not paused 240 if(mainTime != "pause"){setSlider();} 241 if(mainTime != "pause"){runEffect();} 242 if(mainTime != "pause"){setDesc();} 243 244 },(settings.ImgTime-settings.EffectTime)); 245 } 246 } 247 248 //Set the divs (class^="GB_gallery_slider-) backgroundImage and next image 249 function setSlider(){ 250 var temp_divs_con = current_this.find('.GB_helper').find('.GB_divs_con').clone(); 251 //clear the effect divs in case of next image 252 gb_slider.find('.GB_divs_con').remove(); 253 254 //Set all the matrix divs backgroundImage and display them 255 temp_divs_con.find('div[class^="GB_gallery_slider-"]').find('div').css({ 256 backgroundImage : "url("+The_img.find('img').attr('src')+")", 257 display : 'block' 258 }); 259 260 //set the new effect divs in place 261 gb_slider.find('.GB_gallery_loader').before(temp_divs_con); 262 263 //check if there was a preview click 264 if(!next_click){ 265 Old_img = The_img; 266 //check if The_img is the last child 267 if(The_img.is(":last-child")){ 268 //get the first image 269 The_img = current_this.find('.GB_helper').find('.GB_img_con').find('div[id^="GB_img_div"]:first-child'); 270 }else{ 271 //get the next image 272 The_img = The_img.next(); 273 } 274 //set the image to display in the back ground 275 gb_slider.css({ 276 backgroundImage: "url("+The_img.find('img').attr('src')+")" 277 }); 278 }else{ 279 next_click = false; 280 } 281 } 282 283 //Set all the matrix divs in please + set the backgroundPosition and size 284 function build_divs(){ 285 var divs_con = current_this.find('.GB_helper').find('.GB_divs_con'); 286 // set the width and height of one div.GB_gallery_slider in the slider 287 var factorW = settings.width / settings.Resolution; 288 var factorH = settings.height / settings.Resolution; 289 //x represent the column's, y represent the row's 290 var i = 1,x = 0,y = 0; 291 292 293 294 //set all the GB_gallery_slider div's width, height, top, left 295 divs_con.find('div[class^="GB_gallery_slider-"]').each(function(){ 296 jQuery(this).css({ 297 width : factorW+"px", 298 height : factorH+"px", 299 top : (y * factorH).toFixed(2)+'px', 300 left : (x * factorW).toFixed(2)+'px' 301 }); 302 jQuery(this).attr({ 303 row : y, 304 column : x 305 }); 306 307 //set all the GB_gallery_slider inner div's width, height, backgroundSize, backgroundPosition 308 jQuery(this).find('div').css({ 309 width : factorW+'px', 310 height : factorH+'px', 311 backgroundSize : settings.width+'px '+settings.height+'px', 312 backgroundPosition : '-'+ (x*factorW).toFixed(2) + 'px -'+ (y*factorH).toFixed(2) +'px' 313 }); 314 //every 10 div's start a new row 315 if(i==10){ 316 i=1; 317 y++; 318 x=0; 319 }else{ 320 i++; 321 x++; 322 } 323 }); 324 } 325 326 //on preview click get the clicked image 327 function getNext(clicked_img){ 328 //stop the timers 329 window.clearInterval(mainTime); 330 mainTime = "pause"; 331 window.clearInterval(effectTimer); 332 gb_loader(); 333 334 //get the row number 335 var row_on = jQuery('#'+clicked_img).attr('row') * 10; 336 337 //set the loop_num to the clicked li 338 loop_num = jQuery('#'+clicked_img).attr('id').substring(jQuery('#'+clicked_img).attr('id').lastIndexOf("-")+1); 339 340 //get the post id 341 clicked_img = clicked_img.substring(clicked_img.indexOf("-")+1,clicked_img.length); 342 clicked_img = clicked_img.replace("-",""); 343 344 //set the post to The_img 345 The_img = current_this.find('.GB_helper').find('.GB_img_con').find('div[id$="'+clicked_img+'"]'); 346 347 //set the image to display in the back ground 348 gb_slider.css({ 349 backgroundImage: "url("+The_img.find('img').attr('src')+")" 350 }); 351 352 //clear the effect divs 353 gb_slider.find('.GB_divs_con').remove(); 354 355 //set the new image to the GB gallery slider 356 setTimeout(function(){setSlider();},800); 357 358 //set the new description 359 setDesc(); 360 361 //if the preview first line need to be replace 362 if(row_on != gb_preview.find('ul.GB_preview_items li:first-child').attr('row')){ 363 //set the row in preview line 364 get_next_preview(row_on); 365 } 366 367 //Indication foe a preview click 368 next_click = true; 369 370 gb_slider.find('div[class^="GB_gallery_slider-"]').css({ 371 display : 'block' 372 }); 373 //Start the GB Gallery with the effect 374 setTimeout(function(){ 375 if(mainTime == "pause") 376 mainTime = true; 377 runEffect(); 378 },settings.ImgTime); 379 gb_loader(); 380 } 381 382 //Show the title and description 383 function setDesc(){ 384 //clear the description 385 gb_slider.find('.GB_gallery_desc_con').html(''); 386 //set the new description 387 gb_slider.find('.GB_gallery_desc_con').append(The_img.find('.GB_gallery_desc').clone()); 388 } 389 390 //Run the effect 391 function runEffect(){ 392 if(mainTime != "pause"){ 393 window.clearInterval(mainTime); 394 mainTime = "pause"; 395 var effectCon = current_this.find('.GB_gallery_slider').find('.GB_divs_con'); 396 var Math_i = 0, check_i = 0; 397 //get the matrix for the effect 398 buildHideMath(); 399 window.clearInterval(effectTimer); 400 effectTimer = ""; 401 effectTimer = setInterval(function(){ 402 //if it's not the lase one 403 if(Math_i < MathLength-1){ 404 if(Math_i >= check_i){ 405 check_i = Math_i; 406 }else{ 407 window.clearInterval(effectTimer); 408 Math_i = check_i+1; 409 gb_slider.find('.GB_divs_con').remove(); 410 //set the new effect divs in place 411 gb_slider.find('.GB_gallery_loader').before(current_this.find('.GB_helper').find('.GB_divs_con').clone()); 412 runEffect(); 413 } 414 //hide the div in please HideMath[Math_i] 415 effectCon.find('.GB_gallery_slider-'+HideMath[Math_i]).find('div').hide(settings.Effect,'',400,Math_i++); 416 }else{ 417 //stop the effect Interval 418 window.clearInterval(effectTimer); 419
419 effectCon.find('.GB_gallery_slider-'+HideMath[Math_i]).find('div').hide(settings.Effect,function(){ 420 gb_slider.find('.GB_divs_con').remove(); 421 Math_i=MathLength; 422 setDesc(); 423 setTimeout(function(){ 424 mainTime = true; 425 startGBgallery(); 426 },settings.EffectTime);}); 427 Math_i++; 428 } 429 },(settings.EffectTime/MathLength)); 430 } 431 } 432 433 //build the HideMath array 434 function buildHideMath(){ 435 //if settings.Effect = true and the image hes effect 436 if(settings.SpecialEffect && The_img.find('img[effect]').length){ 437 HideMath = The_img.find('img').attr('effect').split(", "); 438 }else{ 439 HideMath = new Array(); 440 for(var i=0;i<MathLength;i++){ 441 HideMath.push(i); 442 } 443 } 444 } 445 446 //Pause the loop 447 function Pause(){ 448 window.clearInterval(mainTime); 449 window.clearInterval(effectTimer); 450 if(gb_slider.find(".GB_gallery_desc").attr("for") != The_img.attr('id')){ 451 setDesc(); 452 } 453 gb_slider.find('.GB_divs_con').remove(); 454 gb_slider.find('.GB_gallery_PP').css({ 455 backgroundPosition : '0px 39px', 456 display : 'block' 457 }); 458 mainTime = "pause"; 459 setTimeout(function(){ 460 gb_slider.find('.GB_gallery_PP').css({ 461 display : 'none' 462 }); 463 },1000); 464 } 465 466 //Play the loop 467 function Play(){ 468 mainTime = true; 469 gb_slider.find('.GB_gallery_PP').css({ 470 backgroundPosition : '0px 0px', 471 display : 'block' 472 }); 473 setTimeout(function(){ 474 gb_slider.find('.GB_gallery_PP').css({ 475 display : 'none' 476 }); 477 },1000); 478 startGBgallery(); 479 } 480 481 //Open the 'More' div 482 function seeMore(){ 483 if(gb_preview.find(".GB_gallery_preview_more").is(':visible')){ 484 gb_preview.find(".GB_gallery_preview_more_btn").find('p').removeClass('u'); 485 gb_preview.find(".GB_gallery_preview_more_btn").find('p').addClass('d'); 486 }else{ 487 gb_preview.find(".GB_gallery_preview_more_btn").find('p').removeClass('d'); 488 gb_preview.find(".GB_gallery_preview_more_btn").find('p').addClass('u'); 489 } 490 gb_preview.find(".GB_gallery_preview_more").slideToggle({direction: 'up'}); 491 } 492 493 //Load the next 10 preview to top 494 function get_next_preview(row_num){ 495 //Index / 10 = the row number 496 row_num = row_num / 10; 497 498 //if the row is the last 1 499 if(row_num > total_loop_num){ 500 row_num = 0; 501 } 502 if(row_num > 0 && row_num < 1){ 503 row_num = 0; 504 } 505 //from = the first line of the preview (visible) 506 var from = gb_preview.find('.GB_preview_items'); 507 508 //to = the container of the preview (not visible) 509 var to = gb_preview.find(".GB_gallery_preview_more").find('.GB_preview_more_items'); 510 511 //width and height of the first line of the preview (big) 512 var from_h = from.find('li:last-child').height(); 513 var from_w = from.find('li:last-child').width(); 514 515 //width and height of the preview (small) 516 var to_h = to.find('li:last-child').height(); 517 var to_w = to.find('li:last-child').width(); 518 519 //while there ar children in the preview(visible) set the width and height to the small preview 520 while(from.children().length){ 521 var gb_this = from.find('li:last-child'); 522 gb_this.width(to_w).height(to_h).prependTo(to); 523 } 524 525 //the row to move need to be in the big size 526 to.find('li[row='+row_num+']').each(function(){ 527 jQuery(this).width(from_w).height(from_h).appendTo(from).hide().show(settings.Effect,'',600); 528 }); 529 } 530 531 //Show/hide the loader image 532 function gb_loader(){ 533 gb_slider.find('.GB_gallery_loader').toggle(); 534 } 535 536 //pre load the GB gallery images 537 function pre_load(Images) { 538 Images.find('div[id^="GB_img_div"]').each(function(){ 539 jQuery('<img />')[0].src = jQuery(this).find('img').attr('src'); 540 jQuery('<img />')[0].onload = all_loaded(); 541 }); 542 } 543 544 //check if the first 10 images are loaded 545 function all_loaded(){ 546 var pre_img_length = gb_preview.find('.GB_preview_items').find('li').find('img').length; 547 image_load++; 548 if(image_load == pre_img_length){ 549 check_load(); 550 } 551 } 552 553 //check if all the preview images are loaded 554 function check_load(){ 555 var pre_img_length = gb_preview.find('.GB_preview_items').find('li').find('img').length; 556 var pre_img = gb_preview.find('.GB_preview_items').find('li').find('img'); 557 var img_num = 0; 558 pre_img.each(function(){ 559 jQuery(this).load(function(){ 560 img_num++; 561 if(img_num == pre_img_length){ 562 load_done(); 563 }else{ 564 gb_slider.find('.GB_gallery_loader').find('b').html(Math.round(((pre_img_length/100)*img_num)*100)); 565 } 566 }); 567 }); 568 } 569 570 //start the GB Gallery after all loaded 571 function load_done(){ 572 mainTime = true; 573 gb_slider.find('.GB_gallery_loader').hide(); 574 gb_preview.show(); 575 gb_slider.on({mouseenter: Pause,mouseleave: Play}); 576 setTimeout(function(){startGBgallery();},settings.EffectTime); 577 } 578 579 function force_load_gb_gallery(my_gallery){ 580 mainTime = true; 581 jQuery(my_gallery).find('.GB_gallery_slider').find('.GB_gallery_loader').hide(); 582 jQuery(my_gallery).find('div[id^="GB_preview-"]').show(); 583 jQuery(my_gallery).find('.GB_gallery_slider').on({mouseenter: Pause,mouseleave: Play}); 584 585 startGBgallery(); 586 } 587 588 //Return the FontSize 589 function get_font_size(the_width, the_height){ 590 switch (true) { 591 case the_width >= 1000: 592 if(the_height >= 500) 593 return "gb_big5"; 594 else 595 return "gb_big5_wide"; 596 case the_width >= 900: 597 if(the_height >= 500) 598 return "gb_big4"; 599 else 600 return "gb_big4_wide"; 601 case the_width >= 800: 602 if(the_height >= 400) 603 return "gb_big3"; 604 else 605 return "gb_big3_wide"; 606 case the_width >= 700: //for Tablet 607 if(the_height >= 300) 608 return "gb_big2"; 609 else 610 return "gb_big2_wide"; 611 case the_width >= 600: 612 if(the_height >= 300) 613 return "gb_big1"; 614 else 615 return "gb_big1_wide"; 616 case the_width >= 500: 617 if(the_height >= 200) 618 return "gb_mid"; 619 else 620 return "gb_mid_wide"; 621 case the_width >= 400: 622 if(the_height >= 200) 623 return "gb_small5"; 624 else 625 return "gb_small5_wide"; 626 case the_width >= 300: 627 if(the_height >= 100) 628 return "gb_small4"; 629 else 630 return "gb_small4_wide"; 631 case the_width >= 280: //for Mobiles 632 if(the_height >= 100) 633 return "gb_small4"; 634 else 635 return "gb_small4_wide"; 636 case the_width >= 200: 637 if(the_height >= 100) 638 return "gb_small3"; 639 else 640 return "gb_small3_wide"; 641 case the_width >= 100: 642 if(the_height >= 50) 643 return "gb_small2"; 644 else 645 return "gb_small2_wide"; 646 default: 647 return "gb_small1"; 648 } 649 } 650 } 651}(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.