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