]> git.mxchange.org Git - friendica.git/blob - include/main.js
convert feed attach to bbcode
[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         var langSelect = false;
30
31         $(document).ready(function() {
32                 $.ajaxSetup({cache: false});
33
34                 msie = $.browser.msie ;
35                 NavUpdate(); 
36                 // Allow folks to stop the ajax page updates with the pause/break key
37                 $(document).keypress(function(event) {
38                         if(event.keyCode == '19') {
39                                 event.preventDefault();
40                                 if(stopped == false) {
41                                         stopped = true;
42                                         $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
43                                 }
44                                 else {
45                                         stopped = false;
46                                         $('#pause').html('');
47                                 }
48                         }
49                         // F8 - show/hide language selector
50                         if(event.keyCode == '119') {
51                                 if(langSelect) {
52                                         langSelect = false;
53                                         $('#language-selector').hide();
54                                 }
55                                 else {
56                                         langSelect = true;
57                                         $('#language-selector').show();
58                                 }
59                         }               
60
61 // this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
62 // update: incompatible usage of onKeyDown vs onKeyPress
63 //                      if(event.keyCode == '36' && event.shiftKey == true) {
64 //                              if(homebase !== undefined) {
65 //                                      event.preventDefault();
66 //                                      document.location = homebase;
67 //                              }
68 //                      }
69                 });                                     
70         });
71
72         function NavUpdate() {
73
74                 if($('#live-network').length) { src = 'network'; liveUpdate(); }
75                 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
76                 if($('#live-display').length) { 
77                         if(liking) {
78                                 liking = 0;
79                                 window.location.href=window.location.href 
80                         }
81                 }
82                 if($('#live-photos').length)  { 
83                         if(liking) {
84                                 liking = 0;
85                                 window.location.href=window.location.href 
86                         }
87                 }
88
89                 if(! stopped) {
90                         $.get("ping",function(data) {
91                                 $(data).find('result').each(function() {
92                                         var net = $(this).find('net').text();
93                                         if(net == 0) { net = ''; }
94                                         $('#net-update').html(net);
95                                         var home = $(this).find('home').text();
96                                         if(home == 0) { home = ''; }
97                                         $('#home-update').html(home);
98                                         var mail = $(this).find('mail').text();
99                                         if(mail == 0) { mail = ''; }
100                                         $('#mail-update').html(mail);
101                                         var intro = $(this).find('intro').text();
102                                         var register = $(this).find('register').text();
103                                         if(intro == 0) { intro = ''; }
104                                         if(register != 0 && intro != '') { intro = intro+'/'+register; }
105                                         if(register != 0 && intro == '') { intro = '0/'+register; }
106                                         $('#notify-update').html(intro);
107
108                                 });
109                         }) ;
110                 }
111                 timer = setTimeout(NavUpdate,30000);
112
113         }
114
115         function liveUpdate() {
116                 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
117                 if(($('.comment-edit-text-full').length) || (in_progress)) {
118                         livetime = setTimeout(liveUpdate, 10000);
119                         return;
120                 }
121                 prev = 'live-' + src;
122
123                 in_progress = true;
124                 var udargs = ((netargs.length) ? '/' + netargs : '');
125                 var update_url = 'update_' + src + udargs + '?p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
126
127                 $.get(update_url,function(data) {
128                         in_progress = false;
129                         $('.ccollapse-wrapper',data).each(function() {
130                                 var ident = $(this).attr('id');
131                                 if($('#' + ident).length) {
132                                         $('#' + ident).replaceWith($(this));
133                                 }
134                         });
135                         $('.wall-item-outside-wrapper',data).each(function() {
136                                 var ident = $(this).attr('id');
137                                 if($('#' + ident).length == 0) { 
138                                         $('img',this).each(function() {
139                                                 $(this).attr('src',$(this).attr('dst'));
140                                         });
141                                         $('#' + prev).after($(this));
142                                 }
143                                 else { 
144
145                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
146                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
147                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
148                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
149                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
150                                                 $(this).attr('src',$(this).attr('dst'));
151                                         });
152                                 }
153                                 prev = ident; 
154                         });
155                         $('.like-rotator').hide();
156                 });
157
158         }
159
160         function imgbright(node) {
161                 $(node).attr("src",$(node).attr("src").replace('hide','show'));
162                 $(node).css('width',24);
163                 $(node).css('height',24);
164         }
165
166         function imgdull(node) {
167                 $(node).attr("src",$(node).attr("src").replace('show','hide'));
168                 $(node).css('width',16);
169                 $(node).css('height',16);
170         }
171
172         // Since our ajax calls are asynchronous, we will give a few 
173         // seconds for the first ajax call (setting like/dislike), then 
174         // run the updater to pick up any changes and display on the page.
175         // The updater will turn any rotators off when it's done. 
176         // This function will have returned long before any of these
177         // events have completed and therefore there won't be any
178         // visible feedback that anything changed without all this
179         // trickery. This still could cause confusion if the "like" ajax call
180         // is delayed and NavUpdate runs before it completes.
181
182         function dolike(ident,verb) {
183                 $('#like-rotator-' + ident.toString()).show();
184                 $.get('like/' + ident.toString() + '?verb=' + verb );
185                 if(timer) clearTimeout(timer);
186                 timer = setTimeout(NavUpdate,3000);
187                 liking = 1;
188         }
189
190         function getPosition(e) {
191                 var cursor = {x:0, y:0};
192                 if ( e.pageX || e.pageY  ) {
193                         cursor.x = e.pageX;
194                         cursor.y = e.pageY;
195                 }
196                 else {
197                         if( e.clientX || e.clientY ) {
198                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
199                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
200                         }
201                         else {
202                                 if( e.x || e.y ) {
203                                         cursor.x = e.x;
204                                         cursor.y = e.y;
205                                 }
206                         }
207                 }
208                 return cursor;
209         }
210
211         var lockvisible = false;
212
213         function lockview(event,id) {
214                 event = event || window.event;
215                 cursor = getPosition(event);
216                 if(lockvisible) {
217                         lockviewhide();
218                 }
219                 else {
220                         lockvisible = true;
221                         $.get('lockview/' + id, function(data) {
222                                 $('#panel').html(data);
223                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
224                                 $('#panel').show();
225                         });
226                 }
227         }
228
229         function lockviewhide() {
230                 lockvisible = false;
231                 $('#panel').hide();
232         }
233
234         function post_comment(id) {
235                 $.post(  
236              "item",  
237              $("#comment-edit-form-" + id).serialize(),
238                         function(data) {
239                                 if(data.success) {
240                                         $("#comment-edit-wrapper-" + id).hide();
241                                         $("#comment-edit-text-" + id).val('');
242                                 var tarea = document.getElementById("comment-edit-text-" + id);
243                                         if(tarea)
244                                                 commentClose(tarea,id);
245                                         if(timer) clearTimeout(timer);
246                                         timer = setTimeout(NavUpdate,10);
247                                 }
248                                 if(data.reload) {
249                                         window.location.href=data.reload;
250                                 }
251                                         
252                         },
253                         "json"  
254          );  
255          return false;  
256         }
257
258
259     function bin2hex(s){  
260         // Converts the binary representation of data to hex    
261         //   
262         // version: 812.316  
263         // discuss at: http://phpjs.org/functions/bin2hex  
264         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
265         // +   bugfixed by: Onno Marsman  
266         // +   bugfixed by: Linuxworld  
267         // *     example 1: bin2hex('Kev');  
268         // *     returns 1: '4b6576'  
269         // *     example 2: bin2hex(String.fromCharCode(0x00));  
270         // *     returns 2: '00'  
271         var v,i, f = 0, a = [];  
272         s += '';  
273         f = s.length;  
274           
275         for (i = 0; i<f; i++) {  
276             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
277         }  
278           
279         return a.join('');  
280     }  
281
282         function groupChangeMember(gid,cid) {
283                 $('body .fakelink').css('cursor', 'wait');
284                 $.get('group/' + gid + '/' + cid, function(data) {
285                                 $('#group-update-wrapper').html(data);
286                                 $('body .fakelink').css('cursor', 'auto');                              
287                 });
288         }
289
290         function profChangeMember(gid,cid) {
291                 $('body .fakelink').css('cursor', 'wait');
292                 $.get('profperm/' + gid + '/' + cid, function(data) {
293                                 $('#prof-update-wrapper').html(data);
294                                 $('body .fakelink').css('cursor', 'auto');                              
295                 });
296         }
297