1 2 var log_elem = null;3 var last_part=null;4 var selection= null;5 6 function log (text){7 log_elem.innerHTML = text;8 }9 10 window.addEventListener('load', init, true);11 12 function init() {13 selection = window.getSelection();14 15 log_elem = document.getElementById('log');16 last_part = document.getElementById('p1');17 18 document.getElementById('p1').editable = true;19 document.getElementById('p2').editable = true;20 document.getElementById('p3').editable = true;21 document.getElementById('p4').editable = true;22 23 24 document.getElementById('doc').addEventListener('keydown',click_handler, true);25 }26 27 28 29 function click_handler(event) {30 31 if (event.keyCode>36 && event.keyCode<41) {32 if (selection.anchorNode.parentNode.editable == true) {33 last_editable = selection.anchorNode;//.parentNode;34 log(last_editable.innerHTML);35 }36 } else {37 38 if (selection.anchorNode.parentNode.editable !=true) {39 var range = document.createRange();40 range.selectNode(last_editable);41 42 selection.removeAllRanges();43 44 selection.addRange(range);45 range.collapse(true);46 }47 }48 }
Este ShareCode tiene versiones:
- comentarios aaaa comentario... (24/04/2013)
- comentarios aaaa comentario... (24/04/2013)
- comentarios aaaa comentario... (24/04/2013)
- comentarios aaaa comentario... (24/04/2013)
Enlace
El enlace para compartir es: