Module: Dommy::WindowReflectingHandlers

Included in:
HTMLBodyElement, HTMLFrameSetElement
Defined in:
lib/dommy/html_elements.rb

Overview

The "Window-reflecting body element event handler set": setting one of these event handler IDL attributes on / (body.onload = fn) actually targets the WINDOW, per HTML — so window.onload fires. A non-reflected handler (body.onclick) stays on the element.

Constant Summary collapse

REFLECTED_HANDLERS =
%w[
  onblur onerror onfocus onload onresize onscroll onafterprint onbeforeprint
  onbeforeunload onhashchange onlanguagechange onmessage onmessageerror onoffline
  ononline onpagehide onpageshow onpopstate onrejectionhandled onstorage
  onunhandledrejection onunload
].to_set.freeze

Instance Method Summary collapse

Instance Method Details

#__js_get__(key) ⇒ Object



162
163
164
165
166
167
168
# File 'lib/dommy/html_elements.rb', line 162

def __js_get__(key)
  if key.is_a?(String) && REFLECTED_HANDLERS.include?(key) && (win = @document&.default_view)
    return win.__js_get__(key)
  end

  super
end

#__js_set__(key, value) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/dommy/html_elements.rb', line 154

def __js_set__(key, value)
  if key.is_a?(String) && REFLECTED_HANDLERS.include?(key) && (win = @document&.default_view)
    return win.__js_set__(key, value)
  end

  super
end