]> git.mxchange.org Git - friendica.git/blob - include/main.js
use atom_time on atom entries
[friendica.git] / include / main.js
1
2   function openClose(theID) {
3     if(document.getElementById(theID).style.display == "block") { 
4       document.getElementById(theID).style.display = "none" 
5     }
6     else { 
7       document.getElementById(theID).style.display = "block" 
8     } 
9   }
10
11   function openMenu(theID) {
12       document.getElementById(theID).style.display = "block" 
13   }
14
15   function closeMenu(theID) {
16       document.getElementById(theID).style.display = "none" 
17   }
18
19         
20         var src = null;
21         var prev = null;
22         var livetime = null;
23         var msie = false;
24         var stopped = false;
25         var timer = null;
26         var pr = 0;
27         var liking = 0;
28         var in_progress = false;
29         var langSelect = false;
30         var commentBusy = false;
31
32         $(function() {
33                 $.ajaxSetup({cache: false});
34
35                 msie = $.browser.msie ;
36                 
37                 
38                 /* nav update event  */
39                 $('nav').bind('nav-update', function(e,data){;
40                         var net = $(data).find('net').text();
41                         if(net == 0) { net = ''; $('#net-update').hide() } else { $('#net-update').show() }
42                         $('#net-update').html(net);
43                         var home = $(data).find('home').text();
44                         if(home == 0) { home = '';  $('#home-update').hide() } else { $('#home-update').show() }
45                         $('#home-update').html(home);
46                         var mail = $(data).find('mail').text();
47                         if(mail == 0) { mail = '';  $('#mail-update').hide() } else { $('#mail-update').show() }
48                         $('#mail-update').html(mail);
49                         var intro = $(data).find('intro').text();
50                         var register = $(data).find('register').text();
51                         if(intro == 0) { intro = ''; }
52                         if(register != 0 && intro != '') { intro = intro+'/'+register; }
53                         if(register != 0 && intro == '') { intro = '0/'+register; }
54                         if (intro == '') { $('#notify-update').hide() } else { $('#notify-update').show() }
55                         $('#notify-update').html(intro);
56                 });
57                 
58                 
59                 NavUpdate(); 
60                 // Allow folks to stop the ajax page updates with the pause/break key
61                 $(document).keypress(function(event) {
62                         if(event.keyCode == '19') {
63                                 event.preventDefault();
64                                 if(stopped == false) {
65                                         stopped = true;
66                                         $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
67                                 }
68                                 else {
69                                         stopped = false;
70                                         $('#pause').html('');
71                                 }
72                         }
73                 });                                     
74         });
75
76         function NavUpdate() {
77
78                 if($('#live-network').length) { src = 'network'; liveUpdate(); }
79                 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
80                 if($('#live-display').length) { 
81                         if(liking) {
82                                 liking = 0;
83                                 window.location.href=window.location.href 
84                         }
85                 }
86                 if($('#live-photos').length)  { 
87                         if(liking) {
88                                 liking = 0;
89                                 window.location.href=window.location.href 
90                         }
91                 }
92
93                 if(! stopped) {
94                         $.get("ping",function(data) {
95                                 $(data).find('result').each(function() {
96                                         // send nav-update event
97                                         $('nav').trigger('nav-update', this);
98                                 });
99                         }) ;
100                 }
101                 timer = setTimeout(NavUpdate,30000);
102         }
103
104         function liveUpdate() {
105                 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
106                 if(($('.comment-edit-text-full').length) || (in_progress)) {
107                         livetime = setTimeout(liveUpdate, 10000);
108                         return;
109                 }
110                 prev = 'live-' + src;
111
112                 in_progress = true;
113                 var udargs = ((netargs.length) ? '/' + netargs : '');
114                 var update_url = 'update_' + src + udargs + '?p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
115
116                 $.get(update_url,function(data) {
117                         in_progress = false;
118                         $('.ccollapse-wrapper',data).each(function() {
119                                 var ident = $(this).attr('id');
120                                 var is_hidden = $('#' + ident).is(':hidden');
121                                 if($('#' + ident).length) {
122                                         $('#' + ident).replaceWith($(this));
123                                         if(is_hidden)
124                                                 $('#' + ident).hide();
125                                 }
126                         });
127                         $('.wall-item-outside-wrapper',data).each(function() {
128                                 var ident = $(this).attr('id');
129                                 if($('#' + ident).length == 0) {
130                                         $('img',this).each(function() {
131                                                 $(this).attr('src',$(this).attr('dst'));
132                                         });
133                                         $('#' + prev).after($(this));
134                                 }
135                                 else { 
136
137                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
138                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
139                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
140                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
141                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
142                                                 $(this).attr('src',$(this).attr('dst'));
143                                         });
144                                 }
145                                 prev = ident; 
146                         });
147                         $('.like-rotator').hide();
148                         if(commentBusy) {
149                                 commentBusy = false;
150                                 $('body').css('cursor', 'auto');
151                         }
152                 });
153         }
154
155         function imgbright(node) {
156                 $(node).removeClass("drophide").addClass("drop");
157         }
158
159         function imgdull(node) {
160                 $(node).removeClass("drop").addClass("drophide");
161         }
162
163         // Since our ajax calls are asynchronous, we will give a few 
164         // seconds for the first ajax call (setting like/dislike), then 
165         // run the updater to pick up any changes and display on the page.
166         // The updater will turn any rotators off when it's done. 
167         // This function will have returned long before any of these
168         // events have completed and therefore there won't be any
169         // visible feedback that anything changed without all this
170         // trickery. This still could cause confusion if the "like" ajax call
171         // is delayed and NavUpdate runs before it completes.
172
173         function dolike(ident,verb) {
174                 $('#like-rotator-' + ident.toString()).show();
175                 $.get('like/' + ident.toString() + '?verb=' + verb );
176                 if(timer) clearTimeout(timer);
177                 timer = setTimeout(NavUpdate,3000);
178                 liking = 1;
179         }
180
181         function getPosition(e) {
182                 var cursor = {x:0, y:0};
183                 if ( e.pageX || e.pageY  ) {
184                         cursor.x = e.pageX;
185                         cursor.y = e.pageY;
186                 }
187                 else {
188                         if( e.clientX || e.clientY ) {
189                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
190                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
191                         }
192                         else {
193                                 if( e.x || e.y ) {
194                                         cursor.x = e.x;
195                                         cursor.y = e.y;
196                                 }
197                         }
198                 }
199                 return cursor;
200         }
201
202         var lockvisible = false;
203
204         function lockview(event,id) {
205                 event = event || window.event;
206                 cursor = getPosition(event);
207                 if(lockvisible) {
208                         lockviewhide();
209                 }
210                 else {
211                         lockvisible = true;
212                         $.get('lockview/' + id, function(data) {
213                                 $('#panel').html(data);
214                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
215                                 $('#panel').show();
216                         });
217                 }
218         }
219
220         function lockviewhide() {
221                 lockvisible = false;
222                 $('#panel').hide();
223         }
224
225         function post_comment(id) {
226                 commentBusy = true;
227                 $('body').css('cursor', 'wait');
228                 $.post(  
229              "item",  
230              $("#comment-edit-form-" + id).serialize(),
231                         function(data) {
232                                 if(data.success) {
233                                         $("#comment-edit-wrapper-" + id).hide();
234                                         $("#comment-edit-text-" + id).val('');
235                                 var tarea = document.getElementById("comment-edit-text-" + id);
236                                         if(tarea)
237                                                 commentClose(tarea,id);
238                                         if(timer) clearTimeout(timer);
239                                         timer = setTimeout(NavUpdate,10);
240                                 }
241                                 if(data.reload) {
242                                         window.location.href=data.reload;
243                                 }
244                         },
245                         "json"  
246          );  
247          return false;  
248         }
249
250
251     function bin2hex(s){  
252         // Converts the binary representation of data to hex    
253         //   
254         // version: 812.316  
255         // discuss at: http://phpjs.org/functions/bin2hex  
256         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
257         // +   bugfixed by: Onno Marsman  
258         // +   bugfixed by: Linuxworld  
259         // *     example 1: bin2hex('Kev');  
260         // *     returns 1: '4b6576'  
261         // *     example 2: bin2hex(String.fromCharCode(0x00));  
262         // *     returns 2: '00'  
263         var v,i, f = 0, a = [];  
264         s += '';  
265         f = s.length;  
266           
267         for (i = 0; i<f; i++) {  
268             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
269         }  
270           
271         return a.join('');  
272     }  
273
274         function groupChangeMember(gid,cid) {
275                 $('body .fakelink').css('cursor', 'wait');
276                 $.get('group/' + gid + '/' + cid, function(data) {
277                                 $('#group-update-wrapper').html(data);
278                                 $('body .fakelink').css('cursor', 'auto');                              
279                 });
280         }
281
282         function profChangeMember(gid,cid) {
283                 $('body .fakelink').css('cursor', 'wait');
284                 $.get('profperm/' + gid + '/' + cid, function(data) {
285                                 $('#prof-update-wrapper').html(data);
286                                 $('body .fakelink').css('cursor', 'auto');                              
287                 });
288         }
289
290 function checkboxhighlight(box) {
291   if($(box).is(':checked')) {
292         $(box).addClass('checkeditem');
293   }
294   else {
295         $(box).removeClass('checkeditem');
296   }
297 }
298
299
300
301 /** 
302  * sprintf in javascript 
303  *      "{0} and {1}".format('zero','uno'); 
304  **/
305 String.prototype.format = function() {
306     var formatted = this;
307     for (var i = 0; i < arguments.length; i++) {
308         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
309         formatted = formatted.replace(regexp, arguments[i]);
310     }
311     return formatted;
312 };