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