pushnote 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rspec +3 -0
  4. data/README.md +11 -30
  5. data/Rakefile +20 -0
  6. data/bin/pushnote +20 -2
  7. data/config.codekit +1005 -0
  8. data/config.ru +2 -0
  9. data/config/database.yml +17 -0
  10. data/db/migrate/20150131202537_create_notes_table.rb +9 -0
  11. data/db/schema.rb +23 -0
  12. data/lib/pushnote.rb +0 -3
  13. data/lib/pushnote/adapters.rb +1 -0
  14. data/lib/pushnote/adapters/base.rb +7 -0
  15. data/lib/pushnote/adapters/local.rb +17 -0
  16. data/lib/pushnote/app.rb +50 -0
  17. data/lib/pushnote/models/note.rb +4 -0
  18. data/lib/pushnote/public/css/foundation.css +6139 -0
  19. data/lib/pushnote/public/css/foundation.min.css +1 -0
  20. data/lib/pushnote/public/css/normalize.css +427 -0
  21. data/lib/pushnote/public/humans.txt +8 -0
  22. data/lib/pushnote/public/img/.gitkeep +1 -0
  23. data/lib/pushnote/public/index.html +166 -0
  24. data/lib/pushnote/public/js/foundation.min.js +5960 -0
  25. data/lib/pushnote/public/js/foundation/foundation.abide.js +318 -0
  26. data/lib/pushnote/public/js/foundation/foundation.accordion.js +67 -0
  27. data/lib/pushnote/public/js/foundation/foundation.alert.js +43 -0
  28. data/lib/pushnote/public/js/foundation/foundation.clearing.js +558 -0
  29. data/lib/pushnote/public/js/foundation/foundation.dropdown.js +439 -0
  30. data/lib/pushnote/public/js/foundation/foundation.equalizer.js +73 -0
  31. data/lib/pushnote/public/js/foundation/foundation.interchange.js +348 -0
  32. data/lib/pushnote/public/js/foundation/foundation.joyride.js +924 -0
  33. data/lib/pushnote/public/js/foundation/foundation.js +690 -0
  34. data/lib/pushnote/public/js/foundation/foundation.magellan.js +198 -0
  35. data/lib/pushnote/public/js/foundation/foundation.offcanvas.js +152 -0
  36. data/lib/pushnote/public/js/foundation/foundation.orbit.js +472 -0
  37. data/lib/pushnote/public/js/foundation/foundation.reveal.js +449 -0
  38. data/lib/pushnote/public/js/foundation/foundation.slider.js +267 -0
  39. data/lib/pushnote/public/js/foundation/foundation.tab.js +217 -0
  40. data/lib/pushnote/public/js/foundation/foundation.tooltip.js +300 -0
  41. data/lib/pushnote/public/js/foundation/foundation.topbar.js +445 -0
  42. data/lib/pushnote/public/js/vendor/fastclick.js +9 -0
  43. data/lib/pushnote/public/js/vendor/jquery.cookie.js +8 -0
  44. data/lib/pushnote/public/js/vendor/jquery.js +26 -0
  45. data/lib/pushnote/public/js/vendor/modernizr.js +8 -0
  46. data/lib/pushnote/public/js/vendor/placeholder.js +2 -0
  47. data/lib/pushnote/public/robots.txt +4 -0
  48. data/lib/pushnote/version.rb +1 -1
  49. data/lib/pushnote/views/index.erb +15 -0
  50. data/lib/pushnote/views/layout.erb +48 -0
  51. data/lib/pushnote/views/show.erb +8 -0
  52. data/pushnote.gemspec +15 -5
  53. data/spec/lib/controllers/notes_spec.rb +21 -0
  54. data/spec/spec_helper.rb +16 -0
  55. metadata +193 -9
  56. data/.pushnote.yml +0 -1
  57. data/lib/pushnote/cli.rb +0 -40
  58. data/lib/pushnote/configuration.rb +0 -12
  59. data/lib/pushnote/note.rb +0 -36
@@ -0,0 +1,318 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.abide = {
5
+ name : 'abide',
6
+
7
+ version : '5.5.0',
8
+
9
+ settings : {
10
+ live_validate : true,
11
+ validate_on_blur: true,
12
+ focus_on_invalid : true,
13
+ error_labels: true, // labels with a for="inputId" will recieve an `error` class
14
+ error_class: 'error',
15
+ timeout : 1000,
16
+ patterns : {
17
+ alpha: /^[a-zA-Z]+$/,
18
+ alpha_numeric : /^[a-zA-Z0-9]+$/,
19
+ integer: /^[-+]?\d+$/,
20
+ number: /^[-+]?\d*(?:[\.\,]\d+)?$/,
21
+
22
+ // amex, visa, diners
23
+ 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})$/,
24
+ cvv : /^([0-9]){3,4}$/,
25
+
26
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
27
+ 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])?)+$/,
28
+
29
+ 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/,
30
+ // abc.de
31
+ domain: /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,8}$/,
32
+
33
+ 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))$/,
34
+ // YYYY-MM-DD
35
+ 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))$/,
36
+ // HH:MM:SS
37
+ time : /^(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$/,
38
+ dateISO: /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/,
39
+ // MM/DD/YYYY
40
+ month_day_year : /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.]\d{4}$/,
41
+ // DD/MM/YYYY
42
+ day_month_year : /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.]\d{4}$/,
43
+
44
+ // #FFF or #FFFFFF
45
+ color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
46
+ },
47
+ validators : {
48
+ equalTo: function(el, required, parent) {
49
+ var from = document.getElementById(el.getAttribute(this.add_namespace('data-equalto'))).value,
50
+ to = el.value,
51
+ valid = (from === to);
52
+
53
+ return valid;
54
+ }
55
+ }
56
+ },
57
+
58
+ timer : null,
59
+
60
+ init : function (scope, method, options) {
61
+ this.bindings(method, options);
62
+ },
63
+
64
+ events : function (scope) {
65
+ var self = this,
66
+ form = self.S(scope).attr('novalidate', 'novalidate'),
67
+ settings = form.data(this.attr_name(true) + '-init') || {};
68
+
69
+ this.invalid_attr = this.add_namespace('data-invalid');
70
+
71
+ form
72
+ .off('.abide')
73
+ .on('submit.fndtn.abide validate.fndtn.abide', function (e) {
74
+ var is_ajax = /ajax/i.test(self.S(this).attr(self.attr_name()));
75
+ return self.validate(self.S(this).find('input, textarea, select').get(), e, is_ajax);
76
+ })
77
+ .on('reset', function() {
78
+ return self.reset($(this));
79
+ })
80
+ .find('input, textarea, select')
81
+ .off('.abide')
82
+ .on('blur.fndtn.abide change.fndtn.abide', function (e) {
83
+ if (settings.validate_on_blur === true) {
84
+ self.validate([this], e);
85
+ }
86
+ })
87
+ .on('keydown.fndtn.abide', function (e) {
88
+ if (settings.live_validate === true && e.which != 9) {
89
+ clearTimeout(self.timer);
90
+ self.timer = setTimeout(function () {
91
+ self.validate([this], e);
92
+ }.bind(this), settings.timeout);
93
+ }
94
+ });
95
+ },
96
+
97
+ reset : function (form) {
98
+ form.removeAttr(this.invalid_attr);
99
+ $(this.invalid_attr, form).removeAttr(this.invalid_attr);
100
+ $('.' + this.settings.error_class, form).not('small').removeClass(this.settings.error_class);
101
+ },
102
+
103
+ validate : function (els, e, is_ajax) {
104
+ var validations = this.parse_patterns(els),
105
+ validation_count = validations.length,
106
+ form = this.S(els[0]).closest('form'),
107
+ submit_event = /submit/.test(e.type);
108
+
109
+ // Has to count up to make sure the focus gets applied to the top error
110
+ for (var i=0; i < validation_count; i++) {
111
+ if (!validations[i] && (submit_event || is_ajax)) {
112
+ if (this.settings.focus_on_invalid) els[i].focus();
113
+ form.trigger('invalid').trigger('invalid.fndtn.abide');
114
+ this.S(els[i]).closest('form').attr(this.invalid_attr, '');
115
+ return false;
116
+ }
117
+ }
118
+
119
+ if (submit_event || is_ajax) {
120
+ form.trigger('valid').trigger('valid.fndtn.abide');
121
+ }
122
+
123
+ form.removeAttr(this.invalid_attr);
124
+
125
+ if (is_ajax) return false;
126
+
127
+ return true;
128
+ },
129
+
130
+ parse_patterns : function (els) {
131
+ var i = els.length,
132
+ el_patterns = [];
133
+
134
+ while (i--) {
135
+ el_patterns.push(this.pattern(els[i]));
136
+ }
137
+
138
+ return this.check_validation_and_apply_styles(el_patterns);
139
+ },
140
+
141
+ pattern : function (el) {
142
+ var type = el.getAttribute('type'),
143
+ required = typeof el.getAttribute('required') === 'string';
144
+
145
+ var pattern = el.getAttribute('pattern') || '';
146
+
147
+ if (this.settings.patterns.hasOwnProperty(pattern) && pattern.length > 0) {
148
+ return [el, this.settings.patterns[pattern], required];
149
+ } else if (pattern.length > 0) {
150
+ return [el, new RegExp(pattern), required];
151
+ }
152
+
153
+ if (this.settings.patterns.hasOwnProperty(type)) {
154
+ return [el, this.settings.patterns[type], required];
155
+ }
156
+
157
+ pattern = /.*/;
158
+
159
+ return [el, pattern, required];
160
+ },
161
+
162
+ // TODO: Break this up into smaller methods, getting hard to read.
163
+ check_validation_and_apply_styles : function (el_patterns) {
164
+ var i = el_patterns.length,
165
+ validations = [],
166
+ form = this.S(el_patterns[0][0]).closest('[data-' + this.attr_name(true) + ']'),
167
+ settings = form.data(this.attr_name(true) + '-init') || {};
168
+ while (i--) {
169
+ var el = el_patterns[i][0],
170
+ required = el_patterns[i][2],
171
+ value = el.value.trim(),
172
+ direct_parent = this.S(el).parent(),
173
+ validator = el.getAttribute(this.add_namespace('data-abide-validator')),
174
+ is_radio = el.type === "radio",
175
+ is_checkbox = el.type === "checkbox",
176
+ label = this.S('label[for="' + el.getAttribute('id') + '"]'),
177
+ valid_length = (required) ? (el.value.length > 0) : true,
178
+ el_validations = [];
179
+
180
+ var parent, valid;
181
+
182
+ // support old way to do equalTo validations
183
+ if(el.getAttribute(this.add_namespace('data-equalto'))) { validator = "equalTo" }
184
+
185
+ if (!direct_parent.is('label')) {
186
+ parent = direct_parent;
187
+ } else {
188
+ parent = direct_parent.parent();
189
+ }
190
+
191
+ if (validator) {
192
+ valid = this.settings.validators[validator].apply(this, [el, required, parent]);
193
+ el_validations.push(valid);
194
+ }
195
+
196
+ if (is_radio && required) {
197
+ el_validations.push(this.valid_radio(el, required));
198
+ } else if (is_checkbox && required) {
199
+ el_validations.push(this.valid_checkbox(el, required));
200
+ } else {
201
+
202
+ if (el_patterns[i][1].test(value) && valid_length ||
203
+ !required && el.value.length < 1 || $(el).attr('disabled')) {
204
+ el_validations.push(true);
205
+ } else {
206
+ el_validations.push(false);
207
+ }
208
+
209
+ el_validations = [el_validations.every(function(valid){return valid;})];
210
+
211
+ if(el_validations[0]){
212
+ this.S(el).removeAttr(this.invalid_attr);
213
+ el.setAttribute('aria-invalid', 'false');
214
+ el.removeAttribute('aria-describedby');
215
+ parent.removeClass(this.settings.error_class);
216
+ if (label.length > 0 && this.settings.error_labels) {
217
+ label.removeClass(this.settings.error_class).removeAttr('role');
218
+ }
219
+ $(el).triggerHandler('valid');
220
+ } else {
221
+ this.S(el).attr(this.invalid_attr, '');
222
+ el.setAttribute('aria-invalid', 'true');
223
+
224
+ // Try to find the error associated with the input
225
+ var errorElem = parent.find('small.'+this.settings.error_class, 'span.'+this.settings.error_class);
226
+ var errorID = errorElem.length > 0 ? errorElem[0].id : "";
227
+ if (errorID.length > 0) el.setAttribute('aria-describedby', errorID);
228
+
229
+ // el.setAttribute('aria-describedby', $(el).find('.error')[0].id);
230
+ parent.addClass(this.settings.error_class);
231
+ if (label.length > 0 && this.settings.error_labels) {
232
+ label.addClass(this.settings.error_class).attr('role', 'alert');
233
+ }
234
+ $(el).triggerHandler('invalid');
235
+ }
236
+ }
237
+ validations.push(el_validations[0]);
238
+ }
239
+ validations = [validations.every(function(valid){return valid;})];
240
+ return validations;
241
+ },
242
+
243
+ valid_checkbox : function(el, required) {
244
+ var el = this.S(el),
245
+ valid = (el.is(':checked') || !required);
246
+
247
+ if (valid) {
248
+ el.removeAttr(this.invalid_attr).parent().removeClass(this.settings.error_class);
249
+ } else {
250
+ el.attr(this.invalid_attr, '').parent().addClass(this.settings.error_class);
251
+ }
252
+
253
+ return valid;
254
+ },
255
+
256
+ valid_radio : function (el, required) {
257
+ var name = el.getAttribute('name'),
258
+ group = this.S(el).closest('[data-' + this.attr_name(true) + ']').find("[name='"+name+"']"),
259
+ count = group.length,
260
+ valid = false;
261
+
262
+ // Has to count up to make sure the focus gets applied to the top error
263
+ for (var i=0; i < count; i++) {
264
+ if (group[i].checked) valid = true;
265
+ }
266
+
267
+ // Has to count up to make sure the focus gets applied to the top error
268
+ for (var i=0; i < count; i++) {
269
+ if (valid) {
270
+ this.S(group[i]).removeAttr(this.invalid_attr).parent().removeClass(this.settings.error_class);
271
+ } else {
272
+ this.S(group[i]).attr(this.invalid_attr, '').parent().addClass(this.settings.error_class);
273
+ }
274
+ }
275
+
276
+ return valid;
277
+ },
278
+
279
+ valid_equal: function(el, required, parent) {
280
+ var from = document.getElementById(el.getAttribute(this.add_namespace('data-equalto'))).value,
281
+ to = el.value,
282
+ valid = (from === to);
283
+
284
+ if (valid) {
285
+ this.S(el).removeAttr(this.invalid_attr);
286
+ parent.removeClass(this.settings.error_class);
287
+ if (label.length > 0 && settings.error_labels) label.removeClass(this.settings.error_class);
288
+ } else {
289
+ this.S(el).attr(this.invalid_attr, '');
290
+ parent.addClass(this.settings.error_class);
291
+ if (label.length > 0 && settings.error_labels) label.addClass(this.settings.error_class);
292
+ }
293
+
294
+ return valid;
295
+ },
296
+
297
+ valid_oneof: function(el, required, parent, doNotValidateOthers) {
298
+ var el = this.S(el),
299
+ others = this.S('[' + this.add_namespace('data-oneof') + ']'),
300
+ valid = others.filter(':checked').length > 0;
301
+
302
+ if (valid) {
303
+ el.removeAttr(this.invalid_attr).parent().removeClass(this.settings.error_class);
304
+ } else {
305
+ el.attr(this.invalid_attr, '').parent().addClass(this.settings.error_class);
306
+ }
307
+
308
+ if (!doNotValidateOthers) {
309
+ var _this = this;
310
+ others.each(function() {
311
+ _this.valid_oneof.call(_this, this, null, null, true);
312
+ });
313
+ }
314
+
315
+ return valid;
316
+ }
317
+ };
318
+ }(jQuery, window, window.document));
@@ -0,0 +1,67 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.accordion = {
5
+ name : 'accordion',
6
+
7
+ version : '5.5.0',
8
+
9
+ settings : {
10
+ content_class: 'content',
11
+ active_class: 'active',
12
+ multi_expand: false,
13
+ toggleable: true,
14
+ callback : function () {}
15
+ },
16
+
17
+ init : function (scope, method, options) {
18
+ this.bindings(method, options);
19
+ },
20
+
21
+ events : function () {
22
+ var self = this;
23
+ var S = this.S;
24
+ S(this.scope)
25
+ .off('.fndtn.accordion')
26
+ .on('click.fndtn.accordion', '[' + this.attr_name() + '] > .accordion-navigation > a', function (e) {
27
+ var accordion = S(this).closest('[' + self.attr_name() + ']'),
28
+ groupSelector = self.attr_name() + '=' + accordion.attr(self.attr_name()),
29
+ settings = accordion.data(self.attr_name(true) + '-init') || self.settings,
30
+ target = S('#' + this.href.split('#')[1]),
31
+ aunts = $('> .accordion-navigation', accordion),
32
+ siblings = aunts.children('.'+settings.content_class),
33
+ active_content = siblings.filter('.' + settings.active_class);
34
+
35
+ e.preventDefault();
36
+
37
+ if (accordion.attr(self.attr_name())) {
38
+ siblings = siblings.add('[' + groupSelector + '] dd > '+'.'+settings.content_class);
39
+ aunts = aunts.add('[' + groupSelector + '] .accordion-navigation');
40
+ }
41
+
42
+ if (settings.toggleable && target.is(active_content)) {
43
+ target.parent('.accordion-navigation').toggleClass(settings.active_class, false);
44
+ target.toggleClass(settings.active_class, false);
45
+ settings.callback(target);
46
+ target.triggerHandler('toggled', [accordion]);
47
+ accordion.triggerHandler('toggled', [target]);
48
+ return;
49
+ }
50
+
51
+ if (!settings.multi_expand) {
52
+ siblings.removeClass(settings.active_class);
53
+ aunts.removeClass(settings.active_class);
54
+ }
55
+
56
+ target.addClass(settings.active_class).parent().addClass(settings.active_class);
57
+ settings.callback(target);
58
+ target.triggerHandler('toggled', [accordion]);
59
+ accordion.triggerHandler('toggled', [target]);
60
+ });
61
+ },
62
+
63
+ off : function () {},
64
+
65
+ reflow : function () {}
66
+ };
67
+ }(jQuery, window, window.document));
@@ -0,0 +1,43 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.alert = {
5
+ name : 'alert',
6
+
7
+ version : '5.5.0',
8
+
9
+ settings : {
10
+ callback: function (){}
11
+ },
12
+
13
+ init : function (scope, method, options) {
14
+ this.bindings(method, options);
15
+ },
16
+
17
+ events : function () {
18
+ var self = this,
19
+ S = this.S;
20
+
21
+ $(this.scope).off('.alert').on('click.fndtn.alert', '[' + this.attr_name() + '] .close', function (e) {
22
+ var alertBox = S(this).closest('[' + self.attr_name() + ']'),
23
+ settings = alertBox.data(self.attr_name(true) + '-init') || self.settings;
24
+
25
+ e.preventDefault();
26
+ if (Modernizr.csstransitions) {
27
+ alertBox.addClass('alert-close');
28
+ alertBox.on('transitionend webkitTransitionEnd oTransitionEnd', function(e) {
29
+ S(this).trigger('close').trigger('close.fndtn.alert').remove();
30
+ settings.callback();
31
+ });
32
+ } else {
33
+ alertBox.fadeOut(300, function () {
34
+ S(this).trigger('close').trigger('close.fndtn.alert').remove();
35
+ settings.callback();
36
+ });
37
+ }
38
+ });
39
+ },
40
+
41
+ reflow : function () {}
42
+ };
43
+ }(jQuery, window, window.document));
@@ -0,0 +1,558 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.clearing = {
5
+ name : 'clearing',
6
+
7
+ version: '5.5.0',
8
+
9
+ settings : {
10
+ templates : {
11
+ viewing : '<a href="#" class="clearing-close">&times;</a>' +
12
+ '<div class="visible-img" style="display: none"><div class="clearing-touch-label"></div><img src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D" alt="" />' +
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, div.clearing-blackout',
20
+
21
+ // Default to the entire li element.
22
+ open_selectors : '',
23
+
24
+ // Image will be skipped in carousel.
25
+ skip_selector : '',
26
+
27
+ touch_label : '',
28
+
29
+ // event initializers and locks
30
+ init : false,
31
+ locked : false
32
+ },
33
+
34
+ init : function (scope, method, options) {
35
+ var self = this;
36
+ Foundation.inherit(this, 'throttle image_loaded');
37
+
38
+ this.bindings(method, options);
39
+
40
+ if (self.S(this.scope).is('[' + this.attr_name() + ']')) {
41
+ this.assemble(self.S('li', this.scope));
42
+ } else {
43
+ self.S('[' + this.attr_name() + ']', this.scope).each(function () {
44
+ self.assemble(self.S('li', this));
45
+ });
46
+ }
47
+ },
48
+
49
+ events : function (scope) {
50
+ var self = this,
51
+ S = self.S,
52
+ $scroll_container = $('.scroll-container');
53
+
54
+ if ($scroll_container.length > 0) {
55
+ this.scope = $scroll_container;
56
+ }
57
+
58
+ S(this.scope)
59
+ .off('.clearing')
60
+ .on('click.fndtn.clearing', 'ul[' + this.attr_name() + '] li ' + this.settings.open_selectors,
61
+ function (e, current, target) {
62
+ var current = current || S(this),
63
+ target = target || current,
64
+ next = current.next('li'),
65
+ settings = current.closest('[' + self.attr_name() + ']').data(self.attr_name(true) + '-init'),
66
+ image = S(e.target);
67
+
68
+ e.preventDefault();
69
+
70
+ if (!settings) {
71
+ self.init();
72
+ settings = current.closest('[' + self.attr_name() + ']').data(self.attr_name(true) + '-init');
73
+ }
74
+
75
+ // if clearing is open and the current image is
76
+ // clicked, go to the next image in sequence
77
+ if (target.hasClass('visible') &&
78
+ current[0] === target[0] &&
79
+ next.length > 0 && self.is_open(current)) {
80
+ target = next;
81
+ image = S('img', target);
82
+ }
83
+
84
+ // set current and target to the clicked li if not otherwise defined.
85
+ self.open(image, current, target);
86
+ self.update_paddles(target);
87
+ })
88
+
89
+ .on('click.fndtn.clearing', '.clearing-main-next',
90
+ function (e) { self.nav(e, 'next') })
91
+ .on('click.fndtn.clearing', '.clearing-main-prev',
92
+ function (e) { self.nav(e, 'prev') })
93
+ .on('click.fndtn.clearing', this.settings.close_selectors,
94
+ function (e) { Foundation.libs.clearing.close(e, this) });
95
+
96
+ $(document).on('keydown.fndtn.clearing',
97
+ function (e) { self.keydown(e) });
98
+
99
+ S(window).off('.clearing').on('resize.fndtn.clearing',
100
+ function () { self.resize() });
101
+
102
+ this.swipe_events(scope);
103
+ },
104
+
105
+ swipe_events : function (scope) {
106
+ var self = this,
107
+ S = self.S;
108
+
109
+ S(this.scope)
110
+ .on('touchstart.fndtn.clearing', '.visible-img', function(e) {
111
+ if (!e.touches) { e = e.originalEvent; }
112
+ var data = {
113
+ start_page_x: e.touches[0].pageX,
114
+ start_page_y: e.touches[0].pageY,
115
+ start_time: (new Date()).getTime(),
116
+ delta_x: 0,
117
+ is_scrolling: undefined
118
+ };
119
+
120
+ S(this).data('swipe-transition', data);
121
+ e.stopPropagation();
122
+ })
123
+ .on('touchmove.fndtn.clearing', '.visible-img', function(e) {
124
+ if (!e.touches) { e = e.originalEvent; }
125
+ // Ignore pinch/zoom events
126
+ if(e.touches.length > 1 || e.scale && e.scale !== 1) return;
127
+
128
+ var data = S(this).data('swipe-transition');
129
+
130
+ if (typeof data === 'undefined') {
131
+ data = {};
132
+ }
133
+
134
+ data.delta_x = e.touches[0].pageX - data.start_page_x;
135
+
136
+ if (Foundation.rtl) {
137
+ data.delta_x = -data.delta_x;
138
+ }
139
+
140
+ if (typeof data.is_scrolling === 'undefined') {
141
+ data.is_scrolling = !!( data.is_scrolling || Math.abs(data.delta_x) < Math.abs(e.touches[0].pageY - data.start_page_y) );
142
+ }
143
+
144
+ if (!data.is_scrolling && !data.active) {
145
+ e.preventDefault();
146
+ var direction = (data.delta_x < 0) ? 'next' : 'prev';
147
+ data.active = true;
148
+ self.nav(e, direction);
149
+ }
150
+ })
151
+ .on('touchend.fndtn.clearing', '.visible-img', function(e) {
152
+ S(this).data('swipe-transition', {});
153
+ e.stopPropagation();
154
+ });
155
+ },
156
+
157
+ assemble : function ($li) {
158
+ var $el = $li.parent();
159
+
160
+ if ($el.parent().hasClass('carousel')) {
161
+ return;
162
+ }
163
+
164
+ $el.after('<div id="foundationClearingHolder"></div>');
165
+
166
+ var grid = $el.detach(),
167
+ grid_outerHTML = '';
168
+
169
+ if (grid[0] == null) {
170
+ return;
171
+ } else {
172
+ grid_outerHTML = grid[0].outerHTML;
173
+ }
174
+
175
+ var holder = this.S('#foundationClearingHolder'),
176
+ settings = $el.data(this.attr_name(true) + '-init'),
177
+ data = {
178
+ grid: '<div class="carousel">' + grid_outerHTML + '</div>',
179
+ viewing: settings.templates.viewing
180
+ },
181
+ wrapper = '<div class="clearing-assembled"><div>' + data.viewing +
182
+ data.grid + '</div></div>',
183
+ touch_label = this.settings.touch_label;
184
+
185
+ if (Modernizr.touch) {
186
+ wrapper = $(wrapper).find('.clearing-touch-label').html(touch_label).end();
187
+ }
188
+
189
+ holder.after(wrapper).remove();
190
+ },
191
+
192
+ open : function ($image, current, target) {
193
+ var self = this,
194
+ body = $(document.body),
195
+ root = target.closest('.clearing-assembled'),
196
+ container = self.S('div', root).first(),
197
+ visible_image = self.S('.visible-img', container),
198
+ image = self.S('img', visible_image).not($image),
199
+ label = self.S('.clearing-touch-label', container),
200
+ error = false;
201
+
202
+ // Event to disable scrolling on touch devices when Clearing is activated
203
+ $('body').on('touchmove',function(e){
204
+ e.preventDefault();
205
+ });
206
+
207
+ image.error(function () {
208
+ error = true;
209
+ });
210
+
211
+ function startLoad() {
212
+ setTimeout(function () {
213
+ this.image_loaded(image, function () {
214
+ if (image.outerWidth() === 1 && !error) {
215
+ startLoad.call(this);
216
+ } else {
217
+ cb.call(this, image);
218
+ }
219
+ }.bind(this));
220
+ }.bind(this), 100);
221
+ }
222
+
223
+ function cb (image) {
224
+ var $image = $(image);
225
+ $image.css('visibility', 'visible');
226
+ // toggle the gallery
227
+ body.css('overflow', 'hidden');
228
+ root.addClass('clearing-blackout');
229
+ container.addClass('clearing-container');
230
+ visible_image.show();
231
+ this.fix_height(target)
232
+ .caption(self.S('.clearing-caption', visible_image), self.S('img', target))
233
+ .center_and_label(image, label)
234
+ .shift(current, target, function () {
235
+ target.closest('li').siblings().removeClass('visible');
236
+ target.closest('li').addClass('visible');
237
+ });
238
+ visible_image.trigger('opened.fndtn.clearing')
239
+ }
240
+
241
+ if (!this.locked()) {
242
+ visible_image.trigger('open.fndtn.clearing');
243
+ // set the image to the selected thumbnail
244
+ image
245
+ .attr('src', this.load($image))
246
+ .css('visibility', 'hidden');
247
+
248
+ startLoad.call(this);
249
+ }
250
+ },
251
+
252
+ close : function (e, el) {
253
+ e.preventDefault();
254
+
255
+ var root = (function (target) {
256
+ if (/blackout/.test(target.selector)) {
257
+ return target;
258
+ } else {
259
+ return target.closest('.clearing-blackout');
260
+ }
261
+ }($(el))),
262
+ body = $(document.body), container, visible_image;
263
+
264
+ if (el === e.target && root) {
265
+ body.css('overflow', '');
266
+ container = $('div', root).first();
267
+ visible_image = $('.visible-img', container);
268
+ visible_image.trigger('close.fndtn.clearing');
269
+ this.settings.prev_index = 0;
270
+ $('ul[' + this.attr_name() + ']', root)
271
+ .attr('style', '').closest('.clearing-blackout')
272
+ .removeClass('clearing-blackout');
273
+ container.removeClass('clearing-container');
274
+ visible_image.hide();
275
+ visible_image.trigger('closed.fndtn.clearing');
276
+ }
277
+
278
+ // Event to re-enable scrolling on touch devices
279
+ $('body').off('touchmove');
280
+
281
+ return false;
282
+ },
283
+
284
+ is_open : function (current) {
285
+ return current.parent().prop('style').length > 0;
286
+ },
287
+
288
+ keydown : function (e) {
289
+ var clearing = $('.clearing-blackout ul[' + this.attr_name() + ']'),
290
+ NEXT_KEY = this.rtl ? 37 : 39,
291
+ PREV_KEY = this.rtl ? 39 : 37,
292
+ ESC_KEY = 27;
293
+
294
+ if (e.which === NEXT_KEY) this.go(clearing, 'next');
295
+ if (e.which === PREV_KEY) this.go(clearing, 'prev');
296
+ if (e.which === ESC_KEY) this.S('a.clearing-close').trigger('click').trigger('click.fndtn.clearing');
297
+ },
298
+
299
+ nav : function (e, direction) {
300
+ var clearing = $('ul[' + this.attr_name() + ']', '.clearing-blackout');
301
+
302
+ e.preventDefault();
303
+ this.go(clearing, direction);
304
+ },
305
+
306
+ resize : function () {
307
+ var image = $('img', '.clearing-blackout .visible-img'),
308
+ label = $('.clearing-touch-label', '.clearing-blackout');
309
+
310
+ if (image.length) {
311
+ this.center_and_label(image, label);
312
+ image.trigger('resized.fndtn.clearing')
313
+ }
314
+ },
315
+
316
+ // visual adjustments
317
+ fix_height : function (target) {
318
+ var lis = target.parent().children(),
319
+ self = this;
320
+
321
+ lis.each(function () {
322
+ var li = self.S(this),
323
+ image = li.find('img');
324
+
325
+ if (li.height() > image.outerHeight()) {
326
+ li.addClass('fix-height');
327
+ }
328
+ })
329
+ .closest('ul')
330
+ .width(lis.length * 100 + '%');
331
+
332
+ return this;
333
+ },
334
+
335
+ update_paddles : function (target) {
336
+ target = target.closest('li');
337
+ var visible_image = target
338
+ .closest('.carousel')
339
+ .siblings('.visible-img');
340
+
341
+ if (target.next().length > 0) {
342
+ this.S('.clearing-main-next', visible_image).removeClass('disabled');
343
+ } else {
344
+ this.S('.clearing-main-next', visible_image).addClass('disabled');
345
+ }
346
+
347
+ if (target.prev().length > 0) {
348
+ this.S('.clearing-main-prev', visible_image).removeClass('disabled');
349
+ } else {
350
+ this.S('.clearing-main-prev', visible_image).addClass('disabled');
351
+ }
352
+ },
353
+
354
+ center_and_label : function (target, label) {
355
+ if (!this.rtl) {
356
+ target.css({
357
+ marginLeft : -(target.outerWidth() / 2),
358
+ marginTop : -(target.outerHeight() / 2)
359
+ });
360
+
361
+ if (label.length > 0) {
362
+ label.css({
363
+ marginLeft : -(label.outerWidth() / 2),
364
+ marginTop : -(target.outerHeight() / 2)-label.outerHeight()-10
365
+ });
366
+ }
367
+ } else {
368
+ target.css({
369
+ marginRight : -(target.outerWidth() / 2),
370
+ marginTop : -(target.outerHeight() / 2),
371
+ left: 'auto',
372
+ right: '50%'
373
+ });
374
+
375
+ if (label.length > 0) {
376
+ label.css({
377
+ marginRight : -(label.outerWidth() / 2),
378
+ marginTop : -(target.outerHeight() / 2)-label.outerHeight()-10,
379
+ left: 'auto',
380
+ right: '50%'
381
+ });
382
+ }
383
+ }
384
+ return this;
385
+ },
386
+
387
+ // image loading and preloading
388
+
389
+ load : function ($image) {
390
+ var href;
391
+
392
+ if ($image[0].nodeName === 'A') {
393
+ href = $image.attr('href');
394
+ } else {
395
+ href = $image.closest('a').attr('href');
396
+ }
397
+
398
+ this.preload($image);
399
+
400
+ if (href) return href;
401
+ return $image.attr('src');
402
+ },
403
+
404
+ preload : function ($image) {
405
+ this
406
+ .img($image.closest('li').next())
407
+ .img($image.closest('li').prev());
408
+ },
409
+
410
+ img : function (img) {
411
+ if (img.length) {
412
+ var new_img = new Image(),
413
+ new_a = this.S('a', img);
414
+
415
+ if (new_a.length) {
416
+ new_img.src = new_a.attr('href');
417
+ } else {
418
+ new_img.src = this.S('img', img).attr('src');
419
+ }
420
+ }
421
+ return this;
422
+ },
423
+
424
+ // image caption
425
+
426
+ caption : function (container, $image) {
427
+ var caption = $image.attr('data-caption');
428
+
429
+ if (caption) {
430
+ container
431
+ .html(caption)
432
+ .show();
433
+ } else {
434
+ container
435
+ .text('')
436
+ .hide();
437
+ }
438
+ return this;
439
+ },
440
+
441
+ // directional methods
442
+
443
+ go : function ($ul, direction) {
444
+ var current = this.S('.visible', $ul),
445
+ target = current[direction]();
446
+
447
+ // Check for skip selector.
448
+ if (this.settings.skip_selector && target.find(this.settings.skip_selector).length != 0) {
449
+ target = target[direction]();
450
+ }
451
+
452
+ if (target.length) {
453
+ this.S('img', target)
454
+ .trigger('click', [current, target]).trigger('click.fndtn.clearing', [current, target])
455
+ .trigger('change.fndtn.clearing');
456
+ }
457
+ },
458
+
459
+ shift : function (current, target, callback) {
460
+ var clearing = target.parent(),
461
+ old_index = this.settings.prev_index || target.index(),
462
+ direction = this.direction(clearing, current, target),
463
+ dir = this.rtl ? 'right' : 'left',
464
+ left = parseInt(clearing.css('left'), 10),
465
+ width = target.outerWidth(),
466
+ skip_shift;
467
+
468
+ var dir_obj = {};
469
+
470
+ // we use jQuery animate instead of CSS transitions because we
471
+ // need a callback to unlock the next animation
472
+ // needs support for RTL **
473
+ if (target.index() !== old_index && !/skip/.test(direction)){
474
+ if (/left/.test(direction)) {
475
+ this.lock();
476
+ dir_obj[dir] = left + width;
477
+ clearing.animate(dir_obj, 300, this.unlock());
478
+ } else if (/right/.test(direction)) {
479
+ this.lock();
480
+ dir_obj[dir] = left - width;
481
+ clearing.animate(dir_obj, 300, this.unlock());
482
+ }
483
+ } else if (/skip/.test(direction)) {
484
+ // the target image is not adjacent to the current image, so
485
+ // do we scroll right or not
486
+ skip_shift = target.index() - this.settings.up_count;
487
+ this.lock();
488
+
489
+ if (skip_shift > 0) {
490
+ dir_obj[dir] = -(skip_shift * width);
491
+ clearing.animate(dir_obj, 300, this.unlock());
492
+ } else {
493
+ dir_obj[dir] = 0;
494
+ clearing.animate(dir_obj, 300, this.unlock());
495
+ }
496
+ }
497
+
498
+ callback();
499
+ },
500
+
501
+ direction : function ($el, current, target) {
502
+ var lis = this.S('li', $el),
503
+ li_width = lis.outerWidth() + (lis.outerWidth() / 4),
504
+ up_count = Math.floor(this.S('.clearing-container').outerWidth() / li_width) - 1,
505
+ target_index = lis.index(target),
506
+ response;
507
+
508
+ this.settings.up_count = up_count;
509
+
510
+ if (this.adjacent(this.settings.prev_index, target_index)) {
511
+ if ((target_index > up_count) && target_index > this.settings.prev_index) {
512
+ response = 'right';
513
+ } else if ((target_index > up_count - 1) && target_index <= this.settings.prev_index) {
514
+ response = 'left';
515
+ } else {
516
+ response = false;
517
+ }
518
+ } else {
519
+ response = 'skip';
520
+ }
521
+
522
+ this.settings.prev_index = target_index;
523
+
524
+ return response;
525
+ },
526
+
527
+ adjacent : function (current_index, target_index) {
528
+ for (var i = target_index + 1; i >= target_index - 1; i--) {
529
+ if (i === current_index) return true;
530
+ }
531
+ return false;
532
+ },
533
+
534
+ // lock management
535
+
536
+ lock : function () {
537
+ this.settings.locked = true;
538
+ },
539
+
540
+ unlock : function () {
541
+ this.settings.locked = false;
542
+ },
543
+
544
+ locked : function () {
545
+ return this.settings.locked;
546
+ },
547
+
548
+ off : function () {
549
+ this.S(this.scope).off('.fndtn.clearing');
550
+ this.S(window).off('.fndtn.clearing');
551
+ },
552
+
553
+ reflow : function () {
554
+ this.init();
555
+ }
556
+ };
557
+
558
+ }(jQuery, window, window.document));