source: extensions/rv_gmaps/trunk/template/windows_13/javascripts/extended_debug.js @ 3447

Last change on this file since 3447 was 3447, checked in by rvelices, 15 years ago
  • added RV Map & Earth extension
  • Property svn:eol-style set to LF
File size: 3.3 KB
Line 
1var commandHistory;
2var historyIndex;
3
4function showExtendedDebug() {
5        if (debugWindow != null) {
6          hideDebug();
7  }
8 
9        if (debugWindow == null) {
10                commandHistory = new Array();
11                historyIndex = 0;
12               
13                debugWindow = new Window('debug_window', {className: 'dialog',width:250, height:100, right:4, minWidth:250, bottom:42, zIndex:1000, opacity:1, showEffect: Element.show, resizable: true, title: "Debug"})
14                debugWindow.getContent().innerHTML = "<style>#debug_window .dialog_content {background:#000;}</style> <div font='monaco' id='debug' style='padding:3px;color:#0F0;font-family:monaco'></div>";
15
16                //create hourglass icon and attach events to it.
17                var cont = "<div id=\"debug_window_inspect\" style=\"width: 15px; height: 15px; background: transparent url(themes/default/inspect.gif) no-repeat 0 0; position:absolute; top:5px; left:70px; cursor:pointer; z-index:3000;\"></div>";
18
19                new Insertion.After('debug_window_maximize', cont);
20                Event.observe('debug_window_inspect', 'click', enterInspectionMode, false);
21
22                //create command text box
23                cont = "Eval:<input id=\"debug_window_command\" type=\"textbox\" style=\"width:150px; height: 12px; color: black;\">"
24                debugWindow.setStatusBar(cont);
25
26                Event.observe('debug_window_command', 'mousedown', donothing);
27                Event.observe('debug_window_command', 'keypress', evalJS, false);
28        }
29        debugWindow.show();             
30}
31
32function donothing(evt){
33                Field.activate('debug_window_command');
34                return false;
35}
36
37function evalJS(evt){
38        if(evt.keyCode == Event.KEY_RETURN){
39                var js = $F('debug_window_command');
40                try{
41                        var ret = eval(js);
42                        if(ret != null)
43                                debug(ret);
44                }catch(e){
45                        debug(e);
46                }
47                $('debug_window_command').value = '';
48
49                Field.activate('debug_window_command');
50                commandHistory.push(js);
51                historyIndex = 0;
52        }
53
54        if(evt.keyCode == Event.KEY_UP){
55                if(commandHistory.length > historyIndex){
56                        historyIndex++;
57                        var js = commandHistory[commandHistory.length-historyIndex];
58                        $('debug_window_command').value = js;
59                        Event.stop(evt);
60                        Field.activate('debug_window_command');
61                }
62        }
63
64        if(evt.keyCode == Event.KEY_DOWN){
65                if(commandHistory.length >= historyIndex && historyIndex > 1){
66                        historyIndex--;
67                        var js = commandHistory[commandHistory.length-historyIndex];
68                        $('debug_window_command').value = js;
69                        Event.stop(evt);
70                        Field.activate('debug_window_command');
71                }
72        }       
73}
74
75function enterInspectionMode(evt){
76        //stop observing magnifying glass
77        Event.stopObserving('debug_window_inspect', 'click', enterInspectionMode, false);
78        //change pointer
79        document.body.style.cursor='help';
80        //start observing mouse clicks
81        Event.observe(window, 'click', inspectItem, false);             
82}
83
84function inspectItem(evt){
85        // the element that triggered the event
86        var element = Event.element(evt);
87        if(element.id!="debug_window_inspect"){
88                clearDebug()
89                //change pointer
90                document.body.style.cursor='default';
91                debug(element.id);
92                inspect(element);
93                //stop observing mouse clicks
94                Event.stopObserving(window, 'click', inspectItem, false);
95                //alert('doing something');
96                //start observing mag
97                Event.observe('debug_window_inspect', 'click', enterInspectionMode, false);
98        }
99}
100
101function clearDebug() {
102        var win = $('debug');
103        if (win == null)
104                return;
105               
106        win.innerHTML=" ";
107        //clear inspections too
108        var divs = document.getElementsByClassName('inspector');
109        divs.each(function(div){
110                Element.remove(div);
111        });
112}
113
Note: See TracBrowser for help on using the repository browser.