Implementing Countable.js to count words.

Changed the words_count method to work with countable.js

Added the gem for countable.js
This commit is contained in:
gotens1211 2017-02-05 16:00:45 +05:30
parent 8b5d6603af
commit c1b81755c9
5 changed files with 17 additions and 14 deletions

View file

@ -45,6 +45,7 @@
//= require osem-commercials
//= require unobtrusive_flash
//= require unobtrusive_flash_bootstrap
//= require countable
$(document).ready(function() {
$('a[disabled=disabled]').click(function(event){

View file

@ -148,19 +148,15 @@ function get_color() {
}
function word_count(text, divId, maxcount) {
var r = 0;
var input = text.value.replace(/\s/g,' ');
var word_array = input.split(' ');
for (var i=0; i < word_array.length; i++) {
if (word_array[i].length > 0) r++;
}
var area = document.getElementById(text.id)
$('#' + divId).text(r);
if (r > maxcount) {
$('#' + divId).css('color', 'red');
} else {
$('#' + divId).css('color', '#333');
}
Countable.live(area, function(counter) {
$('#' + divId).text(counter.words);
if (counter.words > maxcount)
$('#' + divId).css('color', 'red');
else
$('#' + divId).css('color', 'black');
});
};
/* Wait for the DOM to be ready before attaching events to the elements */