webpulser-jrails 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +51 -0
- data/Manifest.txt +17 -0
- data/README +26 -0
- data/bin/jrails +36 -0
- data/init.rb +1 -0
- data/javascripts/jquery-ui.js +298 -0
- data/javascripts/jquery.js +19 -0
- data/javascripts/jrails.js +1 -0
- data/javascripts/sources/jrails.js +186 -0
- data/lib/jrails.rb +412 -0
- data/rails/init.rb +9 -0
- data/tasks/jrails.rake +28 -0
- metadata +72 -0
@@ -0,0 +1 @@
|
|
1
|
+
(function($){$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*"})(jQuery);(function($){$.fn.reset=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset()}})};$.fn.enable=function(){return this.each(function(){this.disabled=false})};$.fn.disable=function(){return this.each(function(){this.disabled=true})}})(jQuery);(function($){$.extend({fieldEvent:function(el,obs){var field=el[0]||el,e="change";if(field.type=="radio"||field.type=="checkbox"){e="click"}else{if(obs&&field.type=="text"||field.type=="textarea"){e="keyup"}}return e}});$.fn.extend({delayedObserver:function(delay,callback){var el=$(this);if(typeof window.delayedObserverStack=="undefined"){window.delayedObserverStack=[]}if(typeof window.delayedObserverCallback=="undefined"){window.delayedObserverCallback=function(stackPos){observed=window.delayedObserverStack[stackPos];if(observed.timer){clearTimeout(observed.timer)}observed.timer=setTimeout(function(){observed.timer=null;observed.callback(observed.obj,observed.obj.formVal())},observed.delay*1000);observed.oldVal=observed.obj.formVal()}}window.delayedObserverStack.push({obj:el,timer:null,delay:delay,oldVal:el.formVal(),callback:callback});var stackPos=window.delayedObserverStack.length-1;if(el[0].tagName=="FORM"){$(":input",el).each(function(){var field=$(this);field.bind($.fieldEvent(field,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})})}else{el.bind($.fieldEvent(el,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})}},formVal:function(){var el=this[0];if(el.tagName=="FORM"){return this.serialize()}if(el.type=="checkbox"||self.type=="radio"){return this.filter("input:checked").val()||""}else{return this.val()}}})})(jQuery);(function($){$.fn.extend({visualEffect:function(o){e=o.replace(/\_(.)/g,function(m,l){return l.toUpperCase()});return eval("$(this)."+e+"()")},appear:function(speed,callback){return this.fadeIn(speed,callback)},blindDown:function(speed,callback){return this.show("blind",{direction:"vertical"},speed,callback)},blindUp:function(speed,callback){return this.hide("blind",{direction:"vertical"},speed,callback)},blindRight:function(speed,callback){return this.show("blind",{direction:"horizontal"},speed,callback)},blindLeft:function(speed,callback){this.hide("blind",{direction:"horizontal"},speed,callback);return this},dropOut:function(speed,callback){return this.hide("drop",{direction:"down"},speed,callback)},dropIn:function(speed,callback){return this.show("drop",{direction:"up"},speed,callback)},fade:function(speed,callback){return this.fadeOut(speed,callback)},fadeToggle:function(speed,callback){return this.animate({opacity:"toggle"},speed,callback)},fold:function(speed,callback){return this.hide("fold",{},speed,callback)},foldOut:function(speed,callback){return this.show("fold",{},speed,callback)},grow:function(speed,callback){return this.show("scale",{},speed,callback)},highlight:function(speed,callback){return this.show("highlight",{},speed,callback)},puff:function(speed,callback){return this.hide("puff",{},speed,callback)},pulsate:function(speed,callback){return this.show("pulsate",{},speed,callback)},shake:function(speed,callback){return this.show("shake",{},speed,callback)},shrink:function(speed,callback){return this.hide("scale",{},speed,callback)},squish:function(speed,callback){return this.hide("scale",{origin:["top","left"]},speed,callback)},switchOff:function(speed,callback){return this.hide("clip",{},speed,callback)},switchOn:function(speed,callback){return this.show("clip",{},speed,callback)}})})(jQuery);
|
@@ -0,0 +1,186 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* jRails ajax extras
|
4
|
+
* version 0.1
|
5
|
+
* <aaron@ennerchi.com> | http://www.ennerchi.com
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
|
9
|
+
(function($) {
|
10
|
+
$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*";
|
11
|
+
})(jQuery);
|
12
|
+
|
13
|
+
|
14
|
+
/*
|
15
|
+
*
|
16
|
+
* jRails form extras
|
17
|
+
* <aaron@ennerchi.com> | http://www.ennerchi.com
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
(function($) {
|
23
|
+
// reset a form
|
24
|
+
$.fn.reset = function() {
|
25
|
+
return this.each(function() {
|
26
|
+
// guard against an input with the name of 'reset'
|
27
|
+
// note that IE reports the reset function as an 'object'
|
28
|
+
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
|
29
|
+
this.reset();
|
30
|
+
});
|
31
|
+
};
|
32
|
+
// enable a form element
|
33
|
+
$.fn.enable = function() {
|
34
|
+
return this.each(function() {
|
35
|
+
this.disabled = false;
|
36
|
+
});
|
37
|
+
};
|
38
|
+
// disable a form element
|
39
|
+
$.fn.disable = function() {
|
40
|
+
return this.each(function() {
|
41
|
+
this.disabled = true;
|
42
|
+
});
|
43
|
+
};
|
44
|
+
|
45
|
+
})(jQuery);
|
46
|
+
|
47
|
+
/*
|
48
|
+
*
|
49
|
+
* jRails form observer plugin
|
50
|
+
* version 0.2
|
51
|
+
* <aaron@ennerchi.com> | http://www.ennerchi.com
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
|
55
|
+
(function($) {
|
56
|
+
$.extend({ // Translate field to event
|
57
|
+
fieldEvent: function(el, obs) {
|
58
|
+
var field = el[0] || el, e = 'change';
|
59
|
+
if (field.type == 'radio' || field.type == 'checkbox') e = 'click';
|
60
|
+
else if (obs && field.type == 'text' || field.type == 'textarea') e = 'keyup';
|
61
|
+
return e;
|
62
|
+
}
|
63
|
+
});
|
64
|
+
$.fn.extend({ // Delayed observer for fields and forms
|
65
|
+
delayedObserver: function(delay, callback){
|
66
|
+
var el = $(this);
|
67
|
+
if (typeof window.delayedObserverStack == 'undefined') window.delayedObserverStack = [];
|
68
|
+
if (typeof window.delayedObserverCallback == 'undefined') {
|
69
|
+
window.delayedObserverCallback = function(stackPos) {
|
70
|
+
var observed = window.delayedObserverStack[stackPos];
|
71
|
+
if (observed.timer) clearTimeout(observed.timer);
|
72
|
+
observed.timer = setTimeout(function(){
|
73
|
+
observed.timer = null;
|
74
|
+
observed.callback(observed.obj, observed.obj.formVal());
|
75
|
+
}, observed.delay * 1000);
|
76
|
+
observed.oldVal = observed.obj.formVal();
|
77
|
+
};
|
78
|
+
}
|
79
|
+
window.delayedObserverStack.push({
|
80
|
+
obj: el, timer: null, delay: delay,
|
81
|
+
oldVal: el.formVal(), callback: callback
|
82
|
+
});
|
83
|
+
var stackPos = window.delayedObserverStack.length-1;
|
84
|
+
if (el[0].tagName == 'FORM') {
|
85
|
+
$(':input', el).each(function(){
|
86
|
+
var field = $(this);
|
87
|
+
field.bind($.fieldEvent(field, delay), function(){
|
88
|
+
var observed = window.delayedObserverStack[stackPos];
|
89
|
+
if (observed.obj.formVal() == observed.oldVal) return;
|
90
|
+
else window.delayedObserverCallback(stackPos);
|
91
|
+
});
|
92
|
+
});
|
93
|
+
} else {
|
94
|
+
el.bind($.fieldEvent(el, delay), function(){
|
95
|
+
var observed = window.delayedObserverStack[stackPos];
|
96
|
+
if (observed.obj.formVal() == observed.oldVal) return;
|
97
|
+
else window.delayedObserverCallback(stackPos);
|
98
|
+
});
|
99
|
+
};
|
100
|
+
},
|
101
|
+
formVal: function() { // Gets form values
|
102
|
+
var el = this[0];
|
103
|
+
if(el.tagName == 'FORM') return this.serialize();
|
104
|
+
if(el.type == 'checkbox' || el.type == 'radio') return this.filter('input:checked').val() || '';
|
105
|
+
else return this.val();
|
106
|
+
}
|
107
|
+
});
|
108
|
+
})(jQuery);
|
109
|
+
|
110
|
+
/*
|
111
|
+
*
|
112
|
+
* jRails visual effects stubs
|
113
|
+
* version 0.2
|
114
|
+
* <aaron@ennerchi.com> | http://www.ennerchi.com
|
115
|
+
*
|
116
|
+
*/
|
117
|
+
|
118
|
+
(function($) {
|
119
|
+
$.fn.extend({
|
120
|
+
visualEffect : function(o) {
|
121
|
+
e = o.replace(/\_(.)/g, function(m, l){return l.toUpperCase()});
|
122
|
+
return eval('$(this).'+e+'()');
|
123
|
+
},
|
124
|
+
appear : function(speed, callback) {
|
125
|
+
return this.fadeIn(speed, callback);
|
126
|
+
},
|
127
|
+
blindDown : function(speed, callback) {
|
128
|
+
return this.show('blind', { direction: 'vertical' }, speed, callback);
|
129
|
+
},
|
130
|
+
blindUp : function(speed, callback) {
|
131
|
+
return this.hide('blind', { direction: 'vertical' }, speed, callback);
|
132
|
+
},
|
133
|
+
blindRight : function(speed, callback) {
|
134
|
+
return this.show('blind', { direction: 'horizontal' }, speed, callback);
|
135
|
+
},
|
136
|
+
blindLeft : function(speed, callback) {
|
137
|
+
this.hide('blind', { direction: 'horizontal' }, speed, callback);
|
138
|
+
return this;
|
139
|
+
},
|
140
|
+
dropOut : function(speed, callback) {
|
141
|
+
return this.hide('drop', {direction: 'down' }, speed, callback);
|
142
|
+
},
|
143
|
+
dropIn : function(speed, callback) {
|
144
|
+
return this.show('drop', { direction: 'up' }, speed, callback);
|
145
|
+
},
|
146
|
+
fade : function(speed, callback) {
|
147
|
+
return this.fadeOut(speed, callback);
|
148
|
+
},
|
149
|
+
fadeToggle : function(speed, callback) {
|
150
|
+
return this.animate({opacity: 'toggle'}, speed, callback);
|
151
|
+
},
|
152
|
+
fold : function(speed, callback) {
|
153
|
+
return this.hide('fold', {}, speed, callback);
|
154
|
+
},
|
155
|
+
foldOut : function(speed, callback) {
|
156
|
+
return this.show('fold', {}, speed, callback);
|
157
|
+
},
|
158
|
+
grow : function(speed, callback) {
|
159
|
+
return this.show('scale', {}, speed, callback);
|
160
|
+
},
|
161
|
+
highlight : function(speed, callback) {
|
162
|
+
return this.show('highlight', {}, speed, callback);
|
163
|
+
},
|
164
|
+
puff : function(speed, callback) {
|
165
|
+
return this.hide('puff', {}, speed, callback);
|
166
|
+
},
|
167
|
+
pulsate : function(speed, callback) {
|
168
|
+
return this.show('pulsate', {}, speed, callback);
|
169
|
+
},
|
170
|
+
shake : function(speed, callback) {
|
171
|
+
return this.show('shake', {}, speed, callback);
|
172
|
+
},
|
173
|
+
shrink : function(speed, callback) {
|
174
|
+
return this.hide('scale', {}, speed, callback);
|
175
|
+
},
|
176
|
+
squish : function(speed, callback) {
|
177
|
+
return this.hide('scale', { origin: ['top', 'left'] }, speed, callback);
|
178
|
+
},
|
179
|
+
switchOff : function(speed, callback) {
|
180
|
+
return this.hide('clip', {}, speed, callback);
|
181
|
+
},
|
182
|
+
switchOn : function(speed, callback) {
|
183
|
+
return this.show('clip', {}, speed, callback);
|
184
|
+
}
|
185
|
+
});
|
186
|
+
})(jQuery);
|
data/lib/jrails.rb
ADDED
@@ -0,0 +1,412 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
module JavaScriptHelper
|
5
|
+
|
6
|
+
# This function can be used to render rjs inline
|
7
|
+
#
|
8
|
+
# <%= javascript_function do |page|
|
9
|
+
# page.replace_html :list, :partial => 'list', :object => @list
|
10
|
+
# end %>
|
11
|
+
#
|
12
|
+
def javascript_function(*args, &block)
|
13
|
+
html_options = args.extract_options!
|
14
|
+
function = args[0] || ''
|
15
|
+
|
16
|
+
html_options.symbolize_keys!
|
17
|
+
function = update_page(&block) if block_given?
|
18
|
+
javascript_tag(function)
|
19
|
+
end
|
20
|
+
|
21
|
+
def jquery_id(id)
|
22
|
+
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
|
23
|
+
end
|
24
|
+
|
25
|
+
def jquery_ids(ids)
|
26
|
+
Array(ids).map{|id| jquery_id(id)}.join(',')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
module PrototypeHelper
|
32
|
+
|
33
|
+
unless const_defined? :JQUERY_VAR
|
34
|
+
JQUERY_VAR = '$'
|
35
|
+
end
|
36
|
+
|
37
|
+
unless const_defined? :JQCALLBACKS
|
38
|
+
JQCALLBACKS = Set.new([ :beforeSend, :complete, :error, :success ] + (100..599).to_a)
|
39
|
+
#instance_eval { remove_const :AJAX_OPTIONS }
|
40
|
+
remove_const(:AJAX_OPTIONS) if const_defined?(:AJAX_OPTIONS)
|
41
|
+
AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
|
42
|
+
:asynchronous, :method, :insertion, :position,
|
43
|
+
:form, :with, :update, :script ]).merge(JQCALLBACKS)
|
44
|
+
end
|
45
|
+
|
46
|
+
def periodically_call_remote(options = {})
|
47
|
+
frequency = options[:frequency] || 10 # every ten seconds by default
|
48
|
+
code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
|
49
|
+
javascript_tag(code)
|
50
|
+
end
|
51
|
+
|
52
|
+
def remote_function(options)
|
53
|
+
javascript_options = options_for_ajax(options)
|
54
|
+
|
55
|
+
update = ''
|
56
|
+
if options[:update] && options[:update].is_a?(Hash)
|
57
|
+
update = []
|
58
|
+
update << "success:'#{options[:update][:success]}'" if options[:update][:success]
|
59
|
+
update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
|
60
|
+
update = '{' + update.join(',') + '}'
|
61
|
+
elsif options[:update]
|
62
|
+
update << "'#{options[:update]}'"
|
63
|
+
end
|
64
|
+
|
65
|
+
function = "#{JQUERY_VAR}.ajax(#{javascript_options})"
|
66
|
+
|
67
|
+
function = "#{options[:before]}; #{function}" if options[:before]
|
68
|
+
function = "#{function}; #{options[:after]}" if options[:after]
|
69
|
+
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
|
70
|
+
function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
|
71
|
+
return function
|
72
|
+
end
|
73
|
+
|
74
|
+
class JavaScriptGenerator
|
75
|
+
module GeneratorMethods
|
76
|
+
|
77
|
+
def insert_html(position, id, *options_for_render)
|
78
|
+
insertion = position.to_s.downcase
|
79
|
+
insertion = 'append' if insertion == 'bottom'
|
80
|
+
insertion = 'prepend' if insertion == 'top'
|
81
|
+
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
|
82
|
+
end
|
83
|
+
|
84
|
+
def replace_html(id, *options_for_render)
|
85
|
+
insert_html(:html, id, *options_for_render)
|
86
|
+
end
|
87
|
+
|
88
|
+
def replace(id, *options_for_render)
|
89
|
+
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
|
90
|
+
end
|
91
|
+
|
92
|
+
def remove(*ids)
|
93
|
+
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").remove"
|
94
|
+
end
|
95
|
+
|
96
|
+
def show(*ids)
|
97
|
+
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").show"
|
98
|
+
end
|
99
|
+
|
100
|
+
def hide(*ids)
|
101
|
+
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").hide"
|
102
|
+
end
|
103
|
+
|
104
|
+
def toggle(*ids)
|
105
|
+
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").toggle"
|
106
|
+
end
|
107
|
+
|
108
|
+
def jquery_id(id)
|
109
|
+
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
|
110
|
+
end
|
111
|
+
|
112
|
+
def jquery_ids(ids)
|
113
|
+
Array(ids).map{|id| jquery_id(id)}.join(',')
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
protected
|
120
|
+
def options_for_ajax(options)
|
121
|
+
js_options = build_callbacks(options)
|
122
|
+
|
123
|
+
url_options = options[:url]
|
124
|
+
url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
|
125
|
+
js_options['url'] = "'#{url_for(url_options)}'"
|
126
|
+
js_options['async'] = false if options[:type] == :synchronous
|
127
|
+
js_options['type'] = options[:method] ? method_option_to_s(options[:method]) : ( options[:form] ? "'post'" : nil )
|
128
|
+
js_options['dataType'] = options[:datatype] ? "'#{options[:datatype]}'" : (options[:update] ? nil : "'script'")
|
129
|
+
|
130
|
+
if options[:form]
|
131
|
+
js_options['data'] = "#{JQUERY_VAR}.param(#{JQUERY_VAR}(this).serializeArray())"
|
132
|
+
elsif options[:submit]
|
133
|
+
js_options['data'] = "#{JQUERY_VAR}(\"##{options[:submit]} :input\").serialize()"
|
134
|
+
elsif options[:with]
|
135
|
+
js_options['data'] = options[:with].gsub("Form.serialize(this.form)","#{JQUERY_VAR}.param(#{JQUERY_VAR}(this.form).serializeArray())")
|
136
|
+
end
|
137
|
+
|
138
|
+
js_options['type'] ||= "'post'"
|
139
|
+
if options[:method]
|
140
|
+
if method_option_to_s(options[:method]) == "'put'" || method_option_to_s(options[:method]) == "'delete'"
|
141
|
+
js_options['type'] = "'post'"
|
142
|
+
if js_options['data']
|
143
|
+
js_options['data'] << " + '&"
|
144
|
+
else
|
145
|
+
js_options['data'] = "'"
|
146
|
+
end
|
147
|
+
js_options['data'] << "_method=#{options[:method]}'"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
if respond_to?('protect_against_forgery?') && protect_against_forgery?
|
152
|
+
if js_options['data']
|
153
|
+
js_options['data'] << " + '&"
|
154
|
+
else
|
155
|
+
js_options['data'] = "'"
|
156
|
+
end
|
157
|
+
js_options['data'] << "#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')"
|
158
|
+
end
|
159
|
+
js_options['data'] = "''" if js_options['type'] == "'post'" && js_options['data'].nil?
|
160
|
+
options_for_javascript(js_options.reject {|key, value| value.nil?})
|
161
|
+
end
|
162
|
+
|
163
|
+
def build_update_for_success(html_id, insertion=nil)
|
164
|
+
insertion = build_insertion(insertion)
|
165
|
+
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request);"
|
166
|
+
end
|
167
|
+
|
168
|
+
def build_update_for_error(html_id, insertion=nil)
|
169
|
+
insertion = build_insertion(insertion)
|
170
|
+
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request.responseText);"
|
171
|
+
end
|
172
|
+
|
173
|
+
def build_insertion(insertion)
|
174
|
+
insertion = insertion ? insertion.to_s.downcase : 'html'
|
175
|
+
insertion = 'append' if insertion == 'bottom'
|
176
|
+
insertion = 'prepend' if insertion == 'top'
|
177
|
+
insertion
|
178
|
+
end
|
179
|
+
|
180
|
+
def build_observer(klass, name, options = {})
|
181
|
+
if options[:with] && (options[:with] !~ /[\{=(.]/)
|
182
|
+
options[:with] = "'#{options[:with]}=' + value"
|
183
|
+
else
|
184
|
+
options[:with] ||= 'value' unless options[:function]
|
185
|
+
end
|
186
|
+
|
187
|
+
callback = options[:function] || remote_function(options)
|
188
|
+
javascript = "#{JQUERY_VAR}('#{jquery_id(name)}').delayedObserver("
|
189
|
+
javascript << "#{options[:frequency] || 0}, "
|
190
|
+
javascript << "function(element, value) {"
|
191
|
+
javascript << "#{callback}}"
|
192
|
+
#javascript << ", '#{options[:on]}'" if options[:on]
|
193
|
+
javascript << ")"
|
194
|
+
javascript_tag(%(#{JQUERY_VAR}(function(){ #{javascript} });))
|
195
|
+
end
|
196
|
+
|
197
|
+
def build_callbacks(options)
|
198
|
+
callbacks = {}
|
199
|
+
options[:beforeSend] = '';
|
200
|
+
[:uninitialized,:loading,:loaded].each do |key|
|
201
|
+
options[:beforeSend] << (options[key].last == ';' ? options.delete(key) : options.delete(key) << ';') if options[key]
|
202
|
+
end
|
203
|
+
options.delete(:beforeSend) if options[:beforeSend].blank?
|
204
|
+
options[:error] = options.delete(:failure) if options[:failure]
|
205
|
+
if options[:update]
|
206
|
+
if options[:update].is_a?(Hash)
|
207
|
+
options[:update][:error] = options[:update].delete(:failure) if options[:update][:failure]
|
208
|
+
if options[:update][:success]
|
209
|
+
options[:success] = build_update_for_success(options[:update][:success], options[:position]) << (options[:success] ? options[:success] : '')
|
210
|
+
end
|
211
|
+
if options[:update][:error]
|
212
|
+
options[:error] = build_update_for_error(options[:update][:error], options[:position]) << (options[:error] ? options[:error] : '')
|
213
|
+
end
|
214
|
+
else
|
215
|
+
options[:success] = build_update_for_success(options[:update], options[:position]) << (options[:success] ? options[:success] : '')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
options.each do |callback, code|
|
219
|
+
if JQCALLBACKS.include?(callback)
|
220
|
+
callbacks[callback] = "function(request){#{code}}"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
callbacks
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
|
229
|
+
|
230
|
+
unless const_defined? :JQUERY_VAR
|
231
|
+
JQUERY_VAR = PrototypeHelper::JQUERY_VAR
|
232
|
+
end
|
233
|
+
|
234
|
+
def initialize(generator, id)
|
235
|
+
id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
|
236
|
+
@id = id
|
237
|
+
super(generator, "#{JQUERY_VAR}(\"#{id}\")")
|
238
|
+
end
|
239
|
+
|
240
|
+
def replace_html(*options_for_render)
|
241
|
+
call 'html', @generator.send(:render, *options_for_render)
|
242
|
+
end
|
243
|
+
|
244
|
+
def replace(*options_for_render)
|
245
|
+
call 'replaceWith', @generator.send(:render, *options_for_render)
|
246
|
+
end
|
247
|
+
|
248
|
+
def reload(options_for_replace={})
|
249
|
+
replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
|
250
|
+
end
|
251
|
+
|
252
|
+
def value()
|
253
|
+
call 'val()'
|
254
|
+
end
|
255
|
+
|
256
|
+
def value=(value)
|
257
|
+
call 'val', value
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
|
263
|
+
|
264
|
+
unless const_defined? :JQUERY_VAR
|
265
|
+
JQUERY_VAR = PrototypeHelper::JQUERY_VAR
|
266
|
+
end
|
267
|
+
|
268
|
+
def initialize(generator, pattern)
|
269
|
+
super(generator, "#{JQUERY_VAR}(#{pattern.to_json})")
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
module ScriptaculousHelper
|
274
|
+
|
275
|
+
unless const_defined? :JQUERY_VAR
|
276
|
+
JQUERY_VAR = PrototypeHelper::JQUERY_VAR
|
277
|
+
end
|
278
|
+
|
279
|
+
unless const_defined? :SCRIPTACULOUS_EFFECTS
|
280
|
+
SCRIPTACULOUS_EFFECTS = {
|
281
|
+
:appear => {:method => 'fadeIn'},
|
282
|
+
:blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
|
283
|
+
:blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
|
284
|
+
:blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
|
285
|
+
:blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
|
286
|
+
:bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
|
287
|
+
:bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
|
288
|
+
:drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
|
289
|
+
:drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
|
290
|
+
:fade => {:method => 'fadeOut'},
|
291
|
+
:fold_in => {:method => 'fold', :mode => 'hide'},
|
292
|
+
:fold_out => {:method => 'fold', :mode => 'show'},
|
293
|
+
:grow => {:method => 'scale', :mode => 'show'},
|
294
|
+
:shrink => {:method => 'scale', :mode => 'hide'},
|
295
|
+
:slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
|
296
|
+
:slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
|
297
|
+
:slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
|
298
|
+
:slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
|
299
|
+
:squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
|
300
|
+
:switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
|
301
|
+
:switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
|
302
|
+
:toggle_appear => {:method => 'fadeToggle'},
|
303
|
+
:toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
|
304
|
+
:toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
|
305
|
+
}
|
306
|
+
end
|
307
|
+
|
308
|
+
def visual_effect(name, element_id = false, js_options = {})
|
309
|
+
element = element_id ? element_id : "this"
|
310
|
+
|
311
|
+
if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
|
312
|
+
effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
|
313
|
+
name = effect[:method]
|
314
|
+
mode = effect[:mode]
|
315
|
+
js_options = js_options.merge(effect[:options]) if effect[:options]
|
316
|
+
end
|
317
|
+
|
318
|
+
[:color, :direction].each do |option|
|
319
|
+
js_options[option] = "'#{js_options[option]}'" if js_options[option]
|
320
|
+
end
|
321
|
+
|
322
|
+
if js_options.has_key? :duration
|
323
|
+
speed = js_options.delete :duration
|
324
|
+
speed = (speed * 1000).to_i unless speed.nil?
|
325
|
+
else
|
326
|
+
speed = js_options.delete :speed
|
327
|
+
end
|
328
|
+
|
329
|
+
if ['fadeIn','fadeOut','fadeToggle'].include?(name)
|
330
|
+
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{name}("
|
331
|
+
javascript << "#{speed}" unless speed.nil?
|
332
|
+
javascript << ");"
|
333
|
+
else
|
334
|
+
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{mode || 'effect'}('#{name}'"
|
335
|
+
javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
|
336
|
+
javascript << ",#{speed}" unless speed.nil?
|
337
|
+
javascript << ");"
|
338
|
+
end
|
339
|
+
%(#{JQUERY_VAR}(function(){ #{javascript} });)
|
340
|
+
end
|
341
|
+
|
342
|
+
def sortable_element_js(element_id, options = {}) #:nodoc:
|
343
|
+
#convert similar attributes
|
344
|
+
options[:handle] = ".#{options[:handle]}" if options[:handle]
|
345
|
+
if options[:tag] || options[:only]
|
346
|
+
options[:items] = "> "
|
347
|
+
options[:items] << options.delete(:tag) if options[:tag]
|
348
|
+
options[:items] << ".#{options.delete(:only)}" if options[:only]
|
349
|
+
end
|
350
|
+
options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
|
351
|
+
options[:containment] = options.delete(:container) if options[:container]
|
352
|
+
options[:dropOnEmpty] = false unless options[:dropOnEmpty]
|
353
|
+
options[:helper] = "'clone'" if options[:ghosting] == true
|
354
|
+
options[:axis] = case options.delete(:constraint)
|
355
|
+
when "vertical"
|
356
|
+
"y"
|
357
|
+
when "horizontal"
|
358
|
+
"x"
|
359
|
+
when false
|
360
|
+
nil
|
361
|
+
when nil
|
362
|
+
"y"
|
363
|
+
end
|
364
|
+
options.delete(:axis) if options[:axis].nil?
|
365
|
+
options.delete(:overlap)
|
366
|
+
options.delete(:ghosting)
|
367
|
+
|
368
|
+
if options[:onUpdate] || options[:url]
|
369
|
+
options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
|
370
|
+
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
|
371
|
+
end
|
372
|
+
|
373
|
+
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
|
374
|
+
options[:update] = options.delete(:onUpdate) if options[:onUpdate]
|
375
|
+
|
376
|
+
[:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
|
377
|
+
options[option] = "'#{options[option]}'" if options[option]
|
378
|
+
end
|
379
|
+
|
380
|
+
options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
|
381
|
+
|
382
|
+
%(#{JQUERY_VAR}(function(){ #{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)}); });)
|
383
|
+
end
|
384
|
+
|
385
|
+
def draggable_element_js(element_id, options = {})
|
386
|
+
%(#{JQUERY_VAR}(function(){ #{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)}); });)
|
387
|
+
end
|
388
|
+
|
389
|
+
def drop_receiving_element_js(element_id, options = {})
|
390
|
+
#convert similar options
|
391
|
+
options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
|
392
|
+
options[:drop] = options.delete(:onDrop) if options[:onDrop]
|
393
|
+
|
394
|
+
if options[:drop] || options[:url]
|
395
|
+
options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
|
396
|
+
options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
|
397
|
+
end
|
398
|
+
|
399
|
+
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
|
400
|
+
|
401
|
+
options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
|
402
|
+
[:activeClass, :hoverClass, :tolerance].each do |option|
|
403
|
+
options[option] = "'#{options[option]}'" if options[option]
|
404
|
+
end
|
405
|
+
|
406
|
+
%(#{JQUERY_VAR}(function(){ #{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)}); });)
|
407
|
+
end
|
408
|
+
|
409
|
+
end
|
410
|
+
|
411
|
+
end
|
412
|
+
end
|