Sha256: 656bfaf458ff8c93d7efa375fe93226080d4dbb991c8065acbfa69014f1c85c8
Contents?: true
Size: 1.88 KB
Versions: 2
Compression:
Stored size: 1.88 KB
Contents
module Nitro # Add Prototype methods to the ScriptGenerator. # Prototype.js is a third-party library that provides a number # of functions for AJAX-style interaction with the browser. # Prototype's homepage is http://prototype.conio.net/ module ScriptGenerator # html = A string or a symbol to an action for rendering. #-- # TODO: resolve html. #++ def insert_html(id, html, options = {}) position = options.fetch(:where, :before) js "new Insertion.#{position.to_s.camelize}('#{id}', '#{html}');" end def replace_html(id, html, options = {}) js "Element.update('#{id}', '#{html}');" end # Hide a DOM element. def hide(id) js "$('#{id}').style.display = 'none';" end # Show a DOM element. def show(id) js "$('#{id}').style.display = 'block';" end # Toggle a DOM element. def toggle(id) js "Element.toggle('#{id}');" end # Perform an ajax, async update. def ajax_update(id, options = {}) code = %~ new Ajax.Updater( { success: '#{id}' }, '#{options[:action] || options[:url]}', { method: '#{options.fetch(:method, :post)}', parameters: #{options[:params] || options[:parameters]}, ~ if before = options[: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 = options[: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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.41.0 | lib/nitro/helper/javascript/prototype.rb |
nitro-0.40.0 | lib/nitro/helper/javascript/prototype.rb |