summaryrefslogtreecommitdiff
path: root/paste/evalexception/media/debug.js
blob: 57f9df3dcc62ff1fcb6d4b2265620a51bd2b89b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
function showFrame(anchor) {
    var tbid = anchor.getAttribute('tbid');
    var expanded = anchor.expanded;
    if (expanded) {
        MochiKit.DOM.hideElement(anchor.expandedElement);
        anchor.expanded = false;
        _swapImage(anchor);
        return false;
    }
    anchor.expanded = true;
    if (anchor.expandedElement) {
        MochiKit.DOM.showElement(anchor.expandedElement);
        _swapImage(anchor);
        $('debug_input_'+tbid).focus();
        return false;
    }
    var url = debug_base
        + '/show_frame?tbid=' + tbid
        + '&debugcount=' + debug_count;
    var d = MochiKit.Async.doSimpleXMLHttpRequest(url);
    d.addCallbacks(function (data) {
        var el = MochiKit.DOM.DIV({});
        anchor.parentNode.insertBefore(el, anchor.nextSibling);
        el.innerHTML = data.responseText;
        anchor.expandedElement = el;
        _swapImage(anchor);
        $('debug_input_'+tbid).focus();
    }, function (error) {
        showError(error.req.responseText);
    });
    return false;
}

function _swapImage(anchor) {
    var el = anchor.getElementsByTagName('IMG')[0];
    if (anchor.expanded) {
        var img = 'minus.jpg';
    } else {
        var img = 'plus.jpg';
    }
    el.src = debug_base + '/media/' + img;
}

function submitInput(button, tbid) {
    var input = $(button.getAttribute('input-from'));
    var output = $(button.getAttribute('output-to'));
    var url = debug_base
        + '/exec_input';
    var history = input.form.history;
    input.historyPosition = 0;
    if (! history) {
        history = input.form.history = [];
    }
    history.push(input.value);
    var vars = {
        tbid: tbid,
        debugcount: debug_count,
        input: input.value
    };
    MochiKit.DOM.showElement(output);
    var d = MochiKit.Async.doSimpleXMLHttpRequest(url, vars);
    d.addCallbacks(function (data) {
        var result = data.responseText;
        output.innerHTML += result;
        input.value = '';
        input.focus();
    }, function (error) {
        showError(error.req.responseText);
    });
    return false;
}

function showError(msg) {
    var el = $('error-container');
    if (el.innerHTML) {
        el.innerHTML += '<hr noshade>\n' + msg;
    } else {
        el.innerHTML = msg;
    }
    MochiKit.DOM.showElement('error-area');
}

function clearError() {
    var el = $('error-container');
    el.innerHTML = '';
    MochiKit.DOM.hideElement('error-area');
}

function expandInput(button) {
    var input = button.form.elements.input;
    stdops = {
        name: 'input',
        style: 'width: 100%',
        autocomplete: 'off'
    };
    if (input.tagName == 'INPUT') {
        var newEl = MochiKit.DOM.TEXTAREA(stdops);
        var text = 'Contract';
    } else {
        stdops['type'] = 'text';
        stdops['onkeypress'] = 'upArrow(this)';
        var newEl = MochiKit.DOM.INPUT(stdops);
        var text = 'Expand';
    }
    newEl.value = input.value;
    newEl.id = input.id;
    MochiKit.DOM.swapDOM(input, newEl);
    newEl.focus();
    button.value = text;
    return false;
}

function upArrow(input, event) {
    if (window.event) {
        event = window.event;
    }
    if (event.keyCode != 38 && event.keyCode != 40) {
        // not an up- or down-arrow
        return true;
    }
    var dir = event.keyCode == 38 ? 1 : -1;
    var history = input.form.history;
    if (! history) {
        history = input.form.history = [];
    }
    var pos = input.historyPosition || 0;
    if (! pos && dir == -1) {
        return true;
    }
    if (! pos && input.value) {
        history.push(input.value);
        pos = 1;
    }
    pos += dir;
    if (history.length-pos < 0) {
        pos = 1;
    }
    if (history.length-pos > history.length-1) {
        input.value = '';
        return true;
    }
    input.historyPosition = pos;
    var line = history[history.length-pos];
    input.value = line;
}

function expandLong(anchor) {
    var span = anchor;
    while (span) {
        if (span.style && span.style.display == 'none') {
            break;
        }
        span = span.nextSibling;
    }
    if (! span) {
        return false;
    }
    MochiKit.DOM.showElement(span);
    MochiKit.DOM.hideElement(anchor);
    return false;
}