counter - Word Counter in Certain Areas of Site 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.
2 posters

    Word Counter in Certain Areas of Site

    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Word Counter in Certain Areas of Site

    Post by SMOakey7 Wed 3 Dec - 16:06

    Hi there,


    I've been looking at putting a word counter in certain areas of my site. It is only in the categories that I wish to apply the code, and I have five of these. How do I add this in to my JavaScript to make it work?


    Everything else in my forum is just a forum, so there are no other categories on the site except those I need to have my 150 word count.

    Also, how do I stop the word counter from picking up the coding in brackets as words?


    Hope this makes sense!
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 9:54

    Code:
    $(function(){$(function(){
    Code:
           var MinNumberOfWords = 150;
           var LetterCountPerWord = 1;
           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");
                 }
              });
           }
        })});

    This is the code I'm using and I want it to apply to Category 4, 5, 6, 7 and 9

    Any help would be appreciated!
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 10:15

    Hello SMOakey7,

    Could you provide a link to your forum ?

    Thanks
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 10:15

    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 10:32

    Try this :
    Code:
    $(function(){$(function() {
      if (c(4) || c(5) || c(6) || c(7) || c(9)) {
           var MinNumberOfWords = 150;
           var LetterCountPerWord = 1;
           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");
                 }
              });
           }
      }
      function c(n) { return n == Number($('.nav a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1')) }
    })});
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 10:36

    This has gotten rid of the word counter completely...
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 11:04

    Okay, see if this works :
    Code:
    $(function(){$(function() {
       if (!$('.nav a:eq(1), .pathname-box a:eq(1)').length) return;
       var c = Number($('.nav a:eq(1), .pathname-box a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1'));
      
      if (c == 4 || c == 5 || c == 6 || c == 7 || c == 9) {
           var MinNumberOfWords = 150;
           var LetterCountPerWord = 1;
           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");
                 }
              });
           }
      }
    })});
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 11:08

    I'm afraid it's still not working Sad I've tried it on All of the pages, and then with none ticked and it doesn't work
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 11:08

    What are the links of the areas you want to add this in ?
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 11:11

    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 11:17

    Are you using the quick reply or full editor ?
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 11:19

    Using both of them, last night the word counter was working in both, but it was showing in all areas, I only need it in the links above, if possible?
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 12:11

    Okay, check if this works for the quick reply :
    Code:
    $(function(){$(function() {
      var c = Number($('.nav a:eq(1)').attr('href').replace(/\/c(\d+)-.*/,'$1'));
     
      if (c == 4 || c == 5 || c == 6 || c == 7 || c == 9) {
          var MinNumberOfWords = 150;
          var LetterCountPerWord = 1;
          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");
                }
              });
          }
      }
    })});
    avatar
    SMOakey7
    New Member


    Posts : 16
    Reputation : 1
    Language : English

    Solved Re: Word Counter in Certain Areas of Site

    Post by SMOakey7 Thu 4 Dec - 12:23

    I'm afraid this isn't working on the quick reply at all.

    Don't worry though, it's now working on the Full Editor, so I'll just get rid of the quick reply as the rest of the code is working great.

    You can put this as resolved now Smile
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Word Counter in Certain Areas of Site

    Post by Ange Tuteur Thu 4 Dec - 17:04

    Okay, great. Smile

    Topic archived