/*! * Angular Material Design * https://github.com/angular/material * @license MIT * v0.11.4 */ goog.provide('ng.material.components.select'); goog.require('ng.material.components.backdrop'); goog.require('ng.material.core'); /** * @ngdoc module * @name material.components.select */ /*************************************************** ### TODO ### **DOCUMENTATION AND DEMOS** - [ ] ng-model with child mdOptions (basic) - [ ] ng-model="foo" ng-model-options="{ trackBy: '$value.id' }" for objects - [ ] mdOption with value - [ ] Usage with input inside ### TODO - POST RC1 ### - [ ] Abstract placement logic in $mdSelect service to $mdMenu service ***************************************************/ var SELECT_EDGE_MARGIN = 8; var selectNextId = 0; angular.module('material.components.select', [ 'material.core', 'material.components.backdrop' ]) .directive('mdSelect', SelectDirective) .directive('mdSelectMenu', SelectMenuDirective) .directive('mdOption', OptionDirective) .directive('mdOptgroup', OptgroupDirective) .provider('$mdSelect', SelectProvider); /** * @ngdoc directive * @name mdSelect * @restrict E * @module material.components.select * * @description Displays a select box, bound to an ng-model. * * @param {expression} ng-model The model! * @param {boolean=} multiple Whether it's multiple. * @param {expression=} md-on-close Expression to be evaluated when the select is closed. * @param {string=} placeholder Placeholder hint text. * @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or * explicit label is present. * @param {string=} md-container-class Class list to get applied to the `.md-select-menu-container` * element (for custom styling). * * @usage * With a placeholder (label and aria-label are added dynamically) * * * * {{ opt }} * * * * * With an explicit label * * * * * {{ opt }} * * * */ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $parse) { return { restrict: 'E', require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'], compile: compile, controller: function() { } // empty placeholder controller to be initialized in link }; function compile(element, attr) { // add the select value that will hold our placeholder or selected option value var valueEl = angular.element(''); valueEl.append(''); valueEl.addClass('md-select-value'); if (!valueEl[0].hasAttribute('id')) { valueEl.attr('id', 'select_value_label_' + $mdUtil.nextUid()); } // There's got to be an md-content inside. If there's not one, let's add it. if (!element.find('md-content').length) { element.append(angular.element('').append(element.contents())); } // Add progress spinner for md-options-loading if (attr.mdOnOpen) { // Show progress indicator while loading async // Use ng-hide for `display:none` so the indicator does not interfere with the options list element .find('md-content') .prepend(angular.element( '
' + ' ' + '
' )); // Hide list [of item options] while loading async element .find('md-option') .attr('ng-show', '$$loadingAsyncDone'); } if (attr.name) { var autofillClone = angular.element(',