Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Minor updates (add some comments, clean up code)
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyapps committed Nov 21, 2011
1 parent 3693c0b commit e690f54
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 40 deletions.
30 changes: 18 additions & 12 deletions source/helpers/jquery.fancybox-buttons.js
@@ -1,28 +1,32 @@
(function ($) {
//Shortcut for fancyBox object
var F = $.fancybox;

//Add helper object
F.helpers.buttons = {
tpl: '<div id="fancybox-buttons"><ul><li><a class="btnPrev" title="Previous" href="javascript:$.fancybox.prev();">Previous</a></li><li><a class="btnPlay" title="Slideshow" href="javascript:$.fancybox.play();;">Play</a></li><li><a class="btnNext" title="Next" href="javascript:$.fancybox.next();">Next</a></li><li><a class="btnToggle" title="Toggle size" href="javascript:$.fancybox.toggle();">Toggle</a></li><li><a class="btnClose" title="Close" href="javascript:$.fancybox.close();">Close</a></li></ul></div>',
list: null,
buttons: {},

//Recheck if can toggle size
update: function () {
var toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn');

//Size toggle button
if (F.current.canShrink) {
this.buttons.toggle.removeClass('btnDisabled').addClass('btnToggleOn');

} else if (F.current.canExpand) {
this.buttons.toggle.removeClass('btnDisabled btnToggleOn');
toggle.addClass('btnToggleOn');

} else {
this.buttons.toggle.removeClass('btnToggleOn').addClass('btnDisabled');
} else if (!F.current.canExpand) {
toggle.addClass('btnDisabled');
}
},

beforeShow: function () {
//Increase top margin to give space for buttons
F.current.margin[0] += 30;
},

// Update slideshow button
onPlayStart: function () {
if (this.list) {
this.buttons.play.text('Pause').addClass('btnPlayOn');
Expand All @@ -36,23 +40,25 @@
},

afterShow: function () {
// Check if initialised
if (!this.list) {
this.list = $(this.tpl).appendTo('body');

this.buttons.prev = this.list.find('.btnPrev');
this.buttons.next = this.list.find('.btnNext');
this.buttons.play = this.list.find('.btnPlay');
this.buttons.toggle = this.list.find('.btnToggle');
this.buttons = {
prev : this.list.find('.btnPrev'),
next : this.list.find('.btnNext'),
play : this.list.find('.btnPlay'),
toggle : this.list.find('.btnToggle')
}
}

//Prev
//Update navigation buttons
if (F.current.index > 0 || F.current.loop) {
this.buttons.prev.removeClass('btnDisabled');
} else {
this.buttons.prev.addClass('btnDisabled');
}

//Next / Play
if (F.current.loop || F.current.index < F.group.length - 1) {
this.buttons.next.removeClass('btnDisabled');
this.buttons.play.removeClass('btnDisabled');
Expand Down
26 changes: 18 additions & 8 deletions source/helpers/jquery.fancybox-thumbs.js
@@ -1,16 +1,25 @@
(function ($) {
//Shortcut for fancyBox object
var F = $.fancybox;

//Add helper object
F.helpers.thumbs = {
wrap: null,
list: null,
width: 0,

//Get thumbnail source from element
source: function (el) {
var img = $(el).find('img');

return img.length ? img.attr('src') : el.href;
},

init: function (opts) {
var that = this,
list;

//Create list
//Build list structure
list = '';

for (var n = 0; n < F.group.length; n++) {
Expand All @@ -20,7 +29,7 @@
this.wrap = $('<div id="fancybox-thumbs"></div>').appendTo('body');
this.list = $('<ul>' + list + '</ul>').appendTo(this.wrap);

//Load thumbs
//Load each thumbnail
$.each(F.group, function (i) {
$("<img />").load(function () {
var width = this.width,
Expand All @@ -31,6 +40,7 @@
return;
}

//Calculate thumbnail width/height and center it
widthRatio = width / opts.width;
heightRatio = height / opts.height;
parent = that.list.children().eq(i).find('a');
Expand Down Expand Up @@ -66,6 +76,7 @@
this.list.width(this.width * (F.group.length + 1)).css('left', Math.floor($(window).width() * 0.5 - (F.current.index * this.width + this.width * 0.5)));
},

//Center list
update: function (opts) {
if (this.list) {
this.list.stop(true).animate({
Expand All @@ -75,28 +86,27 @@
},

beforeLoad: function (opts) {
//Remove self if gallery do not have at least two items
if (F.group.length < 2) {
F.coming.helpers.thumbs = false;

return;
}

F.coming.margin[2] = opts.height + 30; //Increase bottom margin
F.coming.helpers.thumbs.source = function (el) {
var img = $(el).find('img');

return img.length ? img.attr('src') : el.href;
};
//Increase bottom margin to give space for thumbs
F.coming.margin[2] = opts.height + 30;
},

afterShow: function (opts) {
//Check if exists and create or update list
if (this.list) {
this.update(opts);

} else {
this.init(opts);
}

//Set active element
this.list.children().removeClass('active').eq(F.current.index).addClass('active');
},

Expand Down
19 changes: 12 additions & 7 deletions source/jquery.fancybox.js
Expand Up @@ -33,7 +33,7 @@
aspectRatio: false,
topRatio: 0.5,

fixed: (!$.browser.msie || $.browser.version > 6) && $.support.boxModel, // Should set position to 'fixed' if content fits inside viewport
fixed: (!$.browser.msie || $.browser.version > 6) && $.support.boxModel,
scrolling: 'auto', // 'auto', 'yes' or 'no'
wrapCSS: 'fancybox-default',

Expand Down Expand Up @@ -729,7 +729,8 @@
maxWidth = F.current.maxWidth,
maxHeight = F.current.maxHeight,
minWidth = F.current.minWidth,
minHeight = F.current.minHeight;
minHeight = F.current.minHeight,
height_;

viewport.w -= (margin[1] + margin[3]);
viewport.h -= (margin[0] + margin[2]);
Expand Down Expand Up @@ -784,10 +785,12 @@

F.inner.width(width - padding2).height(height - padding2);
F.wrap.width(width);
//todo: iesetot height() kaut kaadaa variaaablii

height_ = F.wrap.height(); // Real wrap height

//Fit wrapper inside
if (width > maxWidth || F.wrap.height() > maxHeight) {
while ((width > maxWidth || F.wrap.height() > maxHeight) && width > minWidth && F.wrap.height() > minHeight) {
if (width > maxWidth || height_ > maxHeight) {
while ((width > maxWidth || height_ > maxHeight) && width > minWidth && height_ > minHeight) {
height = height - 10;

if (F.current.aspectRatio) {
Expand All @@ -804,12 +807,14 @@

F.inner.width(width - padding2).height(height - padding2);
F.wrap.width(width);

height_ = F.wrap.height();
}
}

F.current.dim = {
width: width,
height: F.wrap.height()
height: height_
};

F.current.canGrow = F.current.autoSize && height > minHeight && height < maxHeight;
Expand All @@ -819,7 +824,7 @@
if ((width - padding2) < F.current.width || (height - padding2) < F.current.height) {
F.current.canExpand = true;

} else if ((width > viewport.w || F.current.dim.height > viewport.h) && width > minWidth && height > minHeight) {
} else if ((width > viewport.w || height_ > viewport.h) && width > minWidth && height > minHeight) {
F.current.canShrink = true;
}
},
Expand Down

0 comments on commit e690f54

Please sign in to comment.