Display a real-time indication of your mChat message limit and how many characters you have remaining. You will be prevented from entering any more characters once you reach zero.
Requirements: jQuery maxlength plugin - see attachment (and installed and working mChat)


Open: mchat.php
Code: Select all
'MCHAT_MESSAGE_LNGTH' => $config_mchat['max_message_lngth'],
Code: Select all
'L_MCHAT_MESSAGE_LNGTH_EXPLAIN' => (intval($config_mchat['max_message_lngth'])) ? sprintf($user->lang['MCHAT_MESSAGE_LNGTH_EXPLAIN'], intval($config_mchat['max_message_lngth'])) : '',
Code: Select all
'MCHAT_MESS_LONG' => 'Your message is too long.\nPlease limit it to %s characters',
Code: Select all
'MCHAT_MESSAGE_LNGTH_EXPLAIN' => 'Characters remaining: <span class="charsLeft error"><strong>%d</strong></span>',
Code: Select all
<!-- IF S_MCHAT_ENABLE and (S_MCHAT_ON_INDEX or U_MCHAT) -->
Code: Select all
<script type="text/javascript" src="{ROOT_PATH}mchat/jquery_cookie_mini.js"></script>
Code: Select all
<script type="text/javascript" src="{ROOT_PATH}mchat/jquery.maxlength.min.js"></script>
Code: Select all
<input type="text" name="message" class="inputbox medium mChatText" id="mChatMessage" /><br />
Code: Select all
class="inputbox medium mChatText
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 --> limited<!-- ENDIF -->
Code: Select all
id="mChatMessage"
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 --> maxlength="{MCHAT_MESSAGE_LNGTH}"<!-- ENDIF -->
Code: Select all
<input id="submit_button" type="button" class="button2" onclick="mChat.add();" value="{L_MCHAT_ADD}" />
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 --><p>{L_MCHAT_MESSAGE_LNGTH_EXPLAIN} </p><!-- ENDIF -->
Code: Select all
<!-- IF MCHAT_ALLOW_SMILES and .smiley -->
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 -->
<script type="text/javascript">
// <![CDATA[
$('input.limited').maxlength({
'feedback' : '.charsLeft',
'useInput' : false
});
// ]]>
</script>
<!-- ENDIF -->
Upload jquery.maxlength.min.js to mchat/ folder.
Refresh templates and clear board cache.
Done!
Notes:
In case you are using the textarea mChat modification, you need to figure out the exact edits yourself, basically the following changes are required:
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 -->
<input type="hidden" name="maxlength" value="{MCHAT_MESSAGE_LNGTH}" />
<script type="text/javascript">
// <![CDATA[
$('textarea.limited').maxlength({
'feedback' : '.charsLeft',
'useInput' : true
});
// ]]>
</script>
<!-- ENDIF -->
plus you DO NOT need to add the following to the message textarea:
Code: Select all
<!-- IF MCHAT_MESSAGE_LNGTH neq 0 --> maxlength="{MCHAT_MESSAGE_LNGTH}"<!-- ENDIF -->