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

Fix typo with getAttributeSelectors #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions build/css-selector-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
result.c = this.getClassSelectors(element);
}
if (indexOf.call(this.options.selectors, 'attribute') >= 0) {
result.a = this.getAttributeSelector(element);
result.a = this.getAttributeSelectors(element);
}
if (indexOf.call(this.options.selectors, 'nthchild') >= 0) {
result.n = this.getNthChildSelector(element);
Expand All @@ -205,14 +205,23 @@
};

CssSelectorGenerator.prototype.getUniqueSelector = function(element) {
var all_classes, selector, selectors;
var all_classes, i, item, len, ref, selector, selectors;
selectors = this.getAllSelectors(element);
if (selectors.i != null) {
return selectors.i;
}
if (this.testUniqueness(element, selectors.t)) {
return selectors.t;
}
if (selectors.a !== null && selectors.a.length !== 0) {
ref = selectors.a;
for (i = 0, len = ref.length; i < len; i++) {
item = ref[i];
if (this.testUniqueness(element, item)) {
return item;
}
}
}
if (selectors.c.length !== 0) {
all_classes = selectors.c.join('');
selector = all_classes;
Expand Down
7 changes: 6 additions & 1 deletion src/css-selector-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CssSelectorGenerator
result.c = @getClassSelectors element

if 'attribute' in @options.selectors
result.a = @getAttributeSelector element
result.a = @getAttributeSelectors element

if 'nthchild' in @options.selectors
result.n = @getNthChildSelector element
Expand All @@ -159,6 +159,11 @@ class CssSelectorGenerator
# tag selector (should return unique for BODY)
return selectors.t if @testUniqueness element, selectors.t

# attribute selector
if selectors.a isnt null and selectors.a.length isnt 0
for item in selectors.a
return item if @testUniqueness element, item

# TODO check each class separately
# class selector
if selectors.c.length isnt 0
Expand Down