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 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 December 3rd 2014, 5:06 pm

    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 December 4th 2014, 10:54 am

    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 December 4th 2014, 11:15 am

    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 December 4th 2014, 11:15 am

    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 December 4th 2014, 11:32 am

    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 December 4th 2014, 11:36 am

    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 December 4th 2014, 12:04 pm

    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 December 4th 2014, 12:08 pm

    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 December 4th 2014, 12:08 pm

    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 December 4th 2014, 12:11 pm

    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 December 4th 2014, 12:17 pm

    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 December 4th 2014, 12:19 pm

    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 December 4th 2014, 1:11 pm

    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 December 4th 2014, 1:23 pm

    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 December 4th 2014, 6:04 pm

    Okay, great. Smile

    Topic archived

      Current date/time is November 11th 2024, 10:29 pm