You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/06/10 15:59:38 UTC
svn commit: r413300 [4/16] - in /tapestry/tapestry4/trunk/framework/src/js:
dojo/ dojo/src/ dojo/src/animation/ dojo/src/collections/ dojo/src/compat/
dojo/src/crypto/ dojo/src/data/ dojo/src/data/format/
dojo/src/data/provider/ dojo/src/debug/ dojo/sr...
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/**
+ * Produce a line of debug output.
+ * Does nothing unless djConfig.isDebug is true.
+ * varargs, joined with ''.
+ * Caller should not supply a trailing "\n".
+ */
+dojo.debug = function(){
+ if (!djConfig.isDebug) { return; }
+ var args = arguments;
+ if(dj_undef("println", dojo.hostenv)){
+ dojo.raise("dojo.debug not available (yet?)");
+ }
+ var isJUM = dj_global["jum"] && !dj_global["jum"].isBrowser;
+ var s = [(isJUM ? "": "DEBUG: ")];
+ for(var i=0;i<args.length;++i){
+ if(!false && args[i] && args[i] instanceof Error){
+ var msg = "[" + args[i].name + ": " + dojo.errorToString(args[i]) +
+ (args[i].fileName ? ", file: " + args[i].fileName : "") +
+ (args[i].lineNumber ? ", line: " + args[i].lineNumber : "") + "]";
+ } else {
+ try {
+ var msg = String(args[i]);
+ } catch(e) {
+ if(dojo.render.html.ie) {
+ var msg = "[ActiveXObject]";
+ } else {
+ var msg = "[unknown]";
+ }
+ }
+ }
+ s.push(msg);
+ }
+ if(isJUM){ // this seems to be the only way to get JUM to "play nice"
+ jum.debug(s.join(" "));
+ }else{
+ dojo.hostenv.println(s.join(" "));
+ }
+}
+
+/**
+ * this is really hacky for now - just
+ * display the properties of the object
+**/
+
+dojo.debugShallow = function(obj){
+ if (!djConfig.isDebug) { return; }
+ dojo.debug('------------------------------------------------------------');
+ dojo.debug('Object: '+obj);
+ var props = [];
+ for(var prop in obj){
+ try {
+ props.push(prop + ': ' + obj[prop]);
+ } catch(E) {
+ props.push(prop + ': ERROR - ' + E.message);
+ }
+ }
+ props.sort();
+ for(var i = 0; i < props.length; i++) {
+ dojo.debug(props[i]);
+ }
+ dojo.debug('------------------------------------------------------------');
+}
+
+dojo.debugDeep = function(obj){
+ if (!djConfig.isDebug) { return; }
+ if (!dojo.uri || !dojo.uri.dojoUri){ return dojo.debug("You'll need to load dojo.uri.* for deep debugging - sorry!"); }
+ if (!window.open){ return dojo.debug('Deep debugging is only supported in host environments with window.open'); }
+ var win = window.open(dojo.uri.dojoUri("src/debug/deep.html"), '_blank', 'width=600, height=400, resizable=yes, scrollbars=yes, status=yes');
+ win.debugVar = obj;
+}
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug/arrow_hide.gif
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug/arrow_hide.gif?rev=413300&view=auto
==============================================================================
Binary file - no diff available.
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/debug/arrow_hide.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/DragAndDrop.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/DragAndDrop.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/DragAndDrop.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/DragAndDrop.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,175 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.require("dojo.lang");
+dojo.provide("dojo.dnd.DragSource");
+dojo.provide("dojo.dnd.DropTarget");
+dojo.provide("dojo.dnd.DragObject");
+dojo.provide("dojo.dnd.DragAndDrop");
+
+dojo.dnd.DragSource = function(){
+ var dm = dojo.dnd.dragManager;
+ if(dm["registerDragSource"]){ // side-effect prevention
+ dm.registerDragSource(this);
+ }
+}
+
+dojo.lang.extend(dojo.dnd.DragSource, {
+ type: "",
+
+ onDragEnd: function(){
+ },
+
+ onDragStart: function(){
+ },
+
+ /*
+ * This function gets called when the DOM element was
+ * selected for dragging by the HtmlDragAndDropManager.
+ */
+ onSelected: function(){
+ },
+
+ unregister: function(){
+ dojo.dnd.dragManager.unregisterDragSource(this);
+ },
+
+ reregister: function(){
+ dojo.dnd.dragManager.registerDragSource(this);
+ }
+});
+
+dojo.dnd.DragObject = function(){
+ var dm = dojo.dnd.dragManager;
+ if(dm["registerDragObject"]){ // side-effect prevention
+ dm.registerDragObject(this);
+ }
+}
+
+dojo.lang.extend(dojo.dnd.DragObject, {
+ type: "",
+
+ onDragStart: function(){
+ // gets called directly after being created by the DragSource
+ // default action is to clone self as icon
+ },
+
+ onDragMove: function(){
+ // this changes the UI for the drag icon
+ // "it moves itself"
+ },
+
+ onDragOver: function(){
+ },
+
+ onDragOut: function(){
+ },
+
+ onDragEnd: function(){
+ },
+
+ // normal aliases
+ onDragLeave: this.onDragOut,
+ onDragEnter: this.onDragOver,
+
+ // non-camel aliases
+ ondragout: this.onDragOut,
+ ondragover: this.onDragOver
+});
+
+dojo.dnd.DropTarget = function(){
+ if (this.constructor == dojo.dnd.DropTarget) { return; } // need to be subclassed
+ this.acceptedTypes = [];
+ dojo.dnd.dragManager.registerDropTarget(this);
+}
+
+dojo.lang.extend(dojo.dnd.DropTarget, {
+
+ acceptsType: function(type){
+ if(!dojo.lang.inArray(this.acceptedTypes, "*")){ // wildcard
+ if(!dojo.lang.inArray(this.acceptedTypes, type)) { return false; }
+ }
+ return true;
+ },
+
+ accepts: function(dragObjects){
+ if(!dojo.lang.inArray(this.acceptedTypes, "*")){ // wildcard
+ for (var i = 0; i < dragObjects.length; i++) {
+ if (!dojo.lang.inArray(this.acceptedTypes,
+ dragObjects[i].type)) { return false; }
+ }
+ }
+ return true;
+ },
+
+ onDragOver: function(){
+ },
+
+ onDragOut: function(){
+ },
+
+ onDragMove: function(){
+ },
+
+ onDropStart: function(){
+ },
+
+ onDrop: function(){
+ },
+
+ onDropEnd: function(){
+ }
+});
+
+// NOTE: this interface is defined here for the convenience of the DragManager
+// implementor. It is expected that in most cases it will be satisfied by
+// extending a native event (DOM event in HTML and SVG).
+dojo.dnd.DragEvent = function(){
+ this.dragSource = null;
+ this.dragObject = null;
+ this.target = null;
+ this.eventStatus = "success";
+ //
+ // can be one of:
+ // [ "dropSuccess", "dropFailure", "dragMove",
+ // "dragStart", "dragEnter", "dragLeave"]
+ //
+}
+
+dojo.dnd.DragManager = function(){
+ /*
+ * The DragManager handles listening for low-level events and dispatching
+ * them to higher-level primitives like drag sources and drop targets. In
+ * order to do this, it must keep a list of the items.
+ */
+}
+
+dojo.lang.extend(dojo.dnd.DragManager, {
+ selectedSources: [],
+ dragObjects: [],
+ dragSources: [],
+ registerDragSource: function(){},
+ dropTargets: [],
+ registerDropTarget: function(){},
+ lastDragTarget: null,
+ currentDragTarget: null,
+ onKeyDown: function(){},
+ onMouseOut: function(){},
+ onMouseMove: function(){},
+ onMouseUp: function(){}
+});
+
+// NOTE: despite the existance of the DragManager class, there will be a
+// singleton drag manager provided by the renderer-specific D&D support code.
+// It is therefore sane for us to assign instance variables to the DragManager
+// prototype
+
+// The renderer-specific file will define the following object:
+// dojo.dnd.dragManager = null;
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/DragAndDrop.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragAndDrop.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragAndDrop.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragAndDrop.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragAndDrop.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,475 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.dnd.HtmlDragAndDrop");
+dojo.provide("dojo.dnd.HtmlDragSource");
+dojo.provide("dojo.dnd.HtmlDropTarget");
+dojo.provide("dojo.dnd.HtmlDragObject");
+
+dojo.require("dojo.dnd.HtmlDragManager");
+dojo.require("dojo.dnd.DragAndDrop");
+
+dojo.require("dojo.dom");
+dojo.require("dojo.style");
+dojo.require("dojo.html");
+dojo.require("dojo.html.extras");
+dojo.require("dojo.lang.extras");
+dojo.require("dojo.lfx.*");
+dojo.require("dojo.event");
+
+dojo.dnd.HtmlDragSource = function(node, type){
+ node = dojo.byId(node);
+ this.dragObjects = [];
+ this.constrainToContainer = false;
+ if(node){
+ this.domNode = node;
+ this.dragObject = node;
+ // register us
+ dojo.dnd.DragSource.call(this);
+ // set properties that might have been clobbered by the mixin
+ this.type = (type)||(this.domNode.nodeName.toLowerCase());
+ }
+}
+dojo.inherits(dojo.dnd.HtmlDragSource, dojo.dnd.DragSource);
+dojo.lang.extend(dojo.dnd.HtmlDragSource, {
+ dragClass: "", // CSS classname(s) applied to node when it is being dragged
+
+ onDragStart: function(){
+ var dragObj = new dojo.dnd.HtmlDragObject(this.dragObject, this.type);
+ if(this.dragClass) { dragObj.dragClass = this.dragClass; }
+
+ if (this.constrainToContainer) {
+ dragObj.constrainTo(this.constrainingContainer || this.domNode.parentNode);
+ }
+
+ return dragObj;
+ },
+
+ setDragHandle: function(node){
+ node = dojo.byId(node);
+ dojo.dnd.dragManager.unregisterDragSource(this);
+ this.domNode = node;
+ dojo.dnd.dragManager.registerDragSource(this);
+ },
+
+ setDragTarget: function(node){
+ this.dragObject = node;
+ },
+
+ constrainTo: function(container) {
+ this.constrainToContainer = true;
+ if (container) {
+ this.constrainingContainer = container;
+ }
+ },
+
+ /*
+ *
+ * see dojo.dnd.DragSource.onSelected
+ */
+ onSelected: function() {
+ for (var i=0; i<this.dragObjects.length; i++) {
+ dojo.dnd.dragManager.selectedSources.push(new dojo.dnd.HtmlDragSource(this.dragObjects[i]));
+ }
+ },
+
+ /**
+ * Register elements that should be dragged along with
+ * the actual DragSource.
+ *
+ * Example usage:
+ * var dragSource = new dojo.dnd.HtmlDragSource(...);
+ * // add a single element
+ * dragSource.addDragObjects(dojo.byId('id1'));
+ * // add multiple elements to drag along
+ * dragSource.addDragObjects(dojo.byId('id2'), dojo.byId('id3'));
+ *
+ * el A dom node to add to the drag list.
+ */
+ addDragObjects: function(/*DOMNode*/ el) {
+ for (var i=0; i<arguments.length; i++) {
+ this.dragObjects.push(arguments[i]);
+ }
+ }
+});
+
+dojo.dnd.HtmlDragObject = function(node, type){
+ this.domNode = dojo.byId(node);
+ this.type = type;
+ this.constrainToContainer = false;
+ this.dragSource = null;
+}
+dojo.inherits(dojo.dnd.HtmlDragObject, dojo.dnd.DragObject);
+dojo.lang.extend(dojo.dnd.HtmlDragObject, {
+ dragClass: "",
+ opacity: 0.5,
+ createIframe: true, // workaround IE6 bug
+
+ // if true, node will not move in X and/or Y direction
+ disableX: false,
+ disableY: false,
+
+ createDragNode: function() {
+ var node = this.domNode.cloneNode(true);
+ if(this.dragClass) { dojo.html.addClass(node, this.dragClass); }
+ if(this.opacity < 1) { dojo.style.setOpacity(node, this.opacity); }
+ if(node.tagName.toLowerCase() == "tr"){
+ // dojo.debug("Dragging table row")
+ // Create a table for the cloned row
+ var doc = this.domNode.ownerDocument;
+ var table = doc.createElement("table");
+ var tbody = doc.createElement("tbody");
+ tbody.appendChild(node);
+ table.appendChild(tbody);
+
+ // Set a fixed width to the cloned TDs
+ var domTds = this.domNode.childNodes;
+ var cloneTds = node.childNodes;
+ for(var i = 0; i < domTds.length; i++){
+ if((cloneTds[i])&&(cloneTds[i].style)){
+ cloneTds[i].style.width = dojo.style.getContentWidth(domTds[i]) + "px";
+ }
+ }
+ node = table;
+ }
+
+ if((dojo.render.html.ie55||dojo.render.html.ie60) && this.createIframe){
+ with(node.style) {
+ top="0px";
+ left="0px";
+ }
+ var outer = document.createElement("div");
+ outer.appendChild(node);
+ this.bgIframe = new dojo.html.BackgroundIframe(outer);
+ outer.appendChild(this.bgIframe.iframe);
+ node = outer;
+ }
+ node.style.zIndex = 999;
+ return node;
+ },
+
+ onDragStart: function(e){
+ dojo.html.clearSelection();
+
+ this.scrollOffset = dojo.html.getScrollOffset();
+ this.dragStartPosition = dojo.style.getAbsolutePosition(this.domNode, true);
+
+ this.dragOffset = {y: this.dragStartPosition.y - e.pageY,
+ x: this.dragStartPosition.x - e.pageX};
+
+ this.dragClone = this.createDragNode();
+
+ this.containingBlockPosition = this.domNode.offsetParent ?
+ dojo.style.getAbsolutePosition(this.domNode.offsetParent) : {x:0, y:0};
+
+ if (this.constrainToContainer) {
+ this.constraints = this.getConstraints();
+ }
+
+ // set up for dragging
+ with(this.dragClone.style){
+ position = "absolute";
+ top = this.dragOffset.y + e.pageY + "px";
+ left = this.dragOffset.x + e.pageX + "px";
+ }
+
+ document.body.appendChild(this.dragClone);
+
+ dojo.event.topic.publish('dragStart', { source: this } );
+ },
+
+ /** Return min/max x/y (relative to document.body) for this object) **/
+ getConstraints: function() {
+ if (this.constrainingContainer.nodeName.toLowerCase() == 'body') {
+ var width = dojo.html.getViewportWidth();
+ var height = dojo.html.getViewportHeight();
+ var x = 0;
+ var y = 0;
+ } else {
+ width = dojo.style.getContentWidth(this.constrainingContainer);
+ height = dojo.style.getContentHeight(this.constrainingContainer);
+ x =
+ this.containingBlockPosition.x +
+ dojo.style.getPixelValue(this.constrainingContainer, "padding-left", true) +
+ dojo.style.getBorderExtent(this.constrainingContainer, "left");
+ y =
+ this.containingBlockPosition.y +
+ dojo.style.getPixelValue(this.constrainingContainer, "padding-top", true) +
+ dojo.style.getBorderExtent(this.constrainingContainer, "top");
+ }
+
+ return {
+ minX: x,
+ minY: y,
+ maxX: x + width - dojo.style.getOuterWidth(this.domNode),
+ maxY: y + height - dojo.style.getOuterHeight(this.domNode)
+ }
+ },
+
+ updateDragOffset: function() {
+ var scroll = dojo.html.getScrollOffset();
+ if(scroll.y != this.scrollOffset.y) {
+ var diff = scroll.y - this.scrollOffset.y;
+ this.dragOffset.y += diff;
+ this.scrollOffset.y = scroll.y;
+ }
+ if(scroll.x != this.scrollOffset.x) {
+ var diff = scroll.x - this.scrollOffset.x;
+ this.dragOffset.x += diff;
+ this.scrollOffset.x = scroll.x;
+ }
+ },
+
+ /** Moves the node to follow the mouse */
+ onDragMove: function(e){
+ this.updateDragOffset();
+ var x = this.dragOffset.x + e.pageX;
+ var y = this.dragOffset.y + e.pageY;
+
+ if (this.constrainToContainer) {
+ if (x < this.constraints.minX) { x = this.constraints.minX; }
+ if (y < this.constraints.minY) { y = this.constraints.minY; }
+ if (x > this.constraints.maxX) { x = this.constraints.maxX; }
+ if (y > this.constraints.maxY) { y = this.constraints.maxY; }
+ }
+
+ this.setAbsolutePosition(x, y);
+
+ dojo.event.topic.publish('dragMove', { source: this } );
+ },
+
+ /**
+ * Set the position of the drag clone. (x,y) is relative to <body>.
+ */
+ setAbsolutePosition: function(x, y){
+ // The drag clone is attached to document.body so this is trivial
+ if(!this.disableY) { this.dragClone.style.top = y + "px"; }
+ if(!this.disableX) { this.dragClone.style.left = x + "px"; }
+ },
+
+
+ /**
+ * If the drag operation returned a success we reomve the clone of
+ * ourself from the original position. If the drag operation returned
+ * failure we slide back over to where we came from and end the operation
+ * with a little grace.
+ */
+ onDragEnd: function(e){
+ switch(e.dragStatus){
+
+ case "dropSuccess":
+ dojo.dom.removeNode(this.dragClone);
+ this.dragClone = null;
+ break;
+
+ case "dropFailure": // slide back to the start
+ var startCoords = dojo.style.getAbsolutePosition(this.dragClone, true);
+ // offset the end so the effect can be seen
+ var endCoords = [this.dragStartPosition.x + 1,
+ this.dragStartPosition.y + 1];
+
+ // animate
+ var line = new dojo.lfx.Line(startCoords, endCoords);
+ var anim = new dojo.lfx.Animation(500, line, dojo.lfx.easeOut);
+ var dragObject = this;
+ dojo.event.connect(anim, "onAnimate", function(e) {
+ dragObject.dragClone.style.left = e[0] + "px";
+ dragObject.dragClone.style.top = e[1] + "px";
+ });
+ dojo.event.connect(anim, "onEnd", function (e) {
+ // pause for a second (not literally) and disappear
+ dojo.lang.setTimeout(function() {
+ dojo.dom.removeNode(dragObject.dragClone);
+ // Allow drag clone to be gc'ed
+ dragObject.dragClone = null;
+ },
+ 200);
+ });
+ anim.play();
+ break;
+ }
+
+ // shortly the browser will fire an onClick() event,
+ // but since this was really a drag, just squelch it
+ dojo.event.connect(this.domNode, "onclick", this, "squelchOnClick");
+
+ dojo.event.topic.publish('dragEnd', { source: this } );
+ },
+
+ squelchOnClick: function(e){
+ // squelch this onClick() event because it's the result of a drag (it's not a real click)
+ e.preventDefault();
+
+ // but if a real click comes along, allow it
+ dojo.event.disconnect(this.domNode, "onclick", this, "squelchOnClick");
+ },
+
+ constrainTo: function(container) {
+ this.constrainToContainer=true;
+ if (container) {
+ this.constrainingContainer = container;
+ } else {
+ this.constrainingContainer = this.domNode.parentNode;
+ }
+ }
+});
+
+dojo.dnd.HtmlDropTarget = function(node, types){
+ if (arguments.length == 0) { return; }
+ this.domNode = dojo.byId(node);
+ dojo.dnd.DropTarget.call(this);
+ if(types && dojo.lang.isString(types)) {
+ types = [types];
+ }
+ this.acceptedTypes = types || [];
+}
+dojo.inherits(dojo.dnd.HtmlDropTarget, dojo.dnd.DropTarget);
+
+dojo.lang.extend(dojo.dnd.HtmlDropTarget, {
+ onDragOver: function(e){
+ if(!this.accepts(e.dragObjects)){ return false; }
+
+ // cache the positions of the child nodes
+ this.childBoxes = [];
+ for (var i = 0, child; i < this.domNode.childNodes.length; i++) {
+ child = this.domNode.childNodes[i];
+ if (child.nodeType != dojo.dom.ELEMENT_NODE) { continue; }
+ var pos = dojo.style.getAbsolutePosition(child, true);
+ var height = dojo.style.getInnerHeight(child);
+ var width = dojo.style.getInnerWidth(child);
+ this.childBoxes.push({top: pos.y, bottom: pos.y+height,
+ left: pos.x, right: pos.x+width, node: child});
+ }
+
+ // TODO: use dummy node
+
+ return true;
+ },
+
+ _getNodeUnderMouse: function(e){
+ // find the child
+ for (var i = 0, child; i < this.childBoxes.length; i++) {
+ with (this.childBoxes[i]) {
+ if (e.pageX >= left && e.pageX <= right &&
+ e.pageY >= top && e.pageY <= bottom) { return i; }
+ }
+ }
+
+ return -1;
+ },
+
+ createDropIndicator: function() {
+ this.dropIndicator = document.createElement("div");
+ with (this.dropIndicator.style) {
+ position = "absolute";
+ zIndex = 999;
+ borderTopWidth = "1px";
+ borderTopColor = "black";
+ borderTopStyle = "solid";
+ width = dojo.style.getInnerWidth(this.domNode) + "px";
+ left = dojo.style.getAbsoluteX(this.domNode, true) + "px";
+ }
+ },
+
+ onDragMove: function(e, dragObjects){
+ var i = this._getNodeUnderMouse(e);
+
+ if(!this.dropIndicator){
+ this.createDropIndicator();
+ }
+
+ if(i < 0) {
+ if(this.childBoxes.length) {
+ var before = (dojo.html.gravity(this.childBoxes[0].node, e) & dojo.html.gravity.NORTH);
+ } else {
+ var before = true;
+ }
+ } else {
+ var child = this.childBoxes[i];
+ var before = (dojo.html.gravity(child.node, e) & dojo.html.gravity.NORTH);
+ }
+ this.placeIndicator(e, dragObjects, i, before);
+
+ if(!dojo.html.hasParent(this.dropIndicator)) {
+ document.body.appendChild(this.dropIndicator);
+ }
+ },
+
+ /**
+ * Position the horizontal line that indicates "insert between these two items"
+ */
+ placeIndicator: function(e, dragObjects, boxIndex, before) {
+ with(this.dropIndicator.style){
+ if (boxIndex < 0) {
+ if (this.childBoxes.length) {
+ top = (before ? this.childBoxes[0].top
+ : this.childBoxes[this.childBoxes.length - 1].bottom) + "px";
+ } else {
+ top = dojo.style.getAbsoluteY(this.domNode, true) + "px";
+ }
+ } else {
+ var child = this.childBoxes[boxIndex];
+ top = (before ? child.top : child.bottom) + "px";
+ }
+ }
+ },
+
+ onDragOut: function(e) {
+ if(this.dropIndicator) {
+ dojo.dom.removeNode(this.dropIndicator);
+ delete this.dropIndicator;
+ }
+ },
+
+ /**
+ * Inserts the DragObject as a child of this node relative to the
+ * position of the mouse.
+ *
+ * @return true if the DragObject was inserted, false otherwise
+ */
+ onDrop: function(e){
+ this.onDragOut(e);
+
+ var i = this._getNodeUnderMouse(e);
+
+ if (i < 0) {
+ if (this.childBoxes.length) {
+ if (dojo.html.gravity(this.childBoxes[0].node, e) & dojo.html.gravity.NORTH) {
+ return this.insert(e, this.childBoxes[0].node, "before");
+ } else {
+ return this.insert(e, this.childBoxes[this.childBoxes.length-1].node, "after");
+ }
+ }
+ return this.insert(e, this.domNode, "append");
+ }
+
+ var child = this.childBoxes[i];
+ if (dojo.html.gravity(child.node, e) & dojo.html.gravity.NORTH) {
+ return this.insert(e, child.node, "before");
+ } else {
+ return this.insert(e, child.node, "after");
+ }
+ },
+
+ insert: function(e, refNode, position) {
+ var node = e.dragObject.domNode;
+
+ if(position == "before") {
+ return dojo.html.insertBefore(node, refNode);
+ } else if(position == "after") {
+ return dojo.html.insertAfter(node, refNode);
+ } else if(position == "append") {
+ refNode.appendChild(node);
+ return true;
+ }
+
+ return false;
+ }
+});
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragAndDrop.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragManager.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragManager.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragManager.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragManager.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,475 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.dnd.HtmlDragManager");
+dojo.require("dojo.dnd.DragAndDrop");
+dojo.require("dojo.event.*");
+dojo.require("dojo.lang.array");
+dojo.require("dojo.html");
+dojo.require("dojo.style");
+
+// NOTE: there will only ever be a single instance of HTMLDragManager, so it's
+// safe to use prototype properties for book-keeping.
+dojo.dnd.HtmlDragManager = function(){
+}
+
+dojo.inherits(dojo.dnd.HtmlDragManager, dojo.dnd.DragManager);
+
+dojo.lang.extend(dojo.dnd.HtmlDragManager, {
+ /**
+ * There are several sets of actions that the DnD code cares about in the
+ * HTML context:
+ * 1.) mouse-down ->
+ * (draggable selection)
+ * (dragObject generation)
+ * mouse-move ->
+ * (draggable movement)
+ * (droppable detection)
+ * (inform droppable)
+ * (inform dragObject)
+ * mouse-up
+ * (inform/destroy dragObject)
+ * (inform draggable)
+ * (inform droppable)
+ * 2.) mouse-down -> mouse-down
+ * (click-hold context menu)
+ * 3.) mouse-click ->
+ * (draggable selection)
+ * shift-mouse-click ->
+ * (augment draggable selection)
+ * mouse-down ->
+ * (dragObject generation)
+ * mouse-move ->
+ * (draggable movement)
+ * (droppable detection)
+ * (inform droppable)
+ * (inform dragObject)
+ * mouse-up
+ * (inform draggable)
+ * (inform droppable)
+ * 4.) mouse-up
+ * (clobber draggable selection)
+ */
+ disabled: false, // to kill all dragging!
+ nestedTargets: false,
+ mouseDownTimer: null, // used for click-hold operations
+ dsCounter: 0,
+ dsPrefix: "dojoDragSource",
+
+ // dimension calculation cache for use durring drag
+ dropTargetDimensions: [],
+
+ currentDropTarget: null,
+ // currentDropTargetPoints: null,
+ previousDropTarget: null,
+ _dragTriggered: false,
+
+ selectedSources: [],
+ dragObjects: [],
+
+ // mouse position properties
+ currentX: null,
+ currentY: null,
+ lastX: null,
+ lastY: null,
+ mouseDownX: null,
+ mouseDownY: null,
+ threshold: 7,
+
+ dropAcceptable: false,
+
+ cancelEvent: function(e){ e.stopPropagation(); e.preventDefault();},
+
+ // method over-rides
+ registerDragSource: function(ds){
+ if(ds["domNode"]){
+ // FIXME: dragSource objects SHOULD have some sort of property that
+ // references their DOM node, we shouldn't just be passing nodes and
+ // expecting it to work.
+ var dp = this.dsPrefix;
+ var dpIdx = dp+"Idx_"+(this.dsCounter++);
+ ds.dragSourceId = dpIdx;
+ this.dragSources[dpIdx] = ds;
+ ds.domNode.setAttribute(dp, dpIdx);
+
+ // so we can drag links
+ if(dojo.render.html.ie){
+ dojo.event.connect(ds.domNode, "ondragstart", this.cancelEvent);
+ }
+ }
+ },
+
+ unregisterDragSource: function(ds){
+ if (ds["domNode"]){
+
+ var dp = this.dsPrefix;
+ var dpIdx = ds.dragSourceId;
+ delete ds.dragSourceId;
+ delete this.dragSources[dpIdx];
+ ds.domNode.setAttribute(dp, null);
+ }
+ if(dojo.render.html.ie){
+ dojo.event.disconnect(ds.domNode, "ondragstart", this.cancelEvent );
+ }
+ },
+
+ registerDropTarget: function(dt){
+ this.dropTargets.push(dt);
+ },
+
+ unregisterDropTarget: function(dt){
+ var index = dojo.lang.find(this.dropTargets, dt, true);
+ if (index>=0) {
+ this.dropTargets.splice(index, 1);
+ }
+ },
+
+ /**
+ * Get the DOM element that is meant to drag.
+ * Loop through the parent nodes of the event target until
+ * the element is found that was created as a DragSource and
+ * return it.
+ *
+ * @param event object The event for which to get the drag source.
+ */
+ getDragSource: function(e){
+ var tn = e.target;
+ if(tn === document.body){ return; }
+ var ta = dojo.html.getAttribute(tn, this.dsPrefix);
+ while((!ta)&&(tn)){
+ tn = tn.parentNode;
+ if((!tn)||(tn === document.body)){ return; }
+ ta = dojo.html.getAttribute(tn, this.dsPrefix);
+ }
+ return this.dragSources[ta];
+ },
+
+ onKeyDown: function(e){
+ },
+
+ onMouseDown: function(e){
+ if(this.disabled) { return; }
+
+ // only begin on left click
+ if(dojo.render.html.ie) {
+ if(e.button != 1) { return; }
+ } else if(e.which != 1) {
+ return;
+ }
+
+ var target = e.target.nodeType == dojo.dom.TEXT_NODE ?
+ e.target.parentNode : e.target;
+
+ // do not start drag involvement if the user is interacting with
+ // a form element.
+ if(dojo.html.isTag(target, "button", "textarea", "input", "select", "option")) {
+ return;
+ }
+
+ // find a selection object, if one is a parent of the source node
+ var ds = this.getDragSource(e);
+
+ // this line is important. if we aren't selecting anything then
+ // we need to return now, so preventDefault() isn't called, and thus
+ // the event is propogated to other handling code
+ if(!ds){ return; }
+
+ if(!dojo.lang.inArray(this.selectedSources, ds)){
+ this.selectedSources.push(ds);
+ ds.onSelected();
+ }
+
+ this.mouseDownX = e.pageX;
+ this.mouseDownY = e.pageY;
+
+ // Must stop the mouse down from being propogated, or otherwise can't
+ // drag links in firefox.
+ // WARNING: preventing the default action on all mousedown events
+ // prevents user interaction with the contents.
+ e.preventDefault();
+
+ dojo.event.connect(document, "onmousemove", this, "onMouseMove");
+ },
+
+ onMouseUp: function(e, cancel){
+ // if we aren't dragging then ignore the mouse-up
+ // (in particular, don't call preventDefault(), because other
+ // code may need to process this event)
+ if(this.selectedSources.length==0){
+ return;
+ }
+
+ this.mouseDownX = null;
+ this.mouseDownY = null;
+ this._dragTriggered = false;
+ // e.preventDefault();
+ e.dragSource = this.dragSource;
+ if((!e.shiftKey)&&(!e.ctrlKey)){
+ if(this.currentDropTarget) {
+ this.currentDropTarget.onDropStart();
+ }
+ dojo.lang.forEach(this.dragObjects, function(tempDragObj){
+ var ret = null;
+ if(!tempDragObj){ return; }
+ if(this.currentDropTarget) {
+ e.dragObject = tempDragObj;
+
+ // NOTE: we can't get anything but the current drop target
+ // here since the drag shadow blocks mouse-over events.
+ // This is probelematic for dropping "in" something
+ var ce = this.currentDropTarget.domNode.childNodes;
+ if(ce.length > 0){
+ e.dropTarget = ce[0];
+ while(e.dropTarget == tempDragObj.domNode){
+ e.dropTarget = e.dropTarget.nextSibling;
+ }
+ }else{
+ e.dropTarget = this.currentDropTarget.domNode;
+ }
+ if(this.dropAcceptable){
+ ret = this.currentDropTarget.onDrop(e);
+ }else{
+ this.currentDropTarget.onDragOut(e);
+ }
+ }
+
+ e.dragStatus = this.dropAcceptable && ret ? "dropSuccess" : "dropFailure";
+ // decouple the calls for onDragEnd, so they don't block the execution here
+ // ie. if the onDragEnd would call an alert, the execution here is blocked until the
+ // user has confirmed the alert box and then the rest of the dnd code is executed
+ // while the mouse doesnt "hold" the dragged object anymore ... and so on
+ dojo.lang.delayThese([
+ function() {
+ // in FF1.5 this throws an exception, see
+ // http://dojotoolkit.org/pipermail/dojo-interest/2006-April/006751.html
+ try{
+ tempDragObj.dragSource.onDragEnd(e)
+ } catch(err) {
+ // since the problem seems passing e, we just copy all
+ // properties and try the copy ...
+ var ecopy = {};
+ for (var i in e) {
+ if (i=="type") { // the type property contains the exception, no idea why...
+ ecopy.type = "mouseup";
+ continue;
+ }
+ ecopy[i] = e[i];
+ }
+ tempDragObj.dragSource.onDragEnd(ecopy);
+ }
+ }
+ , function() {tempDragObj.onDragEnd(e)}]);
+ }, this);
+
+ this.selectedSources = [];
+ this.dragObjects = [];
+ this.dragSource = null;
+ if(this.currentDropTarget) {
+ this.currentDropTarget.onDropEnd();
+ }
+ }
+
+ dojo.event.disconnect(document, "onmousemove", this, "onMouseMove");
+ this.currentDropTarget = null;
+ },
+
+ onScroll: function(){
+ for(var i = 0; i < this.dragObjects.length; i++) {
+ if(this.dragObjects[i].updateDragOffset) {
+ this.dragObjects[i].updateDragOffset();
+ }
+ }
+ // TODO: do not recalculate, only adjust coordinates
+ this.cacheTargetLocations();
+ },
+
+ _dragStartDistance: function(x, y){
+ if((!this.mouseDownX)||(!this.mouseDownX)){
+ return;
+ }
+ var dx = Math.abs(x-this.mouseDownX);
+ var dx2 = dx*dx;
+ var dy = Math.abs(y-this.mouseDownY);
+ var dy2 = dy*dy;
+ return parseInt(Math.sqrt(dx2+dy2), 10);
+ },
+
+ cacheTargetLocations: function(){
+ this.dropTargetDimensions = [];
+ dojo.lang.forEach(this.dropTargets, function(tempTarget){
+ var tn = tempTarget.domNode;
+ if(!tn){ return; }
+ var ttx = dojo.style.getAbsoluteX(tn, true);
+ var tty = dojo.style.getAbsoluteY(tn, true);
+ this.dropTargetDimensions.push([
+ [ttx, tty], // upper-left
+ // lower-right
+ [ ttx+dojo.style.getInnerWidth(tn), tty+dojo.style.getInnerHeight(tn) ],
+ tempTarget
+ ]);
+ //dojo.debug("Cached for "+tempTarget)
+ }, this);
+ //dojo.debug("Cache locations")
+ },
+
+ onMouseMove: function(e){
+ if((dojo.render.html.ie)&&(e.button != 1)){
+ // Oooops - mouse up occurred - e.g. when mouse was not over the
+ // window. I don't think we can detect this for FF - but at least
+ // we can be nice in IE.
+ this.currentDropTarget = null;
+ this.onMouseUp(e, true);
+ return;
+ }
+
+ // if we've got some sources, but no drag objects, we need to send
+ // onDragStart to all the right parties and get things lined up for
+ // drop target detection
+
+ if( (this.selectedSources.length)&&
+ (!this.dragObjects.length) ){
+ var dx;
+ var dy;
+ if(!this._dragTriggered){
+ this._dragTriggered = (this._dragStartDistance(e.pageX, e.pageY) > this.threshold);
+ if(!this._dragTriggered){ return; }
+ dx = e.pageX - this.mouseDownX;
+ dy = e.pageY - this.mouseDownY;
+ }
+
+ // the first element is always our dragSource, if there are multiple
+ // selectedSources (elements that move along) then the first one is the master
+ // and for it the events will be fired etc.
+ this.dragSource = this.selectedSources[0];
+
+ dojo.lang.forEach(this.selectedSources, function(tempSource){
+ if(!tempSource){ return; }
+ var tdo = tempSource.onDragStart(e);
+ if(tdo){
+ tdo.onDragStart(e);
+
+ // "bump" the drag object to account for the drag threshold
+ tdo.dragOffset.top += dy;
+ tdo.dragOffset.left += dx;
+ tdo.dragSource = tempSource;
+
+ this.dragObjects.push(tdo);
+ }
+ }, this);
+
+ /* clean previous drop target in dragStart */
+ this.previousDropTarget = null;
+
+ this.cacheTargetLocations();
+ }
+
+ // FIXME: we need to add dragSources and dragObjects to e
+ dojo.lang.forEach(this.dragObjects, function(dragObj){
+ if(dragObj){ dragObj.onDragMove(e); }
+ });
+
+ // if we have a current drop target, check to see if we're outside of
+ // it. If so, do all the actions that need doing.
+ if(this.currentDropTarget){
+ //dojo.debug(dojo.dom.hasParent(this.currentDropTarget.domNode))
+ var c = dojo.style.toCoordinateArray(this.currentDropTarget.domNode, true);
+ // var dtp = this.currentDropTargetPoints;
+ var dtp = [
+ [c[0],c[1]], [c[0]+c[2], c[1]+c[3]]
+ ];
+ }
+
+ if((!this.nestedTargets)&&(dtp)&&(this.isInsideBox(e, dtp))){
+ if(this.dropAcceptable){
+ this.currentDropTarget.onDragMove(e, this.dragObjects);
+ }
+ }else{
+ // FIXME: need to fix the event object!
+ // see if we can find a better drop target
+ var bestBox = this.findBestTarget(e);
+
+ if(bestBox.target === null){
+ if(this.currentDropTarget){
+ this.currentDropTarget.onDragOut(e);
+ this.previousDropTarget = this.currentDropTarget;
+ this.currentDropTarget = null;
+ // this.currentDropTargetPoints = null;
+ }
+ this.dropAcceptable = false;
+ return;
+ }
+
+ if(this.currentDropTarget !== bestBox.target){
+ if(this.currentDropTarget){
+ this.previousDropTarget = this.currentDropTarget;
+ this.currentDropTarget.onDragOut(e);
+ }
+ this.currentDropTarget = bestBox.target;
+ // this.currentDropTargetPoints = bestBox.points;
+ e.dragObjects = this.dragObjects;
+ this.dropAcceptable = this.currentDropTarget.onDragOver(e);
+
+ }else{
+ if(this.dropAcceptable){
+ this.currentDropTarget.onDragMove(e, this.dragObjects);
+ }
+ }
+ }
+ },
+
+ findBestTarget: function(e) {
+ var _this = this;
+ var bestBox = new Object();
+ bestBox.target = null;
+ bestBox.points = null;
+ dojo.lang.every(this.dropTargetDimensions, function(tmpDA) {
+ if(!_this.isInsideBox(e, tmpDA))
+ return true;
+ bestBox.target = tmpDA[2];
+ bestBox.points = tmpDA;
+ // continue iterating only if _this.nestedTargets == true
+ return Boolean(_this.nestedTargets);
+ });
+
+ return bestBox;
+ },
+
+ isInsideBox: function(e, coords){
+ if( (e.pageX > coords[0][0])&&
+ (e.pageX < coords[1][0])&&
+ (e.pageY > coords[0][1])&&
+ (e.pageY < coords[1][1]) ){
+ return true;
+ }
+ return false;
+ },
+
+ onMouseOver: function(e){
+ },
+
+ onMouseOut: function(e){
+ }
+});
+
+dojo.dnd.dragManager = new dojo.dnd.HtmlDragManager();
+
+// global namespace protection closure
+(function(){
+ var d = document;
+ var dm = dojo.dnd.dragManager;
+ // set up event handlers on the document
+ dojo.event.connect(d, "onkeydown", dm, "onKeyDown");
+ dojo.event.connect(d, "onmouseover", dm, "onMouseOver");
+ dojo.event.connect(d, "onmouseout", dm, "onMouseOut");
+ dojo.event.connect(d, "onmousedown", dm, "onMouseDown");
+ dojo.event.connect(d, "onmouseup", dm, "onMouseUp");
+ // TODO: process scrolling of elements, not only window
+ dojo.event.connect(window, "onscroll", dm, "onScroll");
+})();
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragManager.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragMove.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragMove.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragMove.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragMove.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,76 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.dnd.HtmlDragMove");
+dojo.provide("dojo.dnd.HtmlDragMoveSource");
+dojo.provide("dojo.dnd.HtmlDragMoveObject");
+dojo.require("dojo.dnd.*");
+
+dojo.dnd.HtmlDragMoveSource = function(node, type){
+ dojo.dnd.HtmlDragSource.call(this, node, type);
+}
+dojo.inherits(dojo.dnd.HtmlDragMoveSource, dojo.dnd.HtmlDragSource);
+dojo.lang.extend(dojo.dnd.HtmlDragMoveSource, {
+ onDragStart: function(){
+ var dragObj = new dojo.dnd.HtmlDragMoveObject(this.dragObject, this.type);
+ if (this.constrainToContainer) {
+ dragObj.constrainTo(this.constrainingContainer);
+ }
+ return dragObj;
+ },
+ /*
+ * see dojo.dnd.HtmlDragSource.onSelected
+ */
+ onSelected: function() {
+ for (var i=0; i<this.dragObjects.length; i++) {
+ dojo.dnd.dragManager.selectedSources.push(new dojo.dnd.HtmlDragMoveSource(this.dragObjects[i]));
+ }
+ }
+});
+
+dojo.dnd.HtmlDragMoveObject = function(node, type){
+ dojo.dnd.HtmlDragObject.call(this, node, type);
+}
+dojo.inherits(dojo.dnd.HtmlDragMoveObject, dojo.dnd.HtmlDragObject);
+dojo.lang.extend(dojo.dnd.HtmlDragMoveObject, {
+ onDragEnd: function(e){
+ // shortly the browser will fire an onClick() event,
+ // but since this was really a drag, just squelch it
+ dojo.event.connect(this.domNode, "onclick", this, "squelchOnClick");
+ },
+ onDragStart: function(e){
+ dojo.html.clearSelection();
+
+ this.dragClone = this.domNode;
+
+ this.scrollOffset = dojo.html.getScrollOffset();
+ this.dragStartPosition = dojo.style.getAbsolutePosition(this.domNode, true);
+
+ this.dragOffset = {y: this.dragStartPosition.y - e.pageY,
+ x: this.dragStartPosition.x - e.pageX};
+
+ this.containingBlockPosition = this.domNode.offsetParent ?
+ dojo.style.getAbsolutePosition(this.domNode.offsetParent, true) : {x:0, y:0};
+
+ this.dragClone.style.position = "absolute";
+
+ if (this.constrainToContainer) {
+ this.constraints = this.getConstraints();
+ }
+ },
+ /**
+ * Set the position of the drag node. (x,y) is relative to <body>.
+ */
+ setAbsolutePosition: function(x, y){
+ // The drag clone is attached to it's constraining container so offset for that
+ if(!this.disableY) { this.domNode.style.top = (y-this.containingBlockPosition.y) + "px"; }
+ if(!this.disableX) { this.domNode.style.left = (x-this.containingBlockPosition.x) + "px"; }
+ }
+});
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/HtmlDragMove.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/Sortable.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/Sortable.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/Sortable.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/Sortable.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,28 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.dnd.Sortable");
+dojo.require("dojo.dnd.*");
+
+dojo.dnd.Sortable = function () {}
+
+dojo.lang.extend(dojo.dnd.Sortable, {
+
+ ondragstart: function (e) {
+ var dragObject = e.target;
+ while (dragObject.parentNode && dragObject.parentNode != this) {
+ dragObject = dragObject.parentNode;
+ }
+ // TODO: should apply HtmlDropTarget interface to self
+ // TODO: should apply HtmlDragObject interface?
+ return dragObject;
+ }
+
+});
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/Sortable.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/TreeDragAndDrop.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/TreeDragAndDrop.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/TreeDragAndDrop.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/TreeDragAndDrop.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,473 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+/**
+ * TreeDrag* specialized on managing subtree drags
+ * It selects nodes and visualises what's going on,
+ * but delegates real actions upon tree to the controller
+ *
+ * This code is considered a part of controller
+*/
+
+dojo.provide("dojo.dnd.TreeDragAndDrop");
+dojo.provide("dojo.dnd.TreeDragSource");
+dojo.provide("dojo.dnd.TreeDropTarget");
+dojo.provide("dojo.dnd.TreeDNDController");
+
+dojo.require("dojo.dnd.HtmlDragAndDrop");
+dojo.require("dojo.lang.func");
+dojo.require("dojo.lang.array");
+dojo.require("dojo.lang.extras");
+
+dojo.dnd.TreeDragSource = function(node, syncController, type, treeNode){
+ this.controller = syncController;
+ this.treeNode = treeNode;
+
+ dojo.dnd.HtmlDragSource.call(this, node, type);
+}
+
+dojo.inherits(dojo.dnd.TreeDragSource, dojo.dnd.HtmlDragSource);
+
+dojo.lang.extend(dojo.dnd.TreeDragSource, {
+ onDragStart: function(){
+ /* extend adds functions to prototype */
+ var dragObject = dojo.dnd.HtmlDragSource.prototype.onDragStart.call(this);
+ //dojo.debugShallow(dragObject)
+
+ dragObject.treeNode = this.treeNode;
+
+ dragObject.onDragStart = dojo.lang.hitch(dragObject, function(e) {
+
+ /* save selection */
+ this.savedSelectedNode = this.treeNode.tree.selector.selectedNode;
+ if (this.savedSelectedNode) {
+ this.savedSelectedNode.unMarkSelected();
+ }
+
+ var result = dojo.dnd.HtmlDragObject.prototype.onDragStart.apply(this, arguments);
+
+
+ /* remove background grid from cloned object */
+ var cloneGrid = this.dragClone.getElementsByTagName('img');
+ for(var i=0; i<cloneGrid.length; i++) {
+ cloneGrid.item(i).style.backgroundImage='url()';
+ }
+
+ return result;
+
+
+ });
+
+ dragObject.onDragEnd = function(e) {
+
+ /* restore selection */
+ if (this.savedSelectedNode) {
+ this.savedSelectedNode.markSelected();
+ }
+ //dojo.debug(e.dragStatus);
+
+ return dojo.dnd.HtmlDragObject.prototype.onDragEnd.apply(this, arguments);
+ }
+ //dojo.debug(dragObject.domNode.outerHTML)
+
+
+ return dragObject;
+ },
+
+ onDragEnd: function(e){
+
+
+ var res = dojo.dnd.HtmlDragSource.prototype.onDragEnd.call(this, e);
+
+
+ return res;
+ }
+});
+
+// .......................................
+
+dojo.dnd.TreeDropTarget = function(domNode, controller, type, treeNode, DNDMode){
+
+ this.treeNode = treeNode;
+ this.controller = controller; // I will sync-ly process drops
+ this.DNDMode = DNDMode;
+
+ dojo.dnd.HtmlDropTarget.apply(this, [domNode, type]);
+}
+
+dojo.inherits(dojo.dnd.TreeDropTarget, dojo.dnd.HtmlDropTarget);
+
+dojo.lang.extend(dojo.dnd.TreeDropTarget, {
+
+ autoExpandDelay: 1500,
+ autoExpandTimer: null,
+
+
+ position: null,
+
+ indicatorStyle: "2px black solid",
+
+ showIndicator: function(position) {
+
+ // do not change style too often, cause of blinking possible
+ if (this.position == position) {
+ return;
+ }
+
+ //dojo.debug(position)
+
+ this.hideIndicator();
+
+ this.position = position;
+
+ if (position == "before") {
+ this.treeNode.labelNode.style.borderTop = this.indicatorStyle;
+ } else if (position == "after") {
+ this.treeNode.labelNode.style.borderBottom = this.indicatorStyle;
+ } else if (position == "onto") {
+ this.treeNode.markSelected();
+ }
+
+
+ },
+
+ hideIndicator: function() {
+ this.treeNode.labelNode.style.borderBottom="";
+ this.treeNode.labelNode.style.borderTop="";
+ this.treeNode.unMarkSelected();
+ this.position = null;
+ },
+
+
+
+ // is the target possibly ok ?
+ // This function is run on dragOver, but drop possibility is also determined by position over node
+ // that's why acceptsWithPosition is called
+ // doesnt take index into account ( can change while moving mouse w/o changing target )
+
+
+ /**
+ * Coarse (tree-level) access check.
+ * We can't determine real accepts status w/o position
+ */
+ onDragOver: function(e){
+//dojo.debug("onDragOver for "+e);
+
+
+ var accepts = dojo.dnd.HtmlDropTarget.prototype.onDragOver.apply(this, arguments);
+
+ //dojo.debug("TreeDropTarget.onDragOver accepts:"+accepts)
+
+ if (accepts && this.treeNode.isFolder && !this.treeNode.isExpanded) {
+ this.setAutoExpandTimer();
+ }
+
+ return accepts;
+ },
+
+ /* Parent.onDragOver calls this function to get accepts status */
+ accepts: function(dragObjects) {
+
+ var accepts = dojo.dnd.HtmlDropTarget.prototype.accepts.apply(this, arguments);
+
+ if (!accepts) return false;
+
+ var sourceTreeNode = dragObjects[0].treeNode;
+
+ if (dojo.lang.isUndefined(sourceTreeNode) || !sourceTreeNode || !sourceTreeNode.isTreeNode) {
+ dojo.raise("Source is not TreeNode or not found");
+ }
+
+ if (sourceTreeNode === this.treeNode) return false;
+
+ return true;
+ },
+
+
+
+ setAutoExpandTimer: function() {
+ // set up autoexpand timer
+ var _this = this;
+
+ var autoExpand = function () {
+ if (dojo.dnd.dragManager.currentDropTarget === _this) {
+ _this.controller.expand(_this.treeNode);
+ }
+ }
+
+ this.autoExpandTimer = dojo.lang.setTimeout(autoExpand, _this.autoExpandDelay);
+ },
+
+
+ getAcceptPosition: function(e, sourceTreeNode) {
+
+ var DNDMode = this.DNDMode;
+
+ if (DNDMode & dojo.widget.Tree.prototype.DNDModes.ONTO &&
+ // check if ONTO is allowed localy
+ !(
+ !this.treeNode.actionIsDisabled(dojo.widget.TreeNode.prototype.actions.ADDCHILD) // check dynamically cause may change w/o regeneration of dropTarget
+ && sourceTreeNode.parent !== this.treeNode
+ && this.controller.canMove(sourceTreeNode, this.treeNode)
+ )
+ ) {
+ // disable ONTO if can't move
+ DNDMode &= ~dojo.widget.Tree.prototype.DNDModes.ONTO;
+ }
+
+
+ var position = this.getPosition(e, DNDMode);
+
+ //dojo.debug(DNDMode & +" : "+position);
+
+
+ // if onto is here => it was allowed before, no accept check is needed
+ if (position=="onto" ||
+ (!this.isAdjacentNode(sourceTreeNode, position)
+ && this.controller.canMove(sourceTreeNode, this.treeNode.parent)
+ )
+ ) {
+ return position;
+ } else {
+ return false;
+ }
+
+ },
+
+ onDragOut: function(e) {
+ this.clearAutoExpandTimer();
+
+ this.hideIndicator();
+ },
+
+
+ clearAutoExpandTimer: function() {
+ if (this.autoExpandTimer) {
+ clearTimeout(this.autoExpandTimer);
+ this.autoExpandTimer = null;
+ }
+ },
+
+
+
+ onDragMove: function(e, dragObjects){
+
+ var sourceTreeNode = dragObjects[0].treeNode;
+
+ var position = this.getAcceptPosition(e, sourceTreeNode);
+
+ if (position) {
+ this.showIndicator(position);
+ }
+
+ },
+
+ isAdjacentNode: function(sourceNode, position) {
+
+ if (sourceNode === this.treeNode) return true;
+ if (sourceNode.getNextSibling() === this.treeNode && position=="before") return true;
+ if (sourceNode.getPreviousSibling() === this.treeNode && position=="after") return true;
+
+ return false;
+ },
+
+
+ /* get DNDMode and see which position e fits */
+ getPosition: function(e, DNDMode) {
+ node = dojo.byId(this.treeNode.labelNode);
+ var mousey = e.pageY || e.clientY + document.body.scrollTop;
+ var nodey = dojo.html.getAbsoluteY(node);
+ var height = dojo.html.getInnerHeight(node);
+
+ var relY = mousey - nodey;
+ var p = relY / height;
+
+ var position = ""; // "" <=> forbidden
+ if (DNDMode & dojo.widget.Tree.prototype.DNDModes.ONTO
+ && DNDMode & dojo.widget.Tree.prototype.DNDModes.BETWEEN) {
+ if (p<=0.3) {
+ position = "before";
+ } else if (p<=0.7) {
+ position = "onto";
+ } else {
+ position = "after";
+ }
+ } else if (DNDMode & dojo.widget.Tree.prototype.DNDModes.BETWEEN) {
+ if (p<=0.5) {
+ position = "before";
+ } else {
+ position = "after";
+ }
+ }
+ else if (DNDMode & dojo.widget.Tree.prototype.DNDModes.ONTO) {
+ position = "onto";
+ }
+
+
+ return position;
+ },
+
+
+
+ getTargetParentIndex: function(sourceTreeNode, position) {
+
+ var index = position == "before" ? this.treeNode.getParentIndex() : this.treeNode.getParentIndex()+1;
+ if (this.treeNode.parent === sourceTreeNode.parent
+ && this.treeNode.getParentIndex() > sourceTreeNode.getParentIndex()) {
+ index--; // dragging a node is different for simple move bacause of before-after issues
+ }
+
+ return index;
+ },
+
+
+ onDrop: function(e){
+ // onDragOut will clean position
+
+
+ var position = this.position;
+
+//dojo.debug(position);
+
+ this.onDragOut(e);
+
+ var sourceTreeNode = e.dragObject.treeNode;
+
+ if (!dojo.lang.isObject(sourceTreeNode)) {
+ dojo.raise("TreeNode not found in dragObject")
+ }
+
+ if (position == "onto") {
+ return this.controller.move(sourceTreeNode, this.treeNode, 0);
+ } else {
+ var index = this.getTargetParentIndex(sourceTreeNode, position);
+ return this.controller.move(sourceTreeNode, this.treeNode.parent, index);
+ }
+
+ //dojo.debug('drop2');
+
+
+
+ }
+
+
+});
+
+
+
+dojo.dnd.TreeDNDController = function(treeController) {
+
+ // I use this controller to perform actions
+ this.treeController = treeController;
+
+ this.dragSources = {};
+
+ this.dropTargets = {};
+
+}
+
+dojo.lang.extend(dojo.dnd.TreeDNDController, {
+
+
+ listenTree: function(tree) {
+ //dojo.debug("Listen tree "+tree);
+ dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
+ dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
+ dojo.event.topic.subscribe(tree.eventNames.moveTo, this, "onMoveTo");
+ dojo.event.topic.subscribe(tree.eventNames.addChild, this, "onAddChild");
+ dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
+ dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
+ },
+
+
+ unlistenTree: function(tree) {
+ //dojo.debug("Listen tree "+tree);
+ dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
+ dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
+ dojo.event.topic.unsubscribe(tree.eventNames.moveTo, this, "onMoveTo");
+ dojo.event.topic.unsubscribe(tree.eventNames.addChild, this, "onAddChild");
+ dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
+ dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
+ },
+
+ onTreeDestroy: function(message) {
+ this.unlistenTree(message.source);
+ // I'm not widget so don't use destroy() call and dieWithTree
+ },
+
+ onCreateDOMNode: function(message) {
+ this.registerDNDNode(message.source);
+ },
+
+ onAddChild: function(message) {
+ this.registerDNDNode(message.child);
+ },
+
+ onMoveFrom: function(message) {
+ var _this = this;
+ dojo.lang.forEach(
+ message.child.getDescendants(),
+ function(node) { _this.unregisterDNDNode(node); }
+ );
+ },
+
+ onMoveTo: function(message) {
+ var _this = this;
+ dojo.lang.forEach(
+ message.child.getDescendants(),
+ function(node) { _this.registerDNDNode(node); }
+ );
+ },
+
+ /**
+ * Controller(node model) creates DNDNodes because it passes itself to node for synchroneous drops processing
+ * I can't process DnD with events cause an event can't return result success/false
+ */
+ registerDNDNode: function(node) {
+ if (!node.tree.DNDMode) return;
+
+//dojo.debug("registerDNDNode "+node);
+
+ /* I drag label, not domNode, because large domNodes are very slow to copy and large to drag */
+
+ var source = null;
+ var target = null;
+
+ if (!node.actionIsDisabled(node.actions.MOVE)) {
+ //dojo.debug("reg source")
+ var source = new dojo.dnd.TreeDragSource(node.labelNode, this, node.tree.widgetId, node);
+ this.dragSources[node.widgetId] = source;
+ }
+
+ var target = new dojo.dnd.TreeDropTarget(node.labelNode, this.treeController, node.tree.DNDAcceptTypes, node, node.tree.DNDMode);
+
+ this.dropTargets[node.widgetId] = target;
+
+ },
+
+
+ unregisterDNDNode: function(node) {
+
+ if (this.dragSources[node.widgetId]) {
+ dojo.dnd.dragManager.unregisterDragSource(this.dragSources[node.widgetId]);
+ delete this.dragSources[node.widgetId];
+ }
+
+ if (this.dropTargets[node.widgetId]) {
+ dojo.dnd.dragManager.unregisterDropTarget(this.dropTargets[node.widgetId]);
+ delete this.dropTargets[node.widgetId];
+ }
+ }
+
+
+
+
+
+});
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dnd/TreeDragAndDrop.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dom.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/dom.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/dom.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/dom.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,485 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.dom");
+dojo.require("dojo.lang.array");
+
+dojo.dom.ELEMENT_NODE = 1;
+dojo.dom.ATTRIBUTE_NODE = 2;
+dojo.dom.TEXT_NODE = 3;
+dojo.dom.CDATA_SECTION_NODE = 4;
+dojo.dom.ENTITY_REFERENCE_NODE = 5;
+dojo.dom.ENTITY_NODE = 6;
+dojo.dom.PROCESSING_INSTRUCTION_NODE = 7;
+dojo.dom.COMMENT_NODE = 8;
+dojo.dom.DOCUMENT_NODE = 9;
+dojo.dom.DOCUMENT_TYPE_NODE = 10;
+dojo.dom.DOCUMENT_FRAGMENT_NODE = 11;
+dojo.dom.NOTATION_NODE = 12;
+
+dojo.dom.dojoml = "http://www.dojotoolkit.org/2004/dojoml";
+
+/**
+ * comprehensive list of XML namespaces
+**/
+dojo.dom.xmlns = {
+ svg : "http://www.w3.org/2000/svg",
+ smil : "http://www.w3.org/2001/SMIL20/",
+ mml : "http://www.w3.org/1998/Math/MathML",
+ cml : "http://www.xml-cml.org",
+ xlink : "http://www.w3.org/1999/xlink",
+ xhtml : "http://www.w3.org/1999/xhtml",
+ xul : "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
+ xbl : "http://www.mozilla.org/xbl",
+ fo : "http://www.w3.org/1999/XSL/Format",
+ xsl : "http://www.w3.org/1999/XSL/Transform",
+ xslt : "http://www.w3.org/1999/XSL/Transform",
+ xi : "http://www.w3.org/2001/XInclude",
+ xforms : "http://www.w3.org/2002/01/xforms",
+ saxon : "http://icl.com/saxon",
+ xalan : "http://xml.apache.org/xslt",
+ xsd : "http://www.w3.org/2001/XMLSchema",
+ dt: "http://www.w3.org/2001/XMLSchema-datatypes",
+ xsi : "http://www.w3.org/2001/XMLSchema-instance",
+ rdf : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ rdfs : "http://www.w3.org/2000/01/rdf-schema#",
+ dc : "http://purl.org/dc/elements/1.1/",
+ dcq: "http://purl.org/dc/qualifiers/1.0",
+ "soap-env" : "http://schemas.xmlsoap.org/soap/envelope/",
+ wsdl : "http://schemas.xmlsoap.org/wsdl/",
+ AdobeExtensions : "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
+};
+
+dojo.dom.isNode = function(wh){
+ if(typeof Element == "object") {
+ try {
+ return wh instanceof Element;
+ } catch(E) {}
+ } else {
+ // best-guess
+ return wh && !isNaN(wh.nodeType);
+ }
+}
+
+dojo.dom.getTagName = function(node){
+ dojo.deprecated("dojo.dom.getTagName", "use node.tagName instead", "0.4");
+
+ var tagName = node.tagName;
+ if(tagName.substr(0,5).toLowerCase()!="dojo:"){
+
+ if(tagName.substr(0,4).toLowerCase()=="dojo"){
+ // FIXME: this assuumes tag names are always lower case
+ return "dojo:" + tagName.substring(4).toLowerCase();
+ }
+
+ // allow lower-casing
+ var djt = node.getAttribute("dojoType")||node.getAttribute("dojotype");
+ if(djt){
+ return "dojo:"+djt.toLowerCase();
+ }
+
+ if((node.getAttributeNS)&&(node.getAttributeNS(this.dojoml,"type"))){
+ return "dojo:" + node.getAttributeNS(this.dojoml,"type").toLowerCase();
+ }
+ try{
+ // FIXME: IE really really doesn't like this, so we squelch
+ // errors for it
+ djt = node.getAttribute("dojo:type");
+ }catch(e){ /* FIXME: log? */ }
+ if(djt){
+ return "dojo:"+djt.toLowerCase();
+ }
+
+ if((!dj_global["djConfig"])||(!djConfig["ignoreClassNames"])){
+ // FIXME: should we make this optionally enabled via djConfig?
+ var classes = node.className||node.getAttribute("class");
+ // FIXME: following line, without check for existence of classes.indexOf
+ // breaks firefox 1.5's svg widgets
+ if((classes)&&(classes.indexOf)&&(classes.indexOf("dojo-") != -1)){
+ var aclasses = classes.split(" ");
+ for(var x=0; x<aclasses.length; x++){
+ if((aclasses[x].length>5)&&(aclasses[x].indexOf("dojo-")>=0)){
+ return "dojo:"+aclasses[x].substr(5).toLowerCase();
+ }
+ }
+ }
+ }
+
+ }
+ return tagName.toLowerCase();
+}
+
+dojo.dom.getUniqueId = function(){
+ do {
+ var id = "dj_unique_" + (++arguments.callee._idIncrement);
+ }while(document.getElementById(id));
+ return id;
+}
+dojo.dom.getUniqueId._idIncrement = 0;
+
+dojo.dom.firstElement = dojo.dom.getFirstChildElement = function(parentNode, tagName){
+ var node = parentNode.firstChild;
+ while(node && node.nodeType != dojo.dom.ELEMENT_NODE){
+ node = node.nextSibling;
+ }
+ if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
+ node = dojo.dom.nextElement(node, tagName);
+ }
+ return node;
+}
+
+dojo.dom.lastElement = dojo.dom.getLastChildElement = function(parentNode, tagName){
+ var node = parentNode.lastChild;
+ while(node && node.nodeType != dojo.dom.ELEMENT_NODE) {
+ node = node.previousSibling;
+ }
+ if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
+ node = dojo.dom.prevElement(node, tagName);
+ }
+ return node;
+}
+
+dojo.dom.nextElement = dojo.dom.getNextSiblingElement = function(node, tagName){
+ if(!node) { return null; }
+ do {
+ node = node.nextSibling;
+ } while(node && node.nodeType != dojo.dom.ELEMENT_NODE);
+
+ if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+ return dojo.dom.nextElement(node, tagName);
+ }
+ return node;
+}
+
+dojo.dom.prevElement = dojo.dom.getPreviousSiblingElement = function(node, tagName){
+ if(!node) { return null; }
+ if(tagName) { tagName = tagName.toLowerCase(); }
+ do {
+ node = node.previousSibling;
+ } while(node && node.nodeType != dojo.dom.ELEMENT_NODE);
+
+ if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
+ return dojo.dom.prevElement(node, tagName);
+ }
+ return node;
+}
+
+// TODO: hmph
+/*this.forEachChildTag = function(node, unaryFunc) {
+ var child = this.getFirstChildTag(node);
+ while(child) {
+ if(unaryFunc(child) == "break") { break; }
+ child = this.getNextSiblingTag(child);
+ }
+}*/
+
+dojo.dom.moveChildren = function(srcNode, destNode, trim){
+ var count = 0;
+ if(trim) {
+ while(srcNode.hasChildNodes() &&
+ srcNode.firstChild.nodeType == dojo.dom.TEXT_NODE) {
+ srcNode.removeChild(srcNode.firstChild);
+ }
+ while(srcNode.hasChildNodes() &&
+ srcNode.lastChild.nodeType == dojo.dom.TEXT_NODE) {
+ srcNode.removeChild(srcNode.lastChild);
+ }
+ }
+ while(srcNode.hasChildNodes()){
+ destNode.appendChild(srcNode.firstChild);
+ count++;
+ }
+ return count;
+}
+
+dojo.dom.copyChildren = function(srcNode, destNode, trim){
+ var clonedNode = srcNode.cloneNode(true);
+ return this.moveChildren(clonedNode, destNode, trim);
+}
+
+dojo.dom.removeChildren = function(node){
+ var count = node.childNodes.length;
+ while(node.hasChildNodes()){ node.removeChild(node.firstChild); }
+ return count;
+}
+
+dojo.dom.replaceChildren = function(node, newChild){
+ // FIXME: what if newChild is an array-like object?
+ dojo.dom.removeChildren(node);
+ node.appendChild(newChild);
+}
+
+dojo.dom.removeNode = function(node){
+ if(node && node.parentNode){
+ // return a ref to the removed child
+ return node.parentNode.removeChild(node);
+ }
+}
+
+dojo.dom.getAncestors = function(node, filterFunction, returnFirstHit) {
+ var ancestors = [];
+ var isFunction = dojo.lang.isFunction(filterFunction);
+ while(node) {
+ if (!isFunction || filterFunction(node)) {
+ ancestors.push(node);
+ }
+ if (returnFirstHit && ancestors.length > 0) { return ancestors[0]; }
+
+ node = node.parentNode;
+ }
+ if (returnFirstHit) { return null; }
+ return ancestors;
+}
+
+dojo.dom.getAncestorsByTag = function(node, tag, returnFirstHit) {
+ tag = tag.toLowerCase();
+ return dojo.dom.getAncestors(node, function(el){
+ return ((el.tagName)&&(el.tagName.toLowerCase() == tag));
+ }, returnFirstHit);
+}
+
+dojo.dom.getFirstAncestorByTag = function(node, tag) {
+ return dojo.dom.getAncestorsByTag(node, tag, true);
+}
+
+dojo.dom.isDescendantOf = function(node, ancestor, guaranteeDescendant){
+ // guaranteeDescendant allows us to be a "true" isDescendantOf function
+ if(guaranteeDescendant && node) { node = node.parentNode; }
+ while(node) {
+ if(node == ancestor){ return true; }
+ node = node.parentNode;
+ }
+ return false;
+}
+
+dojo.dom.innerXML = function(node){
+ if(node.innerXML){
+ return node.innerXML;
+ }else if (node.xml){
+ return node.xml;
+ }else if(typeof XMLSerializer != "undefined"){
+ return (new XMLSerializer()).serializeToString(node);
+ }
+}
+
+dojo.dom.createDocument = function(){
+ var doc = null;
+
+ if(!dj_undef("ActiveXObject")){
+ var prefixes = [ "MSXML2", "Microsoft", "MSXML", "MSXML3" ];
+ for(var i = 0; i<prefixes.length; i++){
+ try{
+ doc = new ActiveXObject(prefixes[i]+".XMLDOM");
+ }catch(e){ /* squelch */ };
+
+ if(doc){ break; }
+ }
+ }else if((document.implementation)&&
+ (document.implementation.createDocument)){
+ doc = document.implementation.createDocument("", "", null);
+ }
+
+ return doc;
+}
+
+dojo.dom.createDocumentFromText = function(str, mimetype){
+ if(!mimetype){ mimetype = "text/xml"; }
+ if(!dj_undef("DOMParser")){
+ var parser = new DOMParser();
+ return parser.parseFromString(str, mimetype);
+ }else if(!dj_undef("ActiveXObject")){
+ var domDoc = dojo.dom.createDocument();
+ if(domDoc){
+ domDoc.async = false;
+ domDoc.loadXML(str);
+ return domDoc;
+ }else{
+ dojo.debug("toXml didn't work?");
+ }
+ /*
+ }else if((dojo.render.html.capable)&&(dojo.render.html.safari)){
+ // FIXME: this doesn't appear to work!
+ // from: http://web-graphics.com/mtarchive/001606.php
+ // var xml = '<?xml version="1.0"?>'+str;
+ var mtype = "text/xml";
+ var xml = '<?xml version="1.0"?>'+str;
+ var url = "data:"+mtype+";charset=utf-8,"+encodeURIComponent(xml);
+ var req = new XMLHttpRequest();
+ req.open("GET", url, false);
+ req.overrideMimeType(mtype);
+ req.send(null);
+ return req.responseXML;
+ */
+ }else if(document.createElement){
+ // FIXME: this may change all tags to uppercase!
+ var tmp = document.createElement("xml");
+ tmp.innerHTML = str;
+ if(document.implementation && document.implementation.createDocument) {
+ var xmlDoc = document.implementation.createDocument("foo", "", null);
+ for(var i = 0; i < tmp.childNodes.length; i++) {
+ xmlDoc.importNode(tmp.childNodes.item(i), true);
+ }
+ return xmlDoc;
+ }
+ // FIXME: probably not a good idea to have to return an HTML fragment
+ // FIXME: the tmp.doc.firstChild is as tested from IE, so it may not
+ // work that way across the board
+ return ((tmp.document)&&
+ (tmp.document.firstChild ? tmp.document.firstChild : tmp));
+ }
+ return null;
+}
+
+dojo.dom.prependChild = function(node, parent) {
+ if(parent.firstChild) {
+ parent.insertBefore(node, parent.firstChild);
+ } else {
+ parent.appendChild(node);
+ }
+ return true;
+}
+
+dojo.dom.insertBefore = function(node, ref, force){
+ if (force != true &&
+ (node === ref || node.nextSibling === ref)){ return false; }
+ var parent = ref.parentNode;
+ parent.insertBefore(node, ref);
+ return true;
+}
+
+dojo.dom.insertAfter = function(node, ref, force){
+ var pn = ref.parentNode;
+ if(ref == pn.lastChild){
+ if((force != true)&&(node === ref)){
+ return false;
+ }
+ pn.appendChild(node);
+ }else{
+ return this.insertBefore(node, ref.nextSibling, force);
+ }
+ return true;
+}
+
+dojo.dom.insertAtPosition = function(node, ref, position){
+ if((!node)||(!ref)||(!position)){ return false; }
+ switch(position.toLowerCase()){
+ case "before":
+ return dojo.dom.insertBefore(node, ref);
+ case "after":
+ return dojo.dom.insertAfter(node, ref);
+ case "first":
+ if(ref.firstChild){
+ return dojo.dom.insertBefore(node, ref.firstChild);
+ }else{
+ ref.appendChild(node);
+ return true;
+ }
+ break;
+ default: // aka: last
+ ref.appendChild(node);
+ return true;
+ }
+}
+
+dojo.dom.insertAtIndex = function(node, containingNode, insertionIndex){
+ var siblingNodes = containingNode.childNodes;
+
+ // if there aren't any kids yet, just add it to the beginning
+
+ if (!siblingNodes.length){
+ containingNode.appendChild(node);
+ return true;
+ }
+
+ // otherwise we need to walk the childNodes
+ // and find our spot
+
+ var after = null;
+
+ for(var i=0; i<siblingNodes.length; i++){
+
+ var sibling_index = siblingNodes.item(i)["getAttribute"] ? parseInt(siblingNodes.item(i).getAttribute("dojoinsertionindex")) : -1;
+
+ if (sibling_index < insertionIndex){
+ after = siblingNodes.item(i);
+ }
+ }
+
+ if (after){
+ // add it after the node in {after}
+
+ return dojo.dom.insertAfter(node, after);
+ }else{
+ // add it to the start
+
+ return dojo.dom.insertBefore(node, siblingNodes.item(0));
+ }
+}
+
+/**
+ * implementation of the DOM Level 3 attribute.
+ *
+ * @param node The node to scan for text
+ * @param text Optional, set the text to this value.
+ */
+dojo.dom.textContent = function(node, text){
+ if (text) {
+ dojo.dom.replaceChildren(node, document.createTextNode(text));
+ return text;
+ } else {
+ var _result = "";
+ if (node == null) { return _result; }
+ for (var i = 0; i < node.childNodes.length; i++) {
+ switch (node.childNodes[i].nodeType) {
+ case 1: // ELEMENT_NODE
+ case 5: // ENTITY_REFERENCE_NODE
+ _result += dojo.dom.textContent(node.childNodes[i]);
+ break;
+ case 3: // TEXT_NODE
+ case 2: // ATTRIBUTE_NODE
+ case 4: // CDATA_SECTION_NODE
+ _result += node.childNodes[i].nodeValue;
+ break;
+ default:
+ break;
+ }
+ }
+ return _result;
+ }
+}
+
+dojo.dom.collectionToArray = function(collection){
+ dojo.deprecated("dojo.dom.collectionToArray", "use dojo.lang.toArray instead", "0.4");
+ return dojo.lang.toArray(collection);
+}
+
+dojo.dom.hasParent = function (node) {
+ return node && node.parentNode && dojo.dom.isNode(node.parentNode);
+}
+
+/**
+ * Determines if node has any of the provided tag names and
+ * returns the tag name that matches, empty string otherwise.
+ *
+ * Examples:
+ *
+ * myFooNode = <foo />
+ * isTag(myFooNode, "foo"); // returns "foo"
+ * isTag(myFooNode, "bar"); // returns ""
+ * isTag(myFooNode, "FOO"); // returns ""
+ * isTag(myFooNode, "hey", "foo", "bar"); // returns "foo"
+**/
+dojo.dom.isTag = function(node /* ... */) {
+ if(node && node.tagName) {
+ var arr = dojo.lang.toArray(arguments, 1);
+ return arr[ dojo.lang.find(node.tagName, arr) ] || "";
+ }
+ return "";
+}
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/dom.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/framework/src/js/dojo/src/event.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/dojo/src/event.js?rev=413300&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/dojo/src/event.js (added)
+++ tapestry/tapestry4/trunk/framework/src/js/dojo/src/event.js Sat Jun 10 06:59:28 2006
@@ -0,0 +1,575 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.event");
+
+dojo.require("dojo.lang.array");
+dojo.require("dojo.lang.extras");
+dojo.require("dojo.lang.func");
+
+dojo.event = new function(){
+ this.canTimeout = dojo.lang.isFunction(dj_global["setTimeout"])||dojo.lang.isAlien(dj_global["setTimeout"]);
+
+ // FIXME: where should we put this method (not here!)?
+ function interpolateArgs(args, searchForNames){
+ var dl = dojo.lang;
+ var ao = {
+ srcObj: dj_global,
+ srcFunc: null,
+ adviceObj: dj_global,
+ adviceFunc: null,
+ aroundObj: null,
+ aroundFunc: null,
+ adviceType: (args.length>2) ? args[0] : "after",
+ precedence: "last",
+ once: false,
+ delay: null,
+ rate: 0,
+ adviceMsg: false
+ };
+
+ switch(args.length){
+ case 0: return;
+ case 1: return;
+ case 2:
+ ao.srcFunc = args[0];
+ ao.adviceFunc = args[1];
+ break;
+ case 3:
+ if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isString(args[2]))){
+ ao.adviceType = "after";
+ ao.srcObj = args[0];
+ ao.srcFunc = args[1];
+ ao.adviceFunc = args[2];
+ }else if((dl.isString(args[1]))&&(dl.isString(args[2]))){
+ ao.srcFunc = args[1];
+ ao.adviceFunc = args[2];
+ }else if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isFunction(args[2]))){
+ ao.adviceType = "after";
+ ao.srcObj = args[0];
+ ao.srcFunc = args[1];
+ var tmpName = dl.nameAnonFunc(args[2], ao.adviceObj, searchForNames);
+ ao.adviceFunc = tmpName;
+ }else if((dl.isFunction(args[0]))&&(dl.isObject(args[1]))&&(dl.isString(args[2]))){
+ ao.adviceType = "after";
+ ao.srcObj = dj_global;
+ var tmpName = dl.nameAnonFunc(args[0], ao.srcObj, searchForNames);
+ ao.srcFunc = tmpName;
+ ao.adviceObj = args[1];
+ ao.adviceFunc = args[2];
+ }
+ break;
+ case 4:
+ if((dl.isObject(args[0]))&&(dl.isObject(args[2]))){
+ // we can assume that we've got an old-style "connect" from
+ // the sigslot school of event attachment. We therefore
+ // assume after-advice.
+ ao.adviceType = "after";
+ ao.srcObj = args[0];
+ ao.srcFunc = args[1];
+ ao.adviceObj = args[2];
+ ao.adviceFunc = args[3];
+ }else if((dl.isString(args[0]))&&(dl.isString(args[1]))&&(dl.isObject(args[2]))){
+ ao.adviceType = args[0];
+ ao.srcObj = dj_global;
+ ao.srcFunc = args[1];
+ ao.adviceObj = args[2];
+ ao.adviceFunc = args[3];
+ }else if((dl.isString(args[0]))&&(dl.isFunction(args[1]))&&(dl.isObject(args[2]))){
+ ao.adviceType = args[0];
+ ao.srcObj = dj_global;
+ var tmpName = dl.nameAnonFunc(args[1], dj_global, searchForNames);
+ ao.srcFunc = tmpName;
+ ao.adviceObj = args[2];
+ ao.adviceFunc = args[3];
+ }else if((dl.isString(args[0]))&&(dl.isObject(args[1]))&&(dl.isString(args[2]))&&(dl.isFunction(args[3]))){
+ ao.srcObj = args[1];
+ ao.srcFunc = args[2];
+ var tmpName = dl.nameAnonFunc(args[3], dj_global, searchForNames);
+ ao.adviceObj = dj_global;
+ ao.adviceFunc = tmpName;
+ }else if(dl.isObject(args[1])){
+ ao.srcObj = args[1];
+ ao.srcFunc = args[2];
+ ao.adviceObj = dj_global;
+ ao.adviceFunc = args[3];
+ }else if(dl.isObject(args[2])){
+ ao.srcObj = dj_global;
+ ao.srcFunc = args[1];
+ ao.adviceObj = args[2];
+ ao.adviceFunc = args[3];
+ }else{
+ ao.srcObj = ao.adviceObj = ao.aroundObj = dj_global;
+ ao.srcFunc = args[1];
+ ao.adviceFunc = args[2];
+ ao.aroundFunc = args[3];
+ }
+ break;
+ case 6:
+ ao.srcObj = args[1];
+ ao.srcFunc = args[2];
+ ao.adviceObj = args[3]
+ ao.adviceFunc = args[4];
+ ao.aroundFunc = args[5];
+ ao.aroundObj = dj_global;
+ break;
+ default:
+ ao.srcObj = args[1];
+ ao.srcFunc = args[2];
+ ao.adviceObj = args[3]
+ ao.adviceFunc = args[4];
+ ao.aroundObj = args[5];
+ ao.aroundFunc = args[6];
+ ao.once = args[7];
+ ao.delay = args[8];
+ ao.rate = args[9];
+ ao.adviceMsg = args[10];
+ break;
+ }
+
+ if(dl.isFunction(ao.aroundFunc)){
+ var tmpName = dl.nameAnonFunc(ao.aroundFunc, ao.aroundObj, searchForNames);
+ ao.aroundFunc = tmpName;
+ }
+
+ if(dl.isFunction(ao.srcFunc)){
+ ao.srcFunc = dl.getNameInObj(ao.srcObj, ao.srcFunc);
+ }
+
+ if(dl.isFunction(ao.adviceFunc)){
+ ao.adviceFunc = dl.getNameInObj(ao.adviceObj, ao.adviceFunc);
+ }
+
+ if((ao.aroundObj)&&(dl.isFunction(ao.aroundFunc))){
+ ao.aroundFunc = dl.getNameInObj(ao.aroundObj, ao.aroundFunc);
+ }
+
+ if(!ao.srcObj){
+ dojo.raise("bad srcObj for srcFunc: "+ao.srcFunc);
+ }
+ if(!ao.adviceObj){
+ dojo.raise("bad adviceObj for adviceFunc: "+ao.adviceFunc);
+ }
+ return ao;
+ }
+
+ this.connect = function(){
+ if(arguments.length == 1){
+ var ao = arguments[0];
+ }else{
+ var ao = interpolateArgs(arguments, true);
+ }
+
+ if(dojo.lang.isArray(ao.srcObj) && ao.srcObj!=""){
+ var tmpAO = {};
+ for(var x in ao){
+ tmpAO[x] = ao[x];
+ }
+ var mjps = [];
+ dojo.lang.forEach(ao.srcObj, function(src){
+ if((dojo.render.html.capable)&&(dojo.lang.isString(src))){
+ src = dojo.byId(src);
+ // dojo.debug(src);
+ }
+ tmpAO.srcObj = src;
+ // dojo.debug(tmpAO.srcObj, tmpAO.srcFunc);
+ // dojo.debug(tmpAO.adviceObj, tmpAO.adviceFunc);
+ mjps.push(dojo.event.connect.call(dojo.event, tmpAO));
+ });
+ return mjps;
+ }
+
+ // FIXME: just doing a "getForMethod()" seems to be enough to put this into infinite recursion!!
+ var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
+ if(ao.adviceFunc){
+ var mjp2 = dojo.event.MethodJoinPoint.getForMethod(ao.adviceObj, ao.adviceFunc);
+ }
+
+ mjp.kwAddAdvice(ao);
+
+ return mjp; // advanced users might want to fsck w/ the join point
+ // manually
+ }
+
+ this.log = function(a1, a2){
+ var kwArgs;
+ if((arguments.length == 1)&&(typeof a1 == "object")){
+ kwArgs = a1;
+ }else{
+ kwArgs = {
+ srcObj: a1,
+ srcFunc: a2
+ };
+ }
+ kwArgs.adviceFunc = function(){
+ var argsStr = [];
+ for(var x=0; x<arguments.length; x++){
+ argsStr.push(arguments[x]);
+ }
+ dojo.debug("("+kwArgs.srcObj+")."+kwArgs.srcFunc, ":", argsStr.join(", "));
+ }
+ this.kwConnect(kwArgs);
+ }
+
+ this.connectBefore = function(){
+ var args = ["before"];
+ for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
+ return this.connect.apply(this, args);
+ }
+
+ this.connectAround = function(){
+ var args = ["around"];
+ for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
+ return this.connect.apply(this, args);
+ }
+
+ this.connectOnce = function(){
+ var ao = interpolateArgs(arguments, true);
+ ao.once = true;
+ return this.connect(ao);
+ }
+
+ this._kwConnectImpl = function(kwArgs, disconnect){
+ var fn = (disconnect) ? "disconnect" : "connect";
+ if(typeof kwArgs["srcFunc"] == "function"){
+ kwArgs.srcObj = kwArgs["srcObj"]||dj_global;
+ var tmpName = dojo.lang.nameAnonFunc(kwArgs.srcFunc, kwArgs.srcObj, true);
+ kwArgs.srcFunc = tmpName;
+ }
+ if(typeof kwArgs["adviceFunc"] == "function"){
+ kwArgs.adviceObj = kwArgs["adviceObj"]||dj_global;
+ var tmpName = dojo.lang.nameAnonFunc(kwArgs.adviceFunc, kwArgs.adviceObj, true);
+ kwArgs.adviceFunc = tmpName;
+ }
+ return dojo.event[fn]( (kwArgs["type"]||kwArgs["adviceType"]||"after"),
+ kwArgs["srcObj"]||dj_global,
+ kwArgs["srcFunc"],
+ kwArgs["adviceObj"]||kwArgs["targetObj"]||dj_global,
+ kwArgs["adviceFunc"]||kwArgs["targetFunc"],
+ kwArgs["aroundObj"],
+ kwArgs["aroundFunc"],
+ kwArgs["once"],
+ kwArgs["delay"],
+ kwArgs["rate"],
+ kwArgs["adviceMsg"]||false );
+ }
+
+ this.kwConnect = function(kwArgs){
+ return this._kwConnectImpl(kwArgs, false);
+
+ }
+
+ this.disconnect = function(){
+ var ao = interpolateArgs(arguments, true);
+ if(!ao.adviceFunc){ return; } // nothing to disconnect
+ var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
+ return mjp.removeAdvice(ao.adviceObj, ao.adviceFunc, ao.adviceType, ao.once);
+ }
+
+ this.kwDisconnect = function(kwArgs){
+ return this._kwConnectImpl(kwArgs, true);
+ }
+}
+
+// exactly one of these is created whenever a method with a joint point is run,
+// if there is at least one 'around' advice.
+dojo.event.MethodInvocation = function(join_point, obj, args) {
+ this.jp_ = join_point;
+ this.object = obj;
+ this.args = [];
+ for(var x=0; x<args.length; x++){
+ this.args[x] = args[x];
+ }
+ // the index of the 'around' that is currently being executed.
+ this.around_index = -1;
+}
+
+dojo.event.MethodInvocation.prototype.proceed = function() {
+ this.around_index++;
+ if(this.around_index >= this.jp_.around.length){
+ return this.jp_.object[this.jp_.methodname].apply(this.jp_.object, this.args);
+ // return this.jp_.run_before_after(this.object, this.args);
+ }else{
+ var ti = this.jp_.around[this.around_index];
+ var mobj = ti[0]||dj_global;
+ var meth = ti[1];
+ return mobj[meth].call(mobj, this);
+ }
+}
+
+
+dojo.event.MethodJoinPoint = function(obj, methname){
+ this.object = obj||dj_global;
+ this.methodname = methname;
+ this.methodfunc = this.object[methname];
+ this.before = [];
+ this.after = [];
+ this.around = [];
+}
+
+dojo.event.MethodJoinPoint.getForMethod = function(obj, methname) {
+ // if(!(methname in obj)){
+ if(!obj){ obj = dj_global; }
+ if(!obj[methname]){
+ // supply a do-nothing method implementation
+ obj[methname] = function(){};
+ if(!obj[methname]){
+ // e.g. cannot add to inbuilt objects in IE6
+ dojo.raise("Cannot set do-nothing method on that object "+methname);
+ }
+ }else if((!dojo.lang.isFunction(obj[methname]))&&(!dojo.lang.isAlien(obj[methname]))){
+ return null; // FIXME: should we throw an exception here instead?
+ }
+ // we hide our joinpoint instance in obj[methname + '$joinpoint']
+ var jpname = methname + "$joinpoint";
+ var jpfuncname = methname + "$joinpoint$method";
+ var joinpoint = obj[jpname];
+ if(!joinpoint){
+ var isNode = false;
+ if(dojo.event["browser"]){
+ if( (obj["attachEvent"])||
+ (obj["nodeType"])||
+ (obj["addEventListener"]) ){
+ isNode = true;
+ dojo.event.browser.addClobberNodeAttrs(obj, [jpname, jpfuncname, methname]);
+ }
+ }
+ var origArity = obj[methname].length;
+ obj[jpfuncname] = obj[methname];
+ // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, methname);
+ joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, jpfuncname);
+ obj[methname] = function(){
+ var args = [];
+
+ if((isNode)&&(!arguments.length)){
+ var evt = null;
+ try{
+ if(obj.ownerDocument){
+ evt = obj.ownerDocument.parentWindow.event;
+ }else if(obj.documentElement){
+ evt = obj.documentElement.ownerDocument.parentWindow.event;
+ }else{
+ evt = window.event;
+ }
+ }catch(e){
+ evt = window.event;
+ }
+
+ if(evt){
+ args.push(dojo.event.browser.fixEvent(evt, this));
+ }
+ }else{
+ for(var x=0; x<arguments.length; x++){
+ if((x==0)&&(isNode)&&(dojo.event.browser.isEvent(arguments[x]))){
+ args.push(dojo.event.browser.fixEvent(arguments[x], this));
+ }else{
+ args.push(arguments[x]);
+ }
+ }
+ }
+ // return joinpoint.run.apply(joinpoint, arguments);
+ return joinpoint.run.apply(joinpoint, args);
+ }
+ obj[methname].__preJoinArity = origArity;
+ }
+ return joinpoint;
+}
+
+dojo.lang.extend(dojo.event.MethodJoinPoint, {
+ unintercept: function(){
+ this.object[this.methodname] = this.methodfunc;
+ this.before = [];
+ this.after = [];
+ this.around = [];
+ },
+
+ disconnect: dojo.lang.forward("unintercept"),
+
+ run: function() {
+ var obj = this.object||dj_global;
+ var args = arguments;
+
+ // optimization. We only compute once the array version of the arguments
+ // pseudo-arr in order to prevent building it each time advice is unrolled.
+ var aargs = [];
+ for(var x=0; x<args.length; x++){
+ aargs[x] = args[x];
+ }
+
+ var unrollAdvice = function(marr){
+ if(!marr){
+ dojo.debug("Null argument to unrollAdvice()");
+ return;
+ }
+
+ var callObj = marr[0]||dj_global;
+ var callFunc = marr[1];
+
+ if(!callObj[callFunc]){
+ dojo.raise("function \"" + callFunc + "\" does not exist on \"" + callObj + "\"");
+ }
+
+ var aroundObj = marr[2]||dj_global;
+ var aroundFunc = marr[3];
+ var msg = marr[6];
+ var undef;
+
+ var to = {
+ args: [],
+ jp_: this,
+ object: obj,
+ proceed: function(){
+ return callObj[callFunc].apply(callObj, to.args);
+ }
+ };
+ to.args = aargs;
+
+ var delay = parseInt(marr[4]);
+ var hasDelay = ((!isNaN(delay))&&(marr[4]!==null)&&(typeof marr[4] != "undefined"));
+ if(marr[5]){
+ var rate = parseInt(marr[5]);
+ var cur = new Date();
+ var timerSet = false;
+ if((marr["last"])&&((cur-marr.last)<=rate)){
+ if(dojo.event.canTimeout){
+ if(marr["delayTimer"]){
+ clearTimeout(marr.delayTimer);
+ }
+ var tod = parseInt(rate*2); // is rate*2 naive?
+ var mcpy = dojo.lang.shallowCopy(marr);
+ marr.delayTimer = setTimeout(function(){
+ // FIXME: on IE at least, event objects from the
+ // browser can go out of scope. How (or should?) we
+ // deal with it?
+ mcpy[5] = 0;
+ unrollAdvice(mcpy);
+ }, tod);
+ }
+ return;
+ }else{
+ marr.last = cur;
+ }
+ }
+
+ // FIXME: need to enforce rates for a connection here!
+
+ if(aroundFunc){
+ // NOTE: around advice can't delay since we might otherwise depend
+ // on execution order!
+ aroundObj[aroundFunc].call(aroundObj, to);
+ }else{
+ // var tmjp = dojo.event.MethodJoinPoint.getForMethod(obj, methname);
+ if((hasDelay)&&((dojo.render.html)||(dojo.render.svg))){ // FIXME: the render checks are grotty!
+ dj_global["setTimeout"](function(){
+ if(msg){
+ callObj[callFunc].call(callObj, to);
+ }else{
+ callObj[callFunc].apply(callObj, args);
+ }
+ }, delay);
+ }else{ // many environments can't support delay!
+ if(msg){
+ callObj[callFunc].call(callObj, to);
+ }else{
+ callObj[callFunc].apply(callObj, args);
+ }
+ }
+ }
+ }
+
+ if(this.before.length>0){
+ dojo.lang.forEach(this.before, unrollAdvice);
+ }
+
+ var result;
+ if(this.around.length>0){
+ var mi = new dojo.event.MethodInvocation(this, obj, args);
+ result = mi.proceed();
+ }else if(this.methodfunc){
+ result = this.object[this.methodname].apply(this.object, args);
+ }
+
+ if(this.after.length>0){
+ dojo.lang.forEach(this.after, unrollAdvice);
+ }
+
+ return (this.methodfunc) ? result : null;
+ },
+
+ getArr: function(kind){
+ var arr = this.after;
+ // FIXME: we should be able to do this through props or Array.in()
+ if((typeof kind == "string")&&(kind.indexOf("before")!=-1)){
+ arr = this.before;
+ }else if(kind=="around"){
+ arr = this.around;
+ }
+ return arr;
+ },
+
+ kwAddAdvice: function(args){
+ this.addAdvice( args["adviceObj"], args["adviceFunc"],
+ args["aroundObj"], args["aroundFunc"],
+ args["adviceType"], args["precedence"],
+ args["once"], args["delay"], args["rate"],
+ args["adviceMsg"]);
+ },
+
+ addAdvice: function( thisAdviceObj, thisAdvice,
+ thisAroundObj, thisAround,
+ advice_kind, precedence,
+ once, delay, rate, asMessage){
+ var arr = this.getArr(advice_kind);
+ if(!arr){
+ dojo.raise("bad this: " + this);
+ }
+
+ var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage];
+
+ if(once){
+ if(this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr) >= 0){
+ return;
+ }
+ }
+
+ if(precedence == "first"){
+ arr.unshift(ao);
+ }else{
+ arr.push(ao);
+ }
+ },
+
+ hasAdvice: function(thisAdviceObj, thisAdvice, advice_kind, arr){
+ if(!arr){ arr = this.getArr(advice_kind); }
+ var ind = -1;
+ for(var x=0; x<arr.length; x++){
+ var aao = (typeof thisAdvice == "object") ? (new String(thisAdvice)).toString() : thisAdvice;
+ var a1o = (typeof arr[x][1] == "object") ? (new String(arr[x][1])).toString() : arr[x][1];
+ if((arr[x][0] == thisAdviceObj)&&(a1o == aao)){
+ ind = x;
+ }
+ }
+ return ind;
+ },
+
+ removeAdvice: function(thisAdviceObj, thisAdvice, advice_kind, once){
+ var arr = this.getArr(advice_kind);
+ var ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
+ if(ind == -1){
+ return false;
+ }
+ while(ind != -1){
+ arr.splice(ind, 1);
+ if(once){ break; }
+ ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
+ }
+ return true;
+ }
+});
Propchange: tapestry/tapestry4/trunk/framework/src/js/dojo/src/event.js
------------------------------------------------------------------------------
svn:eol-style = native