2 var jotcache = ''; //The jot cache. We use it as cache to restore old/original jot content
4 $(document).ready(function(){
5 //fade in/out based on scrollTop value
6 $(window).scroll(function () {
7 if ($(this).scrollTop() > 1000) {
8 $("#back-to-top").fadeIn();
10 $("#back-to-top").fadeOut();
14 // scroll body to 0px on click
15 $("#back-to-top").click(function () {
16 $("body,html").animate({
22 // add the class "selected" to group widges li if li > a does have the class group-selected
23 if( $("#sidebar-group-ul li a").hasClass("group-selected")) {
24 $("#sidebar-group-ul li a.group-selected").parent("li").addClass("selected");
27 // add the class "selected" to forums widges li if li > a does have the class forum-selected
28 if( $("#forumlist-sidbar-ul li a").hasClass("forum-selected")) {
29 $("#forumlist-sidbar-ul li a.forum-selected").parent("li").addClass("selected");
32 // add the class "active" to tabmenuli if li > a does have the class active
33 if( $("#tabmenu ul li a").hasClass("active")) {
34 $("#tabmenu ul li a.active").parent("li").addClass("active");
37 // give select fields an boostrap classes
38 // @todo: this needs to be changed in friendica core
39 $(".field.select, .field.custom").addClass("form-group");
40 $(".field.select > select, .field.custom > select").addClass("form-control");
42 // move the tabbar to the second nav bar
43 if( $("ul.tabbar").length ) {
44 $("ul.tabbar").appendTo("#topbar-second > .container > #tabmenu");
47 // add mask css url to the logo-img container
49 // This is for firefox - we use a mask which looks like the friendica logo to apply user collers
50 // to the friendica logo (the mask is in nav.tpl at the botom). To make it work we need to apply the
51 // correct url. The only way which comes to my mind was to do this with js
52 // So we apply the correct url (with the link to the id of the mask) after the page is loaded.
53 if($("#logo-img").length ) {
54 var pageurl = "url('" + window.location.href + "#logo-mask')";
55 $("#logo-img").css({"mask": pageurl});
58 // make responsive tabmenu with flexmenu.js
59 // the menupoints which doesn't fit in the second nav bar will moved to a
60 // dropdown menu. Look at common_tabs.tpl
61 $("ul.tabs.flex-nav").flexMenu({
63 'popupClass': "dropdown-menu pull-right",
64 'popupAbsolute': false,
65 'target': ".flex-target"
68 // add Jot botton to the scecond navbar
69 if( $("section #jotOpen").length ) {
70 $("section #jotOpen").appendTo("#topbar-second > .container > #navbar-button");
71 if( $("#jot-popup").is(":hidden")) $("#topbar-second > .container > #navbar-button #jotOpen").hide();
74 // show bulk deletion button at network page if checkbox is checked
75 $("body").change("input.item-select", function(){
78 // We need to get all checked items, so it would close the delete button
79 // if we uncheck one item and others are still checked.
80 // So return checked = true if there is any checked item
81 $('input.item-select').each( function() {
82 if($(this).is(':checked')) {
89 $("a#item-delete-selected").fadeTo(400, 1);
90 $("a#item-delete-selected").show();
92 $("a#item-delete-selected").fadeTo(400, 0, function(){
93 $("a#item-delete-selected").hide();
98 //$('ul.flex-nav').flexMenu();
100 // initialize the bootstrap tooltips
102 selector: '[data-toggle="tooltip"]',
113 // initialize the bootstrap-select
114 $('.selectpicker').selectpicker();
116 // add search-heading to the seccond navbar
117 if( $(".search-heading").length) {
118 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
121 // add search results heading to the second navbar
122 // and insert the search value to the top nav search input
123 if( $(".search-content-wrapper").length ) {
124 // get the text of the heading (we catch the plain text because we don't
125 // want to have a h4 heading in the navbar
126 var searchText = $(".section-title-wrapper > h2").text();
127 // insert the plain text in a <h4> heading and give it a class
128 var newText = '<h4 class="search-heading">'+searchText+'</h4>';
129 // append the new heading to the navbar
130 $("#topbar-second > .container > #tabmenu").append(newText);
132 // try to get the value of the original search input to insert it
133 // as value in the nav-search-input
134 var searchValue = $("#search-wrapper .form-group-search input").val();
136 // if the orignal search value isn't available use the location path as value
137 if( typeof searchValue === "undefined") {
138 // get the location path
139 var urlPath = window.location.search
140 // and split it up in its parts
141 var splitPath = urlPath.split(/(\?search?=)(.*$)/);
143 if(typeof splitPath[2] !== 'undefined') {
144 // decode the path (e.g to decode %40 to the character @)
145 var searchValue = decodeURIComponent(splitPath[2]);
149 if( typeof searchValue !== "undefined") {
150 $("#nav-search-input-field").val(searchValue);
154 // move the "Save the search" button to the second navbar
155 $(".search-content-wrapper #search-save-form ").appendTo("#topbar-second > .container > #navbar-button");
157 // append the vcard-short-info to the second nav after passing the element
158 // with .fn (vcard username). Use scrollspy to get the scroll position.
159 if( $("aside .vcard .fn").length) {
160 $(".vcard .fn").scrollspy({
161 min: $(".vcard .fn").position().top - 50,
162 onLeaveTop: function onLeave(element) {
163 $("#vcard-short-info").fadeOut(500, function () {
164 $("#vcard-short-info").appendTo("#vcard-short-info-wrapper");
167 onEnter: function(element) {
168 $("#vcard-short-info").appendTo("#nav-short-info");
169 $("#vcard-short-info").fadeIn(500);
174 // move the forum contact information of the network page into the second navbar
175 if( $(".network-content-wrapper > #viewcontact_wrapper-network").length) {
176 // get the contact-wrapper element and append it to the second nav bar
177 // Note: We need the first() element with this class since at the present time we
178 // store also the js template information in the html code and thats why
179 // there are two elements with this class but we don't want the js template
180 $(".network-content-wrapper > #viewcontact_wrapper-network .contact-wrapper").first().appendTo("#nav-short-info");
183 // move heading from network stream to the second navbar nav-short-info section
184 if( $(".network-content-wrapper > .section-title-wrapper").length) {
185 // get the heading element
186 var heading = $(".network-content-wrapper > .section-title-wrapper > h2");
187 // get the text of the heading
188 var headingContent = heading.text();
189 // create a new element with the content of the heading
190 var newText = '<h4 class="heading" data-toggle="tooltip" title="'+headingContent+'">'+headingContent+'</h4>';
191 // remove the old heading element
193 // put the new element to the second nav bar
194 $("#topbar-second #nav-short-info").append(newText);
197 if( $(".community-content-wrapper").length) {
198 // get the heading element
199 var heading = $(".community-content-wrapper > h3").first();
200 // get the text of the heading
201 var headingContent = heading.text();
202 // create a new element with the content of the heading
203 var newText = '<h4 class="heading">'+headingContent+'</h4>';
204 // remove the old heading element
206 // put the new element to the second nav bar
207 $("#topbar-second > .container > #tabmenu").append(newText);
210 //function commentOpenUI(obj, id) {
211 // $(document).unbind( "click.commentOpen", handler );
213 // var handler = function() {
214 // if(obj.value == '{{$comment}}') {
216 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
217 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
218 // // The submit button gets tabindex + 1
219 // $("#comment-edit-text-" + id).attr('tabindex','9');
220 // $("#comment-edit-submit-" + id).attr('tabindex','10');
221 // $("#comment-edit-submit-wrapper-" + id).show();
225 // $(document).bind( "click.commentOpen", handler );
228 //function commentCloseUI(obj, id) {
229 // $(document).unbind( "click.commentClose", handler );
231 // var handler = function() {
232 // if(obj.value === '') {
233 // obj.value = '{{$comment}}';
234 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
235 // $("#comment-edit-text-" + id).removeAttr('tabindex');
236 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
237 // $("#comment-edit-submit-wrapper-" + id).hide();
241 // $(document).bind( "click.commentClose", handler );
244 function openClose(theID) {
245 var elem = document.getElementById(theID);
247 if( $(elem).is(':visible')) {
248 $(elem).slideUp(200);
251 $(elem).slideDown(200);
255 function showHide(theID) {
256 if(document.getElementById(theID).style.display == "block") {
257 document.getElementById(theID).style.display = "none"
260 document.getElementById(theID).style.display = "block"
265 function showHideComments(id) {
266 if( $('#collapsed-comments-' + id).is(':visible')) {
267 $('#collapsed-comments-' + id).slideUp();
268 $('#hide-comments-' + id).html(window.showMore);
269 $('#hide-comments-total-' + id).show();
272 $('#collapsed-comments-' + id).slideDown();
273 $('#hide-comments-' + id).html(window.showFewer);
274 $('#hide-comments-total-' + id).hide();
279 function justifyPhotos() {
280 justifiedGalleryActive = true;
281 $('#photo-album-contents').justifiedGallery({
292 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
295 function justifyPhotosAjax() {
296 justifiedGalleryActive = true;
297 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
300 function loadScript(url, callback) {
301 // Adding the script tag to the head as suggested before
302 var head = document.getElementsByTagName('head')[0];
303 var script = document.createElement('script');
304 script.type = 'text/javascript';
307 // Then bind the event to the callback function.
308 // There are several events for cross browser compatibility.
309 script.onreadystatechange = callback;
310 script.onload = callback;
313 head.appendChild(script);
316 function random_digits(digits) {
320 for(var i = 0; i < digits; i++) {
321 var rn = Math.round(Math.random() * (9));
328 // Does we need a ? or a & to append values to a url
329 function qOrAmp(url) {
330 if(url.search('\\?') < 0) {
337 function contact_filter(item) {
338 // get the html content from the js template of the contact-wrapper
339 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
344 username: item.username,
346 img_hover: item.img_hover,
347 edit_hover: item.edit_hover,
348 account_type: item.account_type,
349 photo_menu: item.photo_menu,
350 alt_text: item.alt_text,
351 dir_icon: item.dir_icon,
352 sparkle: item.sparkle,
353 itemurl: item.itemurl,
355 network: item.network,
357 details: item.details,
360 // open a new jSmart instance with the template
361 var tpl = new jSmart (contact_tpl);
363 // replace the variable with the values
364 var html = tpl.fetch(variables);
369 function filter_replace(item) {
375 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
376 if(typeof typ === 'undefined') typ = '';
377 if(typeof autosubmit === 'undefined') autosubmit = false;
379 // Autocomplete contacts
381 match: /(^)([^\n]+)$/,
383 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
384 replace: filter_replace,
385 template: contact_filter,
388 this.attr('autocomplete','off');
389 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
391 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
396 // current time in milliseconds, to send each request to make sure
397 // we 're not getting 304 response
399 return new Date().getTime();
402 String.prototype.normalizeLink = function () {
403 var ret = this.replace('https:', 'http:');
404 var ret = ret.replace('//www', '//');
408 function cleanContactUrl(url) {
409 var parts = parseUrl(url);
411 if(! ("scheme" in parts) || ! ("host" in parts)) {
415 var newUrl =parts["scheme"] + "://" + parts["host"];
417 if("port" in parts) {
418 newUrl += ":" + parts["port"];
421 if("path" in parts) {
422 newUrl += parts["path"];
425 // if(url != newUrl) {
426 // console.log("Cleaned contact url " + url + " to " + newUrl);
432 function parseUrl (str, component) { // eslint-disable-line camelcase
433 // discuss at: http://locutusjs.io/php/parse_url/
434 // original by: Steven Levithan (http://blog.stevenlevithan.com)
435 // reimplemented by: Brett Zamir (http://brett-zamir.me)
436 // input by: Lorenzo Pisani
438 // improved by: Brett Zamir (http://brett-zamir.me)
439 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
440 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
441 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
442 // note 1: Does not replace invalid characters with '_' as in PHP,
443 // note 1: nor does it return false with
444 // note 1: a seriously malformed URL.
445 // note 1: Besides function name, is essentially the same as parseUri as
446 // note 1: well as our allowing
447 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
448 // example 1: parse_url('http://user:pass@host/path?a=v#a')
449 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
450 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
451 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
452 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
453 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
454 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
455 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
459 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
478 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
481 '(?:([^:\\/?#]+):)?',
482 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
484 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
487 '(?:([^:\\/?#]+):)?',
488 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
489 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
492 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
494 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
495 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
496 '(?:\\?([^#]*))?(?:#(.*))?)'
500 var m = parser[mode].exec(str)
511 return uri[component.replace('PHP_URL_', '').toLowerCase()]
514 if (mode !== 'php') {
515 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
516 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
518 query = uri[key[12]] || ''
519 query.replace(parser, function ($0, $1, $2) {
530 // trim function to replace whithespace after the string
531 String.prototype.rtrim = function() {
532 var trimmed = this.replace(/\s+$/g, '');