zurb-foundation-5 5.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.bowerrc +3 -0
  3. data/.editorconfig +9 -0
  4. data/.gitignore +46 -0
  5. data/.travis.yml +34 -0
  6. data/CONTRIBUTING.md +55 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +16 -0
  9. data/Gruntfile.js +222 -0
  10. data/LICENSE +22 -0
  11. data/README.md +44 -0
  12. data/bower.json +20 -0
  13. data/composer.json +9 -0
  14. data/foundation.gemspec +21 -0
  15. data/humans.txt +8 -0
  16. data/js/foundation/foundation.abide.js +299 -0
  17. data/js/foundation/foundation.accordion.js +54 -0
  18. data/js/foundation/foundation.alert.js +43 -0
  19. data/js/foundation/foundation.clearing.js +531 -0
  20. data/js/foundation/foundation.dropdown.js +306 -0
  21. data/js/foundation/foundation.equalizer.js +68 -0
  22. data/js/foundation/foundation.interchange.js +331 -0
  23. data/js/foundation/foundation.joyride.js +849 -0
  24. data/js/foundation/foundation.js +609 -0
  25. data/js/foundation/foundation.magellan.js +173 -0
  26. data/js/foundation/foundation.offcanvas.js +50 -0
  27. data/js/foundation/foundation.orbit.js +606 -0
  28. data/js/foundation/foundation.reveal.js +427 -0
  29. data/js/foundation/foundation.slider.js +200 -0
  30. data/js/foundation/foundation.tab.js +168 -0
  31. data/js/foundation/foundation.tooltip.js +272 -0
  32. data/js/foundation/foundation.topbar.js +422 -0
  33. data/karma.conf.js +114 -0
  34. data/lib/foundation/engine.rb +20 -0
  35. data/lib/foundation/generators/USAGE +15 -0
  36. data/lib/foundation/generators/install_generator.rb +54 -0
  37. data/lib/foundation/generators/templates/application.html.erb +47 -0
  38. data/lib/foundation/generators/templates/application.html.haml +31 -0
  39. data/lib/foundation/generators/templates/application.html.slim +35 -0
  40. data/lib/foundation/sprockets.rb +4 -0
  41. data/lib/foundation/version.rb +3 -0
  42. data/lib/scss.js +114 -0
  43. data/lib/zurb-foundation.rb +33 -0
  44. data/package.json +48 -0
  45. data/robots.txt +4 -0
  46. data/run-tests.sh +83 -0
  47. data/sache.json +5 -0
  48. data/scss/foundation.scss +45 -0
  49. data/scss/foundation/_functions.scss +101 -0
  50. data/scss/foundation/_settings.scss +1279 -0
  51. data/scss/foundation/components/_accordion.scss +52 -0
  52. data/scss/foundation/components/_alert-boxes.scss +126 -0
  53. data/scss/foundation/components/_block-grid.scss +132 -0
  54. data/scss/foundation/components/_breadcrumbs.scss +127 -0
  55. data/scss/foundation/components/_button-groups.scss +108 -0
  56. data/scss/foundation/components/_buttons.scss +222 -0
  57. data/scss/foundation/components/_clearing.scss +247 -0
  58. data/scss/foundation/components/_dropdown-buttons.scss +129 -0
  59. data/scss/foundation/components/_dropdown.scss +248 -0
  60. data/scss/foundation/components/_flex-video.scss +51 -0
  61. data/scss/foundation/components/_forms.scss +496 -0
  62. data/scss/foundation/components/_global.scss +365 -0
  63. data/scss/foundation/components/_grid.scss +261 -0
  64. data/scss/foundation/components/_inline-lists.scss +56 -0
  65. data/scss/foundation/components/_joyride.scss +220 -0
  66. data/scss/foundation/components/_keystrokes.scss +61 -0
  67. data/scss/foundation/components/_labels.scss +104 -0
  68. data/scss/foundation/components/_magellan.scss +34 -0
  69. data/scss/foundation/components/_offcanvas.scss +381 -0
  70. data/scss/foundation/components/_orbit.scss +415 -0
  71. data/scss/foundation/components/_pagination.scss +150 -0
  72. data/scss/foundation/components/_panels.scss +91 -0
  73. data/scss/foundation/components/_pricing-tables.scss +150 -0
  74. data/scss/foundation/components/_progress-bars.scss +79 -0
  75. data/scss/foundation/components/_range-slider.scss +148 -0
  76. data/scss/foundation/components/_reveal-new.scss +0 -0
  77. data/scss/foundation/components/_reveal.scss +216 -0
  78. data/scss/foundation/components/_side-nav.scss +93 -0
  79. data/scss/foundation/components/_split-buttons.scss +191 -0
  80. data/scss/foundation/components/_sub-nav.scss +125 -0
  81. data/scss/foundation/components/_switch.scss +294 -0
  82. data/scss/foundation/components/_tables.scss +97 -0
  83. data/scss/foundation/components/_tabs.scss +105 -0
  84. data/scss/foundation/components/_thumbs.scss +68 -0
  85. data/scss/foundation/components/_tooltips.scss +140 -0
  86. data/scss/foundation/components/_top-bar.scss +640 -0
  87. data/scss/foundation/components/_type.scss +493 -0
  88. data/scss/foundation/components/_visibility.scss +345 -0
  89. data/scss/foundation/test.html +0 -0
  90. data/scss/normalize.scss +423 -0
  91. data/spec/abide/abide.js +173 -0
  92. data/spec/abide/advanced.html +22 -0
  93. data/spec/abide/basic.html +13 -0
  94. data/spec/accordion/accordion.js +94 -0
  95. data/spec/accordion/basic.html +39 -0
  96. data/spec/accordion/grid.html +44 -0
  97. data/spec/accordion/multiexpand.html +20 -0
  98. data/spec/alert/alert.js +35 -0
  99. data/spec/alert/basic.html +4 -0
  100. data/spec/clearing/222.gif +0 -0
  101. data/spec/clearing/777.gif +0 -0
  102. data/spec/clearing/basic.html +5 -0
  103. data/spec/clearing/ccc.gif +0 -0
  104. data/spec/clearing/clearing.js +55 -0
  105. data/spec/dropdown/basic.html +10 -0
  106. data/spec/dropdown/dropdown.js +65 -0
  107. data/spec/equalizer/basic.html +24 -0
  108. data/spec/equalizer/equalizer.js +30 -0
  109. data/spec/framework/framework.js +14 -0
  110. data/spec/helpers.js +37 -0
  111. data/spec/interchange/basic.html +3 -0
  112. data/spec/interchange/interchange.js +60 -0
  113. data/spec/joyride/joyride.js +14 -0
  114. data/spec/magellan/magellan.js +14 -0
  115. data/spec/offcanvas/offcanvas.js +14 -0
  116. data/spec/orbit/orbit.js +14 -0
  117. data/spec/reveal/reveal.js +14 -0
  118. data/spec/tab/tab.js +14 -0
  119. data/spec/tooltip/tooltip.js +14 -0
  120. data/spec/topbar/multidropdown.html +60 -0
  121. data/spec/topbar/sticky.html +31 -0
  122. data/spec/topbar/topbar.js +96 -0
  123. metadata +238 -0
@@ -0,0 +1,306 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.dropdown = {
5
+ name : 'dropdown',
6
+
7
+ version : '5.2.2',
8
+
9
+ settings : {
10
+ active_class: 'open',
11
+ align: 'bottom',
12
+ is_hover: false,
13
+ opened: function(){},
14
+ closed: function(){}
15
+ },
16
+
17
+ init : function (scope, method, options) {
18
+ Foundation.inherit(this, 'throttle');
19
+
20
+ this.bindings(method, options);
21
+ },
22
+
23
+ events : function (scope) {
24
+ var self = this,
25
+ S = self.S;
26
+
27
+ S(this.scope)
28
+ .off('.dropdown')
29
+ .on('click.fndtn.dropdown', '[' + this.attr_name() + ']', function (e) {
30
+ var settings = S(this).data(self.attr_name(true) + '-init') || self.settings;
31
+ if (!settings.is_hover || Modernizr.touch) {
32
+ e.preventDefault();
33
+ self.toggle($(this));
34
+ }
35
+ })
36
+ .on('mouseenter.fndtn.dropdown', '[' + this.attr_name() + '], [' + this.attr_name() + '-content]', function (e) {
37
+ var $this = S(this);
38
+ clearTimeout(self.timeout);
39
+
40
+ if ($this.data(self.data_attr())) {
41
+ var dropdown = S('#' + $this.data(self.data_attr())),
42
+ target = $this;
43
+ } else {
44
+ var dropdown = $this;
45
+ target = S("[" + self.attr_name() + "='" + dropdown.attr('id') + "']");
46
+ }
47
+
48
+ var settings = target.data(self.attr_name(true) + '-init') || self.settings;
49
+
50
+ if(S(e.target).data(self.data_attr()) && settings.is_hover) {
51
+ self.closeall.call(self);
52
+ }
53
+
54
+ if (settings.is_hover) self.open.apply(self, [dropdown, target]);
55
+ })
56
+ .on('mouseleave.fndtn.dropdown', '[' + this.attr_name() + '], [' + this.attr_name() + '-content]', function (e) {
57
+ var $this = S(this);
58
+ self.timeout = setTimeout(function () {
59
+ if ($this.data(self.data_attr())) {
60
+ var settings = $this.data(self.data_attr(true) + '-init') || self.settings;
61
+ if (settings.is_hover) self.close.call(self, S('#' + $this.data(self.data_attr())));
62
+ } else {
63
+ var target = S('[' + self.attr_name() + '="' + S(this).attr('id') + '"]'),
64
+ settings = target.data(self.attr_name(true) + '-init') || self.settings;
65
+ if (settings.is_hover) self.close.call(self, $this);
66
+ }
67
+ }.bind(this), 150);
68
+ })
69
+ .on('click.fndtn.dropdown', function (e) {
70
+ var parent = S(e.target).closest('[' + self.attr_name() + '-content]');
71
+
72
+ if (S(e.target).data(self.data_attr()) || S(e.target).parent().data(self.data_attr())) {
73
+ return;
74
+ }
75
+ if (!(S(e.target).data('revealId')) &&
76
+ (parent.length > 0 && (S(e.target).is('[' + self.attr_name() + '-content]') ||
77
+ $.contains(parent.first()[0], e.target)))) {
78
+ e.stopPropagation();
79
+ return;
80
+ }
81
+
82
+ self.close.call(self, S('[' + self.attr_name() + '-content]'));
83
+ })
84
+ .on('opened.fndtn.dropdown', '[' + self.attr_name() + '-content]', function () {
85
+ self.settings.opened.call(this);
86
+ })
87
+ .on('closed.fndtn.dropdown', '[' + self.attr_name() + '-content]', function () {
88
+ self.settings.closed.call(this);
89
+ });
90
+
91
+ S(window)
92
+ .off('.dropdown')
93
+ .on('resize.fndtn.dropdown', self.throttle(function () {
94
+ self.resize.call(self);
95
+ }, 50));
96
+
97
+ this.resize();
98
+ },
99
+
100
+ close: function (dropdown) {
101
+ var self = this;
102
+ dropdown.each(function () {
103
+ if (self.S(this).hasClass(self.settings.active_class)) {
104
+ self.S(this)
105
+ .css(Foundation.rtl ? 'right':'left', '-99999px')
106
+ .removeClass(self.settings.active_class)
107
+ .prev('[' + self.attr_name() + ']')
108
+ .removeClass(self.settings.active_class);
109
+
110
+ self.S(this).trigger('closed', [dropdown]);
111
+ }
112
+ });
113
+ },
114
+
115
+ closeall: function() {
116
+ var self = this;
117
+ $.each(self.S('[' + this.attr_name() + '-content]'), function() {
118
+ self.close.call(self, self.S(this))
119
+ });
120
+ },
121
+
122
+ open: function (dropdown, target) {
123
+ this
124
+ .css(dropdown
125
+ .addClass(this.settings.active_class), target);
126
+ dropdown.prev('[' + this.attr_name() + ']').addClass(this.settings.active_class);
127
+ dropdown.trigger('opened', [dropdown, target]);
128
+ },
129
+
130
+ data_attr: function () {
131
+ if (this.namespace.length > 0) {
132
+ return this.namespace + '-' + this.name;
133
+ }
134
+
135
+ return this.name;
136
+ },
137
+
138
+ toggle : function (target) {
139
+ var dropdown = this.S('#' + target.data(this.data_attr()));
140
+ if (dropdown.length === 0) {
141
+ // No dropdown found, not continuing
142
+ return;
143
+ }
144
+
145
+ this.close.call(this, this.S('[' + this.attr_name() + '-content]').not(dropdown));
146
+
147
+ if (dropdown.hasClass(this.settings.active_class)) {
148
+ this.close.call(this, dropdown);
149
+ } else {
150
+ this.close.call(this, this.S('[' + this.attr_name() + '-content]'))
151
+ this.open.call(this, dropdown, target);
152
+ }
153
+ },
154
+
155
+ resize : function () {
156
+ var dropdown = this.S('[' + this.attr_name() + '-content].open'),
157
+ target = this.S("[" + this.attr_name() + "='" + dropdown.attr('id') + "']");
158
+
159
+ if (dropdown.length && target.length) {
160
+ this.css(dropdown, target);
161
+ }
162
+ },
163
+
164
+ css : function (dropdown, target) {
165
+ this.clear_idx();
166
+
167
+ if (this.small()) {
168
+ var p = this.dirs.bottom.call(dropdown, target);
169
+
170
+ dropdown.attr('style', '').removeClass('drop-left drop-right drop-top').css({
171
+ position : 'absolute',
172
+ width: '95%',
173
+ 'max-width': 'none',
174
+ top: p.top
175
+ });
176
+
177
+ dropdown.css(Foundation.rtl ? 'right':'left', '2.5%');
178
+ } else {
179
+ var settings = target.data(this.attr_name(true) + '-init') || this.settings;
180
+
181
+ this.style(dropdown, target, settings);
182
+ }
183
+
184
+ return dropdown;
185
+ },
186
+
187
+ style : function (dropdown, target, settings) {
188
+ var css = $.extend({position: 'absolute'},
189
+ this.dirs[settings.align].call(dropdown, target, settings));
190
+
191
+ dropdown.attr('style', '').css(css);
192
+ },
193
+
194
+ // return CSS property object
195
+ // `this` is the dropdown
196
+ dirs : {
197
+ // Calculate target offset
198
+ _base : function (t) {
199
+ var o_p = this.offsetParent(),
200
+ o = o_p.offset(),
201
+ p = t.offset();
202
+
203
+ p.top -= o.top;
204
+ p.left -= o.left;
205
+
206
+ return p;
207
+ },
208
+ top: function (t, s) {
209
+ var self = Foundation.libs.dropdown,
210
+ p = self.dirs._base.call(this, t),
211
+ pip_offset_base = (t.outerWidth() / 2) - 8;
212
+
213
+ this.addClass('drop-top');
214
+
215
+ if (t.outerWidth() < this.outerWidth() || self.small()) {
216
+ self.adjust_pip(pip_offset_base, p);
217
+ }
218
+
219
+ if (Foundation.rtl) {
220
+ return {left: p.left - this.outerWidth() + t.outerWidth(),
221
+ top: p.top - this.outerHeight()};
222
+ }
223
+
224
+ return {left: p.left, top: p.top - this.outerHeight()};
225
+ },
226
+ bottom: function (t, s) {
227
+ var self = Foundation.libs.dropdown,
228
+ p = self.dirs._base.call(this, t),
229
+ pip_offset_base = (t.outerWidth() / 2) - 8;
230
+
231
+ if (t.outerWidth() < this.outerWidth() || self.small()) {
232
+ self.adjust_pip(pip_offset_base, p);
233
+ }
234
+
235
+ if (self.rtl) {
236
+ return {left: p.left - this.outerWidth() + t.outerWidth(), top: p.top + t.outerHeight()};
237
+ }
238
+
239
+ return {left: p.left, top: p.top + t.outerHeight()};
240
+ },
241
+ left: function (t, s) {
242
+ var p = Foundation.libs.dropdown.dirs._base.call(this, t);
243
+
244
+ this.addClass('drop-left');
245
+
246
+ return {left: p.left - this.outerWidth(), top: p.top};
247
+ },
248
+ right: function (t, s) {
249
+ var p = Foundation.libs.dropdown.dirs._base.call(this, t);
250
+
251
+ this.addClass('drop-right');
252
+
253
+ return {left: p.left + t.outerWidth(), top: p.top};
254
+ }
255
+ },
256
+
257
+ // Insert rule to style psuedo elements
258
+ adjust_pip : function (pip_offset_base, p) {
259
+ var sheet = Foundation.stylesheet;
260
+
261
+ if (this.small()) {
262
+ pip_offset_base += p.left - 8;
263
+ }
264
+
265
+ this.rule_idx = sheet.cssRules.length;
266
+
267
+ var sel_before = '.f-dropdown.open:before',
268
+ sel_after = '.f-dropdown.open:after',
269
+ css_before = 'left: ' + pip_offset_base + 'px;',
270
+ css_after = 'left: ' + (pip_offset_base - 1) + 'px;';
271
+
272
+ if (sheet.insertRule) {
273
+ sheet.insertRule([sel_before, '{', css_before, '}'].join(' '), this.rule_idx);
274
+ sheet.insertRule([sel_after, '{', css_after, '}'].join(' '), this.rule_idx + 1);
275
+ } else {
276
+ sheet.addRule(sel_before, css_before, this.rule_idx);
277
+ sheet.addRule(sel_after, css_after, this.rule_idx + 1);
278
+ }
279
+ },
280
+
281
+ // Remove old dropdown rule index
282
+ clear_idx : function () {
283
+ var sheet = Foundation.stylesheet;
284
+
285
+ if (this.rule_idx) {
286
+ sheet.deleteRule(this.rule_idx);
287
+ sheet.deleteRule(this.rule_idx);
288
+ delete this.rule_idx;
289
+ }
290
+ },
291
+
292
+ small : function () {
293
+ return matchMedia(Foundation.media_queries.small).matches &&
294
+ !matchMedia(Foundation.media_queries.medium).matches;
295
+ },
296
+
297
+ off: function () {
298
+ this.S(this.scope).off('.fndtn.dropdown');
299
+ this.S('html, body').off('.fndtn.dropdown');
300
+ this.S(window).off('.fndtn.dropdown');
301
+ this.S('[data-dropdown-content]').off('.fndtn.dropdown');
302
+ },
303
+
304
+ reflow : function () {}
305
+ };
306
+ }(jQuery, this, this.document));
@@ -0,0 +1,68 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.equalizer = {
5
+ name : 'equalizer',
6
+
7
+ version : '5.2.2',
8
+
9
+ settings : {
10
+ use_tallest: true,
11
+ before_height_change: $.noop,
12
+ after_height_change: $.noop
13
+ },
14
+
15
+ init : function (scope, method, options) {
16
+ Foundation.inherit(this, 'image_loaded');
17
+ this.bindings(method, options);
18
+ this.reflow();
19
+ },
20
+
21
+ events : function () {
22
+ this.S(window).off('.equalizer').on('resize.fndtn.equalizer', function(e){
23
+ this.reflow();
24
+ }.bind(this));
25
+ },
26
+
27
+ equalize: function(equalizer) {
28
+ var isStacked = false,
29
+ vals = equalizer.find('[' + this.attr_name() + '-watch]:visible'),
30
+ firstTopOffset = vals.first().offset().top,
31
+ settings = equalizer.data(this.attr_name(true)+'-init');
32
+
33
+ if (vals.length === 0) return;
34
+ settings.before_height_change();
35
+ equalizer.trigger('before-height-change');
36
+ vals.height('inherit');
37
+ vals.each(function(){
38
+ var el = $(this);
39
+ if (el.offset().top !== firstTopOffset) {
40
+ isStacked = true;
41
+ }
42
+ });
43
+ if (isStacked) return;
44
+
45
+ var heights = vals.map(function(){ return $(this).outerHeight() }).get();
46
+ if (settings.use_tallest) {
47
+ var max = Math.max.apply(null, heights);
48
+ vals.css('height', max);
49
+ } else {
50
+ var min = Math.min.apply(null, heights);
51
+ vals.css('height', min);
52
+ }
53
+ settings.after_height_change();
54
+ equalizer.trigger('after-height-change');
55
+ },
56
+
57
+ reflow : function () {
58
+ var self = this;
59
+
60
+ this.S('[' + this.attr_name() + ']', this.scope).each(function(){
61
+ var $eq_target = $(this);
62
+ self.image_loaded(self.S('img', this), function(){
63
+ self.equalize($eq_target)
64
+ });
65
+ });
66
+ }
67
+ };
68
+ }(jQuery, this, this.document));
@@ -0,0 +1,331 @@
1
+ ;(function ($, window, document, undefined) {
2
+ 'use strict';
3
+
4
+ Foundation.libs.interchange = {
5
+ name : 'interchange',
6
+
7
+ version : '5.2.2',
8
+
9
+ cache : {},
10
+
11
+ images_loaded : false,
12
+ nodes_loaded : false,
13
+
14
+ settings : {
15
+ load_attr : 'interchange',
16
+
17
+ named_queries : {
18
+ 'default' : 'only screen',
19
+ small : Foundation.media_queries.small,
20
+ medium : Foundation.media_queries.medium,
21
+ large : Foundation.media_queries.large,
22
+ xlarge : Foundation.media_queries.xlarge,
23
+ xxlarge: Foundation.media_queries.xxlarge,
24
+ landscape : 'only screen and (orientation: landscape)',
25
+ portrait : 'only screen and (orientation: portrait)',
26
+ retina : 'only screen and (-webkit-min-device-pixel-ratio: 2),' +
27
+ 'only screen and (min--moz-device-pixel-ratio: 2),' +
28
+ 'only screen and (-o-min-device-pixel-ratio: 2/1),' +
29
+ 'only screen and (min-device-pixel-ratio: 2),' +
30
+ 'only screen and (min-resolution: 192dpi),' +
31
+ 'only screen and (min-resolution: 2dppx)'
32
+ },
33
+
34
+ directives : {
35
+ replace: function (el, path, trigger) {
36
+ // The trigger argument, if called within the directive, fires
37
+ // an event named after the directive on the element, passing
38
+ // any parameters along to the event that you pass to trigger.
39
+ //
40
+ // ex. trigger(), trigger([a, b, c]), or trigger(a, b, c)
41
+ //
42
+ // This allows you to bind a callback like so:
43
+ // $('#interchangeContainer').on('replace', function (e, a, b, c) {
44
+ // console.log($(this).html(), a, b, c);
45
+ // });
46
+
47
+ if (/IMG/.test(el[0].nodeName)) {
48
+ var orig_path = el[0].src;
49
+
50
+ if (new RegExp(path, 'i').test(orig_path)) return;
51
+
52
+ el[0].src = path;
53
+
54
+ return trigger(el[0].src);
55
+ }
56
+ var last_path = el.data(this.data_attr + '-last-path');
57
+
58
+ if (last_path == path) return;
59
+
60
+ if (/\.(gif|jpg|jpeg|tiff|png)([?#].*)?/i.test(path)) {
61
+ $(el).css('background-image', 'url('+path+')');
62
+ el.data('interchange-last-path', path);
63
+ return trigger(path);
64
+ }
65
+
66
+ return $.get(path, function (response) {
67
+ el.html(response);
68
+ el.data(this.data_attr + '-last-path', path);
69
+ trigger();
70
+ });
71
+
72
+ }
73
+ }
74
+ },
75
+
76
+ init : function (scope, method, options) {
77
+ Foundation.inherit(this, 'throttle random_str');
78
+
79
+ this.data_attr = this.set_data_attr();
80
+ $.extend(true, this.settings, method, options);
81
+ this.bindings(method, options);
82
+ this.load('images');
83
+ this.load('nodes');
84
+ },
85
+
86
+ get_media_hash : function() {
87
+ var mediaHash='';
88
+ for (var queryName in this.settings.named_queries ) {
89
+ mediaHash += matchMedia(this.settings.named_queries[queryName]).matches.toString();
90
+ }
91
+ return mediaHash;
92
+ },
93
+
94
+ events : function () {
95
+ var self = this, prevMediaHash;
96
+
97
+ $(window)
98
+ .off('.interchange')
99
+ .on('resize.fndtn.interchange', self.throttle(function () {
100
+ var currMediaHash = self.get_media_hash();
101
+ if (currMediaHash !== prevMediaHash) {
102
+ self.resize();
103
+ }
104
+ prevMediaHash = currMediaHash;
105
+ }, 50));
106
+
107
+ return this;
108
+ },
109
+
110
+ resize : function () {
111
+ var cache = this.cache;
112
+
113
+ if(!this.images_loaded || !this.nodes_loaded) {
114
+ setTimeout($.proxy(this.resize, this), 50);
115
+ return;
116
+ }
117
+
118
+ for (var uuid in cache) {
119
+ if (cache.hasOwnProperty(uuid)) {
120
+ var passed = this.results(uuid, cache[uuid]);
121
+
122
+ if (passed) {
123
+ this.settings.directives[passed
124
+ .scenario[1]].call(this, passed.el, passed.scenario[0], function () {
125
+ if (arguments[0] instanceof Array) {
126
+ var args = arguments[0];
127
+ } else {
128
+ var args = Array.prototype.slice.call(arguments, 0);
129
+ }
130
+
131
+ passed.el.trigger(passed.scenario[1], args);
132
+ });
133
+ }
134
+ }
135
+ }
136
+
137
+ },
138
+
139
+ results : function (uuid, scenarios) {
140
+ var count = scenarios.length;
141
+
142
+ if (count > 0) {
143
+ var el = this.S('[' + this.add_namespace('data-uuid') + '="' + uuid + '"]');
144
+
145
+ while (count--) {
146
+ var mq, rule = scenarios[count][2];
147
+ if (this.settings.named_queries.hasOwnProperty(rule)) {
148
+ mq = matchMedia(this.settings.named_queries[rule]);
149
+ } else {
150
+ mq = matchMedia(rule);
151
+ }
152
+ if (mq.matches) {
153
+ return {el: el, scenario: scenarios[count]};
154
+ }
155
+ }
156
+ }
157
+
158
+ return false;
159
+ },
160
+
161
+ load : function (type, force_update) {
162
+ if (typeof this['cached_' + type] === 'undefined' || force_update) {
163
+ this['update_' + type]();
164
+ }
165
+
166
+ return this['cached_' + type];
167
+ },
168
+
169
+ update_images : function () {
170
+ var images = this.S('img[' + this.data_attr + ']'),
171
+ count = images.length,
172
+ i = count,
173
+ loaded_count = 0,
174
+ data_attr = this.data_attr;
175
+
176
+ this.cache = {};
177
+ this.cached_images = [];
178
+ this.images_loaded = (count === 0);
179
+
180
+ while (i--) {
181
+ loaded_count++;
182
+ if (images[i]) {
183
+ var str = images[i].getAttribute(data_attr) || '';
184
+
185
+ if (str.length > 0) {
186
+ this.cached_images.push(images[i]);
187
+ }
188
+ }
189
+
190
+ if (loaded_count === count) {
191
+ this.images_loaded = true;
192
+ this.enhance('images');
193
+ }
194
+ }
195
+
196
+ return this;
197
+ },
198
+
199
+ update_nodes : function () {
200
+ var nodes = this.S('[' + this.data_attr + ']').not('img'),
201
+ count = nodes.length,
202
+ i = count,
203
+ loaded_count = 0,
204
+ data_attr = this.data_attr;
205
+
206
+ this.cached_nodes = [];
207
+ this.nodes_loaded = (count === 0);
208
+
209
+
210
+ while (i--) {
211
+ loaded_count++;
212
+ var str = nodes[i].getAttribute(data_attr) || '';
213
+
214
+ if (str.length > 0) {
215
+ this.cached_nodes.push(nodes[i]);
216
+ }
217
+
218
+ if(loaded_count === count) {
219
+ this.nodes_loaded = true;
220
+ this.enhance('nodes');
221
+ }
222
+ }
223
+
224
+ return this;
225
+ },
226
+
227
+ enhance : function (type) {
228
+ var i = this['cached_' + type].length;
229
+
230
+ while (i--) {
231
+ this.object($(this['cached_' + type][i]));
232
+ }
233
+
234
+ return $(window).trigger('resize');
235
+ },
236
+
237
+ parse_params : function (path, directive, mq) {
238
+ return [this.trim(path), this.convert_directive(directive), this.trim(mq)];
239
+ },
240
+
241
+ convert_directive : function (directive) {
242
+
243
+ var trimmed = this.trim(directive);
244
+
245
+ if (trimmed.length > 0) {
246
+ return trimmed;
247
+ }
248
+
249
+ return 'replace';
250
+ },
251
+
252
+ object : function(el) {
253
+ var raw_arr = this.parse_data_attr(el),
254
+ scenarios = [],
255
+ i = raw_arr.length;
256
+
257
+ if (i > 0) {
258
+ while (i--) {
259
+ var split = raw_arr[i].split(/\((.*?)(\))$/);
260
+
261
+ if (split.length > 1) {
262
+ var cached_split = split[0].split(','),
263
+ params = this.parse_params(cached_split[0],
264
+ cached_split[1], split[1]);
265
+
266
+ scenarios.push(params);
267
+ }
268
+ }
269
+ }
270
+
271
+ return this.store(el, scenarios);
272
+ },
273
+
274
+ store : function (el, scenarios) {
275
+ var uuid = this.random_str(),
276
+ current_uuid = el.data(this.add_namespace('uuid', true));
277
+
278
+ if (this.cache[current_uuid]) return this.cache[current_uuid];
279
+
280
+ el.attr(this.add_namespace('data-uuid'), uuid);
281
+
282
+ return this.cache[uuid] = scenarios;
283
+ },
284
+
285
+ trim : function(str) {
286
+
287
+ if (typeof str === 'string') {
288
+ return $.trim(str);
289
+ }
290
+
291
+ return str;
292
+ },
293
+
294
+ set_data_attr: function (init) {
295
+ if (init) {
296
+ if (this.namespace.length > 0) {
297
+ return this.namespace + '-' + this.settings.load_attr;
298
+ }
299
+
300
+ return this.settings.load_attr;
301
+ }
302
+
303
+ if (this.namespace.length > 0) {
304
+ return 'data-' + this.namespace + '-' + this.settings.load_attr;
305
+ }
306
+
307
+ return 'data-' + this.settings.load_attr;
308
+ },
309
+
310
+ parse_data_attr : function (el) {
311
+ var raw = el.attr(this.attr_name()).split(/\[(.*?)\]/),
312
+ i = raw.length,
313
+ output = [];
314
+
315
+ while (i--) {
316
+ if (raw[i].replace(/[\W\d]+/, '').length > 4) {
317
+ output.push(raw[i]);
318
+ }
319
+ }
320
+
321
+ return output;
322
+ },
323
+
324
+ reflow : function () {
325
+ this.load('images', true);
326
+ this.load('nodes', true);
327
+ }
328
+
329
+ };
330
+
331
+ }(jQuery, this, this.document));