@@ -66,19 +66,19 @@ class Drilldown {
66
66
// this._menuLinkEvents();
67
67
// }
68
68
this . $submenuAnchors . each ( function ( ) {
69
- var $sub = $ ( this ) ;
70
- var $link = $sub . find ( 'a:first' ) ;
69
+ var $link = $ ( this ) ;
70
+ var $sub = $link . parent ( ) ;
71
71
if ( _this . options . parentLink ) {
72
72
$link . clone ( ) . prependTo ( $sub . children ( '[data-submenu]' ) ) . wrap ( '<li class="is-submenu-parent-item is-submenu-item is-drilldown-submenu-item" role="menu-item"></li>' ) ;
73
73
}
74
74
$link . data ( 'savedHref' , $link . attr ( 'href' ) ) . removeAttr ( 'href' ) ;
75
- $sub . children ( '[data-submenu]' )
75
+ $link . children ( '[data-submenu]' )
76
76
. attr ( {
77
77
'aria-hidden' : true ,
78
78
'tabindex' : 0 ,
79
79
'role' : 'menu'
80
80
} ) ;
81
- _this . _events ( $sub ) ;
81
+ _this . _events ( $link ) ;
82
82
} ) ;
83
83
this . $submenus . each ( function ( ) {
84
84
var $menu = $ ( this ) ,
@@ -89,8 +89,8 @@ class Drilldown {
89
89
_this . _back ( $menu ) ;
90
90
} ) ;
91
91
if ( ! this . $element . parent ( ) . hasClass ( 'is-drilldown' ) ) {
92
- this . $wrapper = $ ( this . options . wrapper ) . addClass ( 'is-drilldown' ) . css ( this . _getMaxDims ( ) ) ;
93
- this . $element . wrap ( this . $wrapper ) ;
92
+ this . $wrapper = $ ( this . options . wrapper ) . addClass ( 'is-drilldown' ) ;
93
+ this . $wrapper = this . $ element. wrap ( this . $wrapper ) . parent ( ) . css ( this . _getMaxDims ( ) ) ;
94
94
}
95
95
}
96
96
@@ -116,8 +116,9 @@ class Drilldown {
116
116
_this . _show ( $elem . parent ( 'li' ) ) ;
117
117
118
118
if ( _this . options . closeOnClick ) {
119
- var $body = $ ( 'body' ) . not ( _this . $wrapper ) ;
119
+ var $body = $ ( 'body' ) ;
120
120
$body . off ( '.zf.drilldown' ) . on ( 'click.zf.drilldown' , function ( e ) {
121
+ if ( e . target === _this . $element [ 0 ] || $ . contains ( _this . $element [ 0 ] , e . target ) ) { return ; }
121
122
e . preventDefault ( ) ;
122
123
_this . _hideAll ( ) ;
123
124
$body . off ( '.zf.drilldown' ) ;
@@ -132,9 +133,9 @@ class Drilldown {
132
133
*/
133
134
_keyboardEvents ( ) {
134
135
var _this = this ;
135
-
136
+
136
137
this . $menuItems . add ( this . $element . find ( '.js-drilldown-back > a' ) ) . on ( 'keydown.zf.drilldown' , function ( e ) {
137
-
138
+
138
139
var $element = $ ( this ) ,
139
140
$elements = $element . parent ( 'li' ) . parent ( 'ul' ) . children ( 'li' ) . children ( 'a' ) ,
140
141
$prevElement ,
@@ -155,7 +156,7 @@ class Drilldown {
155
156
$element . parent ( 'li' ) . one ( Foundation . transitionend ( $element ) , function ( ) {
156
157
$element . parent ( 'li' ) . find ( 'ul li a' ) . filter ( _this . $menuItems ) . first ( ) . focus ( ) ;
157
158
} ) ;
158
- e . preventDefault ( ) ;
159
+ return true ;
159
160
}
160
161
} ,
161
162
previous : function ( ) {
@@ -165,15 +166,15 @@ class Drilldown {
165
166
$element . parent ( 'li' ) . parent ( 'ul' ) . parent ( 'li' ) . children ( 'a' ) . first ( ) . focus ( ) ;
166
167
} , 1 ) ;
167
168
} ) ;
168
- e . preventDefault ( ) ;
169
+ return true ;
169
170
} ,
170
171
up : function ( ) {
171
172
$prevElement . focus ( ) ;
172
- e . preventDefault ( ) ;
173
+ return true ;
173
174
} ,
174
175
down : function ( ) {
175
176
$nextElement . focus ( ) ;
176
- e . preventDefault ( ) ;
177
+ return true ;
177
178
} ,
178
179
close : function ( ) {
179
180
_this . _back ( ) ;
@@ -186,17 +187,19 @@ class Drilldown {
186
187
setTimeout ( function ( ) {
187
188
$element . parent ( 'li' ) . parent ( 'ul' ) . parent ( 'li' ) . children ( 'a' ) . first ( ) . focus ( ) ;
188
189
} , 1 ) ;
189
- } ) ;
190
- e . preventDefault ( ) ;
190
+ } ) ;
191
191
} else if ( $element . is ( _this . $submenuAnchors ) ) {
192
192
_this . _show ( $element . parent ( 'li' ) ) ;
193
193
$element . parent ( 'li' ) . one ( Foundation . transitionend ( $element ) , function ( ) {
194
194
$element . parent ( 'li' ) . find ( 'ul li a' ) . filter ( _this . $menuItems ) . first ( ) . focus ( ) ;
195
- } ) ;
196
- e . preventDefault ( ) ;
195
+ } ) ;
197
196
}
197
+ return true ;
198
198
} ,
199
- handled : function ( ) {
199
+ handled : function ( preventDefault ) {
200
+ if ( preventDefault ) {
201
+ e . preventDefault ( ) ;
202
+ }
200
203
e . stopImmediatePropagation ( ) ;
201
204
}
202
205
} ) ;
@@ -262,7 +265,10 @@ class Drilldown {
262
265
*/
263
266
_show ( $elem ) {
264
267
$elem . children ( '[data-submenu]' ) . addClass ( 'is-active' ) ;
265
-
268
+ /**
269
+ * Fires when the submenu has opened.
270
+ * @event Drilldown#open
271
+ */
266
272
this . $element . trigger ( 'open.zf.drilldown' , [ $elem ] ) ;
267
273
} ;
268
274
@@ -280,7 +286,7 @@ class Drilldown {
280
286
$elem . blur ( ) ;
281
287
} ) ;
282
288
/**
283
- * Fires when the submenu is has closed.
289
+ * Fires when the submenu has closed.
284
290
* @event Drilldown#hide
285
291
*/
286
292
$elem . trigger ( 'hide.zf.drilldown' , [ $elem ] ) ;
@@ -315,8 +321,10 @@ class Drilldown {
315
321
this . $element . unwrap ( )
316
322
. find ( '.js-drilldown-back, .is-submenu-parent-item' ) . remove ( )
317
323
. end ( ) . find ( '.is-active, .is-closing, .is-drilldown-submenu' ) . removeClass ( 'is-active is-closing is-drilldown-submenu' )
318
- . end ( ) . find ( '[data-submenu]' ) . removeAttr ( 'aria-hidden tabindex role' )
319
- . off ( '.zf.drilldown' ) . end ( ) . off ( 'zf.drilldown' ) ;
324
+ . end ( ) . find ( '[data-submenu]' ) . removeAttr ( 'aria-hidden tabindex role' ) ;
325
+ this . $submenuAnchors . each ( function ( ) {
326
+ $ ( this ) . off ( '.zf.drilldown' ) ;
327
+ } ) ;
320
328
this . $element . find ( 'a' ) . each ( function ( ) {
321
329
var $link = $ ( this ) ;
322
330
if ( $link . data ( 'savedHref' ) ) {
@@ -358,4 +366,4 @@ Drilldown.defaults = {
358
366
// Window exports
359
367
Foundation . plugin ( Drilldown , 'Drilldown' ) ;
360
368
361
- } ( jQuery ) ;
369
+ } ( jQuery ) ;
0 commit comments