PageSourceSearch

https://info-mac.org/styles/basic_infomac/template/ajax.js?assets_version=23

js info-mac.org collected 2026-10-02 11:32:18 UTC 12,234 bytes, 405 lines download raw bytes

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
8phpbb.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*/
48phpbb.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
101phpbb.addAjaxCallback('notification.mark_all_read', function(res) {
102	if (typeof res.success !== 'undefined') {
103		phpbb.markNotifications($('#notification_list li.bg3'), 0);
104		phpbb.closeDarkenWrapper(3000);
105	}
106});
107
108// This callback will mark a notification read
109phpbb.addAjaxCallback('notification.mark_read', function(res) {
110	if (typeof res.success !== 'undefined') {
111		var unreadCount = Number($('#notification_list_button strong').html()) - 1;
112		phpbb.markNotifications($(this).parent('li.bg3'), unreadCount);
113	}
114});
115
116/**
117 * Mark notification popup rows as read.
118 *
119 * @param {jQuery} $popup jQuery object(s) to mark read.
120 * @param {int} unreadCount The new unread notifications count.
121 */
122phpbb.markNotifications = function($popup, unreadCount) {
123	// Remove the unread status.
124	$popup.removeClass('bg3');
125	$popup.find('a.mark_read').remove();
126
127	// Update the notification link to the real URL.
128	$popup.each(function() {
129		var link = $(this).find('a');
130		link.attr('href', link.attr('data-real-url'));
131	});
132
133	// Update the unread count.
134	$('strong', '#notification_list_button').html(unreadCount);
135	// Remove the Mark all read link and hide notification count if there are no unread notifications.
136	if (!unreadCount) {
137		$('#mark_all_notifications').remove();
138		$('#notification_list_button > strong').addClass('hidden');
139	}
140
141	// Update page title
142	var $title = $('title');
143	var originalTitle = $title.text().replace(/(\((\d+)\))/, '');
144	$title.text((unreadCount ? '(' + unreadCount + ')' : '') + originalTitle);
145};
146
147// This callback finds the post from the delete link, and removes it.
148phpbb.addAjaxCallback('post_delete', function() {
149	var $this = $(this),
150		postId;
151
152	if ($this.attr('data-refresh') === undefined) {
153		postId = $this[0].href.split('&p=')[1];
154		var post = $this.parents('#p' + postId).css('pointer-events', 'n
154one');
155		if (post.hasClass('bg1') || post.hasClass('bg2')) {
156			var posts1 = post.nextAll('.bg1');
157			post.nextAll('.bg2').removeClass('bg2').addClass('bg1');
158			posts1.removeClass('bg1').addClass('bg2');
159		}
160		post.fadeOut(function() {
161			$(this).remove();
162		});
163	}
164});
165
166// This callback removes the approve / disapprove div or link.
167phpbb.addAjaxCallback('post_visibility', function(res) {
168	var remove = (res.visible) ? $(this) : $(this).parents('.post');
169	$(remove).css('pointer-events', 'none').fadeOut(function() {
170		$(this).remove();
171	});
172
173	if (res.visible) {
174		// Remove the "Deleted by" message from the post on restoring.
175		remove.parents('.post').find('.post_deleted_msg').css('pointer-events', 'none').fadeOut(function() {
176			$(this).remove();
177		});
178	}
179});
180
181// This removes the parent row of the link or form that fired the callback.
182phpbb.addAjaxCallback('row_delete', function() {
183	$(this).parents('tr').remove();
184});
185
186// This handles friend / foe additions removals.
187phpbb.addAjaxCallback('zebra', function(res) {
188	var zebra;
189
190	if (res.success) {
191		zebra = $('.zebra');
192		zebra.first().html(res.MESSAGE_TEXT);
193		zebra.not(':first').html(' ').prev().html(' ');
194	}
195});
196
197/**
198 * This callback updates the poll results after voting.
199 */
200phpbb.addAjaxCallback('vote_poll', function(res) {
201	if (typeof res.success !== 'undefined') {
202        var poll = $(this).closest('.topic_poll');
203		var panel = poll.find('.panel');
204		var resultsVisible = poll.find('dl:first-child .resultbar').is(':visible');
205		var mostVotes = 0;
206
207		// Set min-height to prevent the page from jumping when the content changes
208		var updatePanelHeight = function (height) {
209			height = (typeof height === 'undefined') ? panel.find('.inner').outerHeight() : height;
210			panel.css('min-height', height);
211		};
212		updatePanelHeight();
213
214		// Remove the View results link
215		if (!resultsVisible) {
216			poll.find('.poll_view_results').hide(500);
217		}
218
219		if (!res.can_vote) {
220			poll.find('.polls, .poll_max_votes, .poll_vote, .poll_option_select').fadeOut(500, function () {
221				poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show();
222			});
223		} else {
224			// If the user can still vote, simply slide down the results
225			poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500);
226		}
227
228		// Get the votes count of the highest poll option
229		poll.find('[data-poll-option-id]').each(function() {
230			var option = $(this);
231			var optionId = option.attr('data-poll-option-id');
232			mostVotes = (res.vote_counts[optionId] >= mostVotes) ? res.vote_counts[optionId] : mostVotes;
233		});
234
235		// Update the total votes count
236		poll.find('.poll_total_vote_cnt').html(res.total_votes);
237
238		// Update each option
239		poll.find('[data-poll-option-id]').each(function() {
240			var $this = $(this);
241			var optionId = $this.attr('data-poll-option-id');
242			var voted = (typeof res.user_votes[optionId] !== 'undefined');
243			var mostVoted = (res.vote_counts[optionId] === mostVotes);
244			var percent = (!res.total_votes) ? 0 : Math.round((res.vote_counts[optionId] / res.total_votes) * 100);
245			var percentRel = (mostVotes === 0) ? 0 : Math.round((res.vote_counts[optionId] / mostVotes) * 100);
246			var altText;
247
248			altText = $this.attr('data-alt-text');
249			if (voted) {
250				$this.attr('title', $.trim(altText));
251			} else {
252				$this.attr('title', '');
253			};
254			$this.toggleClass('voted', voted);
255			$this.toggleClass('most-votes', mostVoted);
256
257			// Update the bars
258			var bar = $this.find('.resultbar div');
259			var barTimeLapse = (res.can_vote) ? 500 : 1500;
260			var newBarClass = (percent === 100) ? 'pollbar5' : 'pollbar' + (Math.floor(percent / 20) + 1);
261
262			setTimeout(function () {
263				bar.animate({ width: percentRel + '%' }, 500)
264					.removeClass('pollbar1 pollbar2 pollbar3 pollbar4 pollbar5')
265					.addClass(newBarClass)
266					.html(res.vote_counts[optionId]);
267
268				var percentText = percent ? percent + '%' : res.NO_VOTES;
269				$this.find('.poll_option_percent').html(percentText);
270			}, barTimeLapse);
271		});
272
273		if (!res.can_vote) {
274			poll.find('.polls').delay(400).fadeIn(500);
275		}
276
277		// Display "Your vote has been cast." message. Disappears after 5 seconds.
278		var confirmationDelay = (res.can_vote) ? 300 : 900;
279		poll.find('.vote-submitted').delay(confirmationDelay).slideDown(200, function() {
280			if (resultsVisible) {
281				updatePanelHeight();
282			}
283
284			$(this).delay(5000).fadeOut(500, function() {
285				resizePanel(300);
286			});
287		});
288
289		// Remove the gap resulting from removing options
290		setTimeout(function() {
291			resizePanel(500);
292		}, 1500);
293
294		var resizePanel = function (time) {
295			var panelHeight = panel.height();
296			var innerHeight = panel.find('.inner').outerHeight();
297
298			if (panelHeight !== innerHeight) {
299				panel.css({ minHeight: '', height: panelHeight })
300					.animate({ height: innerHeight }, time, function () {
301						panel.css({ minHeight: innerHeight, height: '' });
302					});
303			}
304		};
305	}
306});
307
308/**
309 * Show poll results when clicking View results link.
310 */
311$('.poll_view_results a').click(function(e) {
312	// Do not follow the link
313	e.preventDefault();
314
315	var $poll = $(this).parents('.topic_poll');
316
317	$poll.find('.resultbar, .poll_option_percent, .poll_total_votes').show(500);
318	$poll.find('.poll_view_results').hide(500);
319});
320
321$('[data-ajax]').each(function() {
322	var $this = $(this);
323	var ajax = $this.attr('data-ajax');
324	var filter = $this.attr('data-filter');
325
326	if (ajax !== 'false') {
327		var fn = (ajax !== 'true') ? ajax : null;
328		filter = (filter !== undefined) ? phpbb.getFunctionByName(filter) : null;
329
330		phpbb.ajaxify({
331			selector: this,
332			refresh: $this.attr('data-refresh') !== undefined,
333			filter: filter,
334			callback: fn
335		});
336	}
337});
338
339
340/**
341 * This simply appends #preview to the action of the
342 * QR action when you click the Full Editor & Preview button
343 */
344$('#qr_full_editor').click(function() {
345	$('#qr_postform').attr('action', function(i, val) {
346		return val + '#preview';
347	});
348});
349
350
351/**
352 * Make the display post links to use JS
353 */
354$('.display_post').click(function(e) {
355	// Do not follow the link
356	e.preventDefault();
357
358	var postId = $(this).attr('data-post-id');
359	$('#post_content' + postId).show();
360	$('#profile' + postId).show();
361	$('#post_hidden' + postId).hide();
362});
363
364/**
365 * Display hidden post on post review page
366 */
367$('.display_post_review').on('click', function(e) {
368	e.preventDefault();
369
370	let $displayPostLink = $(this);
371	$displayPostLink.closest('.post-ignore').removeClass('post-ignore');
372	$displayPostLink.hide();
373});
374
375/**
376* Toggle the member search panel in memberlist.php.
377*
378* If user returns to search page after viewing results the search panel is automatically displayed.
379* In any case the link will toggle the display status of the search panel and link text will be
380* appropriately changed based on the status of the search panel.
381*/
382$('#member_search').click(function () {
383	var $memberlistSearch = $('#memberlist_search');
384
385	$memberlistSearch.slideToggle('fast');
386	phpbb.ajaxCallbacks.alt_text.call(this);
387
388	// Focus on the username textbox if it's available and displayed
389	if ($memberlistSearch.is(':visible')) {
390		$('#username').focus();
391	}
392	return false;
393});
394
395/**
396* Automatically resize textarea
397*/
398$(function() {
399	var $textarea = $('textarea:not(#message-box textarea, .no-auto-resize)');
400	phpbb.resizeTextArea($textarea, { minHeight: 75, maxHeight: 250 });
401	phpbb.resizeTextArea($('textarea', '#message-box'));
402});
403
404
405})(jQuery); // Avoid conflicts with other libraries

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.