Module: JQueryOnRails::Helpers::JQueryHelper::JavaScriptGenerator::GeneratorMethods
- Defined in:
- lib/jquery_on_rails/helpers/jquery_helper.rb
Overview
Mostly copied from Rails 3 PrototypeHelper
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments) ⇒ Object
232
233
234
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 232
def method_missing(method, *arguments)
JavaScriptProxy.new(self, method.to_s.camelize)
end
|
Instance Method Details
#<<(javascript) ⇒ Object
174
175
176
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 174
def <<(javascript)
@lines << javascript
end
|
#[](id) ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 104
def [](id)
case id
when String, Symbol, NilClass
JavaScriptElementProxy.new(self, id)
else
JavaScriptElementProxy.new(self, ActionController::RecordIdentifier.dom_id(id))
end
end
|
#alert(message) ⇒ Object
153
154
155
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 153
def alert(message)
call 'alert', message
end
|
#assign(variable, value) ⇒ Object
170
171
172
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 170
def assign(variable, value)
record "#{variable} = #{javascript_object_for(value)}"
end
|
#call(function, *arguments, &block) ⇒ Object
166
167
168
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 166
def call(function, *arguments, &block)
record "#{function}(#{arguments_for_call(arguments, block)})"
end
|
#delay(seconds = 1) ⇒ Object
178
179
180
181
182
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 178
def delay(seconds = 1)
record "setTimeout(function(){\n\n"
yield
record "}, #{(seconds * 1000).to_i})"
end
|
#hide(*ids) ⇒ Object
145
146
147
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 145
def hide(*ids)
loop_on_multiple_ids 'hide', ids
end
|
#insert_html(position, id, *options_for_render) ⇒ Object
121
122
123
124
125
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 121
def insert_html(position, id, *options_for_render)
content = javascript_object_for(render(*options_for_render))
position = INSERT_POSITIONS[position.to_sym] || position.to_s.downcase
record "jQuery(\"##{id}\").#{position}(#{content});"
end
|
#literal(code) ⇒ Object
113
114
115
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 113
def literal(code)
::ActiveSupport::JSON::Variable.new(code.to_s)
end
|
#redirect_to(location) ⇒ Object
157
158
159
160
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 157
def redirect_to(location)
url = location.is_a?(String) ? location : @context.url_for(location)
record "window.location.href = #{url.inspect}"
end
|
#reload ⇒ Object
162
163
164
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 162
def reload
record 'window.location.reload()'
end
|
#remove(*ids) ⇒ Object
137
138
139
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 137
def remove(*ids)
loop_on_multiple_ids 'remove', ids
end
|
#replace(id, *options_for_render) ⇒ Object
132
133
134
135
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 132
def replace(id, *options_for_render)
content = javascript_object_for(render(*options_for_render))
record "jQuery(\"##{id}\").replaceWith(#{content});"
end
|
#replace_html(id, *options_for_render) ⇒ Object
127
128
129
130
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 127
def replace_html(id, *options_for_render)
content = javascript_object_for(render(*options_for_render))
record "jQuery(\"##{id}\").html(#{content});"
end
|
#select(pattern) ⇒ Object
117
118
119
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 117
def select(pattern)
JavaScriptElementCollectionProxy.new(self, pattern)
end
|
#show(*ids) ⇒ Object
141
142
143
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 141
def show(*ids)
loop_on_multiple_ids 'show', ids
end
|
#to_s ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 94
def to_s javascript = @lines * $/
if ActionView::Base.debug_rjs
source = javascript.dup
javascript.replace "try {\n#{source}\n} catch (e) "
javascript << "{ alert('RJS error:\\n\\n' + e.toString()); alert('#{source.gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }}'); throw e }"
end
javascript
end
|
#toggle(*ids) ⇒ Object
149
150
151
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 149
def toggle(*ids)
loop_on_multiple_ids 'toggle', ids
end
|
#visual_effect(name, id = nil, options = {}) ⇒ Object
184
185
186
|
# File 'lib/jquery_on_rails/helpers/jquery_helper.rb', line 184
def visual_effect(name, id = nil, options = {})
record @context.send(:visual_effect, name, id, options)
end
|