123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785 |
-
- (function() {
-
- var ie = (/MSIE/.test(navigator.userAgent) && !window.opera);
-
- var log = null;
-
- var repaintFunction = function() { jsPlumb.repaintEverything(); };
- var automaticRepaint = true;
- function repaintEverything() {
- if (automaticRepaint)
- repaintFunction();
- };
- var resizeTimer = null;
-
-
-
-
- var endpointsByElement = {};
- var offsets = [];
- var floatingConnections = {};
- var draggableStates = {};
- var _draggableByDefault = true;
- var sizes = [];
-
- var DEFAULT_NEW_CANVAS_SIZE = 1200;
-
- var _findIndex = function( a, v, b, s ) {
-
- var _eq = function(o1, o2) {
- if (o1 === o2) return true;
- else if (typeof o1 == 'object' && typeof o2 == 'object') {
- var same = true;
- for(var propertyName in o1) {
- if(!_eq(o1[propertyName], o2[propertyName])) {
- same = false;
- break;
- }
- }
- for(var propertyName in o2) {
- if(!_eq(o2[propertyName], o1[propertyName])) {
- same = false;
- break;
- }
- }
- return same;
- }
- };
-
- for( var i = +b || 0, l = a.length; i < l; i++ ) {
- if( _eq(a[i], v)) return i;
- }
- return -1;
- };
-
-
- var _addToList = function(map, key, value) {
- var l = map[key];
- if (l == null) {
- l = [];
- map[key] = l;
- }
- l.push(value);
- };
-
-
- var _draw = function(element, ui) {
- var id = _getAttribute(element, "id");
- var endpoints = endpointsByElement[id];
- if (endpoints) {
- _updateOffset(id, ui);
- var myOffset = offsets[id];
- var myWH = sizes[id];
-
- for (var i = 0; i < endpoints.length; i++) {
- var e = endpoints[i];
- var anchorLoc = endpoints[i].anchor.compute([myOffset.left, myOffset.top], myWH);
- e.paint(anchorLoc);
- var l = e.connections;
- for (var j = 0; j < l.length; j++)
- l[j].paint(id, ui);
- }
- }
- };
-
-
- var _elementProxy = function(element, fn) {
- var retVal = null;
- if (typeof element == 'object' && element.length) {
- retVal = [];
- for (var i = 0; i < element.length; i++) {
- var el = _getElementObject(element[i]);
- var id = _getAttribute(el, "id");
- retVal.push(fn(el, id));
- }
- }
- else {
- var el = _getElementObject(element);
- var id = _getAttribute(el, "id");
- retVal = fn(el, id);
- }
-
- return retVal;
- };
-
-
- var _getAttribute = function(el, attName) {
- var ele = jsPlumb.CurrentLibrary.getElementObject(el);
- return jsPlumb.CurrentLibrary.getAttribute(ele, attName);
- };
-
- var _setAttribute = function(el, attName, attValue) {
- var ele = jsPlumb.CurrentLibrary.getElementObject(el);
- jsPlumb.CurrentLibrary.setAttribute(ele, attName, attValue);
- };
-
- var _addClass = function(el, clazz) {
- var ele = jsPlumb.CurrentLibrary.getElementObject(el);
- jsPlumb.CurrentLibrary.addClass(ele, clazz);
- };
-
- var _getElementObject = function(elId) {
- return jsPlumb.CurrentLibrary.getElementObject(elId);
- };
-
- var _getOffset = function(el) {
- var ele = jsPlumb.CurrentLibrary.getElementObject(el);
- return jsPlumb.CurrentLibrary.getOffset(ele);
- };
-
- var _getSize = function(el) {
- var ele = jsPlumb.CurrentLibrary.getElementObject(el);
- return jsPlumb.CurrentLibrary.getSize(ele);
- };
-
- var _initDraggable = function(el, options) {
- return jsPlumb.CurrentLibrary.initDraggable(el, options);
- };
-
- var _isDragSupported = function(el) {
- return jsPlumb.CurrentLibrary.isDragSupported(el);
- };
-
- var _initDroppable = function(el, options) {
- return jsPlumb.CurrentLibrary.initDroppable(el, options);
- };
-
- var _isDropSupported = function(el) {
- return jsPlumb.CurrentLibrary.isDropSupported(el);
- };
-
- var _animate= function(el, properties, options) {
- return jsPlumb.CurrentLibrary.animate(el, properties, options);
- };
-
- var _appendCanvas = function(canvas) {
- document.body.appendChild(canvas);
- };
-
-
- var _getId = function(element) {
- var id = _getAttribute(element, "id");
- if (!id) {
- id = "_jsPlumb_" + new String((new Date()).getTime());
- _setAttribute(element, "id", id);
- }
- return id;
- };
-
-
- var _initDraggableIfNecessary = function(element, elementId, isDraggable, dragOptions) {
-
- var draggable = isDraggable == null ? _draggableByDefault : isDraggable;
- if (draggable && _isDragSupported(element)) {
- var options = dragOptions || jsPlumb.Defaults.DragOptions;
- options = jsPlumb.extend({}, options);
- var dragEvent = jsPlumb.CurrentLibrary.dragEvents['drag'];
- var initDrag = function(element, elementId, dragFunc) {
- options[dragEvent] = _wrap(options[dragEvent], dragFunc);
- var draggable = draggableStates[elementId];
- options.disabled = draggable == null ? false : !draggable;
- _initDraggable(element, options);
- };
- initDrag(element, elementId, function() {
- var ui = jsPlumb.CurrentLibrary.getUIPosition(arguments);
- _draw(element, ui);
- _addClass(element, "jsPlumb_dragged");
- });
- }
- };
-
- var _log = function(msg) {
-
- }
-
-
- var _newCanvas = function(clazz) {
- var canvas = document.createElement("canvas");
- _appendCanvas(canvas);
- canvas.style.position="absolute";
- if (clazz) { canvas.className=clazz; }
- _getId(canvas);
-
- if (ie) {
-
-
- jsPlumb.sizeCanvas(canvas, 0, 0, DEFAULT_NEW_CANVAS_SIZE, DEFAULT_NEW_CANVAS_SIZE);
- canvas = G_vmlCanvasManager.initElement(canvas);
- }
-
- return canvas;
- };
-
- var _operation = function(elId, func) {
- var endpoints = endpointsByElement[elId];
- if (endpoints && endpoints.length) {
- for (var i = 0; i < endpoints.length; i++) {
- for (var j = 0; j < endpoints[i].connections.length; j++) {
- var retVal = func(endpoints[i].connections[j]);
-
-
- if (retVal) return;
- }
- }
- }
- };
-
- var _operationOnAll = function(func) {
- for (var elId in endpointsByElement) {
- _operation(elId, func);
- }
- };
-
- var _removeElement = function(element) {
- if (element != null) {
- try { document.body.removeChild(element); }
- catch (e) { }
- }
- };
-
- var _removeElements = function(elements) {
- for (var i in elements)
- _removeElement(elements[i]);
- };
-
- var _removeFromList = function(map, key, value) {
- var l = map[key];
- if (l != null) {
- var i = _findIndex(l, value);
- if (i >= 0) {
- delete( l[i] );
- l.splice( i, 1 );
- return true;
- }
- }
- return false;
- };
-
- var _setDraggable = function(element, draggable) {
- var _helper = function(el, id) {
- draggableStates[id] = draggable;
- if (_isDragSupported(el)) {
-
- jsPlumb.CurrentLibrary.setDraggable(el, draggable);
-
- }
- };
-
- return _elementProxy(element, _helper);
- };
-
- var _setVisible = function(el, state) {
- var elId = _getAttribute(el, "id");
- var f = function(jpc) {
- jpc.canvas.style.display = state;
- };
- _operation(elId, f);
- };
-
- var _toggleDraggable = function(el) {
- var fn = function(el, elId) {
- var state = draggableStates[elId] == null ? _draggableByDefault : draggableStates[elId];
- state = !state;
- draggableStates[elId] = state;
-
- jsPlumb.CurrentLibrary.setDraggable(el, state);
- return state;
- };
- return _elementProxy(el, fn);
- };
-
- var _toggleVisible = function(elId) {
- var f = function(jpc) {
- var state = ('none' == jpc.canvas.style.display);
- jpc.canvas.style.display = state ? "block" : "none";
- };
-
- _operation(elId, f);
-
-
- };
-
- var _updateOffset = function(elId, offset, recalc) {
- if (recalc || offset == null) {
-
- var s = _getElementObject(elId);
- sizes[elId] = _getSize(elId);
- offsets[elId] = _getOffset(elId);
- } else {
- offsets[elId] = offset;
- }
- };
-
-
- var _wrap = function(cascadeFunction, plumbFunction) {
- cascadeFunction = cascadeFunction || function() { };
- return function() {
- plumbFunction.apply(this, arguments);
- cascadeFunction.apply(this, arguments);
- };
- }
-
-
-
-
- var Anchor = function(params) {
- var self = this;
- this.x = params.x || 0; this.y = params.y || 0;
- var orientation = params.orientation || [0,0];
- this.offsets = params.offsets || [0,0];
- this.compute = function(xy, wh, txy, twh) {
- return [ xy[0] + (self.x * wh[0]) + self.offsets[0], xy[1] + (self.y * wh[1]) + self.offsets[1] ];
- }
- this.getOrientation = function() { return orientation; };
- };
-
-
- var FloatingAnchor = function(params) {
-
-
- var ref = params.reference;
-
-
-
- var xDir = 0, yDir = 0;
-
- var orientation = null;
-
- this.compute = function(xy, wh, txy, twh) {
-
- xDir = 0;
- yDir = 0;
- return [xy[0], xy[1]];
- };
-
- this.getOrientation = function() {
- if (orientation) return orientation;
- else {
- var o = ref.getOrientation();
-
-
-
- return [Math.abs(o[0]) * xDir * -1, Math.abs(o[1]) * yDir * -1];
- }
- };
-
-
- this.over = function(anchor) {
- orientation = anchor.getOrientation();
- };
-
-
- this.out = function() {
- orientation = null;
- };
- };
-
-
-
-
- var Connection = function(params) {
-
- var self = this;
-
- this.source = _getElementObject(params.source);
- this.target = _getElementObject(params.target);
- this.sourceId = _getAttribute(this.source, "id");
- this.targetId = _getAttribute(this.target, "id");
- this.endpointsOnTop = params.endpointsOnTop != null ? params.endpointsOnTop : true;
-
-
- this.endpoints = [];
- this.endpointStyles = [];
- var prepareEndpoint = function(existing, index, params) {
- if (existing) self.endpoints[index] = existing;
- else {
- if(!params.endpoints) params.endpoints = [null,null];
- var ep = params.endpoints[index] || params.endpoint || jsPlumb.Defaults.Endpoints[index] || jsPlumb.Defaults.Endpoint|| new jsPlumb.Endpoints.Dot();
- if (!params.endpointStyles) params.endpointStyles = [null,null];
- var es = params.endpointStyles[index] || params.endpointStyle || jsPlumb.Defaults.EndpointStyles[index] || jsPlumb.Defaults.EndpointStyle;
- var a = params.anchors ? params.anchors[index] : jsPlumb.Defaults.Anchors[index] || jsPlumb.Anchors.BottomCenter;
- self.endpoints[index] = new Endpoint({style:es, endpoint:ep, connections:[self], anchor:a });
- }
- };
-
- prepareEndpoint(params.sourceEndpoint, 0, params);
- prepareEndpoint(params.targetEndpoint, 1, params);
-
- this.connector = this.endpoints[0].connector || this.endpoints[1].connector || params.connector || jsPlumb.Defaults.Connector || new jsPlumb.Connectors.Bezier();
- this.paintStyle = this.endpoints[0].connectionStyle || this.endpoints[1].connectionStyle || params.paintStyle || jsPlumb.Defaults.PaintStyle;
-
- _updateOffset(this.sourceId);
- _updateOffset(this.targetId);
-
-
- var myOffset = offsets[this.sourceId], myWH = sizes[this.sourceId];
- var anchorLoc = this.endpoints[0].anchor.compute([myOffset.left, myOffset.top], myWH);
- this.endpoints[0].paint(anchorLoc);
- myOffset = offsets[this.targetId]; myWH = sizes[this.targetId];
- anchorLoc = this.endpoints[1].anchor.compute([myOffset.left, myOffset.top], myWH);
- this.endpoints[1].paint(anchorLoc);
-
- var canvas = _newCanvas(jsPlumb.connectorClass);
- this.canvas = canvas;
-
-
- this.paint = function(elId, ui, recalc) {
-
- if (log) log.debug("Painting Connection; element in motion is " + elId + "; ui is [" + ui + "]; recalc is [" + recalc + "]");
-
- var fai = self.floatingAnchorIndex;
-
- var swap = !(elId == this.sourceId);
- var tId = swap ? this.sourceId : this.targetId, sId = swap ? this.targetId : this.sourceId;
- var tIdx = swap ? 0 : 1, sIdx = swap ? 1 : 0;
- var el = swap ? this.target : this.source;
-
- if (this.canvas.getContext) {
-
- _updateOffset(elId, ui, recalc);
- if (recalc) _updateOffset(tId);
-
- var myOffset = offsets[elId];
- var otherOffset = offsets[tId];
- var myWH = sizes[elId];
- var otherWH = sizes[tId];
-
- var ctx = canvas.getContext('2d');
- var sAnchorP = this.endpoints[sIdx].anchor.compute([myOffset.left, myOffset.top], myWH, [otherOffset.left, otherOffset.top], otherWH);
- var sAnchorO = this.endpoints[sIdx].anchor.getOrientation();
- var tAnchorP = this.endpoints[tIdx].anchor.compute([otherOffset.left, otherOffset.top], otherWH, [myOffset.left, myOffset.top], myWH);
- var tAnchorO = this.endpoints[tIdx].anchor.getOrientation();
- var dim = this.connector.compute(sAnchorP, tAnchorP, this.endpoints[sIdx].anchor, this.endpoints[tIdx].anchor, this.paintStyle.lineWidth);
- jsPlumb.sizeCanvas(canvas, dim[0], dim[1], dim[2], dim[3]);
- jsPlumb.extend(ctx, this.paintStyle);
-
- if (this.paintStyle.gradient && !ie) {
- var g = swap ? ctx.createLinearGradient(dim[4], dim[5], dim[6], dim[7]) : ctx.createLinearGradient(dim[6], dim[7], dim[4], dim[5]);
- for (var i = 0; i < this.paintStyle.gradient.stops.length; i++)
- g.addColorStop(this.paintStyle.gradient.stops[i][0],this.paintStyle.gradient.stops[i][1]);
- ctx.strokeStyle = g;
- }
-
- this.connector.paint(dim, ctx);
- }
- };
-
- this.repaint = function() {
- this.paint(this.sourceId, null, true);
- };
- _initDraggableIfNecessary(self.source, self.sourceId, params.draggable, params.dragOptions);
- _initDraggableIfNecessary(self.target, self.targetId, params.draggable, params.dragOptions);
-
-
- if (this.source.resize) {
- this.source.resize(function(e) {
- jsPlumb.repaint(self.sourceId);
- });
- }
- };
-
-
-
-
-
- var Endpoint = function(params) {
- params = params || {};
-
- jsPlumb.extend({}, params);
- var self = this;
- self.anchor = params.anchor || jsPlumb.Anchors.TopCenter;
- var _endpoint = params.endpoint || new jsPlumb.Endpoints.Dot();
- var _style = params.style || jsPlumb.Defaults.EndpointStyle;
- this.connectionStyle = params.connectionStyle;
- this.connector = params.connector;
- var _element = params.source;
- var _elementId = _getAttribute(_element, "id");
- var _maxConnections = params.maxConnections || 1;
- this.canvas = params.canvas || _newCanvas(jsPlumb.endpointClass);
- this.connections = params.connections || [];
- var _reattach = params.reattach || false;
- var floatingEndpoint = null;
- this.addConnection = function(connection) {
- self.connections.push(connection);
- };
- this.removeConnection = function(connection) {
- var idx = _findIndex(self.connections, connection);
- if (idx >= 0)
- self.connections.splice(idx, 1);
- };
-
- this.isConnectedTo = function(endpoint) {
- var found = false;
- if (endpoint) {
- for (var i = 0; i < self.connections.length; i++) {
- if (self.connections[i].endpoints[1] == endpoint) {
- found = true;
- break;
- }
- }
- }
- return found;
- };
-
- this.isFloating = function() { return floatingEndpoint != null; };
-
- var connectorSelector = function() {
- return self.connections.length == 0 || self.connections.length < _maxConnections ? null : self.connections[0];
- };
-
- this.isFull = function() { return _maxConnections < 1 ? false : (self.connections.length >= _maxConnections); };
-
-
- this.paint = function(anchorPoint, connectorPaintStyle, canvas) {
-
- if (log) log.debug("Painting Endpoint with elementId [" + _elementId + "]; anchorPoint is [" + anchorPoint + "]");
-
- if (anchorPoint == null) {
-
- var xy = offsets[_elementId];
- var wh = sizes[_elementId];
- if (xy == null || wh == null) {
- _updateOffset(_elementId);
- xy = offsets[_elementId];
- wh = sizes[_elementId];
- }
- anchorPoint = self.anchor.compute([xy.left, xy.top], wh);
- }
- _endpoint.paint(anchorPoint, self.anchor.getOrientation(), canvas || self.canvas, _style, connectorPaintStyle || _style);
- };
-
-
-
-
- if (params.isSource && _isDragSupported(_element)) {
-
- var n = null, id = null, jpc = null, existingJpc = false, existingJpcParams = null;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var start = function() {
- n = document.createElement("div");
- _appendCanvas(n);
-
- var id = "" + new String(new Date().getTime());
- _setAttribute(_getElementObject(n), "id", id);
- _updateOffset(id);
-
-
- _setAttribute(_getElementObject(self.canvas), "dragId", id);
- _setAttribute(_getElementObject(self.canvas), "elId", _elementId);
-
- var floatingAnchor = new FloatingAnchor({reference:self.anchor});
- floatingEndpoint = new Endpoint({
- style:_style,
- endpoint:_endpoint,
- anchor:floatingAnchor,
- source:n
- });
-
- jpc = connectorSelector();
- if (jpc == null) {
-
- jpc = new Connection({
- sourceEndpoint:self,
- targetEndpoint:floatingEndpoint,
- source:_getElementObject(_element),
- target:_getElementObject(n),
- anchors:[self.anchor, floatingAnchor],
- paintStyle : params.connectionStyle,
- connector: params.connector
- });
-
- self.addConnection(jpc);
- } else {
- existingJpc = true;
- var anchorIdx = jpc.sourceId == _elementId ? 0 : 1;
- jpc.floatingAnchorIndex = anchorIdx;
-
-
- self.removeConnection(jpc);
- if (anchorIdx == 0){
- existingJpcParams = [jpc.source, jpc.sourceId];
- jpc.source = _getElementObject(n);
- jpc.sourceId = id;
- }else {
- existingJpcParams = [jpc.target, jpc.targetId];
- jpc.target = _getElementObject(n);
- jpc.targetId = id;
- }
-
- jpc.suspendedEndpoint = jpc.endpoints[anchorIdx];
- jpc.endpoints[anchorIdx] = floatingEndpoint;
- }
-
-
- floatingConnections[id] = jpc;
-
-
- floatingEndpoint.addConnection(jpc);
-
-
-
- _addToList(endpointsByElement, id, floatingEndpoint);
-
- };
-
- var dragOptions = params.dragOptions || { };
-
- var defaultOpts = jsPlumb.extend({}, jsPlumb.CurrentLibrary.defaultDragOptions);
- dragOptions = jsPlumb.extend(defaultOpts, dragOptions);
- var startEvent = jsPlumb.CurrentLibrary.dragEvents['start'];
- var stopEvent = jsPlumb.CurrentLibrary.dragEvents['stop'];
- var dragEvent = jsPlumb.CurrentLibrary.dragEvents['drag'];
- dragOptions[startEvent] = _wrap(dragOptions[startEvent], start);
- dragOptions[dragEvent] = _wrap(dragOptions[dragEvent], function() {
- var _ui = jsPlumb.CurrentLibrary.getUIPosition(arguments);
- _draw(_getElementObject(n), _ui);
- });
- dragOptions[stopEvent] = _wrap(dragOptions[stopEvent],
- function() {
- _removeFromList(endpointsByElement, id, floatingEndpoint);
- _removeElements([floatingEndpoint.canvas, n]);
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- if (jpc.endpoints[idx] == floatingEndpoint) {
-
- if (existingJpc && jpc.suspendedEndpoint) {
- if (_reattach) {
- jpc.floatingAnchorIndex = null;
- if (idx == 0) {
- jpc.source = existingJpcParams[0];
- jpc.sourceId = existingJpcParams[1];
- } else {
- jpc.target = existingJpcParams[0];
- jpc.targetId = existingJpcParams[1];
- }
- jpc.endpoints[idx] = jpc.suspendedEndpoint;
- jpc.suspendedEndpoint.addConnection(jpc);
- jsPlumb.repaint(existingJpcParams[1]);
- }
- else {
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- _removeElement(jpc.canvas);
- }
- } else {
- _removeElement(jpc.canvas);
- self.removeConnection(jpc);
- }
- }
- jpc = null;
- delete floatingEndpoint;
- }
- );
-
- var i = _getElementObject(self.canvas);
- _initDraggable(i, dragOptions);
- };
-
-
- if (params.isTarget && _isDropSupported(_element)) {
- var dropOptions = params.dropOptions || jsPlumb.Defaults.DropOptions;
- dropOptions = jsPlumb.extend({}, dropOptions);
- var originalAnchor = null;
- dropOptions.drop = _wrap(dropOptions.drop, function() {
- var draggable = jsPlumb.CurrentLibrary.getDragObject(arguments);
- var id = _getAttribute(_getElementObject(draggable), "dragId");
- var elId = _getAttribute(_getElementObject(draggable),"elId");
- var jpc = floatingConnections[id];
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- if (idx == 0) {
- jpc.source = _element;
- jpc.sourceId = _elementId;
- } else {
- jpc.target = _element;
- jpc.targetId = _elementId;
- }
-
- jpc.endpoints[idx].removeConnection(jpc);
- if (jpc.suspendedEndpoint)
- jpc.suspendedEndpoint.removeConnection(jpc);
- jpc.endpoints[idx] = self;
- self.addConnection(jpc);
- _initDraggableIfNecessary(_element, _elementId, params.draggable, {});
- jsPlumb.repaint(elId);
-
- delete floatingConnections[id];
- });
-
-
-
-
-
-
-
-
-
-
-
-
- dropOptions.over = _wrap(dropOptions.over, function() {
- var draggable = jsPlumb.CurrentLibrary.getDragObject(arguments);
- var id = _getAttribute(_getElementObject(draggable),"dragId");
- var jpc = floatingConnections[id];
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- jpc.endpoints[idx].anchor.over(self.anchor);
- });
-
- dropOptions.out = _wrap(dropOptions.out, function() {
- var draggable = jsPlumb.CurrentLibrary.getDragObject(arguments);
- var id = _getAttribute(_getElementObject(draggable),"dragId");
- var jpc = floatingConnections[id];
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- jpc.endpoints[idx].anchor.out();
- });
-
- _initDroppable(_getElementObject(self.canvas), dropOptions);
- }
-
- return self;
- };
-
-
- var jsPlumb = window.jsPlumb = {
-
-
- Defaults : {
- Anchors : [ null, null ],
- Connector : null,
- DragOptions: { },
- DropOptions: { },
- Endpoint : null,
- Endpoints : [ null, null ],
- EndpointStyle : { fillStyle : null },
- EndpointStyles : [ null, null ],
- MaxConnections : null,
- PaintStyle : { lineWidth : 10, strokeStyle : 'red' }
- },
-
-
- connectorClass : '_jsPlumb_connector',
-
-
- endpointClass : '_jsPlumb_endpoint',
-
-
- Anchors : {},
-
-
- Connectors : {},
-
-
- Endpoints : {},
-
-
- addEndpoint : function(target, params) {
- params = jsPlumb.extend({}, params);
- var el = _getElementObject(target);
- var id = _getAttribute(target,"id");
- params.source = el;
- _updateOffset(id);
- var e = new Endpoint(params);
- _addToList(endpointsByElement, id, e);
- var myOffset = offsets[id];
- var myWH = sizes[id];
- var anchorLoc = e.anchor.compute([myOffset.left, myOffset.top], myWH);
- e.paint(anchorLoc);
- return e;
- },
-
-
- addEndpoints : function(target, endpoints) {
- var results = [];
- for (var i = 0; i < endpoints.length; i++) {
- results.push(jsPlumb.addEndpoint(target, endpoints[i]));
- }
- return results;
- },
-
-
-
- animate : function(el, properties, options) {
- var ele = _getElementObject(el);
- var id = _getAttribute(el,"id");
- options = options || {};
- options.step = _wrap(options.step, function() { jsPlumb.repaint(id); });
- _animate(ele, properties, options);
- },
-
-
- connect : function(params) {
- if (params.sourceEndpoint && params.sourceEndpoint.isFull()) {
- _log("could not add connection; source endpoint is full");
- return;
- }
-
- if (params.targetEndpoint && params.targetEndpoint.isFull()) {
- _log("could not add connection; target endpoint is full");
- return;
- }
-
- var jpc = new Connection(params);
-
-
-
-
-
-
- if (!params.sourceEndpoint) _addToList(endpointsByElement, jpc.sourceId, jpc.endpoints[0]);
- if (!params.targetEndpoint) _addToList(endpointsByElement, jpc.targetId, jpc.endpoints[1]);
-
- jpc.endpoints[0].addConnection(jpc);
- jpc.endpoints[1].addConnection(jpc);
-
-
- _draw(jpc.source);
-
- return jpc;
-
- },
-
-
-
-
- detach : function(sourceId, targetId) {
- var f = function(jpc) {
- if ((jpc.sourceId == sourceId && jpc.targetId == targetId) || (jpc.targetId == sourceId && jpc.sourceId == targetId)) {
- _removeElement(jpc.canvas);
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- return true;
- }
- };
-
-
- _operation(sourceId, f);
- },
-
-
- detachAll : function(el) {
- var id = _getAttribute(el, "id");
- var f = function(jpc) {
-
- _removeElement(jpc.canvas);
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- };
- _operation(id, f);
-
- },
-
-
- detachEverything : function() {
- var f = function(jpc) {
- _removeElement(jpc.canvas);
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- };
-
- _operationOnAll(f);
-
-
-
- },
-
- extend : function(o1, o2) {
- return jsPlumb.CurrentLibrary.extend(o1, o2);
- },
-
-
- hide : function(el) {
- _setVisible(el, "none");
- },
-
-
- makeAnchor : function(x, y, xOrientation, yOrientation, xOffset, yOffset) {
-
-
- var params = {};
- if (arguments.length == 1) jsPlumb.extend(params, x);
- else {
- params = {x:x, y:y};
- if (arguments.length >= 4) {
- params.orientation = [arguments[2], arguments[3]];
- }
- if (arguments.length == 6) params.offsets = [arguments[4], arguments[5]];
- }
- return new Anchor(params);
- },
-
-
-
- repaint : function(el) {
-
- var _processElement = function(el) {
- var ele = _getElementObject(el);
- _draw(ele);
- };
-
-
-
-
- if (typeof el =='object') {
- for (var i = 0; i < el.length; i++)
- _processElement(el[i]);
- }
- else _processElement(el);
- },
-
-
- repaintEverything : function() {
- for (var elId in endpointsByElement) {
- _draw(_getElementObject(elId));
- }
- },
-
-
- removeAllEndpoints : function(el) {
- var elId = _getAttribute(el, "id");
-
- jsPlumb.detachAll(elId);
- var ebe = endpointsByElement[elId];
- for (var i in ebe) {
- _removeElement(ebe[i].canvas);
- }
- endpointsByElement[elId] = [];
- },
-
-
- removeEndpoint : function(el, endpoint) {
- var elId = _getAttribute(el, "id");
- var ebe = endpointsByElement[elId];
- if (ebe) {
- if(_removeFromList(endpointsByElement, elId, endpoint))
- _removeElement(endpoint.canvas);
- }
- },
-
-
- setAutomaticRepaint : function(value) {
- automaticRepaint = value;
- },
-
-
- setDefaultNewCanvasSize : function(size) {
- DEFAULT_NEW_CANVAS_SIZE = size;
- },
-
-
- setDraggable: _setDraggable,
-
-
- setDraggableByDefault: function(draggable) {
- _draggableByDefault = draggable;
- },
-
- setDebugLog: function(debugLog) {
- log = debugLog;
- },
-
-
- setRepaintFunction : function(f) {
- repaintFunction = f;
- },
-
-
- show : function(el) {
- _setVisible(el, "block");
- },
-
-
- sizeCanvas : function(canvas, x, y, w, h) {
- if (canvas) {
- canvas.style.height = h + "px"; canvas.height = h;
- canvas.style.width = w + "px"; canvas.width = w;
- canvas.style.left = x + "px"; canvas.style.top = y + "px";
- }
- },
-
-
- getTestHarness : function() {
- return {
- endpointCount : function(elId) {
- var e = endpointsByElement[elId];
- return e ? e.length : 0;
- }
- };
- },
-
-
- toggle : _toggleVisible,
-
-
-
- toggleVisible : _toggleVisible,
-
-
- toggleDraggable : _toggleDraggable,
-
-
- unload : function() {
- delete endpointsByElement;
- delete offsets;
- delete sizes;
- delete floatingConnections;
- delete draggableStates;
- }
- };
- })();
- (function($){
-
- $.fn.plumb = function(options) {
- var options = $.extend({}, options);
- return this.each(function()
- {
- var params = $.extend({source:$(this)}, options);
- jsPlumb.connect(params);
- });
- };
-
-
- $.fn.detach = function(target) {
- return this.each(function()
- {
- var id = $(this).attr("id");
- if (typeof target == 'string') target = [target];
- for (var i = 0; i < target.length; i++)
- jsPlumb.detach(id, target[i]);
- });
- };
-
-
- $.fn.detachAll = function() {
- return this.each(function()
- {
- var id = $(this).attr("id");
- jsPlumb.detachAll(id);
- });
- };
-
-
- $.fn.addEndpoint = function(options) {
- var addedEndpoints = [];
- this.each(function()
- {
- addedEndpoints.push(jsPlumb.addEndpoint($(this).attr("id"), options));
- });
- return addedEndpoints[0];
- };
-
-
- $.fn.addEndpoints = function(endpoints) {
- var addedEndpoints = [];
- return this.each(function()
- {
- var e = jsPlumb.addEndpoints($(this).attr("id"), endpoints);
- for (var i = 0; i < e.length; i++) addedEndpoints.push(e[i]);
- });
- return addedEndpoints;
- };
-
-
- $.fn.removeEndpoint = function(endpoint) {
- this.each(function()
- {
- jsPlumb.removeEndpoint($(this).attr("id"), endpoint);
- });
- };
-
- })(jQuery);
- (function() {
-
- jsPlumb.CurrentLibrary = {
-
-
- dragEvents : {
- 'start':'start', 'stop':'stop', 'drag':'drag'
- },
-
-
- defaultDragOptions : { opacity:0.5, revert:true, helper:'clone' },
-
-
- extend : function(o1, o2) {
- return $.extend(o1, o2);
- },
-
-
- getElementObject : function(el) {
- return typeof(el)=='string' ? $("#" + el) : $(el);
- },
-
-
- getOffset : function(el) {
- return el.offset();
- },
-
-
- getSize : function(el) {
- return [el.outerWidth(), el.outerHeight()];
- },
-
-
- getAttribute : function(el, attName) {
- return el.attr(attName);
- },
-
-
- setAttribute : function(el, attName, attValue) {
- el.attr(attName, attValue);
- },
-
-
- addClass : function(el, clazz) {
- el.addClass(clazz);
- },
-
-
- initDraggable : function(el, options) {
- if (el.length > 1) alert('poo');
- el.draggable(options);
- },
-
-
- isDragSupported : function(el, options) {
- return el.draggable;
- },
-
-
- setDraggable : function(el, draggable) {
- el.draggable("option", "disabled", !draggable);
- },
-
-
- initDroppable : function(el, options) {
- el.droppable(options);
- },
-
-
- isDropSupported : function(el, options) {
- return el.droppable;
- },
-
-
- animate : function(el, properties, options) {
- el.animate(properties, options);
- },
-
-
- getUIPosition : function(eventArgs) {
- var ui = eventArgs[1];
- return ui.absolutePosition || ui.offset;
- },
-
-
- getDragObject : function(eventArgs) {
- return eventArgs[1].draggable;
- }
- };
- })();
|