jQuery.wordStats={ unsortedWords:null, latinOnly:true, sortedWords:null, topWords:null, topWeights:null, _computed:false, addWords:function(str,weight){ if(str&&str.length>1){ var w=this.splitWords(str.toLowerCase()); for(var x=0,y=w.length;x1&&!this.stopWords[word]){ if(this.unsortedWords[word]) this.unsortedWords[word]+=weight; else this.unsortedWords[word]=weight; } } } },addWordsFromTextNodes:function(node,weight){ var nodes=node.childNodes; for(var i=0,j=nodes.length;i=97&&c<=122)||(c>=128&&c<=151)||(c>=160&&c<=164)||(c>=48&&c<=57)||(c>=224&&c<=246)||(c>=249&&c<=255)); } else { return c!=32&&c!=33&&c!=34&&c!=35&&c!=36&&c!=37&&c!=38&&c!=39&&c!=40&&c!=41&&c!=42&&c!=43&&c!=44&&c!=45&&c!=46&&c!=47&&c!=58&&c!=59&&c!=60&&c!=61&&c!=62&&c!=63; } },splitWords:function(words){ var w=new Array(),str=''; for(var i=0,j=words.length;i0) w.push(str); return(w); },computeWords:function(elem){ if(!elem) elem=window.document; this.unsortedWords=new Array(); if(elem.is("textarea")) { this.addWords(elem.val(),1); return; } this.addWords($('title',elem).text(),20); wordstats=this; $('h1',elem).each(function(){ wordstats.addWordsFromTextNodes($(this).get(0),15); }); $('h2',elem).each(function(){ wordstats.addWordsFromTextNodes($(this).get(0),10); }); $('h3, h4, h5, h6',elem).each(function(){ wordstats.addWordsFromTextNodes($(this).get(0),5); }); $('strong, b, em, i',elem).each(function(){ wordstats.addWordsFromTextNodes($(this).get(0),3); }); $('p, div, th, td, li, a, span',elem).each(function(){ wordstats.addWordsFromTextNodes($(this).get(0),2); }); $('img',elem).each(function(){ wordstats.addWords($(this).attr('alt'),1); wordstats.addWords($(this).attr('title'),1); }); this._computed=true; },computeTopWords:function(count,elem){ if(!this._computed) this.computeWords(elem); this.topWords=new Array(); this.topWeights=new Array(); this.topWeights.push(0); for(word in this.unsortedWords){ for(var i=0;ithis.topWeights[i]){ this.topWeights.splice(i,0,this.unsortedWords[word]); this.topWords.splice(i,0,word); break; } } } },sortWords:function(){ this.sortedWords=new Array(); i=0; for(word in this.unsortedWords){ this.sortedWords[i]=word; i++; } this.sortedWords.sort(function(a,b){ return wordstats.unsortedWords[b]-wordstats.unsortedWords[a]; }); },clear:function(){ this.unsortedWords=this.sortedWords=this.topWords=this.topWeights=null; this._computed=false; } }; jQuery.wordStats.stopWords={"able":true,"about":true,"above":true,"abroad":true,"according":true,"accordingly":true,"across":true,"actually":true,"after":true,"afterwards":true,"again":true,"against":true,"ago":true,"ahead":true,"ain't":true,"all":true,"allow":true,"allows":true,"almost":true,"alone":true,"along":true,"alongside":true,"already":true,"also":true,"although":true,"always":true,"am":true,"amid":true,"amidst":true,"among":true,"amongst":true,"an":true,"and":true,"another":true,"any":true,"anybody":true,"anyhow":true,"anyone":true,"anything":true,"anyway":true,"anyways":true,"anywhere":true,"apart":true,"appear":true,"appreciate":true,"appropriate":true,"are":true,"aren't":true,"around":true,"as":true,"aside":true,"ask":true,"asking":true,"associated":true,"at":true,"available":true,"away":true,"awfully":true,"back":true,"backward":true,"backwards":true,"be":true,"became":true,"because":true,"become":true,"becomes":true,"becoming":true,"been":true,"before":true,"beforehand":true,"begin":true,"behind":true,"being":true,"believe":true,"below":true,"beside":true,"besides":true,"best":true,"better":true,"between":true,"beyond":true,"both":true,"brief":true,"but":true,"by":true,"came":true,"can":true,"cannot":true,"cant":true,"can't":true,"caption":true,"cause":true,"causes":true,"certain":true,"certainly":true,"changes":true,"clearly":true,"c'mon":true,"come":true,"comes":true,"concerning":true,"consequently":true,"consider":true,"considering":true,"contain":true,"containing":true,"contains":true,"corresponding":true,"could":true,"couldn't":true,"course":true,"currently":true,"dare":true,"daren't":true,"definitely":true,"described":true,"despite":true,"does":true,"doesn't":true,"doing":true,"done":true,"don't":true,"did":true,"didn't":true,"different":true,"directly":true,"do":true,"down":true,"downwards":true,"during":true,"each":true,"eight":true,"eighty":true,"either":true,"else":true,"elsewhere":true,"end":true,"ending":true,"enough":true,"entirely":true,"especially":true,"etc":true,"even":true,"ever":true,"evermore":true,"every":true,"everybody":true,"everyone":true,"everything":true,"everywhere":true,"ex":true,"exactly":true,"example":true,"except":true,"fairly":true,"far":true,"farther":true,"few":true,"fewer":true,"fifth":true,"first":true,"five":true,"followed":true,"following":true,"follows":true,"for":true,"found":true,"four":true,"from":true,"forever":true,"former":true,"formerly":true,"forth":true,"forward":true,"further":true,"furthermore":true,"get":true,"gets":true,"getting":true,"given":true,"gives":true,"go":true,"gotten":true,"greetings":true,"goes":true,"going":true,"gone":true,"got":true,"had":true,"hadn't":true,"half":true,"happens":true,"hardly":true,"has":true,"hasn't":true,"have":true,"haven't":true,"having":true,"he":true,"he'd":true,"he'll":true,"hello":true,"help":true,"hence":true,"her":true,"here":true,"hereafter":true,"hereby":true,"herein":true,"here's":true,"hereupon":true,"hers":true,"herself":true,"he's":true,"hi":true,"him":true,"himself":true,"his":true,"hither":true,"hopefully":true,"how":true,"however":true,"hudred":true,"i'd":true,"if":true,"ignored":true,"i'll":true,"i'm":true,"immediate":true,"in":true,"inc":true,"indeed":true,"ndicate":true,"indicated":true,"indicates":true,"inner":true,"inside":true,"instead":true,"into":true,"inward":true,"is":true,"isn't":true,"it":true,"it'd":true,"it'll":true,"its":true,"it's":true,"itself":true,"i've":true,"just":true,"keep":true,"keeps":true,"kept":true,"know":true,"known":true,"knows":true,"last":true,"lately":true,"later":true,"latter":true,"latterly":true,"least":true,"less":true,"lest":true,"let":true,"let's":true,"like":true,"liked":true,"likely":true,"likewise":true,"little":true,"look":true,"looking":true,"looks":true,"low":true,"lower":true,"made":true,"mainly":true,"make":true,"makes":true,"many":true,"may":true,"maybe":true,"mayn't":true,"me":true,"mean":true,"meantime":true,"meanwhile":true,"merely":true,"might":true,"mine":true,"minus":true,"miss":true,"more":true,"moreover":true,"most":true,"mostly":true,"mr":true,"mrs":true,"much":true,"must":true,"mustn't":true,"my":true,"myself":true,"name":true,"namely":true,"near":true,"nearly":true,"necessary":true,"ne":true,"needn't":true,"needs":true,"neither":true,"never":true,"neverf":true,"neverless":true,"nevertheless":true,"new":true,"next":true,"nine":true,"ninety":true,"no":true,"nobody":true,"non":true,"none":true,"nonetheless":true,"nor":true,"normally":true,"not":true,"nothing":true,"notwithstanding":true,"novel":true,"now":true,"nowhere":true,"obviously":true,"of":true,"off":true,"often":true,"oh":true,"ok":true,"okay":true,"old":true,"on":true,"once":true,"one":true,"ones":true,"one's":true,"only":true,"onto":true,"opposite":true,"or":true,"other":true,"others":true,"otherwise":true,"ought":true,"oughtn't":true,"our":true,"ours":true,"ourselves":true,"out":true,"outside":true,"over":true,"overall":true,"own":true,"particular":true,"particularly":true,"past":true,"per":true,"perhaps":true,"placed":true,"please":true,"plus":true,"possible":true,"presumably":true,"probably":true,"provided":true,"provides":true,"que":true,"quite":true,"rather":true,"really":true,"reasonably":true,"recent":true,"recently":true,"regarding":true,"regardless":true,"regards":true,"relatively":true,"respectively":true,"right":true,"round":true,"said":true,"same":true,"saw":true,"say":true,"saying":true,"says":true,"second":true,"secondly":true,"see":true,"seeing":true,"seem":true,"seemed":true,"seeming":true,"seems":true,"seen":true,"self":true,"selves":true,"sensible":true,"sent":true,"serious":true,"seriously":true,"seven":true,"several":true,"shall":true,"shan't":true,"she":true,"she'd":true,"she'll":true,"she's":true,"should":true,"shouldn't":true,"since":true,"six":true,"so":true,"some":true,"somebody":true,"someday":true,"somehow":true,"someone":true,"something":true,"sometime":true,"sometimes":true,"somewhat":true,"somewhere":true,"soon":true,"sorry":true,"specified":true,"specify":true,"specifying":true,"still":true,"sub":true,"such":true,"sure":true,"take":true,"taken":true,"taking":true,"tell":true,"tends":true,"than":true,"thank":true,"thanks":true,"thanx":true,"that":true,"that'll":true,"thats":true,"that's":true,"that've":true,"the":true,"their":true,"theirs":true,"them":true,"themselves":true,"then":true,"thence":true,"there":true,"thereafter":true,"thereby":true,"there'd":true,"therefore":true,"therein":true,"there'll":true,"there're":true,"theres":true,"there's":true,"thereupon":true,"there've":true,"these":true,"they":true,"they'd":true,"they'll":true,"they're":true,"they've":true,"thing":true,"things":true,"think":true,"third":true,"thirty":true,"this":true,"thorough":true,"thoroughly":true,"those":true,"though":true,"three":true,"through":true,"throughout":true,"thru":true,"thus":true,"till":true,"to":true,"together":true,"too":true,"took":true,"toward":true,"towards":true,"tried":true,"tries":true,"truly":true,"try":true,"trying":true,"twice":true,"two":true,"under":true,"underneath":true,"undoing":true,"unfortunately":true,"unless":true,"unlike":true,"unlikely":true,"until":true,"unto":true,"up":true,"upon":true,"upwards":true,"us":true,"use":true,"used":true,"useful":true,"uses":true,"using":true,"usually":true,"value":true,"various":true,"versus":true,"very":true,"via":true,"vs":true,"vs.":true,"want":true,"wants":true,"was":true,"wasn't":true,"way":true,"we":true,"we'd":true,"welcome":true,"well":true,"we'll":true,"went":true,"were":true,"we're":true,"weren't":true,"we've":true,"what":true,"whatever":true,"what'll":true,"what's":true,"what've":true,"when":true,"whence":true,"whenever":true,"where":true,"whereafter":true,"whereas":true,"whereby":true,"wherein":true,"where's":true,"whereupon":true,"wherever":true,"whether":true,"which":true,"whichever":true,"while":true,"whilst":true,"whither":true,"who":true,"who'd":true,"whoever":true,"whole":true,"who'll":true,"whom":true,"whomever":true,"who's":true,"whose":true,"why":true,"will":true,"willing":true,"wish":true,"with":true,"within":true,"without":true,"wonder":true,"won't":true,"would":true,"wouldn't":true,"yes":true,"yet":true,"you":true,"you'd":true,"you'll":true,"your":true,"you're":true,"yours":true,"yourself":true,"yourselves":true,"you've":true,"zero":true};; jQuery.extend({ highlight:function(node,re,nodeName,className){ if(node.nodeType===3){ var match=node.data.match(re); if(match){ var highlight=document.createElement(nodeName||'span'); highlight.className=className||'highlight'; var wordNode=node.splitText(match.index); wordNode.splitText(match[0].length); var wordClone=wordNode.cloneNode(true); highlight.appendChild(wordClone); wordNode.parentNode.replaceChild(highlight,wordNode); return 1; } }else if((node.nodeType===1&&node.childNodes)&&!/(script|style)/i.test(node.tagName)&&!(node.tagName===nodeName.toUpperCase()&&node.className===className)){ for(var i=0;i=0;t--){if("undefined"===typeof Array.indexOf&&-1!==localStorage.key(t).indexOf("garlic:")){localStorage.removeItem(localStorage.key(t))}}return"function"===typeof e?e():true},clear:function(e){localStorage.clear();return"function"===typeof e?e():true}};var n=function(e,t,n){this.init("garlic",e,t,n)};n.prototype={constructor:n,init:function(t,n,r,i){this.type=t;this.$element=e(n);this.options=this.getOptions(i);this.storage=r;this.path=this.options.getPath(this.$element)||this.getPath();this.parentForm=this.$element.closest("form");this.$element.addClass("garlic-auto-save");this.expiresFlag=!this.options.expires?false:(this.$element.data("expires")?this.path:this.getPath(this.parentForm))+"_flag";this.$element.on(this.options.events.join("."+this.type+" "),false,e.proxy(this.persist,this));if(this.options.destroy){e(this.parentForm).on("submit reset",false,e.proxy(this.destroy,this))}this.retrieve()},getOptions:function(t){return e.extend({},e.fn[this.type].defaults,t,this.$element.data())},persist:function(){if(this.val===this.getVal()){return}this.val=this.getVal();if(this.options.expires){this.storage.set(this.expiresFlag,((new Date).getTime()+this.options.expires*1e3).toString())}this.storage.set(this.path,this.getVal())},getVal:function(){return!this.$element.is("input[type=checkbox]")?this.$element.val():this.$element.prop("checked")?"checked":"unchecked"},retrieve:function(){if(this.storage.has(this.path)){if(this.options.expires){var e=(new Date).getTime();if(this.storage.get(this.expiresFlag)1&&!e(s).is("input[type=radio]")){o+=":eq("+a.index(s)+")"}n=o+(n?">"+n:"");if("form"==s.nodeName.toLowerCase()){break}i=u}return"garlic:"+document.domain+(this.options.domain?"*":window.location.pathname)+">"+n},getStorage:function(){return this.storage}};e.fn.garlic=function(r,i){function a(t){var i=e(t),u=i.data("garlic"),a=e.extend({},s,i.data());if("undefined"!==typeof a.storage&&!a.storage){return}if("password"===e(t).attr("type")){return}if(!u){i.data("garlic",u=new n(t,o,a))}if("string"===typeof r&&"function"===typeof u[r]){return u[r]()}}var s=e.extend(true,{},e.fn.garlic.defaults,r,this.data()),o=new t,u=false;if(!o.defined){return false}this.each(function(){if(e(this).is("form")){e(this).find(s.inputs).each(function(){u=a(e(this))})}else if(e(this).is(s.inputs)){u=a(e(this))}});return"function"===typeof i?i():u};e.fn.garlic.Constructor=n;e.fn.garlic.defaults={destroy:true,inputs:"input, textarea, select",events:["DOMAttrModified","textInput","input","change","click","keypress","paste","focus"],domain:false,expires:false,conflictManager:{enabled:false,garlicPriority:true,template:'',message:"This is your saved data. Click here to see default one",onConflictDetected:function(e,t){return true}},getPath:function(e){},onRetrieve:function(e,t){}};e(window).on("load",function(){e('[data-persist="garlic"]').each(function(){e(this).garlic()})})}(window.jQuery||window.Zepto) ; $(function() { var textarea,staticOffset; var iLastMousePos=0; var iMin=32; var grip; var box=$("#box"); var count=[]; var fullStr=box.val()+" "; var initial_whitespace_rExp=/^[^A-Za-z0-9]+/gi; var left_trimmedStr=fullStr.replace(initial_whitespace_rExp,""); var non_alphanumerics_rExp=rExp=/[^A-Za-z0-9'’-]+/gi; var cleanedStr=left_trimmedStr.replace(non_alphanumerics_rExp," "); var splitString=cleanedStr.split(" "); count['words']=splitString.length-1; count['chars']=box.val().length; count['sentences']=box.val().split(/[.?!](?=\s|\n)/).length; count['paragraphs']=box.val().split(/\n[^\n]/).length; count['avg_sentence_length']=Math.ceil(count['words']/count['sentences']); displayCount(count); displayTextBoxes(count); function countWords(text,language) { var reg=new RegExp("(\\w)", "g"); //var words=text.replace(/[,;.!:—\/]/g,' ').replace(/[^a-zA-Z\d\s&:]/g,'').match(/\S+/g); var words=text.replace(/[,;.!:—\/]/g,' ').replace(/\\w/g,'').match(/\S+/g); return(words!==null?words.length:0); } function wordCountInternational() { $("#collapseOne").removeClass("hide"); $("#collapseTwo").removeClass("hide"); var count=[]; count['words']=countWords(box.val(),0); chars=box.val().match(/(?:[^\r\n]|\r(?!\n))/g); count['chars']=(chars!==null?chars.length:0); chars_no_spaces=box.val().match(/\S/g);count['chars_no_spaces']=(chars_no_spaces!==null?chars_no_spaces.length:0); sentences=box.val().match(/[^.!?\s][^.!?]*(?:[.!?](?!['"]?\s|$)[^.!?]*)*[.!?]?['"]?(?=\s|$)/g); count['sentences']=(sentences!==null?sentences.length:0); paragraphs=box.val().match(/(\n\n?|^).*?(?=\n\n?|$)/g);count['paragraphs']=(box.val()!=''?(paragraphs!==null?paragraphs.length:0):0); count['avg_sentence_words']=(box.val()!=''?Math.ceil(count['words']/count['sentences']):0); count['avg_sentence_chars']=(box.val()!=''?Math.ceil(count['chars']/count['sentences']):0); displayCount(count); displayTextBoxes(count); } function nl2br(str,is_xhtml){ var breakTag=(is_xhtml||typeof is_xhtml==='undefined')?'
':'
';return(str+'').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,'$1'+breakTag+'$2'); } function displayTextBoxes(count) { $("#word_count").text(count['words']); $("#word_count").parent().find(".labelList").text((count['words'] <= 1) ? "Slovo" : "Slova"); $("#character_count").text(count['chars']); $("#character_count").parent().find(".labelList").text((count['chars'] <= 1) ? "Znak" : "Postavy"); $("#character_count_no_spaces").text(count['chars_no_spaces']); $("#character_count_no_spaces").parent().find(".labelList").text((count['chars_no_spaces'] <= 1) ? "Znak (žádné mezery)" : "Postavy (žádné mezery)"); $("#sentence_count").text(count['sentences']); $("#sentence_count").parent().find(".labelList").text((count['sentences'] <= 1) ? "Věta" : "Fráze"); $("#paragraph_count").text(count['paragraphs']); $("#paragraph_count").parent().find(".labelList").text((count['paragraphs'] <= 1) ? "Část" : "Odstavce"); $("#avg_sentence_words").text(count['avg_sentence_words']); $("#avg_sentence_chars").text(count['avg_sentence_chars']); } function displayCount(count){ if(count['words']<=1){ wordOrWords=" Slovo"; }else{ wordOrWords=" Slova"; } if(count['chars']<=1){ charOrChars=" Znak"; console.log("test="+count['chars']); if (count['chars'] == 0) { $("#collapseOne").addClass("hide"); $("#collapseTwo").addClass("hide"); } }else{ charOrChars=" Postavy"; } $(".counted").html(' '+count['words']+''+wordOrWords+"\n"+' '+count['chars']+''+charOrChars); } function getTotalWeights(arr){ var total=0; $.each(arr,function(){total+=this;}); return total; } function keywordDensity(){ var max=1000; stats=$.wordStats; stats.computeTopWords(max,$('#box')); totalWeights=getTotalWeights(stats.topWeights); density_list=$("#collapseTwo"); density_list.empty(); var text=''; var percentage; var nbShowed = 0; for(i=0;i 3) { percentage=(100*(stats.topWeights[i]/totalWeights)).toFixed(0); density_list.append(' '+stats.topWeights[i]+' ('+percentage+'%)'+stats.topWords[i]+''); nbShowed = nbShowed + 1; } } stats.clear(); } box.keypress(wordCountInternational).change(wordCountInternational).keyup(wordCountInternational).load(wordCountInternational); box.keypress(keywordDensity).change(keywordDensity).keyup(keywordDensity).load(keywordDensity); box.bind('paste',function(e){ var el=$(this); setTimeout(function(){ var text=$(el).val(); keywordDensity(); },4); }); body=$("body"); body.on('click','#collapseTwo a',function(e){ e.preventDefault(); if(!$(this).hasClass('active')) { box_readonly=$('#box_readonly'); box_readonly.show(); box_readonly.html(nl2br($("#box").val())); box_readonly.highlight($(this).find('.word').text(),{wordsOnly:false}); box_readonly.height($('#box').height()+23); $('#form').hide(); $(this).siblings().removeClass('active'); $(this).addClass('active'); } else { $('#box_readonly').hide(); $('#form').show(); $('#collapseTwo').find('a').removeClass('active'); } }); body.on('click','#box_readonly',function(){ $('#box_readonly').hide(); $('#form').show(); $('#collapseTwo').find('a').removeClass('active'); }); $("#clear").click(function() { location.reload(); //$("#box").val('').empty(); //keywordDensity();wordCountInternational(); //$("#collapseOne").addClass("hide"); //$("#collapseTwo").addClass("hide"); return false; }); $("#box").change(function() { keywordDensity();wordCountInternational(); }); });