mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
37 lines
912 B
JavaScript
37 lines
912 B
JavaScript
|
|
IonicModule
|
|
.directive('itemFloatingLabel', function() {
|
|
return {
|
|
restrict: 'C',
|
|
link: function(scope, element) {
|
|
var el = element[0];
|
|
var input = el.querySelector('input, textarea');
|
|
var inputLabel = el.querySelector('.input-label');
|
|
|
|
if ( !input || !inputLabel ) return;
|
|
|
|
var onInput = function() {
|
|
if ( input.value ) {
|
|
inputLabel.classList.add('has-input');
|
|
} else {
|
|
inputLabel.classList.remove('has-input');
|
|
}
|
|
};
|
|
|
|
input.addEventListener('input', onInput);
|
|
|
|
var ngModelCtrl = angular.element(input).controller('ngModel');
|
|
if ( ngModelCtrl ) {
|
|
ngModelCtrl.$render = function() {
|
|
input.value = ngModelCtrl.$viewValue || '';
|
|
onInput();
|
|
};
|
|
}
|
|
|
|
scope.$on('$destroy', function() {
|
|
input.removeEventListener('input', onInput);
|
|
});
|
|
}
|
|
};
|
|
});
|