]> git.mxchange.org Git - friendica.git/blob - include/main.js
750cce74c0ed11a3fdf440071d8f0c01b2eeaaad
[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
30         $(document).ready(function() {
31                 $.ajaxSetup({cache: false});
32
33                 msie = $.browser.msie ;
34                 NavUpdate(); 
35                 // Allow folks to stop the ajax page updates with the pause/break key
36                 $(document).keypress(function(event) {
37                         if(event.keyCode == '19') {
38                                 event.preventDefault();
39                                 if(stopped == false) {
40                                         stopped = true;
41                                         $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
42                                 }
43                                 else {
44                                         stopped = false;
45                                         $('#pause').html('');
46                                 }
47                         }
48 // this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
49 // update: incompatible usage of onKeyDown vs onKeyPress
50 //                      if(event.keyCode == '36' && event.shiftKey == true) {
51 //                              if(homebase !== undefined) {
52 //                                      event.preventDefault();
53 //                                      document.location = homebase;
54 //                              }
55 //                      }
56                 });                                     
57         });
58
59         function NavUpdate() {
60
61                 if($('#live-network').length) { src = 'network'; liveUpdate(); }
62                 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
63                 if($('#live-display').length) { 
64                         if(liking) {
65                                 liking = 0;
66                                 window.location.href=window.location.href 
67                         }
68                 }
69                 if($('#live-photos').length)  { 
70                         if(liking) {
71                                 liking = 0;
72                                 window.location.href=window.location.href 
73                         }
74                 }
75
76                 if(! stopped) {
77                         $.get("ping",function(data) {
78                                 $(data).find('result').each(function() {
79                                         var net = $(this).find('net').text();
80                                         if(net == 0) { net = ''; }
81                                         $('#net-update').html(net);
82                                         var home = $(this).find('home').text();
83                                         if(home == 0) { home = ''; }
84                                         $('#home-update').html(home);
85                                         var mail = $(this).find('mail').text();
86                                         if(mail == 0) { mail = ''; }
87                                         $('#mail-update').html(mail);
88                                         var intro = $(this).find('intro').text();
89                                         var register = $(this).find('register').text();
90                                         if(intro == 0) { intro = ''; }
91                                         if(register != 0 && intro != '') { intro = intro+'/'+register; }
92                                         if(register != 0 && intro == '') { intro = '0/'+register; }
93                                         $('#notify-update').html(intro);
94
95                                 });
96                         }) ;
97                 }
98                 timer = setTimeout(NavUpdate,30000);
99
100         }
101
102         function liveUpdate() {
103                 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
104                 if(($('.comment-edit-text-full').length) || (in_progress)) {
105                         livetime = setTimeout(liveUpdate, 10000);
106                         return;
107                 }
108                 prev = 'live-' + src;
109
110                 in_progress = true;
111                 var udargs = ((netargs.length) ? '/' + netargs : '');
112                 var update_url = 'update_' + src + udargs + '?p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
113
114                 $.get(update_url,function(data) {
115                         in_progress = false;
116                         $('.ccollapse-wrapper',data).each(function() {
117                                 var ident = $(this).attr('id');
118                                 if($('#' + ident).length) {
119                                         $('#' + ident).replaceWith($(this));
120                                 }
121                         });
122                         $('.wall-item-outside-wrapper',data).each(function() {
123                                 var ident = $(this).attr('id');
124                                 if($('#' + ident).length == 0) { 
125                                         $('img',this).each(function() {
126                                                 $(this).attr('src',$(this).attr('dst'));
127                                         });
128                                         $('#' + prev).after($(this));
129                                 }
130                                 else { 
131
132                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
133                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
134                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
135                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
136                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
137                                                 $(this).attr('src',$(this).attr('dst'));
138                                         });
139                                 }
140                                 prev = ident; 
141                         });
142                         $('.like-rotator').hide();
143                 });
144
145         }
146
147         function imgbright(node) {
148                 $(node).attr("src",$(node).attr("src").replace('hide','show'));
149                 $(node).css('width',24);
150                 $(node).css('height',24);
151         }
152
153         function imgdull(node) {
154                 $(node).attr("src",$(node).attr("src").replace('show','hide'));
155                 $(node).css('width',16);
156                 $(node).css('height',16);
157         }
158
159         // Since our ajax calls are asynchronous, we will give a few 
160         // seconds for the first ajax call (setting like/dislike), then 
161         // run the updater to pick up any changes and display on the page.
162         // The updater will turn any rotators off when it's done. 
163         // This function will have returned long before any of these
164         // events have completed and therefore there won't be any
165         // visible feedback that anything changed without all this
166         // trickery. This still could cause confusion if the "like" ajax call
167         // is delayed and NavUpdate runs before it completes.
168
169         function dolike(ident,verb) {
170                 $('#like-rotator-' + ident.toString()).show();
171                 $.get('like/' + ident.toString() + '?verb=' + verb );
172                 if(timer) clearTimeout(timer);
173                 timer = setTimeout(NavUpdate,3000);
174                 liking = 1;
175         }
176
177         function getPosition(e) {
178                 var cursor = {x:0, y:0};
179                 if ( e.pageX || e.pageY  ) {
180                         cursor.x = e.pageX;
181                         cursor.y = e.pageY;
182                 }
183                 else {
184                         if( e.clientX || e.clientY ) {
185                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
186                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
187                         }
188                         else {
189                                 if( e.x || e.y ) {
190                                         cursor.x = e.x;
191                                         cursor.y = e.y;
192                                 }
193                         }
194                 }
195                 return cursor;
196         }
197
198         var lockvisible = false;
199
200         function lockview(event,id) {
201                 event = event || window.event;
202                 cursor = getPosition(event);
203                 if(lockvisible) {
204                         lockviewhide();
205                 }
206                 else {
207                         lockvisible = true;
208                         $.get('lockview/' + id, function(data) {
209                                 $('#panel').html(data);
210                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
211                                 $('#panel').show();
212                         });
213                 }
214         }
215
216         function lockviewhide() {
217                 lockvisible = false;
218                 $('#panel').hide();
219         }
220
221         function post_comment(id) {
222                 $.post(  
223              "item",  
224              $("#comment-edit-form-" + id).serialize(),
225                         function(data) {
226                                 if(data.success) {
227                                         $("#comment-edit-wrapper-" + id).hide();
228                                         $("#comment-edit-text-" + id).val('');
229                                 var tarea = document.getElementById("comment-edit-text-" + id);
230                                         if(tarea)
231                                                 commentClose(tarea,id);
232                                         if(timer) clearTimeout(timer);
233                                         timer = setTimeout(NavUpdate,10);
234                                 }
235                                 if(data.reload) {
236                                         window.location.href=data.reload;
237                                 }
238                                         
239                         },
240                         "json"  
241          );  
242          return false;  
243         }
244