foundation-rails 6.4.1.0 → 6.4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Rakefile +5 -6
- data/lib/foundation/rails/version.rb +1 -1
- data/vendor/assets/js/foundation.abide.js +781 -0
- data/vendor/assets/js/foundation.accordion.js +511 -0
- data/vendor/assets/js/foundation.accordionMenu.js +527 -0
- data/vendor/assets/js/foundation.core.js +860 -0
- data/vendor/assets/js/foundation.drilldown.js +759 -0
- data/vendor/assets/js/foundation.dropdown.js +1131 -0
- data/vendor/assets/js/foundation.dropdownMenu.js +678 -0
- data/vendor/assets/js/foundation.equalizer.js +542 -0
- data/vendor/assets/js/foundation.interchange.js +399 -0
- data/vendor/assets/js/{foundation.js.es6 → foundation.js} +11 -12
- data/vendor/assets/js/foundation.magellan.js +449 -0
- data/vendor/assets/js/foundation.offcanvas.js +1052 -0
- data/vendor/assets/js/foundation.orbit.js +767 -0
- data/vendor/assets/js/foundation.responsiveAccordionTabs.js +440 -0
- data/vendor/assets/js/foundation.responsiveMenu.js +362 -0
- data/vendor/assets/js/foundation.responsiveToggle.js +336 -0
- data/vendor/assets/js/foundation.reveal.js +1066 -0
- data/vendor/assets/js/foundation.slider.js +1236 -0
- data/vendor/assets/js/foundation.smoothScroll.js +303 -0
- data/vendor/assets/js/foundation.sticky.js +1001 -0
- data/vendor/assets/js/foundation.tabs.js +678 -0
- data/vendor/assets/js/foundation.toggler.js +602 -0
- data/vendor/assets/js/foundation.tooltip.js +1195 -0
- data/vendor/assets/js/{foundation.util.box.js.es6 → foundation.util.box.js} +154 -41
- data/vendor/assets/js/foundation.util.imageLoader.js +163 -0
- data/vendor/assets/js/foundation.util.keyboard.js +298 -0
- data/vendor/assets/js/foundation.util.mediaQuery.js +353 -0
- data/vendor/assets/js/foundation.util.motion.js +231 -0
- data/vendor/assets/js/foundation.util.nest.js +181 -0
- data/vendor/assets/js/foundation.util.timer.js +170 -0
- data/vendor/assets/js/foundation.util.timerAndImageLoader.js +90 -0
- data/vendor/assets/js/foundation.util.touch.js +275 -0
- data/vendor/assets/js/foundation.util.triggers.js +399 -0
- data/vendor/assets/js/foundation.zf.responsiveAccordionTabs.js +262 -0
- metadata +37 -71
- data/vendor/assets/js/entries/foundation-plugins.js +0 -25
- data/vendor/assets/js/entries/foundation.js +0 -101
- data/vendor/assets/js/entries/plugins/foundation.abide.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.accordion.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.accordionMenu.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.core.js +0 -21
- data/vendor/assets/js/entries/plugins/foundation.drilldown.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.dropdown.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.dropdownMenu.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.equalizer.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.interchange.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.magellan.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.offcanvas.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.orbit.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.responsiveAccordionTabs.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.responsiveMenu.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.responsiveToggle.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.reveal.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.slider.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.smoothScroll.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.sticky.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.tabs.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.toggler.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.tooltip.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.util.box.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.util.imageLoader.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.util.keyboard.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.util.mediaQuery.js +0 -4
- data/vendor/assets/js/entries/plugins/foundation.util.motion.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.util.nest.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.util.timer.js +0 -5
- data/vendor/assets/js/entries/plugins/foundation.util.touch.js +0 -7
- data/vendor/assets/js/entries/plugins/foundation.util.triggers.js +0 -5
- data/vendor/assets/js/foundation.abide.js.es6 +0 -587
- data/vendor/assets/js/foundation.accordion.js.es6 +0 -329
- data/vendor/assets/js/foundation.accordionMenu.js.es6 +0 -328
- data/vendor/assets/js/foundation.core.js.es6 +0 -337
- data/vendor/assets/js/foundation.drilldown.js.es6 +0 -536
- data/vendor/assets/js/foundation.dropdown.js.es6 +0 -394
- data/vendor/assets/js/foundation.dropdownMenu.js.es6 +0 -458
- data/vendor/assets/js/foundation.equalizer.js.es6 +0 -318
- data/vendor/assets/js/foundation.interchange.js.es6 +0 -210
- data/vendor/assets/js/foundation.magellan.js.es6 +0 -257
- data/vendor/assets/js/foundation.offcanvas.js.es6 +0 -546
- data/vendor/assets/js/foundation.orbit.js.es6 +0 -531
- data/vendor/assets/js/foundation.plugin.js.es6 +0 -54
- data/vendor/assets/js/foundation.positionable.js.es6 +0 -206
- data/vendor/assets/js/foundation.responsiveAccordionTabs.js.es6 +0 -243
- data/vendor/assets/js/foundation.responsiveMenu.js.es6 +0 -155
- data/vendor/assets/js/foundation.responsiveToggle.js.es6 +0 -156
- data/vendor/assets/js/foundation.reveal.js.es6 +0 -585
- data/vendor/assets/js/foundation.slider.js.es6 +0 -712
- data/vendor/assets/js/foundation.smoothScroll.js.es6 +0 -135
- data/vendor/assets/js/foundation.sticky.js.es6 +0 -507
- data/vendor/assets/js/foundation.tabs.js.es6 +0 -498
- data/vendor/assets/js/foundation.toggler.js.es6 +0 -150
- data/vendor/assets/js/foundation.tooltip.js.es6 +0 -462
- data/vendor/assets/js/foundation.util.core.js.es6 +0 -52
- data/vendor/assets/js/foundation.util.imageLoader.js.es6 +0 -45
- data/vendor/assets/js/foundation.util.keyboard.js.es6 +0 -162
- data/vendor/assets/js/foundation.util.mediaQuery.js.es6 +0 -234
- data/vendor/assets/js/foundation.util.motion.js.es6 +0 -104
- data/vendor/assets/js/foundation.util.nest.js.es6 +0 -67
- data/vendor/assets/js/foundation.util.timer.js.es6 +0 -48
- data/vendor/assets/js/foundation.util.touch.js.es6 +0 -149
- data/vendor/assets/js/foundation.util.triggers.js.es6 +0 -268
@@ -1,318 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
import $ from 'jquery';
|
4
|
-
import { MediaQuery } from './foundation.util.mediaQuery';
|
5
|
-
import { onImagesLoaded } from './foundation.util.imageLoader';
|
6
|
-
import { GetYoDigits } from './foundation.util.core';
|
7
|
-
import { Plugin } from './foundation.plugin';
|
8
|
-
|
9
|
-
/**
|
10
|
-
* Equalizer module.
|
11
|
-
* @module foundation.equalizer
|
12
|
-
* @requires foundation.util.mediaQuery
|
13
|
-
* @requires foundation.util.imageLoader if equalizer contains images
|
14
|
-
*/
|
15
|
-
|
16
|
-
class Equalizer extends Plugin {
|
17
|
-
/**
|
18
|
-
* Creates a new instance of Equalizer.
|
19
|
-
* @class
|
20
|
-
* @name Equalizer
|
21
|
-
* @fires Equalizer#init
|
22
|
-
* @param {Object} element - jQuery object to add the trigger to.
|
23
|
-
* @param {Object} options - Overrides to the default plugin settings.
|
24
|
-
*/
|
25
|
-
_setup(element, options){
|
26
|
-
this.$element = element;
|
27
|
-
this.options = $.extend({}, Equalizer.defaults, this.$element.data(), options);
|
28
|
-
this.className = 'Equalizer'; // ie9 back compat
|
29
|
-
|
30
|
-
this._init();
|
31
|
-
}
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Initializes the Equalizer plugin and calls functions to get equalizer functioning on load.
|
35
|
-
* @private
|
36
|
-
*/
|
37
|
-
_init() {
|
38
|
-
var eqId = this.$element.attr('data-equalizer') || '';
|
39
|
-
var $watched = this.$element.find(`[data-equalizer-watch="${eqId}"]`);
|
40
|
-
|
41
|
-
MediaQuery._init();
|
42
|
-
|
43
|
-
this.$watched = $watched.length ? $watched : this.$element.find('[data-equalizer-watch]');
|
44
|
-
this.$element.attr('data-resize', (eqId || GetYoDigits(6, 'eq')));
|
45
|
-
this.$element.attr('data-mutate', (eqId || GetYoDigits(6, 'eq')));
|
46
|
-
|
47
|
-
this.hasNested = this.$element.find('[data-equalizer]').length > 0;
|
48
|
-
this.isNested = this.$element.parentsUntil(document.body, '[data-equalizer]').length > 0;
|
49
|
-
this.isOn = false;
|
50
|
-
this._bindHandler = {
|
51
|
-
onResizeMeBound: this._onResizeMe.bind(this),
|
52
|
-
onPostEqualizedBound: this._onPostEqualized.bind(this)
|
53
|
-
};
|
54
|
-
|
55
|
-
var imgs = this.$element.find('img');
|
56
|
-
var tooSmall;
|
57
|
-
if(this.options.equalizeOn){
|
58
|
-
tooSmall = this._checkMQ();
|
59
|
-
$(window).on('changed.zf.mediaquery', this._checkMQ.bind(this));
|
60
|
-
}else{
|
61
|
-
this._events();
|
62
|
-
}
|
63
|
-
if((tooSmall !== undefined && tooSmall === false) || tooSmall === undefined){
|
64
|
-
if(imgs.length){
|
65
|
-
onImagesLoaded(imgs, this._reflow.bind(this));
|
66
|
-
}else{
|
67
|
-
this._reflow();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Removes event listeners if the breakpoint is too small.
|
74
|
-
* @private
|
75
|
-
*/
|
76
|
-
_pauseEvents() {
|
77
|
-
this.isOn = false;
|
78
|
-
this.$element.off({
|
79
|
-
'.zf.equalizer': this._bindHandler.onPostEqualizedBound,
|
80
|
-
'resizeme.zf.trigger': this._bindHandler.onResizeMeBound,
|
81
|
-
'mutateme.zf.trigger': this._bindHandler.onResizeMeBound
|
82
|
-
});
|
83
|
-
}
|
84
|
-
|
85
|
-
/**
|
86
|
-
* function to handle $elements resizeme.zf.trigger, with bound this on _bindHandler.onResizeMeBound
|
87
|
-
* @private
|
88
|
-
*/
|
89
|
-
_onResizeMe(e) {
|
90
|
-
this._reflow();
|
91
|
-
}
|
92
|
-
|
93
|
-
/**
|
94
|
-
* function to handle $elements postequalized.zf.equalizer, with bound this on _bindHandler.onPostEqualizedBound
|
95
|
-
* @private
|
96
|
-
*/
|
97
|
-
_onPostEqualized(e) {
|
98
|
-
if(e.target !== this.$element[0]){ this._reflow(); }
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Initializes events for Equalizer.
|
103
|
-
* @private
|
104
|
-
*/
|
105
|
-
_events() {
|
106
|
-
var _this = this;
|
107
|
-
this._pauseEvents();
|
108
|
-
if(this.hasNested){
|
109
|
-
this.$element.on('postequalized.zf.equalizer', this._bindHandler.onPostEqualizedBound);
|
110
|
-
}else{
|
111
|
-
this.$element.on('resizeme.zf.trigger', this._bindHandler.onResizeMeBound);
|
112
|
-
this.$element.on('mutateme.zf.trigger', this._bindHandler.onResizeMeBound);
|
113
|
-
}
|
114
|
-
this.isOn = true;
|
115
|
-
}
|
116
|
-
|
117
|
-
/**
|
118
|
-
* Checks the current breakpoint to the minimum required size.
|
119
|
-
* @private
|
120
|
-
*/
|
121
|
-
_checkMQ() {
|
122
|
-
var tooSmall = !MediaQuery.is(this.options.equalizeOn);
|
123
|
-
if(tooSmall){
|
124
|
-
if(this.isOn){
|
125
|
-
this._pauseEvents();
|
126
|
-
this.$watched.css('height', 'auto');
|
127
|
-
}
|
128
|
-
}else{
|
129
|
-
if(!this.isOn){
|
130
|
-
this._events();
|
131
|
-
}
|
132
|
-
}
|
133
|
-
return tooSmall;
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* A noop version for the plugin
|
138
|
-
* @private
|
139
|
-
*/
|
140
|
-
_killswitch() {
|
141
|
-
return;
|
142
|
-
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
* Calls necessary functions to update Equalizer upon DOM change
|
146
|
-
* @private
|
147
|
-
*/
|
148
|
-
_reflow() {
|
149
|
-
if(!this.options.equalizeOnStack){
|
150
|
-
if(this._isStacked()){
|
151
|
-
this.$watched.css('height', 'auto');
|
152
|
-
return false;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
if (this.options.equalizeByRow) {
|
156
|
-
this.getHeightsByRow(this.applyHeightByRow.bind(this));
|
157
|
-
}else{
|
158
|
-
this.getHeights(this.applyHeight.bind(this));
|
159
|
-
}
|
160
|
-
}
|
161
|
-
|
162
|
-
/**
|
163
|
-
* Manually determines if the first 2 elements are *NOT* stacked.
|
164
|
-
* @private
|
165
|
-
*/
|
166
|
-
_isStacked() {
|
167
|
-
if (!this.$watched[0] || !this.$watched[1]) {
|
168
|
-
return true;
|
169
|
-
}
|
170
|
-
return this.$watched[0].getBoundingClientRect().top !== this.$watched[1].getBoundingClientRect().top;
|
171
|
-
}
|
172
|
-
|
173
|
-
/**
|
174
|
-
* Finds the outer heights of children contained within an Equalizer parent and returns them in an array
|
175
|
-
* @param {Function} cb - A non-optional callback to return the heights array to.
|
176
|
-
* @returns {Array} heights - An array of heights of children within Equalizer container
|
177
|
-
*/
|
178
|
-
getHeights(cb) {
|
179
|
-
var heights = [];
|
180
|
-
for(var i = 0, len = this.$watched.length; i < len; i++){
|
181
|
-
this.$watched[i].style.height = 'auto';
|
182
|
-
heights.push(this.$watched[i].offsetHeight);
|
183
|
-
}
|
184
|
-
cb(heights);
|
185
|
-
}
|
186
|
-
|
187
|
-
/**
|
188
|
-
* Finds the outer heights of children contained within an Equalizer parent and returns them in an array
|
189
|
-
* @param {Function} cb - A non-optional callback to return the heights array to.
|
190
|
-
* @returns {Array} groups - An array of heights of children within Equalizer container grouped by row with element,height and max as last child
|
191
|
-
*/
|
192
|
-
getHeightsByRow(cb) {
|
193
|
-
var lastElTopOffset = (this.$watched.length ? this.$watched.first().offset().top : 0),
|
194
|
-
groups = [],
|
195
|
-
group = 0;
|
196
|
-
//group by Row
|
197
|
-
groups[group] = [];
|
198
|
-
for(var i = 0, len = this.$watched.length; i < len; i++){
|
199
|
-
this.$watched[i].style.height = 'auto';
|
200
|
-
//maybe could use this.$watched[i].offsetTop
|
201
|
-
var elOffsetTop = $(this.$watched[i]).offset().top;
|
202
|
-
if (elOffsetTop!=lastElTopOffset) {
|
203
|
-
group++;
|
204
|
-
groups[group] = [];
|
205
|
-
lastElTopOffset=elOffsetTop;
|
206
|
-
}
|
207
|
-
groups[group].push([this.$watched[i],this.$watched[i].offsetHeight]);
|
208
|
-
}
|
209
|
-
|
210
|
-
for (var j = 0, ln = groups.length; j < ln; j++) {
|
211
|
-
var heights = $(groups[j]).map(function(){ return this[1]; }).get();
|
212
|
-
var max = Math.max.apply(null, heights);
|
213
|
-
groups[j].push(max);
|
214
|
-
}
|
215
|
-
cb(groups);
|
216
|
-
}
|
217
|
-
|
218
|
-
/**
|
219
|
-
* Changes the CSS height property of each child in an Equalizer parent to match the tallest
|
220
|
-
* @param {array} heights - An array of heights of children within Equalizer container
|
221
|
-
* @fires Equalizer#preequalized
|
222
|
-
* @fires Equalizer#postequalized
|
223
|
-
*/
|
224
|
-
applyHeight(heights) {
|
225
|
-
var max = Math.max.apply(null, heights);
|
226
|
-
/**
|
227
|
-
* Fires before the heights are applied
|
228
|
-
* @event Equalizer#preequalized
|
229
|
-
*/
|
230
|
-
this.$element.trigger('preequalized.zf.equalizer');
|
231
|
-
|
232
|
-
this.$watched.css('height', max);
|
233
|
-
|
234
|
-
/**
|
235
|
-
* Fires when the heights have been applied
|
236
|
-
* @event Equalizer#postequalized
|
237
|
-
*/
|
238
|
-
this.$element.trigger('postequalized.zf.equalizer');
|
239
|
-
}
|
240
|
-
|
241
|
-
/**
|
242
|
-
* Changes the CSS height property of each child in an Equalizer parent to match the tallest by row
|
243
|
-
* @param {array} groups - An array of heights of children within Equalizer container grouped by row with element,height and max as last child
|
244
|
-
* @fires Equalizer#preequalized
|
245
|
-
* @fires Equalizer#preequalizedrow
|
246
|
-
* @fires Equalizer#postequalizedrow
|
247
|
-
* @fires Equalizer#postequalized
|
248
|
-
*/
|
249
|
-
applyHeightByRow(groups) {
|
250
|
-
/**
|
251
|
-
* Fires before the heights are applied
|
252
|
-
*/
|
253
|
-
this.$element.trigger('preequalized.zf.equalizer');
|
254
|
-
for (var i = 0, len = groups.length; i < len ; i++) {
|
255
|
-
var groupsILength = groups[i].length,
|
256
|
-
max = groups[i][groupsILength - 1];
|
257
|
-
if (groupsILength<=2) {
|
258
|
-
$(groups[i][0][0]).css({'height':'auto'});
|
259
|
-
continue;
|
260
|
-
}
|
261
|
-
/**
|
262
|
-
* Fires before the heights per row are applied
|
263
|
-
* @event Equalizer#preequalizedrow
|
264
|
-
*/
|
265
|
-
this.$element.trigger('preequalizedrow.zf.equalizer');
|
266
|
-
for (var j = 0, lenJ = (groupsILength-1); j < lenJ ; j++) {
|
267
|
-
$(groups[i][j][0]).css({'height':max});
|
268
|
-
}
|
269
|
-
/**
|
270
|
-
* Fires when the heights per row have been applied
|
271
|
-
* @event Equalizer#postequalizedrow
|
272
|
-
*/
|
273
|
-
this.$element.trigger('postequalizedrow.zf.equalizer');
|
274
|
-
}
|
275
|
-
/**
|
276
|
-
* Fires when the heights have been applied
|
277
|
-
*/
|
278
|
-
this.$element.trigger('postequalized.zf.equalizer');
|
279
|
-
}
|
280
|
-
|
281
|
-
/**
|
282
|
-
* Destroys an instance of Equalizer.
|
283
|
-
* @function
|
284
|
-
*/
|
285
|
-
_destroy() {
|
286
|
-
this._pauseEvents();
|
287
|
-
this.$watched.css('height', 'auto');
|
288
|
-
}
|
289
|
-
}
|
290
|
-
|
291
|
-
/**
|
292
|
-
* Default settings for plugin
|
293
|
-
*/
|
294
|
-
Equalizer.defaults = {
|
295
|
-
/**
|
296
|
-
* Enable height equalization when stacked on smaller screens.
|
297
|
-
* @option
|
298
|
-
* @type {boolean}
|
299
|
-
* @default false
|
300
|
-
*/
|
301
|
-
equalizeOnStack: false,
|
302
|
-
/**
|
303
|
-
* Enable height equalization row by row.
|
304
|
-
* @option
|
305
|
-
* @type {boolean}
|
306
|
-
* @default false
|
307
|
-
*/
|
308
|
-
equalizeByRow: false,
|
309
|
-
/**
|
310
|
-
* String representing the minimum breakpoint size the plugin should equalize heights on.
|
311
|
-
* @option
|
312
|
-
* @type {string}
|
313
|
-
* @default ''
|
314
|
-
*/
|
315
|
-
equalizeOn: ''
|
316
|
-
};
|
317
|
-
|
318
|
-
export {Equalizer};
|
@@ -1,210 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
import $ from 'jquery';
|
4
|
-
import { MediaQuery } from './foundation.util.mediaQuery';
|
5
|
-
import { Plugin } from './foundation.plugin';
|
6
|
-
import { GetYoDigits } from './foundation.util.core';
|
7
|
-
|
8
|
-
|
9
|
-
/**
|
10
|
-
* Interchange module.
|
11
|
-
* @module foundation.interchange
|
12
|
-
* @requires foundation.util.mediaQuery
|
13
|
-
*/
|
14
|
-
|
15
|
-
class Interchange extends Plugin {
|
16
|
-
/**
|
17
|
-
* Creates a new instance of Interchange.
|
18
|
-
* @class
|
19
|
-
* @name Interchange
|
20
|
-
* @fires Interchange#init
|
21
|
-
* @param {Object} element - jQuery object to add the trigger to.
|
22
|
-
* @param {Object} options - Overrides to the default plugin settings.
|
23
|
-
*/
|
24
|
-
_setup(element, options) {
|
25
|
-
this.$element = element;
|
26
|
-
this.options = $.extend({}, Interchange.defaults, options);
|
27
|
-
this.rules = [];
|
28
|
-
this.currentPath = '';
|
29
|
-
this.className = 'Interchange'; // ie9 back compat
|
30
|
-
|
31
|
-
this._init();
|
32
|
-
this._events();
|
33
|
-
}
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Initializes the Interchange plugin and calls functions to get interchange functioning on load.
|
37
|
-
* @function
|
38
|
-
* @private
|
39
|
-
*/
|
40
|
-
_init() {
|
41
|
-
MediaQuery._init();
|
42
|
-
|
43
|
-
var id = this.$element[0].id || GetYoDigits(6, 'interchange');
|
44
|
-
this.$element.attr({
|
45
|
-
'data-resize': id,
|
46
|
-
'id': id
|
47
|
-
});
|
48
|
-
|
49
|
-
this._addBreakpoints();
|
50
|
-
this._generateRules();
|
51
|
-
this._reflow();
|
52
|
-
}
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Initializes events for Interchange.
|
56
|
-
* @function
|
57
|
-
* @private
|
58
|
-
*/
|
59
|
-
_events() {
|
60
|
-
this.$element.off('resizeme.zf.trigger').on('resizeme.zf.trigger', () => this._reflow());
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Calls necessary functions to update Interchange upon DOM change
|
65
|
-
* @function
|
66
|
-
* @private
|
67
|
-
*/
|
68
|
-
_reflow() {
|
69
|
-
var match;
|
70
|
-
|
71
|
-
// Iterate through each rule, but only save the last match
|
72
|
-
for (var i in this.rules) {
|
73
|
-
if(this.rules.hasOwnProperty(i)) {
|
74
|
-
var rule = this.rules[i];
|
75
|
-
if (window.matchMedia(rule.query).matches) {
|
76
|
-
match = rule;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
if (match) {
|
82
|
-
this.replace(match.path);
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Gets the Foundation breakpoints and adds them to the Interchange.SPECIAL_QUERIES object.
|
88
|
-
* @function
|
89
|
-
* @private
|
90
|
-
*/
|
91
|
-
_addBreakpoints() {
|
92
|
-
for (var i in MediaQuery.queries) {
|
93
|
-
if (MediaQuery.queries.hasOwnProperty(i)) {
|
94
|
-
var query = MediaQuery.queries[i];
|
95
|
-
Interchange.SPECIAL_QUERIES[query.name] = query.value;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
/**
|
101
|
-
* Checks the Interchange element for the provided media query + content pairings
|
102
|
-
* @function
|
103
|
-
* @private
|
104
|
-
* @param {Object} element - jQuery object that is an Interchange instance
|
105
|
-
* @returns {Array} scenarios - Array of objects that have 'mq' and 'path' keys with corresponding keys
|
106
|
-
*/
|
107
|
-
_generateRules(element) {
|
108
|
-
var rulesList = [];
|
109
|
-
var rules;
|
110
|
-
|
111
|
-
if (this.options.rules) {
|
112
|
-
rules = this.options.rules;
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
rules = this.$element.data('interchange');
|
116
|
-
}
|
117
|
-
|
118
|
-
rules = typeof rules === 'string' ? rules.match(/\[.*?\]/g) : rules;
|
119
|
-
|
120
|
-
for (var i in rules) {
|
121
|
-
if(rules.hasOwnProperty(i)) {
|
122
|
-
var rule = rules[i].slice(1, -1).split(', ');
|
123
|
-
var path = rule.slice(0, -1).join('');
|
124
|
-
var query = rule[rule.length - 1];
|
125
|
-
|
126
|
-
if (Interchange.SPECIAL_QUERIES[query]) {
|
127
|
-
query = Interchange.SPECIAL_QUERIES[query];
|
128
|
-
}
|
129
|
-
|
130
|
-
rulesList.push({
|
131
|
-
path: path,
|
132
|
-
query: query
|
133
|
-
});
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
this.rules = rulesList;
|
138
|
-
}
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Update the `src` property of an image, or change the HTML of a container, to the specified path.
|
142
|
-
* @function
|
143
|
-
* @param {String} path - Path to the image or HTML partial.
|
144
|
-
* @fires Interchange#replaced
|
145
|
-
*/
|
146
|
-
replace(path) {
|
147
|
-
if (this.currentPath === path) return;
|
148
|
-
|
149
|
-
var _this = this,
|
150
|
-
trigger = 'replaced.zf.interchange';
|
151
|
-
|
152
|
-
// Replacing images
|
153
|
-
if (this.$element[0].nodeName === 'IMG') {
|
154
|
-
this.$element.attr('src', path).on('load', function() {
|
155
|
-
_this.currentPath = path;
|
156
|
-
})
|
157
|
-
.trigger(trigger);
|
158
|
-
}
|
159
|
-
// Replacing background images
|
160
|
-
else if (path.match(/\.(gif|jpg|jpeg|png|svg|tiff)([?#].*)?/i)) {
|
161
|
-
path = path.replace(/\(/g, '%28').replace(/\)/g, '%29');
|
162
|
-
this.$element.css({ 'background-image': 'url('+path+')' })
|
163
|
-
.trigger(trigger);
|
164
|
-
}
|
165
|
-
// Replacing HTML
|
166
|
-
else {
|
167
|
-
$.get(path, function(response) {
|
168
|
-
_this.$element.html(response)
|
169
|
-
.trigger(trigger);
|
170
|
-
$(response).foundation();
|
171
|
-
_this.currentPath = path;
|
172
|
-
});
|
173
|
-
}
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Fires when content in an Interchange element is done being loaded.
|
177
|
-
* @event Interchange#replaced
|
178
|
-
*/
|
179
|
-
// this.$element.trigger('replaced.zf.interchange');
|
180
|
-
}
|
181
|
-
|
182
|
-
/**
|
183
|
-
* Destroys an instance of interchange.
|
184
|
-
* @function
|
185
|
-
*/
|
186
|
-
_destroy() {
|
187
|
-
this.$element.off('resizeme.zf.trigger')
|
188
|
-
}
|
189
|
-
}
|
190
|
-
|
191
|
-
/**
|
192
|
-
* Default settings for plugin
|
193
|
-
*/
|
194
|
-
Interchange.defaults = {
|
195
|
-
/**
|
196
|
-
* Rules to be applied to Interchange elements. Set with the `data-interchange` array notation.
|
197
|
-
* @option
|
198
|
-
* @type {?array}
|
199
|
-
* @default null
|
200
|
-
*/
|
201
|
-
rules: null
|
202
|
-
};
|
203
|
-
|
204
|
-
Interchange.SPECIAL_QUERIES = {
|
205
|
-
'landscape': 'screen and (orientation: landscape)',
|
206
|
-
'portrait': 'screen and (orientation: portrait)',
|
207
|
-
'retina': 'only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx)'
|
208
|
-
};
|
209
|
-
|
210
|
-
export {Interchange};
|