forked from oraoto/pib
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
168 lines (148 loc) · 5.18 KB
/
index.html
File metadata and controls
168 lines (148 loc) · 5.18 KB
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
168
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>PIB: PHP in Browser</title>
<script src="//ajaxorg.github.io/ace-builds/src-min/ace.js" type="text/javascript" charset="utf-8"></script>
<style>
body {
background-color: #E1E1DB;
padding: 0 1em;
margin: 0;
font-family: "Open Sans", sans-serif;
box-sizing: border-box;
}
.playground {
display: flex;
height: 100vh;
flex-direction: column;
padding-bottom: 1em;
box-sizing: inherit;
}
.playground-header {
display: flex;
font-size: 12px;
padding: 1.25em 0;
}
.playground-split-vertical {
flex-direction: row;
display: flex;
height: 100vh;
}
.playground-editor {
flex: 1 1 auto;
position: relative;
border: 4px solid #bbb;
border-radius: 4px;
}
#output {
flex: 1 1 auto;
position: relative;
margin-left: 0.5em;
background: #f9ffff;
border: 1px solid #bbb;
border-right: none;
}
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#run {
height: 3em;
padding: 0 1.25em;
display: flex;
align-items: center;
text-transform: uppercase;
text-decoration: none;
font-weight: 700;
white-space: nowrap;
background: #a42;
color: #fff;
border-color: #88361b;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
cursor: pointer;
border-radius: 4px;
border: 1px solid #dedede;
}
</style>
</head>
<body>
<div class="playground">
<div class="playground-header">
<button id="run" disabled>Loading...</button>
</div>
<div class="playground-split-vertical">
<div class="playground-editor">
<div id="editor"></div>
</div>
<iframe allow="midi; geolocation; microphone; camera; encrypted-media;" sandbox="allow-forms allow-scripts allow-same-origin allow-modals allow-popups"
id="output"></iframe>
</div>
</div>
<a href="https://github.com/oraoto/pib"><img style="z-index: 1;position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<script type="text/javascript" src="php.js"></script>
<script type='text/javascript'>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/github");
editor.session.setMode("ace/mode/php");
editor.setShowPrintMargin(false);
var default_code = "<?php\n\nphpinfo();\n"
var query = new URLSearchParams(document.location.search);
if (query.has('code')) {
editor.setValue(decodeURIComponent(query.get('code')));
} else {
editor.setValue(default_code);
}
var input_area = document.getElementById('input');
var run_button = document.getElementById('run');
var output_area = document.getElementById('output').contentWindow.document;
output_area.open();
var phpModule;
function init() {
output_area.close();
output_area.write("Click RUN");
output_area.close();
run_button.disabled = false
run_button.textContent = "Run"
run_button.addEventListener('click', function () {
output_area.close();
var code = editor.getValue();
var query = new URLSearchParams();
if (code.length < 1024) {
query.append('code', encodeURIComponent(code));
history.replaceState({}, document.title, "?" + query.toString());
}
code = code.replace(/^\s*<\?php/, "") // remove <?php
code = code + "\necho PHP_EOL;" // flush line buffer
let ret = phpModule.ccall('pib_eval', 'number', ["string"], [code])
if (ret != 0) {
output_area.write("Error, please check your code")
}
output_area.close();
});
}
var phpModuleOptions = {
postRun: [init],
print: function (text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(' ');
}
output_area.write(text)
},
printErr: function (text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(' ');
}
output_area.write(text)
}
};
phpModule = PHP(phpModuleOptions);
</script>
</body>
</html>