/*
js-mindmap
Copyright (c) 2008/09/10 Kenneth Kufluk http://kenneth.kufluk.com/
MIT (X11) license
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
(function($){
var TIMEOUT = 4; // movement timeout in seconds
var CENTRE_FORCE = 3; // strength of attraction to the centre by the active node
// Define all Node related functions.
function Node(obj, name, parent, opts){
this.obj = obj;
this.options = obj.options;
this.name = name;
this.href = opts.href;
if (opts.url) this.url = opts.url;
this.el = $(''+this.name+'');
this.el.addClass('node');
$('body').prepend(this.el);
if (!parent) {
obj.activeNode = this;
$(this.el).addClass('active');
$(this.el).addClass('root');
} else {
var lineno = obj.lines.length;
obj.lines[lineno] = new Line(obj, this, parent);
}
this.parent = parent;
this.children = new Array();
if (this.parent) this.parent.children.push(this);
this.moving = false;
this.moveTimer = 0;
this.obj.movementStopped = false;
this.visible = true;
this.hasLayout = true;
this.x = 1;
this.y = 1;
this.dx = 0;
this.dy = 0;
this.hasPosition = false;
this.content = []; // array of content elements to display onclick;
this.el.css('position','absolute');
var thisnode = this;
this.el.draggable({
drag:function() {
obj.root.animateToStatic();
}
});
this.el.click(function(){
/*
if (obj.activeNode==thisnode) {
if (thisnode.url) location.href=thisnode.url;
else location.href=this.href;
return false;
}
*/
if (obj.activeNode) {
obj.activeNode.el.removeClass('active');
/*
// remove the activeNodes children
// except, obviously, the node in question (doh!)
var kids = obj.activeNode.children;
var selfIsKid = false;
for (var i=0;i 0) {
fx += f * Math.cos(theta) * xsign;
fy += f * Math.sin(theta) * xsign;
}
}
// if I'm active, attract me to the centre of the area
if (this.obj.activeNode === this) {
// Attractive force (hooke's law)
var otherend = this.options.mapArea;
var x1 = ((otherend.x / 2) - this.options.centreOffset - this.x);
var y1 = ((otherend.y / 2) - this.y);
var dist = Math.sqrt((x1 * x1) + (y1 * y1));
var xsign = x1 / Math.abs(x1);
var theta = Math.atan(y1 / x1);
if (x1 == 0) {
theta = Math.PI / 2;
xsign = 0;
}
// force is based on radial distance
var f = (0.1 * this.options.attract * dist * CENTRE_FORCE) / 1000;
if (Math.abs(dist) > 0) {
fx += f * Math.cos(theta) * xsign;
fy += f * Math.sin(theta) * xsign;
}
}
if (Math.abs(fx) > this.options.maxForce) fx = this.options.maxForce * (fx / Math.abs(fx));
if (Math.abs(fy) > this.options.maxForce) fy = this.options.maxForce * (fy / Math.abs(fy));
return {
x: fx,
y: fy
};
}
Node.prototype.removeNode = function(){
for (var i=0;i