-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
167 lines (153 loc) · 3.8 KB
/
app.js
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
162
163
164
165
166
167
var global = this
$(function () {
var $window = $(window)
var $document = $(document)
var $console = $('#console')
var $verticalbar = $('#verticalbar')
var $horizontalbar = $('#horizontalbar')
var $controller = $('#controller')
var $scope = $('#scope')
var $scopedata = $('#scope-data')
var $log = $('#log')
var $loglist = $('#log>ul')
var $clear = $('#clear-btn')
var barwidth = 4
var clicking = false
var orientation = ''
var xlocation = 0.5
var ylocation = 0.5
var parser = new Parser()
var jqconsole = $('#console').jqconsole('Browser JavaScript\n', '> ')
var envMap = {}
// Events
$verticalbar.mousedown(function () {
clicking = true
orientation = 'x'
})
$horizontalbar.mousedown(function () {
clicking = true
orientation = 'y'
})
$document.mouseup(function () {
clicking = false
})
$document.mousemove(function (e) {
if (clicking === false) {
return
}
if (orientation === 'x') {
xlocation = e.clientX / $window.width()
return resizew(e.clientX)
} else {
ylocation = e.clientY / $window.height()
return resizeh(e.clientY)
}
})
function resizeh (y) {
$scope.css({
height: y - 50 - (barwidth / 2)
})
$horizontalbar.css({
height: barwidth,
top: y - 50 - (barwidth / 2)
})
$log.css({
height: $window.height() - (y + 50 + (barwidth / 2))
})
}
function resizew (x) {
$console.css({
width: (x / $document.width()) * 100 + '%'
})
$verticalbar.css({
width: barwidth,
left: (x / $document.width()) * 100 + '%'
})
$controller.css({
'margin-left': (x / $document.width()) * 100 + '%'
})
}
$window.resize(function () {
resizeh($window.height() * ylocation)
})
$clear.on('click', function () {
for (var id in envMap) {
delete window[id]
}
envMap = {}
$scopedata.html('')
})
jqconsole.RegisterShortcut('R', function () {
this.Reset()
startPrompt()
})
// app logic
function addScope (input) {
var p = parser(input)
for (var i = 0; i < p.length; i++) {
var val = window[p[i]]
var value
try {
if (typeof val === 'object') {
if (Array.isArray(val)) {
value = JSON.stringify(val, 0, 0)
} else {
value = JSON.stringify(val, 0, 2)
}
} else {
value = val.toString().split('\n').join('<br>').split(' ').join(' ')
if (value.indexOf('[native code]') > -1) {
continue
}
}
} catch (e) {
value = val
}
envMap[p[i]] = {
id: p[i],
value: value,
type: Object.prototype.toString.call(val).split(' ')[1].replace(']', '')
}
}
var dataset = []
for (var id in envMap) {
dataset.push(envMap[id])
}
$scopedata.html('')
dataset.forEach(function (el) {
$scopedata.append('<tr><td>' + el.id + '</td><td>' + el.type + '</td><td>' + el.value + '</td></tr>')
})
}
function addLog (input) {
$loglist.prepend('<li>' + input + '</li>')
}
function startPrompt () {
jqconsole.Prompt(true, function (input) {
var output
try {
output = eval.call(global, input)
if (typeof output === 'object') {
if (Array.isArray(output)) {
output = JSON.stringify(output, 0, 0)
} else {
output = JSON.stringify(output, 0, 2)
}
}
addScope(input)
} catch (e) {
output = e
}
if (input) {
addLog(input)
}
if (typeof output !== 'undefined') {
jqconsole.Write(output + '\n', 'jqconsole-output')
}
startPrompt()
})
}
// init
resizew($document.width() * xlocation)
resizeh($document.height() * ylocation)
startPrompt()
})