-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeplayer.js
139 lines (106 loc) · 3.43 KB
/
codeplayer.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
var height = $(window).height();
var heighttext = Math.floor(99 - ((100 * $("#header").height()) / height));
var width = $(window).width();
var widthtext = Math.floor(125 - ((125 * $("header").height()) / width));
var isMobile = false;
var isTablet = false;
if(WURFL.is_mobile)
isMobile = true;
if(WURFL.form_factor == "Tablet")
isTablet = true;
$("#alert").hide();
function focus (editor) {
editor.on("focus", function() {
$(editor.container).css({
"box-shadow":"0 0 5px rgba(81, 203, 238, 1)",
"border":"1px solid rgba(81, 203, 238, 1)"
});
});
editor.on("blur", function() {
$(editor.container).css({
"box-shadow":"",
"border":""
});
});
}
var dom = require("ace/lib/dom");
require("ace/commands/default_commands").commands.push({
name: "Toggle Fullscreen",
bindKey: "F11",
exec: function(editor) {
var fullScreen = dom.toggleCssClass(document.body, "fullScreen");
dom.setCssClass(editor.container, "fullScreen", fullScreen);
editor.setAutoScrollEditorIntoView(!fullScreen);
editor.resize();
}
})
var htmleditor = ace.edit("htmltext", {
mode: "ace/mode/html",
selectionStyle: "text",
theme: "ace/theme/monokai",
showPrintMargin: false,
indentedSoftWrap: true,
animatedScroll: true,
wrap: true,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
autoScrollEditorIntoView: true
});
var jseditor = ace.edit("jstext", {
mode: "ace/mode/javascript",
selectionStyle: "text",
theme: "ace/theme/monokai",
showPrintMargin: false,
indentedSoftWrap: true,
animatedScroll: true,
wrap: true,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
var csseditor = ace.edit("csstext", {
mode: "ace/mode/css",
selectionStyle: "text",
theme: "ace/theme/monokai",
showPrintMargin: false,
indentedSoftWrap: true,
animatedScroll: true,
wrap: true,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
focus(htmleditor);
focus(jseditor);
focus(csseditor);
htmleditor.focus();
function updateOutput() {
$("iframe").contents().find("html").html("<html><head><style type='text/css'>" + csseditor.getValue() + "</style></head><body>" + htmleditor.getValue() + "</body></html>");
document.getElementById("outputpanel").contentWindow.eval(jseditor.getValue());
}
updateOutput();
$(".btn").click(function() {
$(this).button('toggle');
var panelid = $(this).attr("id") + "panel";
$("#" + panelid).toggleClass("hidden");
var numactivepanels = 4 - $(".hidden").length;
if ((isMobile || isTablet) && ($(window).width() < $(window).height())) {
$(".textarea").css("height", (heighttext / numactivepanels) + "vh");
$("#outputpanel").css("height", (heighttext / numactivepanels) + "vh");
}
});
if ((isMobile || isTablet) && ($(window).width() < $(window).height())) {
$(".textarea").css("height", (heighttext / 2) + "vh");
$("#outputpanel").css("height", (heighttext / 2) + "vh");
if ($(window).width() > 991)
$("#alert").show();
} else if ((isMobile || isTablet) && ($(window).width() > $(window).height())) {
$(".textarea").css("height", (widthtext / 2) + "vh");
$("#outputpanel").css("height", (widthtext / 2) + "vh");
}
$("#run").click(function() {
updateOutput();
$("#run").blur();
$("#run").button("toggle");
});