Skip to content

Commit

Permalink
parent toolbars do not need to know all their possible children: remo…
Browse files Browse the repository at this point in the history
…ved that code
  • Loading branch information
dound committed Dec 6, 2008
1 parent 81c0c77 commit d2d2017
Showing 1 changed file with 12 additions and 56 deletions.
68 changes: 12 additions & 56 deletions jtoolbar.js
Expand Up @@ -358,7 +358,6 @@ var JTB = function() {

/* toolbar hierarchy support */
this.tb_parent = null;
this.tb_children = [];
this.vis_tb_child = null;

/* sizing information helpers */
Expand Down Expand Up @@ -684,11 +683,13 @@ var JTB = function() {

/** shows a child toolbar (makes childToolbar a child if it isn't already one) */
JTB.Toolbar.prototype.showChildToolbar = function(childToolbar, x, y) {
/* make sure childToolbar is one of our children */
if(!this.hasChildToolbar(childToolbar)) {
this.addChildToolbar(childToolbar);
}
/* remove the child from any old parent */
childToolbar.removeFromParentToolbar(childToolbar);

/* tell the child toolbar it belongs to us now */
childToolbar.tb_parent = this;

/* show the child */
this.vis_tb_child = childToolbar;
this.refreshGfx();

Expand All @@ -700,60 +701,15 @@ var JTB = function() {
return this.e_content === null;
};

/** adds a child toolbar to this toolbar */
JTB.Toolbar.prototype.addChildToolbar = function(childToolbar) {
/* remove the child from any old parent */
if(childToolbar.tb_parent !== null) {
childToolbar.tb_parent.removeChildToolbar(childToolbar);
}

/* add the child toolbar to our list of toolbars */
this.tb_children[this.tb_children.length] = childToolbar;
childToolbar.tb_parent = this;
return this;
};

/** gets whether e is a child toolbar of this toolbar */
JTB.Toolbar.prototype.hasChildToolbar = function(e) {
return this.indexOfChildToolbar(e) != -1;
};

/** returns non-negative index if e is a child toolbar of this toolbar */
JTB.Toolbar.prototype.indexOfChildToolbar = function(e) {
var i;
for(i=0; i<this.tb_children.length; i++) {
if(this.tb_children[i] === e) {
return i;
/** removes a child toolbar from its parent */
JTB.Toolbar.prototype.removeFromParentToolbar = function(e) {
if(e.tb_parent !== null) {
if(e.tb_parent.vis_tb_child == e) {
e.tb_parent.vis_tb_child = null;
e.tb_parent.refreshGfx();
}
}

return -1;
};

/** removes a child toolbar */
JTB.Toolbar.prototype.removeChildToolbar = function(e) {
var i = this.indexOfChildToolbar(e);
if(i >= 0) {
var container = this.getContainer();
if(container !== null) {
container.removeChild(e);
}

if(this.vis_tb_child == e) {
this.vis_tb_child = null;
}

e.tb_parent = null;

var j;
for(j=i; j<this.tb_children.length-1; j++) {
this.tb_children[j] = this.tb_children[j+1];
}
this.tb_children.length -= 1;

this.refreshGfx();
}
return this;
};

/** get the location of the toolbar on its parent */
Expand Down

0 comments on commit d2d2017

Please sign in to comment.