My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

Simple-Ujs is a plugin that turns all of your view into Unobstrusive Javascripts views.

You don't need to learn any new syntax or a whole bunch of new helpers, you have just to call 1 helper (<%= flush_ujs_handlers_list %>) at the bottom of your master templates as close to the closing tag.

flush_ujs_handlers_list(path = {}, session_id = nil)

'path'

is the url path to the controller/action that will serve the javascript stored in the session with id of session_id. The default path is /javascripts/ujs_handler and you can pass either a Hash or a String
'Session_id'
is the name of the session that will store the javascript code. The default session name is 'ujs_script'

When you install this plugin it will automatically copy the file from /lib/simple_ujs/javascripts_controller.rb into your controllers folder. (From RAILS_ROOT run ruby vendor/plugins/simple_ujs/install.rb)

The content of that file is as follows.

	class JavascriptsController < ApplicationController
	  def ujs_handler
	    render :update do |page|
	      page << session[:ujs_script]
	    end
	  end
	end

There is a global setting SimpleUjs::Base.use_ujs that can be set to either true or false to activate or deactivate the SimpleUjs plugin.

The SimpleUjs plugin also moves all of your javascript includes called with the javascript_include_tag method to the bottom of the page right before the call to /javascripts/ujs_handler. I do this because I strongly agree with Douglas Crockford. I can be convinced to make it user-choice though if somebody has reason. The bottom of the page is the best place to insert javascript includes from a page load and performance perspective.

This plugin is for people like me that are sometimes lazy and believe that the best possible setting for any tool should always be the default one.

to install ruby script/plugin install http://simple-ujs.googlecode.com/svn/simple_ujs/

Powered by Google Project Hosting