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.
The forum of the forums
+2
Ange Tuteur
Ahmed.K
6 posters

    about word counter

    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress about word counter

    Post by Ahmed.K November 27th 2014, 4:23 am

    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
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 4:52 am

    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");
                        }
                  }
                })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 5:46 am

    It works now!
    But can we count only the letters (english letters) and numbers? Not #, $ , . *,....
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 2:08 pm

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


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 3:58 pm

    Doesn't work.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 4:03 pm

    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");
                        }
                  }
                })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 4:21 pm

    It works well, but what about the english letters?
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 4:32 pm

    They should be counted. Isn't that what you wanted ?
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 4:37 pm

    Yes, i mean only the english letters should be counted, not any language else.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 5:29 pm

    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");
                        }
                  }
                })});
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51498
    Reputation : 3523
    Language : English
    Location : United States

    In progress Re: about word counter

    Post by SLGray November 27th 2014, 6:35 pm

    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.




    counter - about word counter Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 6:55 pm

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

    Emoticon like this: :sm015: :sm01: :sm019: :sm09: :sm04: :sm05: :sm06:
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 7:00 pm

    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");
                        }
                  }
                })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 27th 2014, 7:15 pm

    This one is solved too.
    Last thing Smile Can you disable counting anything between this [quote ][/quote] too?
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


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

    In progress Re: about word counter

    Post by _Twisted_Mods_ November 27th 2014, 8:18 pm

    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");
                        }
                  }
                })});
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 27th 2014, 9:46 pm

    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");
                        }
                  }
                })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 28th 2014, 3:52 am

    @_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

    In progress Re: about word counter

    Post by Ahmed.K November 29th 2014, 2:51 am

    No solution to this problem?
    avatar
    ryanzkie
    New Member


    Posts : 1
    Reputation : 1
    Language : english

    In progress Re: about word counter

    Post by ryanzkie November 29th 2014, 3:14 am

    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
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51498
    Reputation : 3523
    Language : English
    Location : United States

    In progress Re: about word counter

    Post by SLGray November 29th 2014, 3:31 am

    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.



    counter - about word counter Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 29th 2014, 4:10 am

    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");
                       }
                 }
               })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 29th 2014, 8:16 am

    Still doesn't work. It is still counting everything between the quote.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 29th 2014, 10:15 am

    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");
                      }
                }
              })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 29th 2014, 11:38 am

    No , still doesn't work if the quote like this: [quote="Admin"]test [b]test[ /b] test [ /quote].
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 30th 2014, 1:23 am

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


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 30th 2014, 2:59 am

    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]
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 30th 2014, 3:28 am

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

    I'm out of ideas for now, sorry.
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K November 30th 2014, 3:39 pm

    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.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    In progress Re: about word counter

    Post by Ange Tuteur November 30th 2014, 9:38 pm

    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");
                      }
                }
              })});
    avatar
    Ahmed.K
    Forumember


    Posts : 347
    Reputation : 4
    Language : English

    In progress Re: about word counter

    Post by Ahmed.K December 1st 2014, 4:03 am


    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]

      Current date/time is September 23rd 2024, 5:18 am