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