Authored by xuqi

respond crossdomain.Review by:@bikai

@@ -12,27 +12,38 @@ @@ -12,27 +12,38 @@
12 {{#if rlsEnv}} 12 {{#if rlsEnv}}
13 <link rel="stylesheet" href="http://cdn.yoho.cn/yohobuy/{{version}}/index.css"> 13 <link rel="stylesheet" href="http://cdn.yoho.cn/yohobuy/{{version}}/index.css">
14 <!--[if lt IE 9]> 14 <!--[if lt IE 9]>
15 - <script src="http://cdn.yoho.cn/yohobuy/respond.min.js"></script> 15 + <script src="http://cdn.yoho.cn/yohobuy/respond/respond.min.js"></script>
  16 + <link href="http://cdn.yoho.cn/yohobuy/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
  17 + <script src="http://cdn.yoho.cn/yohobuy/respond/respond.proxy.js"></script>
16 <![endif]--> 18 <![endif]-->
17 {{/if}} 19 {{/if}}
18 {{#if preEnv}} 20 {{#if preEnv}}
19 <link rel="stylesheet" href="http://cdn.yoho.cn/yohobuy/{{version}}/index.css"> 21 <link rel="stylesheet" href="http://cdn.yoho.cn/yohobuy/{{version}}/index.css">
20 <!--[if lt IE 9]> 22 <!--[if lt IE 9]>
21 - <script src="http://cdn.yoho.cn/yohobuy/respond.min.js"></script> 23 + <script src="http://cdn.yoho.cn/yohobuy/respond/respond.min.js"></script>
  24 + <link href="http://cdn.yoho.cn/yohobuy/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
  25 + <script src="http://cdn.yoho.cn/yohobuy/respond/respond.proxy.js"></script>
22 <![endif]--> 26 <![endif]-->
23 {{/if}} 27 {{/if}}
24 {{#if testEnv}} 28 {{#if testEnv}}
25 <link rel="stylesheet" href="http://static.buy.test.yoho.cn/dist/yohobuy/{{version}}/index.css"> 29 <link rel="stylesheet" href="http://static.buy.test.yoho.cn/dist/yohobuy/{{version}}/index.css">
26 <!--[if lt IE 9]> 30 <!--[if lt IE 9]>
27 - <script src="http://static.buy.test.yoho.cn/dist/yohobuy/respond.min.js"></script> 31 + <script src="http://static.buy.test.yoho.cn/dist/yohobuy/respond/respond.min.js"></script>
  32 + <link href="http://static.buy.test.yoho.cn/dist/yohobuy/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
  33 + <script src="http://static.buy.test.yoho.cn/dist/yohobuy/respond/respond.proxy.js"></script>
28 <![endif]--> 34 <![endif]-->
29 {{/if}} 35 {{/if}}
30 {{#if devEnv}} 36 {{#if devEnv}}
31 <link rel="stylesheet" href="http://webstatic.dev.yohobuy.com/css/index.css"> 37 <link rel="stylesheet" href="http://webstatic.dev.yohobuy.com/css/index.css">
32 <!--[if lt IE 9]> 38 <!--[if lt IE 9]>
33 - <script src="http://webstatic.dev.yohobuy.com/plugin/page-use/respond.min.js"></script> 39 + <script src="http://webstatic.dev.yohobuy.com/plugin/page/respond/respond.min.js"></script>
  40 + <link href="http://webstatic.dev.yohobuy.com/plugin/page/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
  41 + <script src="http://webstatic.dev.yohobuy.com/plugin/page/respond/respond.proxy.js"></script>
34 <![endif]--> 42 <![endif]-->
35 {{/if}} 43 {{/if}}
  44 + <!--[if lt IE 9]>
  45 + <link href="proxy/respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
  46 + <![endif]-->
36 </head> 47 </head>
37 <body> 48 <body>
38 {{> layout/page-header}} 49 {{> layout/page-header}}
@@ -195,6 +195,6 @@ gulp.task('business', ['libs'], function() { @@ -195,6 +195,6 @@ gulp.task('business', ['libs'], function() {
195 195
196 //页面需要直接标签引用的JS 196 //页面需要直接标签引用的JS
197 gulp.task('script', function() { 197 gulp.task('script', function() {
198 - gulp.src('plugin/page-use/*') 198 + gulp.src('plugin/page/**/*')
199 .pipe(gulp.dest(rootDist)); 199 .pipe(gulp.dest(rootDist));
200 }); 200 });
  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: 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 );