Skip to content

Commit

Permalink
Make it possible to override the NiceText chars left HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 23, 2021
1 parent 72c2ead commit 91b20b4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dist/garnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4486,8 +4486,7 @@ Garnish.NiceText = Garnish.Base.extend(
$charsLeft: null,
autoHeight: null,
maxLength: null,
showCharsLeft: null,
charsLeftPrefix: null,
showCharsLeft: false,
showingHint: false,
val: null,
inputBoxSizing: 'content-box',
Expand Down Expand Up @@ -4528,7 +4527,6 @@ Garnish.NiceText = Garnish.Base.extend(

if (this.maxLength && (this.settings.showCharsLeft || Garnish.hasAttr(this.$input, 'data-show-chars-left'))) {
this.showCharsLeft = true;
this.charsLeftPrefix = this.$input.attr('data-chars-left-prefix') || '';

// Remove the maxlength attribute
this.$input.removeAttr('maxlength');
Expand Down Expand Up @@ -4746,7 +4744,7 @@ Garnish.NiceText = Garnish.Base.extend(

updateCharsLeft: function() {
this.updateCharsLeft._charsLeft = this.maxLength - this.val.length;
this.$charsLeft.html('<span class="visually-hidden">' + this.charsLeftPrefix + '</span>' + this.updateCharsLeft._charsLeft);
this.$charsLeft.html(Garnish.NiceText.charsLeftHtml(this.updateCharsLeft._charsLeft));

if (this.updateCharsLeft._charsLeft >= 0) {
this.$charsLeft.removeClass(this.settings.negativeCharsLeftClass);
Expand Down Expand Up @@ -4776,6 +4774,9 @@ Garnish.NiceText = Garnish.Base.extend(
{
interval: 100,
hintFadeDuration: 50,
charsLeftHtml: function(charsLeft) {
return charsLeft;
},
defaults: {
autoHeight: true,
showCharsLeft: false,
Expand Down
4 changes: 2 additions & 2 deletions dist/garnish.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/garnish.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/NiceText.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Garnish.NiceText = Garnish.Base.extend(
$charsLeft: null,
autoHeight: null,
maxLength: null,
showCharsLeft: null,
charsLeftPrefix: null,
showCharsLeft: false,
showingHint: false,
val: null,
inputBoxSizing: 'content-box',
Expand Down Expand Up @@ -52,7 +51,6 @@ Garnish.NiceText = Garnish.Base.extend(

if (this.maxLength && (this.settings.showCharsLeft || Garnish.hasAttr(this.$input, 'data-show-chars-left'))) {
this.showCharsLeft = true;
this.charsLeftPrefix = this.$input.attr('data-chars-left-prefix') || '';

// Remove the maxlength attribute
this.$input.removeAttr('maxlength');
Expand Down Expand Up @@ -270,7 +268,7 @@ Garnish.NiceText = Garnish.Base.extend(

updateCharsLeft: function() {
this.updateCharsLeft._charsLeft = this.maxLength - this.val.length;
this.$charsLeft.html('<span class="visually-hidden">' + this.charsLeftPrefix + '</span>' + this.updateCharsLeft._charsLeft);
this.$charsLeft.html(Garnish.NiceText.charsLeftHtml(this.updateCharsLeft._charsLeft));

if (this.updateCharsLeft._charsLeft >= 0) {
this.$charsLeft.removeClass(this.settings.negativeCharsLeftClass);
Expand Down Expand Up @@ -300,6 +298,9 @@ Garnish.NiceText = Garnish.Base.extend(
{
interval: 100,
hintFadeDuration: 50,
charsLeftHtml: function(charsLeft) {
return charsLeft;
},
defaults: {
autoHeight: true,
showCharsLeft: false,
Expand Down

0 comments on commit 91b20b4

Please sign in to comment.