From 33a92e9c93e3946f7b77e93f06437a2ae4c7e595 Mon Sep 17 00:00:00 2001 From: Marc Singer Date: Sat, 31 Mar 2012 18:59:38 -0700 Subject: [PATCH] Issue 39: Clipboard not integrated with client operating system o Patch for html5 drag-and-drop applied. From the poster, Here is a quick proof-of-concept patch against the current SVN head that adds support for dragging and dropping text into a shellinabox session if the browser supports HTML5 drag-and-drop. It has only been tested with shellinabox/demo/demo.html --- shellinabox/vt100.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/shellinabox/vt100.js b/shellinabox/vt100.js index 15af940..8a5b2f8 100644 --- a/shellinabox/vt100.js +++ b/shellinabox/vt100.js @@ -1047,6 +1047,24 @@ VT100.prototype.initializeElements = function(container) { this.addListener(this.scrollable,'mouseup', mouseEvent(this, 1 /* MOUSE_UP */)); this.addListener(this.scrollable,'click', mouseEvent(this, 2 /* MOUSE_CLICK */)); + // Check that browser supports drag and drop + if ('draggable' in document.createElement('span')) { + var dropEvent = function (vt100) { + return function(e) { + if (!e) e = window.event; + if (e.preventDefault) e.preventDefault(); + vt100.keysPressed(e.dataTransfer.getData('Text')); + return false; + }; + }; + // Tell the browser that we *can* drop on this target + this.addListener(this.scrollable, 'dragover', cancel); + this.addListener(this.scrollable, 'dragenter', cancel); + + // Add a listener for the drop event + this.addListener(this.scrollable, 'drop', dropEvent(this)); + } + // Initialize the blank terminal window. this.currentScreen = 0; this.cursorX = 0; @@ -1060,6 +1078,13 @@ VT100.prototype.initializeElements = function(container) { this.input.focus(); }; +function cancel(event) { + if (event.preventDefault) { + event.preventDefault(); + } + return false; +} + VT100.prototype.getChildById = function(parent, id) { var nodeList = parent.all || parent.getElementsByTagName('*'); if (typeof nodeList.namedItem == 'undefined') {