Word Counter in Certain Areas of Site
2 posters
Page 1 of 1
Word Counter in Certain Areas of Site
Hi there,
I've been looking at putting a word counter in certain areas of my site. It is only in the categories that I wish to apply the code, and I have five of these. How do I add this in to my JavaScript to make it work?
Everything else in my forum is just a forum, so there are no other categories on the site except those I need to have my 150 word count.
Also, how do I stop the word counter from picking up the coding in brackets as words?
Hope this makes sense!
I've been looking at putting a word counter in certain areas of my site. It is only in the categories that I wish to apply the code, and I have five of these. How do I add this in to my JavaScript to make it work?
Everything else in my forum is just a forum, so there are no other categories on the site except those I need to have my 150 word count.
Also, how do I stop the word counter from picking up the coding in brackets as words?
Hope this makes sense!
Re: Word Counter in Certain Areas of Site
- Code:
$(function(){$(function(){
- Code:
var MinNumberOfWords = 150;
var LetterCountPerWord = 1;
var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
if($("#text_editor_textarea").length != 0){
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
$(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val();
var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
var str_arr = str.match(regex);
var str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
sceditor.keyUp(function(e) {
str = sceditor.val();
str_arr = str.match(regex);
str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl + "' />");
$("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
}else{
$("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
});
}
})});
This is the code I'm using and I want it to apply to Category 4, 5, 6, 7 and 9
Any help would be appreciated!
Re: Word Counter in Certain Areas of Site
Hello SMOakey7,
Could you provide a link to your forum ?
Thanks
Could you provide a link to your forum ?
Thanks
Re: Word Counter in Certain Areas of Site
Try this :
- Code:
$(function(){$(function() {
if (c(4) || c(5) || c(6) || c(7) || c(9)) {
var MinNumberOfWords = 150;
var LetterCountPerWord = 1;
var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
if($("#text_editor_textarea").length != 0){
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
$(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val();
var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
var str_arr = str.match(regex);
var str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
sceditor.keyUp(function(e) {
str = sceditor.val();
str_arr = str.match(regex);
str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl + "' />");
$("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
}else{
$("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
});
}
}
function c(n) { return n == Number($('.nav a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1')) }
})});
Re: Word Counter in Certain Areas of Site
Okay, see if this works :
- Code:
$(function(){$(function() {
if (!$('.nav a:eq(1), .pathname-box a:eq(1)').length) return;
var c = Number($('.nav a:eq(1), .pathname-box a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1'));
if (c == 4 || c == 5 || c == 6 || c == 7 || c == 9) {
var MinNumberOfWords = 150;
var LetterCountPerWord = 1;
var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
if($("#text_editor_textarea").length != 0){
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
$(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val();
var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
var str_arr = str.match(regex);
var str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
sceditor.keyUp(function(e) {
str = sceditor.val();
str_arr = str.match(regex);
str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl + "' />");
$("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
}else{
$("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
});
}
}
})});
Re: Word Counter in Certain Areas of Site
I'm afraid it's still not working I've tried it on All of the pages, and then with none ticked and it doesn't work
Re: Word Counter in Certain Areas of Site
http://hogwartsandbeyond.forumotion.co.uk/c1-hogwarts-school-of-witchcraft-wizardry
http://hogwartsandbeyond.forumotion.co.uk/c2-hogsmeade-village
http://hogwartsandbeyond.forumotion.co.uk/c3-university-of-excelled-witchcraft-and-wizardry
http://hogwartsandbeyond.forumotion.co.uk/c4-rest-of-the-world
http://hogwartsandbeyond.forumotion.co.uk/c5-adult-section
These please
http://hogwartsandbeyond.forumotion.co.uk/c2-hogsmeade-village
http://hogwartsandbeyond.forumotion.co.uk/c3-university-of-excelled-witchcraft-and-wizardry
http://hogwartsandbeyond.forumotion.co.uk/c4-rest-of-the-world
http://hogwartsandbeyond.forumotion.co.uk/c5-adult-section
These please
Re: Word Counter in Certain Areas of Site
Using both of them, last night the word counter was working in both, but it was showing in all areas, I only need it in the links above, if possible?
Re: Word Counter in Certain Areas of Site
Okay, check if this works for the quick reply :
- Code:
$(function(){$(function() {
var c = Number($('.nav a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1'));
if (c == 4 || c == 5 || c == 6 || c == 7 || c == 9) {
var MinNumberOfWords = 150;
var LetterCountPerWord = 1;
var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
if($("#text_editor_textarea").length != 0){
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
$(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val();
var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
var str_arr = str.match(regex);
var str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
sceditor.keyUp(function(e) {
str = sceditor.val();
str_arr = str.match(regex);
str_len = str_arr == null ? 0 : str_arr.length;
if(str_len >= MinNumberOfWords) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl + "' />");
$("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
}else{
$("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
});
}
}
})});
Re: Word Counter in Certain Areas of Site
I'm afraid this isn't working on the quick reply at all.
Don't worry though, it's now working on the Full Editor, so I'll just get rid of the quick reply as the rest of the code is working great.
You can put this as resolved now
Don't worry though, it's now working on the Full Editor, so I'll just get rid of the quick reply as the rest of the code is working great.
You can put this as resolved now
Similar topics
» A word counter
» Editor Word Counter
» Word Counter in another language
» Help with word counter?
» Word Counter Issue
» Editor Word Counter
» Word Counter in another language
» Help with word counter?
» Word Counter Issue
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum