]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/theme.js
Merge pull request #7742 from MrPetovan/task/7190-remove-defaults-mod
[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         let $jotButton = $("#jotOpen");
68         let $composeButton = $("#composeOpen");
69         if (compose) {
70                 $jotButton.hide();
71                 if ($composeButton.length) {
72                         $composeButton.appendTo("#topbar-second > .container > #navbar-button");
73                         if($("#jot-popup").is(":hidden")) {
74                                 $composeButton.hide();
75                         }
76                 }
77         } else {
78                 $composeButton.hide();
79                 if ($jotButton.length) {
80                         $jotButton.appendTo("#topbar-second > .container > #navbar-button");
81                         if($("#jot-popup").is(":hidden")) {
82                                 $jotButton.hide();
83                         }
84                 }
85         }
86
87         // show bulk deletion button at network page if checkbox is checked
88         $("body").change("input.item-select", function(){
89                 var checked = false;
90
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')) {
96                                 checked = true;
97                                 return false;
98                         }
99                 });
100
101                 if(checked) {
102                         $("#item-delete-selected").fadeTo(400, 1);
103                         $("#item-delete-selected").show();
104                 } else {
105                         $("#item-delete-selected").fadeTo(400, 0, function(){
106                                 $("#item-delete-selected").hide();
107                         });
108                 }
109         });
110
111         //$('ul.flex-nav').flexMenu();
112
113         // initialize the bootstrap tooltips
114         $('body').tooltip({
115                 selector: '[data-toggle="tooltip"]',
116                 container: 'body',
117                 animation: true,
118                 html: true,
119                 placement: 'auto',
120                 trigger: 'hover',
121                 delay: {
122                         show: 500,
123                         hide: 100
124                 },
125                 sanitizeFn: function (content) {
126                         return DOMPurify.sanitize(content)
127                 },
128         });
129
130         // initialize the bootstrap-select
131         $('.selectpicker').selectpicker();
132
133         // add search-heading to the seccond navbar
134         if( $(".search-heading").length) {
135                 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
136         }
137
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);
148
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();
152
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?=)(.*$)/);
159
160                         if(typeof splitPath[2] !== 'undefined') {
161                                 // decode the path (e.g to decode %40 to the character @)
162                                 var searchValue = decodeURIComponent(splitPath[2]);
163                         }
164                 }
165
166                 if( typeof searchValue !== "undefined") {
167                         $("#nav-search-input-field").val(searchValue);
168                 }
169         }
170
171         // move the "Save the search" button to the second navbar
172         $(".search-content-wrapper #search-save").appendTo("#topbar-second > .container > #navbar-button");
173
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");
182                                 });
183                         },
184                         onEnter: function(element) {
185                                 $("#vcard-short-info").appendTo("#nav-short-info");
186                                 $("#vcard-short-info").fadeIn(500);
187                         },
188                 });
189         }
190
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");
198         }
199
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
209                 heading.remove(),
210                 // put the new element to the second nav bar
211                 $("#topbar-second #nav-short-info").append(newText);
212         }
213
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
222                 heading.remove(),
223                 // put the new element to the second nav bar
224                 $("#topbar-second > .container > #tabmenu").append(newText);
225         }
226
227         // Dropdown menus with the class "dropdown-head" will display the active tab
228         // as button text
229         $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
230                 toggleDropdownText(this);
231         });
232
233         /* setup onoff widgets */
234         // Add the correct class to the switcher according to the input
235         // value (On/Off)
236         $(".toggle input").each(function(){
237                 // Get the value of the input element
238                 val = $(this).val();
239                 id = $(this).attr("id");
240
241                 // The css classes for "on" and "off"
242                 onstyle = "btn-primary";
243                 offstyle = "btn-default off";
244
245                 // Add the correct class in dependence of input value (On/Off)
246                 toggleclass = (val == 0 ? offstyle : onstyle);
247                 $("#"+id+"_onoff").addClass(toggleclass);
248
249         });
250
251         // Change the css class while clicking on the switcher elements
252         $(".toggle label, .toggle .toggle-handle").click(function(event){
253                 event.preventDefault();
254                 // Get the value of the input element
255                 var input = $(this).siblings("input");
256                 var val = 1-input.val();
257                 var id = input.attr("id");
258
259                 // The css classes for "on" and "off"
260                 var onstyle = "btn-primary";
261                 var offstyle = "btn-default off";
262
263                 // According to the value of the input element we need to decide
264                 // which class need to be added and removed when changing the switch
265                 var removedclass = (val == 0 ? onstyle : offstyle);
266                 var addedclass = (val == 0 ? offstyle : onstyle)
267                 $("#"+id+"_onoff").addClass(addedclass).removeClass(removedclass);
268
269                 // After changing the switch the input element is getting
270                 // the newvalue
271                 input.val(val);
272         });
273
274         // Set the padding for input elements with inline buttons
275         //
276         // In Frio we use some input elements where the submit button is visually
277         // inside the the input field (through css). We need to set a padding-right
278         // to the input element where the padding value would be at least the width
279         // of the button. Otherwise long user input would be invisible because it is
280         // behind the button.
281         $("body").on('click', '.form-group-search > input', function() {
282                 // Get the width of the button (if the button isn't available
283                 // buttonWidth will be null
284                 var buttonWidth = $(this).next('.form-button-search').outerWidth();
285
286                 if (buttonWidth) {
287                         // Take the width of the button and ad 5px
288                         var newWidth = buttonWidth + 5;
289                         // Set the padding of the input element according
290                         // to the width of the button
291                         $(this).css('padding-right', newWidth);
292                 }
293
294         });
295
296         /*
297          * This event handler hides all comment UI when the user clicks anywhere on the page
298          * It ensures that we aren't closing the current comment box
299          *
300          * We are making an exception for buttons because of a race condition with the
301          * comment opening button that results in an already closed comment UI.
302          */
303         $(document).on('mousedown', function(event) {
304                 if (event.target.type === 'button') {
305                         return true;
306                 }
307
308                 var $dontclosethis = $(event.target).closest('.wall-item-comment-wrapper').find('.comment-edit-form');
309                 $('.wall-item-comment-wrapper .comment-edit-submit-wrapper:visible').each(function() {
310                         var $parent = $(this).parent('.comment-edit-form');
311                         var itemId = $parent.data('itemId');
312
313                         if ($dontclosethis[0] != $parent[0]) {
314                                 var textarea = $parent.find('textarea').get(0)
315
316                                 commentCloseUI(textarea, itemId);
317                         }
318                 });
319         });
320
321         // Customize some elements when the app is used in standalone mode on Android
322         if (window.matchMedia('(display-mode: standalone)').matches) {
323                 // Open links to source outside of the webview
324                 $('body').on('click', '.plink', function (e) {
325                         $(e.target).attr('target', '_blank');
326                 });
327         }
328
329         /*
330          * This event listeners ensures that the textarea size is updated event if the
331          * value is changed externally (textcomplete, insertFormatting, fbrowser...)
332          */
333         $(document).on('change', 'textarea', function(event) {
334                 autosize.update(event.target);
335         });
336
337         /*
338          * Sticky aside on page scroll
339          * We enable the sticky aside only when window is wider than
340          * 976px - which is the maximum width where the aside is shown in
341          * mobile style - because on chrome-based browsers (desktop and
342          * android) the sticky plugin in mobile style causes the browser to
343          * scroll back to top the main content, making it impossible
344          * to navigate.
345          * A side effect is that the sitky aside isn't really responsive,
346          * since is enabled or not at page loading time.
347          */
348         if ($(window).width() > 976) {
349                 $("aside").stick_in_parent({
350                         offset_top: 100, // px, header + tab bar + spacing
351                         recalc_every: 10
352                 });
353                 // recalculate sticky aside on clicks on <a> elements
354                 // this handle height changes on expanding submenus
355                 $("aside").on("click", "a", function(){
356                         $(document.body).trigger("sticky_kit:recalc");
357                 });
358         }
359
360         /*
361          * Add or remove "aside-out" class to body tag
362          * when the mobile aside is shown or hidden.
363          * The class is used in css to disable scroll in page when the aside
364          * is shown.
365          */
366         $("aside")
367                 .on("shown.bs.offcanvas", function() {
368                         $("body").addClass("aside-out");
369                 })
370                 .on("hidden.bs.offcanvas", function() {
371                         $("body").removeClass("aside-out");
372                 });
373
374         // Event listener for 'Show & hide event map' button in the network stream.
375         $("body").on("click", ".event-map-btn", function() {
376                 showHideEventMap(this);
377         });
378
379 });
380
381 function openClose(theID) {
382         var elem = document.getElementById(theID);
383
384         if( $(elem).is(':visible')) {
385                 $(elem).slideUp(200);
386         }
387         else {
388                 $(elem).slideDown(200);
389         }
390 }
391
392 function showHide(theID) {
393         var elem = document.getElementById(theID);
394         var edit = document.getElementById("comment-edit-submit-wrapper-" + theID.match('[0-9$]+'));
395
396         if ($(elem).is(':visible')) {
397                 if (!$(edit).is(':visible')) {
398                         edit.style.display = "block";
399                 }
400                 else {
401                         elem.style.display = "none";
402                 }
403         }
404         else {
405                 elem.style.display = "block";
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                         'lt48': '-6',
448                         'lt80': '-5',
449                         'lt300': '-4',
450                         'lt320': '-2',
451                         'lt640': '-1',
452                         'lt1024': '-0'
453                 }
454         }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
455 }
456
457 // Load a js script to the html head.
458 function loadScript(url, callback) {
459         // Check if the script is already in the html head.
460         var oscript = $('head script[src="' + url + '"]');
461
462         // Delete the old script from head.
463         if (oscript.length > 0) {
464                 oscript.remove();
465         }
466         // Adding the script tag to the head as suggested before.
467         var head = document.getElementsByTagName('head')[0];
468         var script = document.createElement('script');
469         script.type = 'text/javascript';
470         script.src = url;
471
472         // Then bind the event to the callback function.
473         // There are several events for cross browser compatibility.
474         script.onreadystatechange = callback;
475         script.onload = callback;
476
477         // Fire the loading.
478         head.appendChild(script);
479 }
480
481 // Does we need a ? or a & to append values to a url
482 function qOrAmp(url) {
483         if(url.search('\\?') < 0) {
484                 return '?';
485         } else {
486                 return '&';
487         }
488 }
489
490 String.prototype.normalizeLink = function () {
491         var ret = this.replace('https:', 'http:');
492         var ret = ret.replace('//www', '//');
493         return ret.rtrim();
494 };
495
496 function cleanContactUrl(url) {
497         var parts = parseUrl(url);
498
499         if(! ("scheme" in parts) || ! ("host" in parts)) {
500                 return url;
501         }
502
503         var newUrl =parts["scheme"] + "://" + parts["host"];
504
505         if("port" in parts) {
506                 newUrl += ":" + parts["port"];
507         }
508
509         if("path" in parts) {
510                 newUrl += parts["path"];
511         }
512
513 //      if(url != newUrl) {
514 //              console.log("Cleaned contact url " + url + " to " + newUrl);
515 //      }
516
517         return newUrl;
518 }
519
520 function parseUrl (str, component) { // eslint-disable-line camelcase
521         //       discuss at: http://locutusjs.io/php/parse_url/
522         //      original by: Steven Levithan (http://blog.stevenlevithan.com)
523         // reimplemented by: Brett Zamir (http://brett-zamir.me)
524         //         input by: Lorenzo Pisani
525         //         input by: Tony
526         //      improved by: Brett Zamir (http://brett-zamir.me)
527         //           note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
528         //           note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
529         //           note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
530         //           note 1: Does not replace invalid characters with '_' as in PHP,
531         //           note 1: nor does it return false with
532         //           note 1: a seriously malformed URL.
533         //           note 1: Besides function name, is essentially the same as parseUri as
534         //           note 1: well as our allowing
535         //           note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
536         //        example 1: parse_url('http://user:pass@host/path?a=v#a')
537         //        returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
538         //        example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
539         //        returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
540         //        example 3: parse_url('https://host.domain.tld/a@b.c/folder')
541         //        returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
542         //        example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
543         //        returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
544
545         var query
546
547         var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
548
549         var key = [
550                 'source',
551                 'scheme',
552                 'authority',
553                 'userInfo',
554                 'user',
555                 'pass',
556                 'host',
557                 'port',
558                 'relative',
559                 'path',
560                 'directory',
561                 'file',
562                 'query',
563                 'fragment'
564         ]
565
566         // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
567         var parser = {
568                 php: new RegExp([
569                         '(?:([^:\\/?#]+):)?',
570                         '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
571                         '()',
572                         '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
573                 ].join('')),
574                 strict: new RegExp([
575                         '(?:([^:\\/?#]+):)?',
576                         '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
577                         '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
578                 ].join('')),
579                 loose: new RegExp([
580                         '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
581                         '(?:\\/\\/\\/?)?',
582                         '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
583                         '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
584                         '(?:\\?([^#]*))?(?:#(.*))?)'
585                 ].join(''))
586         }
587
588         var m = parser[mode].exec(str)
589         var uri = {}
590         var i = 14
591
592         while (i--) {
593                 if (m[i]) {
594                         uri[key[i]] = m[i]
595                 }
596         }
597
598         if (component) {
599                 return uri[component.replace('PHP_URL_', '').toLowerCase()]
600         }
601
602         if (mode !== 'php') {
603                 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
604                 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
605                 uri[name] = {}
606                 query = uri[key[12]] || ''
607                 query.replace(parser, function ($0, $1, $2) {
608                         if ($1) {
609                                 uri[name][$1] = $2
610                         }
611                 })
612         }
613
614         delete uri.source
615         return uri
616 }
617
618 // trim function to replace whithespace after the string
619 String.prototype.rtrim = function() {
620         var trimmed = this.replace(/\s+$/g, '');
621         return trimmed;
622 };
623
624 /**
625  * Scroll the screen to the item element whose id is provided, then highlights it
626  *
627  * Note: jquery.color.js is required
628  *
629  * @param {string} elementId The item element id
630  * @returns {undefined}
631  */
632 function scrollToItem(elementId) {
633         if (typeof elementId === "undefined") {
634                 return;
635         }
636
637         var $el = $('#' + elementId +  ' > .media');
638         // Test if the Item exists
639         if (!$el.length) {
640                 return;
641         }
642
643         // Define the colors which are used for highlighting
644         var colWhite = {backgroundColor:'#F5F5F5'};
645         var colShiny = {backgroundColor:'#FFF176'};
646
647         // Get the Item Position (we need to substract 100 to match correct position
648         var itemPos = $el.offset().top - 100;
649
650         // Scroll to the DIV with the ID (GUID)
651         $('html, body').animate({
652                 scrollTop: itemPos
653         }, 400, function() {
654                 // Highlight post/commenent with ID  (GUID)
655                 $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
656         });
657 }
658
659 // format a html string to pure text
660 function htmlToText(htmlString) {
661         // Replace line breaks with spaces
662         var text = htmlString.replace(/<br>/g, ' ');
663         // Strip the text out of the html string
664         text = text.replace(/<[^>]*>/g, '');
665
666         return text;
667 }
668
669 /**
670  * Sends a /like API call and updates the display of the relevant action button
671  * before the update reloads the item.
672  *
673  * @param {string} ident The id of the relevant item
674  * @param {string} verb The verb of the action
675  * @returns {undefined}
676  */
677 function doLikeAction(ident, verb) {
678         unpause();
679
680         if (verb.indexOf('attend') === 0) {
681                 $('.item-' + ident + ' .button-event:not(#' + verb + '-' + ident + ')').removeClass('active');
682         }
683         $('#' + verb + '-' + ident).toggleClass('active');
684         $('#like-rotator-' + ident.toString()).show();
685         $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
686         liking = 1;
687         force_update = true;
688         update_item = ident.toString();
689 }
690
691 // Decodes a hexadecimally encoded binary string
692 function hex2bin (s) {
693         //  discuss at: http://locutus.io/php/hex2bin/
694         // original by: Dumitru Uzun (http://duzun.me)
695         //   example 1: hex2bin('44696d61')
696         //   returns 1: 'Dima'
697         //   example 2: hex2bin('00')
698         //   returns 2: '\x00'
699         //   example 3: hex2bin('2f1q')
700         //   returns 3: false
701         var ret = [];
702         var i = 0;
703         var l;
704         s += '';
705
706         for (l = s.length; i < l; i += 2) {
707                 var c = parseInt(s.substr(i, 1), 16);
708                 var k = parseInt(s.substr(i + 1, 1), 16);
709                 if (isNaN(c) || isNaN(k)) {
710                         return false;
711                 }
712                 ret.push((c << 4) | k);
713         }
714         return String.fromCharCode.apply(String, ret);
715 }
716
717 // Convert binary data into hexadecimal representation
718 function bin2hex (s) {
719         // From: http://phpjs.org/functions
720         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
721         // +   bugfixed by: Onno Marsman
722         // +   bugfixed by: Linuxworld
723         // +   improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616)
724         // *     example 1: bin2hex('Kev');
725         // *     returns 1: '4b6576'
726         // *     example 2: bin2hex(String.fromCharCode(0x00));
727         // *     returns 2: '00'
728
729         var i, l, o = "", n;
730
731         s += "";
732
733         for (i = 0, l = s.length; i < l; i++) {
734                 n = s.charCodeAt(i).toString(16);
735                 o += n.length < 2 ? "0" + n : n;
736         }
737
738         return o;
739 }
740
741 // Dropdown menus with the class "dropdown-head" will display the active tab
742 // as button text
743 function toggleDropdownText(elm) {
744                 $(elm).closest(".dropdown").find('.btn').html($(elm).text() + ' <span class="caret"></span>');
745                 $(elm).closest(".dropdown").find('.btn').val($(elm).data('value'));
746                 $(elm).closest("ul").children("li").show();
747                 $(elm).parent("li").hide();
748 }
749
750 // Check if element does have a specific class
751 function hasClass(elem, cls) {
752         return (" " + elem.className + " " ).indexOf( " "+cls+" " ) > -1;
753 }