summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/route/route.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-ui/modules/directives/route/route.js')
-rw-r--r--js/vendor/angular-ui/modules/directives/route/route.js68
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();
+ });
+ }
+ }
+ };
+}]);