1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/10270] Added JavaScript popups and basic AJAX functionality to PHP.

This commit adds the phpbb object (JavaScript), and alert and confirm box
methods. It also adds the first basic AJAX functionality, to deleting posts
in viewtopic.

PHPBB3-10270
This commit is contained in:
Callum Macrae
2011-07-14 13:33:42 +01:00
committed by Igor Wiedler
parent 4f97cc1295
commit d420ceb9c7
4 changed files with 158 additions and 8 deletions

80
phpBB/styles/script.js Normal file
View File

@@ -0,0 +1,80 @@
var phpbb = {};
/**
* Display a simple alert.
*
* @param string title Title of the message, eg "Information"
* @param string msg Message to display. Can be HTML.
*/
phpbb.alert = function(title, msg) {
var div = $('<div class="jalert"><h3>' + title + '</h3><p>' + msg + '</p></div>');
$(document).bind('click', function(e) {
if ($(e.target).parents('.jalert').length)
{
return true;
}
div.hide(300, function() {
div.remove();
});
return false;
});
$('body').append(div);
div.show(300);
}
/**
* Display a simple yes / no box to the user.
*
* @param string msg Message to display. Can be HTML.
* @param function callback Callback.
*/
phpbb.confirm = function(msg, callback) {
var div = $('<div class="jalert"><p>' + msg + '</p>\
<input type="button" class="jalertbut" value="Yes" />&nbsp;\
<input type="button" class="jalertbut" value="No" /></div>');
$('body').append(div);
$('.jalertbut').bind('click', function(event) {
div.hide(300, function() {
div.remove();
});
callback(this.value === 'Yes');
return false;
});
div.show(300);
}
$('.delete-icon a').click(function()
{
var pid = this.href.split('&p=')[1];
var __self = this;
$.get(this.href, function(res) {
res = JSON.parse(res);
phpbb.confirm(res.MESSAGE_TEXT, function(del) {
if (del)
{
var p = res.S_CONFIRM_ACTION.split('?');
p[1] += '&confirm=Yes'
$.post(p[0], p[1], function(res) {
res = JSON.parse(res);
phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT)
$(__self).parents('div #p' + pid).remove();
//if there is a refresh, check that it isn't to the same place
if (res.REFRESH_DATA && res.REFRESH_DATA.url.indexOf('t=') === -1)
{
setTimeout(function() {
window.location = res.REFRESH_DATA.url;
}, res.REFRESH_DATA.time * 1000);
}
});
}
});
});
return false;
});