-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.remainingwords.min.js
1 lines (1 loc) · 1.41 KB
/
jquery.remainingwords.min.js
1
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=function(a,s){return void 0===s&&(s="undefined"!=typeof window?require("jquery"):require("jquery")(a)),e(s),s}:e(jQuery)}(function(e){var a;e.fn.remainingwords=function(s){var n=e.extend({maxWords:30,warningLevel1:20,warningLevel2:25,overMaxClass:"over-max",warning1Class:"warning-1",warning2Class:"warning-2",template:'<p class="words-remaining-text">Words Remaining: <span class="words-remaining-value"></span></p>',valueSelector:"span.words-remaining-value",complete:null},s);(a=this).addClass("remaining-words"),$template=e(n.template);var l=$template.children(n.valueSelector);return a.after($template),l.text(n.maxWords),a.keyup(function(){var a=e(this).val().split(" ").filter(function(e){return e.length>0}).length;l.text(n.maxWords-a),a>n.maxWords?($template.removeClass(n.warning1Class),$template.removeClass(n.warning2Class),$template.addClass(n.overMaxClass)):a>n.warningLevel2?($template.removeClass(n.warning1Class),$template.removeClass(n.overMaxClass),$template.addClass(n.warning2Class)):a>n.warningLevel1?($template.removeClass(n.warning2Class),$template.removeClass(n.overMaxClass),$template.addClass(n.warning1Class)):($template.removeClass(n.warning1Class),$template.removeClass(n.warning2Class),$template.removeClass(n.overMaxClass))}),e.isFunction(n.complete)&&n.complete.call(this),this}});