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.


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

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


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

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

Instance Method Details

#[](id) ⇒ Object


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

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

#delete(index) ⇒ Object


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

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

#insert(index, rule) ⇒ Object


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

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

#mediaObject


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

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

#ownerObject


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

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

#parentObject


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

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

#rule(selector, body) ⇒ Object


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

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


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

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