/*! matchmedia() polyfill - test a css media type/query in js. authors & copyright (c) 2012: scott jehl, paul irish, nicholas zakas. dual mit/bsd license */ /*! note: if you're already including a window.matchmedia polyfill via modernizr or otherwise, you don't need this part */ (function(w) { "use strict"; w.matchmedia = w.matchmedia || function(doc, undefined) { var bool, docelem = doc.documentelement, refnode = docelem.firstelementchild || docelem.firstchild, fakebody = doc.createelement("body"), div = doc.createelement("div"); div.id = "mq-test-1"; div.style.csstext = "position:absolute;top:-100em"; fakebody.style.background = "none"; fakebody.appendchild(div); return function(q) { div.innerhtml = '­'; docelem.insertbefore(fakebody, refnode); bool = div.offsetwidth === 42; docelem.removechild(fakebody); return { matches: bool, media: q }; }; }(w.document); })(this); /*! respond.js v1.4.0: min/max-width media query polyfill. (c) scott jehl. mit lic. j.mp/respondjs */ (function(w) { "use strict"; var respond = {}; w.respond = respond; respond.update = function() {}; var requestqueue = [], xmlhttp = function() { var xmlhttpmethod = false; try { xmlhttpmethod = new w.xmlhttprequest(); } catch (e) { xmlhttpmethod = new w.activexobject("microsoft.xmlhttp"); } return function() { return xmlhttpmethod; }; }(), ajax = function(url, callback) { var req = xmlhttp(); if (!req) { return; } req.open("get", url, true); req.onreadystatechange = function() { if (req.readystate !== 4 || req.status !== 200 && req.status !== 304) { return; } callback(req.responsetext); }; if (req.readystate === 4) { return; } req.send(null); }; respond.ajax = ajax; respond.queue = requestqueue; respond.regex = { media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi, keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi, urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, findstyles: /@media *([^\{]+)\{([\s\s]+?)$/, only: /(only\s+)?([a-za-z]+)\s?/, minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/, maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ }; respond.mediaqueriessupported = w.matchmedia && w.matchmedia("only all") !== null && w.matchmedia("only all").matches; if (respond.mediaqueriessupported) { return; } var doc = w.document, docelem = doc.documentelement, mediastyles = [], rules = [], appendedels = [], parsedsheets = {}, resizethrottle = 30, head = doc.getelementsbytagname("head")[0] || docelem, base = doc.getelementsbytagname("base")[0], links = head.getelementsbytagname("link"), lastcall, resizedefer, eminpx, getemvalue = function() { var ret, div = doc.createelement("div"), body = doc.body, originalhtmlfontsize = docelem.style.fontsize, originalbodyfontsize = body && body.style.fontsize, fakeused = false; div.style.csstext = "position:absolute;font-size:1em;width:1em"; if (!body) { body = fakeused = doc.createelement("body"); body.style.background = "none"; } docelem.style.fontsize = "100%"; body.style.fontsize = "100%"; body.appendchild(div); if (fakeused) { docelem.insertbefore(body, docelem.firstchild); } ret = div.offsetwidth; if (fakeused) { docelem.removechild(body); } else { body.removechild(div); } docelem.style.fontsize = originalhtmlfontsize; if (originalbodyfontsize) { body.style.fontsize = originalbodyfontsize; } ret = eminpx = parsefloat(ret); return ret; }, applymedia = function(fromresize) { var name = "clientwidth", docelemprop = docelem[name], currwidth = doc.compatmode === "css1compat" && docelemprop || doc.body[name] || docelemprop, styleblocks = {}, lastlink = links[links.length - 1], now = new date().gettime(); if (fromresize && lastcall && now - lastcall < resizethrottle) { w.cleartimeout(resizedefer); resizedefer = w.settimeout(applymedia, resizethrottle); return; } else { lastcall = now; } for (var i in mediastyles) { if (mediastyles.hasownproperty(i)) { var thisstyle = mediastyles[i], min = thisstyle.minw, max = thisstyle.maxw, minnull = min === null, maxnull = max === null, em = "em"; if (!!min) { min = parsefloat(min) * (min.indexof(em) > -1 ? eminpx || getemvalue() : 1); } if (!!max) { max = parsefloat(max) * (max.indexof(em) > -1 ? eminpx || getemvalue() : 1); } if (!thisstyle.hasquery || (!minnull || !maxnull) && (minnull || currwidth >= min) && (maxnull || currwidth <= max)) { if (!styleblocks[thisstyle.media]) { styleblocks[thisstyle.media] = []; } styleblocks[thisstyle.media].push(rules[thisstyle.rules]); } } } for (var j in appendedels) { if (appendedels.hasownproperty(j)) { if (appendedels[j] && appendedels[j].parentnode === head) { head.removechild(appendedels[j]); } } } appendedels.length = 0; for (var k in styleblocks) { if (styleblocks.hasownproperty(k)) { var ss = doc.createelement("style"), css = styleblocks[k].join("\n"); ss.type = "text/css"; ss.media = k; head.insertbefore(ss, lastlink.nextsibling); if (ss.stylesheet) { ss.stylesheet.csstext = css; } else { ss.appendchild(doc.createtextnode(css)); } appendedels.push(ss); } } }, translate = function(styles, href, media) { var qs = styles.replace(respond.regex.keyframes, "").match(respond.regex.media), ql = qs && qs.length || 0; href = href.substring(0, href.lastindexof("/")); var repurls = function(css) { return css.replace(respond.regex.urls, "$1" + href + "$2$3"); }, usemedia = !ql && media; if (href.length) { href += "/"; } if (usemedia) { ql = 1; } for (var i = 0; i < ql; i++) { var fullq, thisq, eachq, eql; if (usemedia) { fullq = media; rules.push(repurls(styles)); } else { fullq = qs[i].match(respond.regex.findstyles) && regexp.$1; rules.push(regexp.$2 && repurls(regexp.$2)); } eachq = fullq.split(","); eql = eachq.length; for (var j = 0; j < eql; j++) { thisq = eachq[j]; mediastyles.push({ media: thisq.split("(")[0].match(respond.regex.only) && regexp.$2 || "all", rules: rules.length - 1, hasquery: thisq.indexof("(") > -1, minw: thisq.match(respond.regex.minw) && parsefloat(regexp.$1) + (regexp.$2 || ""), maxw: thisq.match(respond.regex.maxw) && parsefloat(regexp.$1) + (regexp.$2 || "") }); } } applymedia(); }, makerequests = function() { if (requestqueue.length) { var thisrequest = requestqueue.shift(); ajax(thisrequest.href, function(styles) { translate(styles, thisrequest.href, thisrequest.media); parsedsheets[thisrequest.href] = true; w.settimeout(function() { makerequests(); }, 0); }); } }, ripcss = function() { for (var i = 0; i < links.length; i++) { var sheet = links[i], href = sheet.href, media = sheet.media, iscss = sheet.rel && sheet.rel.tolowercase() === "stylesheet"; if (!!href && iscss && !parsedsheets[href]) { if (sheet.stylesheet && sheet.stylesheet.rawcsstext) { translate(sheet.stylesheet.rawcsstext, href, media); parsedsheets[href] = true; } else { if (!/^([a-za-z:]*\/\/)/.test(href) && !base || href.replace(regexp.$1, "").split("/")[0] === w.location.host) { if (href.substring(0, 2) === "//") { href = w.location.protocol + href; } requestqueue.push({ href: href, media: media }); } } } } makerequests(); }; ripcss(); respond.update = ripcss; respond.getemvalue = getemvalue; function callmedia() { applymedia(true); } if (w.addeventlistener) { w.addeventlistener("resize", callmedia, false); } else if (w.attachevent) { w.attachevent("onresize", callmedia); } })(this);