aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/styles/script.js
diff options
context:
space:
mode:
authorCallum Macrae <callum@lynxphp.com>2011-07-14 13:33:42 +0100
committerIgor Wiedler <igor@wiedler.ch>2012-03-31 02:00:22 +0200
commitd420ceb9c717b83ba29dde3734b563881051e51a (patch)
tree9edac83794c76485d758ce60ad5a5327096deee4 /phpBB/styles/script.js
parent4f97cc12951b2be6fa8d7962beaf631f7c82fb43 (diff)
downloadforums-d420ceb9c717b83ba29dde3734b563881051e51a.tar
forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.gz
forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.bz2
forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.xz
forums-d420ceb9c717b83ba29dde3734b563881051e51a.zip
[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
Diffstat (limited to 'phpBB/styles/script.js')
-rw-r--r--phpBB/styles/script.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js
new file mode 100644
index 0000000000..9be3efd4ce
--- /dev/null
+++ b/phpBB/styles/script.js
@@ -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;
+});