-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode-area.js
44 lines (43 loc) · 1.61 KB
/
code-area.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
$(function () {
$.widget("earthserver.codeArea", {
options: {
content: undefined
},
_create: function () {
this.element.attr("id", "code-area");
this.mobile = this._isMobile();
if (!this.mobile) {
this.codeArea = CodeMirror.fromTextArea(document.getElementById("code-area"), {
lineNumbers: true,
lineWrapping: true,
scrollbarStyle: "simple",
styleActiveLine: true,
placeholder: "Insert WCPS Query here..."
});
} else {
this.codeArea = this.element;
this.codeArea.attr({placeholder: "Insert WCPS Query here..."});
}
if (this.options.content != undefined) {
this.setValue(this.options.content);
}
},
getValue: function() {
return this.mobile ? this.codeArea.val() : this.codeArea.getValue().replace(/\n/g, " ").replace(/\s\s+/g, " ");
},
setValue: function(content) {
this.mobile ? this.codeArea.val(content) : this.codeArea.setValue(content);
},
reset: function() {
if (this.mobile) {
this.codeArea.val("");
} else {
this.codeArea.setValue("");
this.codeArea.clearHistory();
}
},
_isMobile: function() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
}
})
});