1 $(document).ready(function(){
2 //fade in/out based on scrollTop value
3 $(window).scroll(function () {
4 if ($(this).scrollTop() > 1000) {
5 $("#back-to-top").fadeIn();
7 $("#back-to-top").fadeOut();
11 // scroll body to 0px on click
12 $("#back-to-top").click(function () {
13 $("body,html").animate({
19 // add the class "selected" to group widges li if li > a does have the class group-selected
20 if( $("#sidebar-group-ul li a").hasClass("group-selected")) {
21 $("#sidebar-group-ul li a.group-selected").parent("li").addClass("selected");
24 // add the class "selected" to forums widges li if li > a does have the class forum-selected
25 if( $("#forumlist-sidbar-ul li a").hasClass("forum-selected")) {
26 $("#forumlist-sidbar-ul li a.forum-selected").parent("li").addClass("selected");
29 // add the class "active" to tabmenuli if li > a does have the class active
30 if( $("#tabmenu ul li a").hasClass("active")) {
31 $("#tabmenu ul li a.active").parent("li").addClass("active");
34 // give select fields an boostrap classes
35 // @todo: this needs to be changed in friendica core
36 $(".field.select, .field.custom").addClass("form-group");
37 $(".field.select > select, .field.custom > select").addClass("form-control");
39 // move the tabbar to the second nav bar
41 $("ul.tabbar").appendTo("#topbar-second > .container > #tabmenu");
44 // add mask css url to the logo-img container
46 // This is for firefox - we use a mask which looks like the friendica logo to apply user collers
47 // to the friendica logo (the mask is in nav.tpl at the botom). To make it work we need to apply the
48 // correct url. The only way which comes to my mind was to do this with js
49 // So we apply the correct url (with the link to the id of the mask) after the page is loaded.
51 var pageurl = "url('" + window.location.href + "#logo-mask')";
52 $("#logo-img").css({"mask": pageurl});
55 // make responsive tabmenu with flexmenu.js
56 // the menupoints which doesn't fit in the second nav bar will moved to a
57 // dropdown menu. Look at common_tabs.tpl
58 $("ul.tabs.flex-nav").flexMenu({
60 'popupClass': "dropdown-menu pull-right",
61 'popupAbsolute': false,
62 'target': ".flex-target"
65 // add Jot botton to the scecond navbar
66 if( $("section #jotOpen")) {
67 $("section #jotOpen").appendTo("#topbar-second > .container > #navbar-button");
68 if( $("#jot-popup").is(":hidden")) $("#topbar-second > .container > #navbar-button #jotOpen").hide();
71 // show bulk deletion button at network page if checkbox is checked
72 $("body").change("input.item-select", function(){
75 // We need to get all checked items, so it would close the delete button
76 // if we uncheck one item and others are still checked.
77 // So return checked = true if there is any checked item
78 $('input.item-select').each( function() {
79 if($(this).is(':checked')) {
86 $("a#item-delete-selected").fadeTo(400, 1);
87 $("a#item-delete-selected").show();
89 $("a#item-delete-selected").fadeTo(400, 0, function(){
90 $("a#item-delete-selected").hide();
95 // add search-heading to the scecond navbar
96 if( $(".search-heading")) {
97 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
102 //$('ul.flex-nav').flexMenu();
104 // initialize the bootstrap tooltips
106 selector: '[data-toggle="tooltip"]',
119 //function commentOpenUI(obj, id) {
120 // $(document).unbind( "click.commentOpen", handler );
122 // var handler = function() {
123 // if(obj.value == '{{$comment}}') {
125 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
126 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
127 // // The submit button gets tabindex + 1
128 // $("#comment-edit-text-" + id).attr('tabindex','9');
129 // $("#comment-edit-submit-" + id).attr('tabindex','10');
130 // $("#comment-edit-submit-wrapper-" + id).show();
134 // $(document).bind( "click.commentOpen", handler );
137 //function commentCloseUI(obj, id) {
138 // $(document).unbind( "click.commentClose", handler );
140 // var handler = function() {
141 // if(obj.value === '') {
142 // obj.value = '{{$comment}}';
143 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
144 // $("#comment-edit-text-" + id).removeAttr('tabindex');
145 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
146 // $("#comment-edit-submit-wrapper-" + id).hide();
150 // $(document).bind( "click.commentClose", handler );
153 function openClose(theID) {
154 var elem = document.getElementById(theID);
156 if( $(elem).is(':visible')) {
157 $(elem).slideUp(200);
160 $(elem).slideDown(200);
164 function showHide(theID) {
165 if(document.getElementById(theID).style.display == "block") {
166 document.getElementById(theID).style.display = "none"
169 document.getElementById(theID).style.display = "block"
174 function showHideComments(id) {
175 if( $('#collapsed-comments-' + id).is(':visible')) {
176 $('#collapsed-comments-' + id).slideUp();
177 $('#hide-comments-' + id).html(window.showMore);
178 $('#hide-comments-total-' + id).show();
181 $('#collapsed-comments-' + id).slideDown();
182 $('#hide-comments-' + id).html(window.showFewer);
183 $('#hide-comments-total-' + id).hide();
188 function justifyPhotos() {
189 justifiedGalleryActive = true;
190 $('#photo-album-contents').justifiedGallery({
201 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
204 function justifyPhotosAjax() {
205 justifiedGalleryActive = true;
206 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
209 function loadScript(url, callback) {
210 // Adding the script tag to the head as suggested before
211 var head = document.getElementsByTagName('head')[0];
212 var script = document.createElement('script');
213 script.type = 'text/javascript';
216 // Then bind the event to the callback function.
217 // There are several events for cross browser compatibility.
218 script.onreadystatechange = callback;
219 script.onload = callback;
222 head.appendChild(script);
225 function random_digits(digits) {
229 for(var i = 0; i < digits; i++) {
230 var rn = Math.round(Math.random() * (9));
237 // Does we need a ? or a & to append values to a url
238 function qOrAmp(url) {
239 if(url.search('\\?') < 0) {
246 function contact_filter(item) {
247 // get the html content from the js template of the contact-wrapper
248 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
253 username: item.username,
255 img_hover: item.img_hover,
256 edit_hover: item.edit_hover,
257 account_type: item.account_type,
258 photo_menu: item.photo_menu,
259 alt_text: item.alt_text,
260 dir_icon: item.dir_icon,
261 sparkle: item.sparkle,
262 itemurl: item.itemurl,
264 network: item.network,
266 details: item.details,
269 // open a new jSmart instance with the template
270 var tpl = new jSmart (contact_tpl);
272 // replace the variable with the values
273 var html = tpl.fetch(variables);
278 function filter_replace(item) {
284 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
285 if(typeof typ === 'undefined') typ = '';
286 if(typeof autosubmit === 'undefined') autosubmit = false;
288 // Autocomplete contacts
290 match: /(^)([^\n]+)$/,
292 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
293 replace: filter_replace,
294 template: contact_filter,
297 this.attr('autocomplete','off');
298 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
300 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
305 // current time in milliseconds, to send each request to make sure
306 // we 're not getting 304 response
308 return new Date().getTime();
311 String.prototype.normalizeLink = function () {
312 var ret = this.replace('https:', 'http:');
313 var ret = ret.replace('//www', '//');
317 function cleanContactUrl(url) {
318 var parts = parseUrl(url);
320 if(! ("scheme" in parts) || ! ("host" in parts)) {
324 var newUrl =parts["scheme"] + "://" + parts["host"];
326 if("port" in parts) {
327 newUrl += ":" + parts["port"];
330 if("path" in parts) {
331 newUrl += parts["path"];
334 // if(url != newUrl) {
335 // console.log("Cleaned contact url " + url + " to " + newUrl);
341 function parseUrl (str, component) { // eslint-disable-line camelcase
342 // discuss at: http://locutusjs.io/php/parse_url/
343 // original by: Steven Levithan (http://blog.stevenlevithan.com)
344 // reimplemented by: Brett Zamir (http://brett-zamir.me)
345 // input by: Lorenzo Pisani
347 // improved by: Brett Zamir (http://brett-zamir.me)
348 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
349 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
350 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
351 // note 1: Does not replace invalid characters with '_' as in PHP,
352 // note 1: nor does it return false with
353 // note 1: a seriously malformed URL.
354 // note 1: Besides function name, is essentially the same as parseUri as
355 // note 1: well as our allowing
356 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
357 // example 1: parse_url('http://user:pass@host/path?a=v#a')
358 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
359 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
360 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
361 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
362 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
363 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
364 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
368 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
387 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
390 '(?:([^:\\/?#]+):)?',
391 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
393 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
396 '(?:([^:\\/?#]+):)?',
397 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
398 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
401 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
403 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
404 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
405 '(?:\\?([^#]*))?(?:#(.*))?)'
409 var m = parser[mode].exec(str)
420 return uri[component.replace('PHP_URL_', '').toLowerCase()]
423 if (mode !== 'php') {
424 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
425 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
427 query = uri[key[12]] || ''
428 query.replace(parser, function ($0, $1, $2) {
439 // trim function to replace whithespace after the string
440 String.prototype.rtrim = function() {
441 var trimmed = this.replace(/\s+$/g, '');