Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Concatinate multiple textareas live." />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <input id="currentFrame" value="234">
  <button id="addFrameBtn">Add Frame Note</button><br>
  <div id="notesContainer"></div>
  <div id="render"></div>
</body>
</html>
 
body {
  font-family: Helvetica Neue, Helvetica, sans-serif;
}
textarea {
  height: 40px;
  display: none;
}
#render {
  width: 300px;
  background: #eee;
  color: #444;
}
.noteRender{
  padding: 0px;
  position: relative;
  border-top:1px solid #fff;
  cursor: pointer;
}
.noteRender:hover{
  background: #FFFDD2;
}
.noteContentRender:focus{
  background: #FFFA88;
}
.noteLabelRender{
  color: #ccc;
  padding: 2px 5px;
  background: #fff;
  font-size: 9pt;
  text-align: center;
  position: absolute;
  top: 6px;
  right: 6px;
  border-radius: 6px;
  height: 2em;
  min-width: 2em;
  line-height: 2em;
}
.noteContentRender{
  color: #aaa;
  font-size: 9pt;
  line-height: 1.5em;
  padding: 10px;
}
 
var renderArea = document.getElementById('render');
var button1 = document.getElementById('addFrameBtn');
var input1 = document.getElementById('currentFrame');
var notes;
var data = [];
var refresh = function (){
  var result = "",
      frange,
      content,
      i;
  
  // Empty Array
  data = [];
  
  for(i=0;i<notes.length; i++) {
    frange = notes[i].getAttribute('data-frange');
    content = notes[i].value;   
    data.push({f:frange, c:content});
  }
  render();
};
var addNote = function(e){
  var attr = input1.value;
  var n = document.createElement('textarea');
  var p = document.getElementById('notesContainer');
  removeNoteListeners();
  n.className = 'note';
  n.setAttribute('data-frange', attr);
  p.appendChild(n);
  addNoteListeners();
  refresh();
};
var refreshNotesArray = function(){
  console.log("refresh");
  notes = document.getElementsByClassName('note');
};
var removeNoteListeners = function(){
  var note,i;
  for(i=0; i<notes.length; i++){
    note = notes[i];
    note.removeEventListener('keyup', refresh );
  }
};
var addNoteListeners = function(){
  var note,i;
  refreshNotesArray();
  for(i=0; i<notes.length; i++){
    note = notes[i];
    note.addEventListener('keyup', refresh, false );
  }
};
var focus = function(i){
  console.log(i);
  notes[i].focus();
};
var syncDiv2Textarea = function(div, i){
  var content = div.innerHTML;
  notes[i].value = content;
};
var render = function(){
  var arr = data;
  
  // Clear Contents
  while (renderArea.firstChild) {
    renderArea.removeChild(renderArea.firstChild);
  }
  
  //Build Divs
  for (i=0; i<arr.length; i++){
    str = "";
    if(arr[i]){
      if(arr[i].f) str = str + arr[i].f;
      //if(arr[i].f) str = str + "-" + arr[i].f;
      var div = document.createElement('div');
      var label = document.createElement('span');
      var content = document.createElement('div');
     
      label.innerHTML = str;
      content.innerHTML = arr[i].c;
      
      div.className = "noteRender";
      label.className= "noteLabelRender";
      content.className = "noteContentRender";
      
      div.appendChild(label);
      div.appendChild(content);
      renderArea.appendChild(div);
      
      content.contentEditable = true;
      
      (function(content, i, str) {
          content.addEventListener("keyup", function(e) {syncDiv2Textarea(content, i);});
          content.addEventListener("focus", function(e) {console.log(str);});
      })(content, i, str);   
    }
  }
  return;
};
var init = function() {
  button1.addEventListener('click', addNote );
  addNoteListeners();
  refresh();
};
init();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
erikssssspro
0viewers