forked from ajaxorg/ace-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrollable-page.html
152 lines (133 loc) · 3.83 KB
/
scrollable-page.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Editor</title>
<style type="text/css" media="screen">
.ace_editor {
position: relative !important;
border: 1px solid lightgray;
margin: auto;
height: 200px;
width: 80%;
}
.ace_editor.fullScreen {
height: auto;
width: auto;
border: 0;
margin: 0;
position: fixed !important;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
background: white;
}
.fullScreen {
overflow: hidden
}
.scrollmargin {
height: 500px;
text-align: center;
}
.large-button {
color: lightblue;
cursor: pointer;
font: 30px arial;
padding: 20px;
text-align: center;
border: medium solid transparent;
display: inline-block;
}
.large-button:hover {
border: medium solid lightgray;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 12px 0 lightblue;
}
</style>
</head>
<body>
<div class="scrollmargin">
<span onclick="scroll()" class="large-button">
scroll down ⇓
</span>
</div>
<pre id="editor">function foo(items) {
var i;
for (i = 0; i < items.length; i++) {
alert("Ace Rocks " + items[i]);
}
}</pre>
<div class="scrollmargin">
<div style="padding:20px">
press F11 to switch to fullscreen mode
</div>
<span onclick="add()" class="large-button" title="Shift+Enter">+</span>
</div>
<script src="./src/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var $ = document.getElementById.bind(document);
var dom = require("ace/lib/dom");
//add command to all new editor instaces
require("ace/commands/default_commands").commands.push({
name: "Toggle Fullscreen",
bindKey: "F11",
exec: function(editor) {
dom.toggleCssClass(document.body, "fullScreen")
dom.toggleCssClass(editor.container, "fullScreen")
editor.resize()
}
}, {
name: "add",
bindKey: "Shift-Return",
exec: add
})
// create first editor
var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
editor.session.setMode("ace/mode/javascript");
var count = 1;
function add() {
var oldEl = editor.container
var pad = document.createElement("div")
pad.style.padding = "40px"
oldEl.parentNode.insertBefore(pad, oldEl.nextSibling)
var el = document.createElement("div")
oldEl.parentNode.insertBefore(el, pad.nextSibling)
count++
var theme = "ace/theme/" + themes[Math.floor(themes.length * Math.random() - 1e-5)]
editor = ace.edit(el)
editor.setTheme(theme)
editor.session.setMode("ace/mode/javascript")
editor.setValue([
"this is editor number: ", count, "\n",
"using theme \"", theme, "\"\n",
":)"
].join(""), -1)
scroll()
}
function scroll(speed) {
var top = editor.container.getBoundingClientRect().top
speed = speed || 10
if (top > 60 && speed < 500) {
if (speed > top - speed - 50)
speed = top - speed - 50
else
setTimeout(scroll, 10, speed + 10)
window.scrollBy(0, speed)
}
}
var themes = {
bright: [ "chrome", "clouds", "crimson_editor", "dawn", "dreamweaver", "eclipse", "github",
"solarized_light", "textmate", "tomorrow"],
dark: [ "clouds_midnight", "cobalt", "idle_fingers", "kr_theme", "merbivore", "merbivore_soft",
"mono_industrial", "monokai", "pastel_on_dark", "solarized_dark", "tomorrow_night",
"tomorrow_night_blue", "tomorrow_night_bright", "tomorrow_night_eighties", "twilight", "vibrant_ink"]
}
themes = [].concat(themes.bright, themes.dark)
setTimeout(function(){ window.scrollTo(0,0) }, 10)
</script>
</body>
</html>