Permalink
Browse files

initial plugin file commit

  • Loading branch information...
1 parent a068e6c commit 49c5a6eb9d6776431083a3500b482c8f55b04b06 @phikai committed Feb 14, 2012
View
Binary file not shown.
@@ -0,0 +1,80 @@
+<!-- Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs -->
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <title>Respond JS Proxy</title>
+</head>
+<body>
+ <script>
+ (function () {
+ var domain, css, url, match, file, ajax, xmlHttp;
+
+ 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();
+ };
+
+ //define ajax obj
+ xmlHttp = (function() {
+ var xmlhttpmethod = false,
+ attempts = [
+ function(){ return new XMLHttpRequest(); },
+ function(){ return new ActiveXObject("Microsoft.XMLHTTP"); },
+ function(){ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
+ ],
+ al = attempts.length;
+
+ while( al-- ){
+ try {
+ xmlhttpmethod = attempts[ al ]();
+ }
+ catch(e) {
+ continue;
+ }
+ break;
+ }
+ return function(){
+ return xmlhttpmethod;
+ };
+ })();
+
+ url = window.location.href;
+
+ if (url) {
+ match = (/css\=(.*\.css)$/).exec(url.slice(url.indexOf('?') + 1));
+
+ if (match && match[1]) {
+ css = match[1];
+ }
+
+ match = (/url\=([^&]+)/).exec(url);
+
+ if (match && match[1]) {
+ domain = match[1];
+ }
+ }
+
+ if (css) {
+ ajax(css, function (response) {
+ window.name = response;
+ window.location.href = domain;
+ });
+ }
+ }());
+ </script>
+</body>
+</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,123 @@
+/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
+(function(win, doc, undefined){
+ var docElem = doc.documentElement,
+ proxyURL = doc.getElementById("respond-proxy").href,
+ redirectURL = (doc.getElementById("respond-redirect") || location).href,
+ baseElem = doc.getElementsByTagName("base")[0],
+ urls = [],
+ refNode;
+
+ function fakejax( url, callback ){
+
+ var iframe,
+ AXO;
+
+ // All hail Google http://j.mp/iKMI19
+ // Behold, an iframe proxy without annoying clicky noises.
+ if ( "ActiveXObject" in win ) {
+ AXO = new ActiveXObject( "htmlfile" );
+ AXO.open();
+ AXO.write( '<iframe id="x"></iframe>' );
+ AXO.close();
+ iframe = AXO.getElementById( "x" );
+ } else {
+ iframe = doc.createElement( "iframe" );
+ iframe.style.cssText = "position:absolute;top:-99em";
+ docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild );
+ }
+
+ iframe.src = checkBaseURL(proxyURL) + "?url=" + redirectURL + "&css=" + checkBaseURL(url);
+
+ function checkFrameName() {
+ var cssText;
+
+ try {
+ cssText = iframe.contentWindow.name;
+ }
+ catch (e) { }
+
+ if (cssText) {
+ // We've got what we need. Stop the iframe from loading further content.
+ iframe.src = "about:blank";
+ iframe.parentNode.removeChild(iframe);
+ iframe = null;
+
+
+ // Per http://j.mp/kn9EPh, not taking any chances. Flushing the ActiveXObject
+ if (AXO) {
+ AXO = null;
+
+ if (win.CollectGarbage) {
+ win.CollectGarbage();
+ }
+ }
+
+ callback(cssText);
+ }
+ else{
+ win.setTimeout(checkFrameName, 100);
+ }
+ }
+
+ win.setTimeout(checkFrameName, 500);
+ }
+
+ function checkBaseURL(href) {
+ if (baseElem && href.indexOf(baseElem.href) === -1) {
+ bref = (/\/$/).test(baseElem.href) ? baseElem.href : (baseElem.href + "/");
+ href = bref + href;
+ }
+
+ return href;
+ }
+
+ function checkRedirectURL() {
+ // IE6 & IE7 don't build out absolute urls in <link /> attributes.
+ // So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif.
+ // This trickery resolves that issue.
+ if (~ !redirectURL.indexOf(location.host)) {
+
+ var fakeLink = doc.createElement("div");
+
+ fakeLink.innerHTML = '<a href="' + redirectURL + '"></a>';
+ docElem.insertBefore(fakeLink, docElem.firstElementChild || docElem.firstChild );
+
+ // Grab the parsed URL from that dummy object
+ redirectURL = fakeLink.firstChild.href;
+
+ // Clean up
+ fakeLink.parentNode.removeChild(fakeLink);
+ fakeLink = null;
+ }
+ }
+
+ function buildUrls(){
+ var links = doc.getElementsByTagName( "link" );
+
+ for( var i = 0, linkl = links.length; i < linkl; i++ ){
+
+ var thislink = links[i],
+ href = links[i].href,
+ extreg = (/^([a-zA-Z]+?:(\/\/)?(www\.)?)/).test( href ),
+ ext = (baseElem && !extreg) || extreg;
+
+ //make sure it's an external stylesheet
+ if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){
+ (function( link ){
+ fakejax( href, function( css ){
+ link.styleSheet.rawCssText = css;
+ respond.update();
+ } );
+ })( thislink );
+ }
+ }
+
+
+ }
+
+ if( !respond.mediaQueriesSupported ){
+ checkRedirectURL();
+ buildUrls();
+ }
+
+})( window, document );
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Where all the magic happens to set the crossdomain stuff up for you.
+ */
+
+function toz_rjsxd_header(){ ?>
+ <link href="<?php echo str_replace( home_url(), get_option('toz_rjsxd_external_domain'), plugin_dir_url(__FILE__)); ?>cross-domain/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
+<?php }
+
+function toz_rjsxd_footer(){ ?>
+ <link href="<?php echo plugin_dir_url(__FILE__); ?>cross-domain/respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
+ <script type="text/javascript" src="<?php echo plugin_dir_url(__FILE__); ?>cross-domain/respond.proxy.js"></script>
+<?php }
+?>
@@ -0,0 +1,53 @@
+<?php
+/*
+Plugin Name: TOZ Respond.js CrossDomain
+Plugin URI: http://thinkonezero.com
+Description: Easy setup for cross domain (CDN/Subdomain) use of respond.js for responsive design with IE8 and older browsers.
+Author: A. Kai Armstrong
+Version: 1.0
+Author URI: http://kaiarmstrong.com
+*/
+
+if ( @include_once('respond-js-xdomain-base.php') ) {
+ add_action('template_redirect','toz_rjsxd_header', 1);
+ add_action('template_redirect','toz_rjsxd_footer', 1);
+}
+
+/********** WordPress Administrative ********/
+
+function toz_rjsxd_activate() {
+ add_option('toz_rjsxd_external_domain', get_option('siteurl'));
+}
+register_activation_hook( __FILE__, 'toz_rjsxd_activate');
+
+/********** WordPress Interface ********/
+add_action('admin_menu', 'toz_rjsxd_admin_menu');
+
+function toz_rjsxd_admin_menu() {
+ add_options_page('RespondJS XDomain', 'RespondJS XDomain', 8, __FILE__, 'toz_rjsxd_options');
+}
+
+function toz_rjsxd_options() {
+ if ( isset($_POST['action']) && ( $_POST['action'] == 'update_toz_rjsxd' )){
+ update_option('toz_rjsxd_external_domain', $_POST['toz_rjsxd_external_domain']);
+ }
+ $example_external_domain = str_replace('http://', 'http://cdn.', str_replace('www.', '', get_option('siteurl')));
+
+ ?><div class="wrap">
+ <h2>Respond.js XDomain</h2>
+ <p>With the trend towards responsive design, it's important to compensate for older browsers. <a href="https://github.com/scottjehl/Respond"></a>Respond.js</a> does this, however if you're serving your CSS from a CDN you'll run into problems with it not working. This plugin provides easily sets up the necessary pieces for it to work cross domain.</p>
+ <p><form method="post" action="">
+ <table class="form-table"><tbod>
+ <tr valign="top">
+ <th scope="row"><label for="toz_rjsxd_external_domain">EXTERNAL DOMAIN</label></th>
+ <td>
+ <input type="text" name="toz_rjsxd_external_domain" value="<?php echo(get_option('toz_rjsxd_external_domain')); ?>" size="64" class="regular-text code" />
+ <span class="description">The base URL of your CDN or subdomain where your css is served from. <?php echo(get_option('siteurl')); ?> for rewriting. No trailing <code>/</code> please. E.g. <code><?php echo($example_external_domain); ?></code>.</span>
+ </td>
+ </tr>
+ </tbody></table>
+ <input type="hidden" name="action" value="update_toz_rjsxd" />
+ <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
+ </form></p>
+ </div><?php
+}

0 comments on commit 49c5a6e

Please sign in to comment.