The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

about word counter

+2
Ange Tuteur
Ahmed.K
6 posters

Page 1 of 2 1, 2  Next

Go down

In progress about word counter

Post by Ahmed.K Thu 27 Nov - 5:23

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 Thu 27 Nov - 19:50; edited 1 time in total
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 5:52

Hello Ahmed,

Try replacing your script with this :
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|\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");
                    }
              }
            })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 6:46

It works now!
But can we count only the letters (english letters) and numbers? Not #, $ , . *,....
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 15:08

Try 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");           
                  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|\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");
                    }
              }
            })});

I added some characters to the filter.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 16:58

Doesn't work.
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 17:03

Oops, I made a mistake, try 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");         
                  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|\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");
                    }
              }
            })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 17:21

It works well, but what about the english letters?
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 17:32

They should be counted. Isn't that what you wanted ?
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 17:37

Yes, i mean only the english letters should be counted, not any language else.
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 18:29

Try this then :
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(/\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");
                    }
              }
            })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by SLGray Thu 27 Nov - 19:35

Please change the title of your topic to something that is related to your question/issue, so that other users will be able to find their question/issue using the search engine.



about word counter Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51554
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 19:55

This one works perfect, Ange.
But can you disable counting the emoticon?

Emoticon like this: :sm015: :sm01: :sm019: :sm09: :sm04: :sm05: :sm06:
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 20:00

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(/(:.*?:|\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");
                    }
              }
            })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Thu 27 Nov - 20:15

This one is solved too.
Last thing Smile Can you disable counting anything between this [quote ][/quote] too?
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by _Twisted_Mods_ Thu 27 Nov - 21:18

this should work

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\]|\[quote\].*?\[\/quote\]|\[.*?\]|\[\/.*?\]|:.*?:/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(/(:.*?:|\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");
                    }
              }
            })});
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Thu 27 Nov - 22:46

Not sure, but try this :
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(/(:.*?:|\[.*?\].*?\[\/.*?\]|\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");
                    }
              }
            })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Fri 28 Nov - 4:52

@_Twisted_Mods_, no, doesn't work.

@Ange, yes, it works good in the quickreply mode, when i copy/paste any quote [quote ][/quote].
But when i click on the quote button on any post and i go to the advanced mode, i find the Send button is enable. and i can send without writing anything. but when i start to write anything less than 50, i find that the Send button is disabled.
And doesn't work at all if the quote like this: [quote="Admin"]test [b]test[ /b] test [ /quote].
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Sat 29 Nov - 3:51

No solution to this problem?
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by ryanzkie Sat 29 Nov - 4:14

bwi bwi bwi bwi bwi bwi bwi bwi bwi
what a good day:
Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Hello Hello Hello Hello Hello Hello
avatar
ryanzkie
New Member

Posts : 1
Reputation : 1
Language : english

Back to top Go down

In progress Re: about word counter

Post by SLGray Sat 29 Nov - 4:31

ryanzkie wrote:bwi bwi bwi bwi bwi bwi bwi bwi bwi
what a good day:
Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Hello Hello Hello Hello Hello Hello
Please do not reply unless you are offering a solution.


about word counter Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51554
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Sat 29 Nov - 5:10

You can try this :
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(/(:.*?:|\W)/gi,'').replace(/\[.*?\].*?\[\/.*?\]/,'');
                   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");
                   }
             }
           })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Sat 29 Nov - 9:16

Still doesn't work. It is still counting everything between the quote.
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Sat 29 Nov - 11:15

Okay, give this a try :

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(/\[.*?\].*?\[\/.*?\]/g,'').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");
                  }
            }
          })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Sat 29 Nov - 12:38

No , still doesn't work if the quote like this: [quote="Admin"]test [b]test[ /b] test [ /quote].
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Sun 30 Nov - 2:23

Okay, see if this works for the quotes :
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(/(\[quote\]|\[quote=".*?"\]).*?\[\/quote\]/g,'').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");
                  }
            }
          })});

Also, your example has a space in the tag. If there's a space it wont format after posting or be replace by the regex.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Sun 30 Nov - 3:59

Yes, i know.... I did that to show the example here.

The last code doesn't work with multiquote. like this:
Code:
[quote="Admin"][quote="User"]text[/quote][/quote]
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Sun 30 Nov - 4:28

It seems to still work partially from what you've given.

I'm out of ideas for now, sorry.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Sun 30 Nov - 16:39

I think i found an old solution by you, and it works fine with the multiquote mode.
https://help.forumotion.com/t134045-editor-word-counter#902533

I think we can use this part in our code to solve the multiquote problem:
Code:
str = sceditor.val().replace(/\n/g,' ').replace(/\[quote=".*?"\].*?\[\/quote\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[quote\]/gi,'').replace(/\[quote=".*?"\]/gi,'');


But the only problem with this old solution, it counting the spaces in the quote.
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur Sun 30 Nov - 22:38

Okay, give this a try :
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\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[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");
                  }
            }
          })});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K Mon 1 Dec - 5:03


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]
avatar
Ahmed.K
Forumember

Posts : 347
Reputation : 4
Language : English

Back to top Go down

Page 1 of 2 1, 2  Next

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum