mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-15 03:17:38 +01:00
29 lines
850 B
JavaScript
29 lines
850 B
JavaScript
/*
|
|
* charcount.js
|
|
*
|
|
* Usage:
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
* $config['additional_javascript'][] = 'js/charcount.js';
|
|
*
|
|
*/
|
|
|
|
$(document).ready(function(){
|
|
|
|
// Storing this jQuery object outside of the event callback
|
|
// prevents jQuery from having to search the DOM for it again
|
|
// every time an event is fired.
|
|
var $inputArea = $('#body');
|
|
var $coundownField = $('#countchar');
|
|
var $maxChars = 6001;
|
|
|
|
// Preset countdown field to max initial content length
|
|
$coundownField.text($maxChars - $inputArea.length);
|
|
|
|
// input :: for all modern browsers [1]
|
|
// selectionchange :: for IE9 [2]
|
|
// propertychange :: for <IE9 [3]
|
|
$inputArea.on('input selectionchange propertychange', function() {
|
|
$charCount = $maxChars - $inputArea.val().length;
|
|
$coundownField.text($charCount);
|
|
});
|
|
}); |