mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
b78875e8fd
Change-Id: I485e6f51c4184c557187f1ef104adc11c3ba3950
104 lines
3.1 KiB
HTML
104 lines
3.1 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html>
|
|
<head>
|
|
<title>Cursor</title>
|
|
<style>
|
|
.editor {
|
|
border: 1px solid #369;
|
|
outline: none;
|
|
padding: 5px;
|
|
}
|
|
.alien {
|
|
background: #9F9;
|
|
display: block;
|
|
}
|
|
p .alien {
|
|
display: inline;
|
|
}
|
|
.alien::selection {
|
|
background: #CCC;
|
|
}
|
|
.slug {
|
|
display: block;
|
|
height: 1px;
|
|
width: 1px;
|
|
margin-left: -1px;
|
|
margin-bottom: -1px;
|
|
}
|
|
</style>
|
|
<script src="../../modules/jquery/jquery.js"></script>
|
|
<script src="../../modules/rangy/rangy-core.js"></script>
|
|
</head>
|
|
<body>
|
|
<h1>Test 1</h1>
|
|
<div contenteditable="true" class="editor">
|
|
<span class="slug"></span>
|
|
<p><span contenteditable="false" spellcheck="false" class="alien">⁣Alien⁣</span> and some text</p>
|
|
<div contenteditable="false" spellcheck="false" class="alien"><div>Alien in a div</div></div>
|
|
<span class="slug"></span>
|
|
<div contenteditable="false" spellcheck="false" class="alien"><div>Alien in a div</div></div>
|
|
<p>some text before an <span contenteditable="false" spellcheck="true" class="alien">⁣Alien⁣</span></p>
|
|
<span class="slug"></span>
|
|
</div>
|
|
|
|
<h1>Test 2</h1>
|
|
<div contenteditable="true" class="editor">
|
|
<span class="slug"></span>
|
|
<div contenteditable="false" spellcheck="false" class="alien"><div>Alien in a div</div></div>
|
|
<span class="slug"></span>
|
|
<div contenteditable="false" spellcheck="false" class="alien"><div>Alien in a div</div></div>
|
|
<span class="slug"></span>
|
|
<div contenteditable="false" spellcheck="false" class="alien"><div>Alien in a div</div></div>
|
|
<span class="slug"></span>
|
|
</div>
|
|
<script>
|
|
$('.alien').on('click', function() {
|
|
var range = rangy.createRange();
|
|
range.setStart($(this).prev('.slug')[0], 0);
|
|
rangy.getSelection().addRange(range);
|
|
});
|
|
$('.editor').one('keydown', function(e) {
|
|
var newParagraph = $('<p> </p>');
|
|
$('.editor').eq(1).find('.slug').eq(1).replaceWith(newParagraph);
|
|
|
|
console.log(newParagraph);
|
|
var range = rangy.createRange();
|
|
range.setStart( newParagraph[0], 0 );
|
|
range.setEnd( newParagraph[0], 1 );
|
|
rangy.getSelection().setSingleRange(range);
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
var lastSlug = null;
|
|
setInterval(function() {
|
|
var sel = rangy.getSelection();
|
|
if (!sel.anchorNode) {
|
|
return;
|
|
}
|
|
console.log(sel.anchorNode);
|
|
if ($(sel.anchorNode).hasClass('slug')) {
|
|
lastSlug = sel.anchorNode;
|
|
$(sel.anchorNode).css('height', '1em');
|
|
}
|
|
if (sel.anchorNode != lastSlug) {
|
|
$(lastSlug).css('height', '1px');
|
|
}
|
|
}, 50);
|
|
*/
|
|
</script>
|
|
</body>
|
|
</html>
|