diff --git a/ChangeLog b/ChangeLog index 886510d22..ee82a47b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-11-08 Wolfgang Sourdeau + * UI/WebServerResources/generic.js: initialize tabs from the + "unload" event listener that is added programmatically instead of + from the template... Also, added the new DNDManager object. + * UI/WebServerResources/HTMLTableElement.js: added code to simulate XUL drag n drop events. This code will possibly be moved to HTMLElement.js instead later... diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index 844de1a49..347cf99ad 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -1068,3 +1068,195 @@ function indexColor(number) { + d2h((256 / colorTable[1]) - 1) + d2h((256 / colorTable[0]) - 1)); } + +var onLoadHandler = { + handleEvent: function (event) { + initTabs(); + genericInitDnd(); + } +} + +window.addEventListener("load", onLoadHandler, false); + +/* drag and drop */ +document.DNDManager = { + lastSource: 0, + lastDestination: 0, + sources: new Array(), + destinations: new Array(), + registerSource: function (source) { + var id = source.getAttribute("id"); + if (!id) { + id = "_dndSource" + (this.lastSource + 1); + source.setAttribute("id", id); + } + this.sources[id] = source; + this.lastSource++; + if (source instanceof HTMLTableElement) { + source.addEventListener("draggesture-hack", + document.DNDManager.sourceGesture, false); + } + }, + registerDestination: function (destination) { + var id = destination.getAttribute("id"); + if (!id) { + id = "_dndDestination" + (this.lastDestination + 1); + destination.setAttribute("id", id); + } + this.destinations[id] = destination; + this.lastDestination++; + }, + _lookupSource: function (target) { + var source = null; + var id = target.getAttribute("id"); + if (id) + source = document.DNDManager.sources[id]; + return source; + }, + _lookupDestination: function (target) { + var destination = null; + var id = target.getAttribute("id"); + if (id) + destination = document.DNDManager.destinations[id]; + return destination; + }, + sourceGesture: function (event) { + var source = document.DNDManager._lookupSource (event.target); + if (source) + document.DNDManager.currentDndOperation = new document.DNDOperation (source); + }, + destinationEnter: function (event) { + var operation = document.DNDManager.currentDndOperation; + var destination = document.DNDManager._lookupDestination (event.target); + if (operation && destination && destination.dndAcceptType) { + operation.type = null; + var i = 0; + while (operation.type == null + && i < operation.types.length) { + if (destination.dndAcceptType(operation.types[i])) { + operation.type = operation.types[i]; + operation.setDestination(destination); + if (destination.dndEnter) + destination.dndEnter(event, operation.source, operation.type); + } + else + i++; + } + } + }, + destinationExit: function (event) { + var operation = document.DNDManager.currentDndOperation; + if (operation + && operation.destination == event.target) { +// log("exit: " + event.target); + if (operation.destination.dndExit) + event.target.dndExit(); + operation.setDestination(null); + } + }, + destinationOver: function (event) { +// var operation = document.DNDManager.currentDndOperation; +// if (operation +// && operation.destination == event.target) +// log("over: " + event.target); + }, + destinationDrop: function (event) { + var operation = document.DNDManager.currentDndOperation; + if (operation) { + if (operation.ghost) + operation.bustGhost(); + if (operation.source instanceof HTMLTableElement) { + window.removeEventListener("mouseup", + document.DNDManager.destinationDrop, false); + window.removeEventListener("mouseover", + document.DNDManager.destinationEnter, false); + window.removeEventListener("mousemove", + document.DNDManager.destinationOver, false); + window.removeEventListener("mouseout", + document.DNDManager.destinationExit, false); + } + if (operation.destination == event.target) { + log("drag / drop: " + operation.source + " to " + operation.destination); + if (operation.destination.dndExit) + event.target.dndExit(); + if (operation.destination.dndDrop) { + var data = operation.source.dndDataForType(operation.type); + event.target.dndDrop(data); + } + } + document.DNDManager.currentDndOperation = null; + } + }, + currentDndOperation: null, +} + +document.DNDOperation = function (source) { + this.source = source; + if (source.dndTypes) { + this.types = source.dndTypes(); + } + this.type = null; + this.destination = null; + if (source.dndGhost) { + var ghost = source.dndGhost(); + ghost.style.position = "absolute;"; + ghost.style.zIndex = 10000; + ghost.style.MozOpacity = 0.8; + document.body.appendChild(ghost); + this.ghost = ghost; + + document.addEventListener("mousemove", this.moveGhost, false); + } + + return this; +}; + +document.DNDOperation.prototype.setDestination = function(destination) { + this.destination = destination; +} + +document.DNDOperation.prototype.moveGhost = function(event) { + var offsetX = event.clientX; + var offsetY = event.clientY; + if (document.DNDManager.currentDndOperation.ghost.ghostOffsetX) + offsetX += document.DNDManager.currentDndOperation.ghost.ghostOffsetX; + if (document.DNDManager.currentDndOperation.ghost.ghostOffsetY) + offsetY += document.DNDManager.currentDndOperation.ghost.ghostOffsetY; + + document.DNDManager.currentDndOperation.ghost.style.left = offsetX + "px;"; + document.DNDManager.currentDndOperation.ghost.style.top = offsetY + "px;"; +} + +document.DNDOperation.prototype.bustGhost = function() { + document._dyingOperation = this; + document.removeEventListener("mousemove", this.moveGhost, false); + this.ghost.bustStep = 10; + setTimeout("document._dyingOperation._fadeGhost();", 50); +} + +document.DNDOperation.prototype._fadeGhost = function() { + if (this.ghost.bustStep) { + this.ghost.style.MozOpacity = (0.1 * this.ghost.bustStep); + this.ghost.bustStep--; + setTimeout("document._dyingOperation._fadeGhost();", 50); + } + else { + document.body.removeChild(this.ghost); + this.ghost = null; + } +} + +function genericInitDnd() { + log ("generic initDnd"); +// var tables = document.getElementsByTagName("table"); + window.addEventListener("draggesture", document.DNDManager.sourceGesture, false); + window.addEventListener("dragenter", document.DNDManager.destinationEnter, false); + window.addEventListener("dragexit", document.DNDManager.destinationExit, false); + window.addEventListener("dragover", document.DNDManager.destinationOver, false); + window.addEventListener("dragdrop", document.DNDManager.destinationDrop, false); +// for (var i = 0; i < tables.length; i++) { +// tables[i].addEventListener("draggesture", document.DNDManager.sourceGesture, false); +// tables[i].addEventListener("dragstart", document.DNDManager.sourceStart, false); +// tables[i].addEventListener("dragstop", document.DNDManager.sourceStop, false); +// } +}