-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
156 lines (141 loc) · 5.97 KB
/
index.html
File metadata and controls
156 lines (141 loc) · 5.97 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML/CSS/JavaScript在线编辑器</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="https://bornforthis.cn/html_online/plus/img/hcj-editor-favicon.ico"
mce_href="https://bornforthis.cn/html_online/plus/img/hcj-editor-favicon.ico"
type="image/x-icon">
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="//cdn.bootcss.com/codemirror/5.2.0/codemirror.min.js"></script>
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.2.0/codemirror.min.css">
<script src="//cdn.bootcss.com/codemirror/5.2.0/mode/htmlmixed/htmlmixed.min.js"></script>
<script src="//cdn.bootcss.com/codemirror/5.2.0/mode/css/css.min.js"></script>
<script src="//cdn.bootcss.com/codemirror/5.2.0/mode/javascript/javascript.min.js"></script>
<script src="//cdn.bootcss.com/codemirror/5.2.0/mode/xml/xml.min.js"></script>
<script src="//cdn.bootcss.com/codemirror/5.2.0/addon/edit/closetag.min.js"></script>
<script src="//cdn.bootcss.com/codemirror/5.2.0/addon/edit/closebrackets.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="question.css">-->
<link rel="stylesheet" type="text/css" href="https://bornforthis.cn/css/question.css">
<!--[if lt IE 9]>
<script src="//cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
<![endif]-->
</head>
<body>
<h3 class="title">HTML/CSS/JavaScript在线编辑器</h3>
<div class="container">
<div class="row">
<!--源代码编辑-->
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<form class="form-inline">
<div class="row">
<div class="col-xs-6">
<button type="button" class="btn btn-default">源代码:</button>
</div>
<div class="col-xs-6 text-right">
<button type="button" class="btn btn-success" onclick="submitTryit()" id="submitBTN">
<span class="glyphicon glyphicon-send"></span> 提交代码
</button>
</div>
</div>
</form>
</div>
<div class="panel-body">
<textarea class="form-control" id="textareaCode" name="textareaCode">
<p>我叫猎豹。我是一只<strong>萨摩耶</strong>。</p>
</textarea>
</div>
</div>
</div>
<!--运行结果-->
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<form class="form-inline">
<button type="button" class="btn btn-default">运行结果</button>
</form>
</div>
<div class="panel-body">
<div id="iframewrapper"></div>
</div>
</div>
</div>
</div>
</div>
<script>
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{
matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null
},
{
matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"
}]
};
var editor = CodeMirror.fromTextArea(document.getElementById("textareaCode"), {
mode: mixedMode,
selectionPointer: true,
lineNumbers: false,
matchBrackets: true,
indentUnit: 4,
indentWithTabs: true
});
window.addEventListener("resize", autodivheight);
var x = 0;
function autodivheight() {
var winHeight = 0;
if (window.innerHeight) {
winHeight = window.innerHeight;
} else if ((document.body) && (document.body.clientHeight)) {
winHeight = document.body.clientHeight;
}
//通过深入Document内部对body进行检测,获取浏览器窗口高度
if (document.documentElement && document.documentElement.clientHeight) {
winHeight = document.documentElement.clientHeight;
}
height = winHeight * 0.68
editor.setSize('100%', height);
document.getElementById("iframeResult").style.height = height + "px";
}
function submitTryit() {
var text = editor.getValue();
var patternHtml = /<html[^>]*>((.|[\n\r])*)<\/html>/im
var patternHead = /<head[^>]*>((.|[\n\r])*)<\/head>/im
var array_matches_head = patternHead.exec(text);
var patternBody = /<body[^>]*>((.|[\n\r])*)<\/body>/im;
var array_matches_body = patternBody.exec(text);
var basepath_flag = 1;
var basepath = '';
if (basepath_flag) {
// basepath = '<base href="//www.runoob.com/try/demo_source/" target="_blank">';
}
if (array_matches_head) {
text = text.replace('<head>', '<head>' + basepath);
} else if (patternHtml) {
text = text.replace('<html>', '<head>' + basepath + '</head>');
} else if (array_matches_body) {
text = text.replace('<body>', '<body>' + basepath);
} else {
text = basepath + text;
}
var ifr = document.createElement("iframe");
ifr.setAttribute("frameborder", "0");
ifr.setAttribute("id", "iframeResult");
document.getElementById("iframewrapper").innerHTML = "";
document.getElementById("iframewrapper").appendChild(ifr);
var ifrw = (ifr.contentWindow) ? ifr.contentWindow : (ifr.contentDocument.document) ? ifr.contentDocument.document : ifr.contentDocument;
ifrw.document.open();
ifrw.document.write(text);
ifrw.document.close();
autodivheight();
}
submitTryit();
autodivheight();
</script>
</body>
</html>