-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
176 lines (153 loc) · 6.51 KB
/
index.html
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
169
170
171
172
173
174
175
176
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<title>StepBack Playground</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,400&display=swap" rel="stylesheet">
<script type="application/javascript" src="https://unpkg.com/codeflask/build/codeflask.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.5.11/split.min.js"></script>
<link href="style.css" rel="stylesheet">
<link href="runBtn.css" rel="stylesheet">
</head>
<body>
<div class="header">
<div class='logo'> </div><div class="title">Playground</div>
<div id="examplesBtn" class="inline">
<span>Examples ▼</span>
<div class="dropdown">
<span>Examples ◢</span>
<hr/>
<a href="#application">Application</a>
<a href="#fitlayout">Fit layout</a>
<a href="#basic">Basic example</a>
<a href="#vsplitlayout">VSplit layout</a>
</div>
</div>
</div>
<div class='editor'>
<div id='editorWrapper'>
<input id='htmlinput' type="hidden" />
<div class="editorSplitWrapper">
<div id="editorPanelJS" class="editorPanel"></div>
<div id="editorPanelCSS" class="editorPanel"></div>
</div>
<div id="editorActions" class="editorPanel">
<div id="runProgress">
<div class="waiting-message">Change code to autorun....</div>
<div class="progress-message">Autorun in progress...</div>
<div class="progress-bar"></div>
</div>
<button id="runBtn" class="bubbly-button">Run</button>
</div>
</div>
<iframe id="resultPanel">
</iframe>
</div>
</body>
<script>
var getHtmlHeader = function (styles) { return `
<head>
<link href=\'../dist/sb.css\' rel=\'stylesheet' \/>
<script src=\'../dist/sb.js\' type=\'text/javascript\'><\/script>
<style>
${styles}
<\/style>
<\/head>`};
var flaskJS = new CodeFlask('#editorPanelJS', { language: 'js', lineNumbers: true });
var flaskCSS = new CodeFlask('#editorPanelCSS', { language: 'css', lineNumbers: true });
var htmlInput = document.getElementById('htmlinput');
htmlInput.value = '<div id=\"app\"><\/div>';
var pauseFlaskUpdates = false;
function renderCode() {
var codeJS = flaskJS.getCode();
var codeCSS = flaskCSS.getCode();
var frameDoc = document.getElementById('resultPanel').contentWindow.document;
frameDoc.open();
frameDoc.write(`
${getHtmlHeader(codeCSS)}
<body>
${htmlInput.value}
<\/body>
<script type=\"application/javascript\">
${codeJS}
<\/script>`
);
frameDoc.close();
}
document.getElementById('runBtn').onclick = renderCode;
// Firefox does not support calc on flexbox, this hack fixes issue
function windowResize() {
document.querySelector('.editor').style.height = window.innerHeight - 70;
}
window.addEventListener('resize', windowResize);
windowResize();
Split(['#editorWrapper', '#resultPanel'], {
sizes: [45, 55],
gutterSize: 10
});
Split(['#editorPanelJS', '#editorPanelCSS'], {
sizes: [50, 50],
direction: 'vertical',
minSize: 135,
gutterSize: 10,
});
var animateButton = function(e) {
e.preventDefault;
//reset animation
e.target.classList.remove('animate');
e.target.classList.add('animate');
setTimeout(function(){
e.target.classList.remove('animate');
},700);
};
var bubblyButtons = document.getElementsByClassName("bubbly-button");
for (var i = 0; i < bubblyButtons.length; i++) {
bubblyButtons[i].addEventListener('click', animateButton, false);
}
if(window.location.hash) {
loadExample(window.location.hash.substring(1,window.location.hash.length))
}
window.addEventListener('hashchange', function() {
loadExample(window.location.hash.substring(1,window.location.hash.length))
});
function loadExample(name) {
Promise.all([
fetch(`./examples/${name}/index.html`),
fetch(`./examples/${name}/script.js`),
fetch(`./examples/${name}/styles.css`)
]).then(async function (responses) {
var html = await responses[0].text();
var script = await responses[1].text();
var styles = await responses[2].text();
pauseFlaskUpdates = true;
htmlInput.value = html;
flaskJS.updateCode(script);
flaskCSS.updateCode(styles);
renderCode();
setTimeout(function () {
pauseFlaskUpdates = false;
}, 300);
})
}
// bind events after one seconds because for some reason flask is firing few events on initialize
setTimeout(function (){
flaskJS.onUpdate(runDelay);
flaskCSS.onUpdate(runDelay);
},1000);
var RUN_DELAY = 2000;
var progressInterval = null;
function runDelay(code) {
if (pauseFlaskUpdates) return;
var progress = 0;
clearInterval(progressInterval);
progressInterval = setInterval(function () {
progress++;
if (progress > 99) {
progress = 0;
clearInterval(progressInterval);
document.getElementById('runBtn').click();
}
document.querySelector('#runProgress .progress-bar').style.width = progress+"%";
}, RUN_DELAY/100);
}
</script>
</html>