Optional feature : 'Ajax show editors' based on an idea by Tim Starling
[lhc/web/wiklou.git] / skins / common / ajaxshoweditors.js
1 var sajax_debug_mode = false;
2 var canRefresh = null;
3 var ShowEditorsCounting = false;
4 var wgAjaxShowEditors = {} ;
5
6 // The loader. Look at bottom for the sajax hook registration
7 wgAjaxShowEditors.onLoad = function() {
8 var elEditors = document.getElementById( 'ajax-se' );
9 // wgAjaxShowEditors.refresh();
10 elEditors.onclick = function() { wgAjaxShowEditors.refresh(); } ;
11
12 var elTextArea = document.getElementById( 'wpTextbox1' );
13 elTextArea.onkeypress = function() { wgAjaxShowEditors.refresh(); } ;
14
15 wgAjaxShowEditors.allowRefresh();
16 }
17
18
19 // Ask for new data & update UI
20 wgAjaxShowEditors.refresh = function() {
21 if( !canRefresh ) { return; }
22
23 // Disable new requests for 5 seconds
24 canRefresh = false;
25 setTimeout( 'wgAjaxShowEditors.allowRefresh()', 5000 );
26
27 // Load the editors list element, it will get rewrote
28 var elEditorsList = document.getElementById( 'ajax-se-editors' );
29
30 if( wgUserName == null ) {
31 wgUserName = '';
32 }
33
34 // Do the ajax call to the server
35 sajax_do_call( "wfAjaxShowEditors", [ wgArticleId, wgUserName ], elEditorsList );
36 if(!ShowEditorsCounting) {
37 wgAjaxShowEditors.countup();
38 }
39 }
40
41 wgAjaxShowEditors.countup = function() {
42 ShowEditorsCounting = true;
43
44 var elEditorsList = document.getElementById( 'ajax-se-editors' );
45 for(var i=0;i<elEditorsList.childNodes.length;i++) {
46 var item = elEditorsList.childNodes[i];
47 if (item.nodeName == 'SPAN') {
48 var value = parseInt( item.innerHTML );
49 value++;
50 item.innerHTML = value ;
51 }
52 }
53 setTimeout( "wgAjaxShowEditors.countup()", 1000 );
54 }
55
56 // callback to allow refresh
57 wgAjaxShowEditors.allowRefresh = function() {
58 canRefresh = true;
59 }
60
61 // Register our initialization function.
62 hookEvent( "load", wgAjaxShowEditors.onLoad);