This repository was archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathngoverrides.js
1052 lines (943 loc) · 42.4 KB
/
ngoverrides.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
'use strict';
var url = require('url');
var http = require('http');
var https = require('https');
function registerModule(context) {
// provide an empty ngRoute so that apps can depend on it even though we actually
// provide what it provides natively.
context.module('ngRoute', []);
// we also provide an empty 'sdr' for the same reason, since the client-side app will probably
// depend on it but it makes no sense to run server-defined routes *on* the server.
context.module('sdr', []);
// an app that depends on ngAnimate will fail on the absence of $rootElement in unbootstrapped
// server context, and animation is not relevant on the server, so we just override it.
context.module('ngAnimate', []);
// we depend on ngRoute here to be sure that, even if the application has provided the "real"
// ngRoute module, we'll always register after it and get to override $route.
var module = context.module('angularjs-server', ['ng', 'ngRoute']);
var angular = context.getAngular();
// Timeout and interval don't really make sense in the server context, because we're always
// trying to get stuff together as quickly as possible to return. Therefore we change the
// meaning of setTimeout and setInterval to simply "execute once, asynchronously but as soon
// as possible". This supports the case where timeouts are used to force code to run async,
// but it doesn't support the case where a timeout is actually being used to implement a timeout
// for a long-running operation, since of course then the operation will 'time out' immediately.
(function () {
var $injector = angular.injector(['ng']);
var window = $injector.get('$window');
var nextId = 1;
// A map of pending ids to true if they are pending.
// We intentionally avoid storing any references to the provided callback or to the
// immediate object since this guarantees that only nodejs itself holds a reference to
// the callback state and there's no risk of us leaking memory in here.
var pending = {};
var wrapCallback = function (id, cb) {
return function () {
if (pending[id]) {
delete pending[id];
cb.apply(this, arguments);
}
};
};
var enqueue = function (cb) {
var id = nextId++;
var wrappedCb = wrapCallback(id, cb);
pending[id] = true;
setImmediate(wrappedCb);
return id;
};
var dequeue = function (id) {
delete pending[id];
};
window.setTimeout = function (cb) {
return enqueue(cb);
};
window.setInterval = function (cb) {
return enqueue(cb);
};
window.clearTimeout = function (id) {
dequeue(id);
};
window.clearInterval = function (id) {
dequeue(id);
};
// Register so we can know when our context is being disposed, so that we
// can abort any outstanding requests.
context.onDispose(
function () {
pending = {};
}
);
// don't need these guys after we're done setting up.
$injector = undefined;
window = undefined;
})();
module.factory(
'serverRequestContext',
function ($injector) {
var request;
var requestUrlParts;
var redirectTo;
var ifRequest = function (code) {
return function () {
if (request) {
return code();
}
else {
throw new Error('location not available yet');
}
};
};
var parsedUrl = function (code) {
return function (set, value) {
if (request) {
if (! requestUrlParts) {
requestUrlParts = url.parse(request.url, true);
}
return code(requestUrlParts, set, value);
}
else {
throw new Error('location not available yet');
}
};
};
var absUrl = parsedUrl(
function (parts) {
// TODO: Make this be https: when the
// request is SSL?
return 'http://' +
request.headers.host +
parts.pathname +
(parts.search ? parts.search : '');
}
);
var reparseUrl = function () {
requestUrlParts = url.parse(url.format(requestUrlParts), true);
};
return {
location: {
absUrl: absUrl,
hash: function () {
// the server never sees the fragment
return '';
},
host: ifRequest(
function () {
return request.headers.host;
}
),
path: parsedUrl(
function (parts, set) {
if (set) {
var oldUrl = absUrl();
parts.pathname = set;
redirectTo = absUrl();
var $rootScope = $injector.get('$rootScope');
$rootScope.$broadcast(
'$locationChangeSuccess',
redirectTo,
oldUrl
);
requestUrlParts.pathname = set;
reparseUrl();
return this;
}
return parts.pathname;
}
),
port: ifRequest(
function () {
// TODO: Make this actually check the port.
return 80;
}
),
protocol: ifRequest(
function () {
// TODO: Make this be 'https' when the
// request is SSL?
return 'http';
}
),
search: parsedUrl(
function (parts, set, paramValue) {
if (set) {
if (paramValue === null) {
delete parts.query[paramValue];
}
else if (paramValue) {
parts.query[set] = paramValue;
}
else {
parts.query = set;
}
var searchArgs = [];
for (var k in parts.query) {
searchArgs.push(k + '=' + parts.query[k]);
}
requestUrlParts.search = '?' + searchArgs.join('&');
reparseUrl();
return this;
}
return parts.query;
}
),
replace: function () {
return this;
},
runningOnServer: true,
url: parsedUrl(
function (parts, set) {
if (set) {
requestUrlParts = url.parse(set, true);
reparseUrl();
}
return requestUrlParts.path;
}
)
},
setRequest: function (newRequest) {
if (request) {
throw new Error('This context already has a request');
}
else {
request = newRequest;
}
},
hasRequest: function () {
return request ? true : false;
},
getRedirectTo: function () {
return redirectTo;
}
};
}
);
module.provider(
'serverFlattenPromises',
{
$get: function ($q) {
return function (obj) {
var defer = $q.defer();
var outstandingPromises = 0;
var maybeDone = function () {
if (outstandingPromises === 0) {
defer.resolve(obj);
}
};
var flattenKey = function (obj, k, v) {
if (v && typeof v.then === 'function') {
outstandingPromises++;
v.then(
function (nextV) {
outstandingPromises--;
flattenKey(obj, k, nextV);
}
);
}
else {
obj[k] = v;
if (typeof v === 'object') {
flattenObj(v);
}
maybeDone();
}
};
var flattenObj = function (obj) {
for (var k in obj) {
flattenKey(obj, k, obj[k]);
}
};
flattenObj(obj);
maybeDone();
return defer.promise;
};
}
}
);
module.provider(
'$log',
function () {
return {
$get: function (serverRequestContext) {
function makeLogProxy(methodName) {
return function () {
var logArgs = [
serverRequestContext.hasRequest() ?
'[' + serverRequestContext.location.absUrl() + ']' :
'[location not set]'
].concat(Array.prototype.slice.call(arguments, 0));
console[methodName].apply(
console,
logArgs
);
};
}
return {
debug: makeLogProxy('log'),
error: makeLogProxy('error'),
info: makeLogProxy('info'),
log: makeLogProxy('log'),
warn: makeLogProxy('warn')
};
}
};
}
);
module.provider(
'$exceptionHandler',
function () {
return {
$get: function ($log) {
return function (exception, cause) {
var parts = [exception.stack];
if (cause) {
parts.push('\nCaused by: ');
parts.push(cause);
}
$log.error(parts.join(''));
};
}
};
}
);
module.provider(
'$location',
function () {
return {
$get: function (serverRequestContext) {
return serverRequestContext.location;
},
html5Mode: function (mode) {
// not actually relevant on the server, but we support this call anyway
// so that client-oriented code can run unmodified on the server.
return this;
},
hashPrefix: function (prefix) {
// again, not relevant on the server.
return this;
}
};
}
);
module.provider(
'$httpBackend',
function () {
return {
$get: function (serverRequestContext, $location) {
var openReqs = 0;
var doneCallbacks = [];
var nextRequestId = 0;
var pendingRequests = {};
var startRequest = function () {
openReqs++;
};
var endRequest = function () {
openReqs--;
if (openReqs < 1) {
openReqs = 0;
var toCall = doneCallbacks;
doneCallbacks = [];
for (var i = 0; i < toCall.length; i++) {
toCall[i]();
}
}
};
// Register so we can know when our context is being disposed, so that we
// can abort any outstanding requests.
context.onDispose(
function () {
for (var requestId in pendingRequests) {
var req = pendingRequests[requestId];
req.abort();
delete pendingRequests[requestId];
}
}
);
var ret = function (
reqMethod, reqUrl, reqData, callback, headers,
timeout, withCredentials, responseType
) {
var isJSONP = false;
if (reqMethod.toLowerCase() === 'jsonp') {
// We don't want to run an arbitrary callback on the server, so instead
// we'll just strip off the callback invocation and the caller will get
// back whatever JSON is inside.
reqMethod = 'GET';
isJSONP = true;
}
startRequest();
if (! serverRequestContext.hasRequest()) {
// we can't do HTTP requests yet, because we don't know our own URL.
console.error('Denied HTTP request', reqUrl, 'because we have no base URL');
callback(-1, undefined, undefined);
endRequest();
}
reqUrl = url.resolve($location.absUrl(), reqUrl);
var urlParts = url.parse(reqUrl);
var module;
if (urlParts.protocol === 'http:') {
module = http;
if (! urlParts.port) {
urlParts.port = 80;
}
}
else if (urlParts.protocol === 'https:') {
module = https;
if (! urlParts.port) {
urlParts.port = 443;
}
}
else {
setTimeout(
function () {
// FIXME: Figure out what browsers do when an inappropriate
// protocol is specified and mimic that here.
callback(-1, undefined, undefined);
endRequest();
},
1
);
return;
}
var thisRequestId = nextRequestId;
nextRequestId++;
// Pass through any headers that were set in the original request
headers = headers || {};
headers.Host = urlParts.host;
var req = pendingRequests[thisRequestId] = module.request(
{
hostname: urlParts.hostname,
port: urlParts.port,
path: urlParts.pathname +
(urlParts.search ? urlParts.search : ''),
method: reqMethod,
headers: headers
},
function (res) {
// ignore responses to aborted requests
if (! pendingRequests[thisRequestId]) {
return;
}
var status = res.statusCode;
// Angular's interface expects headers as a string,
// so we have to do a bit of an abstraction inversion here.
var headers = '';
for (var k in res.headers) {
headers += k + ': ' + res.headers[k] + '\n';
}
res.setEncoding('utf8'); // FIXME: what if it's not utf8?
var resData = [];
res.on(
'data',
function (chunk) {
// ignore responses to aborted requests
if (! pendingRequests[thisRequestId]) {
return;
}
resData.push(chunk);
}
);
res.on(
'end',
function () {
// ignore responses to aborted requests
if (! pendingRequests[thisRequestId]) {
return;
}
delete pendingRequests[thisRequestId];
var resStr = resData.join('');
if (isJSONP) {
// Assume everything up to the opening paren is the callback name
resStr = resStr.replace(/^[^(]+\(/, '')
.replace(/\)\s*;?\s*$/, '');
}
// Call the callback before endRequest, to give the
// callback a chance to push more requests into the queue
// before we check if we're done.
callback(status, resStr, headers);
endRequest();
}
);
}
);
req.on(
'error',
function (err) {
// ignore responses to aborted requests
if (! pendingRequests[thisRequestId]) {
return;
}
delete pendingRequests[thisRequestId];
// FIXME: What is a good error response code for this case?
callback(-1, undefined, undefined);
endRequest();
}
);
if (reqData) {
req.write(reqData);
}
req.end();
};
// Extra interface to allow our server code to detect when
// we're done loading things, so we know it's time to return
// the response.
ret.notifyWhenNoOpenRequests = function (cb) {
// check for openReqs asynchronously to give any pending requests
// a chance to begin.
setTimeout(
function () {
if (openReqs > 0) {
doneCallbacks.push(cb);
}
else {
setTimeout(cb, 1);
}
},
1
);
};
return ret;
}
};
}
);
// $$SanitizeUri is actually a private service in AngularJS, so ideally we wouldn't touch it nor
// depend on it at all, but this is a very common caller of Angular's internal "urlResolve" function
// that ends up being particularly slow on jsdom, and so we override this service so we can use
// a more efficient implementation in the server. What we really want to do here is override the
// urlResolve function, but that's a local variable inside the AngularJS module and so we can't
// get at it to override it.
module.provider(
'$$sanitizeUri',
function () {
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/;
var imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file):|data:image\//;
var ret = {};
ret.aHrefSanitizationWhitelist = function (regexp) {
if (angular.isDefined(regexp)) {
aHrefSanitizationWhitelist = regexp;
return this;
}
return aHrefSanitizationWhitelist;
};
ret.imgSrcSanitizationWhitelist = function (regexp) {
if (angular.isDefined(regexp)) {
imgSrcSanitizationWhitelist = regexp;
return this;
}
return imgSrcSanitizationWhitelist;
};
ret.$get = function (serverRequestContext) {
return function sanitizeUri(uri, isImage) {
var regex = isImage ? imgSrcSanitizationWhitelist : aHrefSanitizationWhitelist;
// if we don't know our base URL yet then we can't sanitize, so
// just skip. This generally applies only to a context created outside of
// a request, e.g. for server configuration, so malicious links here are
// pretty harmless anyway since we're not a browser and there's no user
// around to click on them.
if (! serverRequestContext.hasRequest()) {
return uri;
}
var baseUrl = serverRequestContext.location.absUrl();
// mimic the behavior of UrlResolve
var normalizedVal;
if (uri === null) {
normalizedVal = url.resolve(baseUrl, '/null');
}
else {
normalizedVal = url.resolve(baseUrl, uri);
}
if (normalizedVal !== '' && !normalizedVal.match(regex)) {
return 'unsafe:' + normalizedVal;
}
else {
return uri;
}
};
};
return ret;
}
);
// The $sceDelegate service is another common caller of urlResolve, so we override this too.
// For the moment we override it to be a no-op, but we might want to revisit this later to
// ensure that we're sanitizing user-provided content on the server as well as the client.
// For now we assume that there are fewer opportunities for injection on the server, since we
// don't run inline scripts, we don't follow links, etc.
module.provider(
'$sceDelegate',
function () {
this.$get = function () {
var ret = {};
ret.trustAs = function (type, value) {
return value;
};
ret.valueOf = function (value) {
return value;
};
ret.getTrusted = function (type, value) {
return value;
};
return ret;
};
// these two are here just to satisfy the interface. We don't actually use them.
this.resourceUrlWhitelist = function () {
return ['self'];
};
this.resourceUrlBlacklist = function () {
return [];
};
}
);
// A reimplementation of $route that is largely the same as the standard $route but makes the
// route introspection functions public.
module.provider(
'$route',
function () {
var routes = {};
var baseRoute = {
reloadOnSearch: true
};
this.when = function (path, route) {
routes[path] = angular.extend(
{},
baseRoute,
route,
path && pathRegExp(path, route)
);
// create redirection for trailing slashes
if (path) {
var redirectPath = (path[path.length - 1] === '/') ?
path.substr(0, path.length - 1) :
path + '/';
routes[redirectPath] = angular.extend(
{redirectTo: path},
baseRoute,
pathRegExp(redirectPath, route)
);
}
return this;
};
this.otherwise = function (params) {
this.when(null, params);
return this;
};
function pathRegExp(path, opts) {
var insensitive = opts.caseInsensitiveMatch,
ret = {
originalPath: path,
regexp: path
},
keys = ret.keys = [];
path = path
.replace(/([().])/g, '\\$1')
.replace(
/(\/)?:(\w+)([\?|\*])?/g,
function (_, slash, key, option) {
var optional = option === '?' ? option : null;
var star = option === '*' ? option : null;
keys.push({ name: key, optional: !!optional });
slash = slash || '';
return '' +
(optional ? '' : slash) +
'(?:' +
(optional ? slash : '') +
(star && '(.+)?' || '([^/]+)?') + ')' +
(optional || '');
})
.replace(/([\/$\*])/g, '\\$1');
ret.regexp = new RegExp('^' + path + '$', insensitive ? 'i' : '');
return ret;
}
function inherit(parent, extra) {
var extendee = angular.extend(
function () {},
{
prototype: parent
}
);
return angular.extend(
new extendee(),
extra
);
}
this.$get = function (
$rootScope,
$location,
$routeParams,
$q,
$injector,
$http,
$templateCache
) {
var routeMethods = {
jsonFriendly: function () {
var route = this;
var flattenPromises = $injector.get('serverFlattenPromises');
var defer = $q.defer();
route.populateLocals().then(
function (route) {
var locals = {};
var localServices = {};
// $template shows up based on the presence of 'template' or 'templateUrl'
// in the route, not based on route.resolve like the others we'll handle
// below.
if (route.locals.$template) {
locals.$template = route.locals.$template;
}
if (route.resolve) {
// We walk resolve rather than route.locals directly so that we can
// recognize which items were requests to inject a service and handle
// those as a special case.
for (var k in route.resolve) {
var resolver = route.resolve[k];
if (typeof resolver === 'string') {
// they want to inject a service, but we can't serialize a service
// as JSON so we just return the service names so the recipient of
// this object can resolve them itself.
localServices[k] = resolver;
}
else {
locals[k] = route.locals[k];
}
}
}
// although route.resolve already resolved the top-level promises,
// we might need to do some more work if there are any promises nested
// inside the already-resolved objects; we have to completely resolve the
// whole structure before we can return the data as JSON.
flattenPromises(locals).then(
function (locals) {
defer.resolve(
{
path: route.originalPath,
controller: route.controller,
locals: locals,
localServices: localServices,
pathParams: route.pathParams
}
);
},
function (error) {
defer.reject(error);
}
);
}
);
return defer.promise;
},
populateLocals: function () {
var route = this;
var $route = $injector.get('$route');
var locals = {};
// route resolve functions often depend on $route.current to get at
// route parameters. In order to make that work in this context, where there isn't
// really a "current route", we inject a special version of $route that has
// $route.current overridden.
// This should work for most apps, although an app that stashes this object somewhere
// for later use outside of the resolve function could run into problems.
var local$route = angular.extend(
{},
$route,
{
current: route
}
);
if (route.resolve) {
for (var k in route.resolve) {
var resolver = route.resolve[k];
if (typeof resolver === 'string') {
locals[k] = $injector.get(resolver);
}
else {
locals[k] = $injector.invoke(
resolver,
undefined,
{
'$route': local$route
}
);
}
}
}
if (route.template !== undefined) {
locals.$template = route.template;
}
else if (route.templateUrl !== undefined) {
// For the moment we just fetch the template from our own server
// using an HTTP request, which ensures that the URL resolution will work
// how it would work in a browser. However, this is not especially efficient
// if the file happens to already be sitting on local disk, so we might
// want to do something better later. For now applications can circumvent
// this oddity by preloading the templates into the $templateCache.
var absTemplateUrl = url.resolve($location.absUrl(), route.templateUrl);
locals.$template = $http.get(
absTemplateUrl,
{
cache: $templateCache
}
).then(
function (response) {
return response.data;
}
);
}
return $q.all(locals).then(
function (resolvedLocals) {
route.locals = resolvedLocals;
return route;
}
);
}
};
var $route = {};
$route.routes = routes;
function switchRouteMatcher(on, route) {
var keys = route.keys;
var params = {};
if (!route.regexp) {
return null;
}
var m = route.regexp.exec(on);
if (!m) {
return null;
}
for (var i = 1, len = m.length; i < len; ++i) {
var key = keys[i - 1];
var val = 'string' === typeof m[i] ?
decodeURIComponent(m[i]) :
m[i];
if (key && val) {
params[key.name] = val;
}
}
return params;
}
$route.getByPath = function (path, search) {
var match = null;
var params;
search = search || {};
angular.forEach(
routes,
function (route, routePath) {
if (! match) {
params = switchRouteMatcher(path, route);
if (params) {
match = inherit(
route,
{
params: angular.extend(
{},
search,
params
),
pathParams: params
}
);
angular.extend(
match,
routeMethods
);
match.$$route = route;
}
}
else {
return;
}
}
);
return match;
};
$route.getOtherwise = function () {
var route = inherit(
routes[null],
{
params: {},
pathParams: {}
}
);
angular.extend(
route,
routeMethods
);
return route;
};
return $route;
};
}
);
module.provider(
'$routeParams',
function () {
this.$get = function () { return {}; };
}
);
// this does basically the same thing as the one in ngRoute, but we're forced to provide this
// here because we can't load ngRoute without its $route implementation obscuring our overridden
// version.
module.directive(
'ngView',
function ($route, $anchorScroll, $compile, $controller, $animate) {
return {
restrict: 'ECA',
terminal: true,
priority: 1000,
transclude: 'element',
compile: function (element, attr, linker) {
return function (scope, $element, attr) {
var currentScope,
currentElement,
onloadExp = attr.onload || '';
function cleanupLastView() {
if (currentScope) {
currentScope.$destroy();
currentScope = null;
}
if (currentElement) {
$animate.leave(currentElement);
currentElement = null;
}
}
function update() {
var locals = $route.current && $route.current.locals,