module ActionView::Helpers::AssetTagHelper
alias_method :rails_javascript_include_tag, :javascript_include_tag
# Adds a new option to Rails' built-in javascript_include_tag
# helper - :unobtrusive. Works in the same way as :defaults - specifying
# :unobtrusive will make sure the necessary javascript
# libraries and behaviours file +script+ tags are loaded. Will happily
# work along side :defaults.
#
# <%= javascript_include_tag :defaults, :unobtrusive %>
#
# This replaces the old +unobtrusive_javascript_files+ helper.
def javascript_include_tag(*sources)
behaviours = ''
if sources.delete :unobtrusive
sources = sources.concat(
['lowpro']
).uniq
behaviours = content_tag("script", "", { "type" => "text/javascript", "src" => behaviours_url })
end
[rails_javascript_include_tag(*sources), behaviours].join("\n")
end
protected
def behaviours_url
action_path = case @controller.request.path
when '', '/'
'/index'
else
@controller.request.path
end
"/behaviours#{action_path}.js"
end
end