-
Notifications
You must be signed in to change notification settings - Fork 6
/
mini5.html
353 lines (297 loc) · 7.88 KB
/
mini5.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<style>
/* set the padding here to match with the size of the top and right
sidebars */
body{
padding-top:120px;
padding-left:100px;
padding-right:320px;
}
div.buttons {
border:1px dotted red;}
p {text-align:justify}
div#header{
background-color:#aabbcc;
position:fixed;
padding-left:10px;
top:0;
left:0;
width:500%;
height:50px; /* so padding-left:70px */
}
div#right-sidebar{
background-color:#bbccee;
position:fixed;
padding-left:20px;
padding-right:10px;
top:50px;
right:0;
width:250px; /* so padding-right in body:270px */
height:100%;
}
div.research {
margin: 1em;
display:block;
background-color: orange;
border-style: solid;
border-width: 1px;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-color: #CDE;
padding: 0.5em;
overflow: auto;
}
div.french {
margin: 1em;
display:block;
background-color: grey;
border-style: solid;
border-width: 1px;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-color: #CDE;
padding: 0.5em;
overflow: auto;
}
div.swedish {
margin: 1em;
display:block;
background-color: #ffaaee;
border-style: solid;
border-width: 1px;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-color: #CDE;
padding: 0.5em;
overflow: auto;
}
pre {
margin: 1em;
font-weight: bold;
background-color: #FED;
border-style: solid;
border-width: 1px;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-color: #48C;
padding: 0.5em;
font-size: 120%;
overflow: auto;
}
h2, div.header {
background: blue;
color: white;
font-size: 100%;
font-weight: bold;
margin: 0.7em 0 0.1em 0;
padding: .25em 1em .25em 1em;
-webkit-border-radius: .7em;
-moz-border-radius: 1em;
}
h3 {
background: yellow;
color: black;
font-size: 100%;
font-weight: bold;
margin: 0.7em 0 0.1em 0;
padding: .25em 1em .25em 1em;
-webkit-border-radius: .7em;
-moz-border-radius: 1em;
}
* html body{
overflow:hidden;
}
* html div.content{
height:100%;
overflow:auto;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script>
var editing;
var c;
var guid;
function setup()
{
c=$("#content");
var bbar = $("<div class='buttons'>Regular buttons<br></div>");
$("#buttons").append(bbar);
add_regular_button(bbar, "Clone", function(){clone()});
add_regular_button(bbar, "toggle research",
function(){toggle_class(".research")});
add_regular_button(bbar, "toggle edit",
function(){toggle_edit()});
var editButtons = $("<div id='editButtons' class='buttons'>Edit buttons<br></div>");
$("#buttons").append(editButtons);
add_regular_button(editButtons, "save", function(){save_edit()});
add_edit_button(editButtons, "Q", "insertHTML", "“quotes”");
add_edit_button(editButtons, "I", "italic", null);
add_edit_button(editButtons, "S", "strikethrough", null);
add_edit_button(editButtons, "B", "bold", null);
add_edit_button(editButtons, "ol", "insertHTML", "<ol><li>one</ol>\n");
add_edit_button(editButtons, "ul", "insertHTML", "<ul><li>one</ul>\n");
add_edit_button(editButtons, "pre", "insertHTML", "<pre></pre>");
add_edit_button(editButtons, "h2", "insertHTML", "<h2>H2</h2>");
add_edit_button(editButtons, "h1", "insertHTML", "<h1>H</h1>");
add_edit_button(editButtons, "p", "insertHTML", "<p>para</p>");
add_edit_button(editButtons, "todo", "insertHTML",
"<h3>To Do</h3><ul><li>one</li>");
add_edit_button(editButtons, "image", "insertHTML",
"<center><img onclick='cimage(1);' width='200' src='p2.jpg'/></center>");
add_regular_button(editButtons, "add research",
function(){add_div("research")});
entry = $("<input id='#input'></input>");
editButtons.append(entry);
var versions = $("<div id='versions' class='buttons'>versions<br></div>");
$("#buttons").append(versions);
// load_versions("2009_06_25d");
// Not yet ...
set_edit_off();
}
function cimage(x)
{
alert(x);
alert($(this));
$(this).hide();
}
function save_edit()
{
// send data back to the server
val = $("#content").html();
$.get("save_content",
{id:guid, value:val}, function(x){done_save(x)}, 'json');
}
function load_content(g)
{
$.get("load_content", {id:g}, function(x){done_load(x)}, 'json');
}
function done_save(x)
{
done_load(x);
$("#versions").html(x.versions);
}
function done_load(x)
{
$("#header").html("guid=" + x.guid + " last modified=" + x.mod
+ " editable=" + x.edit);
guid = x.guid;
$("#content").html(x.val);
switch(x.edit){
case true:
set_edit_on();
break;
case false:
set_edit_off();
break;
};
}
function toggle_edit()
{
switch(editing){
case true:
set_edit_off();
break;
case false:
set_edit_on();
break;
};
}
function load_content_old(type, G)
{
// alert("load content type=" + type + " guid=" + G);
// $("#header").html("Guid=" + G);
$("#content").load("load_content",{id:G});
guid=G;
switch(type){
case "edit":
set_edit_on();
break;
case "lock":
set_edit_off();
break;
default:
alert("????????");
};}
function load_versions(Guid)
{
// load the toolbar with versions ...
$("#versions").load("get_versions",
{"id":Guid});
}
function toggle_class(x)
{
$(x).toggle();
}
function set_edit_off()
{
c.get(0).contentEditable = false;
c.css({background:"white"});
editing=false;
$("#header").html("<h2>This document cannot be edited</h2>");
$("#editButtons").hide();
}
function set_edit_on()
{
c.get(0).contentEditable = true;
c.css({background:"#eeeeee"});
editing=true;
$("#header").html("<h2>You can now edit this document - but you can't save the results</h2>");
$("#editButtons").show();
}
function add_regular_button(x, text, callback)
{
var button = $("<button>" + text + "</button>").
click(callback);
x.append(button);
}
function add_div(x)
{
var y = "." + x;
$(x).show();
document.execCommand("insertHTML",
false,
"<div class='" + x +"'>Add " + x + "here</div>");
}
function add_edit_button(x, text, cmd, val)
{
var button = $("<button>" + text + "</button>").
click(function(){
document.execCommand(cmd, false, val);
});
x.append(button);
}
$(document).ready(function(){setup()});
</script>
<body>
<div id="header">
</div>
<div id="right-sidebar">
<b>Buttons</b><br>
<div id="buttons">
</div>
</div>
<div id="content">
<h2>Mini editor (Part 5)</h2>
<p>This is part five of a seven part series on how to make a
WYSIWYG structure editor using javascript, jquery, erlang and couchDB.
</p>
<ul>
<li><a href="mini1.html">Part1 - toggling content editable</a></li>
<li><a href="mini2.html">Part2 - Adding some style</a></li>
<li><a href="mini3.html">Part3 - Adding editing buttons</a></li>
<li><a href="mini4.html">Part4 - A seamless structure editor</a></li>
<li><a href="mini5.html">Part5 - All the buttons</a></li>
<li><a href="mini6.html">Part6 - Storing the results forever</a></li>
<li><a href="mini7.html">Part7 - Integration with couchdb</a></li>
</ul>
<h2>All the buttons</h2>
<p>Now I've added a load of buttons to the editor. They appear
when you toggle the editing mode.</p>
<div class="research">
<p>And I've added research. Research is not normally visible.
There's a button to add new research (in edit mode) and a button
to view research (in no editing mode).</p>
<p>Hit the <b>toggle research</b> button to hide this button.</p>
</div>
</div>
</body>