Changeset 415 in tmcsimulator for trunk/webapps/einotebook/script/script.js


Ignore:
Timestamp:
06/18/2019 10:44:53 AM (7 years ago)
Author:
jdalbey
Message:

einotebook fix to #131

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/einotebook/script/script.js

    r401 r415  
    1313function jumpToLastExecutedEvent() 
    1414{        
    15         var lastEvent = Script.events.getLastExecutedEvent(readCookie("time")); 
    16          
     15        var lastEventArray = Script.events.getLastExecutedEvent(readCookie("time")); 
     16 
    1717        // IF a current event exists THEN 
    18         if (lastEvent != null) 
    19         { 
    20                 lastEvent.focus(); 
     18        if (lastEventArray != null) 
     19        { 
     20        // Move window focus to first event of the current ones 
     21        var last = lastEventArray.length - 1; 
     22            lastEventArray[last].focus(); 
    2123        } 
    2224        else 
     
    3335function highlightLatestEvent()  
    3436{ 
    35         var currentEvent = Script.events.getLastExecutedEvent(readCookie("time")); 
     37        var currentEventArray = Script.events.getLastExecutedEvent(readCookie("time")); 
    3638 
    3739        // 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          
     40        if (typeof highlightLatestEvent.oldEventArray == 'undefined') 
     41        { 
     42                highlightLatestEvent.oldEventArray = []; /* set up array of old events */ 
     43                var currentEvent = new Object();  
     44                highlightLatestEvent.oldEventArray.push(currentEvent); 
     45                highlightLatestEvent.oldEventArray[0].id = Event.invalidID; 
     46        } 
     47 
    4448        // 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 && currentEvent.id != 0) 
    54                         { 
    55                                 highlightLatestEvent.oldEvent.unhighlight(); 
     49        if (currentEventArray !== null) 
     50        { 
     51                var found = false; /* check if a current event is found in the old event array */ 
     52 
     53                /* traverse the array of current event to check  
     54                if there is event already in the old event array */ 
     55                // IF there is a new current event THEN  
     56                for (j=0; j<highlightLatestEvent.oldEventArray.length; j++) { 
     57                        var oldEvent = highlightLatestEvent.oldEventArray[j]; 
     58                        found = false; 
     59                        for (i=0; i<currentEventArray.length; i++) { 
     60                                var currentEvent = currentEventArray[i]; 
     61                                if (oldEvent.id === currentEvent.id) 
     62                                { 
     63                                        found = true;    
     64                                        break;           
     65                                }  
    5666                        } 
    57                          
    58                         highlightLatestEvent.oldEvent = currentEvent;                    
     67                        /* unhighlight all the events that are no longer current */ 
     68                        if (!found && oldEvent.id !== Event.invalidID) { 
     69                                oldEvent.unhighlight(); 
     70                        }                
    5971                } 
     72 
     73                /* highlight the current event in the array */ 
     74                for (i=0; i<currentEventArray.length; i++) { 
     75                        currentEventArray[i].highlight(); 
     76                } 
     77 
     78                /* update the old events array with current event array */ 
     79                highlightLatestEvent.oldEventArray = currentEventArray; 
    6080        } 
    6181 
    6282    // Set timer to do this again in one second 
    6383        setTimeout("highlightLatestEvent()", 1000); 
    64 } 
    65  
    66  
    67 /** Change color of text of expired events so they appear disabled. 
    68   * @param events The list of events 
    69   * @param currEvent The current event 
    70   */ 
    71 function greyOldEvents(events, currEvent) 
    72 { 
    73           // Examine all events 
    74    for (var evtNum = 0; evtNum < events.length; evtNum++) 
    75    { 
    76                 // Change color of those before current time and Event 
    77       if (events[evtNum].time.compareTo(currEvent.time) < 0 && currEvent.id != events[evtNum].id)  
    78       { 
    79                         events[evtNum].unhighlight(); 
    80       } 
    81         } 
    8284} 
    8385 
     
    101103                // add the Event's html 
    102104                html += Script.events[i].html(); 
    103         } 
    104         
     105        //console.log(Script.events[i].html()); 
     106        } 
    105107         
    106108        // display events in iframe 
     
    115117        Script.events.win.scrollTo(0, readCookie('scriptScrollY')); 
    116118         
    117         greyOldEvents(Script.events, Script.events.getLastExecutedEvent(readCookie("time"))); 
    118119        highlightLatestEvent(); 
    119120 
Note: See TracChangeset for help on using the changeset viewer.