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