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"]',
114 // initialize the bootstrap-select
115 $('.selectpicker').selectpicker();
117 // add search-heading to the seccond navbar
118 if( $(".search-heading").length) {
119 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
122 // add search results heading to the second navbar
123 // and insert the search value to the top nav search input
124 if( $(".search-content-wrapper").length ) {
125 // get the text of the heading (we catch the plain text because we don't
126 // want to have a h4 heading in the navbar
127 var searchText = $(".section-title-wrapper > h2").text();
128 // insert the plain text in a <h4> heading and give it a class
129 var newText = '<h4 class="search-heading">'+searchText+'</h4>';
130 // append the new heading to the navbar
131 $("#topbar-second > .container > #tabmenu").append(newText);
133 // try to get the value of the original search input to insert it
134 // as value in the nav-search-input
135 var searchValue = $("#search-wrapper .form-group-search input").val();
137 // if the orignal search value isn't available use the location path as value
138 if( typeof searchValue === "undefined") {
139 // get the location path
140 var urlPath = window.location.search
141 // and split it up in its parts
142 var splitPath = urlPath.split(/(\?search?=)(.*$)/);
144 if(typeof splitPath[2] !== 'undefined') {
145 // decode the path (e.g to decode %40 to the character @)
146 var searchValue = decodeURIComponent(splitPath[2]);
150 if( typeof searchValue !== "undefined") {
151 $("#nav-search-input-field").val(searchValue);
155 // move the "Save the search" button to the second navbar
156 $(".search-content-wrapper #search-save-form ").appendTo("#topbar-second > .container > #navbar-button");
158 // append the vcard-short-info to the second nav after passing the element
159 // with .fn (vcard username). Use scrollspy to get the scroll position.
160 if( $("aside .vcard .fn").length) {
161 $(".vcard .fn").scrollspy({
162 min: $(".vcard .fn").position().top - 50,
163 onLeaveTop: function onLeave(element) {
164 $("#vcard-short-info").fadeOut(500, function () {
165 $("#vcard-short-info").appendTo("#vcard-short-info-wrapper");
168 onEnter: function(element) {
169 $("#vcard-short-info").appendTo("#nav-short-info");
170 $("#vcard-short-info").fadeIn(500);
175 // move the forum contact information of the network page into the second navbar
176 if( $(".network-content-wrapper > #viewcontact_wrapper-network").length) {
177 // get the contact-wrapper element and append it to the second nav bar
178 // Note: We need the first() element with this class since at the present time we
179 // store also the js template information in the html code and thats why
180 // there are two elements with this class but we don't want the js template
181 $(".network-content-wrapper > #viewcontact_wrapper-network .contact-wrapper").first().appendTo("#nav-short-info");
184 // move heading from network stream to the second navbar nav-short-info section
185 if( $(".network-content-wrapper > .section-title-wrapper").length) {
186 // get the heading element
187 var heading = $(".network-content-wrapper > .section-title-wrapper > h2");
188 // get the text of the heading
189 var headingContent = heading.text();
190 // create a new element with the content of the heading
191 var newText = '<h4 class="heading" data-toggle="tooltip" title="'+headingContent+'">'+headingContent+'</h4>';
192 // remove the old heading element
194 // put the new element to the second nav bar
195 $("#topbar-second #nav-short-info").append(newText);
198 if( $(".community-content-wrapper").length) {
199 // get the heading element
200 var heading = $(".community-content-wrapper > h3").first();
201 // get the text of the heading
202 var headingContent = heading.text();
203 // create a new element with the content of the heading
204 var newText = '<h4 class="heading">'+headingContent+'</h4>';
205 // remove the old heading element
207 // put the new element to the second nav bar
208 $("#topbar-second > .container > #tabmenu").append(newText);
211 // Dropdown menus with the class "dropdown-head" will display the active tab
213 $("body").on('click', '.dropdown-head .dropdown-menu li a', function(){
214 $(this).closest(".dropdown").find('.btn').html($(this).text() + ' <span class="caret"></span>');
215 $(this).closest(".dropdown").find('.btn').val($(this).data('value'));
216 $(this).closest("ul").children("li").show();
217 $(this).parent("li").hide();
221 //function commentOpenUI(obj, id) {
222 // $(document).unbind( "click.commentOpen", handler );
224 // var handler = function() {
225 // if(obj.value == '{{$comment}}') {
227 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
228 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
229 // // The submit button gets tabindex + 1
230 // $("#comment-edit-text-" + id).attr('tabindex','9');
231 // $("#comment-edit-submit-" + id).attr('tabindex','10');
232 // $("#comment-edit-submit-wrapper-" + id).show();
236 // $(document).bind( "click.commentOpen", handler );
239 //function commentCloseUI(obj, id) {
240 // $(document).unbind( "click.commentClose", handler );
242 // var handler = function() {
243 // if(obj.value === '') {
244 // obj.value = '{{$comment}}';
245 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
246 // $("#comment-edit-text-" + id).removeAttr('tabindex');
247 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
248 // $("#comment-edit-submit-wrapper-" + id).hide();
252 // $(document).bind( "click.commentClose", handler );
255 function openClose(theID) {
256 var elem = document.getElementById(theID);
258 if( $(elem).is(':visible')) {
259 $(elem).slideUp(200);
262 $(elem).slideDown(200);
266 function showHide(theID) {
267 if(document.getElementById(theID).style.display == "block") {
268 document.getElementById(theID).style.display = "none"
271 document.getElementById(theID).style.display = "block"
276 function showHideComments(id) {
277 if( $('#collapsed-comments-' + id).is(':visible')) {
278 $('#collapsed-comments-' + id).slideUp();
279 $('#hide-comments-' + id).html(window.showMore);
280 $('#hide-comments-total-' + id).show();
283 $('#collapsed-comments-' + id).slideDown();
284 $('#hide-comments-' + id).html(window.showFewer);
285 $('#hide-comments-total-' + id).hide();
290 function justifyPhotos() {
291 justifiedGalleryActive = true;
292 $('#photo-album-contents').justifiedGallery({
303 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
306 function justifyPhotosAjax() {
307 justifiedGalleryActive = true;
308 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
311 function loadScript(url, callback) {
312 // Adding the script tag to the head as suggested before
313 var head = document.getElementsByTagName('head')[0];
314 var script = document.createElement('script');
315 script.type = 'text/javascript';
318 // Then bind the event to the callback function.
319 // There are several events for cross browser compatibility.
320 script.onreadystatechange = callback;
321 script.onload = callback;
324 head.appendChild(script);
327 function random_digits(digits) {
331 for(var i = 0; i < digits; i++) {
332 var rn = Math.round(Math.random() * (9));
339 // Does we need a ? or a & to append values to a url
340 function qOrAmp(url) {
341 if(url.search('\\?') < 0) {
348 function contact_filter(item) {
349 // get the html content from the js template of the contact-wrapper
350 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
355 username: item.username,
357 img_hover: item.img_hover,
358 edit_hover: item.edit_hover,
359 account_type: item.account_type,
360 photo_menu: item.photo_menu,
361 alt_text: item.alt_text,
362 dir_icon: item.dir_icon,
363 sparkle: item.sparkle,
364 itemurl: item.itemurl,
366 network: item.network,
368 details: item.details,
371 // open a new jSmart instance with the template
372 var tpl = new jSmart (contact_tpl);
374 // replace the variable with the values
375 var html = tpl.fetch(variables);
380 function filter_replace(item) {
386 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
387 if(typeof typ === 'undefined') typ = '';
388 if(typeof autosubmit === 'undefined') autosubmit = false;
390 // Autocomplete contacts
392 match: /(^)([^\n]+)$/,
394 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
395 replace: filter_replace,
396 template: contact_filter,
399 this.attr('autocomplete','off');
400 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
402 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
407 // current time in milliseconds, to send each request to make sure
408 // we 're not getting 304 response
410 return new Date().getTime();
413 String.prototype.normalizeLink = function () {
414 var ret = this.replace('https:', 'http:');
415 var ret = ret.replace('//www', '//');
419 function cleanContactUrl(url) {
420 var parts = parseUrl(url);
422 if(! ("scheme" in parts) || ! ("host" in parts)) {
426 var newUrl =parts["scheme"] + "://" + parts["host"];
428 if("port" in parts) {
429 newUrl += ":" + parts["port"];
432 if("path" in parts) {
433 newUrl += parts["path"];
436 // if(url != newUrl) {
437 // console.log("Cleaned contact url " + url + " to " + newUrl);
443 function parseUrl (str, component) { // eslint-disable-line camelcase
444 // discuss at: http://locutusjs.io/php/parse_url/
445 // original by: Steven Levithan (http://blog.stevenlevithan.com)
446 // reimplemented by: Brett Zamir (http://brett-zamir.me)
447 // input by: Lorenzo Pisani
449 // improved by: Brett Zamir (http://brett-zamir.me)
450 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
451 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
452 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
453 // note 1: Does not replace invalid characters with '_' as in PHP,
454 // note 1: nor does it return false with
455 // note 1: a seriously malformed URL.
456 // note 1: Besides function name, is essentially the same as parseUri as
457 // note 1: well as our allowing
458 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
459 // example 1: parse_url('http://user:pass@host/path?a=v#a')
460 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
461 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
462 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
463 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
464 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
465 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
466 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
470 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
489 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
492 '(?:([^:\\/?#]+):)?',
493 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
495 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
498 '(?:([^:\\/?#]+):)?',
499 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
500 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
503 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
505 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
506 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
507 '(?:\\?([^#]*))?(?:#(.*))?)'
511 var m = parser[mode].exec(str)
522 return uri[component.replace('PHP_URL_', '').toLowerCase()]
525 if (mode !== 'php') {
526 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
527 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
529 query = uri[key[12]] || ''
530 query.replace(parser, function ($0, $1, $2) {
541 // trim function to replace whithespace after the string
542 String.prototype.rtrim = function() {
543 var trimmed = this.replace(/\s+$/g, '');
547 // Scroll to a specific item and highlight it
548 // Note: jquery.color.js is needed
549 function scrollToItem(itemID) {
550 if( typeof itemID === "undefined")
553 var elm = $('#'+itemID);
554 // Test if the Item exists
558 // Define the colors which are used for highlighting
559 var colWhite = {backgroundColor:'#F5F5F5'};
560 var colShiny = {backgroundColor:'#FFF176'};
562 // Get the Item Position (we need to substract 100 to match
564 var itemPos = $(elm).offset().top - 100;
566 // Scroll to the DIV with the ID (GUID)
567 $('html, body').animate({
570 // Highlight post/commenent with ID (GUID)
571 $(elm).animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
575 // format a html string to pure text
576 function htmlToText(htmlString) {
577 // Replace line breaks with spaces
578 var text = htmlString.replace(/<br>/g, ' ');
579 // Strip the text out of the html string
580 text = text.replace(/<[^>]*>/g, '');