Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple-selector rules (definitions w. commas) #20

Closed
psema4 opened this issue Jun 15, 2011 · 2 comments
Closed

Multiple-selector rules (definitions w. commas) #20

psema4 opened this issue Jun 15, 2011 · 2 comments

Comments

@psema4
Copy link

psema4 commented Jun 15, 2011

I'm looking to use cssom alongside jsdom to validate (and expunge unused) css rules.

Cssom has saved me quite a bit of time but It seems like selectors separated by commas aren't treated as individual rules by cssom.

In my app the logic looks like:

  1. Set user-agent and request webpage
  2. Foreach CSS file
  3. Foreach selector
  4. Use jquery to count references to the current selector and store the count in a "registry"

The following is a log excerpt showing selectors read from the css file:

  • Setting UA: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
  • Window Dimensions: 1024x768
  • Has document.getElementsByTagName: true
  • Processing css/ui.css:
  • Regsitry File Key: ui_css
  • Number of rules: 3296
  • Counting references to .ui-slider-vertical .ui-slider-range-max [cls_ui-slider-vertical_-_cls_ui-slider-range-max]
  • Counting references to .ruler [cls_ruler]
  • Counting references to .ruler_time [cls_ruler_time]
  • Counting references to .ui-state-default1, .ui-widget-content .ui-state-default1 [cls_ui-state-default1,_-cls_ui-widget-content-_cls_ui-state-default1]
  • Skipping pseudo selector ".ui-state-default1 a, .ui-state-default1 a:link, .ui-state-default1 a:visited"

The rules above (with the last two showing commas) are from the jQuery UI CSS Framework:

.ui-state-default1, .ui-widget-content .ui-state-default1 { background: url(/js/sliders/aerow_normal.gif) 50% 50% no-repeat; font-weight: normal; color: #555555; outline: none; }
.ui-state-default1 a, .ui-state-default1 a:link, .ui-state-default1 a:visited { color: #555555; text-decoration: none; outline: none; }

@NV
Copy link
Owner

NV commented Jun 15, 2011

... selectors separated by commas aren't treated as individual rules by cssom.

It has been done by design. Browsers do exact same thing.

You have to parse selectors on your own. I believe, simple split(',') would work in most cases.

@NV NV closed this as completed Jun 15, 2011
@psema4
Copy link
Author

psema4 commented Jun 15, 2011

Fair enough - split's they way I've gone. Thanks @NV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants