function handleMessage(message_event) {
  var msg = message_event.data;
  var command = msg[0];
  var args = msg.slice(1);

  if (command == 'ERR') {
    common.logMessage('Error: ' + args[0]);
  } else if (command == 'STAT') {
    common.logMessage(args[0]);
  } else if (command == 'READY') {
    common.logMessage('Filesystem ready!');
  } else if (command == 'DISP') {
    // Find the file editor that is currently visible.
    var fileEditorEl =
        document.querySelector('.function:not([hidden]) > textarea');
    // Rejoin args with pipe (|) -- there is only one argument, and it can
    // contain the pipe character.
    fileEditorEl.value = args.join('|');
  } else if (command == 'LIST') {
    var listDirOutputEl = document.getElementById('listDirOutput');

    // NOTE: files with | in their names will be incorrectly split. Fixing this
    // is left as an exercise for the reader.

    // Remove all children of this element...
    while (listDirOutputEl.firstChild) {
      listDirOutputEl.removeChild(listDirOutputEl.firstChild);
    }

    if (args.length) {
      // Add new <li> elements for each file.
      for (var i = 0; i < args.length; ++i) {
        var itemEl = document.createElement('li');
        itemEl.textContent = args[i];
        listDirOutputEl.appendChild(itemEl);
      }
    } else {
      var itemEl = document.createElement('li');
      itemEl.textContent = '<empty directory>';
      listDirOutputEl.appendChild(itemEl);
    }
  }
}
// Called by the common.js module.
Called by the common.js module.
Called by the common . js module .
function handleMessage(message_event) {
  var msg = message_event.data;
  var command = msg[0];
  var args = msg.slice(1);
  if (command == 'ERR') {
    common.logMessage('Error: ' + args[0]);
  } else if (command == 'STAT') {
    common.logMessage(args[0]);
  } else if (command == 'READY') {
    common.logMessage('Filesystem ready!');
  } else if (command == 'DISP') {
    var fileEditorEl =
        document.querySelector('.function:not([hidden]) > textarea');
    fileEditorEl.value = args.join('|');
  } else if (command == 'LIST') {
    var listDirOutputEl = document.getElementById('listDirOutput');
    while (listDirOutputEl.firstChild) {
      listDirOutputEl.removeChild(listDirOutputEl.firstChild);
    }
    if (args.length) {
      for (var i = 0; i < args.length; ++i) {
        var itemEl = document.createElement('li');
        itemEl.textContent = args[i];
        listDirOutputEl.appendChild(itemEl);
      }
    } else {
      var itemEl = document.createElement('li');
      itemEl.textContent = '<empty directory>';
      listDirOutputEl.appendChild(itemEl);
    }
  }
}
function handleMessage ( message_event ) { var msg = message_event . data ; var command = msg [ 0 ] ; var args = msg . slice ( 1 ) ; if ( command == 'ERR' ) { common . logMessage ( 'Error: ' + args [ 0 ] ) ; } else if ( command == 'STAT' ) { common . logMessage ( args [ 0 ] ) ; } else if ( command == 'READY' ) { common . logMessage ( 'Filesystem ready!' ) ; } else if ( command == 'DISP' ) { var fileEditorEl = document . querySelector ( '.function:not([hidden]) > textarea' ) ; fileEditorEl . value = args . join ( '|' ) ; } else if ( command == 'LIST' ) { var listDirOutputEl = document . getElementById ( 'listDirOutput' ) ; while ( listDirOutputEl . firstChild ) { listDirOutputEl . removeChild ( listDirOutputEl . firstChild ) ; } if ( args . length ) { for ( var i = 0 ; i < args . length ; ++ i ) { var itemEl = document . createElement ( 'li' ) ; itemEl . textContent = args [ i ] ; listDirOutputEl . appendChild ( itemEl ) ; } } else { var itemEl = document . createElement ( 'li' ) ; itemEl . textContent = '<empty directory>' ; listDirOutputEl . appendChild ( itemEl ) ; } } }
Called by the common.js module.
Called by the common . js module .
// Find the file editor that is currently visible. // Rejoin args with pipe (|) -- there is only one argument, and it can // contain the pipe character. // NOTE: files with | in their names will be incorrectly split. Fixing this // is left as an exercise for the reader. // Remove all children of this element... // Add new <li> elements for each file.