diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-09-09 15:57:10 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-09-09 15:57:18 +0200 |
commit | 2824b43b7332e847810f042c4183ce95ee90e852 (patch) | |
tree | 9a10f31c8acbf01d72336d3d065f8c8fda4b83c5 /js/vendor/angular-ui/modules/directives/route/route.js | |
parent | f0abeddd07fcf21e30c95d58885416ef40d65391 (diff) |
use bower for managing deps
Diffstat (limited to 'js/vendor/angular-ui/modules/directives/route/route.js')
-rw-r--r-- | js/vendor/angular-ui/modules/directives/route/route.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/directives/route/route.js b/js/vendor/angular-ui/modules/directives/route/route.js new file mode 100644 index 000000000..1c2be3c44 --- /dev/null +++ b/js/vendor/angular-ui/modules/directives/route/route.js @@ -0,0 +1,68 @@ +/** + * Set a $uiRoute boolean to see if the current route matches + */ +angular.module('ui.directives').directive('uiRoute', ['$location', '$parse', function ($location, $parse) { + return { + restrict: 'AC', + compile: function(tElement, tAttrs) { + var useProperty; + if (tAttrs.uiRoute) { + useProperty = 'uiRoute'; + } else if (tAttrs.ngHref) { + useProperty = 'ngHref'; + } else if (tAttrs.href) { + useProperty = 'href'; + } else { + throw new Error('uiRoute missing a route or href property on ' + tElement[0]); + } + return function ($scope, elm, attrs) { + var modelSetter = $parse(attrs.ngModel || attrs.routeModel || '$uiRoute').assign; + var watcher = angular.noop; + + // Used by href and ngHref + function staticWatcher(newVal) { + if ((hash = newVal.indexOf('#')) > -1) + newVal = newVal.substr(hash + 1); + watcher = function watchHref() { + modelSetter($scope, ($location.path().indexOf(newVal) > -1)); + }; + watcher(); + } + // Used by uiRoute + function regexWatcher(newVal) { + if ((hash = newVal.indexOf('#')) > -1) + newVal = newVal.substr(hash + 1); + watcher = function watchRegex() { + var regexp = new RegExp('^' + newVal + '$', ['i']); + modelSetter($scope, regexp.test($location.path())); + }; + watcher(); + } + + switch (useProperty) { + case 'uiRoute': + // if uiRoute={{}} this will be undefined, otherwise it will have a value and $observe() never gets triggered + if (attrs.uiRoute) + regexWatcher(attrs.uiRoute); + else + attrs.$observe('uiRoute', regexWatcher); + break; + case 'ngHref': + // Setup watcher() every time ngHref changes + if (attrs.ngHref) + staticWatcher(attrs.ngHref); + else + attrs.$observe('ngHref', staticWatcher); + break; + case 'href': + // Setup watcher() + staticWatcher(attrs.href); + } + + $scope.$on('$routeChangeSuccess', function(){ + watcher(); + }); + } + } + }; +}]); |