7aec65e7716bdc06312fdef029cb2f5f39390c52
[quandoparte] / www / screenshot-generator.js
1 var screenshots = {
2         "screenshot-stationlist.png" : "The Station List View",
3         "screenshot-stationview.png" : "The Station Departures View",
4         "screenshot-stationlist-menu.png" : "The Station List Menu",
5         "screenshot-stationview-menu.png" : "The Station Departures Menu",
6 };
7
8 function dismiss_picture()
9 {
10         var parent = this.parentNode;
11         parent.style.opacity = 0.0;
12         parent.style.visibility = 'hidden';
13         parent.display = 'none';
14 }
15
16 function present_picture()
17 {
18         var display = document.getElementById('picture-display');
19         parent.display = 'block';
20         display.style.visibility = 'visible';
21         display.style.opacity = 1.0;
22         display.style.left = (window.width  - display.width) / 2;
23         display.style.top = (window.height  - display.height) / 2;
24         var picture = document.getElementById('picture-display-picture');
25         picture.setAttribute('src', this.getAttribute('src'));
26 }
27
28 function generate_div(value, index, array)
29 {
30         var screenshots = document.getElementById('screenshot-list');
31         var screenshotDiv = document.createElement('div');
32         screenshotDiv.setAttribute('class', 'screenshot');
33         
34         var p1Element = document.createElement('div');
35         var p2Element = p1Element.cloneNode(true);
36         
37         var aElement = document.createElement('img');
38         aElement.setAttribute('src', index);
39         if (aElement.addEventListener) {
40                 aElement.addEventListener('click', present_picture, true);
41         } else if (aElement.attachEvent) {
42                 aElement.attachEvent('onclick', show_picture);
43         }
44
45         var imgElement = document.createElement('img');
46         imgElement.setAttribute('src', index);
47
48         var captionElement = document.createTextNode(value);
49
50         p1Element.appendChild(aElement);
51         aElement.appendChild(imgElement);
52         p2Element.appendChild(captionElement);
53
54         screenshotDiv.appendChild(p1Element);
55         screenshotDiv.appendChild(p2Element);
56         screenshots.appendChild(screenshotDiv);
57 }
58
59 function build_screenshot_list()
60 {
61         for (var key in screenshots)
62                 generate_div(screenshots[key], key, screenshots);
63
64         var element = document.getElementById('picture-display-picture');
65         if (element.addEventListener) {
66                 element.addEventListener('click', dismiss_picture, false);
67         } else if (element.attachEvent) {
68                 window.attachEvent('onclick', dismiss_picture);
69         }
70 }
71
72 if (window.addEventListener) {
73         window.addEventListener('load', build_screenshot_list, false);
74 } else if (window.attachEvent) {
75         window.attachEvent('onload', build_screenshot_list);
76 }
77
78