Skip to content

Commit

Permalink
Added fixes for dropdown as suggested on https://github.com/emilbjork…
Browse files Browse the repository at this point in the history
  • Loading branch information
thednp committed May 28, 2019
1 parent eb0432a commit 6ba2aa9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 deletions.
21 changes: 14 additions & 7 deletions dist/bootstrap-native-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@

// event names
clickEvent = 'click',
focusEvent = 'focus',
hoverEvent = 'hover',
keydownEvent = 'keydown',
keyupEvent = 'keyup',
Expand Down Expand Up @@ -202,16 +203,18 @@
},

// event attach jQuery style / trigger since 1.2.0
on = function (element, event, handler) {
element.addEventListener(event, handler, false);
on = function (element, event, handler, options) {
options = options || false;
element.addEventListener(event, handler, options);
},
off = function(element, event, handler) {
element.removeEventListener(event, handler, false);
off = function(element, event, handler, options) {
options = options || false;
element.removeEventListener(event, handler, options);
},
one = function (element, event, handler) { // one since 2.0.4
one = function (element, event, handler, options) { // one since 2.0.4
on(element, event, function handlerWrapper(e){
handler(e);
off(element, event, handlerWrapper);
off(element, event, handlerWrapper, options);
});
},
getTransitionDurationFromElement = function(element) {
Expand Down Expand Up @@ -907,13 +910,17 @@
type(DOC, clickEvent, dismissHandler);
type(DOC, keydownEvent, preventScroll);
type(DOC, keyupEvent, keyHandler);
type(DOC, focusEvent, dismissHandler, true);
},

// handlers
dismissHandler = function(e) {
var eventTarget = e[target], hasData = eventTarget && (eventTarget[getAttribute](dataToggle)
|| eventTarget[parentNode] && getAttribute in eventTarget[parentNode]
&& eventTarget[parentNode][getAttribute](dataToggle));
if ( e.type === focusEvent && (eventTarget === element || eventTarget === menu || menu[contains](eventTarget) ) ) {
return;
}
if ( (eventTarget === menu || menu[contains](eventTarget)) && (self.persist || hasData) ) { return; }
else {
relatedTarget = eventTarget === element || element[contains](eventTarget) ? element : null;
Expand All @@ -938,7 +945,7 @@
isInsideMenu = menu[contains](activeItem),
isMenuItem = activeItem[parentNode] === menu || activeItem[parentNode][parentNode] === menu;

if ( isMenuItem || isSameElement ) { // navigate up | down
if ( isMenuItem ) { // navigate up | down
idx = isSameElement ? 0
: key === 38 ? (idx>1?idx-1:0)
: key === 40 ? (idx<menuItems[length]-1?idx+1:idx) : idx;
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native-v4.min.js

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions dist/bootstrap-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

// event names
clickEvent = 'click',
focusEvent = 'focus',
hoverEvent = 'hover',
keydownEvent = 'keydown',
keyupEvent = 'keyup',
Expand Down Expand Up @@ -211,16 +212,18 @@
},

// event attach jQuery style / trigger since 1.2.0
on = function (element, event, handler) {
element.addEventListener(event, handler, false);
on = function (element, event, handler, options) {
options = options || false;
element.addEventListener(event, handler, options);
},
off = function(element, event, handler) {
element.removeEventListener(event, handler, false);
off = function(element, event, handler, options) {
options = options || false;
element.removeEventListener(event, handler, options);
},
one = function (element, event, handler) { // one since 2.0.4
one = function (element, event, handler, options) { // one since 2.0.4
on(element, event, function handlerWrapper(e){
handler(e);
off(element, event, handlerWrapper);
off(element, event, handlerWrapper, options);
});
},
getTransitionDurationFromElement = function(element) {
Expand Down Expand Up @@ -1059,13 +1062,17 @@
type(DOC, clickEvent, dismissHandler);
type(DOC, keydownEvent, preventScroll);
type(DOC, keyupEvent, keyHandler);
type(DOC, focusEvent, dismissHandler, true);
},

// handlers
dismissHandler = function(e) {
var eventTarget = e[target], hasData = eventTarget && (eventTarget[getAttribute](dataToggle)
|| eventTarget[parentNode] && getAttribute in eventTarget[parentNode]
&& eventTarget[parentNode][getAttribute](dataToggle));
if ( e.type === focusEvent && (eventTarget === element || eventTarget === menu || menu[contains](eventTarget) ) ) {
return;
}
if ( (eventTarget === menu || menu[contains](eventTarget)) && (self.persist || hasData) ) { return; }
else {
relatedTarget = eventTarget === element || element[contains](eventTarget) ? element : null;
Expand All @@ -1090,7 +1097,7 @@
isInsideMenu = menu[contains](activeItem),
isMenuItem = activeItem[parentNode][parentNode] === menu;

if ( isMenuItem || isSameElement ) { // navigate up | down
if ( isMenuItem ) { // navigate up | down
idx = isSameElement ? 0
: key === 38 ? (idx>1?idx-1:0)
: key === 40 ? (idx<menuItems[length]-1?idx+1:idx) : idx;
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/V3/dropdown-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ var Dropdown = function( element, option ) {
type(DOC, clickEvent, dismissHandler);
type(DOC, keydownEvent, preventScroll);
type(DOC, keyupEvent, keyHandler);
type(DOC, focusEvent, dismissHandler, true);
},

// handlers
dismissHandler = function(e) {
var eventTarget = e[target], hasData = eventTarget && (eventTarget[getAttribute](dataToggle)
|| eventTarget[parentNode] && getAttribute in eventTarget[parentNode]
&& eventTarget[parentNode][getAttribute](dataToggle));
if ( e.type === focusEvent && (eventTarget === element || eventTarget === menu || menu[contains](eventTarget) ) ) {
return;
}
if ( (eventTarget === menu || menu[contains](eventTarget)) && (self.persist || hasData) ) { return; }
else {
relatedTarget = eventTarget === element || element[contains](eventTarget) ? element : null;
Expand All @@ -69,7 +73,7 @@ var Dropdown = function( element, option ) {
isInsideMenu = menu[contains](activeItem),
isMenuItem = activeItem[parentNode][parentNode] === menu;

if ( isMenuItem || isSameElement ) { // navigate up | down
if ( isMenuItem ) { // navigate up | down
idx = isSameElement ? 0
: key === 38 ? (idx>1?idx-1:0)
: key === 40 ? (idx<menuItems[length]-1?idx+1:idx) : idx;
Expand Down
15 changes: 9 additions & 6 deletions lib/V3/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var globalObject = typeof global !== 'undefined' ? global : this||window,

// event names
clickEvent = 'click',
focusEvent = 'focus',
hoverEvent = 'hover',
keydownEvent = 'keydown',
keyupEvent = 'keyup',
Expand Down Expand Up @@ -187,16 +188,18 @@ var globalObject = typeof global !== 'undefined' ? global : this||window,
},

// event attach jQuery style / trigger since 1.2.0
on = function (element, event, handler) {
element.addEventListener(event, handler, false);
on = function (element, event, handler, options) {
options = options || false;
element.addEventListener(event, handler, options);
},
off = function(element, event, handler) {
element.removeEventListener(event, handler, false);
off = function(element, event, handler, options) {
options = options || false;
element.removeEventListener(event, handler, options);
},
one = function (element, event, handler) { // one since 2.0.4
one = function (element, event, handler, options) { // one since 2.0.4
on(element, event, function handlerWrapper(e){
handler(e);
off(element, event, handlerWrapper);
off(element, event, handlerWrapper, options);
});
},
getTransitionDurationFromElement = function(element) {
Expand Down
6 changes: 5 additions & 1 deletion lib/V4/dropdown-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ var Dropdown = function( element, option ) {
type(DOC, clickEvent, dismissHandler);
type(DOC, keydownEvent, preventScroll);
type(DOC, keyupEvent, keyHandler);
type(DOC, focusEvent, dismissHandler, true);
},

// handlers
dismissHandler = function(e) {
var eventTarget = e[target], hasData = eventTarget && (eventTarget[getAttribute](dataToggle)
|| eventTarget[parentNode] && getAttribute in eventTarget[parentNode]
&& eventTarget[parentNode][getAttribute](dataToggle));
if ( e.type === focusEvent && (eventTarget === element || eventTarget === menu || menu[contains](eventTarget) ) ) {
return;
}
if ( (eventTarget === menu || menu[contains](eventTarget)) && (self.persist || hasData) ) { return; }
else {
relatedTarget = eventTarget === element || element[contains](eventTarget) ? element : null;
Expand All @@ -70,7 +74,7 @@ var Dropdown = function( element, option ) {
isInsideMenu = menu[contains](activeItem),
isMenuItem = activeItem[parentNode] === menu || activeItem[parentNode][parentNode] === menu;

if ( isMenuItem || isSameElement ) { // navigate up | down
if ( isMenuItem ) { // navigate up | down
idx = isSameElement ? 0
: key === 38 ? (idx>1?idx-1:0)
: key === 40 ? (idx<menuItems[length]-1?idx+1:idx) : idx;
Expand Down
15 changes: 9 additions & 6 deletions lib/V4/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var globalObject = typeof global !== 'undefined' ? global : this||window,

// event names
clickEvent = 'click',
focusEvent = 'focus',
hoverEvent = 'hover',
keydownEvent = 'keydown',
keyupEvent = 'keyup',
Expand Down Expand Up @@ -178,16 +179,18 @@ var globalObject = typeof global !== 'undefined' ? global : this||window,
},

// event attach jQuery style / trigger since 1.2.0
on = function (element, event, handler) {
element.addEventListener(event, handler, false);
on = function (element, event, handler, options) {
options = options || false;
element.addEventListener(event, handler, options);
},
off = function(element, event, handler) {
element.removeEventListener(event, handler, false);
off = function(element, event, handler, options) {
options = options || false;
element.removeEventListener(event, handler, options);
},
one = function (element, event, handler) { // one since 2.0.4
one = function (element, event, handler, options) { // one since 2.0.4
on(element, event, function handlerWrapper(e){
handler(e);
off(element, event, handlerWrapper);
off(element, event, handlerWrapper, options);
});
},
getTransitionDurationFromElement = function(element) {
Expand Down

0 comments on commit 6ba2aa9

Please sign in to comment.