Sha256: 51e270ea93e11d582d6f4d96d199800403345e3aee21e3c2c4e23e0ad2a1f271

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'browser/location'

module Browser; module DOM

class Document < Element
  def create_element(name, options = {})
    if ns = options[:namespace]
      DOM(`#@native.createElementNS(#{ns}, #{name})`)
    else
      DOM(`#@native.createElement(name)`)
    end
  end

  def window
    Window.new(`#@native.defaultView`)
  end

  def create_text(content)
    DOM(`#@native.createTextNode(#{content})`)
  end

  def [](what)
    %x{
      var result = #@native.getElementById(what);

      if (result) {
        return #{DOM(`result`)};
      }
    }

    xpath(what).first || css(what).first
  end

  alias at []

  def cookies
    Cookies.new(@native) if defined?(`#@native.cookie`)
  end

  def document
    self
  end

  def inspect
    "#<DOM::Document: #{children.inspect}>"
  end

  def location
    Location.new(`#@native.location`) if `#@native.location`
  end

  def title
    `#@native.title`
  end

  def title=(value)
    `#@native.title = value`
  end

  def root
    DOM(`#@native.documentElement`)
  end

  def head
    DOM(`#@native.getElementsByTagName("head")[0]`)
  end

  def body
    DOM(`#@native.body`)
  end

  def style_sheets
    Native::Array.new(`#@native.styleSheets`) {|e|
      CSS::StyleSheet.new(e)
    }
  end

  def root=(element)
    `#@native.documentElement = #{Native.convert(element)}`
  end
end

end; end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-browser-0.1.0.beta1 opal/browser/dom/document.rb