mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-17 21:10:00 +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:
parent
4f97cc1295
commit
d420ceb9c7
@ -2448,8 +2448,17 @@ function build_url($strip_vars = false)
|
|||||||
*/
|
*/
|
||||||
function meta_refresh($time, $url, $disable_cd_check = false)
|
function meta_refresh($time, $url, $disable_cd_check = false)
|
||||||
{
|
{
|
||||||
global $template;
|
global $template, $refresh_data;
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
|
||||||
|
{
|
||||||
|
$refresh_data = array(
|
||||||
|
'time' => $time,
|
||||||
|
'url' => str_replace('&', '&', $url)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$url = redirect($url, true, $disable_cd_check);
|
$url = redirect($url, true, $disable_cd_check);
|
||||||
$url = str_replace('&', '&', $url);
|
$url = str_replace('&', '&', $url);
|
||||||
|
|
||||||
@ -2457,6 +2466,7 @@ function meta_refresh($time, $url, $disable_cd_check = false)
|
|||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'META' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />')
|
'META' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />')
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
@ -2699,6 +2709,21 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
|
|||||||
WHERE user_id = " . $user->data['user_id'];
|
WHERE user_id = " . $user->data['user_id'];
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
|
||||||
|
{
|
||||||
|
$u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id;
|
||||||
|
echo json_encode(array(
|
||||||
|
'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title],
|
||||||
|
'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'],
|
||||||
|
|
||||||
|
'YES_VALUE' => $user->lang['YES'],
|
||||||
|
'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function
|
||||||
|
'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields
|
||||||
|
));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
|
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
|
||||||
{
|
{
|
||||||
adm_page_footer();
|
adm_page_footer();
|
||||||
@ -3922,6 +3947,20 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
|
|||||||
'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false)
|
'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
|
||||||
|
{
|
||||||
|
global $refresh_data;
|
||||||
|
|
||||||
|
echo json_encode(array(
|
||||||
|
'MESSAGE_TITLE' => $msg_title,
|
||||||
|
'MESSAGE_TEXT' => $msg_text,
|
||||||
|
'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false,
|
||||||
|
'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false,
|
||||||
|
'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null
|
||||||
|
));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// We do not want the cron script to be called on error messages
|
// We do not want the cron script to be called on error messages
|
||||||
define('IN_CRON', true);
|
define('IN_CRON', true);
|
||||||
|
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
<!-- IF DEBUG_OUTPUT --><br />{DEBUG_OUTPUT}<!-- ENDIF -->
|
<!-- IF DEBUG_OUTPUT --><br />{DEBUG_OUTPUT}<!-- ENDIF -->
|
||||||
<!-- IF U_ACP --><br /><strong><a href="{U_ACP}">{L_ACP}</a></strong><!-- ENDIF -->
|
<!-- IF U_ACP --><br /><strong><a href="{U_ACP}">{L_ACP}</a></strong><!-- ENDIF -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
|
||||||
|
<script src="styles/script.js"></script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -580,6 +580,34 @@ li.pagination {
|
|||||||
background: none 0 50% no-repeat;
|
background: none 0 50% no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.row .pagination span a, li.pagination span a {
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row .pagination span a:hover, li.pagination span a:hover {
|
||||||
|
background-color: #d2d2d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* jQuery popups
|
||||||
|
---------------------------------------- */
|
||||||
|
.jalert {
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border: 1px solid #999999;
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
top: 100px;
|
||||||
|
left: 35%;
|
||||||
|
width: 30%;
|
||||||
|
z-index: 50;
|
||||||
|
padding: 25px;
|
||||||
|
padding: 0 25px 20px 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jalert p {
|
||||||
|
margin: 8px 0;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Miscellaneous styles
|
/* Miscellaneous styles
|
||||||
---------------------------------------- */
|
---------------------------------------- */
|
||||||
#forum-permissions {
|
#forum-permissions {
|
||||||
|
80
phpBB/styles/script.js
Normal file
80
phpBB/styles/script.js
Normal 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" /> \
|
||||||
|
<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;
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user