From 215f6a94d629d23b1dbbf941f2dc2cd160d2d99a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 May 2014 09:30:09 +0530 Subject: [PATCH] Only return first matching selector, instead of the full selector text --- resources/compiled_coffeescript.zip | Bin 90366 -> 90885 bytes src/calibre/ebooks/oeb/polish/preview.coffee | 26 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index 125bd0cfa549210a82c77fa716073d6590f1e9de..e97e134b2dafc9f2a20fb1732aebc0edf925bc9e 100644 GIT binary patch delta 707 zcmex&khS#~Yr_^sIaR*49h+R%#<%D0G-qJgX}(=YmGPz!la9h<{@rq{sYNA~n%h|| z7}*%Pi!)MFOX4&0Qc^3XAFyI{p6+AGC>~poSX5H1qfk(kUjS5`nF?eV>L?VI=A=T% z_{5ZyqSRubFh~rdT}Pp~L`R{dvH++iJ`;$ufH)^L4?-FODWHzhoRZ?nA7{$(BJ?TP zDonp%$*3)eBBZSypE>=%C8HEKLO6E1juoR47eZiqpcP{wvKO`kz3`RM2;_R8vBf2N z#RWN;B^v5F>YCPE3Q&-lrl0}#pdQe5=_MHob_#~mHI*5aSwN!G1C$xH7K?1(V#655sG)d)pC3d!_+cPd;*n3OII0Mokk`F<{7LA>0L)1F8fD zep)n=!s)(_jCsgG2a0{q?MzOLU5pCI&P8){OEEPwH84*xNHI(?vb3;FH8!wJHnvDKO-;5)H8V4}G@G87 Mz$iBTZ~~(>01%7dm;e9( delta 321 zcmZoY#`^CdYr_^sIaR(ZlQy|roz|bY$&`U%lj(LHRmPh_+qEnh*%+rUc4l;(UT4WD z&YV}8JN<(Lql8d=VoFL;YH_iSLUDSX?8DGs2#f~|tC;pC4qb*JlCG0IH- zz{WQ{UYe0zCb_scs5B?FI66Kv)|yKJ3_!}YZ50fs*I6+tu>pBNnaK|qC`>Mhh33KO2jdwXI2fWC8U8UlWO7s diff --git a/src/calibre/ebooks/oeb/polish/preview.coffee b/src/calibre/ebooks/oeb/polish/preview.coffee index 30d5e5aeb7..95181b571d 100644 --- a/src/calibre/ebooks/oeb/polish/preview.coffee +++ b/src/calibre/ebooks/oeb/polish/preview.coffee @@ -156,19 +156,17 @@ get_style_properties = (style, all_properties, node_style, is_ancestor) -> property = style.item(i)?.toLowerCase() val = style.getPropertyValue(property) if property and val and (not is_ancestor or INHERITED_PROPS.hasOwnProperty(property)) - properties.push([property, val]) + properties.push([property, val, style.getPropertyPriority(property)]) if not all_properties.hasOwnProperty(property) all_properties[property] = node_style.getPropertyValue(property) i += 1 return properties -process_rules = (node, cssRules, address, sheet, matching_selectors, all_properties, node_style, is_ancestor, ans) -> - num = -1 - for rule in cssRules - num += 1 - rule_address = address + [num] +process_rules = (node, cssRules, address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) -> + for rule, rule_index in cssRules + rule_address = address + [rule_index] if rule.type == CSSRule.MEDIA_RULE - process_rules(node, rule.cssRules, rule_address, sheet, matching_selectors, all_properties, node_style, is_ancestor, ans) + process_rules(node, rule.cssRules, rule_address, sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) continue if rule.type != CSSRule.STYLE_RULE continue @@ -183,9 +181,15 @@ process_rules = (node, cssRules, address, sheet, matching_selectors, all_propert if href == null href = get_sourceline_address(sheet.ownerNode) type = 'elem' + parts = st.split(',') # We only want the first matching selector + if parts.length > 1 + for q in parts + if node.webkitMatchesSelector(q) + st = q + break properties = get_style_properties(rule.style, all_properties, node_style, is_ancestor) if properties.length > 0 - data = {'selector':st, 'type':type, 'href':href, 'properties':properties, 'is_ancestor':is_ancestor, 'rule_address':rule_address} + data = {'selector':st, 'type':type, 'href':href, 'properties':properties, 'is_ancestor':is_ancestor, 'rule_address':rule_address, 'sheet_index':sheet_index} ans.push(data) get_matched_css = (node, is_ancestor, all_properties) -> @@ -199,15 +203,15 @@ get_matched_css = (node, is_ancestor, all_properties) -> ans = [] node_style = window.getComputedStyle(node) - for sheet in document.styleSheets + for sheet, sheet_index in document.styleSheets if sheet.disabled continue - process_rules(node, sheet.cssRules, [], sheet, matching_selectors, all_properties, node_style, is_ancestor, ans) + process_rules(node, sheet.cssRules, [], sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) if node.getAttribute('style') properties = get_style_properties(node.style, all_properties, node_style, is_ancestor) if properties.length > 0 - data = {'selector':null, 'type':'inline', 'href':get_sourceline_address(node), 'properties':properties, 'is_ancestor':is_ancestor, 'rule_address':null} + data = {'selector':null, 'type':'inline', 'href':get_sourceline_address(node), 'properties':properties, 'is_ancestor':is_ancestor, 'rule_address':null, 'sheet_index':null} ans.push(data) return ans.reverse()