jquery.blueimp-gallery.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * blueimp Gallery jQuery plugin
  3. * https://github.com/blueimp/Gallery
  4. *
  5. * Copyright 2013, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global define */
  12. ;(function (factory) {
  13. 'use strict'
  14. if (typeof define === 'function' && define.amd) {
  15. define(['jquery', './blueimp-gallery'], factory)
  16. } else {
  17. factory(window.jQuery, window.blueimp.Gallery)
  18. }
  19. })(function ($, Gallery) {
  20. 'use strict'
  21. // Global click handler to open links with data-gallery attribute
  22. // in the Gallery lightbox:
  23. $(document).on('click', '[data-gallery]', function (event) {
  24. // Get the container id from the data-gallery attribute:
  25. var id = $(this).data('gallery')
  26. var widget = $(id)
  27. var container =
  28. (widget.length && widget) || $(Gallery.prototype.options.container)
  29. var callbacks = {
  30. onopen: function () {
  31. container.data('gallery', this).trigger('open')
  32. },
  33. onopened: function () {
  34. container.trigger('opened')
  35. },
  36. onslide: function () {
  37. container.trigger('slide', arguments)
  38. },
  39. onslideend: function () {
  40. container.trigger('slideend', arguments)
  41. },
  42. onslidecomplete: function () {
  43. container.trigger('slidecomplete', arguments)
  44. },
  45. onclose: function () {
  46. container.trigger('close')
  47. },
  48. onclosed: function () {
  49. container.trigger('closed').removeData('gallery')
  50. }
  51. }
  52. var options = $.extend(
  53. // Retrieve custom options from data-attributes
  54. // on the Gallery widget:
  55. container.data(),
  56. {
  57. container: container[0],
  58. index: this,
  59. event: event
  60. },
  61. callbacks
  62. )
  63. // Select all links with the same data-gallery attribute:
  64. var links = $(this)
  65. .closest('[data-gallery-group], body')
  66. .find('[data-gallery="' + id + '"]')
  67. if (options.filter) {
  68. links = links.filter(options.filter)
  69. }
  70. return new Gallery(links, options)
  71. })
  72. })