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

Commit

Permalink
Emergency bug fixes for v1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymun committed Nov 19, 2014
1 parent 55e793f commit 433c41e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,15 @@ <h4 id="overlay-images">Overlay images</h4>
$('#custom-event-2')
.fluidbox({
closeTrigger: [{
selector: "#fluidbox-overlay",
selector: ".fluidbox-overlay",
event: "click"
}, {
selector: "window",
event: "scroll"
}, {
selector: 'document',
event: 'keyup',
keyCode: 27
}]
})
.on('openend', function() {
Expand Down
71 changes: 39 additions & 32 deletions jquery.fluidbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var customTransitionEnd = whichTransitionEvent();
// -----------------------------
(function ($) {

var fbCount = 0;

$.fn.fluidbox = function (opts) {

// Default settings
Expand Down Expand Up @@ -103,12 +105,11 @@ var customTransitionEnd = whichTransitionEvent();
vpRatio,

// Function:
// 1. funcCloseFb() - used to close any instance of opened Fluidbox
// 2. funcPositionFb() - used for dynamic positioning of any instance of opened Fluidbox
// 3. funcCalcAll() - used to run funcCalc() for every instance of targered Fluidbox thumbnail
// 5. fbClickhandler() - universal click handler for all Fluidbox items
funcCloseFb = function () {
$('.fluidbox-opened').trigger('click');
funcCloseFb = function (selector) {
$(selector + '.fluidbox-opened').trigger('click');
},
funcPositionFb = function ($activeFb, customEvent) {
// Get shorthand for more objects
Expand Down Expand Up @@ -343,37 +344,8 @@ var customTransitionEnd = whichTransitionEvent();
$(window).resize(function() { funcResize(); });
}

// When should we close Fluidbox?
if(settings.closeTrigger) {
// Go through array
$.each(settings.closeTrigger, function (i) {
var trigger = settings.closeTrigger[i];

// Attach events
if(trigger.selector != 'window') {
// If it is not 'window', we append click handler to $(document) object, allow it to bubble up
// However, if thes selector is 'document', we use a different .on() syntax
if(trigger.selector == 'document') {
if(trigger.keyCode) {
$(document).on(trigger.event, function (e) {
if(e.keyCode == trigger.keyCode) funcCloseFb();
});
} else {
$(document).on(trigger.event, funcCloseFb);
}
} else {
$(document).on(trigger.event, settings.closeTrigger[i].selector, funcCloseFb);
}
} else {
// If it is 'window', append click handler to $(window) object
$w.on(trigger.event, funcCloseFb);
}
});
}

// Go through each individual object
$fb.each(function (i) {

// Check if Fluidbox:
// 1. Is an anchor element ,<a>
// 2. Contains one and ONLY one child
Expand All @@ -389,10 +361,14 @@ var customTransitionEnd = whichTransitionEvent();
}
});

// Update count for global Fluidbox instances
fbCount+=1;

// Add class
var $fbItem = $(this);
$fbItem
.addClass('fluidbox')
.attr('id', 'fluidbox-'+fbCount)
.wrapInner($fbInnerWrap)
.find('img')
.css({ opacity: 1 })
Expand All @@ -418,6 +394,37 @@ var customTransitionEnd = whichTransitionEvent();
funcResize($(this));
$(this).trigger('recomputeend');
});

// When should we close Fluidbox?
var selector = '#fluidbox-'+fbCount;
if(settings.closeTrigger) {
// Go through array
$.each(settings.closeTrigger, function (i) {
var trigger = settings.closeTrigger[i];

// Attach events
if(trigger.selector != 'window') {
// If it is not 'window', we append click handler to $(document) object, allow it to bubble up
// However, if thes selector is 'document', we use a different .on() syntax
if(trigger.selector == 'document') {
if(trigger.keyCode) {
$(document).on(trigger.event, function (e) {
if(e.keyCode == trigger.keyCode) funcCloseFb(selector);
});
} else {
$(document).on(trigger.event, selector, function() {
funcCloseFb(selector);
});
}
}
} else {
// If it is 'window', append click handler to $(window) object
$w.on(trigger.event, function() {
funcCloseFb(selector);
});
}
});
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion jquery.fluidbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 433c41e

Please sign in to comment.