File: thumbview.js

package info (click to toggle)
zoph 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,632 kB
  • sloc: php: 28,044; javascript: 10,435; sql: 527; sh: 153; makefile: 4
file content (142 lines) | stat: -rw-r--r-- 4,587 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// This file is part of Zoph.
//
// Zoph is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// Zoph is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Zoph; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

var thumbview = function () {

    function init() {
        var popup = getElementsByClass('popup');

        for (var i=0; i<popup.length; i++) {
            popup[i].onmouseover=thumbview.showDetails;
            popup[i].onmouseout=thumbview.destroyDetails;
        }
    }
    
    function toggle(obj) {
        if(obj.className.indexOf("collapsed")>=0) {
            obj.className=obj.className.replace(/\bcollapsed\b/g,'expanded');
        } else if(obj.className.indexOf("expanded")>=0) {
            obj.className=obj.className.replace(/\bexpanded\b/g,'collapsed');
        }
    }

    function collapseall(id) {
        let obj=document.getElementById(id);
        let nodes=getElementsByClass('expanded', obj);
        for(let node of nodes) {
            node.className=node.className.replace(/\bexpanded\b/g,'collapsed');
        }
    }

    function expandall(id) {
        let obj=document.getElementById(id);
        let nodes=getElementsByClass('collapsed',obj);
        for(let node of nodes) {
            node.className=node.className.replace(/\bcollapsed\b/g,'expanded');
        }
    }

    function showDetails(e) {
        var body=document.getElementsByTagName("body")[0];
        
        var id=this.id.split("_");
        id.shift();
       
        
        var div=document.createElement("div");
        div.className="details";
        div.id="details_" + id.join("_");
        div.style.visibility="hidden";
        
        body.appendChild(div);
        
       
        XML.getData(div.id);
    }

    function httpResponse(xml) {
        
        var request=xml.getElementsByTagName("request")[0];

        var classname=request.getElementsByTagName("class")[0].firstChild.nodeValue;
        var id=request.getElementsByTagName("id")[0].firstChild.nodeValue;
       

        var div=document.getElementById("details_" + classname + "_" + id);
        if(div) {
            removeChildren(div);
            var dl=document.createElement("dl");

            var li_id="thumb_" + classname + "_" + id;

            var li=document.getElementById(li_id);

            let details=xml.getElementsByTagName("detail");
            var title, dt, dd, icon, subject, data;

            for(let detail of details) {

                subject=detail.getElementsByTagName("subject")[0].firstChild.nodeValue;
                data=detail.getElementsByTagName("data")[0].firstChild.nodeValue;
            
                if(subject==="title") {
                    title=createNode("h3", data);
                    div.appendChild(title);
                } else {
                    dt=document.createElement("dt");
                    icon=document.createElement("img");

                    icon.setAttribute("src", icons[subject] );
                    icon.setAttribute("alt", subject);
                    dt.appendChild(icon);
                    dd=createNode("dd", data);
                    
                    dl.appendChild(dt);
                    dl.appendChild(dd);
                }
            }
            div.appendChild(dl);
        
            div.style.left=findPos(li)[0] - 20 + "px";
            div.style.top=findPos(li)[1] - div.offsetHeight + "px";
            div.style.visibility="visible";
       } 
   }

   function destroyDetails(e) {
        var id=this.id.split("_");
        id.shift();
        deleteNode(document.getElementById("details_" + id.join("_")));
   }

    return {
        init:init,
        toggle:toggle,
        collapseall:collapseall,
        expandall:expandall,
        showDetails:showDetails,
        destroyDetails:destroyDetails,
        httpResponse:httpResponse
    };

}();


if(window.addEventListener) {
    window.addEventListener("load",thumbview.init,false);
} else {
    // Why can't M$ simply follow the standard?
    window.attachEvent("onload",thumbview.init);
}