PageSourceSearch

https://www.freebeg.com/forum/jscripts/general.js?ver=1806

js freebeg.com collected 2026-09-24 10:01:15 UTC 15,709 bytes, 757 lines download raw bytes

1var MyBB = {
2	init: function()
3	{
4		$(function()
5		{
6			MyBB.pageLoaded();
7		});
8
9		return true;
10	},
11
12	pageLoaded: function()
13	{
14		expandables.init();
15
16		/* Create the Check All feature */
17		$('[name="allbox"]').each(function(key, value) {
18			var allbox = this;
19			var checked = $(this).is(':checked');
20			var checkboxes = $(this).closest('form').find(':checkbox').not('[name="allbox"]');
21
22			checkboxes.on('change', function() {
23				if(checked && !$(this).prop('checked'))
24				{
25					checked = false;
26					$(allbox).trigger('change', ['item']);
27				}
28			});
29
30			$(this).on('change', function(event, origin) {
31				checked = $(this).is(':checked');
32
33				if(typeof(origin) == "undefined")
34				{
35					checkboxes.each(function() {
36						if(checked != $(this).is(':checked'))
37						{
38							$(this).prop('checked', checked).trigger('change');
39						}
40					});
41				}
42			});
43		});
44
45		// Initialise "initial focus" field if we have one
46		var initialfocus = $(".initial_focus");
47		if(initialfocus.length)
48		{
49			initialfocus.trigger('focus');
50		}
51
52		if(typeof(use_xmlhttprequest) != "undefined" && use_xmlhttprequest == 1)
53		{
54			mark_read_imgs = $(".ajax_mark_read");
55			mark_read_imgs.each(function()
56			{
57				var element = $(this);
58				if(element.hasClass('forum_off') || element.hasClass('forum_offclose') || element.hasClass('forum_offlink') || element.hasClass('subforum_minioff') || element.hasClass('subforum_minioffclose') || element.hasClass('subforum_miniofflink') || (element.attr("title") && element.attr("title") == lang.no_new_posts)) return;
59
60				element.on('click', function()
61				{
62					MyBB.markForumRead(this);
63				});
64
65				element.css("cursor", "pointer");
66				if(element.attr("title"))
67				{
68					element.attr("title", element.attr("title") + " - ");
69				}
70				element.attr("title", element.attr("title") + lang.click_mark_read);
71			});
72		}
73
74		if(typeof $.modal !== "undefined")
75		{
76			$(document).on($.modal.OPEN, function(event, modal) {
77				$("body").css("overflow", "hidden");
78				if(initialfocus.length > 0)
79				{
80					initialfocus.trigger('focus');
81				}
82			});
83
84			$(document).on($.modal.CLOSE, function(event, modal) {
85				$("body").css("overflow", "auto");
86			});
87		}
88
89		$("a.referralLink").on('click', MyBB.showReferrals);
90
91		if($('.author_avatar').length)
92		{
93			$(".author_avatar img").on('error', function () {
94				$(this).unbind("error").closest('.author_avatar').remove();
95			});
96		}
97	},
98
99	popupWindow: function(url, options, root)
100	{
101		if(!options) options = { fadeDuration: 250, zIndex: (typeof modal_zindex !== 'undefined' ? modal_zindex : 9999) }
102		if(root != true)
103			url = rootpath + url;
104
105		$.get(url, function(html)
106		{
107			$(html).appendTo('body').modal(options);
108		});
109	},
110
111	prompt: function(message, options)
112	{
113		var defaults = { fadeDuration: 250, zIndex: (typeof modal_zindex !== 'undefined' ? modal_zindex : 9999) };
114		var buttonsText = '', title = '';
115
116		for (var i in options.buttons)
117		{
118			buttonsText += templates.modal_button.replace('__title__', options.buttons[i].title);
119		}
120
121		// Support passing custom title
122		if ($.isArray(message)) {
123			title = message[0];
124			message = message[1];
125		} else {
126			title = lang.confirm_title;
127		}
128
129		var html = templates.modal.replace('__buttons__', buttonsText).replace('__message__', message).replace('__title__', title);
130		var modal = $(html);
131		modal.modal($.extend(defaults, options));
132		var buttons = modal.find('.modal_buttons > .button');
133		buttons.on('click', function(e)
134		{
135			e.preventDefault();
136			var index = $(this).index();
137			if (options.submit(e, options.buttons[index].value) == false)
138				return;
139
140			$.modal.close();
141		});
142
143		if (buttons[0])
144		{
145			modal.on($.modal.OPEN, function()
146			{
147				$(buttons[0]).trigger('focus');
148			});
149		}
150
151		return modal;
152	},
153
154	deleteEvent: function(eid)
155	{
156		MyBB.prompt(deleteevent_confirm, {
157			buttons:[
158					{title: yes_confirm, value: true},
159					{title: no_confirm, value: false}
160			],
161			submit: function(e,v,m,f){
162				if(v == true)
163				{
164					var form = $("<form />",
165							   {
166									method: "post",
167									action: "calendar.php",
168									style: "display: none;"
169							   });
170
171					form.append(
172						$("<input />",
173						{
174							name: "action",
175							type: "hidden",
176							value: "do_deleteevent"
177						})
178					);
179
180					if(my_post_key)
181					{
182						form.append(
183							$("<input />",
184							{
185								name: "my_post_key",
186								type: "hidden",
187								value: my_post_key
188							})
189						);
190					}
191
192					form.append(
193						$("<input />",
194						{
195							name: "eid",
196							type: "hidden",
197							value: eid
198						})
199					);
200
201					form.append(
202						$("<input />",
203						{
204							name: "delete",
205							type: "hidden",
206							value: 1
207						})
208					);
209
210					$("body").append(form);
211					form.trigger('submit');
212				}
213			}
214		});
215	},
216
217	reputation: function(uid, pid)
218	{
219		if(!pid)
220		{
221			var pid = 0;
222		}
223
224		MyBB.popupWindow("/reputation.php?action=add&uid="+uid+"&pid="+pid+"&modal=1");
225	},
226
227	viewNotes: function(uid)
228	{
229		MyBB.popupWindow("/member.php?action=viewnotes&uid="+uid+"&modal=1");
230	},
231
232	getIP: function(pid)
233	{
234		MyBB.popupWindow("/moderation.php?action=getip&pid="+pid+"&modal=1");
235	},
236
237	getPMIP: function(pmid)
238	{
239		MyBB.popupWindow("/moderation.php?action=getpmip&pmid="+pmid+"&modal=1");
240	},
241
242	deleteReputation: function(uid, rid)
243	{
244		MyBB.prompt(delete_reputation_confirm, {
245			buttons:[
246					{title: yes_confirm, value: true},
247					{title: no_confirm, value: false}
248			],
249			submit: function(e,v,m,f){
250				if(v == true)
251				{
252					var form = $("<form />",
253					{
254						method: "post",
255						action: "reputation.php?action=delete",
256						style: "display: none;"
257					});
258
259					form.append(
260						$("<input />",
261						{
262							name: "rid",
263							type: "hidden",
264							value: rid
265						})
266					);
267
268					if(my_post_key)
269					{
270						form.append(
271							$("<input />",
272							{
273								name: "my_post_key",
274								type: "hidden",
275								value: my_post_key
276							})
277						);
278					}
279
280					form.append(
281						$("<input />",
282						{
283							name: "uid",
284							type: "hidden",
285							value: uid
286						})
287					);
288
289					$("body").append(form);
290					form.trigger('submit');
291				}
292			}
293		});
294
295		return false;
296	},
297
298	whoPosted: function(tid, sortby)
299	{
300		var sort = "", url, body;
301
302		if(typeof sortby === "undefined")
303		{
304			sortby = "";
305		}
306
307		if(sortby == "username")
308		{
309			sort = "&sort=" + sortby;
310		}
311		url = "/misc.php?action=whoposted&tid="+tid+sort+"&modal=1";
312
313		// if the modal is already open just replace the contents
314		if($.modal.isActive())
315		{
316			// don't waste a query if we are already sorted correctly
317			if(sortby == MyBB.whoPostedSort)
318			{
319				return;
320			}
321
322			MyBB.whoPostedSort = sortby;
323
324			$.get(rootpath + url, function(html)
325			{
326				// just replace the inner div
327				body = $(html).children("div");
328				$("div.modal").children("div").replaceWith(body);
329			});
330			return;
331		}
332		MyBB.whoPostedSort = "";
333		MyBB.popupWindow(url);
334	},
335
336	markForumRead: function(event)
337	{
338		var element = $(event);
339		if(!element.length)
340		{
341			return false;
342		}
343		var fid = element.attr("id").replace("mark_read_", "");
344		if(!fid)
345		{
346			return false;
347		}
348
349		$.ajax(
350		{
351			url: 'misc.php?action=markread&fid=' + fid + '&ajax=1&my_post_key=' + my_post_key,
352			async: true,
353        	success: function (request)
354        	{
355		  		MyBB.forumMarkedRead(fid, request);
356          	}
357		});
358	},
359
360	forumMarkedRead: function(fid, request)
361	{
362		if(request == 1)
363		{
364			var markreadfid = $("#mark_read_"+fid);
365			if(markreadfid.hasClass('subforum_minion'))
366			{
367				markreadfid.removeClass('subforum_minion').addClass('subforum_minioff');
368			}
369			else
370			{
371				markreadfid.removeClass('forum_on').addClass('forum_off');
372			}
373			markreadfid.css("cursor", "default").attr("title", lang.no_new_posts);
374		}
375	},
376
377	unHTMLchars: function(text)
378	{
379		text = text.replace(/&lt;/g, "<");
380		text = text.replace(/&gt;/g, ">");
381		text = text.replace(/&nbsp;/g, " ");
382		text = text.replace(/&quot;/g, "\"");
383		text = text.replace(/&amp;/g, "&");
384		return text;
385	},
386
387	HTMLchars: function(text)
388	{
389		text = text.replace(new RegExp("&(?!#[0-9]+;)", "g"), "&amp;");
390		text = text.replace(/</g, "&lt;");
391		text = text.replace(/>/g, "&gt;");
392		text = text.replace(/"/g, "&quot;");
393		return text;
394	},
395
396	changeLanguage: function()
397	{
398		form = $("#lang_select");
399		if(!form.length)
400		{
401			return false;
402		}
403		form.trigger('submit');
404	},
405
406	changeTheme: function()
407	{
408		form = $("#theme_select");
409		if(!form.length)
410		{
411			return false;
412		}
413		form.trigger('submit');
414	},
415
416	detectDSTChange: function(timezone_with_dst)
417	{
418		var date = new Date();
419		var local_offset = date.getTimezoneOffset() / 60;
420		if(Math.abs(parseInt(timezone_with_dst) + local_offset) == 1)
421		{
422			$.ajax(
423			{
424				url: 'misc.php?action=dstswitch&ajax=1',
425				async: true,
426				method: 'post',
427	          	error: function (request)
428	          	{
429	          		if(use_xmlhttprequest != 1)
430	                {
431						var form = $("<form />",
432						           {
433						           		method: "post",
434						           		action: "misc.php",
435						           		style: "display: none;"
436						           });
437
438						form.append(
439						    $("<input />",
440							{
441								name: "action",
442								type: "hidden",
443								value: "dstswitch"
444							})
445						);
446
447						$("body").append(form);
448						form.trigger('submit');
449	                }
450	            }
451			});
452		}
453	},
454
455	dismissPMNotice: function(bburl)
456	{
457		var pm_notice = $("#pm_notice");
458		if(!pm_notice.length)
459		{
460			return false;
461		}
462
463		if(use_xmlhttprequest != 1)
464		{
465			return true;
466		}
467
468		$.ajax(
469		{
470			type: 'post',
471			url: bburl + 'private.php?action=dismiss_notice',
472			data: { ajax: 1, my_post_key: my_post_key },
473			async: true
474		});
475		pm_notice.remove();
476		return false;
477	},
478
479	submitReputation: function(uid, pid, del)
480	{
481		// Get form, serialize it and send it
482		var datastring = $(".reputation_"+uid+"_"+pid).serialize();
483
484		if(del == 1)
485			datastring = datastring + '&delete=1';
486
487		$.ajax({
488			type: "POST",
489			url: "reputation.php?modal=1",
490			data: datastring,
491			dataType: "html",
492			success: function(data) {
493				// Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
494				$(".modal_"+uid+"_"+pid).fadeOut('slow', function() {
495					$(".modal_"+uid+"_"+pid).html(data);
496					$(".modal_"+uid+"_"+pid).fadeIn('slow');
497					$(".modal").fadeIn('slow');
498				});
499			},
500			error: function(){
501				  alert(lang.unknown_error);
502			}
503		});
504
505		return false;
506	},
507
508	deleteAnnouncement: function(data)
509	{
510		MyBB.prompt(announcement_quickdelete_confirm, {
511			buttons:[
512					{title: yes_confirm, value: true},
513					{title: no_confirm, value: false}
514			],
515			submit: function(e,v,m,f){
516				if(v == true)
517				{
518					window.location=data.href.replace('action=delete_announcement','action=do_delete_announcement');
519				}
520			}
521		});
522
523		return false;
524	},
525
526	showReferrals: function(e)
527	{
528		var idPieces, uid;
529
530		e.preventDefault();
531		
532		if(typeof this.id == "undefined")
533		{
534			return false;
535		}
536
537		idPieces = this.id.split("_");
538		uid = parseInt(idPieces[idPieces.length - 1], 10);
539
540		if(uid <= 0)
541		{
542			return false;
543		}
544
545		MyBB.popupWindow("/xmlhttp.php?action=get_referrals&uid="+uid);
546	},
547
548	// Fixes https://github.com/mybb/mybb/issues/1232
549	select2: function()
550	{
551		if(typeof $.fn.select2 !== "undefined")
552		{
553			$.extend($.fn.select2.defaults, {
554				formatMatches: function (matches) {
555					if(matches == 1)
556					{
557						return lang.select2_match;
558					}
559					else
560					{
561						return lang.select2_matches.replace('{1}',matches);
562					}
563				},
564				formatNoMatches: function () {
565					return lang.select2_nomatches;
566				},
567				formatInputTooShort: function (input, min) {
568					var n = min - input.length;
569					if( n == 1)
570					{
571						return lang.select2_inputtooshort_single;
572					}
573					else
574					{
575						return lang.select2_inputtooshort_plural.replace('{1}', n);
576					}
577				},
578				formatInputTooLong: function (input, max) {
579					var n = input.length - max;
580					if( n == 1)
581					{
582						return lang.select2_inputtoolong_single;
583					}
584					else
585					{
586						return lang.select2_inputtoolong_plural.replace('{1}', n);
587					}
588				},
589				formatSelectionTooBig: function (limit) {
590					if( limit == 1)
591					{
592						return lang.select2_selectiontoobig_single;
593					}
594					else
595					{
596						return lang.select2_selectiontoobig_plural.replace('{1}', limit);
597					}
598				},
599				formatLoadMore: function (pageNumber) {
600					return lang.select2_loadmore;
601				},
602				formatSearching: function () {
603					return lang.select2_searching;
604				}
605			});
606		}
607	}
608};
609
610var Cookie = {
611	get: function(name)
612	{
613		name = cookiePrefix + name;
614		return Cookies.get(name);
615	},
616
617	set: function(name, value, expires)
618	{
619		name = cookiePrefix + name;
620		if(!expires)
621		{
622			expires = 315360000; // 10*365*24*60*60 => 10 years
623		}
624
625		expire = new Date();
626		expire.setTime(expire.getTime()+(expires*1000));
627
628		options = {
629			expires: expire,
630			path: cookiePath,
631			domain: cookieDomain,
632			secure: cookieSecureFlag == true,
633		};
634
635		return Cookies.set(name, value, options);
636	},
637
638	unset: function(name)
639	{
640		name = cookiePrefix + name;
641
642		options = {
643			path: cookiePath,
644			domain: cookieDomain
645		};
646		return Cookies.remove(name, options);
647	}
648};
649
650var expandables = {
651	init: function()
652	{
653		var expanders = $(".expcolimage .expander");
654		if(expanders.length)
655		{
656			expanders.each(function()
657			{
658        		var expander = $(this);
659				if(!expander || expander.attr("id") == false)
660				{
661					return;
662				}
663
664				expander.on('click', function()
665				{
666					expandables.expandCollapse($(this));
667				});
668
669				expander.css("cursor", MyBB.browser == "ie" ? "hand" : "pointer");
670			});
671		}
672	},
673
674	expandCollapse: function(element)
675	{
676		var controls = element.attr("id").replace("_img", ""),
677			expandedItem = $("#"+controls+"_e");
678
679		if(expandedItem.length)
680		{
681			var expState = + !expandedItem.is(":hidden"),
682				expcolImg = element.attr("src"),			
683				expText = [lang.expcol_collapse, lang.expcol_expand];
684
685			expandedItem.toggle("fast", this.expCallback(controls, expState));
686			
687			element.attr({
688				"alt": expText[expState],
689				"title": expText[expState],
690				"src": expState ? expcolImg.replace('collapse.', 'collapse_collapsed.') : expcolImg.replace('collapse_collapsed.', 'collapse.')
691			})
692			.parents(':eq(1)').toggleClass(element.parents(':eq(1)').hasClass('thead') ? 'thead_collapsed' : 'tcat_collapse_collapsed');
693			this.saveCollapsed(controls, expState);
694		}
695		return true;
696	},
697
698	saveCollapsed: function(id, add)
699	{
700		var saved = [];
701		var newCollapsed = [];
702		var collapsed = Cookie.get('collapsed');
703
704		if(collapsed)
705		{
706			saved = collapsed.split("|");
707
708			$.each(saved, function(intIndex, objValue)
709			{
710				if(objValue != id && objValue != "")
711				{
712					newCollapsed[newCollapsed.length] = objValue;
713				}
714			});
715		}
716
717		if(add == 1)
718		{
719			newCollapsed[newCollapsed.length] = id;
720		}
721		Cookie.set('collapsed', newCollapsed.join("|"));
722	},
723
724	// Dummy callback function to override by theme developers
725	expCallback: function(id, state)
726	{
727		//console.log("id:"+id+" state:"+state);
728	}
729};
730
731/* Lang this! */
732var lang = {
733
734};
735
736/* add keepelement to jquery-modal plugin */
737(function($) {
738	if(typeof $.modal != 'undefined')
739	{
740		$.modal.defaults.keepelement = false;
741
742		$.modal.prototype.oldCloseFunction = $.modal.prototype.close;
743		$.modal.prototype.close = function()
744		{
745			this.oldCloseFunction();
746
747			// Deletes the element (multi-modal feature: e.g. when you click on multiple report buttons, you will want to see different content for each)
748			if(!this.options.keepelement)
749			{
750				this.$elm.remove();
751			}
752		};
753	}
754})(jQuery);
755
756
757MyBB.init();

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.