You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.6 KiB

2 years ago
  1. /*!
  2. * Buttons helper for fancyBox
  3. * version: 1.0.5 (Mon, 15 Oct 2012)
  4. * @requires fancyBox v2.0 or later
  5. *
  6. * Usage:
  7. * $(".fancybox").fancybox({
  8. * helpers : {
  9. * buttons: {
  10. * position : 'top'
  11. * }
  12. * }
  13. * });
  14. *
  15. */
  16. ; (function ($) {
  17. //Shortcut for fancyBox object
  18. var F = $.fancybox;
  19. //Add helper object
  20. F.helpers.buttons = {
  21. defaults: {
  22. skipSingle: false, // disables if gallery contains single image
  23. position: 'top', // 'top' or 'bottom'
  24. tpl: '<div id="fancybox-buttons"><ul><li><a class="btnPrev" title="Previous" href="javascript:;"></a></li><li><a class="btnPlay" title="Start slideshow" href="javascript:;"></a></li><li><a class="btnNext" title="Next" href="javascript:;"></a></li><li><a class="btnToggle" title="Toggle size" href="javascript:;"></a></li><li><a class="btnClose" title="Close" href="javascript:;"></a></li></ul></div>'
  25. },
  26. list: null,
  27. buttons: null,
  28. beforeLoad: function (opts, obj) {
  29. //Remove self if gallery do not have at least two items
  30. if (opts.skipSingle && obj.group.length < 2) {
  31. obj.helpers.buttons = false;
  32. obj.closeBtn = true;
  33. return;
  34. }
  35. //Increase top margin to give space for buttons
  36. obj.margin[opts.position === 'bottom' ? 2 : 0] += 30;
  37. },
  38. onPlayStart: function () {
  39. if (this.buttons) {
  40. this.buttons.play.attr('title', 'Pause slideshow').addClass('btnPlayOn');
  41. }
  42. },
  43. onPlayEnd: function () {
  44. if (this.buttons) {
  45. this.buttons.play.attr('title', 'Start slideshow').removeClass('btnPlayOn');
  46. }
  47. },
  48. afterShow: function (opts, obj) {
  49. var buttons = this.buttons;
  50. if (!buttons) {
  51. this.list = $(opts.tpl).addClass(opts.position).appendTo('body');
  52. buttons = {
  53. prev: this.list.find('.btnPrev').click(F.prev),
  54. next: this.list.find('.btnNext').click(F.next),
  55. play: this.list.find('.btnPlay').click(F.play),
  56. toggle: this.list.find('.btnToggle').click(F.toggle),
  57. close: this.list.find('.btnClose').click(F.close)
  58. }
  59. }
  60. //Prev
  61. if (obj.index > 0 || obj.loop) {
  62. buttons.prev.removeClass('btnDisabled');
  63. } else {
  64. buttons.prev.addClass('btnDisabled');
  65. }
  66. //Next / Play
  67. if (obj.loop || obj.index < obj.group.length - 1) {
  68. buttons.next.removeClass('btnDisabled');
  69. buttons.play.removeClass('btnDisabled');
  70. } else {
  71. buttons.next.addClass('btnDisabled');
  72. buttons.play.addClass('btnDisabled');
  73. }
  74. this.buttons = buttons;
  75. this.onUpdate(opts, obj);
  76. },
  77. onUpdate: function (opts, obj) {
  78. var toggle;
  79. if (!this.buttons) {
  80. return;
  81. }
  82. toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn');
  83. //Size toggle button
  84. if (obj.canShrink) {
  85. toggle.addClass('btnToggleOn');
  86. } else if (!obj.canExpand) {
  87. toggle.addClass('btnDisabled');
  88. }
  89. },
  90. beforeClose: function () {
  91. if (this.list) {
  92. this.list.remove();
  93. }
  94. this.list = null;
  95. this.buttons = null;
  96. }
  97. };
  98. }(jQuery));