Word Counter in another language Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

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.
3 posters

    Word Counter in another language

    avatar
    DeadlyX
    Forumember


    Posts : 75
    Reputation : 4
    Language : English

    Solved Word Counter in another language

    Post by DeadlyX April 9th 2016, 3:54 pm

    I would like this word counter code, provided by ange tuteur, to work with cyrilic words too... is it possible, thanks?

    Code:
    $(function(){$(function(){
     
          var MinNumberOfWords = 5;
          var LetterCountPerWord = 3;
          var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
          var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
     
        if($("#text_editor_textarea").length != 0){
              $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");    
              $(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
            
              var sceditor = $("#text_editor_textarea").sceditor("instance");                
              var str = sceditor.val();
              var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
              var str_arr = str.match(regex);
              var str_len = str_arr == null ? 0 : str_arr.length;
            
              if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
            
              sceditor.keyUp(function(e) {
                str = sceditor.val();
                str_arr = str.match(regex);
                str_len = str_arr == null ? 0 : str_arr.length;
                if(str_len >= MinNumberOfWords) {
                    $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl  + "' />");
                $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
                }else{
                    $("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl  + "' />");
                    $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                }
              });
          }
        })});
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    Solved Re: Word Counter in another language

    Post by Van-Helsing April 10th 2016, 3:11 am

    Hello,
    You will need to modify your javascript's the character set to Cyrillic Language encoding:

    Try to replace your javascript with the following:

    Code:
    $(function(){$(function(){
                  var MinNumberOfWords = 5;
                  var LetterCountPerWord = 3;
                  var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
                  var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png";
                  if($("#text_editor_textarea").length != 0){
                      $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5"); 
                      $(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
                      var sceditor = $("#text_editor_textarea").sceditor("instance");             
                      var str = sceditor.val();
                      var regex = new RegExp('[a-z\u0400-\u04FF]{' + LetterCountPerWord + ',}[a-z\u0400-\u04FF]', 'g');
                      var str_arr = str.match(regex);
                      var str_len = str_arr == null ? 0 : str_arr.length;
                      if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
                        sceditor.keyUp(function(e) {
                        str = sceditor.val();
                        str_arr = str.match(regex);
                        str_len = str_arr == null ? 0 : str_arr.length;
                        if(str_len >= MinNumberOfWords) {
                            $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl  + "' />");
                        $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
                        }else{
                            $("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl  + "' />");
                            $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                        }
                      });
                  }
                })});
    avatar
    DeadlyX
    Forumember


    Posts : 75
    Reputation : 4
    Language : English

    Solved Re: Word Counter in another language

    Post by DeadlyX April 10th 2016, 12:25 pm

    Thanks bro! Worked like a charm Razz

    Solved!
    Van-Helsing
    Van-Helsing
    Hyperactive


    Male Posts : 2431
    Reputation : 116
    Language : English, Greek

    Solved Re: Word Counter in another language

    Post by Van-Helsing April 10th 2016, 12:28 pm

    You are welcome Smile
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Word Counter in another language

    Post by Ape April 10th 2016, 2:46 pm

    Word Counter in another language Ipost12
    Topic solved and archived



    Word Counter in another language Left1212Word Counter in another language Center11Word Counter in another language Right112
    Word Counter in another language Ape_b110
    Word Counter in another language Ape1010