Class: Nitro::ClientMorpher

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

Overview

Transform client attributes. ‘_nc’ marks Nitro generated javascript functions.

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

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

<a client=“action” params=“this.id”>..</a> becomes <a href=“#” onclick=“__nc_action(this.id); 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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/nitro/helper/javascript/morphing.rb', line 99

def before_start(buffer)
  require_script_file :prototype, :effects
  
  params = @attributes['params']

  case @name
  when 'form'
    @attributes['onsubmit'] = "__nc_#@value(#{params}); return false"
  else
    @attributes['href'] = '#'
    @attributes['onclick'] = "__nc_#@value(#{params}); return false"
  end
  @attributes.delete(@key)
  @attributes.delete('params')
end