2017-12-13 14:30:27 +00:00
|
|
|
|
2017-04-21 22:33:38 +00:00
|
|
|
/*
|
|
|
|
* 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');
|
2017-07-17 01:30:31 +00:00
|
|
|
var $maxChars = 6001;
|
2017-04-21 22:33:38 +00:00
|
|
|
|
2017-12-13 14:30:27 +00:00
|
|
|
if ($inputArea.length == 0)
|
|
|
|
return;
|
|
|
|
|
2017-04-21 22:33:38 +00:00
|
|
|
// Preset countdown field to max initial content length
|
2017-12-13 14:30:27 +00:00
|
|
|
$('.countdown').text($maxChars - $inputArea.val().length);
|
2017-04-21 22:33:38 +00:00
|
|
|
|
|
|
|
// 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;
|
2017-12-13 14:30:27 +00:00
|
|
|
$('.countdown').text($charCount);
|
2017-04-21 22:33:38 +00:00
|
|
|
});
|
|
|
|
});
|