volt-foundation 0.0.3 → 0.0.4

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.
@@ -1,558 +0,0 @@
1
- ;(function ($, window, document, undefined) {
2
- 'use strict';
3
-
4
- Foundation.libs.clearing = {
5
- name : 'clearing',
6
-
7
- version: '5.4.6',
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.parent().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));