compass-jquery-plugin 0.3.2.pre.2 → 0.3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/LICENSE.md +20 -20
  2. data/README.md +7 -2
  3. data/VERSION.yml +2 -2
  4. data/lib/jquery/gridify/grid.rb +1 -1
  5. data/lib/jquery/gridify/grid_column.rb +1 -1
  6. data/lib/jquery/gridify/grid_finder.rb +16 -1
  7. data/lib/jquery/gridify/grid_view.rb +1 -1
  8. data/lib/jquery/jqgrid.rb +4 -4
  9. data/lib/jquery/jqtouch.rb +3 -3
  10. data/lib/jquery/jquery.rb +431 -431
  11. data/lib/jquery/jquery_json_response.rb +28 -0
  12. data/lib/jquery/secret_sauce.rb +8 -8
  13. data/lib/jquery/secret_sauce/controller/ui_dialog_controls.rb +13 -13
  14. data/lib/jquery/secret_sauce/controller/ui_grid_controls.rb +18 -18
  15. data/lib/jquery/secret_sauce/helpers/ui_dialog_helper.rb +5 -5
  16. data/lib/jquery/secret_sauce/model/find_for_grid.rb +41 -41
  17. data/templates/dynatree/jquery.dynatree.js +111 -110
  18. data/templates/dynatree/jquery.dynatree.min.js +75 -77
  19. data/templates/dynatree/jquery/dynatree/aero.scss +1 -3
  20. data/templates/dynatree/jquery/dynatree/aqua.scss +1 -3
  21. data/templates/dynatree/jquery/dynatree/crystal.scss +1 -3
  22. data/templates/dynatree/jquery/dynatree/xp.scss +1 -3
  23. data/templates/emulators/emulators/iphone.landscape.png +0 -0
  24. data/templates/emulators/emulators/iphone.landscape.scss +4 -4
  25. data/templates/emulators/emulators/palm.landscape.scss +6 -6
  26. data/templates/emulators/emulators/palm.pre.landscape.png +0 -0
  27. data/templates/ical/jquery.ical.js +3202 -3197
  28. data/templates/ical/jquery.ical.min.js +185 -184
  29. data/templates/ical/jquery/ical.scss +3 -3
  30. data/templates/jqgrid/i18n/jqgrid/locale-ar.js +126 -0
  31. data/templates/jqgrid/i18n/jqgrid/locale-ar.min.js +6 -0
  32. data/templates/jqgrid/i18n/jqgrid/locale-fi.js +45 -47
  33. data/templates/jqgrid/i18n/jqgrid/locale-fi.min.js +6 -6
  34. data/templates/jqgrid/jquery.jqGrid.js +2047 -2036
  35. data/templates/jqgrid/jquery.jqGrid.min.js +48 -48
  36. data/templates/jqgrid/manifest.rb +2 -0
  37. data/templates/jqtouch/jquery.jqtouch.js +122 -113
  38. data/templates/jqtouch/jquery.jqtouch.min.js +1 -1
  39. data/templates/jquery/config/initializers/jquery.rb +4 -2
  40. data/templates/jquery/i18n/jquery.ui/datepicker-ar-DZ.js +23 -0
  41. data/templates/jquery/i18n/jquery.ui/datepicker-ar-DZ.min.js +2 -0
  42. data/templates/jquery/i18n/jquery.ui/datepicker-en-AU.js +23 -0
  43. data/templates/jquery/i18n/jquery.ui/datepicker-en-AU.min.js +2 -0
  44. data/templates/jquery/i18n/jquery.ui/datepicker-en-NZ.js +23 -0
  45. data/templates/jquery/i18n/jquery.ui/datepicker-en-NZ.min.js +2 -0
  46. data/templates/jquery/i18n/jquery.ui/datepicker-ml.js +23 -0
  47. data/templates/jquery/i18n/jquery.ui/datepicker-ml.min.js +2 -0
  48. data/templates/jquery/jquery-ui.js +354 -316
  49. data/templates/jquery/jquery-ui.min.js +544 -544
  50. data/templates/jquery/jquery.cookie.js +3 -3
  51. data/templates/jquery/jquery.form.js +271 -140
  52. data/templates/jquery/jquery.form.min.js +19 -17
  53. data/templates/jquery/jquery.layout.js +2435 -2437
  54. data/templates/jquery/jquery.layout.min.js +4 -3
  55. data/templates/jquery/jquery.mousewheel.js +78 -0
  56. data/templates/jquery/jquery.mousewheel.min.js +2 -0
  57. data/templates/jquery/jquery.offline.js +212 -0
  58. data/templates/jquery/jquery.offline.min.js +4 -0
  59. data/templates/jquery/jquery.tmpl.js +15 -22
  60. data/templates/jquery/jquery.tmpl.min.js +12 -12
  61. data/templates/jquery/jquery.tmplPlus.js +1 -0
  62. data/templates/jquery/jquery/ui/_theme.scss +27 -27
  63. data/templates/jquery/json.js +7 -0
  64. data/templates/jquery/json.min.js +7 -0
  65. data/templates/jquery/manifest.rb +14 -2
  66. data/templates/mobile/glyphish/{Read me first - license.txt → License.txt} +0 -0
  67. data/templates/mobile/jquery.mobile.js +1583 -1408
  68. data/templates/mobile/jquery.mobile.min.js +5 -5
  69. data/templates/mobile/jquery/mobile/_base.scss +938 -1038
  70. data/templates/mobile/jquery/mobile/default.scss +25 -26
  71. data/templates/mobile/jquery/mobile/valencia.scss +0 -1
  72. data/templates/mobile/manifest.rb +1 -1
  73. data/templates/tools/config/initializers/tools.rb +2 -0
  74. data/templates/tools/flowplayer.js +24 -0
  75. data/templates/tools/flowplayer.min.js +30 -0
  76. data/templates/tools/jquery.tools.js +4 -3
  77. data/templates/tools/jquery.tools.min.js +1 -1
  78. data/templates/tools/manifest.rb +4 -0
  79. data/templates/tools/swfobject.js +777 -0
  80. data/templates/tools/swfobject.min.js +19 -0
  81. metadata +31 -15
  82. data/templates/jquery/jquery.metadata.js +0 -122
  83. data/templates/jquery/jquery.metadata.min.js +0 -2
data/LICENSE.md CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009-2011 Kosmas Schuetz
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009-2011 Kosmas Schuetz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -10,7 +10,7 @@ Description
10
10
 
11
11
  A Sass-based Meta-Framework for Compass that allows you to mix and match any of the following:
12
12
 
13
- * jRails with jQuery 1.4.4 and jQuery.UI 1.8.7 including themes
13
+ * jRails with jQuery 1.4.4 and jQuery.UI 1.8.9 including themes
14
14
  * jQuery Tools 1.2.5
15
15
  * jquery.jstree.js V1.0rc3
16
16
  * jquery.dynatree.js V1.0.2
@@ -242,6 +242,8 @@ jQuery Plugins included:
242
242
  * Takayuki Miwa for [jQuery history plugin][19]
243
243
  * Ivan Bozhanov for [jQuery jsTree Plugin][20]
244
244
  * Fabrizio Balliano and Fabrizio Balliano for [jQuery Layout Plugin][21]
245
+ * Brandon Aaron and Fabrizio Balliano for [jQuery Mousewheel Plugin][21]
246
+ * Yehuda Katz for [jQuery Offline Plugin][34]
245
247
  * Andreas Eberhard for [jQuery PngFix Plugin][22] (for IE)
246
248
  * Mikael Soederstroem for [jQuery Ribbon Plugin][23]
247
249
  * Gareth Watts from Splunk Inc for [jQuery Sparklines plugin][24]
@@ -308,4 +310,7 @@ Copyright © 2009-2011 Kosmas Schuetz. See LICENSE for details.
308
310
  [30]: http://acko.net/dev/farbtastic
309
311
  [31]: http://arshaw.com/fullcalendar/
310
312
  [32]: http://github.com/creationix/haml-js
311
- [33]: http://github.com/rubyredrick/ri_cal/
313
+ [33]: http://github.com/rubyredrick/ri_cal/
314
+ [34]: http://github.com/wycats/jquery-offline
315
+ [35]: http://github.com/brandonaaron/jquery-mousewheel
316
+
data/VERSION.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
- :commit: 2
3
- :state: pre
2
+ :commit:
3
+ :state: 0
4
4
  :tiny: 2
5
5
  :minor: 3
6
6
  :major: 0
@@ -131,7 +131,7 @@ module Gridify
131
131
  end.compact
132
132
 
133
133
  if col_include
134
- col_include.each do |sub_model|
134
+ col_include.each do |sub_model|
135
135
  my_model = sub_model.to_s
136
136
  if klass.inheritable_attributes[:reflections][sub_model].options[:class_name]
137
137
  my_class = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
@@ -89,7 +89,7 @@ module Gridify
89
89
  # note, we dont vals[:foo] = foo because dont want to bother generating key if its same as jqGrid default
90
90
  def jqgrid_properties
91
91
  vals = {
92
- :name => name,
92
+ :name => name.gsub(".", "__"),
93
93
  :index => name
94
94
  }
95
95
  #xmlmap not required when same as :name
@@ -111,7 +111,7 @@ module Gridify
111
111
  save = ActiveRecord::Base.include_root_in_json
112
112
  ActiveRecord::Base.include_root_in_json = false
113
113
  if colInclude
114
- json = data.to_json(:include => colInclude)
114
+ json = build_json(data);
115
115
  else
116
116
  json = data.to_json
117
117
  end
@@ -215,6 +215,21 @@ module Gridify
215
215
  end
216
216
  cond = [ expr ] + vals
217
217
  end
218
+
219
+ def build_json(data)
220
+ raw_data = JSON.parse(data.to_json(:include => colInclude))
221
+ raw_data[resource].each do |row|
222
+ colInclude.each do |incl|
223
+ sm = incl.to_s
224
+ if row[sm]
225
+ row[sm].each do |k, v|
226
+ row[sm + "__" + k] = v
227
+ end
228
+ end
229
+ end
230
+ end
231
+ return raw_data.to_json()
232
+ end
218
233
  end
219
234
  end
220
235
 
@@ -23,7 +23,7 @@ module Gridify
23
23
 
24
24
  if options[:ready]
25
25
  s << %Q^
26
- jQuery(document).ready(function(){
26
+ $(document).ready(function(){
27
27
  ^
28
28
  end
29
29
 
data/lib/jquery/jqgrid.rb CHANGED
@@ -1,5 +1,5 @@
1
- module JqGrid#:nodoc:
2
- end
3
-
4
- require 'jquery/jqgrid/jqgrid'
1
+ module JqGrid#:nodoc:
2
+ end
3
+
4
+ require 'jquery/jqgrid/jqgrid'
5
5
  require 'handle_attributes'
@@ -1,4 +1,4 @@
1
- module JqTouch#:nodoc:
2
- end
3
-
1
+ module JqTouch#:nodoc:
2
+ end
3
+
4
4
  #require 'jquery/jqtouch/controller/ui_dialog_controls'
data/lib/jquery/jquery.rb CHANGED
@@ -1,431 +1,431 @@
1
- module ActionView
2
- module Helpers
3
-
4
- def jquery_javascripts(locale)
5
- if locale != 'en'
6
- else
7
- js = capture { javascript_include_tag "i18n/jquery.ui/datepicker-#{locale}.min.js" }
8
- js << capture { '<script type="text/javascript">' }
9
- js << capture { " jQuery.datepicker.setDefaults(jQuery.datepicker.regional['#{locale}']);" }
10
- js << capture { '</script>' }
11
- end
12
- end
13
-
14
- module JavaScriptHelper
15
-
16
- # This function can be used to render rjs inline
17
- #
18
- # <%= javascript_function do |page|
19
- # page.replace_html :list, :partial => 'list', :object => @list
20
- # end %>
21
- #
22
- def javascript_function(*args, &block)
23
- html_options = args.extract_options!
24
- function = args[0] || ''
25
-
26
- html_options.symbolize_keys!
27
- function = update_page(&block) if block_given?
28
- javascript_tag(function)
29
- end
30
-
31
- def jquery_id(id)
32
- id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
33
- end
34
-
35
- def jquery_ids(ids)
36
- Array(ids).map{|id| jquery_id(id)}.join(',')
37
- end
38
-
39
- end
40
-
41
- module PrototypeHelper
42
-
43
- USE_PROTECTION = const_defined?(:DISABLE_JQUERY_FORGERY_PROTECTION) ? !DISABLE_JQUERY_FORGERY_PROTECTION : true
44
-
45
- unless const_defined? :JQUERY_VAR
46
- JQUERY_VAR = 'jQuery'
47
- end
48
-
49
- unless const_defined? :JQCALLBACKS
50
- JQCALLBACKS = Set.new([ :beforeSend, :complete, :error, :success ] + (100..599).to_a)
51
- #instance_eval { remove_const :AJAX_OPTIONS }
52
- remove_const(:AJAX_OPTIONS) if const_defined?(:AJAX_OPTIONS)
53
- AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
54
- :asynchronous, :method, :insertion, :position,
55
- :form, :with, :update, :script ]).merge(JQCALLBACKS)
56
- end
57
-
58
- def periodically_call_remote(options = {})
59
- frequency = options[:frequency] || 10 # every ten seconds by default
60
- code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
61
- javascript_tag(code)
62
- end
63
-
64
- def remote_function(options)
65
- javascript_options = options_for_ajax(options)
66
-
67
- update = ''
68
- if options[:update] && options[:update].is_a?(Hash)
69
- update = []
70
- update << "success:'#{options[:update][:success]}'" if options[:update][:success]
71
- update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
72
- update = '{' + update.join(',') + '}'
73
- elsif options[:update]
74
- update << "'#{options[:update]}'"
75
- end
76
-
77
- function = "#{JQUERY_VAR}.ajax(#{javascript_options})"
78
-
79
- function = "#{options[:before]}; #{function}" if options[:before]
80
- function = "#{function}; #{options[:after]}" if options[:after]
81
- function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
82
- function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
83
- return function
84
- end
85
-
86
- class JavaScriptGenerator
87
- module GeneratorMethods
88
-
89
- def insert_html(position, id, *options_for_render)
90
- insertion = position.to_s.downcase
91
- insertion = 'append' if insertion == 'bottom'
92
- insertion = 'prepend' if insertion == 'top'
93
- call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
94
- end
95
-
96
- def replace_html(id, *options_for_render)
97
- insert_html(:html, id, *options_for_render)
98
- end
99
-
100
- def replace(id, *options_for_render)
101
- call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
102
- end
103
-
104
- def remove(*ids)
105
- call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").remove"
106
- end
107
-
108
- def show(*ids)
109
- call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").show"
110
- end
111
-
112
- def hide(*ids)
113
- call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").hide"
114
- end
115
-
116
- def toggle(*ids)
117
- call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").toggle"
118
- end
119
-
120
- def jquery_id(id)
121
- id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
122
- end
123
-
124
- def jquery_ids(ids)
125
- Array(ids).map{|id| jquery_id(id)}.join(',')
126
- end
127
-
128
- end
129
- end
130
-
131
- protected
132
- def options_for_ajax(options)
133
- js_options = build_callbacks(options)
134
-
135
- url_options = options[:url]
136
- url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
137
- js_options['url'] = "'#{url_for(url_options)}'"
138
- js_options['async'] = false if options[:type] == :synchronous
139
- js_options['type'] = options[:method] ? method_option_to_s(options[:method]) : ( options[:form] ? "'post'" : nil )
140
- js_options['dataType'] = options[:datatype] ? "'#{options[:datatype]}'" : (options[:update] ? nil : "'script'")
141
-
142
- if options[:form]
143
- js_options['data'] = "#{JQUERY_VAR}.param(#{JQUERY_VAR}(this).serializeArray())"
144
- elsif options[:submit]
145
- js_options['data'] = "#{JQUERY_VAR}(\"##{options[:submit]} :input\").serialize()"
146
- elsif options[:with]
147
- js_options['data'] = options[:with].gsub("Form.serialize(this.form)","#{JQUERY_VAR}.param(#{JQUERY_VAR}(this.form).serializeArray())")
148
- end
149
-
150
- js_options['type'] ||= "'post'"
151
- if options[:method]
152
- if method_option_to_s(options[:method]) == "'put'" || method_option_to_s(options[:method]) == "'delete'"
153
- js_options['type'] = "'post'"
154
- if js_options['data']
155
- js_options['data'] << " + '&"
156
- else
157
- js_options['data'] = "'"
158
- end
159
- js_options['data'] << "_method=#{options[:method]}'"
160
- end
161
- end
162
-
163
- if USE_PROTECTION && respond_to?('protect_against_forgery?') && protect_against_forgery?
164
- if js_options['data']
165
- js_options['data'] << " + '&"
166
- else
167
- js_options['data'] = "'"
168
- end
169
- js_options['data'] << "#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')"
170
- end
171
- js_options['data'] = "''" if js_options['type'] == "'post'" && js_options['data'].nil?
172
- options_for_javascript(js_options.reject {|key, value| value.nil?})
173
- end
174
-
175
- def build_update_for_success(html_id, insertion=nil)
176
- insertion = build_insertion(insertion)
177
- "#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request);"
178
- end
179
-
180
- def build_update_for_error(html_id, insertion=nil)
181
- insertion = build_insertion(insertion)
182
- "#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request.responseText);"
183
- end
184
-
185
- def build_insertion(insertion)
186
- insertion = insertion ? insertion.to_s.downcase : 'html'
187
- insertion = 'append' if insertion == 'bottom'
188
- insertion = 'prepend' if insertion == 'top'
189
- insertion
190
- end
191
-
192
- def build_observer(klass, name, options = {})
193
- if options[:with] && (options[:with] !~ /[\{=(.]/)
194
- options[:with] = "'#{options[:with]}=' + value"
195
- else
196
- options[:with] ||= 'value' unless options[:function]
197
- end
198
-
199
- callback = options[:function] || remote_function(options)
200
- javascript = "#{JQUERY_VAR}('#{jquery_id(name)}').delayedObserver("
201
- javascript << "#{options[:frequency] || 0}, "
202
- javascript << "function(element, value) {"
203
- javascript << "#{callback}}"
204
- #javascript << ", '#{options[:on]}'" if options[:on]
205
- javascript << ")"
206
- javascript_tag(javascript)
207
- end
208
-
209
- def build_callbacks(options)
210
- callbacks = {}
211
- options[:beforeSend] = '';
212
- [:uninitialized,:loading].each do |key|
213
- options[:beforeSend] << (options[key].last == ';' ? options.delete(key) : options.delete(key) << ';') if options[key]
214
- end
215
- options.delete(:beforeSend) if options[:beforeSend].blank?
216
- options[:complete] = options.delete(:loaded) if options[:loaded]
217
- options[:error] = options.delete(:failure) if options[:failure]
218
- if options[:update]
219
- if options[:update].is_a?(Hash)
220
- options[:update][:error] = options[:update].delete(:failure) if options[:update][:failure]
221
- if options[:update][:success]
222
- options[:success] = build_update_for_success(options[:update][:success], options[:position]) << (options[:success] ? options[:success] : '')
223
- end
224
- if options[:update][:error]
225
- options[:error] = build_update_for_error(options[:update][:error], options[:position]) << (options[:error] ? options[:error] : '')
226
- end
227
- else
228
- options[:success] = build_update_for_success(options[:update], options[:position]) << (options[:success] ? options[:success] : '')
229
- end
230
- end
231
- options.each do |callback, code|
232
- if JQCALLBACKS.include?(callback)
233
- callbacks[callback] = "function(request){#{code}}"
234
- end
235
- end
236
- callbacks
237
- end
238
-
239
- end
240
-
241
- class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
242
-
243
- unless const_defined? :JQUERY_VAR
244
- JQUERY_VAR = PrototypeHelper::JQUERY_VAR
245
- end
246
-
247
- def initialize(generator, id)
248
- id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
249
- @id = id
250
- super(generator, "#{JQUERY_VAR}(\"#{id}\")")
251
- end
252
-
253
- def replace_html(*options_for_render)
254
- call 'html', @generator.send(:render, *options_for_render)
255
- end
256
-
257
- def replace(*options_for_render)
258
- call 'replaceWith', @generator.send(:render, *options_for_render)
259
- end
260
-
261
- def reload(options_for_replace={})
262
- replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
263
- end
264
-
265
- def value()
266
- call 'val()'
267
- end
268
-
269
- def value=(value)
270
- call 'val', value
271
- end
272
-
273
- end
274
-
275
- class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
276
-
277
- unless const_defined? :JQUERY_VAR
278
- JQUERY_VAR = PrototypeHelper::JQUERY_VAR
279
- end
280
-
281
- def initialize(generator, pattern)
282
- super(generator, "#{JQUERY_VAR}(#{pattern.to_json})")
283
- end
284
- end
285
-
286
- module ScriptaculousHelper
287
-
288
- unless const_defined? :JQUERY_VAR
289
- JQUERY_VAR = PrototypeHelper::JQUERY_VAR
290
- end
291
-
292
- unless const_defined? :SCRIPTACULOUS_EFFECTS
293
- SCRIPTACULOUS_EFFECTS = {
294
- :appear => {:method => 'fadeIn'},
295
- :blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
296
- :blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
297
- :blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
298
- :blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
299
- :bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
300
- :bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
301
- :drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
302
- :drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
303
- :fade => {:method => 'fadeOut'},
304
- :fold_in => {:method => 'fold', :mode => 'hide'},
305
- :fold_out => {:method => 'fold', :mode => 'show'},
306
- :grow => {:method => 'scale', :mode => 'show'},
307
- :shrink => {:method => 'scale', :mode => 'hide'},
308
- :slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
309
- :slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
310
- :slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
311
- :slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
312
- :squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
313
- :switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
314
- :switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
315
- :toggle_appear => {:method => 'fadeToggle'},
316
- :toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
317
- :toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
318
- }
319
- end
320
-
321
- def visual_effect(name, element_id = false, js_options = {})
322
- element = element_id ? element_id : "this"
323
-
324
- if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
325
- effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
326
- name = effect[:method]
327
- mode = effect[:mode]
328
- js_options = js_options.merge(effect[:options]) if effect[:options]
329
- end
330
-
331
- [:color, :direction, :startcolor, :endcolor].each do |option|
332
- js_options[option] = "'#{js_options[option]}'" if js_options[option]
333
- end
334
-
335
- if js_options.has_key? :duration
336
- speed = js_options.delete :duration
337
- speed = (speed * 1000).to_i unless speed.nil?
338
- else
339
- speed = js_options.delete :speed
340
- end
341
-
342
- if ['fadeIn','fadeOut','fadeToggle'].include?(name)
343
- # 090905 - Jake - changed ' to \" so it passes assert_select_rjs with an id
344
- javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{name}("
345
- javascript << "#{speed}" unless speed.nil?
346
- javascript << ");"
347
- else
348
- # 090905 - Jake - changed ' to \" so it passes "assert_select_rjs :effect, ID"
349
- javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{mode || 'effect'}('#{name}'"
350
- javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
351
- javascript << ",#{speed}" unless speed.nil?
352
- javascript << ");"
353
- end
354
-
355
- end
356
-
357
- def sortable_element_js(element_id, options = {}) #:nodoc:
358
- #convert similar attributes
359
- options[:handle] = ".#{options[:handle]}" if options[:handle]
360
- if options[:tag] || options[:only]
361
- options[:items] = "> "
362
- options[:items] << options.delete(:tag) if options[:tag]
363
- options[:items] << ".#{options.delete(:only)}" if options[:only]
364
- end
365
- options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
366
- options[:containment] = options.delete(:container) if options[:container]
367
- options[:dropOnEmpty] = false unless options[:dropOnEmpty]
368
- options[:helper] = "'clone'" if options[:ghosting] == true
369
- options[:axis] = case options.delete(:constraint)
370
- when "vertical", :vertical
371
- "y"
372
- when "horizontal", :horizontal
373
- "x"
374
- when false
375
- nil
376
- when nil
377
- "y"
378
- end
379
- options.delete(:axis) if options[:axis].nil?
380
- options.delete(:overlap)
381
- options.delete(:ghosting)
382
-
383
- if options[:onUpdate] || options[:url]
384
- if options[:format]
385
- options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]', expression:#{options[:format]}})"
386
- options.delete(:format)
387
- else
388
- options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
389
- end
390
-
391
- options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
392
- end
393
-
394
- options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
395
- options[:update] = options.delete(:onUpdate) if options[:onUpdate]
396
-
397
- [:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
398
- options[option] = "'#{options[option]}'" if options[option]
399
- end
400
-
401
- options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
402
-
403
- %(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});)
404
- end
405
-
406
- def draggable_element_js(element_id, options = {})
407
- %(#{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)});)
408
- end
409
-
410
- def drop_receiving_element_js(element_id, options = {})
411
- #convert similar options
412
- options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
413
- options[:drop] = options.delete(:onDrop) if options[:onDrop]
414
-
415
- if options[:drop] || options[:url]
416
- options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
417
- options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
418
- end
419
-
420
- options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
421
-
422
- options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
423
- [:activeClass, :hoverClass, :tolerance].each do |option|
424
- options[option] = "'#{options[option]}'" if options[option]
425
- end
426
-
427
- %(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
428
- end
429
- end
430
- end
431
- end
1
+ module ActionView
2
+ module Helpers
3
+
4
+ def jquery_javascripts(locale)
5
+ if locale != 'en'
6
+ else
7
+ js = capture { javascript_include_tag "i18n/jquery.ui/datepicker-#{locale}.min.js" }
8
+ js << capture { '<script type="text/javascript">' }
9
+ js << capture { " jQuery.datepicker.setDefaults(jQuery.datepicker.regional['#{locale}']);" }
10
+ js << capture { '</script>' }
11
+ end
12
+ end
13
+
14
+ module JavaScriptHelper
15
+
16
+ # This function can be used to render rjs inline
17
+ #
18
+ # <%= javascript_function do |page|
19
+ # page.replace_html :list, :partial => 'list', :object => @list
20
+ # end %>
21
+ #
22
+ def javascript_function(*args, &block)
23
+ html_options = args.extract_options!
24
+ function = args[0] || ''
25
+
26
+ html_options.symbolize_keys!
27
+ function = update_page(&block) if block_given?
28
+ javascript_tag(function)
29
+ end
30
+
31
+ def jquery_id(id)
32
+ id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
33
+ end
34
+
35
+ def jquery_ids(ids)
36
+ Array(ids).map{|id| jquery_id(id)}.join(',')
37
+ end
38
+
39
+ end
40
+
41
+ module PrototypeHelper
42
+
43
+ USE_PROTECTION = const_defined?(:DISABLE_JQUERY_FORGERY_PROTECTION) ? !DISABLE_JQUERY_FORGERY_PROTECTION : true
44
+
45
+ unless const_defined? :JQUERY_VAR
46
+ JQUERY_VAR = 'jQuery'
47
+ end
48
+
49
+ unless const_defined? :JQCALLBACKS
50
+ JQCALLBACKS = Set.new([ :beforeSend, :complete, :error, :success ] + (100..599).to_a)
51
+ #instance_eval { remove_const :AJAX_OPTIONS }
52
+ remove_const(:AJAX_OPTIONS) if const_defined?(:AJAX_OPTIONS)
53
+ AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
54
+ :asynchronous, :method, :insertion, :position,
55
+ :form, :with, :update, :script ]).merge(JQCALLBACKS)
56
+ end
57
+
58
+ def periodically_call_remote(options = {})
59
+ frequency = options[:frequency] || 10 # every ten seconds by default
60
+ code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
61
+ javascript_tag(code)
62
+ end
63
+
64
+ def remote_function(options)
65
+ javascript_options = options_for_ajax(options)
66
+
67
+ update = ''
68
+ if options[:update] && options[:update].is_a?(Hash)
69
+ update = []
70
+ update << "success:'#{options[:update][:success]}'" if options[:update][:success]
71
+ update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
72
+ update = '{' + update.join(',') + '}'
73
+ elsif options[:update]
74
+ update << "'#{options[:update]}'"
75
+ end
76
+
77
+ function = "#{JQUERY_VAR}.ajax(#{javascript_options})"
78
+
79
+ function = "#{options[:before]}; #{function}" if options[:before]
80
+ function = "#{function}; #{options[:after]}" if options[:after]
81
+ function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
82
+ function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
83
+ return function
84
+ end
85
+
86
+ class JavaScriptGenerator
87
+ module GeneratorMethods
88
+
89
+ def insert_html(position, id, *options_for_render)
90
+ insertion = position.to_s.downcase
91
+ insertion = 'append' if insertion == 'bottom'
92
+ insertion = 'prepend' if insertion == 'top'
93
+ call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
94
+ end
95
+
96
+ def replace_html(id, *options_for_render)
97
+ insert_html(:html, id, *options_for_render)
98
+ end
99
+
100
+ def replace(id, *options_for_render)
101
+ call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
102
+ end
103
+
104
+ def remove(*ids)
105
+ call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").remove"
106
+ end
107
+
108
+ def show(*ids)
109
+ call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").show"
110
+ end
111
+
112
+ def hide(*ids)
113
+ call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").hide"
114
+ end
115
+
116
+ def toggle(*ids)
117
+ call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").toggle"
118
+ end
119
+
120
+ def jquery_id(id)
121
+ id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
122
+ end
123
+
124
+ def jquery_ids(ids)
125
+ Array(ids).map{|id| jquery_id(id)}.join(',')
126
+ end
127
+
128
+ end
129
+ end
130
+
131
+ protected
132
+ def options_for_ajax(options)
133
+ js_options = build_callbacks(options)
134
+
135
+ url_options = options[:url]
136
+ url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
137
+ js_options['url'] = "'#{url_for(url_options)}'"
138
+ js_options['async'] = false if options[:type] == :synchronous
139
+ js_options['type'] = options[:method] ? method_option_to_s(options[:method]) : ( options[:form] ? "'post'" : nil )
140
+ js_options['dataType'] = options[:datatype] ? "'#{options[:datatype]}'" : (options[:update] ? nil : "'script'")
141
+
142
+ if options[:form]
143
+ js_options['data'] = "#{JQUERY_VAR}.param(#{JQUERY_VAR}(this).serializeArray())"
144
+ elsif options[:submit]
145
+ js_options['data'] = "#{JQUERY_VAR}(\"##{options[:submit]} :input\").serialize()"
146
+ elsif options[:with]
147
+ js_options['data'] = options[:with].gsub("Form.serialize(this.form)","#{JQUERY_VAR}.param(#{JQUERY_VAR}(this.form).serializeArray())")
148
+ end
149
+
150
+ js_options['type'] ||= "'post'"
151
+ if options[:method]
152
+ if method_option_to_s(options[:method]) == "'put'" || method_option_to_s(options[:method]) == "'delete'"
153
+ js_options['type'] = "'post'"
154
+ if js_options['data']
155
+ js_options['data'] << " + '&"
156
+ else
157
+ js_options['data'] = "'"
158
+ end
159
+ js_options['data'] << "_method=#{options[:method]}'"
160
+ end
161
+ end
162
+
163
+ if USE_PROTECTION && respond_to?('protect_against_forgery?') && protect_against_forgery?
164
+ if js_options['data']
165
+ js_options['data'] << " + '&"
166
+ else
167
+ js_options['data'] = "'"
168
+ end
169
+ js_options['data'] << "#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')"
170
+ end
171
+ js_options['data'] = "''" if js_options['type'] == "'post'" && js_options['data'].nil?
172
+ options_for_javascript(js_options.reject {|key, value| value.nil?})
173
+ end
174
+
175
+ def build_update_for_success(html_id, insertion=nil)
176
+ insertion = build_insertion(insertion)
177
+ "#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request);"
178
+ end
179
+
180
+ def build_update_for_error(html_id, insertion=nil)
181
+ insertion = build_insertion(insertion)
182
+ "#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request.responseText);"
183
+ end
184
+
185
+ def build_insertion(insertion)
186
+ insertion = insertion ? insertion.to_s.downcase : 'html'
187
+ insertion = 'append' if insertion == 'bottom'
188
+ insertion = 'prepend' if insertion == 'top'
189
+ insertion
190
+ end
191
+
192
+ def build_observer(klass, name, options = {})
193
+ if options[:with] && (options[:with] !~ /[\{=(.]/)
194
+ options[:with] = "'#{options[:with]}=' + value"
195
+ else
196
+ options[:with] ||= 'value' unless options[:function]
197
+ end
198
+
199
+ callback = options[:function] || remote_function(options)
200
+ javascript = "#{JQUERY_VAR}('#{jquery_id(name)}').delayedObserver("
201
+ javascript << "#{options[:frequency] || 0}, "
202
+ javascript << "function(element, value) {"
203
+ javascript << "#{callback}}"
204
+ #javascript << ", '#{options[:on]}'" if options[:on]
205
+ javascript << ")"
206
+ javascript_tag(javascript)
207
+ end
208
+
209
+ def build_callbacks(options)
210
+ callbacks = {}
211
+ options[:beforeSend] = '';
212
+ [:uninitialized,:loading].each do |key|
213
+ options[:beforeSend] << (options[key].last == ';' ? options.delete(key) : options.delete(key) << ';') if options[key]
214
+ end
215
+ options.delete(:beforeSend) if options[:beforeSend].blank?
216
+ options[:complete] = options.delete(:loaded) if options[:loaded]
217
+ options[:error] = options.delete(:failure) if options[:failure]
218
+ if options[:update]
219
+ if options[:update].is_a?(Hash)
220
+ options[:update][:error] = options[:update].delete(:failure) if options[:update][:failure]
221
+ if options[:update][:success]
222
+ options[:success] = build_update_for_success(options[:update][:success], options[:position]) << (options[:success] ? options[:success] : '')
223
+ end
224
+ if options[:update][:error]
225
+ options[:error] = build_update_for_error(options[:update][:error], options[:position]) << (options[:error] ? options[:error] : '')
226
+ end
227
+ else
228
+ options[:success] = build_update_for_success(options[:update], options[:position]) << (options[:success] ? options[:success] : '')
229
+ end
230
+ end
231
+ options.each do |callback, code|
232
+ if JQCALLBACKS.include?(callback)
233
+ callbacks[callback] = "function(request){#{code}}"
234
+ end
235
+ end
236
+ callbacks
237
+ end
238
+
239
+ end
240
+
241
+ class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
242
+
243
+ unless const_defined? :JQUERY_VAR
244
+ JQUERY_VAR = PrototypeHelper::JQUERY_VAR
245
+ end
246
+
247
+ def initialize(generator, id)
248
+ id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
249
+ @id = id
250
+ super(generator, "#{JQUERY_VAR}(\"#{id}\")")
251
+ end
252
+
253
+ def replace_html(*options_for_render)
254
+ call 'html', @generator.send(:render, *options_for_render)
255
+ end
256
+
257
+ def replace(*options_for_render)
258
+ call 'replaceWith', @generator.send(:render, *options_for_render)
259
+ end
260
+
261
+ def reload(options_for_replace={})
262
+ replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
263
+ end
264
+
265
+ def value()
266
+ call 'val()'
267
+ end
268
+
269
+ def value=(value)
270
+ call 'val', value
271
+ end
272
+
273
+ end
274
+
275
+ class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
276
+
277
+ unless const_defined? :JQUERY_VAR
278
+ JQUERY_VAR = PrototypeHelper::JQUERY_VAR
279
+ end
280
+
281
+ def initialize(generator, pattern)
282
+ super(generator, "#{JQUERY_VAR}(#{pattern.to_json})")
283
+ end
284
+ end
285
+
286
+ module ScriptaculousHelper
287
+
288
+ unless const_defined? :JQUERY_VAR
289
+ JQUERY_VAR = PrototypeHelper::JQUERY_VAR
290
+ end
291
+
292
+ unless const_defined? :SCRIPTACULOUS_EFFECTS
293
+ SCRIPTACULOUS_EFFECTS = {
294
+ :appear => {:method => 'fadeIn'},
295
+ :blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
296
+ :blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
297
+ :blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
298
+ :blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
299
+ :bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
300
+ :bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
301
+ :drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
302
+ :drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
303
+ :fade => {:method => 'fadeOut'},
304
+ :fold_in => {:method => 'fold', :mode => 'hide'},
305
+ :fold_out => {:method => 'fold', :mode => 'show'},
306
+ :grow => {:method => 'scale', :mode => 'show'},
307
+ :shrink => {:method => 'scale', :mode => 'hide'},
308
+ :slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
309
+ :slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
310
+ :slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
311
+ :slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
312
+ :squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
313
+ :switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
314
+ :switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
315
+ :toggle_appear => {:method => 'fadeToggle'},
316
+ :toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
317
+ :toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
318
+ }
319
+ end
320
+
321
+ def visual_effect(name, element_id = false, js_options = {})
322
+ element = element_id ? element_id : "this"
323
+
324
+ if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
325
+ effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
326
+ name = effect[:method]
327
+ mode = effect[:mode]
328
+ js_options = js_options.merge(effect[:options]) if effect[:options]
329
+ end
330
+
331
+ [:color, :direction, :startcolor, :endcolor].each do |option|
332
+ js_options[option] = "'#{js_options[option]}'" if js_options[option]
333
+ end
334
+
335
+ if js_options.has_key? :duration
336
+ speed = js_options.delete :duration
337
+ speed = (speed * 1000).to_i unless speed.nil?
338
+ else
339
+ speed = js_options.delete :speed
340
+ end
341
+
342
+ if ['fadeIn','fadeOut','fadeToggle'].include?(name)
343
+ # 090905 - Jake - changed ' to \" so it passes assert_select_rjs with an id
344
+ javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{name}("
345
+ javascript << "#{speed}" unless speed.nil?
346
+ javascript << ");"
347
+ else
348
+ # 090905 - Jake - changed ' to \" so it passes "assert_select_rjs :effect, ID"
349
+ javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{mode || 'effect'}('#{name}'"
350
+ javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
351
+ javascript << ",#{speed}" unless speed.nil?
352
+ javascript << ");"
353
+ end
354
+
355
+ end
356
+
357
+ def sortable_element_js(element_id, options = {}) #:nodoc:
358
+ #convert similar attributes
359
+ options[:handle] = ".#{options[:handle]}" if options[:handle]
360
+ if options[:tag] || options[:only]
361
+ options[:items] = "> "
362
+ options[:items] << options.delete(:tag) if options[:tag]
363
+ options[:items] << ".#{options.delete(:only)}" if options[:only]
364
+ end
365
+ options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
366
+ options[:containment] = options.delete(:container) if options[:container]
367
+ options[:dropOnEmpty] = false unless options[:dropOnEmpty]
368
+ options[:helper] = "'clone'" if options[:ghosting] == true
369
+ options[:axis] = case options.delete(:constraint)
370
+ when "vertical", :vertical
371
+ "y"
372
+ when "horizontal", :horizontal
373
+ "x"
374
+ when false
375
+ nil
376
+ when nil
377
+ "y"
378
+ end
379
+ options.delete(:axis) if options[:axis].nil?
380
+ options.delete(:overlap)
381
+ options.delete(:ghosting)
382
+
383
+ if options[:onUpdate] || options[:url]
384
+ if options[:format]
385
+ options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]', expression:#{options[:format]}})"
386
+ options.delete(:format)
387
+ else
388
+ options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
389
+ end
390
+
391
+ options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
392
+ end
393
+
394
+ options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
395
+ options[:update] = options.delete(:onUpdate) if options[:onUpdate]
396
+
397
+ [:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
398
+ options[option] = "'#{options[option]}'" if options[option]
399
+ end
400
+
401
+ options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
402
+
403
+ %(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});)
404
+ end
405
+
406
+ def draggable_element_js(element_id, options = {})
407
+ %(#{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)});)
408
+ end
409
+
410
+ def drop_receiving_element_js(element_id, options = {})
411
+ #convert similar options
412
+ options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
413
+ options[:drop] = options.delete(:onDrop) if options[:onDrop]
414
+
415
+ if options[:drop] || options[:url]
416
+ options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
417
+ options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
418
+ end
419
+
420
+ options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
421
+
422
+ options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
423
+ [:activeClass, :hoverClass, :tolerance].each do |option|
424
+ options[option] = "'#{options[option]}'" if options[option]
425
+ end
426
+
427
+ %(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
428
+ end
429
+ end
430
+ end
431
+ end