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
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.
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")) {
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 // add search-heading to the scecond navbar
99 if( $(".search-heading")) {
100 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
105 //$('ul.flex-nav').flexMenu();
107 // initialize the bootstrap tooltips
109 selector: '[data-toggle="tooltip"]',
120 // initialize the bootstrap-select
121 $('.selectpicker').selectpicker();
123 // append the vcard-short-info to the second nav after passing the element
124 // with .p-addr (vcard). Use scrollspy to get the scroll position.
125 if( $("aside .vcard .p-addr").length) {
126 $(".vcard .p-addr").scrollspy({
127 min: $(".vcard .p-addr").position().top - 50,
128 onLeaveTop: function onLeave(element) {
129 $("#vcard-short-info").fadeOut(500, function () {
130 $("#vcard-short-info").appendTo("#vcard-short-info-wrapper");
135 onEnter: function(element) {
136 $("#vcard-short-info").appendTo("#nav-short-info");
137 $("#vcard-short-info").fadeIn(500);
142 // move the forum contact information of the network page into the second navbar
143 if( $(".network-content-wrapper > #viewcontact_wrapper-network").length) {
144 // get the contact-wrapper element and append it to the second nav bar
145 // Note: We need the first() element with this class since at the present time we
146 // store also the js template information in the html code and thats why
147 // there are two elements with this class but we don't want the js template
148 $(".network-content-wrapper > #viewcontact_wrapper-network .contact-wrapper").first().appendTo("#nav-short-info");
151 //function commentOpenUI(obj, id) {
152 // $(document).unbind( "click.commentOpen", handler );
154 // var handler = function() {
155 // if(obj.value == '{{$comment}}') {
157 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
158 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
159 // // The submit button gets tabindex + 1
160 // $("#comment-edit-text-" + id).attr('tabindex','9');
161 // $("#comment-edit-submit-" + id).attr('tabindex','10');
162 // $("#comment-edit-submit-wrapper-" + id).show();
166 // $(document).bind( "click.commentOpen", handler );
169 //function commentCloseUI(obj, id) {
170 // $(document).unbind( "click.commentClose", handler );
172 // var handler = function() {
173 // if(obj.value === '') {
174 // obj.value = '{{$comment}}';
175 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
176 // $("#comment-edit-text-" + id).removeAttr('tabindex');
177 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
178 // $("#comment-edit-submit-wrapper-" + id).hide();
182 // $(document).bind( "click.commentClose", handler );
185 function openClose(theID) {
186 var elem = document.getElementById(theID);
188 if( $(elem).is(':visible')) {
189 $(elem).slideUp(200);
192 $(elem).slideDown(200);
196 function showHide(theID) {
197 if(document.getElementById(theID).style.display == "block") {
198 document.getElementById(theID).style.display = "none"
201 document.getElementById(theID).style.display = "block"
206 function showHideComments(id) {
207 if( $('#collapsed-comments-' + id).is(':visible')) {
208 $('#collapsed-comments-' + id).slideUp();
209 $('#hide-comments-' + id).html(window.showMore);
210 $('#hide-comments-total-' + id).show();
213 $('#collapsed-comments-' + id).slideDown();
214 $('#hide-comments-' + id).html(window.showFewer);
215 $('#hide-comments-total-' + id).hide();
220 function justifyPhotos() {
221 justifiedGalleryActive = true;
222 $('#photo-album-contents').justifiedGallery({
233 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
236 function justifyPhotosAjax() {
237 justifiedGalleryActive = true;
238 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
241 function loadScript(url, callback) {
242 // Adding the script tag to the head as suggested before
243 var head = document.getElementsByTagName('head')[0];
244 var script = document.createElement('script');
245 script.type = 'text/javascript';
248 // Then bind the event to the callback function.
249 // There are several events for cross browser compatibility.
250 script.onreadystatechange = callback;
251 script.onload = callback;
254 head.appendChild(script);
257 function random_digits(digits) {
261 for(var i = 0; i < digits; i++) {
262 var rn = Math.round(Math.random() * (9));
269 // Does we need a ? or a & to append values to a url
270 function qOrAmp(url) {
271 if(url.search('\\?') < 0) {
278 function contact_filter(item) {
279 // get the html content from the js template of the contact-wrapper
280 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
285 username: item.username,
287 img_hover: item.img_hover,
288 edit_hover: item.edit_hover,
289 account_type: item.account_type,
290 photo_menu: item.photo_menu,
291 alt_text: item.alt_text,
292 dir_icon: item.dir_icon,
293 sparkle: item.sparkle,
294 itemurl: item.itemurl,
296 network: item.network,
298 details: item.details,
301 // open a new jSmart instance with the template
302 var tpl = new jSmart (contact_tpl);
304 // replace the variable with the values
305 var html = tpl.fetch(variables);
310 function filter_replace(item) {
316 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
317 if(typeof typ === 'undefined') typ = '';
318 if(typeof autosubmit === 'undefined') autosubmit = false;
320 // Autocomplete contacts
322 match: /(^)([^\n]+)$/,
324 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
325 replace: filter_replace,
326 template: contact_filter,
329 this.attr('autocomplete','off');
330 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
332 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
337 // current time in milliseconds, to send each request to make sure
338 // we 're not getting 304 response
340 return new Date().getTime();
343 String.prototype.normalizeLink = function () {
344 var ret = this.replace('https:', 'http:');
345 var ret = ret.replace('//www', '//');
349 function cleanContactUrl(url) {
350 var parts = parseUrl(url);
352 if(! ("scheme" in parts) || ! ("host" in parts)) {
356 var newUrl =parts["scheme"] + "://" + parts["host"];
358 if("port" in parts) {
359 newUrl += ":" + parts["port"];
362 if("path" in parts) {
363 newUrl += parts["path"];
366 // if(url != newUrl) {
367 // console.log("Cleaned contact url " + url + " to " + newUrl);
373 function parseUrl (str, component) { // eslint-disable-line camelcase
374 // discuss at: http://locutusjs.io/php/parse_url/
375 // original by: Steven Levithan (http://blog.stevenlevithan.com)
376 // reimplemented by: Brett Zamir (http://brett-zamir.me)
377 // input by: Lorenzo Pisani
379 // improved by: Brett Zamir (http://brett-zamir.me)
380 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
381 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
382 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
383 // note 1: Does not replace invalid characters with '_' as in PHP,
384 // note 1: nor does it return false with
385 // note 1: a seriously malformed URL.
386 // note 1: Besides function name, is essentially the same as parseUri as
387 // note 1: well as our allowing
388 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
389 // example 1: parse_url('http://user:pass@host/path?a=v#a')
390 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
391 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
392 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
393 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
394 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
395 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
396 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
400 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
419 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
422 '(?:([^:\\/?#]+):)?',
423 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
425 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
428 '(?:([^:\\/?#]+):)?',
429 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
430 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
433 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
435 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
436 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
437 '(?:\\?([^#]*))?(?:#(.*))?)'
441 var m = parser[mode].exec(str)
452 return uri[component.replace('PHP_URL_', '').toLowerCase()]
455 if (mode !== 'php') {
456 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
457 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
459 query = uri[key[12]] || ''
460 query.replace(parser, function ($0, $1, $2) {
471 // trim function to replace whithespace after the string
472 String.prototype.rtrim = function() {
473 var trimmed = this.replace(/\s+$/g, '');