aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/styles/prosilver/template/ajax.js
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/styles/prosilver/template/ajax.js')
-rw-r--r--phpBB/styles/prosilver/template/ajax.js159
1 files changed, 156 insertions, 3 deletions
diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js
index 394aca749b..bc68e5ae0c 100644
--- a/phpBB/styles/prosilver/template/ajax.js
+++ b/phpBB/styles/prosilver/template/ajax.js
@@ -8,7 +8,7 @@
* @param int Delay in ms until darkenwrapper's click event is triggered
*/
phpbb.closeDarkenWrapper = function(delay) {
- setTimeout(function() {
+ phpbbAlertTimer = setTimeout(function() {
$('#darkenwrapper').trigger('click');
}, delay);
};
@@ -106,6 +106,47 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, update_topic_links) {
phpbb.closeDarkenWrapper(3000);
});
+// This callback will mark all notifications read
+phpbb.addAjaxCallback('notification.mark_all_read', function(res) {
+ if (typeof res.success !== 'undefined') {
+ phpbb.markNotifications($('#notification_list li.bg2'), 0);
+ phpbb.closeDarkenWrapper(3000);
+ }
+});
+
+// This callback will mark a notification read
+phpbb.addAjaxCallback('notification.mark_read', function(res) {
+ if (typeof res.success !== 'undefined') {
+ var unreadCount = Number($('#notification_list_button strong').html()) - 1;
+ phpbb.markNotifications($(this).parent('li.bg2'), unreadCount);
+ }
+});
+
+/**
+ * Mark notification popup rows as read.
+ *
+ * @param {jQuery} el jQuery object(s) to mark read.
+ * @param {int} unreadCount The new unread notifications count.
+ */
+phpbb.markNotifications = function(el, unreadCount) {
+ // Remove the unread status.
+ el.removeClass('bg2');
+ el.find('a.mark_read').remove();
+
+ // Update the notification link to the real URL.
+ el.each(function() {
+ var link = $(this).find('a');
+ link.attr('href', link.attr('data-real-url'));
+ });
+
+ // Update the unread count.
+ $('#notification_list_button strong').html(unreadCount);
+ // Remove the Mark all read link if there are no unread notifications.
+ if (!unreadCount) {
+ $('#mark_all_notifications').remove();
+ }
+};
+
// This callback finds the post from the delete link, and removes it.
phpbb.addAjaxCallback('post_delete', function() {
var el = $(this),
@@ -157,7 +198,119 @@ phpbb.addAjaxCallback('zebra', function(res) {
}
});
+/**
+ * This callback updates the poll results after voting.
+ */
+phpbb.addAjaxCallback('vote_poll', function(res) {
+ if (typeof res.success !== 'undefined') {
+ var poll = $('.topic_poll');
+ var panel = poll.find('.panel');
+ var results_visible = poll.find('dl:first-child .resultbar').is(':visible');
+ var most_votes = 0;
+
+ // Set min-height to prevent the page from jumping when the content changes
+ var update_panel_height = function (height) {
+ var height = (typeof height === 'undefined') ? panel.find('.inner').outerHeight() : height;
+ panel.css('min-height', height);
+ };
+ update_panel_height();
+
+ // Remove the View results link
+ if (!results_visible) {
+ poll.find('.poll_view_results').hide(500);
+ }
+
+ if (!res.can_vote) {
+ poll.find('.polls, .poll_max_votes, .poll_vote, .poll_option_select').fadeOut(500, function () {
+ poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show();
+ });
+ } else {
+ // If the user can still vote, simply slide down the results
+ poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500);
+ }
+
+ // Get the votes count of the highest poll option
+ poll.find('[data-poll-option-id]').each(function() {
+ var option = $(this);
+ var option_id = option.attr('data-poll-option-id');
+ most_votes = (res.vote_counts[option_id] >= most_votes) ? res.vote_counts[option_id] : most_votes;
+ });
+
+ // Update the total votes count
+ poll.find('.poll_total_vote_cnt').html(res.total_votes);
+
+ // Update each option
+ poll.find('[data-poll-option-id]').each(function() {
+ var option = $(this);
+ var option_id = option.attr('data-poll-option-id');
+ var voted = (typeof res.user_votes[option_id] !== 'undefined') ? true : false;
+ var most_voted = (res.vote_counts[option_id] == most_votes) ? true : false;
+ var percent = (!res.total_votes) ? 0 : Math.round((res.vote_counts[option_id] / res.total_votes) * 100);
+ var percent_rel = (most_votes == 0) ? 0 : Math.round((res.vote_counts[option_id] / most_votes) * 100);
+
+ option.toggleClass('voted', voted);
+ option.toggleClass('most-votes', most_voted);
+
+ // Update the bars
+ var bar = option.find('.resultbar div');
+ var bar_time_lapse = (res.can_vote) ? 500 : 1500;
+ var new_bar_class = (percent == 100) ? 'pollbar5' : 'pollbar' + (Math.floor(percent / 20) + 1);
+
+ setTimeout(function () {
+ bar.animate({width: percent_rel + '%'}, 500).removeClass('pollbar1 pollbar2 pollbar3 pollbar4 pollbar5').addClass(new_bar_class);
+ bar.html(res.vote_counts[option_id]);
+
+ var percent_txt = (!percent) ? res.NO_VOTES : percent + '%';
+ option.find('.poll_option_percent').html(percent_txt);
+ }, bar_time_lapse);
+ });
+
+ if (!res.can_vote) {
+ poll.find('.polls').delay(400).fadeIn(500);
+ }
+
+ // Display "Your vote has been cast." message. Disappears after 5 seconds.
+ var confirmation_delay = (res.can_vote) ? 300 : 900;
+ poll.find('.vote-submitted').delay(confirmation_delay).slideDown(200, function() {
+ if (results_visible) {
+ update_panel_height();
+ }
+
+ $(this).delay(5000).fadeOut(500, function() {
+ resize_panel(300);
+ });
+ });
+
+ // Remove the gap resulting from removing options
+ setTimeout(function() {
+ resize_panel(500);
+ }, 1500);
+
+ var resize_panel = function (time) {
+ var panel_height = panel.height();
+ var inner_height = panel.find('.inner').outerHeight();
+
+ if (panel_height != inner_height) {
+ panel.css({'min-height': '', 'height': panel_height}).animate({height: inner_height}, time, function () {
+ panel.css({'min-height': inner_height, 'height': ''});
+ });
+ }
+ };
+ }
+});
+
+/**
+ * Show poll results when clicking View results link.
+ */
+$('.poll_view_results a').click(function(e) {
+ // Do not follow the link
+ e.preventDefault();
+
+ var poll = $(this).parents('.topic_poll');
+ poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500);
+ poll.find('.poll_view_results').hide(500);
+});
$('[data-ajax]').each(function() {
var $this = $(this),
@@ -231,7 +384,7 @@ $('#quick-mod-select').change(function () {
});
$('#delete_permanent').click(function () {
- if ($(this).attr('checked')) {
+ if ($(this).prop('checked')) {
$('#delete_reason').hide();
} else {
$('#delete_reason').show();
@@ -247,7 +400,7 @@ $('#delete_permanent').click(function () {
*/
$('#member_search').click(function () {
$('#memberlist_search').slideToggle('fast');
- phpbb.ajax_callbacks.alt_text.call(this);
+ phpbb.ajaxCallbacks.alt_text.call(this);
// Focus on the username textbox if it's available and displayed
if ($('#memberlist_search').is(':visible')) {
$('#username').focus();