File: feature.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 (107 lines) | stat: -rw-r--r-- 3,313 bytes parent folder | download
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
let feature=function() {
    function init(e=false) {
        const features = document.getElementsByClassName("featured");
        const width = document.getElementById("main").clientWidth
        
        for (let feature of features) {
            let type = feature.dataset["type"];
            let count = Math.floor((width - 25)/(parseInt(feature.dataset["thumb"])))
            getFeaturePhotos(type, count);
        }
    }

    function getFeaturePhotos(type, count) {
        const url = basePath + "service/feature?type=" + type + "&count=" + count
        let http=new XMLHttpRequest()
        http.responseType = 'json'

        http.open("GET", url, true)
        http.send()
        http.onreadystatechange=function() {
            if (http.readyState == XMLHttpRequest.DONE) {
                processFeatures(http)
            }
        }
    }

    function processFeatures(http) {
        let response = http.response;

        let type = response["type"]
        let objects = response["objects"]
        let ul = null

        const feature = document.querySelector('[data-type="' + type + '"]')
        for (const child of feature.children) {
            if (child.className == "featured-images") {
                ul = child
            }
        }
        switch(type) {
            case "albums":
                featureOrganisers(ul, objects)
                break
            default:
                featurePhotos(ul, objects)
                break
        }
    }

    function featurePhotos(ul, objects) {

        for (let photoId of objects) {
            let a = document.createElement("a");
            a.href = basePath + "photo?photo_id=" + photoId

            let img = document.createElement("img");
            img.className = "thumb";
            img.src = basePath + "image/thumb?photo_id=" + photoId
            let li = document.createElement("li")
            a.appendChild(img)
            li.appendChild(a)
            ul.appendChild(li)
        }

    }
    
    function featureOrganisers(ul, objects) {
        for (let object of objects) {
            let a = document.createElement("a");
            a.href = basePath + "album?album_id=" + object["id"]
            
            let div = document.createElement("div")
            div.className = "coverphoto"

            if (object["cover"] != 0) {
                let img = document.createElement("img");
                img.className = "thumb"
                img.src = basePath + "image/thumb?photo_id=" + object["cover"]
                div.appendChild(img)
                div.appendChild(document.createElement("br"))
            }
            //covera = a.cloneNode()
            a.appendChild(div)
            
            let titlediv = document.createElement("div")
            titlediv.className = "name"

            titlediv.appendChild(document.createTextNode(object["title"]))
            a.appendChild(titlediv)

            let li = document.createElement("li")
            li.className = "thumb_album"
            //li.appendChild(covera)
            li.appendChild(a)
            ul.appendChild(li)
        }
        ul.classList.add("thumbs")
    }

    return {
        init:init,
        getFeaturePhotos:getFeaturePhotos,
    };
}();

window.addEventListener("load",feature.init,false);