• 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: 475
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
joexyz
JOE-vascript
Posts: 1770
Reputation: 78

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 do not work for the company anymore, please contact other staff or tech support
icon by ch-chau

sometimes i lurk here
khen
Posts: 475
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.
joexyz
JOE-vascript
Posts: 1770
Reputation: 78

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 do not work for the company anymore, please contact other staff or tech support
icon by ch-chau

sometimes i lurk here
khen
Posts: 475
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: