Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Topic started by: The Domain Shop on October 25, 2010, 08:14:50 AM

Title: Looking for a mod
Post by: The Domain Shop on October 25, 2010, 08:14:50 AM
Hey guys im looking for a mod if one exists, that counts letters while writing topics so it would show under the post box saying something like 17524 letters remaining i believe the maximum letters per post is 20000. Hope you understand what i mean :)

PS:im using RC3 & simpleportal 2.3.2
Title: Re: Looking for a mod
Post by: gbsothere on October 25, 2010, 08:32:02 AM
Well, close, but no cigar....   searching under "character", "count" and "limit" all I could find is a word count, instead of a character count. 


http://custom.simplemachines.org/mods/index.php?mod=2117


You can set the minimum number of words (meaning the user can't just enter a blank post) and the maximum number of words (meaning they will get a "too many words" if they try to go over).  It might have worked for you, except that I don't see (just from the mod's page, I've not installed it) any sort of counter letting the poster know that he or she is approaching the limit.  (There might be; I just can't tell from the description.)  It would be nice if the poster knew, while typing the reply.

I've seen what you're talking about when filling out online forms, etc., and it's quite nice.  If there's not a mod here for that, it would be a great one to create, if someone is feeling ambitious.   :)
Title: Re: Looking for a mod
Post by: The Domain Shop on October 25, 2010, 08:41:03 AM
Cheers for the reply but a word count's not really what i need, i don't really see the point of it neither as words come in all different sizes only thing it could be used for is to set the minimum amount of words to be put in topics... To be honest im surprised a letter count mod don't already exist ???
Title: Re: Looking for a mod
Post by: gbsothere on October 25, 2010, 08:45:24 AM
Quote from: "Trax" on October 25, 2010, 08:41:03 AM
Cheers for the reply but a word count's not really what i need, i don't really see the point of it neither as words come in all different sizes only thing it could be used for is to set the minimum amount of words to be put in topics... To be honest im surprised a letter count mod don't already exist ???


There doesn't even appear to be an old version here that could be updated. It does seem odd, considering so many sites use this sort of feature.
Title: Re: Looking for a mod
Post by: Joker™ on October 25, 2010, 08:52:21 AM
I think you should see signature's in profile area. When a user start to type his/her content in signature box in profile he word count start to decrease (i think that's what you are after).

So you should take a look at the code in
themes\default\Profile.template.php
Here:
<textarea class="editor" onkeyup="calcCharLeft();" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br />';


Here

<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br />';


And to this script
// Some javascript used to count how many characters have been used so far in the signature.
echo '
<script type="text/javascript"><!-- // --><![CDATA[
function tick()
{
if (typeof(document.forms.creator) != "undefined")
{
calcCharLeft();
setTimeout("tick()", 1000);
}
else
setTimeout("tick()", 800);
}

function calcCharLeft()
{
var maxLength = ', $context['signature_limits']['max_length'], ';
var oldSignature = "", currentSignature = document.forms.creator.signature.value;

if (!document.getElementById("signatureLeft"))
return;

if (oldSignature != currentSignature)
{
oldSignature = currentSignature;

if (currentSignature.replace(/\r/, "").length > maxLength)
document.forms.creator.signature.value = currentSignature.replace(/\r/, "").substring(0, maxLength);
currentSignature = document.forms.creator.signature.value.replace(/\r/, "");
}

setInnerHTML(document.getElementById("signatureLeft"), maxLength - currentSignature.length);
}

addLoadEvent(tick);
// ]]></script>


Hope someone will help you out in this one ;).
Title: Re: Looking for a mod
Post by: The Domain Shop on October 25, 2010, 09:18:46 AM
Quote from: Joker™ on October 25, 2010, 08:52:21 AM
I think you should see signature's in profile area. When a user start to type his/her content in signature box in profile he word count start to decrease (i think that's what you are after).

So you should take a look at the code in
themes\default\Profile.template.php
Here:
<textarea class="editor" onkeyup="calcCharLeft();" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br />';


Here

<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br />';


And to this script
// Some javascript used to count how many characters have been used so far in the signature.
echo '
<script type="text/javascript"><!-- // --><![CDATA[
function tick()
{
if (typeof(document.forms.creator) != "undefined")
{
calcCharLeft();
setTimeout("tick()", 1000);
}
else
setTimeout("tick()", 800);
}

function calcCharLeft()
{
var maxLength = ', $context['signature_limits']['max_length'], ';
var oldSignature = "", currentSignature = document.forms.creator.signature.value;

if (!document.getElementById("signatureLeft"))
return;

if (oldSignature != currentSignature)
{
oldSignature = currentSignature;

if (currentSignature.replace(/\r/, "").length > maxLength)
document.forms.creator.signature.value = currentSignature.replace(/\r/, "").substring(0, maxLength);
currentSignature = document.forms.creator.signature.value.replace(/\r/, "");
}

setInnerHTML(document.getElementById("signatureLeft"), maxLength - currentSignature.length);
}

addLoadEvent(tick);
// ]]></script>


Hope someone will help you out in this one ;).

Yes that's exactly the sort of thing i'm after
Title: Re: Looking for a mod
Post by: Joker™ on November 15, 2010, 02:33:34 PM
I was working on this today and reached very near to the end result. There were just 2 major issues,

1. The count is not getting initiated properly.
2. Count doesn't work with WYSIWYG editor


This is the code reached so far (if anyone want to help me through testing it,make backup of your file)
So here we go,
themes\default\GenericControls.template.php

Find:
$editor_context = &$context['controls']['richedit'][$editor_id];


Add After:
echo'
<script type="text/javascript">
function CountLeft(content, count, max) {
if (content.value.length > max)
content.value = content.value.substring(0, max);
else
count.value = max - content.value.length;
}
</script>';



Find:
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="', $editor_context['rows'], '" cols=" ', $context['browser']['is_ie8'] ? '600' : $editor_context['columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], '; ', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '">', $editor_context['value'], '</textarea>


Replace it with:
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="', $editor_context['rows'], '" cols=" ', $context['browser']['is_ie8'] ? '600' : $editor_context['columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" onKeyDown="CountLeft(this.form.', $editor_id, ',this.form.left,20000);" onKeyUp="CountLeft(this.form.', $editor_id, ',this.form.left,20000);"tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], '; ', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '">', $editor_context['value'], '</textarea>



Find:
<input type="hidden" name="', $editor_id, '_mode" id="', $editor_id, '_mode" value="0" />


Add After:
<input type="text" name="left" size="6" value="',$modSettings['max_messageLength'],'">



Please post suggestion about this, that how can we remove those 2 bugs from this modification.