X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=0bda55b602d9cda95dbf832dc3f6b0db491b3812;hb=3302067aad62d74c7b79545d1be9abc83f65ef89;hp=72fc2a58d5761de591c8652051044b051abc37f1;hpb=77190c9a87f36f6dfc3fd878ca5c568c7c2d1b79;p=quix0rs-gnu-social.git
diff --git a/js/util.js b/js/util.js
index 72fc2a58d5..0bda55b602 100644
--- a/js/util.js
+++ b/js/util.js
@@ -57,6 +57,9 @@ var SN = { // StatusNet
}
},
+ V: { // Variables
+ },
+
/**
* Map of localized message strings exported to script from the PHP
* side via Action::getScriptMessages().
@@ -216,6 +219,18 @@ 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) {
+ form.find("[" + attrs[key] + "~='" + oldId + "']").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.
@@ -590,8 +605,12 @@ var SN = { // StatusNet
$(document).on('click', '.notice-options > a.popup', function (e) {
e.preventDefault();
var noticeEl = $(this).closest('.notice');
- $.get($(this).attr('href'), {ajax: 1}, function (data, textStatus, xhr) {
- SN.U.NoticeOptionPopup(data, noticeEl);
+ $.ajax({
+ url: $(this).attr('href'),
+ data: {ajax: 1},
+ success: function (data, textStatus, xhr) {
+ SN.U.NoticeOptionPopup(data, noticeEl);
+ },
});
return false;
});
@@ -655,6 +674,12 @@ var SN = { // StatusNet
if (list.length == 0) {
list = notice.closest('.threaded-replies');
}
+ if (list.length == 0) {
+ list = $('
');
+ notice.append(list);
+ list = notice.find('.threaded-replies');
+ }
+
var nextStep = function () {
// Override...?
replyForm.find('input[name=inreplyto]').val(id);
@@ -689,23 +714,38 @@ var SN = { // StatusNet
var replyItem = $('li.notice-reply', list);
if (replyItem.length == 0) {
replyItem = $('');
-
- // Fetch a fresh copy of the notice form over AJAX.
- var url = $('#input_form_status > form').attr('action');
- $.get(url, {ajax: 1, inreplyto: id}, function (data, textStatus, xhr) {
- var formEl = document._importNode($('form', data)[0], true);
- replyItem.append(formEl);
- list.append(replyItem);
-
- replyForm = $(formEl);
- SN.Init.NoticeFormSetup(replyForm);
- nextStep();
- });
- } else {
- replyForm = replyItem.children('form');
+ }
+ replyForm = replyItem.children('form');
+ if (replyForm.length == 0) {
+ // Let's try another trick to avoid fetching by URL
+ var noticeForm = $('#input_form_status > form');
+ if (noticeForm.length == 0) {
+ // No notice form found on the page, so let's just
+ // fetch a fresh copy of the notice form over AJAX.
+ $.ajax({
+ url: SN.V.urlNewNotice,
+ data: {ajax: 1, inreplyto: id},
+ success: function (data, textStatus, xhr) {
+ var formEl = document._importNode($('form', data)[0], true);
+ replyForm = $(formEl);
+ replyItem.append(replyForm);
+ list.append(replyItem);
+
+ SN.Init.NoticeFormSetup(replyForm);
+ nextStep();
+ },
+ });
+ // We do everything relevant in 'success' above
+ return;
+ }
+ replyForm = noticeForm.clone();
SN.Init.NoticeFormSetup(replyForm);
- nextStep();
+ replyItem.append(replyForm);
+ list.append(replyItem);
}
+ // replyForm is set, we're not fetching by URL...
+ // Next setp is to configure in-reply-to etc.
+ nextStep();
},
/**
@@ -718,11 +758,15 @@ var SN = { // StatusNet
$(document).on('click', 'li.notice-reply-comments a', function () {
var url = $(this).attr('href');
var area = $(this).closest('.threaded-replies');
- $.get(url, {ajax: 1}, function (data, textStatus, xhr) {
- var replies = $('.threaded-replies', data);
- if (replies.length) {
- area.replaceWith(document._importNode(replies[0], true));
- }
+ $.ajax({
+ url: url,
+ data: {ajax: 1},
+ success: function (data, textStatus, xhr) {
+ var replies = $('.threaded-replies', data);
+ if (replies.length) {
+ area.replaceWith(document._importNode(replies[0], true));
+ }
+ },
});
return false;
});
@@ -1448,6 +1492,7 @@ var SN = { // StatusNet
return false;
}
SN.U.NoticeLocationAttach(form);
+ SN.U.FormNoticeUniqueID(form);
SN.U.FormNoticeXHR(form);
SN.U.FormNoticeEnhancements(form);
SN.U.NoticeDataAttach(form);