summaryrefslogtreecommitdiff
path: root/js
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 /js
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.
Diffstat (limited to 'js')
-rw-r--r--js/util.js38
1 files changed, 22 insertions, 16 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()) {