Browse Source

Fixes issue mentioned by @gabormeszoly #1363

pull/1407/head
jlukic 10 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) { $.fn.sidebar = function(parameters) {
var var
$allModules = $(this), $allModules = $(this),
$window = $(window),
$document = $(document),
$head = $('head'), $head = $('head'),
moduleSelector = $allModules.selector || '', moduleSelector = $allModules.selector || '',
@ -61,6 +63,8 @@ $.fn.sidebar = function(parameters) {
element = this, element = this,
instance = $module.data(moduleNamespace), instance = $module.data(moduleNamespace),
elementNamespace,
id,
currentScroll, currentScroll,
transitionEvent, transitionEvent,
@ -80,7 +84,10 @@ $.fn.sidebar = function(parameters) {
settings.useLegacy = true; 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); requestAnimationFrame(module.setup.layout);
module.instantiate(); module.instantiate();
@ -101,6 +108,10 @@ $.fn.sidebar = function(parameters) {
.off(eventNamespace) .off(eventNamespace)
.removeData(moduleNamespace) .removeData(moduleNamespace)
; ;
// bound by uuid
$context.off(elementNamespace);
$window.off(elementNamespace);
$document.off(elementNamespace);
}, },
event: { event: {
@ -130,31 +141,40 @@ $.fn.sidebar = function(parameters) {
bind: { bind: {
clickaway: function() { 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) { 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 $module
.on('scroll' + eventNamespace, module.event.containScroll) .on('scroll' + eventNamespace, module.event.containScroll)
; ;
if(settings.closable) {
$context
.on('click' + eventNamespace, module.event.clickaway)
.on('touchend' + eventNamespace, module.event.clickaway)
;
}
} }
}, },
unbind: { unbind: {
clickaway: function() { 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); $pusher = $context.children(selector.pusher);
}, },
refreshSidebars: function() {
module.verbose('Refreshing other sidebars');
$sidebars = $context.children(selector.sidebar);
},
repaint: function() { repaint: function() {
module.verbose('Forcing repaint event'); module.verbose('Forcing repaint event');
element.style.display='none'; element.style.display='none';
@ -302,6 +327,7 @@ $.fn.sidebar = function(parameters) {
: function(){} : function(){}
; ;
if(module.is.hidden()) { if(module.is.hidden()) {
module.refreshSidebars();
if(settings.overlay) { if(settings.overlay) {
module.error(error.overlay); module.error(error.overlay);
settings.transition = 'overlay'; settings.transition = 'overlay';
@ -337,6 +363,7 @@ $.fn.sidebar = function(parameters) {
; ;
if(module.is.visible() || module.is.animating()) { if(module.is.visible() || module.is.animating()) {
module.debug('Hiding sidebar', callback); module.debug('Hiding sidebar', callback);
module.refreshSidebars();
animateMethod(function() { animateMethod(function() {
$.proxy(callback, element)(); $.proxy(callback, element)();
$.proxy(settings.onHidden, element)(); $.proxy(settings.onHidden, element)();
@ -349,9 +376,6 @@ $.fn.sidebar = function(parameters) {
othersVisible: function() { othersVisible: function() {
return ($sidebars.not($module).filter('.' + className.visible).size() > 0); return ($sidebars.not($module).filter('.' + className.visible).size() > 0);
}, },
othersActive: function() {
return ($sidebars.not($module).filter('.' + className.active).size() > 0);
},
hideOthers: function(callback) { hideOthers: function(callback) {
var var
@ -404,7 +428,7 @@ $.fn.sidebar = function(parameters) {
module.add.bodyCSS(); module.add.bodyCSS();
module.set.animating(); module.set.animating();
module.set.visible(); module.set.visible();
if(!module.othersActive()) {
if(!module.othersVisible()) {
if(settings.dimPage) { if(settings.dimPage) {
$pusher.addClass(className.dimmed); $pusher.addClass(className.dimmed);
} }
@ -415,6 +439,7 @@ $.fn.sidebar = function(parameters) {
$transition.off(transitionEvent + eventNamespace, transitionEnd); $transition.off(transitionEvent + eventNamespace, transitionEnd);
module.remove.animating(); module.remove.animating();
module.bind.clickaway(); module.bind.clickaway();
module.bind.scrollLock();
$.proxy(callback, element)(); $.proxy(callback, element)();
} }
}; };
@ -427,7 +452,7 @@ $.fn.sidebar = function(parameters) {
transition = module.get.transition(), transition = module.get.transition(),
$transition = (transition == 'safe') $transition = (transition == 'safe')
? $context ? $context
: (transition == 'overlay' || module.othersActive())
: (transition == 'overlay' || module.othersVisible())
? $module ? $module
: $pusher, : $pusher,
animate, animate,
@ -438,13 +463,14 @@ $.fn.sidebar = function(parameters) {
: function(){} : function(){}
; ;
module.verbose('Removing context push state', module.get.direction()); module.verbose('Removing context push state', module.get.direction());
if(!module.othersActive()) {
module.unbind.clickaway();
}
module.unbind.clickaway();
module.unbind.scrollLock();
animate = function() { animate = function() {
module.set.animating(); module.set.animating();
module.remove.visible(); module.remove.visible();
if(settings.dimPage && !module.othersActive()) {
if(settings.dimPage && !module.othersVisible()) {
$pusher.removeClass(className.dimmed); $pusher.removeClass(className.dimmed);
} }
}; };
@ -646,6 +672,9 @@ $.fn.sidebar = function(parameters) {
return transitions[transition]; return transitions[transition];
} }
} }
},
uniqueID: function() {
return (Math.random().toString(16) + '000000000').substr(2,8);
} }
}, },

Loading…
Cancel
Save