Nuestro conocimiento compartido. Nuestro tesoro compartido. Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 2 var log_panel = null;3 4 window.addEventListener('load', init, true);5 6 7 function init() {8  log_panel = document.getElementById('log');9  10  var p1 = document.getElementById('parte1');11  var p2 = document.getElementById('parte2');12  var p3 = document.getElementById('parte3');13 14  p1.contentEditable=true;15  p2.contentEditable=true;16  p3.contentEditable=true;17  18  19  p1.addEventListener('keydown', div_editable_keydown, true);20  p2.addEventListener('keydown', div_editable_keydown, true);21  p3.addEventListener('keydown', div_editable_keydown, true);22 23  24  25 }26 27 var div_editable_keydown = function(event) {28  if (event.keyCode == 13) {29  var div = document.createElement('div');30  div.innerHTML = '';31  div.style.minHeight = '15px';32  event.stopPropagation();33  event.preventDefault();34  div.addEventListener('keydown', div_editable_keydown, true);35  div.addEventListener('blur', div_editable_blur, true);36  if(this.nextSibling) {37  this.parentNode.insertBefore(div, this.nextSibling);38  } else {39  //this.appendChild(this.parentNode);40  }41  //this.parentNode.insertBefore(div, this.nextSibling);42  div.contentEditable=true; 43  div.focus();44  }45  log('part1 keyup '+event.keyCode);46 }47 48 var div_editable_blur = function (event) {49  log('Event change: '+event.target.innerHTML);50 }51 52 53 function log(txt) {54  if (log_panel != null) log_panel.innerHTML = txt+'<br>'+log_panel.innerHTML;55 }
Enlace
El enlace para compartir es: