]> git.mxchange.org Git - friendica.git/blob - include/main.js
deprecate load_view_file
[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                                 if($('#' + ident).length) {
133                                         $('#' + ident).replaceWith($(this));
134                                 }
135                         });
136                         $('.wall-item-outside-wrapper',data).each(function() {
137                                 var ident = $(this).attr('id');
138                                 if($('#' + ident).length == 0) { 
139                                         $('img',this).each(function() {
140                                                 $(this).attr('src',$(this).attr('dst'));
141                                         });
142                                         $('#' + prev).after($(this));
143                                 }
144                                 else { 
145
146                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
147                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
148                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
149                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
150                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
151                                                 $(this).attr('src',$(this).attr('dst'));
152                                         });
153                                 }
154                                 prev = ident; 
155                         });
156                         $('.like-rotator').hide();
157                         if(commentBusy) {
158                                 commentBusy = false;
159                                 $('body').css('cursor', 'auto');
160                         }
161                 });
162         }
163
164         function imgbright(node) {
165                 $(node).removeClass("drophide").addClass("drop");
166         }
167
168         function imgdull(node) {
169                 $(node).removeClass("drop").addClass("drophide");
170         }
171
172         // Since our ajax calls are asynchronous, we will give a few 
173         // seconds for the first ajax call (setting like/dislike), then 
174         // run the updater to pick up any changes and display on the page.
175         // The updater will turn any rotators off when it's done. 
176         // This function will have returned long before any of these
177         // events have completed and therefore there won't be any
178         // visible feedback that anything changed without all this
179         // trickery. This still could cause confusion if the "like" ajax call
180         // is delayed and NavUpdate runs before it completes.
181
182         function dolike(ident,verb) {
183                 $('#like-rotator-' + ident.toString()).show();
184                 $.get('like/' + ident.toString() + '?verb=' + verb );
185                 if(timer) clearTimeout(timer);
186                 timer = setTimeout(NavUpdate,3000);
187                 liking = 1;
188         }
189
190         function getPosition(e) {
191                 var cursor = {x:0, y:0};
192                 if ( e.pageX || e.pageY  ) {
193                         cursor.x = e.pageX;
194                         cursor.y = e.pageY;
195                 }
196                 else {
197                         if( e.clientX || e.clientY ) {
198                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
199                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
200                         }
201                         else {
202                                 if( e.x || e.y ) {
203                                         cursor.x = e.x;
204                                         cursor.y = e.y;
205                                 }
206                         }
207                 }
208                 return cursor;
209         }
210
211         var lockvisible = false;
212
213         function lockview(event,id) {
214                 event = event || window.event;
215                 cursor = getPosition(event);
216                 if(lockvisible) {
217                         lockviewhide();
218                 }
219                 else {
220                         lockvisible = true;
221                         $.get('lockview/' + id, function(data) {
222                                 $('#panel').html(data);
223                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
224                                 $('#panel').show();
225                         });
226                 }
227         }
228
229         function lockviewhide() {
230                 lockvisible = false;
231                 $('#panel').hide();
232         }
233
234         function post_comment(id) {
235                 commentBusy = true;
236                 $('body').css('cursor', 'wait');
237                 $.post(  
238              "item",  
239              $("#comment-edit-form-" + id).serialize(),
240                         function(data) {
241                                 if(data.success) {
242                                         $("#comment-edit-wrapper-" + id).hide();
243                                         $("#comment-edit-text-" + id).val('');
244                                 var tarea = document.getElementById("comment-edit-text-" + id);
245                                         if(tarea)
246                                                 commentClose(tarea,id);
247                                         if(timer) clearTimeout(timer);
248                                         timer = setTimeout(NavUpdate,10);
249                                 }
250                                 if(data.reload) {
251                                         window.location.href=data.reload;
252                                 }
253                         },
254                         "json"  
255          );  
256          return false;  
257         }
258
259
260     function bin2hex(s){  
261         // Converts the binary representation of data to hex    
262         //   
263         // version: 812.316  
264         // discuss at: http://phpjs.org/functions/bin2hex  
265         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
266         // +   bugfixed by: Onno Marsman  
267         // +   bugfixed by: Linuxworld  
268         // *     example 1: bin2hex('Kev');  
269         // *     returns 1: '4b6576'  
270         // *     example 2: bin2hex(String.fromCharCode(0x00));  
271         // *     returns 2: '00'  
272         var v,i, f = 0, a = [];  
273         s += '';  
274         f = s.length;  
275           
276         for (i = 0; i<f; i++) {  
277             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
278         }  
279           
280         return a.join('');  
281     }  
282
283         function groupChangeMember(gid,cid) {
284                 $('body .fakelink').css('cursor', 'wait');
285                 $.get('group/' + gid + '/' + cid, function(data) {
286                                 $('#group-update-wrapper').html(data);
287                                 $('body .fakelink').css('cursor', 'auto');                              
288                 });
289         }
290
291         function profChangeMember(gid,cid) {
292                 $('body .fakelink').css('cursor', 'wait');
293                 $.get('profperm/' + gid + '/' + cid, function(data) {
294                                 $('#prof-update-wrapper').html(data);
295                                 $('body .fakelink').css('cursor', 'auto');                              
296                 });
297         }
298