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