From b8bd4d5460d9952e9a3bb14992636b17859bd457 Mon Sep 17 00:00:00 2001 From: David Chang Date: Thu, 17 Jan 2013 20:08:27 -0800 Subject: [PATCH] feat(directive): added ng-open boolean directive Closes# 1797 add ng-open attribute --- src/jqLite.js | 4 ++-- src/ng/directive/booleanAttrs.js | 31 +++++++++++++++++++++++++++ test/ng/directive/booleanAttrsSpec.js | 10 +++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index 46e0a73c3c54..f84e7d1fe896 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -353,11 +353,11 @@ var JQLitePrototype = JQLite.prototype = { // value on get. ////////////////////////////////////////// var BOOLEAN_ATTR = {}; -forEach('multiple,selected,checked,disabled,readOnly,required'.split(','), function(value) { +forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) { BOOLEAN_ATTR[lowercase(value)] = value; }); var BOOLEAN_ELEMENTS = {}; -forEach('input,select,option,textarea,button,form'.split(','), function(value) { +forEach('input,select,option,textarea,button,form,details'.split(','), function(value) { BOOLEAN_ELEMENTS[uppercase(value)] = true; }); diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index 8902c35d2d4b..864c12c118d9 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -272,6 +272,37 @@ * @param {string} expression Angular expression that will be evaluated. */ +/** + * @ngdoc directive + * @name ng.directive:ngOpen + * @restrict A + * + * @description + * The HTML specs do not require browsers to preserve the special attributes such as open. + * (The presence of them means true and absence means false) + * This prevents the angular compiler from correctly retrieving the binding expression. + * To solve this problem, we introduce the `ngMultiple` directive. + * + * @example + + + Check me check multiple:
+
+ Show/Hide me +
+
+ + it('should toggle open', function() { + expect(element('#details').prop('open')).toBeFalsy(); + input('open').check(); + expect(element('#details').prop('open')).toBeTruthy(); + }); + +
+ * + * @element DETAILS + * @param {string} expression Angular expression that will be evaluated. + */ var ngAttributeAliasDirectives = {}; diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js index 435ffcb9727f..0ce6b555108e 100644 --- a/test/ng/directive/booleanAttrsSpec.js +++ b/test/ng/directive/booleanAttrsSpec.js @@ -74,6 +74,16 @@ describe('boolean attr directives', function() { $rootScope.$digest(); expect(element.attr('multiple')).toBeTruthy(); })); + + it('should bind open', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope) + $rootScope.isOpen=false; + $rootScope.$digest(); + expect(element.attr('open')).toBeFalsy(); + $rootScope.isOpen=true; + $rootScope.$digest(); + expect(element.attr('open')).toBeTruthy(); + })); });