foundation-rails 6.3.1.0 → 6.4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/bower.json +3 -3
  3. data/lib/foundation/rails/version.rb +1 -1
  4. data/lib/generators/foundation/install_generator.rb +1 -1
  5. data/lib/generators/foundation/templates/_settings.scss +291 -48
  6. data/vendor/assets/js/entries/foundation-plugins.js +25 -0
  7. data/vendor/assets/js/entries/foundation.js +101 -0
  8. data/vendor/assets/js/entries/plugins/foundation.abide.js +4 -0
  9. data/vendor/assets/js/entries/plugins/foundation.accordion.js +4 -0
  10. data/vendor/assets/js/entries/plugins/foundation.accordionMenu.js +5 -0
  11. data/vendor/assets/js/entries/plugins/foundation.core.js +21 -0
  12. data/vendor/assets/js/entries/plugins/foundation.drilldown.js +4 -0
  13. data/vendor/assets/js/entries/plugins/foundation.dropdown.js +5 -0
  14. data/vendor/assets/js/entries/plugins/foundation.dropdownMenu.js +4 -0
  15. data/vendor/assets/js/entries/plugins/foundation.equalizer.js +4 -0
  16. data/vendor/assets/js/entries/plugins/foundation.interchange.js +4 -0
  17. data/vendor/assets/js/entries/plugins/foundation.magellan.js +4 -0
  18. data/vendor/assets/js/entries/plugins/foundation.offcanvas.js +4 -0
  19. data/vendor/assets/js/entries/plugins/foundation.orbit.js +5 -0
  20. data/vendor/assets/js/entries/plugins/foundation.responsiveAccordionTabs.js +5 -0
  21. data/vendor/assets/js/entries/plugins/foundation.responsiveMenu.js +5 -0
  22. data/vendor/assets/js/entries/plugins/foundation.responsiveToggle.js +5 -0
  23. data/vendor/assets/js/entries/plugins/foundation.reveal.js +4 -0
  24. data/vendor/assets/js/entries/plugins/foundation.slider.js +5 -0
  25. data/vendor/assets/js/entries/plugins/foundation.smoothScroll.js +5 -0
  26. data/vendor/assets/js/entries/plugins/foundation.sticky.js +5 -0
  27. data/vendor/assets/js/entries/plugins/foundation.tabs.js +5 -0
  28. data/vendor/assets/js/entries/plugins/foundation.toggler.js +5 -0
  29. data/vendor/assets/js/entries/plugins/foundation.tooltip.js +4 -0
  30. data/vendor/assets/js/entries/plugins/foundation.util.box.js +4 -0
  31. data/vendor/assets/js/entries/plugins/foundation.util.imageLoader.js +5 -0
  32. data/vendor/assets/js/entries/plugins/foundation.util.keyboard.js +4 -0
  33. data/vendor/assets/js/entries/plugins/foundation.util.mediaQuery.js +4 -0
  34. data/vendor/assets/js/entries/plugins/foundation.util.motion.js +5 -0
  35. data/vendor/assets/js/entries/plugins/foundation.util.nest.js +5 -0
  36. data/vendor/assets/js/entries/plugins/foundation.util.timer.js +5 -0
  37. data/vendor/assets/js/entries/plugins/foundation.util.touch.js +7 -0
  38. data/vendor/assets/js/entries/plugins/foundation.util.triggers.js +5 -0
  39. data/vendor/assets/js/foundation.abide.js.es6 +18 -15
  40. data/vendor/assets/js/foundation.accordion.js.es6 +37 -23
  41. data/vendor/assets/js/foundation.accordionMenu.js.es6 +96 -51
  42. data/vendor/assets/js/foundation.core.js.es6 +46 -87
  43. data/vendor/assets/js/foundation.drilldown.js.es6 +47 -29
  44. data/vendor/assets/js/foundation.dropdown.js.es6 +84 -122
  45. data/vendor/assets/js/foundation.dropdownMenu.js.es6 +44 -28
  46. data/vendor/assets/js/foundation.equalizer.js.es6 +18 -17
  47. data/vendor/assets/js/foundation.interchange.js.es6 +26 -19
  48. data/vendor/assets/js/foundation.js.es6 +8 -3
  49. data/vendor/assets/js/foundation.magellan.js.es6 +36 -30
  50. data/vendor/assets/js/foundation.offcanvas.js.es6 +148 -36
  51. data/vendor/assets/js/foundation.orbit.js.es6 +26 -18
  52. data/vendor/assets/js/foundation.plugin.js.es6 +54 -0
  53. data/vendor/assets/js/foundation.positionable.js.es6 +206 -0
  54. data/vendor/assets/js/{foundation.zf.responsiveAccordionTabs.js.es6 → foundation.responsiveAccordionTabs.js.es6} +33 -30
  55. data/vendor/assets/js/foundation.responsiveMenu.js.es6 +37 -29
  56. data/vendor/assets/js/foundation.responsiveToggle.js.es6 +17 -16
  57. data/vendor/assets/js/foundation.reveal.js.es6 +61 -79
  58. data/vendor/assets/js/foundation.slider.js.es6 +33 -18
  59. data/vendor/assets/js/foundation.smoothScroll.js.es6 +135 -0
  60. data/vendor/assets/js/foundation.sticky.js.es6 +25 -17
  61. data/vendor/assets/js/foundation.tabs.js.es6 +35 -27
  62. data/vendor/assets/js/foundation.toggler.js.es6 +15 -13
  63. data/vendor/assets/js/foundation.tooltip.js.es6 +100 -108
  64. data/vendor/assets/js/foundation.util.box.js.es6 +114 -78
  65. data/vendor/assets/js/foundation.util.core.js.es6 +52 -0
  66. data/vendor/assets/js/foundation.util.imageLoader.js.es6 +45 -0
  67. data/vendor/assets/js/foundation.util.keyboard.js.es6 +41 -31
  68. data/vendor/assets/js/foundation.util.mediaQuery.js.es6 +59 -55
  69. data/vendor/assets/js/foundation.util.motion.js.es6 +4 -5
  70. data/vendor/assets/js/foundation.util.nest.js.es6 +9 -23
  71. data/vendor/assets/js/{foundation.util.timerAndImageLoader.js.es6 → foundation.util.timer.js.es6} +2 -42
  72. data/vendor/assets/js/foundation.util.touch.js.es6 +91 -294
  73. data/vendor/assets/js/foundation.util.triggers.js.es6 +199 -141
  74. data/vendor/assets/scss/_global.scss +29 -1
  75. data/vendor/assets/scss/components/_accordion-menu.scss +148 -13
  76. data/vendor/assets/scss/components/_accordion.scss +5 -0
  77. data/vendor/assets/scss/components/_breadcrumbs.scss +26 -9
  78. data/vendor/assets/scss/components/_button-group.scss +4 -4
  79. data/vendor/assets/scss/components/_button.scss +59 -12
  80. data/vendor/assets/scss/components/_card.scss +10 -2
  81. data/vendor/assets/scss/components/_drilldown.scss +90 -41
  82. data/vendor/assets/scss/components/_dropdown-menu.scss +52 -6
  83. data/vendor/assets/scss/components/_dropdown.scss +8 -1
  84. data/vendor/assets/scss/components/_flex.scss +85 -2
  85. data/vendor/assets/scss/components/_menu.scss +267 -162
  86. data/vendor/assets/scss/components/_off-canvas.scss +159 -45
  87. data/vendor/assets/scss/components/_pagination.scss +1 -1
  88. data/vendor/assets/scss/components/_reveal.scss +13 -11
  89. data/vendor/assets/scss/components/_slider.scss +0 -1
  90. data/vendor/assets/scss/components/_sticky.scss +1 -0
  91. data/vendor/assets/scss/components/_table.scss +7 -6
  92. data/vendor/assets/scss/components/_tabs.scss +1 -1
  93. data/vendor/assets/scss/components/_title-bar.scss +1 -1
  94. data/vendor/assets/scss/components/_tooltip.scss +74 -21
  95. data/vendor/assets/scss/components/_top-bar.scss +2 -0
  96. data/vendor/assets/scss/forms/_fieldset.scss +0 -1
  97. data/vendor/assets/scss/forms/_meter.scss +7 -1
  98. data/vendor/assets/scss/forms/_select.scss +4 -3
  99. data/vendor/assets/scss/forms/_text.scss +11 -2
  100. data/vendor/assets/scss/foundation.scss +17 -3
  101. data/vendor/assets/scss/grid/_flex-grid.scss +3 -52
  102. data/vendor/assets/scss/prototype/_arrow.scss +36 -0
  103. data/vendor/assets/scss/prototype/_border-box.scss +35 -0
  104. data/vendor/assets/scss/prototype/_border-none.scss +35 -0
  105. data/vendor/assets/scss/prototype/_bordered.scss +54 -0
  106. data/vendor/assets/scss/prototype/_box.scss +23 -0
  107. data/vendor/assets/scss/prototype/_display.scss +50 -0
  108. data/vendor/assets/scss/prototype/_font-styling.scss +95 -0
  109. data/vendor/assets/scss/prototype/_list-style-type.scss +95 -0
  110. data/vendor/assets/scss/prototype/_overflow.scss +72 -0
  111. data/vendor/assets/scss/prototype/_position.scss +114 -0
  112. data/vendor/assets/scss/prototype/_prototype.scss +91 -0
  113. data/vendor/assets/scss/prototype/_relation.scss +157 -0
  114. data/vendor/assets/scss/prototype/_rotate.scss +31 -0
  115. data/vendor/assets/scss/prototype/_rounded.scss +54 -0
  116. data/vendor/assets/scss/prototype/_separator.scss +96 -0
  117. data/vendor/assets/scss/prototype/_shadow.scss +43 -0
  118. data/vendor/assets/scss/prototype/_sizing.scss +73 -0
  119. data/vendor/assets/scss/prototype/_spacing.scss +204 -0
  120. data/vendor/assets/scss/prototype/_text-decoration.scss +48 -0
  121. data/vendor/assets/scss/prototype/_text-transformation.scss +48 -0
  122. data/vendor/assets/scss/prototype/_text-utilities.scss +88 -0
  123. data/vendor/assets/scss/prototype/_typescale.scss +20 -0
  124. data/vendor/assets/scss/settings/_settings.scss +291 -48
  125. data/vendor/assets/scss/typography/_base.scss +2 -2
  126. data/vendor/assets/scss/typography/_helpers.scss +6 -4
  127. data/vendor/assets/scss/util/_breakpoint.scss +60 -1
  128. data/vendor/assets/scss/util/_color.scss +8 -5
  129. data/vendor/assets/scss/util/_mixins.scss +45 -5
  130. data/vendor/assets/scss/xy-grid/_cell.scss +179 -0
  131. data/vendor/assets/scss/xy-grid/_classes.scss +455 -0
  132. data/vendor/assets/scss/xy-grid/_collapse.scss +54 -0
  133. data/vendor/assets/scss/xy-grid/_frame.scss +54 -0
  134. data/vendor/assets/scss/xy-grid/_grid.scss +56 -0
  135. data/vendor/assets/scss/xy-grid/_gutters.scss +45 -0
  136. data/vendor/assets/scss/xy-grid/_layout.scss +33 -0
  137. data/vendor/assets/scss/xy-grid/_position.scss +28 -0
  138. data/vendor/assets/scss/xy-grid/_xy-grid.scss +52 -0
  139. metadata +73 -4
@@ -1,6 +1,12 @@
1
1
  'use strict';
2
2
 
3
- !function($) {
3
+ import $ from 'jquery';
4
+ import { Keyboard } from './foundation.util.keyboard';
5
+ import { GetYoDigits } from './foundation.util.core';
6
+ import { Positionable } from './foundation.positionable';
7
+
8
+ import { Triggers } from './foundation.util.triggers';
9
+
4
10
 
5
11
  /**
6
12
  * Dropdown module.
@@ -9,22 +15,26 @@
9
15
  * @requires foundation.util.box
10
16
  * @requires foundation.util.triggers
11
17
  */
12
-
13
- class Dropdown {
18
+ class Dropdown extends Positionable {
14
19
  /**
15
20
  * Creates a new instance of a dropdown.
16
21
  * @class
22
+ * @name Dropdown
17
23
  * @param {jQuery} element - jQuery object to make into a dropdown.
18
24
  * Object should be of the dropdown panel, rather than its anchor.
19
25
  * @param {Object} options - Overrides to the default plugin settings.
20
26
  */
21
- constructor(element, options) {
27
+ _setup(element, options) {
22
28
  this.$element = element;
23
29
  this.options = $.extend({}, Dropdown.defaults, this.$element.data(), options);
30
+ this.className = 'Dropdown'; // ie9 back compat
31
+
32
+ // Triggers init is idempotent, just need to make sure it is initialized
33
+ Triggers.init($);
34
+
24
35
  this._init();
25
36
 
26
- Foundation.registerPlugin(this, 'Dropdown');
27
- Foundation.Keyboard.register('Dropdown', {
37
+ Keyboard.register('Dropdown', {
28
38
  'ENTER': 'open',
29
39
  'SPACE': 'open',
30
40
  'ESCAPE': 'close'
@@ -54,114 +64,47 @@ class Dropdown {
54
64
  }else{
55
65
  this.$parent = null;
56
66
  }
57
- this.options.positionClass = this.getPositionClass();
58
- this.counter = 4;
59
- this.usedPositions = [];
67
+
60
68
  this.$element.attr({
61
69
  'aria-hidden': 'true',
62
70
  'data-yeti-box': $id,
63
71
  'data-resize': $id,
64
- 'aria-labelledby': this.$anchor[0].id || Foundation.GetYoDigits(6, 'dd-anchor')
72
+ 'aria-labelledby': this.$anchor[0].id || GetYoDigits(6, 'dd-anchor')
65
73
  });
74
+ super._init();
66
75
  this._events();
67
76
  }
68
77
 
69
- /**
70
- * Helper function to determine current orientation of dropdown pane.
71
- * @function
72
- * @returns {String} position - string value of a position class.
73
- */
74
- getPositionClass() {
75
- var verticalPosition = this.$element[0].className.match(/(top|left|right|bottom)/g);
76
- verticalPosition = verticalPosition ? verticalPosition[0] : '';
77
- var horizontalPosition = /float-(\S+)/.exec(this.$anchor[0].className);
78
- horizontalPosition = horizontalPosition ? horizontalPosition[1] : '';
79
- var position = horizontalPosition ? horizontalPosition + ' ' + verticalPosition : verticalPosition;
80
-
81
- return position;
78
+ _getDefaultPosition() {
79
+ // handle legacy classnames
80
+ var position = this.$element[0].className.match(/(top|left|right|bottom)/g);
81
+ if(position) {
82
+ return position[0];
83
+ } else {
84
+ return 'bottom'
85
+ }
82
86
  }
83
87
 
84
- /**
85
- * Adjusts the dropdown panes orientation by adding/removing positioning classes.
86
- * @function
87
- * @private
88
- * @param {String} position - position class to remove.
89
- */
90
- _reposition(position) {
91
- this.usedPositions.push(position ? position : 'bottom');
92
- //default, try switching to opposite side
93
- if(!position && (this.usedPositions.indexOf('top') < 0)){
94
- this.$element.addClass('top');
95
- }else if(position === 'top' && (this.usedPositions.indexOf('bottom') < 0)){
96
- this.$element.removeClass(position);
97
- }else if(position === 'left' && (this.usedPositions.indexOf('right') < 0)){
98
- this.$element.removeClass(position)
99
- .addClass('right');
100
- }else if(position === 'right' && (this.usedPositions.indexOf('left') < 0)){
101
- this.$element.removeClass(position)
102
- .addClass('left');
88
+ _getDefaultAlignment() {
89
+ // handle legacy float approach
90
+ var horizontalPosition = /float-(\S+)/.exec(this.$anchor[0].className);
91
+ if(horizontalPosition) {
92
+ return horizontalPosition[1];
103
93
  }
104
94
 
105
- //if default change didn't work, try bottom or left first
106
- else if(!position && (this.usedPositions.indexOf('top') > -1) && (this.usedPositions.indexOf('left') < 0)){
107
- this.$element.addClass('left');
108
- }else if(position === 'top' && (this.usedPositions.indexOf('bottom') > -1) && (this.usedPositions.indexOf('left') < 0)){
109
- this.$element.removeClass(position)
110
- .addClass('left');
111
- }else if(position === 'left' && (this.usedPositions.indexOf('right') > -1) && (this.usedPositions.indexOf('bottom') < 0)){
112
- this.$element.removeClass(position);
113
- }else if(position === 'right' && (this.usedPositions.indexOf('left') > -1) && (this.usedPositions.indexOf('bottom') < 0)){
114
- this.$element.removeClass(position);
115
- }
116
- //if nothing cleared, set to bottom
117
- else{
118
- this.$element.removeClass(position);
119
- }
120
- this.classChanged = true;
121
- this.counter--;
95
+ return super._getDefaultAlignment();
122
96
  }
123
97
 
98
+
99
+
124
100
  /**
125
- * Sets the position and orientation of the dropdown pane, checks for collisions.
101
+ * Sets the position and orientation of the dropdown pane, checks for collisions if allow-overlap is not true.
126
102
  * Recursively calls itself if a collision is detected, with a new position class.
127
103
  * @function
128
104
  * @private
129
105
  */
130
106
  _setPosition() {
131
- if(this.$anchor.attr('aria-expanded') === 'false'){ return false; }
132
- var position = this.getPositionClass(),
133
- $eleDims = Foundation.Box.GetDimensions(this.$element),
134
- $anchorDims = Foundation.Box.GetDimensions(this.$anchor),
135
- _this = this,
136
- direction = (position === 'left' ? 'left' : ((position === 'right') ? 'left' : 'top')),
137
- param = (direction === 'top') ? 'height' : 'width',
138
- offset = (param === 'height') ? this.options.vOffset : this.options.hOffset;
139
-
140
- if(($eleDims.width >= $eleDims.windowDims.width) || (!this.counter && !Foundation.Box.ImNotTouchingYou(this.$element, this.$parent))){
141
- var newWidth = $eleDims.windowDims.width,
142
- parentHOffset = 0;
143
- if(this.$parent){
144
- var $parentDims = Foundation.Box.GetDimensions(this.$parent),
145
- parentHOffset = $parentDims.offset.left;
146
- if ($parentDims.width < newWidth){
147
- newWidth = $parentDims.width;
148
- }
149
- }
150
-
151
- this.$element.offset(Foundation.Box.GetOffsets(this.$element, this.$anchor, 'center bottom', this.options.vOffset, this.options.hOffset + parentHOffset, true)).css({
152
- 'width': newWidth - (this.options.hOffset * 2),
153
- 'height': 'auto'
154
- });
155
- this.classChanged = true;
156
- return false;
157
- }
158
-
159
- this.$element.offset(Foundation.Box.GetOffsets(this.$element, this.$anchor, position, this.options.vOffset, this.options.hOffset));
160
-
161
- while(!Foundation.Box.ImNotTouchingYou(this.$element, this.$parent, true) && this.counter){
162
- this._reposition(position);
163
- this._setPosition();
164
- }
107
+ super._setPosition(this.$anchor, this.$element, this.$parent);
165
108
  }
166
109
 
167
110
  /**
@@ -212,9 +155,9 @@ class Dropdown {
212
155
  this.$anchor.add(this.$element).on('keydown.zf.dropdown', function(e) {
213
156
 
214
157
  var $target = $(this),
215
- visibleFocusableElements = Foundation.Keyboard.findFocusable(_this.$element);
158
+ visibleFocusableElements = Keyboard.findFocusable(_this.$element);
216
159
 
217
- Foundation.Keyboard.handleKey(e, 'Dropdown', {
160
+ Keyboard.handleKey(e, 'Dropdown', {
218
161
  open: function() {
219
162
  if ($target.is(_this.$anchor)) {
220
163
  _this.open();
@@ -267,12 +210,14 @@ class Dropdown {
267
210
  this.$anchor.addClass('hover')
268
211
  .attr({'aria-expanded': true});
269
212
  // this.$element/*.show()*/;
213
+
214
+ this.$element.addClass('is-opening');
270
215
  this._setPosition();
271
- this.$element.addClass('is-open')
216
+ this.$element.removeClass('is-opening').addClass('is-open')
272
217
  .attr({'aria-hidden': false});
273
218
 
274
219
  if(this.options.autoFocus){
275
- var $focusable = Foundation.Keyboard.findFocusable(this.$element);
220
+ var $focusable = Keyboard.findFocusable(this.$element);
276
221
  if($focusable.length){
277
222
  $focusable.eq(0).focus();
278
223
  }
@@ -281,7 +226,7 @@ class Dropdown {
281
226
  if(this.options.closeOnClick){ this._addBodyHandler(); }
282
227
 
283
228
  if (this.options.trapFocus) {
284
- Foundation.Keyboard.trapFocus(this.$element);
229
+ Keyboard.trapFocus(this.$element);
285
230
  }
286
231
 
287
232
  /**
@@ -306,17 +251,6 @@ class Dropdown {
306
251
  this.$anchor.removeClass('hover')
307
252
  .attr('aria-expanded', false);
308
253
 
309
- if(this.classChanged){
310
- var curPositionClass = this.getPositionClass();
311
- if(curPositionClass){
312
- this.$element.removeClass(curPositionClass);
313
- }
314
- this.$element.addClass(this.options.positionClass)
315
- /*.hide()*/.css({height: '', width: ''});
316
- this.classChanged = false;
317
- this.counter = 4;
318
- this.usedPositions.length = 0;
319
- }
320
254
  /**
321
255
  * Fires once the dropdown is no longer visible.
322
256
  * @event Dropdown#hide
@@ -324,7 +258,7 @@ class Dropdown {
324
258
  this.$element.trigger('hide.zf.dropdown', [this.$element]);
325
259
 
326
260
  if (this.options.trapFocus) {
327
- Foundation.Keyboard.releaseFocus(this.$element);
261
+ Keyboard.releaseFocus(this.$element);
328
262
  }
329
263
  }
330
264
 
@@ -345,11 +279,11 @@ class Dropdown {
345
279
  * Destroys the dropdown.
346
280
  * @function
347
281
  */
348
- destroy() {
282
+ _destroy() {
349
283
  this.$element.off('.zf.trigger').hide();
350
284
  this.$anchor.off('.zf.dropdown');
285
+ $(document.body).off('click.zf.dropdown');
351
286
 
352
- Foundation.unregisterPlugin(this);
353
287
  }
354
288
  }
355
289
 
@@ -386,23 +320,54 @@ Dropdown.defaults = {
386
320
  * Number of pixels between the dropdown pane and the triggering element on open.
387
321
  * @option
388
322
  * @type {number}
389
- * @default 1
323
+ * @default 0
390
324
  */
391
- vOffset: 1,
325
+ vOffset: 0,
392
326
  /**
393
327
  * Number of pixels between the dropdown pane and the triggering element on open.
394
328
  * @option
395
329
  * @type {number}
396
- * @default 1
330
+ * @default 0
397
331
  */
398
- hOffset: 1,
332
+ hOffset: 0,
399
333
  /**
400
- * Class applied to adjust open position. JS will test and fill this in.
334
+ * DEPRECATED: Class applied to adjust open position.
401
335
  * @option
402
336
  * @type {string}
403
337
  * @default ''
404
338
  */
405
339
  positionClass: '',
340
+
341
+ /**
342
+ * Position of dropdown. Can be left, right, bottom, top, or auto.
343
+ * @option
344
+ * @type {string}
345
+ * @default 'auto'
346
+ */
347
+ position: 'auto',
348
+ /**
349
+ * Alignment of dropdown relative to anchor. Can be left, right, bottom, top, center, or auto.
350
+ * @option
351
+ * @type {string}
352
+ * @default 'auto'
353
+ */
354
+ alignment: 'auto',
355
+ /**
356
+ * Allow overlap of container/window. If false, dropdown will first try to position as defined by data-position and data-alignment, but reposition if it would cause an overflow.
357
+ * @option
358
+ * @type {boolean}
359
+ * @default false
360
+ */
361
+ allowOverlap: false,
362
+ /**
363
+ * Allow overlap of only the bottom of the container. This is the most common
364
+ * behavior for dropdowns, allowing the dropdown to extend the bottom of the
365
+ * screen but not otherwise influence or break out of the container.
366
+ * @option
367
+ * @type {boolean}
368
+ * @default true
369
+ */
370
+ allowBottomOverlap: true,
406
371
  /**
407
372
  * Allow the plugin to trap focus to the dropdown pane if opened with keyboard commands.
408
373
  * @option
@@ -426,7 +391,4 @@ Dropdown.defaults = {
426
391
  closeOnClick: false
427
392
  }
428
393
 
429
- // Window exports
430
- Foundation.plugin(Dropdown, 'Dropdown');
431
-
432
- }(jQuery);
394
+ export {Dropdown};
@@ -1,6 +1,12 @@
1
1
  'use strict';
2
2
 
3
- !function($) {
3
+ import $ from 'jquery';
4
+ import { Keyboard } from './foundation.util.keyboard';
5
+ import { Nest } from './foundation.util.nest';
6
+ import { Box } from './foundation.util.box';
7
+ import { rtl as Rtl } from './foundation.util.core';
8
+ import { Plugin } from './foundation.plugin';
9
+
4
10
 
5
11
  /**
6
12
  * DropdownMenu module.
@@ -10,23 +16,24 @@
10
16
  * @requires foundation.util.nest
11
17
  */
12
18
 
13
- class DropdownMenu {
19
+ class DropdownMenu extends Plugin {
14
20
  /**
15
21
  * Creates a new instance of DropdownMenu.
16
22
  * @class
23
+ * @name DropdownMenu
17
24
  * @fires DropdownMenu#init
18
25
  * @param {jQuery} element - jQuery object to make into a dropdown menu.
19
26
  * @param {Object} options - Overrides to the default plugin settings.
20
27
  */
21
- constructor(element, options) {
28
+ _setup(element, options) {
22
29
  this.$element = element;
23
30
  this.options = $.extend({}, DropdownMenu.defaults, this.$element.data(), options);
31
+ this.className = 'DropdownMenu'; // ie9 back compat
24
32
 
25
- Foundation.Nest.Feather(this.$element, 'dropdown');
33
+ Nest.Feather(this.$element, 'dropdown');
26
34
  this._init();
27
35
 
28
- Foundation.registerPlugin(this, 'DropdownMenu');
29
- Foundation.Keyboard.register('DropdownMenu', {
36
+ Keyboard.register('DropdownMenu', {
30
37
  'ENTER': 'open',
31
38
  'SPACE': 'open',
32
39
  'ARROW_RIGHT': 'next',
@@ -50,18 +57,31 @@ class DropdownMenu {
50
57
  this.$tabs = this.$element.children('[role="menuitem"]');
51
58
  this.$tabs.find('ul.is-dropdown-submenu').addClass(this.options.verticalClass);
52
59
 
53
- if (this.$element.hasClass(this.options.rightClass) || this.options.alignment === 'right' || Foundation.rtl() || this.$element.parents('.top-bar-right').is('*')) {
54
- this.options.alignment = 'right';
55
- subs.addClass('opens-left');
60
+ if (this.options.alignment === 'auto') {
61
+ if (this.$element.hasClass(this.options.rightClass) || Rtl() || this.$element.parents('.top-bar-right').is('*')) {
62
+ this.options.alignment = 'right';
63
+ subs.addClass('opens-left');
64
+ } else {
65
+ this.options.alignment = 'left';
66
+ subs.addClass('opens-right');
67
+ }
56
68
  } else {
57
- subs.addClass('opens-right');
69
+ if (this.options.alignment === 'right') {
70
+ subs.addClass('opens-left');
71
+ } else {
72
+ subs.addClass('opens-right');
73
+ }
58
74
  }
59
75
  this.changed = false;
60
76
  this._events();
61
77
  };
62
78
 
63
79
  _isVertical() {
64
- return this.$tabs.css('display') === 'block';
80
+ return this.$tabs.css('display') === 'block' || this.$element.css('flex-direction') === 'column';
81
+ }
82
+
83
+ _isRtl() {
84
+ return this.$element.hasClass('align-right') || (Rtl() && !this.$element.hasClass('align-left'));
65
85
  }
66
86
 
67
87
  /**
@@ -179,7 +199,7 @@ class DropdownMenu {
179
199
  open: openSub,
180
200
  close: function() {
181
201
  _this._hide(_this.$element);
182
- _this.$menuItems.find('a:first').focus(); // focus to first element
202
+ _this.$menuItems.eq(0).children('a').focus(); // focus to first element
183
203
  e.preventDefault();
184
204
  },
185
205
  handled: function() {
@@ -189,7 +209,7 @@ class DropdownMenu {
189
209
 
190
210
  if (isTab) {
191
211
  if (_this._isVertical()) { // vertical menu
192
- if (Foundation.rtl()) { // right aligned
212
+ if (_this._isRtl()) { // right aligned
193
213
  $.extend(functions, {
194
214
  down: nextSibling,
195
215
  up: prevSibling,
@@ -205,7 +225,7 @@ class DropdownMenu {
205
225
  });
206
226
  }
207
227
  } else { // horizontal menu
208
- if (Foundation.rtl()) { // right aligned
228
+ if (_this._isRtl()) { // right aligned
209
229
  $.extend(functions, {
210
230
  next: prevSibling,
211
231
  previous: nextSibling,
@@ -222,7 +242,7 @@ class DropdownMenu {
222
242
  }
223
243
  }
224
244
  } else { // not tabs -> one sub
225
- if (Foundation.rtl()) { // right aligned
245
+ if (_this._isRtl()) { // right aligned
226
246
  $.extend(functions, {
227
247
  next: closeSub,
228
248
  previous: openSub,
@@ -238,7 +258,7 @@ class DropdownMenu {
238
258
  });
239
259
  }
240
260
  }
241
- Foundation.Keyboard.handleKey(e, 'DropdownMenu', functions);
261
+ Keyboard.handleKey(e, 'DropdownMenu', functions);
242
262
 
243
263
  });
244
264
  }
@@ -276,12 +296,12 @@ class DropdownMenu {
276
296
  this._hide($sibs, idx);
277
297
  $sub.css('visibility', 'hidden').addClass('js-dropdown-active')
278
298
  .parent('li.is-dropdown-submenu-parent').addClass('is-active');
279
- var clear = Foundation.Box.ImNotTouchingYou($sub, null, true);
299
+ var clear = Box.ImNotTouchingYou($sub, null, true);
280
300
  if (!clear) {
281
301
  var oldClass = this.options.alignment === 'left' ? '-right' : '-left',
282
302
  $parentLi = $sub.parent('.is-dropdown-submenu-parent');
283
303
  $parentLi.removeClass(`opens${oldClass}`).addClass(`opens-${this.options.alignment}`);
284
- clear = Foundation.Box.ImNotTouchingYou($sub, null, true);
304
+ clear = Box.ImNotTouchingYou($sub, null, true);
285
305
  if (!clear) {
286
306
  $parentLi.removeClass(`opens-${this.options.alignment}`).addClass('opens-inner');
287
307
  }
@@ -343,12 +363,11 @@ class DropdownMenu {
343
363
  * Destroys the plugin.
344
364
  * @function
345
365
  */
346
- destroy() {
366
+ _destroy() {
347
367
  this.$menuItems.off('.zf.dropdownmenu').removeAttr('data-is-click')
348
368
  .removeClass('is-right-arrow is-left-arrow is-down-arrow opens-right opens-left opens-inner');
349
369
  $(document.body).off('.zf.dropdownmenu');
350
- Foundation.Nest.Burn(this.$element, 'dropdown');
351
- Foundation.unregisterPlugin(this);
370
+ Nest.Burn(this.$element, 'dropdown');
352
371
  }
353
372
  }
354
373
 
@@ -393,12 +412,12 @@ DropdownMenu.defaults = {
393
412
 
394
413
  closingTime: 500,
395
414
  /**
396
- * Position of the menu relative to what direction the submenus should open. Handled by JS. Can be `'left'` or `'right'`.
415
+ * Position of the menu relative to what direction the submenus should open. Handled by JS. Can be `'auto'`, `'left'` or `'right'`.
397
416
  * @option
398
417
  * @type {string}
399
- * @default 'left'
418
+ * @default 'auto'
400
419
  */
401
- alignment: 'left',
420
+ alignment: 'auto',
402
421
  /**
403
422
  * Allow clicks on the body to close any open submenus.
404
423
  * @option
@@ -436,7 +455,4 @@ DropdownMenu.defaults = {
436
455
  forceFollow: true
437
456
  };
438
457
 
439
- // Window exports
440
- Foundation.plugin(DropdownMenu, 'DropdownMenu');
441
-
442
- }(jQuery);
458
+ export {DropdownMenu};