@samitouri / QOS-React-2 / commits / 422a8d9c2c

Support minimizable, non-boolean attributes

Fixes GH-1337

Matthew Dapena-Tretter committed Mar 31, 2014 at 21:43 UTC 422a8d9c2ce651f7034d2488e8e744c5e255df56
3 files changed +23 -3
src/browser/ui/dom/DOMProperty.js
+17
@@ -34,6 +34,7 @@ var DOMPropertyInjection = {
34 HAS_BOOLEAN_VALUE: 0x8,
35 HAS_NUMERIC_VALUE: 0x10,
36 HAS_POSITIVE_NUMERIC_VALUE: 0x20 | 0x10,
37 + CAN_BE_MINIMIZED: 0x40,
38
39 /**
40 * Inject some specialized knowledge about the DOM. This takes a config object
@@ -115,6 +116,8 @@ var DOMPropertyInjection = {
116 propConfig & DOMPropertyInjection.HAS_NUMERIC_VALUE;
117 DOMProperty.hasPositiveNumericValue[propName] =
118 propConfig & DOMPropertyInjection.HAS_POSITIVE_NUMERIC_VALUE;
119 + DOMProperty.canBeMinimized[propName] =
120 + propConfig & DOMPropertyInjection.CAN_BE_MINIMIZED;
121
122 invariant(
123 !DOMProperty.mustUseAttribute[propName] ||
@@ -134,6 +137,12 @@ var DOMPropertyInjection = {
137 'DOMProperty: Cannot have both boolean and numeric value: %s',
138 propName
139 );
140 + invariant(
141 + !DOMProperty.hasBooleanValue[propName] ||
142 + !DOMProperty.canBeMinimized[propName],
143 + 'DOMProperty: Cannot have boolean value and be minimizable: %s',
144 + propName
145 + );
146 }
147 }
148 };
@@ -231,6 +240,14 @@ var DOMProperty = {
240 */
241 hasPositiveNumericValue: {},
242
243 + /**
244 + * Whether the property can be used as a flag as well as with a value. Removed
245 + * when strictly equal to false; present without a value when strictly equal
246 + * to true; present with a value otherwise.
247 + * @type {Object}
248 + */
249 + canBeMinimized: {},
250 +
251 /**
252 * All of the isCustomAttribute() functions that have been injected.
253 */
src/browser/ui/dom/DOMPropertyOperations.js
+4 -2
@@ -29,7 +29,8 @@ function shouldIgnoreValue(name, value) {
29 return value == null ||
30 (DOMProperty.hasBooleanValue[name] && !value) ||
31 (DOMProperty.hasNumericValue[name] && isNaN(value)) ||
32 - (DOMProperty.hasPositiveNumericValue[name] && (value < 1));
32 + (DOMProperty.hasPositiveNumericValue[name] && (value < 1)) ||
33 + (DOMProperty.canBeMinimized[name] && value === false);
34 }
35
36 var processAttributeNameAndPrefix = memoizeStringOnly(function(name) {
@@ -96,7 +97,8 @@ var DOMPropertyOperations = {
97 return '';
98 }
99 var attributeName = DOMProperty.getAttributeName[name];
99 - if (DOMProperty.hasBooleanValue[name]) {
100 + if (DOMProperty.hasBooleanValue[name] ||
101 + (DOMProperty.canBeMinimized[name] && value === true)) {
102 return escapeTextForBrowser(attributeName);
103 }
104 return processAttributeNameAndPrefix(attributeName) +
src/browser/ui/dom/DefaultDOMPropertyConfig.js
+2 -1
@@ -29,6 +29,7 @@ var HAS_SIDE_EFFECTS = DOMProperty.injection.HAS_SIDE_EFFECTS;
29 var HAS_NUMERIC_VALUE = DOMProperty.injection.HAS_NUMERIC_VALUE;
30 var HAS_POSITIVE_NUMERIC_VALUE =
31 DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
32 +var CAN_BE_MINIMIZED = DOMProperty.injection.CAN_BE_MINIMIZED;
33
34 var DefaultDOMPropertyConfig = {
35 isCustomAttribute: RegExp.prototype.test.bind(
@@ -66,7 +67,7 @@ var DefaultDOMPropertyConfig = {
67 defer: HAS_BOOLEAN_VALUE,
68 dir: null,
69 disabled: MUST_USE_ATTRIBUTE | HAS_BOOLEAN_VALUE,
69 - download: null,
70 + download: CAN_BE_MINIMIZED,
71 draggable: null,
72 encType: null,
73 form: MUST_USE_ATTRIBUTE,