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