summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-11-11 15:37:17 -0500
committerCraig Andrews <candrews@integralblue.com>2009-11-11 15:37:17 -0500
commit83b92d9ef01cdf640eb7f88e218569e6a5aebbdd (patch)
tree84846dfdf5433d66267accd1977e50c7d87cab63 /js
parentc9eb7c1f0b60cbcf4672bcfca0814dd1bfc1dcf0 (diff)
Refactored the favorite button ajaxification to a separate function
Diffstat (limited to 'js')
-rw-r--r--js/util.js83
1 files changed, 45 insertions, 38 deletions
diff --git a/js/util.js b/js/util.js
index 2165957c3..879bb38ae 100644
--- a/js/util.js
+++ b/js/util.js
@@ -81,32 +81,6 @@ $(document).ready(function(){
// XXX: refactor this code
- var favoptions = { dataType: 'xml',
- beforeSubmit: function(data, target, options) {
- $(target).addClass('processing');
- return true;
- },
- success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
- var dis = new_form.id;
- var fav = dis.replace('disfavor', 'favor');
- $('form#'+fav).replaceWith(new_form);
- $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
- }
- };
-
- var disoptions = { dataType: 'xml',
- beforeSubmit: function(data, target, options) {
- $(target).addClass('processing');
- return true;
- },
- success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
- var fav = new_form.id;
- var dis = fav.replace('favor', 'disfavor');
- $('form#'+dis).replaceWith(new_form);
- $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
- }
- };
-
var joinoptions = { dataType: 'xml',
success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
var leave = new_form.id;
@@ -125,20 +99,8 @@ $(document).ready(function(){
}
};
- function addAjaxHidden() {
- var ajax = document.createElement('input');
- ajax.setAttribute('type', 'hidden');
- ajax.setAttribute('name', 'ajax');
- ajax.setAttribute('value', 1);
- this.appendChild(ajax);
- }
-
- $("form.form_favor").ajaxForm(favoptions);
- $("form.form_disfavor").ajaxForm(disoptions);
$("form.form_group_join").ajaxForm(joinoptions);
$("form.form_group_leave").ajaxForm(leaveoptions);
- $("form.form_favor").each(addAjaxHidden);
- $("form.form_disfavor").each(addAjaxHidden);
$("form.form_group_join").each(addAjaxHidden);
$("form.form_group_leave").each(addAjaxHidden);
@@ -252,6 +214,7 @@ $(document).ready(function(){
$('#'+li.id).fadeIn(2500);
NoticeReply();
NoticeAttachments();
+ NoticeFavors();
}
}
$("#notice_data-text").val("");
@@ -270,8 +233,52 @@ $(document).ready(function(){
NoticeReply();
NoticeAttachments();
NoticeDataAttach();
+ NoticeFavors();
});
+function addAjaxHidden() {
+ var ajax = document.createElement('input');
+ ajax.setAttribute('type', 'hidden');
+ ajax.setAttribute('name', 'ajax');
+ ajax.setAttribute('value', 1);
+ this.appendChild(ajax);
+}
+
+function NoticeFavors() {
+
+ // XXX: refactor this code
+ var favoptions = { dataType: 'xml',
+ beforeSubmit: function(data, target, options) {
+ $(target).addClass('processing');
+ return true;
+ },
+ success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
+ var dis = new_form.id;
+ var fav = dis.replace('disfavor', 'favor');
+ $('form#'+fav).replaceWith(new_form);
+ $('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
+ }
+ };
+
+ var disoptions = { dataType: 'xml',
+ beforeSubmit: function(data, target, options) {
+ $(target).addClass('processing');
+ return true;
+ },
+ success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
+ var fav = new_form.id;
+ var dis = fav.replace('favor', 'disfavor');
+ $('form#'+dis).replaceWith(new_form);
+ $('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
+ }
+ };
+
+ $("form.form_favor").ajaxForm(favoptions);
+ $("form.form_disfavor").ajaxForm(disoptions);
+ $("form.form_favor").each(addAjaxHidden);
+ $("form.form_disfavor").each(addAjaxHidden);
+}
+
function NoticeReply() {
if ($('#notice_data-text').length > 0 && $('#content .notice_reply').length > 0) {
$('#content .notice').each(function() {