Kinetic.TextToTextColumnDropItem = function(config){ Kinetic.Group.call(this, config); this.data = config.data; this.createItem(); this.currentItems = new Array(); this.itemY = 35; } Kinetic.TextToTextColumnDropItem.prototype = { createItem: function(){ this.bg = new Kinetic.Rect({ 'width': this.data.sizeX, 'height': 50, 'stroke': '#CCCCCC', 'strokeWidth': 2 }); this.add(this.bg); this.headerBg = new Kinetic.Rect({ 'width': this.data.sizeX, 'height': 30, 'fill': '#EFEFEF', 'stroke': '#CCCCCC', 'strokeWidth': 2 }); this.add(this.headerBg); this.label = new Kinetic.Text({ 'y': 9, 'text': this.data.value, 'fontSize': 13, 'fontFamily': 'Arial', 'fontStyle': 'bold', 'textFill': '#000000', 'width': this.data.sizeX, 'align': 'center' }); this.add(this.label); }, getWidth: function(){ return this.bg.getWidth(); }, getHeight: function(){ return this.bg.getHeight(); }, addItem: function(item){ this.currentItems.push(item); var itemWidth = item.getWidth(); var xPos = this.getX() - item.getParent().getX() + ((this.bg.getWidth() - itemWidth) / 2); var yPos = this.getY() - item.getParent().getY() + this.itemY; var tween = new Kinetic.Tween({ 'node': item, 'x': oriX, 'y': oriY, 'duration': 0.2, 'easing': Kinetic.Easings.EaseInOut }); tween.play(); this.itemY += item.getHeight() + 5; var bgHeight = 50; for (var i = 0; i < this.currentItems.length; i++){ bgHeight += this.currentItems[i].getHeight() + 5; } var tween = new Kinetic.Tween({ 'node': this.bg, 'height': bgHeight, 'duration': 0.2, 'easing': Kinetic.Easings.EaseInOut }); tween.play(); }, removeItem: function(item){ var moveUp = 0; var spliceIndex = 0; for (var i = 0; i < this.currentItems.length; i++){ if (moveUp > 0){ this.currentItems[i].setY(this.currentItems[i].getY() - moveUp); } if (this.currentItems[i] == item){ spliceIndex = i; moveUp = item.getHeight() + 5; } } this.currentItems.splice(spliceIndex, 1); var tween = new Kinetic.Tween({ 'node': this.bg, 'height': this.bg.getHeight() - moveUp, 'duration': 0.2, 'easing': Kinetic.Easings.EaseInOut }); this.itemY -= moveUp; } } Kinetic.Util.extend(Kinetic.TextToTextColumnDropItem, Kinetic.Group);