MediaWiki:CharCount.js: Difference between revisions
Richardpruen (talk | contribs) No edit summary |
Richardpruen (talk | contribs) Final version, just .js embedding the html into this didn't work |
||
Line 1: | Line 1: | ||
$(function getID(id) { | $( function () { | ||
function getID(id) { | |||
return document.getElementById(id); | return document.getElementById(id); | ||
} | } | ||
$(function addNumericOptions(id, min, max, defIndex) { | $(function addNumericOptions(id, min, max, defIndex) { | ||
var s = getID(id); | var s = getID(id); | ||
Line 13: | Line 15: | ||
s.value = defIndex; | s.value = defIndex; | ||
}); | }); | ||
function getMaxChars() { | |||
var maxChar = getID('chars'); | var maxChar = getID('chars'); | ||
return maxChar.value; | return maxChar.value; | ||
} | } | ||
function getLinkDiscount() { | |||
checkDiscount = getID('linkAbbreviate'); | checkDiscount = getID('linkAbbreviate'); | ||
if (!checkDiscount.checked) return 0; | if (!checkDiscount.checked) return 0; | ||
Line 41: | Line 43: | ||
return discount; | return discount; | ||
} | } | ||
function updateParamValues() { | |||
var c = getParamValue('c'); | var c = getParamValue('c'); | ||
lengthChoice = getID('chars'); | lengthChoice = getID('chars'); | ||
Line 58: | Line 60: | ||
text.rows = c/25; | text.rows = c/25; | ||
} | } | ||
function getParamValue(name) { | |||
var url = window.location.href; | var url = window.location.href; | ||
l1 = url.length; | l1 = url.length; | ||
Line 78: | Line 80: | ||
return null; | return null; | ||
} | } | ||
function updateOutput() { | |||
ld = getLinkDiscount(); | ld = getLinkDiscount(); | ||
cc = getCharacterCount(); | cc = getCharacterCount(); | ||
Line 100: | Line 102: | ||
o.value = v; | o.value = v; | ||
} | } | ||
function getCharacterCount() { | |||
input = getID('text'); | input = getID('text'); | ||
return input.value.length; | return input.value.length; | ||
} | } | ||
function setup() { | |||
addNumericOptions('chars', 40, 1000, 280); | addNumericOptions('chars', 40, 1000, 280); | ||
addNumericOptions('linkChars', 0, 100, 13); | addNumericOptions('linkChars', 0, 100, 13); | ||
Line 112: | Line 114: | ||
updateOutput(); | updateOutput(); | ||
} | } | ||
} ); | |||