1/** 2 * PgwSlideshow - Version 2.0 3 * 4 * Copyright 2014, Jonathan M. Piat 5 * http://pgwjs.com - http://pagawa.com 6 * 7 * Released under the GNU GPLv3 license - http://opensource.org/licenses/gpl-3.0 8 */ 9;(function($){ 10 $.fn.pgwSlideshow = function(options) { 11 12 var defaults = { 13 mainClassName : 'pgwSlideshow', 14 transitionEffect : 'sliding', 15 displayList : true, 16 displayControls : true, 17 touchControls : true, 18 autoSlide : false, 19 beforeSlide : false, 20 afterSlide : false, 21 maxHeight : null, 22 adaptiveDuration : 200, 23 transitionDuration : 500, 24 intervalDuration : 3000 25 }; 26 27 if (this.length == 0) { 28 return this; 29 } else if(this.length > 1) { 30 this.each(function() { 31 $(this).pgwSlideshow(options); 32 }); 33 return this; 34 } 35 36 var pgwSlideshow = this; 37 pgwSlideshow.plugin = this; 38 pgwSlideshow.config = {}; 39 pgwSlideshow.data = []; 40 pgwSlideshow.currentSlide = 0; 41 pgwSlideshow.slideCount = 0; 42 pgwSlideshow.resizeEvent = null; 43 pgwSlideshow.intervalEvent = null; 44 pgwSlideshow.touchFirstPosition = null; 45 pgwSlideshow.touchListLastPosition = false; 46 pgwSlideshow.window = $(window); 47 48 // Init 49 var init = function() { 50 51 // Merge user options with the default configuration 52 pgwSlideshow.config = $.extend({}, defaults, options); 53 54 // Setup 55 setup(); 56 57 // Check list 58 if (pgwSlideshow.config.displayList) { 59 checkList(); 60 } 61 62 // Resize trigger 63 pgwSlideshow.window.resize(function() { 64 clearTimeout(pgwSlideshow.resizeEvent); 65 pgwSlideshow.resizeEvent = setTimeout(function() { 66 setSizeClass(); 67 68 var maxHeight = pgwSlideshow.plugin.find('.ps-current > ul > li.elt_' + pgwSlideshow.currentSlide + ' img').height(); 69 updateHeight(maxHeight); 70 71 if (pgwSlideshow.config.displayList) { 72 checkList(); 73 checkSelectedItem(); 74 } 75 }, 100); 76 }); 77 78 // Activate interval 79 if (pgwSlideshow.config.autoSlide) { 80 activateInterval(); 81 } 82 83 return true; 84 }; 85 86 // Update the current height 87 var updateHeight = function(height, animate) { 88 89 // Check maxHeight 90 if (pgwSlideshow.config.maxHeight) { 91 if (height + pgwSlideshow.plugin.find('.ps-list').height() > pgwSlideshow.config.maxHeight) { 92 height = pgwSlideshow.config.maxHeight - pgwSlideshow.plugin.find('.ps-list').height(); 93 } 94 } 95 96 if (typeof pgwSlideshow.plugin.find('.ps-current').animate == 'function') { 97 pgwSlideshow.plugin.find('.ps-current').stop().animate({ 98 height: height 99 }, pgwSlideshow.config.adaptiveDuration, function() { 100 if (pgwSlideshow.config.maxHeight) { 101 pgwSlideshow.plugin.find('.ps-current > ul > li img').css('max-height', height + 'px'); 102 } 103 }); 104 } else { 105 pgwSlideshow.plugin.find('.ps-current').css('height', height); 106 107 if (pgwSlideshow.config.maxHeight) { 108 pgwSlideshow.plugin.find('.ps-current > ul > li img').css('max-height', height + 'px'); 109 } 110 } 111 112 return true; 113 }; 114 115 // Set list width 116 var setListWidth = function() { 117 var listWidth = 0; 118 119 // The plugin must be visible for a correct calculation 120 pgwSlideshow.plugin.show(); 121 122 pgwSlideshow.plugin.find('.ps-list > ul > li').show().each(function() { 123 listWidth += $(this).width(); 124 }); 125 126 pgwSlideshow.plugin.find('.ps-list >
126 ul').width(listWidth); 127 return true; 128 } 129 130 // Set size class 131 var setSizeClass = function() { 132 if (pgwSlideshow.plugin.width() <= 480) { 133 pgwSlideshow.plugin.addClass('narrow').removeClass('wide'); 134 } else { 135 pgwSlideshow.plugin.addClass('wide').removeClass('narrow'); 136 } 137 138 return true; 139 }; 140 141 // Setup 142 var setup = function() { 143 144 // Create container 145 pgwSlideshow.plugin.removeClass('pgwSlideshow').removeClass(pgwSlideshow.config.mainClassName); 146 pgwSlideshow.plugin.wrap('<div class="ps-list"></div>'); 147 pgwSlideshow.plugin = pgwSlideshow.plugin.parent(); 148 149 pgwSlideshow.plugin.wrap('<div class="' + pgwSlideshow.config.mainClassName + '"></div>'); 150 pgwSlideshow.plugin = pgwSlideshow.plugin.parent(); 151 152 pgwSlideshow.plugin.prepend('<div class="ps-current"><ul></ul><span class="ps-caption"></span></div>'); 153 pgwSlideshow.slideCount = pgwSlideshow.plugin.find('.ps-list > ul > li').length; 154 155 if (pgwSlideshow.slideCount == 0) { 156 throw new Error('pgwSlideshow - No slider item has been found'); 157 return false; 158 } 159 160 // Prev / Next icons 161 if (pgwSlideshow.slideCount > 1) { 162 163 // Slider controls 164 if (pgwSlideshow.config.displayControls) { 165 pgwSlideshow.plugin.find('.ps-current').prepend('<span class="ps-prev"><span class="ps-prevIcon"></span></span>'); 166 pgwSlideshow.plugin.find('.ps-current').append('<span class="ps-next"><span class="ps-nextIcon"></span></span>'); 167 pgwSlideshow.plugin.find('.ps-current .ps-prev').click(function() { 168 pgwSlideshow.previousSlide(); 169 }); 170 pgwSlideshow.plugin.find('.ps-current .ps-next').click(function() { 171 pgwSlideshow.nextSlide(); 172 }); 173 } 174 175 // Touch controls for current image 176 if (pgwSlideshow.config.touchControls) { 177 178 pgwSlideshow.plugin.find('.ps-current').on('touchstart', function(e) { 179 try { 180 if (e.originalEvent.touches[0].clientX && pgwSlideshow.touchFirstPosition == null) { 181 pgwSlideshow.touchFirstPosition = e.originalEvent.touches[0].clientX; 182 } 183 } catch(e) { 184 pgwSlideshow.touchFirstPosition = null; 185 } 186 }); 187 188 pgwSlideshow.plugin.find('.ps-current').on('touchmove', function(e) { 189 try { 190 if (e.originalEvent.touches[0].clientX && pgwSlideshow.touchFirstPosition != null) { 191 if (e.originalEvent.touches[0].clientX > (pgwSlideshow.touchFirstPosition + 50)) { 192 pgwSlideshow.touchFirstPosition = null; 193 pgwSlideshow.previousSlide(); 194 } else if (e.originalEvent.touches[0].clientX < (pgwSlideshow.touchFirstPosition - 50)) { 195 pgwSlideshow.touchFirstPosition = null; 196 pgwSlideshow.nextSlide(); 197 } 198 } 199 } catch(e) { 200 pgwSlideshow.touchFirstPosition = null; 201 } 202 }); 203 204 pgwSlideshow.plugin.find('.ps-current').on('touchend', function(e) { 205 pgwSlideshow.touchFirstPosition = null; 206 }); 207 } 208 } 209 210 // Get slideshow elements 211 var elementId = 1; 212 pgwSlideshow.plugin.find('.ps-list > ul > li').each(function() { 213 var element = getElement($(this));
214 element.id = elementId; 215 pgwSlideshow.data.push(element); 216 217 $(this).addClass('elt_' + element.id); 218 $(this).wrapInner('<span class="ps-item' + (elementId == 1 ? ' ps-selected' : '') + '"></span>'); 219 220 // Set element in the current list 221 var currentElement = $('<li class="elt_' + elementId + '"></li>'); 222 223 if (element.image) { 224 currentElement.html('<img src="' + element.image + '" alt="' + (element.title ? element.title : '') + '">'); 225 } else if (element.thumbnail) { 226 currentElement.html('<img src="' + element.thumbnail + '" alt="' + (element.title ? element.title : '') + '">'); 227 } 228 229 if (element.link) { 230 currentElement.html('<a data-lightbox="property" href="' + element.link + '"' + (element.linkTarget ? ' target="' + element.linkTarget + '"' : '') + '>' + currentElement.html() + '</a>'); 231 } 232 233 pgwSlideshow.plugin.find('.ps-current > ul').append(currentElement); 234 235 $(this).css('cursor', 'pointer').click(function(event) { 236 event.preventDefault(); 237 displayElement(element.id); 238 }); 239 240 elementId++; 241 242 243 }); 244 245 246 247 248 // Set list elements 249 if (pgwSlideshow.config.displayList) { 250 setListWidth(); 251 252 pgwSlideshow.plugin.find('.ps-list').prepend('<span class="ps-prev"><span class="ps-prevIcon"></span></span>'); 253 pgwSlideshow.plugin.find('.ps-list').append('<span class="ps-next"><span class="ps-nextIcon"></span></span>'); 254 pgwSlideshow.plugin.find('.ps-list').show(); 255 } else { 256 pgwSlideshow.plugin.find('.ps-list').hide(); 257 } 258 259 // Attach slide events 260 if (pgwSlideshow.config.autoSlide) { 261 pgwSlideshow.plugin.on('mouseenter', function() { 262 clearInterval(pgwSlideshow.intervalEvent); 263 pgwSlideshow.intervalEvent = null; 264 }).on('mouseleave', function() { 265 activateInterval(); 266 }); 267 } 268 269 // Disable current elements 270 pgwSlideshow.plugin.find('.ps-current > ul > li').hide(); 271 272 // Display the first element 273 displayElement(1); 274 275 // Set the first height 276 pgwSlideshow.plugin.find('.ps-current > ul > li.elt_1 img').on('load', function() { 277 setSizeClass(); 278 279 var maxHeight = pgwSlideshow.plugin.find('.ps-current > ul > li.elt_1 img').height(); 280 updateHeight(maxHeight); 281 }); 282 283 // Enable slideshow 284 setSizeClass(); 285 pgwSlideshow.plugin.show(); 286 287 return true; 288 }; 289 290 // Get element 291 var getElement = function(obj) { 292 var element = {}; 293 294 // Get link 295 var elementLink = obj.find('a').attr('href'); 296 if ((typeof elementLink != 'undefined') && (elementLink != '')) { 297 element.link = elementLink; 298 var elementLinkTarget = obj.find('a').attr('target'); 299 if ((typeof elementLinkTarget != 'undefined') && (elementLinkTarget != '')) { 300 element.linkTarget = elementLinkTarget; 301 } 302 } 303 304 // Get image
305 var elementThumbnail = obj.find('img').attr('src'); 306 if ((typeof elementThumbnail != 'undefined') && (elementThumbnail != '')) { 307 element.thumbnail = elementThumbnail; 308 } 309 310 var elementImage = obj.find('img').attr('data-large-src'); 311 if ((typeof elementImage != 'undefined') && (elementImage != '')) { 312 element.image = elementImage; 313 } 314 315 // Get title 316 var elementTitle = obj.find('img').attr('alt'); 317 if ((typeof elementTitle != 'undefined') && (elementTitle != '')) { 318 element.title = elementTitle; 319 } 320 321 // Get description 322 var elementDescription = obj.find('img').attr('data-description'); 323 if ((typeof elementDescription != 'undefined') && (elementDescription != '')) { 324 element.description = elementDescription; 325 } 326 327 return element; 328 }; 329 330 // Finish element 331 var finishElement = function(element) { 332 333 // Element caption 334 var elementText = ''; 335 if (element.title) { 336 elementText += '<b>' + element.title + '</b>'; 337 } 338 339 if (element.description) { 340 if (elementText != '') elementText += '<br>'; 341 elementText += element.description; 342 } 343 344 if (elementText != '') { 345 if (element.link) { 346 elementText = '<a href="' + element.link + '"' + (element.linkTarget ? ' target="' + element.linkTarget + '"' : '') + '>' + elementText + '</a>'; 347 } 348 349 if (typeof pgwSlideshow.plugin.find('.ps-caption').fadeIn == 'function') { 350 pgwSlideshow.plugin.find('.ps-caption').html(elementText); 351 pgwSlideshow.plugin.find('.ps-caption').fadeIn(pgwSlideshow.config.transitionDuration / 2); 352 } else { 353 pgwSlideshow.plugin.find('.ps-caption').html(elementText); 354 pgwSlideshow.plugin.find('.ps-caption').show(); 355 } 356 } 357 358 // Update list items 359 pgwSlideshow.plugin.find('.ps-list > ul > li .ps-item').removeClass('ps-selected'); 360 pgwSlideshow.plugin.find('.ps-list > ul > li.elt_' + element.id + ' .ps-item').addClass('ps-selected'); 361 362 // Check selected item 363 if (pgwSlideshow.config.displayList) { 364 checkList(); 365 checkSelectedItem(); 366 } 367 368 // Slideshow controls 369 if (pgwSlideshow.config.displayControls) { 370 if (typeof pgwSlideshow.plugin.find('.ps-current > .ps-prev').fadeIn == 'function') { 371 pgwSlideshow.plugin.find('.ps-current > .ps-prev, .ps-current > .ps-next').fadeIn(pgwSlideshow.config.transitionDuration / 2); 372 } else { 373 pgwSlideshow.plugin.find('.ps-current > .ps-prev, .ps-current > .ps-next').show(); 374 } 375 } 376 377 // After slide 378 if (typeof pgwSlideshow.config.afterSlide == 'function') { 379 pgwSlideshow.config.afterSlide(element.id); 380 } 381 382 // Set the container height 383 var maxHeight = pgwSlideshow.plugin.find('.ps-current .elt_' + element.id + ' img').height(); 384 updateHeight(maxHeight, true); 385 386 return true; 387 } 388 389 // Fade an element 390 var fadeElement = function(element) { 391 var elementContainer = pgwSlideshow.plugin.find('.ps-current > ul'); 392 393 elementContainer.find('li').not('.elt_' + pgwSlideshow.currentSlide).not('.elt_' + element.id).each(function(){ 394 if (typeof $(this).stop == 'function') { 395 $(this).stop(); 396 } 397 $(this).css('position', '').css('z-index', 1).hide(); 398 }); 399 400 // Current element 401 if (pgwSlideshow.currentSlide > 0) { 402 var currentElement = elementContainer.find('.elt_' + pgwSlideshow.currentSlide); 403 404 if (typeof currentElement.animate != 'function') { 405 currentElement.animate = function(css, duration, callback) { 406 currentElement.css(css); 407 if (callback) { 408 callback(); 409 } 410 }; 411 } 412 413 if (typeof currentElement.stop == 'function') { 414 currentElement.stop(); 415 } 416 417 currentElement.css('position', 'absolute').animate({ 418 opacity : 0, 419 }, pgwSlideshow.config.transitionDuration, function() { 420 currentElement.css('position', '').css('z-index', 1).hide(); 421 }); 422 } 423 424 // Update current id
425 pgwSlideshow.currentSlide = element.id; 426 427 // Next element 428 var nextElement = elementContainer.find('.elt_' + element.id); 429 430 if (typeof nextElement.animate != 'function') { 431 nextElement.animate = function(css, duration, callback) { 432 nextElement.css(css); 433 if (callback) { 434 callback(); 435 } 436 }; 437 } 438 439 if (typeof nextElement.stop == 'function') { 440 nextElement.stop(); 441 } 442 443 nextElement.css('position', 'absolute').show().animate({ 444 opacity : 1, 445 }, pgwSlideshow.config.transitionDuration, function() { 446 nextElement.css('position', '').css('z-index', 2).css('display', 'block'); 447 finishElement(element); 448 }); 449 450 return true; 451 } 452 453 // Slide an element 454 var slideElement = function(element, direction) { 455 var elementContainer = pgwSlideshow.plugin.find('.ps-current > ul'); 456 457 if (typeof direction == 'undefined') { 458 direction = 'left'; 459 } 460 461 if (pgwSlideshow.currentSlide == 0) { 462 elementContainer.find('.elt_1').css({ 463 position : '', 464 left : '', 465 opacity : 1, 466 'z-index' : 2 467 }).show(); 468 pgwSlideshow.plugin.find('.ps-list > li.elt_1').css('opacity', '1'); 469 finishElement(element); 470 471 } else { 472 473 if (pgwSlideshow.transitionInProgress) { 474 return false; 475 } 476 477 pgwSlideshow.transitionInProgress = true; 478 479 // Get direction details 480 var elementWidth = elementContainer.width(); 481 482 if (direction == 'left') { 483 var elementDest = -elementWidth; 484 var nextOrigin = elementWidth; 485 } else { 486 var elementDest = elementWidth; 487 var nextOrigin = -elementWidth; 488 } 489 490 var currentElement = elementContainer.find('.elt_' + pgwSlideshow.currentSlide); 491 492 if (typeof currentElement.animate != 'function') { 493 currentElement.animate = function(css, duration, callback) { 494 currentElement.css(css); 495 if (callback) { 496 callback(); 497 } 498 }; 499 } 500 501 currentElement.css('position', 'absolute').animate({ 502 left : elementDest, 503 }, pgwSlideshow.config.transitionDuration, function() { 504 currentElement.css('position', '').css('z-index', 1).css('left', '').css('opacity', 0).hide(); 505 }); 506 507 // Next element 508 var nextElement = elementContainer.find('.elt_' + element.id); 509 510 if (typeof nextElement.animate != 'function') { 511 nextElement.animate = function(css, duration, callback) { 512 nextElement.css(css); 513 if (callback) { 514 callback(); 515 } 516 }; 517 } 518 519 nextElement.css('position', 'absolute').css('left', nextOrigin).css('opacity', 1).show().animate({ 520 left : 0, 521 }, pgwSlideshow.config.transitionDuration, function() { 522 nextElement.css('position', '').css('left', '').css('z-index', 2).show(); 523 pgwSlideshow.transitionInProgress = false; 524 finishElement(element); 525 }); 526 } 527 528 // Update current id 529 pgwSlideshow.currentSlide = element.id; 530 531 return true; 532 } 533 534 // Display current element 535 var displayElement = function(elementId, apiController, direction) { 536 537 if (elementId == pgwSlideshow.currentSlide) { 538 return false;
539 } 540 541 var element = pgwSlideshow.data[elementId - 1]; 542 543 if (typeof element == 'undefined') { 544 throw new Error('pgwSlideshow - The element ' + elementId + ' is undefined'); 545 return false; 546 } 547 548 if (typeof direction == 'undefined') { 549 direction = 'left'; 550 } 551 552 // Before slide 553 if (typeof pgwSlideshow.config.beforeSlide == 'function') { 554 pgwSlideshow.config.beforeSlide(elementId); 555 } 556 557 if (typeof pgwSlideshow.plugin.find('.ps-caption').fadeOut == 'function') { 558 pgwSlideshow.plugin.find('.ps-caption, .ps-prev, .ps-next').fadeOut(pgwSlideshow.config.transitionDuration / 2); 559 } else { 560 pgwSlideshow.plugin.find('.ps-caption, .ps-prev, .ps-next').hide(); 561 } 562 563 // Choose the transition effect 564 if (pgwSlideshow.config.transitionEffect == 'sliding') { 565 slideElement(element, direction); 566 } else { 567 fadeElement(element); 568 } 569 570 // Reset interval to avoid a half interval after an API control 571 if (typeof apiController != 'undefined' && pgwSlideshow.config.autoSlide) { 572 activateInterval(); 573 } 574 575 return true; 576 }; 577 578 // Activate interval 579 var activateInterval = function() { 580 clearInterval(pgwSlideshow.intervalEvent); 581 582 if (pgwSlideshow.slideCount > 1 && pgwSlideshow.config.autoSlide) { 583 pgwSlideshow.intervalEvent = setInterval(function() { 584 if (pgwSlideshow.currentSlide + 1 <= pgwSlideshow.slideCount) { 585 var nextItem = pgwSlideshow.currentSlide + 1; 586 } else { 587 var nextItem = 1; 588 } 589 displayElement(nextItem); 590 }, pgwSlideshow.config.intervalDuration); 591 } 592 593 return true; 594 }; 595 596 // Check slide list 597 var checkList = function() { 598 if (! pgwSlideshow.config.displayList) return false; 599 600 // Refresh list width 601 setListWidth(); 602 603 var containerObject = pgwSlideshow.plugin.find('.ps-list'); 604 var containerWidth = containerObject.width(); 605 var listObject = pgwSlideshow.plugin.find('.ps-list > ul'); 606 var listWidth = listObject.width(); 607 608 if (listWidth > containerWidth) { 609 listObject.css('margin', '0 45px'); 610 611 var marginLeft = parseInt(listObject.css('margin-left')); 612 var marginRight = parseInt(listObject.css('margin-right')); 613 containerWidth -= (marginLeft + marginRight); 614 615 // Left button 616 containerObject.find('.ps-prev').show().unbind('click').click(function() { 617 var oldPosition = parseInt(listObject.css('left')); 618 var newPosition = oldPosition + containerWidth; 619 620 if (oldPosition == 0) { 621 newPosition = -(listWidth - containerWidth); 622 } else if (newPosition > 0) { 623 newPosition = 0; 624 } 625 626 if (typeof listObject.animate == 'function') { 627 listObject.animate({ 628 left: newPosition 629 }, pgwSlideshow.config.transitionDuration); 630 } else { 631 listObject.css('left', newPosition); 632 } 633 }); 634 635 // Right button 636 containerObject.find('.ps-next').show().unbind('click').click(function() { 637 var oldPosition = parseInt(listObject.css('left')); 638 var newPosition = oldPosition - containerWidth; 639 var maxPosition = -(listWidth - containerWidth); 640 641 if (oldPosition == maxPosition) { 642 newPosition = 0; 643 } else if (newPosition < maxPosition) { 644 newPosition = maxPosition; 645 } 646 647 if (typeof listObject.animate == 'function') { 648 listObject.animate({ 649 left: newPosition 650 }, pgwSlideshow.config.transitionDuration); 651 } else { 652 listObject.css('left', newPosition); 653 } 654 }); 655 656 // Touch controls for the list
657 if (pgwSlideshow.config.touchControls) { 658 659 pgwSlideshow.plugin.find('.ps-list > ul').on('touchmove', function(e) { 660 try { 661 if (e.originalEvent.touches[0].clientX) { 662 var lastPosition = (pgwSlideshow.touchListLastPosition == false ? 0 : pgwSlideshow.touchListLastPosition); 663 nbPixels = (pgwSlideshow.touchListLastPosition == false ? 1 : Math.abs(lastPosition - e.originalEvent.touches[0].clientX)); 664 pgwSlideshow.touchListLastPosition = e.originalEvent.touches[0].clientX; 665 666 var touchDirection = ''; 667 if (lastPosition > e.originalEvent.touches[0].clientX) { 668 touchDirection = 'left'; 669 } else if (lastPosition < e.originalEvent.touches[0].clientX) { 670 touchDirection = 'right'; 671 } 672 } 673 674 var oldPosition = parseInt(listObject.css('left')); 675 676 if (touchDirection == 'left') { 677 var containerWidth = containerObject.width(); 678 var listWidth = listObject.width(); 679 680 var marginLeft = parseInt(listObject.css('margin-left')); 681 var marginRight = parseInt(listObject.css('margin-right')); 682 containerWidth -= (marginLeft + marginRight); 683 684 var maxPosition = -(listWidth - containerWidth); 685 var newPosition = oldPosition - nbPixels; 686 687 if (newPosition > maxPosition) { 688 listObject.css('left', newPosition); 689 } 690 691 } else if (touchDirection == 'right') { 692 var newPosition = oldPosition + nbPixels; 693 694 if (newPosition < 0) { 695 listObject.css('left', newPosition); 696 } else { 697 listObject.css('left', 0); 698 } 699 } 700 701 } catch(e) { 702 pgwSlideshow.touchListLastPosition = false; 703 } 704 }); 705 706 pgwSlideshow.plugin.find('.ps-list > ul').on('touchend', function(e) { 707 pgwSlideshow.touchListLastPosition = false; 708 }); 709 } 710 711 } else { 712 var marginLeft = parseInt((containerWidth - listWidth) / 2); 713 listObject.css('left', 0).css('margin-left', marginLeft); 714 containerObject.find('.ps-prev').hide(); 715 containerObject.find('.ps-next').hide(); 716 pgwSlideshow.plugin.find('.ps-list > ul').unbind('touchstart touchmove touchend'); 717 } 718 719 return true; 720 }; 721 722 // Check the visibility of the selected item 723 var checkSelectedItem = function() { 724 var containerWidth = pgwSlideshow.plugin.find('.ps-list').width(); 725 var listObject = pgwSlideshow.plugin.find('.ps-list > ul'); 726 var listWidth = listObject.width(); 727 728 var marginLeft = parseInt(listObject.css('margin-left')); 729 var marginRight = parseInt(listObject.css('margin-right')); 730 containerWidth -= (marginLeft + marginRight); 731 732 var visibleZoneStart = Math.abs(parseInt(listObject.css('left'))); 733 var visibleZoneEnd = visibleZoneStart + containerWidth; 734 var elementZoneStart = pgwSlideshow.plugin.find('.ps-list .ps-selected').position().left; 735 var elementZoneEnd = elementZoneStart + pgwSlideshow.plugin.find('.ps-list .ps-selected').width(); 736 737 if ((elementZoneStart < visibleZoneStart) || (elementZoneEnd > visibleZoneEnd) || (listWidth > containerWidth && visibleZoneEnd > elementZoneEnd)) { 738 var maxPosition = -(listWidth - containerWidth); 739 740 if (-elementZoneStart < maxPosition) { 741 listObject.css('left', maxPosition); 742 } else { 743 listObject.css('left', -elementZoneStart); 744 } 745 } 746 747 return true; 748 }; 749 750 // Start auto slide 751 pgwSlideshow.startSlide = function() { 752 pgwSlideshow.config.autoSlide = true; 753 activateInterval(); 754 return true; 755 }; 756 757 // Stop auto slide 758 pgwSlideshow.stopSlide = function() { 759 pgwSlideshow.config.autoSlide = false;
760 clearInterval(pgwSlideshow.intervalEvent); 761 return true; 762 }; 763 764 // Get current slide 765 pgwSlideshow.getCurrentSlide = function() { 766 return pgwSlideshow.currentSlide; 767 }; 768 769 // Get slide count 770 pgwSlideshow.getSlideCount = function() { 771 return pgwSlideshow.slideCount; 772 }; 773 774 // Display slide 775 pgwSlideshow.displaySlide = function(itemId) { 776 displayElement(itemId, true); 777 return true; 778 }; 779 780 // Next slide 781 pgwSlideshow.nextSlide = function() { 782 if (pgwSlideshow.currentSlide + 1 <= pgwSlideshow.slideCount) { 783 var nextItem = pgwSlideshow.currentSlide + 1; 784 } else { 785 var nextItem = 1; 786 } 787 displayElement(nextItem, true, 'left'); 788 return true; 789 }; 790 791 // Previous slide 792 pgwSlideshow.previousSlide = function() { 793 if (pgwSlideshow.currentSlide - 1 >= 1) { 794 var previousItem = pgwSlideshow.currentSlide - 1; 795 } else { 796 var previousItem = pgwSlideshow.slideCount; 797 } 798 displayElement(previousItem, true, 'right'); 799 return true; 800 }; 801 802 // Destroy slider 803 pgwSlideshow.destroy = function(soft) { 804 clearInterval(pgwSlideshow.intervalEvent); 805 806 if (typeof soft != 'undefined') { 807 pgwSlideshow.plugin.find('.ps-list > ul > li').each(function() { 808 $(this).attr('style', null).removeClass().unbind('click'); 809 $(this).html($(this).find('span').html()); 810 }); 811 812 pgwSlideshow.plugin.find('.ps-current').remove(); 813 pgwSlideshow.plugin.find('.ps-list').find('.ps-prev, .ps-next').remove(); 814 pgwSlideshow.plugin.find('.ps-list > ul').addClass(pgwSlideshow.config.mainClassName).attr('style', ''); 815 pgwSlideshow.plugin.find('.ps-list > ul').unwrap().unwrap(); 816 pgwSlideshow.hide(); 817 818 } else { 819 pgwSlideshow.parent().parent().remove(); 820 } 821 822 pgwSlideshow.plugin = null; 823 pgwSlideshow.data = []; 824 pgwSlideshow.config = {}; 825 pgwSlideshow.currentSlide = 0; 826 pgwSlideshow.slideCount = 0; 827 pgwSlideshow.resizeEvent = null; 828 pgwSlideshow.intervalEvent = null; 829 pgwSlideshow.touchFirstPosition = null; 830 pgwSlideshow.window = null; 831 832 return true; 833 }; 834 835 // Reload slider 836 pgwSlideshow.reload = function(newOptions) { 837 pgwSlideshow.destroy(true); 838 839 pgwSlideshow = this; 840 pgwSlideshow.plugin = this; 841 pgwSlideshow.window = $(window); 842 pgwSlideshow.plugin.show(); 843 844 // Merge new options with the default configuration 845 pgwSlideshow.config = $.extend({}, defaults, newOptions); 846 847 // Setup 848 setup(); 849 850 // Resize listener 851 pgwSlideshow.window.resize(function() { 852 clearTimeout(pgwSlideshow.resizeEvent); 853 pgwSlideshow.resizeEvent = setTimeout(function() { 854 setSizeClass(); 855 856 var maxHeight = pgwSlideshow.plugin.find('.ps-current > ul > li.elt_' + pgwSlideshow.currentSlide + ' img').css('max-height', '').height(); 857 updateHeight(maxHeight); 858 859 if (pgwSlideshow.config.displayList) { 860 checkList(); 861 checkSelectedItem(); 862 } 863 }, 100); 864 }); 865 866 // Activate interval 867 if (pgwSlideshow.config.autoSlide) { 868 activateInterval(); 869 } 870 871 return true; 872 }; 873 874 // Slideshow initialization 875 init(); 876 877 878 879 return this; 880 } 881})(window.Zepto || window.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.