/*! * Angular Material Design * https://github.com/angular/material * @license MIT * v0.10.0 */ (function( window, angular, undefined ){ "use strict"; /** * @ngdoc module * @name material.components.input */ angular.module('material.components.input', [ 'material.core' ]) .directive('mdInputContainer', mdInputContainerDirective) .directive('label', labelDirective) .directive('input', inputTextareaDirective) .directive('textarea', inputTextareaDirective) .directive('mdMaxlength', mdMaxlengthDirective) .directive('placeholder', placeholderDirective); /** * @ngdoc directive * @name mdInputContainer * @module material.components.input * * @restrict E * * @description * `` is the parent of any input or textarea element. * * Input and textarea elements will not behave properly unless the md-input-container * parent is provided. * * @param md-is-error {expression=} When the given expression evaluates to true, the input container will go into error state. Defaults to erroring if the input has been touched and is invalid. * @param md-no-float {boolean=} When present, placeholders will not be converted to floating labels * * @usage * * * * * * * * * * * * * */ function mdInputContainerDirective($mdTheming, $parse) { ContainerCtrl.$inject = ["$scope", "$element", "$attrs"]; return { restrict: 'E', link: postLink, controller: ContainerCtrl }; function postLink(scope, element, attr) { $mdTheming(element); } function ContainerCtrl($scope, $element, $attrs) { var self = this; self.isErrorGetter = $attrs.mdIsError && $parse($attrs.mdIsError); self.delegateClick = function() { self.input.focus(); }; self.element = $element; self.setFocused = function(isFocused) { $element.toggleClass('md-input-focused', !!isFocused); }; self.setHasValue = function(hasValue) { $element.toggleClass('md-input-has-value', !!hasValue); }; self.setInvalid = function(isInvalid) { $element.toggleClass('md-input-invalid', !!isInvalid); }; $scope.$watch(function() { return self.label && self.input; }, function(hasLabelAndInput) { if (hasLabelAndInput && !self.label.attr('for')) { self.label.attr('for', self.input.attr('id')); } }); } } mdInputContainerDirective.$inject = ["$mdTheming", "$parse"]; function labelDirective() { return { restrict: 'E', require: '^?mdInputContainer', link: function(scope, element, attr, containerCtrl) { if (!containerCtrl || attr.mdNoFloat) return; containerCtrl.label = element; scope.$on('$destroy', function() { containerCtrl.label = null; }); } }; } /** * @ngdoc directive * @name mdInput * @restrict E * @module material.components.input * * @description * Use the `` or the ` *
*
This is required!
*
That's too long!
*
*
* * * * * * * * * * Requires [ngMessages](https://docs.angularjs.org/api/ngMessages). * Behaves like the [AngularJS input directive](https://docs.angularjs.org/api/ng/directive/input). * */ function inputTextareaDirective($mdUtil, $window, $mdAria) { return { restrict: 'E', require: ['^?mdInputContainer', '?ngModel'], link: postLink }; function postLink(scope, element, attr, ctrls) { var containerCtrl = ctrls[0]; var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel(); var isReadonly = angular.isDefined(attr.readonly); if ( !containerCtrl ) return; if (containerCtrl.input) { throw new Error(" can only have *one* or