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 // add search-headding to the scecond navbar
72 if( $(".search-headding")) {
73 $(".search-headding").appendTo("#topbar-second > .container > #tabmenu");
78 //$('ul.flex-nav').flexMenu();
80 // initialize the bootstrap tooltips
81 $('[data-toggle="tooltip"]').tooltip({
91 // Add Colorbox for viewing Network page images
92 //var cBoxClasses = new Array();
93 $(".wall-item-body a img").each(function(){
94 var aElem = $(this).parent();
95 var imgHref = aElem.attr("href");
97 // We need to make sure we only put a Colorbox on links to Friendica images
98 // We'll try to do this by looking for links of the form
99 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
100 // that that will be unique enough
101 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
103 // Add a unique class to all the images of a certain post, to allow scrolling through
104 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
105 $(this).addClass(cBoxClass);
107 // if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
108 // cBoxClasses.push(cBoxClass);
113 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
114 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
119 // overwrite Dialog.show from main js to load the filebrowser into a bs modal
120 Dialog.show = function(url) {
121 var modal = $('#modal').modal();
124 .load(url, function (responseText, textStatus) {
125 if ( textStatus === 'success' ||
126 textStatus === 'notmodified')
130 // get nickname & filebrowser type from the modal content
131 var nickname = $("#fb-nickname").attr("value");
132 var type = $("#fb-type").attr("value");
134 // try to fetch the hash form the url
135 var match = url.match(/fbrowser\/[a-z]+\/\?mode=modal(.*)/);
138 // initialize the filebrowser
139 var jsbrowser = function() {
140 FileBrowser.init(nickname, type, hash);
142 loadScript("view/theme/frio/js/filebrowser.js", jsbrowser);
147 // overwrite the function _get_url from main.js
148 Dialog._get_url = function(type, name, id) {
150 if (id !== undefined) hash = hash + "-" + id;
151 return "fbrowser/"+type+"/?mode=modal#"+hash;
156 //function commentOpenUI(obj, id) {
157 // $(document).unbind( "click.commentOpen", handler );
159 // var handler = function() {
160 // if(obj.value == '{{$comment}}') {
162 // $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
163 // // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
164 // // The submit button gets tabindex + 1
165 // $("#comment-edit-text-" + id).attr('tabindex','9');
166 // $("#comment-edit-submit-" + id).attr('tabindex','10');
167 // $("#comment-edit-submit-wrapper-" + id).show();
171 // $(document).bind( "click.commentOpen", handler );
174 //function commentCloseUI(obj, id) {
175 // $(document).unbind( "click.commentClose", handler );
177 // var handler = function() {
178 // if(obj.value === '') {
179 // obj.value = '{{$comment}}';
180 // $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
181 // $("#comment-edit-text-" + id).removeAttr('tabindex');
182 // $("#comment-edit-submit-" + id).removeAttr('tabindex');
183 // $("#comment-edit-submit-wrapper-" + id).hide();
187 // $(document).bind( "click.commentClose", handler );
190 function openClose(theID) {
191 var elem = document.getElementById(theID);
193 if( $(elem).is(':visible')) {
194 $(elem).slideUp(200);
197 $(elem).slideDown(200);
201 function showHide(theID) {
202 if(document.getElementById(theID).style.display == "block") {
203 document.getElementById(theID).style.display = "none"
206 document.getElementById(theID).style.display = "block"
211 function showHideComments(id) {
212 if( $('#collapsed-comments-' + id).is(':visible')) {
213 $('#collapsed-comments-' + id).slideUp();
214 $('#hide-comments-' + id).html(window.showMore);
215 $('#hide-comments-total-' + id).show();
218 $('#collapsed-comments-' + id).slideDown();
219 $('#hide-comments-' + id).html(window.showFewer);
220 $('#hide-comments-total-' + id).hide();
225 function justifyPhotos() {
226 justifiedGalleryActive = true;
227 $('#photo-album-contents').justifiedGallery({
238 }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
241 function justifyPhotosAjax() {
242 justifiedGalleryActive = true;
243 $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
246 function loadScript(url, callback) {
247 // Adding the script tag to the head as suggested before
248 var head = document.getElementsByTagName('head')[0];
249 var script = document.createElement('script');
250 script.type = 'text/javascript';
253 // Then bind the event to the callback function.
254 // There are several events for cross browser compatibility.
255 script.onreadystatechange = callback;
256 script.onload = callback;
259 head.appendChild(script);
262 function random_digits(digits) {
266 for(var i = 0; i < digits; i++) {
267 var rn = Math.round(Math.random() * (9));
274 // Does we need a ? or a & to append values to a url
275 function qOrAmp(url) {
276 if(url.search('\\?') < 0) {
283 function insertFormatting(comment,BBcode,id) {
285 var tmpStr = $("#comment-edit-text-" + id).val();
286 if(tmpStr == comment) {
288 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
289 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
290 openMenu("comment-edit-submit-wrapper-" + id);
291 $("#comment-edit-text-" + id).val(tmpStr);
294 textarea = document.getElementById("comment-edit-text-" +id);
295 if (document.selection) {
297 selected = document.selection.createRange();
298 if (BBcode == "url"){
299 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
301 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
302 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
303 var start = textarea.selectionStart;
304 var end = textarea.selectionEnd;
305 if (BBcode == "url"){
306 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
308 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
314 function showThread(id) {
315 $("#collapsed-comments-" + id).show()
316 $("#collapsed-comments-" + id + " .collapsed-comments").show()
318 function hideThread(id) {
319 $("#collapsed-comments-" + id).hide()
320 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
324 function cmtBbOpen(id) {
325 $("#comment-edit-bb-" + id).show();
327 function cmtBbClose(id) {
328 $("#comment-edit-bb-" + id).hide();
331 function contact_filter(item) {
332 // get the html content from the js template of the contact-wrapper
333 contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
338 username: item.username,
340 img_hover: item.img_hover,
341 edit_hover: item.edit_hover,
342 account_type: item.account_type,
343 photo_menu: item.photo_menu,
344 alt_text: item.alt_text,
345 dir_icon: item.dir_icon,
346 sparkle: item.sparkle,
347 itemurl: item.itemurl,
349 network: item.network,
351 details: item.details,
354 // open a new jSmart instance with the template
355 var tpl = new jSmart (contact_tpl);
357 // replace the variable with the values
358 var html = tpl.fetch(variables);
363 function filter_replace(item) {
369 $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
370 if(typeof typ === 'undefined') typ = '';
371 if(typeof autosubmit === 'undefined') autosubmit = false;
373 // Autocomplete contacts
375 match: /(^)([^\n]+)$/,
377 search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
378 replace: filter_replace,
379 template: contact_filter,
382 this.attr('autocomplete','off');
383 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
385 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
390 // current time in milliseconds, to send each request to make sure
391 // we 're not getting 304 response
393 return new Date().getTime();
396 String.prototype.normalizeLink = function () {
397 var ret = this.replace('https:', 'http:');
398 var ret = ret.replace('//www', '//');
402 function cleanContactUrl(url) {
403 var parts = parseUrl(url);
405 if(! ("scheme" in parts) || ! ("host" in parts)) {
409 var newUrl =parts["scheme"] + "://" + parts["host"];
411 if("port" in parts) {
412 newUrl += ":" + parts["port"];
415 if("path" in parts) {
416 newUrl += parts["path"];
419 // if(url != newUrl) {
420 // console.log("Cleaned contact url " + url + " to " + newUrl);
426 function parseUrl (str, component) { // eslint-disable-line camelcase
427 // discuss at: http://locutusjs.io/php/parse_url/
428 // original by: Steven Levithan (http://blog.stevenlevithan.com)
429 // reimplemented by: Brett Zamir (http://brett-zamir.me)
430 // input by: Lorenzo Pisani
432 // improved by: Brett Zamir (http://brett-zamir.me)
433 // note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
434 // note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
435 // note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
436 // note 1: Does not replace invalid characters with '_' as in PHP,
437 // note 1: nor does it return false with
438 // note 1: a seriously malformed URL.
439 // note 1: Besides function name, is essentially the same as parseUri as
440 // note 1: well as our allowing
441 // note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
442 // example 1: parse_url('http://user:pass@host/path?a=v#a')
443 // returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
444 // example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
445 // returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
446 // example 3: parse_url('https://host.domain.tld/a@b.c/folder')
447 // returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
448 // example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
449 // returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
453 var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
472 // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
475 '(?:([^:\\/?#]+):)?',
476 '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
478 '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
481 '(?:([^:\\/?#]+):)?',
482 '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
483 '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
486 '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
488 '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
489 '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
490 '(?:\\?([^#]*))?(?:#(.*))?)'
494 var m = parser[mode].exec(str)
505 return uri[component.replace('PHP_URL_', '').toLowerCase()]
508 if (mode !== 'php') {
509 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
510 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
512 query = uri[key[12]] || ''
513 query.replace(parser, function ($0, $1, $2) {
524 // trim function to replace whithespace after the string
525 String.prototype.rtrim = function() {
526 var trimmed = this.replace(/\s+$/g, '');