The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Modify Minimum Word Counter (JavaScript)

View previous topic View next topic Go down

Solved Modify Minimum Word Counter (JavaScript)

Post by Knyfe on May 3rd 2014, 2:03 am

Hi,
I hate to trouble this forum with another technical difficulty, but I've never been good at JavaScript and would definitely appreciate it if someone could help me with this.
I don't know if it would be possible, but may I make this bit of code applicable to only one forum category? I am working on a roleplay forum, where the minimum is 400 words, but that's a bit ridiculous for free chat and other forums.
I am using a slightly modified version of this code.

I understand if this is not possible and will certainly be able to find an alternative, but I think this would be the easiest way, if someone is willing to devote their time to it.

Forum URL is http://thefireorigin.forumotion.com.


Last edited by Knyfe on May 6th 2014, 3:14 pm; edited 1 time in total

Knyfe
Forumember

Female Posts : 107
Reputation : 1
Language : English
Location : The driveway of justice

http://www.acloserlook.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Hagoromo Otsutsuki on May 3rd 2014, 3:16 am

Message Ange Tuteur :)best coder i know i am still a novice at it Sad

Hagoromo Otsutsuki
Forumember

Male Posts : 514
Reputation : 21
Language : English
Location : Heaven

http://naruto-omniverse.forumotion.com/

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by SLGray on May 3rd 2014, 5:25 am

@Hagoromo Otsutsuki wrote:Message Ange Tuteur :)best coder i know i am still a novice at it Sad
Please do not reply unless you are offering a solution. Also all support needs to be posted, not done through private messages.


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


SLGray
Administrator
Administrator

Male Posts : 35613
Reputation : 2372
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Michael_vx on May 3rd 2014, 6:55 am

hi there
this code should count 400 as minimum words on ech reply

Code:
   $(function(){$(function(){

       var MinNumberOfWords = 400;
       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");
             }
          });
       }
    })});
if you have problem with this code use my old topic and the one was solved
http://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter
have good time

Michael_vx
Forumember

Male Posts : 655
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Knyfe on May 4th 2014, 3:46 am

@Michael_vx wrote:hi there
this code should count 400 as minimum words on ech reply

Code:
   $(function(){$(function(){

       var MinNumberOfWords = 400;
       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");
             }
          });
       }
    })});
if you have problem with this code use my old topic and the one was solved
http://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter
have good time

Thank you for the help, but this is not quite what I am looking for. Smile I am all set on the minimum word count. My request is that a way be created, if it is possible, for the word minimum to only apply to one category of the board.

Knyfe
Forumember

Female Posts : 107
Reputation : 1
Language : English
Location : The driveway of justice

http://www.acloserlook.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Michael_vx on May 4th 2014, 6:29 am

@Knyfe wrote:

if you have problem with this code use my old topic and the one was solved
http://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter
have good time

Thank you for the help, but this is not quite what I am looking for. Smile I am all set on the minimum word count. My request is that a way be created, if it is possible, for the word minimum to only apply to one category of the board.
will i wonder if this could do it
Code:
<script type="text/javascript" src="http://micsoft.xp3.biz/wc.js"></script>
its a html code have the word counter above of my last reply all what i miss is how to find a place for the code to apperd only in the category you want
i wish Ange to be im sure he can do this
i know he can do any thing about codes
 

Michael_vx
Forumember

Male Posts : 655
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Knyfe on May 4th 2014, 8:46 pm

I tried placing that code in both the category and each individual forum, but it didn't work. Is there any other way it could work?

Knyfe
Forumember

Female Posts : 107
Reputation : 1
Language : English
Location : The driveway of justice

http://www.acloserlook.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Ange Tuteur on May 5th 2014, 9:16 am

Hello Knyfe,

This should be absolutely possible by checking the navigation path links.
I would just the need to following informations.


  • A link to the forum(s), or category(-y +ies) you want it applied to

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2681
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Knyfe on May 6th 2014, 1:39 am

I would love if it could be applied to c3. Smile Thank you so much.

Knyfe
Forumember

Female Posts : 107
Reputation : 1
Language : English
Location : The driveway of justice

http://www.acloserlook.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Ange Tuteur on May 6th 2014, 5:34 am

At the beginning of the script add this :
Code:
if ($('a.nav[href^="/c3-"]').length == 0) return;

It should look like :
Code:

   $(function(){$(function(){
       if ($('a.nav[href^="/c3-"]').length == 0) return;

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

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2681
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Knyfe on May 6th 2014, 3:13 pm

That works well. :DThank you!

Knyfe
Forumember

Female Posts : 107
Reputation : 1
Language : English
Location : The driveway of justice

http://www.acloserlook.forumotion.com

Back to top Go down

Solved Re: Modify Minimum Word Counter (JavaScript)

Post by Jophy on May 6th 2014, 4:19 pm

Solved

Jophy
ForumGuru

Male Posts : 17924
Reputation : 835
Language : English
Location : Somewhere

Back to top Go down

View previous topic View next topic Back to top


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