Authored by whb

respond

  1 +<!-- Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs -->
  2 +<!DOCTYPE html>
  3 +<html>
  4 +<head>
  5 + <meta charset="utf-8" />
  6 + <title>Respond JS Proxy</title>
  7 +</head>
  8 +<body>
  9 + <script>
  10 + (function () {
  11 + var domain, css, query, getQueryString, ajax, xmlHttp;
  12 +
  13 + /*
  14 + http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
  15 + */
  16 + getQueryString = function() {
  17 + var ret = {}, parts, i, p;
  18 +
  19 + parts = (document.location.toString().split("?")[1]).split("&");
  20 +
  21 + for (i = 0; i < parts.length; i++) {
  22 +
  23 + p = parts[i].split("=");
  24 + // so strings will be correctly parsed:
  25 + p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));
  26 +
  27 + if (p[0].search(/\[\]/) >= 0) { // then it"s an array
  28 + p[0] = p[0].replace("[]", "");
  29 +
  30 + if (typeof ret[p[0]] != "object") {
  31 + ret[p[0]] = [];
  32 + }
  33 + ret[p[0]].push(p[1]);
  34 + } else {
  35 + ret[p[0]] = p[1];
  36 + }
  37 + }
  38 + return ret;
  39 + };
  40 +
  41 + ajax = function( url, callback ) {
  42 + var req = xmlHttp();
  43 + if (!req){
  44 + return;
  45 + }
  46 + req.open( "GET", url, true );
  47 + req.onreadystatechange = function () {
  48 + if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
  49 + return;
  50 + }
  51 + callback( req.responseText );
  52 + };
  53 + if ( req.readyState == 4 ){
  54 + return;
  55 + }
  56 + req.send();
  57 + };
  58 +
  59 + //define ajax obj
  60 + xmlHttp = (function() {
  61 + var xmlhttpmethod = false,
  62 + attempts = [
  63 + function(){ return new XMLHttpRequest(); },
  64 + function(){ return new ActiveXObject("Microsoft.XMLHTTP"); },
  65 + function(){ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
  66 + ],
  67 + al = attempts.length;
  68 +
  69 + while( al-- ){
  70 + try {
  71 + xmlhttpmethod = attempts[ al ]();
  72 + }
  73 + catch(e) {
  74 + continue;
  75 + }
  76 + break;
  77 + }
  78 + return function(){
  79 + return xmlhttpmethod;
  80 + };
  81 + })();
  82 +
  83 + query = getQueryString();
  84 + css = query["css"];
  85 + domain = query["url"];
  86 +
  87 + if (css && domain) {
  88 + ajax(css, function (response) {
  89 + window.name = response;
  90 + window.location.href = domain;
  91 + });
  92 + }
  93 + }());
  94 + </script>
  95 +</body>
  96 +</html>
  1 +/*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl
  2 + * Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT
  3 + * */
  4 +
  5 +!function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='&shy;<style media="'+a+'"> #mq-test-1 { width: 42px; }</style>',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.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]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b<s.length;b++){var c=s[b],e=c.href,f=c.media,g=c.rel&&"stylesheet"===c.rel.toLowerCase();e&&g&&!o[e]&&(c.styleSheet&&c.styleSheet.rawCssText?(v(c.styleSheet.rawCssText,e,f),o[e]=!0):(!/^([a-zA-Z:]*\/\/)/.test(e)&&!r||e.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&("//"===e.substring(0,2)&&(e=a.location.protocol+e),d.push({href:e,media:f})))}w()};x(),c.update=x,c.getEmValue=t,a.addEventListener?a.addEventListener("resize",b,!1):a.attachEvent&&a.attachEvent("onresize",b)}}(this);
  1 +/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
  2 +(function(win, doc, undefined){
  3 + var docElem = doc.documentElement,
  4 + proxyURL = doc.getElementById("respond-proxy").href,
  5 + redirectURL = (doc.getElementById("respond-redirect") || location).href,
  6 + baseElem = doc.getElementsByTagName("base")[0],
  7 + urls = [],
  8 + refNode;
  9 +
  10 + function encode(url){
  11 + return win.encodeURIComponent(url);
  12 + }
  13 +
  14 + function fakejax( url, callback ){
  15 +
  16 + var iframe,
  17 + AXO;
  18 +
  19 + // All hail Google http://j.mp/iKMI19
  20 + // Behold, an iframe proxy without annoying clicky noises.
  21 + if ( "ActiveXObject" in win ) {
  22 + AXO = new ActiveXObject( "htmlfile" );
  23 + AXO.open();
  24 + AXO.write( '<iframe id="x"></iframe>' );
  25 + AXO.close();
  26 + iframe = AXO.getElementById( "x" );
  27 + } else {
  28 + iframe = doc.createElement( "iframe" );
  29 + iframe.style.cssText = "position:absolute;top:-99em";
  30 + docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
  31 + }
  32 +
  33 + iframe.src = checkBaseURL(proxyURL) + "?url=" + encode(redirectURL) + "&css=" + encode(checkBaseURL(url));
  34 +
  35 + function checkFrameName() {
  36 + var cssText;
  37 +
  38 + try {
  39 + cssText = iframe.contentWindow.name;
  40 + }
  41 + catch (e) { }
  42 +
  43 + if (cssText) {
  44 + // We've got what we need. Stop the iframe from loading further content.
  45 + iframe.src = "about:blank";
  46 + iframe.parentNode.removeChild(iframe);
  47 + iframe = null;
  48 +
  49 +
  50 + // Per http://j.mp/kn9EPh, not taking any chances. Flushing the ActiveXObject
  51 + if (AXO) {
  52 + AXO = null;
  53 +
  54 + if (win.CollectGarbage) {
  55 + win.CollectGarbage();
  56 + }
  57 + }
  58 +
  59 + callback(cssText);
  60 + }
  61 + else{
  62 + win.setTimeout(checkFrameName, 100);
  63 + }
  64 + }
  65 +
  66 + win.setTimeout(checkFrameName, 500);
  67 + }
  68 +
  69 + // http://stackoverflow.com/a/472729
  70 + function checkBaseURL(href) {
  71 + var el = document.createElement('div'),
  72 + escapedURL = href.split('&').join('&amp;').
  73 + split('<').join('&lt;').
  74 + split('"').join('&quot;');
  75 +
  76 + el.innerHTML = '<a href="' + escapedURL + '">x</a>';
  77 + return el.firstChild.href;
  78 + }
  79 +
  80 + function checkRedirectURL() {
  81 + // IE6 & IE7 don't build out absolute urls in <link /> attributes.
  82 + // So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif.
  83 + // This trickery resolves that issue.
  84 + if (~ !redirectURL.indexOf(location.host)) {
  85 +
  86 + var fakeLink = doc.createElement("div");
  87 +
  88 + fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>';
  89 + docElem.insertBefore(fakeLink, docElem.firstElementChild || docElem.firstChild );
  90 +
  91 + // Grab the parsed URL from that dummy object
  92 + redirectURL = fakeLink.firstChild.href;
  93 +
  94 + // Clean up
  95 + fakeLink.parentNode.removeChild(fakeLink);
  96 + fakeLink = null;
  97 + }
  98 + }
  99 +
  100 + function buildUrls(){
  101 + var links = doc.getElementsByTagName( "link" );
  102 +
  103 + for( var i = 0, linkl = links.length; i < linkl; i++ ){
  104 +
  105 + var thislink = links[i],
  106 + href = links[i].href,
  107 + extreg = (/^([a-zA-Z:]*\/\/(www\.)?)/).test( href ),
  108 + ext = (baseElem && !extreg) || extreg;
  109 +
  110 + //make sure it's an external stylesheet
  111 + if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){
  112 + (function( link ){
  113 + fakejax( href, function( css ){
  114 + link.styleSheet.rawCssText = css;
  115 + respond.update();
  116 + } );
  117 + })( thislink );
  118 + }
  119 + }
  120 +
  121 +
  122 + }
  123 +
  124 + if( !respond.mediaQueriesSupported ){
  125 + checkRedirectURL();
  126 + buildUrls();
  127 + }
  128 +
  129 +})( window, document );