Created
August 6, 2015 23:42
-
-
Save clohr/8d42af148428727505c9 to your computer and use it in GitHub Desktop.
Media Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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