source: tmcsimulator/trunk/webapps/cptms/gotoxmltime.html @ 351

Revision 351, 3.2 KB checked in by jdalbey, 7 years ago (diff)

updated ei notebook proof of concepts

Line 
1<html>
2<head>
3<style>
4.pic-container {
5    width: 500px;
6    height: 400px;
7    overflow-y: scroll;
8    overflow-x:hidden;
9}
10#clockdiv {
11    font-size: xx-large;
12    font-weight: bold;
13    font-family: "Lucida Console", Monaco, monospace;
14}
15</style>
16<body>
17<!-- Prototype for a display that scrolls to the current time -->
18<div id="clockdiv">0:00</div>
19<div> <button onclick="scrollToCurrent()">Goto Current Item</button></div>
20<div id="main" class="pic-container"></div>
21<div id="two">Footer</div>
22<script   src="poem.js"></script>
23<script  src="js/common.js"></script>
24<script>
25var xmlDoc;
26var currElement;
27var clockdiv = document.getElementById("clockdiv");
28/** Load the sim clock file and extract the clock string */
29function gettime()
30{
31    loadJSON("sim_clock.json", function(response)
32    {
33        simclockjson = JSON.parse(response);
34        clockstring = simclockjson.clock;
35        clockdiv.innerHTML = clockstring;  // Display current time
36        // Extract the seconds digits
37        digits = clockstring.substring(clockstring.length-2)
38        if (digits.charAt(0) == "0")
39        {
40            digits = digits.charAt(1);
41        }
42        // go adjust the scrolling box
43        //adjust(digits);
44    });
45}
46function getEvents()
47{
48    loadJSON("sample_events.xml", function(response)
49    {       
50        var parser = new DOMParser();
51        xmlDoc = parser.parseFromString(response,"text/xml");
52
53        // Place each line in its own DIV with a sequential ID
54        for (var idx=0; idx < 100; idx++)
55        {
56            var div = document.createElement("div");
57            MHSTime = xmlDoc.getElementsByTagName("time")[idx].childNodes[0].nodeValue;
58            div.id=MHSTime
59            div.className =  "item"
60            div.style.color = "black";
61            div.style.background = "GhostWhite";
62            div.style.height = 30;
63            div.innerHTML = MHSTime + " " + xmlDoc.getElementsByTagName("description")[idx].childNodes[0].nodeValue;
64            // Append it to the parent div
65            document.getElementById("main").appendChild(div);
66            currElement = document.getElementById("0:00:10");
67        }
68
69    });
70}
71// Highlight the current line and scroll to it.
72function scrollToCurrent()
73{
74    if (currElement != null)
75    {
76        currTime = clockdiv.innerHTML;
77        // Find the element with the id = seconds digits
78        target = findNearestElem();
79        //target = document.getElementById(currTime)
80        if (target != null)
81        {
82            // restore the previous element's background color
83            currElement.style.background = "GhostWhite";
84            currElement = target;
85            currElement.style.background = "Gainsboro"; // set background color
86            //currElement.scrollTop = 0;
87            currElement.scrollIntoView();  // scroll to it
88        }
89    }
90}
91
92function findNearestElem()
93{
94    var list = document.getElementsByClassName("item")
95    var idx = 0;
96    while (list[idx].id <  currTime) 
97    {
98        idx++;
99    }
100    return list[idx-1];
101    // Note: will crash when currTime > length of list
102}
103
104// MAIN
105
106getEvents();
107
108// Go get the current sim time every second
109var myinterval = setInterval(gettime,1000);
110//clearTimeout(myVar);
111 
112</script>
113</body>
114
115</html>
Note: See TracBrowser for help on using the repository browser.