mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2026-10-21 06:54:43 +00:00
Merge pull request #588 from jvoisin/deadparam
refactor: remove a dead param in getClassesAndAttr
This commit is contained in:
+5
-5
@@ -117,7 +117,7 @@ func (s *Selection) AddClass(class ...string) *Selection {
|
||||
|
||||
tcls := getClassesSlice(classStr)
|
||||
for _, n := range s.Nodes {
|
||||
curClasses, attr := getClassesAndAttr(n, true)
|
||||
curClasses, attr := getClassesAndAttr(n)
|
||||
for _, newClass := range tcls {
|
||||
if !strings.Contains(curClasses, " "+newClass+" ") {
|
||||
curClasses += newClass + " "
|
||||
@@ -169,7 +169,7 @@ func (s *Selection) RemoveClass(class ...string) *Selection {
|
||||
if remove {
|
||||
removeAttr(n, "class")
|
||||
} else {
|
||||
classes, attr := getClassesAndAttr(n, true)
|
||||
classes, attr := getClassesAndAttr(n)
|
||||
for _, rcl := range rclasses {
|
||||
classes = strings.ReplaceAll(classes, " "+rcl+" ", " ")
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func (s *Selection) ToggleClass(class ...string) *Selection {
|
||||
tcls := getClassesSlice(classStr)
|
||||
|
||||
for _, n := range s.Nodes {
|
||||
classes, attr := getClassesAndAttr(n, true)
|
||||
classes, attr := getClassesAndAttr(n)
|
||||
for _, tcl := range tcls {
|
||||
spaceAroundTcl := " " + tcl + " "
|
||||
if strings.Contains(classes, spaceAroundTcl) {
|
||||
@@ -232,11 +232,11 @@ func getAttributeValue(attrName string, n *html.Node) (val string, exists bool)
|
||||
}
|
||||
|
||||
// Get and normalize the "class" attribute from the node.
|
||||
func getClassesAndAttr(n *html.Node, create bool) (classes string, attr *html.Attribute) {
|
||||
func getClassesAndAttr(n *html.Node) (classes string, attr *html.Attribute) {
|
||||
// Applies only to element nodes
|
||||
if n.Type == html.ElementNode {
|
||||
attr = getAttributePtr("class", n)
|
||||
if attr == nil && create {
|
||||
if attr == nil {
|
||||
n.Attr = append(n.Attr, html.Attribute{
|
||||
Key: "class",
|
||||
Val: "",
|
||||
|
||||
Reference in New Issue
Block a user