Class: Nitro::ScriptMorpher

Inherits:
SharedMorpher show all
Defined in:
lib/nitro/helper/javascript/morphing.rb

Overview

Transform script attributes.

<form script=“action”>… becomes <form onsubmit=“action(); return false”>…

<a script=“action”>..</a> becomes <a href=“#” onclick=“action(); return false”>…</a>

Instance Method Summary collapse

Methods inherited from SharedMorpher

#record_css, #record_js, #require_script_file

Methods inherited from Morpher

#after_end, #after_start, #before_end, #initialize

Constructor Details

This class inherits a constructor from Nitro::Morpher

Instance Method Details

#before_start(buffer) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nitro/helper/javascript/morphing.rb', line 69

def before_start(buffer)
  require_script_file :prototype
  
  case @name
    when 'form'
      @attributes['onsubmit'] = "#@value(); return false"
    else
      @attributes['href'] = '#'
      @attributes['onclick'] = "#@value(); return false"
  end
  @attributes.delete(@key)
end