You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/01/27 00:58:20 UTC
svn commit: r372668 [3/16] - in
/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource:
./ src/ src/alg/ src/animation/ src/collections/ src/crypto/ src/data/
src/dnd/ src/event/ src/flash/ src/flash/flash6/ src...
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragAndDrop.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragAndDrop.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragAndDrop.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragAndDrop.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,381 @@
+/*
+ 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.HtmlDragAndDrop");
+dojo.provide("dojo.dnd.HtmlDragSource");
+dojo.provide("dojo.dnd.HtmlDropTarget");
+dojo.provide("dojo.dnd.HtmlDragObject");
+
+dojo.require("dojo.dnd.HtmlDragManager");
+dojo.require("dojo.animation.*");
+dojo.require("dojo.dom");
+dojo.require("dojo.style");
+dojo.require("dojo.html");
+dojo.require("dojo.lang");
+
+dojo.dnd.HtmlDragSource = function(node, type){
+ node = dojo.byId(node);
+ 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.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, this.dragClass);
+
+ if (this.constrainToContainer) {
+ dragObj.constrainTo(this.constrainingContainer);
+ }
+
+ 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;
+ } else {
+ this.constrainingContainer = this.domNode.parentNode;
+ }
+ }
+});
+
+dojo.dnd.HtmlDragObject = function(node, type, dragClass){
+ this.domNode = dojo.byId(node);
+ this.type = type;
+ if(dragClass) { this.dragClass = dragClass; }
+ this.constrainToContainer = false;
+}
+
+dojo.lang.extend(dojo.dnd.HtmlDragObject, {
+ dragClass: "",
+ opacity: 0.5,
+
+ // if true, node will not move in X and/or Y direction
+ disableX: false,
+ disableY: false,
+
+ /**
+ * Creates a clone of this node and replaces this node with the clone in the
+ * DOM tree. This is done to prevent the browser from selecting the textual
+ * content of the node. This node is then set to opaque and drags around as
+ * the intermediate representation.
+ */
+ onDragStart: function(e){
+ dojo.html.clearSelection();
+
+ this.scrollOffset = {
+ top: dojo.html.getScrollTop(), // document.documentElement.scrollTop,
+ left: dojo.html.getScrollLeft() // document.documentElement.scrollLeft
+ };
+
+ this.dragStartPosition = {top: dojo.style.getAbsoluteY(this.domNode, true) + this.scrollOffset.top,
+ left: dojo.style.getAbsoluteX(this.domNode, true) + this.scrollOffset.left};
+
+
+ this.dragOffset = {top: this.dragStartPosition.top - e.clientY,
+ left: this.dragStartPosition.left - e.clientX};
+
+ this.dragClone = this.domNode.cloneNode(true);
+ //this.domNode.parentNode.replaceChild(this.dragClone, this.domNode);
+
+
+ if ((this.domNode.parentNode.nodeName.toLowerCase() == 'body') || (dojo.style.getComputedStyle(this.domNode.parentNode,"position") == "static")) {
+ 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)};
+ }
+
+ if (this.constrainToContainer) {
+ this.constraints = this.getConstraints();
+ }
+
+ // set up for dragging
+ with(this.dragClone.style){
+ position = "absolute";
+ top = this.dragOffset.top + e.clientY + "px";
+ left = this.dragOffset.left + e.clientX + "px";
+ }
+
+ if(this.dragClass) { dojo.html.addClass(this.dragClone, this.dragClass); }
+ dojo.style.setOpacity(this.dragClone, this.opacity);
+ dojo.html.body().appendChild(this.dragClone);
+ },
+
+ getConstraints: function() {
+
+ if (this.constrainingContainer.nodeName.toLowerCase() == 'body') {
+ width = dojo.html.getViewportWidth();
+ height = dojo.html.getViewportHeight();
+ padLeft = 0;
+ padTop = 0;
+ } else {
+ width = dojo.style.getContentWidth(this.constrainingContainer);
+ height = dojo.style.getContentHeight(this.constrainingContainer);
+ padLeft = dojo.style.getPixelValue(this.constrainingContainer, "padding-left", true);
+ padTop = dojo.style.getPixelValue(this.constrainingContainer, "padding-top", true);
+ }
+
+ return {
+ minX: padLeft,
+ minY: padTop,
+ maxX: padLeft+width - dojo.style.getOuterWidth(this.domNode),
+ maxY: padTop+height - dojo.style.getOuterHeight(this.domNode)
+ }
+ },
+
+ updateDragOffset: function() {
+ var sTop = dojo.html.getScrollTop(); // document.documentElement.scrollTop;
+ var sLeft = dojo.html.getScrollLeft(); // document.documentElement.scrollLeft;
+ if(sTop != this.scrollOffset.top) {
+ var diff = sTop - this.scrollOffset.top;
+ this.dragOffset.top += diff;
+ this.scrollOffset.top = sTop;
+ }
+ },
+
+ /** Moves the node to follow the mouse */
+ onDragMove: function(e){
+ this.updateDragOffset();
+ var x = this.dragOffset.left + e.clientX - this.parentPosition.left;
+ var y = this.dragOffset.top + e.clientY - this.parentPosition.top;
+
+ 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; }
+ }
+
+ 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.getAbsoluteX(this.dragClone),
+ dojo.style.getAbsoluteY(this.dragClone)];
+ // offset the end so the effect can be seen
+ var endCoords = [this.dragStartPosition.left + 1,
+ this.dragStartPosition.top + 1];
+
+ // animate
+ var line = new dojo.math.curves.Line(startCoords, endCoords);
+ var anim = new dojo.animation.Animation(line, 300, 0, 0);
+ var dragObject = this;
+ dojo.event.connect(anim, "onAnimate", function(e) {
+ dragObject.dragClone.style.left = e.x + "px";
+ dragObject.dragClone.style.top = e.y + "px";
+ });
+ dojo.event.connect(anim, "onEnd", function (e) {
+ // pause for a second (not literally) and disappear
+ dojo.lang.setTimeout(dojo.dom.removeNode, 200,
+ dragObject.dragClone);
+ });
+ anim.play();
+ break;
+ }
+ },
+
+ 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; }
+ node = dojo.byId(node);
+ this.domNode = node;
+ dojo.dnd.DropTarget.call(this);
+ 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 top = dojo.style.getAbsoluteY(child);
+ var bottom = top + dojo.style.getInnerHeight(child);
+ var left = dojo.style.getAbsoluteX(child);
+ var right = left + dojo.style.getInnerWidth(child);
+ this.childBoxes.push({top: top, bottom: bottom,
+ left: left, right: right, node: child});
+ }
+
+ // TODO: use dummy node
+
+ return true;
+ },
+
+ _getNodeUnderMouse: function(e){
+ var mousex = e.pageX || e.clientX + dojo.html.body().scrollLeft;
+ var mousey = e.pageY || e.clientY + dojo.html.body().scrollTop;
+
+ // find the child
+ for (var i = 0, child; i < this.childBoxes.length; i++) {
+ with (this.childBoxes[i]) {
+ if (mousex >= left && mousex <= right &&
+ mousey >= top && mousey <= bottom) { return i; }
+ }
+ }
+
+ return -1;
+ },
+
+ createDropIndicator: function() {
+ this.dropIndicator = document.createElement("div");
+ with (this.dropIndicator.style) {
+ position = "absolute";
+ zIndex = 1;
+ borderTopWidth = "1px";
+ borderTopColor = "black";
+ borderTopStyle = "solid";
+ width = dojo.style.getInnerWidth(this.domNode) + "px";
+ left = dojo.style.getAbsoluteX(this.domNode) + "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)) {
+ dojo.html.body().appendChild(this.dropIndicator);
+ }
+ },
+
+ 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) + "px";
+ }
+ } else {
+ var child = this.childBoxes[boxIndex];
+ top = (before ? child.top : child.bottom) + "px";
+ }
+ }
+ },
+
+ onDragOut: function(e) {
+ 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;
+ }
+});
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragManager.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragManager.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragManager.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragManager.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,365 @@
+/*
+ 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.event.*");
+dojo.require("dojo.lang");
+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);
+ },
+
+ getDragSource: function(e){
+ var tn = e.target;
+ if(tn === dojo.html.body()){ return; }
+ var ta = dojo.html.getAttribute(tn, this.dsPrefix);
+ while((!ta)&&(tn)){
+ tn = tn.parentNode;
+ if((!tn)||(tn === dojo.html.body())){ return; }
+ ta = dojo.html.getAttribute(tn, this.dsPrefix);
+ }
+ return this.dragSources[ta];
+ },
+
+ onKeyDown: function(e){
+ },
+
+ onMouseDown: function(e){
+ if(this.disabled) { return; }
+
+ this.mouseDownX = e.clientX;
+ this.mouseDownY = e.clientY;
+
+ 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.
+ switch(target.tagName.toLowerCase()) {
+ case "a": case "button": case "textarea":
+ case "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.dragSource = this.dragSource;
+ if((!e.shiftKey)&&(!e.ctrlKey)){
+ 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;
+ }
+ dojo.event.disconnect(document, "onmousemove", this, "onMouseMove");
+ this.currentDropTarget = null;
+ this.currentDropTargetPoints = null;
+ },
+
+ scrollBy: function(x, y) {
+ for(var i = 0; i < this.dragObjects.length; i++) {
+ if(this.dragObjects[i].updateDragOffset) {
+ this.dragObjects[i].updateDragOffset();
+ }
+ }
+ },
+
+ _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);
+ },
+
+ 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);
+ }
+ });
+
+ 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
+ ]);
+ });
+ }
+ // 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.
+ var dtp = this.currentDropTargetPoints;
+ 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.currentDropTarget = null;
+ this.currentDropTargetPoints = null;
+ }
+ this.dropAcceptable = false;
+ return;
+ }
+
+ if(this.currentDropTarget != bestBox.target){
+ if(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");
+ dojo.event.connect(window, "scrollBy", dm, "scrollBy");
+})();
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragMove.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragMove.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragMove.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/HtmlDragMove.js Thu Jan 26 15:56:50 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: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/Sortable.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/Sortable.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/Sortable.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/Sortable.js Thu Jan 26 15:56:50 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: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/TreeDragAndDrop.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/TreeDragAndDrop.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/TreeDragAndDrop.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/TreeDragAndDrop.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,180 @@
+/*
+ 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.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, {
+
+ /**
+ * Check if I can drop sourceTreeNode here
+ * only tree node targets are implemented ATM
+ */
+ onDragOver: function(e){
+
+ var sourceTreeNode = e.dragObjects[0].treeNode;
+
+
+ if (dojo.lang.isUndefined(sourceTreeNode) || !sourceTreeNode || sourceTreeNode.widgetType != 'EditorTreeNode') {
+ dojo.raise("Source is not of EditorTreeNode widgetType or not found");
+ }
+ //dojo.debug("This " + this.treeNode.title)
+ //dojo.debug("Source " + sourceTreeNode);
+
+ // check types compat
+ var acceptable = dojo.dnd.HtmlDropTarget.prototype.onDragOver.apply(this, arguments);
+
+ //dojo.debug("Check1 "+acceptable)
+
+
+ if (!acceptable) return false;
+
+ // can't drop parent to child etc
+ acceptable = this.controller.canChangeParent(sourceTreeNode, this.treeNode);
+
+
+ //dojo.debug("Check2 "+acceptable)
+
+ if (!acceptable) return false;
+
+
+ // mark current node being dragged into
+ if (sourceTreeNode !== this.treeNode) {
+ this.treeNode.markSelected();
+ }
+
+ return true;
+
+ },
+
+ onDragMove: function(e){
+ },
+
+ onDragOut: function(e) {
+
+ this.treeNode.unMarkSelected();
+
+ //return dojo.dnd.HtmlDropTarget.prototype.onDragOut.call(this, e);
+ },
+
+ onDrop: function(e){
+ this.onDragOut(e);
+
+ //dojo.debug('drop');
+
+ var child = this.domNode;
+ var targetTreeNode = this.treeNode;
+
+
+ if (!dojo.lang.isObject(targetTreeNode)) {
+ dojo.raise("Wrong DropTarget engaged");
+ }
+
+ var sourceTreeNode = e.dragObject.treeNode;
+
+ if (!dojo.lang.isObject(sourceTreeNode)) {
+ return false;
+ }
+
+ // I don't check that trees are same! Target/source system deals with it
+
+ //tree.changeParentRemote(sourceTreeNode, targetTreeNode);
+ return this.controller.processDrop(sourceTreeNode, targetTreeNode);
+
+ }
+});
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/__package__.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/__package__.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/__package__.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dnd/__package__.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,15 @@
+/*
+ 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"]
+});
+dojo.hostenv.moduleLoaded("dojo.dnd.*");
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dom.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dom.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dom.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/dom.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,465 @@
+/*
+ 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");
+
+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 = dojo.lang.isDomNode = function(wh){
+ if(typeof Element == "object") {
+ try {
+ return wh instanceof Element;
+ } catch(E) {}
+ } else {
+ // best-guess
+ return wh && !isNaN(wh.nodeType);
+ }
+}
+dojo.lang.whatAmI.custom["node"] = dojo.dom.isNode;
+
+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: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,484 @@
+/*
+ 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.lang");
+dojo.provide("dojo.event");
+
+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)&&(window.event)){
+ args.push(dojo.event.browser.fixEvent(window.event));
+ }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: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/__package__.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/__package__.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/__package__.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/__package__.js Thu Jan 26 15:56:50 2006
@@ -0,0 +1,15 @@
+/*
+ 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"]
+});
+dojo.hostenv.moduleLoaded("dojo.event.*");
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/browser.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/browser.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/browser.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/browser.js Thu Jan 26 15:56:50 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: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/topic.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/topic.js?rev=372668&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/topic.js (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/dojo/resource/src/event/topic.js Thu Jan 26 15:56:50 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)&&(message.length)&&(typeof message != "string")){
+ 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
+ }
+}
+