]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/js/theme.js
d7372704ed51884d6cb34c78aec75e3a3d6bb99d
[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         $('input.item-select').change(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
118 });
119 //function commentOpenUI(obj, id) {
120 //      $(document).unbind( "click.commentOpen", handler );
121 //
122 //      var handler = function() {
123 //              if(obj.value == '{{$comment}}') {
124 //                      obj.value = '';
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();
131 //              }
132 //      };
133 //
134 //      $(document).bind( "click.commentOpen", handler );
135 //}
136 //
137 //function commentCloseUI(obj, id) {
138 //      $(document).unbind( "click.commentClose", handler );
139 //
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();
147 //              }
148 //      };
149 //
150 //      $(document).bind( "click.commentClose", handler );
151 //}
152
153 function openClose(theID) {
154         var elem = document.getElementById(theID);
155
156         if( $(elem).is(':visible')) {
157                 $(elem).slideUp(200);
158         }
159         else {
160                 $(elem).slideDown(200);
161         }
162 }
163
164 function showHide(theID) {
165         if(document.getElementById(theID).style.display == "block") {
166                 document.getElementById(theID).style.display = "none"
167         }
168         else {
169                 document.getElementById(theID).style.display = "block"
170         }
171 }
172
173
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();
179         }
180         else {
181                 $('#collapsed-comments-' + id).slideDown();
182                 $('#hide-comments-' + id).html(window.showFewer);
183                 $('#hide-comments-total-' + id).hide();
184         }
185 }
186
187
188 function justifyPhotos() {
189         justifiedGalleryActive = true;
190         $('#photo-album-contents').justifiedGallery({
191                 margins: 3,
192                 border: 0,
193                 sizeRangeSuffixes: {
194                         'lt100': '-2',
195                         'lt240': '-2',
196                         'lt320': '-2',
197                         'lt500': '',
198                         'lt640': '-1',
199                         'lt1024': '-0'
200                 }
201         }).on('jg.complete', function(e){ justifiedGalleryActive = false; });
202 }
203
204 function justifyPhotosAjax() {
205         justifiedGalleryActive = true;
206         $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
207 }
208
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';
214         script.src = url;
215
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;
220
221         // Fire the loading
222         head.appendChild(script);
223 }
224
225 function random_digits(digits) {
226         var rn = "";
227         var rnd = "";
228
229         for(var i = 0; i < digits; i++) {
230                 var rn = Math.round(Math.random() * (9));
231                 rnd += rn;
232         }
233
234         return rnd;
235 }
236
237 // Does we need a ? or a & to append values to a url
238 function qOrAmp(url) {
239         if(url.search('\\?') < 0) {
240                 return '?';
241         } else {
242                 return '&';
243         }
244 }
245
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());
249
250         var variables = {
251                         id:             item.id,
252                         name:           item.name,
253                         username:       item.username,
254                         thumb:          item.thumb,
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,
263                         url:            item.url,
264                         network:        item.network,
265                         tags:           item.tags,
266                         details:        item.details,
267         };
268
269         // open a new jSmart instance with the template
270         var tpl = new jSmart (contact_tpl);
271
272         // replace the variable with the values
273         var html = tpl.fetch(variables);
274
275         return html;
276 }
277
278 function filter_replace(item) {
279
280         return item.name;
281 }
282
283 (function( $ ) {
284         $.fn.contact_filter = function(backend_url, typ, autosubmit, onselect) {
285                 if(typeof typ === 'undefined') typ = '';
286                 if(typeof autosubmit === 'undefined') autosubmit = false;
287
288                 // Autocomplete contacts
289                 contacts = {
290                         match: /(^)([^\n]+)$/,
291                         index: 2,
292                         search: function(term, callback) { contact_search(term, callback, backend_url, typ); },
293                         replace: filter_replace,
294                         template: contact_filter,
295                 };
296
297                 this.attr('autocomplete','off');
298                 var a = this.textcomplete([contacts], {className:'accontacts', appendTo: '#contact-list'});
299
300                 a.on('textComplete:select', function(e, value, strategy) { $(".dropdown-menu.textcomplete-dropdown.media-list").show(); });
301         };
302 })( jQuery );
303
304
305 // current time in milliseconds, to send each request to make sure
306 // we 're not getting 304 response
307 function timeNow() {
308         return new Date().getTime();
309 }
310
311 String.prototype.normalizeLink = function () {
312         var ret = this.replace('https:', 'http:');
313         var ret = ret.replace('//www', '//');
314         return ret.rtrim();
315 };
316
317 function cleanContactUrl(url) {
318         var parts = parseUrl(url);
319
320         if(! ("scheme" in parts) || ! ("host" in parts)) {
321                 return url;
322         }
323
324         var newUrl =parts["scheme"] + "://" + parts["host"];
325
326         if("port" in parts) {
327                 newUrl += ":" + parts["port"];
328         }
329
330         if("path" in parts) {
331                 newUrl += parts["path"];
332         }
333
334 //      if(url != newUrl) {
335 //              console.log("Cleaned contact url " + url + " to " + newUrl);
336 //      }
337
338         return newUrl;
339 }
340
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
346         //         input by: Tony
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' }
365
366         var query
367
368         var mode = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.mode') : undefined) || 'php'
369
370         var key = [
371                 'source',
372                 'scheme',
373                 'authority',
374                 'userInfo',
375                 'user',
376                 'pass',
377                 'host',
378                 'port',
379                 'relative',
380                 'path',
381                 'directory',
382                 'file',
383                 'query',
384                 'fragment'
385         ]
386
387         // For loose we added one optional slash to post-scheme to catch file:/// (should restrict this)
388         var parser = {
389                 php: new RegExp([
390                         '(?:([^:\\/?#]+):)?',
391                         '(?:\\/\\/()(?:(?:()(?:([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
392                         '()',
393                         '(?:(()(?:(?:[^?#\\/]*\\/)*)()(?:[^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
394                 ].join('')),
395                 strict: new RegExp([
396                         '(?:([^:\\/?#]+):)?',
397                         '(?:\\/\\/((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?))?',
398                         '((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)'
399                 ].join('')),
400                 loose: new RegExp([
401                         '(?:(?![^:@]+:[^:@\\/]*@)([^:\\/?#.]+):)?',
402                         '(?:\\/\\/\\/?)?',
403                         '((?:(([^:@\\/]*):?([^:@\\/]*))?@)?([^:\\/?#]*)(?::(\\d*))?)',
404                         '(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))',
405                         '(?:\\?([^#]*))?(?:#(.*))?)'
406                 ].join(''))
407         }
408
409         var m = parser[mode].exec(str)
410         var uri = {}
411         var i = 14
412
413         while (i--) {
414                 if (m[i]) {
415                         uri[key[i]] = m[i]
416                 }
417         }
418
419         if (component) {
420                 return uri[component.replace('PHP_URL_', '').toLowerCase()]
421         }
422
423         if (mode !== 'php') {
424                 var name = (typeof require !== 'undefined' ? require('../info/ini_get')('locutus.parse_url.queryKey') : undefined) || 'queryKey'
425                 parser = /(?:^|&)([^&=]*)=?([^&]*)/g
426                 uri[name] = {}
427                 query = uri[key[12]] || ''
428                 query.replace(parser, function ($0, $1, $2) {
429                         if ($1) {
430                                 uri[name][$1] = $2
431                         }
432                 })
433         }
434
435         delete uri.source
436         return uri
437 }
438
439 // trim function to replace whithespace after the string
440 String.prototype.rtrim = function() {
441         var trimmed = this.replace(/\s+$/g, '');
442         return trimmed;
443 };
444