This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.html
928 lines (601 loc) · 35.2 KB
/
layout.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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
<!DOCTYPE html>
<html>
<head>
<title>layout.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="chaplin.html">
chaplin.coffee
</a>
<a class="source" href="application.html">
application.coffee
</a>
<a class="source" href="composer.html">
composer.coffee
</a>
<a class="source" href="controller.html">
controller.coffee
</a>
<a class="source" href="dispatcher.html">
dispatcher.coffee
</a>
<a class="source" href="composition.html">
composition.coffee
</a>
<a class="source" href="event_broker.html">
event_broker.coffee
</a>
<a class="source" href="history.html">
history.coffee
</a>
<a class="source" href="route.html">
route.coffee
</a>
<a class="source" href="router.html">
router.coffee
</a>
<a class="source" href="support.html">
support.coffee
</a>
<a class="source" href="sync_machine.html">
sync_machine.coffee
</a>
<a class="source" href="utils.html">
utils.coffee
</a>
<a class="source" href="mediator.html">
mediator.coffee
</a>
<a class="source" href="collection.html">
collection.coffee
</a>
<a class="source" href="model.html">
model.coffee
</a>
<a class="source" href="collection_view.html">
collection_view.coffee
</a>
<a class="source" href="layout.html">
layout.coffee
</a>
<a class="source" href="view.html">
view.coffee
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>layout.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre><span class="string">'use strict'</span>
_ = <span class="built_in">require</span> <span class="string">'underscore'</span>
Backbone = <span class="built_in">require</span> <span class="string">'backbone'</span>
mediator = <span class="built_in">require</span> <span class="string">'chaplin/mediator'</span>
utils = <span class="built_in">require</span> <span class="string">'chaplin/lib/utils'</span>
EventBroker = <span class="built_in">require</span> <span class="string">'chaplin/lib/event_broker'</span>
View = <span class="built_in">require</span> <span class="string">'chaplin/views/view'</span></pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<p>Shortcut to access the DOM manipulation library.</p>
</div>
<div class="content"><div class='highlight'><pre>$ = Backbone.$
module.<span class="built_in">exports</span> = <span class="class"><span class="keyword">class</span> <span class="title">Layout</span> <span class="keyword">extends</span> <span class="title">View</span></span></pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>Bind to document body by default.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">el</span>: <span class="string">'body'</span></pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>Override default view behavior, we don’t want document.body to be removed.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">keepElement</span>: <span class="literal">true</span></pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>The site title used in the document title.
This should be set in your app-specific Application class
and passed as an option.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">title</span>: <span class="string">''</span></pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<h2 id="regions">Regions</h2>
</div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<p>Collection of registered regions; all view regions are collected here.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">globalRegions</span>: <span class="literal">null</span>
<span class="attribute">listen</span>:
<span class="string">'beforeControllerDispose mediator'</span>: <span class="string">'scroll'</span>
<span class="attribute">constructor</span>: <span class="function"><span class="params">(options = {})</span> -></span>
<span class="property">@globalRegions</span> = []
<span class="property">@title</span> = options.title
<span class="property">@regions</span> = options.regions <span class="keyword">if</span> options.regions
<span class="property">@settings</span> = _.defaults options,
<span class="attribute">titleTemplate</span>: <span class="function"><span class="params">(data)</span> -></span>
st = <span class="keyword">if</span> data.subtitle <span class="keyword">then</span> <span class="string">"<span class="subst">#{data.subtitle}</span> \u2013 "</span> <span class="keyword">else</span> <span class="string">''</span>
st + data.title
<span class="attribute">openExternalToBlank</span>: <span class="literal">false</span>
<span class="attribute">routeLinks</span>: <span class="string">'a, .go-to'</span>
<span class="attribute">skipRouting</span>: <span class="string">'.noscript'</span></pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<p>Per default, jump to the top of the page.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">scrollTo</span>: [<span class="number">0</span>, <span class="number">0</span>]
mediator.setHandler <span class="string">'region:show'</span>, <span class="property">@showRegion</span>, <span class="keyword">this</span>
mediator.setHandler <span class="string">'region:register'</span>, <span class="property">@registerRegionHandler</span>, <span class="keyword">this</span>
mediator.setHandler <span class="string">'region:unregister'</span>, <span class="property">@unregisterRegionHandler</span>, <span class="keyword">this</span>
mediator.setHandler <span class="string">'region:find'</span>, <span class="property">@regionByName</span>, <span class="keyword">this</span>
mediator.setHandler <span class="string">'adjustTitle'</span>, <span class="property">@adjustTitle</span>, <span class="keyword">this</span>
<span class="keyword">super</span></pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">¶</a>
</div>
<p>Set the app link routing.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="property">@startLinkRouting</span>() <span class="keyword">if</span> <span class="property">@settings</span>.routeLinks</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">¶</a>
</div>
<h2 id="controller-startup-and-disposal">Controller startup and disposal</h2>
</div>
</li>
<li id="section-11">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">¶</a>
</div>
<p>Handler for the global beforeControllerDispose event.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">scroll</span>:<span class="function"> -></span></pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">¶</a>
</div>
<p>Reset the scroll position.</p>
</div>
<div class="content"><div class='highlight'><pre> position = <span class="property">@settings</span>.scrollTo
<span class="keyword">if</span> position
window.scrollTo position[<span class="number">0</span>], position[<span class="number">1</span>]</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">¶</a>
</div>
<p>Handler for the global dispatcher:dispatch event.
Change the document title to match the new controller.
Get the title from the title property of the current controller.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">adjustTitle</span>: <span class="function"><span class="params">(subtitle = <span class="string">''</span>)</span> -></span>
title = <span class="property">@settings</span>.titleTemplate {<span class="property">@title</span>, subtitle}</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">¶</a>
</div>
<p>Internet Explorer < 9 workaround.</p>
</div>
<div class="content"><div class='highlight'><pre> setTimeout<span class="function"> =></span>
document.title = title
<span class="property">@publishEvent</span> <span class="string">'adjustTitle'</span>, subtitle, title
, <span class="number">50</span>
title</pre></div></div>
</li>
<li id="section-15">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">¶</a>
</div>
<h2 id="automatic-routing-of-internal-links">Automatic routing of internal links</h2>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">startLinkRouting</span>:<span class="function"> -></span>
route = <span class="property">@settings</span>.routeLinks
<span class="keyword">return</span> <span class="keyword">unless</span> route
<span class="keyword">if</span> $
<span class="property">@$el</span>.<span class="literal">on</span> <span class="string">'click'</span>, route, <span class="property">@openLink</span>
<span class="keyword">else</span>
<span class="property">@delegate</span> <span class="string">'click'</span>, route, <span class="property">@openLink</span>
<span class="attribute">stopLinkRouting</span>:<span class="function"> -></span>
route = <span class="property">@settings</span>.routeLinks
<span class="keyword">if</span> $
<span class="property">@$el</span>.<span class="literal">off</span> <span class="string">'click'</span>, route <span class="keyword">if</span> route
<span class="keyword">else</span>
<span class="property">@undelegate</span> <span class="string">'click'</span>, route, <span class="property">@openLink</span>
<span class="attribute">isExternalLink</span>: <span class="function"><span class="params">(link)</span> -></span>
link.target <span class="keyword">is</span> <span class="string">'_blank'</span> <span class="keyword">or</span>
link.rel <span class="keyword">is</span> <span class="string">'external'</span> <span class="keyword">or</span>
link.protocol <span class="keyword">not</span> <span class="keyword">in</span> [<span class="string">'http:'</span>, <span class="string">'https:'</span>, <span class="string">'file:'</span>] <span class="keyword">or</span>
link.hostname <span class="keyword">not</span> <span class="keyword">in</span> [location.hostname, <span class="string">''</span>]</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">¶</a>
</div>
<p>Handle all clicks on A elements and try to route them internally.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">openLink</span>: <span class="function"><span class="params">(event)</span> =></span>
<span class="keyword">return</span> <span class="keyword">if</span> utils.modifierKeyPressed(event)
el = <span class="keyword">if</span> $ <span class="keyword">then</span> event.currentTarget <span class="keyword">else</span> event.delegateTarget
isAnchor = el.nodeName <span class="keyword">is</span> <span class="string">'A'</span></pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">¶</a>
</div>
<p>Get the href and perform checks on it.</p>
</div>
<div class="content"><div class='highlight'><pre> href = el.getAttribute(<span class="string">'href'</span>) <span class="keyword">or</span> el.getAttribute(<span class="string">'data-href'</span>) <span class="keyword">or</span> <span class="literal">null</span></pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">¶</a>
</div>
<p>Basic href checks.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="keyword">if</span> <span class="keyword">not</span> href? <span class="keyword">or</span></pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">¶</a>
</div>
<p>Technically an empty string is a valid relative URL
but it doesn’t make sense to route it.</p>
</div>
<div class="content"><div class='highlight'><pre> href <span class="keyword">is</span> <span class="string">''</span> <span class="keyword">or</span></pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">¶</a>
</div>
<p>Exclude fragment links.</p>
</div>
<div class="content"><div class='highlight'><pre> href.charAt(<span class="number">0</span>) <span class="keyword">is</span> <span class="string">'#'</span></pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">¶</a>
</div>
<p>Apply skipRouting option.</p>
</div>
<div class="content"><div class='highlight'><pre> skipRouting = <span class="property">@settings</span>.skipRouting
type = <span class="keyword">typeof</span> skipRouting
<span class="keyword">return</span> <span class="keyword">if</span> type <span class="keyword">is</span> <span class="string">'function'</span> <span class="keyword">and</span> <span class="keyword">not</span> skipRouting(href, el) <span class="keyword">or</span>
type <span class="keyword">is</span> <span class="string">'string'</span> <span class="keyword">and</span> (<span class="keyword">if</span> $ <span class="keyword">then</span> $(el).<span class="keyword">is</span>(skipRouting) <span class="keyword">else</span> Backbone.utils.matchesSelector el, skipRouting)</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">¶</a>
</div>
<p>Handle external links.</p>
</div>
<div class="content"><div class='highlight'><pre> external = isAnchor <span class="keyword">and</span> <span class="property">@isExternalLink</span> el
<span class="keyword">if</span> external
<span class="keyword">if</span> <span class="property">@settings</span>.openExternalToBlank</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">¶</a>
</div>
<p>Open external links normally in a new tab.</p>
</div>
<div class="content"><div class='highlight'><pre> event.preventDefault()
window.open href
<span class="keyword">return</span></pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">¶</a>
</div>
<p>Pass to the router, try to route the path internally.</p>
</div>
<div class="content"><div class='highlight'><pre> utils.redirectTo <span class="attribute">url</span>: href</pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">¶</a>
</div>
<p>Prevent default handling if the URL could be routed.</p>
</div>
<div class="content"><div class='highlight'><pre> event.preventDefault()
<span class="keyword">return</span></pre></div></div>
</li>
<li id="section-27">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">¶</a>
</div>
<h2 id="region-management">Region management</h2>
</div>
</li>
<li id="section-28">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-28">¶</a>
</div>
<p>Handler for <code>!region:register</code>.
Register a single view region or all regions exposed.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">registerRegionHandler</span>: <span class="function"><span class="params">(instance, name, selector)</span> -></span>
<span class="keyword">if</span> name?
<span class="property">@registerGlobalRegion</span> instance, name, selector
<span class="keyword">else</span>
<span class="property">@registerGlobalRegions</span> instance</pre></div></div>
</li>
<li id="section-29">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">¶</a>
</div>
<p>Registering one region bound to a view.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">registerGlobalRegion</span>: <span class="function"><span class="params">(instance, name, selector)</span> -></span></pre></div></div>
</li>
<li id="section-30">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-30">¶</a>
</div>
<p>Remove the region if there was already one registered perhaps by
a base class.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="property">@unregisterGlobalRegion</span> instance, name</pre></div></div>
</li>
<li id="section-31">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-31">¶</a>
</div>
<p>Place this region registration into the regions array.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="property">@globalRegions</span>.unshift {instance, name, selector}</pre></div></div>
</li>
<li id="section-32">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-32">¶</a>
</div>
<p>Triggered by view; passed in the regions hash.
Simply register all regions exposed by it.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">registerGlobalRegions</span>: <span class="function"><span class="params">(instance)</span> -></span></pre></div></div>
</li>
<li id="section-33">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-33">¶</a>
</div>
<p>Regions can be be extended by subclasses, so we need to check the
whole prototype chain for matching regions. Regions registered by the
more-derived class overwrites the region registered by the less-derived
class.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">for</span> version <span class="keyword">in</span> utils.getAllPropertyVersions instance, <span class="string">'regions'</span>
<span class="keyword">for</span> name, selector <span class="keyword">of</span> version
<span class="property">@registerGlobalRegion</span> instance, name, selector</pre></div></div>
</li>
<li id="section-34">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-34">¶</a>
</div>
<p>Return nothing.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">return</span></pre></div></div>
</li>
<li id="section-35">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-35">¶</a>
</div>
<p>Handler for <code>!region:unregister</code>.
Unregisters single named region or all view regions.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">unregisterRegionHandler</span>: <span class="function"><span class="params">(instance, name)</span> -></span>
<span class="keyword">if</span> name?
<span class="property">@unregisterGlobalRegion</span> instance, name
<span class="keyword">else</span>
<span class="property">@unregisterGlobalRegions</span> instance</pre></div></div>
</li>
<li id="section-36">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-36">¶</a>
</div>
<p>Unregisters a specific named region from a view.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">unregisterGlobalRegion</span>: <span class="function"><span class="params">(instance, name)</span> -></span>
cid = instance.cid
<span class="property">@globalRegions</span> = (region <span class="keyword">for</span> region <span class="keyword">in</span> <span class="property">@globalRegions</span> <span class="keyword">when</span> (
region.instance.cid <span class="keyword">isnt</span> cid <span class="keyword">or</span> region.name <span class="keyword">isnt</span> name
))</pre></div></div>
</li>
<li id="section-37">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-37">¶</a>
</div>
<p>When views are disposed; remove all their registered regions.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">unregisterGlobalRegions</span>: <span class="function"><span class="params">(instance)</span> -></span>
<span class="property">@globalRegions</span> = (region <span class="keyword">for</span> region <span class="keyword">in</span> <span class="property">@globalRegions</span> <span class="keyword">when</span> (
region.instance.cid <span class="keyword">isnt</span> instance.cid
))</pre></div></div>
</li>
<li id="section-38">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-38">¶</a>
</div>
<p>Returns the region by its name, if found.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">regionByName</span>: <span class="function"><span class="params">(name)</span> -></span>
<span class="keyword">for</span> reg <span class="keyword">in</span> <span class="property">@globalRegions</span> <span class="keyword">when</span> reg.name <span class="keyword">is</span> name <span class="keyword">and</span> <span class="keyword">not</span> reg.instance.stale
<span class="keyword">return</span> reg</pre></div></div>
</li>
<li id="section-39">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-39">¶</a>
</div>
<p>When views are instantiated and request for a region assignment;
attempt to fulfill it.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">showRegion</span>: <span class="function"><span class="params">(name, instance)</span> -></span></pre></div></div>
</li>
<li id="section-40">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-40">¶</a>
</div>
<p>Find an appropriate region.</p>
</div>
<div class="content"><div class='highlight'><pre> region = <span class="property">@regionByName</span> name</pre></div></div>
</li>
<li id="section-41">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-41">¶</a>
</div>
<p>Assert that we got a valid region.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">throw</span> <span class="keyword">new</span> Error <span class="string">"No region registered under <span class="subst">#{name}</span>"</span> <span class="keyword">unless</span> region</pre></div></div>
</li>
<li id="section-42">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-42">¶</a>
</div>
<p>Apply the region selector.</p>
</div>
<div class="content"><div class='highlight'><pre> instance.container = <span class="keyword">if</span> region.selector <span class="keyword">is</span> <span class="string">''</span>
<span class="keyword">if</span> $
region.instance.$el
<span class="keyword">else</span>
region.instance.el
<span class="keyword">else</span>
<span class="keyword">if</span> region.instance.noWrap
<span class="keyword">if</span> $
$(region.instance.container).find region.selector
<span class="keyword">else</span>
region.instance.container.querySelector region.selector
<span class="keyword">else</span>
region.instance[<span class="keyword">if</span> $ <span class="keyword">then</span> <span class="string">'$'</span> <span class="keyword">else</span> <span class="string">'find'</span>] region.selector</pre></div></div>
</li>
<li id="section-43">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-43">¶</a>
</div>
<h2 id="disposal">Disposal</h2>
</div>
</li>
<li id="section-44">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-44">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre> <span class="attribute">dispose</span>:<span class="function"> -></span>
<span class="keyword">return</span> <span class="keyword">if</span> <span class="property">@disposed</span></pre></div></div>
</li>
<li id="section-45">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-45">¶</a>
</div>
<p>Stop routing links.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="property">@stopLinkRouting</span>()</pre></div></div>
</li>
<li id="section-46">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-46">¶</a>
</div>
<p>Remove all regions and document title setting.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="keyword">delete</span> <span class="keyword">this</span>[prop] <span class="keyword">for</span> prop <span class="keyword">in</span> [<span class="string">'globalRegions'</span>, <span class="string">'title'</span>, <span class="string">'route'</span>]
mediator.removeHandlers <span class="keyword">this</span>
<span class="keyword">super</span></pre></div></div>
</li>
</ul>
</div>
</body>
</html>