Updated FormNoticeEnhancements and Counter to use the max text value

from HTML. It also allows each .form_notice to have its own counter.
This commit is contained in:
Sarven Capadisli 2009-12-10 14:16:07 +01:00
parent 155659dd1f
commit 1e166e1bc4
3 changed files with 22 additions and 20 deletions

View File

@ -57,21 +57,28 @@ var SN = { // StatusNet
U: { // Utils
FormNoticeEnhancements: function(form) {
form_id = form.attr('id');
$('#'+form_id+' #'+SN.C.S.NoticeDataText).unbind('keyup');
$('#'+form_id+' #'+SN.C.S.NoticeDataText).unbind('keydown');
if (maxLength > 0) {
$('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keyup', function(e) {
if (jQuery.data(form[0], 'ElementData') === undefined) {
MaxLength = $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text();
if (typeof(MaxLength) == 'undefined') {
MaxLength = SN.C.I.MaxLength;
}
jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength});
SN.U.Counter(form);
NDT = $('#'+form_id+' #'+SN.C.S.NoticeDataText);
NDT.bind('keyup', function(e) {
SN.U.Counter(form);
});
// run once in case there's something in there
SN.U.Counter(form);
NDT.bind('keydown', function(e) {
SN.U.SubmitOnReturn(e, form);
});
}
$('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keydown', function(e) {
SN.U.SubmitOnReturn(e, form);
});
if($('body')[0].id != 'conversation') {
if ($('body')[0].id != 'conversation') {
$('#'+form_id+' textarea').focus();
}
},
@ -91,15 +98,14 @@ var SN = { // StatusNet
Counter: function(form) {
SN.C.I.FormNoticeCurrent = form;
form_id = form.attr('id');
if (typeof(maxLength) == "undefined") {
maxLength = SN.C.I.MaxLength;
}
if (maxLength <= 0) {
var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength;
if (MaxLength <= 0) {
return;
}
var remaining = maxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length;
var remaining = MaxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length;
var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount);
if (remaining.toString() != counter.text()) {

View File

@ -154,8 +154,6 @@ class MessageForm extends Form
$contentLimit = Message::maxContent();
$this->out->inlineScript('maxLength = ' . $contentLimit . ';');
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
$this->out->element('dt', null, _('Available characters'));

View File

@ -178,8 +178,6 @@ class NoticeForm extends Form
$contentLimit = Notice::maxContent();
$this->out->inlineScript('maxLength = ' . $contentLimit . ';');
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
$this->out->element('dt', null, _('Available characters'));