| Index: third_party/pkg/angular/lib/directive/input_select.dart
|
| ===================================================================
|
| --- third_party/pkg/angular/lib/directive/input_select.dart (revision 33054)
|
| +++ third_party/pkg/angular/lib/directive/input_select.dart (working copy)
|
| @@ -3,28 +3,26 @@
|
| typedef dynamic ItemEval(dynamic item, num index);
|
|
|
| /**
|
| - * HTML [SELECT] element with angular data-binding if used with
|
| - * [NgModelDirective].
|
| + * HTML [SELECT] element with angular data-binding if used with [NgModelDirective].
|
| *
|
| - * The [NgModelDirective] will receive the currently selected item. The binding
|
| - * is performed on the [OPTION].[value] property. An empty [OPTION].[value] is
|
| - * treated as null.
|
| + * The [NgModelDirective] will receive the currently selected item. The binding is
|
| + * performed on the [OPTION].[value] property.
|
| + * An empty [OPTION].[value] is treated as null.
|
| *
|
| * If you the model contains value which does not map to any [OPTION] then a new
|
| - * unknown [OPTION] is inserted into the list. Once the model points to an
|
| - * existing [OPTION] the unknown [OPTION] is removed.
|
| + * unknown [OPTION] is inserted into the list. Once the model points to an existing
|
| + * [OPTION] the unknown [OPTION] is removed.
|
| *
|
| - * Becouse [OPTION].[value] attribute is a string, the model is bound to a
|
| - * string. If there is need to bind to an object then [OptionValueDirective]
|
| - * should be used.
|
| + * Becouse [OPTION].[value] attribute is a string, the model is bound to a string.
|
| + * If there is need to bind to an object then [OptionValueDirective] should be used.
|
| *
|
| */
|
| @NgDirective(
|
| selector: 'select[ng-model]',
|
| - visibility: NgDirective.CHILDREN_VISIBILITY)
|
| + visibility: NgDirective.CHILDREN_VISIBILITY
|
| +)
|
| class InputSelectDirective implements NgAttachAware {
|
| - final Expando<OptionValueDirective> expando =
|
| - new Expando<OptionValueDirective>();
|
| + final Expando<OptionValueDirective> expando = new Expando<OptionValueDirective>();
|
| final dom.SelectElement _selectElement;
|
| final NodeAttrs _attrs;
|
| final NgModel _model;
|
| @@ -36,8 +34,7 @@
|
| _SelectMode _mode = new _SelectMode(null, null, null);
|
| bool _dirty = false;
|
|
|
| - InputSelectDirective(dom.Element this._selectElement, this._attrs, this._model,
|
| - this._scope) {
|
| + InputSelectDirective(dom.Element this._selectElement, this._attrs, this._model, this._scope) {
|
| _unknownOption.value = '?';
|
| _unknownOption.text = ''; // Explicit due to dartbug.com/14407
|
| _selectElement.querySelectorAll('option').forEach((o) {
|
| @@ -61,58 +58,54 @@
|
| });
|
|
|
| _selectElement.onChange.listen((event) => _mode.onViewChange(event));
|
| - _model.render = (value) {
|
| - // TODO(misko): this hack need to delay the rendering until after domRead
|
| - // because the modelChange reads from the DOM. We should be able to render
|
| - // without DOM changes.
|
| - _scope.rootScope.domRead(() {
|
| - _scope.rootScope.domWrite(() => _mode.onModelChange(value));
|
| - });
|
| - };
|
| + _model.render = (value) => _mode.onModelChange(value);
|
| }
|
|
|
| /**
|
| - * This method invalidates the current state of the selector and forces a
|
| - * re-rendering of the options using the [Scope.evalAsync].
|
| + * This method invalidates the current state of the selector and forces a re-rendering of the
|
| + * options using the [Scope.$evalAsync].
|
| */
|
| dirty() {
|
| if (!_dirty) {
|
| _dirty = true;
|
| - // TODO(misko): this hack need to delay the rendering until after domRead
|
| - // becouse the modelChange reads from the DOM. We should be able to render
|
| - // without DOM changes.
|
| - _scope.rootScope.domRead(() {
|
| - _scope.rootScope.domWrite(() {
|
| - _dirty = false;
|
| - _mode.onModelChange(_model.viewValue);
|
| - });
|
| + _scope.$evalAsync(() {
|
| + _dirty = false;
|
| + _mode.onModelChange(_model.viewValue);
|
| });
|
| }
|
| }
|
| }
|
|
|
| /**
|
| - * Since the [value] attribute of the [OPTION] can only be a string, Angular
|
| - * provides [ng-value] which allows binding to any expression.
|
| + * Since the [value] attirbute of the [OPTION] can only be a string, Angular provides
|
| + * [ng-value] which allows binding to any expression.
|
| *
|
| */
|
| @NgDirective(
|
| - selector: 'option')
|
| -class OptionValueDirective implements NgAttachAware,
|
| - NgDetachAware {
|
| + selector: 'option',
|
| + publishTypes: const [TextChangeListener],
|
| + map: const {'ng-value': '&ngValue'}
|
| +)
|
| +class OptionValueDirective implements TextChangeListener, NgAttachAware, NgDetachAware {
|
| final InputSelectDirective _inputSelectDirective;
|
| - final dom.Element _element;
|
| + final NodeAttrs _attrs;
|
|
|
| - NgValue _ngValue;
|
| + Getter _ngValue;
|
|
|
| - OptionValueDirective(this._element, this._inputSelectDirective, this._ngValue) {
|
| + OptionValueDirective(this._attrs, this._inputSelectDirective) {
|
| if (_inputSelectDirective != null) {
|
| - _inputSelectDirective.expando[_element] = this;
|
| + _inputSelectDirective.expando[_attrs.element] = this;
|
| }
|
| }
|
|
|
| attach() {
|
| if (_inputSelectDirective != null) {
|
| + this._attrs.observe('value', (_) => _inputSelectDirective.dirty());
|
| + }
|
| + }
|
| +
|
| + call(String text) {
|
| + if (_inputSelectDirective != null) {
|
| _inputSelectDirective.dirty();
|
| }
|
| }
|
| @@ -120,11 +113,13 @@
|
| detach() {
|
| if (_inputSelectDirective != null) {
|
| _inputSelectDirective.dirty();
|
| - _inputSelectDirective.expando[_element] = null;
|
| + _inputSelectDirective.expando[_attrs.element] = null;
|
| }
|
| }
|
|
|
| - get ngValue => _ngValue.readValue(_element);
|
| + set ngValue(Getter value) => _ngValue = value;
|
| + get ngValue =>
|
| + _attrs['ng-value'] is String ? _ngValue() : (_attrs.element as dom.OptionElement).value;
|
| }
|
|
|
| class _SelectMode {
|
| @@ -140,9 +135,11 @@
|
|
|
| get _options => select.querySelectorAll('option');
|
| _forEachOption(fn, [quiteOnReturn = false]) {
|
| - for (var i = 0; i < _options.length; i++) {
|
| - var retValue = fn(_options[i], i);
|
| - if (quiteOnReturn && retValue != null) return retValue;
|
| + for(var os = _options, i = 0, ii = os.length; i < ii; i++) {
|
| + var retValue = fn(os[i], i);
|
| + if (quiteOnReturn && retValue != null) {
|
| + return retValue;
|
| + }
|
| }
|
| return null;
|
| }
|
| @@ -168,7 +165,9 @@
|
| if (option.selected) {
|
| return option == _nullOption ? null : expando[option].ngValue;
|
| }
|
| - if (option != _unknownOption && option != _nullOption) i++;
|
| + if (option != _unknownOption && option != _nullOption) {
|
| + i++;
|
| + }
|
| }, true);
|
| }
|
|
|
| @@ -205,14 +204,16 @@
|
| class _MultipleSelectionMode extends _SelectMode {
|
| _MultipleSelectionMode(Expando<OptionValueDirective> expando,
|
| dom.SelectElement select,
|
| - NgModel model)
|
| - : super(expando, select, model);
|
| + NgModel model
|
| + ): super(expando, select, model);
|
|
|
| onViewChange(event) {
|
| var selected = [];
|
|
|
| _forEachOption((o, i) {
|
| - if (o.selected) selected.add(expando[o].ngValue);
|
| + if (o.selected) {
|
| + selected.add(expando[o].ngValue);
|
| + }
|
| });
|
| model.viewValue = selected;
|
| }
|
| @@ -221,14 +222,7 @@
|
| Function fn = (o, i) => o.selected = null;
|
|
|
| if (selectedValues is List) {
|
| - fn = (o, i) {
|
| - var selected = expando[o];
|
| - if (selected == null) {
|
| - return false;
|
| - } else {
|
| - return o.selected = selectedValues.contains(selected.ngValue);
|
| - }
|
| - };
|
| + fn = (o, i) => o.selected = selectedValues.contains(expando[o].ngValue);
|
| }
|
|
|
| _forEachOption(fn);
|
|
|