about word counter
+2
Ange Tuteur
Ahmed.K
6 posters
Page 2 of 2
Page 2 of 2 • 1, 2
about word counter
First topic message reminder :
About this code:
https://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter#885030
the code works fine. but ...
It doesn't work when i copy/paste any text (of course more than 50 characters) without pressing any key on the keyboard.
After searching in Google, I tested this ...
sceditor.on('keyup change', function(e){
instead of
sceditor.keyUp(function(e) {
But it doesn't work too. Any ideas?
About this code:
https://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter#885030
- Code:
$(function(){$(function(){
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
var str_len = str.length;
if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
sceditor.keyUp(function(e) {
str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
str_len = str.length;
if(str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
});
}
})});
the code works fine. but ...
It doesn't work when i copy/paste any text (of course more than 50 characters) without pressing any key on the keyboard.
After searching in Google, I tested this ...
sceditor.on('keyup change', function(e){
instead of
sceditor.keyUp(function(e) {
But it doesn't work too. Any ideas?
Last edited by Ahmed.K on November 27th 2014, 6:50 pm; edited 1 time in total
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
I think this is going the be the closest I can get it.
- Code:
$(function(){$(function(){
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
var str_len = str.length;
if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() { getLen() });
$('.sceditor-container textarea').on('input', function() { getLen() });
sceditor.keyUp(function() { getLen() });
}
function getLen() {
str = sceditor.val().replace(/\n/g,' ').replace(/(\[quote=".*?"\]|\[quote\]).*?\[\/quote\]/gi,'').replace(/.*?(?=\[\/quote\])/gi,'').replace(/(:.*?:|\W)/gi,'');
str_len = str.length;
if(str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})});
Re: about word counter
This one doesn't work at all, even with the default multiquote mode (without any text).
Ahmed.K wrote:
Finally, Ange, the code now understand the multiquote system in the default mode (without any text) like this:
- Code:
[quote="Admin"][quote="User"][quote="User1"][/quote][/quote][/quote]
but still there one problem.
the code works well and doesn't count the text in the first quote, like this (text1):
- Code:
[quote="Admin"][quote="User"][quote="User1"] text1 [/quote][/quote][/quote]
but it count the text in the second and third quote, like this (text2 and text3):
- Code:
[quote="Admin"][quote="User"][quote="User1"] text1 [/quote] text2 [/quote] text3 [/quote]
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
@Ahmed.K
Hello!
This is only an issue of regex pattern where to eliminate all bbcode and html tags should be like this:
</?[a-z][a-z0-9]*[^\[\]]*>|\[/?[a-z][a-z0-9]*[^\[\]]*\]
Test with the code below:
See others patterns:
JS
Hello!
This is only an issue of regex pattern where to eliminate all bbcode and html tags should be like this:
</?[a-z][a-z0-9]*[^\[\]]*>|\[/?[a-z][a-z0-9]*[^\[\]]*\]
Test with the code below:
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
// var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi, '');
var str = $('.sceditor-container iframe').contents().find('body').text();
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/\n/g, '').replace(/<\/?[a-z][a-z0-9]*[^\[\]]*>|\[\/?[a-z][a-z0-9]*[^\[\]]*\]/gi, '');
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
See others patterns:
Delete repeated words:
Find any word that occurs twice or more in a row. Delete all occurrences except the first.
\b(\w+)(?:\s+\1\b)+
Duplicate lines:
This regex matches two or more lines, each identical to the first line.
^(.*)(\r?\n\1)+$
Delete blank lines:
Regex match includes line break after the line.
^[ \t]*$\r?\n
JS
Re: about word counter
Hello JScript. No, doesn't work, still the same problem...
the code doesn't understand the multiquote system.
It count the text in this quote, example (text1 - text2 - text3):
the code doesn't understand the multiquote system.
It count the text in this quote, example (text1 - text2 - text3):
- Code:
[quote="Admin"][quote="User"][quote="User1"] text1 [/quote] text2 [/quote] text3 [/quote]
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
@Ahmed.K
Hello, I'm sorry but I got it wrong!
So you do not really want to anything quote or multiquote be "captured" and interpreted as character, is it?
In this case I will change the regex, do some tests and then post the result here ok?
Edit:
Test this other code:
JS
Hello, I'm sorry but I got it wrong!
So you do not really want to anything quote or multiquote be "captured" and interpreted as character, is it?
In this case I will change the regex, do some tests and then post the result here ok?
Edit:
Test this other code:
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val().replace(/^[ \t]*$\r?\n|\[\/?[^.]*\]/gi, '');
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/^[ \t]*$\r?\n|\[\/?[^.]*\]/gi, '');
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
JS
Re: about word counter
Yes!JScript wrote:So you do not really want to anything quote or multiquote be "captured" and interpreted as character, is it?
Still doesn't work. here is an example, doesn't work with this quote, try it:
- Spoiler:
- Code:
Last edited by Ahmed.K on December 1st 2014, 4:02 pm; edited 1 time in total
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
Ok, try this other;
JS
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
str = sceditor.val().replace(/^[ \t]*$\r?\n|^[ \t]+|[ \t]+$|\b(\w+)(?:\s+\1\b)+|\[\/?[^*]*\]/img, "$1");
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/^[ \t]*$\r?\n|^[ \t]+|[ \t]+$|\b(\w+)(?:\s+\1\b)+|\[\/?[^*]*\]/img, "$1");
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
JS
Re: about word counter
Good work, JScript. It works good now with the multiquote system.
But there is one problem with your code (it was working fine with the Ange code)...
It counting spaces and these characters #, $ , . , ! , ...
I want just count Letters and numbers and in english not any language else.
But there is one problem with your code (it was working fine with the Ange code)...
It counting spaces and these characters #, $ , . , ! , ...
I want just count Letters and numbers and in english not any language else.
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
O...k...a...y..., no problem!!!
Try this other:
JS
Try this other:
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
str = sceditor.val().replace(/^[ \t]*$\r?\n|\[\/?[^*]*\]|\b(\w+)(?:\s+\1\b)+|(:.*?:|\W)/img, "$1");
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/^[ \t]*$\r?\n|\[\/?[^*]*\]|\b(\w+)(?:\s+\1\b)+|(:.*?:|\W)/img, "$1");
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
JS
Re: about word counter
It works great now!
Thanks JScript!
Thanks Ange!
Thanks JScript!
Thanks Ange!
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
Topic solved and archived
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: about word counter
There is still a problem with the code...
It doesn't count such post, don't know why.
It doesn't count such post, don't know why.
- Code:
[size=18][b][u]text[/u][/b][/size]
[img]http://img560.imageshack.us/img560/7411/togaii.png[/img]
[img]http://s26.postimg.org/hygj21xo5/Disaster_Area.png[/img]
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
@Ahmed.K
Okay, then let's continue!
I'll do some tests with a new regex and I post the result as soon as possible ok?
JS
Okay, then let's continue!
I'll do some tests with a new regex and I post the result as soon as possible ok?
JS
Re: about word counter
Ok. Waiting for the solution.
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
Try this:Ahmed.K wrote:Ok. Waiting for the solution.
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
str = sceditor.val().replace(/\[quote.*[^]+\[\/quote\]|(:.*?:|\W)/ig, "");
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/\[quote.*[^]+\[\/quote\]|(:.*?:|\W)/ig, "");
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
JS
Re: about word counter
There is a problem with another example...
When you write this:
It says "You've written 8 character(s).", I think it counting the "code" word.
code + code = 8 characters
When you write this:
- Code:
[code] . [/code]
It says "You've written 8 character(s).", I think it counting the "code" word.
code + code = 8 characters
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
@Ahmed.K
Wow, I'm sorry friend because I forgot to add the other regex!!!
Try this now:
See:
JS
Wow, I'm sorry friend because I forgot to add the other regex!!!
Try this now:
- Code:
$(function() {
$(function() {
var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
var sceditor = $("#text_editor_textarea").sceditor("instance");
str = sceditor.val().replace(/\[quote.*[^]+\[\/quote\]|\[\/?[a-z][a-z0-9]*[^\[\]]*\]|(:.*?:|\W)/ig, "");
var str_len = str.length;
if (str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
$('.sceditor-container iframe').contents().on('input', function() {
getLen()
});
$('.sceditor-container textarea').on('input', function() {
getLen()
});
sceditor.keyUp(function() {
getLen()
});
}
function getLen() {
str = sceditor.val().replace(/\[quote.*[^]+\[\/quote\]|\[\/?[a-z][a-z0-9]*[^\[\]]*\]|(:.*?:|\W)/ig, "");
str_len = str.length;
if (str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
$("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
}
}
})
});
See:
JS
Re: about word counter
JScript, is there detect for the live changes?
Because when MinNumberOfChars = 3;
And i write, for example "Hi JScript"... you can now send the message and the "Send" button is enabled, right? Ok. now when i add with this text a quote, like this:
Because when MinNumberOfChars = 3;
And i write, for example "Hi JScript"... you can now send the message and the "Send" button is enabled, right? Ok. now when i add with this text a quote, like this:
- Code:
[quote]Hi JScript[/quote]
Ahmed.K- Forumember
- Posts : 347
Reputation : 4
Language : English
Re: about word counter
I'm just facing a unique problem: Detect when you manually enter the same content as the quote tag.Ahmed.K wrote:Ok, JScript.
The code is still in testing ok?
JS
Page 2 of 2 • 1, 2
Similar topics
» Word Counter Box
» Help with word counter?
» A word counter
» Add a word counter to the editor
» something not right i just noticed about word counter
» Help with word counter?
» A word counter
» Add a word counter to the editor
» something not right i just noticed about word counter
Page 2 of 2
Permissions in this forum:
You cannot reply to topics in this forum