aboutsummaryrefslogtreecommitdiffstats
path: root/src/directives.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/directives.js')
-rw-r--r--src/directives.js38
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' : '');
+ });
+ };
+});
/////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////