foundation-rails 5.0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/controllers/foundation/rails/styleguide_controller.rb +10 -0
  8. data/app/views/foundation/rails/styleguide/show.html.erb +134 -0
  9. data/config/routes.rb +3 -0
  10. data/foundation-rails.gemspec +25 -0
  11. data/lib/foundation-rails.rb +1 -0
  12. data/lib/foundation/rails.rb +3 -0
  13. data/lib/foundation/rails/engine.rb +7 -0
  14. data/lib/foundation/rails/generators/install_generator.rb +56 -0
  15. data/lib/foundation/rails/templates/application.html.erb +19 -0
  16. data/lib/foundation/rails/templates/application.html.haml +18 -0
  17. data/lib/foundation/rails/templates/application.html.slim +17 -0
  18. data/lib/foundation/rails/version.rb +5 -0
  19. data/test/dummy/.gitignore +16 -0
  20. data/test/dummy/Gemfile +47 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/images/.keep +0 -0
  24. data/test/dummy/app/assets/javascripts/application.js +8 -0
  25. data/test/dummy/app/assets/stylesheets/application.css +4 -0
  26. data/test/dummy/app/assets/stylesheets/foundation_and_overrides.scss +4 -0
  27. data/test/dummy/app/controllers/application_controller.rb +5 -0
  28. data/test/dummy/app/controllers/concerns/.keep +0 -0
  29. data/test/dummy/app/controllers/styleguide_controller.rb +4 -0
  30. data/test/dummy/app/helpers/application_helper.rb +2 -0
  31. data/test/dummy/app/helpers/styleguide_helper.rb +2 -0
  32. data/test/dummy/app/mailers/.keep +0 -0
  33. data/test/dummy/app/models/.keep +0 -0
  34. data/test/dummy/app/models/concerns/.keep +0 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +19 -0
  36. data/test/dummy/app/views/styleguide/show.html.erb +109 -0
  37. data/test/dummy/bin/bundle +3 -0
  38. data/test/dummy/bin/rails +4 -0
  39. data/test/dummy/bin/rake +4 -0
  40. data/test/dummy/config.ru +4 -0
  41. data/test/dummy/config/application.rb +23 -0
  42. data/test/dummy/config/boot.rb +4 -0
  43. data/test/dummy/config/database.yml +25 -0
  44. data/test/dummy/config/environment.rb +5 -0
  45. data/test/dummy/config/environments/development.rb +29 -0
  46. data/test/dummy/config/environments/production.rb +80 -0
  47. data/test/dummy/config/environments/test.rb +36 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/mime_types.rb +5 -0
  52. data/test/dummy/config/initializers/secret_token.rb +12 -0
  53. data/test/dummy/config/initializers/session_store.rb +3 -0
  54. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/test/dummy/config/locales/en.yml +23 -0
  56. data/test/dummy/config/routes.rb +3 -0
  57. data/test/dummy/db/seeds.rb +7 -0
  58. data/test/dummy/lib/assets/.keep +0 -0
  59. data/test/dummy/lib/tasks/.keep +0 -0
  60. data/test/dummy/log/.keep +0 -0
  61. data/test/dummy/public/404.html +58 -0
  62. data/test/dummy/public/422.html +58 -0
  63. data/test/dummy/public/500.html +57 -0
  64. data/test/dummy/public/favicon.ico +0 -0
  65. data/test/dummy/public/robots.txt +5 -0
  66. data/test/dummy/test/controllers/.keep +0 -0
  67. data/test/dummy/test/controllers/styleguide_controller_test.rb +9 -0
  68. data/test/dummy/test/fixtures/.keep +0 -0
  69. data/test/dummy/test/helpers/.keep +0 -0
  70. data/test/dummy/test/helpers/styleguide_helper_test.rb +4 -0
  71. data/test/dummy/test/integration/.keep +0 -0
  72. data/test/dummy/test/mailers/.keep +0 -0
  73. data/test/dummy/test/models/.keep +0 -0
  74. data/test/dummy/test/test_helper.rb +15 -0
  75. data/test/dummy/vendor/assets/javascripts/.keep +0 -0
  76. data/test/dummy/vendor/assets/stylesheets/.keep +0 -0
  77. data/vendor/_settings.scss +992 -0
  78. data/vendor/assets/javascripts/foundation.js +15 -0
  79. data/vendor/assets/javascripts/foundation/foundation.abide.js +201 -0
  80. data/vendor/assets/javascripts/foundation/foundation.accordion.js +41 -0
  81. data/vendor/assets/javascripts/foundation/foundation.alert.js +34 -0
  82. data/vendor/assets/javascripts/foundation/foundation.clearing.js +450 -0
  83. data/vendor/assets/javascripts/foundation/foundation.dropdown.js +184 -0
  84. data/vendor/assets/javascripts/foundation/foundation.interchange.js +304 -0
  85. data/vendor/assets/javascripts/foundation/foundation.joyride.js +839 -0
  86. data/vendor/assets/javascripts/foundation/foundation.js +416 -0
  87. data/vendor/assets/javascripts/foundation/foundation.magellan.js +118 -0
  88. data/vendor/assets/javascripts/foundation/foundation.offcanvas.js +37 -0
  89. data/vendor/assets/javascripts/foundation/foundation.orbit.js +434 -0
  90. data/vendor/assets/javascripts/foundation/foundation.reveal.js +347 -0
  91. data/vendor/assets/javascripts/foundation/foundation.tab.js +37 -0
  92. data/vendor/assets/javascripts/foundation/foundation.tooltip.js +202 -0
  93. data/vendor/assets/javascripts/foundation/foundation.topbar.js +380 -0
  94. data/vendor/assets/javascripts/vendor/modernizr.js +4 -0
  95. data/vendor/assets/stylesheets/foundation.scss +38 -0
  96. data/vendor/assets/stylesheets/foundation/_functions.scss +75 -0
  97. data/vendor/assets/stylesheets/foundation/_settings.scss +992 -0
  98. data/vendor/assets/stylesheets/foundation/components/_accordion.scss +49 -0
  99. data/vendor/assets/stylesheets/foundation/components/_alert-boxes.scss +113 -0
  100. data/vendor/assets/stylesheets/foundation/components/_block-grid.scss +83 -0
  101. data/vendor/assets/stylesheets/foundation/components/_breadcrumbs.scss +123 -0
  102. data/vendor/assets/stylesheets/foundation/components/_button-groups.scss +97 -0
  103. data/vendor/assets/stylesheets/foundation/components/_buttons.scss +234 -0
  104. data/vendor/assets/stylesheets/foundation/components/_clearing.scss +233 -0
  105. data/vendor/assets/stylesheets/foundation/components/_dropdown-buttons.scss +125 -0
  106. data/vendor/assets/stylesheets/foundation/components/_dropdown.scss +159 -0
  107. data/vendor/assets/stylesheets/foundation/components/_flex-video.scss +47 -0
  108. data/vendor/assets/stylesheets/foundation/components/_forms.scss +472 -0
  109. data/vendor/assets/stylesheets/foundation/components/_functions.scss +70 -0
  110. data/vendor/assets/stylesheets/foundation/components/_global.scss +387 -0
  111. data/vendor/assets/stylesheets/foundation/components/_grid.scss +234 -0
  112. data/vendor/assets/stylesheets/foundation/components/_inline-lists.scss +52 -0
  113. data/vendor/assets/stylesheets/foundation/components/_joyride.scss +220 -0
  114. data/vendor/assets/stylesheets/foundation/components/_keystrokes.scss +57 -0
  115. data/vendor/assets/stylesheets/foundation/components/_labels.scss +100 -0
  116. data/vendor/assets/stylesheets/foundation/components/_magellan.scss +30 -0
  117. data/vendor/assets/stylesheets/foundation/components/_offcanvas.scss +360 -0
  118. data/vendor/assets/stylesheets/foundation/components/_orbit.scss +353 -0
  119. data/vendor/assets/stylesheets/foundation/components/_pagination.scss +145 -0
  120. data/vendor/assets/stylesheets/foundation/components/_panels.scss +87 -0
  121. data/vendor/assets/stylesheets/foundation/components/_pricing-tables.scss +146 -0
  122. data/vendor/assets/stylesheets/foundation/components/_progress-bars.scss +75 -0
  123. data/vendor/assets/stylesheets/foundation/components/_reveal.scss +165 -0
  124. data/vendor/assets/stylesheets/foundation/components/_side-nav.scss +83 -0
  125. data/vendor/assets/stylesheets/foundation/components/_split-buttons.scss +187 -0
  126. data/vendor/assets/stylesheets/foundation/components/_sub-nav.scss +118 -0
  127. data/vendor/assets/stylesheets/foundation/components/_switch.scss +314 -0
  128. data/vendor/assets/stylesheets/foundation/components/_tables.scss +93 -0
  129. data/vendor/assets/stylesheets/foundation/components/_tabs.scss +95 -0
  130. data/vendor/assets/stylesheets/foundation/components/_thumbs.scss +71 -0
  131. data/vendor/assets/stylesheets/foundation/components/_tooltips.scss +121 -0
  132. data/vendor/assets/stylesheets/foundation/components/_top-bar.scss +590 -0
  133. data/vendor/assets/stylesheets/foundation/components/_type.scss +447 -0
  134. data/vendor/assets/stylesheets/foundation/components/_visibility.scss +661 -0
  135. data/vendor/assets/stylesheets/normalize.scss +410 -0
  136. metadata +292 -0
@@ -0,0 +1,15 @@
1
+ //= require foundation/foundation
2
+ //= require foundation/foundation.abide
3
+ //= require foundation/foundation.accordion
4
+ //= require foundation/foundation.alert
5
+ //= require foundation/foundation.clearing
6
+ //= require foundation/foundation.dropdown
7
+ //= require foundation/foundation.interchange
8
+ //= require foundation/foundation.joyride
9
+ //= require foundation/foundation.magellan
10
+ //= require foundation/foundation.offcanvas
11
+ //= require foundation/foundation.orbit
12
+ //= require foundation/foundation.reveal
13
+ //= require foundation/foundation.tab
14
+ //= require foundation/foundation.tooltip
15
+ //= require foundation/foundation.topbar
@@ -0,0 +1,201 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.abide = {
5
+ name : 'abide',
6
+
7
+ version : '5.0.0',
8
+
9
+ settings : {
10
+ focus_on_invalid : true,
11
+ timeout : 1000,
12
+ patterns : {
13
+ alpha: /[a-zA-Z]+/,
14
+ alpha_numeric : /[a-zA-Z0-9]+/,
15
+ integer: /-?\d+/,
16
+ number: /-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?/,
17
+
18
+ // generic password: upper-case, lower-case, number/special character, and min 8 characters
19
+ password : /(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/,
20
+
21
+ // amex, visa, diners
22
+ card : /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,
23
+ cvv : /^([0-9]){3,4}$/,
24
+
25
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
26
+ email : /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
27
+
28
+ url: /(https?|ftp|file|ssh):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?/,
29
+ // abc.de
30
+ domain: /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/,
31
+
32
+ datetime: /([0-2][0-9]{3})\-([0-1][0-9])\-([0-3][0-9])T([0-5][0-9])\:([0-5][0-9])\:([0-5][0-9])(Z|([\-\+]([0-1][0-9])\:00))/,
33
+ // YYYY-MM-DD
34
+ date: /(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))/,
35
+ // HH:MM:SS
36
+ time : /(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}/,
37
+ dateISO: /\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/,
38
+ // MM/DD/YYYY
39
+ month_day_year : /(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/,
40
+
41
+ // #FFF or #FFFFFF
42
+ color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
43
+ }
44
+ },
45
+
46
+ timer : null,
47
+
48
+ init : function (scope, method, options) {
49
+ this.bindings(method, options);
50
+ },
51
+
52
+ events : function (scope) {
53
+ var self = this,
54
+ form = $(scope).attr('novalidate', 'novalidate'),
55
+ settings = form.data('abide-init');
56
+
57
+ form
58
+ .off('.abide')
59
+ .on('submit.fndtn.abide validate.fndtn.abide', function (e) {
60
+ var is_ajax = /ajax/i.test($(this).attr('data-abide'));
61
+ return self.validate($(this).find('input, textarea, select').get(), e, is_ajax);
62
+ })
63
+ .find('input, textarea, select')
64
+ .off('.abide')
65
+ .on('blur.fndtn.abide change.fndtn.abide', function (e) {
66
+ self.validate([this], e);
67
+ })
68
+ .on('keydown.fndtn.abide', function (e) {
69
+ var settings = $(this).closest('form').data('abide-init');
70
+ clearTimeout(self.timer);
71
+ self.timer = setTimeout(function () {
72
+ self.validate([this], e);
73
+ }.bind(this), settings.timeout);
74
+ });
75
+ },
76
+
77
+ validate : function (els, e, is_ajax) {
78
+ var validations = this.parse_patterns(els),
79
+ validation_count = validations.length,
80
+ form = $(els[0]).closest('form'),
81
+ submit_event = /submit/.test(e.type);
82
+
83
+ for (var i=0; i < validation_count; i++) {
84
+ if (!validations[i] && (submit_event || is_ajax)) {
85
+ if (this.settings.focus_on_invalid) els[i].focus();
86
+ form.trigger('invalid');
87
+ $(els[i]).closest('form').attr('data-invalid', '');
88
+ return false;
89
+ }
90
+ }
91
+
92
+ if (submit_event || is_ajax) {
93
+ form.trigger('valid');
94
+ }
95
+
96
+ form.removeAttr('data-invalid');
97
+
98
+ if (is_ajax) return false;
99
+
100
+ return true;
101
+ },
102
+
103
+ parse_patterns : function (els) {
104
+ var count = els.length,
105
+ el_patterns = [];
106
+
107
+ for (var i = count - 1; i >= 0; i--) {
108
+ el_patterns.push(this.pattern(els[i]));
109
+ }
110
+
111
+ return this.check_validation_and_apply_styles(el_patterns);
112
+ },
113
+
114
+ pattern : function (el) {
115
+ var type = el.getAttribute('type'),
116
+ required = typeof el.getAttribute('required') === 'string';
117
+
118
+ if (this.settings.patterns.hasOwnProperty(type)) {
119
+ return [el, this.settings.patterns[type], required];
120
+ }
121
+
122
+ var pattern = el.getAttribute('pattern') || '';
123
+
124
+ if (this.settings.patterns.hasOwnProperty(pattern) && pattern.length > 0) {
125
+ return [el, this.settings.patterns[pattern], required];
126
+ } else if (pattern.length > 0) {
127
+ return [el, new RegExp(pattern), required];
128
+ }
129
+
130
+ pattern = /.*/;
131
+
132
+ return [el, pattern, required];
133
+ },
134
+
135
+ check_validation_and_apply_styles : function (el_patterns) {
136
+ var count = el_patterns.length,
137
+ validations = [];
138
+
139
+ for (var i = count - 1; i >= 0; i--) {
140
+ var el = el_patterns[i][0],
141
+ required = el_patterns[i][2],
142
+ value = el.value,
143
+ is_equal = el.getAttribute('data-equalto'),
144
+ is_radio = el.type === "radio",
145
+ valid_length = (required) ? (el.value.length > 0) : true;
146
+
147
+ if (is_radio && required) {
148
+ validations.push(this.valid_radio(el, required));
149
+ } else if (is_equal && required) {
150
+ validations.push(this.valid_equal(el, required));
151
+ } else {
152
+ if (el_patterns[i][1].test(value) && valid_length ||
153
+ !required && el.value.length < 1) {
154
+ $(el).removeAttr('data-invalid').parent().removeClass('error');
155
+ validations.push(true);
156
+ } else {
157
+ $(el).attr('data-invalid', '').parent().addClass('error');
158
+ validations.push(false);
159
+ }
160
+ }
161
+ }
162
+
163
+ return validations;
164
+ },
165
+
166
+ valid_radio : function (el, required) {
167
+ var name = el.getAttribute('name'),
168
+ group = document.getElementsByName(name),
169
+ count = group.length,
170
+ valid = false;
171
+
172
+ for (var i=0; i < count; i++) {
173
+ if (group[i].checked) valid = true;
174
+ }
175
+
176
+ for (var i=0; i < count; i++) {
177
+ if (valid) {
178
+ $(group[i]).removeAttr('data-invalid').parent().removeClass('error');
179
+ } else {
180
+ $(group[i]).attr('data-invalid', '').parent().addClass('error');
181
+ }
182
+ }
183
+
184
+ return valid;
185
+ },
186
+
187
+ valid_equal: function(el, required) {
188
+ var from = document.getElementById(el.getAttribute('data-equalto')).value,
189
+ to = el.value,
190
+ valid = (from === to);
191
+
192
+ if (valid) {
193
+ $(el).removeAttr('data-invalid').parent().removeClass('error');
194
+ } else {
195
+ $(el).attr('data-invalid', '').parent().addClass('error');
196
+ }
197
+
198
+ return valid;
199
+ }
200
+ };
201
+ }(jQuery, this, this.document));
@@ -0,0 +1,41 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.accordion = {
5
+ name : 'accordion',
6
+
7
+ version : '5.0.1',
8
+
9
+ settings : {
10
+ active_class: 'active',
11
+ toggleable: true
12
+ },
13
+
14
+ init : function (scope, method, options) {
15
+ this.bindings(method, options);
16
+ },
17
+
18
+ events : function () {
19
+ $(this.scope).off('.accordion').on('click.fndtn.accordion', '[data-accordion] > dd > a', function (e) {
20
+ var accordion = $(this).parent(),
21
+ target = $('#' + this.href.split('#')[1]),
22
+ siblings = $('> dd > .content', target.closest('[data-accordion]')),
23
+ settings = accordion.parent().data('accordion-init'),
24
+ active = $('> dd > .content.' + settings.active_class, accordion.parent());
25
+
26
+ e.preventDefault();
27
+
28
+ if (active[0] == target[0] && settings.toggleable) {
29
+ return target.toggleClass(settings.active_class);
30
+ }
31
+
32
+ siblings.removeClass(settings.active_class);
33
+ target.addClass(settings.active_class);
34
+ });
35
+ },
36
+
37
+ off : function () {},
38
+
39
+ reflow : function () {}
40
+ };
41
+ }(jQuery, this, this.document));
@@ -0,0 +1,34 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.alert = {
5
+ name : 'alert',
6
+
7
+ version : '5.0.0',
8
+
9
+ settings : {
10
+ animation: 'fadeOut',
11
+ speed: 300, // fade out speed
12
+ callback: function (){}
13
+ },
14
+
15
+ init : function (scope, method, options) {
16
+ this.bindings(method, options);
17
+ },
18
+
19
+ events : function () {
20
+ $(this.scope).off('.alert').on('click.fndtn.alert', '[data-alert] a.close', function (e) {
21
+ var alertBox = $(this).closest("[data-alert]"),
22
+ settings = alertBox.data('alert-init');
23
+
24
+ e.preventDefault();
25
+ alertBox[settings.animation](settings.speed, function () {
26
+ $(this).trigger('closed').remove();
27
+ settings.callback();
28
+ });
29
+ });
30
+ },
31
+
32
+ reflow : function () {}
33
+ };
34
+ }(jQuery, this, this.document));
@@ -0,0 +1,450 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.clearing = {
5
+ name : 'clearing',
6
+
7
+ version: '5.0.0',
8
+
9
+ settings : {
10
+ templates : {
11
+ viewing : '<a href="#" class="clearing-close">&times;</a>' +
12
+ '<div class="visible-img" style="display: none"><img src="//:0">' +
13
+ '<p class="clearing-caption"></p><a href="#" class="clearing-main-prev"><span></span></a>' +
14
+ '<a href="#" class="clearing-main-next"><span></span></a></div>'
15
+ },
16
+
17
+ // comma delimited list of selectors that, on click, will close clearing,
18
+ // add 'div.clearing-blackout, div.visible-img' to close on background click
19
+ close_selectors : '.clearing-close',
20
+
21
+ // event initializers and locks
22
+ init : false,
23
+ locked : false
24
+ },
25
+
26
+ init : function (scope, method, options) {
27
+ var self = this;
28
+ Foundation.inherit(this, 'throttle loaded');
29
+
30
+ this.bindings(method, options);
31
+
32
+ if ($(this.scope).is('[data-clearing]')) {
33
+ this.assemble($('li', this.scope));
34
+ } else {
35
+ $('[data-clearing]', this.scope).each(function () {
36
+ self.assemble($('li', this));
37
+ });
38
+ }
39
+ },
40
+
41
+ events : function (scope) {
42
+ var self = this;
43
+
44
+ $(this.scope)
45
+ .off('.clearing')
46
+ .on('click.fndtn.clearing', 'ul[data-clearing] li',
47
+ function (e, current, target) {
48
+ var current = current || $(this),
49
+ target = target || current,
50
+ next = current.next('li'),
51
+ settings = current.closest('[data-clearing]').data('clearing-init'),
52
+ image = $(e.target);
53
+
54
+ e.preventDefault();
55
+
56
+ if (!settings) {
57
+ self.init();
58
+ settings = current.closest('[data-clearing]').data('clearing-init');
59
+ }
60
+
61
+ // if clearing is open and the current image is
62
+ // clicked, go to the next image in sequence
63
+ if (target.hasClass('visible') &&
64
+ current[0] === target[0] &&
65
+ next.length > 0 && self.is_open(current)) {
66
+ target = next;
67
+ image = $('img', target);
68
+ }
69
+
70
+ // set current and target to the clicked li if not otherwise defined.
71
+ self.open(image, current, target);
72
+ self.update_paddles(target);
73
+ })
74
+
75
+ .on('click.fndtn.clearing', '.clearing-main-next',
76
+ function (e) { self.nav(e, 'next') })
77
+ .on('click.fndtn.clearing', '.clearing-main-prev',
78
+ function (e) { self.nav(e, 'prev') })
79
+ .on('click.fndtn.clearing', this.settings.close_selectors,
80
+ function (e) { Foundation.libs.clearing.close(e, this) })
81
+ .on('keydown.fndtn.clearing',
82
+ function (e) { self.keydown(e) });
83
+
84
+ $(window).off('.clearing').on('resize.fndtn.clearing',
85
+ function () { self.resize() });
86
+
87
+ this.swipe_events(scope);
88
+ },
89
+
90
+ swipe_events : function (scope) {
91
+ var self = this;
92
+
93
+ $(this.scope)
94
+ .on('touchstart.fndtn.clearing', '.visible-img', function(e) {
95
+ if (!e.touches) { e = e.originalEvent; }
96
+ var data = {
97
+ start_page_x: e.touches[0].pageX,
98
+ start_page_y: e.touches[0].pageY,
99
+ start_time: (new Date()).getTime(),
100
+ delta_x: 0,
101
+ is_scrolling: undefined
102
+ };
103
+
104
+ $(this).data('swipe-transition', data);
105
+ e.stopPropagation();
106
+ })
107
+ .on('touchmove.fndtn.clearing', '.visible-img', function(e) {
108
+ if (!e.touches) { e = e.originalEvent; }
109
+ // Ignore pinch/zoom events
110
+ if(e.touches.length > 1 || e.scale && e.scale !== 1) return;
111
+
112
+ var data = $(this).data('swipe-transition');
113
+
114
+ if (typeof data === 'undefined') {
115
+ data = {};
116
+ }
117
+
118
+ data.delta_x = e.touches[0].pageX - data.start_page_x;
119
+
120
+ if ( typeof data.is_scrolling === 'undefined') {
121
+ data.is_scrolling = !!( data.is_scrolling || Math.abs(data.delta_x) < Math.abs(e.touches[0].pageY - data.start_page_y) );
122
+ }
123
+
124
+ if (!data.is_scrolling && !data.active) {
125
+ e.preventDefault();
126
+ var direction = (data.delta_x < 0) ? 'next' : 'prev';
127
+ data.active = true;
128
+ self.nav(e, direction);
129
+ }
130
+ })
131
+ .on('touchend.fndtn.clearing', '.visible-img', function(e) {
132
+ $(this).data('swipe-transition', {});
133
+ e.stopPropagation();
134
+ });
135
+ },
136
+
137
+ assemble : function ($li) {
138
+ var $el = $li.parent();
139
+
140
+ if ($el.parent().hasClass('carousel')) return;
141
+ $el.after('<div id="foundationClearingHolder"></div>');
142
+
143
+ var holder = $('#foundationClearingHolder'),
144
+ settings = $el.data('clearing-init'),
145
+ grid = $el.detach(),
146
+ data = {
147
+ grid: '<div class="carousel">' + grid[0].outerHTML + '</div>',
148
+ viewing: settings.templates.viewing
149
+ },
150
+ wrapper = '<div class="clearing-assembled"><div>' + data.viewing +
151
+ data.grid + '</div></div>';
152
+
153
+ return holder.after(wrapper).remove();
154
+ },
155
+
156
+ open : function ($image, current, target) {
157
+ var root = target.closest('.clearing-assembled'),
158
+ container = $('div', root).first(),
159
+ visible_image = $('.visible-img', container),
160
+ image = $('img', visible_image).not($image);
161
+
162
+ if (!this.locked()) {
163
+ // set the image to the selected thumbnail
164
+ image
165
+ .attr('src', this.load($image))
166
+ .css('visibility', 'hidden');
167
+
168
+ this.loaded(image, function () {
169
+ image.css('visibility', 'visible');
170
+ // toggle the gallery
171
+ root.addClass('clearing-blackout');
172
+ container.addClass('clearing-container');
173
+ visible_image.show();
174
+ this.fix_height(target)
175
+ .caption($('.clearing-caption', visible_image), $image)
176
+ .center(image)
177
+ .shift(current, target, function () {
178
+ target.siblings().removeClass('visible');
179
+ target.addClass('visible');
180
+ });
181
+ }.bind(this));
182
+ }
183
+ },
184
+
185
+ close : function (e, el) {
186
+ e.preventDefault();
187
+
188
+ var root = (function (target) {
189
+ if (/blackout/.test(target.selector)) {
190
+ return target;
191
+ } else {
192
+ return target.closest('.clearing-blackout');
193
+ }
194
+ }($(el))), container, visible_image;
195
+
196
+ if (el === e.target && root) {
197
+ container = $('div', root).first();
198
+ visible_image = $('.visible-img', container);
199
+ this.settings.prev_index = 0;
200
+ $('ul[data-clearing]', root)
201
+ .attr('style', '').closest('.clearing-blackout')
202
+ .removeClass('clearing-blackout');
203
+ container.removeClass('clearing-container');
204
+ visible_image.hide();
205
+ }
206
+
207
+ return false;
208
+ },
209
+
210
+ is_open : function (current) {
211
+ return current.parent().prop('style').length > 0;
212
+ },
213
+
214
+ keydown : function (e) {
215
+ var clearing = $('ul[data-clearing]', '.clearing-blackout');
216
+
217
+ if (e.which === 39) this.go(clearing, 'next');
218
+ if (e.which === 37) this.go(clearing, 'prev');
219
+ if (e.which === 27) $('a.clearing-close').trigger('click');
220
+ },
221
+
222
+ nav : function (e, direction) {
223
+ var clearing = $('ul[data-clearing]', '.clearing-blackout');
224
+
225
+ e.preventDefault();
226
+ this.go(clearing, direction);
227
+ },
228
+
229
+ resize : function () {
230
+ var image = $('img', '.clearing-blackout .visible-img');
231
+
232
+ if (image.length) {
233
+ this.center(image);
234
+ }
235
+ },
236
+
237
+ // visual adjustments
238
+ fix_height : function (target) {
239
+ var lis = target.parent().children(),
240
+ self = this;
241
+
242
+ lis.each(function () {
243
+ var li = $(this),
244
+ image = li.find('img');
245
+
246
+ if (li.height() > image.outerHeight()) {
247
+ li.addClass('fix-height');
248
+ }
249
+ })
250
+ .closest('ul')
251
+ .width(lis.length * 100 + '%');
252
+
253
+ return this;
254
+ },
255
+
256
+ update_paddles : function (target) {
257
+ var visible_image = target
258
+ .closest('.carousel')
259
+ .siblings('.visible-img');
260
+
261
+ if (target.next().length > 0) {
262
+ $('.clearing-main-next', visible_image)
263
+ .removeClass('disabled');
264
+ } else {
265
+ $('.clearing-main-next', visible_image)
266
+ .addClass('disabled');
267
+ }
268
+
269
+ if (target.prev().length > 0) {
270
+ $('.clearing-main-prev', visible_image)
271
+ .removeClass('disabled');
272
+ } else {
273
+ $('.clearing-main-prev', visible_image)
274
+ .addClass('disabled');
275
+ }
276
+ },
277
+
278
+ center : function (target) {
279
+ if (!this.rtl) {
280
+ target.css({
281
+ marginLeft : -(target.outerWidth() / 2),
282
+ marginTop : -(target.outerHeight() / 2)
283
+ });
284
+ } else {
285
+ target.css({
286
+ marginRight : -(target.outerWidth() / 2),
287
+ marginTop : -(target.outerHeight() / 2)
288
+ });
289
+ }
290
+ return this;
291
+ },
292
+
293
+ // image loading and preloading
294
+
295
+ load : function ($image) {
296
+ if ($image[0].nodeName === "A") {
297
+ var href = $image.attr('href');
298
+ } else {
299
+ var href = $image.parent().attr('href');
300
+ }
301
+
302
+ this.preload($image);
303
+
304
+ if (href) return href;
305
+ return $image.attr('src');
306
+ },
307
+
308
+ preload : function ($image) {
309
+ this
310
+ .img($image.closest('li').next())
311
+ .img($image.closest('li').prev());
312
+ },
313
+
314
+ img : function (img) {
315
+ if (img.length) {
316
+ var new_img = new Image(),
317
+ new_a = $('a', img);
318
+
319
+ if (new_a.length) {
320
+ new_img.src = new_a.attr('href');
321
+ } else {
322
+ new_img.src = $('img', img).attr('src');
323
+ }
324
+ }
325
+ return this;
326
+ },
327
+
328
+ // image caption
329
+
330
+ caption : function (container, $image) {
331
+ var caption = $image.data('caption');
332
+
333
+ if (caption) {
334
+ container
335
+ .html(caption)
336
+ .show();
337
+ } else {
338
+ container
339
+ .text('')
340
+ .hide();
341
+ }
342
+ return this;
343
+ },
344
+
345
+ // directional methods
346
+
347
+ go : function ($ul, direction) {
348
+ var current = $('.visible', $ul),
349
+ target = current[direction]();
350
+
351
+ if (target.length) {
352
+ $('img', target)
353
+ .trigger('click', [current, target]);
354
+ }
355
+ },
356
+
357
+ shift : function (current, target, callback) {
358
+ var clearing = target.parent(),
359
+ old_index = this.settings.prev_index || target.index(),
360
+ direction = this.direction(clearing, current, target),
361
+ left = parseInt(clearing.css('left'), 10),
362
+ width = target.outerWidth(),
363
+ skip_shift;
364
+
365
+ // we use jQuery animate instead of CSS transitions because we
366
+ // need a callback to unlock the next animation
367
+ if (target.index() !== old_index && !/skip/.test(direction)){
368
+ if (/left/.test(direction)) {
369
+ this.lock();
370
+ clearing.animate({left : left + width}, 300, this.unlock());
371
+ } else if (/right/.test(direction)) {
372
+ this.lock();
373
+ clearing.animate({left : left - width}, 300, this.unlock());
374
+ }
375
+ } else if (/skip/.test(direction)) {
376
+ // the target image is not adjacent to the current image, so
377
+ // do we scroll right or not
378
+ skip_shift = target.index() - this.settings.up_count;
379
+ this.lock();
380
+
381
+ if (skip_shift > 0) {
382
+ clearing.animate({left : -(skip_shift * width)}, 300, this.unlock());
383
+ } else {
384
+ clearing.animate({left : 0}, 300, this.unlock());
385
+ }
386
+ }
387
+
388
+ callback();
389
+ },
390
+
391
+ direction : function ($el, current, target) {
392
+ var lis = $('li', $el),
393
+ li_width = lis.outerWidth() + (lis.outerWidth() / 4),
394
+ up_count = Math.floor($('.clearing-container').outerWidth() / li_width) - 1,
395
+ target_index = lis.index(target),
396
+ response;
397
+
398
+ this.settings.up_count = up_count;
399
+
400
+ if (this.adjacent(this.settings.prev_index, target_index)) {
401
+ if ((target_index > up_count)
402
+ && target_index > this.settings.prev_index) {
403
+ response = 'right';
404
+ } else if ((target_index > up_count - 1)
405
+ && target_index <= this.settings.prev_index) {
406
+ response = 'left';
407
+ } else {
408
+ response = false;
409
+ }
410
+ } else {
411
+ response = 'skip';
412
+ }
413
+
414
+ this.settings.prev_index = target_index;
415
+
416
+ return response;
417
+ },
418
+
419
+ adjacent : function (current_index, target_index) {
420
+ for (var i = target_index + 1; i >= target_index - 1; i--) {
421
+ if (i === current_index) return true;
422
+ }
423
+ return false;
424
+ },
425
+
426
+ // lock management
427
+
428
+ lock : function () {
429
+ this.settings.locked = true;
430
+ },
431
+
432
+ unlock : function () {
433
+ this.settings.locked = false;
434
+ },
435
+
436
+ locked : function () {
437
+ return this.settings.locked;
438
+ },
439
+
440
+ off : function () {
441
+ $(this.scope).off('.fndtn.clearing');
442
+ $(window).off('.fndtn.clearing');
443
+ },
444
+
445
+ reflow : function () {
446
+ this.init();
447
+ }
448
+ };
449
+
450
+ }(jQuery, this, this.document));