Skip to content

Commit 985f1ec

Browse files
committed
v1.2.0
1 parent 6d00ccb commit 985f1ec

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

Gruntfile.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ module.exports = function(grunt) {
2727
},
2828

2929
karma: {
30-
once: {
30+
angular115: {
3131
options: {
3232
keepalive: true,
33-
configFile: 'karma.conf.js',
33+
configFile: 'karma-angular-1.1.5.conf.js',
3434
autoWatch: false,
3535
singleRun: true
3636
}
3737
},
38-
keep: {
38+
angular120: {
3939
options: {
4040
keepalive: true,
41-
configFile: 'karma.conf.js',
42-
autoWatch: true,
43-
singleRun: false
44-
}
41+
configFile: 'karma-angular-1.2.0rc1.conf.js',
42+
autoWatch: false,
43+
singleRun: true
44+
}
4545
}
4646
},
4747

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-route-segment",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"main": "build/angular-route-segment.min.js",
55
"ignore": [
66
"**/.*",

build/angular-route-segment.js

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-route-segment v1.1.0
2+
* angular-route-segment v1.2.0
33
* https://angular-route-segment.com
44
* @author Artem Chivchalov
55
* @license MIT License http://opensource.org/licenses/MIT
@@ -212,19 +212,30 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
212212
// if we went back to the same state as we were before resolving new segment
213213
resolvingSemaphoreChain[i] = newSegment.name;
214214
else
215-
updates.push(updateSegment(i, newSegment));
215+
updates.push({index: i, newSegment: newSegment});
216216
}
217217
}
218218

219-
$q.all(updates).then(function(result) {
219+
var curSegmentPromise = $q.when();
220220

221-
$routeSegment.name = segmentName;
222-
$routeSegment.$routeParams = angular.copy($routeParams);
221+
if(updates.length > 0) {
222+
for(var i=0; i<updates.length; i++) {
223+
(function(i) {
224+
curSegmentPromise = curSegmentPromise.then(function() {
223225

224-
for(var i=0; i < result.length; i++) {
225-
if(result[i].success != undefined)
226-
broadcast(result[i].success);
226+
return updateSegment(updates[i].index, updates[i].newSegment);
227+
228+
}).then(function(result) {
229+
230+
if(result.success != undefined) {
231+
broadcast(result.success);
232+
}
233+
})
234+
})(i);
227235
}
236+
}
237+
238+
curSegmentPromise.then(function() {
228239

229240
// Removing redundant segment in case if new segment chain is shorter than old one
230241
if($routeSegment.chain.length > segmentNameChain.length) {
@@ -234,7 +245,8 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
234245
for(var i=segmentNameChain.length; i < oldLength; i++)
235246
updateSegment(i, null);
236247
}
237-
});
248+
})
249+
238250

239251

240252
}
@@ -264,7 +276,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
264276
}
265277

266278
resolvingSemaphoreChain[index] = segment.name;
267-
279+
268280
if(segment.params.untilResolved) {
269281
return resolve(index, segment.name, segment.params.untilResolved)
270282
.then(function(result) {
@@ -354,6 +366,14 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
354366
}
355367

356368
function broadcast(index) {
369+
370+
$routeSegment.$routeParams = angular.copy($routeParams);
371+
372+
$routeSegment.name = '';
373+
for(var i=0; i<$routeSegment.chain.length; i++)
374+
$routeSegment.name += $routeSegment.chain[i].name+".";
375+
$routeSegment.name = $routeSegment.name.substr(0, $routeSegment.name.length-1);
376+
357377
$rootScope.$broadcast( 'routeSegmentChange', {
358378
index: index,
359379
segment: $routeSegment.chain[index] || null } );
@@ -393,20 +413,9 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
393413
})(angular);;'use strict';
394414

395415
/**
396-
* The directive app:view is more powerful replacement of built-in ng:view. It allows views to be nested, where each
397-
* following view in the chain corresponds to the next route segment (see $routeSegment service).
398-
*
399-
* Sample:
400-
* <div>
401-
* <h4>Section</h4>
402-
* <div app:view>Nothing selected</div>
403-
* </div>
404-
*
405-
* Initial contents of an element with app:view will display if corresponding route segment doesn't exist.
406-
*
407-
* View resolving are depends on route segment params:
408-
* - `template` define contents of the view
409-
* - `controller` is attached to view contents when compiled and linked
416+
* appViewSegment directive
417+
* It is based on ngView directive code:
418+
* https://github.com/angular/angular.js/blob/master/src/ngRoute/directive/ngView.js
410419
*/
411420

412421
(function(angular) {
@@ -427,7 +436,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
427436

428437
return function($scope) {
429438

430-
var currentScope, currentElement, onloadExp = tAttrs.onload || '', animate,
439+
var currentScope, currentElement, currentSegment, onloadExp = tAttrs.onload || '', animate,
431440
viewSegmentIndex = parseInt(tAttrs.appViewSegment);
432441

433442
try {
@@ -447,7 +456,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
447456

448457
// Watching for the specified route segment and updating contents
449458
$scope.$on('routeSegmentChange', function(event, args) {
450-
if(args.index == viewSegmentIndex)
459+
if(args.index == viewSegmentIndex && currentSegment != args.segment)
451460
update(args.segment);
452461
});
453462

@@ -467,6 +476,8 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
467476

468477
function update(segment) {
469478

479+
currentSegment = segment;
480+
470481
if(isDefault) {
471482
isDefault = false;
472483
tElement.replaceWith(anchor);
@@ -484,36 +495,31 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
484495
var locals = angular.extend({}, segment.locals),
485496
template = locals && locals.$template;
486497

487-
if (template) {
488-
489-
clearContent();
490-
491-
currentElement = tElement.clone();
492-
currentElement.html(template);
493-
animate.enter( currentElement, null, anchor );
498+
clearContent();
494499

495-
var link = $compile(currentElement, false, 499), controller;
500+
currentElement = tElement.clone();
501+
currentElement.html(template ? template : defaultContent);
502+
animate.enter( currentElement, null, anchor );
496503

497-
currentScope = $scope.$new();
498-
if (segment.params.controller) {
499-
locals.$scope = currentScope;
500-
controller = $controller(segment.params.controller, locals);
501-
if(segment.params.controllerAs)
502-
currentScope[segment.params.controllerAs] = controller;
503-
currentElement.data('$ngControllerController', controller);
504-
currentElement.children().data('$ngControllerController', controller);
505-
}
504+
var link = $compile(currentElement, false, 499), controller;
506505

507-
link(currentScope);
508-
currentScope.$emit('$viewContentLoaded');
509-
currentScope.$eval(onloadExp);
510-
} else {
511-
clearContent();
506+
currentScope = $scope.$new();
507+
if (segment.params.controller) {
508+
locals.$scope = currentScope;
509+
controller = $controller(segment.params.controller, locals);
510+
if(segment.params.controllerAs)
511+
currentScope[segment.params.controllerAs] = controller;
512+
currentElement.data('$ngControllerController', controller);
513+
currentElement.children().data('$ngControllerController', controller);
512514
}
515+
516+
link(currentScope);
517+
currentScope.$emit('$viewContentLoaded');
518+
currentScope.$eval(onloadExp);
513519
}
514520
}
515521
}
516522
}
517523
}]);
518524

519-
})(angular);
525+
})(angular);

build/angular-route-segment.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)