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