Sha256: 4dcbdae1eb86ce9eb03e4ac2a4758c36d6e0b1e803c4a994f6faec0423594b32

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

var error_log = function(data){
  log("<span class='error'>" + data + '</div>')
}

var log = function(data){
  var new_element = document.createElement('div');
  new_element.innerHTML = data;
  document.getElementById('log_output').appendChild(new_element);
};

var clear_log = function(){
  document.getElementById('log_output').innerHTML='';
}


/*
 * To avoid any kind of name conflict I am renaming trim to javascript_lab_trim
 * http://developer.loftdigital.com/blog/trim-a-string-in-javascript
 */
String.prototype.javascript_lab_trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


var processForm = function(){
  try {
  var javascript_code = document.lab.javascript_code.value.javascript_lab_trim();
  eval(javascript_code);
  }catch(e){
    var error_text = 'Error: '+ e.name + ' ' + e.message;
    error_log(error_text);
  }

  return false;
};

var verifyJsonForm = function(){
  clear_log();
  try {
   var json_input = document.lab.json_input.value.javascript_lab_trim();
   var json_encoded = $.evalJSON(json_input); 
   error_log('Valid JSON'); 
  }catch(e){
    var error_text = 'Error: ' + e.name + ' ' + e.message;
    error_log(error_text);
  }
  return false;
};

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
neerajdotname-javascript_lab-0.0.11 public/javascripts/app.js
neerajdotname-javascript_lab-0.0.12 public/javascripts/app.js
neerajdotname-javascript_lab-0.0.13 public/javascripts/app.js
neerajdotname-javascript_lab-0.0.14 public/javascripts/app.js
neerajdotname-javascript_lab-0.0.15 public/javascripts/app.js