| 
									
										
										
										
											2020-09-27 16:36:33 +00:00
										 |  |  | // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-01-19 06:05:23 +00:00
										 |  |  |  * Contains functions for bootstrap modal handling. | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | $(document).ready(function(){ | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Clear bs modal on close.
 | 
					
						
							|  |  |  | 	// We need this to prevent that the modal displays old content.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	$('body, footer').on('hidden.bs.modal', '.modal', function () { | 
					
						
							|  |  |  | 		$(this).removeData('bs.modal'); | 
					
						
							|  |  |  | 		$("#modal-title").empty(); | 
					
						
							|  |  |  | 		$('#modal-body').empty(); | 
					
						
							| 
									
										
										
										
											2017-03-25 20:10:57 +00:00
										 |  |  | 		// Remove the file browser from jot (else we would have problems
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// with AjaxUpload.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		$(".fbrowser").remove(); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Remove the AjaxUpload element.
 | 
					
						
							| 
									
										
										
										
											2018-08-20 04:29:50 +00:00
										 |  |  | 		$(".ajaxbutton-wrapper").remove(); | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Clear bs modal on close.
 | 
					
						
							|  |  |  | 	// We need this to prevent that the modal displays old content.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	$('body').on('hidden.bs.modal', '#jot-modal', function () { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Restore cached jot at its hidden position ("#jot-content").
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 		$("#jot-content").append(jotcache); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Clear the jotcache.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 07:40:50 +00:00
										 |  |  | 		jotcache = ''; | 
					
						
							| 
									
										
										
										
											2019-02-02 02:12:36 +00:00
										 |  |  | 		// Destroy the attachment linkPreviw for Jot.
 | 
					
						
							|  |  |  | 		if (typeof linkPreview === 'object') { | 
					
						
							|  |  |  | 			linkPreview.destroy(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Add Colorbox for viewing Network page images.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	//var cBoxClasses = new Array();
 | 
					
						
							| 
									
										
										
										
											2016-05-16 22:35:32 +00:00
										 |  |  | 	$("body").on("click", ".wall-item-body a img", function(){ | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		var aElem = $(this).parent(); | 
					
						
							|  |  |  | 		var imgHref = aElem.attr("href"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// We need to make sure we only put a Colorbox on links to Friendica images.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		// We'll try to do this by looking for links of the form
 | 
					
						
							|  |  |  | 		// .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// that that will be unique enough.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Add a unique class to all the images of a certain post, to allow scrolling through
 | 
					
						
							|  |  |  | 			var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox"; | 
					
						
							|  |  |  | 			$(this).addClass(cBoxClass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //			if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
 | 
					
						
							|  |  |  | //				cBoxClasses.push(cBoxClass);
 | 
					
						
							|  |  |  | //			}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			aElem.colorbox({ | 
					
						
							|  |  |  | 				maxHeight: '90%', | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 				photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo.
 | 
					
						
							|  |  |  | 				rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0].
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Navbar login.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 07:58:26 +00:00
										 |  |  | 	$("body").on("click", "#nav-login", function(e){ | 
					
						
							|  |  |  | 		e.preventDefault(); | 
					
						
							|  |  |  | 		Dialog.show(this.href, this.dataset.originalTitle || this.title); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Jot nav menu..
 | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	$("body").on("click", "#jot-modal .jot-nav li .jot-nav-lnk", function(e){ | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		e.preventDefault(); | 
					
						
							|  |  |  | 		toggleJotNav(this); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Bookmarklet page needs an jot modal which appears automatically.
 | 
					
						
							| 
									
										
										
										
											2016-06-15 22:27:45 +00:00
										 |  |  | 	if(window.location.pathname.indexOf("/bookmarklet") >=0 && $("#jot-modal").length){ | 
					
						
							| 
									
										
										
										
											2016-06-15 22:20:00 +00:00
										 |  |  | 		jotShow(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 	// Open filebrowser for elements with the class "image-select"
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// The following part handles the filebrowser for field_fileinput.tpl.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 07:40:50 +00:00
										 |  |  | 	$("body").on("click", ".image-select", function(){ | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Set a extra attribute to mark the clicked button.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 		this.setAttribute("image-input", "select"); | 
					
						
							|  |  |  | 		Dialog.doImageBrowser("input"); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Insert filebrowser images into the input field (field_fileinput.tpl).
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 	$("body").on("fbrowser.image.input", function(e, filename, embedcode, id, img) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Select the clicked button by it's attribute.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 07:40:50 +00:00
										 |  |  | 		var elm = $("[image-input='select']"); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Select the input field which belongs to this button.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 		var input = elm.parent(".input-group").children("input"); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Remove the special indicator attribut from the button.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 		elm.removeAttr("image-input"); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Insert the link from the image into the input field.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:30:09 +00:00
										 |  |  | 		input.val(img); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2019-06-03 12:31:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Generic delegated event to open an anchor URL in a modal.
 | 
					
						
							|  |  |  | 	// Used in the hovercard.
 | 
					
						
							|  |  |  | 	document.getElementsByTagName('body')[0].addEventListener('click', function(e) { | 
					
						
							|  |  |  | 		var target = e.target; | 
					
						
							|  |  |  | 		while (target) { | 
					
						
							|  |  |  | 			if (target.matches && target.matches('a.add-to-modal')) { | 
					
						
							|  |  |  | 				addToModal(target.href); | 
					
						
							|  |  |  | 				e.preventDefault(); | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			target = target.parentNode || null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Overwrite Dialog.show from main js to load the filebrowser into a bs modal.
 | 
					
						
							| 
									
										
										
										
											2016-11-25 18:13:40 +00:00
										 |  |  | Dialog.show = function(url, title) { | 
					
						
							| 
									
										
										
										
											2016-11-25 18:18:01 +00:00
										 |  |  | 	if (typeof(title) === 'undefined') { | 
					
						
							| 
									
										
										
										
											2016-11-25 18:13:40 +00:00
										 |  |  | 		title = ""; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	var modal = $('#modal').modal(); | 
					
						
							| 
									
										
										
										
											2016-06-11 07:58:26 +00:00
										 |  |  | 	modal.find("#modal-header h4").html(title); | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	modal | 
					
						
							|  |  |  | 		.find('#modal-body') | 
					
						
							|  |  |  | 		.load(url, function (responseText, textStatus) { | 
					
						
							|  |  |  | 			if ( textStatus === 'success' ||  | 
					
						
							|  |  |  | 				textStatus === 'notmodified')  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				modal.show(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				$(function() {Dialog._load(url);}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Overwrite the function _get_url from main.js.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | Dialog._get_url = function(type, name, id) { | 
					
						
							|  |  |  | 	var hash = name; | 
					
						
							|  |  |  | 	if (id !== undefined) hash = hash + "-" + id; | 
					
						
							| 
									
										
										
										
											2019-04-26 02:06:27 +00:00
										 |  |  | 	return "fbrowser/"+type+"/?mode=none&theme=frio#"+hash; | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Does load the filebrowser into the jot modal.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | Dialog.showJot = function() { | 
					
						
							|  |  |  | 	var type = "image"; | 
					
						
							|  |  |  | 	var name = "main"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var url = Dialog._get_url(type, name); | 
					
						
							|  |  |  | 	if(($(".modal-body #jot-fbrowser-wrapper .fbrowser").length) < 1 ) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Load new content to fbrowser window.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 		$("#jot-fbrowser-wrapper").load(url,function(responseText, textStatus){ | 
					
						
							|  |  |  | 			if ( textStatus === 'success' ||  | 
					
						
							|  |  |  | 				textStatus === 'notmodified')  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				$(function() {Dialog._load(url);}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Init the filebrowser after page load.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | Dialog._load = function(url) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Get nickname & filebrowser type from the modal content.
 | 
					
						
							| 
									
										
										
										
											2019-11-30 15:48:23 +00:00
										 |  |  | 	let filebrowser = document.getElementById('filebrowser'); | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Try to fetch the hash form the url.
 | 
					
						
							| 
									
										
										
										
											2019-11-30 15:48:23 +00:00
										 |  |  | 	let match = url.match(/fbrowser\/[a-z]+\/.*(#.*)/); | 
					
						
							|  |  |  | 	if (!filebrowser || match === null) { | 
					
						
							|  |  |  | 		return; //not fbrowser
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Initialize the filebrowser.
 | 
					
						
							| 
									
										
										
										
											2018-04-21 12:05:40 +00:00
										 |  |  | 	loadScript("view/js/ajaxupload.js"); | 
					
						
							| 
									
										
										
										
											2019-11-30 15:48:23 +00:00
										 |  |  | 	loadScript("view/theme/frio/js/filebrowser.js", function() { | 
					
						
							|  |  |  | 		FileBrowser.init(filebrowser.dataset.nickname, filebrowser.dataset.type, match[1]); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-01-19 06:05:23 +00:00
										 |  |  |  * Add first element with the class "heading" as modal title | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  |  *  | 
					
						
							|  |  |  |  * Note: this should be really done in the template | 
					
						
							|  |  |  |  * and is the solution where we havent done it until this | 
					
						
							|  |  |  |  * moment or where it isn't possible because of design | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function loadModalTitle() { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Clear the text of the title.
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:33:12 +00:00
										 |  |  | 	$("#modal-title").empty(); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Hide the first element with the class "heading" of the modal body.
 | 
					
						
							| 
									
										
										
										
											2016-05-19 23:50:56 +00:00
										 |  |  | 	$("#modal-body .heading").first().hide(); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-12 16:23:10 +00:00
										 |  |  | 	var title = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Get the text of the first element with "heading" class.
 | 
					
						
							| 
									
										
										
										
											2016-06-12 16:23:10 +00:00
										 |  |  | 	title = $("#modal-body .heading").first().text(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// for event modals we need some speacial handling
 | 
					
						
							|  |  |  | 	if($("#modal-body .event-wrapper .event-summary").length) { | 
					
						
							|  |  |  | 		title = '<i class="fa fa-calendar" aria-hidden="true"></i> '; | 
					
						
							|  |  |  | 		var eventsum = $("#modal-body .event-wrapper .event-summary").text(); | 
					
						
							|  |  |  | 		title = title + eventsum; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// And append it to modal title.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 	if (title!=="") { | 
					
						
							|  |  |  | 		$("#modal-title").append(title); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:30:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * This function loads html content from a friendica page into a modal. | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @param {string} url The url with html content. | 
					
						
							|  |  |  |  * @param {string} id The ID of a html element (can be undefined). | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function addToModal(url, id) { | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 	var char = qOrAmp(url); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 07:40:50 +00:00
										 |  |  | 	url = url + char + 'mode=none'; | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 	var modal = $('#modal').modal(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:30:07 +00:00
										 |  |  | 	// Only search for an element if we have an ID.
 | 
					
						
							|  |  |  | 	if (typeof id !== "undefined") { | 
					
						
							|  |  |  | 		url = url + " div#" + id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 	modal | 
					
						
							|  |  |  | 		.find('#modal-body') | 
					
						
							|  |  |  | 		.load(url, function (responseText, textStatus) { | 
					
						
							|  |  |  | 			if ( textStatus === 'success' ||  | 
					
						
							|  |  |  | 				textStatus === 'notmodified')  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				modal.show(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 				//Get first element with the class "heading"
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 				//and use it as title.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 				loadModalTitle(); | 
					
						
							| 
									
										
										
										
											2018-04-24 15:33:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// We need to initialize autosize again for new
 | 
					
						
							|  |  |  | 				// modal conent.
 | 
					
						
							|  |  |  | 				autosize($('.modal .text-autosize')); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-06-11 07:40:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 15:30:07 +00:00
										 |  |  | // Add an element (by its id) to a bootstrap modal.
 | 
					
						
							| 
									
										
										
										
											2016-07-27 17:53:22 +00:00
										 |  |  | function addElmToModal(id) { | 
					
						
							|  |  |  | 	var elm = $(id).html(); | 
					
						
							|  |  |  | 	var modal = $('#modal').modal(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	modal | 
					
						
							|  |  |  | 		.find('#modal-body') | 
					
						
							|  |  |  | 		.append(elm) | 
					
						
							|  |  |  | 		.modal.show; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	loadModalTitle(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Function to load the html from the edit post page into
 | 
					
						
							|  |  |  | // the jot modal.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | function editpost(url) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Next to normel posts the post can be an event post. The event posts don't
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	// use the normal Jot modal. For event posts we will use a normal modal
 | 
					
						
							|  |  |  | 	// But first we have to test if the url links to an event. So we will split up
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// the url in its parts.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	var splitURL = parseUrl(url); | 
					
						
							|  |  |  | 	// Test if in the url path containing "events/event". If the path containing this
 | 
					
						
							|  |  |  | 	// expression then we will call the addToModal function and exit this function at
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// this point.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	if (splitURL.path.indexOf('events/event') > -1) { | 
					
						
							|  |  |  | 		addToModal(splitURL.path); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 	var modal = $('#jot-modal').modal(); | 
					
						
							| 
									
										
										
										
											2016-08-04 12:33:08 +00:00
										 |  |  | 	url = url + " #jot-sections"; | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 08:33:20 +00:00
										 |  |  | 	$(".jot-nav .jot-perms-lnk").parent("li").addClass("hidden"); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-04 12:33:08 +00:00
										 |  |  | 	// For editpost we load the modal html of "jot-sections" of the edit page. So we would have two jot forms in
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	// the page html. To avoid js conflicts we store the original jot in the variable jotcache.
 | 
					
						
							|  |  |  | 	// After closing the modal original jot should be restored at its orginal position in the html structure.
 | 
					
						
							| 
									
										
										
										
											2016-08-04 12:33:08 +00:00
										 |  |  | 	jotcache = $("#jot-content > #jot-sections"); | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Remove the original Jot as long as the edit Jot is open.
 | 
					
						
							| 
									
										
										
										
											2020-10-10 22:42:18 +00:00
										 |  |  | 	jotcache.detach(); | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Add the class "edit" to the modal to have some kind of identifier to
 | 
					
						
							|  |  |  | 	// have the possibility to e.g. put special event-listener.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	$("#jot-modal").addClass("edit-jot"); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	jotreset(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	modal | 
					
						
							| 
									
										
										
										
											2016-06-27 08:33:20 +00:00
										 |  |  | 		.find('#jot-modal-content') | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 		.load(url, function (responseText, textStatus) { | 
					
						
							|  |  |  | 			if ( textStatus === 'success' ||  | 
					
						
							|  |  |  | 				textStatus === 'notmodified')  | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 				// get the item type and hide the input for title and category if it isn't needed.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 				var type = $(responseText).find("#profile-jot-form input[name='type']").val(); | 
					
						
							|  |  |  | 				if(type === "wall-comment" || type === "remote-comment") | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 					// Hide title and category input fields because we don't.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 					$("#profile-jot-form #jot-title-wrap").hide(); | 
					
						
							|  |  |  | 					$("#profile-jot-form #jot-category-wrap").hide(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				modal.show(); | 
					
						
							|  |  |  | 				$("#jot-popup").show(); | 
					
						
							| 
									
										
										
										
											2019-02-02 02:12:36 +00:00
										 |  |  | 				linkPreview = $('#profile-jot-text').linkPreview(); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Remove content from the jot modal.
 | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | function jotreset() { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Clear bs modal on close.
 | 
					
						
							|  |  |  | 	// We need this to prevent that the modal displays old content.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	$('body').on('hidden.bs.modal', '#jot-modal.edit-jot', function () { | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 		$(this).removeData('bs.modal'); | 
					
						
							| 
									
										
										
										
											2016-06-27 08:33:20 +00:00
										 |  |  | 		$(".jot-nav .jot-perms-lnk").parent("li").removeClass("hidden"); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | 		$("#profile-jot-form #jot-title-wrap").show(); | 
					
						
							|  |  |  | 		$("#profile-jot-form #jot-category-wrap").show(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Remove the "edit-jot" class so we can the standard behavior on close.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 		$("#jot-modal.edit-jot").removeClass("edit-jot"); | 
					
						
							| 
									
										
										
										
											2016-06-27 08:33:20 +00:00
										 |  |  | 		$("#jot-modal-content").empty(); | 
					
						
							| 
									
										
										
										
											2016-06-08 18:53:01 +00:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-05-06 14:48:06 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // Give the active "jot-nav" list element the class "active".
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | function toggleJotNav (elm) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Get the ID of the tab panel which should be activated.
 | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	var tabpanel = elm.getAttribute("aria-controls"); | 
					
						
							|  |  |  | 	var cls = hasClass(elm, "jot-nav-lnk-mobile"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Select all li of jot-nav and remove the active class.
 | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	$(elm).parent("li").siblings("li").removeClass("active"); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Add the active class to the parent of the link which was selected.
 | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | 	$(elm).parent("li").addClass("active"); | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Minimize all tab content wrapper and activate only the selected
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// tab panel.
 | 
					
						
							| 
									
										
										
										
											2019-11-28 17:42:12 +00:00
										 |  |  | 	$('#profile-jot-form > [role=tabpanel]').addClass("minimize").attr("aria-hidden" ,"true"); | 
					
						
							|  |  |  | 	$('#' + tabpanel).removeClass("minimize").attr("aria-hidden" ,"false"); | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Set the aria-selected states
 | 
					
						
							| 
									
										
										
										
											2019-11-28 17:42:12 +00:00
										 |  |  | 	$("#jot-modal .modal-header .nav-tabs .jot-nav-lnk").attr("aria-selected", "false"); | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	elm.setAttribute("aria-selected", "true"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// For some some tab panels we need to execute other js functions.
 | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	if (tabpanel === "jot-preview-content") { | 
					
						
							|  |  |  | 		preview_post(); | 
					
						
							| 
									
										
										
										
											2018-09-20 15:09:39 +00:00
										 |  |  | 		// Make Share button visivle in preview
 | 
					
						
							|  |  |  | 		$('#jot-preview-share').removeClass("minimize").attr("aria-hidden" ,"false"); | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	} else if (tabpanel === "jot-fbrowser-wrapper") { | 
					
						
							|  |  |  | 		$(function() { | 
					
						
							|  |  |  | 			Dialog.showJot(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// If element is a mobile dropdown nav menu we need to change the botton text.
 | 
					
						
							| 
									
										
										
										
											2017-04-05 09:46:42 +00:00
										 |  |  | 	if (cls) { | 
					
						
							|  |  |  | 		toggleDropdownText(elm); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-09 19:08:11 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-25 11:02:53 +00:00
										 |  |  | // Wall Message needs a special handling because in some cases
 | 
					
						
							|  |  |  | // it redirects you to your own server. In such cases we can't
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | // load it into a modal.
 | 
					
						
							| 
									
										
										
										
											2016-06-25 11:02:53 +00:00
										 |  |  | function openWallMessage(url) { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// Split the the url in its parts.
 | 
					
						
							| 
									
										
										
										
											2016-06-25 11:02:53 +00:00
										 |  |  | 	var parts = parseUrl(url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// If the host isn't the same we can't load it in a modal.
 | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 	// So we will go to to the url directly.
 | 
					
						
							| 
									
										
										
										
											2016-06-25 11:02:53 +00:00
										 |  |  | 	if( ("host" in parts) && (parts.host !== window.location.host)) { | 
					
						
							|  |  |  | 		window.location.href = url; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 		// Otherwise load the wall message into a modal.
 | 
					
						
							| 
									
										
										
										
											2016-06-25 11:02:53 +00:00
										 |  |  | 		addToModal(url); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-15 20:34:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This function load the content of the edit url into a modal.
 | 
					
						
							|  |  |  | /// @todo Rename this function because it can be used for more than events.
 | 
					
						
							|  |  |  | function eventEdit(url) { | 
					
						
							|  |  |  | 	var char = qOrAmp(url); | 
					
						
							|  |  |  | 	url = url + char + 'mode=none'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$.get(url, function(data) { | 
					
						
							|  |  |  | 		$("#modal-body").empty(); | 
					
						
							|  |  |  | 		$("#modal-body").append(data); | 
					
						
							|  |  |  | 	}).done(function() { | 
					
						
							|  |  |  | 		loadModalTitle(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-27 16:36:33 +00:00
										 |  |  | // @license-end
 |