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.ObjectStatics.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,eyJ2ZXJzaW9uIjozL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HZhbHVlRWxlbWVudDogSlF1ZXJ5O1xuICAgICAgICBwcml2YXRlIG1heExlbmd0aEVsZW1lbnQ6IEpRdWVyeTtcbiAgICAgICAgcHJpdmF0ZSBoYXNJbml0aWFsVmFsaWRhdGlvbkVycm9yOiBib29sZWFuO1xuXG4gICAgICAgIGNvbnN0cnVjdG9yKHJvb3RFbGVtZW50OiBKUXVlcnksIG9wdGlvbnM6IE1heExlbmd0aEluZGljYXRvck9wdGlvbnMpIHtcbiAgICAgICAgICAgIHRoaXMucm9vdEVsZW1lbnQgPSByb290RWxlbWVudDtcbiAgICAgICAgICAgIHRoaXMub3B0aW9ucyA9IG9wdGlvbnM7XG4gICAgICAgICAgICB0aGlzLnZhbHVlRWxlbWVudCA9IHRoaXMucm9vdEVsZW1lbnQuZmluZChcInRleHRhcmVhXCIpO1xuICAgICAgICAgICAgdGhpcy5tYXhMZW5ndGhFbGVtZW50ID0gJChcIjxkaXY+XCIpLmFkZENsYXNzKFwiYnV0dGVyLWNvbXBvbmVudC1tYXhsZW5ndGgtY291bnRlclwiKTtcblxuICAgICAgICAgICAgdGhpcy5tYXhMZW5ndGhFbGVtZW50Lmluc2VydEFmdGVyKHRoaXMudmFsdWVFbGVtZW50KTtcblxuICAgICAgICAgICAgdGhpcy5pbml0aWFsaXplQ29tcG9uZW50KCk7XG4gICAgICAgIH1cblxuICAgICAgICBwcml2YXRlIGluaXRpYWxpemVDb21wb25lbnQoKTogdm9pZCB7XG4gICAgICAgICAgICBjb25zb2xlLmxvZyhcIkJ1dHRlckZhY2VzLk1heExlbmd0aEluZGljYXRvciAtIGluaXRpYWxpemVDb21wb25lbnRcIik7XG4gICAgICAgICAgICB0aGlzLmhhc0luaXRpYWxWYWxpZGF0aW9uRXJyb3IgPSB0aGlzLnJvb3RFbGVtZW50Lmhhc0NsYXNzKEVSUk9SX1NUWUxFX0NMQVNTKTtcblxuICAgICAgICAgICAgY29uc29sZS5sb2codGhpcy52YWx1ZUVsZW1lbnQpO1xuICAg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ICAgICAgICAgICAgICAgaWYgKGZyZWVMZXR0ZXJDb3VudCA8IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucm9vdEVsZW1lbnQuYWRkQ2xhc3MoRVJST1JfU1RZTEVfQ0xBU1MpO1xuICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy52YWx1ZUVsZW1lbnQuYWRkQ2xhc3MoSU5WQUxJRF9TVFlMRV9DTEFTUyk7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnJvb3RFbGVtZW50LnJlbW92ZUNsYXNzKEVSUk9SX1NUWUxFX0NMQVNTKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMudmFsdWVFbGVtZW50LnJlbW92ZUNsYXNzKElOVkFMSURfU1RZTEVfQ0xBU1MpO1xuICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufSJdfQ==
© 2015 - 2024 Weber Informatics LLC | Privacy Policy