(function() { /** * @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); /** * @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. * * @usage * * * * * * * * * * * * * */ function mdInputContainerDirective($mdTheming) { return { restrict: 'E', link: postLink, controller: ContainerCtrl }; function postLink(scope, element, attr) { $mdTheming(element); } function ContainerCtrl($scope, $element, $mdUtil) { var self = this; self.setFocused = function(isFocused) { $element.toggleClass('md-input-focused', !!isFocused); }; self.setHasValue = function(hasValue) { $element.toggleClass('md-input-has-value', !!hasValue); }; $scope.$watch(function() { return self.label && self.input; }, function(hasLabelAndInput) { if (hasLabelAndInput && !self.label.attr('for')) { self.label.attr('for', self.input.attr('id')); } }); } } function labelDirective() { return { restrict: 'E', require: '^?mdInputContainer', link: function(scope, element, attr, containerCtrl) { if (!containerCtrl) return; containerCtrl.label = element; scope.$on('$destroy', function() { containerCtrl.label = null; }); } }; } function inputTextareaDirective($mdUtil, $window) { return { restrict: 'E', require: ['^?mdInputContainer', '?ngModel'], compile: compile, }; function compile(element) { element.addClass('md-input'); return postLink; } function postLink(scope, element, attr, ctrls) { var containerCtrl = ctrls[0]; var ngModelCtrl = ctrls[1]; if ( !containerCtrl ) return; if (element[0].tagName.toLowerCase() === 'textarea') { setupTextarea(); } if (containerCtrl.input) { throw new Error(" can only have *one* or