]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/theme.js
418c233e72c46916fd4231a350ecd5baf64833f1
[friendica.git] / view / theme / frio / js / theme.js
1
2 var jotcache = ''; //The jot cache. We use it as cache to restore old/original jot content
3
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();
9                 } else {
10                         $("#back-to-top").fadeOut();
11                 }
12         });
13  
14         // scroll body to 0px on click
15         $("#back-to-top").click(function () {
16                 $("body,html").animate({
17                         scrollTop: 0
18                 }, 400);
19                 return false;
20         });
21
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");
25         }
26
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");
30         }
31
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");
35         }
36
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");
41
42         // move the tabbar to the second nav bar
43         if( $("ul.tabbar")) {
44                 $("ul.tabbar").appendTo("#topbar-second > .container > #tabmenu");
45         }
46
47         // add mask css url to the logo-img container
48         //
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")) {
54                 var pageurl = "url('" + window.location.href + "#logo-mask')";
55                 $("#logo-img").css({"mask": pageurl});
56         }
57
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({
62                 'cutoff': 2,
63                 'popupClass': "dropdown-menu pull-right",
64                 'popupAbsolute': false,
65                 'target': ".flex-target"
66         });
67
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();
72         }
73
74         // show bulk deletion button at network page if checkbox is checked
75         $("body").change("input.item-select", function(){
76                 var checked = false;
77
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')) {
83                                 checked = true;
84                                 return false;
85                         }
86                 });
87                 
88                 if(checked == true) {
89                         $("a#item-delete-selected").fadeTo(400, 1);
90                         $("a#item-delete-selected").show();
91                 } else {
92                         $("a#item-delete-selected").fadeTo(400, 0, function(){
93                                 $("a#item-delete-selected").hide();
94                         });     
95                 }
96         });
97
98         // add search-heading to the scecond navbar
99         if( $(".search-heading")) {
100                 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
101         }
102
103         
104                 
105         //$('ul.flex-nav').flexMenu();
106
107         // initialize the bootstrap tooltips
108         $('body').tooltip({
109                 selector: '[data-toggle="tooltip"]',
110                 animation: true,
111                 html: true,
112                 placement: 'auto',
113                 trigger: 'hover',
114                 delay: {
115                         show: 500,
116                         hide: 100
117                 }
118         });
119
120         // initialize the bootstrap-select
121         $('.selectpicker').selectpicker();
122
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");
131                                 });
132                                 
133
134                         },
135                         onEnter: function(element) {
136                                 $("#vcard-short-info").appendTo("#nav-short-info");
137                                 $("#vcard-short-info").fadeIn(500);
138                         },
139                 });
140         }
141
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");
149         }
150 });
151 //function commentOpenUI(obj, id) {
152 //      $(document).unbind( "click.commentOpen", handler );
153 //
154 //      var handler = function() {
155 //              if(obj.value == '{{$comment}}') {
156 //                      obj.value = '';
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();
163 //              }
164 //      };
165 //
166 //      $(document).bind( "click.commentOpen", handler );
167 //}
168 //
169 //function commentCloseUI(obj, id) {
170 //      $(document).unbind( "click.commentClose", handler );
171 //
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();
179 //              }
180 //      };
181 //
182 //      $(document).bind( "click.commentClose", handler );
183 //}
184
185 function openClose(theID) {
186         var elem = document.getElementById(theID);
187
188         if( $(elem).is(':visible')) {
189                 $(elem).slideUp(200);
190         }
191         else {
192                 $(elem).slideDown(200);
193         }
194 }
195
196 function showHide(theID) {
197         if(document.getElementById(theID).style.display == "block") {
198                 document.getElementById(theID).style.display = "none"
199         }
200         else {
201                 document.getElementById(theID).style.display = "block"
202         }
203 }
204
205
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();
211         }
212         else {
213                 $('#collapsed-comments-' + id).slideDown();
214                 $('#hide-comments-' + id).html(window.showFewer);
215                 $('#hide-comments-total-' + id).hide();
216         }
217 }
218
219
220 function justifyPhotos() {
221         justifiedGalleryActive = true;
222         $('#photo-album-contents').justifiedGallery({
223                 margins: 3,
224                 border: 0,
225                 sizeRangeSuffixes: {
226                         'lt100': '-2',
227                         'lt240': '-2',
228                         'lt320': '-2',
229                         'lt500': '',
230                         'lt640': '-1',
231                         'lt1024': '-0'
232                 }
233         }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
234 }
235
236 function justifyPhotosAjax() {
237         justifiedGalleryActive = true;
238         $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
239 }
240
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';
246         script.src = url;
247
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;
252
253         // Fire the loading
254         head.appendChild(script);
255 }
256
257 function random_digits(digits) {
258         var rn = "";
259         var rnd = "";
260
261         for(var i = 0; i < digits; i++) {
262                 var rn = Math.round(Math.random() * (9));
263                 rnd += rn;
264         }
265
266         return rnd;
267 }
268
269 // Does we need a ? or a & to append values to a url
270 function qOrAmp(url) {
271         if(url.search('\\?') < 0) {
272                 return '?';
273         } else {
274                 return '&';
275         }
276 }
277
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());
281
282         var variables = {
283                         id:             item.id,
284                         name:           item.name,
285                         username:       item.username,
286                         thumb:          item.thumb,
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,
295                         url:            item.url,
296                         network:        item.network,
297                         tags:           item.tags,
298                         details:        item.details,
299         };
300
301         // open a new jSmart instance with the template
302         var tpl = new jSmart (contact_tpl);
303
304         // replace the variable with the values
305         var html = tpl.fetch(variables);
306
307         return html;
308 }
309
310 function filter_replace(item) {
311
312         return item.name;
313 }
314
315 (function( $ ) {
316         $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
317                 if(typeof typ === 'undefined') typ = '';
318                 if(typeof autosubmit === 'undefined') autosubmit = false;
319
320                 // Autocomplete contacts
321                 contacts = {
322                         match: /(^)([^\n]+)$/,
323                         index: 2,
324                         search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
325                         replace: filter_replace,
326                         template: contact_filter,
327                 };
328
329                 this.attr('autocomplete','off');
330                 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
331
332                 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
333         };
334 })( jQuery );
335
336
337 // current time in milliseconds, to send each request to make sure
338 // we 're not getting 304 response
339 function timeNow() {
340         return new Date().getTime();
341 }
342
343 String.prototype.normalizeLink = function () {
344         var ret = this.replace('https:', 'http:');
345         var ret = ret.replace('//www', '//');
346         return ret.rtrim();
347 };
348
349 function cleanContactUrl(url) {
350         var parts = parseUrl(url);
351
352         if(! ("scheme" in parts) || ! ("host" in parts)) {
353                 return url;
354         }
355
356         var newUrl =parts["scheme"] + "://" + parts["host"];
357
358         if("port" in parts) {
359                 newUrl += ":" + parts["port"];
360         }
361
362         if("path" in parts) {
363                 newUrl += parts["path"];
364         }
365
366 //      if(url != newUrl) {
367 //              console.log("Cleaned contact url " + url + " to " + newUrl);
368 //      }
369
370         return newUrl;
371 }
372
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
378         //         input by: Tony
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' }
397
398         var query
399
400         var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
401
402         var key = [
403                 'source',
404                 'scheme',
405                 'authority',
406                 'userInfo',
407                 'user',
408                 'pass',
409                 'host',
410                 'port',
411                 'relative',
412                 'path',
413                 'directory',
414                 'file',
415                 'query',
416                 'fragment'
417         ]
418
419         // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
420         var parser = {
421                 php: new RegExp([
422                         '(?:([^:\\/?#]+):)?',
423                         '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
424                         '()',
425                         '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
426                 ].join('')),
427                 strict: new RegExp([
428                         '(?:([^:\\/?#]+):)?',
429                         '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
430                         '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
431                 ].join('')),
432                 loose: new RegExp([
433                         '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
434                         '(?:\\/\\/\\/?)?',
435                         '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
436                         '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
437                         '(?:\\?([^#]*))?(?:#(.*))?)'
438                 ].join(''))
439         }
440
441         var m = parser[mode].exec(str)
442         var uri = {}
443         var i = 14
444
445         while (i--) {
446                 if (m[i]) {
447                         uri[key[i]] = m[i]
448                 }
449         }
450
451         if (component) {
452                 return uri[component.replace('PHP_URL_', '').toLowerCase()]
453         }
454
455         if (mode !== 'php') {
456                 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
457                 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
458                 uri[name] = {}
459                 query = uri[key[12]] || ''
460                 query.replace(parser, function ($0, $1, $2) {
461                         if ($1) {
462                                 uri[name][$1] = $2
463                         }
464                 })
465         }
466
467         delete uri.source
468         return uri
469 }
470
471 // trim function to replace whithespace after the string
472 String.prototype.rtrim = function() {
473         var trimmed = this.replace(/\s+$/g, '');
474         return trimmed;
475 };
476