X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=b645e8b0298aa1dc0d5e218acac82f979f02aa6e;hb=ec98fd0c438f5b8f8e5eeee893ad84f121b7249f;hp=85f917b09aeb67f107f20814c0f71166c2396342;hpb=be15ab47dca8b65acd8a313692ad607f0aeb34aa;p=quix0rs-gnu-social.git
diff --git a/js/util.js b/js/util.js
index 85f917b09a..b645e8b029 100644
--- a/js/util.js
+++ b/js/util.js
@@ -53,10 +53,20 @@ var SN = { // StatusNet
NoticeDataGeo: 'notice_data-geo',
NoticeDataGeoCookie: 'NoticeDataGeo',
NoticeDataGeoSelected: 'notice_data-geo_selected',
- StatusNetInstance: 'StatusNetInstance'
}
},
+ V: { // Variables
+ // These get set on runtime via inline scripting, so don't put anything here.
+ },
+
+ /**
+ * list of callbacks, categorized into _callbacks['event_name'] = [ callback_function_1, callback_function_2 ]
+ *
+ * @access private
+ */
+ _callbacks: {},
+
/**
* Map of localized message strings exported to script from the PHP
* side via Action::getScriptMessages().
@@ -216,6 +226,27 @@ var SN = { // StatusNet
return url;
},
+ FormNoticeUniqueID: function (form) {
+ var oldId = form.attr('id');
+ var newId = 'form_notice_' + Math.floor(Math.random()*999999999);
+ var attrs = ['name', 'for', 'id'];
+ for (var key in attrs) {
+ if (form.attr(attrs[key]) === undefined) {
+ continue;
+ }
+ form.attr(attrs[key], form.attr(attrs[key]).replace(oldId, newId));
+ }
+ for (var key in attrs) {
+ form.find("[" + attrs[key] + "*='" + oldId + "']").each(function () {
+ if ($(this).attr(attrs[key]) === undefined) {
+ return; // since we're inside the each(function () { ... });
+ }
+ var newAttr = $(this).attr(attrs[key]).replace(oldId, newId);
+ $(this).attr(attrs[key], newAttr);
+ });
+ }
+ },
+
/**
* Grabs form data and submits it asynchronously, with 'ajax=1'
* parameter added to the rest.
@@ -319,21 +350,6 @@ var SN = { // StatusNet
// Make sure we don't have a mixed HTTP/HTTPS submission...
form.attr('action', SN.U.RewriteAjaxAction(form.attr('action')));
- /**
- * Show a response feedback bit under the new-notice dialog.
- *
- * @param {String} cls: CSS class name to use ('error' or 'success')
- * @param {String} text
- * @access private
- */
- var showFeedback = function (cls, text) {
- form.append(
- $('
')
- .addClass(cls)
- .text(text)
- );
- };
-
/**
* Hide the previous response feedback, if any.
*/
@@ -343,7 +359,7 @@ var SN = { // StatusNet
form.ajaxForm({
dataType: 'xml',
- timeout: '60000',
+ timeout: SN.V.xhrTimeout,
beforeSend: function (formData) {
if (form.find('.notice_data-text:first').val() == '') {
form.addClass(SN.C.S.Warning);
@@ -368,7 +384,7 @@ var SN = { // StatusNet
removeFeedback();
if (textStatus == 'timeout') {
// @fixme i18n
- showFeedback('error', 'Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.');
+ SN.U.showFeedback(form, 'error', 'Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.');
} else {
var response = SN.U.GetResponseXML(xhr);
if ($('.' + SN.C.S.Error, response).length > 0) {
@@ -381,7 +397,7 @@ var SN = { // StatusNet
SN.U.FormNoticeEnhancements(form);
} else {
// @fixme i18n
- showFeedback('error', '(Sorry! We had trouble sending your notice (' + xhr.status + ' ' + xhr.statusText + '). Please report the problem to the site administrator if this happens again.');
+ SN.U.showFeedback(form, 'error', '(Sorry! We had trouble sending your notice (' + xhr.status + ' ' + xhr.statusText + '). Please report the problem to the site administrator if this happens again.');
}
}
}
@@ -390,59 +406,9 @@ var SN = { // StatusNet
removeFeedback();
var errorResult = $('#' + SN.C.S.Error, data);
if (errorResult.length > 0) {
- showFeedback('error', errorResult.text());
+ SN.U.showFeedback(form, 'error', errorResult.text());
} else {
- var commandResult = $('#' + SN.C.S.CommandResult, data);
- if (commandResult.length > 0) {
- showFeedback('success', commandResult.text());
- } else {
- // New notice post was successful. If on our timeline, show it!
- var notice = document._importNode($('li', data)[0], true);
- var notices = $('#notices_primary .notices:first');
- var replyItem = form.closest('li.notice-reply');
-
- if (replyItem.length > 0) {
- // If this is an inline reply, remove the form...
- var list = form.closest('.threaded-replies');
-
- var id = $(notice).attr('id');
- if ($('#' + id).length == 0) {
- $(notice).insertBefore(replyItem);
- } // else Realtime came through before us...
-
- replyItem.remove();
-
- } else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
- // Not a reply. If on our timeline, show it at the top!
-
- if ($('#' + notice.id).length === 0) {
- var notice_irt_value = form.find('[name=inreplyto]').val();
- var notice_irt = '#notices_primary #notice-' + notice_irt_value;
- if ($('body')[0].id == 'conversation') {
- if (notice_irt_value.length > 0 && $(notice_irt + ' .notices').length < 1) {
- $(notice_irt).append('