[webui] update jrails plugin to a version maintained
[opensuse:build-service.git] / src / webui / vendor / plugins / jrails / lib / jrails / asset_tag_ext.rb
1 # The following options can be changed by creating an initializer in config/initializers/jrails.rb
2
3 # jRails does NOT use jQuery.noConflict() by default
4 # to use jQuery.noConflict() , use:
5 # ActionView::Helpers::PrototypeHelper::JQUERY_VAR = 'jQuery'
6
7
8 JRails.load_config
9
10 if JRails.google?
11   ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jrails => ["jrails/jrails#{".min" if JRails.compressed?}"]
12 else
13   ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jrails => ["jquery/jquery#{".min" if JRails.compressed?}","jquery/jquery-ui#{".min" if JRails.compressed?}","jquery/jquery-ui-i18n#{".min" if JRails.compressed?}","jrails/jrails#{".min" if JRails.compressed?}"]
14 end
15
16
17 ActionView::Helpers::AssetTagHelper.module_eval do 
18   def yield_authenticity_javascript
19 <<JAVASCRIPT
20 <script type='text/javascript'>
21  //<![CDATA[
22    window._auth_token = '#{form_authenticity_token}';
23   $(document).ajaxSend(function(event, xhr, s) {
24     if (typeof(window._auth_token) == "undefined") return;
25     if (s.data && s.data.match(new RegExp("\\bauthenticity_token="))) return;
26     if (s.data)
27       s.data += "&";
28     else {
29       s.data = "";
30       xhr.setRequestHeader("Content-Type", s.contentType);
31     }
32     s.data += "authenticity_token=" + encodeURIComponent(window._auth_token);
33   });
34  //]]>
35 </script>
36 JAVASCRIPT
37   end 
38
39   def javascript_include_tag_with_jquery(*source)
40     if source.first == :jrails
41       javascripts = []
42       if JRails.google?
43         javascripts \
44           << javascript_include_tag_without_jquery(JRails.jquery_path) \
45           << javascript_include_tag_without_jquery(JRails.jqueryui_path) \
46           << javascript_include_tag_without_jquery(JRails.jqueryui_i18n_path) \
47       end
48       javascripts << javascript_include_tag_without_jquery(*source)
49       javascripts << yield_authenticity_javascript if protect_against_forgery?
50       javascripts.join("\n")
51     else
52       javascript_include_tag_without_jquery(*source)
53     end
54   end
55   alias_method_chain :javascript_include_tag, :jquery
56 end