Module: DOM::ClassList

Included in:
Element
Defined in:
opal/fron/dom/modules/classlist.rb

Overview

ClassList management for DOM::Element

Instance Method Summary collapse

Instance Method Details

#addClass(*classes) ⇒ Object

Adds classes to the class list


7
8
9
# File 'opal/fron/dom/modules/classlist.rb', line 7

def addClass(*classes)
  classes.each { |cls| `#{@el}.classList.add(#{cls})` }
end

#hasClass(cls) ⇒ Boolean

Returns whether the class list has the given class or not


23
24
25
# File 'opal/fron/dom/modules/classlist.rb', line 23

def hasClass(cls)
  `#{@el}.classList.contains(#{cls})`
end

#removeClass(*classes) ⇒ Object

Removes classes from the class list


14
15
16
# File 'opal/fron/dom/modules/classlist.rb', line 14

def removeClass(*classes)
  classes.each { |cls| `#{@el}.classList.remove(#{cls})` }
end

#toggleClass(cls, value = nil) ⇒ Object

Toggles the given class based on the second argument, or if omitted then toggles the class.


32
33
34
35
36
37
38
# File 'opal/fron/dom/modules/classlist.rb', line 32

def toggleClass(cls, value = nil)
  if value || (value.nil? && !hasClass(cls))
    addClass cls
  else
    removeClass cls
  end
end