]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/theme.js
aa6db99c15daf250bc66dfd7d3b33ebbecdf880f
[friendica.git] / view / theme / frio / js / theme.js
1
2 var jotcache = ''; //The jot cache. We use it as cache to restore old/original jot content
3
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();
9                 } else {
10                         $("#back-to-top").fadeOut();
11                 }
12         });
13
14         // scroll body to 0px on click
15         $("#back-to-top").click(function () {
16                 $("body,html").animate({
17                         scrollTop: 0
18                 }, 400);
19                 return false;
20         });
21
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");
25         }
26
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");
30         }
31
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");
35         }
36
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");
41
42         // move the tabbar to the second nav bar
43         $("section .tabbar-wrapper").first().appendTo("#topbar-second > .container > #tabmenu");
44
45         // add mask css url to the logo-img container
46         //
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});
54         }
55
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({
60                 'cutoff': 2,
61                 'popupClass': "dropdown-menu pull-right",
62                 'popupAbsolute': false,
63                 'target': ".flex-target"
64         });
65
66         // add Jot botton to the scecond navbar
67         if( $("section #jotOpen").length ) {
68                 $("section #jotOpen").appendTo("#topbar-second > .container > #navbar-button");
69                 if( $("#jot-popup").is(":hidden")) $("#topbar-second > .container > #navbar-button #jotOpen").hide();
70         }
71
72         // show bulk deletion button at network page if checkbox is checked
73         $("body").change("input.item-select", function(){
74                 var checked = false;
75
76                 // We need to get all checked items, so it would close the delete button
77                 // if we uncheck one item and others are still checked.
78                 // So return checked = true if there is any checked item
79                 $('input.item-select').each( function() {
80                         if($(this).is(':checked')) {
81                                 checked = true;
82                                 return false;
83                         }
84                 });
85
86                 if(checked) {
87                         $("#item-delete-selected").fadeTo(400, 1);
88                         $("#item-delete-selected").show();
89                 } else {
90                         $("#item-delete-selected").fadeTo(400, 0, function(){
91                                 $("#item-delete-selected").hide();
92                         });
93                 }
94         });
95
96         //$('ul.flex-nav').flexMenu();
97
98         // initialize the bootstrap tooltips
99         $('body').tooltip({
100                 selector: '[data-toggle="tooltip"]',
101                 container: 'body',
102                 animation: true,
103                 html: true,
104                 placement: 'auto',
105                 trigger: 'hover',
106                 delay: {
107                         show: 500,
108                         hide: 100
109                 }
110         });
111
112         // initialize the bootstrap-select
113         $('.selectpicker').selectpicker();
114
115         // add search-heading to the seccond navbar
116         if( $(".search-heading").length) {
117                 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
118         }
119
120         // add search results heading to the second navbar
121         // and insert the search value to the top nav search input
122         if( $(".search-content-wrapper").length ) {
123                 // get the text of the heading (we catch the plain text because we don't
124                 // want to have a h4 heading in the navbar
125                 var searchText = $(".section-title-wrapper > h2").text();
126                 // insert the plain text in a <h4> heading and give it a class
127                 var newText = '<h4 class="search-heading">'+searchText+'</h4>';
128                 // append the new heading to the navbar
129                 $("#topbar-second > .container > #tabmenu").append(newText);
130
131                 // try to get the value of the original search input to insert it
132                 // as value in the nav-search-input
133                 var searchValue = $("#search-wrapper .form-group-search input").val();
134
135                 // if the orignal search value isn't available use the location path as value
136                 if( typeof searchValue === "undefined") {
137                         // get the location path
138                         var urlPath = window.location.search
139                         // and split it up in its parts
140                         var splitPath = urlPath.split(/(\?search?=)(.*$)/);
141
142                         if(typeof splitPath[2] !== 'undefined') {
143                                 // decode the path (e.g to decode %40 to the character @)
144                                 var searchValue = decodeURIComponent(splitPath[2]);
145                         }
146                 }
147
148                 if( typeof searchValue !== "undefined") {
149                         $("#nav-search-input-field").val(searchValue);
150                 }
151         }
152
153         // move the "Save the search" button to the second navbar
154         $(".search-content-wrapper #search-save-form ").appendTo("#topbar-second > .container > #navbar-button");
155
156         // append the vcard-short-info to the second nav after passing the element
157         // with .fn (vcard username). Use scrollspy to get the scroll position.
158         if( $("aside .vcard .fn").length) {
159                 $(".vcard .fn").scrollspy({
160                         min: $(".vcard .fn").position().top - 50,
161                         onLeaveTop: function onLeave(element) {
162                                 $("#vcard-short-info").fadeOut(500, function () {
163                                         $("#vcard-short-info").appendTo("#vcard-short-info-wrapper");
164                                 });
165                         },
166                         onEnter: function(element) {
167                                 $("#vcard-short-info").appendTo("#nav-short-info");
168                                 $("#vcard-short-info").fadeIn(500);
169                         },
170                 });
171         }
172
173         // move the forum contact information of the network page into the second navbar
174         if( $(".network-content-wrapper > #viewcontact_wrapper-network").length) {
175                 // get the contact-wrapper element and append it to the second nav bar
176                 // Note: We need the first() element with this class since at the present time we
177                 // store also the js template information in the html code and thats why
178                 // there are two elements with this class but we don't want the js template
179                 $(".network-content-wrapper > #viewcontact_wrapper-network .contact-wrapper").first().appendTo("#nav-short-info");
180         }
181
182         // move heading from network stream to the second navbar nav-short-info section
183         if( $(".network-content-wrapper > .section-title-wrapper").length) {
184                 // get the heading element
185                 var heading = $(".network-content-wrapper > .section-title-wrapper > h2");
186                 // get the text of the heading
187                 var headingContent = heading.text();
188                 // create a new element with the content of the heading
189                 var newText = '<h4 class="heading" data-toggle="tooltip" title="'+headingContent+'">'+headingContent+'</h4>';
190                 // remove the old heading element
191                 heading.remove(),
192                 // put the new element to the second nav bar
193                 $("#topbar-second #nav-short-info").append(newText);
194         }
195
196         if( $(".community-content-wrapper").length) {
197                 // get the heading element
198                 var heading = $(".community-content-wrapper > h3").first();
199                 // get the text of the heading
200                 var headingContent = heading.text();
201                 // create a new element with the content of the heading
202                 var newText = '<h4 class="heading">'+headingContent+'</h4>';
203                 // remove the old heading element
204                 heading.remove(),
205                 // put the new element to the second nav bar
206                 $("#topbar-second > .container > #tabmenu").append(newText);
207         }
208
209         if( $(".global-content-wrapper").length) {
210                 // get the heading element
211                 var heading = $(".global-content-wrapper > h3").first();
212                 // get the text of the heading
213                 var headingContent = heading.text();
214                 // create a new element with the content of the heading
215                 var newText = '<h4 class="heading">'+headingContent+'</h4>';
216                 // remove the old heading element
217                 heading.remove(),
218                 // put the new element to the second nav bar
219                 $("#topbar-second > .container > #tabmenu").append(newText);
220         }
221
222         // Dropdown menus with the class "dropdown-head" will display the active tab
223         // as button text
224         $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
225                 toggleDropdownText(this);
226         });
227
228         /* setup onoff widgets */
229         // Add the correct class to the switcher according to the input
230         // value (On/Off)
231         $(".toggle input").each(function(){
232                 // Get the value of the input element
233                 val = $(this).val();
234                 id = $(this).attr("id");
235
236                 // The css classes for "on" and "off"
237                 onstyle = "btn-primary";
238                 offstyle = "btn-default off";
239
240                 // Add the correct class in dependence of input value (On/Off)
241                 toggleclass = (val == 0 ? offstyle : onstyle);
242                 $("#"+id+"_onoff").addClass(toggleclass);
243
244         });
245
246         // Change the css class while clicking on the switcher elements
247         $(".toggle label, .toggle .toggle-handle").click(function(event){
248                 event.preventDefault();
249                 // Get the value of the input element
250                 var input = $(this).siblings("input");
251                 var val = 1-input.val();
252                 var id = input.attr("id");
253
254                 // The css classes for "on" and "off"
255                 var onstyle = "btn-primary";
256                 var offstyle = "btn-default off";
257
258                 // According to the value of the input element we need to decide
259                 // which class need to be added and removed when changing the switch
260                 var removedclass = (val == 0 ? onstyle : offstyle);
261                 var addedclass = (val == 0 ? offstyle : onstyle)
262                 $("#"+id+"_onoff").addClass(addedclass).removeClass(removedclass);
263
264                 // After changing the switch the input element is getting
265                 // the newvalue
266                 input.val(val);
267         });
268
269         // Set the padding for input elements with inline buttons
270         //
271         // In Frio we use some input elements where the submit button is visually
272         // inside the the input field (through css). We need to set a padding-right
273         // to the input element where the padding value would be at least the width
274         // of the button. Otherwise long user input would be invisible because it is
275         // behind the button.
276         $("body").on('click', '.form-group-search > input', function() {
277                 // Get the width of the button (if the button isn't available
278                 // buttonWidth will be null
279                 var buttonWidth = $(this).next('.form-button-search').outerWidth();
280
281                 if (buttonWidth) {
282                         // Take the width of the button and ad 5px
283                         var newWidth = buttonWidth + 5;
284                         // Set the padding of the input element according
285                         // to the width of the button
286                         $(this).css('padding-right', newWidth);
287                 }
288
289         });
290
291         /*
292          * This event handler hides all comment UI when the user clicks anywhere on the page
293          * It ensures that we aren't closing the current comment box
294          *
295          * We are making an exception for buttons because of a race condition with the
296          * comment opening button that results in an already closed comment UI.
297          */
298         $(document).on('click', function(event) {
299                 if (event.target.type === 'button') {
300                         return true;
301                 }
302
303                 var $dontclosethis = $(event.target).closest('.wall-item-comment-wrapper').find('.comment-edit-form');
304                 $('.wall-item-comment-wrapper .comment-edit-submit-wrapper:visible').each(function() {
305                         var $parent = $(this).parent('.comment-edit-form');
306                         var itemId = $parent.data('itemId');
307
308                         if ($dontclosethis[0] != $parent[0]) {
309                                 var textarea = $parent.find('textarea').get(0)
310
311                                 commentCloseUI(textarea, itemId);
312                         }
313                 });
314         });
315
316         // Customize some elements when the app is used in standalone mode on Android
317         if (window.matchMedia('(display-mode: standalone)').matches) {
318                 // Open links to source outside of the webview
319                 $('body').on('click', '.plink', function (e) {
320                         $(e.target).attr('target', '_blank');
321                 });
322         }
323
324         /*
325          * This event listeners ensures that the textarea size is updated event if the
326          * value is changed externally (textcomplete, insertFormatting, fbrowser...)
327          */
328         $(document).on('change', 'textarea', function(event) {
329                 autosize.update(event.target);
330         });
331
332         /*
333          * Sticky aside on page scroll
334          * We enable the sticky aside only when window is wider than
335          * 976px - which is the maximum width where the aside is shown in
336          * mobile style - because on chrome-based browsers (desktop and
337          * android) the sticky plugin in mobile style causes the browser to
338          * scroll back to top the main content, making it impossible
339          * to navigate.
340          * A side effect is that the sitky aside isn't really responsive,
341          * since is enabled or not at page loading time.
342          */
343         if ($(window).width() > 976) {
344                 $("aside").stick_in_parent({
345                         offset_top: 100, // px, header + tab bar + spacing
346                         recalc_every: 10
347                 });
348                 // recalculate sticky aside on clicks on <a> elements
349                 // this handle height changes on expanding submenus
350                 $("aside").on("click", "a", function(){
351                         $(document.body).trigger("sticky_kit:recalc");
352                 });
353         }
354
355         /*
356          * Add or remove "aside-out" class to body tag
357          * when the mobile aside is shown or hidden.
358          * The class is used in css to disable scroll in page when the aside
359          * is shown.
360          */
361         $("aside")
362                 .on("shown.bs.offcanvas", function() {
363                         $("body").addClass("aside-out");
364                 })
365                 .on("hidden.bs.offcanvas", function() {
366                         $("body").removeClass("aside-out");
367                 });
368
369         // Event listener for 'Show & hide event map' button in the network stream.
370         $("body").on("click", ".event-map-btn", function() {
371                 showHideEventMap(this);
372         });
373
374 });
375
376 function openClose(theID) {
377         var elem = document.getElementById(theID);
378
379         if( $(elem).is(':visible')) {
380                 $(elem).slideUp(200);
381         }
382         else {
383                 $(elem).slideDown(200);
384         }
385 }
386
387 function showHide(theID) {
388         if(document.getElementById(theID).style.display == "block") {
389                 document.getElementById(theID).style.display = "none"
390         }
391         else {
392                 document.getElementById(theID).style.display = "block"
393         }
394 }
395
396 function showHideComments(id) {
397         if( $('#collapsed-comments-' + id).is(':visible')) {
398                 $('#collapsed-comments-' + id).slideUp();
399                 $('#hide-comments-' + id).html(window.showMore);
400                 $('#hide-comments-total-' + id).show();
401         }
402         else {
403                 $('#collapsed-comments-' + id).slideDown();
404                 $('#hide-comments-' + id).html(window.showFewer);
405                 $('#hide-comments-total-' + id).hide();
406         }
407 }
408
409 // Show & hide event map in the network stream by button click.
410 function showHideEventMap(elm) {
411         // Get the id of the map element - it should be provided through
412         // the atribute "data-map-id".
413         var mapID = elm.getAttribute('data-map-id');
414
415         // Get translation labels.
416         var mapshow = elm.getAttribute('data-show-label');
417         var maphide = elm.getAttribute('data-hide-label');
418
419         // Change the button labels.
420         if (elm.innerText == mapshow) {
421                 $('#' + elm.id).text(maphide);
422         } else {
423                 $('#' + elm.id).text(mapshow);
424         }
425         // Because maps are iframe elements, we cant hide it through css (display: none).
426         // We solve this issue by putting the map outside the screen with css.
427         // So the first time the 'Show map' button is pressed we move the map
428         // element into the screen area.
429         var mappos = $('#' + mapID).css('position');
430
431         if (mappos === 'absolute') {
432                 $('#' + mapID).hide();
433                 $('#' + mapID).css({position: 'relative', left: 'auto', top: 'auto'});
434                 openClose(mapID);
435         } else {
436                 openClose(mapID);
437         }
438         return false;
439 }
440
441 function justifyPhotos() {
442         justifiedGalleryActive = true;
443         $('#photo-album-contents').justifiedGallery({
444                 margins: 3,
445                 border: 0,
446                 sizeRangeSuffixes: {
447                         'lt100': '-2',
448                         'lt240': '-2',
449                         'lt320': '-2',
450                         'lt500': '',
451                         'lt640': '-1',
452                         'lt1024': '-0'
453                 }
454         }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
455 }
456
457 function justifyPhotosAjax() {
458         justifiedGalleryActive = true;
459         $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
460 }
461
462 function loadScript(url, callback) {
463         // Adding the script tag to the head as suggested before
464         var head = document.getElementsByTagName('head')[0];
465         var script = document.createElement('script');
466         script.type = 'text/javascript';
467         script.src = url;
468
469         // Then bind the event to the callback function.
470         // There are several events for cross browser compatibility.
471         script.onreadystatechange = callback;
472         script.onload = callback;
473
474         // Fire the loading
475         head.appendChild(script);
476 }
477
478 function random_digits(digits) {
479         var rn = "";
480         var rnd = "";
481
482         for(var i = 0; i < digits; i++) {
483                 var rn = Math.round(Math.random() * (9));
484                 rnd += rn;
485         }
486
487         return rnd;
488 }
489
490 // Does we need a ? or a & to append values to a url
491 function qOrAmp(url) {
492         if(url.search('\\?') < 0) {
493                 return '?';
494         } else {
495                 return '&';
496         }
497 }
498
499 function contact_filter(item) {
500         // get the html content from the js template of the contact-wrapper
501         contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
502
503         var variables = {
504                         id:             item.id,
505                         name:           item.name,
506                         username:       item.username,
507                         thumb:          item.thumb,
508                         img_hover:      item.img_hover,
509                         edit_hover:     item.edit_hover,
510                         account_type:   item.account_type,
511                         photo_menu:     item.photo_menu,
512                         alt_text:       item.alt_text,
513                         dir_icon:       item.dir_icon,
514                         sparkle:        item.sparkle,
515                         itemurl:        item.itemurl,
516                         url:            item.url,
517                         network:        item.network,
518                         tags:           item.tags,
519                         details:        item.details,
520         };
521
522         // open a new jSmart instance with the template
523         var tpl = new jSmart (contact_tpl);
524
525         // replace the variable with the values
526         var html = tpl.fetch(variables);
527
528         return html;
529 }
530
531 function filter_replace(item) {
532
533         return item.name;
534 }
535
536 (function($) {
537         $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
538                 if (typeof typ === 'undefined') {
539                         typ = '';
540                 }
541
542                 if (typeof autosubmit === 'undefined') {
543                         autosubmit = false;
544                 }
545
546                 // Autocomplete contacts
547                 contacts = {
548                         match: /(^)([^\n]+)$/,
549                         index: 2,
550                         search: function(term, callback) {contact_search(term, callback, backend_url, typ);},
551                         replace: filter_replace,
552                         template: contact_filter
553                 };
554
555                 this.attr('autocomplete','off');
556                 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
557
558                 a.on('textComplete:select', function(e, value, strategy) {
559                         $(".dropdown-menu.textcomplete-dropdown.media-list").show();
560                 });
561         };
562 })( jQuery );
563
564 // current time in milliseconds, to send each request to make sure
565 // we 're not getting 304 response
566 function timeNow() {
567         return new Date().getTime();
568 }
569
570 String.prototype.normalizeLink = function () {
571         var ret = this.replace('https:', 'http:');
572         var ret = ret.replace('//www', '//');
573         return ret.rtrim();
574 };
575
576 function cleanContactUrl(url) {
577         var parts = parseUrl(url);
578
579         if(! ("scheme" in parts) || ! ("host" in parts)) {
580                 return url;
581         }
582
583         var newUrl =parts["scheme"] + "://" + parts["host"];
584
585         if("port" in parts) {
586                 newUrl += ":" + parts["port"];
587         }
588
589         if("path" in parts) {
590                 newUrl += parts["path"];
591         }
592
593 //      if(url != newUrl) {
594 //              console.log("Cleaned contact url " + url + " to " + newUrl);
595 //      }
596
597         return newUrl;
598 }
599
600 function parseUrl (str, component) { // eslint-disable-line camelcase
601         //       discuss at: http://locutusjs.io/php/parse_url/
602         //      original by: Steven Levithan (http://blog.stevenlevithan.com)
603         // reimplemented by: Brett Zamir (http://brett-zamir.me)
604         //         input by: Lorenzo Pisani
605         //         input by: Tony
606         //      improved by: Brett Zamir (http://brett-zamir.me)
607         //           note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
608         //           note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
609         //           note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
610         //           note 1: Does not replace invalid characters with '_' as in PHP,
611         //           note 1: nor does it return false with
612         //           note 1: a seriously malformed URL.
613         //           note 1: Besides function name, is essentially the same as parseUri as
614         //           note 1: well as our allowing
615         //           note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
616         //        example 1: parse_url('http://user:pass@host/path?a=v#a')
617         //        returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
618         //        example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
619         //        returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
620         //        example 3: parse_url('https://host.domain.tld/a@b.c/folder')
621         //        returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
622         //        example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
623         //        returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
624
625         var query
626
627         var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
628
629         var key = [
630                 'source',
631                 'scheme',
632                 'authority',
633                 'userInfo',
634                 'user',
635                 'pass',
636                 'host',
637                 'port',
638                 'relative',
639                 'path',
640                 'directory',
641                 'file',
642                 'query',
643                 'fragment'
644         ]
645
646         // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
647         var parser = {
648                 php: new RegExp([
649                         '(?:([^:\\/?#]+):)?',
650                         '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
651                         '()',
652                         '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
653                 ].join('')),
654                 strict: new RegExp([
655                         '(?:([^:\\/?#]+):)?',
656                         '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
657                         '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
658                 ].join('')),
659                 loose: new RegExp([
660                         '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
661                         '(?:\\/\\/\\/?)?',
662                         '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
663                         '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
664                         '(?:\\?([^#]*))?(?:#(.*))?)'
665                 ].join(''))
666         }
667
668         var m = parser[mode].exec(str)
669         var uri = {}
670         var i = 14
671
672         while (i--) {
673                 if (m[i]) {
674                         uri[key[i]] = m[i]
675                 }
676         }
677
678         if (component) {
679                 return uri[component.replace('PHP_URL_', '').toLowerCase()]
680         }
681
682         if (mode !== 'php') {
683                 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
684                 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
685                 uri[name] = {}
686                 query = uri[key[12]] || ''
687                 query.replace(parser, function ($0, $1, $2) {
688                         if ($1) {
689                                 uri[name][$1] = $2
690                         }
691                 })
692         }
693
694         delete uri.source
695         return uri
696 }
697
698 // trim function to replace whithespace after the string
699 String.prototype.rtrim = function() {
700         var trimmed = this.replace(/\s+$/g, '');
701         return trimmed;
702 };
703
704 /**
705  * Scroll the screen to the item element whose id is provided, then highlights it
706  *
707  * Note: jquery.color.js is required
708  *
709  * @param {string} elementId The item element id
710  * @returns {undefined}
711  */
712 function scrollToItem(elementId) {
713         if (typeof elementId === "undefined") {
714                 return;
715         }
716
717         var $el = $(document.getElementById(elementId));
718         // Test if the Item exists
719         if (!$el.length) {
720                 return;
721         }
722
723         // Define the colors which are used for highlighting
724         var colWhite = {backgroundColor:'#F5F5F5'};
725         var colShiny = {backgroundColor:'#FFF176'};
726
727         // Get the Item Position (we need to substract 100 to match correct position
728         var itemPos = $el.offset().top - 100;
729
730         // Scroll to the DIV with the ID (GUID)
731         $('html, body').animate({
732                 scrollTop: itemPos
733         }, 400, function() {
734                 // Highlight post/commenent with ID  (GUID)
735                 $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
736         });
737 }
738
739 // format a html string to pure text
740 function htmlToText(htmlString) {
741         // Replace line breaks with spaces
742         var text = htmlString.replace(/<br>/g, ' ');
743         // Strip the text out of the html string
744         text = text.replace(/<[^>]*>/g, '');
745
746         return text;
747 }
748
749 /**
750  * Sends a /like API call and updates the display of the relevant action button
751  * before the update reloads the item.
752  *
753  * @param {string} ident The id of the relevant item
754  * @param {string} verb The verb of the action
755  * @returns {undefined}
756  */
757 function doLikeAction(ident, verb) {
758         unpause();
759
760         if (verb.indexOf('attend') === 0) {
761                 $('.item-' + ident + ' .button-event:not(#' + verb + '-' + ident + ')').removeClass('active');
762         }
763         $('#' + verb + '-' + ident).toggleClass('active');
764         $('#like-rotator-' + ident.toString()).show();
765         $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
766         liking = 1;
767         force_update = true;
768 }
769
770 // Decodes a hexadecimally encoded binary string
771 function hex2bin (s) {
772         //  discuss at: http://locutus.io/php/hex2bin/
773         // original by: Dumitru Uzun (http://duzun.me)
774         //   example 1: hex2bin('44696d61')
775         //   returns 1: 'Dima'
776         //   example 2: hex2bin('00')
777         //   returns 2: '\x00'
778         //   example 3: hex2bin('2f1q')
779         //   returns 3: false
780         var ret = [];
781         var i = 0;
782         var l;
783         s += '';
784
785         for (l = s.length; i < l; i += 2) {
786                 var c = parseInt(s.substr(i, 1), 16);
787                 var k = parseInt(s.substr(i + 1, 1), 16);
788                 if (isNaN(c) || isNaN(k)) {
789                         return false;
790                 }
791                 ret.push((c << 4) | k);
792         }
793         return String.fromCharCode.apply(String, ret);
794 }
795
796 // Convert binary data into hexadecimal representation
797 function bin2hex (s) {
798         // From: http://phpjs.org/functions
799         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
800         // +   bugfixed by: Onno Marsman
801         // +   bugfixed by: Linuxworld
802         // +   improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616)
803         // *     example 1: bin2hex('Kev');
804         // *     returns 1: '4b6576'
805         // *     example 2: bin2hex(String.fromCharCode(0x00));
806         // *     returns 2: '00'
807
808         var i, l, o = "", n;
809
810         s += "";
811
812         for (i = 0, l = s.length; i < l; i++) {
813                 n = s.charCodeAt(i).toString(16);
814                 o += n.length < 2 ? "0" + n : n;
815         }
816
817         return o;
818 }
819
820 // Dropdown menus with the class "dropdown-head" will display the active tab
821 // as button text
822 function toggleDropdownText(elm) {
823                 $(elm).closest(".dropdown").find('.btn').html($(elm).text() + ' <span class="caret"></span>');
824                 $(elm).closest(".dropdown").find('.btn').val($(elm).data('value'));
825                 $(elm).closest("ul").children("li").show();
826                 $(elm).parent("li").hide();
827 }
828
829 // Check if element does have a specific class
830 function hasClass(elem, cls) {
831         return (" " + elem.className + " " ).indexOf( " "+cls+" " ) > -1;
832 }