NazariyM
2/2/2017 - 10:33 PM

adds "active" class to NOT empty input so we can style placeholder like in "zruchna"

adds "active" class to NOT empty input so we can style placeholder like in "zruchna"

function Input(opt) {
	this._input = opt.el;

	if(this._isNotEmpty(this._input)) {

		this._input.addClass('is-active');
	}

	this._input.on('input change', this._addClass.bind(this));

}

Input.prototype._isNotEmpty = function(el) {
	return !!el.val();
};

Input.prototype._addClass = function(e) {
	var el = $(e.currentTarget);

	if(this._isNotEmpty(el)) {
		el.addClass('is-active');

	} else {
		el.removeClass('is-active');
	}
};


var input = new Input({
	el: $('.js-input')
});