Method: ActionView::Helpers::JavaScriptHelper#define_javascript_functions

Defined in:
lib/action_view/helpers/javascript_helper.rb

#define_javascript_functionsObject

Includes the Action Pack JavaScript libraries inside a single <script> tag. The function first includes prototype.js and then its core extensions, (determined by filenames starting with “prototype”). Afterwards, any additional scripts will be included in undefined order.

Note: The recommended approach is to copy the contents of lib/action_view/helpers/javascripts/ into your application’s public/javascripts/ directory, and use javascript_include_tag to create remote <script> links.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/action_view/helpers/javascript_helper.rb', line 134

def define_javascript_functions
  javascript = '<script type="text/javascript">'
  
  # load prototype.js and its extensions first 
  prototype_libs = Dir.glob(File.join(JAVASCRIPT_PATH, 'prototype*')).sort.reverse
  prototype_libs.each do |filename| 
    javascript << "\n" << IO.read(filename)
  end
  
  # load other librairies
  (Dir.glob(File.join(JAVASCRIPT_PATH, '*')) - prototype_libs).each do |filename| 
    javascript << "\n" << IO.read(filename)
  end
  javascript << '</script>'
end