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