mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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:
parent
8b5d6603af
commit
c1b81755c9
5 changed files with 17 additions and 14 deletions
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue