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