Class: DOM::Style

Inherits:
Object show all
Defined in:
opal/fron/dom/style.rb

Overview

Style

Instance Method Summary collapse

Constructor Details

#initialize(el) ⇒ Style

Initializes the style

Parameters:



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

def initialize(el)
  @el = el
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, value) ⇒ String

Sets or gets a given CSS property

Parameters:

  • name (String)

    The property

  • value (String)

    The value

Returns:

  • (String)

    The value of the property



17
18
19
20
21
22
23
# File 'opal/fron/dom/style.rb', line 17

def method_missing(name, value)
  if name =~ /\=$/
    self[name[0..-2]] = value
  else
    self[name]
  end
end

Instance Method Details

#[](prop) ⇒ String

Gets a CSS property value

Parameters:

  • prop (String)

    The property

Returns:

  • (String)

    The value of the property



30
31
32
# File 'opal/fron/dom/style.rb', line 30

def [](prop)
  `#{@el}.style[#{prop}]`
end

#[]=(prop, value) ⇒ Object

Sets the given CSS property with the given value

Parameters:

  • prop (String)

    The property

  • value (String)

    The value



38
39
40
# File 'opal/fron/dom/style.rb', line 38

def []=(prop, value)
  `#{@el}.style[#{prop}] = #{value}`
end