class DYI::Script::EcmaScript::EventListener
Class representing a event listener of ECMAScript. The scripting becomes effective only when it is output by SVG format.
Public Class Methods
new(body, name=nil, argument='evt')
click to toggle source
@param [String] body body of client scripting @param [String] name a function name @param [String] argument argument’s name
Calls superclass method
DYI::Script::EcmaScript::Function::new
# File lib/dyi/script/ecmascript.rb, line 382 def initialize(body, name=nil, argument='evt') super @events = [] end
Public Instance Methods
contents()
click to toggle source
Returns string expression of this function in ECMAScript @return [String] expression in ECMAScript @since 1.0.3
Calls superclass method
DYI::Script::EcmaScript::Function#contents
# File lib/dyi/script/ecmascript.rb, line 404 def contents if name super else parts = [] parts << "document.addEventListener(\"DOMContentLoaded\", function(evt){\n" @events.each do |event| if event.event_name == :load parts << @body else if event.target.root_element? parts << ' document.documentElement.addEventListener("' else parts << ' document.getElementById("' parts << event.target.id parts << '").addEventListener("' end parts << event.event_name parts << '", ' parts << super parts << ", false);\n" end end parts << "\n}, false);\n" parts.join end end