META-INF.resources.butterfaces-dist-js.butterfaces-maxlength.jquery.js Maven / Gradle / Ivy
///
///
///
(function ($) {
// you have to extend jQuery with the fn["pluginName"] notation because in Typescript you can't extend
// the existing typing interface with fn.pluginName!
$.fn["butterMaxLength"] = function (options) {
return this.each(function (index, element) {
new ButterFaces.MaxLengthIndicator($(element), options);
});
};
})(jQuery);
var ButterFaces;
(function (ButterFaces) {
var ERROR_STYLE_CLASS = "has-error";
var INVALID_STYLE_CLASS = "is-invalid";
var MaxLengthIndicator = /** @class */ (function () {
function MaxLengthIndicator(rootElement, options) {
this.rootElement = rootElement;
this.options = options;
this.valueElement = this.rootElement.find("textarea");
this.maxLengthElement = $("").addClass("butter-component-maxlength-counter");
this.maxLengthElement.insertAfter(this.valueElement);
this.initializeComponent();
}
MaxLengthIndicator.prototype.initializeComponent = function () {
console.log("ButterFaces.MaxLengthIndicator - initializeComponent");
this.hasInitialValidationError = this.rootElement.hasClass(ERROR_STYLE_CLASS);
console.log(this.valueElement);
var that = this;
this.valueElement.on("focus blur keyup cut paste", function () {
that.checkValue();
});
// initial check
this.checkValue();
};
MaxLengthIndicator.prototype.checkValue = function () {
var value = this.valueElement.val();
if (!ButterFaces.Object.isNullOrUndefined(value)) {
console.log("ButterFaces.MaxLengthIndicator: updating maxlength value");
var freeLetterCount = this.options.maxLength - value.length;
var formatted = ButterFaces.String.format(this.options.maxLengthText, [freeLetterCount, this.options.maxLength]);
this.maxLengthElement.text(formatted);
if (!this.hasInitialValidationError) {
if (freeLetterCount < 0) {
this.rootElement.addClass(ERROR_STYLE_CLASS);
this.valueElement.addClass(INVALID_STYLE_CLASS);
}
else {
this.rootElement.removeClass(ERROR_STYLE_CLASS);
this.valueElement.removeClass(INVALID_STYLE_CLASS);
}
}
}
};
return MaxLengthIndicator;
}());
ButterFaces.MaxLengthIndicator = MaxLengthIndicator;
})(ButterFaces || (ButterFaces = {}));
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3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VyQ291bnQsIHRoaXMub3B0aW9ucy5tYXhMZW5ndGhdKTtcbiAgICAgICAgICAgICAgICB0aGlzLm1heExlbmd0aEVsZW1lbnQudGV4dChmb3JtYXR0ZWQpO1xuXG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmhhc0luaXRpYWxWYWxpZGF0aW9uRXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKGZyZWVMZXR0ZXJDb3VudCA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucm9vdEVsZW1lbnQuYWRkQ2xhc3MoRVJST1JfU1RZTEVfQ0xBU1MpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy52YWx1ZUVsZW1lbnQuYWRkQ2xhc3MoSU5WQUxJRF9TVFlMRV9DTEFTUyk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnJvb3RFbGVtZW50LnJlbW92ZUNsYXNzKEVSUk9SX1NUWUxFX0NMQVNTKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMudmFsdWVFbGVtZW50LnJlbW92ZUNsYXNzKElOVkFMSURfU1RZTEVfQ0xBU1MpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSJdfQ==
© 2015 - 2024 Weber Informatics LLC | Privacy Policy