X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=1b855caaf2c9ffaa4327535c3eb5198f6db0f6c7;hb=728ead799273d5665e211899874576f05de23329;hp=4ba1bcfba5eb49e99b4397de0eb5816ee283122d;hpb=1ddf69f30ef576e3090d43be9e3aca9ee24f6119;p=quix0rs-gnu-social.git
diff --git a/js/util.js b/js/util.js
index 4ba1bcfba5..1b855caaf2 100644
--- a/js/util.js
+++ b/js/util.js
@@ -14,92 +14,60 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
+ *
+ * @category UI interaction
+ * @package StatusNet
+ * @author Sarven Capadisli
+ * @author Evan Prodromou
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
*/
$(document).ready(function(){
- var counterBlackout = false;
-
- // count character on keyup
- function counter(event){
- if (maxLength <= 0) {
- return;
- }
- var currentLength = $("#notice_data-text").val().length;
- var remaining = maxLength - currentLength;
- var counter = $("#notice_text-count");
-
- if (remaining.toString() != counter.text()) {
- if (!counterBlackout || remaining == 0) {
- if (counter.text() != String(remaining)) {
- counter.text(remaining);
- }
-
- if (remaining < 0) {
- $("#form_notice").addClass("warning");
- } else {
- $("#form_notice").removeClass("warning");
- }
- // Skip updates for the next 500ms.
- // On slower hardware, updating on every keypress is unpleasant.
- if (!counterBlackout) {
- counterBlackout = true;
- window.setTimeout(clearCounterBlackout, 500);
- }
- }
- }
- }
-
- function clearCounterBlackout() {
- // Allow keyup events to poke the counter again
- counterBlackout = false;
- // Check if the string changed since we last looked
- counter(null);
- }
-
-
-
- // define maxLength if it wasn't defined already
+ if ($('body.user_in').length > 0) {
+ if ($('#'+SN.C.S.NoticeDataText).length) {
+ if (maxLength > 0) {
+ $('#'+SN.C.S.NoticeDataText).bind('keyup', function(e) {
+ SN.U.Counter();
+ });
+ // run once in case there's something in there
+ SN.U.Counter();
+ }
- if (typeof(maxLength) == "undefined") {
- maxLength = 140;
- }
+ $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) {
+ SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice));
+ });
- if ($("#notice_data-text").length) {
- if (maxLength > 0) {
- $("#notice_data-text").bind("keyup", counter);
- // run once in case there's something in there
- counter();
- }
+ if($('body')[0].id != 'conversation') {
+ $('#'+SN.C.S.NoticeDataText).focus();
+ }
+ }
- $('#'+SN.C.S.NoticeDataText).bind('keydown', function(e) {
- SN.U.SubmitOnReturn(e, $('#'+SN.C.S.FormNotice));
- });
+ $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_favor').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_group_join').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); });
+ $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); });
- if($('body')[0].id != 'conversation') {
- $("#notice_data-text").focus();
- }
- }
+ SN.U.FormNoticeXHR();
- $('.form_user_subscribe').each(function() { SN.U.FormXHR($(this)); });
- $('.form_user_unsubscribe').each(function() { SN.U.FormXHR($(this)); });
- $('.form_favor').each(function() { SN.U.FormXHR($(this)); });
- $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); });
- $('.form_group_join').each(function() { SN.U.FormXHR($(this)); });
- $('.form_group_leave').each(function() { SN.U.FormXHR($(this)); });
- $('.form_user_nudge').each(function() { SN.U.FormXHR($(this)); });
+ SN.U.NoticeReply();
- SN.U.FormNoticeXHR();
+ SN.U.NoticeDataAttach();
+ }
- SN.U.NoticeReply();
SN.U.NoticeAttachments();
- SN.U.NoticeDataAttach();
});
var SN = { // StatusNet
C: { // Config
I: {
- NoticeTextCharMax: 140,
+ CounterBlackout: false,
+ MaxLength: 140,
PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]
},
@@ -116,7 +84,7 @@ var SN = { // StatusNet
NoticeInReplyTo: 'notice_in-reply-to',
NoticeDataAttach: 'notice_data-attach',
NoticeDataAttachSelected: 'notice_data-attach_selected',
- NoticeActionSubmit: 'notice_action-submit'
+ NoticeActionSubmit: 'notice_action-submit',
}
},
@@ -133,6 +101,45 @@ var SN = { // StatusNet
return true;
},
+ Counter: function() {
+ if (typeof(maxLength) == "undefined") {
+ maxLength = SN.C.I.MaxLength;
+ }
+
+ if (maxLength <= 0) {
+ return;
+ }
+
+ var remaining = maxLength - $('#'+SN.C.S.NoticeDataText).val().length;
+ var counter = $('#'+SN.C.S.NoticeTextCount);
+
+ if (remaining.toString() != counter.text()) {
+ if (!SN.C.I.CounterBlackout || remaining == 0) {
+ if (counter.text() != String(remaining)) {
+ counter.text(remaining);
+ }
+ if (remaining < 0) {
+ $('#'+SN.C.S.FormNotice).addClass(SN.C.S.Warning);
+ } else {
+ $('#'+SN.C.S.FormNotice).removeClass(SN.C.S.Warning);
+ }
+ // Skip updates for the next 500ms.
+ // On slower hardware, updating on every keypress is unpleasant.
+ if (!SN.C.I.CounterBlackout) {
+ SN.C.I.CounterBlackout = true;
+ window.setTimeout(SN.U.ClearCounterBlackout, 500);
+ }
+ }
+ }
+ },
+
+ ClearCounterBlackout: function() {
+ // Allow keyup events to poke the counter again
+ SN.C.I.CounterBlackout = false;
+ // Check if the string changed since we last looked
+ SN.U.Counter(null);
+ },
+
FormXHR: function(f) {
f.bind('submit', function(e) {
form_id = $(this)[0].id;
@@ -194,7 +201,7 @@ var SN = { // StatusNet
}
else {
SN.C.I.NoticeDataText.val('');
-// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax);
+ SN.U.Counter();
}
}
}
@@ -235,7 +242,7 @@ var SN = { // StatusNet
$('#'+SN.C.S.NoticeDataText).val('');
$('#'+SN.C.S.NoticeDataAttach).val('');
$('#'+SN.C.S.NoticeInReplyTo).val('');
-// SN.U.NoticeTextCounter($('#'+SN.C.S.NoticeDataText), $('#'+SN.C.S.NoticeTextCount), SN.C.I.NoticeTextCharMax);
+ SN.U.Counter();
}
},
complete: function(xhr, textStatus) {