Skip to content

Commit fe5b80d

Browse files
committed
Readded whitespaces to only show usefull updates
1 parent 1c21f9f commit fe5b80d

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

src/route-segment.js

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
var mod = angular.module( 'route-segment', [] );
66
mod.provider( '$routeSegment',
77
['$routeProvider', function($routeProvider) {
8-
8+
99
var $routeSegmentProvider = this;
10-
10+
1111
var options = $routeSegmentProvider.options = {
12-
12+
1313
/**
1414
* When true, it will resolve `templateUrl` automatically via $http service and put its
1515
* contents into `template`.
1616
* @type {boolean}
1717
*/
1818
autoLoadTemplates: true,
19-
19+
2020
/**
2121
* When true, all attempts to call `within` method on non-existing segments will throw an error (you would
2222
* usually want this behavior in production). When false, it will transparently create new empty segment
@@ -25,46 +25,46 @@ mod.provider( '$routeSegment',
2525
*/
2626
strictMode: false
2727
};
28-
28+
2929
var segments = this.segments = {},
3030
rootPointer = pointer(segments, null),
3131
segmentRoutes = {};
32-
32+
3333
function camelCase(name) {
3434
return name.replace(/([\:\-\_]+(.))/g, function(_, separator, letter, offset) {
3535
return offset ? letter.toUpperCase() : letter;
3636
});
3737
}
38-
38+
3939
function pointer(segment, parent) {
40-
40+
4141
if(!segment)
4242
throw new Error('Invalid pointer segment');
43-
43+
4444
var lastAddedName;
45-
45+
4646
return {
47-
47+
4848
/**
4949
* Adds new segment at current pointer level.
50-
*
50+
*
5151
* @param string} name Name of a segment.
5252
* @param {Object} params Segment's parameters hash. The following params are supported:
5353
* - `template` provides HTML for the given segment view;
5454
* - `templateUrl` is a template should be fetched from network via this URL;
5555
* - `controller` is attached to the given segment view when compiled and linked,
5656
* this can be any controller definition AngularJS supports;
57-
* - `dependencies` is an array of route param names which are forcing the view
57+
* - `dependencies` is an array of route param names which are forcing the view
5858
* to recreate when changed;
5959
* - `watcher` is a $watch-function for recreating the view when its returning value
6060
* is changed;
6161
* - `resolve` is a hash of functions or injectable names which should be resolved
6262
* prior to instantiating the template and the controller;
6363
* - `untilResolved` is the alternate set of params (e.g. `template` and `controller`)
64-
* which should be used before resolving is completed;
65-
* - `resolveFailed` is the alternate set of params which should be used
64+
* which should be used before resolving is completed;
65+
* - `resolveFailed` is the alternate set of params which should be used
6666
* if resolving failed;
67-
*
67+
*
6868
* @returns {Object} The same level pointer.
6969
*/
7070
segment: function(name, params) {
@@ -79,11 +79,11 @@ mod.provider( '$routeSegment',
7979
*
8080
* @param {string} childName An existing segment's name. If undefined, then the last added segment is selected.
8181
* @returns {Object} The pointer to the child segment.
82-
*/
83-
within: function(childName) {
82+
*/
83+
within: function(childName) {
8484
var child;
8585
childName = childName || lastAddedName;
86-
86+
8787
if(child = segment[camelCase(childName)]) {
8888
if(child.children == undefined)
8989
child.children = {};
@@ -93,19 +93,19 @@ mod.provider( '$routeSegment',
9393
throw new Error('Cannot get into unknown `'+childName+'` segment');
9494
else {
9595
child = segment[camelCase(childName)] = {params: {}, children: {}};
96-
}
96+
}
9797
}
9898
return pointer(child.children, this);
9999
},
100-
100+
101101
/**
102102
* Traverses up in the tree.
103103
* @returns {Object} The pointer which are parent to the current one;
104104
*/
105105
up: function() {
106106
return parent;
107107
},
108-
108+
109109
/**
110110
* Traverses to the root.
111111
* @returns The root pointer.
@@ -115,7 +115,7 @@ mod.provider( '$routeSegment',
115115
}
116116
}
117117
}
118-
118+
119119
/**
120120
* The shorthand for $routeProvider.when() method with specified route name.
121121
* @param {string} path Route URL, e.g. '/foo/bar'
@@ -131,18 +131,18 @@ mod.provider( '$routeSegment',
131131
segmentRoutes[name] = path;
132132
return this;
133133
};
134-
134+
135135
// Extending the provider with the methods of rootPointer
136136
// to start configuration.
137137
angular.extend($routeSegmentProvider, rootPointer);
138-
139-
138+
139+
140140
// the service factory
141141
this.$get = ['$rootScope', '$q', '$http', '$templateCache', '$route', '$routeParams', '$injector',
142142
function($rootScope, $q, $http, $templateCache, $route, $routeParams, $injector) {
143-
144-
var $routeSegment = {
145-
143+
144+
var $routeSegment = {
145+
146146
/**
147147
* Fully qualified name of current active route
148148
* @type {string}
@@ -156,7 +156,7 @@ mod.provider( '$routeSegment',
156156
* @type {Object}
157157
*/
158158
$routeParams: angular.copy($routeParams),
159-
159+
160160
/**
161161
* Array of segments splitted by each level separately. Each item contains the following properties:
162162
* - `name` is the name of a segment;
@@ -167,7 +167,7 @@ mod.provider( '$routeSegment',
167167
* @type {Array.<Object>}
168168
*/
169169
chain: [],
170-
170+
171171
/**
172172
* Helper method for checking whether current route starts with the given string
173173
* @param {string} val
@@ -177,7 +177,7 @@ mod.provider( '$routeSegment',
177177
var regexp = new RegExp('^'+val);
178178
return regexp.test($routeSegment.name);
179179
},
180-
180+
181181
/**
182182
* Helper method for checking whether current route contains the given string
183183
* @param {string} val
@@ -214,22 +214,22 @@ mod.provider( '$routeSegment',
214214

215215
return url;
216216
}
217-
};
217+
};
218218

219219
var resolvingSemaphoreChain = {};
220-
220+
221221
// When a route changes, all interested parties should be notified about new segment chain
222222
$rootScope.$on('$routeChangeSuccess', function(event, args) {
223223

224-
var route = args.$route || args.$$route;
224+
var route = args.$route || args.$$route;
225225
if(route && route.segment) {
226226

227227
var segmentName = route.segment;
228228
var segmentNameChain = segmentName.split(".");
229229
var updates = [], lastUpdateIndex = -1;
230-
230+
231231
for(var i=0; i < segmentNameChain.length; i++) {
232-
232+
233233
var newSegment = getSegmentInChain( i, segmentNameChain );
234234

235235
if(resolvingSemaphoreChain[i] != newSegment.name || updates.length > 0 || isDependenciesChanged(newSegment)) {
@@ -242,7 +242,7 @@ mod.provider( '$routeSegment',
242242
updates.push({index: i, newSegment: newSegment});
243243
lastUpdateIndex = i;
244244
}
245-
}
245+
}
246246
}
247247

248248
var curSegmentPromise = $q.when();
@@ -310,7 +310,7 @@ mod.provider( '$routeSegment',
310310
lastUpdateIndex = index;
311311
}
312312
})(i, children, index);
313-
313+
314314

315315
}
316316
}
@@ -320,7 +320,7 @@ mod.provider( '$routeSegment',
320320
});
321321
}
322322
});
323-
323+
324324
function isDependenciesChanged(segment) {
325325

326326
var result = false;
@@ -357,22 +357,22 @@ mod.provider( '$routeSegment',
357357
else
358358
return resolve(index, segment.name, segment.params);
359359
}
360-
360+
361361
function resolve(index, name, params) {
362-
362+
363363
var locals = angular.extend({}, params.resolve);
364-
364+
365365
angular.forEach(locals, function(value, key) {
366366
locals[key] = angular.isString(value) ? $injector.get(value) : $injector.invoke(value);
367367
});
368-
368+
369369
if(params.template) {
370370

371371
locals.$template = params.template;
372372
if(angular.isFunction(locals.$template))
373373
locals.$template = $injector.invoke(locals.$template);
374374
}
375-
375+
376376
if(options.autoLoadTemplates && params.templateUrl) {
377377

378378
locals.$template = params.templateUrl;
@@ -387,7 +387,7 @@ mod.provider( '$routeSegment',
387387
}
388388

389389
return $q.all(locals).then(
390-
390+
391391
function(resolvedLocals) {
392392

393393
if(resolvingSemaphoreChain[index] != name)
@@ -432,9 +432,9 @@ mod.provider( '$routeSegment',
432432

433433
return {success: index};
434434
},
435-
435+
436436
function(error) {
437-
437+
438438
if(params.resolveFailed) {
439439
var newResolve = {error: function() { return $q.when(error); }};
440440
return resolve(index, name, angular.extend({resolve: newResolve}, params.resolveFailed));
@@ -459,34 +459,34 @@ mod.provider( '$routeSegment',
459459
index: index,
460460
segment: $routeSegment.chain[index] || null } );
461461
}
462-
462+
463463
function getSegmentInChain(segmentIdx, segmentNameChain) {
464-
465-
if(!segmentNameChain)
466-
return null;
467-
468-
if(segmentIdx >= segmentNameChain.length)
469-
return null;
470-
464+
465+
if(!segmentNameChain)
466+
return null;
467+
468+
if(segmentIdx >= segmentNameChain.length)
469+
return null;
470+
471471
var curSegment = segments, nextName;
472-
for(var i=0;i<=segmentIdx;i++) {
472+
for(var i=0;i<=segmentIdx;i++) {
473473

474474
nextName = segmentNameChain[i];
475475

476476
if(curSegment[ camelCase(nextName) ] != undefined)
477477
curSegment = curSegment[ camelCase(nextName) ];
478-
478+
479479
if(i < segmentIdx)
480480
curSegment = curSegment.children;
481481
}
482-
482+
483483
return {
484484
name: nextName,
485485
params: curSegment.params,
486486
children: curSegment.children
487487
};
488488
}
489-
489+
490490
return $routeSegment;
491491
}];
492492
}]);

0 commit comments

Comments
 (0)