| 1 | /** |
|---|
| 2 | * Holds references to the events and incidents. |
|---|
| 3 | */ |
|---|
| 4 | function Script() |
|---|
| 5 | { |
|---|
| 6 | Script.events = null; |
|---|
| 7 | Script.incidents = null; |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * Scrolls to the last event executed based on time. |
|---|
| 12 | */ |
|---|
| 13 | function jumpToLastExecutedEvent() |
|---|
| 14 | { |
|---|
| 15 | var lastEvent = Script.events.getLastExecutedEvent(readCookie("time")); |
|---|
| 16 | |
|---|
| 17 | // IF a current event exists THEN |
|---|
| 18 | if (lastEvent != null) |
|---|
| 19 | { |
|---|
| 20 | lastEvent.focus(); |
|---|
| 21 | } |
|---|
| 22 | else |
|---|
| 23 | { |
|---|
| 24 | alert("No events have been executed yet."); |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Finds the Event that was last executed by based on time and highlights it. |
|---|
| 30 | * Removes highlighting from old events. |
|---|
| 31 | * @return |
|---|
| 32 | */ |
|---|
| 33 | function highlightLatestEvent() |
|---|
| 34 | { |
|---|
| 35 | var currentEvent = Script.events.getLastExecutedEvent(readCookie("time")); |
|---|
| 36 | |
|---|
| 37 | // IF the old event is has not been set THEN |
|---|
| 38 | if (typeof highlightLatestEvent.oldEvent == 'undefined') |
|---|
| 39 | { |
|---|
| 40 | highlightLatestEvent.oldEvent = new Object(); |
|---|
| 41 | highlightLatestEvent.oldEvent.id = Event.invalidID; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | // IF a current event exists THEN |
|---|
| 45 | if (currentEvent != null) |
|---|
| 46 | { |
|---|
| 47 | // IF there is a new current event THEN |
|---|
| 48 | if (highlightLatestEvent.oldEvent.id != currentEvent.id) |
|---|
| 49 | { |
|---|
| 50 | currentEvent.highlight(); |
|---|
| 51 | |
|---|
| 52 | // IF there was previously a current event THEN |
|---|
| 53 | if (highlightLatestEvent.oldEvent.id != Event.invalidID) |
|---|
| 54 | { |
|---|
| 55 | highlightLatestEvent.oldEvent.unhighlight(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | highlightLatestEvent.oldEvent = currentEvent; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | // Set timer to do this again in one second |
|---|
| 63 | setTimeout("highlightLatestEvent()", 1000); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Loads the the script tab for the given document. |
|---|
| 68 | * @pre script.html must be completely loaded |
|---|
| 69 | * @param aDocument |
|---|
| 70 | */ |
|---|
| 71 | function loadScript(theEvents, theIncidents) |
|---|
| 72 | { |
|---|
| 73 | Script.incidents = theIncidents; |
|---|
| 74 | Script.events = theEvents; |
|---|
| 75 | Script.events.win = document.getElementById("view").contentWindow; |
|---|
| 76 | Script.events.doc = getDocumentFromFrame('view'); |
|---|
| 77 | |
|---|
| 78 | var html = ""; |
|---|
| 79 | |
|---|
| 80 | // FOR each Event |
|---|
| 81 | for (var i = 0; i < Script.events.length; i++) |
|---|
| 82 | { |
|---|
| 83 | // add the Event's html |
|---|
| 84 | html += Script.events[i].html(); |
|---|
| 85 | //console.log(Script.events[i].html()); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | // display events in iframe |
|---|
| 89 | getDocumentFromFrame('view').body.innerHTML = html; |
|---|
| 90 | |
|---|
| 91 | // resize iframe to appropriate height |
|---|
| 92 | resizeIframe(); |
|---|
| 93 | window.onresize = resizeIframe; |
|---|
| 94 | // This line is causing an error |
|---|
| 95 | //window.frames['view'].setEvents(Script.events); |
|---|
| 96 | |
|---|
| 97 | Script.events.win.scrollTo(0, readCookie('scriptScrollY')); |
|---|
| 98 | |
|---|
| 99 | highlightLatestEvent(); |
|---|
| 100 | |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * @param id The id of the frame element. |
|---|
| 105 | * @return The document of the frame element. |
|---|
| 106 | */ |
|---|
| 107 | function getDocumentFromFrame(id) |
|---|
| 108 | { |
|---|
| 109 | var frame=document.getElementById(id); |
|---|
| 110 | var doc=(frame.contentWindow || frame.contentDocument); |
|---|
| 111 | |
|---|
| 112 | if (doc.document)doc=doc.document; |
|---|
| 113 | |
|---|
| 114 | return doc; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | * Finds the height of an element relative to the BODY tag. |
|---|
| 119 | * @param elem The element to find the height of. |
|---|
| 120 | * @return The y-coordinate of the given element relative to the BODY tag. |
|---|
| 121 | */ |
|---|
| 122 | function pageY(elem) |
|---|
| 123 | { |
|---|
| 124 | return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * Resizes the view for the events so that the view's height is at the bottom of its |
|---|
| 129 | * container. |
|---|
| 130 | */ |
|---|
| 131 | function resizeIframe() |
|---|
| 132 | { |
|---|
| 133 | var height = document.documentElement.clientHeight; |
|---|
| 134 | height -= pageY(document.getElementById('view')); |
|---|
| 135 | height = (height < 0) ? 0 : height - 10; |
|---|
| 136 | document.getElementById('view').style.height = height + 'px'; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * Highlights the text of an input text element after a small delay. |
|---|
| 141 | * This method was made because using the code "onFocus='this.focus()'" did not work. |
|---|
| 142 | * @pre textField must have an 'id' attribute |
|---|
| 143 | * @param textField An input text element. |
|---|
| 144 | */ |
|---|
| 145 | function highlightTextField(textField) |
|---|
| 146 | { |
|---|
| 147 | setTimeout("document.getElementById('" + textField.id + "').select();", 100); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | /** |
|---|
| 151 | * Formats a two digit textbox. If the text box contains only one digit, then a zero |
|---|
| 152 | * is appended to the front. |
|---|
| 153 | * @param textField An input text element. |
|---|
| 154 | */ |
|---|
| 155 | function formatTimeTextfield(textField) |
|---|
| 156 | { |
|---|
| 157 | // IF the text field contains 1 digits THEN |
|---|
| 158 | if (textField.value.length == 1) |
|---|
| 159 | { |
|---|
| 160 | textField.value = "0".concat(textField.value); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | /** |
|---|
| 165 | * Scrolls to the event latest executed event if the current simulation time was given |
|---|
| 166 | * by text fields 'timeTextSeconds', 'timeTextMinutes', 'timeTextHours'. |
|---|
| 167 | */ |
|---|
| 168 | function jumpToTime() |
|---|
| 169 | { |
|---|
| 170 | var seconds = parseInt(document.getElementById('timeTextSeconds').value, 10); |
|---|
| 171 | var minutes = parseInt(document.getElementById('timeTextMinutes').value, 10); |
|---|
| 172 | var hours = parseInt(document.getElementById('timeTextHours').value, 10); |
|---|
| 173 | |
|---|
| 174 | var lastEvent = Script.events.getLastExecutedEvent(new Time(hours, minutes, seconds).getSeconds()); |
|---|
| 175 | |
|---|
| 176 | // IF an event was executed THEN |
|---|
| 177 | if (lastEvent != null) |
|---|
| 178 | { |
|---|
| 179 | lastEvent.focus(); |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | /** |
|---|
| 184 | * Collapses the elements based on the value of the dropdownbox with id 'domain'. |
|---|
| 185 | */ |
|---|
| 186 | function collapse() |
|---|
| 187 | { |
|---|
| 188 | var selection = document.getElementById('domain'); |
|---|
| 189 | var selectedIndex = selection.selectedIndex; |
|---|
| 190 | var selectedValue = selection.options[selectedIndex].value; |
|---|
| 191 | |
|---|
| 192 | eval("Script.events.collapseAll" + selectedValue + "();"); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | * Expands the elements based on the value of the dropdownbox with id 'domain'. |
|---|
| 197 | */ |
|---|
| 198 | function expand() |
|---|
| 199 | { |
|---|
| 200 | var selection = document.getElementById('domain'); |
|---|
| 201 | var selectedIndex = selection.selectedIndex; |
|---|
| 202 | var selectedValue = selection.options[selectedIndex].value; |
|---|
| 203 | |
|---|
| 204 | eval("Script.events.expandAll" + selectedValue + "();"); |
|---|
| 205 | } |
|---|
| 206 | |
|---|