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
3
Gemfile
3
Gemfile
|
|
@ -178,6 +178,9 @@ gem 'cloudinary'
|
|||
# for setting app configuration in the environment
|
||||
gem 'dotenv-rails'
|
||||
|
||||
# For countable.js
|
||||
gem "countable-rails", "~> 0.0.1"
|
||||
|
||||
# Both are not in a group as we use it also for rake data:demo
|
||||
# for fake data
|
||||
gem 'faker'
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ GEM
|
|||
execjs
|
||||
coffee-script-source (1.10.0)
|
||||
columnize (0.8.9)
|
||||
countable-rails (0.0.1)
|
||||
railties (>= 3.1)
|
||||
countries (1.2.5)
|
||||
currencies (~> 0.4.2)
|
||||
i18n_data (~> 0.7.0)
|
||||
|
|
@ -555,6 +557,7 @@ DEPENDENCIES
|
|||
chart-js-rails
|
||||
cloudinary
|
||||
cocoon
|
||||
countable-rails (~> 0.0.1)
|
||||
country_select
|
||||
coveralls
|
||||
daemons
|
||||
|
|
@ -634,4 +637,4 @@ DEPENDENCIES
|
|||
whenever
|
||||
|
||||
BUNDLED WITH
|
||||
1.12.5
|
||||
1.14.3
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
= link_to 'Change your avatar here', 'https://gravatar.com'
|
||||
= f.input :affiliation, as: :string,
|
||||
hint: 'This could be a company, a user group, or nothing at all.'
|
||||
= f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' }, 'onkeyup' => "word_count(this, 'biography-count', 150)" },
|
||||
= f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' } },
|
||||
hint: markdown_hint
|
||||
You have used
|
||||
%span#bio_length
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue