• Page 1 of 1
  • 1
Forum moderator: bigblog  
uCoz Community » For Webmasters » Custom Solutions » Help! I need Word Count Script for the File Catalog Entry/Ed
Help! I need Word Count Script for the File Catalog Entry/Ed
khen
Posts: 466
Reputation: 13

Message # 1 | 12:35 PM
I need a word count script.

I know bigblog knows some script for word count of the File Catalog Entry Adding/Editing page.

Word count changes on the fly as the user types words.

Please help me.

Post edited by khen - Wednesday, 2016-09-14, 12:36 PM
bigblog
Twink
Posts: 1537
Reputation: 72

Message # 2 | 7:25 PM
khen, insert the following code after the $BODY$ tag:
Code
<script type="text/javascript">
$(document).ready(function(){$("#edttmessage").after("<div class=\"wordCount\">The text has <b>0</b> words.</div>");});
$(function() {
    var count = {};
    $("#message").keyup(function() {
        var all = this.value.match(/\b/g);
        count[this.id] = all ? all.length / 2 : 0;
        var output = 0;
        $.each(count, function(k, v) {
            output += v;
        });
        $('.wordCount b').text(output)
    }).keyup();
});
</script>


Please, note that this code will only work with the HTML or BB Code editor of the entry full text. If you want it to work with the editor of the entry brief text, use the following code:
Code
<script type="text/javascript">
$(document).ready(function(){$("#edttbrief").after("<div class=\"wordCount\">The text has <b>0</b> words.</div>");});
$(function() {
    var count = {};
    $("#brief").keyup(function() {
        var all = this.value.match(/\b/g);
        count[this.id] = all ? all.length / 2 : 0;
        var output = 0;
        $.each(count, function(k, v) {
            output += v;
        });
        $('.wordCount b').text(output)
    }).keyup();
});
</script>


If you want to use it for both, this code will fit your needs:

Code
<script type="text/javascript">
$(document).ready(function(){$("#edttmessage").after("<div class=\"wordCount\">The text has <b>0</b> words.</div>");});
$(document).ready(function(){$("#edttbrief").after("<div class=\"wordCountBrief\">The text has <b>0</b> words.</div>");});
$(function() {
    var count = {};
    $("#message").keyup(function() {
        var all = this.value.match(/\b/g);
        count[this.id] = all ? all.length / 2 : 0;
        var output = 0;
        $.each(count, function(k, v) {
            output += v;
        });
        $('.wordCount b').text(output)
    }).keyup();
});
$(function() {
    var count = {};
    $("#brief").keyup(function() {
        var all = this.value.match(/\b/g);
        count[this.id] = all ? all.length / 2 : 0;
        var output = 0;
        $.each(count, function(k, v) {
            output += v;
        });
        $('.wordCountBrief b').text(output)
    }).keyup();
});
</script>

hey i'm joe and i'm a twink, please enjoy your stay

i do not work for the company anymore, sorry for the late replies
icon by Nathan Butler
khen
Posts: 466
Reputation: 13

Message # 3 | 1:20 AM
bigblog, thanks to you man. You're such a blessing. But is there a way to make it work using the Visual Editor? Because I'm using the Visual Editor.
bigblog
Twink
Posts: 1537
Reputation: 72

Message # 4 | 3:39 PM
khen, since the visual editor is loaded through an HTML frame, I'm afraid, it's not possible to retrieve any property of its content.
hey i'm joe and i'm a twink, please enjoy your stay

i do not work for the company anymore, sorry for the late replies
icon by Nathan Butler
khen
Posts: 466
Reputation: 13

Message # 5 | 3:13 AM
bigblog, ah. ok. I get it. Thanks to you bigblog. I really appreciate your help.
uCoz Community » For Webmasters » Custom Solutions » Help! I need Word Count Script for the File Catalog Entry/Ed
  • Page 1 of 1
  • 1
Search: