Comparing version 0.0.4 to 0.0.5
@@ -22,3 +22,3 @@ | ||
exports.version = '0.0.4'; | ||
exports.version = '0.0.5'; | ||
@@ -44,2 +44,9 @@ /** | ||
/** | ||
* Ignored pseudo-selectors. | ||
* | ||
*/ | ||
exports.ignoredPseudos = ['hover', 'active', 'focus', 'visited', 'link']; | ||
/** | ||
* Inlines the CSS specified by `css` into the `html` | ||
@@ -53,3 +60,3 @@ * | ||
var styleSelector = new Selector('<style attribute>', [1, 0, 0, 0]) | ||
, importantSelector = new Selector('!important', [2, 0, 0, 0]) | ||
, importantSelector = new Selector('<!important>', [2, 0, 0, 0]) | ||
@@ -65,9 +72,11 @@ function juice (html, css, options) { | ||
, style = rule[1] | ||
, matches = document.querySelectorAll(sel) | ||
, selector | ||
, selector = new Selector(sel) | ||
utils.toArray(matches).forEach(function (el) { | ||
// we initialize the Selector lazily to avoid needless parsing | ||
if (!selector) selector = new Selector(sel) | ||
if (selector.parsed().some(function (sel) { | ||
return sel.pseudos && sel.pseudos.some(function (pseudo) { | ||
return ~exports.ignoredPseudos.indexOf(pseudo.key); | ||
}); | ||
})) return; | ||
utils.toArray(document.querySelectorAll(sel)).forEach(function (el) { | ||
if (!el.styleProps) { | ||
@@ -74,0 +83,0 @@ el.styleProps = {} |
@@ -6,3 +6,3 @@ | ||
var parse = require('mootools-slick-parser').Slick.parse | ||
var parser = require('mootools-slick-parser').Slick.parse | ||
@@ -29,2 +29,13 @@ /** | ||
/** | ||
* Get parsed selector. | ||
* | ||
* @api public | ||
*/ | ||
Selector.prototype.parsed = function () { | ||
if (!this.tokens) this.tokens = parse(this.text); | ||
return this.tokens; | ||
}; | ||
/** | ||
* Lazy specificity getter | ||
@@ -36,8 +47,7 @@ * | ||
Selector.prototype.specificity = function () { | ||
if (!this.spec) return specificity(this.text); | ||
if (!this.spec) this.spec = specificity(this.text, this.parsed()); | ||
return this.spec; | ||
function specificity (text) { | ||
var parsed = parse(text) | ||
, expressions = parsed.expressions[0] | ||
function specificity (text, parsed) { | ||
var expressions = parsed || parse(text) | ||
, spec = [0, 0, 0, 0] | ||
@@ -81,1 +91,16 @@ , nots = [] | ||
} | ||
/** | ||
* Parses a selector and returns the tokens. | ||
* | ||
* @param {String} selector | ||
* @api private. | ||
*/ | ||
function parse (text) { | ||
try { | ||
return parser(text).expressions[0]; | ||
} catch (e) { | ||
return []; | ||
} | ||
} |
@@ -77,3 +77,10 @@ | ||
exports.jsdom = function (html) { | ||
return jsdom.html(html, null, { features: { 'QuerySelector' : ['1.0'] } }); | ||
return jsdom.html(html, null, { | ||
features: { | ||
QuerySelector: ['1.0'] | ||
, FetchExternalResources: false | ||
, ProcessExternalResources: false | ||
, MutationEvents: false | ||
} | ||
}); | ||
}; | ||
@@ -80,0 +87,0 @@ |
{ | ||
"name": "juice" | ||
, "version": "0.0.4" | ||
, "version": "0.0.5" | ||
, "description": "Inlines css into html source" | ||
@@ -5,0 +5,0 @@ , "contributors": [ |
9006
318