diff options
| author | Misko Hevery | 2010-04-07 14:14:25 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-04-07 14:14:25 -0700 | 
| commit | ab7b7dbf76d25401c4862171b3e54c9748b5098c (patch) | |
| tree | 3cf6892b65f29c57e24f75db892533ce1fff9e5b /src/widgets.js | |
| parent | 29309e0e5a5f5eafd0f948100417d63127d3332d (diff) | |
| download | angular.js-ab7b7dbf76d25401c4862171b3e54c9748b5098c.tar.bz2 | |
ngswitch using
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 24 | 
1 files changed, 21 insertions, 3 deletions
diff --git a/src/widgets.js b/src/widgets.js index 012f13e2..0f781f2c 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -206,10 +206,12 @@ angularWidget('NG:SWITCH', function ngSwitch(element){      this.$watch(watchExpr, function(value){        element.html('');        childScope = null; +      var params = {};        foreach(cases, function(switchCase){ -        if (switchCase.when(childScope, value)) { +        if (switchCase.when(params, value)) {            element.append(switchCase.element);            childScope = createScope(scope); +          extend(childScope, params);            childScope.$tryEval(switchCase.change, element);            switchCase.template(switchCase.element, childScope);            childScope.$init(); @@ -225,7 +227,23 @@ angularWidget('NG:SWITCH', function ngSwitch(element){      return on == when;    },    route: function(on, when) { -    this.name = 'misko'; -    return true; +    var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$', params = [], self = this; +    foreach(when.split(/\W/), function(param){ +      if (param) { +        var paramRegExp = new RegExp(":" + param + "([\\W])"); +        if (regex.match(paramRegExp)) { +          regex = regex.replace(paramRegExp, "(.*)$1"); +          params.push(param); +        } +      } +    }); +    console.log(regex); +    var match = on.match(new RegExp(regex)); +    if (match) { +      foreach(params, function(name, index){ +        self[name] = match[index + 1]; +      }); +    } +    return match;    }  });  | 
