praiadeseselle/wire/modules/Inputfield/InputfieldText/InputfieldTextLength.min.js

1 line
2 KiB
JavaScript
Raw Normal View History

2022-03-08 15:55:41 +01:00
function InputfieldTextLength(d){var e=jQuery;if(typeof ProcessWire!="undefined"){var b=ProcessWire.config.InputfieldTextLength}else{var b=config.InputfieldTextLength}function f(i,h){var g=i.siblings(".InputfieldTextLengthNote");if(g.length){if(!h.length){g.remove();e(window).resize()}}else{if(h.length){g=e("<div class='InputfieldTextLengthNote'></div>");g.css("margin","2px 0 0 0");if(i.is("textarea")&&i.closest(".InputfieldCKEditor").length){i.parent().append(g)}else{i.after(g)}e(window).resize()}}if(h.length){g.html('<small class="detail">'+h+"</small>")}}function c(l,h){var j;if(l.closest(".InputfieldCKEditor").length){var k=l.attr("id");var g=CKEDITOR.instances[k];if(typeof g=="undefined"){return 0}j=g.getData();j=j.replace(/<[^>]+>/g,(h?" ":""));j=j.replace(/&[#a-z0-9]+;/gi," ")}else{j=e.trim(l.val())}if(h){if(!j.length){return 0}i=j;var i=j.replace(/[\r\n\t,:.!?\/]+/g," ");if(i.indexOf("&nbsp;")>-1){i=i.replace(/&nbsp;/gi," ")}i=e.trim(i.replace(/\s\s+/g," "));console.log(i);return i.split(" ").length}else{return j.length}}function a(m){var j=m.attr("data-showCount");var h=0;var l="";var g=false;if(j=="1"){var k=m.attr("data-minlength");var i=m.attr("maxlength");h=c(m,false);l=b.chars.replace("%d",h)+" ";if(h==1){l=b.char1+" "}if(typeof i=="undefined"||!i){i=m.attr("data-maxlength")}k=typeof k=="undefined"||!k?0:parseInt(k);i=typeof i=="undefined"||!i?0:parseInt(i);if(k){if(h>0&&h<k){l+="<span style='color:red'>"+b.min.replace("%d",k)+"</span>";g=true}}if(i){if(h>0&&h>i){l+="<span style='color:red'>"+b.max.replace("%d",i)+"</span>";g=true}else{if(h>=0&&!g){l+=b.max.replace("%d",i)}}}}else{if(j=="2"){h=c(m,true);if(h==1){l=b.word1+" "}else{if(h>1){l=b.words.replace("%d",h)+" "}}}}f(m,l)}if(d.length){d.on("keyup focus pw-focus change",function(g){a(e(this))});d.each(function(){a(e(this))})}}jQuery(document).ready(function(a){InputfieldTextLength(a(".InputfieldTextLength"));a(document).on("reloaded",".Inputfield",function(){InputfieldTextLength(a(this).find(".InputfieldTextLength"))})});