diff options
| author | Misko Hevery | 2011-09-08 13:56:29 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-10-11 11:01:45 -0700 |
| commit | 4f78fd692c0ec51241476e6be9a4df06cd62fdd6 (patch) | |
| tree | 91f70bb89b9c095126fbc093f51cedbac5cb0c78 /src/Angular.js | |
| parent | df6d2ba3266de405ad6c2f270f24569355706e76 (diff) | |
| download | angular.js-4f78fd692c0ec51241476e6be9a4df06cd62fdd6.tar.bz2 | |
feat(forms): new and improved forms
Diffstat (limited to 'src/Angular.js')
| -rw-r--r-- | src/Angular.js | 105 |
1 files changed, 65 insertions, 40 deletions
diff --git a/src/Angular.js b/src/Angular.js index caa51a06..7c218c6e 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -55,7 +55,6 @@ function fromCharCode(code) { return String.fromCharCode(code); } var _undefined = undefined, _null = null, $$scope = '$scope', - $$validate = '$validate', $angular = 'angular', $array = 'array', $boolean = 'boolean', @@ -93,12 +92,10 @@ var _undefined = undefined, angularDirective = extensionMap(angular, 'directive'), /** @name angular.widget */ angularWidget = extensionMap(angular, 'widget', lowercase), - /** @name angular.validator */ - angularValidator = extensionMap(angular, 'validator'), - /** @name angular.fileter */ + /** @name angular.filter */ angularFilter = extensionMap(angular, 'filter'), - /** @name angular.formatter */ - angularFormatter = extensionMap(angular, 'formatter'), + /** @name angular.service */ + angularInputType = extensionMap(angular, 'inputType', lowercase), /** @name angular.service */ angularService = extensionMap(angular, 'service'), angularCallbacks = extensionMap(angular, 'callbacks'), @@ -156,10 +153,18 @@ function forEach(obj, iterator, context) { return obj; } -function forEachSorted(obj, iterator, context) { +function sortedKeys(obj) { var keys = []; - for (var key in obj) keys.push(key); - keys.sort(); + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + keys.push(key); + } + } + return keys.sort(); +} + +function forEachSorted(obj, iterator, context) { + var keys = sortedKeys(obj) for ( var i = 0; i < keys.length; i++) { iterator.call(context, obj[keys[i]], keys[i]); } @@ -180,7 +185,6 @@ function formatError(arg) { } /** - * @description * A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric * characters such as '012ABC'. The reason why we are not using simply a number counter is that * the number string gets longer over time, and it can also overflow, where as the the nextId @@ -599,20 +603,33 @@ function isLeafNode (node) { * @example * <doc:example> * <doc:source> - Salutation: <input type="text" name="master.salutation" value="Hello" /><br/> - Name: <input type="text" name="master.name" value="world"/><br/> - <button ng:click="form = master.$copy()">copy</button> - <hr/> - - The master object is <span ng:hide="master.$equals(form)">NOT</span> equal to the form object. - - <pre>master={{master}}</pre> - <pre>form={{form}}</pre> + <script> + function Ctrl(){ + this.master = { + salutation: 'Hello', + name: 'world' + }; + this.copy = function (){ + this.form = angular.copy(this.master); + } + } + </script> + <div ng:controller="Ctrl"> + Salutation: <input type="text" ng:model="master.salutation" ><br/> + Name: <input type="text" ng:model="master.name"><br/> + <button ng:click="copy()">copy</button> + <hr/> + + The master object is <span ng:hide="master.$equals(form)">NOT</span> equal to the form object. + + <pre>master={{master}}</pre> + <pre>form={{form}}</pre> + </div> * </doc:source> * <doc:scenario> it('should print that initialy the form object is NOT equal to master', function() { - expect(element('.doc-example-live input[name="master.salutation"]').val()).toBe('Hello'); - expect(element('.doc-example-live input[name="master.name"]').val()).toBe('world'); + expect(element('.doc-example-live input[ng\\:model="master.salutation"]').val()).toBe('Hello'); + expect(element('.doc-example-live input[ng\\:model="master.name"]').val()).toBe('world'); expect(element('.doc-example-live span').css('display')).toBe('inline'); }); @@ -691,20 +708,31 @@ function copy(source, destination){ * @example * <doc:example> * <doc:source> - Salutation: <input type="text" name="greeting.salutation" value="Hello" /><br/> - Name: <input type="text" name="greeting.name" value="world"/><br/> - <hr/> - - The <code>greeting</code> object is - <span ng:hide="greeting.$equals({salutation:'Hello', name:'world'})">NOT</span> equal to - <code>{salutation:'Hello', name:'world'}</code>. - - <pre>greeting={{greeting}}</pre> + <script> + function Ctrl(){ + this.master = { + salutation: 'Hello', + name: 'world' + }; + this.greeting = angular.copy(this.master); + } + </script> + <div ng:controller="Ctrl"> + Salutation: <input type="text" ng:model="greeting.salutation"><br/> + Name: <input type="text" ng:model="greeting.name"><br/> + <hr/> + + The <code>greeting</code> object is + <span ng:hide="greeting.$equals(master)">NOT</span> equal to + <code>{salutation:'Hello', name:'world'}</code>. + + <pre>greeting={{greeting}}</pre> + </div> * </doc:source> * <doc:scenario> it('should print that initialy greeting is equal to the hardcoded value object', function() { - expect(element('.doc-example-live input[name="greeting.salutation"]').val()).toBe('Hello'); - expect(element('.doc-example-live input[name="greeting.name"]').val()).toBe('world'); + expect(element('.doc-example-live input[ng\\:model="greeting.salutation"]').val()).toBe('Hello'); + expect(element('.doc-example-live input[ng\\:model="greeting.name"]').val()).toBe('world'); expect(element('.doc-example-live span').css('display')).toBe('none'); }); @@ -915,24 +943,19 @@ function angularInit(config, document){ if (config.css) $browser.addCss(config.base_url + config.css); - else if(msie<8) - $browser.addJs(config.ie_compat, config.ie_compat_id); scope.$apply(); } } -function angularJsConfig(document, config) { +function angularJsConfig(document) { bindJQuery(); var scripts = document.getElementsByTagName("script"), + config = {}, match; - config = extend({ - ie_compat_id: 'ng-ie-compat' - }, config); for(var j = 0; j < scripts.length; j++) { match = (scripts[j].src || "").match(rngScript); if (match) { config.base_url = match[1]; - config.ie_compat = match[1] + 'angular-ie-compat' + (match[2] || '') + '.js'; extend(config, parseKeyValue(match[6])); eachAttribute(jqLite(scripts[j]), function(value, name){ if (/^ng:/.exec(name)) { @@ -974,11 +997,13 @@ function assertArg(arg, name, reason) { (reason || "required")); throw error; } + return arg; } function assertArgFn(arg, name) { - assertArg(isFunction(arg), name, 'not a function, got ' + + assertArg(isFunction(arg), name, 'not a function, got ' + (typeof arg == 'object' ? arg.constructor.name : typeof arg)); + return arg; } |
