Permalink
Browse files

bugg fix for closing menu on none menuy clicks

  • Loading branch information...
1 parent da89790 commit edb3d97480ed6250ef886f3c2a4edd7af641e02c Dennis Mårtensson committed Jul 15, 2012
Showing with 15 additions and 16 deletions.
  1. +15 −16 dropdown/dropdown.js
View
@@ -2,35 +2,34 @@
//add click lisener to body for closing menu if you click on any thing else then the menu
//document.body.setAttribute('data-action-type', 'closeMenuAll');
-
window.addEventListener('click', function(e) {
var action = e.target,
- parent = action.parentNode,
actionType = action.getAttribute('data-action-type');
- if (actionType) {
-
- switch (actionType) {
-
- case 'closeMenuAll':
- var dropdown = document.getElementsByTagName('x-dropdown');
- if (dropdown.length > 0) {
- dropdown[0].xtag.closeMenuAll();
- } else {
- console.log('Missing x-dropdown element');
- }
- break;
+ if (actionType !== "closeMenu" && actionType !== "openMenu" && getParentByTagName(action, 'x-dropdown')) {
+ var dropdown = document.getElementsByTagName('x-dropdown');
+ if (dropdown.length > 0) {
+ dropdown[0].xtag.closeMenuAll();
+ } else {
+ console.log('Missing x-dropdown element');
}
-
}
});
+ function getParentByTagName(obj, tag) {
+ var obj_parent = obj.parentNode;
+ if(obj_parent.tagName.toLowerCase() == 'html') return true;
+ if (!obj_parent) return true;
+ if (obj_parent.tagName.toLowerCase() == tag) return false;
+ else return getParentByTagName(obj_parent, tag);
+ }
+
xtag.register('x-dropdown', {
onCreate: function() {
//Set data-type-action to body if not set
- if(document.body.getAttribute('data-action-type') != 'closeMenuAll'){
+ if (document.body.getAttribute('data-action-type') != 'closeMenuAll') {
document.body.setAttribute('data-action-type', 'closeMenuAll');
}

0 comments on commit edb3d97

Please sign in to comment.