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