aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDi Peng2011-06-06 12:13:07 -0700
committerIgor Minar2011-06-16 21:17:46 -0700
commite6ee9947645c5cca9cf6efd902cae1a4a31ea13c (patch)
treeaef3c87645697d98b49e51b1a0e805c271dfc1d1
parentc8ee00cb2bfffcc25fdfc14c56b5b82cf71284d5 (diff)
downloadangular.js-e6ee9947645c5cca9cf6efd902cae1a4a31ea13c.tar.bz2
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
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/directives.js3
-rw-r--r--src/markups.js163
-rw-r--r--test/markupSpec.js50
4 files changed, 216 insertions, 1 deletions
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:
+ * <pre>
+ * <div ng:init="scope = { isDisabled: false }">
+ * <button disabled="{{scope.isDisabled}}">Disabled</button>
+ * </div>
+ * </pre>
+ *
+ * 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
+ <doc:example>
+ <doc:source>
+ Click me to toggle: <input type="checkbox" name="checked"><br/>
+ <button name="button" ng:disabled="{{checked}}">Button</button>
+ </doc:source>
+ <doc:scenario>
+ 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();
+ });
+ </doc:scenario>
+ </doc:example>
+ *
+ * @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
+ <doc:example>
+ <doc:source>
+ Check me to check both: <input type="checkbox" name="master"><br/>
+ <input id="checkSlave" type="checkbox" ng:checked="{{master}}">
+ </doc:source>
+ <doc:scenario>
+ 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();
+ });
+ </doc:scenario>
+ </doc:example>
+ *
+ * @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
+ <doc:example>
+ <doc:source>
+ Check me check multiple: <input type="checkbox" name="checked"><br/>
+ <select id="select" ng:multiple="{{checked}}">
+ <option>Misko</option>
+ <option>Igor</option>
+ <option>Vojita</option>
+ <option>Di</option>
+ </select>
+ </doc:source>
+ <doc:scenario>
+ 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();
+ });
+ </doc:scenario>
+ </doc:example>
+ *
+ * @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
+ <doc:example>
+ <doc:source>
+ Check me to make text readonly: <input type="checkbox" name="checked"><br/>
+ <input type="text" ng:readonly="{{checked}}" value="I'm Angular"/>
+ </doc:source>
+ <doc:scenario>
+ 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();
+ });
+ </doc:scenario>
+ </doc:example>
+ *
+ * @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
+ <doc:example>
+ <doc:source>
+ Check me to select: <input type="checkbox" name="checked"><br/>
+ <select>
+ <option>Hello!</option>
+ <option id="greet" ng:selected="{{checked}}">Greetings!</option>
+ </select>
+ </doc:source>
+ <doc:scenario>
+ 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();
+ });
+ </doc:scenario>
+ </doc:example>
+* @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('<a ng:bind-attr="{"href":"{{url}}"}"></a>');
});
+ it('should bind disabled', function() {
+ compile('<button ng:disabled="{{isDisabled}}">Button</button>');
+ 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('<input type="checkbox" ng:checked="{{isChecked}}" />');
+ 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('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>');
+ 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('<input type="text" ng:readonly="{{isReadonly}}" />');
+ 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('<select ng:multiple="{{isMultiple}}"></select>');
+ 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('<img ng:src="{{url}}" />');
scope.url = 'http://localhost/';