jquery.wmuGallery.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*!
  2. * jQuery wmuGallery v2.1
  3. *
  4. * Copyright (c) 2011 Brice Lechatellier
  5. * http://brice.lechatellier.com/
  6. *
  7. * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
  8. */
  9. ;(function($) {
  10. $.fn.wmuGallery = function(options) {
  11. /* Default Options
  12. ================================================== */
  13. var defaults = {
  14. position: 'before',
  15. animationDuration: 600,
  16. touch: false,
  17. slide: 'article',
  18. items: 5
  19. };
  20. var options = $.extend(defaults, options);
  21. return this.each(function() {
  22. /* Variables
  23. ================================================== */
  24. var $this = $(this);
  25. var slides = $this.find(options.slide);
  26. var gallery;
  27. var image;
  28. var slider;
  29. /* Slider
  30. ================================================== */
  31. var loadImage = function(i) {
  32. var imageURI = $(slides[i]).find('img').attr('data-src-full');
  33. if (!image) {
  34. image = $('<img src="' + imageURI + '" />');
  35. gallery.append(image);
  36. } else {
  37. image.attr('src', imageURI);
  38. }
  39. };
  40. /* Init
  41. ================================================== */
  42. var init = function() {
  43. gallery = $('<div class="wmuGalleryImage"></div>');
  44. if (options.position == 'before') {
  45. $this.prepend(gallery);
  46. } else if (options.position == 'after') {
  47. $this.append(gallery);
  48. }
  49. if (!$.isFunction($.fn.wmuSlider)) {
  50. $.ajax({
  51. url: 'jquery.wmuSlider.min.js',
  52. async: false
  53. });
  54. }
  55. if ($.isFunction($.fn.wmuSlider)) {
  56. slider = $this.find('.wmuSlider');
  57. slider.bind('hasLoaded', function(e) {
  58. var prev = slider.find('.wmuSliderPrev');
  59. var next = slider.find('.wmuSliderNext');
  60. var pagination = slider.find('.wmuSliderPagination');
  61. gallery.append(prev);
  62. gallery.append(next);
  63. gallery.append(pagination);
  64. slides = $this.find(options.slide);
  65. slides.each(function(i) {
  66. var slide = $(this);
  67. slide.click(function(e) {
  68. e.preventDefault();
  69. slider.trigger('loadSlide', parseInt(slide.attr('data-index')));
  70. });
  71. });
  72. }).bind('slideLoaded', function(e, i) {
  73. loadImage(i);
  74. }).wmuSlider({
  75. touch: options.touch,
  76. animation: 'slide',
  77. animationDuration: options.animationDuration,
  78. slide: options.slide,
  79. items: options.items
  80. });
  81. }
  82. };
  83. init();
  84. });
  85. }
  86. })(jQuery);