12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299 |
- ;(function() {
-
-
-
- var ie = !!!document.createElement('canvas').getContext;
-
- var canvasAvailable = !!document.createElement('canvas').getContext;
- var svgAvailable = !!window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1");
-
- var vmlAvailable = !(canvasAvailable | svgAvailable);
-
- 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);
- return l;
- };
-
-
- var _connectionBeingDragged = null;
- var _getAttribute = function(el, attName) { return jsPlumb.CurrentLibrary.getAttribute(_getElementObject(el), attName); };
- var _setAttribute = function(el, attName, attValue) { jsPlumb.CurrentLibrary.setAttribute(_getElementObject(el), attName, attValue); };
- var _addClass = function(el, clazz) { jsPlumb.CurrentLibrary.addClass(_getElementObject(el), clazz); };
- var _hasClass = function(el, clazz) { return jsPlumb.CurrentLibrary.hasClass(_getElementObject(el), clazz); };
- var _removeClass = function(el, clazz) { jsPlumb.CurrentLibrary.removeClass(_getElementObject(el), clazz); };
- var _getElementObject = function(el) { return jsPlumb.CurrentLibrary.getElementObject(el); };
- var _getOffset = function(el) { return jsPlumb.CurrentLibrary.getOffset(_getElementObject(el)); };
- var _getSize = function(el) { return jsPlumb.CurrentLibrary.getSize(_getElementObject(el)); };
- var _log = function(jsp, msg) {
- if (jsp.logEnabled && typeof console != "undefined")
- console.log(msg);
- };
-
-
-
- var EventGenerator = function() {
- var _listeners = {}, self = this;
-
-
-
-
-
-
- var eventsToDieOn = [ "ready" ];
-
-
- this.bind = function(event, listener) {
- _addToList(_listeners, event, listener);
- };
-
-
- this.fire = function(event, value, originalEvent) {
- if (_listeners[event]) {
- for ( var i = 0; i < _listeners[event].length; i++) {
-
-
- if (_findIndex(eventsToDieOn, event) != -1)
- _listeners[event][i](value, originalEvent);
- else {
-
- try {
- _listeners[event][i](value, originalEvent);
- } catch (e) {
- _log("jsPlumb: fire failed for event " + event + " : " + e);
- }
- }
- }
- }
- };
-
- this.clearListeners = function(event) {
- if (event) {
- delete _listeners[event];
- } else {
- delete _listeners;
- _listeners = {};
- }
- };
-
- };
-
-
- var jsPlumbUIComponent = function(params) {
- var self = this, a = arguments, _hover = false;
- self._jsPlumb = params["_jsPlumb"];
-
-
- EventGenerator.apply(this);
-
- this.clone = function() {
- var o = new Object();
- self.constructor.apply(o, a);
- return o;
- };
-
- this.overlayPlacements = [],
- this.paintStyle = null,
- this.hoverPaintStyle = null;
-
-
-
-
- var _updateHoverStyle = function() {
- if (self.paintStyle && self.hoverPaintStyle) {
- var mergedHoverStyle = {};
- jsPlumb.extend(mergedHoverStyle, self.paintStyle);
- jsPlumb.extend(mergedHoverStyle, self.hoverPaintStyle);
- delete self.hoverPaintStyle;
-
- if (mergedHoverStyle.gradient && self.paintStyle.fillStyle)
- delete mergedHoverStyle.gradient;
- self.hoverPaintStyle = mergedHoverStyle;
- }
- };
-
-
- this.setPaintStyle = function(style, doNotRepaint) {
- self.paintStyle = style;
- self.paintStyleInUse = self.paintStyle;
- _updateHoverStyle();
- if (!doNotRepaint) self.repaint();
- };
-
-
- this.setHoverPaintStyle = function(style, doNotRepaint) {
- self.hoverPaintStyle = style;
- _updateHoverStyle();
- if (!doNotRepaint) self.repaint();
- };
-
-
- this.setHover = function(hover, ignoreAttachedElements) {
- _hover = hover;
- if (self.hoverPaintStyle != null) {
- self.paintStyleInUse = hover ? self.hoverPaintStyle : self.paintStyle;
- self.repaint();
-
- if (!ignoreAttachedElements)
- _updateAttachedElements(hover);
- }
- };
-
- this.isHover = function() {
- return _hover;
- };
-
- this.attachListeners = function(o, c) {
- var jpcl = jsPlumb.CurrentLibrary,
- events = [ "click", "dblclick", "mouseenter", "mouseout", "mousemove", "mousedown", "mouseup" ],
- eventFilters = { "mouseout":"mouseexit" },
- bindOne = function(evt) {
- var filteredEvent = eventFilters[evt] || evt;
- jpcl.bind(o, evt, function(ee) {
- c.fire(filteredEvent, c, ee);
- });
- };
- for (var i = 0; i < events.length; i++) {
- bindOne(events[i]);
- }
- };
-
- var _updateAttachedElements = function(state) {
- var affectedElements = self.getAttachedElements();
- if (affectedElements) {
- for (var i = 0; i < affectedElements.length; i++) {
- affectedElements[i].setHover(state, true);
- }
- }
- };
- };
-
- var jsPlumbInstance = function(_defaults) {
-
-
- this.Defaults = {
- Anchor : "BottomCenter",
- Anchors : [ null, null ],
- Connector : "Bezier",
- DragOptions : { },
- DropOptions : { },
- Endpoint : "Dot",
- Endpoints : [ null, null ],
- EndpointStyle : { fillStyle : null },
- EndpointStyles : [ null, null ],
- EndpointHoverStyle : null,
- EndpointHoverStyles : [ null, null ],
- HoverPaintStyle : null,
- LabelStyle : { color : "black" },
- LogEnabled : false,
- Overlays : [ ],
- MaxConnections : 1,
- MouseEventsEnabled : true,
- PaintStyle : { lineWidth : 8, strokeStyle : "#456" },
- RenderMode : "canvas",
- Scope : "_jsPlumb_DefaultScope"
- };
- if (_defaults) jsPlumb.extend(this.Defaults, _defaults);
-
- this.logEnabled = this.Defaults.LogEnabled;
- EventGenerator.apply(this);
- var _bb = this.bind;
- this.bind = function(event, fn) {
- if ("ready" === event && initialized) fn();
- else _bb(event, fn);
- };
- var _currentInstance = this,
- log = null,
- repaintFunction = function() {
- jsPlumb.repaintEverything();
- },
- automaticRepaint = true,
- repaintEverything = function() {
- if (automaticRepaint)
- repaintFunction();
- },
- resizeTimer = null,
- initialized = false,
- connectionsByScope = {},
-
- endpointsByElement = {},
- endpointsByUUID = {},
- offsets = {},
- offsetTimestamps = {},
- floatingConnections = {},
- draggableStates = {},
- _mouseEventsEnabled = this.Defaults.MouseEventsEnabled,
- _draggableByDefault = true,
- canvasList = [],
- sizes = [],
- listeners = {},
- DEFAULT_SCOPE = this.Defaults.Scope,
- renderMode = null,
-
- _addToList = function(map, key, value) {
- var l = map[key];
- if (l == null) {
- l = [];
- map[key] = l;
- }
- l.push(value);
- return l;
- },
-
- _appendElement = function(el, parent) {
- if (!parent)
- document.body.appendChild(el);
- else
- jsPlumb.CurrentLibrary.appendElement(el, parent);
- },
-
- _timestamp = function() { return "" + (new Date()).getTime(); },
-
-
- _convertYUICollection = function(c) {
- return c._nodes ? c._nodes : c;
- },
-
- _draw = function(element, ui, timestamp) {
- var id = _getAttribute(element, "id");
- var endpoints = endpointsByElement[id];
- if (!timestamp) timestamp = _timestamp();
- if (endpoints) {
- _updateOffset( { elId : id, offset : ui, recalc : false, timestamp : timestamp });
-
- var myOffset = offsets[id], myWH = sizes[id];
- for ( var i = 0; i < endpoints.length; i++) {
- endpoints[i].paint( { timestamp : timestamp, offset : myOffset, dimensions : myWH });
- var l = endpoints[i].connections;
- for ( var j = 0; j < l.length; j++) {
- l[j].paint( { elId : id, ui : ui, recalc : false, timestamp : timestamp });
-
- var oIdx = l[j].endpoints[0] == endpoints[i] ? 1 : 0;
- if (l[j].endpoints[oIdx].anchor.isDynamic && !l[j].endpoints[oIdx].isFloating()) {
- var oId = oIdx == 0 ? l[j].sourceId : l[j].targetId,
- oOffset = offsets[oId], oWH = sizes[oId],
-
- anchorLoc = l[j].endpoints[oIdx].anchor.compute( {
- xy : [ oOffset.left, oOffset.top ],
- wh : oWH,
- element : l[j].endpoints[oIdx],
- txy : [ myOffset.left, myOffset.top ],
- twh : myWH,
- tElement : endpoints[i]
- });
- l[j].endpoints[oIdx].paint({ anchorLoc : anchorLoc });
- }
- }
- }
- }
- },
-
- _elementProxy = function(element, fn) {
- var retVal = null;
- if (element.constructor == Array) {
- retVal = [];
- for ( var i = 0; i < element.length; i++) {
- var el = _getElementObject(element[i]), id = _getAttribute(el, "id");
- retVal.push(fn(el, id));
- }
- } else {
- var el = _getElementObject(element), id = _getAttribute(el, "id");
- retVal = fn(el, id);
- }
- return retVal;
- },
-
- _getEndpoint = function(uuid) { return endpointsByUUID[uuid]; },
-
- _initDraggableIfNecessary = function(element, isDraggable, dragOptions) {
- var draggable = isDraggable == null ? _draggableByDefault : isDraggable;
- if (draggable) {
- if (jsPlumb.CurrentLibrary.isDragSupported(element) && !jsPlumb.CurrentLibrary.isAlreadyDraggable(element)) {
- var options = dragOptions || _currentInstance.Defaults.DragOptions || jsPlumb.Defaults.DragOptions;
- options = jsPlumb.extend( {}, options);
- var dragEvent = jsPlumb.CurrentLibrary.dragEvents['drag'];
- var stopEvent = jsPlumb.CurrentLibrary.dragEvents['stop'];
- options[dragEvent] = _wrap(options[dragEvent], function() {
- var ui = jsPlumb.CurrentLibrary.getUIPosition(arguments);
- _draw(element, ui);
- _addClass(element, "jsPlumb_dragged");
- });
- options[stopEvent] = _wrap(options[stopEvent], function() {
- var ui = jsPlumb.CurrentLibrary.getUIPosition(arguments);
- _draw(element, ui);
- _removeClass(element, "jsPlumb_dragged");
- });
- var draggable = draggableStates[_getId(element)];
- options.disabled = draggable == null ? false : !draggable;
- jsPlumb.CurrentLibrary.initDraggable(element, options);
- }
- }
- },
-
- _newConnection = function(params) {
- var connectionFunc = jsPlumb.Defaults.ConnectionType || Connection,
- endpointFunc = jsPlumb.Defaults.EndpointType || Endpoint,
- parent = jsPlumb.CurrentLibrary.getParent;
-
- if (params.sourceEndpoint)
- params["parent"] = params.sourceEndpoint.parent;
- else if (params.source.constructor == endpointFunc)
- params["parent"] = params.source.parent;
- else params["parent"] = parent(params.source);
-
- params["_jsPlumb"] = _currentInstance;
- var con = new connectionFunc(params);
- _eventFireProxy("click", "click", con);
- _eventFireProxy("dblclick", "dblclick", con);
- return con;
- },
-
- _eventFireProxy = function(event, proxyEvent, obj) {
- obj.bind(event, function(e) {
- _currentInstance.fire(proxyEvent, obj, e);
- });
- },
-
- _newEndpoint = function(params) {
- var endpointFunc = jsPlumb.Defaults.EndpointType || Endpoint;
- params["parent"] = jsPlumb.CurrentLibrary.getParent(params.source);
- params["_jsPlumb"] = _currentInstance,
- ep = new endpointFunc(params);
- _eventFireProxy("click", "endpointClick", ep);
- _eventFireProxy("dblclick", "endpointDblClick", ep);
- return ep;
- },
-
-
- _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;
- }
- }
- }
- },
-
- _operationOnAll = function(func) {
- for ( var elId in endpointsByElement) {
- _operation(elId, func);
- }
- },
-
-
- _removeElement = function(element, parent) {
- if (element != null && element.parentNode != null) {
- element.parentNode.removeChild(element);
- }
- },
-
- _removeElements = function(elements, parent) {
- for ( var i = 0; i < elements.length; i++)
- _removeElement(elements[i], parent);
- },
-
- _removeFromList = function(map, key, value) {
- if (key != null) {
- 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;
- },
-
- _setDraggable = function(element, draggable) {
- return _elementProxy(element, function(el, id) {
- draggableStates[id] = draggable;
- if (jsPlumb.CurrentLibrary.isDragSupported(el)) {
- jsPlumb.CurrentLibrary.setDraggable(el, draggable);
- }
- });
- },
-
- _setVisible = function(el, state) {
- _operation(_getAttribute(el, "id"), function(jpc) {
- jpc.canvas.style.display = state;
- });
- },
-
- _toggleDraggable = function(el) {
- return _elementProxy(el, function(el, elId) {
- var state = draggableStates[elId] == null ? _draggableByDefault : draggableStates[elId];
- state = !state;
- draggableStates[elId] = state;
- jsPlumb.CurrentLibrary.setDraggable(el, state);
- return state;
- });
- },
-
- _toggleVisible = function(elId) {
- _operation(elId, function(jpc) {
- var state = ('none' == jpc.canvas.style.display);
- jpc.canvas.style.display = state ? "block" : "none";
- });
-
-
-
- },
-
- _updateOffset = function(params) {
- var timestamp = params.timestamp, recalc = params.recalc, offset = params.offset, elId = params.elId;
- if (!recalc) {
- if (timestamp && timestamp === offsetTimestamps[elId])
- return;
- }
- if (recalc || offset == null) {
-
-
- var s = _getElementObject(elId);
- if (s != null) {
- sizes[elId] = _getSize(s);
- offsets[elId] = _getOffset(s);
- offsetTimestamps[elId] = timestamp;
- }
- } else {
- offsets[elId] = offset;
- }
- },
- _getId = function(element, uuid) {
- var ele = _getElementObject(element);
- var id = _getAttribute(ele, "id");
- if (!id || id == "undefined") {
-
- if (arguments.length == 2 && arguments[1] != undefined)
- id = uuid;
- else
- id = "jsPlumb_" + _timestamp();
- _setAttribute(ele, "id", id);
- }
- return id;
- },
-
- _wrap = function(wrappedFunction, newFunction, returnOnThisValue) {
- wrappedFunction = wrappedFunction || function() { };
- newFunction = newFunction || function() { };
- return function() {
- var r = null;
- try {
- r = newFunction.apply(this, arguments);
- } catch (e) {
- _log(_currentInstance, 'jsPlumb function failed : ' + e);
- }
- if (returnOnThisValue == null || (r !== returnOnThisValue)) {
- try {
- wrappedFunction.apply(this, arguments);
- } catch (e) {
- _log(_currentInstance, 'wrapped function failed : ' + e);
- }
- }
- return r;
- };
- };
-
- this.connectorClass = "_jsPlumb_connector";
-
- this.endpointClass = "_jsPlumb_endpoint";
-
- this.overlayClass = "_jsPlumb_overlay";
-
- this.Anchors = {};
-
- this.Connectors = {
- "canvas":{},
- "svg":{},
- "vml":{}
- };
- this.Endpoints = {
- "canvas":{},
- "svg":{},
- "vml":{}
- };
- this.Overlays = {
- "canvas":{},
- "svg":{},
- "vml":{}
- };
-
-
-
-
-
-
-
-
- this.addEndpoint = function(el, params, referenceParams) {
- referenceParams = referenceParams || {};
- var p = jsPlumb.extend({}, referenceParams);
- jsPlumb.extend(p, params);
- p.endpoint = p.endpoint || _currentInstance.Defaults.Endpoint || jsPlumb.Defaults.Endpoint;
- p.paintStyle = p.paintStyle || _currentInstance.Defaults.EndpointStyle || jsPlumb.Defaults.EndpointStyle;
-
-
- el = _convertYUICollection(el);
-
- var results = [], inputs = el.length && el.constructor != String ? el : [ el ];
-
- for (var i = 0; i < inputs.length; i++) {
- var _el = _getElementObject(inputs[i]), id = _getId(_el);
- p.source = _el;
- _updateOffset({ elId : id });
- var e = _newEndpoint(p);
- _addToList(endpointsByElement, id, e);
- var myOffset = offsets[id], myWH = sizes[id];
- var anchorLoc = e.anchor.compute( { xy : [ myOffset.left, myOffset.top ], wh : myWH, element : e });
- e.paint({ anchorLoc : anchorLoc });
- results.push(e);
- }
-
- return results.length == 1 ? results[0] : results;
- };
-
-
- this.addEndpoints = function(el, endpoints, referenceParams) {
- var results = [];
- for ( var i = 0; i < endpoints.length; i++) {
- Array.prototype.push.apply(results, _currentInstance.addEndpoint(el, endpoints[i], referenceParams));
- }
- return results;
- };
-
- this.animate = function(el, properties, options) {
- var ele = _getElementObject(el), id = _getAttribute(el, "id");
- options = options || {};
- var stepFunction = jsPlumb.CurrentLibrary.dragEvents['step'];
- var completeFunction = jsPlumb.CurrentLibrary.dragEvents['complete'];
- options[stepFunction] = _wrap(options[stepFunction], function() {
- _currentInstance.repaint(id);
- });
-
- options[completeFunction] = _wrap(options[completeFunction],
- function() {
- _currentInstance.repaint(id);
- });
- jsPlumb.CurrentLibrary.animate(ele, properties, options);
- };
-
- this.connect = function(params, referenceParams) {
- var _p = jsPlumb.extend( {}, params);
- if (referenceParams) jsPlumb.extend(_p, referenceParams);
-
- if (_p.source && _p.source.endpoint) _p.sourceEndpoint = _p.source;
- if (_p.source && _p.target.endpoint) _p.targetEndpoint = _p.target;
-
-
- if (params.uuids) {
- _p.sourceEndpoint = _getEndpoint(params.uuids[0]);
- _p.targetEndpoint = _getEndpoint(params.uuids[1]);
- }
-
- if (_p.sourceEndpoint && _p.sourceEndpoint.isFull()) {
- _log(_currentInstance, "could not add connection; source endpoint is full");
- return;
- }
- if (_p.targetEndpoint && _p.targetEndpoint.isFull()) {
- _log(_currentInstance, "could not add connection; target endpoint is full");
- return;
- }
-
-
-
- if (_p.dynamicAnchors) {
-
-
- var a = _p.dynamicAnchors.constructor == Array;
- var sa = a ? new DynamicAnchor(jsPlumb.makeAnchors(_p.dynamicAnchors)) : new DynamicAnchor(jsPlumb.makeAnchors(_p.dynamicAnchors.source));
- var ta = a ? new DynamicAnchor(jsPlumb.makeAnchors(_p.dynamicAnchors)) : new DynamicAnchor(jsPlumb.makeAnchors(_p.dynamicAnchors.target));
- _p.anchors = [sa,ta];
- }
- var jpc = _newConnection(_p);
-
- _addToList(connectionsByScope, jpc.scope, jpc);
-
- _currentInstance.fire("jsPlumbConnection", {
- connection:jpc,
- source : jpc.source, target : jpc.target,
- sourceId : jpc.sourceId, targetId : jpc.targetId,
- sourceEndpoint : jpc.endpoints[0], targetEndpoint : jpc.endpoints[1]
- });
-
- _draw(jpc.source);
- return jpc;
- };
-
-
- this.deleteEndpoint = function(object) {
- var endpoint = (typeof object == "string") ? endpointsByUUID[object] : object;
- if (endpoint) {
- var uuid = endpoint.getUuid();
- if (uuid) endpointsByUUID[uuid] = null;
- endpoint.detachAll();
- _removeElement(endpoint.canvas, endpoint.parent);
-
- for (var e in endpointsByElement) {
- var endpoints = endpointsByElement[e];
- if (endpoints) {
- var newEndpoints = [];
- for (var i = 0; i < endpoints.length; i++)
- if (endpoints[i] != endpoint) newEndpoints.push(endpoints[i]);
-
- endpointsByElement[e] = newEndpoints;
- }
- }
- delete endpoint;
- }
- };
-
-
- this.deleteEveryEndpoint = function() {
- for ( var id in endpointsByElement) {
- var endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0; i < endpoints.length; i++) {
- _currentInstance.deleteEndpoint(endpoints[i]);
- }
- }
- }
- delete endpointsByElement;
- endpointsByElement = {};
- delete endpointsByUUID;
- endpointsByUUID = {};
- };
- var fireDetachEvent = function(jpc) {
- _currentInstance.fire("jsPlumbConnectionDetached", {
- connection:jpc,
- source : jpc.source, target : jpc.target,
- sourceId : jpc.sourceId, targetId : jpc.targetId,
- sourceEndpoint : jpc.endpoints[0], targetEndpoint : jpc.endpoints[1]
- });
- };
-
- this.detach = function(source, target) {
- if (arguments.length == 2) {
- var s = _getElementObject(source), sId = _getId(s);
- var t = _getElementObject(target), tId = _getId(t);
- _operation(sId, function(jpc) {
- if ((jpc.sourceId == sId && jpc.targetId == tId) || (jpc.targetId == sId && jpc.sourceId == tId)) {
- _removeElements(jpc.connector.getDisplayElements(), jpc.parent);
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- _removeFromList(connectionsByScope, jpc.scope, jpc);
- }
- });
- }
-
-
- else if (arguments.length == 1) {
-
- if (arguments[0].constructor == Connection) {
- arguments[0].endpoints[0].detachFrom(arguments[0].endpoints[1]);
- }
- else if (arguments[0].connection) {
- arguments[0].connection.endpoints[0].detachFrom(arguments[0].connection.endpoints[1]);
- }
- else {
- var _p = jsPlumb.extend( {}, source);
-
- if (_p.uuids) {
- _getEndpoint(_p.uuids[0]).detachFrom(_getEndpoint(_p.uuids[1]));
- } else if (_p.sourceEndpoint && _p.targetEndpoint) {
- _p.sourceEndpoint.detachFrom(_p.targetEndpoint);
- } else {
- var sourceId = _getId(_p.source);
- var targetId = _getId(_p.target);
- _operation(sourceId, function(jpc) {
- if ((jpc.sourceId == sourceId && jpc.targetId == targetId) || (jpc.targetId == sourceId && jpc.sourceId == targetId)) {
- _removeElements(jpc.connector.getDisplayElements(), jpc.parent);
- jpc.endpoints[0].removeConnection(jpc);
- jpc.endpoints[1].removeConnection(jpc);
- _removeFromList(connectionsByScope, jpc.scope, jpc);
- }
- });
- }
- }
- }
- };
-
- this.detachAllConnections = function(el) {
- var id = _getAttribute(el, "id");
- var endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0; i < endpoints.length; i++) {
- endpoints[i].detachAll();
- }
- }
- };
-
-
- this.detachAll = this.detachAllConnections;
-
- this.detachEveryConnection = function() {
- for ( var id in endpointsByElement) {
- var endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0; i < endpoints.length; i++) {
- endpoints[i].detachAll();
- }
- }
- }
- delete connectionsByScope;
- connectionsByScope = {};
- };
-
-
- this.detachEverything = this.detachEveryConnection;
-
- this.draggable = function(el, options) {
- if (typeof el == 'object' && el.length) {
- for ( var i = 0; i < el.length; i++) {
- var ele = _getElementObject(el[i]);
- if (ele) _initDraggableIfNecessary(ele, true, options);
- }
- }
- else if (el._nodes) {
-
- for ( var i = 0; i < el._nodes.length; i++) {
- var ele = _getElementObject(el._nodes[i]);
- if (ele) _initDraggableIfNecessary(ele, true, options);
- }
- }
- else {
- var ele = _getElementObject(el);
- if (ele) _initDraggableIfNecessary(ele, true, options);
- }
- };
-
- this.extend = function(o1, o2) {
- return jsPlumb.CurrentLibrary.extend(o1, o2);
- };
-
-
- this.getDefaultEndpointType = function() {
- return Endpoint;
- };
-
-
- this.getDefaultConnectionType = function() {
- return Connection;
- };
-
- this.getConnections = function(options) {
- if (!options) {
- options = {};
- } else if (options.constructor == String) {
- options = { "scope": options };
- }
- var prepareList = function(input) {
- var r = [];
- if (input) {
- if (typeof input == 'string')
- r.push(input);
- else
- r = input;
- }
- return r;
- };
- var scope = options.scope || jsPlumb.getDefaultScope(),
- scopes = prepareList(scope),
- sources = prepareList(options.source),
- targets = prepareList(options.target),
- filter = function(list, value) {
- return list.length > 0 ? _findIndex(list, value) != -1 : true;
- },
- results = scopes.length > 1 ? {} : [],
- _addOne = function(scope, obj) {
- if (scopes.length > 1) {
- var ss = results[scope];
- if (ss == null) {
- ss = []; results[scope] = ss;
- }
- ss.push(obj);
- } else results.push(obj);
- };
- for ( var i in connectionsByScope) {
- if (filter(scopes, i)) {
- for ( var j = 0; j < connectionsByScope[i].length; j++) {
- var c = connectionsByScope[i][j];
- if (filter(sources, c.sourceId) && filter(targets, c.targetId))
- _addOne(i, c);
- }
- }
- }
- return results;
- };
-
- this.getAllConnections = function() {
- return connectionsByScope;
- };
-
- this.getDefaultScope = function() {
- return DEFAULT_SCOPE;
- };
-
- this.getEndpoint = _getEndpoint;
-
-
- this.getEndpoints = function(el) {
- return endpointsByElement[_getId(el)];
- };
-
- this.getId = _getId;
-
- this.appendElement = _appendElement;
-
- this.hide = function(el) {
- _setVisible(el, "none");
- };
-
-
- this.init = function() {
- if (!initialized) {
- _currentInstance.setRenderMode(_currentInstance.Defaults.RenderMode);
-
- var _bind = function(event) {
- jsPlumb.CurrentLibrary.bind(document, event, function(e) {
- if (!_currentInstance.currentlyDragging && _mouseEventsEnabled && renderMode == jsPlumb.CANVAS) {
-
- for (var scope in connectionsByScope) {
- var c = connectionsByScope[scope];
- for (var i = 0; i < c.length; i++) {
- var t = c[i].connector[event](e);
- if (t) return;
- }
- }
- for (var el in endpointsByElement) {
- var ee = endpointsByElement[el];
- for (var i = 0; i < ee.length; i++) {
- if (ee[i].endpoint[event](e)) return;
- }
- }
- }
- });
- };
- _bind("click");
- _bind("dblclick");
- _bind("mousemove");
- _bind("mousedown");
- _bind("mouseup");
-
- initialized = true;
- _currentInstance.fire("ready");
- }
- };
-
- this.jsPlumbUIComponent = jsPlumbUIComponent;
- this.EventGenerator = EventGenerator;
-
- this.makeAnchor = function(x, y, xOrientation, yOrientation, xOffset, yOffset) {
-
-
-
-
-
- if (arguments.length == 0) return null;
- var params = {};
- if (arguments.length == 1) {
- var specimen = arguments[0];
-
- if (specimen.compute && specimen.getOrientation) return specimen;
-
- else if (typeof specimen == "string") return _currentInstance.Anchors[arguments[0]]();
-
- else if (specimen.constructor == Array) {
- if (specimen[0].constructor == Array || specimen[0].constructor == String)
- return new DynamicAnchor(specimen);
- else
- return jsPlumb.makeAnchor.apply(this, specimen);
- }
-
- else if (typeof arguments[0] == "object") 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] ];
- }
- var a = new Anchor(params);
- a.clone = function() {
- return new Anchor(params);
- };
- return a;
- };
-
- this.makeAnchors = function(types) {
- var r = [];
- for ( var i = 0; i < types.length; i++)
- if (typeof types[i] == "string")
- r.push(_currentInstance.Anchors[types[i]]());
- else if (types[i].constructor == Array)
- r.push(jsPlumb.makeAnchor(types[i]));
- return r;
- };
-
- this.makeDynamicAnchor = function(anchors, anchorSelector) {
- return new DynamicAnchor(anchors, anchorSelector);
- };
-
-
- this.makeTarget = function(el, params, referenceParams) {
-
- var p = jsPlumb.extend({}, referenceParams);
- jsPlumb.extend(p, params);
- var jpcl = jsPlumb.CurrentLibrary,
- scope = p.scope || _currentInstance.Defaults.Scope,
- deleteEndpointsOnDetach = p.deleteEndpointsOnDetach || false,
- _doOne = function(_el) {
- var dropOptions = jsPlumb.extend({}, p.dropOptions || {});
- var _drop = function() {
- var draggable = _getElementObject(jpcl.getDragObject(arguments)),
- id = _getAttribute(draggable, "dragId"),
-
- scope = _getAttribute(draggable, "originalScope");
-
- if (scope) jsPlumb.CurrentLibrary.setDragScope(draggable, scope);
-
-
- var jpc = floatingConnections[id],
- source = jpc.endpoints[0],
- _endpoint = p.endpoint ? jsPlumb.extend({}, p.endpoint) : null,
-
- newEndpoint = jsPlumb.addEndpoint(_el, _endpoint);
-
- var c = jsPlumb.connect({
- source:source,
- target:newEndpoint,
- scope:scope
- });
- if (deleteEndpointsOnDetach)
- c.endpointToDeleteOnDetach = newEndpoint;
- };
-
- var dropEvent = jpcl.dragEvents['drop'];
- dropOptions["scope"] = dropOptions["scope"] || scope;
- dropOptions[dropEvent] = _wrap(dropOptions[dropEvent], _drop);
-
- jpcl.initDroppable(_el, dropOptions);
- };
-
- el = _convertYUICollection(el);
-
- var results = [], inputs = el.length && el.constructor != String ? el : [ el ];
-
- for (var i = 0; i < inputs.length; i++) {
- _doOne(_getElementObject(inputs[i]));
- }
- };
-
-
- this.makeTargets = function(els, params, referenceParams) {
- for ( var i = 0; i < els.length; i++) {
- _currentInstance.makeTarget(els[i], params, referenceParams);
- }
- };
-
- this.repaint = function(el) {
- var _processElement = function(el) { _draw(_getElementObject(el)); };
-
- if (typeof el == 'object')
- for ( var i = 0; i < el.length; i++) _processElement(el[i]);
- else
- _processElement(el);
- };
-
- this.repaintEverything = function() {
- var timestamp = _timestamp();
- for ( var elId in endpointsByElement) {
- _draw(_getElementObject(elId), null, timestamp);
- }
- };
-
- this.removeAllEndpoints = function(el) {
- var elId = _getAttribute(el, "id");
- var ebe = endpointsByElement[elId];
- for ( var i in ebe)
- _currentInstance.deleteEndpoint(ebe[i]);
- endpointsByElement[elId] = [];
- };
-
- this.removeEveryEndpoint = this.deleteEveryEndpoint;
-
-
- this.removeEndpoint = function(el, endpoint) {
- _currentInstance.deleteEndpoint(endpoint);
- };
-
- this.reset = function() {
- this.deleteEveryEndpoint();
- this.clearListeners();
- };
-
- this.setAutomaticRepaint = function(value) {
- automaticRepaint = value;
- };
-
- this.setDefaultScope = function(scope) {
- DEFAULT_SCOPE = scope;
- };
-
- this.setDraggable = _setDraggable;
-
- this.setDraggableByDefault = function(draggable) {
- _draggableByDefault = draggable;
- };
- this.setDebugLog = function(debugLog) {
- log = debugLog;
- };
-
- this.setRepaintFunction = function(f) {
- repaintFunction = f;
- };
-
-
- this.setMouseEventsEnabled = function(enabled) {
- _mouseEventsEnabled = enabled;
- };
-
-
- this.CANVAS = "canvas";
-
-
- this.SVG = "svg";
-
- this.VML = "vml";
-
-
- this.setRenderMode = function(mode) {
- if (mode)
- mode = mode.toLowerCase();
- else
- return;
- if (mode !== jsPlumb.CANVAS && mode !== jsPlumb.SVG && mode !== jsPlumb.VML) throw new Error("render mode must be one of jsPlumb.CANVAS, jsPlumb.SVG or jsPlumb.VML");
-
- if (mode === jsPlumb.CANVAS && canvasAvailable)
- renderMode = jsPlumb.CANVAS;
- else if (mode === jsPlumb.SVG && svgAvailable)
- renderMode = jsPlumb.SVG;
- else if (vmlAvailable)
- renderMode = jsPlumb.VML;
-
- return renderMode;
- };
-
- this.getRenderMode = function() { return renderMode; };
-
- this.show = function(el) {
- _setVisible(el, "block");
- };
-
- this.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";
- }
- };
-
- this.getTestHarness = function() {
- return {
- endpointsByElement : endpointsByElement,
- endpointCount : function(elId) {
- var e = endpointsByElement[elId];
- return e ? e.length : 0;
- },
- connectionCount : function(scope) {
- scope = scope || DEFAULT_SCOPE;
- var c = connectionsByScope[scope];
- return c ? c.length : 0;
- },
- findIndex : _findIndex,
- getId : _getId,
- makeAnchor:self.makeAnchor,
- makeDynamicAnchor:self.makeDynamicAnchor
- };
- };
-
- this.toggle = _toggleVisible;
-
-
- this.toggleVisible = _toggleVisible;
-
- this.toggleDraggable = _toggleDraggable;
-
- this.unload = function() {
- delete endpointsByElement;
- delete endpointsByUUID;
- delete offsets;
- delete sizes;
- delete floatingConnections;
- delete draggableStates;
- delete canvasList;
- };
-
- this.wrap = _wrap;
- this.addListener = this.bind;
-
- var Anchor = function(params) {
- var self = this;
- this.x = params.x || 0;
- this.y = params.y || 0;
- var orientation = params.orientation || [ 0, 0 ];
- var lastTimestamp = null, lastReturnValue = null;
- this.offsets = params.offsets || [ 0, 0 ];
- self.timestamp = null;
- this.compute = function(params) {
- var xy = params.xy, wh = params.wh, element = params.element, timestamp = params.timestamp;
- if (timestamp && timestamp === self.timestamp) {
- return lastReturnValue;
- }
- lastReturnValue = [ xy[0] + (self.x * wh[0]) + self.offsets[0], xy[1] + (self.y * wh[1]) + self.offsets[1] ];
-
- var container = element ? element.parent : null;
- if (container != null) {
- var parentPosition = element.canvas.parentNode.style.position;
- var parentIsPositioned = parentPosition != null && parentPosition != "" && parentPosition != "static";
- if (parentIsPositioned) {
- console.log("positioning");
- var o = _getOffset(element.canvas.parentNode);
- lastReturnValue[0] = lastReturnValue[0] - o.left;
- lastReturnValue[1] = lastReturnValue[1] - o.top;
- }
- }
-
- self.timestamp = timestamp;
- return lastReturnValue;
- };
- this.getOrientation = function() { return orientation; };
- this.equals = function(anchor) {
- if (!anchor) return false;
- var ao = anchor.getOrientation();
- var o = this.getOrientation();
- return this.x == anchor.x && this.y == anchor.y
- && this.offsets[0] == anchor.offsets[0]
- && this.offsets[1] == anchor.offsets[1]
- && o[0] == ao[0] && o[1] == ao[1];
- };
- this.getCurrentLocation = function() { return lastReturnValue; };
- };
-
- var FloatingAnchor = function(params) {
-
-
- var ref = params.reference;
-
- var refCanvas = params.referenceCanvas;
- var size = _getSize(_getElementObject(refCanvas));
-
-
-
-
-
- var xDir = 0, yDir = 0;
-
-
- var orientation = null;
- var _lastResult = null;
- this.compute = function(params) {
- var xy = params.xy, element = params.element;
- var result = [ xy[0] + (size[0] / 2), xy[1] + (size[1] / 2) ];
-
- var container = element ? element.parent : null;
- if (container != null) {
- var parentPosition = element.canvas.parentNode.style.position;
- var parentIsPositioned = parentPosition != null && parentPosition != "" && parentPosition != "static";
- if (parentIsPositioned) {
- var o = _getOffset(element.canvas.parentNode);
- result[0] = result[0] - o.left;
- result[1] = result[1] - o.top;
- }
- }
-
-
- _lastResult = result;
- return result;
- };
- 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; };
- this.getCurrentLocation = function() { return _lastResult; };
- };
-
- var DynamicAnchor = function(anchors, anchorSelector) {
- this.isSelective = true;
- this.isDynamic = true;
- var _anchors = [];
- var _convert = function(anchor) { return anchor.constructor == Anchor ? anchor: jsPlumb.makeAnchor(anchor); };
- for (var i = 0; i < anchors.length; i++) _anchors[i] = _convert(anchors[i]);
- this.addAnchor = function(anchor) { _anchors.push(_convert(anchor)); };
- this.getAnchors = function() { return _anchors; };
- var _curAnchor = _anchors.length > 0 ? _anchors[0] : null;
- var _curIndex = _anchors.length > 0 ? 0 : -1;
- this.locked = false;
- var self = this;
-
-
- var _distance = function(anchor, cx, cy, xy, wh) {
- var ax = xy[0] + (anchor.x * wh[0]), ay = xy[1] + (anchor.y * wh[1]);
- return Math.sqrt(Math.pow(cx - ax, 2) + Math.pow(cy - ay, 2));
- };
-
-
-
-
-
-
-
- var _anchorSelector = anchorSelector || function(xy, wh, txy, twh, anchors) {
- var cx = txy[0] + (twh[0] / 2), cy = txy[1] + (twh[1] / 2);
- var minIdx = -1, minDist = Infinity;
- for ( var i = 0; i < anchors.length; i++) {
- var d = _distance(anchors[i], cx, cy, xy, wh);
- if (d < minDist) {
- minIdx = i + 0;
- minDist = d;
- }
- }
- return anchors[minIdx];
- };
- this.compute = function(params) {
- var xy = params.xy, wh = params.wh, timestamp = params.timestamp, txy = params.txy, twh = params.twh;
-
-
-
- if (self.locked || txy == null || twh == null)
- return _curAnchor.compute(params);
- else
- params.timestamp = null;
-
- _curAnchor = _anchorSelector(xy, wh, txy, twh, _anchors);
-
- var pos = _curAnchor.compute(params);
- return pos;
- };
- this.getCurrentLocation = function() {
- var cl = _curAnchor != null ? _curAnchor.getCurrentLocation() : null;
- return cl;
- };
- this.getOrientation = function() { return _curAnchor != null ? _curAnchor.getOrientation() : [ 0, 0 ]; };
- this.over = function(anchor) { if (_curAnchor != null) _curAnchor.over(anchor); };
- this.out = function() { if (_curAnchor != null) _curAnchor.out(); };
- };
-
-
- var Connection = function(params) {
- jsPlumbUIComponent.apply(this, arguments);
-
- var self = this;
- var visible = true;
-
- this.isVisible = function() { return visible; };
-
- this.setVisible = function(v) {
- visible = v;
- if (self.connector && self.connector.canvas) self.connector.canvas.style.display = v ? "block" : "none";
- };
- var id = new String('_jsplumb_c_' + (new Date()).getTime());
- this.getId = function() { return id; };
- this.parent = params.parent;
-
- this.source = _getElementObject(params.source);
-
- this.target = _getElementObject(params.target);
-
- if (params.sourceEndpoint) this.source = params.sourceEndpoint.getElement();
- if (params.targetEndpoint) this.target = params.targetEndpoint.getElement();
-
- this.sourceId = _getAttribute(this.source, "id");
-
- this.targetId = _getAttribute(this.target, "id");
- this.endpointsOnTop = params.endpointsOnTop != null ? params.endpointsOnTop : true;
-
-
- this.getAttachedElements = function() {
- return self.endpoints;
- };
-
-
- var srcWhenMouseDown = null, targetWhenMouseDown = null;
- this.savePosition = function() {
- srcWhenMouseDown = jsPlumb.CurrentLibrary.getOffset(jsPlumb.CurrentLibrary.getElementObject(self.source));
- targetWhenMouseDown = jsPlumb.CurrentLibrary.getOffset(jsPlumb.CurrentLibrary.getElementObject(self.target));
- };
-
-
- this.scope = params.scope;
-
- this.endpoints = [];
- this.endpointStyles = [];
-
- var _makeAnchor = function(anchorParams) {
- if (anchorParams)
- return jsPlumb.makeAnchor(anchorParams);
- };
- var prepareEndpoint = function(existing, index, params, element, connectorPaintStyle, connectorHoverPaintStyle) {
- if (existing) {
- self.endpoints[index] = existing;
- existing.addConnection(self);
- } else {
- if (!params.endpoints) params.endpoints = [ null, null ];
- var ep = params.endpoints[index]
- || params.endpoint
- || _currentInstance.Defaults.Endpoints[index]
- || jsPlumb.Defaults.Endpoints[index]
- || _currentInstance.Defaults.Endpoint
- || jsPlumb.Defaults.Endpoint;
- if (!params.endpointStyles) params.endpointStyles = [ null, null ];
- if (!params.endpointHoverStyles) params.endpointHoverStyles = [ null, null ];
- var es = params.endpointStyles[index] || params.endpointStyle || _currentInstance.Defaults.EndpointStyles[index] || jsPlumb.Defaults.EndpointStyles[index] || _currentInstance.Defaults.EndpointStyle || jsPlumb.Defaults.EndpointStyle;
-
- if (es.fillStyle == null && connectorPaintStyle != null)
- es.fillStyle = connectorPaintStyle.strokeStyle;
-
-
-
- if (es.outlineColor == null && connectorPaintStyle != null)
- es.outlineColor = connectorPaintStyle.outlineColor;
- if (es.outlineWidth == null && connectorPaintStyle != null)
- es.outlineWidth = connectorPaintStyle.outlineWidth;
-
-
- var ehs = params.endpointHoverStyles[index] || params.endpointHoverStyle || _currentInstance.Defaults.EndpointHoverStyles[index] || jsPlumb.Defaults.EndpointHoverStyles[index] || _currentInstance.Defaults.EndpointHoverStyle || jsPlumb.Defaults.EndpointHoverStyle;
-
- if (connectorHoverPaintStyle != null) {
- if (ehs == null) ehs = {};
- if (ehs.fillStyle == null) {
- ehs.fillStyle = connectorHoverPaintStyle.strokeStyle;
- }
- }
- var a = params.anchors ? params.anchors[index] : _makeAnchor(_currentInstance.Defaults.Anchors[index]) || _makeAnchor(jsPlumb.Defaults.Anchors[index]) || _makeAnchor(_currentInstance.Defaults.Anchor) || _makeAnchor(jsPlumb.Defaults.Anchor);
- var u = params.uuids ? params.uuids[index] : null;
- var e = _newEndpoint( { paintStyle : es, hoverPaintStyle:ehs, endpoint : ep, connections : [ self ], uuid : u, anchor : a, source : element });
- self.endpoints[index] = e;
-
- if (params.drawEndpoints === false) e.setVisible(false, true, true);
-
- return e;
- }
- };
- var eS = prepareEndpoint(params.sourceEndpoint, 0, params, self.source, params.paintStyle, params.hoverPaintStyle);
- if (eS) _addToList(endpointsByElement, this.sourceId, eS);
- var eT = prepareEndpoint(params.targetEndpoint, 1, params, self.target, params.paintStyle, params.hoverPaintStyle);
- if (eT) _addToList(endpointsByElement, this.targetId, eT);
-
- if (!this.scope) this.scope = this.endpoints[0].scope;
-
- this.setConnector = function(connector, doNotRepaint) {
- if (self.connector != null) _removeElements(self.connector.getDisplayElements(), self.parent);
- var connectorArgs = { _jsPlumb:self._jsPlumb, parent:params.parent, cssClass:params.cssClass };
- if (connector.constructor == String)
- this.connector = new jsPlumb.Connectors[renderMode][connector](connectorArgs);
- else if (connector.constructor == Array)
- this.connector = new jsPlumb.Connectors[renderMode][connector[0]](jsPlumb.extend(connector[1], connectorArgs));
- this.canvas = this.connector.canvas;
- var _mouseDown = false, _mouseWasDown = false, _mouseDownAt = null;
-
- this.connector.bind("click", function(con, e) {
- _mouseWasDown = false;
- self.fire("click", self, e);
- });
- this.connector.bind("dblclick", function(con, e) { _mouseWasDown = false;self.fire("dblclick", self, e); });
- this.connector.bind("mouseenter", function(con, e) {
- if (!self.isHover()) {
- if (_connectionBeingDragged == null) {
- self.setHover(true);
- }
- self.fire("mouseenter", self, e);
- }
- });
- this.connector.bind("mouseexit", function(con, e) {
- if (self.isHover()) {
- if (_connectionBeingDragged == null) {
- self.setHover(false);
- }
- self.fire("mouseexit", self, e);
- }
- });
- this.connector.bind("mousedown", function(con, e) {
- _mouseDown = true;
- _mouseDownAt = jsPlumb.CurrentLibrary.getPageXY(e);
- self.savePosition();
- });
- this.connector.bind("mouseup", function(con, e) {
- _mouseDown = false;
- if (self.connector == _connectionBeingDragged) _connectionBeingDragged = null;
- });
-
- if (!doNotRepaint) self.repaint();
- };
-
-
-
- self.setConnector(this.endpoints[0].connector ||
- this.endpoints[1].connector ||
- params.connector ||
- _currentInstance.Defaults.Connector ||
- jsPlumb.Defaults.Connector, true);
-
- this.setPaintStyle(this.endpoints[0].connectorStyle ||
- this.endpoints[1].connectorStyle ||
- params.paintStyle ||
- _currentInstance.Defaults.PaintStyle ||
- jsPlumb.Defaults.PaintStyle, true);
-
- this.setHoverPaintStyle(this.endpoints[0].connectorHoverStyle ||
- this.endpoints[1].connectorHoverStyle ||
- params.hoverPaintStyle ||
- _currentInstance.Defaults.HoverPaintStyle ||
- jsPlumb.Defaults.HoverPaintStyle, true);
-
- this.paintStyleInUse = this.paintStyle;
-
-
- this.overlays = [];
- var _overlays = params.overlays || _currentInstance.Defaults.Overlays;
- if (_overlays) {
- for (var i = 0; i < _overlays.length; i++) {
- var o = _overlays[i], _newOverlay = null, _overlayEvents = null;
- if (o.constructor == Array) {
-
-
-
- var type = o[0];
- var p = jsPlumb.CurrentLibrary.extend({connection:self, _jsPlumb:_currentInstance}, o[1]);
- if (o.length == 3) jsPlumb.CurrentLibrary.extend(p, o[2]);
- _newOverlay = new jsPlumb.Overlays[renderMode][type](p);
- if (p.events) {
- for (var evt in p.events) {
- _newOverlay.bind(evt, p.events[evt]);
- }
- }
- } else if (o.constructor == String) {
- _newOverlay = new jsPlumb.Overlays[renderMode][o]({connection:self, _jsPlumb:_currentInstance});
- } else {
- _newOverlay = o;
- }
-
-
-
- this.overlays.push(_newOverlay);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- this.addOverlay = function(overlay) { self.overlays.push(overlay); };
-
-
- this.removeAllOverlays = function() {
- self.overlays.splice(0, self.overlays.length);
- self.repaint();
- };
-
-
- this.removeOverlay = function(overlayId) {
- var idx = -1;
- for (var i = 0; i < self.overlays.length; i++) {
- if (overlayId === self.overlays[i].id) {
- idx = i;
- break;
- }
- }
- if (idx != -1) self.overlays.splice(idx, 1);
- };
-
-
- this.removeOverlays = function() {
- for (var i = 0; i < arguments.length; i++)
- self.removeOverlay(arguments[i]);
- };
-
-
- this.labelStyle = params.labelStyle || _currentInstance.Defaults.LabelStyle || jsPlumb.Defaults.LabelStyle;
- this.label = params.label;
- if (this.label) {
- this.overlays.push(new jsPlumb.Overlays[renderMode].Label( {
- cssClass:params.cssClass,
- labelStyle : this.labelStyle,
- label : this.label,
- connection:self,
- _jsPlumb:_currentInstance
- }));
- }
- _updateOffset( { elId : this.sourceId });
- _updateOffset( { elId : this.targetId });
-
- this.setLabel = function(l) {
- self.label = l;
- _currentInstance.repaint(self.source);
- };
-
- var myOffset = offsets[this.sourceId], myWH = sizes[this.sourceId];
- var otherOffset = offsets[this.targetId];
- var otherWH = sizes[this.targetId];
- var anchorLoc = this.endpoints[0].anchor.compute( {
- xy : [ myOffset.left, myOffset.top ], wh : myWH, element : this.endpoints[0],
- txy : [ otherOffset.left, otherOffset.top ], twh : otherWH, tElement : this.endpoints[1]
- });
- this.endpoints[0].paint( { anchorLoc : anchorLoc });
- anchorLoc = this.endpoints[1].anchor.compute( {
- xy : [ otherOffset.left, otherOffset.top ], wh : otherWH, element : this.endpoints[1],
- txy : [ myOffset.left, myOffset.top ], twh : myWH, tElement : this.endpoints[0]
- });
- this.endpoints[1].paint({ anchorLoc : anchorLoc });
-
-
- this.paint = function(params) {
- params = params || {};
- var elId = params.elId, ui = params.ui, recalc = params.recalc, timestamp = params.timestamp;
- var fai = self.floatingAnchorIndex;
-
- var swap = false;
- 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;
- _updateOffset( { elId : elId, offset : ui, recalc : recalc, timestamp : timestamp });
- _updateOffset( { elId : tId, timestamp : timestamp });
- var sAnchorP = this.endpoints[sIdx].anchor.getCurrentLocation();
- var sAnchorO = this.endpoints[sIdx].anchor.getOrientation();
- var tAnchorP = this.endpoints[tIdx].anchor.getCurrentLocation();
- var tAnchorO = this.endpoints[tIdx].anchor.getOrientation();
-
-
- var maxSize = 0;
- for ( var i = 0; i < self.overlays.length; i++) {
- var o = self.overlays[i];
- var s = o.computeMaxSize(self.connector);
- if (s > maxSize)
- maxSize = s;
- }
- var dim = this.connector.compute(sAnchorP, tAnchorP, this.endpoints[sIdx].anchor, this.endpoints[tIdx].anchor, self.paintStyleInUse.lineWidth, maxSize);
-
- self.connector.paint(dim, self.paintStyleInUse);
-
- for ( var i = 0; i < self.overlays.length; i++) {
- var o = self.overlays[i];
- self.overlayPlacements[i] = o.draw(self.connector, self.paintStyleInUse, dim);
- }
- };
-
- this.repaint = function() {
- this.paint({ elId : this.sourceId, recalc : true });
- };
- _initDraggableIfNecessary(self.source, params.draggable, params.dragOptions);
- _initDraggableIfNecessary(self.target, params.draggable, params.dragOptions);
-
-
- if (this.source.resize) {
- this.source.resize(function(e) {
- jsPlumb.repaint(self.sourceId);
- });
- }
-
-
- self.repaint();
- };
-
-
- var Endpoint = function(params) {
- jsPlumb.jsPlumbUIComponent.apply(this, arguments);
- params = params || {};
- var self = this;
-
-
-
-
-
-
-
-
-
- var visible = true;
-
- this.isVisible = function() { return visible; };
-
- this.setVisible = function(v, doNotChangeConnections, doNotNotifyOtherEndpoint) {
- visible = v;
- if (self.canvas) self.canvas.style.display = v ? "block" : "none";
- if (!doNotChangeConnections) {
- for (var i = 0; i < self.connections.length; i++) {
- self.connections[i].setVisible(v);
- if (!doNotNotifyOtherEndpoint) {
- var oIdx = self === self.connections[i].endpoints[0] ? 1 : 0;
-
- if (self.connections[i].endpoints[oIdx].connections.length == 1) self.connections[i].endpoints[oIdx].setVisible(v, true, true);
- }
- }
- }
- };
- var id = new String('_jsplumb_e_' + (new Date()).getTime());
- this.getId = function() { return id; };
- if (params.dynamicAnchors)
- self.anchor = new DynamicAnchor(jsPlumb.makeAnchors(params.dynamicAnchors));
- else
- self.anchor = params.anchor ? jsPlumb.makeAnchor(params.anchor) : params.anchors ? jsPlumb.makeAnchor(params.anchors) : jsPlumb.makeAnchor("TopCenter");
- var _endpoint = params.endpoint || _currentInstance.Defaults.Endpoint || jsPlumb.Defaults.Endpoint || "Dot",
- endpointArgs = { _jsPlumb:self._jsPlumb, parent:params.parent };
- if (_endpoint.constructor == String)
- _endpoint = new jsPlumb.Endpoints[renderMode][_endpoint](endpointArgs);
- else if (_endpoint.constructor == Array)
- _endpoint = new jsPlumb.Endpoints[renderMode][_endpoint[0]](jsPlumb.extend(_endpoint[1], endpointArgs ));
- else _endpoint = _endpoint.clone();
- self.endpoint = _endpoint;
- this.endpoint.bind("click", function(e) { self.fire("click", self, e); });
- this.endpoint.bind("dblclick", function(e) { self.fire("dblclick", self, e); });
- this.setPaintStyle(params.paintStyle ||
- params.style ||
- _currentInstance.Defaults.EndpointStyle ||
- jsPlumb.Defaults.EndpointStyle, true);
- this.setHoverPaintStyle(params.hoverPaintStyle ||
- _currentInstance.Defaults.EndpointHoverStyle ||
- jsPlumb.Defaults.EndpointHoverStyle, true);
- this.paintStyleInUse = this.paintStyle;
- this.connectorStyle = params.connectorStyle;
- this.connectorHoverStyle = params.connectorHoverStyle;
- this.connectorOverlays = params.connectorOverlays;
- this.connector = params.connector;
- this.parent = params.parent;
- this.isSource = params.isSource || false;
- this.isTarget = params.isTarget || false;
- var _element = params.source,
- _uuid = params.uuid,
- floatingEndpoint = null,
- inPlaceCopy = null;
- if (_uuid) endpointsByUUID[_uuid] = self;
- var _elementId = _getAttribute(_element, "id");
- this.elementId = _elementId;
- this.element = _element;
- var _maxConnections = params.maxConnections || _currentInstance.Defaults.MaxConnections;
-
- this.getAttachedElements = function() {
- return self.connections;
- };
-
-
- this.canvas = this.endpoint.canvas;
-
- this.connections = params.connections || [];
-
- this.scope = params.scope || DEFAULT_SCOPE;
- this.timestamp = null;
- var _reattach = params.reattach || false;
- var dragAllowedWhenFull = params.dragAllowedWhenFull || true;
- this.computeAnchor = function(params) {
- return self.anchor.compute(params);
- };
-
- this.addConnection = function(connection) {
- self.connections.push(connection);
- };
-
- this.detach = function(connection, ignoreTarget) {
- var idx = _findIndex(self.connections, connection);
- if (idx >= 0) {
- self.connections.splice(idx, 1);
-
-
- if (!ignoreTarget) {
- var t = connection.endpoints[0] == self ? connection.endpoints[1] : connection.endpoints[0];
- t.detach(connection, true);
-
-
-
-
-
-
-
- if (connection.endpointToDeleteOnDetach && connection.endpointToDeleteOnDetach.connections.length == 0)
- jsPlumb.deleteEndpoint(connection.endpointToDeleteOnDetach);
- }
- _removeElements(connection.connector.getDisplayElements(), connection.parent);
- _removeFromList(connectionsByScope, connection.scope, connection);
- if(!ignoreTarget) fireDetachEvent(connection);
- }
- };
-
- this.detachAll = function() {
- while (self.connections.length > 0) {
- self.detach(self.connections[0]);
- }
- };
-
- this.detachFrom = function(targetEndpoint) {
- var c = [];
- for ( var i = 0; i < self.connections.length; i++) {
- if (self.connections[i].endpoints[1] == targetEndpoint
- || self.connections[i].endpoints[0] == targetEndpoint) {
- c.push(self.connections[i]);
- }
- }
- for ( var i = 0; i < c.length; i++) {
- c[i].setHover(false);
- self.detach(c[i]);
- }
- };
-
- this.detachFromConnection = function(connection) {
- var idx = _findIndex(self.connections, connection);
- if (idx >= 0) {
- self.connections.splice(idx, 1);
- }
- };
-
- this.getElement = function() {
- return _element;
- };
-
- this.getUuid = function() {
- return _uuid;
- };
-
- this.makeInPlaceCopy = function() {
- return _newEndpoint( { anchor : self.anchor, source : _element, paintStyle : this.paintStyle, endpoint : _endpoint });
- };
-
- 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;
- };
-
-
- this.connectorSelector = function() {
- return (self.connections.length < _maxConnections) ? null : self.connections[0];
- };
-
- this.isFull = function() {
- return !(self.isFloating() || _maxConnections < 1 || self.connections.length < _maxConnections);
- };
-
- this.setDragAllowedWhenFull = function(allowed) {
- dragAllowedWhenFull = allowed;
- };
-
- this.setStyle = self.setPaintStyle;
-
- this.equals = function(endpoint) {
- return this.anchor.equals(endpoint.anchor);
- };
-
- this.paint = function(params) {
- params = params || {};
- var timestamp = params.timestamp;
- if (!timestamp || self.timestamp !== timestamp) {
- var ap = params.anchorPoint, canvas = params.canvas, connectorPaintStyle = params.connectorPaintStyle;
- if (ap == null) {
- var xy = params.offset || offsets[_elementId];
- var wh = params.dimensions || sizes[_elementId];
- if (xy == null || wh == null) {
- _updateOffset( { elId : _elementId, timestamp : timestamp });
- xy = offsets[_elementId];
- wh = sizes[_elementId];
- }
- var anchorParams = { xy : [ xy.left, xy.top ], wh : wh, element : self, timestamp : timestamp };
- if (self.anchor.isDynamic) {
- if (self.connections.length > 0) {
- var c = self.connections[0];
- var oIdx = c.endpoints[0] == self ? 1 : 0;
- var oId = oIdx == 0 ? c.sourceId : c.targetId;
- var oOffset = offsets[oId], oWH = sizes[oId];
- anchorParams.txy = [ oOffset.left, oOffset.top ];
- anchorParams.twh = oWH;
- anchorParams.tElement = c.endpoints[oIdx];
- }
- }
- ap = self.anchor.compute(anchorParams);
- }
-
- var d = _endpoint.compute(ap, self.anchor.getOrientation(), self.paintStyleInUse, connectorPaintStyle || self.paintStyleInUse);
- _endpoint.paint(d, self.paintStyleInUse, self.anchor);
-
- self.timestamp = timestamp;
- }
- };
-
- this.repaint = this.paint;
-
- this.removeConnection = this.detach;
-
-
- if (params.isSource && jsPlumb.CurrentLibrary.isDragSupported(_element)) {
- var n = null, id = null, jpc = null, existingJpc = false, existingJpcParams = null;
- var start = function() {
- jpc = self.connectorSelector();
- if (self.isFull() && !dragAllowedWhenFull) return false;
- _updateOffset( { elId : _elementId });
- inPlaceCopy = self.makeInPlaceCopy();
- inPlaceCopy.paint();
-
- n = document.createElement("div");
- n.style.position = "absolute";
- var nE = _getElementObject(n);
- _appendElement(n, self.parent);
-
- var id = _getId(nE);
-
-
- var ipcoel = _getElementObject(inPlaceCopy.canvas),
- ipco = jsPlumb.CurrentLibrary.getOffset(ipcoel),
- ipcs = jsPlumb.CurrentLibrary.getSize(ipcoel);
- jsPlumb.CurrentLibrary.setOffset(n, ipco);
-
- _updateOffset( { elId : id });
-
-
- _setAttribute(_getElementObject(self.canvas), "dragId", id);
- _setAttribute(_getElementObject(self.canvas), "elId", _elementId);
-
- var floatingAnchor = new FloatingAnchor( { reference : self.anchor, referenceCanvas : self.canvas });
- floatingEndpoint = _newEndpoint({ paintStyle : self.paintStyle, endpoint : _endpoint, anchor : floatingAnchor, source : nE });
- if (jpc == null) {
- self.anchor.locked = true;
-
-
- jpc = _newConnection({
- sourceEndpoint : self,
- targetEndpoint : floatingEndpoint,
- source : _getElementObject(_element),
- target : _getElementObject(n),
- anchors : [ self.anchor, floatingAnchor ],
- paintStyle : params.connectorStyle,
- hoverPaintStyle:params.connectorHoverStyle,
- connector : params.connector,
- overlays : params.connectorOverlays
- });
-
-
-
- jpc.connector.setHover(false);
- } else {
- existingJpc = true;
-
-
-
- jpc.connector.setHover(false);
-
- _initDropTarget(_getElementObject(inPlaceCopy.canvas));
- var anchorIdx = jpc.sourceId == _elementId ? 0 : 1;
-
- jpc.floatingAnchorIndex = anchorIdx;
- self.detachFromConnection(jpc);
-
-
- var c = _getElementObject(self.canvas);
- var dragScope = jsPlumb.CurrentLibrary.getDragScope(c);
- _setAttribute(c, "originalScope", dragScope);
-
- var newScope = "scope_" + (new Date()).getTime();
-
- if (anchorIdx == 0) {
- existingJpcParams = [ jpc.source, jpc.sourceId, i, dragScope ];
- jpc.source = _getElementObject(n);
- jpc.sourceId = id;
- } else {
- existingJpcParams = [ jpc.target, jpc.targetId, i, dragScope ];
- jpc.target = _getElementObject(n);
- jpc.targetId = id;
- }
-
- jsPlumb.CurrentLibrary.setDragScope(i, newScope);
-
- jpc.endpoints[anchorIdx == 0 ? 1 : 0].anchor.locked = true;
-
- jpc.suspendedEndpoint = jpc.endpoints[anchorIdx];
- jpc.endpoints[anchorIdx] = floatingEndpoint;
- }
-
- floatingConnections[id] = jpc;
-
-
- floatingEndpoint.addConnection(jpc);
-
-
-
-
- _addToList(endpointsByElement, id, floatingEndpoint);
-
-
- _currentInstance.currentlyDragging = true;
- };
- var jpcl = jsPlumb.CurrentLibrary,
- dragOptions = params.dragOptions || {},
- defaultOpts = jsPlumb.extend( {}, jpcl.defaultDragOptions),
- startEvent = jpcl.dragEvents['start'],
- stopEvent = jpcl.dragEvents['stop'],
- dragEvent = jpcl.dragEvents['drag'];
-
- dragOptions = jsPlumb.extend(defaultOpts, dragOptions);
- dragOptions.scope = dragOptions.scope || self.scope;
- dragOptions[startEvent] = _wrap(dragOptions[startEvent], start);
- dragOptions[dragEvent] = _wrap(dragOptions[dragEvent],
- function() {
- var _ui = jsPlumb.CurrentLibrary.getUIPosition(arguments);
- jsPlumb.CurrentLibrary.setOffset(n, _ui);
- _draw(_getElementObject(n), _ui);
- });
- dragOptions[stopEvent] = _wrap(dragOptions[stopEvent],
- function() {
- _removeFromList(endpointsByElement, id, floatingEndpoint);
- _removeElements( [ n, floatingEndpoint.canvas ], _element);
- _removeElement(inPlaceCopy.canvas, _element);
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- jpc.endpoints[idx == 0 ? 1 : 0].anchor.locked = false;
- if (jpc.endpoints[idx] == floatingEndpoint) {
-
- if (existingJpc && jpc.suspendedEndpoint) {
-
-
- if (idx == 0) {
- jpc.source = existingJpcParams[0];
- jpc.sourceId = existingJpcParams[1];
- } else {
- jpc.target = existingJpcParams[0];
- jpc.targetId = existingJpcParams[1];
- }
-
-
- jsPlumb.CurrentLibrary.setDragScope(existingJpcParams[2], existingJpcParams[3]);
-
- jpc.endpoints[idx] = jpc.suspendedEndpoint;
- if (_reattach) {
-
- jpc.floatingAnchorIndex = null;
- jpc.suspendedEndpoint.addConnection(jpc);
- jsPlumb.repaint(existingJpcParams[1]);
- } else {
- jpc.endpoints[idx == 0 ? 1 : 0].detach(jpc);
-
- }
- } else {
-
-
- _removeElements(jpc.connector.getDisplayElements(), self.parent);
- self.detachFromConnection(jpc);
- }
- }
- self.anchor.locked = false;
- self.paint();
- jpc.setHover(false);
- jpc.repaint();
- jpc = null;
- delete inPlaceCopy;
- delete endpointsByElement[floatingEndpoint.elementId];
- floatingEndpoint = null;
- delete floatingEndpoint;
-
- _currentInstance.currentlyDragging = false;
- });
-
- var i = _getElementObject(self.canvas);
- jsPlumb.CurrentLibrary.initDraggable(i, dragOptions);
- }
-
-
- var _initDropTarget = function(canvas) {
- if (params.isTarget && jsPlumb.CurrentLibrary.isDropSupported(_element)) {
- var dropOptions = params.dropOptions || _currentInstance.Defaults.DropOptions || jsPlumb.Defaults.DropOptions;
- dropOptions = jsPlumb.extend( {}, dropOptions);
- dropOptions.scope = dropOptions.scope || self.scope;
- var originalAnchor = null;
- var dropEvent = jsPlumb.CurrentLibrary.dragEvents['drop'];
- var overEvent = jsPlumb.CurrentLibrary.dragEvents['over'];
- var outEvent = jsPlumb.CurrentLibrary.dragEvents['out'];
- var drop = function() {
- var draggable = _getElementObject(jsPlumb.CurrentLibrary.getDragObject(arguments));
- var id = _getAttribute(draggable, "dragId");
- var elId = _getAttribute(draggable, "elId");
-
-
- var scope = _getAttribute(draggable, "originalScope");
- if (scope) jsPlumb.CurrentLibrary.setDragScope(draggable, scope);
-
- var jpc = floatingConnections[id];
-
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex, oidx = idx == 0 ? 1 : 0;
- if (!self.isFull() && !(idx == 0 && !self.isSource) && !(idx == 1 && !self.isTarget)) {
- if (idx == 0) {
- jpc.source = _element;
- jpc.sourceId = _elementId;
- } else {
- jpc.target = _element;
- jpc.targetId = _elementId;
- }
-
-
- jpc.endpoints[idx].detachFromConnection(jpc);
- if (jpc.suspendedEndpoint) jpc.suspendedEndpoint.detachFromConnection(jpc);
- jpc.endpoints[idx] = self;
- self.addConnection(jpc);
- if (!jpc.suspendedEndpoint) {
- _addToList(connectionsByScope, jpc.scope, jpc);
- _initDraggableIfNecessary(_element, params.draggable, {});
- }
- else {
- var suspendedElement = jpc.suspendedEndpoint.getElement(), suspendedElementId = jpc.suspendedEndpoint.elementId;
-
- _currentInstance.fire("jsPlumbConnectionDetached", {
- source : idx == 0 ? suspendedElement : jpc.source,
- target : idx == 1 ? suspendedElement : jpc.target,
- sourceId : idx == 0 ? suspendedElementId : jpc.sourceId,
- targetId : idx == 1 ? suspendedElementId : jpc.targetId,
- sourceEndpoint : idx == 0 ? jpc.suspendedEndpoint : jpc.endpoints[0],
- targetEndpoint : idx == 1 ? jpc.suspendedEndpoint : jpc.endpoints[1],
- connection : jpc
- });
- }
-
- jsPlumb.repaint(elId);
-
- _currentInstance.fire("jsPlumbConnection", {
- source : jpc.source, target : jpc.target,
- sourceId : jpc.sourceId, targetId : jpc.targetId,
- sourceEndpoint : jpc.endpoints[0],
- targetEndpoint : jpc.endpoints[1],
- connection:jpc
- });
- }
-
- _currentInstance.currentlyDragging = false;
- delete floatingConnections[id];
- };
-
- dropOptions[dropEvent] = _wrap(dropOptions[dropEvent], drop);
- dropOptions[overEvent] = _wrap(dropOptions[overEvent],
- function() {
- var draggable = jsPlumb.CurrentLibrary.getDragObject(arguments);
- var id = _getAttribute( _getElementObject(draggable), "dragId");
- var jpc = floatingConnections[id];
- if (jpc != null) {
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- jpc.endpoints[idx].anchor.over(self.anchor);
- }
- });
-
- dropOptions[outEvent] = _wrap(dropOptions[outEvent],
- function() {
- var draggable = jsPlumb.CurrentLibrary.getDragObject(arguments),
- id = _getAttribute(_getElementObject(draggable), "dragId"),
- jpc = floatingConnections[id];
- if (jpc != null) {
- var idx = jpc.floatingAnchorIndex == null ? 1 : jpc.floatingAnchorIndex;
- jpc.endpoints[idx].anchor.out();
- }
- });
-
- jsPlumb.CurrentLibrary.initDroppable(canvas, dropOptions);
- }
- };
-
-
- _initDropTarget(_getElementObject(self.canvas));
- return self;
- };
- };
- var jsPlumb = window.jsPlumb = new jsPlumbInstance();
- jsPlumb.getInstance = function(_defaults) {
- var j = new jsPlumbInstance(_defaults);
-
- return j;
- };
-
- var _curryAnchor = function(x,y,ox,oy) {
- return function() {
- return jsPlumb.makeAnchor(x,y,ox,oy);
- };
- };
- jsPlumb.Anchors["TopCenter"] = _curryAnchor(0.5, 0, 0,-1);
- jsPlumb.Anchors["BottomCenter"] = _curryAnchor(0.5, 1, 0, 1);
- jsPlumb.Anchors["LeftMiddle"] = _curryAnchor(0, 0.5, -1, 0);
- jsPlumb.Anchors["RightMiddle"] = _curryAnchor(1, 0.5, 1, 0);
- jsPlumb.Anchors["Center"] = _curryAnchor(0.5, 0.5, 0, 0);
- jsPlumb.Anchors["TopRight"] = _curryAnchor(1, 0, 0,-1);
- jsPlumb.Anchors["BottomRight"] = _curryAnchor(1, 1, 0, 1);
- jsPlumb.Anchors["TopLeft"] = _curryAnchor(0, 0, 0, -1);
- jsPlumb.Anchors["BottomLeft"] = _curryAnchor(0, 1, 0, 1);
-
- jsPlumb.Defaults.DynamicAnchors = function() {
- return jsPlumb.makeAnchors(["TopCenter", "RightMiddle", "BottomCenter", "LeftMiddle"]);
- };
- jsPlumb.Anchors["AutoDefault"] = function() { return jsPlumb.makeDynamicAnchor(jsPlumb.Defaults.DynamicAnchors()); };
-
-
- })();
|