]> git.mxchange.org Git - friendica.git/blob - include/main.js
abd097e54a07bcfd7442377823039f264b52e8b4
[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                 $.get('update_' + src + '?p=' + profile_uid + '&msie=' + ((msie) ? 1 : 0),function(data) {
112                         in_progress = false;
113                         $('.wall-item-outside-wrapper',data).each(function() {
114                                 var ident = $(this).attr('id');
115                                 if($('#' + ident).length == 0) { 
116                                         $('img',this).each(function() {
117                                                 $(this).attr('src',$(this).attr('dst'));
118                                         });
119                                         $('#' + prev).after($(this));
120                                 }
121                                 else { 
122
123                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
124                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
125                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
126                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
127                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
128                                                 $(this).attr('src',$(this).attr('dst'));
129                                         });
130
131
132                                 }
133                                 prev = ident; 
134                         });
135                         $('.like-rotator').hide();
136                 });
137
138         }
139
140         function imgbright(node) {
141                 $(node).attr("src",$(node).attr("src").replace('hide','show'));
142                 $(node).css('width',24);
143                 $(node).css('height',24);
144         }
145
146         function imgdull(node) {
147                 $(node).attr("src",$(node).attr("src").replace('show','hide'));
148                 $(node).css('width',16);
149                 $(node).css('height',16);
150         }
151
152         // Since our ajax calls are asynchronous, we will give a few 
153         // seconds for the first ajax call (setting like/dislike), then 
154         // run the updater to pick up any changes and display on the page.
155         // The updater will turn any rotators off when it's done. 
156         // This function will have returned long before any of these
157         // events have completed and therefore there won't be any
158         // visible feedback that anything changed without all this
159         // trickery. This still could cause confusion if the "like" ajax call
160         // is delayed and NavUpdate runs before it completes.
161
162         function dolike(ident,verb) {
163                 $('#like-rotator-' + ident.toString()).show();
164                 $.get('like/' + ident.toString() + '?verb=' + verb );
165                 if(timer) clearTimeout(timer);
166                 timer = setTimeout(NavUpdate,3000);
167                 liking = 1;
168         }
169
170         function getPosition(e) {
171                 var cursor = {x:0, y:0};
172                 if ( e.pageX || e.pageY  ) {
173                         cursor.x = e.pageX;
174                         cursor.y = e.pageY;
175                 }
176                 else {
177                         if( e.clientX || e.clientY ) {
178                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
179                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
180                         }
181                         else {
182                                 if( e.x || e.y ) {
183                                         cursor.x = e.x;
184                                         cursor.y = e.y;
185                                 }
186                         }
187                 }
188                 return cursor;
189         }
190
191         var lockvisible = false;
192
193         function lockview(event,id) {
194                 event = event || window.event;
195                 cursor = getPosition(event);
196                 if(lockvisible) {
197                         lockviewhide();
198                 }
199                 else {
200                         lockvisible = true;
201                         $.get('lockview/' + id, function(data) {
202                                 $('#panel').html(data);
203                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
204                                 $('#panel').show();
205                         });
206                 }
207         }
208
209         function lockviewhide() {
210                 lockvisible = false;
211                 $('#panel').hide();
212         }
213
214         function post_comment(id) {
215                 $.post(  
216              "item",  
217              $("#comment-edit-form-" + id).serialize(),
218                         function(data) {
219                                 if(data.success) {
220                                         $("#comment-edit-wrapper-" + id).hide();
221                                         $("#comment-edit-text-" + id).val('');
222                                 var tarea = document.getElementById("comment-edit-text-" + id);
223                                         if(tarea)
224                                                 commentClose(tarea,id);
225                                         if(timer) clearTimeout(timer);
226                                         timer = setTimeout(NavUpdate,10);
227                                 }
228                         },
229                         "json"  
230          );  
231          return false;  
232         }
233