xref: /plugin/qc/script.js (revision 73b69db12a4e06e2b26f58f4d33b1f04f891a3bd)
1
2/**
3 * extend index object function to add quality icons to all pages
4 */
5index.saved_treeattach = index.treeattach;
6index.treeattach = function(obj){
7    index.saved_treeattach(obj);
8
9    var items = getElementsByClass('wikilink1',obj,'a');
10    for(var i=0; i<items.length; i++){
11        var elem = items[i];
12
13        var img       = document.createElement('img');
14        img.src       = DOKU_BASE+'lib/plugins/qc/icon.php?id='+elem.title+'&type=small';
15        img.alt       = '';
16        img.className = 'qc_smallicon';
17        elem.parentNode.appendChild(img);
18    }
19};
20
21
22function plugin_qc_toggle(e){
23    var out = $('plugin__qc__out');
24    if(!out) return;
25
26    // extract needed params from the icon src URL
27    var param = e.target.src.split('?');
28
29    // it's shown currently -> disable
30    if(out.style.display != 'none'){
31        out.style.display = 'none';
32        return;
33    }
34
35    // it's not shown currently -> fetch
36    out.innerHTML = 'loading...';
37    out.style.display = '';
38
39    var ajax = new sack(DOKU_BASE + 'lib/plugins/qc/pageinfo.php');
40    ajax.AjaxFailedAlert = '';
41    ajax.encodeURIString = false;
42    ajax.elementObj = out;
43    ajax.runAJAX(param[1]);
44
45}
46
47addInitEvent(function(){
48    var icon = $('plugin__qc__icon');
49    if(!icon) return;
50    addEvent(icon,'click',plugin_qc_toggle);
51    icon.style.cursor = 'pointer';
52});
53