up
This commit is contained in:
parent
1f61c2ab1d
commit
af0ee2a49e
66 changed files with 12263 additions and 2059 deletions
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<link type="text/css" rel="stylesheet" href="my.css">
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<ul>
|
||||
<li>Click the div to edit.</li>
|
||||
<li>Enter or blur saves the result.</li>
|
||||
</ul>
|
||||
|
||||
HTML is allowed.
|
||||
|
||||
<div id="view" class="view">Text</div>
|
||||
|
||||
<script>
|
||||
let area = null;
|
||||
let view = document.getElementById('view');
|
||||
|
||||
view.onclick = function() {
|
||||
editStart();
|
||||
};
|
||||
|
||||
function editStart() {
|
||||
area = document.createElement('textarea');
|
||||
area.className = 'edit';
|
||||
area.value = view.innerHTML;
|
||||
|
||||
area.onkeydown = function(event) {
|
||||
if (event.key == 'Enter') {
|
||||
this.blur();
|
||||
}
|
||||
};
|
||||
|
||||
area.onblur = function() {
|
||||
editEnd();
|
||||
};
|
||||
|
||||
view.replaceWith(area);
|
||||
area.focus();
|
||||
}
|
||||
|
||||
function editEnd() {
|
||||
view.innerHTML = area.value;
|
||||
area.replaceWith(view);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
.view,
|
||||
.edit {
|
||||
height: 150px;
|
||||
width: 400px;
|
||||
font-family: arial;
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.view {
|
||||
/* padding + border = 3px */
|
||||
padding: 2px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.edit {
|
||||
/* replace padding with border (still 3px not to shift the contents) */
|
||||
border: 3px solid blue;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.edit:focus {
|
||||
outline: none;
|
||||
/* remove focus border in Safari */
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue