Module: Kernel

Defined in:
opal/browser/css.rb,
opal/browser/dom.rb,
opal/browser/delay.rb,
opal/browser/window.rb,
opal/browser/interval.rb,
opal/browser/immediate.rb,
opal/browser/animation_frame.rb

Instance Method Summary collapse

Instance Method Details

#after(time, &block) ⇒ Delay

Execute a block after the given seconds.

Parameters:

  • time (Float)

    the seconds after it gets called

Returns:

  • (Delay)

    the object representing the timeout


69
70
71
# File 'opal/browser/delay.rb', line 69

def after(time, &block)
  $window.after(time, &block)
end

#after!(time, &block) ⇒ Delay

Execute a block after the given seconds, you have to call [#start] on it yourself.

Parameters:

  • time (Float)

    the seconds after it gets called

Returns:

  • (Delay)

    the object representing the timeout


74
75
76
# File 'opal/browser/delay.rb', line 74

def after!(time, &block)
  $window.after!(time, &block)
end

#alert(value) ⇒ Object

Alert the passed string.


120
121
122
# File 'opal/browser/window.rb', line 120

def alert(value)
  $window.alert(value)
end

#animation_frame(&block) ⇒ Object


101
102
103
# File 'opal/browser/animation_frame.rb', line 101

def animation_frame(&block)
  Browser::AnimationFrame.new($window, &block)
end

#confirm(value) ⇒ Object

Display a confirmation dialog with the passed string as text.


130
131
132
# File 'opal/browser/window.rb', line 130

def confirm(value)
  $window.confirm(value)
end

#CSS(document = $document, &block) ⇒ Browser::DOM::Element #CSS(string, document = $document) ⇒ Browser::DOM::Element

Overloads:


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'opal/browser/css.rb', line 24

def CSS(*args, &block)
  document = if args.length > 1 || block_given?
    args.pop
  end || $document

  style = document.create_element(:style)
  style[:type] = 'text/css'

  if block
    style.inner_text = Paggio.css(&block)
  else
    style.inner_text = args.join("")
  end

  style
end

#defer(*args, &block) ⇒ Object


136
137
138
# File 'opal/browser/immediate.rb', line 136

def defer(*args, &block)
  Browser::Immediate.new(block, args).tap(&:dispatch)
end

#DOM(document = $document, &block) ⇒ Browser::DOM::Node, Browser::DOM::NodeSet #DOM(string, document = $document) ⇒ Browser::DOM::Node #DOM(native) ⇒ Browser::DOM::Node

Overloads:


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'opal/browser/dom.rb', line 64

def DOM(*args, &block)
  if block
    document = args.shift || $document
    roots    = Browser::DOM::Builder.new(document, &block).to_a

    if roots.length == 1
      roots.first
    else
      Browser::DOM::NodeSet.new(roots)
    end
  else
    what     = args.shift
    document = args.shift || $document

    if native?(what)
      Browser::DOM::Node.new(what)
    elsif Browser::DOM::Node === what
      what
    elsif String === what
      %x{
        var doc = #{Native.try_convert(document)}.createElement('div');
        doc.innerHTML = what;

        return #{DOM(`doc.childNodes.length == 1 ? doc.childNodes[0] : doc`)};
      }
    else
      raise ArgumentError, "argument not DOM convertible"
    end
  end
end

#every(time, &block) ⇒ Interval

Execute the block every given seconds.

Parameters:

  • time (Float)

    the seconds between every call

Returns:

  • (Interval)

    the object representing the interval


91
92
93
# File 'opal/browser/interval.rb', line 91

def every(time, &block)
  $window.every(time, &block)
end

#every!(time, &block) ⇒ Interval

Execute the block every given seconds, you have to call [#start] on it yourself.

Parameters:

  • time (Float)

    the seconds between every call

Returns:

  • (Interval)

    the object representing the interval


96
97
98
# File 'opal/browser/interval.rb', line 96

def every!(time, &block)
  $window.every!(time, &block)
end

#prompt(value, default = nil) ⇒ Object

Display a prompt dialog with the passed string as text.


125
126
127
# File 'opal/browser/window.rb', line 125

def prompt(value, default=nil)
  $window.prompt(value, default)
end

#resolve_after(time) ⇒ Promise

Returns a promise that will resolve after the given seconds.

Parameters:

  • time (Float)

    the seconds after it gets called

Returns:

  • (Promise)

    the promise that will resolve after timeout happens


79
80
81
# File 'opal/browser/delay.rb', line 79

def resolve_after(time)
  $window.resolve_after(time)
end

#XML(what) ⇒ Browser::DOM::Document

Parse an XML string into a DOM usable Browser::DOM::Document

Parameters:

  • what (String)

    the string to parse

Returns:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'opal/browser/dom.rb', line 20

def XML(what)
  %x{
    var doc;

    if (window.DOMParser) {
      doc = new DOMParser().parseFromString(what, 'text/xml');
    }
    else {
      doc       = new ActiveXObject('Microsoft.XMLDOM');
      doc.async = 'false';
      doc.loadXML(what);
    }
  }

  DOM(`doc`)
end