@@ -18,7 +18,32 @@ module Helpers
18
18
# See the documentation at http://script.aculo.us for more information on
19
19
# using these helpers in your application.
20
20
module JqueryUiHelper
21
- TOGGLE_EFFECTS = [ :toggle_appear , :toggle_slide , :toggle_blind ]
21
+ SCRIPTACULOUS_EFFECTS = {
22
+ :appear => { :method => 'fade' , :mode => 'show' } ,
23
+ :blind_down => { :method => 'blind' , :mode => 'show' , :options => { :direction => 'vertical' } } ,
24
+ :blind_up => { :method => 'blind' , :mode => 'hide' , :options => { :direction => 'vertical' } } ,
25
+ :blind_right => { :method => 'blind' , :mode => 'show' , :options => { :direction => 'horizontal' } } ,
26
+ :blind_left => { :method => 'blind' , :mode => 'hide' , :options => { :direction => 'horizontal' } } ,
27
+ :bounce_in => { :method => 'bounce' , :mode => 'show' , :options => { :direction => 'up' } } ,
28
+ :bounce_out => { :method => 'bounce' , :mode => 'hide' , :options => { :direction => 'up' } } ,
29
+ :drop_in => { :method => 'drop' , :mode => 'show' , :options => { :direction => 'up' } } ,
30
+ :drop_out => { :method => 'drop' , :mode => 'hide' , :options => { :direction => 'down' } } ,
31
+ :fade => { :method => 'fade' , :mode => 'hide' } ,
32
+ :fold_in => { :method => 'fold' , :mode => 'hide' } ,
33
+ :fold_out => { :method => 'fold' , :mode => 'show' } ,
34
+ :grow => { :method => 'scale' , :mode => 'show' } ,
35
+ :shrink => { :method => 'scale' , :mode => 'hide' } ,
36
+ :slide_down => { :method => 'slide' , :mode => 'show' , :options => { :direction => 'up' } } ,
37
+ :slide_up => { :method => 'slide' , :mode => 'hide' , :options => { :direction => 'up' } } ,
38
+ :slide_right => { :method => 'slide' , :mode => 'show' , :options => { :direction => 'left' } } ,
39
+ :slide_left => { :method => 'slide' , :mode => 'hide' , :options => { :direction => 'left' } } ,
40
+ :squish => { :method => 'scale' , :mode => 'hide' , :options => { :origin => "['top','left']" } } ,
41
+ :switch_on => { :method => 'clip' , :mode => 'show' , :options => { :direction => 'vertical' } } ,
42
+ :switch_off => { :method => 'clip' , :mode => 'hide' , :options => { :direction => 'vertical' } } ,
43
+ :toggle_appear => { :method => 'fade' , :mode => 'toggle' } ,
44
+ :toggle_slide => { :method => 'slide' , :mode => 'toggle' , :options => { :direction => 'up' } } ,
45
+ :toggle_blind => { :method => 'blind' , :mode => 'toggle' , :options => { :direction => 'vertical' } } ,
46
+ }
22
47
23
48
# Returns a JavaScript snippet to be used on the Ajax callbacks for
24
49
# starting visual effects.
@@ -39,23 +64,33 @@ module JqueryUiHelper
39
64
# You can change the behaviour with various options, see
40
65
# http://script.aculo.us for more documentation.
41
66
def visual_effect ( name , element_id = false , js_options = { } )
42
- element = element_id ? ActiveSupport ::JSON . encode ( element_id ) : "element "
67
+ element = element_id ? ActiveSupport ::JSON . encode ( jquery_id ( element_id ) ) : "this "
43
68
69
+ if SCRIPTACULOUS_EFFECTS . has_key? name . to_sym
70
+ effect = SCRIPTACULOUS_EFFECTS [ name . to_sym ]
71
+ name = effect [ :method ]
72
+ mode = effect [ :mode ]
73
+ js_options = js_options . merge ( effect [ :options ] ) if effect [ :options ]
74
+ end
75
+
44
76
js_options [ :queue ] = if js_options [ :queue ] . is_a? ( Hash )
45
77
'{' + js_options [ :queue ] . map { |k , v | k == :limit ? "#{ k } :#{ v } " : "#{ k } :'#{ v } '" } . join ( ',' ) + '}'
46
78
elsif js_options [ :queue ]
47
79
"'#{ js_options [ :queue ] } '"
48
80
end if js_options [ :queue ]
49
-
50
- [ :endcolor , :direction , :startcolor , :scaleMode , :restorecolor ] . each do |option |
81
+
82
+ [ :color , :direction , :startcolor , :endcolor ] . each do |option |
51
83
js_options [ option ] = "'#{ js_options [ option ] } '" if js_options [ option ]
52
84
end
85
+
86
+ js_options [ :duration ] = ( js_options [ :duration ] * 1000 ) . to_i if js_options . has_key? :duration
87
+
88
+ #if ['fadeIn','fadeOut','fadeToggle'].include?(name)
89
+ # "$(\"#{jquery_id(element_id)}\").#{name}();"
90
+ #else
91
+ "$(#{ element } ).#{ mode || "effect" } (\" #{ name } \" ,#{ options_for_javascript ( js_options ) } );"
92
+ #end
53
93
54
- if TOGGLE_EFFECTS . include? name . to_sym
55
- "Effect.toggle(#{ element } ,'#{ name . to_s . gsub ( /^toggle_/ , '' ) } ',#{ options_for_javascript ( js_options ) } );"
56
- else
57
- "new Effect.#{ name . to_s . camelize } (#{ element } ,#{ options_for_javascript ( js_options ) } );"
58
- end
59
94
end
60
95
61
96
# Makes the element with the DOM ID specified by +element_id+ sortable
@@ -136,7 +171,7 @@ def sortable_element(element_id, options = {})
136
171
def sortable_element_js ( element_id , options = { } ) #:nodoc:
137
172
options [ :with ] ||= "Sortable.serialize(#{ ActiveSupport ::JSON . encode ( element_id ) } )"
138
173
options [ :onUpdate ] ||= "function(){" + remote_function ( options ) + "}"
139
- options . delete_if { |key , value | PrototypeHelper ::AJAX_OPTIONS . include? ( key ) }
174
+ options . delete_if { |key , value | JqueryHelper ::AJAX_OPTIONS . include? ( key ) }
140
175
141
176
[ :tag , :overlap , :constraint , :handle ] . each do |option |
142
177
options [ option ] = "'#{ options [ option ] } '" if options [ option ]
@@ -207,7 +242,7 @@ def drop_receiving_element(element_id, options = {})
207
242
def drop_receiving_element_js ( element_id , options = { } ) #:nodoc:
208
243
options [ :with ] ||= "'id=' + encodeURIComponent(element.id)"
209
244
options [ :onDrop ] ||= "function(element){" + remote_function ( options ) + "}"
210
- options . delete_if { |key , value | PrototypeHelper ::AJAX_OPTIONS . include? ( key ) }
245
+ options . delete_if { |key , value | JqueryHelper ::AJAX_OPTIONS . include? ( key ) }
211
246
212
247
options [ :accept ] = array_or_string_for_javascript ( options [ :accept ] ) if options [ :accept ]
213
248
options [ :hoverclass ] = "'#{ options [ :hoverclass ] } '" if options [ :hoverclass ]
0 commit comments