Skip to content

Commit

Permalink
Fixes issue mentioned by @gabormeszoly #1363
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Dec 8, 2014
1 parent bd8ee7e commit 1aa8dc1
Showing 1 changed file with 53 additions and 24 deletions.
77 changes: 53 additions & 24 deletions src/definitions/modules/sidebar.js
Expand Up @@ -16,6 +16,8 @@
$.fn.sidebar = function(parameters) {
var
$allModules = $(this),
$window = $(window),
$document = $(document),
$head = $('head'),

moduleSelector = $allModules.selector || '',
Expand Down Expand Up @@ -61,6 +63,8 @@ $.fn.sidebar = function(parameters) {
element = this,
instance = $module.data(moduleNamespace),

elementNamespace,
id,
currentScroll,
transitionEvent,

Expand All @@ -80,7 +84,10 @@ $.fn.sidebar = function(parameters) {
settings.useLegacy = true;
}

// avoid locking rendering if included in onReady
id = module.get.uniqueID();
elementNamespace = '.' + id;

// avoids locking rendering if initialized in onReady
requestAnimationFrame(module.setup.layout);

module.instantiate();
Expand All @@ -101,6 +108,10 @@ $.fn.sidebar = function(parameters) {
.off(eventNamespace)
.removeData(moduleNamespace)
;
// bound by uuid
$context.off(elementNamespace);
$window.off(elementNamespace);
$document.off(elementNamespace);
},

event: {
Expand Down Expand Up @@ -130,31 +141,40 @@ $.fn.sidebar = function(parameters) {

bind: {
clickaway: function() {
module.verbose('Adding clickaway events to context', $context);
if(settings.closable) {
$context
.on('click' + elementNamespace, module.event.clickaway)
.on('touchend' + elementNamespace, module.event.clickaway)
;
}
},
scrollLock: function() {
if(settings.scrollLock) {
$(window)
.on('DOMMouseScroll' + eventNamespace, module.event.scroll)
module.debug('Disabling page scroll');
$window
.on('DOMMouseScroll' + elementNamespace, module.event.scroll)
;
}
$(document)
.on('touchmove' + eventNamespace, module.event.touch)
module.verbose('Adding events to contain sidebar scroll');
$document
.on('touchmove' + elementNamespace, module.event.touch)
;
$module
.on('scroll' + eventNamespace, module.event.containScroll)
;
if(settings.closable) {
$context
.on('click' + eventNamespace, module.event.clickaway)
.on('touchend' + eventNamespace, module.event.clickaway)
;
}
}
},
unbind: {
clickaway: function() {
$context.off(eventNamespace);
$pusher.off(eventNamespace);
$(document).off(eventNamespace);
$(window).off(eventNamespace);
module.verbose('Removing clickaway events from context', $context);
$context.off(elementNamespace);
},
scrollLock: function() {
module.verbose('Removing scroll lock from page');
$document.off(elementNamespace);
$window.off(elementNamespace);
$module.off('scroll' + eventNamespace);
}
},

Expand Down Expand Up @@ -239,6 +259,11 @@ $.fn.sidebar = function(parameters) {
$pusher = $context.children(selector.pusher);
},

refreshSidebars: function() {
module.verbose('Refreshing other sidebars');
$sidebars = $context.children(selector.sidebar);
},

repaint: function() {
module.verbose('Forcing repaint event');
element.style.display='none';
Expand Down Expand Up @@ -302,6 +327,7 @@ $.fn.sidebar = function(parameters) {
: function(){}
;
if(module.is.hidden()) {
module.refreshSidebars();
if(settings.overlay) {
module.error(error.overlay);
settings.transition = 'overlay';
Expand Down Expand Up @@ -337,6 +363,7 @@ $.fn.sidebar = function(parameters) {
;
if(module.is.visible() || module.is.animating()) {
module.debug('Hiding sidebar', callback);
module.refreshSidebars();
animateMethod(function() {
$.proxy(callback, element)();
$.proxy(settings.onHidden, element)();
Expand All @@ -349,9 +376,6 @@ $.fn.sidebar = function(parameters) {
othersVisible: function() {
return ($sidebars.not($module).filter('.' + className.visible).size() > 0);
},
othersActive: function() {
return ($sidebars.not($module).filter('.' + className.active).size() > 0);
},

hideOthers: function(callback) {
var
Expand Down Expand Up @@ -404,7 +428,7 @@ $.fn.sidebar = function(parameters) {
module.add.bodyCSS();
module.set.animating();
module.set.visible();
if(!module.othersActive()) {
if(!module.othersVisible()) {
if(settings.dimPage) {
$pusher.addClass(className.dimmed);
}
Expand All @@ -415,6 +439,7 @@ $.fn.sidebar = function(parameters) {
$transition.off(transitionEvent + eventNamespace, transitionEnd);
module.remove.animating();
module.bind.clickaway();
module.bind.scrollLock();
$.proxy(callback, element)();
}
};
Expand All @@ -427,7 +452,7 @@ $.fn.sidebar = function(parameters) {
transition = module.get.transition(),
$transition = (transition == 'safe')
? $context
: (transition == 'overlay' || module.othersActive())
: (transition == 'overlay' || module.othersVisible())
? $module
: $pusher,
animate,
Expand All @@ -438,13 +463,14 @@ $.fn.sidebar = function(parameters) {
: function(){}
;
module.verbose('Removing context push state', module.get.direction());
if(!module.othersActive()) {
module.unbind.clickaway();
}

module.unbind.clickaway();
module.unbind.scrollLock();

animate = function() {
module.set.animating();
module.remove.visible();
if(settings.dimPage && !module.othersActive()) {
if(settings.dimPage && !module.othersVisible()) {
$pusher.removeClass(className.dimmed);
}
};
Expand Down Expand Up @@ -646,6 +672,9 @@ $.fn.sidebar = function(parameters) {
return transitions[transition];
}
}
},
uniqueID: function() {
return (Math.random().toString(16) + '000000000').substr(2,8);
}
},

Expand Down

0 comments on commit 1aa8dc1

Please sign in to comment.