Creo en nosotros. Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 2 var log_panel = null;3 var log_count = 0;4 var log_count_max = 10;5 var sel = null;6 7 window.addEventListener('load', init, true);8 window.addEventListener('mouseup', window_selection, false);9 window.addEventListener('keyup', window_selection, false);10 window.addEventListener('keypress', window_selection, false);11 12 function window_selection(event) {13  //var sel = window.getSelection();14  var s = '';15  for(key in sel)16  s += key + ' = ' + sel[key] + '<br>';17  log(s);18  19  //if (sel.nextSibling != null) sel.nextSibling.style.border = 'solid';20  21  // Pruebas:22  //sel.selectAllChildren();23 }24 25 26 function init() {27  log_panel = document.getElementById('log');28  sel = window.getSelection();29  30  /*31  var p1 = document.getElementById('parte1');32  p1.contentEditable=true;33  p1.addEventListener('keydown', div_editable_keydown, true);34 */35  add_text(document.getElementById('document'));36  37  38 }39 40 var add_text = function(parent) {41  var dom = document.createElement('div');42  var comments = document.createElement('div'); comments.className = 'comments';43  var users1 = document.createElement('div'); users1.style.cssFloat = 'right'; users1.style.fontSize='10px';44  var users2 = document.createElement('div'); users2.innerHTML = 'Editando: fulanita'; users2.style.display = 'inline';45  var users3 = document.createElement('div'); users3.innerHTML = ' + '; users3.style.display = 'inline'; users3.style.color = 'blue';46  users3.addEventListener('click', function() {47  var comment = document.createElement('div');48  comment.className = 'comment';49  comment.innerHTML = 'Su comentario...';50  comment.contentEditable = true;51  comments.appendChild(comment);52  comment.focus();53  }, true);54  var editor = document.createElement('div'); editor.className = 'editor-text';55  dom.appendChild(comments);56  dom.appendChild(users1);57  dom.appendChild(editor);58  users1.appendChild(users2);59  users1.appendChild(users3);60  editor.innerHTML = '';61  editor.style.minHeight = '15px';62 63  editor.addEventListener('keydown', div_editable_keydown, true);64  editor.addEventListener('blur', div_editable_blur, true);65  if(parent.parentNode.nextSibling) {66  parent.parentNode.parentNode.insertBefore(dom, parent.parentNode.nextSibling);67  } else {68  parent.appendChild(parent.parentNode);69  }70  editor.contentEditable=true; 71  editor.focus();72 }73 74 var div_editable_keydown = function(event) {75  if (event.keyCode == 13) {76  event.stopPropagation();77  event.preventDefault();78  add_text(this);79  }80 }81 82 var div_editable_blur = function (event) {83  log('Event change: '+event.target.innerHTML);84 }85 86 87 function log(txt) {88  if (log_count <= 0) {log_count = log_count_max; log_panel.innerHTML = 0;}89  if (log_panel != null) {log_panel.innerHTML = txt+'<br>'+log_panel.innerHTML; log_count--}90 }
Enlace
El enlace para compartir es: