]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/theme.js
frio: saved_searches_aside & searchbox template
[friendica.git] / view / theme / frio / js / theme.js
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();
6                 } else {
7                         $("#back-to-top").fadeOut();
8                 }
9         });
10  
11         // scroll body to 0px on click
12         $("#back-to-top").click(function () {
13                 $("body,html").animate({
14                         scrollTop: 0
15                 }, 400);
16                 return false;
17         });
18
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");
22         }
23
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");
27         }
28
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");
32         }
33
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");
38
39         // move the tabbar to the second nav bar
40         if( $("ul.tabbar")) {
41                 $("ul.tabbar").appendTo("#topbar-second > .container > #tabmenu");
42         }
43
44         // add mask css url to the logo-img container
45         //
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.
50         if($("#logo-img")) {
51                 var pageurl = "url('" + window.location.href + "#logo-mask')";
52                 $("#logo-img").css({"mask": pageurl});
53         }
54
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({
59                 'cutoff': 2,
60                 'popupClass': "dropdown-menu pull-right",
61                 'popupAbsolute': false,
62                 'target': ".flex-target"
63         });
64
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();
69         }
70
71         // show bulk deletion button at network page if checkbox is checked
72         $("body").change("input.item-select", function(){
73                 var checked = false;
74
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')) {
80                                 checked = true;
81                                 return false;
82                         }
83                 });
84                 
85                 if(checked == true) {
86                         $("a#item-delete-selected").fadeTo(400, 1);
87                         $("a#item-delete-selected").show();
88                 } else {
89                         $("a#item-delete-selected").fadeTo(400, 0, function(){
90                                 $("a#item-delete-selected").hide();
91                         });     
92                 }
93         });
94
95         // add search-heading to the scecond navbar
96         if( $(".search-heading")) {
97                 $(".search-heading").appendTo("#topbar-second > .container > #tabmenu");
98         }
99
100         
101                 
102         //$('ul.flex-nav').flexMenu();
103
104         // initialize the bootstrap tooltips
105         $('body').tooltip({
106                 selector: '[data-toggle="tooltip"]',
107                 animation: true,
108                 html: true,
109                 placement: 'auto',
110                 trigger: 'hover',
111                 delay: {
112                         show: 500,
113                         hide: 100
114                 }
115         });
116
117         // initialize the bootstrap-select
118         $('.selectpicker').selectpicker();
119
120
121 });
122 //function commentOpenUI(obj, id) {
123 //      $(document).unbind( "click.commentOpen", handler );
124 //
125 //      var handler = function() {
126 //              if(obj.value == '{{$comment}}') {
127 //                      obj.value = '';
128 //                      $("#comment-edit-text-" + id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
129 //                      // Choose an arbitrary tab index that's greater than what we're using in jot (3 of them)
130 //                      // The submit button gets tabindex + 1
131 //                      $("#comment-edit-text-" + id).attr('tabindex','9');
132 //                      $("#comment-edit-submit-" + id).attr('tabindex','10');
133 //                      $("#comment-edit-submit-wrapper-" + id).show();
134 //              }
135 //      };
136 //
137 //      $(document).bind( "click.commentOpen", handler );
138 //}
139 //
140 //function commentCloseUI(obj, id) {
141 //      $(document).unbind( "click.commentClose", handler );
142 //
143 //      var handler = function() {
144 //              if(obj.value === '') {
145 //              obj.value = '{{$comment}}';
146 //                      $("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
147 //                      $("#comment-edit-text-" + id).removeAttr('tabindex');
148 //                      $("#comment-edit-submit-" + id).removeAttr('tabindex');
149 //                      $("#comment-edit-submit-wrapper-" + id).hide();
150 //              }
151 //      };
152 //
153 //      $(document).bind( "click.commentClose", handler );
154 //}
155
156 function openClose(theID) {
157         var elem = document.getElementById(theID);
158
159         if( $(elem).is(':visible')) {
160                 $(elem).slideUp(200);
161         }
162         else {
163                 $(elem).slideDown(200);
164         }
165 }
166
167 function showHide(theID) {
168         if(document.getElementById(theID).style.display == "block") {
169                 document.getElementById(theID).style.display = "none"
170         }
171         else {
172                 document.getElementById(theID).style.display = "block"
173         }
174 }
175
176
177 function showHideComments(id) {
178         if( $('#collapsed-comments-' + id).is(':visible')) {
179                 $('#collapsed-comments-' + id).slideUp();
180                 $('#hide-comments-' + id).html(window.showMore);
181                 $('#hide-comments-total-' + id).show();
182         }
183         else {
184                 $('#collapsed-comments-' + id).slideDown();
185                 $('#hide-comments-' + id).html(window.showFewer);
186                 $('#hide-comments-total-' + id).hide();
187         }
188 }
189
190
191 function justifyPhotos() {
192         justifiedGalleryActive = true;
193         $('#photo-album-contents').justifiedGallery({
194                 margins: 3,
195                 border: 0,
196                 sizeRangeSuffixes: {
197                         'lt100': '-2',
198                         'lt240': '-2',
199                         'lt320': '-2',
200                         'lt500': '',
201                         'lt640': '-1',
202                         'lt1024': '-0'
203                 }
204         }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
205 }
206
207 function justifyPhotosAjax() {
208         justifiedGalleryActive = true;
209         $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
210 }
211
212 function loadScript(url, callback) {
213         // Adding the script tag to the head as suggested before
214         var head = document.getElementsByTagName('head')[0];
215         var script = document.createElement('script');
216         script.type = 'text/javascript';
217         script.src = url;
218
219         // Then bind the event to the callback function.
220         // There are several events for cross browser compatibility.
221         script.onreadystatechange = callback;
222         script.onload = callback;
223
224         // Fire the loading
225         head.appendChild(script);
226 }
227
228 function random_digits(digits) {
229         var rn = "";
230         var rnd = "";
231
232         for(var i = 0; i < digits; i++) {
233                 var rn = Math.round(Math.random() * (9));
234                 rnd += rn;
235         }
236
237         return rnd;
238 }
239
240 // Does we need a ? or a & to append values to a url
241 function qOrAmp(url) {
242         if(url.search('\\?') < 0) {
243                 return '?';
244         } else {
245                 return '&';
246         }
247 }
248
249 function contact_filter(item) {
250         // get the html content from the js template of the contact-wrapper
251         contact_tpl = unescape($(".javascript-template[rel=contact-template]").html());
252
253         var variables = {
254                         id:             item.id,
255                         name:           item.name,
256                         username:       item.username,
257                         thumb:          item.thumb,
258                         img_hover:      item.img_hover,
259                         edit_hover:     item.edit_hover,
260                         account_type:   item.account_type,
261                         photo_menu:     item.photo_menu,
262                         alt_text:       item.alt_text,
263                         dir_icon:       item.dir_icon,
264                         sparkle:        item.sparkle,
265                         itemurl:        item.itemurl,
266                         url:            item.url,
267                         network:        item.network,
268                         tags:           item.tags,
269                         details:        item.details,
270         };
271
272         // open a new jSmart instance with the template
273         var tpl = new jSmart (contact_tpl);
274
275         // replace the variable with the values
276         var html = tpl.fetch(variables);
277
278         return html;
279 }
280
281 function filter_replace(item) {
282
283         return item.name;
284 }
285
286 (function( $ ) {
287         $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
288                 if(typeof typ === 'undefined') typ = '';
289                 if(typeof autosubmit === 'undefined') autosubmit = false;
290
291                 // Autocomplete contacts
292                 contacts = {
293                         match: /(^)([^\n]+)$/,
294                         index: 2,
295                         search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
296                         replace: filter_replace,
297                         template: contact_filter,
298                 };
299
300                 this.attr('autocomplete','off');
301                 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
302
303                 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
304         };
305 })( jQuery );
306
307
308 // current time in milliseconds, to send each request to make sure
309 // we 're not getting 304 response
310 function timeNow() {
311         return new Date().getTime();
312 }
313
314 String.prototype.normalizeLink = function () {
315         var ret = this.replace('https:', 'http:');
316         var ret = ret.replace('//www', '//');
317         return ret.rtrim();
318 };
319
320 function cleanContactUrl(url) {
321         var parts = parseUrl(url);
322
323         if(! ("scheme" in parts) || ! ("host" in parts)) {
324                 return url;
325         }
326
327         var newUrl =parts["scheme"] + "://" + parts["host"];
328
329         if("port" in parts) {
330                 newUrl += ":" + parts["port"];
331         }
332
333         if("path" in parts) {
334                 newUrl += parts["path"];
335         }
336
337 //      if(url != newUrl) {
338 //              console.log("Cleaned contact url " + url + " to " + newUrl);
339 //      }
340
341         return newUrl;
342 }
343
344 function parseUrl (str, component) { // eslint-disable-line camelcase
345         //       discuss at: http://locutusjs.io/php/parse_url/
346         //      original by: Steven Levithan (http://blog.stevenlevithan.com)
347         // reimplemented by: Brett Zamir (http://brett-zamir.me)
348         //         input by: Lorenzo Pisani
349         //         input by: Tony
350         //      improved by: Brett Zamir (http://brett-zamir.me)
351         //           note 1: original by http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
352         //           note 1: blog post at http://blog.stevenlevithan.com/archives/parseuri
353         //           note 1: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
354         //           note 1: Does not replace invalid characters with '_' as in PHP,
355         //           note 1: nor does it return false with
356         //           note 1: a seriously malformed URL.
357         //           note 1: Besides function name, is essentially the same as parseUri as
358         //           note 1: well as our allowing
359         //           note 1: an extra slash after the scheme/protocol (to allow file:/// as in PHP)
360         //        example 1: parse_url('http://user:pass@host/path?a=v#a')
361         //        returns 1: {scheme: 'http', host: 'host', user: 'user', pass: 'pass', path: '/path', query: 'a=v', fragment: 'a'}
362         //        example 2: parse_url('http://en.wikipedia.org/wiki/%22@%22_%28album%29')
363         //        returns 2: {scheme: 'http', host: 'en.wikipedia.org', path: '/wiki/%22@%22_%28album%29'}
364         //        example 3: parse_url('https://host.domain.tld/a@b.c/folder')
365         //        returns 3: {scheme: 'https', host: 'host.domain.tld', path: '/a@b.c/folder'}
366         //        example 4: parse_url('https://gooduser:secretpassword@www.example.com/a@b.c/folder?foo=bar')
367         //        returns 4: { scheme: 'https', host: 'www.example.com', path: '/a@b.c/folder', query: 'foo=bar', user: 'gooduser', pass: 'secretpassword' }
368
369         var query
370
371         var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
372
373         var key = [
374                 'source',
375                 'scheme',
376                 'authority',
377                 'userInfo',
378                 'user',
379                 'pass',
380                 'host',
381                 'port',
382                 'relative',
383                 'path',
384                 'directory',
385                 'file',
386                 'query',
387                 'fragment'
388         ]
389
390         // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
391         var parser = {
392                 php: new RegExp([
393                         '(?:([^:\\/?#]+):)?',
394                         '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
395                         '()',
396                         '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
397                 ].join('')),
398                 strict: new RegExp([
399                         '(?:([^:\\/?#]+):)?',
400                         '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
401                         '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
402                 ].join('')),
403                 loose: new RegExp([
404                         '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
405                         '(?:\\/\\/\\/?)?',
406                         '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
407                         '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
408                         '(?:\\?([^#]*))?(?:#(.*))?)'
409                 ].join(''))
410         }
411
412         var m = parser[mode].exec(str)
413         var uri = {}
414         var i = 14
415
416         while (i--) {
417                 if (m[i]) {
418                         uri[key[i]] = m[i]
419                 }
420         }
421
422         if (component) {
423                 return uri[component.replace('PHP_URL_', '').toLowerCase()]
424         }
425
426         if (mode !== 'php') {
427                 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
428                 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
429                 uri[name] = {}
430                 query = uri[key[12]] || ''
431                 query.replace(parser, function ($0, $1, $2) {
432                         if ($1) {
433                                 uri[name][$1] = $2
434                         }
435                 })
436         }
437
438         delete uri.source
439         return uri
440 }
441
442 // trim function to replace whithespace after the string
443 String.prototype.rtrim = function() {
444         var trimmed = this.replace(/\s+$/g, '');
445         return trimmed;
446 };
447