forked from vectorsize/substance-text
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.html
76 lines (69 loc) · 2.21 KB
/
editor.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
<!DOCTYPE html>
<html>
<head>
<title>Rich Text Editor</title>
<!-- Meta tags-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<!-- Styles -->
<link href="page.css" media="screen" rel="stylesheet" type="text/css" />
<link href="proper.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Libraries -->
<script src="jquery-min.js"></script>
<script src="jquery.hotkeys.js"></script>
<script src="underscore.js"></script>
<!-- Source -->
<script src="proper.js"></script>
<script>
// Proper Init
$(function() {
window.editor = new Proper();
editor.activate($('#content'), {
});
$('#tools a.command').click(function(e) {
e.preventDefault();
window.editor.exec($(e.currentTarget).data('command'));
window.editor.updateCommandState();
});
});
//window.location = 'http://localhost:8001'
// Utility
function escape( content ) {
content = $(content).map(function( index, e ) {
if($(e).get(0).tagName.toLowerCase() == "p")
return e.innerHTML + "<br>";
else
return e.outerHTML;
});
content = content.toArray().join("");
content = content.replace(/<br>(<br>)+/, "<br>");
content = content.replace(/<br>$/, "");
return content;
}
function getContent() {
return escape(window.editor.content());
}
function setContent(content) {
var content_div = $('#content');
content_div.html(content || '');
if($.trim(content).length === 0) {
content_div.addClass('empty');
}
else {
content_div.removeClass('empty');
}
}
</script>
</head>
<body>
<div id="tools">
<a href="#" class="command strong" data-command="strong">B</a>
<a href="#" class="command em" data-command="em">E</a>
<a href="#" class="command ul" data-command="ul">U</a>
<a href="#" class="command ol" data-command="ol">O</a>
<a href="#" class="command internalLink" data-command="internalLink">L</a>
</div>
<div id="content"></div>
</body>
</html>