Wikipedia para siempre
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 var Ajax = function (url) {2  3  this.query = function (params) {4  var data = '';//'q='+encodeURIComponent(q);5  for (key in params)6  data += key+'='+encodeURIComponent(params[key])+'&';7  ajax.setRequestHeader('Content-length', data.length );8  ajax.send(data);9  }10  11  this.setCallback200 = function (cb) {12  _callback200 = cb;13  }14  15  // constructor:16  17  var _callback200 = null;18  var ajax = null;19  try { // Firefox, Opera 8.0+, Safari20  ajax = new XMLHttpRequest()21  } catch (e) { // Puto y pestilente Internet Explorer22  try {23  ajax = new ActiveXObject("Msxml2.XMLHTTP")24  } catch (e) {25  ajax = new ActiveXObject("Microsoft.XMLHTTP")26  }27  }28  ajax.open('POST', url, true);29  ajax.setRequestHeader('Connection', 'close');30  ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');31  ajax.onreadystatechange = function () {32  if (ajax.readyState == 4) {33  if (ajax.status == 200) {34  if (_callback200!=null)35  _callback200(ajax.responseText);36  }37  }38  }39 }40 41 42 43 44 var AjaxSSH = function (parent) {45 46  this.setParentNode = function (parent) {47  parent.appendChild(dom);48  line.focus();49  }50  51  this.sendCommand = function (command) {52  var result = document.createElement('div');53  result.innerHTML = command;54  workarea.appendChild(result);55  }56 57 58  // Atributos59  var dom = document.createElement('div');60 61  // Constructor62  var clase = this;63 64  // -- creando objetos y sus propiedades:65  var toolbar = document.createElement('div');66  toolbar.innerHTML = 'toolbar';67  toolbar.setAttribute('style', 'position:absolute; height:32px; overflow:hidden; top:0; left:0; right:0;');68  dom.appendChild(toolbar);69  70  71  var workarea = document.createElement('div');72  workarea.innerHTML = 'workarea';73  workarea.setAttribute('style', 'position:absolute; overflow-y:auto; top:32px; left:0; right:0; bottom:20px;');74  dom.appendChild(workarea);75  76  var line = document.createElement('input');77  line.prompt = 'c:\\>';78  //line.value = line.prompt;79  line.command = '';80  line.callback = function(command) {81  if (command == 'upload') {82  var upload = document.createElement('input');83  upload.setAttribute('type', 'file');84  workarea.appendChild(upload);85  return true;86  }87  return false;88  };89  line.clear = function() {this.value = this.prompt;};90  line.setAttribute('style', 'position:absolute; border:none; display:block; width:100%; font-size:inherit; color:inherit; background:none; left:0; right:0; bottom:0px;');91  line.addEventListener('keyup', function(event) {92  if (this.value.length<this.prompt.length) this.value=this.prompt;93  this.command = this.value.substring(this.prompt.length);94  95  if (this.callback != null && this.callback(this.command)==true) 96  this.clear();97  else98  if(event.keyCode==13) {clase.sendCommand(this.command); this.value=this.prompt;}99  100  }, true);101  line.clear();102  dom.appendChild(line);103  104  105  // anexo la interfaz completa al dom:106  if (parent == undefined) parent = null; else this.setParentNode(parent);107 108 }109 110 


Este ShareCode tiene versiones:
  1. var ssh = new AjaxSSH(document.bo... (24/04/2013)
Enlace
El enlace para compartir es: