foundation-rails 5.5.3.2 → 6.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -8
  4. data/Rakefile +23 -0
  5. data/app/views/foundation/rails/styleguide/show.html.erb +2 -5
  6. data/bower.json +2 -2
  7. data/lib/foundation/rails/version.rb +1 -1
  8. data/lib/generators/foundation/install_generator.rb +6 -3
  9. data/lib/generators/foundation/templates/_settings.scss +546 -0
  10. data/lib/generators/foundation/templates/application.html.erb +0 -1
  11. data/lib/generators/foundation/templates/application.html.haml +0 -2
  12. data/lib/generators/foundation/templates/application.html.slim +0 -2
  13. data/lib/generators/foundation/templates/foundation_and_overrides.scss +51 -0
  14. data/vendor/assets/js/foundation.abide.js +418 -0
  15. data/vendor/assets/js/foundation.accordion.js +229 -0
  16. data/vendor/assets/js/foundation.accordionMenu.js +262 -0
  17. data/vendor/assets/js/foundation.core.js +378 -0
  18. data/vendor/assets/js/foundation.drilldown.js +321 -0
  19. data/vendor/assets/js/foundation.dropdown.js +390 -0
  20. data/vendor/assets/js/foundation.dropdownMenu.js +391 -0
  21. data/vendor/assets/js/foundation.equalizer.js +274 -0
  22. data/vendor/assets/js/foundation.interchange.js +184 -0
  23. data/vendor/assets/js/foundation.js +28 -0
  24. data/vendor/assets/js/foundation.magellan.js +212 -0
  25. data/vendor/assets/js/foundation.offcanvas.js +371 -0
  26. data/vendor/assets/js/foundation.orbit.js +419 -0
  27. data/vendor/assets/js/foundation.responsiveMenu.js +145 -0
  28. data/vendor/assets/js/foundation.responsiveToggle.js +106 -0
  29. data/vendor/assets/js/foundation.reveal.js +478 -0
  30. data/vendor/assets/js/foundation.slider.js +484 -0
  31. data/vendor/assets/js/foundation.sticky.js +436 -0
  32. data/vendor/assets/js/foundation.tabs.js +306 -0
  33. data/vendor/assets/js/foundation.toggler.js +147 -0
  34. data/vendor/assets/js/foundation.tooltip.js +429 -0
  35. data/vendor/assets/js/foundation.util.box.js +169 -0
  36. data/vendor/assets/js/foundation.util.keyboard.js +115 -0
  37. data/vendor/assets/js/foundation.util.mediaQuery.js +210 -0
  38. data/vendor/assets/js/foundation.util.motion.js +89 -0
  39. data/vendor/assets/js/foundation.util.nest.js +64 -0
  40. data/vendor/assets/js/foundation.util.timerAndImageLoader.js +78 -0
  41. data/vendor/assets/js/foundation.util.touch.js +339 -0
  42. data/vendor/assets/js/foundation.util.triggers.js +222 -0
  43. data/vendor/assets/scss/_global.scss +626 -0
  44. data/vendor/assets/scss/components/_accordion-menu.scss +32 -0
  45. data/vendor/assets/scss/components/_accordion.scss +113 -0
  46. data/vendor/assets/scss/components/_badge.scss +55 -0
  47. data/vendor/assets/scss/components/_breadcrumbs.scss +94 -0
  48. data/vendor/assets/scss/components/_button-group.scss +130 -0
  49. data/vendor/assets/scss/components/_button.scss +265 -0
  50. data/vendor/assets/scss/components/_callout.scss +105 -0
  51. data/vendor/assets/scss/components/_close-button.scss +61 -0
  52. data/vendor/assets/scss/components/_drilldown.scss +75 -0
  53. data/vendor/assets/scss/components/_dropdown-menu.scss +148 -0
  54. data/vendor/assets/scss/components/_dropdown.scss +64 -0
  55. data/vendor/assets/scss/components/_flex-video.scss +63 -0
  56. data/vendor/assets/scss/components/_float.scss +27 -0
  57. data/vendor/assets/scss/components/_label.scss +56 -0
  58. data/vendor/assets/scss/components/_media-object.scss +74 -0
  59. data/vendor/assets/scss/components/_menu.scss +209 -0
  60. data/vendor/assets/scss/components/_off-canvas.scss +180 -0
  61. data/vendor/assets/scss/components/_orbit.scss +193 -0
  62. data/vendor/assets/scss/components/_pagination.scss +158 -0
  63. data/vendor/assets/scss/components/_progress-bar.scss +83 -0
  64. data/vendor/assets/scss/components/_reveal.scss +156 -0
  65. data/vendor/assets/scss/components/_slider.scss +158 -0
  66. data/vendor/assets/scss/components/_sticky.scss +38 -0
  67. data/vendor/assets/scss/components/_switch.scss +232 -0
  68. data/vendor/assets/scss/components/_table.scss +213 -0
  69. data/vendor/assets/scss/components/_tabs.scss +170 -0
  70. data/vendor/assets/scss/components/_thumbnail.scss +54 -0
  71. data/vendor/assets/scss/components/_title-bar.scss +68 -0
  72. data/vendor/assets/scss/components/_tooltip.scss +100 -0
  73. data/vendor/assets/scss/components/_top-bar.scss +89 -0
  74. data/vendor/assets/scss/components/_visibility.scss +131 -0
  75. data/vendor/assets/scss/forms/_checkbox.scss +36 -0
  76. data/vendor/assets/scss/forms/_error.scss +82 -0
  77. data/vendor/assets/scss/forms/_fieldset.scss +53 -0
  78. data/vendor/assets/scss/forms/_forms.scss +32 -0
  79. data/vendor/assets/scss/forms/_help-text.scss +30 -0
  80. data/vendor/assets/scss/forms/_input-group.scss +91 -0
  81. data/vendor/assets/scss/forms/_label.scss +48 -0
  82. data/vendor/assets/scss/forms/_select.scss +63 -0
  83. data/vendor/assets/scss/forms/_text.scss +154 -0
  84. data/vendor/assets/scss/foundation.scss +91 -0
  85. data/vendor/assets/scss/grid/_classes.scss +153 -0
  86. data/vendor/assets/scss/grid/_column.scss +124 -0
  87. data/vendor/assets/scss/grid/_flex-grid.scss +281 -0
  88. data/vendor/assets/scss/grid/_grid.scss +48 -0
  89. data/vendor/assets/scss/grid/_gutter.scss +34 -0
  90. data/vendor/assets/scss/grid/_layout.scss +33 -0
  91. data/vendor/assets/scss/grid/_position.scss +72 -0
  92. data/vendor/assets/scss/grid/_row.scss +97 -0
  93. data/vendor/assets/scss/grid/_size.scss +24 -0
  94. data/vendor/assets/scss/settings/_settings.scss +547 -0
  95. data/vendor/assets/scss/typography/_alignment.scss +22 -0
  96. data/vendor/assets/scss/typography/_base.scss +439 -0
  97. data/vendor/assets/scss/typography/_helpers.scss +77 -0
  98. data/vendor/assets/scss/typography/_print.scss +73 -0
  99. data/vendor/assets/scss/typography/_typography.scss +28 -0
  100. data/vendor/assets/scss/util/_breakpoint.scss +266 -0
  101. data/vendor/assets/scss/util/_color.scss +41 -0
  102. data/vendor/assets/scss/util/_mixins.scss +223 -0
  103. data/vendor/assets/scss/util/_selector.scss +40 -0
  104. data/vendor/assets/scss/util/_unit.scss +90 -0
  105. data/vendor/assets/scss/util/_util.scss +15 -0
  106. data/vendor/assets/scss/util/_value.scss +126 -0
  107. metadata +97 -64
  108. data/update-gem.sh +0 -20
  109. data/vendor/assets/javascripts/foundation.js +0 -17
  110. data/vendor/assets/javascripts/foundation/foundation.abide.js +0 -426
  111. data/vendor/assets/javascripts/foundation/foundation.accordion.js +0 -125
  112. data/vendor/assets/javascripts/foundation/foundation.alert.js +0 -43
  113. data/vendor/assets/javascripts/foundation/foundation.clearing.js +0 -586
  114. data/vendor/assets/javascripts/foundation/foundation.dropdown.js +0 -468
  115. data/vendor/assets/javascripts/foundation/foundation.equalizer.js +0 -104
  116. data/vendor/assets/javascripts/foundation/foundation.interchange.js +0 -360
  117. data/vendor/assets/javascripts/foundation/foundation.joyride.js +0 -935
  118. data/vendor/assets/javascripts/foundation/foundation.js +0 -732
  119. data/vendor/assets/javascripts/foundation/foundation.magellan.js +0 -214
  120. data/vendor/assets/javascripts/foundation/foundation.offcanvas.js +0 -225
  121. data/vendor/assets/javascripts/foundation/foundation.orbit.js +0 -476
  122. data/vendor/assets/javascripts/foundation/foundation.reveal.js +0 -522
  123. data/vendor/assets/javascripts/foundation/foundation.slider.js +0 -296
  124. data/vendor/assets/javascripts/foundation/foundation.tab.js +0 -247
  125. data/vendor/assets/javascripts/foundation/foundation.tooltip.js +0 -348
  126. data/vendor/assets/javascripts/foundation/foundation.topbar.js +0 -458
  127. data/vendor/assets/javascripts/vendor/modernizr.js +0 -1406
  128. data/vendor/assets/stylesheets/foundation.scss +0 -42
  129. data/vendor/assets/stylesheets/foundation/_functions.scss +0 -156
  130. data/vendor/assets/stylesheets/foundation/_settings.scss +0 -1489
  131. data/vendor/assets/stylesheets/foundation/components/_accordion.scss +0 -161
  132. data/vendor/assets/stylesheets/foundation/components/_alert-boxes.scss +0 -128
  133. data/vendor/assets/stylesheets/foundation/components/_block-grid.scss +0 -133
  134. data/vendor/assets/stylesheets/foundation/components/_breadcrumbs.scss +0 -132
  135. data/vendor/assets/stylesheets/foundation/components/_button-groups.scss +0 -208
  136. data/vendor/assets/stylesheets/foundation/components/_buttons.scss +0 -261
  137. data/vendor/assets/stylesheets/foundation/components/_clearing.scss +0 -260
  138. data/vendor/assets/stylesheets/foundation/components/_dropdown-buttons.scss +0 -130
  139. data/vendor/assets/stylesheets/foundation/components/_dropdown.scss +0 -269
  140. data/vendor/assets/stylesheets/foundation/components/_flex-video.scss +0 -51
  141. data/vendor/assets/stylesheets/foundation/components/_forms.scss +0 -607
  142. data/vendor/assets/stylesheets/foundation/components/_global.scss +0 -566
  143. data/vendor/assets/stylesheets/foundation/components/_grid.scss +0 -292
  144. data/vendor/assets/stylesheets/foundation/components/_icon-bar.scss +0 -460
  145. data/vendor/assets/stylesheets/foundation/components/_inline-lists.scss +0 -58
  146. data/vendor/assets/stylesheets/foundation/components/_joyride.scss +0 -220
  147. data/vendor/assets/stylesheets/foundation/components/_keystrokes.scss +0 -60
  148. data/vendor/assets/stylesheets/foundation/components/_labels.scss +0 -106
  149. data/vendor/assets/stylesheets/foundation/components/_magellan.scss +0 -34
  150. data/vendor/assets/stylesheets/foundation/components/_offcanvas.scss +0 -606
  151. data/vendor/assets/stylesheets/foundation/components/_orbit.scss +0 -388
  152. data/vendor/assets/stylesheets/foundation/components/_pagination.scss +0 -163
  153. data/vendor/assets/stylesheets/foundation/components/_panels.scss +0 -107
  154. data/vendor/assets/stylesheets/foundation/components/_pricing-tables.scss +0 -150
  155. data/vendor/assets/stylesheets/foundation/components/_progress-bars.scss +0 -85
  156. data/vendor/assets/stylesheets/foundation/components/_range-slider.scss +0 -177
  157. data/vendor/assets/stylesheets/foundation/components/_reveal.scss +0 -212
  158. data/vendor/assets/stylesheets/foundation/components/_side-nav.scss +0 -120
  159. data/vendor/assets/stylesheets/foundation/components/_split-buttons.scss +0 -203
  160. data/vendor/assets/stylesheets/foundation/components/_sub-nav.scss +0 -125
  161. data/vendor/assets/stylesheets/foundation/components/_switches.scss +0 -241
  162. data/vendor/assets/stylesheets/foundation/components/_tables.scss +0 -135
  163. data/vendor/assets/stylesheets/foundation/components/_tabs.scss +0 -142
  164. data/vendor/assets/stylesheets/foundation/components/_thumbs.scss +0 -66
  165. data/vendor/assets/stylesheets/foundation/components/_tooltips.scss +0 -142
  166. data/vendor/assets/stylesheets/foundation/components/_top-bar.scss +0 -745
  167. data/vendor/assets/stylesheets/foundation/components/_type.scss +0 -525
  168. data/vendor/assets/stylesheets/foundation/components/_visibility.scss +0 -425
  169. data/vendor/assets/stylesheets/normalize.scss +0 -424
@@ -0,0 +1,28 @@
1
+ //= require foundation.abide
2
+ //= require foundation.accordion
3
+ //= require foundation.accordionMenu
4
+ //= require foundation.core
5
+ //= require foundation.drilldown
6
+ //= require foundation.dropdown
7
+ //= require foundation.dropdownMenu
8
+ //= require foundation.equalizer
9
+ //= require foundation.interchange
10
+ //= require foundation.magellan
11
+ //= require foundation.offcanvas
12
+ //= require foundation.orbit
13
+ //= require foundation.responsiveMenu
14
+ //= require foundation.responsiveToggle
15
+ //= require foundation.reveal
16
+ //= require foundation.slider
17
+ //= require foundation.sticky
18
+ //= require foundation.tabs
19
+ //= require foundation.toggler
20
+ //= require foundation.tooltip
21
+ //= require foundation.util.box
22
+ //= require foundation.util.keyboard
23
+ //= require foundation.util.mediaQuery
24
+ //= require foundation.util.motion
25
+ //= require foundation.util.nest
26
+ //= require foundation.util.timerAndImageLoader
27
+ //= require foundation.util.touch
28
+ //= require foundation.util.triggers
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Magellan module.
3
+ * @module foundation.magellan
4
+ */
5
+ !function(Foundation, $) {
6
+ 'use strict';
7
+
8
+ /**
9
+ * Creates a new instance of Magellan.
10
+ * @class
11
+ * @fires Magellan#init
12
+ * @param {Object} element - jQuery object to add the trigger to.
13
+ * @param {Object} options - Overrides to the default plugin settings.
14
+ */
15
+ function Magellan(element, options) {
16
+ this.$element = element;
17
+ this.options = $.extend({}, Magellan.defaults, this.$element.data(), options);
18
+
19
+ this._init();
20
+
21
+ Foundation.registerPlugin(this, 'Magellan');
22
+ }
23
+
24
+ /**
25
+ * Default settings for plugin
26
+ */
27
+ Magellan.defaults = {
28
+ /**
29
+ * Amount of time, in ms, the animated scrolling should take between locations.
30
+ * @option
31
+ * @example 500
32
+ */
33
+ animationDuration: 500,
34
+ /**
35
+ * Animation style to use when scrolling between locations.
36
+ * @option
37
+ * @example 'ease-in-out'
38
+ */
39
+ animationEasing: 'linear',
40
+ /**
41
+ * Number of pixels to use as a marker for location changes.
42
+ * @option
43
+ * @example 50
44
+ */
45
+ threshold: 50,
46
+ /**
47
+ * Class applied to the active locations link on the magellan container.
48
+ * @option
49
+ * @example 'active'
50
+ */
51
+ activeClass: 'active',
52
+ /**
53
+ * Allows the script to manipulate the url of the current page, and if supported, alter the history.
54
+ * @option
55
+ * @example true
56
+ */
57
+ deepLinking: false,
58
+ /**
59
+ * Number of pixels to offset the scroll of the page on item click if using a sticky nav bar.
60
+ * @option
61
+ * @example 25
62
+ */
63
+ barOffset: 0
64
+ };
65
+
66
+ /**
67
+ * Initializes the Magellan plugin and calls functions to get equalizer functioning on load.
68
+ * @private
69
+ */
70
+ Magellan.prototype._init = function() {
71
+ var id = this.$element[0].id || Foundation.GetYoDigits(6, 'magellan'),
72
+ _this = this;
73
+ this.$targets = $('[data-magellan-target]');
74
+ this.$links = this.$element.find('a');
75
+ this.$element.attr({
76
+ 'data-resize': id,
77
+ 'data-scroll': id,
78
+ 'id': id
79
+ });
80
+ this.$active = $();
81
+ this.scrollPos = parseInt(window.pageYOffset, 10);
82
+
83
+ this._events();
84
+ };
85
+ /**
86
+ * Calculates an array of pixel values that are the demarcation lines between locations on the page.
87
+ * Can be invoked if new elements are added or the size of a location changes.
88
+ * @function
89
+ */
90
+ Magellan.prototype.calcPoints = function(){
91
+ var _this = this,
92
+ body = document.body,
93
+ html = document.documentElement;
94
+
95
+ this.points = [];
96
+ this.winHeight = Math.round(Math.max(window.innerHeight, html.clientHeight));
97
+ this.docHeight = Math.round(Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight));
98
+
99
+ this.$targets.each(function(){
100
+ var $tar = $(this),
101
+ pt = Math.round($tar.offset().top - _this.options.threshold);
102
+ $tar.targetPoint = pt;
103
+ _this.points.push(pt);
104
+ });
105
+ };
106
+ /**
107
+ * Initializes events for Magellan.
108
+ * @private
109
+ */
110
+ Magellan.prototype._events = function() {
111
+ var _this = this,
112
+ $body = $('html, body'),
113
+ opts = {
114
+ duration: _this.options.animationDuration,
115
+ easing: _this.options.animationEasing
116
+ };
117
+
118
+ $(window).one('load', function(){
119
+ _this.calcPoints();
120
+ _this._updateActive();
121
+ });
122
+
123
+ this.$element.on({
124
+ 'resizeme.zf.trigger': this.reflow.bind(this),
125
+ 'scrollme.zf.trigger': this._updateActive.bind(this)
126
+ }).on('click.zf.magellan', 'a[href^="#"]', function(e) {
127
+ e.preventDefault();
128
+ var arrival = this.getAttribute('href'),
129
+ scrollPos = $(arrival).offset().top - _this.options.threshold / 2 - _this.options.barOffset;
130
+
131
+ // requestAnimationFrame is disabled for this plugin currently
132
+ // Foundation.Move(_this.options.animationDuration, $body, function(){
133
+ $body.stop(true).animate({
134
+ scrollTop: scrollPos
135
+ }, opts);
136
+ });
137
+ // });
138
+ };
139
+ /**
140
+ * Calls necessary functions to update Magellan upon DOM change
141
+ * @function
142
+ */
143
+ Magellan.prototype.reflow = function(){
144
+ this.calcPoints();
145
+ this._updateActive();
146
+ };
147
+ /**
148
+ * Updates the visibility of an active location link, and updates the url hash for the page, if deepLinking enabled.
149
+ * @private
150
+ * @function
151
+ * @fires Magellan#update
152
+ */
153
+ Magellan.prototype._updateActive = function(/*evt, elem, scrollPos*/){
154
+ var winPos = /*scrollPos ||*/ parseInt(window.pageYOffset, 10),
155
+ curIdx;
156
+
157
+ if(winPos + this.winHeight === this.docHeight){ curIdx = this.points.length - 1; }
158
+ else if(winPos < this.points[0]){ curIdx = 0; }
159
+ else{
160
+ var isDown = this.scrollPos < winPos,
161
+ _this = this,
162
+ curVisible = this.points.filter(function(p, i){
163
+ return isDown ? p <= winPos : p - _this.options.threshold <= winPos;//&& winPos >= _this.points[i -1] - _this.options.threshold;
164
+ });
165
+ curIdx = curVisible.length ? curVisible.length - 1 : 0;
166
+ }
167
+
168
+ this.$active.removeClass(this.options.activeClass);
169
+ this.$active = this.$links.eq(curIdx).addClass(this.options.activeClass);
170
+
171
+ if(this.options.deepLinking){
172
+ var hash = this.$active[0].getAttribute('href');
173
+ if(window.history.pushState){
174
+ window.history.pushState(null, null, hash);
175
+ }else{
176
+ window.location.hash = hash;
177
+ }
178
+ }
179
+
180
+ this.scrollPos = winPos;
181
+ /**
182
+ * Fires when magellan is finished updating to the new active element.
183
+ * @event Magellan#update
184
+ */
185
+ this.$element.trigger('update.zf.magellan', [this.$active]);
186
+ };
187
+ /**
188
+ * Destroys an instance of Magellan and resets the url of the window.
189
+ * @function
190
+ */
191
+ Magellan.prototype.destroy = function(){
192
+ this.$element.off('.zf.trigger .zf.magellan')
193
+ .find('.' + this.options.activeClass).removeClass(this.options.activeClass);
194
+
195
+ if(this.options.deepLinking){
196
+ var hash = this.$active[0].getAttribute('href');
197
+ window.location.hash.replace(hash, '');
198
+ }
199
+
200
+ Foundation.unregisterPlugin(this);
201
+ };
202
+ Foundation.plugin(Magellan, 'Magellan');
203
+
204
+ // Exports for AMD/Browserify
205
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
206
+ module.exports = Magellan;
207
+ if (typeof define === 'function')
208
+ define(['foundation'], function() {
209
+ return Magellan;
210
+ });
211
+
212
+ }(Foundation, jQuery);
@@ -0,0 +1,371 @@
1
+ /**
2
+ * OffCanvas module.
3
+ * @module foundation.offcanvas
4
+ * @requires foundation.util.triggers
5
+ * @requires foundation.util.motion
6
+ */
7
+ !function($, Foundation) {
8
+
9
+ 'use strict';
10
+
11
+ /**
12
+ * Creates a new instance of an off-canvas wrapper.
13
+ * @class
14
+ * @fires OffCanvas#init
15
+ * @param {Object} element - jQuery object to initialize.
16
+ * @param {Object} options - Overrides to the default plugin settings.
17
+ */
18
+ function OffCanvas(element, options) {
19
+ this.$element = element;
20
+ this.options = $.extend({}, OffCanvas.defaults, this.$element.data(), options);
21
+ this.$lastTrigger = $();
22
+
23
+ this._init();
24
+ this._events();
25
+
26
+ Foundation.registerPlugin(this, 'OffCanvas');
27
+ }
28
+
29
+ OffCanvas.defaults = {
30
+ /**
31
+ * Allow the user to click outside of the menu to close it.
32
+ * @option
33
+ * @example true
34
+ */
35
+ closeOnClick: true,
36
+ /**
37
+ * Amount of time in ms the open and close transition requires. If none selected, pulls from body style.
38
+ * @option
39
+ * @example 500
40
+ */
41
+ transitionTime: 0,
42
+ /**
43
+ * Direction the offcanvas opens from. Determines class applied to body.
44
+ * @option
45
+ * @example left
46
+ */
47
+ position: 'left',
48
+ /**
49
+ * Force the page to scroll to top on open.
50
+ */
51
+ forceTop: true,
52
+ /**
53
+ * Allow the offcanvas to be sticky while open. Does nothing if Sass option `$maincontent-prevent-scroll === true`.
54
+ * Performance in Safari OSX/iOS is not great.
55
+ */
56
+ // isSticky: false,
57
+ /**
58
+ * Allow the offcanvas to remain open for certain breakpoints. Can be used with `isSticky`.
59
+ * @option
60
+ * @example false
61
+ */
62
+ isRevealed: false,
63
+ /**
64
+ * Breakpoint at which to reveal. JS will use a RegExp to target standard classes, if changing classnames, pass your class @`revealClass`.
65
+ * @option
66
+ * @example reveal-for-large
67
+ */
68
+ revealOn: null,
69
+ /**
70
+ * Force focus to the offcanvas on open. If true, will focus the opening trigger on close.
71
+ * @option
72
+ * @example true
73
+ */
74
+ autoFocus: true,
75
+ /**
76
+ * Class used to force an offcanvas to remain open. Foundation defaults for this are `reveal-for-large` & `reveal-for-medium`.
77
+ * @option
78
+ * TODO improve the regex testing for this.
79
+ * @example reveal-for-large
80
+ */
81
+ revealClass: 'reveal-for-',
82
+ /**
83
+ * Triggers optional focus trapping when opening an offcanvas. Sets tabindex of [data-off-canvas-content] to -1 for accessibility purposes.
84
+ * @option
85
+ * @example true
86
+ */
87
+ trapFocus: false
88
+ };
89
+
90
+ /**
91
+ * Initializes the off-canvas wrapper by adding the exit overlay (if needed).
92
+ * @function
93
+ * @private
94
+ */
95
+ OffCanvas.prototype._init = function() {
96
+ var id = this.$element.attr('id');
97
+
98
+ this.$element.attr('aria-hidden', 'true');
99
+
100
+ // Find triggers that affect this element and add aria-expanded to them
101
+ $(document)
102
+ .find('[data-open="'+id+'"], [data-close="'+id+'"], [data-toggle="'+id+'"]')
103
+ .attr('aria-expanded', 'false')
104
+ .attr('aria-controls', id);
105
+
106
+ // Add a close trigger over the body if necessary
107
+ if (this.options.closeOnClick){
108
+ if($('.js-off-canvas-exit').length){
109
+ this.$exiter = $('.js-off-canvas-exit');
110
+ }else{
111
+ var exiter = document.createElement('div');
112
+ exiter.setAttribute('class', 'js-off-canvas-exit');
113
+ $('[data-off-canvas-content]').append(exiter);
114
+
115
+ this.$exiter = $(exiter);
116
+ }
117
+ }
118
+
119
+ this.options.isRevealed = this.options.isRevealed || new RegExp(this.options.revealClass, 'g').test(this.$element[0].className);
120
+
121
+ if(this.options.isRevealed){
122
+ this.options.revealOn = this.options.revealOn || this.$element[0].className.match(/(reveal-for-medium|reveal-for-large)/g)[0].split('-')[2];
123
+ this._setMQChecker();
124
+ }
125
+ if(!this.options.transitionTime){
126
+ this.options.transitionTime = parseFloat(window.getComputedStyle($('[data-off-canvas-wrapper]')[0]).transitionDuration) * 1000;
127
+ }
128
+ };
129
+
130
+ /**
131
+ * Adds event handlers to the off-canvas wrapper and the exit overlay.
132
+ * @function
133
+ * @private
134
+ */
135
+ OffCanvas.prototype._events = function() {
136
+ this.$element.off('.zf.trigger .zf.offcanvas').on({
137
+ 'open.zf.trigger': this.open.bind(this),
138
+ 'close.zf.trigger': this.close.bind(this),
139
+ 'toggle.zf.trigger': this.toggle.bind(this),
140
+ 'keydown.zf.offcanvas': this._handleKeyboard.bind(this)
141
+ });
142
+
143
+ if (this.$exiter.length) {
144
+ var _this = this;
145
+ this.$exiter.on({'click.zf.offcanvas': this.close.bind(this)});
146
+ }
147
+ };
148
+ /**
149
+ * Applies event listener for elements that will reveal at certain breakpoints.
150
+ * @private
151
+ */
152
+ OffCanvas.prototype._setMQChecker = function(){
153
+ var _this = this;
154
+
155
+ $(window).on('changed.zf.mediaquery', function(){
156
+ if(Foundation.MediaQuery.atLeast(_this.options.revealOn)){
157
+ _this.reveal(true);
158
+ }else{
159
+ _this.reveal(false);
160
+ }
161
+ }).one('load.zf.offcanvas', function(){
162
+ if(Foundation.MediaQuery.atLeast(_this.options.revealOn)){
163
+ _this.reveal(true);
164
+ }
165
+ });
166
+ };
167
+ /**
168
+ * Handles the revealing/hiding the off-canvas at breakpoints, not the same as open.
169
+ * @param {Boolean} isRevealed - true if element should be revealed.
170
+ * @function
171
+ */
172
+ OffCanvas.prototype.reveal = function(isRevealed){
173
+ var $closer = this.$element.find('[data-close]');
174
+ if(isRevealed){
175
+ this.close();
176
+ this.isRevealed = true;
177
+ // if(!this.options.forceTop){
178
+ // var scrollPos = parseInt(window.pageYOffset);
179
+ // this.$element[0].style.transform = 'translate(0,' + scrollPos + 'px)';
180
+ // }
181
+ // if(this.options.isSticky){ this._stick(); }
182
+ this.$element.off('open.zf.trigger toggle.zf.trigger');
183
+ if($closer.length){ $closer.hide(); }
184
+ }else{
185
+ this.isRevealed = false;
186
+ // if(this.options.isSticky || !this.options.forceTop){
187
+ // this.$element[0].style.transform = '';
188
+ // $(window).off('scroll.zf.offcanvas');
189
+ // }
190
+ this.$element.on({
191
+ 'open.zf.trigger': this.open.bind(this),
192
+ 'toggle.zf.trigger': this.toggle.bind(this)
193
+ });
194
+ if($closer.length){
195
+ $closer.show();
196
+ }
197
+ }
198
+ };
199
+
200
+ /**
201
+ * Opens the off-canvas menu.
202
+ * @function
203
+ * @param {Object} event - Event object passed from listener.
204
+ * @param {jQuery} trigger - element that triggered the off-canvas to open.
205
+ * @fires OffCanvas#opened
206
+ */
207
+ OffCanvas.prototype.open = function(event, trigger) {
208
+ if (this.$element.hasClass('is-open') || this.isRevealed){ return; }
209
+ var _this = this,
210
+ $body = $(document.body);
211
+ $('body').scrollTop(0);
212
+ // window.pageYOffset = 0;
213
+
214
+ // if(!this.options.forceTop){
215
+ // var scrollPos = parseInt(window.pageYOffset);
216
+ // this.$element[0].style.transform = 'translate(0,' + scrollPos + 'px)';
217
+ // if(this.$exiter.length){
218
+ // this.$exiter[0].style.transform = 'translate(0,' + scrollPos + 'px)';
219
+ // }
220
+ // }
221
+ /**
222
+ * Fires when the off-canvas menu opens.
223
+ * @event OffCanvas#opened
224
+ */
225
+ Foundation.Move(this.options.transitionTime, this.$element, function(){
226
+ $('[data-off-canvas-wrapper]').addClass('is-off-canvas-open is-open-'+ _this.options.position);
227
+
228
+ _this.$element
229
+ .addClass('is-open')
230
+
231
+ // if(_this.options.isSticky){
232
+ // _this._stick();
233
+ // }
234
+ });
235
+ this.$element.attr('aria-hidden', 'false')
236
+ .trigger('opened.zf.offcanvas');
237
+
238
+
239
+ if(trigger){
240
+ this.$lastTrigger = trigger.attr('aria-expanded', 'true');
241
+ }
242
+ if(this.options.autoFocus){
243
+ this.$element.one('finished.zf.animate', function(){
244
+ _this.$element.find('a, button').eq(0).focus();
245
+ });
246
+ }
247
+ if(this.options.trapFocus){
248
+ $('[data-off-canvas-content]').attr('tabindex', '-1');
249
+ this._trapFocus();
250
+ }
251
+ };
252
+ /**
253
+ * Traps focus within the offcanvas on open.
254
+ * @private
255
+ */
256
+ OffCanvas.prototype._trapFocus = function(){
257
+ var focusable = Foundation.Keyboard.findFocusable(this.$element),
258
+ first = focusable.eq(0),
259
+ last = focusable.eq(-1);
260
+
261
+ focusable.off('.zf.offcanvas').on('keydown.zf.offcanvas', function(e){
262
+ if(e.which === 9 || e.keycode === 9){
263
+ if(e.target === last[0] && !e.shiftKey){
264
+ e.preventDefault();
265
+ first.focus();
266
+ }
267
+ if(e.target === first[0] && e.shiftKey){
268
+ e.preventDefault();
269
+ last.focus();
270
+ }
271
+ }
272
+ });
273
+ };
274
+ /**
275
+ * Allows the offcanvas to appear sticky utilizing translate properties.
276
+ * @private
277
+ */
278
+ // OffCanvas.prototype._stick = function(){
279
+ // var elStyle = this.$element[0].style;
280
+ //
281
+ // if(this.options.closeOnClick){
282
+ // var exitStyle = this.$exiter[0].style;
283
+ // }
284
+ //
285
+ // $(window).on('scroll.zf.offcanvas', function(e){
286
+ // console.log(e);
287
+ // var pageY = window.pageYOffset;
288
+ // elStyle.transform = 'translate(0,' + pageY + 'px)';
289
+ // if(exitStyle !== undefined){ exitStyle.transform = 'translate(0,' + pageY + 'px)'; }
290
+ // });
291
+ // // this.$element.trigger('stuck.zf.offcanvas');
292
+ // };
293
+ /**
294
+ * Closes the off-canvas menu.
295
+ * @function
296
+ * @param {Function} cb - optional cb to fire after closure.
297
+ * @fires OffCanvas#closed
298
+ */
299
+ OffCanvas.prototype.close = function(cb) {
300
+ if(!this.$element.hasClass('is-open') || this.isRevealed){ return; }
301
+
302
+ var _this = this;
303
+
304
+ // Foundation.Move(this.options.transitionTime, this.$element, function(){
305
+ $('[data-off-canvas-wrapper]').removeClass('is-off-canvas-open is-open-' + _this.options.position);
306
+ _this.$element.removeClass('is-open');
307
+ // Foundation._reflow();
308
+ // });
309
+ this.$element.attr('aria-hidden', 'true')
310
+ /**
311
+ * Fires when the off-canvas menu opens.
312
+ * @event OffCanvas#closed
313
+ */
314
+ .trigger('closed.zf.offcanvas');
315
+ // if(_this.options.isSticky || !_this.options.forceTop){
316
+ // setTimeout(function(){
317
+ // _this.$element[0].style.transform = '';
318
+ // $(window).off('scroll.zf.offcanvas');
319
+ // }, this.options.transitionTime);
320
+ // }
321
+
322
+ this.$lastTrigger.attr('aria-expanded', 'false');
323
+ if(this.options.trapFocus){
324
+ $('[data-off-canvas-content]').removeAttr('tabindex');
325
+ }
326
+
327
+ };
328
+
329
+ /**
330
+ * Toggles the off-canvas menu open or closed.
331
+ * @function
332
+ * @param {Object} event - Event object passed from listener.
333
+ * @param {jQuery} trigger - element that triggered the off-canvas to open.
334
+ */
335
+ OffCanvas.prototype.toggle = function(event, trigger) {
336
+ if (this.$element.hasClass('is-open')) {
337
+ this.close(event, trigger);
338
+ }
339
+ else {
340
+ this.open(event, trigger);
341
+ }
342
+ };
343
+
344
+ /**
345
+ * Handles keyboard input when detected. When the escape key is pressed, the off-canvas menu closes, and focus is restored to the element that opened the menu.
346
+ * @function
347
+ * @private
348
+ */
349
+ OffCanvas.prototype._handleKeyboard = function(event) {
350
+ if (event.which !== 27) return;
351
+
352
+ event.stopPropagation();
353
+ event.preventDefault();
354
+ this.close();
355
+ this.$lastTrigger.focus();
356
+ };
357
+ /**
358
+ * Destroys the offcanvas plugin.
359
+ * @function
360
+ */
361
+ OffCanvas.prototype.destroy = function(){
362
+ this.close();
363
+ this.$element.off('.zf.trigger .zf.offcanvas');
364
+ this.$exiter.off('.zf.offcanvas');
365
+
366
+ Foundation.unregisterPlugin(this);
367
+ };
368
+
369
+ Foundation.plugin(OffCanvas, 'OffCanvas');
370
+
371
+ }(jQuery, Foundation);