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