From 1f0562150921ea2f05149b64ef0440937491def9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 2 Jul 2010 15:39:47 -0700 Subject: change all attributes from ng- to ng: prefix --- src/Compiler.js | 4 +- src/delete/Binder.js | 76 +++++++++++++++++++------------------- src/delete/Widgets.js | 4 +- src/directives.js | 40 ++++++++++---------- src/markups.js | 28 +++++++------- src/moveToAngularCom/ControlBar.js | 4 +- src/widgets.js | 8 ++-- 7 files changed, 82 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/Compiler.js b/src/Compiler.js index c8910c27..9faafb13 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -121,7 +121,7 @@ Compiler.prototype = { descend: function(value){ if(isDefined(value)) descend = value; return descend;}, directives: function(value){ if(isDefined(value)) directives = value; return directives;} }; - priority = element.attr('ng-eval-order') || priority || 0; + priority = element.attr('ng:eval-order') || priority || 0; if (isString(priority)) { priority = PRIORITY[uppercase(priority)] || 0; } @@ -200,7 +200,7 @@ function eachAttribute(element, fn){ var i, attrs = element[0].attributes || [], chld, attr, name, value, attrValue = {}; for (i = 0; i < attrs.length; i++) { attr = attrs[i]; - name = attr.name.replace(':', '-'); + name = attr.name; value = attr.value; if (msie && name == 'href') { value = decodeURIComponent(element[0].getAttribute(name, 2)); diff --git a/src/delete/Binder.js b/src/delete/Binder.js index 9fc32513..095e2b08 100644 --- a/src/delete/Binder.js +++ b/src/delete/Binder.js @@ -112,24 +112,24 @@ Binder.prototype = { }, executeInit: function() { - this.docFindWithSelf("[ng-init]").each(function() { + this.docFindWithSelf("[ng:init]").each(function() { var jThis = jQuery(this); var scope = jThis.scope(); try { - scope.eval(jThis.attr('ng-init')); + scope.eval(jThis.attr('ng:init')); } catch (e) { - alert("EVAL ERROR:\n" + jThis.attr('ng-init') + '\n' + toJson(e, true)); + alert("EVAL ERROR:\n" + jThis.attr('ng:init') + '\n' + toJson(e, true)); } }); }, entity: function (scope) { var self = this; - this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() { + this.docFindWithSelf("[ng-entity]").attr("ng:watch", function() { try { var jNode = jQuery(this); var decl = scope.entity(jNode.attr("ng-entity"), self.datastore); - return decl + (jNode.attr('ng-watch') || ""); + return decl + (jNode.attr('ng:watch') || ""); } catch (e) { log(e); alert(e); @@ -142,7 +142,7 @@ Binder.prototype = { if (this.config['autoSubmit']) { var submits = this.docFindWithSelf(":submit").not("[ng-action]"); submits.attr("ng-action", "$save()"); - submits.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", '{disabled:"{{$invalidWidgets}}"}'); + submits.not(":disabled").not("ng:bind-attr").attr("ng:bind-attr", '{disabled:"{{$invalidWidgets}}"}'); } this.precompile(this.doc)(this.doc, jNode.scope(), ""); this.docFindWithSelf("a[ng-action]").live('click', function (event) { @@ -168,9 +168,9 @@ Binder.prototype = { if (parts.length > 1 || Binder.binding(parts[0])) { var parent = node.parentNode; if (isLeafNode(parent)) { - parent.setAttribute('ng-bind-template', node.nodeValue); + parent.setAttribute('ng:bind-template', node.nodeValue); factories.push({path:path, fn:function(node, scope, prefix) { - return new BindUpdater(node, node.getAttribute('ng-bind-template')); + return new BindUpdater(node, node.getAttribute('ng:bind-template')); }}); } else { for (var i = 0; i < parts.length; i++) { @@ -180,7 +180,7 @@ Binder.prototype = { if (binding) { newNode = document.createElement("span"); var jNewNode = jQuery(newNode); - jNewNode.attr("ng-bind", binding); + jNewNode.attr("ng:bind", binding); if (i === 0) { factories.push({path:path.concat(offset + i), fn:this.ng_bind}); } @@ -228,13 +228,13 @@ Binder.prototype = { } if (!node.getAttribute) return; - var nonBindable = node.getAttribute('ng-non-bindable'); + var nonBindable = node.getAttribute('ng:non-bindable'); if (nonBindable || nonBindable === "") return; var attributes = node.attributes; if (attributes) { - var bindings = node.getAttribute('ng-bind-attr'); - node.removeAttribute('ng-bind-attr'); + var bindings = node.getAttribute('ng:bind-attr'); + node.removeAttribute('ng:bind-attr'); bindings = bindings ? fromJson(bindings) : {}; var attrLen = attributes.length; for (var i = 0; i < attrLen; i++) { @@ -249,23 +249,23 @@ Binder.prototype = { } var json = toJson(bindings); if (json.length > 2) { - node.setAttribute("ng-bind-attr", json); + node.setAttribute("ng:bind-attr", json); } } if (!node.getAttribute) log(node); - var repeaterExpression = node.getAttribute('ng-repeat'); + var repeaterExpression = node.getAttribute('ng:repeat'); if (repeaterExpression) { - node.removeAttribute('ng-repeat'); + node.removeAttribute('ng:repeat'); var precompiled = this.precompile(node); - var view = document.createComment("ng-repeat: " + repeaterExpression); + var view = document.createComment("ng:repeat: " + repeaterExpression); var parentNode = node.parentNode; parentNode.insertBefore(view, node); parentNode.removeChild(node); function template(childScope, prefix, i) { var clone = jQuery(node).clone(); clone.css('display', ''); - clone.attr('ng-repeat-index', "" + i); + clone.attr('ng:repeat-index', "" + i); clone.data('scope', childScope); precompiled(clone[0], childScope, prefix + i + ":"); return clone; @@ -276,16 +276,16 @@ Binder.prototype = { return; } - if (node.getAttribute('ng-eval')) factories.push({path:path, fn:this.ng_eval}); - if (node.getAttribute('ng-bind')) factories.push({path:path, fn:this.ng_bind}); - if (node.getAttribute('ng-bind-attr')) factories.push({path:path, fn:this.ng_bind_attr}); - if (node.getAttribute('ng-hide')) factories.push({path:path, fn:this.ng_hide}); - if (node.getAttribute('ng-show')) factories.push({path:path, fn:this.ng_show}); - if (node.getAttribute('ng-class')) factories.push({path:path, fn:this.ng_class}); - if (node.getAttribute('ng-class-odd')) factories.push({path:path, fn:this.ng_class_odd}); - if (node.getAttribute('ng-class-even')) factories.push({path:path, fn:this.ng_class_even}); - if (node.getAttribute('ng-style')) factories.push({path:path, fn:this.ng_style}); - if (node.getAttribute('ng-watch')) factories.push({path:path, fn:this.ng_watch}); + if (node.getAttribute('ng:eval')) factories.push({path:path, fn:this.ng_eval}); + if (node.getAttribute('ng:bind')) factories.push({path:path, fn:this.ng_bind}); + if (node.getAttribute('ng:bind-attr')) factories.push({path:path, fn:this.ng_bind_attr}); + if (node.getAttribute('ng:hide')) factories.push({path:path, fn:this.ng_hide}); + if (node.getAttribute('ng:show')) factories.push({path:path, fn:this.ng_show}); + if (node.getAttribute('ng:class')) factories.push({path:path, fn:this.ng_class}); + if (node.getAttribute('ng:class-odd')) factories.push({path:path, fn:this.ng_class_odd}); + if (node.getAttribute('ng:class-even')) factories.push({path:path, fn:this.ng_class_even}); + if (node.getAttribute('ng:style')) factories.push({path:path, fn:this.ng_style}); + if (node.getAttribute('ng:watch')) factories.push({path:path, fn:this.ng_watch}); var nodeName = node.nodeName; if ((nodeName == 'INPUT' ) || nodeName == 'TEXTAREA' || @@ -301,7 +301,7 @@ Binder.prototype = { var html = jQuery('' + + '' + '' + '' + '' + @@ -640,7 +640,7 @@ function RepeaterUpdater(view, repeaterExpression, template, prefix) { this.children = []; var match = repeaterExpression.match(/^\s*(.+)\s+in\s+(.*)\s*$/); if (! match) { - throw "Expected ng-repeat in form of 'item in collection' but got '" + + throw "Expected ng:repeat in form of 'item in collection' but got '" + repeaterExpression + "'."; } var keyValue = match[1]; diff --git a/src/directives.js b/src/directives.js index cabf0c23..1b422331 100644 --- a/src/directives.js +++ b/src/directives.js @@ -1,10 +1,10 @@ -angularDirective("ng-init", function(expression){ +angularDirective("ng:init", function(expression){ return function(element){ this.$tryEval(expression, element); }; }); -angularDirective("ng-controller", function(expression){ +angularDirective("ng:controller", function(expression){ return function(element){ var controller = getter(window, expression, true) || getter(this, expression, true); if (!controller) @@ -16,13 +16,13 @@ angularDirective("ng-controller", function(expression){ }; }); -angularDirective("ng-eval", function(expression){ +angularDirective("ng:eval", function(expression){ return function(element){ this.$onEval(expression, element); }; }); -angularDirective("ng-bind", function(expression){ +angularDirective("ng:bind", function(expression){ return function(element) { var lastValue = noop, lastError = noop; this.$onEval(function() { @@ -89,7 +89,7 @@ function compileBindTemplate(template){ return fn; } -angularDirective("ng-bind-template", function(expression){ +angularDirective("ng:bind-template", function(expression){ var templateFn = compileBindTemplate(expression); return function(element) { var lastValue; @@ -108,7 +108,7 @@ var REMOVE_ATTRIBUTES = { 'readonly':'readOnly', 'checked':'checked' }; -angularDirective("ng-bind-attr", function(expression){ +angularDirective("ng:bind-attr", function(expression){ return function(element){ var lastValue = {}; this.$onEval(function(){ @@ -134,17 +134,17 @@ angularDirective("ng-bind-attr", function(expression){ }; }); -angularWidget("@ng-non-bindable", noop); +angularWidget("@ng:non-bindable", noop); -angularWidget("@ng-repeat", function(expression, element){ - element.removeAttr('ng-repeat'); - element.replaceWith(this.comment("ng-repeat: " + expression)); +angularWidget("@ng:repeat", function(expression, element){ + element.removeAttr('ng:repeat'); + element.replaceWith(this.comment("ng:repeat: " + expression)); var template = this.compile(element); return function(reference){ var match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/), lhs, rhs, valueIdent, keyIdent; if (! match) { - throw "Expected ng-repeat in form of 'item in collection' but got '" + + throw "Expected ng:repeat in form of 'item in collection' but got '" + expression + "'."; } lhs = match[1]; @@ -176,7 +176,7 @@ angularWidget("@ng-repeat", function(expression, element){ if (keyIdent) childScope[keyIdent] = key; lastElement.after(childScope.$element); childScope.$index = index; - childScope.$element.attr('ng-repeat-index', index); + childScope.$element.attr('ng:repeat-index', index); childScope.$init(); children.push(childScope); } @@ -192,7 +192,7 @@ angularWidget("@ng-repeat", function(expression, element){ }; }); -angularDirective("ng-click", function(expression, element){ +angularDirective("ng:click", function(expression, element){ return function(element){ var self = this; element.bind('click', function(){ @@ -203,7 +203,7 @@ angularDirective("ng-click", function(expression, element){ }; }); -angularDirective("ng-watch", function(expression, element){ +angularDirective("ng:watch", function(expression, element){ return function(element){ var self = this; new Parser(expression).watch()({ @@ -231,11 +231,11 @@ function ngClass(selector) { }; } -angularDirective("ng-class", ngClass(function(){return true;})); -angularDirective("ng-class-odd", ngClass(function(i){return i % 2 === 0;})); -angularDirective("ng-class-even", ngClass(function(i){return i % 2 === 1;})); +angularDirective("ng:class", ngClass(function(){return true;})); +angularDirective("ng:class-odd", ngClass(function(i){return i % 2 === 0;})); +angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;})); -angularDirective("ng-show", function(expression, element){ +angularDirective("ng:show", function(expression, element){ return function(element){ this.$onEval(function(){ element.css('display', toBoolean(this.$eval(expression)) ? '' : 'none'); @@ -243,7 +243,7 @@ angularDirective("ng-show", function(expression, element){ }; }); -angularDirective("ng-hide", function(expression, element){ +angularDirective("ng:hide", function(expression, element){ return function(element){ this.$onEval(function(){ element.css('display', toBoolean(this.$eval(expression)) ? 'none' : ''); @@ -251,7 +251,7 @@ angularDirective("ng-hide", function(expression, element){ }; }); -angularDirective("ng-style", function(expression, element){ +angularDirective("ng:style", function(expression, element){ return function(element){ this.$onEval(function(){ element.css(this.$eval(expression)); diff --git a/src/markups.js b/src/markups.js index 74b293b8..ac2b5636 100644 --- a/src/markups.js +++ b/src/markups.js @@ -32,14 +32,14 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) { self = this; if (hasBindings(bindings)) { if (isLeafNode(parentElement[0])) { - parentElement.attr('ng-bind-template', text); + 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); + newElement.attr('ng:bind', exp); } else { newElement = self.text(text); } @@ -68,18 +68,18 @@ angularTextMarkup('OPTION', function(text, textNode, parentElement){ } }); -var NG_BIND_ATTR = 'ng-bind-attr'; +var NG_BIND_ATTR = 'ng:bind-attr'; angularAttrMarkup('{{}}', function(value, name, element){ - if (name.substr(0, 3) != 'ng-') { - if (msie && name == 'src') - value = decodeURI(value); - var bindings = parseBindings(value), - bindAttr; - if (hasBindings(bindings)) { - element.removeAttr(name); - bindAttr = fromJson(element.attr(NG_BIND_ATTR) || "{}"); - bindAttr[name] = value; - element.attr(NG_BIND_ATTR, toJson(bindAttr)); - } + // don't process existing attribute markup + if (angularDirective(name) || angularDirective("@" + name)) return; + if (msie && name == 'src') + value = decodeURI(value); + var bindings = parseBindings(value), + bindAttr; + if (hasBindings(bindings)) { + element.removeAttr(name); + bindAttr = fromJson(element.attr(NG_BIND_ATTR) || "{}"); + bindAttr[name] = value; + element.attr(NG_BIND_ATTR, toJson(bindAttr)); } }); diff --git a/src/moveToAngularCom/ControlBar.js b/src/moveToAngularCom/ControlBar.js index 685beeb2..b9a2de8a 100644 --- a/src/moveToAngularCom/ControlBar.js +++ b/src/moveToAngularCom/ControlBar.js @@ -9,14 +9,14 @@ function ControlBar(document, serverUrl, database) { ControlBar.HTML = '
' + '
' + - '
' + + '
' + '' + '
' + '
'; ControlBar.FORBIDEN = - '
' + + '
' + 'Sorry, you do not have permission for this!'+ '
'; diff --git a/src/widgets.js b/src/widgets.js index efafa9c5..94f09c7b 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -196,7 +196,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) { action = element.attr('ng-change') || '', lastValue; initFn.call(scope, model, view, element); - this.$eval(element.attr('ng-init')||''); + this.$eval(element.attr('ng:init')||''); // Don't register a handler if we are a button (noopAccessor) and there is no action if (action || modelAccessor !== noopAccessor) { element.bind(events, function(){ @@ -236,11 +236,11 @@ angularWidget('NG:INCLUDE', function(element){ var compiler = this, srcExp = element.attr("src"), scopeExp = element.attr("scope") || ''; - if (element[0]['ng-compiled']) { + if (element[0]['ng:compiled']) { this.descend(true); this.directives(true); } else { - element[0]['ng-compiled'] = true; + element[0]['ng:compiled'] = true; return function(element){ var scope = this, childScope; var changeCounter = 0; @@ -276,7 +276,7 @@ var ngSwitch = angularWidget('NG:SWITCH', function (element){ cases = []; if (!usingFn) throw "Using expression '" + usingExpr + "' unknown."; eachNode(element, function(caseElement){ - var when = caseElement.attr('ng-switch-when'); + var when = caseElement.attr('ng:switch-when'); if (when) { cases.push({ when: function(scope, value){ -- cgit v1.2.3 From b5195b8f67b143d6c38de9ae2295cb364fab0d95 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 2 Jul 2010 17:26:26 -0700 Subject: changed the eval for ie to be able to return a function --- src/Scope.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Scope.js b/src/Scope.js index e9b61ec4..b45efbce 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -72,8 +72,8 @@ function getterFn(path){ } }); code += ' return self;\n}'; - fn = eval('(' + code + ')'); - fn.toString = function(){ return code; }; + fn = eval('fn = ' + code); + fn["toString"] = function(){ return code; }; return getterFnCache[path] = fn; } -- cgit v1.2.3 From ee82dae3186b7a4fc4d339fc97d5792b2b5e2648 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Jul 2010 10:40:54 -0700 Subject: added class as a constant keyword to generated code --- src/Scope.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Scope.js b/src/Scope.js index b45efbce..35da77fe 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -46,7 +46,14 @@ function setter(instance, path, value){ /////////////////////////////////// var getterFnCache = {}; -var JS_KEYWORDS = ["this", "throw", "for", "foreach", "var", "const"]; +var JS_KEYWORDS = {}; +foreach( + ["break", "const", "continue", "class", "delete", + "do", "while", "for", "function", "if", + "instanceof", "new", "return", "switch", + "this", "throw", "try", "catch", "with"], + function(key){ JS_KEYWORDS[key] = true;} +); function getterFn(path){ var fn = getterFnCache[path]; if (fn) return fn; @@ -54,7 +61,7 @@ function getterFn(path){ var code = 'function (self){\n'; code += ' var last, fn, type;\n'; foreach(path.split('.'), function(key) { - key = (includes(JS_KEYWORDS, key)) ? '["' + key + '"]' : '.' + key; + key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key; code += ' if(!self) return self;\n'; code += ' last = self;\n'; code += ' self = self' + key + ';\n'; -- cgit v1.2.3 From 00bb79039251ca6e4622df677fe4894552774bd5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Jul 2010 15:55:00 -0700 Subject: fixed IE tests --- src/scenario/DSL.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 194a28d6..b713cfd6 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -35,9 +35,8 @@ angular.scenario.dsl.input = function(selector) { value + "'", function(done){ var input = this.testDocument. find(':radio[name$=@' + selector + '][value=' + value + ']'); - var event = this.testWindow.document.createEvent('MouseEvent'); - event.initMouseEvent('click', true, true, this.testWindow, 0,0,0,0,0, false, false, false, false, 0, null); - input[0].dispatchEvent(event); + jqLiteWrap(input[0]).trigger('click'); + input[0].checked = true; done(); }); } -- cgit v1.2.3 From 228b54aa2ea9c5faf9280f39317fdf07b2d49580 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 9 Jul 2010 14:45:29 -0700 Subject: ng:repeat ignores prototype keys --- src/directives.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index 1b422331..a333c4c4 100644 --- a/src/directives.js +++ b/src/directives.js @@ -162,8 +162,9 @@ angularWidget("@ng:repeat", function(expression, element){ var children = [], currentScope = this; this.$onEval(function(){ var index = 0, childCount = children.length, childScope, lastElement = reference, - collection = this.$tryEval(rhs, reference); + collection = this.$tryEval(rhs, reference), is_array = isArray(collection); for ( var key in collection) { + if (is_array && !collection.hasOwnProperty(key)) break; if (index < childCount) { // reuse existing child childScope = children[index]; -- cgit v1.2.3 From 87cfc27be331685043ea2a4414eba4fd8fbb4a2c Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 13 Jul 2010 11:20:11 -0700 Subject: changed remaining ng- to ng: --- src/delete/Widgets.js | 6 +++--- src/filters.js | 2 +- src/widgets.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/delete/Widgets.js b/src/delete/Widgets.js index d2f0c75a..53536ed0 100644 --- a/src/delete/Widgets.js +++ b/src/delete/Widgets.js @@ -19,7 +19,7 @@ WidgetFactory.prototype = { if (exp) exp = exp.split(':').pop(); var event = "change"; var bubbleEvent = true; - var formatter = angularFormatter[input.attr('ng-format')] || angularFormatter['noop']; + var formatter = angularFormatter[input.attr('ng:format')] || angularFormatter['noop']; if (type == 'button' || type == 'submit' || type == 'reset' || type == 'image') { controller = new ButtonController(input[0], exp, formatter); event = "click"; @@ -191,8 +191,8 @@ function TextController(view, exp, formatter) { this.view = view; this.formatter = formatter; this.exp = exp; - this.validator = view.getAttribute('ng-validate'); - this.required = typeof view.attributes['ng-required'] != "undefined"; + this.validator = view.getAttribute('ng:validate'); + this.required = typeof view.attributes['ng:required'] != "undefined"; this.lastErrorText = null; this.lastValue = undefined; this.initialValue = this.formatter['parse'](view.value); diff --git a/src/filters.js b/src/filters.js index a911b935..24464477 100644 --- a/src/filters.js +++ b/src/filters.js @@ -2,7 +2,7 @@ var angularFilterGoogleChartApi; foreach({ 'currency': function(amount){ - this.$element.toggleClass('ng-format-negative', amount < 0); + this.$element.toggleClass('ng:format-negative', amount < 0); return '$' + angularFilter['number'].apply(this, [amount, 2]); }, diff --git a/src/widgets.js b/src/widgets.js index 94f09c7b..ebfcc456 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -15,7 +15,7 @@ function modelAccessor(scope, element) { function modelFormattedAccessor(scope, element) { var accessor = modelAccessor(scope, element), - formatterName = element.attr('ng-format') || NOOP, + formatterName = element.attr('ng:format') || NOOP, formatter = angularFormatter(formatterName); if (!formatter) throw "Formatter named '" + formatterName + "' not found."; return { @@ -33,10 +33,10 @@ function compileValidator(expr) { } function valueAccessor(scope, element) { - var validatorName = element.attr('ng-validate') || NOOP, + var validatorName = element.attr('ng:validate') || NOOP, validator = compileValidator(validatorName), - requiredExpr = element.attr('ng-required'), - formatterName = element.attr('ng-format') || NOOP, + requiredExpr = element.attr('ng:required'), + formatterName = element.attr('ng:format') || NOOP, formatter = angularFormatter(formatterName), format, parse, lastError, required; invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop}; -- cgit v1.2.3 From 4034a2d1e2efb6c76020273c96c3da5ae146f5ca Mon Sep 17 00:00:00 2001 From: Rob Spies Date: Tue, 13 Jul 2010 14:09:53 -0700 Subject: better naming for our verify cache scheme, and tests. --- src/Resource.js | 9 +++++---- src/services.js | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Resource.js b/src/Resource.js index ba460c30..1279dc54 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -1,3 +1,5 @@ + + function Route(template, defaults) { this.template = template = template + '#'; this.defaults = defaults || {}; @@ -86,7 +88,7 @@ ResourceFactory.prototype = { throw "Expected between 0-3 arguments [params, data, callback], got " + arguments.length + " arguments."; } - var value = action.isArray ? [] : new Resource(data;) + var value = action.isArray ? [] : new Resource(data) self.xhr( action.method, route.url(extend({}, action.params || {}, extractParams(data), params)), @@ -94,8 +96,7 @@ ResourceFactory.prototype = { function(status, response, clear) { if (status == 200) { if (action.isArray) { - if (action.cacheThenRetrieve) - value = []; + value.length = 0; foreach(response, function(item){ value.push(new Resource(item)); }); @@ -107,7 +108,7 @@ ResourceFactory.prototype = { throw {status: status, response:response, message: status + ": " + response}; } }, - action.cacheThenRetrieve + action.verifyCache ); return value; }; diff --git a/src/services.js b/src/services.js index 64f2ea4f..ed6f73ad 100644 --- a/src/services.js +++ b/src/services.js @@ -313,7 +313,7 @@ angularService('$xhr.bulk', function($xhr, $error, $log){ angularService('$xhr.cache', function($xhr){ var inflight = {}, self = this;; - function cache(method, url, post, callback, cacheThenRetrieve){ + function cache(method, url, post, callback, verifyCache){ if (isFunction(post)) { callback = post; post = null; @@ -322,7 +322,7 @@ angularService('$xhr.cache', function($xhr){ var data; if (data = cache.data[url]) { callback(200, copy(data.value)); - if (!cacheThenRetrieve) + if (!verifyCache) return; } -- cgit v1.2.3 From 10cd9751ea4c76f5f0ebcd0197054b6ac3be563c Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 13 Jul 2010 15:21:42 -0700 Subject: ng-change ng:change --- src/widgets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets.js b/src/widgets.js index ebfcc456..0b77dbf4 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -193,7 +193,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) { var scope = this, model = modelAccessor(scope, element), view = viewAccessor(scope, element), - action = element.attr('ng-change') || '', + action = element.attr('ng:change') || '', lastValue; initFn.call(scope, model, view, element); this.$eval(element.attr('ng:init')||''); -- cgit v1.2.3 From 0a57273f0000421639c926d4d180680e3a64c0f7 Mon Sep 17 00:00:00 2001 From: Kai Compagner Date: Thu, 15 Jul 2010 03:08:55 +0800 Subject: fix undefine style --- src/directives.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index a333c4c4..6b81d864 100644 --- a/src/directives.js +++ b/src/directives.js @@ -255,7 +255,7 @@ angularDirective("ng:hide", function(expression, element){ angularDirective("ng:style", function(expression, element){ return function(element){ this.$onEval(function(){ - element.css(this.$eval(expression)); + element.css(this.$eval(expression) || {}); }, element); }; }); -- cgit v1.2.3 From e3e9ac86750b20fb8ad6765011e06d569899612d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 14 Jul 2010 17:07:23 -0700 Subject: ng:style remembers previous style and properly resets to it --- src/directives.js | 11 ++++++++++- src/jqLite.js | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index 6b81d864..4e7c070b 100644 --- a/src/directives.js +++ b/src/directives.js @@ -254,8 +254,17 @@ angularDirective("ng:hide", function(expression, element){ angularDirective("ng:style", function(expression, element){ return function(element){ + var resetStyle = element.css(); this.$onEval(function(){ - element.css(this.$eval(expression) || {}); + var style = this.$eval(expression) || {}, key, mergedStyle = {}; + for(key in style) { + if (typeof resetStyle[key] == 'undefined') resetStyle[key] = null; + mergedStyle[key] = style[key]; + } + for(key in resetStyle) { + mergedStyle[key] = mergedStyle[key] || resetStyle[key]; + } + element.css(mergedStyle); }, element); }; }); diff --git a/src/jqLite.js b/src/jqLite.js index 68172fd8..a024507f 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -175,8 +175,15 @@ JQLite.prototype = { } else { return style[name]; } - } else { + } else if(name) { extend(style, name); + } else { + var current = {}; + for (var i=0; i undefined --- src/Parser.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Parser.js b/src/Parser.js index df270792..5c2307e4 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -602,6 +602,8 @@ Parser.prototype = { var fnPtr = fn(self); if (typeof fnPtr === 'function') { return fnPtr.apply(self, args); + } else if (fnPtr === undefined) { + return fnPtr; } else { throw "Expression '" + fn.isAssignable + "' is not a function."; } -- cgit v1.2.3 From 748e91ba92af4a85de3579be504914092381c7e1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 11:38:52 -0700 Subject: fixed some of the IE bugs --- src/Browser.js | 1 - src/services.js | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Browser.js b/src/Browser.js index 2777dcda..3299540c 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -22,7 +22,6 @@ function Browser(location, document, head) { this.location = location; this.document = document; - this.body = jqLite(document[0].body); this.head = head; this.idCounter = 0; } diff --git a/src/services.js b/src/services.js index c9799b32..89cca6fc 100644 --- a/src/services.js +++ b/src/services.js @@ -75,8 +75,8 @@ angularService("$log", function($window){ }; }, {inject:['$window']}); -angularService("$hover", function(browser) { - var tooltip, self = this, error, width = 300, arrowWidth = 10; +angularService("$hover", function(browser, document) { + var tooltip, self = this, error, width = 300, arrowWidth = 10, body = jqLite(document[0].body);; browser.hover(function(element, show){ if (show && (error = element.attr(NG_EXCEPTION) || element.attr(NG_VALIDATION_ERROR))) { if (!tooltip) { @@ -89,9 +89,9 @@ angularService("$hover", function(browser) { tooltip.callout.append(tooltip.arrow); tooltip.callout.append(tooltip.title); tooltip.callout.append(tooltip.content); - self.$browser.body.append(tooltip.callout); + body.append(tooltip.callout); } - var docRect = self.$browser.body[0].getBoundingClientRect(), + var docRect = body[0].getBoundingClientRect(), elementRect = element[0].getBoundingClientRect(), leftSpace = docRect.right - elementRect.right - arrowWidth; tooltip.title.text(element.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error..."); @@ -119,7 +119,7 @@ angularService("$hover", function(browser) { tooltip = null; } }); -}, {inject:['$browser']}); +}, {inject:['$browser', '$document']}); angularService("$invalidWidgets", function(){ var invalidWidgets = []; -- cgit v1.2.3 From 1a730a9996f6a1ec420e23e5dae0b863b9c7ba12 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 11:46:04 -0700 Subject: fixed some of the IE bugs --- src/Browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Browser.js b/src/Browser.js index 3299540c..3287cf0e 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -67,7 +67,7 @@ Browser.prototype = { script.src = url.replace('JSON_CALLBACK', callbackId); this.head.append(script); window[callbackId] = function(data){ - delete window[callbackId]; + window[callbackId] = undefined; callback(200, data); }; } else { -- cgit v1.2.3 From 2ac66b78f0d2068166c617e6e82d038ac4d46f0a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 12:01:59 -0700 Subject: minor per improvement --- src/directives.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index 3e0aeffb..32b012f3 100644 --- a/src/directives.js +++ b/src/directives.js @@ -224,8 +224,8 @@ function ngClass(selector) { var existing = element[0].className + ' '; return function(element){ this.$onEval(function(){ - var value = this.$eval(expression); if (selector(this.$index)) { + var value = this.$eval(expression); if (isArray(value)) value = value.join(' '); element[0].className = trim(existing + value); } -- cgit v1.2.3 From 3b41979891f5dc6a68e05cd5ed9c355c34774193 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 13:36:08 -0700 Subject: fix bug which only showed up in ie7 --- src/directives.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index 32b012f3..ffe37890 100644 --- a/src/directives.js +++ b/src/directives.js @@ -166,26 +166,27 @@ angularWidget("@ng:repeat", function(expression, element){ var index = 0, childCount = children.length, childScope, lastElement = reference, collection = this.$tryEval(rhs, reference), is_array = isArray(collection); for ( var key in collection) { - if (is_array && !collection.hasOwnProperty(key)) break; - if (index < childCount) { - // reuse existing child - childScope = children[index]; - childScope[valueIdent] = collection[key]; - if (keyIdent) childScope[keyIdent] = key; - } else { - // grow children - childScope = template(element.clone(), createScope(currentScope)); - childScope[valueIdent] = collection[key]; - if (keyIdent) childScope[keyIdent] = key; - lastElement.after(childScope.$element); - childScope.$index = index; - childScope.$element.attr('ng:repeat-index', index); - childScope.$init(); - children.push(childScope); + if (!is_array || collection.hasOwnProperty(key)) { + if (index < childCount) { + // reuse existing child + childScope = children[index]; + childScope[valueIdent] = collection[key]; + if (keyIdent) childScope[keyIdent] = key; + } else { + // grow children + childScope = template(element.clone(), createScope(currentScope)); + childScope[valueIdent] = collection[key]; + if (keyIdent) childScope[keyIdent] = key; + lastElement.after(childScope.$element); + childScope.$index = index; + childScope.$element.attr('ng:repeat-index', index); + childScope.$init(); + children.push(childScope); + } + childScope.$eval(); + lastElement = childScope.$element; + index ++; } - childScope.$eval(); - lastElement = childScope.$element; - index ++; }; // shrink children while(children.length > index) { -- cgit v1.2.3 From b288cb08b450cd28423595de82693631cc6d6dda Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 26 Jul 2010 15:32:08 -0700 Subject: minor performance improvements --- src/Angular.js | 18 ++++++++++-------- src/Compiler.js | 4 +++- src/Scope.js | 9 ++++++--- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 404d241d..850fe34c 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -16,7 +16,7 @@ var consoleNode, msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)), jqLite = jQuery || jqLiteWrap, slice = Array.prototype.slice, - error = window['console'] ? bind(window['console'], window['console']['error']) : noop, + error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop, angular = window['angular'] || (window['angular'] = {}), angularTextMarkup = extensionMap(angular, 'textMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'), @@ -292,12 +292,14 @@ function escapeAttr(html) { } function bind(_this, _function) { - if (!isFunction(_function)) - throw "Not a function!"; var curryArgs = slice.call(arguments, 2, arguments.length); - return function() { - return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length))); - }; + return curryArgs.length == 0 ? + function() { + return _function.apply(_this, arguments); + } : + function() { + return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length))); + }; } function outerHTML(node) { @@ -331,12 +333,12 @@ function merge(src, dst) { } } -function compile(element, parentScope, overrides) { +function compile(element, parentScope) { var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget), $element = jqLite(element), parent = extend({}, parentScope); parent.$element = $element; - return compiler.compile($element)($element, parent, overrides); + return compiler.compile($element)($element, parent); } ///////////////////////////////////////////////// diff --git a/src/Compiler.js b/src/Compiler.js index a6fd88ec..bcf1f61a 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -30,7 +30,9 @@ Template.prototype = { element = jqLite(element); foreach(this.inits, function(fn) { queue.push(function(scope) { - scope.$tryEval(fn, element, element); + scope.$tryEval(function(){ + return fn.call(scope, element); + }, element); }); }); diff --git a/src/Scope.js b/src/Scope.js index 549cc944..6b011936 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -131,7 +131,7 @@ function createScope(parent, services, existing) { $eval: function $eval(exp) { if (exp !== undefined) { - return expressionCompile(exp).apply(instance, slice.call(arguments, 1, arguments.length)); + return expressionCompile(exp).call(instance); } else { for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) { for ( var queue = evalLists.sorted[i], @@ -145,7 +145,7 @@ function createScope(parent, services, existing) { $tryEval: function (expression, exceptionHandler) { try { - return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length)); + return expressionCompile(expression).call(instance); } catch (e) { (instance.$log || {error:error}).error(e); if (isFunction(exceptionHandler)) { @@ -161,12 +161,15 @@ function createScope(parent, services, existing) { $watch: function(watchExp, listener, exceptionHandler) { var watch = expressionCompile(watchExp), last; + listener = expressionCompile(listener); function watcher(){ var value = watch.call(instance), lastValue = last; if (last !== value) { last = value; - instance.$tryEval(listener, exceptionHandler, value, lastValue); + instance.$tryEval(function(){ + return listener.call(instance, value, lastValue); + }, exceptionHandler); } } instance.$onEval(PRIORITY_WATCH, watcher); -- cgit v1.2.3 From 94759f4c2cab91d35a18159a00fbdaec0af79aa9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 26 Jul 2010 15:35:02 -0700 Subject: remove old unneded files --- src/delete/Binder.js | 356 ------------ src/delete/Model.js | 65 --- src/delete/Scope.js | 407 -------------- src/delete/Widgets.js | 806 --------------------------- src/moveToAngularCom/ControlBar.js | 72 --- src/moveToAngularCom/DataStore.js | 330 ----------- src/moveToAngularCom/Server.js | 68 --- src/moveToAngularCom/Users.js | 35 -- src/moveToAngularCom/directivesAngularCom.js | 29 - 9 files changed, 2168 deletions(-) delete mode 100644 src/delete/Binder.js delete mode 100644 src/delete/Model.js delete mode 100644 src/delete/Scope.js delete mode 100644 src/delete/Widgets.js delete mode 100644 src/moveToAngularCom/ControlBar.js delete mode 100644 src/moveToAngularCom/DataStore.js delete mode 100644 src/moveToAngularCom/Server.js delete mode 100644 src/moveToAngularCom/Users.js delete mode 100644 src/moveToAngularCom/directivesAngularCom.js (limited to 'src') diff --git a/src/delete/Binder.js b/src/delete/Binder.js deleted file mode 100644 index 095e2b08..00000000 --- a/src/delete/Binder.js +++ /dev/null @@ -1,356 +0,0 @@ -function Binder(doc, widgetFactory, datastore, location, config) { - this.doc = doc; - this.location = location; - this.datastore = datastore; - this.anchor = {}; - this.widgetFactory = widgetFactory; - this.config = config || {}; - this.updateListeners = []; -} - -Binder.parseBindings = function(string) { - var results = []; - var lastIndex = 0; - var index; - while((index = string.indexOf('{{', lastIndex)) > -1) { - if (lastIndex < index) - results.push(string.substr(lastIndex, index - lastIndex)); - lastIndex = index; - - index = string.indexOf('}}', index); - index = index < 0 ? string.length : index + 2; - - results.push(string.substr(lastIndex, index - lastIndex)); - lastIndex = index; - } - if (lastIndex != string.length) - results.push(string.substr(lastIndex, string.length - lastIndex)); - return results.length === 0 ? [ string ] : results; -}; - -Binder.hasBinding = function(string) { - var bindings = Binder.parseBindings(string); - return bindings.length > 1 || Binder.binding(bindings[0]) !== null; -}; - -Binder.binding = function(string) { - var binding = string.replace(/\n/gm, ' ').match(/^\{\{(.*)\}\}$/); - return binding ? binding[1] : null; -}; - - -Binder.prototype = { - parseQueryString: function(query) { - var params = {}; - query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, - function (match, left, right) { - if (left) params[decodeURIComponent(left)] = decodeURIComponent(right); - }); - return params; - }, - - parseAnchor: function() { - var self = this, url = this.location['get']() || ""; - - var anchorIndex = url.indexOf('#'); - if (anchorIndex < 0) return; - var anchor = url.substring(anchorIndex + 1); - - var anchorQuery = this.parseQueryString(anchor); - foreach(self.anchor, function(newValue, key) { - delete self.anchor[key]; - }); - foreach(anchorQuery, function(newValue, key) { - self.anchor[key] = newValue; - }); - }, - - onUrlChange: function() { - this.parseAnchor(); - this.updateView(); - }, - - updateAnchor: function() { - var url = this.location['get']() || ""; - var anchorIndex = url.indexOf('#'); - if (anchorIndex > -1) - url = url.substring(0, anchorIndex); - url += "#"; - var sep = ''; - for (var key in this.anchor) { - var value = this.anchor[key]; - if (typeof value === 'undefined' || value === null) { - delete this.anchor[key]; - } else { - url += sep + encodeURIComponent(key); - if (value !== true) - url += "=" + encodeURIComponent(value); - sep = '&'; - } - } - this.location['set'](url); - return url; - }, - - updateView: function() { - var start = new Date().getTime(); - var scope = jQuery(this.doc).scope(); - scope.clearInvalid(); - scope.updateView(); - var end = new Date().getTime(); - this.updateAnchor(); - foreach(this.updateListeners, function(fn) {fn();}); - }, - - docFindWithSelf: function(exp){ - var doc = jQuery(this.doc); - var selection = doc.find(exp); - if (doc.is(exp)){ - selection = selection.andSelf(); - } - return selection; - }, - - executeInit: function() { - this.docFindWithSelf("[ng:init]").each(function() { - var jThis = jQuery(this); - var scope = jThis.scope(); - try { - scope.eval(jThis.attr('ng:init')); - } catch (e) { - alert("EVAL ERROR:\n" + jThis.attr('ng:init') + '\n' + toJson(e, true)); - } - }); - }, - - entity: function (scope) { - var self = this; - this.docFindWithSelf("[ng-entity]").attr("ng:watch", function() { - try { - var jNode = jQuery(this); - var decl = scope.entity(jNode.attr("ng-entity"), self.datastore); - return decl + (jNode.attr('ng:watch') || ""); - } catch (e) { - log(e); - alert(e); - } - }); - }, - - compile: function() { - var jNode = jQuery(this.doc); - if (this.config['autoSubmit']) { - var submits = this.docFindWithSelf(":submit").not("[ng-action]"); - submits.attr("ng-action", "$save()"); - submits.not(":disabled").not("ng:bind-attr").attr("ng:bind-attr", '{disabled:"{{$invalidWidgets}}"}'); - } - this.precompile(this.doc)(this.doc, jNode.scope(), ""); - this.docFindWithSelf("a[ng-action]").live('click', function (event) { - var jNode = jQuery(this); - var scope = jNode.scope(); - try { - scope.eval(jNode.attr('ng-action')); - jNode.removeAttr('ng-error'); - jNode.removeClass("ng-exception"); - } catch (e) { - jNode.addClass("ng-exception"); - jNode.attr('ng-error', toJson(e, true)); - } - scope.get('$updateView')(); - return false; - }); - }, - - translateBinding: function(node, parentPath, factories) { - var path = parentPath.concat(); - var offset = path.pop(); - var parts = Binder.parseBindings(node.nodeValue); - if (parts.length > 1 || Binder.binding(parts[0])) { - var parent = node.parentNode; - if (isLeafNode(parent)) { - parent.setAttribute('ng:bind-template', node.nodeValue); - factories.push({path:path, fn:function(node, scope, prefix) { - return new BindUpdater(node, node.getAttribute('ng:bind-template')); - }}); - } else { - for (var i = 0; i < parts.length; i++) { - var part = parts[i]; - var binding = Binder.binding(part); - var newNode; - if (binding) { - newNode = document.createElement("span"); - var jNewNode = jQuery(newNode); - jNewNode.attr("ng:bind", binding); - if (i === 0) { - factories.push({path:path.concat(offset + i), fn:this.ng_bind}); - } - } else if (msie && part.charAt(0) == ' ') { - newNode = document.createElement("span"); - newNode.innerHTML = ' ' + part.substring(1); - } else { - newNode = document.createTextNode(part); - } - parent.insertBefore(newNode, node); - } - } - parent.removeChild(node); - } - }, - - precompile: function(root) { - var factories = []; - this.precompileNode(root, [], factories); - return function (template, scope, prefix) { - var len = factories.length; - for (var i = 0; i < len; i++) { - var factory = factories[i]; - var node = template; - var path = factory.path; - for (var j = 0; j < path.length; j++) { - node = node.childNodes[path[j]]; - } - try { - scope.addWidget(factory.fn(node, scope, prefix)); - } catch (e) { - alert(e); - } - } - }; - }, - - precompileNode: function(node, path, factories) { - var nodeType = node.nodeType; - if (nodeType == Node.TEXT_NODE) { - this.translateBinding(node, path, factories); - return; - } else if (nodeType != Node.ELEMENT_NODE && nodeType != Node.DOCUMENT_NODE) { - return; - } - - if (!node.getAttribute) return; - var nonBindable = node.getAttribute('ng:non-bindable'); - if (nonBindable || nonBindable === "") return; - - var attributes = node.attributes; - if (attributes) { - var bindings = node.getAttribute('ng:bind-attr'); - node.removeAttribute('ng:bind-attr'); - bindings = bindings ? fromJson(bindings) : {}; - var attrLen = attributes.length; - for (var i = 0; i < attrLen; i++) { - var attr = attributes[i]; - var attrName = attr.name; - // http://www.glennjones.net/Post/809/getAttributehrefbug.htm - var attrValue = msie && attrName == 'href' ? - decodeURI(node.getAttribute(attrName, 2)) : attr.value; - if (Binder.hasBinding(attrValue)) { - bindings[attrName] = attrValue; - } - } - var json = toJson(bindings); - if (json.length > 2) { - node.setAttribute("ng:bind-attr", json); - } - } - - if (!node.getAttribute) log(node); - var repeaterExpression = node.getAttribute('ng:repeat'); - if (repeaterExpression) { - node.removeAttribute('ng:repeat'); - var precompiled = this.precompile(node); - var view = document.createComment("ng:repeat: " + repeaterExpression); - var parentNode = node.parentNode; - parentNode.insertBefore(view, node); - parentNode.removeChild(node); - function template(childScope, prefix, i) { - var clone = jQuery(node).clone(); - clone.css('display', ''); - clone.attr('ng:repeat-index', "" + i); - clone.data('scope', childScope); - precompiled(clone[0], childScope, prefix + i + ":"); - return clone; - } - factories.push({path:path, fn:function(node, scope, prefix) { - return new RepeaterUpdater(jQuery(node), repeaterExpression, template, prefix); - }}); - return; - } - - if (node.getAttribute('ng:eval')) factories.push({path:path, fn:this.ng_eval}); - if (node.getAttribute('ng:bind')) factories.push({path:path, fn:this.ng_bind}); - if (node.getAttribute('ng:bind-attr')) factories.push({path:path, fn:this.ng_bind_attr}); - if (node.getAttribute('ng:hide')) factories.push({path:path, fn:this.ng_hide}); - if (node.getAttribute('ng:show')) factories.push({path:path, fn:this.ng_show}); - if (node.getAttribute('ng:class')) factories.push({path:path, fn:this.ng_class}); - if (node.getAttribute('ng:class-odd')) factories.push({path:path, fn:this.ng_class_odd}); - if (node.getAttribute('ng:class-even')) factories.push({path:path, fn:this.ng_class_even}); - if (node.getAttribute('ng:style')) factories.push({path:path, fn:this.ng_style}); - if (node.getAttribute('ng:watch')) factories.push({path:path, fn:this.ng_watch}); - var nodeName = node.nodeName; - if ((nodeName == 'INPUT' ) || - nodeName == 'TEXTAREA' || - nodeName == 'SELECT' || - nodeName == 'BUTTON') { - var self = this; - factories.push({path:path, fn:function(node, scope, prefix) { - node.name = prefix + node.name.split(":").pop(); - return self.widgetFactory.createController(jQuery(node), scope); - }}); - } - if (nodeName == 'OPTION') { - var html = jQuery('' + - '' + - '' + - '' + - ''); -}; - -extend(FileController.prototype, { - 'cancel': noop, - 'complete': noop, - 'httpStatus': function(status) { - alert("httpStatus:" + this.scopeName + " status:" + status); - }, - 'ioError': function() { - alert("ioError:" + this.scopeName); - }, - 'open': function() { - alert("open:" + this.scopeName); - }, - 'progress':noop, - 'securityError': function() { - alert("securityError:" + this.scopeName); - }, - 'uploadCompleteData': function(data) { - var value = fromJson(data); - value.url = this.attachmentsPath + '/' + value.id + '/' + value.text; - this.view.find("input").attr('checked', true); - var scope = this.view.scope(); - this.value = value; - this.updateModel(scope); - this.value = null; - }, - 'select': function(name, size, type) { - this.name = name; - this.view.find("a").text(name).attr('href', name); - this.view.find("span").text(angular['filter']['bytes'](size)); - this.upload(); - }, - - updateModel: function(scope) { - var isChecked = this.view.find("input").attr('checked'); - var value = isChecked ? this.value : null; - if (this.lastValue === value) { - return false; - } else { - scope.set(this.scopeName, value); - return true; - } - }, - - updateView: function(scope) { - var modelValue = scope.get(this.scopeName); - if (modelValue && this.value !== modelValue) { - this.value = modelValue; - this.view.find("a"). - attr("href", this.value.url). - text(this.value.text); - this.view.find("span").text(angular['filter']['bytes'](this.value.size)); - } - this.view.find("input").attr('checked', !!modelValue); - }, - - upload: function() { - if (this.name) { - this.uploader['uploadFile'](this.attachmentsPath); - } - } -}); - -/////////////////////// -// NullController -/////////////////////// -function NullController(view) {this.view = view;}; -NullController.prototype = { - updateModel: function() { return true; }, - updateView: noop -}; -NullController.instance = new NullController(); - - -/////////////////////// -// ButtonController -/////////////////////// -var ButtonController = NullController; - -/////////////////////// -// TextController -/////////////////////// -function TextController(view, exp, formatter) { - this.view = view; - this.formatter = formatter; - this.exp = exp; - this.validator = view.getAttribute('ng:validate'); - this.required = typeof view.attributes['ng:required'] != "undefined"; - this.lastErrorText = null; - this.lastValue = undefined; - this.initialValue = this.formatter['parse'](view.value); - var widget = view.getAttribute('ng-widget'); - if (widget === 'datepicker') { - jQuery(view).datepicker(); - } -}; - -TextController.prototype = { - updateModel: function(scope) { - var value = this.formatter['parse'](this.view.value); - if (this.lastValue === value) { - return false; - } else { - scope.setEval(this.exp, value); - this.lastValue = value; - return true; - } - }, - - updateView: function(scope) { - var view = this.view; - var value = scope.get(this.exp); - if (typeof value === "undefined") { - value = this.initialValue; - scope.setEval(this.exp, value); - } - value = value ? value : ''; - if (!_(this.lastValue).isEqual(value)) { - view.value = this.formatter['format'](value); - this.lastValue = value; - } - - var isValidationError = false; - view.removeAttribute('ng-error'); - if (this.required) { - isValidationError = !(value && $.trim("" + value).length > 0); - } - var errorText = isValidationError ? "Required Value" : null; - if (!isValidationError && this.validator && value) { - errorText = scope.validate(this.validator, value, view); - isValidationError = !!errorText; - } - if (this.lastErrorText !== errorText) { - this.lastErrorText = isValidationError; - if (errorText && isVisible(view)) { - view.setAttribute('ng-error', errorText); - scope.markInvalid(this); - } - jQuery(view).toggleClass('ng-validation-error', isValidationError); - } - } -}; - -/////////////////////// -// CheckboxController -/////////////////////// -function CheckboxController(view, exp, formatter) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.formatter = formatter; - this.initialValue = this.formatter['parse'](view.checked ? view.value : ""); -}; - -CheckboxController.prototype = { - updateModel: function(scope) { - var input = this.view; - var value = input.checked ? input.value : ''; - value = this.formatter['parse'](value); - value = this.formatter['format'](value); - if (this.lastValue === value) { - return false; - } else { - scope.setEval(this.exp, this.formatter['parse'](value)); - this.lastValue = value; - return true; - } - }, - - updateView: function(scope) { - var input = this.view; - var value = scope.eval(this.exp); - if (typeof value === "undefined") { - value = this.initialValue; - scope.setEval(this.exp, value); - } - input.checked = this.formatter['parse'](input.value) == value; - } -}; - -/////////////////////// -// SelectController -/////////////////////// -function SelectController(view, exp) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.initialValue = view.value; -}; - -SelectController.prototype = { - updateModel: function(scope) { - var input = this.view; - if (input.selectedIndex < 0) { - scope.setEval(this.exp, null); - } else { - var value = this.view.value; - if (this.lastValue === value) { - return false; - } else { - scope.setEval(this.exp, value); - this.lastValue = value; - return true; - } - } - }, - - updateView: function(scope) { - var input = this.view; - var value = scope.get(this.exp); - if (typeof value === 'undefined') { - value = this.initialValue; - scope.setEval(this.exp, value); - } - if (value !== this.lastValue) { - input.value = value ? value : ""; - this.lastValue = value; - } - } -}; - -/////////////////////// -// MultiSelectController -/////////////////////// -function MultiSelectController(view, exp) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.initialValue = this.selected(); -}; - -MultiSelectController.prototype = { - selected: function () { - var value = []; - var options = this.view.options; - for ( var i = 0; i < options.length; i++) { - var option = options[i]; - if (option.selected) { - value.push(option.value); - } - } - return value; - }, - - updateModel: function(scope) { - var value = this.selected(); - // TODO: This is wrong! no caching going on here as we are always comparing arrays - if (this.lastValue === value) { - return false; - } else { - scope.setEval(this.exp, value); - this.lastValue = value; - return true; - } - }, - - updateView: function(scope) { - var input = this.view; - var selected = scope.get(this.exp); - if (typeof selected === "undefined") { - selected = this.initialValue; - scope.setEval(this.exp, selected); - } - if (selected !== this.lastValue) { - var options = input.options; - for ( var i = 0; i < options.length; i++) { - var option = options[i]; - option.selected = _.include(selected, option.value); - } - this.lastValue = selected; - } - } -}; - -/////////////////////// -// RadioController -/////////////////////// -function RadioController(view, exp) { - this.view = view; - this.exp = exp; - this.lastChecked = undefined; - this.lastValue = undefined; - this.inputValue = view.value; - this.initialValue = view.checked ? view.value : null; -}; - -RadioController.prototype = { - updateModel: function(scope) { - var input = this.view; - if (this.lastChecked) { - return false; - } else { - input.checked = true; - this.lastValue = scope.setEval(this.exp, this.inputValue); - this.lastChecked = true; - return true; - } - }, - - updateView: function(scope) { - var input = this.view; - var value = scope.get(this.exp); - if (this.initialValue && typeof value === "undefined") { - value = this.initialValue; - scope.setEval(this.exp, value); - } - if (this.lastValue != value) { - this.lastChecked = input.checked = this.inputValue == (''+value); - this.lastValue = value; - } - } -}; - -/////////////////////// -//ElementController -/////////////////////// -function BindUpdater(view, exp) { - this.view = view; - this.exp = Binder.parseBindings(exp); - this.hasError = false; -}; - -BindUpdater.toText = function(obj) { - var e = escapeHtml; - switch(typeof obj) { - case "string": - case "boolean": - case "number": - return e(obj); - case "function": - return BindUpdater.toText(obj()); - case "object": - if (isNode(obj)) { - return outerHTML(obj); - } else if (obj instanceof angular.filter.Meta) { - switch(typeof obj.html) { - case "string": - case "number": - return obj.html; - case "function": - return obj.html(); - case "object": - if (isNode(obj.html)) - return outerHTML(obj.html); - default: - break; - } - switch(typeof obj.text) { - case "string": - case "number": - return e(obj.text); - case "function": - return e(obj.text()); - default: - break; - } - } - if (obj === null) - return ""; - return e(toJson(obj, true)); - default: - return ""; - } -}; - -BindUpdater.prototype = { - updateModel: noop, - updateView: function(scope) { - var html = []; - var parts = this.exp; - var length = parts.length; - for(var i=0; i iteratorCounter; --r) { - this.children.pop().element.remove(); - } - // Special case for option in select - if (child && child.element[0].nodeName === "OPTION") { - var select = jQuery(child.element[0].parentNode); - var cntl = select.data('controller'); - if (cntl) { - cntl.lastValue = undefined; - cntl.updateView(scope); - } - } - }); - } -}; - -////////////////////////////////// -// PopUp -////////////////////////////////// - -function PopUp(doc) { - this.doc = doc; -}; - -PopUp.OUT_EVENT = "mouseleave mouseout click dblclick keypress keyup"; - -PopUp.onOver = function(e) { - PopUp.onOut(); - var jNode = jQuery(this); - jNode.bind(PopUp.OUT_EVENT, PopUp.onOut); - var position = jNode.position(); - var de = document.documentElement; - var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth; - var hasArea = w - position.left; - var width = 300; - var title = jNode.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error..."; - var msg = jNode.attr("ng-error"); - - var x; - var arrowPos = hasArea>(width+75) ? "left" : "right"; - var tip = jQuery( - "
" + - "
" + - "
"+title+"
" + - "
"+msg+"
" + - "
"); - jQuery("body").append(tip); - if(arrowPos === 'left'){ - x = position.left + this.offsetWidth + 11; - }else{ - x = position.left - (width + 15); - tip.find('.ng-arrow-right').css({left:width+1}); - } - - tip.css({left: x+"px", top: (position.top - 3)+"px"}); - return true; -}; - -PopUp.onOut = function() { - jQuery('#ng-callout'). - unbind(PopUp.OUT_EVENT, PopUp.onOut). - remove(); - return true; -}; - -PopUp.prototype = { - bind: function () { - var self = this; - this.doc.find('.ng-validation-error,.ng-exception'). - live("mouseover", PopUp.onOver); - } -}; - -////////////////////////////////// -// Status -////////////////////////////////// - -function NullStatus(body) { -}; - -NullStatus.prototype = { - beginRequest:function(){}, - endRequest:function(){} -}; - -function Status(body) { - this.requestCount = 0; - this.body = body; -}; - -Status.DOM ='
loading....
'; - -Status.prototype = { - beginRequest: function () { - if (this.requestCount === 0) { - (this.loader = this.loader || this.body.append(Status.DOM).find("#ng-loading")).show(); - } - this.requestCount++; - }, - - endRequest: function () { - this.requestCount--; - if (this.requestCount === 0) { - this.loader.hide("fold"); - } - } -}; diff --git a/src/moveToAngularCom/ControlBar.js b/src/moveToAngularCom/ControlBar.js deleted file mode 100644 index b9a2de8a..00000000 --- a/src/moveToAngularCom/ControlBar.js +++ /dev/null @@ -1,72 +0,0 @@ -function ControlBar(document, serverUrl, database) { - this._document = document; - this.serverUrl = serverUrl; - this.database = database; - this._window = window; - this.callbacks = []; -}; - -ControlBar.HTML = - '
' + - '
' + - '
' + - '' + - '
' + - '
'; - - -ControlBar.FORBIDEN = - '
' + - 'Sorry, you do not have permission for this!'+ - '
'; - -ControlBar.prototype = { - bind: function () { - }, - - login: function (loginSubmitFn) { - this.callbacks.push(loginSubmitFn); - if (this.callbacks.length == 1) { - this.doTemplate("/user_session/new.mini?database="+encodeURIComponent(this.database)+"&return_url=" + encodeURIComponent(this.urlWithoutAnchor())); - } - }, - - logout: function (loginSubmitFn) { - this.callbacks.push(loginSubmitFn); - if (this.callbacks.length == 1) { - this.doTemplate("/user_session/do_destroy.mini"); - } - }, - - urlWithoutAnchor: function (path) { - return this._window['location']['href'].split("#")[0]; - }, - - doTemplate: function (path) { - var self = this; - var id = new Date().getTime(); - var url = this.urlWithoutAnchor() + "#$iframe_notify=" + id; - var iframeHeight = 330; - var loginView = jQuery('