[ Index ] |
PHP Cross Reference of phpBB-3.3.12-deutsch |
[Summary view] [Print] [Text view]
1 /* global phpbb */ 2 3 (function($) { // Avoid conflicts with other libraries 4 5 'use strict'; 6 7 // This callback will mark all forum icons read 8 phpbb.addAjaxCallback('mark_forums_read', function(res) { 9 var readTitle = res.NO_UNREAD_POSTS; 10 var unreadTitle = res.UNREAD_POSTS; 11 var iconsArray = { 12 forum_unread: 'forum_read', 13 forum_unread_subforum: 'forum_read_subforum', 14 forum_unread_locked: 'forum_read_locked' 15 }; 16 17 $('li.row').find('dl[class*="forum_unread"]').each(function() { 18 var $this = $(this); 19 20 $.each(iconsArray, function(unreadClass, readClass) { 21 if ($this.hasClass(unreadClass)) { 22 $this.removeClass(unreadClass).addClass(readClass); 23 } 24 }); 25 $this.children('dt[title="' + unreadTitle + '"]').attr('title', readTitle); 26 }); 27 28 // Mark subforums read 29 $('a.subforum[class*="unread"]').removeClass('unread').addClass('read').children('.icon.icon-red').removeClass('icon-red').addClass('icon-blue'); 30 31 // Mark topics read if we are watching a category and showing active topics 32 if ($('#active_topics').length) { 33 phpbb.ajaxCallbacks.mark_topics_read.call(this, res, false); 34 } 35 36 // Update mark forums read links 37 $('[data-ajax="mark_forums_read"]').attr('href', res.U_MARK_FORUMS); 38 39 phpbb.closeDarkenWrapper(3000); 40 }); 41 42 /** 43 * This callback will mark all topic icons read 44 * 45 * @param {bool} [update_topic_links=true] Whether "Mark topics read" links 46 * should be updated. Defaults to true. 47 */ 48 phpbb.addAjaxCallback('mark_topics_read', function(res, updateTopicLinks) { 49 var readTitle = res.NO_UNREAD_POSTS; 50 var unreadTitle = res.UNREAD_POSTS; 51 var iconsArray = { 52 global_unread: 'global_read', 53 announce_unread: 'announce_read', 54 sticky_unread: 'sticky_read', 55 topic_unread: 'topic_read' 56 }; 57 var iconsState = ['', '_hot', '_hot_mine', '_locked', '_locked_mine', '_mine']; 58 var unreadClassSelectors; 59 var classMap = {}; 60 var classNames = []; 61 62 if (typeof updateTopicLinks === 'undefined') { 63 updateTopicLinks = true; 64 } 65 66 $.each(iconsArray, function(unreadClass, readClass) { 67 $.each(iconsState, function(key, value) { 68 // Only topics can be hot 69 if ((value === '_hot' || value === '_hot_mine') && unreadClass !== 'topic_unread') { 70 return true; 71 } 72 classMap[unreadClass + value] = readClass + value; 73 classNames.push(unreadClass + value); 74 }); 75 }); 76 77 unreadClassSelectors = '.' + classNames.join(',.'); 78 79 $('li.row').find(unreadClassSelectors).each(function() { 80 var $this = $(this); 81 $.each(classMap, function(unreadClass, readClass) { 82 if ($this.hasClass(unreadClass)) { 83 $this.removeClass(unreadClass).addClass(readClass); 84 } 85 }); 86 $this.children('dt[title="' + unreadTitle + '"]').attr('title', readTitle); 87 }); 88 89 // Remove link to first unread post 90 $('a.unread').has('.icon-red').remove(); 91 92 // Update mark topics read links 93 if (updateTopicLinks) { 94 $('[data-ajax="mark_topics_read"]').attr('href', res.U_MARK_TOPICS); 95 } 96 97 phpbb.closeDarkenWrapper(3000); 98 }); 99 100 // This callback will mark all notifications read 101 phpbb.addAjaxCallback('notification.mark_all_read', function(res) { 102 if (typeof res.success !== 'undefined') { 103 phpbb.markNotifications($('#notification_list li.bg2'), 0); 104 phpbb.toggleDropdown.call($('#notification_list_button')); 105 phpbb.closeDarkenWrapper(3000); 106 } 107 }); 108 109 // This callback will mark a notification read 110 phpbb.addAjaxCallback('notification.mark_read', function(res) { 111 if (typeof res.success !== 'undefined') { 112 var unreadCount = Number($('#notification_list_button strong').html()) - 1; 113 phpbb.markNotifications($(this).parent('li.bg2'), unreadCount); 114 } 115 }); 116 117 /** 118 * Mark notification popup rows as read. 119 * 120 * @param {jQuery} $popup jQuery object(s) to mark read. 121 * @param {int} unreadCount The new unread notifications count. 122 */ 123 phpbb.markNotifications = function($popup, unreadCount) { 124 // Remove the unread status. 125 $popup.removeClass('bg2'); 126 $popup.find('a.mark_read').remove(); 127 128 // Update the notification link to the real URL. 129 $popup.each(function() { 130 var link = $(this).find('a'); 131 link.attr('href', link.attr('data-real-url')); 132 }); 133 134 // Update the unread count. 135 $('strong', '#notification_list_button').html(unreadCount); 136 // Remove the Mark all read link and hide notification count if there are no unread notifications. 137 if (!unreadCount) { 138 $('#mark_all_notifications').remove(); 139 $('#notification_list_button > strong').addClass('hidden'); 140 } 141 142 // Update page title 143 var $title = $('title'); 144 var originalTitle = $title.text().replace(/(\((\d+)\))/, ''); 145 $title.text((unreadCount ? '(' + unreadCount + ')' : '') + originalTitle); 146 }; 147 148 // This callback finds the post from the delete link, and removes it. 149 phpbb.addAjaxCallback('post_delete', function() { 150 var $this = $(this), 151 postId; 152 153 if ($this.attr('data-refresh') === undefined) { 154 postId = $this[0].href.split('&p=')[1]; 155 var post = $this.parents('#p' + postId).css('pointer-events', 'none'); 156 if (post.hasClass('bg1') || post.hasClass('bg2')) { 157 var posts1 = post.nextAll('.bg1'); 158 post.nextAll('.bg2').removeClass('bg2').addClass('bg1'); 159 posts1.removeClass('bg1').addClass('bg2'); 160 } 161 post.fadeOut(function() { 162 $(this).remove(); 163 }); 164 } 165 }); 166 167 // This callback removes the approve / disapprove div or link. 168 phpbb.addAjaxCallback('post_visibility', function(res) { 169 var remove = (res.visible) ? $(this) : $(this).parents('.post'); 170 $(remove).css('pointer-events', 'none').fadeOut(function() { 171 $(this).remove(); 172 }); 173 174 if (res.visible) { 175 // Remove the "Deleted by" message from the post on restoring. 176 remove.parents('.post').find('.post_deleted_msg').css('pointer-events', 'none').fadeOut(function() { 177 $(this).remove(); 178 }); 179 } 180 }); 181 182 // This removes the parent row of the link or form that fired the callback. 183 phpbb.addAjaxCallback('row_delete', function() { 184 $(this).parents('tr').remove(); 185 }); 186 187 // This handles friend / foe additions removals. 188 phpbb.addAjaxCallback('zebra', function(res) { 189 var zebra; 190 191 if (res.success) { 192 zebra = $('.zebra'); 193 zebra.first().html(res.MESSAGE_TEXT); 194 zebra.not(':first').html(' ').prev().html(' '); 195 } 196 }); 197 198 /** 199 * This callback updates the poll results after voting. 200 */ 201 phpbb.addAjaxCallback('vote_poll', function(res) { 202 if (typeof res.success !== 'undefined') { 203 var poll = $(this).closest('.topic_poll'); 204 var panel = poll.find('.panel'); 205 var resultsVisible = poll.find('dl:first-child .resultbar').is(':visible'); 206 var mostVotes = 0; 207 208 // Set min-height to prevent the page from jumping when the content changes 209 var updatePanelHeight = function (height) { 210 height = (typeof height === 'undefined') ? panel.find('.inner').outerHeight() : height; 211 panel.css('min-height', height); 212 }; 213 updatePanelHeight(); 214 215 // Remove the View results link 216 if (!resultsVisible) { 217 poll.find('.poll_view_results').hide(500); 218 } 219 220 if (!res.can_vote) { 221 poll.find('.polls, .poll_max_votes, .poll_vote, .poll_option_select').fadeOut(500, function () { 222 poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(); 223 }); 224 } else { 225 // If the user can still vote, simply slide down the results 226 poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500); 227 } 228 229 // Get the votes count of the highest poll option 230 poll.find('[data-poll-option-id]').each(function() { 231 var option = $(this); 232 var optionId = option.attr('data-poll-option-id'); 233 mostVotes = (res.vote_counts[optionId] >= mostVotes) ? res.vote_counts[optionId] : mostVotes; 234 }); 235 236 // Update the total votes count 237 poll.find('.poll_total_vote_cnt').html(res.total_votes); 238 239 // Update each option 240 poll.find('[data-poll-option-id]').each(function() { 241 var $this = $(this); 242 var optionId = $this.attr('data-poll-option-id'); 243 var voted = (typeof res.user_votes[optionId] !== 'undefined'); 244 var mostVoted = (res.vote_counts[optionId] === mostVotes); 245 var percent = (!res.total_votes) ? 0 : Math.round((res.vote_counts[optionId] / res.total_votes) * 100); 246 var percentRel = (mostVotes === 0) ? 0 : Math.round((res.vote_counts[optionId] / mostVotes) * 100); 247 var altText; 248 249 altText = $this.attr('data-alt-text'); 250 if (voted) { 251 $this.attr('title', $.trim(altText)); 252 } else { 253 $this.attr('title', ''); 254 }; 255 $this.toggleClass('voted', voted); 256 $this.toggleClass('most-votes', mostVoted); 257 258 // Update the bars 259 var bar = $this.find('.resultbar div'); 260 var barTimeLapse = (res.can_vote) ? 500 : 1500; 261 var newBarClass = (percent === 100) ? 'pollbar5' : 'pollbar' + (Math.floor(percent / 20) + 1); 262 263 setTimeout(function () { 264 bar.animate({ width: percentRel + '%' }, 500) 265 .removeClass('pollbar1 pollbar2 pollbar3 pollbar4 pollbar5') 266 .addClass(newBarClass) 267 .html(res.vote_counts[optionId]); 268 269 var percentText = percent ? percent + '%' : res.NO_VOTES; 270 $this.find('.poll_option_percent').html(percentText); 271 }, barTimeLapse); 272 }); 273 274 if (!res.can_vote) { 275 poll.find('.polls').delay(400).fadeIn(500); 276 } 277 278 // Display "Your vote has been cast." message. Disappears after 5 seconds. 279 var confirmationDelay = (res.can_vote) ? 300 : 900; 280 poll.find('.vote-submitted').delay(confirmationDelay).slideDown(200, function() { 281 if (resultsVisible) { 282 updatePanelHeight(); 283 } 284 285 $(this).delay(5000).fadeOut(500, function() { 286 resizePanel(300); 287 }); 288 }); 289 290 // Remove the gap resulting from removing options 291 setTimeout(function() { 292 resizePanel(500); 293 }, 1500); 294 295 var resizePanel = function (time) { 296 var panelHeight = panel.height(); 297 var innerHeight = panel.find('.inner').outerHeight(); 298 299 if (panelHeight !== innerHeight) { 300 panel.css({ minHeight: '', height: panelHeight }) 301 .animate({ height: innerHeight }, time, function () { 302 panel.css({ minHeight: innerHeight, height: '' }); 303 }); 304 } 305 }; 306 } 307 }); 308 309 /** 310 * Show poll results when clicking View results link. 311 */ 312 $('.poll_view_results a').click(function(e) { 313 // Do not follow the link 314 e.preventDefault(); 315 316 var $poll = $(this).parents('.topic_poll'); 317 318 $poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500); 319 $poll.find('.poll_view_results').hide(500); 320 }); 321 322 $('[data-ajax]').each(function() { 323 var $this = $(this); 324 var ajax = $this.attr('data-ajax'); 325 var filter = $this.attr('data-filter'); 326 327 if (ajax !== 'false') { 328 var fn = (ajax !== 'true') ? ajax : null; 329 filter = (filter !== undefined) ? phpbb.getFunctionByName(filter) : null; 330 331 phpbb.ajaxify({ 332 selector: this, 333 refresh: $this.attr('data-refresh') !== undefined, 334 filter: filter, 335 callback: fn 336 }); 337 } 338 }); 339 340 // Prevent accidental double submission of form 341 $('[data-prevent-flood] input[type=submit]').click(function(event) { 342 const $submitButton = $(this); // Store the button element 343 const $form = $submitButton.closest('form'); 344 345 // Always add the disabled class for visual feedback 346 $submitButton.addClass('disabled'); 347 348 // Submit form if it hasn't been submitted yet 349 if (!$form.prop('data-form-submitted')) { 350 $form.prop('data-form-submitted', true); 351 352 return; 353 } 354 355 // Prevent default submission for subsequent clicks within 5 seconds 356 event.preventDefault(); 357 358 setTimeout(() => { 359 $form.prop('removeProp', 'data-form-submitted'); 360 $submitButton.removeClass('disabled'); // Re-enable after 5 seconds 361 }, 5000); 362 }); 363 364 /** 365 * This simply appends #preview to the action of the 366 * QR action when you click the Full Editor & Preview button 367 */ 368 $('#qr_full_editor').click(function() { 369 $('#qr_postform').attr('action', function(i, val) { 370 return val + '#preview'; 371 }); 372 }); 373 374 375 /** 376 * Make the display post links to use JS 377 */ 378 $('.display_post').click(function(e) { 379 // Do not follow the link 380 e.preventDefault(); 381 382 var postId = $(this).attr('data-post-id'); 383 $('#post_content' + postId).show(); 384 $('#profile' + postId).show(); 385 $('#post_hidden' + postId).hide(); 386 }); 387 388 /** 389 * Display hidden post on post review page 390 */ 391 $('.display_post_review').on('click', function(e) { 392 e.preventDefault(); 393 394 let $displayPostLink = $(this); 395 $displayPostLink.closest('.post-ignore').removeClass('post-ignore'); 396 $displayPostLink.hide(); 397 }); 398 399 /** 400 * Toggle the member search panel in memberlist.php. 401 * 402 * If user returns to search page after viewing results the search panel is automatically displayed. 403 * In any case the link will toggle the display status of the search panel and link text will be 404 * appropriately changed based on the status of the search panel. 405 */ 406 $('#member_search').click(function () { 407 var $memberlistSearch = $('#memberlist_search'); 408 409 $memberlistSearch.slideToggle('fast'); 410 phpbb.ajaxCallbacks.alt_text.call(this); 411 412 // Focus on the username textbox if it's available and displayed 413 if ($memberlistSearch.is(':visible')) { 414 $('#username').focus(); 415 } 416 return false; 417 }); 418 419 /** 420 * Automatically resize textarea 421 */ 422 $(function() { 423 var $textarea = $('textarea:not(#message-box textarea, .no-auto-resize)'); 424 phpbb.resizeTextArea($textarea, { minHeight: 75, maxHeight: 250 }); 425 phpbb.resizeTextArea($('textarea', '#message-box')); 426 }); 427 428 429 })(jQuery); // Avoid conflicts with other libraries
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jun 23 12:25:44 2024 | Cross-referenced by PHPXref 0.7.1 |