From e6ee9947645c5cca9cf6efd902cae1a4a31ea13c Mon Sep 17 00:00:00 2001 From: Di Peng Date: Mon, 6 Jun 2011 12:13:07 -0700 Subject: Added ng:disabled, ng:checked, ng:multiple, ng:readonly, ng:selected to markup.js. Also added coresponding descriptions live examples and tests for each directive to be displayed on the website. Closes #351 --- CHANGELOG.md | 1 + src/directives.js | 3 +- src/markups.js | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/markupSpec.js | 50 ++++++++++++++++ 4 files changed, 216 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbf740d2..c38ca167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New Features - Added prepend() to jqLite - Added ng:options directive (http://docs.angularjs.org/#!angular.directive.ng:options) +- Added ng:disabled, ng:selected, ng:checked, ng:multiple, ng:readonly directive. ### Bug Fixes diff --git a/src/directives.js b/src/directives.js index 016ba9fe..aa30fab2 100644 --- a/src/directives.js +++ b/src/directives.js @@ -384,7 +384,8 @@ var REMOVE_ATTRIBUTES = { 'disabled':'disabled', 'readonly':'readOnly', 'checked':'checked', - 'selected':'selected' + 'selected':'selected', + 'multiple':'multiple' }; /** * @workInProgress diff --git a/src/markups.js b/src/markups.js index 7edde728..09481187 100644 --- a/src/markups.js +++ b/src/markups.js @@ -235,8 +235,171 @@ angularTextMarkup('option', function(text, textNode, parentElement){ * @param {template} template any string which can contain `{{}}` markup. */ +/** + * @workInProgress + * @ngdoc directive + * @name angular.directive.ng:disabled + * + * @description + * + * The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs: + *
+ * 
+ * + *
+ *
+ * + * the HTML specs do not require browsers preserve the special attributes such as disabled.(The presense of them means true and absense means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng:disabled. + * + * @example + + + Click me to toggle:
+ +
+ + it('should toggle button', function() { + expect(element('.doc-example-live :button').attr('disabled')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :button').attr('disabled')).toBeTruthy(); + }); + +
+ * + * @element ANY + * @param {template} template any string which can contain '{{}}' markup. + */ + + +/** + * @workInProgress + * @ngdoc directive + * @name angular.directive.ng:checked + * + * @description + * the HTML specs do not require browsers preserve the special attributes such as checked.(The presense of them means true and absense means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng:checked. + * @example + + + Check me to check both:
+ +
+ + it('should check both checkBoxes', function() { + expect(element('.doc-example-live #checkSlave').attr('checked')).toBeFalsy(); + input('master').check(); + expect(element('.doc-example-live #checkSlave').attr('checked')).toBeTruthy(); + }); + +
+ * + * @element ANY + * @param {template} template any string which can contain '{{}}' markup. + */ + + +/** + * @workInProgress + * @ngdoc directive + * @name angular.directive.ng:multiple + * + * @description + * the HTML specs do not require browsers preserve the special attributes such as multiple.(The presense of them means true and absense means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng:multiple. + * + * @example + + + Check me check multiple:
+ +
+ + it('should toggle multiple', function() { + expect(element('.doc-example-live #select').attr('multiple')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live #select').attr('multiple')).toBeTruthy(); + }); + +
+ * + * @element ANY + * @param {template} template any string which can contain '{{}}' markup. + */ + + +/** + * @workInProgress + * @ngdoc directive + * @name angular.directive.ng:readonly + * + * @description + * the HTML specs do not require browsers preserve the special attributes such as readonly.(The presense of them means true and absense means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce ng:readonly. + * @example + + + Check me to make text readonly:
+ +
+ + it('should toggle readonly attr', function() { + expect(element('.doc-example-live :text').attr('readonly')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live :text').attr('readonly')).toBeTruthy(); + }); + +
+ * + * @element ANY + * @param {template} template any string which can contain '{{}}' markup. + */ + + +/** +* @workInProgress +* @ngdoc directive +* @name angular.directive.ng:selected +* +* @description +* the HTML specs do not require browsers preserve the special attributes such as selected.(The presense of them means true and absense means false) +* This prevents the angular compiler from correctly retrieving the binding expression. +* To solve this problem, we introduce ng:selected. +* @example + + + Check me to select:
+ +
+ + it('should select Greetings!', function() { + expect(element('.doc-example-live #greet').attr('selected')).toBeFalsy(); + input('checked').check(); + expect(element('.doc-example-live #greet').attr('selected')).toBeTruthy(); + }); + +
+* @element ANY +* @param {template} template any string which can contain '{{}}' markup. +*/ + + var NG_BIND_ATTR = 'ng:bind-attr'; var SPECIAL_ATTRS = {}; + forEach('src,href,checked,disabled,multiple,readonly,selected'.split(','), function(name) { SPECIAL_ATTRS['ng:' + name] = name; }); diff --git a/test/markupSpec.js b/test/markupSpec.js index 765c3108..0e5c8457 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -89,6 +89,56 @@ describe("markups", function(){ expect(sortedHtml(element)).toEqual(''); }); + it('should bind disabled', function() { + compile(''); + scope.isDisabled = false; + scope.$eval(); + expect(element.attr('disabled')).toBeFalsy(); + scope.isDisabled = true; + scope.$eval(); + expect(element.attr('disabled')).toBeTruthy(); + }); + + it('should bind checked', function() { + compile(''); + scope.isChecked = false; + scope.$eval(); + expect(element.attr('checked')).toBeFalsy(); + scope.isChecked=true; + scope.$eval(); + expect(element.attr('checked')).toBeTruthy(); + }); + + it('should bind selected', function() { + compile(''); + scope.isSelected=false; + scope.$eval(); + expect(element.children()[1].selected).toBeFalsy(); + scope.isSelected=true; + scope.$eval(); + expect(element.children()[1].selected).toBeTruthy(); + }); + + it('should bind readonly', function() { + compile(''); + scope.isReadonly=false; + scope.$eval(); + expect(element.attr('readOnly')).toBeFalsy(); + scope.isReadonly=true; + scope.$eval(); + expect(element.attr('readOnly')).toBeTruthy(); + }); + + it('should bind multiple', function() { + compile(''); + scope.isMultiple=false; + scope.$eval(); + expect(element.attr('multiple')).toBeFalsy(); + scope.isMultiple='multiple'; + scope.$eval(); + expect(element.attr('multiple')).toBeTruthy(); + }); + it('should bind src', function() { compile(''); scope.url = 'http://localhost/'; -- cgit v1.2.3