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,147 @@
1
+ /**
2
+ * Toggler module.
3
+ * @module foundation.toggler
4
+ * @requires foundation.util.motion
5
+ */
6
+
7
+ !function(Foundation, $) {
8
+ 'use strict';
9
+
10
+ /**
11
+ * Creates a new instance of Toggler.
12
+ * @class
13
+ * @fires Toggler#init
14
+ * @param {Object} element - jQuery object to add the trigger to.
15
+ * @param {Object} options - Overrides to the default plugin settings.
16
+ */
17
+ function Toggler(element, options) {
18
+ this.$element = element;
19
+ this.options = $.extend({}, Toggler.defaults, element.data(), options);
20
+ this.className = '';
21
+
22
+ this._init();
23
+ this._events();
24
+
25
+ Foundation.registerPlugin(this, 'Toggler');
26
+ }
27
+
28
+ Toggler.defaults = {
29
+ /**
30
+ * Tells the plugin if the element should animated when toggled.
31
+ * @option
32
+ * @example false
33
+ */
34
+ animate: false
35
+ };
36
+
37
+ /**
38
+ * Initializes the Toggler plugin by parsing the toggle class from data-toggler, or animation classes from data-animate.
39
+ * @function
40
+ * @private
41
+ */
42
+ Toggler.prototype._init = function() {
43
+ var input;
44
+ // Parse animation classes if they were set
45
+ if (this.options.animate) {
46
+ input = this.options.animate.split(' ');
47
+
48
+ this.animationIn = input[0];
49
+ this.animationOut = input[1] || null;
50
+ }
51
+ // Otherwise, parse toggle class
52
+ else {
53
+ input = this.$element.data('toggler');
54
+ // Allow for a . at the beginning of the string
55
+ this.className = input[0] === '.' ? input.slice(1) : input;
56
+ }
57
+
58
+ // Add ARIA attributes to triggers
59
+ var id = this.$element[0].id;
60
+ $('[data-open="'+id+'"], [data-close="'+id+'"], [data-toggle="'+id+'"]')
61
+ .attr('aria-controls', id);
62
+ // If the target is hidden, add aria-hidden
63
+ this.$element.attr('aria-expanded', this.$element.is(':hidden') ? false : true);
64
+ };
65
+
66
+ /**
67
+ * Initializes events for the toggle trigger.
68
+ * @function
69
+ * @private
70
+ */
71
+ Toggler.prototype._events = function() {
72
+ this.$element.off('toggle.zf.trigger').on('toggle.zf.trigger', this.toggle.bind(this));
73
+ };
74
+
75
+ /**
76
+ * Toggles the target class on the target element. An event is fired from the original trigger depending on if the resultant state was "on" or "off".
77
+ * @function
78
+ * @fires Toggler#on
79
+ * @fires Toggler#off
80
+ */
81
+ Toggler.prototype.toggle = function() {
82
+ this[ this.options.animate ? '_toggleAnimate' : '_toggleClass']();
83
+ };
84
+
85
+ Toggler.prototype._toggleClass = function() {
86
+ this.$element.toggleClass(this.className);
87
+
88
+ var isOn = this.$element.hasClass(this.className);
89
+ if (isOn) {
90
+ /**
91
+ * Fires if the target element has the class after a toggle.
92
+ * @event Toggler#on
93
+ */
94
+ this.$element.trigger('on.zf.toggler');
95
+ }
96
+ else {
97
+ /**
98
+ * Fires if the target element does not have the class after a toggle.
99
+ * @event Toggler#off
100
+ */
101
+ this.$element.trigger('off.zf.toggler');
102
+ }
103
+
104
+ this._updateARIA(isOn);
105
+ };
106
+
107
+ Toggler.prototype._toggleAnimate = function() {
108
+ var _this = this;
109
+
110
+ if (this.$element.is(':hidden')) {
111
+ Foundation.Motion.animateIn(this.$element, this.animationIn, function() {
112
+ this.trigger('on.zf.toggler');
113
+ _this._updateARIA(true);
114
+ });
115
+ }
116
+ else {
117
+ Foundation.Motion.animateOut(this.$element, this.animationOut, function() {
118
+ this.trigger('off.zf.toggler');
119
+ _this._updateARIA(false);
120
+ });
121
+ }
122
+ };
123
+
124
+ Toggler.prototype._updateARIA = function(isOn) {
125
+ this.$element.attr('aria-expanded', isOn ? true : false);
126
+ };
127
+
128
+ /**
129
+ * Destroys the instance of Toggler on the element.
130
+ * @function
131
+ */
132
+ Toggler.prototype.destroy= function() {
133
+ this.$element.off('.zf.toggler');
134
+ Foundation.unregisterPlugin(this);
135
+ };
136
+
137
+ Foundation.plugin(Toggler, 'Toggler');
138
+
139
+ // Exports for AMD/Browserify
140
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
141
+ module.exports = Toggler;
142
+ if (typeof define === 'function')
143
+ define(['foundation'], function() {
144
+ return Toggler;
145
+ });
146
+
147
+ }(Foundation, jQuery);
@@ -0,0 +1,429 @@
1
+ /**
2
+ * Tooltip module.
3
+ * @module foundation.tooltip
4
+ * @requires foundation.util.box
5
+ * @requires foundation.util.triggers
6
+ */
7
+ !function($, document, Foundation){
8
+ 'use strict';
9
+
10
+ /**
11
+ * Creates a new instance of a Tooltip.
12
+ * @class
13
+ * @fires Tooltip#init
14
+ * @param {jQuery} element - jQuery object to attach a tooltip to.
15
+ * @param {Object} options - object to extend the default configuration.
16
+ */
17
+ function Tooltip(element, options){
18
+ this.$element = element;
19
+ this.options = $.extend({}, Tooltip.defaults, this.$element.data(), options);
20
+
21
+ this.isActive = false;
22
+ this.isClick = false;
23
+ this._init();
24
+
25
+ Foundation.registerPlugin(this, 'Tooltip');
26
+ }
27
+
28
+ Tooltip.defaults = {
29
+ disableForTouch: false,
30
+ /**
31
+ * Time, in ms, before a tooltip should open on hover.
32
+ * @option
33
+ * @example 200
34
+ */
35
+ hoverDelay: 200,
36
+ /**
37
+ * Time, in ms, a tooltip should take to fade into view.
38
+ * @option
39
+ * @example 150
40
+ */
41
+ fadeInDuration: 150,
42
+ /**
43
+ * Time, in ms, a tooltip should take to fade out of view.
44
+ * @option
45
+ * @example 150
46
+ */
47
+ fadeOutDuration: 150,
48
+ /**
49
+ * Disables hover events from opening the tooltip if set to true
50
+ * @option
51
+ * @example false
52
+ */
53
+ disableHover: false,
54
+ /**
55
+ * Optional addtional classes to apply to the tooltip template on init.
56
+ * @option
57
+ * @example 'my-cool-tip-class'
58
+ */
59
+ templateClasses: '',
60
+ /**
61
+ * Non-optional class added to tooltip templates. Foundation default is 'tooltip'.
62
+ * @option
63
+ * @example 'tooltip'
64
+ */
65
+ tooltipClass: 'tooltip',
66
+ /**
67
+ * Class applied to the tooltip anchor element.
68
+ * @option
69
+ * @example 'has-tip'
70
+ */
71
+ triggerClass: 'has-tip',
72
+ /**
73
+ * Minimum breakpoint size at which to open the tooltip.
74
+ * @option
75
+ * @example 'small'
76
+ */
77
+ showOn: 'small',
78
+ /**
79
+ * Custom template to be used to generate markup for tooltip.
80
+ * @option
81
+ * @example '<div class="tooltip"></div>'
82
+ */
83
+ template: '',
84
+ /**
85
+ * Text displayed in the tooltip template on open.
86
+ * @option
87
+ * @example 'Some cool space fact here.'
88
+ */
89
+ tipText: '',
90
+ touchCloseText: 'Tap to close.',
91
+ /**
92
+ * Allows the tooltip to remain open if triggered with a click or touch event.
93
+ * @option
94
+ * @example true
95
+ */
96
+ clickOpen: true,
97
+ /**
98
+ * Additional positioning classes, set by the JS
99
+ * @option
100
+ * @example 'top'
101
+ */
102
+ positionClass: '',
103
+ /**
104
+ * Distance, in pixels, the template should push away from the anchor on the Y axis.
105
+ * @option
106
+ * @example 10
107
+ */
108
+ vOffset: 10,
109
+ /**
110
+ * Distance, in pixels, the template should push away from the anchor on the X axis, if aligned to a side.
111
+ * @option
112
+ * @example 12
113
+ */
114
+ hOffset: 12
115
+ };
116
+
117
+ /**
118
+ * Initializes the tooltip by setting the creating the tip element, adding it's text, setting private variables and setting attributes on the anchor.
119
+ * @private
120
+ */
121
+ Tooltip.prototype._init = function(){
122
+ var elemId = this.$element.attr('aria-describedby') || Foundation.GetYoDigits(6, 'tooltip');
123
+
124
+ this.options.positionClass = this._getPositionClass(this.$element);
125
+ this.options.tipText = this.options.tipText || this.$element.attr('title');
126
+ this.template = this.options.template ? $(this.options.template) : this._buildTemplate(elemId);
127
+
128
+ this.template.appendTo(document.body)
129
+ .text(this.options.tipText)
130
+ .hide();
131
+
132
+ this.$element.attr({
133
+ 'title': '',
134
+ 'aria-describedby': elemId,
135
+ 'data-yeti-box': elemId,
136
+ 'data-toggle': elemId,
137
+ 'data-resize': elemId
138
+ }).addClass(this.triggerClass);
139
+
140
+ //helper variables to track movement on collisions
141
+ this.usedPositions = [];
142
+ this.counter = 4;
143
+ this.classChanged = false;
144
+
145
+ this._events();
146
+ };
147
+
148
+ /**
149
+ * Grabs the current positioning class, if present, and returns the value or an empty string.
150
+ * @private
151
+ */
152
+ Tooltip.prototype._getPositionClass = function(element){
153
+ if(!element){ return ''; }
154
+ // var position = element.attr('class').match(/top|left|right/g);
155
+ var position = element[0].className.match(/(top|left|right)/g);
156
+ position = position ? position[0] : '';
157
+ return position;
158
+ };
159
+ /**
160
+ * builds the tooltip element, adds attributes, and returns the template.
161
+ * @private
162
+ */
163
+ Tooltip.prototype._buildTemplate = function(id){
164
+ var templateClasses = (this.options.tooltipClass + ' ' + this.options.positionClass).trim();
165
+ var $template = $('<div></div>').addClass(templateClasses).attr({
166
+ 'role': 'tooltip',
167
+ 'aria-hidden': true,
168
+ 'data-is-active': false,
169
+ 'data-is-focus': false,
170
+ 'id': id
171
+ });
172
+ return $template;
173
+ };
174
+
175
+ /**
176
+ * Function that gets called if a collision event is detected.
177
+ * @param {String} position - positioning class to try
178
+ * @private
179
+ */
180
+ Tooltip.prototype._reposition = function(position){
181
+ this.usedPositions.push(position ? position : 'bottom');
182
+
183
+ //default, try switching to opposite side
184
+ if(!position && (this.usedPositions.indexOf('top') < 0)){
185
+ this.template.addClass('top');
186
+ }else if(position === 'top' && (this.usedPositions.indexOf('bottom') < 0)){
187
+ this.template.removeClass(position);
188
+ }else if(position === 'left' && (this.usedPositions.indexOf('right') < 0)){
189
+ this.template.removeClass(position)
190
+ .addClass('right');
191
+ }else if(position === 'right' && (this.usedPositions.indexOf('left') < 0)){
192
+ this.template.removeClass(position)
193
+ .addClass('left');
194
+ }
195
+
196
+ //if default change didn't work, try bottom or left first
197
+ else if(!position && (this.usedPositions.indexOf('top') > -1) && (this.usedPositions.indexOf('left') < 0)){
198
+ this.template.addClass('left');
199
+ }else if(position === 'top' && (this.usedPositions.indexOf('bottom') > -1) && (this.usedPositions.indexOf('left') < 0)){
200
+ this.template.removeClass(position)
201
+ .addClass('left');
202
+ }else if(position === 'left' && (this.usedPositions.indexOf('right') > -1) && (this.usedPositions.indexOf('bottom') < 0)){
203
+ this.template.removeClass(position);
204
+ }else if(position === 'right' && (this.usedPositions.indexOf('left') > -1) && (this.usedPositions.indexOf('bottom') < 0)){
205
+ this.template.removeClass(position);
206
+ }
207
+ //if nothing cleared, set to bottom
208
+ else{
209
+ this.template.removeClass(position);
210
+ }
211
+ this.classChanged = true;
212
+ this.counter--;
213
+
214
+ };
215
+
216
+ /**
217
+ * sets the position class of an element and recursively calls itself until there are no more possible positions to attempt, or the tooltip element is no longer colliding.
218
+ * if the tooltip is larger than the screen width, default to full width - any user selected margin
219
+ * @private
220
+ */
221
+ Tooltip.prototype._setPosition = function(){
222
+ var position = this._getPositionClass(this.template),
223
+ $tipDims = Foundation.Box.GetDimensions(this.template),
224
+ $anchorDims = Foundation.Box.GetDimensions(this.$element),
225
+ direction = (position === 'left' ? 'left' : ((position === 'right') ? 'left' : 'top')),
226
+ param = (direction === 'top') ? 'height' : 'width',
227
+ offset = (param === 'height') ? this.options.vOffset : this.options.hOffset,
228
+ _this = this;
229
+
230
+ if(($tipDims.width >= $tipDims.windowDims.width) || (!this.counter && !Foundation.Box.ImNotTouchingYou(this.template))){
231
+ this.template.offset(Foundation.Box.GetOffsets(this.template, this.$element, 'center bottom', this.options.vOffset, this.options.hOffset, true)).css({
232
+ // this.$element.offset(Foundation.GetOffsets(this.template, this.$element, 'center bottom', this.options.vOffset, this.options.hOffset, true)).css({
233
+ 'width': $anchorDims.windowDims.width - (this.options.hOffset * 2),
234
+ 'height': 'auto'
235
+ });
236
+ return false;
237
+ }
238
+
239
+ this.template.offset(Foundation.Box.GetOffsets(this.template, this.$element,'center ' + (position || 'bottom'), this.options.vOffset, this.options.hOffset));
240
+
241
+ while(!Foundation.Box.ImNotTouchingYou(this.template) && this.counter){
242
+ this._reposition(position);
243
+ this._setPosition();
244
+ }
245
+ };
246
+
247
+ /**
248
+ * reveals the tooltip, and fires an event to close any other open tooltips on the page
249
+ * @fires Closeme#tooltip
250
+ * @fires Tooltip#show
251
+ * @function
252
+ */
253
+ Tooltip.prototype.show = function(){
254
+ if(this.options.showOn !== 'all' && !Foundation.MediaQuery.atLeast(this.options.showOn)){
255
+ // console.error('The screen is too small to display this tooltip');
256
+ return false;
257
+ }
258
+
259
+ var _this = this;
260
+ this.template.css('visibility', 'hidden').show();
261
+ this._setPosition();
262
+
263
+ /**
264
+ * Fires to close all other open tooltips on the page
265
+ * @event Closeme#tooltip
266
+ */
267
+ this.$element.trigger('closeme.zf.tooltip', this.template.attr('id'));
268
+
269
+
270
+ this.template.attr({
271
+ 'data-is-active': true,
272
+ 'aria-hidden': false
273
+ });
274
+ _this.isActive = true;
275
+ // console.log(this.template);
276
+ this.template.stop().hide().css('visibility', '').fadeIn(this.options.fadeInDuration, function(){
277
+ //maybe do stuff?
278
+ });
279
+ /**
280
+ * Fires when the tooltip is shown
281
+ * @event Tooltip#show
282
+ */
283
+ this.$element.trigger('show.zf.tooltip');
284
+ };
285
+
286
+ /**
287
+ * Hides the current tooltip, and resets the positioning class if it was changed due to collision
288
+ * @fires Tooltip#hide
289
+ * @function
290
+ */
291
+ Tooltip.prototype.hide = function(){
292
+ // console.log('hiding', this.$element.data('yeti-box'));
293
+ var _this = this;
294
+ this.template.stop().attr({
295
+ 'aria-hidden': true,
296
+ 'data-is-active': false
297
+ }).fadeOut(this.options.fadeOutDuration, function(){
298
+ _this.isActive = false;
299
+ _this.isClick = false;
300
+ if(_this.classChanged){
301
+ _this.template
302
+ .removeClass(_this._getPositionClass(_this.template))
303
+ .addClass(_this.options.positionClass);
304
+
305
+ _this.usedPositions = [];
306
+ _this.counter = 4;
307
+ _this.classChanged = false;
308
+ }
309
+ });
310
+ /**
311
+ * fires when the tooltip is hidden
312
+ * @event Tooltip#hide
313
+ */
314
+ this.$element.trigger('hide.zf.tooltip');
315
+ };
316
+
317
+ /**
318
+ * adds event listeners for the tooltip and its anchor
319
+ * TODO combine some of the listeners like focus and mouseenter, etc.
320
+ * @private
321
+ */
322
+ Tooltip.prototype._events = function(){
323
+ var _this = this;
324
+ var $template = this.template;
325
+ var isFocus = false;
326
+
327
+ if(!this.options.disableHover){
328
+
329
+ this.$element
330
+ .on('mouseenter.zf.tooltip', function(e){
331
+ if(!_this.isActive){
332
+ _this.timeout = setTimeout(function(){
333
+ _this.show();
334
+ }, _this.options.hoverDelay);
335
+ }
336
+ })
337
+ .on('mouseleave.zf.tooltip', function(e){
338
+ clearTimeout(_this.timeout);
339
+ if(!isFocus || (!_this.isClick && _this.options.clickOpen)){
340
+ _this.hide();
341
+ }
342
+ });
343
+ }
344
+ if(this.options.clickOpen){
345
+ this.$element.on('mousedown.zf.tooltip', function(e){
346
+ e.stopImmediatePropagation();
347
+ if(_this.isClick){
348
+ _this.hide();
349
+ // _this.isClick = false;
350
+ }else{
351
+ _this.isClick = true;
352
+ if((_this.options.disableHover || !_this.$element.attr('tabindex')) && !_this.isActive){
353
+ _this.show();
354
+ }
355
+ }
356
+ });
357
+ }
358
+
359
+ if(!this.options.disableForTouch){
360
+ this.$element
361
+ .on('tap.zf.tooltip touchend.zf.tooltip', function(e){
362
+ _this.isActive ? _this.hide() : _this.show();
363
+ });
364
+ }
365
+
366
+ this.$element.on({
367
+ // 'toggle.zf.trigger': this.toggle.bind(this),
368
+ // 'close.zf.trigger': this.hide.bind(this)
369
+ 'close.zf.trigger': this.hide.bind(this)
370
+ });
371
+
372
+ this.$element
373
+ .on('focus.zf.tooltip', function(e){
374
+ isFocus = true;
375
+ // console.log(_this.isClick);
376
+ if(_this.isClick){
377
+ return false;
378
+ }else{
379
+ // $(window)
380
+ _this.show();
381
+ }
382
+ })
383
+
384
+ .on('focusout.zf.tooltip', function(e){
385
+ isFocus = false;
386
+ _this.isClick = false;
387
+ _this.hide();
388
+ })
389
+
390
+ .on('resizeme.zf.trigger', function(){
391
+ if(_this.isActive){
392
+ _this._setPosition();
393
+ }
394
+ });
395
+ };
396
+ /**
397
+ * adds a toggle method, in addition to the static show() & hide() functions
398
+ * @function
399
+ */
400
+ Tooltip.prototype.toggle = function(){
401
+ if(this.isActive){
402
+ this.hide();
403
+ }else{
404
+ this.show();
405
+ }
406
+ };
407
+ /**
408
+ * Destroys an instance of tooltip, removes template element from the view.
409
+ * @function
410
+ */
411
+ Tooltip.prototype.destroy = function(){
412
+ this.$element.attr('title', this.template.text())
413
+ .off('.zf.trigger .zf.tootip')
414
+ // .removeClass('has-tip')
415
+ .removeAttr('aria-describedby')
416
+ .removeAttr('data-yeti-box')
417
+ .removeAttr('data-toggle')
418
+ .removeAttr('data-resize');
419
+
420
+ this.template.remove();
421
+
422
+ Foundation.unregisterPlugin(this);
423
+ };
424
+ /**
425
+ * TODO utilize resize event trigger
426
+ */
427
+
428
+ Foundation.plugin(Tooltip, 'Tooltip');
429
+ }(jQuery, window.document, window.Foundation);