From b016a6c603040c8a0d7e94f5dbf34d9431aa3bfb Mon Sep 17 00:00:00 2001 From: TooBug Date: Fri, 11 Oct 2013 19:51:12 +0800 Subject: [PATCH 1/2] fix a bug when there's no element on page e.g. input[checkbox]:checked{ abc:abc; } when no checkbox on page, it will output: /*some css 1*/ { abc:abc; } /*some css 2*/ thus makes 'some css 2' invaild. Another case: input[checkbox]:checked,input[checkbox]:disabled:checked{ abc:abc; } if no checkbox is disabled, it will output: /*some css 1*/ CPS0,CPS1,{ abc:abc; } /*some css 2*/ makes the selector is invalid. --- jQuery.cssParentSelector.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jQuery.cssParentSelector.js b/jQuery.cssParentSelector.js index 91834cb..ecf63b2 100644 --- a/jQuery.cssParentSelector.js +++ b/jQuery.cssParentSelector.js @@ -73,9 +73,11 @@ declarations = declarations.replace(/;/g, ' !important;'); + var hasChild = false; + for (j = -1; selectors[++j], selector = $.trim(selectors[j]);) { - j && (parsed += ','); + // j && (parsed += ','); if (/!/.test(selector) ) { @@ -97,6 +99,9 @@ // E! P > F:state => state state = (selector.split('>')[1].split(/:+/)[1] || '').split(' ')[0] || []._; + if(child.length){ + hasChild = true; + } child.each(function(i) { @@ -124,7 +129,7 @@ $(subject).toggleClass(id) }; - i && (parsed += ','); + (j || i) && (parsed += ','); parsed += '.' + id; var $this = $(this); @@ -139,7 +144,12 @@ } } - parsed += declarations; + if(hasChild){ + + parsed += declarations; + + } + }; From b35169a19414431a844e555552b409ddcff101c2 Mon Sep 17 00:00:00 2001 From: TooBug Date: Fri, 11 Oct 2013 19:52:07 +0800 Subject: [PATCH 2/2] remove useless code --- jQuery.cssParentSelector.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/jQuery.cssParentSelector.js b/jQuery.cssParentSelector.js index ecf63b2..dd1d3f0 100644 --- a/jQuery.cssParentSelector.js +++ b/jQuery.cssParentSelector.js @@ -77,8 +77,6 @@ for (j = -1; selectors[++j], selector = $.trim(selectors[j]);) { - // j && (parsed += ','); - if (/!/.test(selector) ) { // E! P > F => E