jquery.fancybox-buttons.js 2.8 KB

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