| OLD | NEW |
| 1 part of angular.directive; | 1 part of angular.directive; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * Allows adding and removing the boolean attributes from the element. | 4 * Allows adding and removing the boolean attributes from the element. |
| 5 * | 5 * |
| 6 * Using `<button disabled="{{false}}">` does not work since it would result | 6 * Using `<button disabled="{{false}}">` does not work since it would result |
| 7 * in `<button disabled="false">` rather than `<button>`. | 7 * in `<button disabled="false">` rather than `<button>`. |
| 8 * Browsers change behavior based on presence/absence of attribute rather the | 8 * Browsers change behavior based on presence/absence of attribute rather the |
| 9 * its value. | 9 * its value. |
| 10 * | 10 * |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * - [ng-selected] | 23 * - [ng-selected] |
| 24 */ | 24 */ |
| 25 @NgDirective(selector: '[ng-checked]', map: const {'ng-checked': '=>checked'}) | 25 @NgDirective(selector: '[ng-checked]', map: const {'ng-checked': '=>checked'}) |
| 26 @NgDirective(selector: '[ng-disabled]', map: const {'ng-disabled': '=>disabled'}
) | 26 @NgDirective(selector: '[ng-disabled]', map: const {'ng-disabled': '=>disabled'}
) |
| 27 @NgDirective(selector: '[ng-multiple]', map: const {'ng-multiple': '=>multiple'}
) | 27 @NgDirective(selector: '[ng-multiple]', map: const {'ng-multiple': '=>multiple'}
) |
| 28 @NgDirective(selector: '[ng-open]', map: const {'ng-open': '=>open'}) | 28 @NgDirective(selector: '[ng-open]', map: const {'ng-open': '=>open'}) |
| 29 @NgDirective(selector: '[ng-readonly]', map: const {'ng-readonly': '=>readonly'}
) | 29 @NgDirective(selector: '[ng-readonly]', map: const {'ng-readonly': '=>readonly'}
) |
| 30 @NgDirective(selector: '[ng-required]', map: const {'ng-required': '=>required'}
) | 30 @NgDirective(selector: '[ng-required]', map: const {'ng-required': '=>required'}
) |
| 31 @NgDirective(selector: '[ng-selected]', map: const {'ng-selected': '=>selected'}
) | 31 @NgDirective(selector: '[ng-selected]', map: const {'ng-selected': '=>selected'}
) |
| 32 class NgBooleanAttributeDirective { | 32 class NgBooleanAttributeDirective { |
| 33 final NodeAttrs attrs; | 33 NodeAttrs attrs; |
| 34 NgBooleanAttributeDirective(this.attrs); | 34 NgBooleanAttributeDirective(this.attrs); |
| 35 | 35 |
| 36 _setBooleanAttribute(name, value) => attrs[name] = (toBool(value) ? '' : null)
; | 36 _setBooleanAttribute(name, value) => attrs[name] = (toBool(value) ? '' : null)
; |
| 37 | 37 |
| 38 set checked(value) => _setBooleanAttribute('checked', value); | 38 set checked(value) => _setBooleanAttribute('checked', value); |
| 39 set disabled(value) => _setBooleanAttribute('disabled', value); | 39 set disabled(value) => _setBooleanAttribute('disabled', value); |
| 40 set multiple(value) => _setBooleanAttribute('multiple', value); | 40 set multiple(value) => _setBooleanAttribute('multiple', value); |
| 41 set open(value) => _setBooleanAttribute('open', value); | 41 set open(value) => _setBooleanAttribute('open', value); |
| 42 set readonly(value) => _setBooleanAttribute('readonly', value); | 42 set readonly(value) => _setBooleanAttribute('readonly', value); |
| 43 set required(value) => _setBooleanAttribute('required', value); | 43 set required(value) => _setBooleanAttribute('required', value); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 * The full list of supported attributes are: | 58 * The full list of supported attributes are: |
| 59 * | 59 * |
| 60 * - [ng-href] | 60 * - [ng-href] |
| 61 * - [ng-src] | 61 * - [ng-src] |
| 62 * - [ng-srcset] | 62 * - [ng-srcset] |
| 63 */ | 63 */ |
| 64 @NgDirective(selector: '[ng-href]', map: const {'ng-href': '@href'}) | 64 @NgDirective(selector: '[ng-href]', map: const {'ng-href': '@href'}) |
| 65 @NgDirective(selector: '[ng-src]', map: const {'ng-src': '@src'}) | 65 @NgDirective(selector: '[ng-src]', map: const {'ng-src': '@src'}) |
| 66 @NgDirective(selector: '[ng-srcset]', map: const {'ng-srcset': '@srcset'}) | 66 @NgDirective(selector: '[ng-srcset]', map: const {'ng-srcset': '@srcset'}) |
| 67 class NgSourceDirective { | 67 class NgSourceDirective { |
| 68 final NodeAttrs attrs; | 68 NodeAttrs attrs; |
| 69 NgSourceDirective(this.attrs); | 69 NgSourceDirective(this.attrs); |
| 70 | 70 |
| 71 set href(value) => attrs['href'] = value; | 71 set href(value) => attrs['href'] = value; |
| 72 set src(value) => attrs['src'] = value; | 72 set src(value) => attrs['src'] = value; |
| 73 set srcset(value) => attrs['srcset'] = value; | 73 set srcset(value) => attrs['srcset'] = value; |
| 74 | 74 |
| 75 } | 75 } |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * In SVG some attributes have a specific syntax. Placing `{{interpolation}}` in | 78 * In SVG some attributes have a specific syntax. Placing `{{interpolation}}` in
those |
| 79 * those attributes will break the attribute syntax, and browser will clear the | 79 * attributes will break the attribute syntax, and browser will clear the attrib
ute. |
| 80 * attribute. | |
| 81 * | 80 * |
| 82 * The `ng-attr-*` is a generic way to use interpolation without breaking the | 81 * The `ng-attr-*` is a generic way to use interpolation without breaking the at
tribute |
| 83 * attribute syntax validator. The `ng-attr-` part get stripped. | 82 * syntax validator. The `ng-attr-` part get stripped. |
| 84 * | 83 * |
| 85 * @example | 84 * @example |
| 86 * <svg> | 85 <svg> |
| 87 * <circle ng-attr-cx="{{cx}}"></circle> | 86 <circle ng-attr-cx="{{cx}}"></circle> |
| 88 * </svg> | 87 </svg> |
| 89 */ | 88 */ |
| 90 @NgDirective(selector: '[ng-attr-*]') | 89 @NgDirective(selector: '[ng-attr-*]') |
| 91 class NgAttributeDirective implements NgAttachAware { | 90 class NgAttributeDirective implements NgAttachAware { |
| 92 final NodeAttrs _attrs; | 91 NodeAttrs _attrs; |
| 93 | 92 |
| 94 NgAttributeDirective(this._attrs); | 93 NgAttributeDirective(NodeAttrs this._attrs); |
| 95 | 94 |
| 96 void attach() { | 95 void attach() { |
| 97 String ngAttrPrefix = 'ng-attr-'; | |
| 98 _attrs.forEach((key, value) { | 96 _attrs.forEach((key, value) { |
| 99 if (key.startsWith(ngAttrPrefix)) { | 97 if (key.startsWith('ngAttr')) { |
| 100 var newKey = key.substring(ngAttrPrefix.length); | 98 String newKey = snakecase(key.substring(6)); |
| 101 _attrs[newKey] = value; | 99 _attrs[newKey] = value; |
| 102 _attrs.observe(key, (newValue) => _attrs[newKey] = newValue ); | 100 _attrs.observe(snakecase(key), (newValue) => _attrs[newKey] = newValue )
; |
| 103 } | 101 } |
| 104 }); | 102 }); |
| 105 } | 103 } |
| 106 } | 104 } |
| OLD | NEW |