Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
artch committed Aug 29, 2013
1 parent 6d00ccb commit 985f1ec
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 59 deletions.
14 changes: 7 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ module.exports = function(grunt) {
},

karma: {
once: {
angular115: {
options: {
keepalive: true,
configFile: 'karma.conf.js',
configFile: 'karma-angular-1.1.5.conf.js',
autoWatch: false,
singleRun: true
}
},
keep: {
angular120: {
options: {
keepalive: true,
configFile: 'karma.conf.js',
autoWatch: true,
singleRun: false
}
configFile: 'karma-angular-1.2.0rc1.conf.js',
autoWatch: false,
singleRun: true
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-route-segment",
"version": "1.1.0",
"version": "1.2.0",
"main": "build/angular-route-segment.min.js",
"ignore": [
"**/.*",
Expand Down
104 changes: 55 additions & 49 deletions build/angular-route-segment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-route-segment v1.1.0
* angular-route-segment v1.2.0
* https://angular-route-segment.com
* @author Artem Chivchalov
* @license MIT License http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -212,19 +212,30 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
// if we went back to the same state as we were before resolving new segment
resolvingSemaphoreChain[i] = newSegment.name;
else
updates.push(updateSegment(i, newSegment));
updates.push({index: i, newSegment: newSegment});
}
}

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

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

for(var i=0; i < result.length; i++) {
if(result[i].success != undefined)
broadcast(result[i].success);
return updateSegment(updates[i].index, updates[i].newSegment);

}).then(function(result) {

if(result.success != undefined) {
broadcast(result.success);
}
})
})(i);
}
}

curSegmentPromise.then(function() {

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



}
Expand Down Expand Up @@ -264,7 +276,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
}

resolvingSemaphoreChain[index] = segment.name;

if(segment.params.untilResolved) {
return resolve(index, segment.name, segment.params.untilResolved)
.then(function(result) {
Expand Down Expand Up @@ -354,6 +366,14 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
}

function broadcast(index) {

$routeSegment.$routeParams = angular.copy($routeParams);

$routeSegment.name = '';
for(var i=0; i<$routeSegment.chain.length; i++)
$routeSegment.name += $routeSegment.chain[i].name+".";
$routeSegment.name = $routeSegment.name.substr(0, $routeSegment.name.length-1);

$rootScope.$broadcast( 'routeSegmentChange', {
index: index,
segment: $routeSegment.chain[index] || null } );
Expand Down Expand Up @@ -393,20 +413,9 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
})(angular);;'use strict';

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

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

return function($scope) {

var currentScope, currentElement, onloadExp = tAttrs.onload || '', animate,
var currentScope, currentElement, currentSegment, onloadExp = tAttrs.onload || '', animate,
viewSegmentIndex = parseInt(tAttrs.appViewSegment);

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

// Watching for the specified route segment and updating contents
$scope.$on('routeSegmentChange', function(event, args) {
if(args.index == viewSegmentIndex)
if(args.index == viewSegmentIndex && currentSegment != args.segment)
update(args.segment);
});

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

function update(segment) {

currentSegment = segment;

if(isDefault) {
isDefault = false;
tElement.replaceWith(anchor);
Expand All @@ -484,36 +495,31 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
var locals = angular.extend({}, segment.locals),
template = locals && locals.$template;

if (template) {

clearContent();

currentElement = tElement.clone();
currentElement.html(template);
animate.enter( currentElement, null, anchor );
clearContent();

var link = $compile(currentElement, false, 499), controller;
currentElement = tElement.clone();
currentElement.html(template ? template : defaultContent);
animate.enter( currentElement, null, anchor );

currentScope = $scope.$new();
if (segment.params.controller) {
locals.$scope = currentScope;
controller = $controller(segment.params.controller, locals);
if(segment.params.controllerAs)
currentScope[segment.params.controllerAs] = controller;
currentElement.data('$ngControllerController', controller);
currentElement.children().data('$ngControllerController', controller);
}
var link = $compile(currentElement, false, 499), controller;

link(currentScope);
currentScope.$emit('$viewContentLoaded');
currentScope.$eval(onloadExp);
} else {
clearContent();
currentScope = $scope.$new();
if (segment.params.controller) {
locals.$scope = currentScope;
controller = $controller(segment.params.controller, locals);
if(segment.params.controllerAs)
currentScope[segment.params.controllerAs] = controller;
currentElement.data('$ngControllerController', controller);
currentElement.children().data('$ngControllerController', controller);
}

link(currentScope);
currentScope.$emit('$viewContentLoaded');
currentScope.$eval(onloadExp);
}
}
}
}
}]);

})(angular);
})(angular);
4 changes: 2 additions & 2 deletions build/angular-route-segment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 985f1ec

Please sign in to comment.