diff options
| author | Misko Hevery | 2010-03-23 14:57:11 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-03-23 14:57:11 -0700 | 
| commit | bb98ae14f2aef74efbd8345e93f62ac67f460f7f (patch) | |
| tree | b50ac4417c7b1bda996dd569069d7eb834eef2ff /src/directives.js | |
| parent | 6ff550cfa9524bbb124d10caf1fc13c911ab3b4b (diff) | |
| download | angular.js-bb98ae14f2aef74efbd8345e93f62ac67f460f7f.tar.bz2 | |
markup now wroks, some refactorings
Diffstat (limited to 'src/directives.js')
| -rw-r--r-- | src/directives.js | 65 | 
1 files changed, 50 insertions, 15 deletions
diff --git a/src/directives.js b/src/directives.js index bbf68669..747da3f5 100644 --- a/src/directives.js +++ b/src/directives.js @@ -18,9 +18,50 @@ angularDirective("ng-bind", function(expression){    };  }); +var bindTemplateCache = {}; +function compileBindTemplate(template){ +  var fn = bindTemplateCache[template]; +  if (!fn) { +    var bindings = []; +    foreach(parseBindings(template), function(text){ +      var exp = binding(text); +      bindings.push(exp ? function(){ +        return this.$eval(exp); +      } : function(){ +        return text; +      }); +    }); +    bindTemplateCache[template] = fn = function(){ +      var parts = [], self = this; +      foreach(bindings, function(fn){ +        parts.push(fn.call(self)); +      }); +      return parts.join(''); +    }; +  } +  return fn; +}; +angularDirective("ng-bind-template", function(expression){ +  var templateFn = compileBindTemplate(expression); +  return function(element) { +    var lastValue; +    this.$addEval(function() { +      var value = templateFn.call(this); +      if (value != lastValue) { +        element.text(value); +        lastValue = value; +      } +    }); +  }; +}); +  angularDirective("ng-bind-attr", function(expression){    return function(element){ -    this.$watch(expression, bind(element, element.attr)); +    this.$addEval(function(){ +      foreach(this.$eval(expression), function(value, key){ +        element.attr(key, compileBindTemplate(value).call(this)); +      }, this); +    });    };  }); @@ -29,7 +70,7 @@ angularDirective("ng-non-bindable", function(){  });  angularDirective("ng-repeat", function(expression, element){ -  var reference = this.reference("ng-repeat: " + expression), +  var reference = this.comment("ng-repeat: " + expression),        r = element.removeAttr('ng-repeat'),        template = this.compile(element),        match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/), @@ -135,18 +176,12 @@ angularDirective("ng-hide", function(expression, element){      });    };  }); -///////////////////////////////////////// -///////////////////////////////////////// -///////////////////////////////////////// -///////////////////////////////////////// -///////////////////////////////////////// - - - - -//widget related -//ng-validate, ng-required, ng-formatter -//ng-error +angularDirective("ng-style", function(expression, element){ +  return function(element){ +    this.$addEval(expression, function(value){ +      element.css(value); +    }); +  }; +}); -//ng-scope ng-controller????  | 
