1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-01 03:54:56 +02:00

[ticket/10272] AJAXified most links.

This commit makes some significant changes to the phpbb.confirm_box function
(namely, removing some duplicate code), and also manually adds most link
to the phpBB AJAX functions.

PHPBB3-10272
This commit is contained in:
Callum Macrae 2011-07-14 14:57:45 +01:00 committed by Igor Wiedler
parent e6401c081e
commit 2556f5fcc2

View File

@ -53,6 +53,39 @@ phpbb.confirm = function(msg, callback) {
return div;
}
/**
* Clearing up some duplicate code - don't use this.
*/
function handle_refresh(data, refresh, div)
{
if (data)
{
if (typeof refresh === 'function')
{
refresh = refresh(data.url)
}
else if (typeof refresh !== 'boolean')
{
refresh = false;
}
if (refresh)
{
setTimeout(function() {
window.location = data.url;
}, data.time * 1000);
}
else
{
setTimeout(function() {
div.hide(300, function() {
div.remove();
});
}, data.time * 1000);
}
}
}
/**
* This function interacts via AJAX with phpBBs confirm_box function.
@ -77,34 +110,13 @@ phpbb.confirm_box = function(condition, refresh, callback)
$.post(p[0], p[1], function(res) {
res = JSON.parse(res);
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
callback(__self);
if (res.REFRESH_DATA)
if (typeof callback !== 'undefined')
{
if (typeof refresh === 'function')
{
refresh = refresh(res.REFRESH_DATA.url)
}
else if (typeof refresh !== 'boolean')
{
refresh = false;
}
if (refresh)
{
setTimeout(function() {
window.location = res.REFRESH_DATA.url;
}, res.REFRESH_DATA.time * 1000);
}
else
{
setTimeout(function() {
div.hide(300, function() {
div.remove();
});
}, res.REFRESH_DATA.time * 1000);
}
callback(__self);
}
handle_refresh(res.REFRESH_DATA, refresh, alert);
});
}
});
@ -113,6 +125,26 @@ phpbb.confirm_box = function(condition, refresh, callback)
});
}
/**
* Makes a link use AJAX instead of loading an entire page.
*/
phpbb.ajaxify = function(selector, refresh, callback) {
$(selector).click(function() {
var __self = this;
$.get(this.href, function(res) {
res = JSON.parse(res);
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
if (typeof callback !== 'undefined')
{
callback(__self, res);
}
handle_refresh(res.REFRESH_DATA, refresh, alert);
});
return false;
});
}
var refresh = function(url) {
return (url.indexOf('t=') === -1);
}
@ -121,3 +153,22 @@ var callback = function(el) {
$(el).parents('div #p' + pid).remove();
}
phpbb.confirm_box('.delete-icon a', refresh, callback);
phpbb.confirm_box('a[href$="ucp.php?mode=delete_cookies"]', true);
phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) {
var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1);
text = (text) ? 'Remove from bookmarks' : 'Bookmark topic';
$(el).text(el.title = text);
});
phpbb.ajaxify('a[href*="&watch=topic"]', false, function(el, res) {
var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1);
text = (text) ? 'Unsubscribe topic' : 'Subscribe topic';
$(el).text(el.title = text);
});
phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) {
var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1);
text = (text) ? 'Unsubscribe forum' : 'Subscribe forum';
$(el).text(el.title = text);
});
phpbb.ajaxify('a[href*="mode=bump"]');
phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums