-
Notifications
You must be signed in to change notification settings - Fork 4
/
limit-post-titles.min.js
1 lines (1 loc) · 1.4 KB
/
limit-post-titles.min.js
1
!function(){var a=function(){var a={limit:window.sr_post_titles.limit,bootstrap:function(){this.el=document.getElementById("titlewrap"),this.submitBtn=document.getElementById("publish"),this.postForm=document.getElementById("post"),this.el&&this.appendCounter()},appendCounter:function(){this.counter=document.createElement("span"),this.counter.appendChild(document.createTextNode("")),this.counter.id="sr-title-limiter",this.el.appendChild(this.counter),this.titleInput=this.el.getElementsByTagName("input")[0],this.run()},setCounter:function(){this.counter.childNodes[0].nodeValue=this.getLength(),this.setClasses()},setClasses:function(){parseInt(this.getLength(),10)<0?(this.counter.style.color="red",this.submitBtn.className="button button-primary-disabled button-large"):(this.counter.style.color="#999",this.submitBtn.className="button button-primary button-large")},getLength:function(){return this.limit-this.titleInput.value.length},checkLimit:function(a){return this.getLength()<1?(window.alert("Your title must be below "+this.limit+" characters."),a.stopImmediatePropagation(),a.preventDefault(),!1):void 0},run:function(){this.setCounter(),this.titleInput.addEventListener("keyup",this.setCounter.bind(this)),this.submitBtn.addEventListener("click",this.checkLimit.bind(this)),this.postForm.addEventListener("submit",this.checkLimit.bind(this))}};this.init=function(){a.bootstrap()}},b=new a;window.setTimeout(b.init,0)}();