diff options
| -rw-r--r-- | example/widgets.html | 21 | ||||
| -rw-r--r-- | jsTestDriver.conf | 1 | ||||
| -rw-r--r-- | src/Widgets.js | 25 | ||||
| -rw-r--r-- | src/angular-bootstrap.js | 55 |
4 files changed, 90 insertions, 12 deletions
diff --git a/example/widgets.html b/example/widgets.html new file mode 100644 index 00000000..ced5ffd6 --- /dev/null +++ b/example/widgets.html @@ -0,0 +1,21 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <script type="text/javascript" src="../lib/underscore/underscore.js"></script> + <script type="text/javascript" src="../lib/jquery/jquery-1.3.2.js"></script> + <script type="text/javascript" src="../src/angular-bootstrap.js"></script> + <script type="text/javascript"> + $(document).ready(function(){ + angular.compile(document).init(); + }); + </script> + </head> + <body> + <input name="form.list" ng-format="list" /> + <input name="form.list" ng-format="list" /> + <hr/> + <input type="checkbox" name="form.boolean" ng-format="boolean" value="true" checked="checked" /> + <input type="checkbox" name="form.boolean" ng-format="boolean" value="true" /> + <pre>{{form}}</pre> + </body> +</html> diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 766b8c73..8b36e7d4 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -18,3 +18,4 @@ load: exclude: - src/angular.prefix - src/angular.suffix + - src/angular-bootstrap.js diff --git a/src/Widgets.js b/src/Widgets.js index d392d285..69b444c0 100644 --- a/src/Widgets.js +++ b/src/Widgets.js @@ -195,7 +195,7 @@ function TextController(view, exp, formatter) { this.required = typeof view.attributes['ng-required'] != "undefined"; this.lastErrorText = null; this.lastValue = undefined; - this.initialValue = view.value; + this.initialValue = this.formatter['parse'](view.value); var widget = view.getAttribute('ng-widget'); if (widget === 'datepicker') { jQuery(view).datepicker(); @@ -204,11 +204,11 @@ function TextController(view, exp, formatter) { TextController.prototype = { updateModel: function(scope) { - var value = this.view.value; + var value = this.formatter['parse'](this.view.value); if (this.lastValue === value) { return false; } else { - scope.setEval(this.exp, this.formatter['parse'](value)); + scope.setEval(this.exp, value); this.lastValue = value; return true; } @@ -216,16 +216,17 @@ TextController.prototype = { updateView: function(scope) { var view = this.view; - var value = this.formatter['format'](scope.get(this.exp)); + var value = scope.get(this.exp); if (typeof value === "undefined") { value = this.initialValue; - scope.setEval(this.exp, this.formatter['parse'](value)); + scope.setEval(this.exp, value); } value = value ? value : ''; - if (this.lastValue != value) { - view.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) { @@ -255,14 +256,15 @@ function CheckboxController(view, exp, formatter) { this.exp = exp; this.lastValue = undefined; this.formatter = formatter; - this.initialValue = view.checked ? view.value : ""; + this.initialValue = this.formatter['parse'](view.checked ? view.value : ""); }; CheckboxController.prototype = { updateModel: function(scope) { - jstd.console.log("model"); 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 { @@ -277,10 +279,9 @@ CheckboxController.prototype = { var value = scope.eval(this.exp); if (typeof value === "undefined") { value = this.initialValue; - scope.setEval(this.exp, this.formatter['parse'](value)); + scope.setEval(this.exp, value); } - value = this.formatter['format'](value); - input.checked = input.value == value; + input.checked = this.formatter['parse'](input.value) == value; } }; diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js new file mode 100644 index 00000000..0f7cd2ea --- /dev/null +++ b/src/angular-bootstrap.js @@ -0,0 +1,55 @@ +/** + * The MIT License + * + * Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +(function(previousOnLoad){ + var filename = /(.*)\/angular-(.*).js/; + var scripts = document.getElementsByTagName("script"); + var serverPath; + for(var j = 0; j < scripts.length; j++) { + var match = (scripts[j].src || "").match(filename); + if (match) { + serverPath = match[1]; + } + } + + function addScript(file){ + document.write('<script type="text/javascript" src="' + serverPath + file +'"></script>'); + }; + + addScript("/Angular.js"); + addScript("/API.js"); + addScript("/Binder.js"); + addScript("/ControlBar.js"); + addScript("/DataStore.js"); + addScript("/Filters.js"); + addScript("/Formatters.js"); + addScript("/JSON.js"); + addScript("/Model.js"); + addScript("/Parser.js"); + addScript("/Scope.js"); + addScript("/Server.js"); + addScript("/Users.js"); + addScript("/Validators.js"); + addScript("/Widgets.js"); +})(window.onload); + |
