aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js15
-rw-r--r--src/Compiler.js13
-rw-r--r--src/markup.js48
-rw-r--r--src/widgets2.js26
4 files changed, 53 insertions, 49 deletions
diff --git a/src/Angular.js b/src/Angular.js
index dc530921..0c6d081e 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -32,24 +32,13 @@ function extensionMap(angular, name) {
});
}
-function extensionList(angular, name) {
- var extPoint, length = 0;
- return angular[name] || (extPoint = angular[name] = function (fn, prop){
- if (isDefined(fn)) {
- extPoint[length] = extend(fn, prop || {});
- length++;
- }
- return extPoint;
- });
-}
-
var consoleNode, msie,
NOOP = 'noop',
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
slice = Array.prototype.slice,
angular = window['angular'] || (window['angular'] = {}),
- angularTextMarkup = extensionList(angular, 'textMarkup'),
- angularAttrMarkup = extensionList(angular, 'attrMarkup'),
+ angularTextMarkup = extensionMap(angular, 'textMarkup'),
+ angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
angularDirective = extensionMap(angular, 'directive'),
angularWidget = extensionMap(angular, 'widget'),
angularValidator = extensionMap(angular, 'validator'),
diff --git a/src/Compiler.js b/src/Compiler.js
index 4423fcef..47ab0c14 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -120,6 +120,7 @@ Compiler.prototype = {
};
if (widget) {
+ descend = false;
template.addInit(widget.call(selfApi, element));
} else {
// process markup for text nodes only
@@ -152,12 +153,12 @@ Compiler.prototype = {
template.addInit(directive());
});
- // Process non text child nodes
- if (descend) {
- eachNode(element, function(child, i){
- template.addChild(i, self.templatize(child));
- });
- }
+ }
+ // Process non text child nodes
+ if (descend) {
+ eachNode(element, function(child, i){
+ template.addChild(i, self.templatize(child));
+ });
}
return template.empty() ? null : template;
}
diff --git a/src/markup.js b/src/markup.js
index add7ce03..5fb10779 100644
--- a/src/markup.js
+++ b/src/markup.js
@@ -27,30 +27,42 @@ function hasBindings(bindings) {
return bindings.length > 1 || Binder.binding(bindings[0]) !== null;
};
-angularTextMarkup(function(text, textNode, parentElement) {
+angularTextMarkup('{{}}', function(text, textNode, parentElement) {
var bindings = parseBindings(text),
self = this;
- if (isLeafNode(parentElement[0])) {
- parentElement.attr('ng-bind-template', text);
- } else {
- var cursor = textNode, newElement;
- foreach(parseBindings(text), function(text){
- var exp = binding(text);
- if (exp) {
- newElement = self.element('span');
- newElement.attr('ng-bind', exp);
- } else {
- newElement = self.text(text);
- }
- cursor.after(newElement);
- cursor = newElement;
- });
+ if (hasBindings(bindings)) {
+ if (isLeafNode(parentElement[0])) {
+ parentElement.attr('ng-bind-template', text);
+ } else {
+ var cursor = textNode, newElement;
+ foreach(parseBindings(text), function(text){
+ var exp = binding(text);
+ if (exp) {
+ newElement = self.element('span');
+ newElement.attr('ng-bind', exp);
+ } else {
+ newElement = self.text(text);
+ }
+ cursor.after(newElement);
+ cursor = newElement;
+ });
+ }
+ textNode.remove();
+ }
+});
+
+angularTextMarkup('OPTION', function(text, textNode, parentElement){
+ if (parentElement[0].nodeName == "OPTION") {
+ var select = document.createElement('select');
+ select.insertBefore(parentElement[0].cloneNode(true), null);
+ if (!select.innerHTML.match(/<option(\s.*\s|\s)value\s*=\s*.*>.*<\/\s*option\s*>/gi)) {
+ parentElement.attr('value', text);
+ }
}
- textNode.remove();
});
var NG_BIND_ATTR = 'ng-bind-attr';
-angularAttrMarkup(function(value, name, element){
+angularAttrMarkup('{{}}', function(value, name, element){
if (name.substr(0, 3) != 'ng-') {
var bindings = parseBindings(value),
bindAttr;
diff --git a/src/widgets2.js b/src/widgets2.js
index b67694b1..a8d17105 100644
--- a/src/widgets2.js
+++ b/src/widgets2.js
@@ -73,8 +73,8 @@ var NG_ERROR = 'ng-error',
'reset': buttonWidget,
'image': buttonWidget,
'checkbox': inputWidget('click', modelAccessor, checkedAccessor, false),
- 'radio': inputWidget('click', modelAccessor, radioAccessor, undefined)
-// 'select-one': [null, 'change'],
+ 'radio': inputWidget('click', modelAccessor, radioAccessor, undefined),
+ 'select-one': inputWidget('click', modelAccessor, valueAccessor, null)
// 'select-multiple': [[], 'change'],
// 'file': [{}, 'click']
};
@@ -84,9 +84,10 @@ function inputWidget(events, modelAccessor, viewAccessor, initValue) {
var scope = this,
model = modelAccessor(scope, element),
view = viewAccessor(element),
- action = element.attr('ng-action') || '';
- var value = view.get() || initValue;
+ action = element.attr('ng-action') || '',
+ value = view.get() || initValue;
if (isDefined(value)) model.set(value);
+ this.$eval(element.attr('ng-init')||'');
element.bind(events, function(){
model.set(view.get());
scope.$eval(action);
@@ -95,13 +96,14 @@ function inputWidget(events, modelAccessor, viewAccessor, initValue) {
};
}
-angularWidget('INPUT', function input(element){
- return function(element) {
- this.$eval(element.attr('ng-init')||'');
- (INPUT_TYPE[lowercase(element[0].type)] || noop).call(this, element);
- };
-});
+function inputWidgetSelector(element){
+ return INPUT_TYPE[lowercase(element[0].type)] || noop;
+}
-angularWidget('TEXTAREA', function(){
- return textWidget;
+angularWidget('INPUT', inputWidgetSelector);
+angularWidget('TEXTAREA', inputWidgetSelector);
+angularWidget('BUTTON', inputWidgetSelector);
+angularWidget('SELECT', function(element){
+ this.descend(true);
+ return inputWidgetSelector.call(this, element);
});