-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
108 lines (92 loc) · 2.8 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WYSIWYG</title>
<meta name="author" content="Adam Sanderson">
<link rel="stylesheet" href="build/build.css" type="text/css" media="screen" charset="utf-8">
<style type="text/css" media="screen">
body {
padding: 20px;
font-family: sans-serif;
background: white;
}
footer {
position: fixed;
bottom: 20px;
background: white;
}
button {
border: 1px solid #ccc;
background: #eee;
border-radius: 2px;
box-shadow: 1px 1px 2px #ddd;
}
button:hover {
background: #ffe;
}
button.active {
background: #fcffa2;
}
</style>
</head>
<body>
<h1>WYSIWYG</h1>
<div id='toolbar'>
</div>
<div contenteditable="true" id='content'>
<p>
This is a <i>demo</i> of the WYSIWYG commands.
Select some of this text and try the commands out.
</p>
<p>
<em><b>Note:</b> this is not a full editor.</em> WYSIWYG provides tools for writing an html editor.
</p>
</div>
<footer>
See the <a href='https://github.com/adamsanderson/wysiwyg/'>GitHub repository</a> for more information.
</footer>
<script src="build/build.js" type="text/javascript" charset="utf-8"></script>
<script>
var wysiwyg = require('wysiwyg');
var events = require('component-event');
var toolbar = document.getElementById('toolbar');
var content = document.getElementById('content');
var ignore = {html: true, img: true};
for (var name in wysiwyg.commands){
if (!ignore[name]){
toolbar.appendChild(makeCommandButton(name));
}
}
function makeCommandButton(name){
var command = wysiwyg.commands[name];
var checkState = wysiwyg.state[name];
var button = document.createElement("button");
button.setAttribute("name", name);
if (button.textContent === ""){
button.textContent = name;
} else {
button.innerText = name;
}
events.bind(button, "click", function(){
command();
content.focus();
if (checkState) updateState();
});
if (checkState){
events.bind(content, "keyup", updateState);
events.bind(content, "mouseup", updateState);
}
var timer = null;
var timeout = 100;
function updateState(){
clearTimeout(timer);
timer = setTimeout(function(){
button.setAttribute("class", checkState() ? "active" : "");
},timeout);
}
return button;
}
</script>
</body>
</html>