]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Updated FormNoticeEnhancements and Counter to use the max text value
authorSarven Capadisli <csarven@status.net>
Thu, 10 Dec 2009 13:16:07 +0000 (14:16 +0100)
committerSarven Capadisli <csarven@status.net>
Thu, 10 Dec 2009 13:16:07 +0000 (14:16 +0100)
from HTML. It also allows each .form_notice to have its own counter.

js/util.js
lib/messageform.php
lib/noticeform.php

index 67df73507bc8f0f2e9e050be1410753d44bf7a5d..60865d35200e8cf2b8855e99bb341d240d1a7b22 100644 (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);
-            }
 
-            $('#'+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()) {
index 4df193c6d1bf94a58cc154995dbd71e2559466e7..0c568e1bd8e12983f94904e2b9d8408926585359 100644 (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'));
index 0dd3f2d7772d192d5d88477972200d43c49a77e5..593a1e93220a1f6a5e1b9fd41dc5905227314e79 100644 (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'));