Class: Browser::CSS::Declaration

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Native
Defined in:
opal/browser/css/declaration.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, value = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'opal/browser/css/declaration.rb', line 74

def method_missing(name, value = nil)
  if name.end_with? ?=
    self[name[0 .. -2]] = value
  else
    self[name]
  end
end

Instance Method Details

#[](name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'opal/browser/css/declaration.rb', line 37

def [](name)
  %x{
    var result = #@native.getPropertyValue(#{name});

    if (result == null || result === "") {
      return nil;
    }

    return result;
  }
end

#[]=(name, value) ⇒ Object



49
50
51
# File 'opal/browser/css/declaration.rb', line 49

def []=(name, value)
  `#@native.setProperty(#{name}, #{value.to_s}, "")`
end

#apply(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'opal/browser/css/declaration.rb', line 23

def apply(&block)
  Paggio::CSS::Definition.new(&block).each {|style|
    if style.important
      `#@native.setProperty(#{style.name}, #{style.value}, "important")`
    else
      `#@native.setProperty(#{style.name}, #{style.value}, "")`
    end
  }
end

#assign(data) ⇒ Object



11
12
13
14
15
16
17
# File 'opal/browser/css/declaration.rb', line 11

def assign(data)
  data.each {|name, value|
    self[name] = value
  }

  self
end

#delete(name) ⇒ Object



33
34
35
# File 'opal/browser/css/declaration.rb', line 33

def delete(name)
  `#@native.removeProperty(#{name})`
end

#each(&block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'opal/browser/css/declaration.rb', line 57

def each(&block)
  return enum_for :each unless block_given?

  %x{
    for (var i = 0, length = #@native.length; i < length; i++) {
      var name  = #@native.item(i);

      #{yield `name`, self[`name`]}
    }
  }

  self
end

#important?(name) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'opal/browser/css/declaration.rb', line 53

def important?(name)
  `#@native.getPropertyPriority(#{name}) == "important"`
end

#replace(string) ⇒ Object



19
20
21
# File 'opal/browser/css/declaration.rb', line 19

def replace(string)
  `#@native.cssText = #{string}`
end

#ruleObject



7
8
9
# File 'opal/browser/css/declaration.rb', line 7

def rule
  Rule.new(`#@native.parentRule`) if defined?(`#@native.parentRule`)
end