From 866346e1ada583daeb649c253516c8f8a879c387 Mon Sep 17 00:00:00 2001 From: git5 Date: Thu, 1 Jan 1970 00:00:01 +0000 Subject: git5: git5track synced with perforce at 0 --- .gitignore | 24 ++++++++++++++++++++++++ READONLY | 1 + 2 files changed, 25 insertions(+) create mode 100644 .gitignore create mode 120000 READONLY diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2b10d121 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.git4_perforce_config +blaze-eclipse +google3/blaze-* +google3/Makefile* +google3/buildconf +google3/bin +google3/.forge +google3/genfiles +.p4config +/review +google3/linux-* +*.pyc +*~ +.nfs* +.*.swp +*.pyc-2.4 +.dotest +google3/.forge +google3/.grunt +google3/.gwt-tmp +google3/alloc +google3tomcat +google3/mbin +google3/mgenfiles \ No newline at end of file diff --git a/READONLY b/READONLY new file mode 120000 index 00000000..fda55c75 --- /dev/null +++ b/READONLY @@ -0,0 +1 @@ +/google/src/files/0/depot \ No newline at end of file -- cgit v1.2.3 From 8f9bf37bcf38165e89f37c147f9315cb8e72fc1f Mon Sep 17 00:00:00 2001 From: Rob Spies Date: Tue, 22 Jun 2010 17:11:57 -0700 Subject: asdsad --- test/ResourceSpec.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index d11c3e08..4ab3537c 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -35,11 +35,6 @@ describe("resource", function() { var item = LineItem.get({id:456}); xhr.flush(); nakedExpect(item).toEqual({id:'abc'}); - - item = LineItem.get({id:456}); - xhr.flush(); - nakedExpect(item).toEqual({id:'abc'}); - }); it("should create resource", function(){ -- cgit v1.2.3 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 --- example/memoryLeak.html | 4 +- example/tweeter/tweeter_addressbook.html | 30 +++---- example/tweeter/tweeter_demo.html | 10 +-- scenario/application-account.html | 4 +- scenario/application.html | 6 +- scenario/cross-site-post/index.html | 2 +- scenario/datastore.html | 4 +- scenario/perf.html | 6 +- scenario/widgets.html | 6 +- 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 +- test.sh | 9 +- test/BinderTest.js | 148 +++++++++++++++---------------- test/ScenarioSpec.js | 2 +- test/delete/WidgetsTest.js | 2 +- test/directivesSpec.js | 90 +++++++++---------- test/markupSpec.js | 10 +-- test/moveToAngularCom/miscTest.js | 6 +- test/testabilityPatch.js | 4 +- test/widgetsSpec.js | 8 +- 25 files changed, 260 insertions(+), 255 deletions(-) diff --git a/example/memoryLeak.html b/example/memoryLeak.html index 9e5f512d..19b0d45d 100644 --- a/example/memoryLeak.html +++ b/example/memoryLeak.html @@ -48,8 +48,8 @@ - - + +
diff --git a/example/tweeter/tweeter_addressbook.html b/example/tweeter/tweeter_addressbook.html index 4844c035..ba915cb1 100644 --- a/example/tweeter/tweeter_addressbook.html +++ b/example/tweeter/tweeter_addressbook.html @@ -8,25 +8,25 @@ - +

Address Book

[ Filter: ]
-
+
@@ -37,7 +37,7 @@ - +

@@ -58,16 +58,16 @@ tweets={{tweets}}

Tweets: {{$anchor.user}}

[ Filter: - | << All + | << All ]
Loading...
    -
  • +
  • - [ {{user.nickname || user.name || user.screen_name }} - | + + [ {{user.nickname || user.name || user.screen_name }} + | + ]: {{tweet.text | linky}} {{tweet.created_at}} diff --git a/example/tweeter/tweeter_demo.html b/example/tweeter/tweeter_demo.html index 138d4e2b..a5ba95ba 100644 --- a/example/tweeter/tweeter_demo.html +++ b/example/tweeter/tweeter_demo.html @@ -8,19 +8,19 @@ - + (TODO: I should fetch current tweets)

    Tweets: {{$anchor.user}}

    [ Filter: (TODO: this should act as search box) - | << All + | << All ]
    Loading...
      -
    • +
    • - [ {{tweet.user.nickname || tweet.user.name || tweet.user.screen_name }} + [ {{tweet.user.nickname || tweet.user.name || tweet.user.screen_name }} ]: {{tweet.text}} (TODO: I want urls as links) {{tweet.created_at}} diff --git a/scenario/application-account.html b/scenario/application-account.html index a43deffc..81176df7 100644 --- a/scenario/application-account.html +++ b/scenario/application-account.html @@ -1,6 +1,6 @@ -
      +
      account page goes here! - +
      diff --git a/scenario/application.html b/scenario/application.html index 6b6ced69..5d5bb809 100644 --- a/scenario/application.html +++ b/scenario/application.html @@ -16,14 +16,14 @@ - + [ login | account ] -
      login screen
      - +
      login screen
      +
      diff --git a/scenario/cross-site-post/index.html b/scenario/cross-site-post/index.html index 3ff6af85..d7a87d3b 100644 --- a/scenario/cross-site-post/index.html +++ b/scenario/cross-site-post/index.html @@ -4,7 +4,7 @@ - +
      people = {{people}}
      diff --git a/scenario/datastore.html b/scenario/datastore.html index 525d3636..1720b3bc 100644 --- a/scenario/datastore.html +++ b/scenario/datastore.html @@ -8,9 +8,9 @@ $(document).ready(function(){angular.compile(document).init();}); - +

      {{book.$id}}

      -
    • +
    • {{book.name}}
    • diff --git a/scenario/perf.html b/scenario/perf.html index 50a8d28f..94af8b69 100644 --- a/scenario/perf.html +++ b/scenario/perf.html @@ -20,12 +20,12 @@ }; - +
      diff --git a/scenario/widgets.html b/scenario/widgets.html index 86269e86..2626843d 100644 --- a/scenario/widgets.html +++ b/scenario/widgets.html @@ -72,7 +72,7 @@ Buttons - ng-change
      ng-click + ng-change
      ng:click

      @@ -85,10 +85,10 @@ Repeaters - ng-repeat + ng:repeat
        -
      • {{name}}
      • +
      • {{name}}
      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){ diff --git a/test.sh b/test.sh index a1717861..d0a4839a 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,7 @@ -java -jar lib/jstestdriver/JsTestDriver.jar --tests all -# java -jar lib/jstestdriver/JsTestDriver.jar --tests all --config jsTestDriver-jquery.conf +tests=$1 +if [[ $tests = "" ]]; then + tests="all" +fi + +java -jar lib/jstestdriver/JsTestDriver.jar --tests "$tests" +# java -jar lib/jstestdriver/JsTestDriver.jar --tests "$tests" --config jsTestDriver-jquery.conf diff --git a/test/BinderTest.js b/test/BinderTest.js index ecdd506f..6dc47cce 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -47,7 +47,7 @@ BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ }; BinderTest.prototype.testBindUpdate = function() { - var c = this.compile('
      '); + var c = this.compile('
      '); assertEquals(123, c.scope.$get('a')); }; @@ -71,26 +71,26 @@ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ }; BinderTest.prototype.testExecuteInitialization = function() { - var c = this.compile('
      '); + var c = this.compile('
      '); assertEquals(c.scope.$get('a'), 123); }; BinderTest.prototype.testExecuteInitializationStatements = function() { - var c = this.compile('
      '); + var c = this.compile('
      '); assertEquals(c.scope.$get('a'), 123); assertEquals(c.scope.$get('b'), 345); }; BinderTest.prototype.testApplyTextBindings = function(){ - var form = this.compile('
      x
      '); + var form = this.compile('
      x
      '); form.scope.$set('model', {a:123}); form.scope.$eval(); assertEquals('123', form.node.text()); }; BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { - assertEquals(this.compileToHtml("a{{b}}c"), 'ac'); - assertEquals(this.compileToHtml("{{b}}"), ''); + assertEquals(this.compileToHtml("a{{b}}c"), 'ac'); + assertEquals(this.compileToHtml("{{b}}"), ''); }; BinderTest.prototype.testBindingSpaceConfusesIE = function() { @@ -99,16 +99,16 @@ BinderTest.prototype.testBindingSpaceConfusesIE = function() { span.innerHTML = ' '; var nbsp = span.firstChild.nodeValue; assertEquals( - ''+nbsp+'', + ''+nbsp+'', this.compileToHtml("{{a}} {{b}}")); assertEquals( - ''+nbsp+'x '+nbsp+'()', + ''+nbsp+'x '+nbsp+'()', this.compileToHtml("{{A}} x {{B}} ({{C}})")); }; BinderTest.prototype.testBindingOfAttributes = function() { var c = this.compile(""); - var attrbinding = c.node.attr("ng-bind-attr"); + var attrbinding = c.node.attr("ng:bind-attr"); var bindings = fromJson(attrbinding); assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); assertTrue(!bindings.foo); @@ -116,7 +116,7 @@ BinderTest.prototype.testBindingOfAttributes = function() { BinderTest.prototype.testMarkMultipleAttributes = function() { var c = this.compile(''); - var attrbinding = c.node.attr("ng-bind-attr"); + var attrbinding = c.node.attr("ng:bind-attr"); var bindings = fromJson(attrbinding); assertEquals(bindings.foo, "{{d}}"); assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); @@ -126,17 +126,17 @@ BinderTest.prototype.testAttributesNoneBound = function() { var c = this.compile(""); var a = c.node; assertEquals(a[0].nodeName, "A"); - assertTrue(!a.attr("ng-bind-attr")); + assertTrue(!a.attr("ng:bind-attr")); }; BinderTest.prototype.testExistingAttrbindingIsAppended = function() { - var c = this.compile(""); + var c = this.compile(""); var a = c.node; - assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr')); + assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr')); }; BinderTest.prototype.testAttributesAreEvaluated = function(){ - var c = this.compile(''); + var c = this.compile(''); var binder = c.binder, form = c.node; c.scope.$eval('a=1;b=2'); c.scope.$eval(); @@ -147,7 +147,7 @@ BinderTest.prototype.testAttributesAreEvaluated = function(){ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ var savedCalled = false; - var c = this.compile(''); + var c = this.compile(''); c.scope.$set("person.save", function(){ savedCalled = true; }); @@ -157,7 +157,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){ var log = ""; - var c = this.compile(''); + var c = this.compile(''); c.scope.$set("action", function(){ log += 'click;'; }); @@ -168,7 +168,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ var savedCalled = false; - var c = this.compile(''); + var c = this.compile(''); c.scope.$set("person.save", function(){ savedCalled = true; }); @@ -177,7 +177,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ }; BinderTest.prototype.testRepeaterUpdateBindings = function(){ - var a = this.compile('
      '); + var a = this.compile('
      '); var form = a.node; var items = [{a:"A"}, {a:"B"}]; a.scope.$set('model', {items:items}); @@ -185,25 +185,25 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ a.scope.$eval(); assertEquals('
        ' + '<#comment>' + - '
      • A
      • ' + - '
      • B
      • ' + + '
      • A
      • ' + + '
      • B
      • ' + '
      ', sortedHtml(form)); items.unshift({a:'C'}); a.scope.$eval(); assertEquals('
        ' + '<#comment>' + - '
      • C
      • ' + - '
      • A
      • ' + - '
      • B
      • ' + + '
      • C
      • ' + + '
      • A
      • ' + + '
      • B
      • ' + '
      ', sortedHtml(form)); items.shift(); a.scope.$eval(); assertEquals('
        ' + '<#comment>' + - '
      • A
      • ' + - '
      • B
      • ' + + '
      • A
      • ' + + '
      • B
      • ' + '
      ', sortedHtml(form)); items.shift(); @@ -212,19 +212,19 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ }; BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ - var a = this.compile('
      '); + var a = this.compile('
      '); a.scope.$set('model', {items:[{a:"A"}]}); a.scope.$eval(); assertEquals('
        ' + '<#comment>' + - '
      • A
      • ' + + '
      • A
      • ' + '
      ', sortedHtml(a.node)); }; BinderTest.prototype.testExpandEntityTag = function(){ assertEquals( - '
      ', - this.compileToHtml('
      ')); + '
      ', + this.compileToHtml('
      ')); }; BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ @@ -233,7 +233,7 @@ BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ }; BinderTest.prototype.testRepeaterAdd = function(){ - var c = this.compile('
      '); + var c = this.compile('
      '); var doc = c.node; c.scope.$set('items', [{x:'a'}, {x:'b'}]); c.scope.$eval(); @@ -248,7 +248,7 @@ BinderTest.prototype.testRepeaterAdd = function(){ }; BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ - var c = this.compile('
      {{i}}
      '); + var c = this.compile('
      {{i}}
      '); var items = {}; c.scope.$set("items", items); @@ -308,8 +308,8 @@ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheAttribute = function }; BinderTest.prototype.testNestedRepeater = function() { - var a = this.compile('
      ' + - '
        ' + + var a = this.compile('
        ' + + '
          ' + '
          '); a.scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); @@ -317,20 +317,20 @@ BinderTest.prototype.testNestedRepeater = function() { assertEquals('
          '+ '<#comment>'+ - '
          '+ + '
          '+ '<#comment>'+ - '
            '+ - '
              '+ + '
                '+ + '
                  '+ '
                  '+ - '
                  '+ + '
                  '+ '<#comment>'+ - '
                    '+ - '
                      '+ + '
                        '+ + '
                          '+ '
                          ', sortedHtml(a.node)); }; BinderTest.prototype.testHideBindingExpression = function() { - var a = this.compile('
                          '); + var a = this.compile('
                          '); a.scope.$set('hidden', 3); a.scope.$eval(); @@ -344,7 +344,7 @@ BinderTest.prototype.testHideBindingExpression = function() { }; BinderTest.prototype.testHideBinding = function() { - var c = this.compile('
                          '); + var c = this.compile('
                          '); c.scope.$set('hidden', 'true'); c.scope.$eval(); @@ -363,7 +363,7 @@ BinderTest.prototype.testHideBinding = function() { }; BinderTest.prototype.testShowBinding = function() { - var c = this.compile('
                          '); + var c = this.compile('
                          '); c.scope.$set('show', 'true'); c.scope.$eval(); @@ -382,42 +382,42 @@ BinderTest.prototype.testShowBinding = function() { }; BinderTest.prototype.testBindClassUndefined = function() { - var doc = this.compile('
                          '); + var doc = this.compile('
                          '); doc.scope.$eval(); assertEquals( - '
                          ', + '
                          ', sortedHtml(doc.node)); }; BinderTest.prototype.testBindClass = function() { - var c = this.compile('
                          '); + var c = this.compile('
                          '); c.scope.$set('class', 'testClass'); c.scope.$eval(); assertEquals(sortedHtml(c.node), - '
                          '); + '
                          '); c.scope.$set('class', ['a', 'b']); c.scope.$eval(); assertEquals(sortedHtml(c.node), - '
                          '); + '
                          '); }; BinderTest.prototype.testBindClassEvenOdd = function() { - var x = this.compile('
                          '); + var x = this.compile('
                          '); x.scope.$eval(); assertEquals( '
                          <#comment>' + - '
                          ' + - '
                          ', + '
                          ' + + '
                          ', sortedHtml(x.node)); }; BinderTest.prototype.testBindStyle = function() { - var c = this.compile('
                          '); + var c = this.compile('
                          '); c.scope.$eval('style={color:"red"}'); c.scope.$eval(); @@ -430,7 +430,7 @@ BinderTest.prototype.testBindStyle = function() { BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var model = {books:[]}; - var c = this.compile('Add Phone', model); + var c = this.compile('Add Phone', model); c.scope.action = function(){ throw {a:'abc', b:2}; }; @@ -450,23 +450,23 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ var c = this.compile("
                          {{a}}" + - "
                          {{a}}
                          " + - "
                          {{b}}
                          " + - "
                          {{c}}
                          "); + "
                          {{a}}
                          " + + "
                          {{b}}
                          " + + "
                          {{c}}
                          "); c.scope.$set('a', 123); c.scope.$eval(); assertEquals('123{{a}}{{b}}{{c}}', c.node.text()); }; BinderTest.prototype.testOptionShouldUpdateParentToGetProperBinding = function() { - var c = this.compile(''); + var c = this.compile(''); c.scope.$set('s', 1); c.scope.$eval(); assertEquals(1, c.node[0].selectedIndex); }; BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { - var c = this.compile('
                          '); + var c = this.compile('
                          '); c.scope.$set('items', [{}, {name:'misko'}]); c.scope.$eval(); @@ -475,7 +475,7 @@ BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { }; BinderTest.prototype.testRepeaterShouldCreateArray = function () { - var c = this.compile(''); + var c = this.compile(''); c.scope.$eval(); assertEquals(0, c.scope.$get('items').length); @@ -486,7 +486,7 @@ BinderTest.prototype.testShouldTemplateBindPreElements = function () { c.scope.$set("name", "World"); c.scope.$eval(); - assertEquals('
                          Hello World!
                          ', sortedHtml(c.node)); + assertEquals('
                          Hello World!
                          ', sortedHtml(c.node)); }; BinderTest.prototype.testFillInOptionValueWhenMissing = function() { @@ -511,7 +511,7 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { BinderTest.prototype.testValidateForm = function() { var c = this.compile('
                          ' + - '
                          '); + '
                          '); var items = [{}, {}]; c.scope.$set("items", items); c.scope.$eval(); @@ -539,7 +539,7 @@ BinderTest.prototype.testValidateForm = function() { }; BinderTest.prototype.testValidateOnlyVisibleItems = function(){ - var c = this.compile('
                          '); + var c = this.compile('
                          '); jqLite(document.body).append(c.node); c.scope.$set("show", true); c.scope.$eval(); @@ -552,9 +552,9 @@ BinderTest.prototype.testValidateOnlyVisibleItems = function(){ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { var c = this.compile('
                          ' + - '' + - '' + - '
                          '); + '' + + '' + + '
                          '); c.scope.$eval(); function assertChild(index, disabled) { var child = childNode(c.node, index); @@ -571,8 +571,8 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ var c = this.compile('
                          ' + - '' + - '
                          '); + '' + + '
                          '); var first = jqLite(c.node[0].childNodes[0]); var second = jqLite(c.node[0].childNodes[1]); @@ -605,8 +605,8 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { BinderTest.prototype.testItShouldListenOnRightScope = function() { var c = this.compile( - '
                            ' + - '
                          '); + '
                            ' + + '
                          '); c.scope.$eval(); assertEquals(0, c.scope.$get("counter")); assertEquals(0, c.scope.$get("gCounter")); @@ -618,25 +618,25 @@ BinderTest.prototype.testItShouldListenOnRightScope = function() { }; BinderTest.prototype.testItShouldRepeatOnHashes = function() { - var x = this.compile('
                          '); + var x = this.compile('
                          '); x.scope.$eval(); assertEquals('
                            ' + '<#comment>' + - '
                          • a0
                          • ' + - '
                          • b1
                          • ' + + '
                          • a0
                          • ' + + '
                          • b1
                          • ' + '
                          ', sortedHtml(x.node)); }; BinderTest.prototype.testItShouldFireChangeListenersBeforeUpdate = function(){ - var x = this.compile('
                          '); + var x = this.compile('
                          '); x.scope.$set("name", ""); x.scope.$watch("watched", "name=123"); x.scope.$set("watched", "change"); x.scope.$eval(); assertEquals(123, x.scope.$get("name")); assertEquals( - '
                          123
                          ', + '
                          123
                          ', sortedHtml(x.node)); }; @@ -657,7 +657,7 @@ BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { x.scope.a = "acd"; x.scope.$eval(); assertEquals( - '
                          before acdafter
                          ', + '
                          before acdafter
                          ', sortedHtml(x.node)); }; diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 9afe8e95..7ea3192d 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -1,6 +1,6 @@ describe("ScenarioSpec: Compilation", function(){ it("should compile dom node and return scope", function(){ - var node = jqLite('
                          {{b=a+1}}
                          ')[0]; + var node = jqLite('
                          {{b=a+1}}
                          ')[0]; var scope = compile(node); scope.$init(); expect(scope.a).toEqual(1); diff --git a/test/delete/WidgetsTest.js b/test/delete/WidgetsTest.js index 313d7372..9acc6126 100644 --- a/test/delete/WidgetsTest.js +++ b/test/delete/WidgetsTest.js @@ -111,7 +111,7 @@ RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){ try { var repeater = new RepeaterUpdater(null, "a=b"); } catch (e) { - assertEquals("Expected ng-repeat in form of 'item in collection' but got 'a=b'.", e); + assertEquals("Expected ng:repeat in form of 'item in collection' but got 'a=b'.", e); } }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 42869a05..836c51e8 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -17,57 +17,57 @@ describe("directives", function(){ expect(size(jqCache)).toEqual(0); }); - it("should ng-init", function() { - var scope = compile('
                          '); + it("should ng:init", function() { + var scope = compile('
                          '); expect(scope.a).toEqual(123); }); - it("should ng-eval", function() { - var scope = compile('
                          '); + it("should ng:eval", function() { + var scope = compile('
                          '); expect(scope.a).toEqual(1); scope.$eval(); expect(scope.a).toEqual(2); }); - it('should ng-bind', function() { - var scope = compile('
                          '); + it('should ng:bind', function() { + var scope = compile('
                          '); expect(element.text()).toEqual(''); scope.a = 'misko'; scope.$eval(); expect(element.text()).toEqual('misko'); }); - it('should ng-bind html', function() { - var scope = compile('
                          '); + it('should ng:bind html', function() { + var scope = compile('
                          '); scope.html = '
                          hello
                          '; scope.$eval(); expect(lowercase(element.html())).toEqual('
                          hello
                          '); }); - it('should ng-bind element', function() { + it('should ng:bind element', function() { angularFilter.myElement = function() { return jqLite('hello'); }; - var scope = compile('
                          '); + var scope = compile('
                          '); scope.$eval(); expect(lowercase(element.html())).toEqual('hello'); }); - it('should ng-bind-template', function() { - var scope = compile('
                          '); + it('should ng:bind-template', function() { + var scope = compile('
                          '); scope.$set('name', 'Misko'); scope.$eval(); expect(element.text()).toEqual('Hello Misko!'); }); - it('should ng-bind-attr', function(){ - var scope = compile(''); + it('should ng:bind-attr', function(){ + var scope = compile(''); expect(element.attr('src')).toEqual('http://localhost/mysrc'); expect(element.attr('alt')).toEqual('myalt'); }); it('should remove special attributes on false', function(){ - var scope = compile(''); + var scope = compile(''); var input = scope.$element[0]; expect(input.disabled).toEqual(false); expect(input.readOnly).toEqual(false); @@ -83,15 +83,15 @@ describe("directives", function(){ expect(input.checked).toEqual(true); }); - it('should ng-non-bindable', function(){ - var scope = compile('
                          '); + it('should ng:non-bindable', function(){ + var scope = compile('
                          '); scope.$set('name', 'misko'); scope.$eval(); expect(element.text()).toEqual(''); }); - it('should ng-repeat over array', function(){ - var scope = compile('
                          '); + it('should ng:repeat over array', function(){ + var scope = compile('
                          '); scope.$set('items', ['misko', 'shyam']); scope.$eval(); @@ -106,28 +106,28 @@ describe("directives", function(){ expect(element.text()).toEqual('brad;'); }); - it('should ng-repeat over object', function(){ - var scope = compile('
                          '); + it('should ng:repeat over object', function(){ + var scope = compile('
                          '); scope.$set('items', {misko:'swe', shyam:'set'}); scope.$eval(); expect(element.text()).toEqual('misko:swe;shyam:set;'); }); - it('should set ng-repeat to [] if undefinde', function(){ - var scope = compile('
                          '); + it('should set ng:repeat to [] if undefinde', function(){ + var scope = compile('
                          '); expect(scope.items).toEqual([]); }); - it('should error on wrong parsing of ng-repeat', function(){ - var scope = compile('
                          '); + it('should error on wrong parsing of ng:repeat', function(){ + var scope = compile('
                          '); var log = ""; log += element.attr('ng-exception') + ';'; log += element.hasClass('ng-exception') + ';'; - expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); + expect(log).toEqual("\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); }); - it('should ng-watch', function(){ - var scope = compile('
                          '); + it('should ng:watch', function(){ + var scope = compile('
                          '); scope.$eval(); scope.$eval(); expect(scope.$get('count')).toEqual(0); @@ -138,8 +138,8 @@ describe("directives", function(){ expect(scope.$get('count')).toEqual(1); }); - it('should ng-click', function(){ - var scope = compile('
                          '); + it('should ng:click', function(){ + var scope = compile('
                          '); scope.$eval(); expect(scope.$get('clicked')).toBeFalsy(); @@ -147,16 +147,16 @@ describe("directives", function(){ expect(scope.$get('clicked')).toEqual(true); }); - it('should ng-class', function(){ - var scope = compile('
                          '); + it('should ng:class', function(){ + var scope = compile('
                          '); scope.$eval(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); expect(element.hasClass('B')).toBeTruthy(); }); - it('should ng-class odd/even', function(){ - var scope = compile('
                            • '); + it('should ng:class odd/even', function(){ + var scope = compile('
                                • '); scope.$eval(); var e1 = jqLite(element[0].childNodes[1]); var e2 = jqLite(element[0].childNodes[2]); @@ -166,14 +166,14 @@ describe("directives", function(){ expect(e2.hasClass('even')).toBeTruthy(); }); - it('should ng-style', function(){ - var scope = compile('
                                  '); + it('should ng:style', function(){ + var scope = compile('
                                  '); scope.$eval(); expect(element.css('color')).toEqual('red'); }); - it('should ng-show', function(){ - var scope = compile('
                                  '); + it('should ng:show', function(){ + var scope = compile('
                                  '); scope.$eval(); expect(isCssVisible(scope.$element)).toEqual(true); scope.$set('hide', true); @@ -181,8 +181,8 @@ describe("directives", function(){ expect(isCssVisible(scope.$element)).toEqual(false); }); - it('should ng-hide', function(){ - var scope = compile('
                                  '); + it('should ng:hide', function(){ + var scope = compile('
                                  '); scope.$eval(); expect(isCssVisible(scope.$element)).toEqual(false); scope.$set('show', true); @@ -190,7 +190,7 @@ describe("directives", function(){ expect(isCssVisible(scope.$element)).toEqual(true); }); - describe('ng-controller', function(){ + describe('ng:controller', function(){ it('should bind', function(){ window.Greeter = function(){ this.greeting = 'hello'; @@ -203,18 +203,18 @@ describe("directives", function(){ return this.greeting + ' ' + name + this.suffix; } }; - var scope = compile('
                                  '); + var scope = compile('
                                  '); expect(scope.greeting).toEqual('hello'); expect(scope.greet('misko')).toEqual('hello misko!'); window.Greeter = undefined; }); }); - it('should eval things according to ng-eval-order', function(){ + it('should eval things according to ng:eval-order', function(){ var scope = compile( - '
                                  ' + + '
                                  ' + '{{log = log + \'e\'}}' + - '' + + '' + '{{log = log + \'b\'}}' + '' + '' + diff --git a/test/markupSpec.js b/test/markupSpec.js index 8358b673..5fe5bba9 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -20,23 +20,23 @@ describe("markups", function(){ it('should translate {{}} in text', function(){ compile('
                                  hello {{name}}!
                                  '); - expect(sortedHtml(element)).toEqual('
                                  hello !
                                  '); + expect(sortedHtml(element)).toEqual('
                                  hello !
                                  '); scope.$set('name', 'Misko'); scope.$eval(); - expect(sortedHtml(element)).toEqual('
                                  hello Misko!
                                  '); + expect(sortedHtml(element)).toEqual('
                                  hello Misko!
                                  '); }); it('should translate {{}} in terminal nodes', function(){ compile(''); - expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); + expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); - expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); + expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); }); it('should translate {{}} in attributes', function(){ compile(''); - expect(element.attr('ng-bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); + expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); scope.$set('path', 'a/b'); scope.$eval(); expect(element.attr('src')).toEqual("http://server/a/b.png"); diff --git a/test/moveToAngularCom/miscTest.js b/test/moveToAngularCom/miscTest.js index aa0e1186..cc8f1c8c 100644 --- a/test/moveToAngularCom/miscTest.js +++ b/test/moveToAngularCom/miscTest.js @@ -1,7 +1,7 @@ BinderTest.prototype.testExpandEntityTagWithName = function(){ var c = this.compile('
                                  '); assertEquals( - '
                                  ', + '
                                  ', sortedHtml(c.node)); assertEquals("Person", c.scope.$get("friend.$entity")); assertEquals("friend", c.scope.$get("friend.$$anchor")); @@ -10,7 +10,7 @@ BinderTest.prototype.testExpandEntityTagWithName = function(){ BinderTest.prototype.testExpandSubmitButtonToAction = function(){ var html = this.compileToHtml(''); assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); - assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); + assertTrue(html, html.indexOf('ng:bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); }; BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ @@ -29,7 +29,7 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ assertEquals( - '
                                  ', + '
                                  ', this.compileToHtml('
                                  ')); }; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index d621b1f1..3020dfba 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -65,7 +65,7 @@ function sortedHtml(element) { var attrs = []; for(var i=0; i'); + compile(''); expect(scope.$get('name')).toEqual("Misko"); expect(scope.$get('count')).toEqual(0); @@ -382,7 +382,7 @@ describe("widget", function(){ describe('ng:switch', function(){ it('should switch on value change', function(){ - compile('
                                  first:{{name}}
                                  second:{{name}}
                                  '); + compile('
                                  first:{{name}}
                                  second:{{name}}
                                  '); expect(element.html()).toEqual(''); scope.select = 1; scope.$eval(); @@ -399,7 +399,7 @@ describe("widget", function(){ }); it("should match urls", function(){ - var scope = angular.compile('
                                  {{params.name}}
                                  '); + var scope = angular.compile('
                                  {{params.name}}
                                  '); scope.url = '/Book/Moby'; scope.$init(); expect(scope.$element.text()).toEqual('Moby'); @@ -412,7 +412,7 @@ describe("widget", function(){ }); it('should call init on switch', function(){ - var scope = angular.compile('
                                  {{name}}
                                  '); + var scope = angular.compile('
                                  {{name}}
                                  '); var cleared = false; scope.url = 'a'; scope.$invalidWidgets = {clearOrphans: function(){ -- 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 ++-- test/testabilityPatch.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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; } diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 3020dfba..b71943f6 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -81,7 +81,7 @@ function sortedHtml(element) { attr.name !='style' && attr.name.substr(0, 6) != 'jQuery') { // in IE we need to check for all of these. - if (!/ng:\d+/.exec(attr.name)) + if (!/ng-\d+/.exec(attr.name)) attrs.push(' ' + attr.name + '="' + attr.value + '"'); } } -- 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 +++++++++-- test/BinderTest.js | 6 ++---- 2 files changed, 11 insertions(+), 6 deletions(-) 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'; diff --git a/test/BinderTest.js b/test/BinderTest.js index 6dc47cce..ef1ef362 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -396,14 +396,12 @@ BinderTest.prototype.testBindClass = function() { c.scope.$set('class', 'testClass'); c.scope.$eval(); - assertEquals(sortedHtml(c.node), - '
                                  '); + assertEquals('
                                  ', sortedHtml(c.node)); c.scope.$set('class', ['a', 'b']); c.scope.$eval(); - assertEquals(sortedHtml(c.node), - '
                                  '); + assertEquals('
                                  ', sortedHtml(c.node)); }; BinderTest.prototype.testBindClassEvenOdd = function() { -- 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 --- Rakefile | 1 + src/scenario/DSL.js | 5 ++--- test/scenario/RunnerSpec.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index c8de5b78..4eb22ade 100644 --- a/Rakefile +++ b/Rakefile @@ -36,6 +36,7 @@ task :compile_scenario do lib/jquery/jquery-1.4.2.js \ src/scenario/angular.prefix \ src/Angular.js \ + src/jqLite.js \ src/JSON.js \ src/Scope.js \ src/Parser.js \ 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(); }); } diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 884e897a..bbdd9e8c 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -163,7 +163,7 @@ describe('Runner', function(){ expect(log).toEqual('first;second;'); next(); expect(log).toEqual('first;second;done;'); - expect(spec).not.toEqual(window); + expect(spec === window).toEqual(false); expect(spec).toEqual(firstThis); expect(spec).toEqual(secondThis); expect(spec).toEqual(doneThis); -- 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 --- java | 2 ++ src/directives.js | 3 ++- test/directivesSpec.js | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100755 java diff --git a/java b/java new file mode 100755 index 00000000..da0e133b --- /dev/null +++ b/java @@ -0,0 +1,2 @@ +#!/bin/sh +/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java $@ 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]; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 836c51e8..df0b5b94 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -93,15 +93,17 @@ describe("directives", function(){ it('should ng:repeat over array', function(){ var scope = compile('
                                  '); - scope.$set('items', ['misko', 'shyam']); + Array.prototype.extraProperty = "should be ignored"; + scope.items = ['misko', 'shyam']; scope.$eval(); expect(element.text()).toEqual('misko;shyam;'); + delete Array.prototype.extraProperty; - scope.$set('items', ['adam', 'kai', 'brad']); + scope.items = ['adam', 'kai', 'brad']; scope.$eval(); expect(element.text()).toEqual('adam;kai;brad;'); - scope.$set('items', ['brad']); + scope.items = ['brad']; scope.$eval(); expect(element.text()).toEqual('brad;'); }); -- 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 ++++---- test/BinderTest.js | 10 +++++----- test/FiltersTest.js | 6 +++--- test/ValidatorsTest.js | 6 +++--- test/delete/WidgetsTest.js | 6 +++--- test/servicesSpec.js | 2 +- test/widgetsSpec.js | 42 +++++++++++++++++++++--------------------- 9 files changed, 44 insertions(+), 44 deletions(-) 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}; diff --git a/test/BinderTest.js b/test/BinderTest.js index ef1ef362..1b1201fa 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -42,7 +42,7 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ }; BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ - var form = this.compile(''); + var form = this.compile(''); assertEquals(true, form.scope.model.price); }; @@ -508,8 +508,8 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { }; BinderTest.prototype.testValidateForm = function() { - var c = this.compile('
                                  ' + - '
                                  '); + var c = this.compile('
                                  ' + + '
                                  '); var items = [{}, {}]; c.scope.$set("items", items); c.scope.$eval(); @@ -537,7 +537,7 @@ BinderTest.prototype.testValidateForm = function() { }; BinderTest.prototype.testValidateOnlyVisibleItems = function(){ - var c = this.compile('
                                  '); + var c = this.compile('
                                  '); jqLite(document.body).append(c.node); c.scope.$set("show", true); c.scope.$eval(); @@ -660,7 +660,7 @@ BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { }; BinderTest.prototype.testItShouldUseFormaterForText = function() { - var x = this.compile(''); + var x = this.compile(''); x.scope.$eval(); assertEquals(['a','b'], x.scope.$get('a')); var input = x.node; diff --git a/test/FiltersTest.js b/test/FiltersTest.js index f839bb51..903a7a2f 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -6,11 +6,11 @@ FiltersTest.prototype.testCurrency = function(){ var currency = bind(context, angular.filter.currency); assertEquals(currency(0), '$0.00'); - assertEquals(html.hasClass('ng-format-negative'), false); + assertEquals(html.hasClass('ng:format-negative'), false); assertEquals(currency(-999), '$-999.00'); - assertEquals(html.hasClass('ng-format-negative'), true); + assertEquals(html.hasClass('ng:format-negative'), true); assertEquals(currency(1234.5678), '$1,234.57'); - assertEquals(html.hasClass('ng-format-negative'), false); + assertEquals(html.hasClass('ng:format-negative'), false); }; FiltersTest.prototype.testFilterThisIsContext = function(){ diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 573c340d..2e156f84 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -7,7 +7,7 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() { validator.last = last; validator._this = this; }; - var scope = compile(''); + var scope = compile(''); scope.name = 'misko'; scope.$init(); assertEquals('misko', validator.first); @@ -109,7 +109,7 @@ describe('Validator:asynchronous', function(){ it('should make a request and show spinner', function(){ var value, fn; - var scope = compile(''); + var scope = compile(''); scope.$init(); var input = scope.$element; scope.asyncFn = function(v,f){ @@ -151,7 +151,7 @@ describe('Validator:asynchronous', function(){ }); it("should handle update function", function(){ - var scope = angular.compile(''); + var scope = angular.compile(''); scope.asyncFn = jasmine.createSpy(); scope.updateFn = jasmine.createSpy(); scope.name = 'misko'; diff --git a/test/delete/WidgetsTest.js b/test/delete/WidgetsTest.js index 9acc6126..ccc87afd 100644 --- a/test/delete/WidgetsTest.js +++ b/test/delete/WidgetsTest.js @@ -1,7 +1,7 @@ WidgetTest = TestCase('WidgetTest'); WidgetTest.prototype.testRequired = function () { - var view = $(''); + var view = $(''); var scope = new Scope({$invalidWidgets:[]}); var cntl = new TextController(view[0], 'a', angularFormatter.noop); cntl.updateView(scope); @@ -14,7 +14,7 @@ WidgetTest.prototype.testRequired = function () { }; WidgetTest.prototype.testValidator = function () { - var view = $(''); + var view = $(''); var scope = new Scope({$invalidWidgets:[]}); var cntl = new TextController(view[0], 'a', angularFormatter.noop); angular.validator.testValidator = function(value, expect){ @@ -42,7 +42,7 @@ WidgetTest.prototype.testValidator = function () { }; WidgetTest.prototype.testRequiredValidator = function () { - var view = $(''); + var view = $(''); var scope = new Scope({$invalidWidgets:[]}); var cntl = new TextController(view[0], 'a', angularFormatter.noop); angular.validator.testValidator = function(value, expect){ diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f679a39b..32e7812a 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -136,7 +136,7 @@ describe("service", function(){ describe("$invalidWidgets", function(){ it("should count number of invalid widgets", function(){ - var scope = compile('').$init(); + var scope = compile('').$init(); expect(scope.$invalidWidgets.length).toEqual(1); scope.price = 123; scope.$eval(); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 158b24a8..1c9e698a 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -41,10 +41,10 @@ describe("widget", function(){ expect(scope.$get('count')).toEqual(2); }); - describe("ng-format", function(){ + describe("ng:format", function(){ it("should format text", function(){ - compile(''); + compile(''); expect(scope.$get('list')).toEqual(['a', 'b', 'c']); scope.$set('list', ['x', 'y', 'z']); @@ -57,7 +57,7 @@ describe("widget", function(){ }); it("should come up blank if null", function(){ - compile('', function(){ + compile('', function(){ scope.age = null; }); expect(scope.age).toBeNull(); @@ -65,7 +65,7 @@ describe("widget", function(){ }); it("should show incorect text while number does not parse", function(){ - compile(''); + compile(''); scope.age = 123; scope.$eval(); scope.$element.val('123X'); @@ -76,14 +76,14 @@ describe("widget", function(){ }); it("should clober incorect text if model changes", function(){ - compile(''); + compile(''); scope.age = 456; scope.$eval(); expect(scope.$element.val()).toEqual('456'); }); it("should not clober text if model changes doe to itself", function(){ - compile(''); + compile(''); scope.$element.val('a '); scope.$element.trigger('change'); @@ -107,7 +107,7 @@ describe("widget", function(){ }); it("should come up blank when no value specifiend", function(){ - compile(''); + compile(''); scope.$eval(); expect(scope.$element.val()).toEqual(''); expect(scope.age).toEqual(null); @@ -134,7 +134,7 @@ describe("widget", function(){ expect(scope.checkbox).toEqual(true); }); - it("should use ng-format", function(){ + it("should use ng:format", function(){ angularFormatter('testFormat', { parse: function(value){ return value ? "Worked" : "Failed"; @@ -146,7 +146,7 @@ describe("widget", function(){ } }); - compile(''); + compile(''); expect(scope.state).toEqual("Worked"); expect(scope.$element[0].checked).toEqual(true); @@ -161,9 +161,9 @@ describe("widget", function(){ }); }); - describe("ng-validate", function(){ - it("should process ng-validate", function(){ - compile(''); + describe("ng:validate", function(){ + it("should process ng:validate", function(){ + compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-validation-error')).toEqual('Not a number'); @@ -179,7 +179,7 @@ describe("widget", function(){ }); it('should not blow up for validation with bound attributes', function() { - compile(''); + compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-validation-error')).toEqual('Required'); @@ -192,7 +192,7 @@ describe("widget", function(){ it("should not call validator if undefined/empty", function(){ var lastValue = "NOT_CALLED"; angularValidator.myValidator = function(value){lastValue = value;}; - compile(''); + compile(''); expect(lastValue).toEqual("NOT_CALLED"); scope.url = 'http://server'; @@ -205,19 +205,19 @@ describe("widget", function(){ }); it("should ignore disabled widgets", function(){ - compile(''); + compile(''); expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-validation-error')).toBeFalsy(); }); it("should ignore readonly widgets", function(){ - compile(''); + compile(''); expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-validation-error')).toBeFalsy(); }); - it("should process ng-required", function(){ - compile(''); + it("should process ng:required", function(){ + compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-validation-error')).toEqual('Required'); @@ -232,8 +232,8 @@ describe("widget", function(){ expect(element.attr('ng-validation-error')).toEqual('Required'); }); - it('should allow conditions on ng-required', function() { - compile(''); + it('should allow conditions on ng:required', function() { + compile(''); scope.$set('ineedz', false); scope.$eval(); expect(element.hasClass('ng-validation-error')).toBeFalsy(); @@ -256,7 +256,7 @@ describe("widget", function(){ expect(element.attr('ng-validation-error')).toBeFalsy(); }); - it("should process ng-required2", function() { + it("should process ng:required2", function() { compile(''); expect(scope.$get('name')).toEqual("Misko"); -- 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 ++-- test/ResourceSpec.js | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) 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; } diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 4ab3537c..18b3979b 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -30,8 +30,7 @@ describe("resource", function() { it("should build resource with default param", function(){ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); - xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'ddd'}); - var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); + var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}, {verifyCache: 'blah'}); var item = LineItem.get({id:456}); xhr.flush(); nakedExpect(item).toEqual({id:'abc'}); @@ -136,6 +135,23 @@ describe("resource", function() { expect(person.name).toEqual('misko'); }); + it('should return the same object when verifying the cache', function(){ + var scope = angular.compile('
                                  '); + var Person = scope.$resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); + scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"misko"\n}\n]'); + var person = Person.query({id:123}); + scope.$browser.xhr.flush(); + expect(person[0].name).toEqual('misko'); + + scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"rob"\n}\n]'); + var person2 = Person.query({id:123}); + expect(person2[0].name).toEqual('misko'); + var person2Cache = person2; + scope.$browser.xhr.flush(); + expect(person2Cache).toEqual(person2); + expect(person2[0].name).toEqual('rob'); + }); + describe('failure mode', function(){ it('should report error when non 200', function(){ xhr.expectGET('/CreditCard/123').respond(500, "Server Error"); -- cgit v1.2.3 From ac3c2736c786abe996acc3d01d857dd5f0b3328a Mon Sep 17 00:00:00 2001 From: Rob Spies Date: Tue, 13 Jul 2010 14:15:01 -0700 Subject: Removes silly test addition. --- test/ResourceSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 18b3979b..4882e70e 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -30,7 +30,7 @@ describe("resource", function() { it("should build resource with default param", function(){ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); - var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}, {verifyCache: 'blah'}); + var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); var item = LineItem.get({id:456}); xhr.flush(); nakedExpect(item).toEqual({id:'abc'}); -- 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 +- test/widgetsSpec.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) 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')||''); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 1c9e698a..03f31bfe 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -22,7 +22,7 @@ describe("widget", function(){ describe("text", function(){ it('should input-text auto init and handle keyup/change events', function(){ - compile(''); + compile(''); expect(scope.$get('name')).toEqual("Misko"); expect(scope.$get('count')).toEqual(0); @@ -125,7 +125,7 @@ describe("widget", function(){ }); it('should support type="checkbox"', function(){ - compile(''); + compile(''); expect(scope.checkbox).toEqual(true); click(element); expect(scope.checkbox).toEqual(false); @@ -273,14 +273,14 @@ describe("widget", function(){ expect(scope.$get('name')).toEqual('Kai'); }); - it('should call ng-change on button click', function(){ - compile(''); + it('should call ng:change on button click', function(){ + compile(''); click(element); expect(scope.$get('clicked')).toEqual(true); }); it('should support button alias', function(){ - compile(''); + compile(''); click(element); expect(scope.$get('clicked')).toEqual(true); }); @@ -289,9 +289,9 @@ describe("widget", function(){ it('should support type="radio"', function(){ compile('
                                  ' + - '' + - '' + - '' + + '' + + '' + + '' + '
                                  '); var a = element[0].childNodes[0]; var b = element[0].childNodes[1]; @@ -373,8 +373,8 @@ describe("widget", function(){ expect(element.hasClass('ng-exception')).toBeTruthy(); }); - it('should report error on ng-change exception', function(){ - compile(''); + it('should report error on ng:change exception', function(){ + compile(''); click(element); expect(element.hasClass('ng-exception')).toBeTruthy(); }); -- cgit v1.2.3 From f084fd37dbc80d9701f417a726b4ac3232039d93 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 13 Jul 2010 15:40:39 -0700 Subject: romeve miscTest --- test/moveToAngularCom/miscTest.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 test/moveToAngularCom/miscTest.js diff --git a/test/moveToAngularCom/miscTest.js b/test/moveToAngularCom/miscTest.js deleted file mode 100644 index cc8f1c8c..00000000 --- a/test/moveToAngularCom/miscTest.js +++ /dev/null @@ -1,35 +0,0 @@ -BinderTest.prototype.testExpandEntityTagWithName = function(){ - var c = this.compile('
                                  '); - assertEquals( - '
                                  ', - sortedHtml(c.node)); - assertEquals("Person", c.scope.$get("friend.$entity")); - assertEquals("friend", c.scope.$get("friend.$$anchor")); -}; - -BinderTest.prototype.testExpandSubmitButtonToAction = function(){ - var html = this.compileToHtml(''); - assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); - assertTrue(html, html.indexOf('ng:bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); -}; - -BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ - expectAsserts(1); - var form = jQuery("body").append('
                                  '); - form.data('scope', new Scope()); - var factory = {}; - var binder = new Binder(form.get(0), factory, new MockLocation()); - factory.createController = function(node){ - assertEquals(node.attr('type'), 'file'); - return {updateModel:function(){}}; - }; - binder.compile(); - jQuery("#testTag").remove(); -}; - -BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ - assertEquals( - '
                                  ', - this.compileToHtml('
                                  ')); -}; - -- 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 +- test/directivesSpec.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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); }; }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index df0b5b94..ef4814bf 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -174,6 +174,13 @@ describe("directives", function(){ expect(element.css('color')).toEqual('red'); }); + it('should silently ignore undefined ng:style', function() { + var scope = compile('
                                  '); + scope.$eval(); + dump(sortedHtml(element)); + expect(element.hasClass('ng-exception')).toBeFalsy(); + }); + it('should ng:show', function(){ var scope = compile('
                                  '); scope.$eval(); -- 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 ++++++++- test/directivesSpec.js | 33 +++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 12 deletions(-) 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
                                  '); - scope.$eval(); - expect(element.css('color')).toEqual('red'); - }); + describe('ng:style', function(){ + it('should set', function(){ + var scope = compile('
                                  '); + scope.$eval(); + expect(element.css('color')).toEqual('red'); + }); - it('should silently ignore undefined ng:style', function() { - var scope = compile('
                                  '); - scope.$eval(); - dump(sortedHtml(element)); - expect(element.hasClass('ng-exception')).toBeFalsy(); + it('should silently ignore undefined style', function() { + var scope = compile('
                                  '); + scope.$eval(); + expect(element.hasClass('ng-exception')).toBeFalsy(); + }); + + it('should preserve and remove previus style', function(){ + var scope = compile('
                                  '); + scope.$eval(); + expect(element.css()).toEqual({color:'red'}); + scope.myStyle = {color:'blue', width:'10px'}; + scope.$eval(); + expect(element.css()).toEqual({color:'blue', width:'10px'}); + scope.myStyle = {}; + scope.$eval(); + expect(element.css()).toEqual({color:'red'}); + }); }); it('should ng:show', function(){ -- cgit v1.2.3 From 17d2ced9cc7e45d1d7272a1217861e598e5522dd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 14 Jul 2010 17:48:09 -0700 Subject: appease IE on CSS styles --- src/directives.js | 4 ++-- src/jqLite.js | 19 +++++++++++-------- test.sh | 2 +- test/BinderTest.js | 2 +- test/directivesSpec.js | 6 +++--- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/directives.js b/src/directives.js index 4e7c070b..bcc427e8 100644 --- a/src/directives.js +++ b/src/directives.js @@ -254,11 +254,11 @@ angularDirective("ng:hide", function(expression, element){ angularDirective("ng:style", function(expression, element){ return function(element){ - var resetStyle = element.css(); + var resetStyle = getStyle(element); this.$onEval(function(){ var style = this.$eval(expression) || {}, key, mergedStyle = {}; for(key in style) { - if (typeof resetStyle[key] == 'undefined') resetStyle[key] = null; + if (resetStyle[key] === undefined) resetStyle[key] = ''; mergedStyle[key] = style[key]; } for(key in resetStyle) { diff --git a/src/jqLite.js b/src/jqLite.js index a024507f..de1884a3 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -36,6 +36,16 @@ function jqClearData(element) { } } +function getStyle(element) { + var current = {}, style = element[0].style, value; + for (var name in style) { + value = style[name]; + if (1*name != name && name != 'cssText' && value && typeof value == 'string' && value !='false') + current[name] = value; + } + return current; +} + function JQLite(element) { if (isElement(element)) { this[0] = element; @@ -175,15 +185,8 @@ JQLite.prototype = { } else { return style[name]; } - } else if(name) { - extend(style, name); } else { - var current = {}; - for (var i=0; iabc'); c.scope.$eval(); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 8ce949aa..a42faa9a 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -184,13 +184,13 @@ describe("directives", function(){ it('should preserve and remove previus style', function(){ var scope = compile('
                                  '); scope.$eval(); - expect(element.css()).toEqual({color:'red'}); + expect(getStyle(element)).toEqual({color:'red'}); scope.myStyle = {color:'blue', width:'10px'}; scope.$eval(); - expect(element.css()).toEqual({color:'blue', width:'10px'}); + expect(getStyle(element)).toEqual({color:'blue', width:'10px'}); scope.myStyle = {}; scope.$eval(); - expect(element.css()).toEqual({color:'red'}); + expect(getStyle(element)).toEqual({color:'red'}); }); }); -- cgit v1.2.3 From 09e2295975b5bb8dfc067303fee86a9f2ebb433d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Jul 2010 09:41:25 -0700 Subject: updated list of JavaScript keywords --- src/Scope.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Scope.js b/src/Scope.js index 35da77fe..f577f695 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -48,10 +48,11 @@ function setter(instance, path, value){ var getterFnCache = {}; var JS_KEYWORDS = {}; foreach( - ["break", "const", "continue", "class", "delete", - "do", "while", "for", "function", "if", - "instanceof", "new", "return", "switch", - "this", "throw", "try", "catch", "with"], + ["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", + "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", + "if", "implements", "import", "ininstanceof", "intinterface", "long", "native", "new", "null", "package", "private", + "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", + "transient", "true", "try", "typeof", "var", "volatile", "void", "while", "with"], function(key){ JS_KEYWORDS[key] = true;} ); function getterFn(path){ -- cgit v1.2.3 From 9abd10e7b8a34b9dcd1a6af5ff37f57bd27cf920 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Jul 2010 13:13:21 -0700 Subject: proper handlig of $element in filters --- src/Angular.js | 4 +++ src/directives.js | 18 ++++++++----- src/widgets.js | 3 +-- test/directivesSpec.js | 72 ++++++++++++++++++++++++++++++++------------------ 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 2b26c88d..07e9096b 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -78,6 +78,10 @@ function extend(dst) { return dst; } +function inherit(parent, extra) { + return extend(new (extend(function(){}, {prototype:parent}))(), extra); +}; + function noop() {} function identity($) {return $;} function extensionMap(angular, name) { diff --git a/src/directives.js b/src/directives.js index bcc427e8..b57e5ecd 100644 --- a/src/directives.js +++ b/src/directives.js @@ -26,12 +26,13 @@ angularDirective("ng:bind", function(expression){ return function(element) { var lastValue = noop, lastError = noop; this.$onEval(function() { - var error, - value = this.$tryEval(expression, function(e){ - error = toJson(e); - }), - isHtml, - isDomElement; + var error, value, isHtml, isDomElement, + oldElement = this.hasOwnProperty('$element') ? this.$element : undefined; + this.$element = element; + value = this.$tryEval(expression, function(e){ + error = toJson(e); + }); + this.$element = oldElement; if (lastValue === value && lastError == error) return; isHtml = value instanceof HTML, isDomElement = isElement(value); @@ -74,7 +75,9 @@ function compileBindTemplate(template){ }); }); bindTemplateCache[template] = fn = function(element){ - var parts = [], self = this; + var parts = [], self = this, + oldElement = this.hasOwnProperty('$element') ? this.$element : undefined; + this.$element = element; for ( var i = 0; i < bindings.length; i++) { var value = bindings[i].call(self, element); if (isElement(value)) @@ -83,6 +86,7 @@ function compileBindTemplate(template){ value = toJson(value, true); parts.push(value); }; + this.$element = oldElement; return parts.join(''); }; } diff --git a/src/widgets.js b/src/widgets.js index 0b77dbf4..7bd51c8c 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -83,8 +83,7 @@ function valueAccessor(scope, element) { elementError(element, NG_VALIDATION_ERROR, null); invalidWidgets.markValid(element); } else { - var error, - validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element}); + var error, validateScope = inherit(scope, {$element:element}); error = required && !value ? 'Required' : (value ? validator(validateScope, value) : null); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index a42faa9a..b6ccf764 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -29,35 +29,57 @@ describe("directives", function(){ expect(scope.a).toEqual(2); }); - it('should ng:bind', function() { - var scope = compile('
                                  '); - expect(element.text()).toEqual(''); - scope.a = 'misko'; - scope.$eval(); - expect(element.text()).toEqual('misko'); - }); + describe('ng:bind', function(){ + it('should set text', function() { + var scope = compile('
                                  '); + expect(element.text()).toEqual(''); + scope.a = 'misko'; + scope.$eval(); + expect(element.text()).toEqual('misko'); + }); - it('should ng:bind html', function() { - var scope = compile('
                                  '); - scope.html = '
                                  hello
                                  '; - scope.$eval(); - expect(lowercase(element.html())).toEqual('
                                  hello
                                  '); - }); + it('should set html', function() { + var scope = compile('
                                  '); + scope.html = '
                                  hello
                                  '; + scope.$eval(); + expect(lowercase(element.html())).toEqual('
                                  hello
                                  '); + }); + + it('should set element element', function() { + angularFilter.myElement = function() { + return jqLite('hello'); + }; + var scope = compile('
                                  '); + scope.$eval(); + expect(lowercase(element.html())).toEqual('hello'); + }); + + it('should have $element set to current bind element', function(){ + angularFilter.myFilter = function(){ + this.$element.text('HELLO'); + }; + var scope = compile('
                                  before
                                  after
                                  '); + expect(scope.$element.text()).toEqual("beforeHELLOafter"); + }); - it('should ng:bind element', function() { - angularFilter.myElement = function() { - return jqLite('hello'); - }; - var scope = compile('
                                  '); - scope.$eval(); - expect(lowercase(element.html())).toEqual('hello'); }); - it('should ng:bind-template', function() { - var scope = compile('
                                  '); - scope.$set('name', 'Misko'); - scope.$eval(); - expect(element.text()).toEqual('Hello Misko!'); + describe('ng:bind-template', function(){ + it('should ng:bind-template', function() { + var scope = compile('
                                  '); + scope.$set('name', 'Misko'); + scope.$eval(); + expect(element.text()).toEqual('Hello Misko!'); + }); + + it('should have $element set to current bind element', function(){ + angularFilter.myFilter = function(){ + this.$element.text('HELLO'); + }; + var scope = compile('
                                  before
                                  after
                                  '); + expect(scope.$element.text()).toEqual("beforeHELLOafter"); + }); + }); it('should ng:bind-attr', function(){ -- cgit v1.2.3 From 1de82283dbf1bed2fc04700584dc1123b1e159fe Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Jul 2010 13:35:00 -0700 Subject: proper handlig of $element in filters --- src/directives.js | 6 +++--- test/directivesSpec.js | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/directives.js b/src/directives.js index b57e5ecd..04831131 100644 --- a/src/directives.js +++ b/src/directives.js @@ -76,8 +76,8 @@ function compileBindTemplate(template){ }); bindTemplateCache[template] = fn = function(element){ var parts = [], self = this, - oldElement = this.hasOwnProperty('$element') ? this.$element : undefined; - this.$element = element; + oldElement = this.hasOwnProperty('$element') ? self.$element : undefined; + self.$element = element; for ( var i = 0; i < bindings.length; i++) { var value = bindings[i].call(self, element); if (isElement(value)) @@ -86,7 +86,7 @@ function compileBindTemplate(template){ value = toJson(value, true); parts.push(value); }; - this.$element = oldElement; + self.$element = oldElement; return parts.join(''); }; } diff --git a/test/directivesSpec.js b/test/directivesSpec.js index b6ccf764..fb1e868a 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -73,11 +73,14 @@ describe("directives", function(){ }); it('should have $element set to current bind element', function(){ - angularFilter.myFilter = function(){ - this.$element.text('HELLO'); + var innerText; + angularFilter.myFilter = function(text){ + innerText = this.$element.text(); + return text; }; - var scope = compile('
                                  before
                                  after
                                  '); + var scope = compile('
                                  before
                                  INNER
                                  after
                                  '); expect(scope.$element.text()).toEqual("beforeHELLOafter"); + expect(innerText).toEqual('INNER'); }); }); -- cgit v1.2.3 From 7cef4358aea6f3cfa18dcfb8145d7bc0560bf157 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Jul 2010 14:16:04 -0700 Subject: fixed build --- src/filters.js | 2 +- src/jqLite.js | 17 ++++++++++++----- test/AngularSpec.js | 4 ++++ test/directivesSpec.js | 6 +++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/filters.js b/src/filters.js index 24464477..c8473af5 100644 --- a/src/filters.js +++ b/src/filters.js @@ -34,7 +34,7 @@ foreach({ return text; }, - 'date': function(amount) { + 'date': function(date) { }, 'json': function(object) { diff --git a/src/jqLite.js b/src/jqLite.js index de1884a3..cff9ae00 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -37,11 +37,18 @@ function jqClearData(element) { } function getStyle(element) { - var current = {}, style = element[0].style, value; - for (var name in style) { - value = style[name]; - if (1*name != name && name != 'cssText' && value && typeof value == 'string' && value !='false') - current[name] = value; + var current = {}, style = element[0].style, value, name, i; + if (typeof style.length == 'number') { + for(i = 0; i < style.length; i++) { + name = style[i]; + current[name] = style[name]; + } + } else { + for (name in style) { + value = style[name]; + if (1*name != name && name != 'cssText' && value && typeof value == 'string' && value !='false') + current[name] = value; + } } return current; } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index de724f03..6d462b14 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1,3 +1,7 @@ +beforeEach(function(){ + compileCache = {}; +}); + describe('Angular', function(){ xit('should fire on updateEvents', function(){ var onUpdateView = jasmine.createSpy(); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index fb1e868a..dffc8906 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -73,12 +73,12 @@ describe("directives", function(){ }); it('should have $element set to current bind element', function(){ - var innerText; + var innerText = 'blank'; angularFilter.myFilter = function(text){ innerText = this.$element.text(); return text; }; - var scope = compile('
                                  before
                                  INNER
                                  after
                                  '); + var scope = compile('
                                  beforeINNERafter
                                  '); expect(scope.$element.text()).toEqual("beforeHELLOafter"); expect(innerText).toEqual('INNER'); }); @@ -206,7 +206,7 @@ describe("directives", function(){ expect(element.hasClass('ng-exception')).toBeFalsy(); }); - it('should preserve and remove previus style', function(){ + it('should preserve and remove previous style', function(){ var scope = compile('
                                  '); scope.$eval(); expect(getStyle(element)).toEqual({color:'red'}); -- cgit v1.2.3 From cc097867f49673005d47a7f8f0cbe25f7d5c2163 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Jul 2010 14:35:04 -0700 Subject: add basic date support --- src/filters.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/filters.js b/src/filters.js index c8473af5..99d17405 100644 --- a/src/filters.js +++ b/src/filters.js @@ -35,6 +35,10 @@ foreach({ }, 'date': function(date) { + if (date instanceof Date) + return date.toLocaleDateString(); + else + return date; }, 'json': function(object) { -- cgit v1.2.3 From 7e96af0fdd9af8c479992363f68578305df0337e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Jul 2010 12:29:24 -0700 Subject: added equals method to angular.equals and $equals --- example/temp.html | 23 +++++++++++++++-------- src/Angular.js | 28 +++++++++++++++++++++++++++- src/AngularPublic.js | 1 + src/apis.js | 3 ++- test/AngularSpec.js | 27 +++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/example/temp.html b/example/temp.html index d07a6948..838a463d 100644 --- a/example/temp.html +++ b/example/temp.html @@ -1,13 +1,20 @@ - - + + - + + - {{$location.hashSearch.order}}
                                  - A
                                  - B
                                  - C
                                  - {{$location.hashSearch.order}}
                                  + Hello {{'World'}}! diff --git a/src/Angular.js b/src/Angular.js index 07e9096b..e39e31c9 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -263,6 +263,32 @@ function copy(source, destination){ } } +function equals(o1, o2) { + if (o1 == o2) return true; + var t1 = typeof o1, t2 = typeof o2, length, key, keySet; + if (t1 == t2 && t1 == 'object') { + if (o1 instanceof Array) { + if ((length = o1.length) == o2.length) { + for(key=0; key - + src="../src/angular-bootstrap.js#autobind"> - + Hello {{'World'}}! diff --git a/src/Angular.js b/src/Angular.js index e39e31c9..8c0b591d 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -22,7 +22,7 @@ var consoleNode, angularTextMarkup = extensionMap(angular, 'textMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'), angularDirective = extensionMap(angular, 'directive'), - angularWidget = extensionMap(angular, 'widget'), + angularWidget = extensionMap(angular, 'widget', lowercase), angularValidator = extensionMap(angular, 'validator'), angularFilter = extensionMap(angular, 'filter'), angularFormatter = extensionMap(angular, 'formatter'), @@ -84,9 +84,10 @@ function inherit(parent, extra) { function noop() {} function identity($) {return $;} -function extensionMap(angular, name) { +function extensionMap(angular, name, transform) { var extPoint; return angular[name] || (extPoint = angular[name] = function (name, fn, prop){ + name = (transform || identity)(name); if (isDefined(fn)) { extPoint[name] = extend(fn, prop || {}); } @@ -419,7 +420,7 @@ function angularInit(config){ function angularJsConfig(document) { var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/, - scripts = document.getElementsByTagName("SCRIPT"), + scripts = document.getElementsByTagName("script"), match; for(var j = 0; j < scripts.length; j++) { match = (scripts[j].src || "").match(filename); diff --git a/src/AngularPublic.js b/src/AngularPublic.js index 817a1f93..e2e576fd 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -18,6 +18,8 @@ extend(angular, { 'foreach': foreach, 'noop':noop, 'bind':bind, + 'toJson': toJson, + 'fromJson': fromJson, 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, diff --git a/src/Compiler.js b/src/Compiler.js index 9faafb13..a6fd88ec 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -121,20 +121,25 @@ 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; + try { + priority = element.attr('ng:eval-order') || priority || 0; + } catch (e) { + // for some reason IE throws error under some weird circumstances. so just assume nothing + priority = priority || 0; + } if (isString(priority)) { priority = PRIORITY[uppercase(priority)] || 0; } template = new Template(priority); eachAttribute(element, function(value, name){ if (!widget) { - if (widget = self.widgets['@' + name]) { + if (widget = self.widgets('@' + name)) { widget = bind(selfApi, widget, value, element); } } }); if (!widget) { - if (widget = self.widgets[nodeName(element)]) { + if (widget = self.widgets(nodeName(element))) { widget = bind(selfApi, widget, element); } } diff --git a/src/apis.js b/src/apis.js index 2d0c571e..136473b6 100644 --- a/src/apis.js +++ b/src/apis.js @@ -12,6 +12,7 @@ var angularGlobal = { }; var angularCollection = { + 'copy': copy, 'size': size, 'equals': equals }; diff --git a/src/services.js b/src/services.js index ed6f73ad..c9799b32 100644 --- a/src/services.js +++ b/src/services.js @@ -65,13 +65,13 @@ angularService("$location", function(browser){ }, {inject: ['$browser']}); angularService("$log", function($window){ - var console = $window.console, - log = console && console.log || noop; + var console = $window.console || {log: noop, warn: noop, info: noop, error: noop}, + log = console.log || noop; return { - log: log, - warn: console && console.warn || log, - info: console && console.info || log, - error: console && console.error || log + log: bind(console, log), + warn: bind(console, console.warn || log), + info: bind(console, console.info || log), + error: bind(console, console.error || log) }; }, {inject:['$window']}); diff --git a/src/widgets.js b/src/widgets.js index 7bd51c8c..5f0fcf7c 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -222,16 +222,16 @@ function inputWidgetSelector(element){ return INPUT_TYPE[lowercase(element[0].type)] || noop; } -angularWidget('INPUT', inputWidgetSelector); -angularWidget('TEXTAREA', inputWidgetSelector); -angularWidget('BUTTON', inputWidgetSelector); -angularWidget('SELECT', function(element){ +angularWidget('input', inputWidgetSelector); +angularWidget('textarea', inputWidgetSelector); +angularWidget('button', inputWidgetSelector); +angularWidget('select', function(element){ this.descend(true); return inputWidgetSelector.call(this, element); }); -angularWidget('NG:INCLUDE', function(element){ +angularWidget('ng:include', function(element){ var compiler = this, srcExp = element.attr("src"), scopeExp = element.attr("scope") || ''; @@ -265,7 +265,7 @@ angularWidget('NG:INCLUDE', function(element){ } }); -var ngSwitch = angularWidget('NG:SWITCH', function (element){ +var ngSwitch = angularWidget('ng:switch', function (element){ var compiler = this, watchExpr = element.attr("on"), usingExpr = (element.attr("using") || 'equals'), diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index da354ea5..3736ff4e 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -22,7 +22,7 @@ describe('compiler', function(){ }; textMarkup = []; attrMarkup = []; - widgets = {}; + widgets = extensionMap({}, 'widget'); compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compile = function(html){ var e = jqLite("
                                  " + html + "
                                  "); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 03f31bfe..ad98e482 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -407,7 +407,7 @@ describe("widget", function(){ it("should match sandwich ids", function(){ var scope = {}; - var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); + var match = angular.widget('NG:SWITCH').route.call(scope, '/a/123/b', '/a/:id'); expect(match).toBeFalsy(); }); -- cgit v1.2.3 From 0f4b068bd66cde63b222b114dbc1c5fec257a890 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 20 Jul 2010 17:03:34 -0700 Subject: fix test --- test/servicesSpec.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 32e7812a..90f3d12b 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -33,32 +33,36 @@ describe("service", function(){ describe("$log", function(){ it('should use console if present', function(){ - function log(){}; - function warn(){}; - function info(){}; - function error(){}; + var logger = ""; + function log(){ logger+= 'log;'; }; + function warn(){ logger+= 'warn;'; }; + function info(){ logger+= 'info;'; }; + function error(){ logger+= 'error;'; }; var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}}); - expect(scope.$log.log).toEqual(log); - expect(scope.$log.warn).toEqual(warn); - expect(scope.$log.info).toEqual(info); - expect(scope.$log.error).toEqual(error); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); + expect(logger).toEqual('log;warn;info;error;'); }); it('should use console.log if other not present', function(){ - function log(){}; + var logger = ""; + function log(){ logger+= 'log;'; }; var scope = createScope(null, angularService, {$window: {console:{log:log}}}); - expect(scope.$log.log).toEqual(log); - expect(scope.$log.warn).toEqual(log); - expect(scope.$log.info).toEqual(log); - expect(scope.$log.error).toEqual(log); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); + expect(logger).toEqual('log;log;log;log;'); }); it('should use noop if no console', function(){ var scope = createScope(null, angularService, {$window: {}}); - expect(scope.$log.log).toEqual(noop); - expect(scope.$log.warn).toEqual(noop); - expect(scope.$log.info).toEqual(noop); - expect(scope.$log.error).toEqual(noop); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); }); }); -- cgit v1.2.3 From 719f6e15a052d50f30dcecc722193804a3d5eaed Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 20 Jul 2010 17:13:31 -0700 Subject: clean up error handling a bit. --- src/Angular.js | 33 --------------------------------- src/Scope.js | 2 +- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 8c0b591d..62747cf8 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -30,10 +30,6 @@ var consoleNode, angularCallbacks = extensionMap(angular, 'callbacks'), nodeName; -function angularAlert(){ - log(arguments); window.alert.apply(window, arguments); -} - function foreach(obj, iterator, context) { var key; if (obj) { @@ -178,21 +174,6 @@ function indexOf(array, obj) { return -1; } -function log(a, b, c){ - var console = window['console']; - switch(arguments.length) { - case 1: - console['log'](a); - break; - case 2: - console['log'](a, b); - break; - default: - console['log'](a, b, c); - break; - } -} - function error(a, b, c){ var console = window['console']; switch(arguments.length) { @@ -208,20 +189,6 @@ function error(a, b, c){ } } -function consoleLog(level, objs) { - var log = document.createElement("div"); - log.className = level; - var msg = ""; - var sep = ""; - for ( var i = 0; i < objs.length; i++) { - var obj = objs[i]; - msg += sep + (typeof obj == 'string' ? obj : toJson(obj)); - sep = " "; - } - log.appendChild(document.createTextNode(msg)); - consoleNode.appendChild(log); -} - function isLeafNode (node) { if (node) { switch (node.nodeName) { diff --git a/src/Scope.js b/src/Scope.js index f577f695..549cc944 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -147,7 +147,7 @@ function createScope(parent, services, existing) { try { return expressionCompile(expression).apply(instance, slice.call(arguments, 2, arguments.length)); } catch (e) { - error(e); + (instance.$log || {error:error}).error(e); if (isFunction(exceptionHandler)) { exceptionHandler(e); } else if (exceptionHandler) { -- cgit v1.2.3 From b5bbfaeb80c3f89c65d14c72cff6f0e1c8aa497a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Jul 2010 13:28:14 -0700 Subject: clean up error reporting --- src/Angular.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 62747cf8..404d241d 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -3,8 +3,6 @@ if (typeof document.getAttribute == 'undefined') document.getAttribute = function() {}; -if (!window['console']) window['console']={'log':noop, 'error':noop}; - var consoleNode, PRIORITY_FIRST = -99999, PRIORITY_WATCH = -1000, @@ -18,6 +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, angular = window['angular'] || (window['angular'] = {}), angularTextMarkup = extensionMap(angular, 'textMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'), @@ -174,21 +173,6 @@ function indexOf(array, obj) { return -1; } -function error(a, b, c){ - var console = window['console']; - switch(arguments.length) { - case 1: - console['error'](a); - break; - case 2: - console['error'](a, b); - break; - default: - console['error'](a, b, c); - break; - } -} - function isLeafNode (node) { if (node) { switch (node.nodeName) { -- cgit v1.2.3 From 849a05b5a578f19ddc3d24dc9fbd304e0e07612a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Jul 2010 11:18:32 -0700 Subject: added jsonp to resources --- example/buzz/buzz.css | 0 example/buzz/buzz.html | 30 ++++++++++++++++++++++++++++++ example/buzz/buzz.js | 19 +++++++++++++++++++ src/AngularPublic.js | 5 ++++- src/Browser.js | 48 +++++++++++++++++++++++++++++++----------------- src/Resource.js | 3 ++- test/BrowserSpecs.js | 28 ++++++++++++++++++++++++++-- test/ResourceSpec.js | 12 ++++++++++++ test/angular-mocks.js | 1 + 9 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 example/buzz/buzz.css create mode 100644 example/buzz/buzz.html create mode 100644 example/buzz/buzz.js diff --git a/example/buzz/buzz.css b/example/buzz/buzz.css new file mode 100644 index 00000000..e69de29b diff --git a/example/buzz/buzz.html b/example/buzz/buzz.html new file mode 100644 index 00000000..ee2b2bb9 --- /dev/null +++ b/example/buzz/buzz.html @@ -0,0 +1,30 @@ + + + + + + + + + +
                                  + + +
                                  + + + diff --git a/example/buzz/buzz.js b/example/buzz/buzz.js new file mode 100644 index 00000000..871982d7 --- /dev/null +++ b/example/buzz/buzz.js @@ -0,0 +1,19 @@ +angular.service('myApplication', function($resource){ + this.Activity = $resource( + 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments', + {alt:'json', callback:'JSON_CALLBACK'}, + { + get: {method:'JSON', params:{visibility:'@self'}}, + replies: {method:'JSON', params:{visibility:'@self', comments:'@comments'}} + }); +}, {inject:['$resource']}); + +function BuzzController(){ + this.$watch('$location.hashPath', this.userChange); +} +BuzzController.prototype = { + userChange: function(){ + this.userId = this.$location.hashPath; + this.activities = this.Activity.get({userId:this.userId}); + } +}; diff --git a/src/AngularPublic.js b/src/AngularPublic.js index e2e576fd..7b093f88 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -1,7 +1,10 @@ var browserSingleton; angularService('$browser', function browserFactory(){ if (!browserSingleton) { - browserSingleton = new Browser(window.location, window.document); + browserSingleton = new Browser( + window.location, + jqLite(window.document), + jqLite(window.document.getElementsByTagName('head')[0])); browserSingleton.startUrlWatcher(); browserSingleton.bind(); } diff --git a/src/Browser.js b/src/Browser.js index 0552b3ae..3299540c 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -2,7 +2,7 @@ // Browser ////////////////////////////// -function Browser(location, document) { +function Browser(location, document, head) { this.delay = 50; this.expectedUrl = location.href; this.urlListeners = []; @@ -21,8 +21,9 @@ function Browser(location, document) { }; this.location = location; - this.document = jqLite(document); - this.body = jqLite(document.body); + this.document = document; + this.head = head; + this.idCounter = 0; } Browser.prototype = { @@ -58,21 +59,34 @@ Browser.prototype = { callback = post; post = null; } - var xhr = new this.XHR(), - self = this; - xhr.open(method, url, true); - this.outstandingRequests.count ++; - xhr.onreadystatechange = function() { - if (xhr.readyState == 4) { - try { - callback(xhr.status || 200, xhr.responseText); - } finally { - self.outstandingRequests.count--; - self.processRequestCallbacks(); + if (lowercase(method) == 'json') { + var callbackId = "angular_" + Math.random() + '_' + (this.idCounter++); + callbackId = callbackId.replace(/\d\./, ''); + var script = this.document[0].createElement('script'); + script.type = 'text/javascript'; + script.src = url.replace('JSON_CALLBACK', callbackId); + this.head.append(script); + window[callbackId] = function(data){ + delete window[callbackId]; + callback(200, data); + }; + } else { + var xhr = new this.XHR(), + self = this; + xhr.open(method, url, true); + this.outstandingRequests.count ++; + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + try { + callback(xhr.status || 200, xhr.responseText); + } finally { + self.outstandingRequests.count--; + self.processRequestCallbacks(); + } } - } - }; - xhr.send(post || ''); + }; + xhr.send(post || ''); + } }, processRequestCallbacks: function(){ diff --git a/src/Resource.js b/src/Resource.js index 1279dc54..f4f26ebd 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -28,6 +28,7 @@ Route.prototype = { query.push(encodeURI(key) + '=' + encodeURI(value)); } }); + url = url.replace(/\/*$/, ''); return url + (query.length ? '?' + query.join('&') : ''); } }; @@ -88,7 +89,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)), diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 3ce158b4..a9f61a6b 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -1,10 +1,15 @@ describe('browser', function(){ - var browser, location; + var browser, location, head; beforeEach(function(){ location = {href:"http://server", hash:""}; - browser = new Browser(location, {}); + document = jqLite(window.document); + head = { + scripts: [], + append: function(node){head.scripts.push(node);} + }; + browser = new Browser(location, jqLite(window.document), head); browser.setTimeout = noop; }); @@ -45,4 +50,23 @@ describe('browser', function(){ }); }); + describe('xhr', function(){ + describe('JSON', function(){ + it('should add script tag for request', function() { + var log = ""; + browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', function(code, data){ + log += code + ':' + data + ';'; + }); + expect(head.scripts.length).toEqual(1); + var url = head.scripts[0].src.split('?cb='); + expect(url[0]).toEqual('http://example.org/path'); + expect(typeof window[url[1]]).toEqual('function'); + window[url[1]]('data'); + expect(log).toEqual('200:data;'); + expect(typeof window[url[1]]).toEqual('undefined'); + + }); + }); + }); + }); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 4882e70e..6e32ce18 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -28,6 +28,18 @@ describe("resource", function() { resource.route('URL').query(); }); + it('should ignore slashes of undefinend parameters', function(){ + var R = resource.route('/Path/:a/:b/:c'); + xhr.expectGET('/Path').respond({}); + xhr.expectGET('/Path/1').respond({}); + xhr.expectGET('/Path/2/3').respond({}); + xhr.expectGET('/Path/4/5/6').respond({}); + R.get({}); + R.get({a:1}); + R.get({a:2, b:3}); + R.get({a:4, b:5, c:6}); + }); + it("should build resource with default param", function(){ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 8838b2cd..bac2e800 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -66,6 +66,7 @@ function MockBrowser() { self.xhr.expectPOST = angular.bind(self, self.xhr.expect, 'POST'); self.xhr.expectDELETE = angular.bind(self, self.xhr.expect, 'DELETE'); self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT'); + self.xhr.expectJSON = angular.bind(self, self.xhr.expect, 'JSON'); self.xhr.flush = function() { while(requests.length) { requests.pop()(); -- cgit v1.2.3 From 2987f7f705baffad8081fc4a3a95eab79b0d9695 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Jul 2010 15:32:57 -0700 Subject: fix howers which were accidently broken --- example/buzz/buzz.css | 45 +++++++++++++++++++++++++++++++++++++++++++++ example/buzz/buzz.html | 36 ++++++++++++++++++++++-------------- example/buzz/buzz.js | 27 +++++++++++++++++++++++++++ src/Browser.js | 1 + src/directives.js | 2 -- test/BinderTest.js | 9 +-------- test/directivesSpec.js | 5 ----- 7 files changed, 96 insertions(+), 29 deletions(-) diff --git a/example/buzz/buzz.css b/example/buzz/buzz.css index e69de29b..e77c3bac 100644 --- a/example/buzz/buzz.css +++ b/example/buzz/buzz.css @@ -0,0 +1,45 @@ +body { + background: -webkit-gradient(linear, left top, left 400, from(#1C4070), to(#fff)); + background-repeat: no-repeat; + margin: 0px; +} + +.bar { + border-top: 1px solid white; + border-bottom: 1px solid black; + text-align: right; + background: -webkit-gradient(linear, left top, left bottom, from(#CCC), to(#888)); + -webkit-background-origin: padding; -webkit-background-clip: content; +} +.bar button { + margin: 5px; +} + +.bar span { + float: left; + font-family: monospace; + font-size: 1.5em; + color: black; +} + +ul.buzz { + list-style: none; + padding: 5px; + margin: 0; +} + +ul.buzz > li { + border: 1px solid yellow; + margin: 5px; + padding: 0; +} + +ul.buzz > li > h1 { + border: 1px solid yellow; + margin: 0; +} + +ul.buzz > li > div { + border: 1px solid yellow; + margin: 0; +} diff --git a/example/buzz/buzz.html b/example/buzz/buzz.html index ee2b2bb9..f1916f54 100644 --- a/example/buzz/buzz.html +++ b/example/buzz/buzz.html @@ -2,28 +2,36 @@ + - +
                                  - + <angular/> Buzz +
                                  -
                                    + diff --git a/example/buzz/buzz.js b/example/buzz/buzz.js index 871982d7..40813d16 100644 --- a/example/buzz/buzz.js +++ b/example/buzz/buzz.js @@ -15,5 +15,32 @@ BuzzController.prototype = { userChange: function(){ this.userId = this.$location.hashPath; this.activities = this.Activity.get({userId:this.userId}); + }, + + expandReplies: function(activity) { + var self = this; + if (activity.replies) { + activity.replies.show = !activity.replies.show; + } else { + activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id}, function(){ + activity.replies.show = true; + }); + } } }; + +angular.widget('my:expand', function(element){ + element.css('display', 'block'); + this.descend(true); + return function(element) { + element.hide(); + var watch = element.attr('expand'); + this.$watch(watch, function(value){ + if (value) { + element.delay(0).slideDown('slow'); + } else { + element.slideUp('slow'); + } + }); + }; +}); diff --git a/src/Browser.js b/src/Browser.js index 3299540c..2777dcda 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -22,6 +22,7 @@ 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/directives.js b/src/directives.js index 04831131..3e0aeffb 100644 --- a/src/directives.js +++ b/src/directives.js @@ -161,8 +161,6 @@ angularWidget("@ng:repeat", function(expression, element){ valueIdent = match[3] || match[1]; keyIdent = match[2]; - if (isUndefined(this.$eval(rhs))) this.$set(rhs, []); - var children = [], currentScope = this; this.$onEval(function(){ var index = 0, childCount = children.length, childScope, lastElement = reference, diff --git a/test/BinderTest.js b/test/BinderTest.js index 44f918e4..b90d1789 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -27,7 +27,7 @@ BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ state.scope.$eval(); assertEquals('abc', state.scope.model.price); }; - + BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ var c = this.compile(''); c.scope.$eval(); @@ -472,13 +472,6 @@ BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { assertEquals("misko", c.scope.$eval('items[1].name')); }; -BinderTest.prototype.testRepeaterShouldCreateArray = function () { - var c = this.compile(''); - c.scope.$eval(); - - assertEquals(0, c.scope.$get('items').length); -}; - BinderTest.prototype.testShouldTemplateBindPreElements = function () { var c = this.compile('
                                    Hello {{name}}!
                                    '); c.scope.$set("name", "World"); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index dffc8906..8a7da41d 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -140,11 +140,6 @@ describe("directives", function(){ expect(element.text()).toEqual('misko:swe;shyam:set;'); }); - it('should set ng:repeat to [] if undefinde', function(){ - var scope = compile('
                                    '); - expect(scope.items).toEqual([]); - }); - it('should error on wrong parsing of ng:repeat', function(){ var scope = compile('
                                    '); var log = ""; -- cgit v1.2.3 From 8015e09e383bcd3ebf85d44cd68c67dd85db5771 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 10:48:18 -0700 Subject: added buzz demo, fix undefined() -> undefined --- example/buzz/buzz.css | 72 ++++++++++++++++++++++++++++++++++++++++---------- example/buzz/buzz.html | 30 ++++++++++++++------- src/Parser.js | 2 ++ test/ScopeSpec.js | 5 ++++ 4 files changed, 86 insertions(+), 23 deletions(-) diff --git a/example/buzz/buzz.css b/example/buzz/buzz.css index e77c3bac..5fd5763d 100644 --- a/example/buzz/buzz.css +++ b/example/buzz/buzz.css @@ -1,45 +1,89 @@ body { - background: -webkit-gradient(linear, left top, left 400, from(#1C4070), to(#fff)); + background: -webkit-gradient(linear, left top, left 100, from(#bbb), to(#fff)); background-repeat: no-repeat; margin: 0px; + font-family: sans-serif; + font-size: 12px; } -.bar { +body > div { border-top: 1px solid white; border-bottom: 1px solid black; - text-align: right; + text-align: center; background: -webkit-gradient(linear, left top, left bottom, from(#CCC), to(#888)); -webkit-background-origin: padding; -webkit-background-clip: content; } -.bar button { +body > div button { margin: 5px; } -.bar span { +body > div span:FIRST-CHILD { float: left; font-family: monospace; font-size: 1.5em; color: black; + padding: 2px 5px; } -ul.buzz { +body > div span:last-child { + float: right; +} + +ul { list-style: none; - padding: 5px; + padding: 10px; margin: 0; } -ul.buzz > li { - border: 1px solid yellow; - margin: 5px; +body > ul > li { + border: 1px solid black; + margin: 15px 5px; padding: 0; + -webkit-box-shadow: 5px 5px 5px #888; +} + +body > ul > li > h1 { + margin: 0; + background: -webkit-gradient(linear, left top, left bottom, from(#ddd), to(#999)); + font-size: 13px; + border-bottom: 1px solid black; +} + +h1 > img, +li > img { + max-height: 30px; + max-width: 30px; + vertical-align: middle; + padding: 3px; } -ul.buzz > li > h1 { - border: 1px solid yellow; +a > img { + margin-right: 5px; + margin-top: 5px; +} + +body > ul > li > h1 > a:last-child { + float: right; + margin: 10px; +} + +body > ul > li > div { + background-color: white; + background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ddd)); margin: 0; + padding: 10px; } -ul.buzz > li > div { - border: 1px solid yellow; +body > ul > li ul { margin: 0; + padding: 0; + margin-left: 5px; + border-left: 5px solid lightgray; } + +body > ul > li ul > li { + margin: 0; + padding: 10px; + background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ddd)); +} + diff --git a/example/buzz/buzz.html b/example/buzz/buzz.html index f1916f54..a6777ff8 100644 --- a/example/buzz/buzz.html +++ b/example/buzz/buzz.html @@ -2,32 +2,44 @@ - - + + -
                                    +
                                    <angular/> Buzz - - + + filter: + + + + user: + + +
                                    -
                                      -
                                    • +
                                        +
                                      • {{item.actor.name}} + Replies: {{item.links.replies[0].count}}

                                        {{item.object.content | html}} - Replies: {{item.links.replies[0].count}} +
                                        + + + +
                                        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."; } diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index d93400e5..013b1bfc 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -15,6 +15,11 @@ describe('scope/model', function(){ expect(model.$root).toEqual(model); }); + it('should return noop function when LHS is undefined', function(){ + var model = createScope(); + expect(model.$eval('x.$filter()')).toEqual(undefined); + }); + describe('$eval', function(){ it('should eval function with correct this and pass arguments', function(){ var model = createScope(); -- 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 +++++----- test/BrowserSpecs.js | 1 - test/servicesSpec.js | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) 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 = []; diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index a9f61a6b..48387b4d 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -4,7 +4,6 @@ describe('browser', function(){ beforeEach(function(){ location = {href:"http://server", hash:""}; - document = jqLite(window.document); head = { scripts: [], append: function(node){head.scripts.push(node);} diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 90f3d12b..031c48f0 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,5 +1,5 @@ describe("service", function(){ - var scope, $xhrError, $log; + var scope, $xhrError, $log, mockServices; beforeEach(function(){ $xhrError = jasmine.createSpy('$xhr.error'); @@ -38,7 +38,7 @@ describe("service", function(){ function warn(){ logger+= 'warn;'; }; function info(){ logger+= 'info;'; }; function error(){ logger+= 'error;'; }; - var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}}); + var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); @@ -49,7 +49,7 @@ describe("service", function(){ it('should use console.log if other not present', function(){ var logger = ""; function log(){ logger+= 'log;'; }; - var scope = createScope(null, angularService, {$window: {console:{log:log}}}); + var scope = createScope(null, angularService, {$window: {console:{log:log}}, $document:[{}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); @@ -58,7 +58,7 @@ describe("service", function(){ }); it('should use noop if no console', function(){ - var scope = createScope(null, angularService, {$window: {}}); + var scope = createScope(null, angularService, {$window: {}, $document:[{}]}); scope.$log.log(); scope.$log.warn(); scope.$log.info(); -- 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 +- test/BrowserSpecs.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 { diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 48387b4d..99632928 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -63,7 +63,6 @@ describe('browser', function(){ window[url[1]]('data'); expect(log).toEqual('200:data;'); expect(typeof window[url[1]]).toEqual('undefined'); - }); }); }); -- 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(-) 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(-) 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 b2b170099f957e6575e309c35fed42915e95dd47 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 23 Jul 2010 13:54:12 -0700 Subject: fix issues with ie 7 --- test/BinderTest.js | 4 ++++ test/testabilityPatch.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/test/BinderTest.js b/test/BinderTest.js index b90d1789..f38383ae 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -407,6 +407,10 @@ BinderTest.prototype.testBindClass = function() { BinderTest.prototype.testBindClassEvenOdd = function() { var x = this.compile('
                                        '); x.scope.$eval(); + var d1 = jqLite(x.node[0].childNodes[1]); + var d2 = jqLite(x.node[0].childNodes[2]); + expect(d1.hasClass('o')).toBeTruthy(); + expect(d2.hasClass('e')).toBeTruthy(); assertEquals( '
                                        <#comment>' + '
                                        ' + diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index b71943f6..5d0df780 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -63,6 +63,8 @@ function sortedHtml(element) { html += '<' + node.nodeName.toLowerCase(); var attributes = node.attributes || []; var attrs = []; + if (node.className) + attrs.push(' class="' + node.className + '"'); for(var i=0; i -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('