Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #127 from Shopify/respond-js
Browse files Browse the repository at this point in the history
Added media query support to oldIE with respond.js
  • Loading branch information
cshold committed Jun 20, 2014
2 parents e07dc9b + e42a4b4 commit 215c621
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 54 deletions.
8 changes: 4 additions & 4 deletions assets/ajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ var ajaxifyShopify = (function(module, $) {
sizeModal = function(isResizing) {
if (!isResizing) {
$modalContainer.css('opacity', 0);
$closeCart.css('opacity', 0);
}

// Position modal by negative margin
Expand All @@ -474,7 +473,7 @@ var ajaxifyShopify = (function(module, $) {
right: ( $w.width() - ( $modalContainer.offset().left + $modalContainer.outerWidth() ) - 15 ),
opacity: 1
});
}, 600);
}, 460);

toggleCallback({
'is_visible': true
Expand Down Expand Up @@ -760,8 +759,9 @@ var ajaxifyShopify = (function(module, $) {

/* Hack to get product image thumbnail
* - Remove file extension, add _small, and re-add extension
* - Create server relative link
*/
var prodImg = cartItem.image.replace(/(\.[^.]*)$/, "_small$1");
var prodImg = cartItem.image.replace(/(\.[^.]*)$/, "_small$1").replace('http:', '');
var prodName = cartItem.title.replace(/(\-[^-]*)$/, "");
var prodVariation = cartItem.title.replace(/^[^\-]*/, "").replace(/-/, "");

Expand Down Expand Up @@ -1083,4 +1083,4 @@ var ajaxifyShopify = (function(module, $) {

return module;

}(ajaxifyShopify || {}, jQuery));
}(ajaxifyShopify || {}, jQuery));
6 changes: 3 additions & 3 deletions assets/ajaxify.scss.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $gutter: 24px;

/*============================================================================
Dependency-free breakpoint mixin
- http://blog.grayghostvisuals.com/sass/sass-media-query-mixin/
// http://blog.grayghostvisuals.com/sass/sass-media-query-mixin/
==============================================================================*/
$min: min-width;
$max: max-width;
Expand Down Expand Up @@ -599,7 +599,7 @@ form[action^="/cart/add"] {
#ajaxifyModal .ajaxifyCart--content {
background-color: $modalBackgroundColor;
color: color-control($modalBackgroundColor);
@include transform(scale(0.7));
@include transform(scale(0.9));
opacity: 0;

// Typography styles
Expand Down Expand Up @@ -807,7 +807,7 @@ form[action^="/cart/add"] {
background-color: $ajaxifyGreyDark;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDE0IDc5LjE1MTQ4MSwgMjAxMy8wMy8xMy0xMjowOToxNSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkMzRUY2REVBNDY1QjExRTM4ODdCODU0OEQ4MDA1MjgwIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkMzRUY2REVCNDY1QjExRTM4ODdCODU0OEQ4MDA1MjgwIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QzNFRjZERTg0NjVCMTFFMzg4N0I4NTQ4RDgwMDUyODAiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QzNFRjZERTk0NjVCMTFFMzg4N0I4NTQ4RDgwMDUyODAiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz7sdZ8fAAAAp0lEQVR42nSPQQ6CMBBFx4ZEj+DSY8BGt9SVwRP1QBDdULeygaN4BFzpn+Q3mZCW5DFk/uvQ2YUQfiIygYuUnzc4O7wW/QCxIEbmi8oNG23mgO03js0reDF4gCNry77mUpkpHvSgo7QHA7gnwW1+q8FKcbViTtbJB/Bl7Uty5BWe4MTa2aWTPJplbuDDmpYe04IzqBn4zbU8J2udHcUpI9oDmtd/AQYAX20mtnhTCxQAAAAASUVORK5CYII=);
z-index: 999999999;
@include transition(all 100ms ease-in-out);
@include transition(opacity 100ms ease-in-out);

#ajaxifyModal.is-visible + & {
display: block;
Expand Down
96 changes: 96 additions & 0 deletions assets/respond-proxy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!-- 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, query, getQueryString, ajax, xmlHttp;

/*
http://stackoverflow.com/questions/4963673/get-url-array-variables-in-javascript-jquery/4963817#4963817
*/
getQueryString = function() {
var ret = {}, parts, i, p;

parts = (document.location.toString().split("?")[1]).split("&");

for (i = 0; i < parts.length; i++) {

p = parts[i].split("=");
// so strings will be correctly parsed:
p[1] = decodeURIComponent(p[1].replace(/\+/g, " "));

if (p[0].search(/\[\]/) >= 0) { // then it"s an array
p[0] = p[0].replace("[]", "");

if (typeof ret[p[0]] != "object") {
ret[p[0]] = [];
}
ret[p[0]].push(p[1]);
} else {
ret[p[0]] = p[1];
}
}
return ret;
};

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;
};
})();

query = getQueryString();
css = query["css"];
domain = query["url"];

if (css && domain) {
ajax(css, function (response) {
window.name = response;
window.location.href = domain;
});
}
}());
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions assets/respond.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/timber.scss.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ body {

.main-content {
display: block;
padding-top: $gutter;
margin-top: $gutter;
padding-bottom: $gutter*2;
}

Expand Down
9 changes: 9 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@
<!-- Header hook for plugins ================================================== -->
{{ content_for_header }}

{% comment %}
Setup respond.js for media query support in oldIE
- By Gavin Ballard: http://gavinballard.com/using-respond.js-with-shopify-redux/
{% endcomment %}
{% assign respond_js_secret_key = (shop.domain | md5) %}
<!--[if lt IE 9]>
{{ '//html5shiv.googlecode.com/svn/trunk/html5.js' | script_tag }}
<script src="{{ 'respond.min.js' | asset_url }}"></script>
<link href="{{ 'respond-proxy.html' | asset_url | split: '?' | first }}" id="respond-proxy" rel="respond-proxy" />
<link href="//{{shop.domain}}/search?q={{ respond_js_secret_key }}" id="respond-redirect" rel="respond-redirect" />
<script src="//{{shop.domain}}/search?q={{ respond_js_secret_key }}" type="text/javascript"></script>
<![endif]-->

{% comment %}
Expand Down
129 changes: 129 additions & 0 deletions snippets/respond.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*! 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 encode(url){
return win.encodeURIComponent(url);
}

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=" + encode(redirectURL) + "&css=" + encode(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);
}

// http://stackoverflow.com/a/472729
function checkBaseURL(href) {
var el = document.createElement('div'),
escapedURL = href.split('&').join('&amp;').
split('<').join('&lt;').
split('"').join('&quot;');

el.innerHTML = '<a href="' + escapedURL + '">x</a>';
return el.firstChild.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 comments on commit 215c621

Please sign in to comment.