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