OLD | NEW |
(Empty) | |
| 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 |
| 20 //Add helper object |
| 21 F.helpers.buttons = { |
| 22 defaults : { |
| 23 skipSingle : false, // disables if gallery contains sing
le image |
| 24 position : 'top', // 'top' or 'bottom' |
| 25 tpl : '<div id="fancybox-buttons"><ul><li><a clas
s="btnPrev" title="Previous" href="javascript:;"></a></li><li><a class="btnPlay"
title="Start slideshow" href="javascript:;"></a></li><li><a class="btnNext" tit
le="Next" href="javascript:;"></a></li><li><a class="btnToggle" title="Toggle si
ze" href="javascript:;"></a></li><li><a class="btnClose" title="Close" href="jav
ascript:jQuery.fancybox.close();"></a></li></ul></div>' |
| 26 }, |
| 27 |
| 28 list : null, |
| 29 buttons: null, |
| 30 |
| 31 beforeLoad: function (opts, obj) { |
| 32 //Remove self if gallery do not have at least two items |
| 33 |
| 34 if (opts.skipSingle && obj.group.length < 2) { |
| 35 obj.helpers.buttons = false; |
| 36 obj.closeBtn = true; |
| 37 |
| 38 return; |
| 39 } |
| 40 |
| 41 //Increase top margin to give space for buttons |
| 42 obj.margin[ opts.position === 'bottom' ? 2 : 0 ] += 30; |
| 43 }, |
| 44 |
| 45 onPlayStart: function () { |
| 46 if (this.buttons) { |
| 47 this.buttons.play.attr('title', 'Pause slideshow
').addClass('btnPlayOn'); |
| 48 } |
| 49 }, |
| 50 |
| 51 onPlayEnd: function () { |
| 52 if (this.buttons) { |
| 53 this.buttons.play.attr('title', 'Start slideshow
').removeClass('btnPlayOn'); |
| 54 } |
| 55 }, |
| 56 |
| 57 afterShow: function (opts, obj) { |
| 58 var buttons = this.buttons; |
| 59 |
| 60 if (!buttons) { |
| 61 this.list = $(opts.tpl).addClass(opts.position).
appendTo('body'); |
| 62 |
| 63 buttons = { |
| 64 prev : this.list.find('.btnPrev').clic
k( F.prev ), |
| 65 next : this.list.find('.btnNext').clic
k( F.next ), |
| 66 play : this.list.find('.btnPlay').clic
k( F.play ), |
| 67 toggle : this.list.find('.btnToggle').cl
ick( F.toggle ) |
| 68 } |
| 69 } |
| 70 |
| 71 //Prev |
| 72 if (obj.index > 0 || obj.loop) { |
| 73 buttons.prev.removeClass('btnDisabled'); |
| 74 } else { |
| 75 buttons.prev.addClass('btnDisabled'); |
| 76 } |
| 77 |
| 78 //Next / Play |
| 79 if (obj.loop || obj.index < obj.group.length - 1) { |
| 80 buttons.next.removeClass('btnDisabled'); |
| 81 buttons.play.removeClass('btnDisabled'); |
| 82 |
| 83 } else { |
| 84 buttons.next.addClass('btnDisabled'); |
| 85 buttons.play.addClass('btnDisabled'); |
| 86 } |
| 87 |
| 88 this.buttons = buttons; |
| 89 |
| 90 this.onUpdate(opts, obj); |
| 91 }, |
| 92 |
| 93 onUpdate: function (opts, obj) { |
| 94 var toggle; |
| 95 |
| 96 if (!this.buttons) { |
| 97 return; |
| 98 } |
| 99 |
| 100 toggle = this.buttons.toggle.removeClass('btnDisabled bt
nToggleOn'); |
| 101 |
| 102 //Size toggle button |
| 103 if (obj.canShrink) { |
| 104 toggle.addClass('btnToggleOn'); |
| 105 |
| 106 } else if (!obj.canExpand) { |
| 107 toggle.addClass('btnDisabled'); |
| 108 } |
| 109 }, |
| 110 |
| 111 beforeClose: function () { |
| 112 if (this.list) { |
| 113 this.list.remove(); |
| 114 } |
| 115 |
| 116 this.list = null; |
| 117 this.buttons = null; |
| 118 } |
| 119 }; |
| 120 |
| 121 }(jQuery)); |
OLD | NEW |