javascript fixes for reply form fetching
It doesn't update the ID properly yet, which should be done to avoid creating duplicate forms which are identical to HTML parsers...
This commit is contained in:
parent
0a2c51510c
commit
3302067aad
43
js/util.js
43
js/util.js
|
@ -57,6 +57,9 @@ var SN = { // StatusNet
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
V: { // Variables
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of localized message strings exported to script from the PHP
|
* Map of localized message strings exported to script from the PHP
|
||||||
* side via Action::getScriptMessages().
|
* side via Action::getScriptMessages().
|
||||||
|
@ -216,6 +219,18 @@ var SN = { // StatusNet
|
||||||
return url;
|
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'
|
* Grabs form data and submits it asynchronously, with 'ajax=1'
|
||||||
* parameter added to the rest.
|
* parameter added to the rest.
|
||||||
|
@ -699,11 +714,16 @@ var SN = { // StatusNet
|
||||||
var replyItem = $('li.notice-reply', list);
|
var replyItem = $('li.notice-reply', list);
|
||||||
if (replyItem.length == 0) {
|
if (replyItem.length == 0) {
|
||||||
replyItem = $('<li class="notice-reply"></li>');
|
replyItem = $('<li class="notice-reply"></li>');
|
||||||
|
}
|
||||||
// Fetch a fresh copy of the notice form over AJAX.
|
replyForm = replyItem.children('form');
|
||||||
var url = $('#input_form_status > form').attr('action');
|
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({
|
$.ajax({
|
||||||
url: url,
|
url: SN.V.urlNewNotice,
|
||||||
data: {ajax: 1, inreplyto: id},
|
data: {ajax: 1, inreplyto: id},
|
||||||
success: function (data, textStatus, xhr) {
|
success: function (data, textStatus, xhr) {
|
||||||
var formEl = document._importNode($('form', data)[0], true);
|
var formEl = document._importNode($('form', data)[0], true);
|
||||||
|
@ -715,11 +735,17 @@ var SN = { // StatusNet
|
||||||
nextStep();
|
nextStep();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
// We do everything relevant in 'success' above
|
||||||
replyForm = replyItem.children('form');
|
return;
|
||||||
SN.Init.NoticeFormSetup(replyForm);
|
|
||||||
nextStep();
|
|
||||||
}
|
}
|
||||||
|
replyForm = noticeForm.clone();
|
||||||
|
SN.Init.NoticeFormSetup(replyForm);
|
||||||
|
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();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1466,6 +1492,7 @@ var SN = { // StatusNet
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SN.U.NoticeLocationAttach(form);
|
SN.U.NoticeLocationAttach(form);
|
||||||
|
SN.U.FormNoticeUniqueID(form);
|
||||||
SN.U.FormNoticeXHR(form);
|
SN.U.FormNoticeXHR(form);
|
||||||
SN.U.FormNoticeEnhancements(form);
|
SN.U.FormNoticeEnhancements(form);
|
||||||
SN.U.NoticeDataAttach(form);
|
SN.U.NoticeDataAttach(form);
|
||||||
|
|
|
@ -431,6 +431,7 @@ class Action extends HTMLOutputter // lawsuit
|
||||||
$this->inlineScript('var _peopletagAC = "' .
|
$this->inlineScript('var _peopletagAC = "' .
|
||||||
common_local_url('peopletagautocomplete') . '";');
|
common_local_url('peopletagautocomplete') . '";');
|
||||||
$this->showScriptMessages();
|
$this->showScriptMessages();
|
||||||
|
$this->showScriptVariables();
|
||||||
// Anti-framing code to avoid clickjacking attacks in older browsers.
|
// Anti-framing code to avoid clickjacking attacks in older browsers.
|
||||||
// This will show a blank page if the page is being framed, which is
|
// This will show a blank page if the page is being framed, which is
|
||||||
// consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
|
// consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
|
||||||
|
@ -473,6 +474,19 @@ class Action extends HTMLOutputter // lawsuit
|
||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function showScriptVariables()
|
||||||
|
{
|
||||||
|
$vars = array();
|
||||||
|
|
||||||
|
if (Event::handle('StartScriptVariables', array($this, &$vars))) {
|
||||||
|
$vars['urlNewNotice'] = common_local_url('newnotice');
|
||||||
|
}
|
||||||
|
if (!empty($vars)) {
|
||||||
|
$this->inlineScript('SN.V = ' . json_encode($vars));
|
||||||
|
}
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the action will need localizable text strings, export them here like so:
|
* If the action will need localizable text strings, export them here like so:
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user