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/01/23 02:24:57 UTC
svn commit: r371434 [14/21] - in /jakarta/tapestry/trunk: ./ config/
examples/Workbench/src/context/WEB-INF/
framework/src/java/org/apache/tapestry/html/
framework/src/java/org/apache/tapestry/services/impl/ framework/src/js/
framework/src/js/dojo/ fra...
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTree.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTree.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTree.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTree.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,560 @@
+/*
+ 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
+*/
+
+/**
+ * Tree model does all the drawing, visual node management etc.
+ * Throws events about clicks on it, so someone may catch them and process
+ * Tree knows nothing about DnD stuff, covered in TreeDragAndDrop and (if enabled) attached by controller
+*/
+dojo.provide("dojo.widget.EditorTree");
+
+dojo.require("dojo.event.*");
+dojo.require("dojo.fx.html");
+dojo.require("dojo.io.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.widget.EditorTreeNode");
+dojo.require("dojo.widget.EditorTreeSelector");
+dojo.require("dojo.widget.EditorTreeController");
+
+
+
+// make it a tag
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTree");
+
+
+dojo.widget.EditorTree = function() {
+ dojo.widget.HtmlWidget.call(this);
+
+ this.eventNames = {
+ // new node built.. Well, just built
+ nodeCreate: "",
+ // expand icon clicked
+ treeClick: "",
+ // node icon clicked
+ iconClick: "",
+ // node title clicked
+ titleClick: ""
+ };
+
+ this.tree = this;
+ this.acceptDropSources = [];
+ this.actionsDisabled = [];
+
+}
+dojo.inherits(dojo.widget.EditorTree, dojo.widget.HtmlWidget);
+
+/* extend DOES NOT copy recursively */
+dojo.lang.extend(dojo.widget.EditorTree, {
+ widgetType: "EditorTree",
+
+ isContainer: true,
+
+ acceptDropSources: "",
+
+ templateCssPath: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/EditorTree.css"),
+
+ templateString: '<div class="dojoTree"></div>',
+
+ /* Model events */
+ eventNames: null,
+ eventNaming: "default",
+
+ toggler: null,
+
+ isExpanded: true, // consider this "root node" to be always expanded
+
+ isTree: true,
+
+ objectId: "",
+
+
+ //
+ // these icons control the grid and expando buttons for the whole tree
+ //
+
+ blankIconSrc: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_blank.gif"),
+
+ gridIconSrcT: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_t.gif"), // for non-last child grid
+ gridIconSrcL: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_l.gif"), // for last child grid
+ gridIconSrcV: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_v.gif"), // vertical line
+ gridIconSrcP: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_p.gif"), // for under parent item child icons
+ gridIconSrcC: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_c.gif"), // for under child item child icons
+ gridIconSrcX: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_x.gif"), // grid for sole root item
+ gridIconSrcY: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_y.gif"), // grid for last rrot item
+ gridIconSrcZ: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_grid_z.gif"), // for under root parent item child icon
+
+ expandIconSrcPlus: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_expand_plus.gif"),
+ expandIconSrcMinus: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_expand_minus.gif"),
+ expandIconSrcLoading: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/treenode_loading.gif"),
+
+
+ iconWidth: 18,
+ iconHeight: 18,
+
+
+ //
+ // tree options
+ //
+
+ showGrid: true,
+ showRootGrid: true,
+
+ toggle: "default",
+ toggleDuration: 150,
+ selector: null,
+
+
+ actionIsDisabled: function(action) {
+ var _this = this;
+ return dojo.lang.inArray(_this.actionsDisabled, action)
+ },
+
+
+ actions: {
+ ADDCHILD: "ADDCHILD"
+ },
+
+
+ getInfo: function() {
+ var _this = this;
+ var info = {
+ widgetId: _this.widgetId,
+ objectId: _this.objectId
+ }
+
+ return info;
+ },
+
+ initialize: function(args, frag){
+
+ var _this = this;
+ //this.acceptDropSources = this.acceptDropSources.split(',');
+ /*
+ var sources;
+ if ( (sources = args['acceptDropSources']) || (sources = args['acceptDropSources']) ) {
+
+ }
+ */
+ //this.actionsDisabled = this.actionsDisabled.split(",");
+ for(var i=0; i<this.actionsDisabled.length; i++) {
+ this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase();
+ }
+
+
+ switch (this.toggle) {
+
+ case "fade": this.toggler = new dojo.widget.EditorTree.FadeToggle(); break;
+ // buggy - try to open many nodes in FF (IE is ok)
+ case "wipe": this.toggler = new dojo.widget.EditorTree.WipeToggle(); break;
+ default : this.toggler = new dojo.widget.EditorTree.DefaultToggle();
+ }
+
+
+ if (this.eventNaming == "default") { // IE || FF
+
+ for (eventName in this.eventNames) {
+ this.eventNames[eventName] = this.widgetId+"/"+eventName;
+ }
+ /*
+ this.eventNames.watch("nodeCreate",
+ function (id,oldval,newval) {
+ alert("o." + id + " changed from " + oldval + " to " + newval);
+ return newval;
+ }
+ );
+ */
+
+ // alert(dojo.widget.manager.getWidgetById('firstTree').widgetId)
+ // alert(dojo.widget.manager.getWidgetById('firstTree').eventNames.nodeCreate);
+
+ }
+
+
+ if (args['controller']) {
+ var controller = dojo.widget.manager.getWidgetById(args['controller']);
+
+ controller.subscribeTree(this); // controller listens to my events
+ }
+
+ if (args['selector']) {
+ this.selector = dojo.widget.manager.getWidgetById(args['selector']);
+ } else {
+ this.selector = new dojo.widget.createWidget("EditorTreeSelector");
+ }
+
+ this.containerNode = this.domNode;
+
+ },
+
+
+
+ postCreate: function() {
+ this.buildTree();
+ },
+
+ buildTree: function() {
+
+ dojo.html.disableSelection(this.domNode);
+
+ for(var i=0; i<this.children.length; i++){
+
+ this.children[i].isFirstNode = (i == 0) ? true : false;
+ this.children[i].isLastNode = (i == this.children.length-1) ? true : false;
+ this.children[i].parent = this; // root nodes have tree as parent
+
+ var node = this.children[i].buildNode(this, 0);
+
+
+ this.domNode.appendChild(node);
+ }
+
+
+ //
+ // when we don't show root toggles, we need to auto-expand root nodes
+ //
+
+ if (!this.showRootGrid){
+ for(var i=0; i<this.children.length; i++){
+ this.children[i].expand();
+ }
+ }
+
+
+ },
+
+
+
+ /**
+ * Move child to newParent as last child
+ * redraw tree and update icons
+ */
+ changeParent: function(child, newParent, index) {
+// dojo.debug("Move "+child+" to "+newParent+" index "+index)
+
+ //dojo.debug(dojo.widget.manager.getWidgetById('1.3').containerNode.style.display);
+
+ var destIdx = index;
+/*
+ if (child.parent === newParent && child.getParentIndex()<=index) {
+ dojo.debug("shift dest index")
+ destIdx--; // shift index cause child.length is less by 1 after removal
+ }
+ */
+
+ /* do actual parent change here. Write remove child first */
+ child.parent.removeChild(child);
+
+ newParent.addChild(child, destIdx);
+
+ },
+
+ removeChild: function(child) {
+
+ var parent = child.parent;
+
+ var children = parent.children;
+
+ for(var i=0; i<children.length; i++){
+ if(children[i] === child){
+ if (children.length>1) {
+ if (i==0) {
+ children[i+1].isFirstNode = true;
+ }
+ if (i==children.length-1) {
+ children[i-1].isLastNode = true;
+ }
+ }
+ children.splice(i, 1);
+ break;
+ }
+ }
+
+ dojo.dom.removeNode(child.domNode);
+
+
+ //dojo.debug("removeChild: "+child.title+" from "+parent.title);
+
+ /*
+ if (children.length == 0) {
+ // toggle empty container off
+ if (!parent.isTree) { // if has container
+ parent.containerNode.style.display = 'none';
+ }
+
+ }
+ */
+
+ parent.updateIconTree();
+
+
+
+ return child;
+
+ },
+
+
+ // not called for initial tree building. See buildNode instead.
+ // builds child html node if needed
+ // index is "last node" by default
+ addChild: function(child, index){
+
+
+ dojo.profile.start("AddChild");
+
+ if (dojo.lang.isUndefined(index)) {
+ index = this.children.length;
+ }
+
+
+ //dojo.debug("This "+this+" Child "+child+" index "+index+" children.length "+this.children.length);
+
+ //
+ // this function gets called to add nodes to both trees and nodes, so it's a little confusing :)
+ //
+
+ if (!child.isTreeNode){
+ dojo.raise("You can only add EditorTreeNode widgets to a "+this.widgetType+" widget!");
+ return;
+ }
+
+ // set/clean isFirstNode and isLastNode
+ if (this.children.length){
+ if (index == 0) {
+ this.children[0].isFirstNode = false;
+ child.isFirstNode = true;
+ } else {
+ child.isFirstNode = false;
+ }
+ if (index == this.children.length) {
+ this.children[index-1].isLastNode = false;
+ child.isLastNode = true;
+ } else {
+ child.isLastNode = false;
+ }
+ } else {
+ child.isLastNode = true;
+ child.isFirstNode = true;
+ }
+
+
+ //dojo.debug("For new child set first:"+child.isFirstNode+" last:"+child.isLastNode);
+
+
+ // usually it is impossible to change "isFolder" state, but if anyone wants to add a child to leaf,
+ // it is possible program-way.
+ if (this.isTreeNode){
+ if (!this.isFolder) { // just became a folder.
+ this.setFolder();
+ }
+ }
+
+ // adjust tree
+ var _this = this;
+ dojo.lang.forEach(child.getDescendants(), function(elem) { elem.tree = _this.tree; });
+
+ /*
+ var stack = [child];
+ var elem;
+ // change tree for all subnodes
+ while (elem = stack.pop()) {
+ //dojo.debug("Tree for "+elem.title);
+ elem.tree = tree;
+ dojo.lang.forEach(elem.children, function(elem) { stack.push(elem); });
+ }
+ */
+
+ // fix parent
+ child.parent = this;
+
+
+ // no dynamic loading for those who are parents already
+ if (this.isTreeNode) {
+ this.state = this.loadStates.LOADED;
+ }
+
+ // if node exists - adjust its depth, otherwise build it
+ if (child.domNodeInitialized) {
+ //dojo.debug(this.widgetType)
+ var d = this.isTreeNode ? this.depth : -1;
+ //dojo.debug('Depth is '+this.depth);
+ child.adjustDepth( d - child.depth + 1 );
+ } else {
+ child.depth = this.isTreeNode ? this.depth+1 : 0;
+ child.buildNode(child.tree, child.depth);
+ }
+
+
+ //dojo.debug(child.domNode.outerHTML)
+
+ if (index < this.children.length) {
+
+ //dojo.debug('insert '+index)
+ //dojo.debugShallow(child);
+
+ // insert
+ dojo.dom.insertBefore(child.domNode, this.children[index].domNode);
+ } else {
+ this.containerNode.appendChild(child.domNode);
+ }
+
+ /*
+ if (index == this.children.length && this.children.length == 0) {
+ this.containerNode.style.display = 'block';
+ }
+ */
+
+ this.children.splice(index, 0, child);
+
+ //dojo.lang.forEach(this.children, function(child) { dojo.debug("Child "+child.title); } );
+
+ //dojo.debugShallow(child);
+
+ //this.expand();
+
+
+
+ dojo.profile.end("AddChild");
+
+ dojo.profile.start("updateIconTree");
+
+ //this.updateIconTree();
+ child.updateIcons();
+ if (this.children.length>1) {
+ if (child.isFirstNode) {
+ this.children[1].updateIcons();
+ }
+ if (child.isLastNode) {
+ this.children[this.children.length-2].updateIcons();
+ }
+ }
+
+ dojo.profile.end("updateIconTree");
+
+
+ },
+
+ // adds an array of children in "batch mode" into empty node
+ // optimized for fast loading of large collections into empty nodes
+ addAllChildren: function(children) {
+
+ if (children.length == 0) return;
+
+ dojo.profile.start("addAllChildren");
+
+ var _this = this;
+
+ children[0].isFirstNode = true;
+ children[children.length-1].isLastNode = true;
+
+ if (this.isTreeNode){
+ if (!this.isFolder) { // just became a folder.
+ this.setFolder();
+ }
+ }
+
+ dojo.lang.forEach(children,
+ function(child) {
+ child.parent = _this;
+ child.buildNode(_this.tree, _this.isTreeNode ? _this.depth+1 : 0);
+ _this.containerNode.appendChild(child.domNode);
+ }
+
+ );
+
+ // no dynamic loading for those who are parents already
+ if (this.isTreeNode) {
+ this.state = this.loadStates.LOADED;
+ }
+
+
+ this.children = children;
+
+ //this.updateIconTree();
+
+ dojo.profile.end("addAllChildren");
+
+ },
+
+ makeBlankImg: function() {
+ var img = document.createElement('img');
+
+ img.style.width = this.iconWidth + 'px';
+ img.style.height = this.iconHeight + 'px';
+ img.src = this.blankIconSrc;
+ img.style.verticalAlign = 'middle';
+
+ return img;
+ },
+
+
+
+
+ updateIconTree: function(){
+
+ //dojo.debug("Update icons for "+this)
+ if (!this.isTree) {
+ this.updateIcons();
+ }
+
+ for(var i=0; i<this.children.length; i++){
+ this.children[i].updateIconTree();
+ }
+
+ },
+
+ toString: function() {
+ return "["+this.widgetType+" ID:"+this.widgetId+"]"
+ }
+
+
+
+
+
+});
+
+
+
+dojo.widget.EditorTree.DefaultToggle = function(){
+
+ this.show = function(node){
+ node.style.display = 'block';
+ }
+
+ this.hide = function(node){
+ node.style.display = 'none';
+ }
+}
+
+dojo.widget.EditorTree.FadeToggle = function(duration){
+ this.toggleDuration = duration ? duration : 150;
+
+ this.show = function(node){
+ node.style.display = 'block';
+ dojo.fx.html.fade(node, this.toggleDuration, 0, 1);
+ }
+
+ this.hide = function(node){
+ dojo.fx.html.fadeOut(node, this.toggleDuration, function(node){ node.style.display = 'none'; });
+ }
+}
+
+dojo.widget.EditorTree.WipeToggle = function(duration){
+ this.toggleDuration = duration ? duration : 150;
+
+ this.show = function(node){
+ node.style.display = 'block';
+ dojo.fx.html.wipeIn(node, this.toggleDuration);
+ }
+
+ this.hide = function(node){
+ dojo.fx.html.wipeOut(node, this.toggleDuration, function(node){ node.style.display = 'none'; });
+ }
+}
+
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeContextMenu.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeContextMenu.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeContextMenu.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeContextMenu.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,145 @@
+/*
+ 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.widget.EditorTreeContextMenu");
+dojo.provide("dojo.widget.EditorTreeMenuItem");
+
+dojo.require("dojo.event.*");
+dojo.require("dojo.io.*");
+dojo.require("dojo.widget.Menu2");
+
+
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreeContextMenu");
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreeMenuItem");
+
+
+
+dojo.widget.EditorTreeContextMenu = function() {
+ dojo.widget.PopupMenu2.call(this);
+
+
+}
+
+
+dojo.inherits(dojo.widget.EditorTreeContextMenu, dojo.widget.PopupMenu2);
+
+dojo.lang.extend(dojo.widget.EditorTreeContextMenu, {
+
+ widgetType: "EditorTreeContextMenu",
+
+ open: function(x, y, parentMenu, explodeSrc){
+
+ var result = dojo.widget.PopupMenu2.prototype.open.apply(this, arguments);
+
+ /* publish many events here about structural changes */
+ dojo.event.topic.publish(this.eventNames.open, { menu:this });
+
+ return result;
+ },
+
+ bindToTree: function(tree) {
+ /* add context menu to all nodes that exist already */
+ var nodes = tree.getDescendants();
+
+ for(var i=0; i<nodes.length; i++) {
+ if (!nodes[i].isTreeNode) continue;
+ this.bindDomNode(nodes[i].labelNode);
+ }
+
+
+ /* bind context menu to all nodes that will be created in the future (e.g loaded from server)*/
+ var _this = this;
+ dojo.event.topic.subscribe(tree.eventNames.nodeCreate,
+ function(message) { _this.bindDomNode(message.source.labelNode); }
+ );
+ }
+
+
+
+
+});
+
+
+
+
+
+
+dojo.widget.EditorTreeMenuItem = function() {
+ dojo.widget.MenuItem2.call(this);
+
+}
+
+
+dojo.inherits(dojo.widget.EditorTreeMenuItem, dojo.widget.MenuItem2);
+
+
+dojo.lang.extend(dojo.widget.EditorTreeMenuItem, {
+
+ widgetType: "EditorTreeMenuItem",
+
+ // treeActions menu item performs following actions (to be checked for permissions)
+ treeActions: "",
+
+ initialize: function(args, frag) {
+
+ this.treeActions = this.treeActions.split(",");
+ for(var i=0; i<this.treeActions.length; i++) {
+ this.treeActions[i] = this.treeActions[i].toUpperCase();
+ }
+
+ },
+
+ getTreeNode: function() {
+ var menu = this;
+
+ while (! (menu instanceof dojo.widget.EditorTreeContextMenu) ) {
+ menu = menu.parent;
+ }
+
+ var source = menu.getTopOpenEvent().target;
+
+ while (!source.treeNode && source.tagName != 'body') {
+ source = source.parentNode;
+ }
+ if (source.tagName == 'body') {
+ dojo.raise("treeNode not detected");
+ }
+ var treeNode = dojo.widget.manager.getWidgetById(source.treeNode);
+
+ return treeNode;
+ },
+
+
+ menuOpen: function(message) {
+ var treeNode = this.getTreeNode();
+
+ this.setDisabled(false); // enable by default
+
+ var _this = this;
+ dojo.lang.forEach(_this.treeActions,
+ function(action) {
+ if(treeNode.actionIsDisabled(action)) {
+ _this.setDisabled(true);
+ } else {
+ //dojo.debug("Allowed "+action)
+ }
+ }
+ );
+
+ },
+
+ toString: function() {
+ return "["+this.widgetType+" node "+this.getTreeNode()+"]";
+ }
+
+});
+
+
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeController.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeController.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeController.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeController.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,690 @@
+/*
+ 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.widget.EditorTreeController");
+
+dojo.require("dojo.event.*");
+dojo.require("dojo.dnd.TreeDragAndDrop");
+dojo.require("dojo.json")
+dojo.require("dojo.io.*");
+
+
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreeController");
+
+
+dojo.widget.EditorTreeController = function() {
+ dojo.widget.HtmlWidget.call(this);
+
+ this.eventNames = {
+ select : "",
+ deselect : "",
+ collapse: "",
+ expand: "",
+ dblselect: "", // select already selected node.. Edit or whatever
+
+ move: "", // a child was moved from one place to another
+ remove: ""
+ };
+
+
+ this.dragSources = {};
+
+ this.dropTargets = {};
+}
+
+dojo.inherits(dojo.widget.EditorTreeController, dojo.widget.HtmlWidget);
+
+
+dojo.lang.extend(dojo.widget.EditorTreeController, {
+ widgetType: "EditorTreeController",
+
+ RPCUrl: "local",
+
+ errorHandler: null, // function pointer on error handler
+
+ eventNaming: "default",
+
+ initialize: function(args, frag){
+
+ if (this.eventNaming == "default") { // IE || FF
+ for (eventName in this.eventNames) {
+ this.eventNames[eventName] = this.widgetId+"/"+eventName;
+ }
+ }
+
+ },
+
+
+ DNDMode: "off",
+
+
+ /**
+ * Common RPC error handler (dies)
+ */
+ RPCErrorHandler: function(type, obj) {
+ var message = "Error: ";
+ if (obj.message) message = message + obj.message;
+
+ alert(message);
+ },
+
+
+ /**
+ * Binds controller to all tree events
+ */
+ subscribeTree: function(tree) {
+
+ if (!tree.eventNames.nodeCreate) dojo.raise("Can't subscribe controller to empty nodeCreate")
+ if (!tree.eventNames.treeClick) dojo.raise("Can't subscribe controller to empty treeClick")
+ if (!tree.eventNames.iconClick) dojo.raise("Can't subscribe controller to empty iconClick")
+ if (!tree.eventNames.titleClick) dojo.raise("Can't subscribe controller to empty titleClick")
+
+ dojo.event.topic.subscribe(tree.eventNames.nodeCreate, this, "onNodeCreate");
+ dojo.event.topic.subscribe(tree.eventNames.treeClick, this, "onTreeClick");
+ dojo.event.topic.subscribe(tree.eventNames.iconClick, this, "onIconClick");
+ dojo.event.topic.subscribe(tree.eventNames.titleClick, this, "onTitleClick");
+ },
+
+
+ /**
+ * Checks whether it is ok to change parent of child to newParent
+ * May incur type checks etc
+ *
+ * It should check only hierarchical possibility w/o index, etc
+ * because in onDragOver event for Between DND mode we can't calculate index at once on onDragOVer.
+ * index changes as client moves mouse up-down over the node
+ */
+ canChangeParent: function(child, newParent){
+
+ if (child.actionIsDisabled(child.actions.MOVE)) {
+ return false;
+ }
+
+ if (child.parent !== newParent && newParent.actionIsDisabled(newParent.actions.ADDCHILD)) {
+ return false;
+ }
+
+ // Can't move parent under child. check whether new parent is child of "child".
+ var node = newParent;
+ while(node.isTreeNode) {
+ //dojo.debugShallow(node.title)
+
+
+ if (node === child) {
+ // parent of newParent is child
+ return false;
+ }
+ node = node.parent;
+ }
+
+
+ // check for newParent being a folder (if node)
+ if (newParent.isTreeNode && !newParent.isFolder) {
+ return false;
+ }
+
+
+ return true;
+ },
+
+
+ getRPCUrl: function(action) {
+
+ if (this.RPCUrl == "local") { // for demo and tests. May lead to widgetId collisions
+ var dir = document.location.href.substr(0, document.location.href.lastIndexOf('/'));
+ var localUrl = dir+"/"+action;
+ //dojo.debug(localUrl);
+ return localUrl;
+ }
+
+
+ if (!this.RPCUrl) {
+ dojo.raise("Empty RPCUrl: can't load");
+ }
+
+ return this.RPCUrl + ( this.RPCUrl.indexOf("?") > -1 ? "&" : "?") + "action="+action;
+ },
+
+
+ /**
+ * Make request to server about moving children.
+ *
+ * Request returns "true" if move succeeded,
+ * object with error field if failed
+ *
+ * I can't leave DragObject floating until async request returns, need to return false/true
+ * so making it sync way...
+ *
+ * Also, "loading" icon is not shown until function finishes execution, so no indication for remote request.
+ */
+ changeParentRemote: function(child, newParent, index){
+
+
+
+ //if (newParent.isTreeNode) newParent.markLoading();
+
+ var params = {
+ // where from
+ child: child.getInfo(),
+ childTree: child.tree.getInfo(),
+ // where to
+ newParent: newParent.getInfo(),
+ newParentTree: newParent.tree.getInfo()
+ };
+
+ var success;
+
+ //dojo.debug("changeParentRemote request")
+
+ dojo.io.bind({
+ url: this.getRPCUrl('changeParent'),
+ /* I hitch to get this.loadOkHandler */
+ load: dojo.lang.hitch(this,
+ function(type, obj) {
+ success = this.changeParentProcessResponse(type, obj, child, newParent, index) ;
+ }
+ ),
+ error: this.RPCErrorHandler,
+ mimetype: "text/json",
+ preventCache: true,
+ sync: true,
+ content: { data: dojo.json.serialize(params) }
+ });
+
+ //dojo.debug("changeParentRemote request done")
+
+ return success;
+ },
+
+ changeParentProcessResponse: function(type, result, child, newParent, index) {
+
+
+ if (!dojo.lang.isUndefined(result.error)) {
+ this.RPCErrorHandler(result.error);
+ return false;
+ }
+
+ child.tree.changeParent(child, newParent, index);
+ this.updateDND(child);
+
+ return true;
+ },
+
+ /**
+ * return true on success, false on failure
+ */
+ changeParent: function(child, newParent, index) {
+
+ /* move sourceTreeNode to new parent */
+ if (!this.canChangeParent(child, newParent)) {
+ return false;
+ }
+
+ /* load nodes into newParent in sync mode, if needed, first */
+ if (newParent.isTreeNode && newParent.state == newParent.loadStates.UNCHECKED) {
+ this.loadRemote(newParent, true);
+ }
+
+ var oldParent = child.parent;
+ var oldParentIndex = child.getParentIndex();
+
+
+ var result = this.changeParentRemote(child, newParent, index);
+
+ if (!result) return result;
+
+
+
+ /* publish many events here about structural changes */
+ dojo.event.topic.publish(this.eventNames.move,
+ {
+ oldParent: oldParent, oldParentIndex: oldParentIndex,
+ newParent: child.parent, newParentIndex: index,
+ child: child
+ }
+ );
+
+ this.expand(newParent);
+
+ return result;
+ },
+
+
+
+
+
+ /**
+ * Add all loaded nodes from array obj as node children and expand it
+ */
+ loadProcessResponse: function(type, node, result, callback) {
+
+ if (!dojo.lang.isUndefined(result.error)) {
+ this.RPCErrorHandler(result.error);
+ return false;
+ }
+
+ var newChildren = result;
+
+ if (!dojo.lang.isArray(newChildren)) {
+ dojo.raise('Not array loaded: '+newChildren);
+ }
+
+ for(var i=0; i<newChildren.length; i++) {
+ // looks like dojo.widget.manager needs no special "add" command
+ newChildren[i] = dojo.widget.createWidget(node.widgetType, newChildren[i]);
+ }
+
+ node.addAllChildren(newChildren);
+
+ node.state = node.loadStates.LOADED;
+
+ if (dojo.lang.isFunction(callback)) {
+ callback.apply(this, [node, newChildren]);
+ }
+ //this.expand(node);
+ },
+
+
+ /**
+ * Load children of the node from server
+ * Synchroneous loading doesn't break control flow
+ * I need sync mode for DnD
+ */
+ loadRemote: function(node, sync, callback){
+ node.markLoading();
+
+
+ var params = {
+ node: node.getInfo(),
+ tree: node.tree.getInfo()
+ };
+
+ var requestUrl = this.getRPCUrl('getChildren');
+ //dojo.debug(requestUrl)
+
+ dojo.io.bind({
+ url: requestUrl,
+ /* I hitch to get this.loadOkHandler */
+ load: dojo.lang.hitch(this,
+ function(type, result) {
+ this.loadProcessResponse(type, node, result, callback) ;
+ }
+ ),
+ error: this.RPCErrorHandler,
+ mimetype: "text/json",
+ preventCache: true,
+ sync: sync,
+ content: { data: dojo.json.serialize(params) }
+ });
+
+
+ },
+
+ onTreeClick: function(message){
+
+ //dojo.debug("EXPAND")
+
+ var node = message.source;
+
+ if (node.isExpanded){
+ this.collapse(node);
+ } else {
+ this.expand(node);
+ }
+ },
+
+
+ onIconClick: function(message){
+ this.onTitleClick(message);
+ },
+
+ onTitleClick: function(message){
+ var node = message.source;
+ var e = message.event;
+
+ if (node.tree.selector.selectedNode === node){
+ dojo.event.topic.publish(this.eventNames.dblselect, { source: node });
+ return;
+ }
+
+
+ /* deselect old node */
+ if (node.tree.selector.selectedNode) {
+ this.deselect(node.tree.selector.selectedNode);
+ }
+
+ this.select(node);
+
+
+ },
+
+
+ /**
+ * Process drag'n'drop -> drop
+ * NOT event-driven, because its result is important (success/false)
+ * in event system subscriber can't return a result into _current function control-flow_
+ * @return true on success, false on failure
+ */
+ processDrop: function(sourceNode, parentNode, index){
+ if (dojo.lang.isUndefined(index)) {
+ var index = 0;
+ }
+
+ //dojo.debug('drop index '+index)
+ return this.changeParent(sourceNode, parentNode, index)
+
+ },
+
+
+ onNodeCreate: function(message) {
+ this.registerDNDNode(message.source);
+ },
+
+ select: function(node){
+
+ node.markSelected();
+
+ node.tree.selector.selectedNode = node;
+
+
+ dojo.event.topic.publish(this.eventNames.select, {source: node} );
+ },
+
+ deselect: function(node){
+ node.unMarkSelected();
+
+ node.tree.selector.selectedNode = null;
+ dojo.event.topic.publish(this.eventNames.deselect, {source: node} );
+ },
+
+ expand: function(node) {
+ //if (this.node=="Item 1.1") dojo.debug("expand IsExpanded:"+this.isExpanded);
+
+ if (node.isExpanded) return;
+
+ if (node.state == node.loadStates.UNCHECKED) {
+ this.loadRemote(node, false,
+ function(node, newChildren) {
+ this.expand(node);
+ }
+ );
+ } else {
+ node.expand();
+
+ dojo.event.topic.publish(this.eventNames.expand, {source: node} );
+ }
+ },
+
+ collapse: function(node) {
+ if (!node.isExpanded) return;
+
+ node.collapse();
+ dojo.event.topic.publish(this.eventNames.collapse, {source: node} );
+ },
+
+
+ /**
+ * Controller(node model) creates DNDNodes because it passes itself to node for synchroneous drops processing
+ * I can't process DnD with events cause an event can't return result success/false
+ */
+ registerDNDNode: function(node) {
+
+ if (this.DNDMode=="off") return;
+
+
+
+ //dojo.debug("registerDNDNode node "+node.title+" tree "+node.tree+" accepted sources "+node.tree.acceptDropSources);
+
+ /* I drag label, not domNode, because large domNodes are very slow to copy and large to drag */
+
+ var source = null;
+ var target = null;
+
+ if (!node.actionIsDisabled(node.actions.MOVE)) {
+ //dojo.debug("reg source")
+ var source = new dojo.dnd.TreeDragSource(node.labelNode, this, node.tree.widgetId, node);
+ this.dragSources[node.widgetId] = source;
+ }
+
+ //dojo.debugShallow(node.tree.widgetId)
+
+ if (this.DNDMode=="onto") {
+ var target = new dojo.dnd.TreeDropOntoTarget(node.labelNode, this, node.tree.acceptDropSources, node);
+ } else if (this.DNDMode=="between") {
+ var target = new dojo.dnd.TreeDropBetweenTarget(node.labelNode, this, node.tree.acceptDropSources, node);
+ }
+
+ this.dropTargets[node.widgetId] = target;
+
+
+ //dojo.debug("registerDNDNode "+this.dragSources[node.widgetId].treeNode.title)
+
+ },
+
+
+ unregisterDNDNode: function(node) {
+
+ //dojo.debug("unregisterDNDNode "+node.title)
+ //dojo.debug("unregisterDNDNode "+this.dragSources[node.widgetId].treeNode.title)
+
+ if (this.dragSources[node.widgetId]) {
+ dojo.dnd.dragManager.unregisterDragSource(this.dragSources[node.widgetId]);
+ delete this.dragSources[node.widgetId];
+ }
+
+ if (this.dropTargets[node.widgetId]) {
+ dojo.dnd.dragManager.unregisterDropTarget(this.dropTargets[node.widgetId]);
+ delete this.dropTargets[node.widgetId];
+ }
+ },
+
+ // update types for DND right accept
+ // E.g when move from one tree to another tree
+ updateDND: function(node) {
+
+ this.unregisterDNDNode(node);
+
+ this.registerDNDNode(node);
+
+
+ //dojo.debug("!!!"+this.dropTargets[node].acceptedTypes)
+
+ for(var i=0; i<node.children.length; i++) {
+ // dojo.debug(node.children[i].title);
+ this.updateDND(node.children[i]);
+ }
+
+ },
+
+
+
+
+ // -----------------------------------------------------------------------------
+ // Remove nodes stuff
+ // -----------------------------------------------------------------------------
+
+
+
+ canRemoveNode: function(node) {
+ return true;
+ },
+
+ removeNode: function(node, callback) {
+ if (!this.canRemoveNode(node)) {
+ return false;
+ }
+
+ return this.removeNodeRemote(node, callback);
+
+ },
+
+
+ removeNodeRemote: function(node, callback) {
+
+ var params = {
+ node: node.getInfo(),
+ tree: node.tree.getInfo()
+ }
+
+ dojo.io.bind({
+ url: this.getRPCUrl('removeNode'),
+ /* I hitch to get this.loadOkHandler */
+ load: dojo.lang.hitch(this, function(type, obj) {
+ this.removeNodeProcessResponse(type, node, callback, obj) }
+ ),
+ error: this.RPCErrorHandler,
+ mimetype: "text/json",
+ preventCache: true,
+ content: {data: dojo.json.serialize(params) }
+ });
+
+ },
+
+ removeNodeProcessResponse: function(type, node, callback, result) {
+ if (!dojo.lang.isUndefined(result.error)) {
+ this.RPCErrorHandler(result.error);
+ return false;
+ }
+
+ if (!result) return false;
+
+ if (result == true) {
+ /* change parent succeeded */
+ this.doRemoveNode(node, node);
+ if (callback) {
+ // provide context manually e.g with dojo.lang.hitch.
+ callback.apply(this, [node]);
+ }
+
+ return true;
+ } else if (dojo.lang.isObject(result)) {
+ dojo.raise(result.error);
+ } else {
+ dojo.raise("Invalid response "+obj)
+ }
+
+
+ },
+
+
+ /* This function does the real job only w/o any checks */
+ doRemoveNode: function(node) {
+ /* publish many events here about structural changes */
+
+ if (node.tree.selector.selectedNode === node) {
+ this.deselect(node);
+ }
+
+ this.unregisterDNDNode(node);
+
+ removed_node = node.tree.removeChild(node);
+
+ // nodes AFTER
+ dojo.event.topic.publish(this.eventNames.remove,
+ { node: removed_node }
+ );
+
+ },
+
+
+ // -----------------------------------------------------------------------------
+ // Create node stuff
+ // -----------------------------------------------------------------------------
+
+
+
+
+ canCreateNode: function(parent, index, data) {
+ if (!parent.isFolder) return false;
+
+ return true;
+ },
+
+
+ /* send data to server and add child from server */
+ /* data may contain an almost ready child, or anything else, suggested to server */
+ /* server responds with child data to be inserted */
+ createNode: function(parent, index, data, callback) {
+ if (!this.canCreateNode(parent, index, data)) {
+ return false;
+ }
+
+
+ /* load nodes into newParent in sync mode, if needed, first */
+ if (parent.state == parent.loadStates.UNCHECKED) {
+ this.loadRemote(parent, true);
+ }
+
+
+ return this.createNodeRemote(parent, index, data, callback);
+
+ },
+
+
+ createNodeRemote: function(parent, index, data, callback) {
+
+ var params = {
+ treeId: parent.tree.widgetId,
+ parentId: parent.widgetId,
+ index: index,
+ data: dojo.json.serialize(data)
+ }
+
+ dojo.io.bind({
+ url: this.getRPCUrl('createNode'),
+ /* I hitch to get this.loadOkHandler */
+ load: dojo.lang.hitch(this, function(type, obj) {
+ this.createNodeProcessResponse(type, obj, parent, index, callback) }
+ ),
+ error: this.RPCErrorHandler,
+ mimetype: "text/json",
+ preventCache: true,
+ content: params
+ });
+
+ },
+
+ createNodeProcessResponse: function(type, result, parent, index, callback) {
+
+ if (!dojo.lang.isUndefined(result.error)) {
+ this.RPCErrorHandler(result.error);
+ return false;
+ }
+
+ if (!parent.isTreeNode) {
+ dojo.raise("Can only add children to EditorTreeNode")
+ }
+
+ if (!dojo.lang.isObject(result)) {
+ dojo.raise("Invalid result "+result)
+ }
+
+ this.doCreateNode(parent, index, result);
+
+ if (callback) {
+ // provide context manually e.g with dojo.lang.hitch.
+ callback.apply(this, [parent, index, result]);
+ }
+
+ },
+
+
+ doCreateNode: function(parent, index, child) {
+
+ var newChild = dojo.widget.createWidget("EditorTreeNode", child);
+
+ parent.addChild(newChild, index);
+
+ this.expand(parent);
+ }
+
+
+});
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeNode.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeNode.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeNode.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeNode.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,572 @@
+/*
+ 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.widget.EditorTreeNode");
+
+dojo.require("dojo.event.*");
+dojo.require("dojo.fx.html");
+dojo.require("dojo.io.*");
+
+// make it a tag
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreeNode");
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreePropertySetter");
+
+dojo.widget.EditorTreePropertySetter = function() {
+ dojo.widget.HtmlWidget.call(this);
+}
+dojo.inherits(dojo.widget.EditorTreePropertySetter, dojo.widget.HtmlWidget);
+
+dojo.lang.extend(dojo.widget.EditorTreePropertySetter, {
+ widgetType: "EditorTreePropertySetter",
+
+ property: "",
+ domNode: null,
+
+ /* delete myself from document and set as parent's property */
+ postCreate: function() {
+ this.parent[this.property] = this;
+
+ this.destroyRendering();
+ dojo.widget.HtmlWidget.prototype.removeChild.apply(this.parent, [this]);
+ }
+
+});
+
+// # //////////
+
+dojo.widget.EditorTreeNode = function() {
+ dojo.widget.HtmlWidget.call(this);
+
+ this.actionsDisabled = [];
+}
+
+dojo.inherits(dojo.widget.EditorTreeNode, dojo.widget.HtmlWidget);
+
+dojo.lang.extend(dojo.widget.EditorTreeNode, {
+ widgetType: "EditorTreeNode",
+
+ loadStates: {
+ UNCHECKED: "UNCHECKED",
+ LOADING: "LOADING",
+ LOADED: "LOADED"
+ },
+
+
+ actions: {
+ MOVE: "MOVE",
+ REMOVE: "REMOVE",
+ EDIT: "EDIT",
+ ADDCHILD: "ADDCHILD"
+ },
+
+ isContainer: true,
+
+ domNode: null,
+ containerNode: null,
+
+
+ templateString: '<div class="dojoTreeNode"><div style="display:none" dojoAttachPoint="containerNode"></div></div>',
+
+ //childIconSrc: null,
+ childIconSrc: null,
+ childIconFolderSrc: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/closed.gif").toString(), // for under root parent item child icon,
+ childIconDocumentSrc: dojo.uri.dojoUri("src/widget/templates/images/EditorTree/document.gif").toString(), // for under root parent item child icon,
+
+ childIcon: null,
+ isTreeNode: true,
+
+ objectId: "", // the widget represents an object
+
+ afterLabel: "",
+ afterLabelNode: null, // node to the left of labelNode
+
+ // an icon left from childIcon: imgs[-2].
+ // if +/- for folders, blank for leaves
+ expandIcon: null,
+
+ title: "",
+ href: "", // node may have href for navigation purposes
+ isFolder: false,
+
+ labelNode: null, // the item label
+ titleNode: null, // the item title
+ imgs: null, // an array of icons imgs
+
+
+ tree: null,
+
+ depth: 0,
+
+ isFirstNode: false,
+ isLastNode: false,
+ isExpanded: false,
+
+ state: null, // after creation will change to loadStates: "loaded/loading/unchecked"
+ domNodeInitialized: false, // domnode is initialized with icons etc
+
+ actionIsDisabled: function(action) {
+ var _this = this;
+
+ //dojo.debug(this+" "+action+" ::"+this.actionsDisabled);
+
+ if (action == this.actions.ADDCHILD && !this.isFolder) return true;
+
+ var disabled = dojo.lang.inArray(_this.actionsDisabled, action);
+
+ return disabled;
+ },
+
+ getInfo: function() {
+ var _this = this;
+ // No title here (title may be widget)
+ var info = {
+ widgetId: _this.widgetId,
+ objectId: _this.objectId,
+ index: _this.getParentIndex(),
+ isFolder: _this.isFolder
+ }
+
+ return info;
+ },
+
+ initialize: function(args, frag){
+ var _this = this;
+ this.state = this.loadStates.UNCHECKED;
+
+
+ //dojo.lang.forEach(this.children, function(child) { alert(child.widgetType); })
+ //var titleNode = this.getChildrenOfType("dojo.widget.EditorTreeNodeTitle");
+ //alert(titleNode);
+
+/*
+ if (args['isFolder'] == "true" || args['isFolder'] === true || args['isfolder'] == "true" ) { // IE || program args || FF
+ this.isFolder = true;
+ } else {
+ this.isFolder = false;
+ }
+*/
+
+ for(var i=0; i<this.actionsDisabled.length; i++) {
+ this.actionsDisabled[i] = this.actionsDisabled[i].toUpperCase();
+ }
+
+
+
+ //this.domNode.treeNode = this; // domNode knows about its treeNode owner. E.g for DnD
+ },
+
+
+ /**
+ * Change visible node depth by appending/prepending with blankImgs
+ * @param depthDiff Integer positive => move right, negative => move left
+ */
+ adjustDepth: function(depthDiff) {
+
+ for(var i=0; i<this.children.length; i++) {
+ this.children[i].adjustDepth(depthDiff);
+ }
+
+ this.depth += depthDiff;
+
+ if (depthDiff>0) {
+ for(var i=0; i<depthDiff; i++) {
+ var img = this.tree.makeBlankImg();
+ this.imgs.unshift(img);
+ //dojo.debugShallow(this.domNode);
+ this.domNode.insertBefore(this.imgs[0], this.domNode.firstChild);
+
+ }
+ }
+ if (depthDiff<0) {
+ for(var i=0; i<-depthDiff;i++) {
+ this.imgs.shift();
+ this.domNode.removeChild(this.domNode.firstChild);
+ }
+ }
+
+ },
+
+
+ markLoading: function() {
+ this.expandIcon.src = this.tree.expandIconSrcLoading;
+
+
+ },
+
+
+ setFolder: function() {
+ dojo.event.connect(this.expandIcon, 'onclick', this, 'onTreeClick');
+ this.isFolder = true;
+ },
+
+ makeTitleNode: function() {
+ var domNode = document.createElement('span');
+
+ if (dojo.lang.isString(this.title)) {
+ var textNode = document.createTextNode(this.title);
+ domNode.appendChild(textNode);
+ } else if (this.title instanceof dojo.widget.EditorTreePropertySetter) {
+ dojo.dom.moveChildren(this.title.domNode, domNode);
+ }
+ dojo.html.addClass(domNode, 'dojoTreeNodeLabelTitle');
+
+ return domNode;
+
+ },
+
+ makeAfterLabelNode: function() {
+
+ var domNode = document.createElement('span');
+
+ if (dojo.lang.isString(this.afterLabel)) {
+ var textNode = document.createTextNode(this.afterLabel);
+ domNode.appendChild(textNode);
+ } else if (this.afterLabel instanceof dojo.widget.EditorTreePropertySetter) {
+ dojo.dom.moveChildren(this.afterLabel.domNode, domNode);
+ }
+ dojo.html.addClass(domNode, 'dojoTreeNodeAfterLabel');
+
+ return domNode;
+ },
+
+ buildNode: function(tree, depth){
+
+ this.tree = tree;
+ this.depth = depth;
+
+
+ //
+ // add the tree icons
+ //
+
+ this.imgs = [];
+
+ for(var i=0; i<this.depth+1; i++){
+
+ var img = this.tree.makeBlankImg();
+
+ this.domNode.insertBefore(img, this.containerNode);
+
+ this.imgs.push(img);
+ }
+
+
+ this.expandIcon = this.imgs[this.imgs.length-1];
+
+
+ //
+ // add the cell label
+ //
+
+
+ this.labelNode = document.createElement('span');
+ this.labelNode.treeNode = this.widgetId; // link label node w/ real treeNode object(w/ self)
+ dojo.html.addClass(this.labelNode, 'dojoTreeNodeLabel');
+
+ // add child icon to label
+ this.childIcon = this.tree.makeBlankImg();
+ //this.childIcon.treeNode = this.widgetId;
+
+ // add to images before the title
+ this.imgs.push(this.childIcon);
+
+ this.labelNode.appendChild(this.childIcon);
+
+ // add title to label
+ this.titleNode = this.makeTitleNode();
+
+ this.labelNode.appendChild(this.titleNode);
+
+ this.domNode.insertBefore(this.labelNode, this.containerNode);
+
+ this.afterLabelNode = this.makeAfterLabelNode();
+
+ this.domNode.insertBefore(this.afterLabelNode, this.containerNode);
+
+
+ // node with children(from source html) becomes folder on build stage.
+ if (this.children.length || this.isFolder) {
+ this.setFolder();
+ }
+
+ dojo.event.connect(this.childIcon, 'onclick', this, 'onIconClick');
+ dojo.event.connect(this.titleNode, 'onclick', this, 'onTitleClick');
+
+
+ //
+ // create the child rows
+ //
+
+
+ for(var i=0; i<this.children.length; i++){
+
+ this.children[i].isFirstNode = (i == 0) ? true : false;
+ this.children[i].isLastNode = (i == this.children.length-1) ? true : false;
+ this.children[i].parent = this;
+
+ var node = this.children[i].buildNode(this.tree, this.depth+1);
+
+ this.containerNode.appendChild(node);
+ }
+
+
+ if (this.children.length) {
+ this.state = this.loadStates.LOADED;
+ }
+
+ if (this.isExpanded) {
+ this.expand();
+ }else { // leads to double icon updates
+ this.updateIcons();
+ }
+
+ this.domNodeInitialized = true;
+
+ dojo.event.topic.publish(this.tree.eventNames.nodeCreate, { source: this } );
+
+ return this.domNode;
+ },
+
+ onTreeClick: function(e){
+ dojo.event.topic.publish(this.tree.eventNames.treeClick, { source: this, event: e });
+ },
+
+ onIconClick: function(e){
+ dojo.event.topic.publish(this.tree.eventNames.iconClick, { source: this, event: e });
+ },
+
+ onTitleClick: function(e){
+ dojo.event.topic.publish(this.tree.eventNames.titleClick, { source: this, event: e });
+ },
+
+ markSelected: function() {
+ dojo.html.addClass(this.titleNode, 'dojoTreeNodeLabelSelected');
+ },
+
+
+ unMarkSelected: function() {
+ //dojo.debug('unmark')
+ dojo.html.removeClass(this.titleNode, 'dojoTreeNodeLabelSelected');
+ },
+
+
+ updateIcons: function(){
+
+
+ dojo.profile.start("updateIcons")
+
+ //dojo.debug("Update icons for "+this.widgetId)
+ //dojo.debug(this.isFolder)
+
+ this.imgs[0].style.display = this.tree.showRootGrid ? 'inline' : 'none';
+
+
+ //
+ // set the expand icon
+ //
+
+ if (this.isFolder){
+
+ this.expandIcon.src = this.isExpanded ? this.tree.expandIconSrcMinus : this.tree.expandIconSrcPlus;
+
+ } else {
+ this.expandIcon.src = this.tree.blankIconSrc;
+ }
+
+ //
+ // set the child icon
+ //
+ this.buildChildIcon();
+
+
+ //
+ // set the grid under the expand icon
+ //
+
+ if (this.tree.showGrid){
+ if (this.depth){
+ this.setGridImage(-2, this.isLastNode ? this.tree.gridIconSrcL : this.tree.gridIconSrcT);
+ }else{
+ //dojo.debug("Depth 0 "+this+" first:"+this.isFirstNode+" last:"+this.isLastNode)
+ if (this.isFirstNode){
+ this.setGridImage(-2, this.isLastNode ? this.tree.gridIconSrcX : this.tree.gridIconSrcY);
+ }else{
+ this.setGridImage(-2, this.isLastNode ? this.tree.gridIconSrcL : this.tree.gridIconSrcT);
+ }
+ }
+ }else{
+ this.setGridImage(-2, this.tree.blankIconSrc);
+ }
+
+
+
+ //
+ // set the grid under the child icon
+ //
+
+ if ((this.depth || this.tree.showRootGrid) && this.tree.showGrid){
+ this.setGridImage(-1, (this.children.length && this.isExpanded) ? this.tree.gridIconSrcP : this.tree.gridIconSrcC);
+ }else{
+ if (this.tree.showGrid && !this.tree.showRootGrid){
+ this.setGridImage(-1, (this.children.length && this.isExpanded) ? this.tree.gridIconSrcZ : this.tree.blankIconSrc);
+ }else{
+ this.setGridImage(-1, this.tree.blankIconSrc);
+ }
+ }
+
+
+
+ //if (this.title=="Item 1.1") dojo.debug("updateIcons IsExpanded:"+this.isExpanded+" "+this.expandIcon.src);
+
+ //
+ // set the vertical grid icons
+ //
+
+ var parent = this.parent;
+
+ for(var i=0; i<this.depth; i++){
+
+ var idx = this.imgs.length-(3+i);
+
+ this.setGridImage(
+ idx,
+ (this.tree.showGrid && !parent.isLastNode) ? this.tree.gridIconSrcV : this.tree.blankIconSrc
+ );
+
+ parent = parent.parent;
+ }
+
+ //alert(dojo.profile.toSource());
+ dojo.profile.stop("updateIcons")
+
+ },
+
+ buildChildIcon: function() {
+ /* no child icon */
+ if (this.childIconSrc == "none") {
+ this.childIcon.style.display = 'none';
+ return;
+ }
+
+ /* assign default icon if not set */
+ if (!this.childIconSrc) {
+ if (this.isFolder){
+ this.childIconSrc = this.childIconFolderSrc;
+ } else {
+ this.childIconSrc = this.childIconDocumentSrc;
+ }
+ }
+
+ this.childIcon.style.display = 'inline';
+ this.childIcon.src = this.childIconSrc;
+ },
+
+ setGridImage: function(idx, src){
+
+ if (idx < 0){
+ idx = this.imgs.length + idx;
+ }
+
+ //if (idx >= this.imgs.length-2) return;
+ this.imgs[idx].style.backgroundImage = 'url(' + src + ')';
+ },
+
+
+ updateIconTree: function(){
+ this.tree.updateIconTree.call(this);
+ },
+
+
+
+ expand: function(){
+
+ //if (this.title=="Item 1.1") dojo.debug("expand IsExpanded:"+this.isExpanded);
+
+
+ if (this.children.length) {
+ this.showChildren();
+ }
+
+ this.isExpanded = true;
+
+ this.updateIcons();
+ },
+
+ collapse: function(){
+ this.hideChildren();
+ this.isExpanded = false;
+ this.updateIcons();
+ },
+
+ hideChildren: function(){
+ this.tree.toggler.hide(this.containerNode);
+
+ /* if dnd is in action, recalculate changed coordinates */
+ if(dojo.dnd.dragManager.dragObjects.length) {
+ dojo.dnd.dragManager.cacheTargetLocations();
+ }
+ },
+
+ showChildren: function(){
+ this.tree.toggler.show(this.containerNode);
+
+ /* if dnd is in action, recalculate changed coordinates */
+ if(dojo.dnd.dragManager.dragObjects.length) {
+ dojo.dnd.dragManager.cacheTargetLocations();
+ }
+ },
+
+
+ addChild: function(){
+ return this.tree.addChild.apply(this, arguments);
+ },
+
+ addAllChildren: function(){
+ return this.tree.addAllChildren.apply(this, arguments);
+ },
+
+ removeChild: function(){
+ return this.tree.removeChild.apply(this, arguments);
+ },
+
+
+ /* Edit current node : change properties and update contents */
+ edit: function(props) {
+ dojo.lang.mixin(this, props);
+ if (props.title) {
+ var domNode = this.makeTitleNode();
+ this.titleNode.parentNode.replaceChild(domNode, this.titleNode);
+ this.titleNode = domNode;
+ }
+
+ if (props.afterLabel) {
+ var domNode = this.makeAfterLabelNode();
+ this.afterLabelNode.parentNode.replaceChild(domNode, this.afterLabelNode);
+ this.afterLabelNode = domNode;
+ }
+
+ if (props.childIconSrc) {
+ this.childIcon.src = this.childIconSrc;
+ }
+
+
+ },
+
+ toString: function() {
+ return "["+this.widgetType+" Tree:"+this.tree+" ID:"+this.widgetId+"]";
+
+ }
+
+});
+
+
+
+
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeSelector.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeSelector.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeSelector.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/EditorTreeSelector.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,34 @@
+/*
+ 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.widget.EditorTreeSelector");
+
+dojo.require("dojo.widget.HtmlWidget");
+
+
+dojo.widget.tags.addParseTreeHandler("dojo:EditorTreeSelector");
+
+
+dojo.widget.EditorTreeSelector = function() {
+ dojo.widget.HtmlWidget.call(this);
+}
+
+dojo.inherits(dojo.widget.EditorTreeSelector, dojo.widget.HtmlWidget);
+
+
+dojo.lang.extend(dojo.widget.EditorTreeSelector, {
+ widgetType: "EditorTreeSelector",
+ selectedNode: null
+
+});
+
+
+
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FisheyeList.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FisheyeList.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FisheyeList.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FisheyeList.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,742 @@
+/*
+ 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.widget.FisheyeList");
+dojo.provide("dojo.widget.html.FisheyeList");
+dojo.provide("dojo.widget.html.FisheyeListItem");
+
+//
+// TODO
+// fix SVG support, and turn it on only if the browser supports it
+// fix really long labels in vertical mode
+//
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.HtmlWidget");
+dojo.require("dojo.dom");
+dojo.require("dojo.html");
+dojo.require("dojo.style");
+dojo.require("dojo.event");
+
+dojo.widget.tags.addParseTreeHandler("dojo:FisheyeList");
+dojo.widget.tags.addParseTreeHandler("dojo:FisheyeListItem");
+
+dojo.widget.html.FisheyeList = function(){
+ dojo.widget.HtmlWidget.call(this);
+}
+dojo.inherits(dojo.widget.html.FisheyeList, dojo.widget.HtmlWidget);
+
+dojo.lang.extend(dojo.widget.html.FisheyeList, {
+
+ templateString: '<div class="dojoHtmlFisheyeListBar"></div>',
+ templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlFisheyeList.css"),
+ widgetType: "FisheyeList",
+
+ EDGE: {
+ CENTER: 0,
+ LEFT: 1,
+ RIGHT: 2,
+ TOP: 3,
+ BOTTOM: 4
+ },
+
+ isContainer: true,
+ snarfChildDomOutput: true,
+
+ pos: {x: -1, y: -1}, // current cursor position, relative to the grid
+
+ // for conservative trigger mode, when triggered, timerScale is gradually increased from 0 to 1
+ timerScale: 1.0,
+
+ /////////////////////////////////////////////////////////////////
+ //
+ // i spy OPTIONS!!!!
+ //
+
+ itemWidth: 40,
+ itemHeight: 40,
+
+ itemMaxWidth: 150,
+ itemMaxHeight: 150,
+
+ orientation: 'horizontal',
+
+ conservativeTrigger: false, // don't active menu until mouse is over an image (macintosh style)
+
+ effectUnits: 2,
+ itemPadding: 10,
+
+ attachEdge: 'center',
+ labelEdge: 'bottom',
+
+ enableCrappySvgSupport: false,
+
+
+ //
+ //
+ //
+ /////////////////////////////////////////////////////////////////
+
+ fillInTemplate: function(args, frag) {
+ //dojo.debug(this.orientation);
+
+ dojo.html.disableSelection(this.domNode);
+
+ this.isHorizontal = (this.orientation == 'horizontal') ? 1 : 0;
+ this.selectedNode = -1;
+
+ this.isOver = false;
+ this.hitX1 = -1;
+ this.hitY1 = -1;
+ this.hitX2 = -1;
+ this.hitY2 = -1;
+
+ //
+ // only some edges make sense...
+ //
+
+ this.anchorEdge = this.toEdge(this.attachEdge, this.EDGE.CENTER);
+ this.labelEdge = this.toEdge(this.labelEdge, this.EDGE.TOP);
+
+ if ( this.isHorizontal && (this.anchorEdge == this.EDGE.LEFT )){ this.anchorEdge = this.EDGE.CENTER; }
+ if ( this.isHorizontal && (this.anchorEdge == this.EDGE.RIGHT )){ this.anchorEdge = this.EDGE.CENTER; }
+ if (!this.isHorizontal && (this.anchorEdge == this.EDGE.TOP )){ this.anchorEdge = this.EDGE.CENTER; }
+ if (!this.isHorizontal && (this.anchorEdge == this.EDGE.BOTTOM)){ this.anchorEdge = this.EDGE.CENTER; }
+
+ if (this.labelEdge == this.EDGE.CENTER){ this.labelEdge = this.EDGE.TOP; }
+ if ( this.isHorizontal && (this.labelEdge == this.EDGE.LEFT )){ this.labelEdge = this.EDGE.TOP; }
+ if ( this.isHorizontal && (this.labelEdge == this.EDGE.RIGHT )){ this.labelEdge = this.EDGE.TOP; }
+ if (!this.isHorizontal && (this.labelEdge == this.EDGE.TOP )){ this.labelEdge = this.EDGE.LEFT; }
+ if (!this.isHorizontal && (this.labelEdge == this.EDGE.BOTTOM)){ this.labelEdge = this.EDGE.LEFT; }
+
+
+ //
+ // figure out the proximity size
+ //
+
+ this.proximityLeft = this.itemWidth * (this.effectUnits - 0.5);
+ this.proximityRight = this.itemWidth * (this.effectUnits - 0.5);
+ this.proximityTop = this.itemHeight * (this.effectUnits - 0.5);
+ this.proximityBottom = this.itemHeight * (this.effectUnits - 0.5);
+
+ if (this.anchorEdge == this.EDGE.LEFT){
+ this.proximityLeft = 0;
+ }
+ if (this.anchorEdge == this.EDGE.RIGHT){
+ this.proximityRight = 0;
+ }
+ if (this.anchorEdge == this.EDGE.TOP){
+ this.proximityTop = 0;
+ }
+ if (this.anchorEdge == this.EDGE.BOTTOM){
+ this.proximityBottom = 0;
+ }
+ if (this.anchorEdge == this.EDGE.CENTER){
+ this.proximityLeft /= 2;
+ this.proximityRight /= 2;
+ this.proximityTop /= 2;
+ this.proximityBottom /= 2;
+ }
+ },
+
+ postCreate: function(args, frag) {
+
+ this.itemCount = this.children.length;
+
+ this.barWidth = (this.isHorizontal ? this.itemCount : 1) * this.itemWidth;
+ this.barHeight = (this.isHorizontal ? 1 : this.itemCount) * this.itemHeight;
+
+ this.totalWidth = this.proximityLeft + this.proximityRight + this.barWidth;
+ this.totalHeight = this.proximityTop + this.proximityBottom + this.barHeight;
+
+ //
+ // calculate effect ranges for each item
+ //
+
+ for (var i=0; i<this.children.length; i++){
+
+ this.children[i].posX = this.itemWidth * (this.isHorizontal ? i : 0);
+ this.children[i].posY = this.itemHeight * (this.isHorizontal ? 0 : i);
+
+ this.children[i].cenX = this.children[i].posX + (this.itemWidth / 2);
+ this.children[i].cenY = this.children[i].posY + (this.itemHeight / 2);
+
+ var isz = this.isHorizontal ? this.itemWidth : this.itemHeight;
+ var r = this.effectUnits * isz;
+ var c = this.isHorizontal ? this.children[i].cenX : this.children[i].cenY;
+ var lhs = this.isHorizontal ? this.proximityLeft : this.proximityTop;
+ var rhs = this.isHorizontal ? this.proximityRight : this.proximityBottom;
+ var siz = this.isHorizontal ? this.barWidth : this.barHeight;
+
+ var range_lhs = r;
+ var range_rhs = r;
+
+ if (range_lhs > c+lhs){ range_lhs = c+lhs; }
+ if (range_rhs > (siz-c+rhs)){ range_rhs = siz-c+rhs; }
+
+ this.children[i].effectRangeLeft = range_lhs / isz;
+ this.children[i].effectRangeRght = range_rhs / isz;
+
+ //dojo.debug('effect range for '+i+' is '+range_lhs+'/'+range_rhs);
+ }
+
+
+ //
+ // create the bar
+ //
+
+ this.domNode.style.width = this.barWidth + 'px';
+ this.domNode.style.height = this.barHeight + 'px';
+
+
+ //
+ // position the items
+ //
+ for (var i=0; i<this.children.length; i++){
+ var itm = this.children[i];
+ var elm = itm.domNode;
+ elm.style.left = itm.posX + 'px';
+ elm.style.top = itm.posY + 'px';
+ elm.style.width = this.itemWidth + 'px';
+ elm.style.height = this.itemHeight + 'px';
+
+ if ( itm.svgNode ) {
+ itm.svgNode.style.position = 'absolute';
+ itm.svgNode.style.left = this.itemPadding+'%';
+ itm.svgNode.style.top = this.itemPadding+'%';
+ itm.svgNode.style.width = (100 - 2 * this.itemPadding) + '%';
+ itm.svgNode.style.height = (100 - 2 * this.itemPadding) + '%';
+ itm.svgNode.style.zIndex = 1;
+
+ itm.svgNode.setSize(this.itemWidth, this.itemHeight);
+ } else {
+ itm.imgNode.style.left = this.itemPadding+'%';
+ itm.imgNode.style.top = this.itemPadding+'%';
+ itm.imgNode.style.width = (100 - 2 * this.itemPadding) + '%';
+ itm.imgNode.style.height = (100 - 2 * this.itemPadding) + '%';
+ }
+ }
+
+ //
+ // calc the grid
+ //
+
+ this.calcHitGrid();
+
+ //
+ // in liberal trigger mode, activate menu whenever mouse is close
+ //
+ if( !this.conservativeTrigger ){
+ dojo.event.connect(document.documentElement, "onmousemove", this, "mouseHandler");
+ }
+
+ // Deactivate the menu if mouse is moved off screen (doesn't work for FF?)
+ dojo.event.connect(document.documentElement, "onmouseout", this, "onBodyOut");
+ },
+
+ onBodyOut: function(e){
+ // clicking over an object inside of body causes this event to fire; ignore that case
+ if( dojo.html.overElement(document.body, e) ){
+ return;
+ }
+ this.setDormant(e);
+ },
+
+ // when mouse moves out of menu's range
+ setDormant: function(e){
+ if( !this.isOver ){ return; } // already dormant?
+ this.isOver = false;
+
+ if ( this.conservativeTrigger ) {
+ // user can't re-trigger the menu expansion
+ // until he mouses over a icon again
+ dojo.event.disconnect(document.documentElement, "onmousemove", this, "mouseHandler");
+ }
+ this.onGridMouseMove(-1, -1);
+ },
+
+ // when mouse is moved into menu's range
+ setActive: function(e){
+ if( this.isOver ){ return; } // already activated?
+ this.isOver = true;
+
+ if ( this.conservativeTrigger ) {
+ // switch event handlers so that we handle mouse events from anywhere near
+ // the menu
+ dojo.event.connect(document.documentElement, "onmousemove", this, "mouseHandler");
+
+ this.timerScale=0.0;
+
+ // call mouse handler to do some initial necessary calculations/positioning
+ this.mouseHandler(e);
+
+ // slowly expand the icon size so it isn't jumpy
+ this.expandSlowly();
+ }
+ },
+
+ // when mouse is moved
+ mouseHandler: function(e) {
+ var p = this.getCursorPos(e);
+
+ if ((p.x >= this.hitX1) && (p.x <= this.hitX2) &&
+ (p.y >= this.hitY1) && (p.y <= this.hitY2)){
+ if( !this.isOver ){
+ this.setActive(e);
+ }
+ this.onGridMouseMove(p.x-this.hitX1, p.y-this.hitY1);
+ }else{
+ if (this.isOver){
+ this.setDormant(e);
+ }
+ }
+ },
+
+ onResized: function() {
+ this.calcHitGrid();
+ },
+
+ onGridMouseMove: function(x, y){
+ this.pos = {x:x, y:y};
+ this.paint();
+ },
+
+ paint: function(){
+ var x=this.pos.x;
+ var y=this.pos.y;
+
+ if( this.itemCount <= 0 ){ return; }
+
+ //
+ // figure out our main index
+ //
+
+ var pos = this.isHorizontal ? x : y;
+ var prx = this.isHorizontal ? this.proximityLeft : this.proximityTop;
+ var siz = this.isHorizontal ? this.itemWidth : this.itemHeight;
+ var sim = this.isHorizontal ?
+ (1.0-this.timerScale)*this.itemWidth + this.timerScale*this.itemMaxWidth :
+ (1.0-this.timerScale)*this.itemHeight + this.timerScale*this.itemMaxHeight ;
+
+ var cen = ((pos - prx) / siz) - 0.5;
+ var max_off_cen = (sim / siz) - 0.5;
+
+ if (max_off_cen > this.effectUnits){ max_off_cen = this.effectUnits; }
+
+
+ //
+ // figure out our off-axis weighting
+ //
+
+ var off_weight = 0;
+
+ if (this.anchorEdge == this.EDGE.BOTTOM){
+ var cen2 = (y - this.proximityTop) / this.itemHeight;
+ off_weight = (cen2 > 0.5) ? 1 : y / (this.proximityTop + (this.itemHeight / 2));
+ }
+ if (this.anchorEdge == this.EDGE.TOP){
+ var cen2 = (y - this.proximityTop) / this.itemHeight;
+ off_weight = (cen2 < 0.5) ? 1 : (this.totalHeight - y) / (this.proximityBottom + (this.itemHeight / 2));
+ }
+ if (this.anchorEdge == this.EDGE.RIGHT){
+ var cen2 = (x - this.proximityLeft) / this.itemWidth;
+ off_weight = (cen2 > 0.5) ? 1 : x / (this.proximityLeft + (this.itemWidth / 2));
+ }
+ if (this.anchorEdge == this.EDGE.LEFT){
+ var cen2 = (x - this.proximityLeft) / this.itemWidth;
+ off_weight = (cen2 < 0.5) ? 1 : (this.totalWidth - x) / (this.proximityRight + (this.itemWidth / 2));
+ }
+ if (this.anchorEdge == this.EDGE.CENTER){
+
+ if (this.isHorizontal){
+ off_weight = y / (this.totalHeight);
+ }else{
+ off_weight = x / (this.totalWidth);
+ }
+
+ if (off_weight > 0.5){
+ off_weight = 1 - off_weight;
+ }
+
+ off_weight *= 2;
+ }
+
+
+ //
+ // set the sizes
+ //
+
+ for(var i=0; i<this.itemCount; i++){
+
+ var weight = this.weightAt(cen, i);
+
+ if (weight < 0){weight = 0;}
+
+ this.setitemsize(i, weight * off_weight);
+ }
+
+ //
+ // set the positions
+ //
+
+ var main_p = Math.round(cen);
+ var offset = 0;
+
+ if (cen < 0){
+ main_p = 0;
+
+ }else if (cen > this.itemCount - 1){
+
+ main_p = this.itemCount -1;
+
+ }else{
+
+ offset = (cen - main_p) * ((this.isHorizontal ? this.itemWidth : this.itemHeight) - this.children[main_p].sizeMain);
+ }
+
+ this.positionElementsFrom(main_p, offset);
+ },
+
+ weightAt: function(cen, i){
+
+ var dist = Math.abs(cen - i);
+
+ var limit = ((cen - i) > 0) ? this.children[i].effectRangeRght : this.children[i].effectRangeLeft;
+
+ return (dist > limit) ? 0 : (1 - dist / limit);
+ },
+
+ positionFromNode: function(p, w){
+
+ //
+ // we need to grow all the nodes growing out from node 'i'
+ //
+
+ this.setitemsize(p, w);
+
+ var wx = w;
+ for(var i=p; i<this.itemCount; i++){
+ wx = 0.8 * wx;
+ this.setitemsize(i, wx);
+ }
+
+ var wx = w;
+ for(var i=p; i>=0; i--){
+ wx = 0.8 * wx;
+ this.setitemsize(i, wx);
+ }
+ },
+
+ setitemsize: function(p, scale){
+ scale *= this.timerScale;
+ var w = Math.round(this.itemWidth + ((this.itemMaxWidth - this.itemWidth ) * scale));
+ var h = Math.round(this.itemHeight + ((this.itemMaxHeight - this.itemHeight) * scale));
+
+ if (this.isHorizontal){
+
+ this.children[p].sizeW = w;
+ this.children[p].sizeH = h;
+
+ this.children[p].sizeMain = w;
+ this.children[p].sizeOff = h;
+
+ var y = 0;
+
+ if (this.anchorEdge == this.EDGE.TOP){
+
+ y = (this.children[p].cenY - (this.itemHeight / 2));
+
+ }else if (this.anchorEdge == this.EDGE.BOTTOM){
+
+ y = (this.children[p].cenY - (h - (this.itemHeight / 2)));
+
+ }else{
+
+ y = (this.children[p].cenY - (h / 2));
+ }
+
+ this.children[p].usualX = Math.round(this.children[p].cenX - (w / 2));
+
+ this.children[p].domNode.style.top = y + 'px';
+
+ this.children[p].domNode.style.left = this.children[p].usualX + 'px';
+
+ }else{
+
+ this.children[p].sizeW = w;
+ this.children[p].sizeH = h;
+
+ this.children[p].sizeOff = w;
+ this.children[p].sizeMain = h;
+
+ var x = 0;
+
+ if (this.anchorEdge == this.EDGE.LEFT){
+
+ x = this.children[p].cenX - (this.itemWidth / 2);
+
+ }else if (this.anchorEdge == this.EDGE.RIGHT){
+
+ x = this.children[p].cenX - (w - (this.itemWidth / 2));
+ }else{
+
+ x = this.children[p].cenX - (w / 2);
+ }
+
+ this.children[p].domNode.style.left = x + 'px';
+ this.children[p].usualY = Math.round(this.children[p].cenY - (h / 2));
+
+ this.children[p].domNode.style.top = this.children[p].usualY + 'px';
+ }
+
+ this.children[p].domNode.style.width = w + 'px';
+ this.children[p].domNode.style.height = h + 'px';
+
+ if (this.children[p].svgNode){
+ this.children[p].svgNode.setSize(w, h);
+ }
+ },
+
+ positionElementsFrom: function(p, offset){
+
+ var pos = 0;
+
+ if (this.isHorizontal){
+ pos = Math.round(this.children[p].usualX + offset);
+ this.children[p].domNode.style.left = pos + 'px';
+ }else{
+ pos = Math.round(this.children[p].usualY + offset);
+ this.children[p].domNode.style.top = pos + 'px';
+ }
+ this.positionLabel(this.children[p]);
+
+
+ //
+ // position before
+ //
+
+ var bpos = pos;
+
+ for(var i=p-1; i>=0; i--){
+
+ bpos -= this.children[i].sizeMain;
+
+ if (this.isHorizontal){
+ this.children[i].domNode.style.left = bpos + 'px';
+ }else{
+ this.children[i].domNode.style.top = bpos + 'px';
+ }
+ this.positionLabel(this.children[i]);
+ }
+
+ //
+ // position after
+ //
+
+ var apos = pos;
+
+ for(var i=p+1; i<this.itemCount; i++){
+
+ apos += this.children[i-1].sizeMain;
+
+ if (this.isHorizontal){
+ this.children[i].domNode.style.left = apos + 'px';
+ }else{
+ this.children[i].domNode.style.top = apos + 'px';
+ }
+ this.positionLabel(this.children[i]);
+ }
+
+ },
+
+ positionLabel: function(itm){
+
+ var x = 0;
+ var y = 0;
+
+ var labelW = dojo.style.getOuterWidth(itm.lblNode);
+ var labelH = dojo.style.getOuterHeight(itm.lblNode);
+
+ if (this.labelEdge == this.EDGE.TOP){
+ x = Math.round((itm.sizeW / 2) - (labelW / 2));
+ y = -labelH;
+ }
+
+ if (this.labelEdge == this.EDGE.BOTTOM){
+ x = Math.round((itm.sizeW / 2) - (labelW / 2));
+ y = itm.sizeH;
+ }
+
+ if (this.labelEdge == this.EDGE.LEFT){
+ x = -labelW;
+ y = Math.round((itm.sizeH / 2) - (labelH / 2));
+ }
+
+ if (this.labelEdge == this.EDGE.RIGHT){
+ x = itm.sizeW;
+ y = Math.round((itm.sizeH / 2) - (labelH / 2));
+ }
+
+ itm.lblNode.style.left = x + 'px';
+ itm.lblNode.style.top = y + 'px';
+ },
+
+ getCursorPos: function(e){
+ return {
+ 'x': e.pageX || e.clientX + document.body.scrollLeft,
+ 'y': e.pageY || e.clientY + document.body.scrollTop
+ };
+ },
+
+ calcHitGrid: function(){
+
+ var pos = dojo.style.getAbsolutePosition(this.domNode);
+
+ this.hitX1 = pos.x - this.proximityLeft;
+ this.hitY1 = pos.y - this.proximityTop;
+ this.hitX2 = this.hitX1 + this.totalWidth;
+ this.hitY2 = this.hitY1 + this.totalHeight;
+
+ //dojo.debug(this.hitX1+','+this.hitY1+' // '+this.hitX2+','+this.hitY2);
+ },
+
+ toEdge: function(inp, def){
+ return this.EDGE[inp.toUpperCase()] || def;
+ },
+
+ // slowly expand the image to user specified max size
+ expandSlowly: function(){
+ if( !this.isOver ){ return; }
+ this.timerScale += 0.2;
+ this.paint();
+ if ( this.timerScale<1.0 ) {
+ dojo.lang.setTimeout(this, "expandSlowly", 10);
+ }
+ }
+
+});
+
+dojo.widget.html.FisheyeListItem = function(){
+ dojo.widget.HtmlWidget.call(this);
+}
+dojo.inherits(dojo.widget.html.FisheyeListItem, dojo.widget.HtmlWidget);
+
+dojo.lang.extend(dojo.widget.html.FisheyeListItem, {
+ widgetType: "FisheyeListItem",
+
+ // Constructor arguments
+ iconSrc: "",
+ svgSrc: "",
+ caption: "",
+
+ blankImgPath: dojo.uri.dojoUri("src/widget/templates/images/blank.gif"),
+
+ templateString:
+ '<div class="dojoHtmlFisheyeListItem">' +
+ ' <img class="dojoHtmlFisheyeListItemImage" dojoAttachPoint="imgNode" dojoAttachEvent="onMouseOver;onMouseOut;onClick">' +
+ ' <div class="dojoHtmlFisheyeListItemLabel" dojoAttachPoint="lblNode"></div>' +
+ '</div>',
+
+ imgNode: null,
+
+ fillInTemplate: function() {
+ //
+ // set image
+ // TODO: turn on/off SVG support based on browser version.
+ // this.parent.enableCrappySvgSupport is not available to this function
+ //
+ if (this.svgSrc != ""){
+ this.svgNode = this.createSvgNode(this.svgSrc);
+ this.domNode.appendChild(this.svgNode);
+ this.imgNode.style.display = 'none';
+ } else if((this.iconSrc.toLowerCase().substring(this.iconSrc.length-4)==".png")&&(dojo.render.html.ie)){
+ this.imgNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.iconSrc+"', sizingMethod='scale')";
+ this.imgNode.src = this.blankImgPath.toString();
+ } else {
+ this.imgNode.src = this.iconSrc;
+ }
+
+ //
+ // Label
+ //
+ if ( this.lblNode ) {
+ this.lblNode.appendChild(document.createTextNode(this.caption));
+ }
+ dojo.html.disableSelection(this.domNode);
+ },
+
+ createSvgNode: function(src){
+
+ var elm = document.createElement('embed');
+ elm.src = src;
+ elm.type = 'image/svg+xml';
+ //elm.style.border = '1px solid black';
+ elm.style.width = '1px';
+ elm.style.height = '1px';
+ elm.loaded = 0;
+ elm.setSizeOnLoad = false;
+
+ elm.onload = function(){
+ this.svgRoot = this.getSVGDocument().rootElement;
+ this.svgDoc = this.getSVGDocument().documentElement;
+ this.zeroWidth = this.svgRoot.width.baseVal.value;
+ this.zeroHeight = this.svgRoot.height.baseVal.value;
+ this.loaded = true;
+
+ if (this.setSizeOnLoad){
+ this.setSize(this.setWidth, this.setHeight);
+ }
+ }
+
+ elm.setSize = function(w, h){
+ if (!this.loaded){
+ this.setWidth = w;
+ this.setHeight = h;
+ this.setSizeOnLoad = true;
+ return;
+ }
+
+ this.style.width = w+'px';
+ this.style.height = h+'px';
+ this.svgRoot.width.baseVal.value = w;
+ this.svgRoot.height.baseVal.value = h;
+
+ var scale_x = w / this.zeroWidth;
+ var scale_y = h / this.zeroHeight;
+
+ for(var i=0; i<this.svgDoc.childNodes.length; i++){
+ if (this.svgDoc.childNodes[i].setAttribute){
+ this.svgDoc.childNodes[i].setAttribute( "transform", "scale("+scale_x+","+scale_y+")" );
+ }
+ }
+ }
+
+ return elm;
+ },
+
+ onMouseOver: function(e) {
+ // in conservative mode, don't activate the menu until user mouses over an icon
+ if( !this.parent.isOver ){
+ this.parent.setActive(e);
+ }
+ if ( this.caption != "" ) {
+ dojo.html.addClass(this.lblNode, "selected");
+ this.parent.positionLabel(this);
+ }
+ },
+
+ onMouseOut: function() {
+ dojo.html.removeClass(this.lblNode, "selected");
+ },
+
+ onClick: function() {
+ }
+});
+
Added: jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FloatingPane.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FloatingPane.js?rev=371434&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FloatingPane.js (added)
+++ jakarta/tapestry/trunk/framework/src/js/dojo/src/widget/FloatingPane.js Sun Jan 22 17:23:23 2006
@@ -0,0 +1,528 @@
+/*
+ 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.widget.FloatingPane");
+dojo.provide("dojo.widget.html.FloatingPane");
+
+//
+// this widget provides a window-like floating pane
+//
+
+dojo.require("dojo.widget.*");
+dojo.require("dojo.widget.Manager");
+dojo.require("dojo.html");
+dojo.require("dojo.style");
+dojo.require("dojo.dom");
+dojo.require("dojo.widget.ContentPane");
+dojo.require("dojo.widget.LayoutPane");
+dojo.require("dojo.dnd.HtmlDragMove");
+dojo.require("dojo.dnd.HtmlDragMoveSource");
+dojo.require("dojo.dnd.HtmlDragMoveObject");
+
+dojo.widget.html.FloatingPane = function(){
+ dojo.widget.html.LayoutPane.call(this);
+}
+
+dojo.inherits(dojo.widget.html.FloatingPane, dojo.widget.html.LayoutPane);
+
+dojo.lang.extend(dojo.widget.html.FloatingPane, {
+ widgetType: "FloatingPane",
+
+ // Constructor arguments
+ title: '',
+ iconSrc: '',
+ hasShadow: false,
+ constrainToContainer: false,
+ taskBarId: "",
+ resizable: true, // note: if specified, user must include ResizeHandle
+ overflow: "",
+
+ resizable: false,
+ titleBarDisplay: "fancy",
+ titleHeight: 22, // workaround to CSS loading race condition bug
+
+ href: "",
+ extractContent: true,
+ parseContent: true,
+ cacheContent: true,
+
+ // FloatingPane supports 3 modes for the client area (the part below the title bar)
+ // default - client area is a ContentPane, that can hold
+ // either inlined data and/or data downloaded from a URL
+ // layout - the client area is a layout pane
+ // none - the user specifies a single widget which becomes the content pane
+ contentWrapper: "default",
+
+ containerNode: null,
+ domNode: null,
+ clientPane: null,
+ dragBar: null,
+
+ windowState: "normal",
+ displayCloseAction: false,
+
+ maxTaskBarConnectAttempts: 5,
+ taskBarConnectAttempts: 0,
+
+ minimizeIcon: dojo.uri.dojoUri("src/widget/templates/images/floatingPaneMinimize.gif"),
+ maximizeIcon: dojo.uri.dojoUri("src/widget/templates/images/floatingPaneMaximize.gif"),
+ restoreIcon: dojo.uri.dojoUri("src/widget/templates/images/floatingPaneRestore.gif"),
+ closeIcon: dojo.uri.dojoUri("src/widget/templates/images/floatingPaneClose.gif"),
+ titleBarBackground: dojo.uri.dojoUri("src/widget/templates/images/titlebar-bg.jpg"),
+
+ shadowPng: dojo.uri.dojoUri("src/widget/templates/images/shadow"),
+ shadowThickness: 8,
+ shadowOffset: 15,
+
+ templateString: '<div></div>',
+ templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlFloatingPane.css"),
+
+ initialized: false,
+
+ addChild: function(child, overrideContainerNode, pos, ref, insertIndex) {
+ this.clientPane.addChild(child, overrideContainerNode, pos, ref, insertIndex);
+ },
+
+ // make a widget container to hold all the contents of the floating pane (other than the
+ // title and the resize bar at the bottom)
+ _makeClientPane: function(clientDiv){
+ var args = {
+ layoutAlign: "client",
+ id:this.widgetId+"_client",
+ href: this.href,
+ cacheContent: this.cacheContent,
+ extractContent: this.extractContent,
+ parseContent: this.parseContent
+ };
+ var pane = this._createPane(this.contentWrapper=="layout"?"LayoutPane":"ContentPane", clientDiv, args);
+ return pane;
+ },
+
+ fillInTemplate: function(args, frag){
+ var source = this.getFragNodeRef(frag);
+
+ // Copy style info and id from input node to output node
+ this.domNode.style.cssText = source.style.cssText;
+ dojo.html.addClass(this.domNode, dojo.html.getClass(source));
+ dojo.html.addClass(this.domNode, "dojoFloatingPane");
+ this.domNode.style.position="absolute";
+ this.domNode.id = source.id;
+ if(dojo.render.html.safari){
+ document.body.appendChild(this.domNode);
+ }
+
+ // make client pane wrapper to hold the contents of this floating pane
+ if(this.contentWrapper!="none"){
+ var clientDiv = document.createElement('div');
+ dojo.dom.moveChildren(source, clientDiv, 0);
+ this.clientPane = this._makeClientPane(clientDiv);
+ }
+
+ if (this.titleBarDisplay != "none") {
+ // this is our chrome
+ var chromeDiv = document.createElement('div');
+ dojo.html.addClass(chromeDiv, 'dojoFloatingPaneDragbar');
+ chromeDiv.style.height=this.titleHeight+"px"; // workaround CSS loading race condition bug
+
+ this.dragBar = this._createPane("LayoutPane", chromeDiv, {layoutAlign: 'top', id:this.widgetId+"_chrome"});
+ dojo.html.disableSelection(this.dragBar.domNode);
+
+ if( this.titleBarDisplay == "fancy"){
+ // image background to get gradient
+ var img = document.createElement('img');
+ img.src = this.titleBarBackground;
+ dojo.html.addClass(img, 'dojoFloatingPaneDragbarBackground');
+ var backgroundPane = dojo.widget.createWidget("ContentPane", {layoutAlign:"flood", id:this.widgetId+"_titleBackground"}, img);
+ this.dragBar.addChild(backgroundPane);
+ }
+
+ //Title Bar
+ var titleBar = document.createElement('div');
+ dojo.html.addClass(titleBar, "dojoFloatingPaneTitleBar");
+ dojo.html.disableSelection(titleBar);
+
+ //TitleBarActions
+ var titleBarActions = document.createElement('div');
+ dojo.html.addClass(titleBarActions, "dojoFloatingPaneActions");
+
+ //Title Icon
+ if(this.iconSrc!=""){
+ var titleIcon = document.createElement('img');
+ dojo.html.addClass(titleIcon,"dojoTitleBarIcon");
+ titleIcon.src = this.iconSrc;
+ titleBar.appendChild(titleIcon);
+ }
+
+ //Title text
+ var titleText = document.createTextNode(this.title)
+ titleBar.appendChild(titleText);
+
+ if (this.resizable) {
+
+ //FloatingPane Action Minimize
+ this.minimizeAction = document.createElement("img");
+ dojo.html.addClass(this.minimizeAction, "dojoFloatingPaneActionItem");
+ this.minimizeAction.src = this.minimizeIcon;
+ titleBarActions.appendChild(this.minimizeAction);
+ dojo.event.connect(this.minimizeAction, 'onclick', this, 'minimizeWindow');
+
+ //FloatingPane Action Restore
+ this.restoreAction = document.createElement("img");
+ dojo.html.addClass(this.restoreAction, "dojoFloatingPaneActionItem");
+ this.restoreAction.src = this.restoreIcon;
+ titleBarActions.appendChild(this.restoreAction);
+ dojo.event.connect(this.restoreAction, 'onclick', this, 'restoreWindow');
+
+ if (this.windowState != "normal") {
+ this.restoreAction.style.display="inline";
+ } else {
+ this.restoreAction.style.display="none";
+ }
+
+ //FloatingPane Action Maximize
+ this.maximizeAction = document.createElement("img");
+ dojo.html.addClass(this.maximizeAction, "dojoFloatingPaneActionItem");
+ this.maximizeAction.src = this.maximizeIcon;
+ titleBarActions.appendChild(this.maximizeAction);
+ dojo.event.connect(this.maximizeAction, 'onclick', this, 'maximizeWindow');
+
+ if (this.windowState != "maximized") {
+ this.maximizeAction.style.display="inline";
+ } else {
+ this.maximizeAction.style.display="none";
+ }
+
+ }
+
+ if (this.displayCloseAction) {
+ //FloatingPane Action Close
+ var closeAction= document.createElement("img");
+ dojo.html.addClass(closeAction, "dojoFloatingPaneActionItem");
+ closeAction.src = this.closeIcon;
+ titleBarActions.appendChild(closeAction);
+ dojo.event.connect(closeAction, 'onclick', this, 'closeWindow');
+ }
+
+
+ chromeDiv.appendChild(titleBar);
+ chromeDiv.appendChild(titleBarActions);
+ }
+
+ if ( this.resizable ) {
+ // add the resize handle
+ var resizeDiv = document.createElement('div');
+ dojo.html.addClass(resizeDiv, "dojoFloatingPaneResizebar");
+ dojo.html.disableSelection(resizeDiv);
+ var rh = dojo.widget.createWidget("ResizeHandle", {targetElmId: this.widgetId, id:this.widgetId+"_resize"});
+ this.resizePane = this._createPane("ContentPane", resizeDiv, {layoutAlign: "bottom"});
+ this.resizePane.addChild(rh);
+ }
+
+ // add a drop shadow
+ this._makeShadow();
+
+ dojo.event.connect(this.domNode, 'onmousedown', this, 'onMouseDown');
+
+ // Prevent IE bleed-through problem
+ this.bgIframe = new dojo.html.BackgroundIframe();
+ if( this.bgIframe.iframe ){
+ this.domNode.appendChild(this.bgIframe.iframe);
+ }
+ if ( this.isVisible() ) {
+ this.bgIframe.show();
+ };
+
+ if( this.taskBarId ){
+ this.taskBarSetup();
+ }
+
+ if (dojo.hostenv.post_load_) {
+ this.setInitialWindowState();
+ } else {
+ dojo.addOnLoad(this, "setInitialWindowState");
+ }
+ if(dojo.render.html.safari){
+ document.body.removeChild(this.domNode);
+ }
+
+ dojo.widget.html.FloatingPane.superclass.postCreate.call(this, args, frag);
+ },
+
+ postCreate: function(args, frag){
+ // Make the client pane. It will either be the widget specified by the user,
+ // or a wrapper widget
+ if(this.contentWrapper=="none"){
+ // the user has specified a single widget which will become our content
+ this.clientPane = this.children[0];
+ this.domNode.appendChild(this.clientPane.domNode);
+ }else{
+ // move our 'children' into the client pane
+ // we already moved the domnodes, but now we need to move the 'children'
+ var kids = this.children.concat();
+ this.children = [];
+
+ for(var i=0; i<kids.length; i++){
+ if (kids[i].ownerPane == this){
+ this.children.push(kids[i]);
+ }else{
+ if(this.contentWrapper=="layout"){
+ this.clientPane.addChild(kids[i]);
+ }else{
+ this.clientPane.children.push(kids[i]);
+ }
+ }
+ }
+ }
+ dojo.html.addClass(this.clientPane.domNode, 'dojoFloatingPaneClient');
+ this.clientPane.layoutAlign="client";
+ this.clientPane.ownerPane=this;
+ if (this.overflow != "") {
+ this.clientPane.domNode.style.overflow=this.overflow;
+ }
+
+ if (this.titleBarDisplay != "none") {
+ var drag = new dojo.dnd.HtmlDragMoveSource(this.domNode);
+
+ if (this.constrainToContainer) {
+ drag.constrainTo();
+ }
+
+ drag.setDragHandle(this.dragBar.domNode);
+ }
+
+ this.initialized=true;
+ },
+
+ _makeShadow: function(){
+ if ( this.hasShadow ) {
+ // make all the pieces of the shadow, and position/size them as much
+ // as possible (but a lot of the coordinates are set in sizeShadow
+ this.shadow={};
+ var x1 = -1 * this.shadowThickness;
+ var y0 = this.shadowOffset;
+ var y1 = this.shadowOffset + this.shadowThickness;
+ this._makeShadowPiece("ul", "top", y0, "left", x1);
+ this._makeShadowPiece("l", "top", y1, "left", x1, "scale");
+ this._makeShadowPiece("ur", "top", y0, "left", 0);
+ this._makeShadowPiece("r", "top", y1, "left", 0, "scale");
+ this._makeShadowPiece("bl", "top", 0, "left", x1);
+ this._makeShadowPiece("b", "top", 0, "left", 0, "crop");
+ this._makeShadowPiece("br", "top", 0, "left", 0);
+ }
+ },
+
+ _makeShadowPiece: function(name, vertAttach, vertCoord, horzAttach, horzCoord, sizing){
+ var img;
+ var url = this.shadowPng + name.toUpperCase() + ".png";
+ if(dojo.render.html.ie){
+ img=document.createElement("div");
+ img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"'"+
+ (sizing?", sizingMethod='"+sizing+"'":"") + ")";
+ }else{
+ img=document.createElement("img");
+ img.src=url;
+ }
+ img.style.position="absolute";
+ img.style[vertAttach]=vertCoord+"px";
+ img.style[horzAttach]=horzCoord+"px";
+ img.style.width=this.shadowThickness+"px";
+ img.style.height=this.shadowThickness+"px";
+ this.shadow[name]=img;
+ this.domNode.appendChild(img);
+ },
+
+ _sizeShadow: function(width, height){
+ if ( this.shadow ) {
+ var sideHeight = height - (this.shadowOffset+this.shadowThickness+1);
+ this.shadow.l.style.height = sideHeight+"px";
+ this.shadow.r.style.height = sideHeight+"px";
+ this.shadow.b.style.width = (width-1)+"px";
+ this.shadow.bl.style.top = (height-1)+"px";
+ this.shadow.b.style.top = (height-1)+"px";
+ this.shadow.br.style.top = (height-1)+"px";
+ this.shadow.ur.style.left = (width-1)+"px";
+ this.shadow.r.style.left = (width-1)+"px";
+ this.shadow.br.style.left = (width-1)+"px";
+ }
+ },
+
+ maximizeWindow: function(evt) {
+ this.previousWidth= this.domNode.style.width;
+ this.previousHeight= this.domNode.style.height;
+ this.previousLeft = this.domNode.style.left;
+ this.previousTop = this.domNode.style.top;
+
+ this.domNode.style.left =
+ dojo.style.getPixelValue(this.domNode.parentNode, "padding-left", true) + "px";
+ this.domNode.style.top =
+ dojo.style.getPixelValue(this.domNode.parentNode, "padding-top", true) + "px";
+
+ if ((this.domNode.parentNode.nodeName.toLowerCase() == 'body')) {
+ dojo.style.setOuterWidth(this.domNode, dojo.html.getViewportWidth()-dojo.style.getPaddingWidth(document.body));
+ dojo.style.setOuterHeight(this.domNode, dojo.html.getViewportHeight()-dojo.style.getPaddingHeight(document.body));
+ } else {
+ dojo.style.setOuterWidth(this.domNode, dojo.style.getContentWidth(this.domNode.parentNode));
+ dojo.style.setOuterHeight(this.domNode, dojo.style.getContentHeight(this.domNode.parentNode));
+ }
+ this.maximizeAction.style.display="none";
+ this.restoreAction.style.display="inline";
+ this.windowState="maximized";
+ this.onResized();
+ },
+
+ minimizeWindow: function(evt) {
+ this.hide();
+ if (this.resizable) {
+ this.maximizeAction.style.display="inline";
+ this.restoreAction.style.display="inline";
+ }
+
+ this.windowState = "minimized";
+ },
+
+ restoreWindow: function(evt) {
+ if (this.previousWidth && this.previousHeight && this.previousLeft && this.previousTop) {
+ this.domNode.style.width = this.previousWidth;
+ this.domNode.style.height = this.previousHeight;
+ this.domNode.style.left = this.previousLeft;
+ this.domNode.style.top = this.previousTop;
+ dojo.widget.html.FloatingPane.superclass.onResized.call(this);
+ }
+
+ if (this.widgetState != "maximized") {
+ this.show();
+ }
+
+ if (this.resizable) {
+ this.maximizeAction.style.display="inline";
+ this.restoreAction.style.display="none";
+ }
+
+ this.bringToTop();
+ this.windowState="normal";
+ },
+
+ closeWindow: function(evt) {
+ this.destroy();
+ },
+
+ onMouseDown: function(evt) {
+ this.bringToTop();
+ },
+
+ bringToTop: function() {
+ var floatingPaneStartingZ = 100;
+ var floatingPanes= dojo.widget.manager.getWidgetsByType("FloatingPane");
+ var windows = []
+ var y=0;
+ for (var x=0; x<floatingPanes.length; x++) {
+ if (this.widgetId != floatingPanes[x].widgetId) {
+ windows.push(floatingPanes[x]);
+ }
+ }
+
+ windows.sort(function(a,b) {
+ return a.domNode.style.zIndex - b.domNode.style.zIndex;
+ });
+
+ windows.push(this);
+
+ for (x=0; x<windows.length;x++) {
+ windows[x].domNode.style.zIndex = floatingPaneStartingZ + x;
+ }
+ },
+
+ setInitialWindowState: function() {
+ if (this.windowState == "maximized") {
+ this.maximizeWindow();
+ this.show();
+ this.bringToTop();
+ return;
+ }
+
+ if (this.windowState=="normal") {
+ dojo.lang.setTimeout(this, this.onResized, 50);
+ this.show();
+ this.bringToTop();
+ return;
+ }
+
+ if (this.windowState=="minimized") {
+ this.hide();
+ return;
+ }
+
+ this.windowState="minimized";
+ },
+
+ // add icon to task bar, connected to me
+ taskBarSetup: function() {
+ var taskbar = dojo.widget.getWidgetById(this.taskBarId);
+ if (!taskbar){
+ if (this.taskBarConnectAttempts < this.maxTaskBarConnectAttempts) {
+ dojo.lang.setTimeout(this, this.taskBarSetup, 50);
+ this.taskBarConnectAttempts++;
+ } else {
+ dojo.debug("Unable to connect to the taskBar");
+ }
+ return;
+ }
+ taskbar.addChild(this);
+ },
+
+ onResized: function(){
+ if( !this.isVisible() ){ return; }
+ var newHeight = dojo.style.getInnerHeight(this.domNode);
+ var newWidth = dojo.style.getInnerWidth(this.domNode);
+
+ //if ( newWidth != this.width || newHeight != this.height ) {
+ this.width = newWidth;
+ this.height = newHeight;
+ this._sizeShadow(newWidth, newHeight);
+ dojo.widget.html.FloatingPane.superclass.onResized.call(this);
+ //}
+
+ // bgIframe is a child of this.domNode, so position should be relative to [0,0]
+ if(this.bgIframe){
+ this.bgIframe.size([0, 0, newWidth, newHeight]);
+ }
+ },
+
+ hide: function(){
+ dojo.widget.html.FloatingPane.superclass.hide.call(this);
+ if(this.bgIframe){
+ this.bgIframe.hide();
+ }
+ },
+
+ show: function(){
+ dojo.widget.html.FloatingPane.superclass.show.call(this);
+ if(this.bgIframe){
+ this.bgIframe.show();
+ }
+ },
+
+ _createPane: function(type, node, args){
+ var pane = dojo.widget.createWidget(type, args, node);
+ dojo.widget.html.FloatingPane.superclass.addChild.call(this,pane);
+ pane.ownerPane=this;
+ return pane;
+ },
+
+ setUrl: function(url){
+ this.clientPane.setUrl(url);
+ },
+
+ setContent: function(str){
+ this.clientPane.setContent(str);
+ }
+});
+
+dojo.widget.tags.addParseTreeHandler("dojo:FloatingPane");
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org