/*! jquery-word-and-character-counter-plugin 2.5.1 https://qwertypants@github.com/qwertypants/jQuery-Word-and-Character-Counter-Plugin 24-06-2017 */ !function(a){"use strict";a.fn.extend({counter:function(b){var c={type:"char",count:"down",goal:140,text:!0,target:!1,append:!0,translation:"",msg:"",containerClass:""},d="",e="",f=!1,b=a.extend({},c,b),g={init:function(c){var e=c.attr("id"),f=e+"_count";g.isLimitless(),d=a("");var h=a("
").attr("id",e+"_counter").append(d).append(" "+g.setMsg());b.containerClass&&b.containerClass.length&&h.addClass(b.containerClass),b.target&&a(b.target).length?b.append?a(b.target).append(h):a(b.target).prepend(h):b.append?h.insertAfter(c):h.insertBefore(c),c.attr("aria-controls",e+"_counter"),g.bind(c)},bind:function(a){a.on("keypress.counter keydown.counter keyup.counter blur.counter focus.counter change.counter paste.counter",g.updateCounter),a.on("keydown.counter",g.doStopTyping),a.trigger("keydown")},isLimitless:function(){if("sky"===b.goal)return b.count="up",f=!0},setMsg:function(){if(""!==b.msg)return b.msg;if(b.text===!1)return"";if(f)return""!==b.msg?b.msg:"";switch(this.text=b.translation||"character word left max",this.text=this.text.split(" "),this.chars="s ( )".split(" "),this.msg=null,b.type){case"char":b.count===c.count&&b.text?this.msg=this.text[0]+this.chars[1]+this.chars[0]+this.chars[2]+" "+this.text[2]:"up"===b.count&&b.text&&(this.msg=this.text[0]+this.chars[0]+" "+this.chars[1]+b.goal+" "+this.text[3]+this.chars[2]);break;case"word":b.count===c.count&&b.text?this.msg=this.text[1]+this.chars[1]+this.chars[0]+this.chars[2]+" "+this.text[2]:"up"===b.count&&b.text&&(this.msg=this.text[1]+this.chars[1]+this.chars[0]+this.chars[2]+" "+this.chars[1]+b.goal+" "+this.text[3]+this.chars[2])}return this.msg},getWords:function(b){return""!==b?a.trim(b).replace(/\s+/g," ").split(" ").length:0},updateCounter:function(f){var h="true"==a(this).attr("contentEditable")?a(this).text():a(this).val();(e<0||e>b.goal)&&g.passedGoal(a(this)),b.type===c.type?b.count===c.count?(e=b.goal-h.length,e<=0?d.text("0"):d.text(e)):"up"===b.count&&(e=h.length,d.text(e)):"word"===b.type&&(b.count===c.count?(e=g.getWords(h),e<=b.goal?(e=b.goal-e,d.text(e)):d.text("0")):"up"===b.count&&(e=g.getWords(h),d.text(e)))},doStopTyping:function(a){var d=[46,8,9,35,36,37,38,39,40,32];if(g.isGoalReached(a)&&a.keyCode!==d[0]&&a.keyCode!==d[1]&&a.keyCode!==d[2]&&a.keyCode!==d[3]&&a.keyCode!==d[4]&&a.keyCode!==d[5]&&a.keyCode!==d[6]&&a.keyCode!==d[7]&&a.keyCode!==d[8]){if(b.type!==c.type)return a.keyCode!==d[9]&&a.keyCode!==d[1]&&b.type!=c.type;if(49===!a.keyCode||17===!a.keyCode)return!1}},isGoalReached:function(a,d){return!f&&(b.count===c.count?(d=0,e<=d):(d=b.goal,e>=d))},wordStrip:function(b,c){var d=c.replace(/\s+/g," ").split(" ").length;return c=a.trim(c),b<=0||b===d?c:(c=a.trim(c).split(" "),c.splice(b,d,""),a.trim(c.join(" ")))},passedGoal:function(a){var c=a.val();"word"===b.type&&a.val(g.wordStrip(b.goal,c)),"char"===b.type&&a.val(c.substring(0,b.goal)),"down"===b.type&&d.val("0"),"up"===b.type&&d.val(b.goal)}};return this.each(function(){g.init(a(this))})}})}(jQuery);