Просмотр файла wu-static/js/lightgallery/js/lg-pager.js

Размер файла: 3.27Kb
  1. /*! lg-pager - v1.0.0 - 2016-09-20
  2. * http://sachinchoolur.github.io/lightGallery
  3. * Copyright (c) 2016 Sachin N; Licensed GPLv3 */
  4.  
  5. (function (root, factory) {
  6. if (typeof define === 'function' && define.amd) {
  7. // AMD. Register as an anonymous module unless amdModuleId is set
  8. define([], function () {
  9. return (factory());
  10. });
  11. } else if (typeof exports === 'object') {
  12. // Node. Does not work with strict CommonJS, but
  13. // only CommonJS-like environments that support module.exports,
  14. // like Node.
  15. module.exports = factory();
  16. } else {
  17. factory();
  18. }
  19. }(this, function () {
  20.  
  21. (function($, window, document, undefined) {
  22.  
  23. 'use strict';
  24.  
  25. var defaults = {
  26. pager: false
  27. };
  28.  
  29. var Pager = function(element) {
  30.  
  31. this.core = $(element).data('lightGallery');
  32.  
  33. this.$el = $(element);
  34. this.core.s = $.extend({}, defaults, this.core.s);
  35. if (this.core.s.pager && this.core.$items.length > 1) {
  36. this.init();
  37. }
  38.  
  39. return this;
  40. };
  41.  
  42. Pager.prototype.init = function() {
  43. var _this = this;
  44. var pagerList = '';
  45. var $pagerCont;
  46. var $pagerOuter;
  47. var timeout;
  48.  
  49. _this.core.$outer.find('.lg').append('<div class="lg-pager-outer"></div>');
  50.  
  51. if (_this.core.s.dynamic) {
  52. for (var i = 0; i < _this.core.s.dynamicEl.length; i++) {
  53. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + _this.core.s.dynamicEl[i].thumb + '" /></div></span>';
  54. }
  55. } else {
  56. _this.core.$items.each(function() {
  57.  
  58. if (!_this.core.s.exThumbImage) {
  59. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).find('img').attr('src') + '" /></div></span>';
  60. } else {
  61. pagerList += '<span class="lg-pager-cont"> <span class="lg-pager"></span><div class="lg-pager-thumb-cont"><span class="lg-caret"></span> <img src="' + $(this).attr(_this.core.s.exThumbImage) + '" /></div></span>';
  62. }
  63.  
  64. });
  65. }
  66.  
  67. $pagerOuter = _this.core.$outer.find('.lg-pager-outer');
  68.  
  69. $pagerOuter.html(pagerList);
  70.  
  71. $pagerCont = _this.core.$outer.find('.lg-pager-cont');
  72. $pagerCont.on('click.lg touchend.lg', function() {
  73. var _$this = $(this);
  74. _this.core.index = _$this.index();
  75. _this.core.slide(_this.core.index, false, false);
  76. });
  77.  
  78. $pagerOuter.on('mouseover.lg', function() {
  79. clearTimeout(timeout);
  80. $pagerOuter.addClass('lg-pager-hover');
  81. });
  82.  
  83. $pagerOuter.on('mouseout.lg', function() {
  84. timeout = setTimeout(function() {
  85. $pagerOuter.removeClass('lg-pager-hover');
  86. });
  87. });
  88.  
  89. _this.core.$el.on('onBeforeSlide.lg.tm', function(e, prevIndex, index) {
  90. $pagerCont.removeClass('lg-pager-active');
  91. $pagerCont.eq(index).addClass('lg-pager-active');
  92. });
  93.  
  94. };
  95.  
  96. Pager.prototype.destroy = function() {
  97.  
  98. };
  99.  
  100. $.fn.lightGallery.modules.pager = Pager;
  101.  
  102. })(jQuery, window, document);
  103.  
  104.  
  105. }));