]> git.mxchange.org Git - friendica.git/blob - include/main.js
ca6d56d8b83e542fb4317ee32dd57cf08414ea46
[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         function commentOpen(obj,id) {
20                 if(obj.value == 'Comment') {
21                         obj.value = '';
22                         obj.className = "comment-edit-text-full";
23                         openMenu("comment-edit-submit-wrapper-" + id);
24                 }
25         }
26         function commentClose(obj,id) {
27                 if(obj.value == '') {
28                         obj.value = 'Comment';
29                         obj.className="comment-edit-text-empty";
30                         closeMenu("comment-edit-submit-wrapper-" + id);
31                 }
32         }
33
34         var src = null;
35         var prev = null;
36         var livetime = null;
37         var msie = false;
38         var stopped = false;
39
40         $(document).ready(function() {
41                 $.ajaxSetup({cache: false});
42                 msie = $.browser.msie ;
43                 NavUpdate(); 
44                 // Allow folks to stop the ajax page updates with the pause/break key
45                 $(document).keypress(function(event) {
46                         if(event.keyCode == '19') {
47                                 event.preventDefault();
48                                 if(stopped == false)
49                                         stopped = true;
50                                 else {
51                                         stopped = false;
52                                 }
53                         }
54                 });                                     
55         });
56
57         function NavUpdate() {
58
59                 if($('#live-network').length) { src = 'network'; liveUpdate(); }
60                 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
61
62                 if(! stopped) {
63                         $.get("ping",function(data) {
64                                 $(data).find('result').each(function() {
65                                         var net = $(this).find('net').text();
66                                         if(net == 0) { net = ''; }
67                                         $('#net-update').html(net);
68                                         var home = $(this).find('home').text();
69                                         if(home == 0) { home = ''; }
70                                         $('#home-update').html(home);
71                                         var mail = $(this).find('mail').text();
72                                         if(mail == 0) { mail = ''; }
73                                         $('#mail-update').html(mail);
74                                         var intro = $(this).find('intro').text();
75                                         if(intro == 0) { intro = ''; }
76                                         $('#notify-update').html(intro);
77                                 });
78                         }) ;
79                 }
80                 setTimeout(NavUpdate,30000);
81
82         }
83
84         function liveUpdate() {
85                 if((src == null) || (stopped)) { return; }
86                 if($('.comment-edit-text-full').length) {
87                         livetime = setTimeout(liveUpdate, 10000);
88                         return;
89                 }
90                 prev = 'live-' + src;
91
92                 $.get('update_' + src + '?msie=' + ((msie) ? 1 : 0),function(data) {
93                         $('.wall-item-outside-wrapper',data).each(function() {
94                                 var ident = $(this).attr('id');
95                                 if($('#' + ident).length == 0) { 
96                                         $('img',this).each(function() {
97                                                 $(this).attr('src',$(this).attr('dst'));
98                                         });
99                                         $('#' + prev).after($(this));
100                                 }
101                                 else { 
102
103                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
104                                         $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
105                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
106                                                 $(this).attr('src',$(this).attr('dst'));
107                                         });
108
109
110                                 }
111                                 prev = ident; 
112                         });
113                 });
114
115         }
116
117         function confirmDelete() { 
118                 return confirm("Delete this item?");
119         }
120
121         function imgbright(node) {
122                 $(node).attr("src",$(node).attr("src").replace('hide','show'));
123                 $(node).css('width',24);
124                 $(node).css('height',24);
125         }
126
127         function imgdull(node) {
128                 $(node).attr("src",$(node).attr("src").replace('show','hide'));
129                 $(node).css('width',16);
130                 $(node).css('height',16);
131         }