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();
125 //function commentOpenUI(obj, id) {
126 // $(document).unbind( "click.commentOpen", handler );
128 // var handler = function() {
129 // if(obj.value == '{{$comment}}') {
131 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
132 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
133 // // The submit button gets tabindex + 1
134 // $("#comment-edit-text-" + id).attr('tabindex','9');
135 // $("#comment-edit-submit-" + id).attr('tabindex','10');
136 // $("#comment-edit-submit-wrapper-" + id).show();
140 // $(document).bind( "click.commentOpen", handler );
143 //function commentCloseUI(obj, id) {
144 // $(document).unbind( "click.commentClose", handler );
146 // var handler = function() {
147 // if(obj.value === '') {
148 // obj.value = '{{$comment}}';
149 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
150 // $("#comment-edit-text-" + id).removeAttr('tabindex');
151 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
152 // $("#comment-edit-submit-wrapper-" + id).hide();
156 // $(document).bind( "click.commentClose", handler );
159 function openClose(theID) {
160 var elem = document.getElementById(theID);
162 if( $(elem).is(':visible')) {
163 $(elem).slideUp(200);
166 $(elem).slideDown(200);
170 function showHide(theID) {
171 if(document.getElementById(theID).style.display == "block") {
172 document.getElementById(theID).style.display = "none"
175 document.getElementById(theID).style.display = "block"
180 function showHideComments(id) {
181 if( $('#collapsed-comments-' + id).is(':visible')) {
182 $('#collapsed-comments-' + id).slideUp();
183 $('#hide-comments-' + id).html(window.showMore);
184 $('#hide-comments-total-' + id).show();
187 $('#collapsed-comments-' + id).slideDown();
188 $('#hide-comments-' + id).html(window.showFewer);
189 $('#hide-comments-total-' + id).hide();
194 function justifyPhotos() {
195 justifiedGalleryActive = true;
196 $('#photo-album-contents').justifiedGallery({
207 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
210 function justifyPhotosAjax() {
211 justifiedGalleryActive = true;
212 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
215 function loadScript(url, callback) {
216 // Adding the script tag to the head as suggested before
217 var head = document.getElementsByTagName('head')[0];
218 var script = document.createElement('script');
219 script.type = 'text/javascript';
222 // Then bind the event to the callback function.
223 // There are several events for cross browser compatibility.
224 script.onreadystatechange = callback;
225 script.onload = callback;
228 head.appendChild(script);
231 function random_digits(digits) {
235 for(var i = 0; i < digits; i++) {
236 var rn = Math.round(Math.random() * (9));
243 // Does we need a ? or a & to append values to a url
244 function qOrAmp(url) {
245 if(url.search('\\?') < 0) {
252 function contact_filter(item) {
253 // get the html content from the js template of the contact-wrapper
254 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
259 username: item.username,
261 img_hover: item.img_hover,
262 edit_hover: item.edit_hover,
263 account_type: item.account_type,
264 photo_menu: item.photo_menu,
265 alt_text: item.alt_text,
266 dir_icon: item.dir_icon,
267 sparkle: item.sparkle,
268 itemurl: item.itemurl,
270 network: item.network,
272 details: item.details,
275 // open a new jSmart instance with the template
276 var tpl = new jSmart (contact_tpl);
278 // replace the variable with the values
279 var html = tpl.fetch(variables);
284 function filter_replace(item) {
290 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
291 if(typeof typ === 'undefined') typ = '';
292 if(typeof autosubmit === 'undefined') autosubmit = false;
294 // Autocomplete contacts
296 match: /(^)([^\n]+)$/,
298 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
299 replace: filter_replace,
300 template: contact_filter,
303 this.attr('autocomplete','off');
304 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
306 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
311 // current time in milliseconds, to send each request to make sure
312 // we 're not getting 304 response
314 return new Date().getTime();
317 String.prototype.normalizeLink = function () {
318 var ret = this.replace('https:', 'http:');
319 var ret = ret.replace('//www', '//');
323 function cleanContactUrl(url) {
324 var parts = parseUrl(url);
326 if(! ("scheme" in parts) || ! ("host" in parts)) {
330 var newUrl =parts["scheme"] + "://" + parts["host"];
332 if("port" in parts) {
333 newUrl += ":" + parts["port"];
336 if("path" in parts) {
337 newUrl += parts["path"];
340 // if(url != newUrl) {
341 // console.log("Cleaned contact url " + url + " to " + newUrl);
347 function parseUrl (str, component) { // eslint-disable-line camelcase
348 // discuss at: http://locutusjs.io/php/parse_url/
349 // original by: Steven Levithan (http://blog.stevenlevithan.com)
350 // reimplemented by: Brett Zamir (http://brett-zamir.me)
351 // input by: Lorenzo Pisani
353 // improved by: Brett Zamir (http://brett-zamir.me)
354 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
355 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
356 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
357 // note 1: Does not replace invalid characters with '_' as in PHP,
358 // note 1: nor does it return false with
359 // note 1: a seriously malformed URL.
360 // note 1: Besides function name, is essentially the same as parseUri as
361 // note 1: well as our allowing
362 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
363 // example 1: parse_url('http://user:pass@host/path?a=v#a')
364 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
365 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
366 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
367 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
368 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
369 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
370 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
374 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
393 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
396 '(?:([^:\\/?#]+):)?',
397 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
399 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
402 '(?:([^:\\/?#]+):)?',
403 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
404 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
407 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
409 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
410 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
411 '(?:\\?([^#]*))?(?:#(.*))?)'
415 var m = parser[mode].exec(str)
426 return uri[component.replace('PHP_URL_', '').toLowerCase()]
429 if (mode !== 'php') {
430 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
431 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
433 query = uri[key[12]] || ''
434 query.replace(parser, function ($0, $1, $2) {
445 // trim function to replace whithespace after the string
446 String.prototype.rtrim = function() {
447 var trimmed = this.replace(/\s+$/g, '');