You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/02/01 06:41:23 UTC
svn commit: r373998 [6/23] - in
/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo:
./ src/ src/alg/ src/animation/ src/collections/ src/crypto/ src/data/
src/dnd/ src/event/ src/flash/ src/flash/flash6/ src/flash/flash8/ src/fx/
...
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragManager.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragManager.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragManager.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragManager.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,416 @@
+/*
+ Copyright (c) 2004-2005, 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,
+
+ // 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);
+ }
+ },
+
+ 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);
+ }
+ },
+
+ 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);
+ }
+ },
+
+ 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 != 0) { return; }
+ } else if(e.which != 1) {
+ return;
+ }
+
+ this.mouseDownX = e.clientX;
+ this.mouseDownY = e.clientY;
+
+ var target = e.target.nodeType == dojo.dom.TEXT_NODE ?
+ e.target.parentNode : e.target;
+
+ /*
+ FIXME(algo): I believe that is not a problem any more because of drag tolerance.
+ Anyway, why forbid dragging items by clicking on links inside them ?
+ There are problems with dragging by links in IE, should be solved another way..
+ */
+ // do not start drag involvement if the user is interacting with
+ // a form element.
+ if(dojo.html.isTag(target, "a", "button", "textarea", "input")) {
+ return;
+ }
+
+ // find a selection object, if one is a parent of the source node
+ var ds = this.getDragSource(e);
+ if(!ds){ return; }
+ if(!dojo.lang.inArray(this.selectedSources, ds)){
+ this.selectedSources.push(ds);
+ }
+
+ // 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){
+ this.mouseDownX = null;
+ this.mouseDownY = null;
+ this._dragTriggered = false;
+ var _this = this;
+ 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";
+ tempDragObj.onDragEnd(e);
+ });
+
+ this.selectedSources = [];
+ this.dragObjects = [];
+ this.dragSource = null;
+ if(_this.currentDropTarget) {
+ _this.currentDropTarget.onDropEnd();
+ }
+ }
+ dojo.event.disconnect(document, "onmousemove", this, "onMouseMove");
+ this.currentDropTarget = null;
+ // this.currentDropTargetPoints = 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() {
+ var _this = this;
+
+ 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)
+ });
+
+ //dojo.debug("Cache locations")
+
+ },
+
+ onMouseMove: function(e){
+ var _this = this;
+ // 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.clientX, e.clientY) > this.threshold);
+ if(!this._dragTriggered){ return; }
+ dx = e.clientX-this.mouseDownX;
+ dy = e.clientY-this.mouseDownY;
+ }
+
+ if (this.selectedSources.length == 1) {
+ 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;
+
+ _this.dragObjects.push(tdo);
+ }
+ });
+
+ /* clean previous drop target in dragStart */
+ this.previousDropTarget = null;
+
+ this.cacheTargetLocations();
+ }
+ // FIXME: we need to add dragSources and dragObjects to e
+ for (var i = 0; i < this.dragObjects.length; i++){
+ if(this.dragObjects[i]){ this.dragObjects[i].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.html.toCoordinateArray(this.currentDropTarget.domNode);
+ // 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.forEach(this.dropTargetDimensions, function(tmpDA) {
+ if(_this.isInsideBox(e, tmpDA)){
+ bestBox.target = tmpDA[2];
+ bestBox.points = tmpDA;
+ if(!_this.nestedTargets){ return "break"; }
+ }
+ });
+
+ return bestBox;
+ },
+
+ isInsideBox: function(e, coords){
+ if( (e.clientX > coords[0][0])&&
+ (e.clientX < coords[1][0])&&
+ (e.clientY > coords[0][1])&&
+ (e.clientY < 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");
+})();
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragMove.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragMove.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragMove.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/HtmlDragMove.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,74 @@
+/*
+ Copyright (c) 2004-2005, 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;
+ }
+});
+
+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){
+ delete this.dragClone;
+ },
+
+ onDragStart: function(e){
+ dojo.html.clearSelection();
+
+ this.dragClone = this.domNode;
+
+ this.scrollOffset = {
+ top: dojo.html.getScrollTop(), // document.documentElement.scrollTop,
+ left: dojo.html.getScrollLeft() // document.documentElement.scrollLeft
+ };
+
+ this.dragStartPosition = {top: dojo.style.getAbsoluteY(this.domNode) ,
+ left: dojo.style.getAbsoluteX(this.domNode) };
+
+ this.dragOffset = {top: this.dragStartPosition.top - e.clientY,
+ left: this.dragStartPosition.left - e.clientX};
+
+ if (this.domNode.parentNode.nodeName.toLowerCase() == 'body') {
+ this.parentPosition = {top: 0, left: 0};
+ } else {
+ this.parentPosition = {top: dojo.style.getAbsoluteY(this.domNode.parentNode, true),
+ left: dojo.style.getAbsoluteX(this.domNode.parentNode,true)};
+ }
+
+ this.dragClone.style.position = "absolute";
+
+ if (this.constrainToContainer) {
+ this.constraints = this.getConstraints();
+ }
+ }
+
+});
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/Sortable.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/Sortable.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/Sortable.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/Sortable.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,28 @@
+/*
+ Copyright (c) 2004-2005, 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;
+ }
+
+});
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/TreeDragAndDrop.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/TreeDragAndDrop.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/TreeDragAndDrop.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/TreeDragAndDrop.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,446 @@
+/*
+ Copyright (c) 2004-2005, 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.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 */
+ dojo.lang.forEach(
+ this.dragClone.getElementsByTagName('img'),
+ function(elem) { elem.style.backgroundImage='' }
+ );
+
+ 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(node, syncController, type, treeNode){
+
+ this.treeNode = treeNode;
+ this.controller = syncController; // I will sync-ly process drops
+
+ dojo.dnd.HtmlDropTarget.apply(this, [node, type]);
+
+}
+
+dojo.inherits(dojo.dnd.TreeDropTarget, dojo.dnd.HtmlDropTarget);
+
+dojo.lang.extend(dojo.dnd.TreeDropTarget, {
+
+ autoExpandDelay: 1500,
+ autoExpandTimer: null,
+
+ /**
+ * Check if I can drop sourceTreeNode here
+ * only tree node targets are implemented ATM
+ */
+ onDragOver: function(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;
+ },
+
+
+ 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);
+ },
+
+
+ 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");
+ }
+
+ return true;
+ },
+
+
+ onDragOut: function(e) {
+ this.clearAutoExpandTimer();
+ },
+
+
+ clearAutoExpandTimer: function() {
+ if (this.autoExpandTimer) {
+ clearTimeout(this.autoExpandTimer);
+ delete this.autoExpandTimer;
+ this.autoExpandTimer = null;
+ }
+ },
+
+ onDragMove: function(e, dragObjects){
+ }
+
+
+});
+
+
+dojo.dnd.TreeDropOntoTarget = function(node, syncController, type, treeNode){
+ dojo.dnd.TreeDropTarget.apply(this, arguments);
+}
+
+
+dojo.inherits(dojo.dnd.TreeDropOntoTarget, dojo.dnd.TreeDropTarget);
+
+
+dojo.lang.extend(dojo.dnd.TreeDropOntoTarget, {
+
+
+ accepts: function(dragObjects) {
+ //dojo.debug("TreeDropOntoTarget.accepts")
+
+ var accepts = dojo.dnd.TreeDropTarget.prototype.accepts.apply(this, arguments);
+
+ if (!accepts) return false;
+
+ // checked by parent call
+ var sourceTreeNode = dragObjects[0].treeNode;
+
+ // can't drop parent to child etc
+ accepts = this.controller.canChangeParent(sourceTreeNode, this.treeNode);
+
+ if (!accepts) return false;
+
+ // can't drag to same parent in onto mode
+ if (sourceTreeNode.parent === this.treeNode) {
+ return false;
+ }
+
+
+
+ //dojo.debug("Check2 "+acceptable)
+
+
+ return true;
+
+ },
+
+ onDragOver: function(e) {
+
+ // perform common DnD actions and learn whether the drop acceptable
+ var accepts = dojo.dnd.TreeDropTarget.prototype.onDragOver.apply(this, arguments);
+
+ //dojo.debug("TreeDropOntoTarget.onDragOver accepts:"+accepts)
+
+ if (!accepts) return false;
+
+ // mark current node being dragged into
+ this.treeNode.markSelected();
+
+
+ return true;
+
+ },
+
+ // called for all targets
+ onDragOut: function(e) {
+
+ dojo.dnd.TreeDropTarget.prototype.onDragOut.apply(this, arguments);
+
+ this.treeNode.unMarkSelected();
+ },
+
+
+ // called for accepted objects only
+ onDrop: function(e) {
+
+ this.onDragOut(e);
+
+ var sourceTreeNode = e.dragObject.treeNode;
+
+ return this.controller.processDrop(sourceTreeNode, this.treeNode, 0);
+ }
+
+
+});
+
+
+// .......................................
+
+
+dojo.dnd.TreeDropBetweenTarget = function(node, syncController, type, treeNode){
+ dojo.dnd.TreeDropTarget.apply(this, arguments);
+}
+
+
+dojo.inherits(dojo.dnd.TreeDropBetweenTarget, dojo.dnd.TreeDropTarget);
+
+
+dojo.lang.extend(dojo.dnd.TreeDropBetweenTarget, {
+
+ indicatorPosition: null,
+
+ indicatorStyle: "2px black solid",
+ indicatorVisible: false,
+
+
+ showIndicator: function(position) {
+
+ // do not change style too often, cause of blinking possible
+ if (this.indicatorPosition == position && this.indicatorVisible) {
+ return;
+ }
+
+ //dojo.debug(position)
+
+ this.hideIndicator();
+
+ this.indicatorPosition = position;
+ this.indicatorVisible = true;
+
+ if (position == "before") {
+ this.treeNode.labelNode.style.borderTop = this.indicatorStyle;
+ } else if (position == "after") {
+ this.treeNode.labelNode.style.borderBottom = this.indicatorStyle;
+ }
+
+
+ },
+
+ hideIndicator: function() {
+ this.indicatorVisible = false;
+ this.treeNode.labelNode.style.borderBottom="";
+ this.treeNode.labelNode.style.borderTop="";
+ },
+
+
+
+ // 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 )
+ accepts: function(dragObjects) {
+ //dojo.debug("TreeDropBetweenTarget.accepts")
+
+ var accepts = dojo.dnd.TreeDropTarget.prototype.accepts.apply(this, arguments);
+
+ if (!accepts) return false;
+
+ // checked by parent call
+ var sourceTreeNode = dragObjects[0].treeNode;
+
+ // can't drop parent to child etc
+ accepts = this.controller.canChangeParent(sourceTreeNode, this.treeNode.parent);
+
+ if (!accepts) return false;
+
+
+ //dojo.debug("Check2 "+acceptable)
+
+
+ return true;
+
+ },
+
+
+ acceptsWithPosition: function(sourceNode, position) {
+ return !this.isAdjacentNode(sourceNode, 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;
+ },
+
+
+ /**
+ * Check if I can drop sourceTreeNode here
+ * only tree node targets are implemented ATM
+ *
+ * returns true for nodes different from current node even if they are siblings.
+ */
+ onDragOver: function(e){
+
+ // perform common DnD actions and learn whether the drop acceptable
+ var accepts = dojo.dnd.TreeDropTarget.prototype.onDragOver.apply(this, arguments);
+
+ if (!accepts) return false;
+
+ return true;
+
+ },
+
+ getPosition: function(e) {
+ if (dojo.html.gravity(this.treeNode.labelNode, e) & dojo.html.gravity.NORTH) {
+ var position = "before";
+ } else {
+ var position = "after";
+ }
+
+ return position;
+ },
+
+
+ // only called if drop acceptable
+ onDragMove: function(e, dragObjects){
+
+ //dojo.debugShallow(dragObjects);
+
+ var position = this.getPosition(e);
+
+ var sourceTreeNode = dragObjects[0].treeNode;
+
+ if (this.acceptsWithPosition(sourceTreeNode, position)) {
+ this.showIndicator(position);
+ }
+
+ },
+
+ onDragOut: function(e) {
+ //dojo.debug("Out");
+
+ dojo.dnd.TreeDropTarget.prototype.onDragOut.apply(this, arguments);
+
+ this.hideIndicator();
+
+ //return dojo.dnd.HtmlDropTarget.prototype.onDragOut.call(this, e);
+ },
+
+
+ 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 changeParent bacause of before-after issues
+ }
+
+ return index;
+ },
+
+
+ onDrop: function(e){
+ this.onDragOut(e);
+
+ //dojo.debug('drop');
+
+ var sourceTreeNode = e.dragObject.treeNode;
+
+ if (!dojo.lang.isObject(sourceTreeNode)) {
+ dojo.raise("TreeNode not found in dragObject")
+ }
+
+
+ if (!this.acceptsWithPosition(sourceTreeNode, this.indicatorPosition)) {
+ return false;
+ }
+
+ // I don't check that trees are same! Target/source system deals with it
+
+ //tree.changeParentRemote(sourceTreeNode, targetTreeNode);
+ var index = this.getTargetParentIndex(sourceTreeNode, this.indicatorPosition);
+
+ //dojo.debug('drop2');
+
+ return this.controller.processDrop(sourceTreeNode, this.treeNode.parent, index);
+
+ },
+
+ toString: function() {
+ return "[TreeDropBetweenTarget "+this.treeNode+"]";
+ }
+});
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/__package__.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/__package__.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/__package__.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dnd/__package__.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,16 @@
+/*
+ Copyright (c) 2004-2005, 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.hostenv.conditionalLoadModule({
+ common: ["dojo.dnd.DragAndDrop"],
+ browser: ["dojo.dnd.HtmlDragAndDrop"],
+ dashboard: ["dojo.dnd.HtmlDragAndDrop"]
+});
+dojo.hostenv.moduleLoaded("dojo.dnd.*");
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dom.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dom.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dom.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/dom.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,464 @@
+/*
+ Copyright (c) 2004-2005, 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){
+ 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(typeof XMLSerializer != "undefined"){
+ return (new XMLSerializer()).serializeToString(node);
+ }
+}
+
+dojo.dom.createDocumentFromText = function(str, mimetype){
+ if(!mimetype) { mimetype = "text/xml"; }
+ if(typeof DOMParser != "undefined") {
+ var parser = new DOMParser();
+ return parser.parseFromString(str, mimetype);
+ }else if(typeof ActiveXObject != "undefined"){
+ var domDoc = new ActiveXObject("Microsoft.XMLDOM");
+ 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");
+ return dojo.lang.toArray(collection);
+}
+
+dojo.dom.hasParent = function(node) {
+ if(!node || !node.parentNode || (node.parentNode && !node.parentNode.tagName)) {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * 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 "";
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,501 @@
+/*
+ Copyright (c) 2004-2005, 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.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){
+ 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 = dojo.lang.nameAnonFunc(args[2], ao.adviceObj);
+ 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 = dojo.lang.nameAnonFunc(args[0], ao.srcObj);
+ 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 = dojo.lang.nameAnonFunc(args[1], dj_global);
+ ao.srcFunc = tmpName;
+ ao.adviceObj = args[2];
+ ao.adviceFunc = args[3];
+ }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((typeof ao.srcFunc).toLowerCase() != "string"){
+ ao.srcFunc = dojo.lang.getNameInObj(ao.srcObj, ao.srcFunc);
+ }
+
+ if((typeof ao.adviceFunc).toLowerCase() != "string"){
+ ao.adviceFunc = dojo.lang.getNameInObj(ao.adviceObj, ao.adviceFunc);
+ }
+
+ if((ao.aroundObj)&&((typeof ao.aroundFunc).toLowerCase() != "string")){
+ ao.aroundFunc = dojo.lang.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(){
+ var ao = interpolateArgs(arguments);
+
+ // 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.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._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);
+ kwArgs.srcFunc = tmpName;
+ }
+ if(typeof kwArgs["adviceFunc"] == "function"){
+ kwArgs.adviceObj = kwArgs["adviceObj"]||dj_global;
+ var tmpName = dojo.lang.nameAnonFunc(kwArgs.adviceFunc, kwArgs.adviceObj);
+ 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);
+ 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(){};
+ }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]);
+ }
+ }
+ 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));
+ }
+ }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]));
+ }else{
+ args.push(arguments[x]);
+ }
+ }
+ }
+ // return joinpoint.run.apply(joinpoint, arguments);
+ return joinpoint.run.apply(joinpoint, args);
+ }
+ }
+ return joinpoint;
+}
+
+dojo.lang.extend(dojo.event.MethodJoinPoint, {
+ unintercept: function() {
+ this.object[this.methodname] = this.methodfunc;
+ },
+
+ 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, true);
+ }
+
+ 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, true);
+ }
+
+ 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++){
+ if((arr[x][0] == thisAdviceObj)&&(arr[x][1] == thisAdvice)){
+ 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;
+ }
+});
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/__package__.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/__package__.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/__package__.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/__package__.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,16 @@
+/*
+ Copyright (c) 2004-2005, 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.hostenv.conditionalLoadModule({
+ common: ["dojo.event", "dojo.event.topic"],
+ browser: ["dojo.event.browser"],
+ dashboard: ["dojo.event.browser"]
+});
+dojo.hostenv.moduleLoaded("dojo.event.*");
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/browser.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/browser.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/browser.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/browser.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,266 @@
+/*
+ Copyright (c) 2004-2005, 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.browser");
+dojo.require("dojo.event");
+
+dojo_ie_clobber = new function(){
+ this.clobberNodes = [];
+
+ function nukeProp(node, prop){
+ // try{ node.removeAttribute(prop); }catch(e){ /* squelch */ }
+ try{ node[prop] = null; }catch(e){ /* squelch */ }
+ try{ delete node[prop]; }catch(e){ /* squelch */ }
+ // FIXME: JotLive needs this, but I'm not sure if it's too slow or not
+ try{ node.removeAttribute(prop); }catch(e){ /* squelch */ }
+ }
+
+ this.clobber = function(nodeRef){
+ var na;
+ var tna;
+ if(nodeRef){
+ tna = nodeRef.getElementsByTagName("*");
+ na = [nodeRef];
+ for(var x=0; x<tna.length; x++){
+ // if we're gonna be clobbering the thing, at least make sure
+ // we aren't trying to do it twice
+ if(tna[x]["__doClobber__"]){
+ na.push(tna[x]);
+ }
+ }
+ }else{
+ try{ window.onload = null; }catch(e){}
+ na = (this.clobberNodes.length) ? this.clobberNodes : document.all;
+ }
+ tna = null;
+ var basis = {};
+ for(var i = na.length-1; i>=0; i=i-1){
+ var el = na[i];
+ if(el["__clobberAttrs__"]){
+ for(var j=0; j<el.__clobberAttrs__.length; j++){
+ nukeProp(el, el.__clobberAttrs__[j]);
+ }
+ nukeProp(el, "__clobberAttrs__");
+ nukeProp(el, "__doClobber__");
+ }
+ }
+ na = null;
+ }
+}
+
+if(dojo.render.html.ie){
+ window.onunload = function(){
+ dojo_ie_clobber.clobber();
+ try{
+ if((dojo["widget"])&&(dojo.widget["manager"])){
+ dojo.widget.manager.destroyAll();
+ }
+ }catch(e){}
+ try{ window.onload = null; }catch(e){}
+ try{ window.onunload = null; }catch(e){}
+ dojo_ie_clobber.clobberNodes = [];
+ // CollectGarbage();
+ }
+}
+
+dojo.event.browser = new function(){
+
+ var clobberIdx = 0;
+
+ this.clean = function(node){
+ if(dojo.render.html.ie){
+ dojo_ie_clobber.clobber(node);
+ }
+ }
+
+ this.addClobberNode = function(node){
+ if(!node["__doClobber__"]){
+ node.__doClobber__ = true;
+ dojo_ie_clobber.clobberNodes.push(node);
+ // this might not be the most efficient thing to do, but it's
+ // much less error prone than other approaches which were
+ // previously tried and failed
+ node.__clobberAttrs__ = [];
+ }
+ }
+
+ this.addClobberNodeAttrs = function(node, props){
+ this.addClobberNode(node);
+ for(var x=0; x<props.length; x++){
+ node.__clobberAttrs__.push(props[x]);
+ }
+ }
+
+ this.removeListener = function(node, evtName, fp, capture){
+ if(!capture){ var capture = false; }
+ evtName = evtName.toLowerCase();
+ if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); }
+ // FIXME: this is mostly a punt, we aren't actually doing anything on IE
+ if(node.removeEventListener){
+ node.removeEventListener(evtName, fp, capture);
+ }
+ }
+
+ this.addListener = function(node, evtName, fp, capture, dontFix){
+ if(!node){ return; } // FIXME: log and/or bail?
+ if(!capture){ var capture = false; }
+ evtName = evtName.toLowerCase();
+ if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; }
+
+ if(!dontFix){
+ // build yet another closure around fp in order to inject fixEvent
+ // around the resulting event
+ var newfp = function(evt){
+ if(!evt){ evt = window.event; }
+ var ret = fp(dojo.event.browser.fixEvent(evt));
+ if(capture){
+ dojo.event.browser.stopEvent(evt);
+ }
+ return ret;
+ }
+ }else{
+ newfp = fp;
+ }
+
+ if(node.addEventListener){
+ node.addEventListener(evtName.substr(2), newfp, capture);
+ return newfp;
+ }else{
+ if(typeof node[evtName] == "function" ){
+ var oldEvt = node[evtName];
+ node[evtName] = function(e){
+ oldEvt(e);
+ return newfp(e);
+ }
+ }else{
+ node[evtName]=newfp;
+ }
+ if(dojo.render.html.ie){
+ this.addClobberNodeAttrs(node, [evtName]);
+ }
+ return newfp;
+ }
+ }
+
+ this.isEvent = function(obj){
+ // FIXME: event detection hack ... could test for additional attributes
+ // if necessary
+ return (typeof obj != "undefined")&&(typeof Event != "undefined")&&(obj.eventPhase);
+ // Event does not support instanceof in Opera, otherwise:
+ //return (typeof Event != "undefined")&&(obj instanceof Event);
+ }
+
+ this.currentEvent = null;
+
+ this.callListener = function(listener, curTarget){
+ if(typeof listener != 'function'){
+ dojo.raise("listener not a function: " + listener);
+ }
+ dojo.event.browser.currentEvent.currentTarget = curTarget;
+ return listener.call(curTarget, dojo.event.browser.currentEvent);
+ }
+
+ this.stopPropagation = function(){
+ dojo.event.browser.currentEvent.cancelBubble = true;
+ }
+
+ this.preventDefault = function(){
+ dojo.event.browser.currentEvent.returnValue = false;
+ }
+
+ this.keys = {
+ KEY_BACKSPACE: 8,
+ KEY_TAB: 9,
+ KEY_ENTER: 13,
+ KEY_SHIFT: 16,
+ KEY_CTRL: 17,
+ KEY_ALT: 18,
+ KEY_PAUSE: 19,
+ KEY_CAPS_LOCK: 20,
+ KEY_ESCAPE: 27,
+ KEY_SPACE: 32,
+ KEY_PAGE_UP: 33,
+ KEY_PAGE_DOWN: 34,
+ KEY_END: 35,
+ KEY_HOME: 36,
+ KEY_LEFT_ARROW: 37,
+ KEY_UP_ARROW: 38,
+ KEY_RIGHT_ARROW: 39,
+ KEY_DOWN_ARROW: 40,
+ KEY_INSERT: 45,
+ KEY_DELETE: 46,
+ KEY_LEFT_WINDOW: 91,
+ KEY_RIGHT_WINDOW: 92,
+ KEY_SELECT: 93,
+ KEY_F1: 112,
+ KEY_F2: 113,
+ KEY_F3: 114,
+ KEY_F4: 115,
+ KEY_F5: 116,
+ KEY_F6: 117,
+ KEY_F7: 118,
+ KEY_F8: 119,
+ KEY_F9: 120,
+ KEY_F10: 121,
+ KEY_F11: 122,
+ KEY_F12: 123,
+ KEY_NUM_LOCK: 144,
+ KEY_SCROLL_LOCK: 145
+ };
+
+ // reverse lookup
+ this.revKeys = [];
+ for(var key in this.keys){
+ this.revKeys[this.keys[key]] = key;
+ }
+
+ this.fixEvent = function(evt){
+ if((!evt)&&(window["event"])){
+ var evt = window.event;
+ }
+
+ if((evt["type"])&&(evt["type"].indexOf("key") == 0)){ // key events
+ evt.keys = this.revKeys;
+ // FIXME: how can we eliminate this iteration?
+ for(var key in this.keys) {
+ evt[key] = this.keys[key];
+ }
+ if((dojo.render.html.ie)&&(evt["type"] == "keypress")){
+ evt.charCode = evt.keyCode;
+ }
+ }
+
+ if(dojo.render.html.ie){
+ if(!evt.target){ evt.target = evt.srcElement; }
+ if(!evt.currentTarget){ evt.currentTarget = evt.srcElement; }
+ if(!evt.layerX){ evt.layerX = evt.offsetX; }
+ if(!evt.layerY){ evt.layerY = evt.offsetY; }
+ // mouseover
+ if(evt.fromElement){ evt.relatedTarget = evt.fromElement; }
+ // mouseout
+ if(evt.toElement){ evt.relatedTarget = evt.toElement; }
+ this.currentEvent = evt;
+ evt.callListener = this.callListener;
+ evt.stopPropagation = this.stopPropagation;
+ evt.preventDefault = this.preventDefault;
+ }
+ return evt;
+ }
+
+ this.stopEvent = function(ev) {
+ if(window.event){
+ ev.returnValue = false;
+ ev.cancelBubble = true;
+ }else{
+ ev.preventDefault();
+ ev.stopPropagation();
+ }
+ }
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/topic.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/topic.js?rev=373998&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/topic.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/event/topic.js Tue Jan 31 21:39:49 2006
@@ -0,0 +1,90 @@
+/*
+ Copyright (c) 2004-2005, 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.event");
+dojo.provide("dojo.event.topic");
+
+dojo.event.topic = new function(){
+ this.topics = {};
+
+ this.getTopic = function(topicName){
+ if(!this.topics[topicName]){
+ this.topics[topicName] = new this.TopicImpl(topicName);
+ }
+ return this.topics[topicName];
+ }
+
+ this.registerPublisher = function(topic, obj, funcName){
+ var topic = this.getTopic(topic);
+ topic.registerPublisher(obj, funcName);
+ }
+
+ this.subscribe = function(topic, obj, funcName){
+ var topic = this.getTopic(topic);
+ topic.subscribe(obj, funcName);
+ }
+
+ this.unsubscribe = function(topic, obj, funcName){
+ var topic = this.getTopic(topic);
+ topic.unsubscribe(obj, funcName);
+ }
+
+ this.publish = function(topic, message){
+ var topic = this.getTopic(topic);
+ // if message is an array, we treat it as a set of arguments,
+ // otherwise, we just pass on the arguments passed in as-is
+ var args = [];
+ if(arguments.length == 2 && (dojo.lang.isArray(message) || message.callee)){
+ args = message;
+ }else{
+ var args = [];
+ for(var x=1; x<arguments.length; x++){
+ args.push(arguments[x]);
+ }
+ }
+ topic.sendMessage.apply(topic, args);
+ }
+}
+
+dojo.event.topic.TopicImpl = function(topicName){
+ this.topicName = topicName;
+ var self = this;
+
+ self.subscribe = function(listenerObject, listenerMethod){
+ var tf = listenerMethod||listenerObject;
+ var to = (!listenerMethod) ? dj_global : listenerObject;
+ dojo.event.kwConnect({
+ srcObj: self,
+ srcFunc: "sendMessage",
+ adviceObj: to,
+ adviceFunc: tf
+ });
+ }
+
+ self.unsubscribe = function(listenerObject, listenerMethod){
+ var tf = (!listenerMethod) ? listenerObject : listenerMethod;
+ var to = (!listenerMethod) ? null : listenerObject;
+ dojo.event.kwDisconnect({
+ srcObj: self,
+ srcFunc: "sendMessage",
+ adviceObj: to,
+ adviceFunc: tf
+ });
+ }
+
+ self.registerPublisher = function(publisherObject, publisherMethod){
+ dojo.event.connect(publisherObject, publisherMethod, self, "sendMessage");
+ }
+
+ self.sendMessage = function(message){
+ // The message has been propagated
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org