Module: Nitro::ScriptGenerator
- Includes:
- JavascriptUtils
- Defined in:
- lib/nitro/helper/javascript.rb,
lib/nitro/helper/javascript/prototype.rb,
lib/nitro/helper/javascript/scriptaculous.rb
Overview
Add Scriptaculous methods to the ScriptGenerator.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
Instance Method Summary collapse
-
#ajax_update(id, options = {}) ⇒ Object
Perform an ajax, async update.
-
#alert(text) ⇒ Object
Present an alert dialog box.
-
#hide(id) ⇒ Object
Hide a DOM element.
-
#insert_html(id, html, options = {}) ⇒ Object
html = A string or a symbol to an action for rendering.
- #replace_html(id, html, options = {}) ⇒ Object
-
#show(id) ⇒ Object
Show a DOM element.
-
#toggle(id) ⇒ Object
Toggle a DOM element.
- #visual_effect(name, id = false, options = {}) ⇒ Object (also: #effect)
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
68 69 70 |
# File 'lib/nitro/helper/javascript.rb', line 68 def buffer @buffer end |
Instance Method Details
#ajax_update(id, options = {}) ⇒ Object
Perform an ajax, async update.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 44 def ajax_update(id, = {}) code = %~ new Ajax.Updater( { success: '#{id}' }, '#{[:action] || [:url]}', { method: '#{.fetch(:method, :post)}', parameters: #{[:params] || [:parameters]}, ~ if before = [:before] if before.is_a? Proc old_buffer = @buffer @buffer = '' before.call before = @buffer @buffer = old_buffer + @buffer end code << %~ onLoading: function(request) { #{before} }, ~ end if success = [:success] if success.is_a? Proc old_buffer = @buffer @buffer = '' success.call success = @buffer @buffer = old_buffer end code << %~ onComplete: function(request) { #{success} } ~ end code << %~ } ); ~ js(code) end |
#alert(text) ⇒ Object
Present an alert dialog box.
72 73 74 |
# File 'lib/nitro/helper/javascript.rb', line 72 def alert(text) js "alert('#{text}');" end |
#hide(id) ⇒ Object
Hide a DOM element.
26 27 28 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 26 def hide(id) js "$('#{id}').style.display = 'none';" end |
#insert_html(id, html, options = {}) ⇒ Object
html = A string or a symbol to an action for rendering. – TODO: resolve html. ++
15 16 17 18 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 15 def insert_html(id, html, = {}) position = .fetch(:where, :before) js "new Insertion.#{position.to_s.camelize}('#{id}', '#{html}');" end |
#replace_html(id, html, options = {}) ⇒ Object
20 21 22 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 20 def replace_html(id, html, = {}) js "Element.update('#{id}', '#{html}');" end |
#show(id) ⇒ Object
Show a DOM element.
32 33 34 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 32 def show(id) js "$('#{id}').style.display = 'block';" end |
#toggle(id) ⇒ Object
Toggle a DOM element.
38 39 40 |
# File 'lib/nitro/helper/javascript/prototype.rb', line 38 def toggle(id) js "Element.toggle('#{id}');" end |
#visual_effect(name, id = false, options = {}) ⇒ Object Also known as: effect
7 8 9 10 11 |
# File 'lib/nitro/helper/javascript/scriptaculous.rb', line 7 def visual_effect(name, id = false, = {}) element = id ? "'#{id}'" : "element" [:queue] = "'#{[:queue]}'" if [:queue] js "new Effect.#{name.to_s.camelize}(#{element}, #{hash_to_js()});" end |