Page 1 of 11
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: 434
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
Great & Powerful
Posts: 1309
Reputation: 62
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>

trixie took over this account halp
khen
Posts: 434
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
Great & Powerful
Posts: 1309
Reputation: 62
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.
trixie took over this account halp
khen
Posts: 434
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 11
Search: