From 5fa6e3d960c55374496666a1c24fe938363d2949 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 22 Apr 2012 18:02:15 +0200 Subject: [PATCH] Prefixfree update. closes #128 --- .../static/scripts/library/prefix_free.js | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/couchpotato/static/scripts/library/prefix_free.js b/couchpotato/static/scripts/library/prefix_free.js index 1ca634ee..4876187b 100644 --- a/couchpotato/static/scripts/library/prefix_free.js +++ b/couchpotato/static/scripts/library/prefix_free.js @@ -25,20 +25,24 @@ var self = window.StyleFix = { var url = link.href || link.getAttribute('data-href'), base = url.replace(/[^\/]+$/, ''), parent = link.parentNode, - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(), + process; - xhr.open('GET', url); - xhr.onreadystatechange = function() { if(xhr.readyState === 4) { + process(); + } + }; + + process = function() { var css = xhr.responseText; - if(css && link.parentNode) { + if(css && link.parentNode && (!xhr.status || xhr.status < 400 || xhr.status > 600)) { css = self.fix(css, true, link); // Convert relative URLs to absolute, if needed if(base) { - css = css.replace(/url\(((?:"|')?)(.+?)\1\)/gi, function($0, quote, url) { + css = css.replace(/url\(\s*?((?:"|')?)(.+?)\1\s*?\)/gi, function($0, quote, url) { if(!/^([a-z]{3,10}:|\/|#)/i.test(url)) { // If url not absolute & not a hash // May contain sequences like /../ and /./ but those DO work return 'url("' + base + url + '")'; @@ -60,10 +64,21 @@ var self = window.StyleFix = { parent.insertBefore(style, link); parent.removeChild(link); } - } }; - - xhr.send(null); + + try { + xhr.open('GET', url); + xhr.send(null); + } catch (e) { + // Fallback to XDomainRequest if available + if (typeof XDomainRequest != "undefined") { + xhr = new XDomainRequest(); + xhr.onerror = xhr.onprogress = function() {}; + xhr.onload = process; + xhr.open("GET", url); + xhr.send(null); + } + } link.setAttribute('data-inprogress', ''); }, @@ -135,7 +150,7 @@ function $(expr, con) { })(); /** - * PrefixFree 1.0.4 + * PrefixFree 1.0.5 * @author Lea Verou * MIT license */ @@ -300,6 +315,10 @@ var functions = { 'element': { property: 'backgroundImage', params: '#foo' + }, + 'cross-fade': { + property: 'backgroundImage', + params: 'url(a.png), url(b.png), 50%' } };