tips:wordcounter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:wordcounter [2010-03-11 22:07] – 67.175.65.231 | tips:wordcounter [2022-12-19 11:46] (current) – [Discussion] 183.82.239.152 | ||
---|---|---|---|
Line 8: | Line 8: | ||
/** | /** | ||
* Script to add a wordcounter on the edit form | * Script to add a wordcounter on the edit form | ||
+ | * https:// | ||
* | * | ||
* @author Andreas Gohr < | * @author Andreas Gohr < | ||
Line 34: | Line 35: | ||
} | } | ||
- | addInitEvent(function(){ | + | // replaced next line as per https:// |
- | var form = $(' | + | // addInitEvent(function(){ |
+ | jQuery(function(){ | ||
+ | // replaced next line as per https:// | ||
+ | | ||
+ | var $form = jQuery('# | ||
+ | var form = $form[0]; | ||
if(!form) return; | if(!form) return; | ||
var div = document.createElement(' | var div = document.createElement(' | ||
Line 52: | Line 58: | ||
zei_all += charcounter(form.elements.suffix.value); | zei_all += charcounter(form.elements.suffix.value); | ||
- | addEvent(form.elements.wikitext,' | + | |
+ | // addEvent(form.elements.wikitext,' | ||
+ | jQuery(form.elements.wikitext).keyup(function(){ | ||
if(wordcounter_timeout) window.clearTimeout(wordcounter_timeout); | if(wordcounter_timeout) window.clearTimeout(wordcounter_timeout); | ||
wordcounter_timeout = window.setTimeout(function(){ | wordcounter_timeout = window.setTimeout(function(){ | ||
Line 70: | Line 78: | ||
</ | </ | ||
===== Discussion ===== | ===== Discussion ===== | ||
- | Can this be turned into a plugin that generates | + | Can this be turned into a plugin that generates |
+ | |||
+ | I can't get any of the word count scripts to work, either as userscript.js, | ||
+ | |||
+ | >same problem as [Kevin Dunn] is there a way to run this with HRUN? or can i check somehow if userscript.js is already running with or without errors? Thanks [kbsit] | ||
+ | |||
+ | Another alternative solution is using a good word count & character count tool freely available on the web, such as [[http:// | ||
+ | ==== Issue ==== | ||
+ | ReferenceError: | ||
+ | === a revised version === | ||
+ | I changed the script to add wordcounter below the summary bar. Cause I'm a newbie on javascript, I just cut out some unresolved parts (counting for section, floating on textarea) 8-o. It works on // | ||
+ | -- [[inbonk@gmail.com | In-Bon Kuh]] | ||
+ | |||
+ | <code javascript conf/ | ||
+ | /** | ||
+ | * Script to add a wordcounter below the summary bar | ||
+ | * https:// | ||
+ | * | ||
+ | * @author Andreas Gohr < | ||
+ | * @author Lars Flintzak | ||
+ | * @license GPL 2 | ||
+ | */ | ||
+ | |||
+ | var wordcounter_timeout; | ||
+ | |||
+ | function wordcounter(text){ | ||
+ | var list = text.split(/ | ||
+ | var len = list.length; | ||
+ | if(list[len-1] == '' | ||
+ | if(list[0] == '' | ||
+ | if(len < 0) len=0; | ||
+ | return len; | ||
+ | } | ||
+ | |||
+ | function charcounter(text){ | ||
+ | var list = text.split(/ | ||
+ | var len = text.length; | ||
+ | if(list[len-1] == '' | ||
+ | if(list[0] == '' | ||
+ | if(len < 0) len=0; | ||
+ | return len; | ||
+ | } | ||
+ | |||
+ | jQuery(function(){ | ||
+ | var $form = jQuery('# | ||
+ | var form = $form[0]; | ||
+ | if(!form) return; | ||
+ | |||
+ | var div = document.createElement(' | ||
+ | div.id = ' | ||
+ | div.style.color = '# | ||
+ | div.style.padding = '0.2em 0.2em'; | ||
+ | |||
+ | var $summary = jQuery(' | ||
+ | var summary = $summary[0]; | ||
+ | summary.appendChild(div); | ||
+ | |||
+ | jQuery(form.elements.wikitext).keyup(function(){ | ||
+ | if(wordcounter_timeout) window.clearTimeout(wordcounter_timeout); | ||
+ | wordcounter_timeout = window.setTimeout(function(){ | ||
+ | var len = wordcounter(form.elements.wikitext.value); | ||
+ | var zei = charcounter(form.elements.wikitext.value); | ||
+ | div.innerHTML = | ||
+ | 'text count: & | ||
+ | +(len)+' | ||
+ | },1000); | ||
+ | return true; | ||
+ | }); | ||
+ | }); | ||
+ | </ |
tips/wordcounter.1268341630.txt.gz · Last modified: 2010-03-11 22:07 by 67.175.65.231