Replace explicit FormXHR setup for a bunch of simple AJAX form submissions with adding the 'ajax' class on them.
This avoids having to add extra custom JS bits just to initialize forms using the common AJAX submission path.
This commit is contained in:
parent
90f1cfcfc0
commit
28809035d0
21
js/util.js
21
js/util.js
|
@ -228,6 +228,9 @@ var SN = { // StatusNet
|
||||||
* will be extracted and copied in, replacing the original form.
|
* will be extracted and copied in, replacing the original form.
|
||||||
* If there's no form, the first paragraph will be used.
|
* If there's no form, the first paragraph will be used.
|
||||||
*
|
*
|
||||||
|
* This will automatically be applied on the 'submit' event for
|
||||||
|
* any form with the 'ajax' class.
|
||||||
|
*
|
||||||
* @fixme can sometimes explode confusingly if returnd data is bogus
|
* @fixme can sometimes explode confusingly if returnd data is bogus
|
||||||
* @fixme error handling is pretty vague
|
* @fixme error handling is pretty vague
|
||||||
* @fixme can't submit file uploads
|
* @fixme can't submit file uploads
|
||||||
|
@ -633,17 +636,6 @@ var SN = { // StatusNet
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup function -- DOES NOT apply immediately.
|
|
||||||
*
|
|
||||||
* Sets up event handlers for favor/disfavor forms to submit via XHR.
|
|
||||||
* Uses 'live' rather than 'bind', so applies to future as well as present items.
|
|
||||||
*/
|
|
||||||
NoticeFavor: function() {
|
|
||||||
$('.form_favor').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
$('.form_disfavor').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
},
|
|
||||||
|
|
||||||
NoticeInlineReplyPlaceholder: function(notice) {
|
NoticeInlineReplyPlaceholder: function(notice) {
|
||||||
var list = notice.find('ul.threaded-replies');
|
var list = notice.find('ul.threaded-replies');
|
||||||
var placeholder = $('<li class="notice-reply-placeholder">' +
|
var placeholder = $('<li class="notice-reply-placeholder">' +
|
||||||
|
@ -1331,7 +1323,6 @@ var SN = { // StatusNet
|
||||||
if (masterForm.length > 0) {
|
if (masterForm.length > 0) {
|
||||||
SN.C.I.NoticeFormMaster = document._importNode(masterForm[0], true);
|
SN.C.I.NoticeFormMaster = document._importNode(masterForm[0], true);
|
||||||
}
|
}
|
||||||
SN.U.NoticeFavor();
|
|
||||||
SN.U.NoticeRepeat();
|
SN.U.NoticeRepeat();
|
||||||
SN.U.NoticeReply();
|
SN.U.NoticeReply();
|
||||||
SN.U.NoticeInlineReplySetup();
|
SN.U.NoticeInlineReplySetup();
|
||||||
|
@ -1348,12 +1339,6 @@ var SN = { // StatusNet
|
||||||
*/
|
*/
|
||||||
EntityActions: function() {
|
EntityActions: function() {
|
||||||
if ($('body.user_in').length > 0) {
|
if ($('body.user_in').length > 0) {
|
||||||
$('.form_user_subscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
$('.form_user_unsubscribe').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
$('.form_group_join').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
$('.form_group_leave').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
$('.form_user_nudge').live('click', function() { SN.U.FormXHR($(this)); return false; });
|
|
||||||
|
|
||||||
SN.U.NewDirectMessage();
|
SN.U.NewDirectMessage();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
2
js/util.min.js
vendored
2
js/util.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -147,6 +147,6 @@ class DisfavorForm extends Form
|
||||||
*/
|
*/
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_disfavor';
|
return 'form_disfavor ajax';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,6 @@ class FavorForm extends Form
|
||||||
*/
|
*/
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_favor';
|
return 'form_favor ajax';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,13 @@ class Form extends Widget
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class of the form.
|
* Class of the form. May include space-separated list of multiple classes.
|
||||||
|
*
|
||||||
|
* If 'ajax' is included, the form will automatically be submitted with
|
||||||
|
* an 'ajax=1' parameter added, and the resulting form or error message
|
||||||
|
* will replace the form after submission.
|
||||||
|
*
|
||||||
|
* It's up to you to make sure that the target action supports this!
|
||||||
*
|
*
|
||||||
* @return string the form's class
|
* @return string the form's class
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -88,7 +88,7 @@ class JoinForm extends Form
|
||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_group_join';
|
return 'form_group_join ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -88,7 +88,7 @@ class LeaveForm extends Form
|
||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_group_leave';
|
return 'form_group_leave ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,7 +89,7 @@ class NudgeForm extends Form
|
||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_user_nudge';
|
return 'form_user_nudge ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class SubscribeForm extends Form
|
||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_user_subscribe';
|
return 'form_user_subscribe ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class UnsubscribeForm extends Form
|
||||||
|
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_user_unsubscribe';
|
return 'form_user_unsubscribe ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -180,21 +180,6 @@ class UserFlagPlugin extends Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize any flagging buttons on the page
|
|
||||||
*
|
|
||||||
* @param Action $action action being shown
|
|
||||||
*
|
|
||||||
* @return boolean hook result
|
|
||||||
*/
|
|
||||||
function onEndShowScripts($action)
|
|
||||||
{
|
|
||||||
$action->inlineScript('if ($(".form_entity_flag").length > 0) { '.
|
|
||||||
'$(".form_entity_flag").bind("click", function() {'.
|
|
||||||
'SN.U.FormXHR($(this)); return false; }); }');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a user has one of our defined rights
|
* Check whether a user has one of our defined rights
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,7 +54,7 @@ class FlagProfileForm extends ProfileActionForm
|
||||||
*/
|
*/
|
||||||
function formClass()
|
function formClass()
|
||||||
{
|
{
|
||||||
return 'form_entity_flag';
|
return 'form_entity_flag ajax';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user