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