From 60fcd6f4d8b895162b37a940c3f33164d8044382 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 7 Jan 2015 13:26:49 -0700 Subject: [PATCH] feat(input): add parent for inputs/textareas, deprecate md-text-float Closes #993. Closes #372. Closes #476. Closes #523. Closes #543. Closes #547. Closes #553. Closes #562. Closes #575. Closes #605. Closes #606. Closes #612. Closes #654. Closes #687. Closes #744. Closes #839. Closes #847. Closes #931. Closes #993. md-textfloat has been deprecated due to flaws (explanation in [#547](https://github.com/angular/material/issues/547)). Now, to create an input you use the native `` and ` + * + * + * + */ +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 inputDirective($mdUtil) { + 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 (containerCtrl.input) { + throw new Error(" can only have *one* or