2 var jotcache = ''; //The jot cache. We use it as cache to restore old/original jot content
4 $(document).ready(function(){
5 //fade in/out based on scrollTop value
6 $(window).scroll(function () {
7 if ($(this).scrollTop() > 1000) {
8 $("#back-to-top").fadeIn();
10 $("#back-to-top").fadeOut();
14 // scroll body to 0px on click
15 $("#back-to-top").click(function () {
16 $("body,html").animate({
22 // add the class "selected" to group widges li if li > a does have the class group-selected
23 if( $("#sidebar-group-ul li a").hasClass("group-selected")) {
24 $("#sidebar-group-ul li a.group-selected").parent("li").addClass("selected");
27 // add the class "selected" to forums widges li if li > a does have the class forum-selected
28 if( $("#forumlist-sidbar-ul li a").hasClass("forum-selected")) {
29 $("#forumlist-sidbar-ul li a.forum-selected").parent("li").addClass("selected");
32 // add the class "active" to tabmenuli if li > a does have the class active
33 if( $("#tabmenu ul li a").hasClass("active")) {
34 $("#tabmenu ul li a.active").parent("li").addClass("active");
37 // give select fields an boostrap classes
38 // @todo: this needs to be changed in friendica core
39 $(".field.select, .field.custom").addClass("form-group");
40 $(".field.select > select, .field.custom > select").addClass("form-control");
42 // move the tabbar to the second nav bar
43 $("section .tabbar-wrapper").first().appendTo("#topbar-second > .container > #tabmenu");
45 // add mask css url to the logo-img container
47 // This is for firefox - we use a mask which looks like the friendica logo to apply user collers
48 // to the friendica logo (the mask is in nav.tpl at the botom). To make it work we need to apply the
49 // correct url. The only way which comes to my mind was to do this with js
50 // So we apply the correct url (with the link to the id of the mask) after the page is loaded.
51 if($("#logo-img").length ) {
52 var pageurl = "url('" + window.location.href + "#logo-mask')";
53 $("#logo-img").css({"mask": pageurl});
56 // make responsive tabmenu with flexmenu.js
57 // the menupoints which doesn't fit in the second nav bar will moved to a
58 // dropdown menu. Look at common_tabs.tpl
59 $("ul.tabs.flex-nav").flexMenu({
61 'popupClass': "dropdown-menu pull-right",
62 'popupAbsolute': false,
63 'target': ".flex-target"
66 // add Jot botton to the scecond navbar
67 let $jotButton = $("#jotOpen");
68 let $composeButton = $("#composeOpen");
71 if ($composeButton.length) {
72 $composeButton.appendTo("#topbar-second > .container > #navbar-button");
73 if($("#jot-popup").is(":hidden")) {
74 $composeButton.hide();
78 $composeButton.hide();
79 if ($jotButton.length) {
80 $jotButton.appendTo("#topbar-second > .container > #navbar-button");
81 if($("#jot-popup").is(":hidden")) {
87 // show bulk deletion button at network page if checkbox is checked
88 $("body").change("input.item-select", function(){
91 // We need to get all checked items, so it would close the delete button
92 // if we uncheck one item and others are still checked.
93 // So return checked = true if there is any checked item
94 $('input.item-select').each( function() {
95 if($(this).is(':checked')) {
102 $("#item-delete-selected").fadeTo(400, 1);
103 $("#item-delete-selected").show();
105 $("#item-delete-selected").fadeTo(400, 0, function(){
106 $("#item-delete-selected").hide();
111 //$('ul.flex-nav').flexMenu();
113 // initialize the bootstrap tooltips
115 selector: '[data-toggle="tooltip"]',
125 sanitizeFn: function (content) {
126 return DOMPurify.sanitize(content)
130 // initialize the bootstrap-select
131 $('.selectpicker').selectpicker();
133 // add search-heading to the seccond navbar
134 if( $(".search-heading").length) {
135 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
138 // add search results heading to the second navbar
139 // and insert the search value to the top nav search input
140 if( $(".search-content-wrapper").length ) {
141 // get the text of the heading (we catch the plain text because we don't
142 // want to have a h4 heading in the navbar
143 var searchText = $(".section-title-wrapper > h2").text();
144 // insert the plain text in a <h4> heading and give it a class
145 var newText = '<h4 class="search-heading">'+searchText+'</h4>';
146 // append the new heading to the navbar
147 $("#topbar-second > .container > #tabmenu").append(newText);
149 // try to get the value of the original search input to insert it
150 // as value in the nav-search-input
151 var searchValue = $("#search-wrapper .form-group-search input").val();
153 // if the orignal search value isn't available use the location path as value
154 if( typeof searchValue === "undefined") {
155 // get the location path
156 var urlPath = window.location.search
157 // and split it up in its parts
158 var splitPath = urlPath.split(/(\?search?=)(.*$)/);
160 if(typeof splitPath[2] !== 'undefined') {
161 // decode the path (e.g to decode %40 to the character @)
162 var searchValue = decodeURIComponent(splitPath[2]);
166 if( typeof searchValue !== "undefined") {
167 $("#nav-search-input-field").val(searchValue);
171 // move the "Save the search" button to the second navbar
172 $(".search-content-wrapper #search-save").appendTo("#topbar-second > .container > #navbar-button");
174 // append the vcard-short-info to the second nav after passing the element
175 // with .fn (vcard username). Use scrollspy to get the scroll position.
176 if( $("aside .vcard .fn").length) {
177 $(".vcard .fn").scrollspy({
178 min: $(".vcard .fn").position().top - 50,
179 onLeaveTop: function onLeave(element) {
180 $("#vcard-short-info").fadeOut(500, function () {
181 $("#vcard-short-info").appendTo("#vcard-short-info-wrapper");
184 onEnter: function(element) {
185 $("#vcard-short-info").appendTo("#nav-short-info");
186 $("#vcard-short-info").fadeIn(500);
191 // move the forum contact information of the network page into the second navbar
192 if( $(".network-content-wrapper > #viewcontact_wrapper-network").length) {
193 // get the contact-wrapper element and append it to the second nav bar
194 // Note: We need the first() element with this class since at the present time we
195 // store also the js template information in the html code and thats why
196 // there are two elements with this class but we don't want the js template
197 $(".network-content-wrapper > #viewcontact_wrapper-network .contact-wrapper").first().appendTo("#nav-short-info");
200 // move heading from network stream to the second navbar nav-short-info section
201 if( $(".network-content-wrapper > .section-title-wrapper").length) {
202 // get the heading element
203 var heading = $(".network-content-wrapper > .section-title-wrapper > h2");
204 // get the text of the heading
205 var headingContent = heading.text();
206 // create a new element with the content of the heading
207 var newText = '<h4 class="heading" data-toggle="tooltip" title="'+headingContent+'">'+headingContent+'</h4>';
208 // remove the old heading element
210 // put the new element to the second nav bar
211 $("#topbar-second #nav-short-info").append(newText);
214 if( $(".community-content-wrapper").length) {
215 // get the heading element
216 var heading = $(".community-content-wrapper > h3").first();
217 // get the text of the heading
218 var headingContent = heading.text();
219 // create a new element with the content of the heading
220 var newText = '<h4 class="heading">'+headingContent+'</h4>';
221 // remove the old heading element
223 // put the new element to the second nav bar
224 $("#topbar-second > .container > #tabmenu").append(newText);
227 // Dropdown menus with the class "dropdown-head" will display the active tab
229 $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
230 toggleDropdownText(this);
233 // Change the css class while clicking on the switcher elements
234 $(".toggle label, .toggle .toggle-handle").click(function(event){
235 event.preventDefault();
236 // Get the value of the input element
237 var input = $(this).siblings("input");
238 var val = 1-input.val();
239 var id = input.attr("id");
241 // The css classes for "on" and "off"
242 var onstyle = "btn-primary";
243 var offstyle = "btn-default off";
245 // According to the value of the input element we need to decide
246 // which class need to be added and removed when changing the switch
247 var removedclass = (val == 0 ? onstyle : offstyle);
248 var addedclass = (val == 0 ? offstyle : onstyle)
249 $("#"+id+"_onoff").addClass(addedclass).removeClass(removedclass);
251 // After changing the switch the input element is getting
256 // Set the padding for input elements with inline buttons
258 // In Frio we use some input elements where the submit button is visually
259 // inside the the input field (through css). We need to set a padding-right
260 // to the input element where the padding value would be at least the width
261 // of the button. Otherwise long user input would be invisible because it is
262 // behind the button.
263 $("body").on('click', '.form-group-search > input', function() {
264 // Get the width of the button (if the button isn't available
265 // buttonWidth will be null
266 var buttonWidth = $(this).next('.form-button-search').outerWidth();
269 // Take the width of the button and ad 5px
270 var newWidth = buttonWidth + 5;
271 // Set the padding of the input element according
272 // to the width of the button
273 $(this).css('padding-right', newWidth);
279 * This event handler hides all comment UI when the user clicks anywhere on the page
280 * It ensures that we aren't closing the current comment box
282 * We are making an exception for buttons because of a race condition with the
283 * comment opening button that results in an already closed comment UI.
285 $(document).on('mousedown', function(event) {
286 if (event.target.type === 'button') {
290 var $dontclosethis = $(event.target).closest('.wall-item-comment-wrapper').find('.comment-edit-form');
291 $('.wall-item-comment-wrapper .comment-edit-submit-wrapper:visible').each(function() {
292 var $parent = $(this).parent('.comment-edit-form');
293 var itemId = $parent.data('itemId');
295 if ($dontclosethis[0] != $parent[0]) {
296 var textarea = $parent.find('textarea').get(0)
298 commentCloseUI(textarea, itemId);
303 // Customize some elements when the app is used in standalone mode on Android
304 if (window.matchMedia('(display-mode: standalone)').matches) {
305 // Open links to source outside of the webview
306 $('body').on('click', '.plink', function (e) {
307 $(e.target).attr('target', '_blank');
312 * This event listeners ensures that the textarea size is updated event if the
313 * value is changed externally (textcomplete, insertFormatting, fbrowser...)
315 $(document).on('change', 'textarea', function(event) {
316 autosize.update(event.target);
320 * Sticky aside on page scroll
321 * We enable the sticky aside only when window is wider than
322 * 976px - which is the maximum width where the aside is shown in
323 * mobile style - because on chrome-based browsers (desktop and
324 * android) the sticky plugin in mobile style causes the browser to
325 * scroll back to top the main content, making it impossible
327 * A side effect is that the sitky aside isn't really responsive,
328 * since is enabled or not at page loading time.
330 if ($(window).width() > 976) {
331 $("aside").stick_in_parent({
332 offset_top: 100, // px, header + tab bar + spacing
335 // recalculate sticky aside on clicks on <a> elements
336 // this handle height changes on expanding submenus
337 $("aside").on("click", "a", function(){
338 $(document.body).trigger("sticky_kit:recalc");
343 * Add or remove "aside-out" class to body tag
344 * when the mobile aside is shown or hidden.
345 * The class is used in css to disable scroll in page when the aside
349 .on("shown.bs.offcanvas", function() {
350 $("body").addClass("aside-out");
352 .on("hidden.bs.offcanvas", function() {
353 $("body").removeClass("aside-out");
356 // Event listener for 'Show & hide event map' button in the network stream.
357 $("body").on("click", ".event-map-btn", function() {
358 showHideEventMap(this);
363 function openClose(theID) {
364 var elem = document.getElementById(theID);
366 if( $(elem).is(':visible')) {
367 $(elem).slideUp(200);
370 $(elem).slideDown(200);
374 function showHide(theID) {
375 var elem = document.getElementById(theID);
376 var edit = document.getElementById("comment-edit-submit-wrapper-" + theID.match('[0-9$]+'));
378 if ($(elem).is(':visible')) {
379 if (!$(edit).is(':visible')) {
380 edit.style.display = "block";
383 elem.style.display = "none";
387 elem.style.display = "block";
391 // Show & hide event map in the network stream by button click.
392 function showHideEventMap(elm) {
393 // Get the id of the map element - it should be provided through
394 // the atribute "data-map-id".
395 var mapID = elm.getAttribute('data-map-id');
397 // Get translation labels.
398 var mapshow = elm.getAttribute('data-show-label');
399 var maphide = elm.getAttribute('data-hide-label');
401 // Change the button labels.
402 if (elm.innerText == mapshow) {
403 $('#' + elm.id).text(maphide);
405 $('#' + elm.id).text(mapshow);
407 // Because maps are iframe elements, we cant hide it through css (display: none).
408 // We solve this issue by putting the map outside the screen with css.
409 // So the first time the 'Show map' button is pressed we move the map
410 // element into the screen area.
411 var mappos = $('#' + mapID).css('position');
413 if (mappos === 'absolute') {
414 $('#' + mapID).hide();
415 $('#' + mapID).css({position: 'relative', left: 'auto', top: 'auto'});
423 function justifyPhotos() {
424 justifiedGalleryActive = true;
425 $('#photo-album-contents').justifiedGallery({
436 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
439 // Load a js script to the html head.
440 function loadScript(url, callback) {
441 // Check if the script is already in the html head.
442 var oscript = $('head script[src="' + url + '"]');
444 // Delete the old script from head.
445 if (oscript.length > 0) {
448 // Adding the script tag to the head as suggested before.
449 var head = document.getElementsByTagName('head')[0];
450 var script = document.createElement('script');
451 script.type = 'text/javascript';
454 // Then bind the event to the callback function.
455 // There are several events for cross browser compatibility.
456 script.onreadystatechange = callback;
457 script.onload = callback;
460 head.appendChild(script);
463 // Does we need a ? or a & to append values to a url
464 function qOrAmp(url) {
465 if(url.search('\\?') < 0) {
472 String.prototype.normalizeLink = function () {
473 var ret = this.replace('https:', 'http:');
474 var ret = ret.replace('//www', '//');
478 function cleanContactUrl(url) {
479 var parts = parseUrl(url);
481 if(! ("scheme" in parts) || ! ("host" in parts)) {
485 var newUrl =parts["scheme"] + "://" + parts["host"];
487 if("port" in parts) {
488 newUrl += ":" + parts["port"];
491 if("path" in parts) {
492 newUrl += parts["path"];
495 // if(url != newUrl) {
496 // console.log("Cleaned contact url " + url + " to " + newUrl);
502 function parseUrl (str, component) { // eslint-disable-line camelcase
503 // discuss at: http://locutusjs.io/php/parse_url/
504 // original by: Steven Levithan (http://blog.stevenlevithan.com)
505 // reimplemented by: Brett Zamir (http://brett-zamir.me)
506 // input by: Lorenzo Pisani
508 // improved by: Brett Zamir (http://brett-zamir.me)
509 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
510 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
511 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
512 // note 1: Does not replace invalid characters with '_' as in PHP,
513 // note 1: nor does it return false with
514 // note 1: a seriously malformed URL.
515 // note 1: Besides function name, is essentially the same as parseUri as
516 // note 1: well as our allowing
517 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
518 // example 1: parse_url('http://user:pass@host/path?a=v#a')
519 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
520 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
521 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
522 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
523 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
524 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
525 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
529 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
548 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
551 '(?:([^:\\/?#]+):)?',
552 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
554 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
557 '(?:([^:\\/?#]+):)?',
558 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
559 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
562 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
564 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
565 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
566 '(?:\\?([^#]*))?(?:#(.*))?)'
570 var m = parser[mode].exec(str)
581 return uri[component.replace('PHP_URL_', '').toLowerCase()]
584 if (mode !== 'php') {
585 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
586 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
588 query = uri[key[12]] || ''
589 query.replace(parser, function ($0, $1, $2) {
600 // trim function to replace whithespace after the string
601 String.prototype.rtrim = function() {
602 var trimmed = this.replace(/\s+$/g, '');
607 * Scroll the screen to the item element whose id is provided, then highlights it
609 * Note: jquery.color.js is required
611 * @param {string} elementId The item element id
612 * @returns {undefined}
614 function scrollToItem(elementId) {
615 if (typeof elementId === "undefined") {
619 var $el = $('#' + elementId + ' > .media');
620 // Test if the Item exists
625 // Define the colors which are used for highlighting
626 var colWhite = {backgroundColor:'#F5F5F5'};
627 var colShiny = {backgroundColor:'#FFF176'};
629 // Get the Item Position (we need to substract 100 to match correct position
630 var itemPos = $el.offset().top - 100;
632 // Scroll to the DIV with the ID (GUID)
633 $('html, body').animate({
635 }, 400).promise().done( function() {
636 // Highlight post/commenent with ID (GUID)
637 $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
641 // format a html string to pure text
642 function htmlToText(htmlString) {
643 // Replace line breaks with spaces
644 var text = htmlString.replace(/<br>/g, ' ');
645 // Strip the text out of the html string
646 text = text.replace(/<[^>]*>/g, '');
652 * Sends a /like API call and updates the display of the relevant action button
653 * before the update reloads the item.
655 * @param {string} ident The id of the relevant item
656 * @param {string} verb The verb of the action
657 * @returns {undefined}
659 function doLikeAction(ident, verb) {
662 if (verb.indexOf('attend') === 0) {
663 $('.item-' + ident + ' .button-event:not(#' + verb + '-' + ident + ')').removeClass('active');
665 $('#' + verb + '-' + ident).toggleClass('active');
666 $('#like-rotator-' + ident.toString()).show();
667 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
670 update_item = ident.toString();
673 // Decodes a hexadecimally encoded binary string
674 function hex2bin (s) {
675 // discuss at: http://locutus.io/php/hex2bin/
676 // original by: Dumitru Uzun (http://duzun.me)
677 // example 1: hex2bin('44696d61')
679 // example 2: hex2bin('00')
681 // example 3: hex2bin('2f1q')
688 for (l = s.length; i < l; i += 2) {
689 var c = parseInt(s.substr(i, 1), 16);
690 var k = parseInt(s.substr(i + 1, 1), 16);
691 if (isNaN(c) || isNaN(k)) {
694 ret.push((c << 4) | k);
696 return String.fromCharCode.apply(String, ret);
699 // Convert binary data into hexadecimal representation
700 function bin2hex (s) {
701 // From: http://phpjs.org/functions
702 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
703 // + bugfixed by: Onno Marsman
704 // + bugfixed by: Linuxworld
705 // + improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616)
706 // * example 1: bin2hex('Kev');
707 // * returns 1: '4b6576'
708 // * example 2: bin2hex(String.fromCharCode(0x00));
715 for (i = 0, l = s.length; i < l; i++) {
716 n = s.charCodeAt(i).toString(16);
717 o += n.length < 2 ? "0" + n : n;
723 // Dropdown menus with the class "dropdown-head" will display the active tab
725 function toggleDropdownText(elm) {
726 $(elm).closest(".dropdown").find('.btn').html($(elm).text() + ' <span class="caret"></span>');
727 $(elm).closest(".dropdown").find('.btn').val($(elm).data('value'));
728 $(elm).closest("ul").children("li").show();
729 $(elm).parent("li").hide();
732 // Check if element does have a specific class
733 function hasClass(elem, cls) {
734 return (" " + elem.className + " " ).indexOf( " "+cls+" " ) > -1;