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