Skip to content

Instantly share code, notes, and snippets.

@clohr
Created August 6, 2015 23:42
Show Gist options
  • Save clohr/8d42af148428727505c9 to your computer and use it in GitHub Desktop.
Save clohr/8d42af148428727505c9 to your computer and use it in GitHub Desktop.
Media Query
'use strict';
var mediaQuery = function() {
var _queries = {};
var getMediaQueries = function getMediaQueries() {
var metaTags = document.querySelectorAll('meta[data-breakpoint]');
var metaArr = [].slice.call(metaTags);
var key;
metaArr.forEach(function(tag) {
key = tag.getAttribute('class');
_queries[key] = window.getComputedStyle(tag).fontFamily.replace(/\'/g, '').replace(/\"/g, '');
});
};
getMediaQueries();
return {
/**
* Polyfill for matchMedia
* @memberof module:lib/MediaQuery
* @public
* @method
* @param {String} query Media query to test
* @returns {Boolean} true or false if media query matches
*/
matchBreak: function(query) {
var myMatch = false;
var mq = null;
var styleMedia;
if (window.matchMedia) {
mq = window.matchMedia(query);
myMatch = mq.matches;
} else {
styleMedia = window.styleMedia || window.media;
myMatch = styleMedia.matchMedium(query);
}
return myMatch;
},
/**
* Returns supports media queries
* @memberof module:lib/MediaQuery
* @public
* @returns {Object} _queries: supported media queries
*/
get queries() {
return _queries;
}
};
};
/**
* Media Query Module to verify current breakpoint
* @module lib/mediaQuery
*/
module.exports = mediaQuery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment