bgneal@106: /*! bgneal@106: * Buttons helper for fancyBox bgneal@106: * version: 1.0.5 (Mon, 15 Oct 2012) bgneal@106: * @requires fancyBox v2.0 or later bgneal@106: * bgneal@106: * Usage: bgneal@106: * $(".fancybox").fancybox({ bgneal@106: * helpers : { bgneal@106: * buttons: { bgneal@106: * position : 'top' bgneal@106: * } bgneal@106: * } bgneal@106: * }); bgneal@106: * bgneal@106: */ bgneal@106: (function ($) { bgneal@106: //Shortcut for fancyBox object bgneal@106: var F = $.fancybox; bgneal@106: bgneal@106: //Add helper object bgneal@106: F.helpers.buttons = { bgneal@106: defaults : { bgneal@106: skipSingle : false, // disables if gallery contains single image bgneal@106: position : 'top', // 'top' or 'bottom' bgneal@106: tpl : '
' bgneal@106: }, bgneal@106: bgneal@106: list : null, bgneal@106: buttons: null, bgneal@106: bgneal@106: beforeLoad: function (opts, obj) { bgneal@106: //Remove self if gallery do not have at least two items bgneal@106: bgneal@106: if (opts.skipSingle && obj.group.length < 2) { bgneal@106: obj.helpers.buttons = false; bgneal@106: obj.closeBtn = true; bgneal@106: bgneal@106: return; bgneal@106: } bgneal@106: bgneal@106: //Increase top margin to give space for buttons bgneal@106: obj.margin[ opts.position === 'bottom' ? 2 : 0 ] += 30; bgneal@106: }, bgneal@106: bgneal@106: onPlayStart: function () { bgneal@106: if (this.buttons) { bgneal@106: this.buttons.play.attr('title', 'Pause slideshow').addClass('btnPlayOn'); bgneal@106: } bgneal@106: }, bgneal@106: bgneal@106: onPlayEnd: function () { bgneal@106: if (this.buttons) { bgneal@106: this.buttons.play.attr('title', 'Start slideshow').removeClass('btnPlayOn'); bgneal@106: } bgneal@106: }, bgneal@106: bgneal@106: afterShow: function (opts, obj) { bgneal@106: var buttons = this.buttons; bgneal@106: bgneal@106: if (!buttons) { bgneal@106: this.list = $(opts.tpl).addClass(opts.position).appendTo('body'); bgneal@106: bgneal@106: buttons = { bgneal@106: prev : this.list.find('.btnPrev').click( F.prev ), bgneal@106: next : this.list.find('.btnNext').click( F.next ), bgneal@106: play : this.list.find('.btnPlay').click( F.play ), bgneal@106: toggle : this.list.find('.btnToggle').click( F.toggle ), bgneal@106: close : this.list.find('.btnClose').click( F.close ) bgneal@106: } bgneal@106: } bgneal@106: bgneal@106: //Prev bgneal@106: if (obj.index > 0 || obj.loop) { bgneal@106: buttons.prev.removeClass('btnDisabled'); bgneal@106: } else { bgneal@106: buttons.prev.addClass('btnDisabled'); bgneal@106: } bgneal@106: bgneal@106: //Next / Play bgneal@106: if (obj.loop || obj.index < obj.group.length - 1) { bgneal@106: buttons.next.removeClass('btnDisabled'); bgneal@106: buttons.play.removeClass('btnDisabled'); bgneal@106: bgneal@106: } else { bgneal@106: buttons.next.addClass('btnDisabled'); bgneal@106: buttons.play.addClass('btnDisabled'); bgneal@106: } bgneal@106: bgneal@106: this.buttons = buttons; bgneal@106: bgneal@106: this.onUpdate(opts, obj); bgneal@106: }, bgneal@106: bgneal@106: onUpdate: function (opts, obj) { bgneal@106: var toggle; bgneal@106: bgneal@106: if (!this.buttons) { bgneal@106: return; bgneal@106: } bgneal@106: bgneal@106: toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn'); bgneal@106: bgneal@106: //Size toggle button bgneal@106: if (obj.canShrink) { bgneal@106: toggle.addClass('btnToggleOn'); bgneal@106: bgneal@106: } else if (!obj.canExpand) { bgneal@106: toggle.addClass('btnDisabled'); bgneal@106: } bgneal@106: }, bgneal@106: bgneal@106: beforeClose: function () { bgneal@106: if (this.list) { bgneal@106: this.list.remove(); bgneal@106: } bgneal@106: bgneal@106: this.list = null; bgneal@106: this.buttons = null; bgneal@106: } bgneal@106: }; bgneal@106: bgneal@106: }(jQuery));