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,52 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
import $ from 'jquery';
|
4
|
-
|
5
|
-
// Core Foundation Utilities, utilized in a number of places.
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Returns a boolean for RTL support
|
9
|
-
*/
|
10
|
-
function rtl() {
|
11
|
-
return $('html').attr('dir') === 'rtl';
|
12
|
-
}
|
13
|
-
|
14
|
-
/**
|
15
|
-
* returns a random base-36 uid with namespacing
|
16
|
-
* @function
|
17
|
-
* @param {Number} length - number of random base-36 digits desired. Increase for more random strings.
|
18
|
-
* @param {String} namespace - name of plugin to be incorporated in uid, optional.
|
19
|
-
* @default {String} '' - if no plugin name is provided, nothing is appended to the uid.
|
20
|
-
* @returns {String} - unique id
|
21
|
-
*/
|
22
|
-
function GetYoDigits(length, namespace){
|
23
|
-
length = length || 6;
|
24
|
-
return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1) + (namespace ? `-${namespace}` : '');
|
25
|
-
}
|
26
|
-
|
27
|
-
function transitionend($elem){
|
28
|
-
var transitions = {
|
29
|
-
'transition': 'transitionend',
|
30
|
-
'WebkitTransition': 'webkitTransitionEnd',
|
31
|
-
'MozTransition': 'transitionend',
|
32
|
-
'OTransition': 'otransitionend'
|
33
|
-
};
|
34
|
-
var elem = document.createElement('div'),
|
35
|
-
end;
|
36
|
-
|
37
|
-
for (var t in transitions){
|
38
|
-
if (typeof elem.style[t] !== 'undefined'){
|
39
|
-
end = transitions[t];
|
40
|
-
}
|
41
|
-
}
|
42
|
-
if(end){
|
43
|
-
return end;
|
44
|
-
}else{
|
45
|
-
end = setTimeout(function(){
|
46
|
-
$elem.triggerHandler('transitionend', [$elem]);
|
47
|
-
}, 1);
|
48
|
-
return 'transitionend';
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
export {rtl, GetYoDigits, transitionend};
|
@@ -1,45 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
import $ from 'jquery';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Runs a callback function when images are fully loaded.
|
7
|
-
* @param {Object} images - Image(s) to check if loaded.
|
8
|
-
* @param {Func} callback - Function to execute when image is fully loaded.
|
9
|
-
*/
|
10
|
-
function onImagesLoaded(images, callback){
|
11
|
-
var self = this,
|
12
|
-
unloaded = images.length;
|
13
|
-
|
14
|
-
if (unloaded === 0) {
|
15
|
-
callback();
|
16
|
-
}
|
17
|
-
|
18
|
-
images.each(function(){
|
19
|
-
// Check if image is loaded
|
20
|
-
if (this.complete && this.naturalWidth !== undefined) {
|
21
|
-
singleImageLoaded();
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
// If the above check failed, simulate loading on detached element.
|
25
|
-
var image = new Image();
|
26
|
-
// Still count image as loaded if it finalizes with an error.
|
27
|
-
var events = "load.zf.images error.zf.images";
|
28
|
-
$(image).one(events, function me(event){
|
29
|
-
// Unbind the event listeners. We're using 'one' but only one of the two events will have fired.
|
30
|
-
$(this).off(events, me);
|
31
|
-
singleImageLoaded();
|
32
|
-
});
|
33
|
-
image.src = $(this).attr('src');
|
34
|
-
}
|
35
|
-
});
|
36
|
-
|
37
|
-
function singleImageLoaded() {
|
38
|
-
unloaded--;
|
39
|
-
if (unloaded === 0) {
|
40
|
-
callback();
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
export { onImagesLoaded };
|
@@ -1,162 +0,0 @@
|
|
1
|
-
/*******************************************
|
2
|
-
* *
|
3
|
-
* This util was created by Marius Olbertz *
|
4
|
-
* Please thank Marius on GitHub /owlbertz *
|
5
|
-
* or the web http://www.mariusolbertz.de/ *
|
6
|
-
* *
|
7
|
-
******************************************/
|
8
|
-
|
9
|
-
'use strict';
|
10
|
-
|
11
|
-
import $ from 'jquery';
|
12
|
-
import { rtl as Rtl } from './foundation.util.core';
|
13
|
-
|
14
|
-
const keyCodes = {
|
15
|
-
9: 'TAB',
|
16
|
-
13: 'ENTER',
|
17
|
-
27: 'ESCAPE',
|
18
|
-
32: 'SPACE',
|
19
|
-
35: 'END',
|
20
|
-
36: 'HOME',
|
21
|
-
37: 'ARROW_LEFT',
|
22
|
-
38: 'ARROW_UP',
|
23
|
-
39: 'ARROW_RIGHT',
|
24
|
-
40: 'ARROW_DOWN'
|
25
|
-
}
|
26
|
-
|
27
|
-
var commands = {}
|
28
|
-
|
29
|
-
// Functions pulled out to be referenceable from internals
|
30
|
-
function findFocusable($element) {
|
31
|
-
if(!$element) {return false; }
|
32
|
-
return $element.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(function() {
|
33
|
-
if (!$(this).is(':visible') || $(this).attr('tabindex') < 0) { return false; } //only have visible elements and those that have a tabindex greater or equal 0
|
34
|
-
return true;
|
35
|
-
});
|
36
|
-
}
|
37
|
-
|
38
|
-
function parseKey(event) {
|
39
|
-
var key = keyCodes[event.which || event.keyCode] || String.fromCharCode(event.which).toUpperCase();
|
40
|
-
|
41
|
-
// Remove un-printable characters, e.g. for `fromCharCode` calls for CTRL only events
|
42
|
-
key = key.replace(/\W+/, '');
|
43
|
-
|
44
|
-
if (event.shiftKey) key = `SHIFT_${key}`;
|
45
|
-
if (event.ctrlKey) key = `CTRL_${key}`;
|
46
|
-
if (event.altKey) key = `ALT_${key}`;
|
47
|
-
|
48
|
-
// Remove trailing underscore, in case only modifiers were used (e.g. only `CTRL_ALT`)
|
49
|
-
key = key.replace(/_$/, '');
|
50
|
-
|
51
|
-
return key;
|
52
|
-
}
|
53
|
-
|
54
|
-
var Keyboard = {
|
55
|
-
keys: getKeyCodes(keyCodes),
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Parses the (keyboard) event and returns a String that represents its key
|
59
|
-
* Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
|
60
|
-
* @param {Event} event - the event generated by the event handler
|
61
|
-
* @return String key - String that represents the key pressed
|
62
|
-
*/
|
63
|
-
parseKey: parseKey,
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Handles the given (keyboard) event
|
67
|
-
* @param {Event} event - the event generated by the event handler
|
68
|
-
* @param {String} component - Foundation component's name, e.g. Slider or Reveal
|
69
|
-
* @param {Objects} functions - collection of functions that are to be executed
|
70
|
-
*/
|
71
|
-
handleKey(event, component, functions) {
|
72
|
-
var commandList = commands[component],
|
73
|
-
keyCode = this.parseKey(event),
|
74
|
-
cmds,
|
75
|
-
command,
|
76
|
-
fn;
|
77
|
-
|
78
|
-
if (!commandList) return console.warn('Component not defined!');
|
79
|
-
|
80
|
-
if (typeof commandList.ltr === 'undefined') { // this component does not differentiate between ltr and rtl
|
81
|
-
cmds = commandList; // use plain list
|
82
|
-
} else { // merge ltr and rtl: if document is rtl, rtl overwrites ltr and vice versa
|
83
|
-
if (Rtl()) cmds = $.extend({}, commandList.ltr, commandList.rtl);
|
84
|
-
|
85
|
-
else cmds = $.extend({}, commandList.rtl, commandList.ltr);
|
86
|
-
}
|
87
|
-
command = cmds[keyCode];
|
88
|
-
|
89
|
-
fn = functions[command];
|
90
|
-
if (fn && typeof fn === 'function') { // execute function if exists
|
91
|
-
var returnValue = fn.apply();
|
92
|
-
if (functions.handled || typeof functions.handled === 'function') { // execute function when event was handled
|
93
|
-
functions.handled(returnValue);
|
94
|
-
}
|
95
|
-
} else {
|
96
|
-
if (functions.unhandled || typeof functions.unhandled === 'function') { // execute function when event was not handled
|
97
|
-
functions.unhandled();
|
98
|
-
}
|
99
|
-
}
|
100
|
-
},
|
101
|
-
|
102
|
-
/**
|
103
|
-
* Finds all focusable elements within the given `$element`
|
104
|
-
* @param {jQuery} $element - jQuery object to search within
|
105
|
-
* @return {jQuery} $focusable - all focusable elements within `$element`
|
106
|
-
*/
|
107
|
-
|
108
|
-
findFocusable: findFocusable,
|
109
|
-
|
110
|
-
/**
|
111
|
-
* Returns the component name name
|
112
|
-
* @param {Object} component - Foundation component, e.g. Slider or Reveal
|
113
|
-
* @return String componentName
|
114
|
-
*/
|
115
|
-
|
116
|
-
register(componentName, cmds) {
|
117
|
-
commands[componentName] = cmds;
|
118
|
-
},
|
119
|
-
|
120
|
-
|
121
|
-
// TODO9438: These references to Keyboard need to not require global. Will 'this' work in this context?
|
122
|
-
//
|
123
|
-
/**
|
124
|
-
* Traps the focus in the given element.
|
125
|
-
* @param {jQuery} $element jQuery object to trap the foucs into.
|
126
|
-
*/
|
127
|
-
trapFocus($element) {
|
128
|
-
var $focusable = findFocusable($element),
|
129
|
-
$firstFocusable = $focusable.eq(0),
|
130
|
-
$lastFocusable = $focusable.eq(-1);
|
131
|
-
|
132
|
-
$element.on('keydown.zf.trapfocus', function(event) {
|
133
|
-
if (event.target === $lastFocusable[0] && parseKey(event) === 'TAB') {
|
134
|
-
event.preventDefault();
|
135
|
-
$firstFocusable.focus();
|
136
|
-
}
|
137
|
-
else if (event.target === $firstFocusable[0] && parseKey(event) === 'SHIFT_TAB') {
|
138
|
-
event.preventDefault();
|
139
|
-
$lastFocusable.focus();
|
140
|
-
}
|
141
|
-
});
|
142
|
-
},
|
143
|
-
/**
|
144
|
-
* Releases the trapped focus from the given element.
|
145
|
-
* @param {jQuery} $element jQuery object to release the focus for.
|
146
|
-
*/
|
147
|
-
releaseFocus($element) {
|
148
|
-
$element.off('keydown.zf.trapfocus');
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
/*
|
153
|
-
* Constants for easier comparing.
|
154
|
-
* Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
|
155
|
-
*/
|
156
|
-
function getKeyCodes(kcs) {
|
157
|
-
var k = {};
|
158
|
-
for (var kc in kcs) k[kcs[kc]] = kcs[kc];
|
159
|
-
return k;
|
160
|
-
}
|
161
|
-
|
162
|
-
export {Keyboard};
|
@@ -1,234 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
import $ from 'jquery';
|
4
|
-
|
5
|
-
// Default set of media queries
|
6
|
-
const defaultQueries = {
|
7
|
-
'default' : 'only screen',
|
8
|
-
landscape : 'only screen and (orientation: landscape)',
|
9
|
-
portrait : 'only screen and (orientation: portrait)',
|
10
|
-
retina : 'only screen and (-webkit-min-device-pixel-ratio: 2),' +
|
11
|
-
'only screen and (min--moz-device-pixel-ratio: 2),' +
|
12
|
-
'only screen and (-o-min-device-pixel-ratio: 2/1),' +
|
13
|
-
'only screen and (min-device-pixel-ratio: 2),' +
|
14
|
-
'only screen and (min-resolution: 192dpi),' +
|
15
|
-
'only screen and (min-resolution: 2dppx)'
|
16
|
-
};
|
17
|
-
|
18
|
-
|
19
|
-
// matchMedia() polyfill - Test a CSS media type/query in JS.
|
20
|
-
// Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license
|
21
|
-
let matchMedia = window.matchMedia || (function() {
|
22
|
-
'use strict';
|
23
|
-
|
24
|
-
// For browsers that support matchMedium api such as IE 9 and webkit
|
25
|
-
var styleMedia = (window.styleMedia || window.media);
|
26
|
-
|
27
|
-
// For those that don't support matchMedium
|
28
|
-
if (!styleMedia) {
|
29
|
-
var style = document.createElement('style'),
|
30
|
-
script = document.getElementsByTagName('script')[0],
|
31
|
-
info = null;
|
32
|
-
|
33
|
-
style.type = 'text/css';
|
34
|
-
style.id = 'matchmediajs-test';
|
35
|
-
|
36
|
-
script && script.parentNode && script.parentNode.insertBefore(style, script);
|
37
|
-
|
38
|
-
// 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers
|
39
|
-
info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;
|
40
|
-
|
41
|
-
styleMedia = {
|
42
|
-
matchMedium(media) {
|
43
|
-
var text = `@media ${media}{ #matchmediajs-test { width: 1px; } }`;
|
44
|
-
|
45
|
-
// 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
|
46
|
-
if (style.styleSheet) {
|
47
|
-
style.styleSheet.cssText = text;
|
48
|
-
} else {
|
49
|
-
style.textContent = text;
|
50
|
-
}
|
51
|
-
|
52
|
-
// Test if media query is true or false
|
53
|
-
return info.width === '1px';
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
return function(media) {
|
59
|
-
return {
|
60
|
-
matches: styleMedia.matchMedium(media || 'all'),
|
61
|
-
media: media || 'all'
|
62
|
-
};
|
63
|
-
}
|
64
|
-
})();
|
65
|
-
|
66
|
-
var MediaQuery = {
|
67
|
-
queries: [],
|
68
|
-
|
69
|
-
current: '',
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Initializes the media query helper, by extracting the breakpoint list from the CSS and activating the breakpoint watcher.
|
73
|
-
* @function
|
74
|
-
* @private
|
75
|
-
*/
|
76
|
-
_init() {
|
77
|
-
var self = this;
|
78
|
-
var $meta = $('meta.foundation-mq');
|
79
|
-
if(!$meta.length){
|
80
|
-
$('<meta class="foundation-mq">').appendTo(document.head);
|
81
|
-
}
|
82
|
-
|
83
|
-
var extractedStyles = $('.foundation-mq').css('font-family');
|
84
|
-
var namedQueries;
|
85
|
-
|
86
|
-
namedQueries = parseStyleToObject(extractedStyles);
|
87
|
-
|
88
|
-
for (var key in namedQueries) {
|
89
|
-
if(namedQueries.hasOwnProperty(key)) {
|
90
|
-
self.queries.push({
|
91
|
-
name: key,
|
92
|
-
value: `only screen and (min-width: ${namedQueries[key]})`
|
93
|
-
});
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
this.current = this._getCurrentSize();
|
98
|
-
|
99
|
-
this._watcher();
|
100
|
-
},
|
101
|
-
|
102
|
-
/**
|
103
|
-
* Checks if the screen is at least as wide as a breakpoint.
|
104
|
-
* @function
|
105
|
-
* @param {String} size - Name of the breakpoint to check.
|
106
|
-
* @returns {Boolean} `true` if the breakpoint matches, `false` if it's smaller.
|
107
|
-
*/
|
108
|
-
atLeast(size) {
|
109
|
-
var query = this.get(size);
|
110
|
-
|
111
|
-
if (query) {
|
112
|
-
return matchMedia(query).matches;
|
113
|
-
}
|
114
|
-
|
115
|
-
return false;
|
116
|
-
},
|
117
|
-
|
118
|
-
/**
|
119
|
-
* Checks if the screen matches to a breakpoint.
|
120
|
-
* @function
|
121
|
-
* @param {String} size - Name of the breakpoint to check, either 'small only' or 'small'. Omitting 'only' falls back to using atLeast() method.
|
122
|
-
* @returns {Boolean} `true` if the breakpoint matches, `false` if it does not.
|
123
|
-
*/
|
124
|
-
is(size) {
|
125
|
-
size = size.trim().split(' ');
|
126
|
-
if(size.length > 1 && size[1] === 'only') {
|
127
|
-
if(size[0] === this._getCurrentSize()) return true;
|
128
|
-
} else {
|
129
|
-
return this.atLeast(size[0]);
|
130
|
-
}
|
131
|
-
return false;
|
132
|
-
},
|
133
|
-
|
134
|
-
/**
|
135
|
-
* Gets the media query of a breakpoint.
|
136
|
-
* @function
|
137
|
-
* @param {String} size - Name of the breakpoint to get.
|
138
|
-
* @returns {String|null} - The media query of the breakpoint, or `null` if the breakpoint doesn't exist.
|
139
|
-
*/
|
140
|
-
get(size) {
|
141
|
-
for (var i in this.queries) {
|
142
|
-
if(this.queries.hasOwnProperty(i)) {
|
143
|
-
var query = this.queries[i];
|
144
|
-
if (size === query.name) return query.value;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
return null;
|
149
|
-
},
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Gets the current breakpoint name by testing every breakpoint and returning the last one to match (the biggest one).
|
153
|
-
* @function
|
154
|
-
* @private
|
155
|
-
* @returns {String} Name of the current breakpoint.
|
156
|
-
*/
|
157
|
-
_getCurrentSize() {
|
158
|
-
var matched;
|
159
|
-
|
160
|
-
for (var i = 0; i < this.queries.length; i++) {
|
161
|
-
var query = this.queries[i];
|
162
|
-
|
163
|
-
if (matchMedia(query.value).matches) {
|
164
|
-
matched = query;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
if (typeof matched === 'object') {
|
169
|
-
return matched.name;
|
170
|
-
} else {
|
171
|
-
return matched;
|
172
|
-
}
|
173
|
-
},
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Activates the breakpoint watcher, which fires an event on the window whenever the breakpoint changes.
|
177
|
-
* @function
|
178
|
-
* @private
|
179
|
-
*/
|
180
|
-
_watcher() {
|
181
|
-
$(window).off('resize.zf.mediaquery').on('resize.zf.mediaquery', () => {
|
182
|
-
var newSize = this._getCurrentSize(), currentSize = this.current;
|
183
|
-
|
184
|
-
if (newSize !== currentSize) {
|
185
|
-
// Change the current media query
|
186
|
-
this.current = newSize;
|
187
|
-
|
188
|
-
// Broadcast the media query change on the window
|
189
|
-
$(window).trigger('changed.zf.mediaquery', [newSize, currentSize]);
|
190
|
-
}
|
191
|
-
});
|
192
|
-
}
|
193
|
-
};
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// Thank you: https://github.com/sindresorhus/query-string
|
198
|
-
function parseStyleToObject(str) {
|
199
|
-
var styleObject = {};
|
200
|
-
|
201
|
-
if (typeof str !== 'string') {
|
202
|
-
return styleObject;
|
203
|
-
}
|
204
|
-
|
205
|
-
str = str.trim().slice(1, -1); // browsers re-quote string style values
|
206
|
-
|
207
|
-
if (!str) {
|
208
|
-
return styleObject;
|
209
|
-
}
|
210
|
-
|
211
|
-
styleObject = str.split('&').reduce(function(ret, param) {
|
212
|
-
var parts = param.replace(/\+/g, ' ').split('=');
|
213
|
-
var key = parts[0];
|
214
|
-
var val = parts[1];
|
215
|
-
key = decodeURIComponent(key);
|
216
|
-
|
217
|
-
// missing `=` should be `null`:
|
218
|
-
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
219
|
-
val = val === undefined ? null : decodeURIComponent(val);
|
220
|
-
|
221
|
-
if (!ret.hasOwnProperty(key)) {
|
222
|
-
ret[key] = val;
|
223
|
-
} else if (Array.isArray(ret[key])) {
|
224
|
-
ret[key].push(val);
|
225
|
-
} else {
|
226
|
-
ret[key] = [ret[key], val];
|
227
|
-
}
|
228
|
-
return ret;
|
229
|
-
}, {});
|
230
|
-
|
231
|
-
return styleObject;
|
232
|
-
}
|
233
|
-
|
234
|
-
export {MediaQuery};
|