10 examples of 'jquery media query' in JavaScript

Every line of 'jquery media query' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
150export function media(query) {
151 return window.matchMedia(`(${query})`).matches;
152}
300function matchMedia(media) {
301 var id = _queryID,
302 mql = {
303 matches: false,
304 media: media,
305 addListener: function addListener(listener) {
306 _queries[id].listeners || (_queries[id].listeners = []);
307 listener && _queries[id].listeners.push(listener);
308 },
309 removeListener: function removeListener(listener) {
310 var query = _queries[id],
311 i = 0,
312 il = 0;
313 if (!query) {
314 return;
315 }
316 il = query.listeners.length;
317 for (; i < il; i++) {
318 if (query.listeners[i] === listener) {
319 query.listeners.splice(i, 1);
320 }
321 }
322 }
323 };
324 if (media === "") {
325 mql.matches = true;
326 return mql;
327 }
328 mql.matches = _matches(media);
329 _queryID = _queries.push({
330 mql: mql,
331 listeners: null
332 });
333 return mql;
334}
17export function matchMedia(query: string): MediaQueryList {
18 const platform = getPlatform();
19
20 if (platform.WEBKIT) {
21 createEmptyStyleRule(query);
22 }
23
24 const _matchMedia =
25 platform.isBrowser && window.matchMedia ? window.matchMedia.bind(window) : noopMatchMedia;
26
27 return _matchMedia(query);
28}
4constructor(query, ruleSet) {
5 super()
6 this.query = query
7 this.ruleSet = ruleSet
8}
70function matchMedia(query: string) {
71 return window.matchMedia(query).matches;
72}
91static stopMedia($element) {
92 const selector = "div[data-id='" + $element.data('id') + "'] ";
93 const htmlMedia = document.querySelector(selector + 'audio, ' + selector + 'video');
94 if (null !== htmlMedia) {
95 htmlMedia.pause();
96 htmlMedia.currentTime = 0;
97
98 return;
99 }
100
101 const providerMedia = document.querySelector(selector + 'iframe');
102 if (null !== providerMedia) {
103 const source = providerMedia.src;
104 providerMedia.src = source;
105 }
106}
39function matchMediaMoz(query) {
40 return win.matchMedia(query).matches;
41}
216function matchesMediaQuery() {
217 return stickyMediaQuery === false || mediaQuery.matches(stickyMediaQuery);
218}
275value: function _checkMediaQueries() {
276 var matchedMq,
277 _this = this;
278 // Iterate through each rule and find the last matching rule
279 __WEBPACK_IMPORTED_MODULE_0_jquery___default.a.each(this.rules, function (key) {
280 if (__WEBPACK_IMPORTED_MODULE_1__foundation_util_mediaQuery__["MediaQuery"].atLeast(key)) {
281 matchedMq = key;
282 }
283 });
284
285 // No match? No dice
286 if (!matchedMq) return;
287
288 // Plugin already initialized? We good
289 if (this.currentPlugin instanceof this.rules[matchedMq].plugin) return;
290
291 // Remove existing plugin-specific CSS classes
292 __WEBPACK_IMPORTED_MODULE_0_jquery___default.a.each(MenuPlugins, function (key, value) {
293 _this.$element.removeClass(value.cssClass);
294 });
295
296 // Add the CSS class for the new plugin
297 this.$element.addClass(this.rules[matchedMq].cssClass);
298
299 // Create an instance of the new plugin
300 if (this.currentPlugin) this.currentPlugin.destroy();
301 this.currentPlugin = new this.rules[matchedMq].plugin(this.$element, {});
302}
153function updateMatchedMedia(polyfill, queries) {
154 var query
155 , current = {}
156
157 // clear the cache since a resize just happened
158 MediaManager.clearCache()
159
160 // look for media matches that have changed since the last inspection
161 for (query in queries) {
162 if (!queries.hasOwnProperty(query)) continue
163 current[query] = MediaManager.matchMedia(query).matches
164 if (current[query] != state[query]) {
165 callback.call(polyfill, query, MediaManager.matchMedia(query).matches)
166 }
167 }
168 state = current
169}

Related snippets