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.

about word counter

Page 1 of 2 1, 2  Next

View previous topic View next topic Go down

In progress about word counter

Post by Ahmed.K on November 27th 2014, 4:23 am

About this code:
http://help.forumotion.com/t131882-just-one-last-change-at-the-word-counter#885030

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

  var MinNumberOfChars = 50;
  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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
 
  var sceditor = $("#text_editor_textarea").sceditor("instance");
  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
  var str_len = str.length;
 
  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
 
  sceditor.keyUp(function(e) {
  str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
  str_len = str.length;
  if(str_len >= MinNumberOfChars) {
  $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl + "' />");
  $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
  }
  });
  }
  })});

the code works fine. but ...
It doesn't work when i copy/paste any text (of course more than 50 characters) without pressing any key on the keyboard.

After searching in Google, I tested this ...
sceditor.on('keyup change', function(e){
instead of
sceditor.keyUp(function(e) {

But it doesn't work too. Any ideas?


Last edited by Ahmed.K on November 27th 2014, 6:50 pm; edited 1 time in total

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 4:52 am

Hello Ahmed,

Try replacing your script with this :
Code:
  $(function(){$(function(){

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
               
                  var sceditor = $("#text_editor_textarea").sceditor("instance");             
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
               
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
               
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                    str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 5:46 am

It works now!
But can we countonly the letters (english letters) and numbers? Not #, $ , . *,....

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 2:08 pm

Try now :
Code:
  $(function(){$(function(){

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
             
                  var sceditor = $("#text_editor_textarea").sceditor("instance");           
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
             
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
             
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                    str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:|[!@#$%\^&\*\(\)\[\]`~;:'"<,>\.\?\/_-=+]+/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl  + "' />");
                        $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                    }
              }
            })});

I added some characters to the filter.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 3:58 pm

Doesn't work.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 4:03 pm

Oops, I made a mistake, try now :
Code:
  $(function(){$(function(){

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
           
                  var sceditor = $("#text_editor_textarea").sceditor("instance");         
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
           
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
           
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                    str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:|[!@#$%\^&\*\(\)\[\]`~;:'"<,>\.\?\/\_\-\=\+]+/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 4:21 pm

It works well, but what about the english letters?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 4:32 pm

They should be counted. Isn't that what you wanted ?

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 4:37 pm

Yes, i mean only the english letters should be counted, not any language else.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 5:29 pm

Try this then :
Code:
  $(function(){$(function(){

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
         
                  var sceditor = $("#text_editor_textarea").sceditor("instance");       
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
         
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
         
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                    str = sceditor.val().replace(/\W/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by SLGray on November 27th 2014, 6:35 pm

Please change the title of your topic to something that is related to your question/issue, so that other users will be able to find their question/issue using the search engine.



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


SLGray
Administrator
Administrator

Male Posts : 36639
Reputation : 2441
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 6:55 pm

This one works perfect, Ange.
But can you disable counting the emoticon?

Emoticon like this: :sm015: :sm01: :sm019: :sm09: :sm04: :sm05: :sm06:

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 7:00 pm

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

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
       
                  var sceditor = $("#text_editor_textarea").sceditor("instance");     
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
       
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
       
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                str = sceditor.val().replace(/(:.*?:|\W)/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 27th 2014, 7:15 pm

This one is solved too.
Last thing Smile Can you disable counting anything between this [quote ][/quote] too?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by _Twisted_Mods_ on November 27th 2014, 8:18 pm

this should work

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

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
     
                  var sceditor = $("#text_editor_textarea").sceditor("instance");   
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[quote\].*?\[\/quote\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
     
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
     
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                str = sceditor.val().replace(/(:.*?:|\W)/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl  + "' />");
                        $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                    }
              }
            })});

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 27th 2014, 9:46 pm

Not sure, but try this :
Code:
  $(function(){$(function(){

              var MinNumberOfChars = 50;
              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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
     
                  var sceditor = $("#text_editor_textarea").sceditor("instance");   
                  var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                  var str_len = str.length;
     
                  if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
     
                  $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                  $('.sceditor-container textarea').on('input', function() { getLen() });
                  sceditor.keyUp(function() { getLen() });
              }
              function getLen() {
                str = sceditor.val().replace(/(:.*?:|\[.*?\].*?\[\/.*?\]|\W)/gi,'');
                    str_len = str.length;
                    if(str_len >= MinNumberOfChars) {
                        $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 28th 2014, 3:52 am

@_Twisted_Mods_, no, doesn't work.

@Ange, yes, it works good in the quickreply mode, when i copy/paste any quote [quote ][/quote].
But when i click on the quote button on any post and i go to the advanced mode, i find the Send button is enable. and i can send without writing anything. but when i start to write anything less than 50, i find that the Send button is disabled.
And doesn't work at all if the quote like this: [quote="Admin"]test [b]test[ /b] test [ /quote].

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 29th 2014, 2:51 am

No solution to this problem?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by ryanzkie on November 29th 2014, 3:14 am

bwi bwi bwi bwi bwi bwi bwi bwi bwi
what a good day:
Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Hello Hello Hello Hello Hello Hello

ryanzkie
New Member

Posts : 1
Reputation : 1
Language : english

Back to top Go down

In progress Re: about word counter

Post by SLGray on November 29th 2014, 3:31 am

@ryanzkie wrote:bwi bwi bwi bwi bwi bwi bwi bwi bwi
what a good day:
Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Hello Hello Hello Hello Hello Hello
Please do not reply unless you are offering a solution.


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


SLGray
Administrator
Administrator

Male Posts : 36639
Reputation : 2441
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 29th 2014, 4:10 am

You can try this :
Code:
 $(function(){$(function(){

var MinNumberOfChars = 50;
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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");

var sceditor = $("#text_editor_textarea").sceditor("instance");
var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
var str_len = str.length;

if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");

$('.sceditor-container iframe').contents().on('input', function() { getLen() });
$('.sceditor-container textarea').on('input', function() { getLen() });
sceditor.keyUp(function() { getLen() });
}
function getLen() {
str = sceditor.val().replace(/(:.*?:|\W)/gi,'').replace(/\[.*?\].*?\[\/.*?\]/,'');
str_len = str.length;
if(str_len >= MinNumberOfChars) {
$("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 29th 2014, 8:16 am

Still doesn't work. It is still counting everything between the quote.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 29th 2014, 10:15 am

Okay, give this a try :

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

            var MinNumberOfChars = 50;
            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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
 
                var sceditor = $("#text_editor_textarea").sceditor("instance"); 
                var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                var str_len = str.length;
 
                if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
 
                $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                $('.sceditor-container textarea').on('input', function() { getLen() });
                sceditor.keyUp(function() { getLen() });
            }
            function getLen() {
              str = sceditor.val().replace(/\[.*?\].*?\[\/.*?\]/g,'').replace(/(:.*?:|\W)/gi,'');
                  str_len = str.length;
                  if(str_len >= MinNumberOfChars) {
                      $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 29th 2014, 11:38 am

No , still doesn't work if the quote like this: [quote="Admin"]test [b]test[ /b] test [ /quote].

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 30th 2014, 1:23 am

Okay, see if this works for the quotes :
Code:
  $(function(){$(function(){

            var MinNumberOfChars = 50;
            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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
 
                var sceditor = $("#text_editor_textarea").sceditor("instance");
                var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                var str_len = str.length;
 
                if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
 
                $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                $('.sceditor-container textarea').on('input', function() { getLen() });
                sceditor.keyUp(function() { getLen() });
            }
            function getLen() {
              str = sceditor.val().replace(/(\[quote\]|\[quote=".*?"\]).*?\[\/quote\]/g,'').replace(/(:.*?:|\W)/gi,'');
                  str_len = str.length;
                  if(str_len >= MinNumberOfChars) {
                      $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(s) to send this message <img src='" + ico_incompl  + "' />");
                      $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
                  }
            }
          })});

Also, your example has a space in the tag. If there's a space it wont format after posting or be replace by the regex.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 30th 2014, 2:59 am

Yes, i know....I did that to show the example here.

The last code doesn't work with multiquote. like this:
Code:
[quote="Admin"][quote="User"]text[/quote][/quote]

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 30th 2014, 3:28 am

It seems to still work partially from what you've given.

I'm out of ideas for now, sorry.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on November 30th 2014, 3:39 pm

I think i found an oldsolution by you, and it works fine with the multiquote mode.
http://help.forumotion.com/t134045-editor-word-counter#902533

I think we can use this part in our code to solve the multiquote problem:
Code:
str = sceditor.val().replace(/\n/g,' ').replace(/\[quote=".*?"\].*?\[\/quote\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[quote\]/gi,'').replace(/\[quote=".*?"\]/gi,'');


But the only problem with this old solution, it counting the spaces in the quote.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: about word counter

Post by Ange Tuteur on November 30th 2014, 9:38 pm

Okay, give this a try :
Code:
  $(function(){$(function(){

            var MinNumberOfChars = 50;
            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 characters to send a message: " + MinNumberOfChars + " </div><div id='div_minchars_info'></div></div>");
 
                var sceditor = $("#text_editor_textarea").sceditor("instance");
                var str = sceditor.val().replace(/ |\n|\s+|\[img\].*?\[\/img\]|\[.*?\]|\[\/.*?\]|:.*?:/gi,'');
                var str_len = str.length;
 
                if(str_len >= MinNumberOfChars) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
 
                $('.sceditor-container iframe').contents().on('input', function() { getLen() });
                $('.sceditor-container textarea').on('input', function() { getLen() });
                sceditor.keyUp(function() { getLen() });
            }
            function getLen() {
              str = sceditor.val().replace(/\n/g,' ').replace(/\[quote=".*?"\].*?\[\/quote\]/gi,'').replace(/\[quote\].*?\[\/quote\]/gi,'').replace(/\[\/quote\]/gi,'').replace(/\[quote\]/gi,'').replace(/\[quote=".*?"\]/gi,'').replace(/(:.*?:|\W)/gi,'');
                  str_len = str.length;
                  if(str_len >= MinNumberOfChars) {
                      $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> character(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> character(s). You need " + (MinNumberOfChars - str_len) + " character(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 : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: about word counter

Post by Ahmed.K on December 1st 2014, 4:03 am


Finally, Ange, the code now understand the multiquote system in the default mode (without any text) like this:
Code:
[quote="Admin"][quote="User"][quote="User1"][/quote][/quote][/quote]

but still there one problem.
the code works well and doesn't count the text in the first quote, like this (text1):

Code:
[quote="Admin"][quote="User"][quote="User1"] text1 [/quote][/quote][/quote]


but it count the text in the second and third quote, like this (text2 and text3):

Code:
[quote="Admin"][quote="User"][quote="User1"] text1 [/quote] text2 [/quote] text3 [/quote]

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Page 1 of 2 1, 2  Next

View previous topic View next topic Back to top


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