MediaWiki:CharCount.js: Difference between revisions

This should work, it's what the example says!
Forgot the identifier
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(function () {
$( function () {
var myPlace = document.getElementById('CharCount');
var myPlace = document.getElementById('CharCount');
myPlace.innerHTML =$(function addNumericOptions(id, min, max, defIndex) {
function getID(id) {
var s = getID(id);
return document.getElementById(id);
for (ii=min; ii<=max; ii++) {
}
var option =  document.createElement("option");
 
option.text = ii;
function addNumericOptions(id, min, max, defIndex) {
option.value = ii;
var s = getID(id);
s.add(option);
for (ii=min; ii<=max; ii++) {
}
var option =  document.createElement("option");
s.value = defIndex;
option.text = ii;
});
option.value = ii;
$(function getMaxChars() {
s.add(option);
}
s.value = defIndex;
}
function getMaxChars() {
var maxChar = getID('chars');
var maxChar = getID('chars');
return maxChar.value;
return maxChar.value;
}
}
);
 
$(function getLinkDiscount() {
function getLinkDiscount() {
checkDiscount = getID('linkAbbreviate');
checkDiscount = getID('linkAbbreviate');
if (!checkDiscount.checked) return 0;
if (!checkDiscount.checked) return 0;
Line 39: Line 43:
return discount;
return discount;
}
}
);
 
$(function updateParamValues() {
function updateParamValues() {
var c = getParamValue('c');
var c = getParamValue('c');
lengthChoice = getID('chars');
lengthChoice = getID('chars');
Line 56: Line 60:
text.rows = c/25;
text.rows = c/25;
}
}
);
 
$(function getParamValue(name) {
function getParamValue(name) {
var url = window.location.href;
var url = window.location.href;
l1 = url.length;
l1 = url.length;
Line 76: Line 80:
return null;
return null;
}
}
);
 
$(function updateOutput() {
function updateOutput() {
ld = getLinkDiscount();
ld = getLinkDiscount();
cc = getCharacterCount();
cc = getCharacterCount();
Line 98: Line 102:
o.value = v;
o.value = v;
}
}
);
 
$(function getCharacterCount() {
function getCharacterCount() {
input = getID('text');
input = getID('text');
return input.value.length;
return input.value.length;
}
}
);
 
$(function setup() {
function setup() {
addNumericOptions('chars', 40, 1000, 280);
addNumericOptions('chars', 40, 1000, 280);
addNumericOptions('linkChars', 0, 100, 13);
addNumericOptions('linkChars', 0, 100, 13);
Line 110: Line 114:
updateOutput();
updateOutput();
}
}
);
 
}());
});