annotate static/js/fancybox2/source/helpers/jquery.fancybox-buttons.js @ 151:762e46d0bb4a

urlquote photologue filenames when building URLs.
author Brian Neal <bgneal@gmail.com>
date Wed, 30 Jul 2014 20:07:21 -0500
parents 846cda22d77c
children
rev   line source
bgneal@106 1 /*!
bgneal@106 2 * Buttons helper for fancyBox
bgneal@106 3 * version: 1.0.5 (Mon, 15 Oct 2012)
bgneal@106 4 * @requires fancyBox v2.0 or later
bgneal@106 5 *
bgneal@106 6 * Usage:
bgneal@106 7 * $(".fancybox").fancybox({
bgneal@106 8 * helpers : {
bgneal@106 9 * buttons: {
bgneal@106 10 * position : 'top'
bgneal@106 11 * }
bgneal@106 12 * }
bgneal@106 13 * });
bgneal@106 14 *
bgneal@106 15 */
bgneal@106 16 (function ($) {
bgneal@106 17 //Shortcut for fancyBox object
bgneal@106 18 var F = $.fancybox;
bgneal@106 19
bgneal@106 20 //Add helper object
bgneal@106 21 F.helpers.buttons = {
bgneal@106 22 defaults : {
bgneal@106 23 skipSingle : false, // disables if gallery contains single image
bgneal@106 24 position : 'top', // 'top' or 'bottom'
bgneal@106 25 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>'
bgneal@106 26 },
bgneal@106 27
bgneal@106 28 list : null,
bgneal@106 29 buttons: null,
bgneal@106 30
bgneal@106 31 beforeLoad: function (opts, obj) {
bgneal@106 32 //Remove self if gallery do not have at least two items
bgneal@106 33
bgneal@106 34 if (opts.skipSingle && obj.group.length < 2) {
bgneal@106 35 obj.helpers.buttons = false;
bgneal@106 36 obj.closeBtn = true;
bgneal@106 37
bgneal@106 38 return;
bgneal@106 39 }
bgneal@106 40
bgneal@106 41 //Increase top margin to give space for buttons
bgneal@106 42 obj.margin[ opts.position === 'bottom' ? 2 : 0 ] += 30;
bgneal@106 43 },
bgneal@106 44
bgneal@106 45 onPlayStart: function () {
bgneal@106 46 if (this.buttons) {
bgneal@106 47 this.buttons.play.attr('title', 'Pause slideshow').addClass('btnPlayOn');
bgneal@106 48 }
bgneal@106 49 },
bgneal@106 50
bgneal@106 51 onPlayEnd: function () {
bgneal@106 52 if (this.buttons) {
bgneal@106 53 this.buttons.play.attr('title', 'Start slideshow').removeClass('btnPlayOn');
bgneal@106 54 }
bgneal@106 55 },
bgneal@106 56
bgneal@106 57 afterShow: function (opts, obj) {
bgneal@106 58 var buttons = this.buttons;
bgneal@106 59
bgneal@106 60 if (!buttons) {
bgneal@106 61 this.list = $(opts.tpl).addClass(opts.position).appendTo('body');
bgneal@106 62
bgneal@106 63 buttons = {
bgneal@106 64 prev : this.list.find('.btnPrev').click( F.prev ),
bgneal@106 65 next : this.list.find('.btnNext').click( F.next ),
bgneal@106 66 play : this.list.find('.btnPlay').click( F.play ),
bgneal@106 67 toggle : this.list.find('.btnToggle').click( F.toggle ),
bgneal@106 68 close : this.list.find('.btnClose').click( F.close )
bgneal@106 69 }
bgneal@106 70 }
bgneal@106 71
bgneal@106 72 //Prev
bgneal@106 73 if (obj.index > 0 || obj.loop) {
bgneal@106 74 buttons.prev.removeClass('btnDisabled');
bgneal@106 75 } else {
bgneal@106 76 buttons.prev.addClass('btnDisabled');
bgneal@106 77 }
bgneal@106 78
bgneal@106 79 //Next / Play
bgneal@106 80 if (obj.loop || obj.index < obj.group.length - 1) {
bgneal@106 81 buttons.next.removeClass('btnDisabled');
bgneal@106 82 buttons.play.removeClass('btnDisabled');
bgneal@106 83
bgneal@106 84 } else {
bgneal@106 85 buttons.next.addClass('btnDisabled');
bgneal@106 86 buttons.play.addClass('btnDisabled');
bgneal@106 87 }
bgneal@106 88
bgneal@106 89 this.buttons = buttons;
bgneal@106 90
bgneal@106 91 this.onUpdate(opts, obj);
bgneal@106 92 },
bgneal@106 93
bgneal@106 94 onUpdate: function (opts, obj) {
bgneal@106 95 var toggle;
bgneal@106 96
bgneal@106 97 if (!this.buttons) {
bgneal@106 98 return;
bgneal@106 99 }
bgneal@106 100
bgneal@106 101 toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn');
bgneal@106 102
bgneal@106 103 //Size toggle button
bgneal@106 104 if (obj.canShrink) {
bgneal@106 105 toggle.addClass('btnToggleOn');
bgneal@106 106
bgneal@106 107 } else if (!obj.canExpand) {
bgneal@106 108 toggle.addClass('btnDisabled');
bgneal@106 109 }
bgneal@106 110 },
bgneal@106 111
bgneal@106 112 beforeClose: function () {
bgneal@106 113 if (this.list) {
bgneal@106 114 this.list.remove();
bgneal@106 115 }
bgneal@106 116
bgneal@106 117 this.list = null;
bgneal@106 118 this.buttons = null;
bgneal@106 119 }
bgneal@106 120 };
bgneal@106 121
bgneal@106 122 }(jQuery));