Editor Word Counter
2 posters
Page 1 of 1
Editor Word Counter
Greetings everyone,
I've applied the Word Counter as per this tutorial here on Forumotion: https://help.forumotion.com/t131191-add-a-word-counter-to-the-editor
It works great, however when you use the "Quote" button to post reply (on a given member's post), It also takes Into account the "Quoted text" (from the given member), hence the "minimum words to send" has already been exceeded (from the quoted text) without even posting anything.
Is there a way so the Word Counter does not take the quoted text Into account when quoting a post?
Thanks In advance for all help given.
I've applied the Word Counter as per this tutorial here on Forumotion: https://help.forumotion.com/t131191-add-a-word-counter-to-the-editor
It works great, however when you use the "Quote" button to post reply (on a given member's post), It also takes Into account the "Quoted text" (from the given member), hence the "minimum words to send" has already been exceeded (from the quoted text) without even posting anything.
Is there a way so the Word Counter does not take the quoted text Into account when quoting a post?
Thanks In advance for all help given.
Last edited by inallsorts on July 5th 2014, 10:11 am; edited 1 time in total (Reason for editing : Topic marked as solved.)
inallsorts- Forumember
- Posts : 246
Reputation : 8
Language : English
Re: Editor Word Counter
Hello inallsorts,
We can try to filter out the quotes with a regular expression. Give this a try :
We can try to filter out the quotes with a regular expression. Give this a try :
- Code:
$(function(){$(function(){
var MinNumberOfWords = 5;
var LetterCountPerWord = 3;
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().replace(/\n/g,' ').replace(/\[quote=".*?"\].*?\[\/quote\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[quote\]/gi,'').replace(/\[quote=".*?"\]/gi,'');
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: Editor Word Counter
Ange Tuteur wrote:Hello inallsorts,
We can try to filter out the quotes with a regular expression. Give this a try :
- Code:
$(function(){$(function(){
var MinNumberOfWords = 5;
var LetterCountPerWord = 3;
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().replace(/\n/g,' ').replace(/\[quote=".*?"\].*?\[\/quote\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[quote\]/gi,'').replace(/\[quote=".*?"\]/gi,'');
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");
}
});
}
})});\".*?"\\ wrote:
You're absolutely brilliant! What would this board do without you.
The code has worked nicely, thank you kindly once again.
/Topic.
inallsorts- Forumember
- Posts : 246
Reputation : 8
Language : English
Similar topics
» Add a word counter to the editor
» Problem in Add a word counter to the editor
» Help with word counter?
» Word Counter Issue
» Word Counter in another language
» Problem in Add a word counter to the editor
» Help with word counter?
» Word Counter Issue
» Word Counter in another language
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum