-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjslibrary.html
675 lines (614 loc) · 39.5 KB
/
jslibrary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://ogp.me/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Clutch.io - JavaScript Library Reference - Documentation</title>
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/main.js"></script>
<script type="text/javascript" src="_static/bootstrap-modal.js"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="top" title="Clutch 1.0 documentation" href="index.html" />
<link rel="up" title="Reference" href="reference.html" />
<link rel="next" title="iOS Library Reference" href="ioslibrary.html" />
<link rel="prev" title="Reference" href="reference.html" />
</head>
<body id="docs" class="secondary ">
<div id="header">
<div class="content">
<div class="ribbon"></div>
<h1 class="logo"><a href="/">Clutch.io</a></h1>
</div>
</div>
<div class="edge"></div>
<div class="document">
<div class="documentwrapper section-wrap">
<div class="relbar">
<div class="breadcrumbs">
<a href="index.html" class="main-link">Clutch 1.0 documentation</a> »
<a href="framework.html" >Clutch Framework</a> »
<a href="reference.html" accesskey="U">Reference</a> »
JavaScript Library Reference
</div>
<div class="rellinks">
<a href="index.html" class="left">home</a>
<a href="genindex.html" class="right" title="General Index" accesskey="I">index</a>
<a href="ioslibrary.html" class="right" title="iOS Library Reference" accesskey="N">next</a>
<a href="reference.html" class="right" title="Reference" accesskey="P">previous</a>
</div>
<div class="clear"></div>
</div>
<div class="bodywrapper content">
<div class="body main-sec">
<div class="section" id="javascript-library-reference">
<h1>JavaScript Library Reference<a class="headerlink" href="#javascript-library-reference" title="Permalink to this headline">¶</a></h1>
<p>Applications using Clutch are made using a combination of native code and
HTML/CSS/JavaScript. The Clutch JavaScript library is designed to create
content areas for your application using web technology that both looks and
feels native.</p>
<p>To achieve this kind of performance and flexibility, we’ve built the core of
the library on top of the best mobile JavaScript code we could find:
<a class="reference external" href="http://zeptojs.com/">Zepto</a>, <a class="reference external" href="http://documentcloud.github.com/backbone/">Backbone</a>, and <a class="reference external" href="http://documentcloud.github.com/underscore/">Underscore</a>.</p>
<div class="section" id="core">
<h2>Core<a class="headerlink" href="#core" title="Permalink to this headline">¶</a></h2>
<p>The first thing that Clutch does when it loads is set up some bookkeeping and
set up a communication channel between your native code and your JavaScript
code. Once that’s all finished, it calls the function you attach using
<tt class="docutils literal"><span class="pre">Clutch.Core.init</span></tt>.</p>
<dl class="function">
<dt id="Clutch.Core.init">
<tt class="descclassname">Clutch.Core.</tt><tt class="descname">init</tt><big>(</big><em>func</em><big>)</big><a class="headerlink" href="#Clutch.Core.init" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>func</strong> – The function to run once Clutch is initialized.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<p>Keep in mind you should not start your rendering until after this function has
been called. Here’s an example of how that could look in your code:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">alert</span><span class="p">(</span><span class="s1">'Hello from Clutch!'</span><span class="p">);</span>
<span class="p">});</span>
</pre></div>
</div>
<p>Once that is set up, you can go ahead and use any of Clutch’s resources–the
communication channel, the UI helpers, and more.</p>
<p>But the real core of Clutch is really just the communication channel between
the JavaScript that you write and the iOS code that you write.</p>
<dl class="function">
<dt id="Clutch.Core.callMethod">
<tt class="descclassname">Clutch.Core.</tt><tt class="descname">callMethod</tt><big>(</big><em>methodName</em><span class="optional">[</span>, <em>params</em>, <em>callback</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.Core.callMethod" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
<li><strong>methodName</strong> (<em>string</em>) – The name of the Objective-C method you want to call.</li>
<li><strong>params</strong> – An optional mapping of parameters to pass to the method.</li>
<li><strong>callback</strong> – An optional callback that will be called with the object passed into
the callback block in Objective-C.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Nothing</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<p>As you can see, it’s simple and straightforward. As an example, if a user
taps on a button and you want something to happen, you might write something
like this:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">callMethod</span><span class="p">(</span><span class="s1">'userTapped'</span><span class="p">,</span> <span class="p">{</span><span class="nx">userId</span><span class="o">:</span> <span class="mi">10</span><span class="p">});</span>
</pre></div>
</div>
<p>In this example, we’re calling the <tt class="docutils literal"><span class="pre">userTapped</span></tt> method in your iOS code, and
passing an NSDictionary whose key <tt class="docutils literal"><span class="pre">userId</span></tt> is set to <tt class="docutils literal"><span class="pre">10</span></tt>. You can also
pass a callback function, which might look something like this:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">callMethod</span><span class="p">(</span><span class="s1">'getUsername'</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">alert</span><span class="p">(</span><span class="s1">'Hello, '</span> <span class="o">+</span> <span class="nx">data</span><span class="p">.</span><span class="nx">username</span><span class="p">);</span>
<span class="p">});</span>
</pre></div>
</div>
<p>To register a function on the JavaScript side that iOS can call, Clutch
provides a <tt class="docutils literal"><span class="pre">registerMethod</span></tt> function.</p>
<dl class="function">
<dt id="Clutch.Core.registerMethod">
<tt class="descclassname">Clutch.Core.</tt><tt class="descname">registerMethod</tt><big>(</big><em>methodName</em>, <em>func</em><big>)</big><a class="headerlink" href="#Clutch.Core.registerMethod" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>methodName</strong> (<em>string</em>) – The name of the JavaScript method that you are exposing.</li>
<li><strong>func</strong> – The actual JavaScript function to be exposed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The function that you expose will always receive a single argument: an
object of parameters passed from iOS.</p>
</div>
<p>Here’s how it might look if you were to expose an <tt class="docutils literal"><span class="pre">alertUser</span></tt> function which
pops open an alert dialog with the given alert text:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">alertUser</span><span class="p">(</span><span class="nx">params</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">alert</span><span class="p">(</span><span class="nx">params</span><span class="p">.</span><span class="nx">alertText</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">registerMethod</span><span class="p">(</span><span class="s1">'alertUser'</span><span class="p">,</span> <span class="nx">alertUser</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="loading">
<h2>Loading<a class="headerlink" href="#loading" title="Permalink to this headline">¶</a></h2>
<p>One thing we need to do all the time in building iOS apps is to wait for some
data. Whenever we do that, we need to somehow indicate to the user that
there’s something loading. Clutch provides an easy mechanism for showing and
hiding loading screens.</p>
<dl class="function">
<dt id="Clutch.Load.begin">
<tt class="descclassname">Clutch.Load.</tt><tt class="descname">begin</tt><big>(</big><span class="optional">[</span><em>loadingText</em><span class="optional">]</span><span class="optional">[</span>, <em>top</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.Load.begin" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>loadingText</strong> (<em>string</em>) – Optional text to show to the user inside of the loading dialog.</li>
<li><strong>top</strong> (<em>float</em>) – Optional offset from the top of the ClutchView, in pixels.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Pops up the loading dialog with optional loading text.</p>
</dd></dl>
<dl class="function">
<dt id="Clutch.Load.end">
<tt class="descclassname">Clutch.Load.</tt><tt class="descname">end</tt><big>(</big><big>)</big><a class="headerlink" href="#Clutch.Load.end" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes the loading dialog.</p>
</dd></dl>
</div>
<div class="section" id="ui">
<h2>UI<a class="headerlink" href="#ui" title="Permalink to this headline">¶</a></h2>
<p>Clutch helps you present a UI to your users that looks and feels like it’s
native. Here’s what’s provided:</p>
<dl class="function">
<dt id="Clutch.UI.View">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">View</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.View" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>This view is the core of all of the Clutch-provided UI constructs. It’s
actually a subclass of <a class="reference external" href="http://documentcloud.github.com/backbone/#View">Backbone.View</a>, with a few added extras. Here are
the added properties and functions:</p>
<dl class="attribute">
<dt id="template">
<tt class="descname">template</tt><a class="headerlink" href="#template" title="Permalink to this definition">¶</a></dt>
<dd><p>The default template provided for all Clutch.UI.View subclasses is
a simple <a class="reference external" href="http://documentcloud.github.com/underscore/#template">underscore template</a> that looks like <tt class="docutils literal"><span class="pre"><%=</span> <span class="pre">c.value</span> <span class="pre">%></span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="render">
<tt class="descname">render</tt><big>(</big><big>)</big><a class="headerlink" href="#render" title="Permalink to this definition">¶</a></dt>
<dd><p>The default render for all Clutch.UI.View subclasses renders the
template but passes the view options as the <tt class="docutils literal"><span class="pre">c</span></tt> varible. It’s
equivalent to this implementation:</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">template</span><span class="p">({</span><span class="nx">c</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">}));</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.Table">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">Table</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.Table" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>This view creates a user interface that looks and acts like Cocoa’s
<tt class="docutils literal"><span class="pre">UITableView</span></tt>.</p>
<p>You must extend this view to populate it with any data, and here are the
parameters you can provide in your extension:</p>
<p><strong>Required</strong></p>
<dl class="attribute">
<dt id="numSections">
<tt class="descname">numSections</tt><a class="headerlink" href="#numSections" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of table sections that should be displayed.</p>
</dd></dl>
<dl class="function">
<dt id="numCells">
<tt class="descname">numCells</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#numCells" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>section</strong> – The 0-indexed integer of the current section.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Determines the number of cells to be rendered for the given section.</p>
</dd></dl>
<dl class="function">
<dt id="cell">
<tt class="descname">cell</tt><big>(</big><em>section</em>, <em>row</em><big>)</big><a class="headerlink" href="#cell" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>section</strong> – The 0-indexed integer of the current section.</li>
<li><strong>row</strong> – The 0-indexed integer of the current row.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Returns the <tt class="docutils literal"><span class="pre">Clutch.UI.TableCell</span></tt> subclass that should render the
requested table cell.</p>
</dd></dl>
<p><strong>Optional</strong></p>
<dl class="attribute">
<dt id="style">
<tt class="descname">style</tt><a class="headerlink" href="#style" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines the visual style of the table. Currently only supports
<tt class="docutils literal"><span class="pre">'normal'</span></tt> and <tt class="docutils literal"><span class="pre">'grouped'</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="tableHeader">
<tt class="descname">tableHeader</tt><big>(</big><big>)</big><a class="headerlink" href="#tableHeader" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <tt class="docutils literal"><span class="pre">Clutch.UI.TableHeader</span></tt> subclass that should render into
the table’s header area.</p>
</dd></dl>
<dl class="function">
<dt id="tableFooter">
<tt class="descname">tableFooter</tt><big>(</big><big>)</big><a class="headerlink" href="#tableFooter" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns tje <tt class="docutils literal"><span class="pre">Clutch.UI.TableFooter</span></tt> subclass that should render into
the table’s footer area.</p>
</dd></dl>
<dl class="function">
<dt id="sectionHeader">
<tt class="descname">sectionHeader</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#sectionHeader" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>section</strong> – The 0-indexed integer of the current section.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Returns a <tt class="docutils literal"><span class="pre">Clutch.UI.SectionHeader</span></tt> subclass that should render into
the given table section’s header area.</p>
</dd></dl>
<dl class="function">
<dt id="sectionFooter">
<tt class="descname">sectionFooter</tt><big>(</big><em>section</em><big>)</big><a class="headerlink" href="#sectionFooter" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>section</strong> – The 0-indexed integer of the current section.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Returns a <tt class="docutils literal"><span class="pre">Clutch.UI.SectionHeader</span></tt> subclass that should render into
the given table section’s footer area.</p>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.TableHeader">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">TableHeader</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.TableHeader" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>A <tt class="docutils literal"><span class="pre">Clutch.UI.View</span></tt> subclass for rendering table headers.</p>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.TableFooter">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">TableFooter</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.TableFooter" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>A <tt class="docutils literal"><span class="pre">Clutch.UI.View</span></tt> subclass for rendering table footers.</p>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.SectionHeader">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">SectionHeader</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.SectionHeader" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>A <tt class="docutils literal"><span class="pre">Clutch.UI.View</span></tt> subclass for rendering table section headers.</p>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.SectionFooter">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">SectionFooter</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.SectionFooter" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>A <tt class="docutils literal"><span class="pre">Clutch.UI.View</span></tt> subclass for rendering table section footers.</p>
</dd></dl>
<dl class="function">
<dt id="Clutch.UI.TableCell">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">TableCell</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#Clutch.UI.TableCell" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>options</strong> – A mapping of options to be provided to the view instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>In that <tt class="docutils literal"><span class="pre">options</span></tt> object, here are the expected and optional parameters:</p>
<p><strong>Required</strong></p>
<dl class="attribute">
<dt id="value">
<tt class="descname">value</tt><a class="headerlink" href="#value" title="Permalink to this definition">¶</a></dt>
<dd><p>The value that should be displayed in the cell.</p>
</dd></dl>
<p><strong>Optional</strong></p>
<dl class="attribute">
<dt id="accessory">
<tt class="descname">accessory</tt><a class="headerlink" href="#accessory" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines which accessory to display for the cell. Should be one of
<tt class="docutils literal"><span class="pre">Clutch.UI.Accessories</span></tt>.</p>
</dd></dl>
<dl class="function">
<dt id="tap">
<tt class="descname">tap</tt><big>(</big><em>e</em><big>)</big><a class="headerlink" href="#tap" title="Permalink to this definition">¶</a></dt>
<dd><p>An optional function which will receive an event whenever this table
cell is tapped by the end user.</p>
</dd></dl>
</dd></dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If you subclass <tt class="docutils literal"><span class="pre">Clutch.UI.TableCell</span></tt>, then you can set the <tt class="docutils literal"><span class="pre">multiline</span></tt>
attribute to <tt class="docutils literal"><span class="pre">true</span></tt> and it will be able to display more than one line
of content.</p>
<div class="last highlight-javascript"><div class="highlight"><pre><span class="kd">var</span> <span class="nx">MultiLineCell</span> <span class="o">=</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">TableCell</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
<span class="nx">multiline</span><span class="o">:</span> <span class="kc">true</span>
<span class="p">});</span>
</pre></div>
</div>
</div>
<dl class="attribute">
<dt id="Clutch.UI.Accessories">
<tt class="descclassname">Clutch.UI.</tt><tt class="descname">Accessories</tt><a class="headerlink" href="#Clutch.UI.Accessories" title="Permalink to this definition">¶</a></dt>
<dd><p>Accessories that can be used to decorate a table cell.</p>
<dl class="attribute">
<dt id="Checkmark">
<tt class="descname">Checkmark</tt><a class="headerlink" href="#Checkmark" title="Permalink to this definition">¶</a></dt>
<dd><p>Shows a check mark.</p>
</dd></dl>
<dl class="attribute">
<dt id="DisclosureButton">
<tt class="descname">DisclosureButton</tt><a class="headerlink" href="#DisclosureButton" title="Permalink to this definition">¶</a></dt>
<dd><p>Shows a button with a right-facing triangle indicating that there is
more content.</p>
</dd></dl>
<dl class="attribute">
<dt id="DisclosureIndicator">
<tt class="descname">DisclosureIndicator</tt><a class="headerlink" href="#DisclosureIndicator" title="Permalink to this definition">¶</a></dt>
<dd><p>Shows a right-facing triangle indicating that there is more content.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>Here’s an example of how you could use this JavaScript library to create a
table which has some cells and a few headers.</p>
<div class="highlight-javascript"><div class="highlight"><pre><span class="c1">// Let's create a simple table by subclassing Clutch.UI.Table</span>
<span class="kd">var</span> <span class="nx">SimpleTable</span> <span class="o">=</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">Table</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
<span class="c1">// Our table should have two sections</span>
<span class="nx">numSections</span><span class="o">:</span> <span class="mi">2</span><span class="p">,</span>
<span class="c1">// We want it to display in the "grouped" style which looks cooler</span>
<span class="nx">style</span><span class="o">:</span> <span class="s1">'grouped'</span><span class="p">,</span>
<span class="nx">numCells</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">section</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Each section has 4 cells</span>
<span class="k">return</span> <span class="mi">4</span><span class="p">;</span>
<span class="p">},</span>
<span class="nx">sectionHeader</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">section</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// The section header just displays its own index</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">TableSectionHeader</span><span class="p">(</span>
<span class="p">{</span><span class="nx">value</span><span class="o">:</span> <span class="s1">'Section '</span> <span class="o">+</span> <span class="nx">section</span> <span class="o">+</span> <span class="s1">' Header'</span><span class="p">}</span>
<span class="p">);</span>
<span class="p">},</span>
<span class="nx">sectionFooter</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">section</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// The first section doesn't have a footer</span>
<span class="k">if</span><span class="p">(</span><span class="nx">section</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// The second section does have a footer though</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">TableSectionFooter</span><span class="p">(</span>
<span class="p">{</span><span class="nx">value</span><span class="o">:</span> <span class="s1">'Section '</span> <span class="o">+</span> <span class="nx">section</span> <span class="o">+</span> <span class="s1">' Footer'</span><span class="p">}</span>
<span class="p">);</span>
<span class="p">},</span>
<span class="nx">cell</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">section</span><span class="p">,</span> <span class="nx">row</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="s1">'Section '</span> <span class="o">+</span> <span class="nx">section</span> <span class="o">+</span> <span class="s1">' Cell '</span> <span class="o">+</span> <span class="nx">row</span><span class="p">;</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">TableCell</span><span class="p">({</span>
<span class="nx">value</span><span class="o">:</span> <span class="nx">value</span><span class="p">,</span>
<span class="nx">accessory</span><span class="o">:</span> <span class="nx">Clutch</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">Accessories</span><span class="p">.</span><span class="nx">DisclosureButton</span><span class="p">,</span>
<span class="nx">tap</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Call the "tapped" method on iOS, and pass</span>
<span class="c1">// the text value of the cell as an argument.</span>
<span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">callMethod</span><span class="p">(</span><span class="s1">'tapped'</span><span class="p">,</span> <span class="p">{</span><span class="nx">value</span><span class="o">:</span> <span class="nx">value</span><span class="p">});</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="c1">// Remember to wait for this event before rendering out our table.</span>
<span class="nx">Clutch</span><span class="p">.</span><span class="nx">Core</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="c1">// Instantiate our new table</span>
<span class="kd">var</span> <span class="nx">table</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SimpleTable</span><span class="p">();</span>
<span class="c1">// Render the table</span>
<span class="nx">$</span><span class="p">(</span><span class="s1">'body'</span><span class="p">).</span><span class="nx">append</span><span class="p">(</span><span class="nx">table</span><span class="p">.</span><span class="nx">render</span><span class="p">().</span><span class="nx">el</span><span class="p">);</span>
<span class="p">});</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar secondary-sec">
<div class="sphinxsidebarwrapper">
<h3 class="contents">Contents</h3>
<div class="pad">
<ul>
<li><a class="reference internal" href="#">JavaScript Library Reference</a><ul>
<li><a class="reference internal" href="#core">Core</a></li>
<li><a class="reference internal" href="#loading">Loading</a></li>
<li><a class="reference internal" href="#ui">UI</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>
</div>
<h4>Previous topic</h4>
<p class="topless pad">
<a href="reference.html" title="previous chapter">Reference</a>
</p>
<h4>Next topic</h4>
<p class="topless pad">
<a href="ioslibrary.html" title="next chapter">iOS Library Reference</a>
</p>
<h3>This Page</h3>
<ul class="this-page-menu pad">
<li>
<a href="_sources/jslibrary.txt" rel="nofollow">Show Source</a>
</li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<div class="pad">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" class="btn gray small" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip">
Enter search terms or a module, class or function name.
</p>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div id="footer">
<div class="content">
<div class="left">
<ul>
<li><a href="/">Home</a></li>
<li class="#"><a href="http://blog.clutch.io">Blog</a></li>
</ul>
<br class="cl">
<a href="https://twitter.com/clutchio" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @clutchio</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="right">
<p class="copyright">Copyright © 2011-2012 Boilerplate Inc. San Francisco, CA.
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</p>
</div>
</div>
</div>
<!-- begin olark code --><script type='text/javascript'>/*{literal}<![CDATA[*/window.olark||(function(i){var e=window,h=document,a=e.location.protocol=="https:"?"https:":"http:",g=i.name,b="load";(function(){e[g]=function(){(c.s=c.s||[]).push(arguments)};var c=e[g]._={},f=i.methods.length; while(f--){(function(j){e[g][j]=function(){e[g]("call",j,arguments)}})(i.methods[f])} c.l=i.loader;c.i=arguments.callee;c.f=setTimeout(function(){if(c.f){(new Image).src=a+"//"+c.l.replace(".js",".png")+"&"+escape(e.location.href)}c.f=null},20000);c.p={0:+new Date};c.P=function(j){c.p[j]=new Date-c.p[0]};function d(){c.P(b);e[g](b)}e.addEventListener?e.addEventListener(b,d,false):e.attachEvent("on"+b,d); (function(){function l(j){j="head";return["<",j,"></",j,"><",z,' onl'+'oad="var d=',B,";d.getElementsByTagName('head')[0].",y,"(d.",A,"('script')).",u,"='",a,"//",c.l,"'",'"',"></",z,">"].join("")}var z="body",s=h[z];if(!s){return setTimeout(arguments.callee,100)}c.P(1);var y="appendChild",A="createElement",u="src",r=h[A]("div"),G=r[y](h[A](g)),D=h[A]("iframe"),B="document",C="domain",q;r.style.display="none";s.insertBefore(r,s.firstChild).id=g;D.frameBorder="0";D.id=g+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){D.src="javascript:false"} D.allowTransparency="true";G[y](D);try{D.contentWindow[B].open()}catch(F){i[C]=h[C];q="javascript:var d="+B+".open();d.domain='"+h.domain+"';";D[u]=q+"void(0);"}try{var H=D.contentWindow[B];H.write(l());H.close()}catch(E){D[u]=q+'d.write("'+l().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}c.P(2)})()})()})({loader:(function(a){return "static.olark.com/jsclient/loader0.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]});
/* custom configuration goes here (www.olark.com/documentation) */
olark.configure('system.domain', '.clutch.io');
olark.identify('8940-141-10-1241');/*]]>{/literal}*/</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29049023-2']);
_gaq.push(['_setDomainName', 'clutch.io']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>