|
$(function() { |
|
addDonateChangeButton(); |
|
}); |
|
|
|
var flagDonate = 0; |
|
|
|
function addDonateChangeButton() { |
|
var $donateChangeButton = $('<a></a>').addClass('newButtons').html('太少不捐!').attr({ |
|
'title': '切换捐赠数额', |
|
'href': 'javascript:' |
|
}).click(exchangeDonateButton); |
|
var $donateChangeLi = $('<li></li>').append($donateChangeButton); |
|
$('.forum-post-toolbox.minor-list.horizon-compact ul').append($donateChangeLi); |
|
} |
|
|
|
function exchangeDonateButton() { |
|
if (flagDonate == 0) { |
|
$('#to_donate .donate').each(function() { |
|
$(this).html($(this).html() * 8).unbind('click').click(takeBonusExchange); |
|
|
|
}); |
|
$(this).text('太多嫌贵!') |
|
flagDonate = 1; |
|
} else { |
|
$('#to_donate .donate').each(function() { |
|
$(this).html($(this).html() / 8).unbind('click').click(originBonus); |
|
}); |
|
$(this).text('太少不捐!') |
|
flagDonate = 0; |
|
} |
|
} |
|
|
|
function takeBonusExchange(e) { |
|
e.preventDefault(); |
|
var form = $(this), |
|
price = form.text(), |
|
submits=$('#outer :submit:enabled'), |
|
dialog = $('<div></div>', { title: '确认', text: '你确定要交换该项魔力值么?' }).dialog({ modal: true, autoOpen: false });; |
|
var text = '你确定要向楼主捐赠' + price + '点魔力值么?'; |
|
var usernames = $('[data-find = _5]').find('.username a').text(); |
|
dialog.text(text).dialog('option', 'buttons', { |
|
OK: function() { |
|
submits.attr('disabled', 'disabled'); |
|
var query = { |
|
'option': '7', |
|
'username': usernames, |
|
'bonusgift': price, |
|
'message': '主题赠送来自' + window.location.href |
|
}; |
|
$.post('takebonusexchange.php?format=json', query, function(result) { |
|
submits.removeAttr('disabled'); |
|
if (result.success) { |
|
$('#bonus, .bonus').text(result.bonus); |
|
$('#uploaded').text(result.uploaded); |
|
$('#invites').text(result.invites); |
|
$('.post-donation').html("无偿捐献成功!"); |
|
} |
|
}, 'json'); |
|
dialog.dialog("close"); |
|
}, |
|
Cancel: function() { |
|
dialog.dialog("close"); |
|
} |
|
}).dialog('open'); |
|
} |
|
|
|
function originBonus(e) { |
|
e.preventDefault(); |
|
var topicid = hb.topic.id, |
|
bonus = parseInt(hb.config.user.bonus), |
|
to_donate = parseInt($(this).html()); |
|
if (bonus < to_donate) { |
|
alert('你的魔力值不足,谢谢你的好心,继续努力吧~') |
|
} else if (confirm('确认向楼主捐赠 ' + to_donate + ' 魔力值吗?')) { |
|
var url = '/donateBonus.php', |
|
data = { |
|
amount: to_donate, |
|
topicid: topicid, |
|
type: 'topic' |
|
}; |
|
$.post(url, data, function(data) { |
|
if (data.status == 9) { |
|
var newDonate = '<div class="donate' + data.amount + ' donate" id="donated_successfully" title="[' + data.amount + ' 魔力值] ' + data.date + '">' + data.donater + '</div><div style="clear:both;"></div>'; |
|
if ($('#donater_list div').size() == 0) { |
|
$('#donater_list').html(newDonate) |
|
} else { |
|
$('#donater_list :last-child').remove(); |
|
$('#donater_list').append(newDonate) |
|
}; |
|
$('#to_donate').html("你已经于 " + data.date + " 对楼主进行过魔力值捐赠,谢谢你!") |
|
} else if (data.status == 1) { |
|
alert('谢谢你,但是你的魔力值不足,继续努力吧。') |
|
} else if (data.status == 2) { |
|
alert('你要捐赠主题不存在。') |
|
} else if (data.status == 3) { |
|
alert('你要捐赠的用户不存在。') |
|
} else if (data.status == 4) { |
|
alert('只允许以下几个数量的捐赠额:8, 16, 32, 64, 128。') |
|
} else if (data.status == 5) { |
|
alert('不能给自己捐赠的哦!') |
|
} else if (data.status == 6) { |
|
alert('你已经捐赠过了,谢谢!') |
|
} else alert('貌似系统出问题了,呼管理员!') |
|
}, 'json') |
|
} |
|
} |