bivouac 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +6 -7
- data/bin/bivouac +1 -1
- data/doc/rdoc/classes/BivouacHelpers/BaseView.html +178 -0
- data/doc/rdoc/classes/BivouacHelpers/FormView.html +398 -0
- data/doc/rdoc/classes/BivouacHelpers/HtmlView.html +305 -0
- data/doc/rdoc/classes/BivouacHelpers/JavaScriptView.html +573 -0
- data/doc/rdoc/classes/BivouacHelpers/ScriptAculoUsView.html +258 -0
- data/doc/rdoc/classes/BivouacHelpers/TooltipView.html +158 -0
- data/doc/rdoc/classes/BivouacHelpers.html +117 -0
- data/doc/rdoc/classes/JavaScriptGenerator.html +564 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/AUTHORS.html +109 -0
- data/doc/rdoc/files/COPYING.html +533 -0
- data/doc/rdoc/files/README.html +427 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/base_rb.html +109 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/form_rb.html +109 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/html_rb.html +109 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/javascript_rb.html +113 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/scriptaculous_rb.html +113 -0
- data/doc/rdoc/files/lib/bivouac/helpers/view/goh/tooltip_rb.html +109 -0
- data/doc/rdoc/index.html +10 -0
- data/doc/rdoc/permalink.gif +0 -0
- data/doc/rdoc/rdoc-style.css +106 -0
- data/doc/rdoc/rubyfr.png +0 -0
- data/examples/bivouac_sample/Rakefile +48 -0
- data/examples/bivouac_sample/app/bivouac_sample.rb +15 -7
- data/examples/bivouac_sample/app/controllers/index.rb +2 -2
- data/examples/bivouac_sample/app/controllers/sound.rb +10 -0
- data/examples/bivouac_sample/app/helpers/_helpers.rb +6 -3
- data/examples/bivouac_sample/app/views/sound.rb +16 -0
- data/examples/bivouac_sample/config/environment.rb +5 -2
- data/examples/bivouac_sample/config/postamble.rb +89 -18
- data/examples/bivouac_sample/public/javascripts/builder.js +12 -7
- data/examples/bivouac_sample/public/javascripts/controls.js +485 -355
- data/examples/bivouac_sample/public/javascripts/dragdrop.js +82 -52
- data/examples/bivouac_sample/public/javascripts/effects.js +361 -329
- data/examples/bivouac_sample/public/javascripts/prototype.js +2826 -1120
- data/examples/bivouac_sample/public/javascripts/scriptaculous.js +15 -8
- data/examples/bivouac_sample/public/javascripts/slider.js +40 -43
- data/examples/bivouac_sample/public/javascripts/sound.js +55 -0
- data/examples/bivouac_sample/public/javascripts/unittest.js +16 -12
- data/examples/bivouac_sample/public/sound/sword.mp3 +0 -0
- data/examples/bivouac_sample/script/console +6 -0
- data/examples/bivouac_sample/script/plugin +3 -0
- data/examples/bivouac_sample/script/server +2 -1
- data/examples/bivouac_sample/test/test_sound.rb +15 -0
- data/lib/bivouac/helpers/view/goh/sound.rb +38 -0
- data/lib/bivouac/template/application/helpers_goh.rb +2 -0
- data/lib/bivouac/template/static/builder.js +12 -7
- data/lib/bivouac/template/static/controls.js +485 -355
- data/lib/bivouac/template/static/dragdrop.js +82 -52
- data/lib/bivouac/template/static/effects.js +361 -329
- data/lib/bivouac/template/static/prototype.js +2826 -1120
- data/lib/bivouac/template/static/scriptaculous.js +15 -8
- data/lib/bivouac/template/static/slider.js +40 -43
- data/lib/bivouac/template/static/sound.js +55 -0
- data/lib/bivouac/template/static/unittest.js +16 -12
- metadata +45 -2
@@ -0,0 +1,573 @@
|
|
1
|
+
|
2
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>
|
6
|
+
Bivouac, the Documentation » Module: BivouacHelpers::JavaScriptView
|
7
|
+
</title>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
9
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
10
|
+
<script language="JavaScript" type="text/javascript">
|
11
|
+
// <![CDATA[
|
12
|
+
|
13
|
+
function toggleSource( id )
|
14
|
+
{
|
15
|
+
var elem
|
16
|
+
var link
|
17
|
+
|
18
|
+
if( document.getElementById )
|
19
|
+
{
|
20
|
+
elem = document.getElementById( id )
|
21
|
+
link = document.getElementById( "l_" + id )
|
22
|
+
}
|
23
|
+
else if ( document.all )
|
24
|
+
{
|
25
|
+
elem = eval( "document.all." + id )
|
26
|
+
link = eval( "document.all.l_" + id )
|
27
|
+
}
|
28
|
+
else
|
29
|
+
return false;
|
30
|
+
|
31
|
+
if( elem.style.display == "block" )
|
32
|
+
{
|
33
|
+
elem.style.display = "none"
|
34
|
+
link.innerHTML = "show source"
|
35
|
+
}
|
36
|
+
else
|
37
|
+
{
|
38
|
+
elem.style.display = "block"
|
39
|
+
link.innerHTML = "hide source"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
function openCode( url )
|
44
|
+
{
|
45
|
+
window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
|
46
|
+
}
|
47
|
+
// ]]>
|
48
|
+
</script>
|
49
|
+
</head>
|
50
|
+
<body>
|
51
|
+
<!--
|
52
|
+
<div id="menu">
|
53
|
+
<h3 class="title">Module: BivouacHelpers::JavaScriptView</h3>
|
54
|
+
</div>
|
55
|
+
-->
|
56
|
+
<div id="fullpage">
|
57
|
+
<div id="pager">
|
58
|
+
<table>
|
59
|
+
<tr><td><img src="../../rubyfr.png" /></td>
|
60
|
+
<td id="pagertd">
|
61
|
+
<strong># Module: BivouacHelpers::JavaScriptView<br />
|
62
|
+
[
|
63
|
+
"<a href="../../files/README.html" value="File: README">README</a>",
|
64
|
+
"<a href="../../files/AUTHORS.html" value="File: AUTHORS">AUTHORS</a>",
|
65
|
+
"<a href="../../files/COPYING.html" value="File: COPYING">COPYING</a>",
|
66
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/base_rb.html" value="File: base.rb">lib/bivouac/helpers/view/goh/base.rb</a>",
|
67
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/form_rb.html" value="File: form.rb">lib/bivouac/helpers/view/goh/form.rb</a>",
|
68
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/html_rb.html" value="File: html.rb">lib/bivouac/helpers/view/goh/html.rb</a>",
|
69
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/tooltip_rb.html" value="File: tooltip.rb">lib/bivouac/helpers/view/goh/tooltip.rb</a>",
|
70
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/scriptaculous_rb.html" value="File: scriptaculous.rb">lib/bivouac/helpers/view/goh/scriptaculous.rb</a>",
|
71
|
+
"<a href="../../files/lib/bivouac/helpers/view/goh/javascript_rb.html" value="File: javascript.rb">lib/bivouac/helpers/view/goh/javascript.rb</a>",
|
72
|
+
<a href="http://greg.rubyfr.net">nil</a>].each do<br />
|
73
|
+
<a href="../../classes/JavaScriptGenerator.html" title="Class: JavaScriptGenerator">JavaScriptGenerator</a>.view_html<br />
|
74
|
+
<a href="../../classes/BivouacHelpers.html" title="Module: BivouacHelpers">BivouacHelpers</a>.view_html<br />
|
75
|
+
<a href="../../classes/BivouacHelpers/TooltipView.html" title="Module: BivouacHelpers::TooltipView">BivouacHelpers::TooltipView</a>.view_html<br />
|
76
|
+
<a href="../../classes/BivouacHelpers/ScriptAculoUsView.html" title="Module: BivouacHelpers::ScriptAculoUsView">BivouacHelpers::ScriptAculoUsView</a>.view_html<br />
|
77
|
+
<a href="../../classes/BivouacHelpers/BaseView.html" title="Module: BivouacHelpers::BaseView">BivouacHelpers::BaseView</a>.view_html<br />
|
78
|
+
<a href="../../classes/BivouacHelpers/JavaScriptView.html" title="Module: BivouacHelpers::JavaScriptView">BivouacHelpers::JavaScriptView</a>.view_html<br />
|
79
|
+
<a href="../../classes/BivouacHelpers/HtmlView.html" title="Module: BivouacHelpers::HtmlView">BivouacHelpers::HtmlView</a>.view_html<br />
|
80
|
+
<a href="../../classes/BivouacHelpers/FormView.html" title="Module: BivouacHelpers::FormView">BivouacHelpers::FormView</a>.view_html<br />
|
81
|
+
end</strong>
|
82
|
+
</td></tr>
|
83
|
+
</table>
|
84
|
+
</ul>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
<div id="BivouacHelpers::JavaScriptView" class="page_shade">
|
89
|
+
<div class="page">
|
90
|
+
<h3>Module BivouacHelpers::JavaScriptView < Object</h3>
|
91
|
+
|
92
|
+
(in files
|
93
|
+
<a href="../../files/lib/bivouac/helpers/view/goh/javascript_rb.html">lib/bivouac/helpers/view/goh/javascript.rb</a>
|
94
|
+
)
|
95
|
+
|
96
|
+
<p>
|
97
|
+
bivouac/helpers/view/html
|
98
|
+
</p>
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
<h2 class="ruled">Methods</h2>
|
105
|
+
<h4 class="ruled">Public Instance method:
|
106
|
+
<strong><a name="M000029">escape_javascript(javascript)</a></strong> <a href="#M000029"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: escape_javascript" /></a></h4>
|
107
|
+
|
108
|
+
<p>
|
109
|
+
Escape carrier returns and single and double quotes for JavaScript
|
110
|
+
segments.
|
111
|
+
</p>
|
112
|
+
|
113
|
+
<div class="sourcecode">
|
114
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000029_source')" id="l_M000029_source">show source</a> ]</p>
|
115
|
+
<div id="M000029_source" class="dyn-source">
|
116
|
+
<pre>
|
117
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 202</span>
|
118
|
+
202: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">escape_javascript</span>(<span class="ruby-identifier">javascript</span>)
|
119
|
+
203: (<span class="ruby-identifier">javascript</span> <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\\'</span>,<span class="ruby-value str">'\0\0'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\r\n|\n|\r/</span>, <span class="ruby-value str">"\\n"</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/["']/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-node">"\\#{m}"</span> }
|
120
|
+
204: <span class="ruby-keyword kw">end</span>
|
121
|
+
</pre>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
<h4 class="ruled">Public Instance method:
|
125
|
+
<strong><a name="M000030">javascript_tag( content, options = {} )</a></strong> <a href="#M000030"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: javascript_tag" /></a></h4>
|
126
|
+
|
127
|
+
<p>
|
128
|
+
Returns a JavaScript tag with the <tt>block</tt> inside. Example:
|
129
|
+
</p>
|
130
|
+
<pre>
|
131
|
+
javascript_tag( "alert('Hello World!')", :defer => 'true' )
|
132
|
+
</pre>
|
133
|
+
<p>
|
134
|
+
Returns:
|
135
|
+
</p>
|
136
|
+
<pre>
|
137
|
+
<script defer="true" type="text/javascript">
|
138
|
+
//<![CDATA[
|
139
|
+
alert('Hello World!')
|
140
|
+
//]]>
|
141
|
+
</script>
|
142
|
+
</pre>
|
143
|
+
|
144
|
+
<div class="sourcecode">
|
145
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000030_source')" id="l_M000030_source">show source</a> ]</p>
|
146
|
+
<div id="M000030_source" class="dyn-source">
|
147
|
+
<pre>
|
148
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 218</span>
|
149
|
+
218: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">javascript_tag</span>( <span class="ruby-identifier">content</span>, <span class="ruby-identifier">options</span> = {} )
|
150
|
+
219: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:type</span>] = <span class="ruby-value str">"text/javascript"</span>
|
151
|
+
220: <span class="ruby-identifier">script</span>( <span class="ruby-identifier">options</span> ) <span class="ruby-keyword kw">do</span>
|
152
|
+
221: <span class="ruby-value str">"//<![CDATA[\n"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">content</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n//]]>"</span>
|
153
|
+
222: <span class="ruby-keyword kw">end</span>
|
154
|
+
223: <span class="ruby-keyword kw">end</span>
|
155
|
+
</pre>
|
156
|
+
</div>
|
157
|
+
</div>
|
158
|
+
<h4 class="ruled">Public Instance method:
|
159
|
+
<strong><a name="M000033">link_to_function( name, *args, &block )</a></strong> <a href="#M000033"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: link_to_function" /></a></h4>
|
160
|
+
|
161
|
+
<p>
|
162
|
+
Returns a link that will trigger a JavaScript function using the onclick
|
163
|
+
handler and return false after the fact.
|
164
|
+
</p>
|
165
|
+
<p>
|
166
|
+
The function argument can be omitted in favor of an <a
|
167
|
+
href="JavaScriptView.html#M000031">update_page</a> block, which evaluates
|
168
|
+
to a string when the template is rendered (instead of making an Ajax
|
169
|
+
request first).
|
170
|
+
</p>
|
171
|
+
<p>
|
172
|
+
Examples:
|
173
|
+
</p>
|
174
|
+
<pre>
|
175
|
+
link_to_function "Greeting", "alert('Hello world!')"
|
176
|
+
</pre>
|
177
|
+
<p>
|
178
|
+
Produces:
|
179
|
+
</p>
|
180
|
+
<pre>
|
181
|
+
<a onclick="alert('Hello world!'); return false;" href="#">Greeting</a>
|
182
|
+
|
183
|
+
link_to_function(image_tag("delete"), "if (confirm('Really?')) do_delete()")
|
184
|
+
</pre>
|
185
|
+
<p>
|
186
|
+
Produces:
|
187
|
+
</p>
|
188
|
+
<pre>
|
189
|
+
<a onclick="if (confirm('Really?')) do_delete(); return false;" href="#">
|
190
|
+
<img src="/images/delete.png?" alt="Delete"/>
|
191
|
+
</a>
|
192
|
+
|
193
|
+
link_to_function("Show me more", nil, :id => "more_link") do |page|
|
194
|
+
page[:details].visual_effect :toggle_blind
|
195
|
+
page[:more_link].replace_html "Show me less"
|
196
|
+
end
|
197
|
+
</pre>
|
198
|
+
<p>
|
199
|
+
Produces:
|
200
|
+
</p>
|
201
|
+
<pre>
|
202
|
+
<a href="#" id="more_link" onclick="try {
|
203
|
+
$(&quot;details&quot;).visualEffect(&quot;toggle_blind&quot;);
|
204
|
+
$(&quot;more_link&quot;).update(&quot;Show me less&quot;);
|
205
|
+
}
|
206
|
+
catch (e) {
|
207
|
+
alert('RJS error:\n\n' + e.toString());
|
208
|
+
alert('$(\&quot;details\&quot;).visualEffect(\&quot;toggle_blind\&quot;);
|
209
|
+
\n$(\&quot;more_link\&quot;).update(\&quot;Show me less\&quot;);');
|
210
|
+
throw e
|
211
|
+
};
|
212
|
+
return false;">Show me more</a>
|
213
|
+
</pre>
|
214
|
+
|
215
|
+
<div class="sourcecode">
|
216
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000033_source')" id="l_M000033_source">show source</a> ]</p>
|
217
|
+
<div id="M000033_source" class="dyn-source">
|
218
|
+
<pre>
|
219
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 273</span>
|
220
|
+
273: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_function</span>( <span class="ruby-identifier">name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
221
|
+
274: <span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span> <span class="ruby-operator">:</span> {}
|
222
|
+
275: <span class="ruby-identifier">function</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>
|
223
|
+
276:
|
224
|
+
277: <span class="ruby-identifier">function</span> = <span class="ruby-identifier">update_page</span>( <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> ) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
225
|
+
278:
|
226
|
+
279: <span class="ruby-identifier">a</span>( <span class="ruby-identifier">html_options</span>.<span class="ruby-identifier">merge</span>({
|
227
|
+
280: <span class="ruby-identifier">:href</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">html_options</span>[<span class="ruby-identifier">:href</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">"#"</span>,
|
228
|
+
281: <span class="ruby-identifier">:onclick</span> =<span class="ruby-operator">></span> (<span class="ruby-identifier">html_options</span>[<span class="ruby-identifier">:onclick</span>] <span class="ruby-operator">?</span> <span class="ruby-node">"#{html_options[:onclick]}; "</span> <span class="ruby-operator">:</span> <span class="ruby-value str">""</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"#{function}; return false;"</span>
|
229
|
+
282: }) ) <span class="ruby-keyword kw">do</span>
|
230
|
+
283: <span class="ruby-identifier">name</span>
|
231
|
+
284: <span class="ruby-keyword kw">end</span>
|
232
|
+
285: <span class="ruby-keyword kw">end</span>
|
233
|
+
</pre>
|
234
|
+
</div>
|
235
|
+
</div>
|
236
|
+
<h4 class="ruled">Public Instance method:
|
237
|
+
<strong><a name="M000034">link_to_remote(name, options = {}, html_options = {})</a></strong> <a href="#M000034"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: link_to_remote" /></a></h4>
|
238
|
+
|
239
|
+
<p>
|
240
|
+
Returns a link to a remote action defined by <tt>options[:url]</tt>
|
241
|
+
that‘s called in the background using XMLHttpRequest. The result of
|
242
|
+
that request can then be inserted into a DOM object whose id can be
|
243
|
+
specified with <tt>options[:update]</tt>. Usually, the result would be a
|
244
|
+
partial prepared by the controller.
|
245
|
+
</p>
|
246
|
+
<p>
|
247
|
+
Examples:
|
248
|
+
</p>
|
249
|
+
<pre>
|
250
|
+
link_to_remote "Delete this post", :update => "posts",
|
251
|
+
:url => R(Destroy, 1)
|
252
|
+
link_to_remote(image_tag("refresh"), :update => "emails",
|
253
|
+
:url => R(ListEmails)
|
254
|
+
</pre>
|
255
|
+
<p>
|
256
|
+
You can also specify a hash for <tt>options[:update]</tt> to allow for easy
|
257
|
+
redirection of output to an other DOM element if a server-side error
|
258
|
+
occurs:
|
259
|
+
</p>
|
260
|
+
<p>
|
261
|
+
Example:
|
262
|
+
</p>
|
263
|
+
<pre>
|
264
|
+
link_to_remote "Delete this post",
|
265
|
+
:url => R(Destroy, 1)
|
266
|
+
:update => { :success => "posts", :failure => "error" }
|
267
|
+
</pre>
|
268
|
+
<p>
|
269
|
+
Optionally, you can use the <tt>options[:position]</tt> parameter to
|
270
|
+
influence how the target DOM element is updated. It must be one of
|
271
|
+
<tt>:before</tt>, <tt>:top</tt>, <tt>:bottom</tt>, or <tt>:after</tt>.
|
272
|
+
</p>
|
273
|
+
<p>
|
274
|
+
To access the server response, use <tt>request.responseText</tt>, to find
|
275
|
+
out the HTTP status, use <tt>request.status</tt>.
|
276
|
+
</p>
|
277
|
+
<p>
|
278
|
+
Example:
|
279
|
+
</p>
|
280
|
+
<pre>
|
281
|
+
link_to_remote word,
|
282
|
+
:url => R(Undo, word_counter)
|
283
|
+
:complete => "undoRequestCompleted(request)"
|
284
|
+
</pre>
|
285
|
+
<p>
|
286
|
+
The callbacks that may be specified are (in order):
|
287
|
+
</p>
|
288
|
+
<table>
|
289
|
+
<tr><td valign="top"><tt>:loading</tt>:</td><td>Called when the remote document is being loaded with data by the browser.
|
290
|
+
|
291
|
+
</td></tr>
|
292
|
+
<tr><td valign="top"><tt>:loaded</tt>:</td><td>Called when the browser has finished loading the remote document.
|
293
|
+
|
294
|
+
</td></tr>
|
295
|
+
<tr><td valign="top"><tt>:interactive</tt>:</td><td>Called when the user can interact with the remote document, even though it
|
296
|
+
has not finished loading.
|
297
|
+
|
298
|
+
</td></tr>
|
299
|
+
<tr><td valign="top"><tt>:success</tt>:</td><td>Called when the XMLHttpRequest is completed, and the HTTP status code is in
|
300
|
+
the 2XX range.
|
301
|
+
|
302
|
+
</td></tr>
|
303
|
+
<tr><td valign="top"><tt>:failure</tt>:</td><td>Called when the XMLHttpRequest is completed, and the HTTP status code is
|
304
|
+
not in the 2XX range.
|
305
|
+
|
306
|
+
</td></tr>
|
307
|
+
<tr><td valign="top"><tt>:complete</tt>:</td><td>Called when the XMLHttpRequest is complete (fires after success/failure if
|
308
|
+
they are present).
|
309
|
+
|
310
|
+
</td></tr>
|
311
|
+
</table>
|
312
|
+
<p>
|
313
|
+
You can further refine <tt>:success</tt> and <tt>:failure</tt> by adding
|
314
|
+
additional callbacks for specific status codes.
|
315
|
+
</p>
|
316
|
+
<p>
|
317
|
+
Example:
|
318
|
+
</p>
|
319
|
+
<pre>
|
320
|
+
link_to_remote word,
|
321
|
+
:url => R(Action),
|
322
|
+
404 => "alert('Not found...? Wrong URL...?')",
|
323
|
+
:failure => "alert('HTTP Error ' + request.status + '!')"
|
324
|
+
</pre>
|
325
|
+
<p>
|
326
|
+
A status code callback overrides the success/failure handlers if present.
|
327
|
+
</p>
|
328
|
+
<p>
|
329
|
+
If you for some reason or another need synchronous processing
|
330
|
+
(that‘ll block the browser while the request is happening), you can
|
331
|
+
specify <tt>options[:type] = :synchronous</tt>.
|
332
|
+
</p>
|
333
|
+
<p>
|
334
|
+
You can customize further browser side call logic by passing in JavaScript
|
335
|
+
code snippets via some optional parameters. In their order of use these
|
336
|
+
are:
|
337
|
+
</p>
|
338
|
+
<table>
|
339
|
+
<tr><td valign="top"><tt>:confirm</tt>:</td><td>Adds confirmation dialog.
|
340
|
+
|
341
|
+
</td></tr>
|
342
|
+
<tr><td valign="top"><tt>:condition</tt>:</td><td>Perform remote request conditionally by this expression. Use this to
|
343
|
+
describe browser-side conditions when request should not be initiated.
|
344
|
+
|
345
|
+
</td></tr>
|
346
|
+
<tr><td valign="top"><tt>:before</tt>:</td><td>Called before request is initiated.
|
347
|
+
|
348
|
+
</td></tr>
|
349
|
+
<tr><td valign="top"><tt>:after</tt>:</td><td>Called immediately after request was initiated and before
|
350
|
+
<tt>:loading</tt>.
|
351
|
+
|
352
|
+
</td></tr>
|
353
|
+
<tr><td valign="top"><tt>:submit</tt>:</td><td>Specifies the DOM element ID that‘s used as the parent of the form
|
354
|
+
elements. By default this is the current form, but it could just as well be
|
355
|
+
the ID of a table row or any other DOM element.
|
356
|
+
|
357
|
+
</td></tr>
|
358
|
+
</table>
|
359
|
+
|
360
|
+
<div class="sourcecode">
|
361
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000034_source')" id="l_M000034_source">show source</a> ]</p>
|
362
|
+
<div id="M000034_source" class="dyn-source">
|
363
|
+
<pre>
|
364
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 371</span>
|
365
|
+
371: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_remote</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
|
366
|
+
372: <span class="ruby-identifier">link_to_function</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">remote_function</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">html_options</span>)
|
367
|
+
373: <span class="ruby-keyword kw">end</span>
|
368
|
+
</pre>
|
369
|
+
</div>
|
370
|
+
</div>
|
371
|
+
<h4 class="ruled">Public Instance method:
|
372
|
+
<strong><a name="M000036">observe_field(field_id, options = {})</a></strong> <a href="#M000036"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: observe_field" /></a></h4>
|
373
|
+
|
374
|
+
<p>
|
375
|
+
Observes the field with the DOM ID specified by <tt>field_id</tt> and makes
|
376
|
+
an Ajax call when its contents have changed.
|
377
|
+
</p>
|
378
|
+
<p>
|
379
|
+
Required <tt>options</tt> are either of:
|
380
|
+
</p>
|
381
|
+
<table>
|
382
|
+
<tr><td valign="top"><tt>:url</tt>:</td><td><tt>url_for</tt>-style options for the action to call when the field has
|
383
|
+
changed.
|
384
|
+
|
385
|
+
</td></tr>
|
386
|
+
<tr><td valign="top"><tt>:function</tt>:</td><td>Instead of making a remote call to a URL, you can specify a function to be
|
387
|
+
called instead.
|
388
|
+
|
389
|
+
</td></tr>
|
390
|
+
</table>
|
391
|
+
<p>
|
392
|
+
Additional options are:
|
393
|
+
</p>
|
394
|
+
<table>
|
395
|
+
<tr><td valign="top"><tt>:frequency</tt>:</td><td>The frequency (in seconds) at which changes to this field will be detected.
|
396
|
+
Not setting this option at all or to a value equal to or less than zero
|
397
|
+
will use event based observation instead of time based observation.
|
398
|
+
|
399
|
+
</td></tr>
|
400
|
+
<tr><td valign="top"><tt>:update</tt>:</td><td>Specifies the DOM ID of the element whose innerHTML should be updated with
|
401
|
+
the XMLHttpRequest response text.
|
402
|
+
|
403
|
+
</td></tr>
|
404
|
+
<tr><td valign="top"><tt>:with</tt>:</td><td>A JavaScript expression specifying the parameters for the XMLHttpRequest.
|
405
|
+
This defaults to ‘value’, which in the evaluated context refers
|
406
|
+
to the new field value. If you specify a string without a "=",
|
407
|
+
it‘ll be extended to mean the form key that the value should be
|
408
|
+
assigned to. So :with => "term" gives
|
409
|
+
"’term’=value". If a "=" is present, no
|
410
|
+
extension will happen.
|
411
|
+
|
412
|
+
</td></tr>
|
413
|
+
<tr><td valign="top"><tt>:on</tt>:</td><td>Specifies which event handler to observe. By default, it‘s set to
|
414
|
+
"changed" for text fields and areas and "click" for
|
415
|
+
radio buttons and checkboxes. With this, you can specify it instead to be
|
416
|
+
"blur" or "focus" or any other event.
|
417
|
+
|
418
|
+
</td></tr>
|
419
|
+
</table>
|
420
|
+
<p>
|
421
|
+
Additionally, you may specify any of the options documented in <a
|
422
|
+
href="JavaScriptView.html#M000034">link_to_remote</a>.
|
423
|
+
</p>
|
424
|
+
|
425
|
+
<div class="sourcecode">
|
426
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000036_source')" id="l_M000036_source">show source</a> ]</p>
|
427
|
+
<div id="M000036_source" class="dyn-source">
|
428
|
+
<pre>
|
429
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 420</span>
|
430
|
+
420: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">observe_field</span>(<span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span> = {})
|
431
|
+
421: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">&&</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
432
|
+
422: <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.Element.Observer'</span>, <span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span>)
|
433
|
+
423: <span class="ruby-keyword kw">else</span>
|
434
|
+
424: <span class="ruby-identifier">build_observer</span>(<span class="ruby-value str">'Form.Element.EventObserver'</span>, <span class="ruby-identifier">field_id</span>, <span class="ruby-identifier">options</span>)
|
435
|
+
425: <span class="ruby-keyword kw">end</span>
|
436
|
+
426: <span class="ruby-keyword kw">end</span>
|
437
|
+
</pre>
|
438
|
+
</div>
|
439
|
+
</div>
|
440
|
+
<h4 class="ruled">Public Instance method:
|
441
|
+
<strong><a name="M000035">periodically_call_remote(options = {})</a></strong> <a href="#M000035"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: periodically_call_remote" /></a></h4>
|
442
|
+
|
443
|
+
<p>
|
444
|
+
Periodically calls the specified url (<tt>options[:url]</tt>) every
|
445
|
+
<tt>options[:frequency]</tt> seconds (default is 10). Usually used to
|
446
|
+
update a specified div (<tt>options[:update]</tt>) with the results of the
|
447
|
+
remote call. The options for specifying the target with :url and defining
|
448
|
+
callbacks is the same as <a
|
449
|
+
href="JavaScriptView.html#M000034">link_to_remote</a>.
|
450
|
+
</p>
|
451
|
+
|
452
|
+
<div class="sourcecode">
|
453
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000035_source')" id="l_M000035_source">show source</a> ]</p>
|
454
|
+
<div id="M000035_source" class="dyn-source">
|
455
|
+
<pre>
|
456
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 380</span>
|
457
|
+
380: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">periodically_call_remote</span>(<span class="ruby-identifier">options</span> = {})
|
458
|
+
381: <span class="ruby-identifier">frequency</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:frequency</span>] <span class="ruby-operator">||</span> <span class="ruby-value">10</span> <span class="ruby-comment cmt"># every ten seconds by default</span>
|
459
|
+
382: <span class="ruby-identifier">code</span> = <span class="ruby-node">"new PeriodicalExecuter(function() {#{remote_function(options)}}, #{frequency})"</span>
|
460
|
+
383: <span class="ruby-identifier">javascript_tag</span>(<span class="ruby-identifier">code</span>)
|
461
|
+
384: <span class="ruby-keyword kw">end</span>
|
462
|
+
</pre>
|
463
|
+
</div>
|
464
|
+
</div>
|
465
|
+
<h4 class="ruled">Public Instance method:
|
466
|
+
<strong><a name="M000037">remote_function(options)</a></strong> <a href="#M000037"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: remote_function" /></a></h4>
|
467
|
+
|
468
|
+
<p>
|
469
|
+
Returns the JavaScript needed for a remote function. Takes the same
|
470
|
+
arguments as <a href="JavaScriptView.html#M000034">link_to_remote</a>.
|
471
|
+
</p>
|
472
|
+
<p>
|
473
|
+
Example:
|
474
|
+
</p>
|
475
|
+
<pre>
|
476
|
+
select( :id => "options",
|
477
|
+
:onChange => remote_function(
|
478
|
+
:update => "options",
|
479
|
+
:url => R(Update),
|
480
|
+
:onSuccess => visual_effect( :highlight, 'my_element' )
|
481
|
+
)
|
482
|
+
) do
|
483
|
+
option( "Hello", :value => 0 )
|
484
|
+
option( "World", :value => 1 )
|
485
|
+
end
|
486
|
+
</pre>
|
487
|
+
|
488
|
+
<div class="sourcecode">
|
489
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000037_source')" id="l_M000037_source">show source</a> ]</p>
|
490
|
+
<div id="M000037_source" class="dyn-source">
|
491
|
+
<pre>
|
492
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 442</span>
|
493
|
+
442: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remote_function</span>(<span class="ruby-identifier">options</span>)
|
494
|
+
443: <span class="ruby-identifier">javascript_options</span> = <span class="ruby-identifier">options_for_ajax</span>(<span class="ruby-identifier">options</span>)
|
495
|
+
444:
|
496
|
+
445: <span class="ruby-identifier">update</span> = <span class="ruby-value str">''</span>
|
497
|
+
446: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>] <span class="ruby-operator">&&</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
498
|
+
447: <span class="ruby-identifier">update</span> = []
|
499
|
+
448: <span class="ruby-identifier">update</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"success:'#{options[:update][:success]}'"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>][<span class="ruby-identifier">:success</span>]
|
500
|
+
449: <span class="ruby-identifier">update</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"failure:'#{options[:update][:failure]}'"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>][<span class="ruby-identifier">:failure</span>]
|
501
|
+
450: <span class="ruby-identifier">update</span> = <span class="ruby-value str">'{'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">update</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">','</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'}'</span>
|
502
|
+
451: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:update</span>]
|
503
|
+
452: <span class="ruby-identifier">update</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"'#{options[:update]}'"</span>
|
504
|
+
453: <span class="ruby-keyword kw">end</span>
|
505
|
+
454:
|
506
|
+
455: <span class="ruby-identifier">function</span> = <span class="ruby-identifier">update</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span>
|
507
|
+
456: <span class="ruby-value str">"new Ajax.Request("</span> <span class="ruby-operator">:</span>
|
508
|
+
457: <span class="ruby-node">"new Ajax.Updater(#{update}, "</span>
|
509
|
+
458:
|
510
|
+
459: <span class="ruby-identifier">function</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"'#{options[:url]}'"</span>
|
511
|
+
460: <span class="ruby-identifier">function</span> <span class="ruby-operator"><<</span> <span class="ruby-node">", #{javascript_options})"</span>
|
512
|
+
461:
|
513
|
+
462: <span class="ruby-identifier">function</span> = <span class="ruby-node">"#{options[:before]}; #{function}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:before</span>]
|
514
|
+
463: <span class="ruby-identifier">function</span> = <span class="ruby-node">"#{function}; #{options[:after]}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:after</span>]
|
515
|
+
464: <span class="ruby-identifier">function</span> = <span class="ruby-node">"if (#{options[:condition]}) { #{function}; }"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:condition</span>]
|
516
|
+
465: <span class="ruby-identifier">function</span> = <span class="ruby-node">"if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:confirm</span>]
|
517
|
+
466:
|
518
|
+
467: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">function</span>
|
519
|
+
468: <span class="ruby-keyword kw">end</span>
|
520
|
+
</pre>
|
521
|
+
</div>
|
522
|
+
</div>
|
523
|
+
<h4 class="ruled">Public Instance method:
|
524
|
+
<strong><a name="M000031">update_page( &block )</a></strong> <a href="#M000031"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: update_page" /></a></h4>
|
525
|
+
|
526
|
+
<p>
|
527
|
+
Yields a <a href="../JavaScriptGenerator.html">JavaScriptGenerator</a> and
|
528
|
+
returns the generated JavaScript code. Use this to update multiple elements
|
529
|
+
on a page in an Ajax response. See <a
|
530
|
+
href="../JavaScriptGenerator.html">JavaScriptGenerator</a> for more
|
531
|
+
information.
|
532
|
+
</p>
|
533
|
+
|
534
|
+
<div class="sourcecode">
|
535
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000031_source')" id="l_M000031_source">show source</a> ]</p>
|
536
|
+
<div id="M000031_source" class="dyn-source">
|
537
|
+
<pre>
|
538
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 228</span>
|
539
|
+
228: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_page</span>( <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
540
|
+
229: <span class="ruby-constant">JavaScriptGenerator</span>.<span class="ruby-identifier">new</span>( <span class="ruby-keyword kw">self</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> ).<span class="ruby-identifier">to_s</span>
|
541
|
+
230: <span class="ruby-keyword kw">end</span>
|
542
|
+
</pre>
|
543
|
+
</div>
|
544
|
+
</div>
|
545
|
+
<h4 class="ruled">Public Instance method:
|
546
|
+
<strong><a name="M000032">update_page_tag( options = {}, &block )</a></strong> <a href="#M000032"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: update_page_tag" /></a></h4>
|
547
|
+
|
548
|
+
<p>
|
549
|
+
Works like <a href="JavaScriptView.html#M000031">update_page</a> but wraps
|
550
|
+
the generated JavaScript in a <script> tag. See <a
|
551
|
+
href="../JavaScriptGenerator.html">JavaScriptGenerator</a> for more
|
552
|
+
information.
|
553
|
+
</p>
|
554
|
+
|
555
|
+
<div class="sourcecode">
|
556
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000032_source')" id="l_M000032_source">show source</a> ]</p>
|
557
|
+
<div id="M000032_source" class="dyn-source">
|
558
|
+
<pre>
|
559
|
+
<span class="ruby-comment cmt"># File lib/bivouac/helpers/view/goh/javascript.rb, line 234</span>
|
560
|
+
234: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_page_tag</span>( <span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> )
|
561
|
+
235: <span class="ruby-identifier">javascript_tag</span> <span class="ruby-identifier">update_page</span>( <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> ), <span class="ruby-identifier">options</span>
|
562
|
+
236: <span class="ruby-keyword kw">end</span>
|
563
|
+
</pre>
|
564
|
+
</div>
|
565
|
+
</div>
|
566
|
+
|
567
|
+
</div>
|
568
|
+
</div>
|
569
|
+
|
570
|
+
|
571
|
+
</div>
|
572
|
+
</body>
|
573
|
+
</html>
|