MediaWiki:CharCount.js: Difference between revisions

Final version, just .js embedding the html into this didn't work
No edit summary
(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() {
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 41: 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 58: 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 78: Line 80:
return null;
return null;
}
}
);
 
$(function updateOutput() {
function updateOutput() {
ld = getLinkDiscount();
ld = getLinkDiscount();
cc = getCharacterCount();
cc = getCharacterCount();
Line 100: 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 112: Line 114:
updateOutput();
updateOutput();
}
}
);
} );
 
$(function () {
$('#CharCount').html(
'<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Char Count</title>
<style>
body {
font-family: sans-serif;
}
</style>
<script src='CharCount.js'></script>
</head>
<body onload='setup()'>
<h1>Character Count</h1>
<p>This form is useful for planning text and links for a text input area that has a character limit.
<form id='textForm' oninput='updateOutput()'>
<table border=0>
<tr>
<td colspan=2>
Maximum Characters Allowed:
<select id="chars" name='chars' size="1">
</select>
<br>Abbreviates Links? <input type='checkbox' id='linkAbbreviate' value='Short Links'>
Characters/Link: <select id="linkChars" size="1">
</select>
</td>
</tr>
<tr>
<td colspan=2>
<textarea id='text' rows=10 cols=80>
</textarea>
</td>
</tr>
<tr>
<td id='warningLevel' style='border: solid 1px black; color: green; width: 20px; height: 20px'>
</td>
<td>
<output id="outputCount" value='0 of ?'>0 of ?</output>
</td>
</tr>
</table>
</form>
<h2>Notes</h2>
<table border=1>
<tr>
<th>Platform</th>
<th>User Type</th>
<th>Char Limit</th>
<th>Link Chars</th>
<th>Use these options</th>
</tr>
<tr>
<td>&#120143; (Twitter)</td>
<td>CN Unverified</td>
<td>280</td>
<td>-</td>
<td>
<a href='?c=280'>Setup</a>
</td>
</tr>
<tr>
<td>&#120143; (Twitter)</td>
<td>CN Verified</td>
<td>580?</td>
<td>-</td>
<td>
<a href='?c=580'>Setup</a>
</td>
</tr>
<tr>
<td>&#120143; (Twitter)</td>
<td>Unverified</td>
<td>280</td>
<td>13</td>
<td>
<a href='?c=280&l=13'>Setup</a>
</td>
</tr>
<tr>
<td>&#120143; (Twitter)</td>
<td>Verified</td>
<td>580</td>
<td>13</td>
<td>
<a href='?c=580&l=13'>Setup</a>
</td>
</tr>
</table>
</body>
</html>');