add tests for End() rollbacks, doc

This commit is contained in:
Martin Angers
2012-09-05 09:35:53 -04:00
parent 3aaca8f8ea
commit 2d885ccd3a
11 changed files with 169 additions and 47 deletions
+1 -13
View File
@@ -47,20 +47,8 @@ func (this *Selection) Get(index int) *html.Node {
// Index() returns the position of the first element within the Selection object
// relative to its sibling elements.
func (this *Selection) Index() int {
// TODO : Eventually refactor with prevAll(), like jQuery's code
if len(this.Nodes) > 0 {
n := this.Nodes[0]
if p := n.Parent; p != nil {
var i = 0
for _, c := range p.Child {
if c == n {
// This is the index of the element
return i
} else if c.Type == html.ElementNode {
i++
}
}
}
return newSingleSelection(this.Nodes[0], this.document).PrevAll().Length()
}
return -1
}