diff options
| author | Misko Hevery | 2010-03-22 21:29:57 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-03-22 21:29:57 -0700 | 
| commit | 6ff550cfa9524bbb124d10caf1fc13c911ab3b4b (patch) | |
| tree | d76902a8bd2bac2d2064daee7e605ed59e625179 /src/directives.js | |
| parent | a8227086748e37c31c1bb71dec50c96d63c45eef (diff) | |
| download | angular.js-6ff550cfa9524bbb124d10caf1fc13c911ab3b4b.tar.bz2 | |
all angular.js directives now work
Diffstat (limited to 'src/directives.js')
| -rw-r--r-- | src/directives.js | 38 | 
1 files changed, 32 insertions, 6 deletions
diff --git a/src/directives.js b/src/directives.js index adcfa508..bbf68669 100644 --- a/src/directives.js +++ b/src/directives.js @@ -102,13 +102,39 @@ angularDirective("ng-watch", function(expression, element){    };  }); -//Styling -// -//ng-class -//ng-class-odd, ng-class-even -//ng-style -//ng-show, ng-hide +function ngClass(selector) { +  return function(expression, element){ +    var existing = element[0].className + ' '; +    return function(element){ +      this.$addEval(expression, function(value){ +        if (selector(this.$index)) { +          if (isArray(value)) value = value.join(' '); +          element[0].className = (existing + value).replace(/\s\s+/g, ' '); +        } +      }); +    }; +  }; +} + +angularDirective("ng-class", ngClass(function(){return true;})); +angularDirective("ng-class-odd", ngClass(function(i){return i % 2 == 1;})); +angularDirective("ng-class-even", ngClass(function(i){return i % 2 == 0;})); +angularDirective("ng-show", function(expression, element){ +  return function(element){ +    this.$addEval(expression, function(value){ +      element.css('display', toBoolean(value) ? '' : 'none'); +    }); +  }; +}); + +angularDirective("ng-hide", function(expression, element){ +  return function(element){ +    this.$addEval(expression, function(value){ +      element.css('display', toBoolean(value) ? 'none' : ''); +    }); +  }; +});  /////////////////////////////////////////  /////////////////////////////////////////  /////////////////////////////////////////  | 
