summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarven Capadisli <csarven@status.net>2009-12-10 14:16:07 +0100
committerSarven Capadisli <csarven@status.net>2009-12-10 14:16:07 +0100
commit1e166e1bc4a8b16ad2ef8e99db6a112f47803eda (patch)
tree0d06326eade1df6c48d78f5cad1659001e118f3e
parent155659dd1fee44c011962432a3e2ef6d523f1a7d (diff)
Updated FormNoticeEnhancements and Counter to use the max text value
from HTML. It also allows each .form_notice to have its own counter.
-rw-r--r--js/util.js38
-rw-r--r--lib/messageform.php2
-rw-r--r--lib/noticeform.php2
3 files changed, 22 insertions, 20 deletions
diff --git a/js/util.js b/js/util.js
index 67df73507..60865d352 100644
--- a/js/util.js
+++ b/js/util.js
@@ -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);
- }
- $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keydown', function(e) {
- SN.U.SubmitOnReturn(e, form);
- });
+ NDT.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()) {
diff --git a/lib/messageform.php b/lib/messageform.php
index 4df193c6d..0c568e1bd 100644
--- a/lib/messageform.php
+++ b/lib/messageform.php
@@ -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'));
diff --git a/lib/noticeform.php b/lib/noticeform.php
index 0dd3f2d77..593a1e932 100644
--- a/lib/noticeform.php
+++ b/lib/noticeform.php
@@ -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'));