Class: Browser::CSS::StyleSheet

Inherits:
Object
  • Object
show all
Includes:
NativeCachedWrapper
Defined in:
opal/browser/css/style_sheet.rb

Defined Under Namespace

Classes: Media

Instance Method Summary collapse

Methods included from NativeCachedWrapper

#restricted?, #set_native_reference

Constructor Details

#initialize(what) ⇒ StyleSheet

Returns a new instance of StyleSheet.



7
8
9
10
11
12
13
# File 'opal/browser/css/style_sheet.rb', line 7

def initialize(what)
  if DOM::Element === what
    super(`#{what.to_n}.sheet`)
  else
    super(what)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



64
65
66
# File 'opal/browser/css/style_sheet.rb', line 64

def method_missing(*args, &block)
  rules.__send__(*args, &block)
end

Instance Method Details

#[](id) ⇒ Object



60
61
62
# File 'opal/browser/css/style_sheet.rb', line 60

def [](id)
  rules.find { |r| log r; r.id == id }
end

#delete(index) ⇒ Object



38
39
40
# File 'opal/browser/css/style_sheet.rb', line 38

def delete(index)
  `#@native.deleteRule(index)`
end

#insert(index, rule) ⇒ Object



42
43
44
# File 'opal/browser/css/style_sheet.rb', line 42

def insert(index, rule)
  `#@native.insertRule(#{rule}, #{index})`
end

#mediaObject



20
21
22
# File 'opal/browser/css/style_sheet.rb', line 20

def media
  Media.new(`#@native.media`) if `#@native.media != null`
end

#ownerObject



24
25
26
# File 'opal/browser/css/style_sheet.rb', line 24

def owner
  DOM(`#@native.ownerNode`)
end

#parentObject



28
29
30
# File 'opal/browser/css/style_sheet.rb', line 28

def parent
  Sheet.new(`#@native.parentStyleSheet`) if `#@native.parentStyleSheet != null`
end

#rule(selector, body) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'opal/browser/css/style_sheet.rb', line 46

def rule(selector, body)
  unless String === selector
    selector = selector.join ', '
  end

  unless String === body
    body = body.map {|name, value|
      "#{name}: #{value};"
    }.join "\n"
  end

  insert(length, "#{selector} { #{body} }")
end

#rulesObject



32
33
34
35
36
# File 'opal/browser/css/style_sheet.rb', line 32

def rules
  Native::Array.new(`#@native.cssRules`) { |e|
    Rule.new(e)
  }
end