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.

Word Counter in Certain Areas of Site

2 posters

Go down

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

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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!
avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Word Counter in Certain Areas of Site

Post by SMOakey7 December 4th 2014, 11:15 am

avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

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...
avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

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
avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

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?
avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

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

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

https://fmdesign.forumotion.com

Back to top Go down

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
avatar
SMOakey7
New Member

Posts : 16
Reputation : 1
Language : English

http://hogwartsandbeyond.forumotion.co.uk/

Back to top Go down

Solved Re: Word Counter in Certain Areas of Site

Post by Ange Tuteur December 4th 2014, 6:04 pm

Okay, great. Smile

Topic archived
Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Back to top


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