Browse Source

Fixes issue mentioned by @gabormeszoly #1363

pull/1407/head
jlukic 9 years ago
parent
commit
1aa8dc1598
1 changed files with 53 additions and 24 deletions
  1. 77
      src/definitions/modules/sidebar.js

77
src/definitions/modules/sidebar.js

@ -16,6 +16,8 @@
$.fn.sidebar = function(parameters) {
var
$allModules = $(this),
$window = $(window),
$document = $(document),
$head = $('head'),
moduleSelector = $allModules.selector || '',
@ -61,6 +63,8 @@ $.fn.sidebar = function(parameters) {
element = this,
instance = $module.data(moduleNamespace),
elementNamespace,
id,
currentScroll,
transitionEvent,
@ -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();
@ -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: {
@ -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);
}
},
@ -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';
@ -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';
@ -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)();
@ -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
@ -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);
}
@ -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)();
}
};
@ -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,
@ -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);
}
};
@ -646,6 +672,9 @@ $.fn.sidebar = function(parameters) {
return transitions[transition];
}
}
},
uniqueID: function() {
return (Math.random().toString(16) + '000000000').substr(2,8);
}
},

Loading…
Cancel
Save