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

ShareCode

1 var MongoString = function() {2  var that = this;3  4  this.dom = document.createElement('div');5  this.dom.setAttribute('contentEditable', true);6  this.dom.setAttribute('component', 'MongoString');7  8  this.load = function(data) {9  that.dom.innerHTML = data; // TODO: change this by contentText10  };11  12 };13 14 var MongoNumber = function() {15  var that = this;16  17  this.dom = document.createElement('div');18  this.dom.setAttribute('contentEditable', true);19  this.dom.setAttribute('component', 'MongoNumber');20  21  this.dom.addEventListener('keyup', function(){22  var sanitized = ""+parseFloat(this.innerHTML);23  if (this.innerHTML != sanitized) {24  this.innerHTML = sanitized;25  console.log("no es un número");26  }27  }, true);28  29  this.load = function(data) {30  that.dom.innerHTML = data; // TODO: change this by contentText31  };32 };33 34 var MongoBoolean = function() {35  var that = this;36  37  this.dom = document.createElement('div');38  this.dom.setAttribute('component', 'MongoBoolean');39 40  this.check = document.createElement('input');41  this.check.setAttribute('type', 'checkbox');42  this.dom.appendChild(this.check);43 44  this.load = function(data) {45  that.check.checked = data;46  };47 };48 49 var MongoId = function() {50  var that = this;51  52  this.dom = document.createElement('div');53  this.dom.setAttribute('component', 'MongoId');54  55  this.load = function(data) {56  that.dom.innerHTML = data; // TODO: change this by contentText57  };58 };59 60 var MongoNull = function() {61  var that = this;62  63  this.dom = document.createElement('div');64  this.dom.setAttribute('component', 'MongoNull');65  this.dom.innerHTML = 'null';66 };67 68 var MongoUndefined = function() {69  var that = this;70  71  this.dom = document.createElement('div');72  this.dom.setAttribute('component', 'MongoUndefined');73  this.dom.innerHTML = 'undefined';74  75  this.load = function(data) {};76 };77 78 var MongoKeyValue = function() {79  var that = this;80  81  var key = '';82  83  this.dom = document.createElement('div');84  this.dom.setAttribute('component', 'MongoKeyValue');85  86  this.key = document.createElement('div');87  this.key.classList.add('key');88  this.dom.appendChild(this.key);89  90  this.value = document.createElement('div');91  this.value.classList.add('value');92  this.dom.appendChild(this.value);93  94  this.setKey = function(k) {95  key = k;96  that.key.innerHTML = k; // TODO user contentText (check spelling)97  };98 };99 100 var MongoArray = function() {101  102  var that = this;103  104  this.items = null;105  106  this.dom = document.createElement('div');107  this.dom.setAttribute('component', 'MongoArray');108  109  this.load = function(data) {110  // TODO: clear this111  for (i in data) { // TODO: change i by key112  var type = typeof data[i];113  if ('_id' == i) {114  type = 'id';115  } else if ('object' == type && data[i] instanceof Array) {116  type = 'array';117  } else if ('object' == type && null === data[i]) {118  type = 'null';119  }120  121  var mkv = new MongoKeyValue();122  mkv.setKey(i);123  124  switch (type) {125  case 'id':126  var mi = new MongoId();127  mi.load(data[i]);128  mkv.value.appendChild(mi.dom);129  break;130  case 'undefined':131  var mu = new MongoUndefined();132  mkv.value.appendChild(mu.dom);133  break;134  case 'null':135  var mn = new MongoNull();136  mkv.value.appendChild(mn.dom);137  break;138  case 'boolean':139  var mb = new MongoBoolean();140  mb.load(data[i]);141  mkv.value.appendChild(mb.dom);142  break;143  case 'string':144  var ms = new MongoString();145  ms.load(data[i]);146  mkv.value.appendChild(ms.dom);147  break;148  case 'number':149  var mn = new MongoNumber();150  mn.load(data[i]);151  mkv.value.appendChild(mn.dom);152  break;153  case 'object':154  var mo = new MongoDocument();155  mo.load(data[i]);156  mkv.value.appendChild(mo.dom);157  break;158  case 'array':159  var ma = new MongoArray();160  ma.load(data[i]);161  mkv.value.appendChild(ma.dom);162  break;163  }164  165  that.dom.appendChild(mkv.dom);166  }167  };168 };169 170 var MongoDocument = function() {171  var that = this;172  173  this.items = null;174  175  this.dom = document.createElement('div');176  this.dom.setAttribute('component', 'MongoDocument');177  178  this.load = function(data) {179  // TODO: clear this180  for (i in data) { // TODO: change i by key181  var type = typeof data[i];182  if ('_id' == i) {183  type = 'id';184  } else if ('object' == type && data[i] instanceof Array) {185  type = 'array';186  } else if ('object' == type && null === data[i]) {187  type = 'null';188  }189  190  var mkv = new MongoKeyValue();191  mkv.setKey(i);192  193  switch (type) {194  case 'id':195  var mi = new MongoId();196  mi.load(data[i]);197  mkv.value.appendChild(mi.dom);198  break;199  case 'undefined':200  var mu = new MongoUndefined();201  mkv.value.appendChild(mu.dom);202  break;203  case 'null':204  var mn = new MongoNull();205  mkv.value.appendChild(mn.dom);206  break;207  case 'boolean':208  var mb = new MongoBoolean();209  mb.load(data[i]);210  mkv.value.appendChild(mb.dom);211  break;212  case 'string':213  var ms = new MongoString();214  ms.load(data[i]);215  mkv.value.appendChild(ms.dom);216  break;217  case 'number':218  var mn = new MongoNumber();219  mn.load(data[i]);220  mkv.value.appendChild(mn.dom);221  break;222  case 'object':223  var mo = new MongoDocument();224  mo.load(data[i]);225  mkv.value.appendChild(mo.dom);226  break;227  case 'array':228  var ma = new MongoArray();229  ma.load(data[i]);230  mkv.value.appendChild(ma.dom);231  break;232  }233  234  that.dom.appendChild(mkv.dom);235  }236  };237 };238 239 var MongoCollection = function() {240  241  var that = this;242  243  this.documents = [];244  245  this.dom = document.createElement('div');246  this.dom.setAttribute('component', 'MongoCollection');247  248  this.SetData = function(data) {249  // TODO: destroy all items250  for (i in data) {251  var d = data[i];252  var item = new MongoDocument();253  item.load(d);254  that.dom.appendChild(item.dom);255  }256  };257  258 };
Enlace
El enlace para compartir es: