-
Notifications
You must be signed in to change notification settings - Fork 6
/
views.js
4616 lines (3588 loc) · 126 KB
/
views.js
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// This file is automatically generated. any changes will be lost
//
require("window");
var jQuery, $; jQuery = $ = require("jquery");
require("./runtime");
Ember.imports.jQuery = Ember.imports.jQuery || jQuery;
(function() {
/**
@module ember
@submodule ember-views
*/
var jQuery = Ember.imports.jQuery;
Ember.assert("Ember Views require jQuery 1.7 or 1.8", jQuery && (jQuery().jquery.match(/^1\.(7(?!$)(?!\.[01])|8)(\.\d+)?(pre|rc\d?)?/) || Ember.ENV.FORCE_JQUERY));
/**
Alias for jQuery
@method $
@for Ember
*/
Ember.$ = jQuery;
})();
(function() {
/**
@module ember
@submodule ember-views
*/
// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dndevents
var dragEvents = Ember.String.w('dragstart drag dragenter dragleave dragover drop dragend');
// Copies the `dataTransfer` property from a browser event object onto the
// jQuery event object for the specified events
Ember.EnumerableUtils.forEach(dragEvents, function(eventName) {
Ember.$.event.fixHooks[eventName] = { props: ['dataTransfer'] };
});
})();
(function() {
/**
@module ember
@submodule ember-views
*/
var get = Ember.get, set = Ember.set;
var indexOf = Ember.ArrayPolyfills.indexOf;
var ClassSet = function() {
this.seen = {};
this.list = [];
};
ClassSet.prototype = {
add: function(string) {
if (string in this.seen) { return; }
this.seen[string] = true;
this.list.push(string);
},
toDOM: function() {
return this.list.join(" ");
}
};
/**
Ember.RenderBuffer gathers information regarding the a view and generates the
final representation. Ember.RenderBuffer will generate HTML which can be pushed
to the DOM.
@class RenderBuffer
@namespace Ember
@constructor
*/
Ember.RenderBuffer = function(tagName) {
return new Ember._RenderBuffer(tagName);
};
Ember._RenderBuffer = function(tagName) {
this.elementTag = tagName;
this.childBuffers = [];
};
Ember._RenderBuffer.prototype =
/** @scope Ember.RenderBuffer.prototype */ {
/**
Array of class-names which will be applied in the class="" attribute
You should not maintain this array yourself, rather, you should use
the addClass() method of Ember.RenderBuffer.
@property elementClasses
@type Array
@default []
*/
elementClasses: null,
/**
The id in of the element, to be applied in the id="" attribute
You should not set this property yourself, rather, you should use
the id() method of Ember.RenderBuffer.
@property elementId
@type String
@default null
*/
elementId: null,
/**
A hash keyed on the name of the attribute and whose value will be
applied to that attribute. For example, if you wanted to apply a
data-view="Foo.bar" property to an element, you would set the
elementAttributes hash to {'data-view':'Foo.bar'}
You should not maintain this hash yourself, rather, you should use
the attr() method of Ember.RenderBuffer.
@property elementAttributes
@type Hash
@default {}
*/
elementAttributes: null,
/**
The tagname of the element an instance of Ember.RenderBuffer represents.
Usually, this gets set as the first parameter to Ember.RenderBuffer. For
example, if you wanted to create a `p` tag, then you would call
Ember.RenderBuffer('p')
@property elementTag
@type String
@default null
*/
elementTag: null,
/**
A hash keyed on the name of the style attribute and whose value will
be applied to that attribute. For example, if you wanted to apply a
background-color:black;" style to an element, you would set the
elementStyle hash to {'background-color':'black'}
You should not maintain this hash yourself, rather, you should use
the style() method of Ember.RenderBuffer.
@property elementStyle
@type Hash
@default {}
*/
elementStyle: null,
/**
Nested RenderBuffers will set this to their parent RenderBuffer
instance.
@property parentBuffer
@type Ember._RenderBuffer
*/
parentBuffer: null,
/**
Adds a string of HTML to the RenderBuffer.
@method push
@param {String} string HTML to push into the buffer
@chainable
*/
push: function(string) {
this.childBuffers.push(String(string));
return this;
},
/**
Adds a class to the buffer, which will be rendered to the class attribute.
@method addClass
@param {String} className Class name to add to the buffer
@chainable
*/
addClass: function(className) {
// lazily create elementClasses
var elementClasses = this.elementClasses = (this.elementClasses || new ClassSet());
this.elementClasses.add(className);
return this;
},
/**
Sets the elementID to be used for the element.
@method id
@param {String} id
@chainable
*/
id: function(id) {
this.elementId = id;
return this;
},
// duck type attribute functionality like jQuery so a render buffer
// can be used like a jQuery object in attribute binding scenarios.
/**
Adds an attribute which will be rendered to the element.
@method attr
@param {String} name The name of the attribute
@param {String} value The value to add to the attribute
@chainable
@return {Ember.RenderBuffer|String} this or the current attribute value
*/
attr: function(name, value) {
var attributes = this.elementAttributes = (this.elementAttributes || {});
if (arguments.length === 1) {
return attributes[name];
} else {
attributes[name] = value;
}
return this;
},
/**
Remove an attribute from the list of attributes to render.
@method removeAttr
@param {String} name The name of the attribute
@chainable
*/
removeAttr: function(name) {
var attributes = this.elementAttributes;
if (attributes) { delete attributes[name]; }
return this;
},
/**
Adds a style to the style attribute which will be rendered to the element.
@method style
@param {String} name Name of the style
@param {String} value
@chainable
*/
style: function(name, value) {
var style = this.elementStyle = (this.elementStyle || {});
this.elementStyle[name] = value;
return this;
},
/**
@private
Create a new child render buffer from a parent buffer. Optionally set
additional properties on the buffer. Optionally invoke a callback
with the newly created buffer.
This is a primitive method used by other public methods: `begin`,
`prepend`, `replaceWith`, `insertAfter`.
@method newBuffer
@param {String} tagName Tag name to use for the child buffer's element
@param {Ember._RenderBuffer} parent The parent render buffer that this
buffer should be appended to.
@param {Function} fn A callback to invoke with the newly created buffer.
@param {Object} other Additional properties to add to the newly created
buffer.
*/
newBuffer: function(tagName, parent, fn, other) {
var buffer = new Ember._RenderBuffer(tagName);
buffer.parentBuffer = parent;
if (other) { Ember.$.extend(buffer, other); }
if (fn) { fn.call(this, buffer); }
return buffer;
},
/**
@private
Replace the current buffer with a new buffer. This is a primitive
used by `remove`, which passes `null` for `newBuffer`, and `replaceWith`,
which passes the new buffer it created.
@method replaceWithBuffer
@param {Ember._RenderBuffer} buffer The buffer to insert in place of
the existing buffer.
*/
replaceWithBuffer: function(newBuffer) {
var parent = this.parentBuffer;
if (!parent) { return; }
var childBuffers = parent.childBuffers;
var index = indexOf.call(childBuffers, this);
if (newBuffer) {
childBuffers.splice(index, 1, newBuffer);
} else {
childBuffers.splice(index, 1);
}
},
/**
Creates a new Ember.RenderBuffer object with the provided tagName as
the element tag and with its parentBuffer property set to the current
Ember.RenderBuffer.
@method begin
@param {String} tagName Tag name to use for the child buffer's element
@return {Ember.RenderBuffer} A new RenderBuffer object
*/
begin: function(tagName) {
return this.newBuffer(tagName, this, function(buffer) {
this.childBuffers.push(buffer);
});
},
/**
Prepend a new child buffer to the current render buffer.
@method prepend
@param {String} tagName Tag name to use for the child buffer's element
*/
prepend: function(tagName) {
return this.newBuffer(tagName, this, function(buffer) {
this.childBuffers.splice(0, 0, buffer);
});
},
/**
Replace the current buffer with a new render buffer.
@method replaceWith
@param {String} tagName Tag name to use for the new buffer's element
*/
replaceWith: function(tagName) {
var parentBuffer = this.parentBuffer;
return this.newBuffer(tagName, parentBuffer, function(buffer) {
this.replaceWithBuffer(buffer);
});
},
/**
Insert a new render buffer after the current render buffer.
@method insertAfter
@param {String} tagName Tag name to use for the new buffer's element
*/
insertAfter: function(tagName) {
var parentBuffer = get(this, 'parentBuffer');
return this.newBuffer(tagName, parentBuffer, function(buffer) {
var siblings = parentBuffer.childBuffers;
var index = indexOf.call(siblings, this);
siblings.splice(index + 1, 0, buffer);
});
},
/**
Closes the current buffer and adds its content to the parentBuffer.
@method end
@return {Ember.RenderBuffer} The parentBuffer, if one exists. Otherwise, this
*/
end: function() {
var parent = this.parentBuffer;
return parent || this;
},
remove: function() {
this.replaceWithBuffer(null);
},
/**
@method element
@return {DOMElement} The element corresponding to the generated HTML
of this buffer
*/
element: function() {
return Ember.$(this.string())[0];
},
/**
Generates the HTML content for this buffer.
@method string
@return {String} The generated HTMl
*/
string: function() {
var content = '', tag = this.elementTag, openTag;
if (tag) {
var id = this.elementId,
classes = this.elementClasses,
attrs = this.elementAttributes,
style = this.elementStyle,
styleBuffer = '', prop;
openTag = ["<" + tag];
if (id) { openTag.push('id="' + this._escapeAttribute(id) + '"'); }
if (classes) { openTag.push('class="' + this._escapeAttribute(classes.toDOM()) + '"'); }
if (style) {
for (prop in style) {
if (style.hasOwnProperty(prop)) {
styleBuffer += (prop + ':' + this._escapeAttribute(style[prop]) + ';');
}
}
openTag.push('style="' + styleBuffer + '"');
}
if (attrs) {
for (prop in attrs) {
if (attrs.hasOwnProperty(prop)) {
openTag.push(prop + '="' + this._escapeAttribute(attrs[prop]) + '"');
}
}
}
openTag = openTag.join(" ") + '>';
}
var childBuffers = this.childBuffers;
Ember.ArrayPolyfills.forEach.call(childBuffers, function(buffer) {
var stringy = typeof buffer === 'string';
content += (stringy ? buffer : buffer.string());
});
if (tag) {
return openTag + content + "</" + tag + ">";
} else {
return content;
}
},
_escapeAttribute: function(value) {
// Stolen shamelessly from Handlebars
var escape = {
"<": "<",
">": ">",
'"': """,
"'": "'",
"`": "`"
};
var badChars = /&(?!\w+;)|[<>"'`]/g;
var possible = /[&<>"'`]/;
var escapeChar = function(chr) {
return escape[chr] || "&";
};
var string = value.toString();
if(!possible.test(string)) { return string; }
return string.replace(badChars, escapeChar);
}
};
})();
(function() {
/**
@module ember
@submodule ember-views
*/
var get = Ember.get, set = Ember.set, fmt = Ember.String.fmt;
/**
Ember.EventDispatcher handles delegating browser events to their corresponding
Ember.Views. For example, when you click on a view, Ember.EventDispatcher ensures
that that view's `mouseDown` method gets called.
@class EventDispatcher
@namespace Ember
@private
@extends Ember.Object
*/
Ember.EventDispatcher = Ember.Object.extend(
/** @scope Ember.EventDispatcher.prototype */{
/**
@private
The root DOM element to which event listeners should be attached. Event
listeners will be attached to the document unless this is overridden.
Can be specified as a DOMElement or a selector string.
The default body is a string since this may be evaluated before document.body
exists in the DOM.
@property rootElement
@type DOMElement
@default 'body'
*/
rootElement: 'body',
/**
@private
Sets up event listeners for standard browser events.
This will be called after the browser sends a DOMContentReady event. By
default, it will set up all of the listeners on the document body. If you
would like to register the listeners on a different element, set the event
dispatcher's `root` property.
@method setup
@param addedEvents {Hash}
*/
setup: function(addedEvents) {
var event, events = {
touchstart : 'touchStart',
touchmove : 'touchMove',
touchend : 'touchEnd',
touchcancel : 'touchCancel',
keydown : 'keyDown',
keyup : 'keyUp',
keypress : 'keyPress',
mousedown : 'mouseDown',
mouseup : 'mouseUp',
contextmenu : 'contextMenu',
click : 'click',
dblclick : 'doubleClick',
mousemove : 'mouseMove',
focusin : 'focusIn',
focusout : 'focusOut',
mouseenter : 'mouseEnter',
mouseleave : 'mouseLeave',
submit : 'submit',
input : 'input',
change : 'change',
dragstart : 'dragStart',
drag : 'drag',
dragenter : 'dragEnter',
dragleave : 'dragLeave',
dragover : 'dragOver',
drop : 'drop',
dragend : 'dragEnd'
};
Ember.$.extend(events, addedEvents || {});
var rootElement = Ember.$(get(this, 'rootElement'));
Ember.assert(fmt('You cannot use the same root element (%@) multiple times in an Ember.Application', [rootElement.selector || rootElement[0].tagName]), !rootElement.is('.ember-application'));
Ember.assert('You cannot make a new Ember.Application using a root element that is a descendent of an existing Ember.Application', !rootElement.closest('.ember-application').length);
Ember.assert('You cannot make a new Ember.Application using a root element that is an ancestor of an existing Ember.Application', !rootElement.find('.ember-application').length);
rootElement.addClass('ember-application');
Ember.assert('Unable to add "ember-application" class to rootElement. Make sure you set rootElement to the body or an element in the body.', rootElement.is('.ember-application'));
for (event in events) {
if (events.hasOwnProperty(event)) {
this.setupHandler(rootElement, event, events[event]);
}
}
},
/**
@private
Registers an event listener on the document. If the given event is
triggered, the provided event handler will be triggered on the target
view.
If the target view does not implement the event handler, or if the handler
returns false, the parent view will be called. The event will continue to
bubble to each successive parent view until it reaches the top.
For example, to have the `mouseDown` method called on the target view when
a `mousedown` event is received from the browser, do the following:
setupHandler('mousedown', 'mouseDown');
@method setupHandler
@param {Element} rootElement
@param {String} event the browser-originated event to listen to
@param {String} eventName the name of the method to call on the view
*/
setupHandler: function(rootElement, event, eventName) {
var self = this;
rootElement.delegate('.ember-view', event + '.ember', function(evt, triggeringManager) {
return Ember.handleErrors(function() {
var view = Ember.View.views[this.id],
result = true, manager = null;
manager = self._findNearestEventManager(view,eventName);
if (manager && manager !== triggeringManager) {
result = self._dispatchEvent(manager, evt, eventName, view);
} else if (view) {
result = self._bubbleEvent(view,evt,eventName);
} else {
evt.stopPropagation();
}
return result;
}, this);
});
rootElement.delegate('[data-ember-action]', event + '.ember', function(evt) {
return Ember.handleErrors(function() {
var actionId = Ember.$(evt.currentTarget).attr('data-ember-action'),
action = Ember.Handlebars.ActionHelper.registeredActions[actionId],
handler = action.handler;
if (action.eventName === eventName) {
return handler(evt);
}
}, this);
});
},
_findNearestEventManager: function(view, eventName) {
var manager = null;
while (view) {
manager = get(view, 'eventManager');
if (manager && manager[eventName]) { break; }
view = get(view, 'parentView');
}
return manager;
},
_dispatchEvent: function(object, evt, eventName, view) {
var result = true;
var handler = object[eventName];
if (Ember.typeOf(handler) === 'function') {
result = handler.call(object, evt, view);
// Do not preventDefault in eventManagers.
evt.stopPropagation();
}
else {
result = this._bubbleEvent(view, evt, eventName);
}
return result;
},
_bubbleEvent: function(view, evt, eventName) {
return Ember.run(function() {
return view.handleEvent(eventName, evt);
});
},
destroy: function() {
var rootElement = get(this, 'rootElement');
Ember.$(rootElement).undelegate('.ember').removeClass('ember-application');
return this._super();
}
});
})();
(function() {
/**
@module ember
@submodule ember-views
*/
// Add a new named queue for rendering views that happens
// after bindings have synced.
var queues = Ember.run.queues;
queues.splice(Ember.$.inArray('actions', queues)+1, 0, 'render');
})();
(function() {
/**
@module ember
@submodule ember-views
*/
var get = Ember.get, set = Ember.set;
// Original class declaration and documentation in runtime/lib/controllers/controller.js
// NOTE: It may be possible with YUIDoc to combine docs in two locations
/**
Additional methods for the ControllerMixin
@class ControllerMixin
@namespace Ember
*/
Ember.ControllerMixin.reopen({
target: null,
controllers: null,
namespace: null,
view: null,
/**
`connectOutlet` creates a new instance of a provided view
class, wires it up to its associated controller, and
assigns the new view to a property on the current controller.
The purpose of this method is to enable views that use
outlets to quickly assign new views for a given outlet.
For example, an application view's template may look like
this:
``` handlebars
<h1>My Blog</h1>
{{outlet}}
```
The view for this outlet is specified by assigning a
`view` property to the application's controller. The
following code will assign a new `App.PostsView` to
that outlet:
``` javascript
applicationController.connectOutlet('posts');
```
In general, you will also want to assign a controller
to the newly created view. By convention, a controller
named `postsController` will be assigned as the view's
controller.
In an application initialized using `app.initialize(router)`,
`connectOutlet` will look for `postsController` on the
router. The initialization process will automatically
create an instance of `App.PostsController` called
`postsController`, so you don't need to do anything
beyond `connectOutlet` to assign your view and wire it
up to its associated controller.
You can supply a `content` for the controller by supplying
a final argument after the view class:
``` javascript
applicationController.connectOutlet('posts', App.Post.find());
```
You can specify a particular outlet to use. For example, if your main
template looks like:
``` handlebars
<h1>My Blog</h1>
{{outlet masterView}}
{{outlet detailView}}
```
You can assign an `App.PostsView` to the masterView outlet:
``` javascript
applicationController.connectOutlet({
outletName: 'masterView',
name: 'posts',
context: App.Post.find()
});
```
You can write this as:
``` javascript
applicationController.connectOutlet('masterView', 'posts', App.Post.find());
```
@method connectOutlet
@param {String} outletName a name for the outlet to set
@param {String} name a view/controller pair name
@param {Object} context a context object to assign to the
controller's `content` property, if a controller can be
found (optional)
*/
connectOutlet: function(name, context) {
// Normalize arguments. Supported arguments:
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
//
// name: the name of the controller and view
// to use. If this is passed, the name
// determines the view and controller.
// outletName: the name of the outlet to
// fill in. default: 'view'
// viewClass: the class of the view to instantiate
// controller: the controller instance to pass
// to the view
// context: an object that should become the
// controller's `content` and thus the
// template's context.
var outletName, viewClass, view, controller, options;
if (Ember.typeOf(context) === 'string') {
outletName = name;
name = context;
context = arguments[2];
}
if (arguments.length === 1) {
if (Ember.typeOf(name) === 'object') {
options = name;
outletName = options.outletName;
name = options.name;
viewClass = options.viewClass;
controller = options.controller;
context = options.context;
}
} else {
options = {};
}
outletName = outletName || 'view';
Ember.assert("The viewClass is either missing or the one provided did not resolve to a view", !!name || (!name && !!viewClass));
Ember.assert("You must supply a name or a viewClass to connectOutlet, but not both", (!!name && !viewClass && !controller) || (!name && !!viewClass));
if (name) {
var namespace = get(this, 'namespace'),
controllers = get(this, 'controllers');
var viewClassName = name.charAt(0).toUpperCase() + name.substr(1) + "View";
viewClass = get(namespace, viewClassName);
controller = get(controllers, name + 'Controller');
Ember.assert("The name you supplied " + name + " did not resolve to a view " + viewClassName, !!viewClass);
Ember.assert("The name you supplied " + name + " did not resolve to a controller " + name + 'Controller', (!!controller && !!context) || !context);
}
if (controller && context) { set(controller, 'content', context); }
view = this.createOutletView(outletName, viewClass);
if (controller) { set(view, 'controller', controller); }
set(this, outletName, view);
return view;
},
/**
Convenience method to connect controllers. This method makes other controllers
available on the controller the method was invoked on.
For example, to make the `personController` and the `postController` available
on the `overviewController`, you would call:
overviewController.connectControllers('person', 'post');
@method connectControllers
@param {String...} controllerNames the controllers to make available
*/
connectControllers: function() {
var controllers = get(this, 'controllers'),
controllerNames = Array.prototype.slice.apply(arguments),
controllerName;
for (var i=0, l=controllerNames.length; i<l; i++) {
controllerName = controllerNames[i] + 'Controller';
set(this, controllerName, get(controllers, controllerName));
}
},
/**
`disconnectOutlet` removes previously attached view from given outlet.
@method disconnectOutlet
@param {String} outletName the outlet name. (optional)
*/
disconnectOutlet: function(outletName) {
outletName = outletName || 'view';
set(this, outletName, null);
},
/**
`createOutletView` is a hook you may want to override if you need to do
something special with the view created for the outlet. For example
you may want to implement views sharing across outlets.
@method createOutletView
@param outletName {String}
@param viewClass {Ember.View}
*/
createOutletView: function(outletName, viewClass) {
return viewClass.create();
}
});
})();
(function() {
})();
(function() {
/**
@module ember
@submodule ember-views
*/
var get = Ember.get, set = Ember.set, addObserver = Ember.addObserver, removeObserver = Ember.removeObserver;
var meta = Ember.meta, fmt = Ember.String.fmt;
var a_slice = [].slice;
var a_forEach = Ember.EnumerableUtils.forEach;
var childViewsProperty = Ember.computed(function() {
var childViews = this._childViews;
var ret = Ember.A();
a_forEach(childViews, function(view) {
if (view.isVirtual) {
ret.pushObjects(get(view, 'childViews'));
} else {
ret.push(view);
}
});
return ret;
}).property();
Ember.warn("The VIEW_PRESERVES_CONTEXT flag has been removed and the functionality can no longer be disabled.", Ember.ENV.VIEW_PRESERVES_CONTEXT !== false);
/**
Global hash of shared templates. This will automatically be populated
by the build tools so that you can store your Handlebars templates in
separate files that get loaded into JavaScript at buildtime.
@property TEMPLATES
@for Ember
@type Hash
*/
Ember.TEMPLATES = {};
var invokeForState = {
preRender: {},
inBuffer: {},
hasElement: {},
inDOM: {},
destroyed: {}
};
Ember.CoreView = Ember.Object.extend(Ember.Evented, {
init: function() {
this._super();
// Register the view for event handling. This hash is used by
// Ember.EventDispatcher to dispatch incoming events.
if (!this.isVirtual) Ember.View.views[get(this, 'elementId')] = this;
},
/**
If the view is currently inserted into the DOM of a parent view, this
property will point to the parent of the view.