Hi
I want to create a drag drop tool box using javascript... Can anyone please guide me in this regard
Thanks
I want to create a drag drop tool box using javascript... Can anyone please guide me in this regard
Thanks
Flowchart = Class.create();
var varText;
Flowchart.prototype.initialize=function(conf)
{this.conf=conf;
window.flowchart=this;
this.objects={};
this.objectsConnection=[];
this.editObjectIndex=false;
this.language();
this.initKeylistener();
Event.observe(window.document, 'click', this.clickListener.bindAsEventListener(this));
Event.observe(window.document, 'contextmenu', this.customContext.bindAsEventListener(this));
Event.observe(window.document, "dblclick", function (e) {
var target=(e.target) ? e.target : e.srcElement;
if(target.tagName.toLowerCase()=="body" || target.tagName.toLowerCase()=="html")
this.addObject(1, {x: Event.pointerX(e), y: Event.pointerY(e)});
}.bindAsEventListener(this), false);
Event.observe(window, "load", function () {
this.loadImages();
this.loadText();
}.bind(this), false);
};
Flowchart.prototype.loadText=function() {
var objs=document.getElementsByClassName('trans');
objs.each(function(obj, index) {
obj.parentNode.innerHTML=this.getText(obj.innerHTML);
}.bind(this));
};
Flowchart.prototype.getObjectIndex=function() {
return 'fj_'+String((new Date()).getTime()).substr(8, 5);
};
Flowchart.prototype.getObjectsLength=function() {
var counter = 0;
for(var key in this.objects) {
counter++;
}
return counter;
};
Flowchart.prototype.language=function(lang) {
this.lang = typeof(this.language[bw.lang]) == 'object' ? bw.lang : 'en';
};
Flowchart.prototype.loadImages=function() {
var index=0;
var img=[];
var imgPath=['arrow_down.gif',
'arrow_left.gif',
'arrow_right.gif',
'arrow_up.gif',
'corners.gif',
'corners_on.gif',
'mouse_connect.gif',
'mouse_connect_on.gif']
imgPath.each(function(path) {
img.push(new Image());
img.last().src="images/"+path;
});
};
Flowchart.prototype.customContext=function(e) {
var target=(e.target) ? e.target : e.srcElement;
if(target.tagName.toLowerCase()==(bw.ie ? 'body' : 'html')) {
// show flowchart menu
this.showContextMenu(false, e);
}
e.cancelBubble=true;
e.returnValue=false;
};
Flowchart.prototype.clickListener=function(e) {
var target=(e.target) ? e.target : e.srcElement;
// nothing clicked
if(target.tagName.toLowerCase()==(bw.ie ? 'body' : 'html')) {
this.setMouseMode();
// unmark all flowchart objects
if(!e.ctrlKey)
this.unmarkAllObjects();
// hide flowchart menu
this.hideContextMenu();
this.disableEdit();
}
else if((target.index || target.index===0) && this.mouseMode=="connect") {
this.setMouseMode("connect");
}
};
Flowchart.prototype.initKeylistener=function() {
// new keylistener object
this.keyListener = new Key.listener();
// moving objects with up/down/left/right
this.keyListener.add('down', 37, function(e, direction) {
this.moveObjectByKey(e, 'left');
}.bindAsEventListener(this));
this.keyListener.add('down', 39, function(e, direction) {
this.moveObjectByKey(e, 'right');
}.bindAsEventListener(this));
this.keyListener.add('down', 38, function(e, direction) {
this.moveObjectByKey(e, 'up');
}.bindAsEventListener(this));
this.keyListener.add('down', 40, function(e, direction) {
this.moveObjectByKey(e, 'down');
}.bindAsEventListener(this));
// delete object
this.keyListener.add('down', 46, this.removeMarkedObjects.bind(this));
};
Flowchart.prototype.addObject=function(type, pos) {
var index=this.getObjectIndex();
alert("index "+index)
if($("grid").checked) {
pos=this.getSnapPos(pos);
}
else if(!pos) {
pos=this.getFlowchartObjectStartPosition();//gets the start position
}
alert("u called getFlowchartObjectStartPosition------rcame back to addOObject");
// create new layer object
var myTemp=new Layer.object(index, {x:pos.x, y:pos.y, width:160, height:70, vis:1});
this.objects[index]=myTemp
if(bw.ie)
this.objects[index].element.style.overflow="hidden";
// save index
this.objects[index].index=index;
var varTemp1='<div class="top_left" id="flowchart_top_left_'+index+'"></div>'+
'<div class="top_right" id="flowchart_top_right_'+index+'"></div>'+
'<div class="inside" id="flowchart_inside_'+index+'"></div>'+
'<div class="resize" id="flowchart_resize_'+index+'"></div>'+
'<div class="bottom_left" id="flowchart_bottom_left_'+index+'"></div>'+
'<div class="bottom_right" id="flowchart_bottom_right_'+index+'"></div>';
alert("------varTemp1 in addObject ----"+varTemp1);
alert("--- varText before adding---"+varText);
// varText=varText+varTemp1;
varText=varTemp1;
alert("addObject------varText"+varText);
this.objects[index].write(varTemp1);
alert("addObject------object formed");
var resizeDiv=$("flowchart_resize_"+index);
resizeDiv.index=index;
Event.observe(resizeDiv, "mousedown", this.enableResize.bindAsEventListener(this), false);
// add write method
this.objects[index].write=function(content){this.element.childNodes[2].innerHTML=content};
// add mark method
this.objects[index].setStyle=function(mode) {
var inside=$('flowchart_inside_'+this.index);
var top_left=$('flowchart_top_left_'+this.index);
var top_right=$('flowchart_top_right_'+this.index);
var bottom_left=$('flowchart_bottom_left_'+this.index);
var bottom_right=$('flowchart_bottom_right_'+this.index);
if(mode=='marked' && inside.className!='inside_on') {
inside.className='inside_on';
top_left.className='top_left_on';
top_right.className='top_right_on';
bottom_left.className='bottom_left_on';
bottom_right.className='bottom_right_on';
}
else if(mode!='marked' && inside.className=='inside_on') {
inside.className='inside';
top_left.className='top_left';
top_right.className='top_right';
bottom_left.className='bottom_left';
bottom_right.className='bottom_right';
}
};
var inside=$('flowchart_inside_'+index);
alert("----addObject----inside---"+inside);
inside.index=index;
Event.observe(inside, "dblclick", function(e){
var target=(e.target) ? e.target : e.srcElement;
if(target.index || target.index===0)
this.enableEdit(e, target.index);
}.bindAsEventListener(this), false);
// make object draggable
this.setDraggable(index, true);
return false;
};
var varTemp1='<div class="top_left" id="flowchart_top_left_'+index+'"></div>'+
'<div class="top_right" id="flowchart_top_right_'+index+'"></div>'+
'<div class="inside" id="flowchart_inside_'+index+'"></div>'+
'<div class="resize" id="flowchart_resize_'+index+'"></div>'+
'<div class="bottom_left" id="flowchart_bottom_left_'+index+'"></div>'+
'<div class="bottom_right" id="flowchart_bottom_right_'+index+'"></div>';
alert("------varTemp1 in addObject ----"+varTemp1);
alert("--- varText before adding---"+varText);
// varText=varText+varTemp1;
varText=varTemp1;
alert("addObject------varText"+varText);
Comment