test page for copy and paste support

This commit is contained in:
christian 2012-02-07 22:15:04 +00:00
parent 0ced900973
commit 2530451094
Notes: Gabriel Wicke 2012-02-27 16:40:01 +00:00
2 changed files with 47 additions and 0 deletions

16
cut-copy-paste.html Normal file
View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>-----cut-----copy-----paste-----</title>
<script src="modules/jquery/jquery.js"></script>
<script src="contentEditable/rangy/rangy-core.js"></script>
<script src="cut-copy-paste.js"></script>
</head>
<body>
<div id="editor" contenteditable="true">
<p>Here is some text. I dare you to mess with me.</p>
<p>More text here. Don't you dare!</p>
</div>
<div id="paste" contenteditable="true" style="height: 1px; width: 1px; position: absolute; left: -20000px;"></div>
</body>
</html>

31
cut-copy-paste.js Normal file
View file

@ -0,0 +1,31 @@
$(function() {
var paste = {};
$('#editor')
.on('copy', function(event) {
var range = rangy.getSelection().getRangeAt(0);
var key = range.toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
paste = {};
paste[key] = 'some wikidom';
})
.on('paste', function(event) {
$('#paste').html('');
$('#paste').focus();
setTimeout(function() {
var key = $('#paste').text().replace(/( |\r\n|\n|\r|\t)/gm,"");
console.log(paste);
if (paste[key]) {
alert('you pasted from wikidom');
} else {
alert('i don\'t know where you pasted from');
}
}, 1);
});
});