Wikipedia para siempre
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  p1.contentEditable=true;12  p1.addEventListener('keydown', div_editable_keydown, true);13 14 15  16  17 }18 19 var div_editable_keydown = function(event) {20  if (event.keyCode == 13) {21  var dom = document.createElement('div');22  var comments = document.createElement('div'); comments.className = 'comments';23  var users1 = document.createElement('div'); users1.style.cssFloat = 'right'; users1.style.fontSize='10px';24  var users2 = document.createElement('div'); users2.innerHTML = 'Editando: fulanita'; users2.style.display = 'inline';25  var users3 = document.createElement('div'); users3.innerHTML = ' + '; users3.style.display = 'inline'; users3.style.color = 'blue';26  users3.addEventListener('click', function() {27  var comment = document.createElement('div');28  comment.className = 'comment';29  comment.innerHTML = 'Su comentario...';30  comment.contentEditable = true;31  comments.appendChild(comment);32  comment.focus();33  }, true);34  var editor = document.createElement('div'); editor.className = 'editor-text';35  dom.appendChild(comments);36  dom.appendChild(users1);37  dom.appendChild(editor);38  users1.appendChild(users2);39  users1.appendChild(users3);40  editor.innerHTML = '';41  editor.style.minHeight = '15px';42  event.stopPropagation();43  event.preventDefault();44  editor.addEventListener('keydown', div_editable_keydown, true);45  editor.addEventListener('blur', div_editable_blur, true);46  if(this.parentNode.nextSibling) {47  this.parentNode.parentNode.insertBefore(dom, this.parentNode.nextSibling);48  } else {49  this.appendChild(this.parentNode);50  }51  //this.parentNode.insertBefore(div, this.nextSibling);52  editor.contentEditable=true; 53  editor.focus();54  }55 }56 57 var div_editable_blur = function (event) {58  log('Event change: '+event.target.innerHTML);59 }60 61 62 function log(txt) {63  if (log_panel != null) log_panel.innerHTML = txt+'<br>'+log_panel.innerHTML;64 }
Enlace
El enlace para compartir es: