123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214 |
- (function() {
-
- if(typeof Math.sgn == "undefined") {
- Math.sgn = function(x) { return x == 0 ? 0 : x > 0 ? 1 :-1; };
- }
-
- var Vectors = {
- subtract : function(v1, v2) { return {x:v1.x - v2.x, y:v1.y - v2.y }; },
- dotProduct : function(v1, v2) { return (v1.x * v2.x) + (v1.y * v2.y); },
- square : function(v) { return Math.sqrt((v.x * v.x) + (v.y * v.y)); },
- scale : function(v, s) { return {x:v.x * s, y:v.y * s }; }
- },
-
- maxRecursion = 64,
- flatnessTolerance = Math.pow(2.0,-maxRecursion-1);
-
- var _distanceFromCurve = function(point, curve) {
- var candidates = [],
- w = _convertToBezier(point, curve),
- degree = curve.length - 1, higherDegree = (2 * degree) - 1,
- numSolutions = _findRoots(w, higherDegree, candidates, 0),
- v = Vectors.subtract(point, curve[0]), dist = Vectors.square(v), t = 0.0;
- for (var i = 0; i < numSolutions; i++) {
- v = Vectors.subtract(point, _bezier(curve, degree, candidates[i], null, null));
- var newDist = Vectors.square(v);
- if (newDist < dist) {
- dist = newDist;
- t = candidates[i];
- }
- }
- v = Vectors.subtract(point, curve[degree]);
- newDist = Vectors.square(v);
- if (newDist < dist) {
- dist = newDist;
- t = 1.0;
- }
- return {location:t, distance:dist};
- };
-
- var _nearestPointOnCurve = function(point, curve) {
- var td = _distanceFromCurve(point, curve);
- return {point:_bezier(curve, curve.length - 1, td.location, null, null), location:td.location};
- };
- var _convertToBezier = function(point, curve) {
- var degree = curve.length - 1, higherDegree = (2 * degree) - 1,
- c = [], d = [], cdTable = [], w = [],
- z = [ [1.0, 0.6, 0.3, 0.1], [0.4, 0.6, 0.6, 0.4], [0.1, 0.3, 0.6, 1.0] ];
-
- for (var i = 0; i <= degree; i++) c[i] = Vectors.subtract(curve[i], point);
- for (var i = 0; i <= degree - 1; i++) {
- d[i] = Vectors.subtract(curve[i+1], curve[i]);
- d[i] = Vectors.scale(d[i], 3.0);
- }
- for (var row = 0; row <= degree - 1; row++) {
- for (var column = 0; column <= degree; column++) {
- if (!cdTable[row]) cdTable[row] = [];
- cdTable[row][column] = Vectors.dotProduct(d[row], c[column]);
- }
- }
- for (i = 0; i <= higherDegree; i++) {
- if (!w[i]) w[i] = [];
- w[i].y = 0.0;
- w[i].x = parseFloat(i) / higherDegree;
- }
- var n = degree, m = degree-1;
- for (var k = 0; k <= n + m; k++) {
- var lb = Math.max(0, k - m),
- ub = Math.min(k, n);
- for (i = lb; i <= ub; i++) {
- j = k - i;
- w[i+j].y += cdTable[j][i] * z[j][i];
- }
- }
- return w;
- };
-
- var _findRoots = function(w, degree, t, depth) {
- var left = [], right = [],
- left_count, right_count,
- left_t = [], right_t = [];
-
- switch (_getCrossingCount(w, degree)) {
- case 0 : {
- return 0;
- }
- case 1 : {
- if (depth >= maxRecursion) {
- t[0] = (w[0].x + w[degree].x) / 2.0;
- return 1;
- }
- if (_isFlatEnough(w, degree)) {
- t[0] = _computeXIntercept(w, degree);
- return 1;
- }
- break;
- }
- }
- _bezier(w, degree, 0.5, left, right);
- left_count = _findRoots(left, degree, left_t, depth+1);
- right_count = _findRoots(right, degree, right_t, depth+1);
- for (var i = 0; i < left_count; i++) t[i] = left_t[i];
- for (var i = 0; i < right_count; i++) t[i+left_count] = right_t[i];
- return (left_count+right_count);
- };
- var _getCrossingCount = function(curve, degree) {
- var n_crossings = 0, sign, old_sign;
- sign = old_sign = Math.sgn(curve[0].y);
- for (var i = 1; i <= degree; i++) {
- sign = Math.sgn(curve[i].y);
- if (sign != old_sign) n_crossings++;
- old_sign = sign;
- }
- return n_crossings;
- };
- var _isFlatEnough = function(curve, degree) {
- var error,
- intercept_1, intercept_2, left_intercept, right_intercept,
- a, b, c, det, dInv, a1, b1, c1, a2, b2, c2;
- a = curve[0].y - curve[degree].y;
- b = curve[degree].x - curve[0].x;
- c = curve[0].x * curve[degree].y - curve[degree].x * curve[0].y;
-
- var max_distance_above = max_distance_below = 0.0;
-
- for (var i = 1; i < degree; i++) {
- var value = a * curve[i].x + b * curve[i].y + c;
- if (value > max_distance_above)
- max_distance_above = value;
- else if (value < max_distance_below)
- max_distance_below = value;
- }
-
- a1 = 0.0; b1 = 1.0; c1 = 0.0; a2 = a; b2 = b;
- c2 = c - max_distance_above;
- det = a1 * b2 - a2 * b1;
- dInv = 1.0/det;
- intercept_1 = (b1 * c2 - b2 * c1) * dInv;
- a2 = a; b2 = b; c2 = c - max_distance_below;
- det = a1 * b2 - a2 * b1;
- dInv = 1.0/det;
- intercept_2 = (b1 * c2 - b2 * c1) * dInv;
- left_intercept = Math.min(intercept_1, intercept_2);
- right_intercept = Math.max(intercept_1, intercept_2);
- error = right_intercept - left_intercept;
- return (error < flatnessTolerance)? 1 : 0;
- };
- var _computeXIntercept = function(curve, degree) {
- var XLK = 1.0, YLK = 0.0,
- XNM = curve[degree].x - curve[0].x, YNM = curve[degree].y - curve[0].y,
- XMK = curve[0].x - 0.0, YMK = curve[0].y - 0.0,
- det = XNM*YLK - YNM*XLK, detInv = 1.0/det,
- S = (XNM*YMK - YNM*XMK) * detInv;
- return 0.0 + XLK * S;
- };
- var _bezier = function(curve, degree, t, left, right) {
- var temp = [[]];
- for (var j =0; j <= degree; j++) temp[0][j] = curve[j];
- for (var i = 1; i <= degree; i++) {
- for (var j =0 ; j <= degree - i; j++) {
- if (!temp[i]) temp[i] = [];
- if (!temp[i][j]) temp[i][j] = {};
- temp[i][j].x = (1.0 - t) * temp[i-1][j].x + t * temp[i-1][j+1].x;
- temp[i][j].y = (1.0 - t) * temp[i-1][j].y + t * temp[i-1][j+1].y;
- }
- }
- if (left != null)
- for (j = 0; j <= degree; j++) left[j] = temp[j][0];
- if (right != null)
- for (j = 0; j <= degree; j++) right[j] = temp[degree-j][j];
-
- return (temp[degree][0]);
- };
-
- var _curveFunctionCache = {};
- var _getCurveFunctions = function(order) {
- var fns = _curveFunctionCache[order];
- if (!fns) {
- fns = [];
- var f_term = function() { return function(t) { return Math.pow(t, order); }; },
- l_term = function() { return function(t) { return Math.pow((1-t), order); }; },
- c_term = function(c) { return function(t) { return c; }; },
- t_term = function() { return function(t) { return t; }; },
- one_minus_t_term = function() { return function(t) { return 1-t; }; },
- _termFunc = function(terms) {
- return function(t) {
- var p = 1;
- for (var i = 0; i < terms.length; i++) p = p * terms[i](t);
- return p;
- };
- };
-
- fns.push(new f_term());
- for (var i = 1; i < order; i++) {
- var terms = [new c_term(order)];
- for (var j = 0 ; j < (order - i); j++) terms.push(new t_term());
- for (var j = 0 ; j < i; j++) terms.push(new one_minus_t_term());
- fns.push(new _termFunc(terms));
- }
- fns.push(new l_term());
-
- _curveFunctionCache[order] = fns;
- }
-
- return fns;
- };
-
-
-
- var _pointOnPath = function(curve, location) {
- var cc = _getCurveFunctions(curve.length - 1),
- _x = 0, _y = 0;
- for (var i = 0; i < curve.length ; i++) {
- _x = _x + (curve[i].x * cc[i](location));
- _y = _y + (curve[i].y * cc[i](location));
- }
-
- return {x:_x, y:_y};
- };
-
- var _dist = function(p1,p2) {
- return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
- };
- var _isPoint = function(curve) {
- return curve[0].x == curve[1].x && curve[0].y == curve[1].y;
- };
-
-
- var _pointAlongPath = function(curve, location, distance) {
- if (_isPoint(curve)) {
- return {
- point:curve[0],
- location:location
- };
- }
- var prev = _pointOnPath(curve, location),
- tally = 0,
- curLoc = location,
- direction = distance > 0 ? 1 : -1,
- cur = null;
-
- while (tally < Math.abs(distance)) {
- curLoc += (0.005 * direction);
- cur = _pointOnPath(curve, curLoc);
- tally += _dist(cur, prev);
- prev = cur;
- }
- return {point:cur, location:curLoc};
- };
-
- var _length = function(curve) {
- if (_isPoint(curve)) return 0;
- var prev = _pointOnPath(curve, 0),
- tally = 0,
- curLoc = 0,
- direction = 1,
- cur = null;
-
- while (curLoc < 1) {
- curLoc += (0.005 * direction);
- cur = _pointOnPath(curve, curLoc);
- tally += _dist(cur, prev);
- prev = cur;
- }
- return tally;
- };
-
-
- var _pointAlongPathFrom = function(curve, location, distance) {
- return _pointAlongPath(curve, location, distance).point;
- };
-
- var _locationAlongPathFrom = function(curve, location, distance) {
- return _pointAlongPath(curve, location, distance).location;
- };
-
-
- var _gradientAtPoint = function(curve, location) {
- var p1 = _pointOnPath(curve, location),
- p2 = _pointOnPath(curve.slice(0, curve.length - 1), location),
- dy = p2.y - p1.y, dx = p2.x - p1.x;
- return dy == 0 ? Infinity : Math.atan(dy / dx);
- };
-
-
- var _gradientAtPointAlongPathFrom = function(curve, location, distance) {
- var p = _pointAlongPath(curve, location, distance);
- if (p.location > 1) p.location = 1;
- if (p.location < 0) p.location = 0;
- return _gradientAtPoint(curve, p.location);
- };
-
- var _perpendicularToPathAt = function(curve, location, length, distance) {
- distance = distance == null ? 0 : distance;
- var p = _pointAlongPath(curve, location, distance),
- m = _gradientAtPoint(curve, p.location),
- _theta2 = Math.atan(-1 / m),
- y = length / 2 * Math.sin(_theta2),
- x = length / 2 * Math.cos(_theta2);
- return [{x:p.point.x + x, y:p.point.y + y}, {x:p.point.x - x, y:p.point.y - y}];
- };
-
- var jsBezier = window.jsBezier = {
- distanceFromCurve : _distanceFromCurve,
- gradientAtPoint : _gradientAtPoint,
- gradientAtPointAlongCurveFrom : _gradientAtPointAlongPathFrom,
- nearestPointOnCurve : _nearestPointOnCurve,
- pointOnCurve : _pointOnPath,
- pointAlongCurveFrom : _pointAlongPathFrom,
- perpendicularToCurveAt : _perpendicularToPathAt,
- locationAlongCurveFrom:_locationAlongPathFrom,
- getLength:_length
- };
- })();
- ;(function() {
-
- "use strict";
- var Biltong = this.Biltong = {};
- var _isa = function(a) { return Object.prototype.toString.call(a) === "[object Array]"; },
- _pointHelper = function(p1, p2, fn) {
- p1 = _isa(p1) ? p1 : [p1.x, p1.y];
- p2 = _isa(p2) ? p2 : [p2.x, p2.y];
- return fn(p1, p2);
- },
-
- _gradient = Biltong.gradient = function(p1, p2) {
- return _pointHelper(p1, p2, function(_p1, _p2) {
- if (_p2[0] == _p1[0])
- return _p2[1] > _p1[1] ? Infinity : -Infinity;
- else if (_p2[1] == _p1[1])
- return _p2[0] > _p1[0] ? 0 : -0;
- else
- return (_p2[1] - _p1[1]) / (_p2[0] - _p1[0]);
- });
- },
-
- _normal = Biltong.normal = function(p1, p2) {
- return -1 / _gradient(p1, p2);
- },
-
- _lineLength = Biltong.lineLength = function(p1, p2) {
- return _pointHelper(p1, p2, function(_p1, _p2) {
- return Math.sqrt(Math.pow(_p2[1] - _p1[1], 2) + Math.pow(_p2[0] - _p1[0], 2));
- });
- },
-
- _quadrant = Biltong.quadrant = function(p1, p2) {
- return _pointHelper(p1, p2, function(_p1, _p2) {
- if (_p2[0] > _p1[0]) {
- return (_p2[1] > _p1[1]) ? 2 : 1;
- }
- else if (_p2[0] == _p1[0]) {
- return _p2[1] > _p1[1] ? 2 : 1;
- }
- else {
- return (_p2[1] > _p1[1]) ? 3 : 4;
- }
- });
- },
-
- _theta = Biltong.theta = function(p1, p2) {
- return _pointHelper(p1, p2, function(_p1, _p2) {
- var m = _gradient(_p1, _p2),
- t = Math.atan(m),
- s = _quadrant(_p1, _p2);
- if ((s == 4 || s== 3)) t += Math.PI;
- if (t < 0) t += (2 * Math.PI);
-
- return t;
- });
- },
-
- _intersects = Biltong.intersects = function(r1, r2) {
- var x1 = r1.x, x2 = r1.x + r1.w, y1 = r1.y, y2 = r1.y + r1.h,
- a1 = r2.x, a2 = r2.x + r2.w, b1 = r2.y, b2 = r2.y + r2.h;
-
- return ( (x1 <= a1 && a1 <= x2) && (y1 <= b1 && b1 <= y2) ) ||
- ( (x1 <= a2 && a2 <= x2) && (y1 <= b1 && b1 <= y2) ) ||
- ( (x1 <= a1 && a1 <= x2) && (y1 <= b2 && b2 <= y2) ) ||
- ( (x1 <= a2 && a1 <= x2) && (y1 <= b2 && b2 <= y2) ) ||
- ( (a1 <= x1 && x1 <= a2) && (b1 <= y1 && y1 <= b2) ) ||
- ( (a1 <= x2 && x2 <= a2) && (b1 <= y1 && y1 <= b2) ) ||
- ( (a1 <= x1 && x1 <= a2) && (b1 <= y2 && y2 <= b2) ) ||
- ( (a1 <= x2 && x1 <= a2) && (b1 <= y2 && y2 <= b2) );
- },
-
- _encloses = Biltong.encloses = function(r1, r2, allowSharedEdges) {
- var x1 = r1.x, x2 = r1.x + r1.w, y1 = r1.y, y2 = r1.y + r1.h,
- a1 = r2.x, a2 = r2.x + r2.w, b1 = r2.y, b2 = r2.y + r2.h,
- c = function(v1, v2, v3, v4) { return allowSharedEdges ? v1 <= v2 && v3>= v4 : v1 < v2 && v3 > v4; };
-
- return c(x1,a1,x2,a2) && c(y1,b1,y2,b2);
- },
- _segmentMultipliers = [null, [1, -1], [1, 1], [-1, 1], [-1, -1] ],
- _inverseSegmentMultipliers = [null, [-1, -1], [-1, 1], [1, 1], [1, -1] ],
-
- _pointOnLine = Biltong.pointOnLine = function(fromPoint, toPoint, distance) {
- var m = _gradient(fromPoint, toPoint),
- s = _quadrant(fromPoint, toPoint),
- segmentMultiplier = distance > 0 ? _segmentMultipliers[s] : _inverseSegmentMultipliers[s],
- theta = Math.atan(m),
- y = Math.abs(distance * Math.sin(theta)) * segmentMultiplier[1],
- x = Math.abs(distance * Math.cos(theta)) * segmentMultiplier[0];
- return { x:fromPoint.x + x, y:fromPoint.y + y };
- },
-
-
- _perpendicularLineTo = Biltong.perpendicularLineTo = function(fromPoint, toPoint, length) {
- var m = _gradient(fromPoint, toPoint),
- theta2 = Math.atan(-1 / m),
- y = length / 2 * Math.sin(theta2),
- x = length / 2 * Math.cos(theta2);
- return [{x:toPoint.x + x, y:toPoint.y + y}, {x:toPoint.x - x, y:toPoint.y - y}];
- };
- }).call(this);
- ;(function() {
- "use strict";
- var Sniff = {
- android:navigator.userAgent.toLowerCase().indexOf("android") > -1
- };
- var matchesSelector = function(el, selector, ctx) {
- ctx = ctx || el.parentNode;
- var possibles = ctx.querySelectorAll(selector);
- for (var i = 0; i < possibles.length; i++) {
- if (possibles[i] === el) {
- return true;
- }
- }
- return false;
- },
- _gel = function(el) { return typeof el == "string" ? document.getElementById(el) : el; },
- _t = function(e) { return e.srcElement || e.target; },
- _d = function(l, fn) {
- for (var i = 0, j = l.length; i < j; i++) {
- if (l[i] == fn) break;
- }
- if (i < l.length) l.splice(i, 1);
- },
- guid = 1,
-
-
-
-
-
- _store = function(obj, event, fn) {
- var g = guid++;
- obj.__ta = obj.__ta || {};
- obj.__ta[event] = obj.__ta[event] || {};
-
- obj.__ta[event][g] = fn;
-
- fn.__tauid = g;
- return g;
- },
- _unstore = function(obj, event, fn) {
- obj.__ta && obj.__ta[event] && delete obj.__ta[event][fn.__tauid];
-
- if (fn.__taExtra) {
- for (var i = 0; i < fn.__taExtra.length; i++) {
- _unbind(obj, fn.__taExtra[i][0], fn.__taExtra[i][1]);
- }
- fn.__taExtra.length = 0;
- }
-
- fn.__taUnstore && fn.__taUnstore();
- },
- _curryChildFilter = function(children, obj, fn, evt) {
- if (children == null) return fn;
- else {
- var c = children.split(","),
- _fn = function(e) {
- _fn.__tauid = fn.__tauid;
- var t = _t(e);
- for (var i = 0; i < c.length; i++) {
- if (matchesSelector(t, c[i], obj)) {
- fn.apply(t, arguments);
- }
- }
- };
- registerExtraFunction(fn, evt, _fn);
- return _fn;
- }
- },
-
-
-
-
- registerExtraFunction = function(fn, evt, newFn) {
- fn.__taExtra = fn.__taExtra || [];
- fn.__taExtra.push([evt, newFn]);
- },
- DefaultHandler = function(obj, evt, fn, children) {
-
-
-
-
-
-
- if (isTouchDevice && touchMap[evt]) {
- _bind(obj, touchMap[evt], _curryChildFilter(children, obj, fn, touchMap[evt]), fn);
- }
- else
- _bind(obj, evt, _curryChildFilter(children, obj, fn, evt), fn);
- },
- SmartClickHandler = function(obj, evt, fn, children) {
- if (obj.__taSmartClicks == null) {
- var down = function(e) { obj.__tad = _pageLocation(e); },
- up = function(e) { obj.__tau = _pageLocation(e); },
- click = function(e) {
- if (obj.__tad && obj.__tau && obj.__tad[0] === obj.__tau[0] && obj.__tad[1] === obj.__tau[1]) {
- for (var i = 0; i < obj.__taSmartClicks.length; i++)
- obj.__taSmartClicks[i].apply(_t(e), [ e ]);
- }
- };
- DefaultHandler(obj, "mousedown", down, children);
- DefaultHandler(obj, "mouseup", up, children);
- DefaultHandler(obj, "click", click, children);
- obj.__taSmartClicks = [];
- }
-
-
- obj.__taSmartClicks.push(fn);
-
- fn.__taUnstore = function() {
- _d(obj.__taSmartClicks, fn);
- };
- },
- _tapProfiles = {
- "tap":{touches:1, taps:1},
- "dbltap":{touches:1, taps:2},
- "contextmenu":{touches:2, taps:1}
- },
- TapHandler = function(clickThreshold, dblClickThreshold) {
- return function(obj, evt, fn, children) {
-
-
- if (evt == "contextmenu" && isMouseDevice)
- DefaultHandler(obj, evt, fn, children);
- else {
-
-
-
-
-
- if (obj.__taTapHandler == null) {
- var tt = obj.__taTapHandler = {
- tap:[],
- dbltap:[],
- contextmenu:[],
- down:false,
- taps:0,
- downSelectors:[]
- };
- var down = function(e) {
- var target = e.srcElement || e.target;
- for (var i = 0; i < tt.downSelectors.length; i++) {
- if (tt.downSelectors[i] == null || matchesSelector(target, tt.downSelectors[i], obj)) {
- tt.down = true;
- setTimeout(clearSingle, clickThreshold);
- setTimeout(clearDouble, dblClickThreshold);
- break;
- }
- }
- },
- up = function(e) {
- if (tt.down) {
- var target = e.srcElement || e.target;
- tt.taps++;
- var tc = _touchCount(e);
- for (var eventId in _tapProfiles) {
- var p = _tapProfiles[eventId];
- if (p.touches === tc && (p.taps === 1 || p.taps === tt.taps)) {
- for (var i = 0; i < tt[eventId].length; i++) {
- if (tt[eventId][i][1] == null || matchesSelector(target, tt[eventId][i][1], obj))
- tt[eventId][i][0].apply(_t(e), [ e ]);
- }
- }
- }
- }
- },
- clearSingle = function() {
- tt.down = false;
- },
- clearDouble = function() {
- tt.taps = 0;
- };
-
- DefaultHandler(obj, "mousedown", down);
- DefaultHandler(obj, "mouseup", up);
- }
-
- obj.__taTapHandler.downSelectors.push(children);
- obj.__taTapHandler[evt].push([fn, children]);
-
- fn.__taUnstore = function() {
- _d(obj.__taTapHandler[evt], fn);
- };
- }
- };
- },
- meeHelper = function(type, evt, obj, target) {
- for (var i in obj.__tamee[type]) {
- obj.__tamee[type][i].apply(target, [ evt ]);
- }
- },
- MouseEnterExitHandler = function() {
- var activeElements = [];
- return function(obj, evt, fn, children) {
- if (!obj.__tamee) {
-
-
- obj.__tamee = { over:false, mouseenter:[], mouseexit:[] };
-
- var over = function(e) {
- var t = _t(e);
- if ( (children== null && (t == obj && !obj.__tamee.over)) || (matchesSelector(t, children, obj) && (t.__tamee == null || !t.__tamee.over)) ) {
- meeHelper("mouseenter", e, obj, t);
- t.__tamee = t.__tamee || {};
- t.__tamee.over = true;
- activeElements.push(t);
- }
- },
- out = function(e) {
- var t = _t(e);
-
-
- for (var i = 0; i < activeElements.length; i++) {
- if (t == activeElements[i] && !matchesSelector((e.relatedTarget || e.toElement), "*", t)) {
- t.__tamee.over = false;
- activeElements.splice(i, 1);
- meeHelper("mouseexit", e, obj, t);
- }
- }
- };
-
- _bind(obj, "mouseover", _curryChildFilter(children, obj, over, "mouseover"), over);
- _bind(obj, "mouseout", _curryChildFilter(children, obj, out, "mouseout"), out);
- }
- fn.__taUnstore = function() {
- delete obj.__tamee[evt][fn.__tauid];
- };
- _store(obj, evt, fn);
- obj.__tamee[evt][fn.__tauid] = fn;
- };
- },
- isTouchDevice = "ontouchstart" in document.documentElement,
- isMouseDevice = "onmousedown" in document.documentElement,
- touchMap = { "mousedown":"touchstart", "mouseup":"touchend", "mousemove":"touchmove" },
- touchstart="touchstart",touchend="touchend",touchmove="touchmove",
- ta_down = "__MottleDown", ta_up = "__MottleUp",
- ta_context_down = "__MottleContextDown", ta_context_up = "__MottleContextUp",
- iev = (function() {
- var rv = -1;
- if (navigator.appName == 'Microsoft Internet Explorer') {
- var ua = navigator.userAgent,
- re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
- if (re.exec(ua) != null)
- rv = parseFloat(RegExp.$1);
- }
- return rv;
- })(),
- isIELT9 = iev > -1 && iev < 9,
- _genLoc = function(e, prefix) {
- if (e == null) return [ 0, 0 ];
- var ts = _touches(e), t = _getTouch(ts, 0);
- return [t[prefix + "X"], t[prefix + "Y"]];
- },
- _pageLocation = function(e) {
- if (e == null) return [ 0, 0 ];
- if (isIELT9) {
- return [ e.clientX + document.documentElement.scrollLeft, e.clientY + document.documentElement.scrollTop ];
- }
- else {
- return _genLoc(e, "page");
- }
- },
- _screenLocation = function(e) {
- return _genLoc(e, "screen");
- },
- _clientLocation = function(e) {
- return _genLoc(e, "client");
- },
- _getTouch = function(touches, idx) { return touches.item ? touches.item(idx) : touches[idx]; },
- _touches = function(e) {
- return e.touches && e.touches.length > 0 ? e.touches :
- e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches :
- e.targetTouches && e.targetTouches.length > 0 ? e.targetTouches :
- [ e ];
- },
- _touchCount = function(e) { return _touches(e).length; },
-
- _bind = function( obj, type, fn, originalFn) {
- _store(obj, type, fn);
- originalFn.__tauid = fn.__tauid;
- if (obj.addEventListener)
- obj.addEventListener( type, fn, false );
- else if (obj.attachEvent) {
- var key = type + fn.__tauid;
- obj["e" + key] = fn;
-
- obj[key] = function() {
- obj["e"+key] && obj["e"+key]( window.event );
- };
- obj.attachEvent( "on"+type, obj[key] );
- }
- },
- _unbind = function( obj, type, fn) {
- if (fn == null) return;
- _each(obj, function() {
- var _el = _gel(this);
- _unstore(_el, type, fn);
-
- if (fn.__tauid != null) {
- if (_el.removeEventListener)
- _el.removeEventListener( type, fn, false );
- else if (this.detachEvent) {
- var key = type + fn.__tauid;
- _el[key] && _el.detachEvent( "on"+type, _el[key] );
- _el[key] = null;
- _el["e"+key] = null;
- }
- }
- });
- },
- _devNull = function() {},
- _each = function(obj, fn) {
- if (obj == null) return;
-
-
-
- obj = (typeof obj !== "string") && (obj.tagName == null && obj.length != null) ? obj : typeof obj === "string" ? document.querySelectorAll(obj) : [ obj ];
- for (var i = 0; i < obj.length; i++)
- fn.apply(obj[i]);
- };
-
- this.Mottle = function(params) {
- params = params || {};
- var self = this,
- clickThreshold = params.clickThreshold || 150,
- dblClickThreshold = params.dblClickThreshold || 350,
- mouseEnterExitHandler = new MouseEnterExitHandler(),
- tapHandler = new TapHandler(clickThreshold, dblClickThreshold),
- _smartClicks = params.smartClicks,
- _doBind = function(obj, evt, fn, children) {
- if (fn == null) return;
- _each(obj, function() {
- var _el = _gel(this);
- if (_smartClicks && evt === "click")
- SmartClickHandler(_el, evt, fn, children);
- else if (evt === "tap" || evt === "dbltap" || evt === "contextmenu") {
- tapHandler(_el, evt, fn, children);
- }
- else if (evt === "mouseenter" || evt == "mouseexit")
- mouseEnterExitHandler(_el, evt, fn, children);
- else
- DefaultHandler(_el, evt, fn, children);
- });
- };
-
- this.remove = function(el) {
- _each(el, function() {
- var _el = _gel(this);
- if (_el.__ta) {
- for (var evt in _el.__ta) {
- for (var h in _el.__ta[evt]) {
- _unbind(_el, evt, _el.__ta[evt][h]);
- }
- }
- }
- _el.parentNode && _el.parentNode.removeChild(_el);
- });
- return this;
- };
-
- this.on = function(el, event, children, fn) {
- var _el = arguments[0],
- _c = arguments.length == 4 ? arguments[2] : null,
- _e = arguments[1],
- _f = arguments[arguments.length - 1];
- _doBind(_el, _e, _f, _c);
- return this;
- };
-
- this.off = function(el, evt, fn) {
- _unbind(el, evt, fn);
- return this;
- };
-
- this.trigger = function(el, event, originalEvent, payload) {
- var eventToBind = (isTouchDevice && touchMap[event]) ? touchMap[event] : event;
- var pl = _pageLocation(originalEvent), sl = _screenLocation(originalEvent), cl = _clientLocation(originalEvent);
- _each(el, function() {
- var _el = _gel(this), evt;
- originalEvent = originalEvent || {
- screenX:sl[0],
- screenY:sl[1],
- clientX:cl[0],
- clientY:cl[1]
- };
- var _decorate = function(_evt) {
- if (payload) _evt.payload = payload;
- };
- var eventGenerators = {
- "TouchEvent":function(evt) {
- var t = document.createTouch(window, _el, 0, pl[0], pl[1],
- sl[0], sl[1],
- cl[0], cl[1],
- 0,0,0,0);
- evt.initTouchEvent(eventToBind, true, true, window, 0,
- sl[0], sl[1],
- cl[0], cl[1],
- false, false, false, false, document.createTouchList(t));
- },
- "MouseEvents":function(evt) {
- evt.initMouseEvent(eventToBind, true, true, window, 0,
- sl[0], sl[1],
- cl[0], cl[1],
- false, false, false, false, 1, _el);
-
- if (Sniff.android) {
-
- var t = document.createTouch(window, _el, 0, pl[0], pl[1],
- sl[0], sl[1],
- cl[0], cl[1],
- 0,0,0,0);
- evt.touches = evt.targetTouches = evt.changedTouches = document.createTouchList(t);
- }
- }
- };
- if (document.createEvent) {
- var ite = (isTouchDevice && touchMap[event] && !Sniff.android), evtName = ite ? "TouchEvent" : "MouseEvents";
- evt = document.createEvent(evtName);
- eventGenerators[evtName](evt);
- _decorate(evt);
- _el.dispatchEvent(evt);
- }
- else if (document.createEventObject) {
- evt = document.createEventObject();
- evt.eventType = evt.eventName = eventToBind;
- evt.screenX = sl[0];
- evt.screenY = sl[1];
- evt.clientX = cl[0];
- evt.clientY = cl[1];
- _decorate(evt);
- _el.fireEvent('on' + eventToBind, evt);
- }
- });
- return this;
- }
- };
-
- Mottle.consume = function(e, doNotPreventDefault) {
- if (e.stopPropagation)
- e.stopPropagation();
- else
- e.returnValue = false;
- if (!doNotPreventDefault && e.preventDefault)
- e.preventDefault();
- };
-
- Mottle.pageLocation = _pageLocation;
- }).call(this);
- ;(function() {
- var _isa = function(a) { return Object.prototype.toString.call(a) === "[object Array]"; },
- _isnum = function(n) { return Object.prototype.toString.call(n) === "[object Number]"; },
- _iss = function(s) { return typeof s === "string"; },
- _isb = function(s) { return typeof s === "boolean"; },
- _isnull = function(s) { return s == null; },
- _iso = function(o) { return o == null ? false : Object.prototype.toString.call(o) === "[object Object]"; },
- _isd = function(o) { return Object.prototype.toString.call(o) === "[object Date]"; },
- _isf = function(o) { return Object.prototype.toString.call(o) === "[object Function]"; },
- _ise = function(o) {
- for (var i in o) { if (o.hasOwnProperty(i)) return false; }
- return true;
- },
- pointHelper = function(p1, p2, fn) {
- p1 = _isa(p1) ? p1 : [p1.x, p1.y];
- p2 = _isa(p2) ? p2 : [p2.x, p2.y];
- return fn(p1, p2);
- };
- var root = this;
- var exports = root.jsPlumbUtil = {
- isArray : _isa,
- isString : _iss,
- isBoolean: _isb,
- isNull : _isnull,
- isObject : _iso,
- isDate : _isd,
- isFunction: _isf,
- isEmpty:_ise,
- isNumber:_isnum,
- clone : function(a) {
- if (_iss(a)) return "" + a;
- else if (_isb(a)) return !!a;
- else if (_isd(a)) return new Date(a.getTime());
- else if (_isf(a)) return a;
- else if (_isa(a)) {
- var b = [];
- for (var i = 0; i < a.length; i++)
- b.push(this.clone(a[i]));
- return b;
- }
- else if (_iso(a)) {
- var c = {};
- for (var j in a)
- c[j] = this.clone(a[j]);
- return c;
- }
- else return a;
- },
- merge : function(a, b, collations) {
-
- var cMap = {}, ar, i;
- collations = collations || [];
- for (i = 0; i < collations.length; i++)
- cMap[collations[i]] = true;
- var c = this.clone(a);
- for (i in b) {
- if (c[i] == null)
- c[i] = b[i];
- else if (_iss(b[i]) || _isb(b[i])) {
- if (!cMap[i]) c[i] = b[i];
- else {
- ar = [];
-
- ar.push.apply(ar, _isa(c[i]) ? c[i] : [ c[i] ] );
- ar.push.apply(ar, _isa(b[i]) ? b[i] : [ b[i] ] );
- c[i] = ar;
- }
- }
- else {
- if (_isa(b[i])) {
- ar = [];
-
- if (_isa(c[i])) ar.push.apply(ar, c[i]);
- ar.push.apply(ar, b[i]);
- c[i] = ar;
- }
- else if(_iso(b[i])) {
-
- if (!_iso(c[i]))
- c[i] = {};
- for (var j in b[i])
- c[i][j] = b[i][j];
- }
- }
- }
- return c;
- },
- replace:function(inObj, path, value) {
- if (inObj == null) return;
- var q = inObj, t = q;
- path.replace(/([^\.])+/g, function(term, lc, pos, str) {
- var array = term.match(/([^\[0-9]+){1}(\[)([0-9+])/),
- last = pos + term.length >= str.length,
- _getArray = function() {
- return t[array[1]] || (function() { t[array[1]] = []; return t[array[1]]; })();
- };
- if (last) {
-
- if (array)
- _getArray()[array[3]] = value;
- else
- t[term] = value;
- }
- else {
-
- if (array) {
- var a = _getArray();
- t = a[array[3]] || (function() { a[array[3]] = {}; return a[array[3]]; })();
- }
- else
- t = t[term] || (function() { t[term] = {}; return t[term]; })();
- }
- });
- return inObj;
- },
-
-
-
-
- functionChain : function(successValue, failValue, fns) {
- for (var i = 0; i < fns.length; i++) {
- var o = fns[i][0][fns[i][1]].apply(fns[i][0], fns[i][2]);
- if (o === failValue) {
- return o;
- }
- }
- return successValue;
- },
-
- populate : function(model, values) {
-
- var getValue = function(fromString) {
- var matches = fromString.match(/(\${.*?})/g);
- if (matches != null) {
- for (var i = 0; i < matches.length; i++) {
- var val = values[matches[i].substring(2, matches[i].length - 1)] || "";
- if (val != null) {
- fromString = fromString.replace(matches[i], val);
- }
- }
- }
- return fromString;
- },
-
- _one = function(d) {
- if (d != null) {
- if (_iss(d)) {
- return getValue(d);
- }
- else if (_isa(d)) {
- var r = [];
- for (var i = 0; i < d.length; i++)
- r.push(_one(d[i]));
- return r;
- }
- else if (_iso(d)) {
- var s = {};
- for (var j in d) {
- s[j] = _one(d[j]);
- }
- return s;
- }
- else {
- return d;
- }
- }
- };
- return _one(model);
- },
- convertStyle : function(s, ignoreAlpha) {
-
- if ("transparent" === s) return s;
- var o = s,
- pad = function(n) { return n.length == 1 ? "0" + n : n; },
- hex = function(k) { return pad(Number(k).toString(16)); },
- pattern = /(rgb[a]?\()(.*)(\))/;
- if (s.match(pattern)) {
- var parts = s.match(pattern)[2].split(",");
- o = "#" + hex(parts[0]) + hex(parts[1]) + hex(parts[2]);
- if (!ignoreAlpha && parts.length == 4)
- o = o + hex(parts[3]);
- }
- return o;
- },
- findWithFunction : function(a, f) {
- if (a)
- for (var i = 0; i < a.length; i++) if (f(a[i])) return i;
- return -1;
- },
- indexOf : function(l, v) {
- return l.indexOf ? l.indexOf(v) : exports.findWithFunction(l, function(_v) { return _v == v; });
- },
- removeWithFunction : function(a, f) {
- var idx = exports.findWithFunction(a, f);
- if (idx > -1) a.splice(idx, 1);
- return idx != -1;
- },
- remove : function(l, v) {
- var idx = exports.indexOf(l, v);
- if (idx > -1) l.splice(idx, 1);
- return idx != -1;
- },
-
- addWithFunction : function(list, item, hashFunction) {
- if (exports.findWithFunction(list, hashFunction) == -1) list.push(item);
- },
- addToList : function(map, key, value, insertAtStart) {
- var l = map[key];
- if (l == null) {
- l = [];
- map[key] = l;
- }
- l[insertAtStart ? "unshift" : "push"](value);
- return l;
- },
-
-
-
-
- extend : function(child, parent, _protoFn) {
- var i;
- parent = _isa(parent) ? parent : [ parent ];
- for (i = 0; i < parent.length; i++) {
- for (var j in parent[i].prototype) {
- if(parent[i].prototype.hasOwnProperty(j)) {
- child.prototype[j] = parent[i].prototype[j];
- }
- }
- }
- var _makeFn = function(name, protoFn) {
- return function() {
- for (i = 0; i < parent.length; i++) {
- if (parent[i].prototype[name])
- parent[i].prototype[name].apply(this, arguments);
- }
- return protoFn.apply(this, arguments);
- };
- };
- var _oneSet = function(fns) {
- for (var k in fns) {
- child.prototype[k] = _makeFn(k, fns[k]);
- }
- };
- if (arguments.length > 2) {
- for (i = 2; i < arguments.length; i++)
- _oneSet(arguments[i]);
- }
- return child;
- },
- uuid : function() {
- return ('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- }));
- },
- logEnabled : true,
- log : function() {
- if (exports.logEnabled && typeof console != "undefined") {
- try {
- var msg = arguments[arguments.length - 1];
- console.log(msg);
- }
- catch (e) {}
- }
- },
-
- wrap : function(wrappedFunction, newFunction, returnOnThisValue) {
- wrappedFunction = wrappedFunction || function() { };
- newFunction = newFunction || function() { };
- return function() {
- var r = null;
- try {
- r = newFunction.apply(this, arguments);
- } catch (e) {
- exports.log("jsPlumb function failed : " + e);
- }
- if (returnOnThisValue == null || (r !== returnOnThisValue)) {
- try {
- r = wrappedFunction.apply(this, arguments);
- } catch (e) {
- exports.log("wrapped function failed : " + e);
- }
- }
- return r;
- };
- }
- };
- exports.EventGenerator = function() {
- var _listeners = {},
- eventsSuspended = false,
-
- eventsToDieOn = { "ready":true };
- this.bind = function(event, listener, insertAtStart) {
- exports.addToList(_listeners, event, listener, insertAtStart);
- return this;
- };
- this.fire = function(event, value, originalEvent) {
- if (!eventsSuspended && _listeners[event]) {
- var l = _listeners[event].length, i = 0, _gone = false, ret = null;
- if (!this.shouldFireEvent || this.shouldFireEvent(event, value, originalEvent)) {
- while (!_gone && i < l && ret !== false) {
-
-
- if (eventsToDieOn[event])
- _listeners[event][i].apply(this, [ value, originalEvent]);
- else {
- try {
- ret = _listeners[event][i].apply(this, [ value, originalEvent ]);
- } catch (e) {
- exports.log("jsPlumb: fire failed for event " + event + " : " + e);
- }
- }
- i++;
- if (_listeners == null || _listeners[event] == null)
- _gone = true;
- }
- }
- }
- return this;
- };
- this.unbind = function(event) {
- if (event)
- delete _listeners[event];
- else {
- _listeners = {};
- }
- return this;
- };
- this.getListener = function(forEvent) { return _listeners[forEvent]; };
- this.setSuspendEvents = function(val) { eventsSuspended = val; };
- this.isSuspendEvents = function() { return eventsSuspended; };
- this.cleanupListeners = function() {
- for (var i in _listeners) {
- _listeners[i] = null;
- }
- };
- };
- exports.EventGenerator.prototype = {
- cleanup:function() {
- this.cleanupListeners();
- }
- };
-
-
- if (!Function.prototype.bind) {
- Function.prototype.bind = function (oThis) {
- if (typeof this !== "function") {
-
- throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
- }
- var aArgs = Array.prototype.slice.call(arguments, 1),
- fToBind = this,
- fNOP = function () {},
- fBound = function () {
- return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
- aArgs.concat(Array.prototype.slice.call(arguments)));
- };
- fNOP.prototype = this.prototype;
- fBound.prototype = new fNOP();
- return fBound;
- };
- }
- }).call(this);
- ;(function() {
- "use strict";
- var root = this;
- var exports = root.jsPlumbUtil;
- exports.ieVersion = /MSIE\s([\d.]+)/.test(navigator.userAgent) ? (new Number(RegExp.$1)) : -1;
- exports.oldIE = exports.ieVersion > -1 && exports.ieVersion < 9;
- exports.matchesSelector = function(el, selector, ctx) {
- ctx = ctx || el.parentNode;
- var possibles = ctx.querySelectorAll(selector);
- for (var i = 0; i < possibles.length; i++) {
- if (possibles[i] === el)
- return true;
- }
- return false;
- };
- exports.consume = function(e, doNotPreventDefault) {
- if (e.stopPropagation)
- e.stopPropagation();
- else
- e.returnValue = false;
- if (!doNotPreventDefault && e.preventDefault)
- e.preventDefault();
- };
-
- exports.sizeElement = function(el, x, y, w, h) {
- if (el) {
- el.style.height = h + "px";
- el.height = h;
- el.style.width = w + "px";
- el.width = w;
- el.style.left = x + "px";
- el.style.top = y + "px";
- }
- };
- }).call(this);
- ;(function() {
- var root = this;
- var svgAvailable = !!window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"),
- vmlAvailable = function() {
- if (vmlAvailable.vml === undefined) {
- var a = document.body.appendChild(document.createElement('div'));
- a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
- var b = a.firstChild;
- if (b != null && b.style != null) {
- b.style.behavior = "url(#default#VML)";
- vmlAvailable.vml = b ? typeof b.adj == "object": true;
- }
- else
- vmlAvailable.vml = false;
- a.parentNode.removeChild(a);
- }
- return vmlAvailable.vml;
- },
-
-
- iev = (function() {
- var rv = -1;
- if (navigator.appName == 'Microsoft Internet Explorer') {
- var ua = navigator.userAgent,
- re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
- if (re.exec(ua) != null)
- rv = parseFloat(RegExp.$1);
- }
- return rv;
- })(),
- isIELT9 = iev > -1 && iev < 9,
- _genLoc = function(e, prefix) {
- if (e == null) return [ 0, 0 ];
- var ts = _touches(e), t = _getTouch(ts, 0);
- return [t[prefix + "X"], t[prefix + "Y"]];
- },
- _pageLocation = function(e) {
- if (e == null) return [ 0, 0 ];
- if (isIELT9) {
- return [ e.clientX + document.documentElement.scrollLeft, e.clientY + document.documentElement.scrollTop ];
- }
- else {
- return _genLoc(e, "page");
- }
- },
- _screenLocation = function(e) {
- return _genLoc(e, "screen");
- },
- _clientLocation = function(e) {
- return _genLoc(e, "client");
- },
- _getTouch = function(touches, idx) { return touches.item ? touches.item(idx) : touches[idx]; },
- _touches = function(e) {
- return e.touches && e.touches.length > 0 ? e.touches :
- e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches :
- e.targetTouches && e.targetTouches.length > 0 ? e.targetTouches :
- [ e ];
- };
-
- var DragManager = function(_currentInstance) {
- var _draggables = {}, _dlist = [], _delements = {}, _elementsWithEndpoints = {},
-
- _draggablesForElements = {};
-
- this.register = function(el) {
- var id = _currentInstance.getId(el),
- parentOffset = jsPlumbAdapter.getOffset(el, _currentInstance);
- if (!_draggables[id]) {
- _draggables[id] = el;
- _dlist.push(el);
- _delements[id] = {};
- }
-
- var _oneLevel = function(p, startOffset) {
- if (p) {
- for (var i = 0; i < p.childNodes.length; i++) {
- if (p.childNodes[i].nodeType != 3 && p.childNodes[i].nodeType != 8) {
- var cEl = jsPlumb.getElementObject(p.childNodes[i]),
- cid = _currentInstance.getId(p.childNodes[i], null, true);
- if (cid && _elementsWithEndpoints[cid] && _elementsWithEndpoints[cid] > 0) {
- var cOff = jsPlumbAdapter.getOffset(cEl, _currentInstance);
- _delements[id][cid] = {
- id:cid,
- offset:{
- left:cOff.left - parentOffset.left,
- top:cOff.top - parentOffset.top
- }
- };
- _draggablesForElements[cid] = id;
- }
- _oneLevel(p.childNodes[i]);
- }
- }
- }
- };
- _oneLevel(el);
- };
-
- this.updateOffsets = function(elId) {
- if (elId != null) {
- var domEl = jsPlumb.getDOMElement(elId),
- id = _currentInstance.getId(domEl),
- children = _delements[id],
- parentOffset = jsPlumbAdapter.getOffset(domEl, _currentInstance);
- if (children) {
- for (var i in children) {
- var cel = jsPlumb.getElementObject(i),
- cOff = jsPlumbAdapter.getOffset(cel, _currentInstance);
- _delements[id][i] = {
- id:i,
- offset:{
- left:cOff.left - parentOffset.left,
- top:cOff.top - parentOffset.top
- }
- };
- _draggablesForElements[i] = id;
- }
- }
- }
- };
-
- this.endpointAdded = function(el, id) {
- id = id || _currentInstance.getId(el);
- var b = document.body,
- p = el.parentNode;
- _elementsWithEndpoints[id] = _elementsWithEndpoints[id] ? _elementsWithEndpoints[id] + 1 : 1;
- while (p != null && p != b) {
- var pid = _currentInstance.getId(p, null, true);
- if (pid && _draggables[pid]) {
- var pLoc = jsPlumbAdapter.getOffset(p, _currentInstance);
- if (_delements[pid][id] == null) {
- var cLoc = jsPlumbAdapter.getOffset(el, _currentInstance);
- _delements[pid][id] = {
- id:id,
- offset:{
- left:cLoc.left - pLoc.left,
- top:cLoc.top - pLoc.top
- }
- };
- _draggablesForElements[id] = pid;
- }
- break;
- }
- p = p.parentNode;
- }
- };
- this.endpointDeleted = function(endpoint) {
- if (_elementsWithEndpoints[endpoint.elementId]) {
- _elementsWithEndpoints[endpoint.elementId]--;
- if (_elementsWithEndpoints[endpoint.elementId] <= 0) {
- for (var i in _delements) {
- if (_delements[i]) {
- delete _delements[i][endpoint.elementId];
- delete _draggablesForElements[endpoint.elementId];
- }
- }
- }
- }
- };
- this.changeId = function(oldId, newId) {
- _delements[newId] = _delements[oldId];
- _delements[oldId] = {};
- _draggablesForElements[newId] = _draggablesForElements[oldId];
- _draggablesForElements[oldId] = null;
- };
- this.getElementsForDraggable = function(id) {
- return _delements[id];
- };
- this.elementRemoved = function(elementId) {
- var elId = _draggablesForElements[elementId];
- if (elId) {
- delete _delements[elId][elementId];
- delete _draggablesForElements[elementId];
- }
- };
- this.reset = function() {
- _draggables = {};
- _dlist = [];
- _delements = {};
- _elementsWithEndpoints = {};
- };
-
-
-
-
- this.dragEnded = function(el) {
- var id = _currentInstance.getId(el),
- ancestor = _draggablesForElements[id];
- if (ancestor) this.updateOffsets(ancestor);
- };
- this.setParent = function(el, elId, p, pId) {
- var current = _draggablesForElements[elId];
- if (current) {
- if (!_delements[pId])
- _delements[pId] = {};
- _delements[pId][elId] = _delements[current][elId];
- delete _delements[current][elId];
- var pLoc = jsPlumbAdapter.getOffset(p, _currentInstance),
- cLoc = jsPlumbAdapter.getOffset(el, _currentInstance);
- _delements[pId][elId].offset = {
- left:cLoc.left - pLoc.left,
- top:cLoc.top - pLoc.top
- };
- _draggablesForElements[elId] = pId;
- }
- };
- this.getDragAncestor = function(el) {
- var de = jsPlumb.getDOMElement(el),
- id = _currentInstance.getId(de),
- aid = _draggablesForElements[id];
- if (aid)
- return jsPlumb.getDOMElement(aid);
- else
- return null;
- };
- };
-
- if (!window.console)
- window.console = { time:function(){}, timeEnd:function(){}, group:function(){}, groupEnd:function(){}, log:function(){} };
-
- var trim = function(str) {
- return str == null ? null : (str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''));
- },
- _setClassName = function(el, cn) {
- cn = trim(cn);
- if (typeof el.className.baseVal != "undefined")
- el.className.baseVal = cn;
- else
- el.className = cn;
- },
- _getClassName = function(el) {
- return (typeof el.className.baseVal == "undefined") ? el.className : el.className.baseVal;
- },
- _classManip = function(el, add, clazz) {
-
- var classesToAddOrRemove = jsPlumbUtil.isArray(clazz) ? clazz : clazz.split(/\s+/),
- className = _getClassName(el),
- curClasses = className.split(/\s+/);
- for (var i = 0; i < classesToAddOrRemove.length; i++) {
- if (add) {
- if (jsPlumbUtil.indexOf(curClasses, classesToAddOrRemove[i]) == -1)
- curClasses.push(classesToAddOrRemove[i]);
- }
- else {
- var idx = jsPlumbUtil.indexOf(curClasses, classesToAddOrRemove[i]);
- if (idx != -1)
- curClasses.splice(idx, 1);
- }
- }
- _setClassName(el, curClasses.join(" "));
- },
- _classManipNew = function(el, classesToAdd, classesToRemove) {
-
- classesToAdd = classesToAdd == null ? [] : jsPlumbUtil.isArray(classesToAdd) ? classesToAdd : classesToAdd.split(/\s+/);
- classesToRemove= classesToRemove== null ? [] : jsPlumbUtil.isArray(classesToRemove) ? classesToRemove: classesToRemove.split(/\s+/);
- var className = _getClassName(el),
- curClasses = className.split(/\s+/);
- var _oneSet = function(add, classes) {
- for (var i = 0; i < classes.length; i++) {
- if (add) {
- if (jsPlumbUtil.indexOf(curClasses, classes[i]) == -1)
- curClasses.push(classes[i]);
- }
- else {
- var idx = jsPlumbUtil.indexOf(curClasses, classes[i]);
- if (idx != -1)
- curClasses.splice(idx, 1);
- }
- }
- };
- _oneSet(true, classesToAdd);
- _oneSet(false, classesToRemove);
- _setClassName(el, curClasses.join(" "));
- },
- _each = function(spec, fn) {
- if (spec == null) return;
- if (typeof spec === "string")
- fn(jsPlumb.getDOMElement(spec));
- else if (spec.length != null) {
- for (var i = 0; i < spec.length; i++)
- fn(jsPlumb.getDOMElement(spec[i]));
- }
- else
- fn(spec);
- };
- window.jsPlumbAdapter = {
- headless:false,
- pageLocation:_pageLocation,
- screenLocation:_screenLocation,
- clientLocation:_clientLocation,
- getAttribute:function(el, attName) {
- return el.getAttribute(attName);
- },
- setAttribute:function(el, a, v) {
- el.setAttribute(a, v);
- },
- appendToRoot : function(node) {
- document.body.appendChild(node);
- },
- getRenderModes : function() {
- return [ "svg", "vml" ];
- },
- isRenderModeAvailable : function(m) {
- return {
- "svg":svgAvailable,
- "vml":vmlAvailable()
- }[m];
- },
- getDragManager : function(_jsPlumb) {
- return new DragManager(_jsPlumb);
- },
- setRenderMode : function(mode) {
- var renderMode;
- if (mode) {
- mode = mode.toLowerCase();
- var svgAvailable = this.isRenderModeAvailable("svg"),
- vmlAvailable = this.isRenderModeAvailable("vml");
-
- if (mode === "svg") {
- if (svgAvailable) renderMode = "svg";
- else if (vmlAvailable) renderMode = "vml";
- }
- else if (vmlAvailable) renderMode = "vml";
- }
- return renderMode;
- },
- addClass:function(el, clazz) {
- _each(el, function(e) {
- _classManipNew(e, clazz);
- });
- },
- hasClass:function(el, clazz) {
- el = jsPlumb.getDOMElement(el);
- if (el.classList) return el.classList.contains(clazz);
- else {
- return _getClassName(el).indexOf(clazz) != -1;
- }
- },
- removeClass:function(el, clazz) {
- _each(el, function(e) {
- _classManipNew(e, null, clazz);
- });
- },
- updateClasses:function(el, toAdd, toRemove) {
- _each(el, function(e) {
- _classManipNew(e, toAdd, toRemove);
- });
- },
- setClass:function(el, clazz) {
- _each(el, function(e) {
- _setClassName(e, clazz);
- });
- },
- setPosition:function(el, p) {
- el.style.left = p.left + "px";
- el.style.top = p.top + "px";
- },
- getPosition:function(el) {
- var _one = function(prop) {
- var v = el.style[prop];
- return v ? v.substring(0, v.length - 2) : 0;
- };
- return {
- left:_one("left"),
- top:_one("top")
- };
- },
- getOffset:function(el, _instance, relativeToRoot) {
- el = jsPlumb.getDOMElement(el);
- var container = _instance.getContainer();
- var l = el.offsetLeft, t = el.offsetTop, op = (relativeToRoot || (container != null && el.offsetParent != container)) ? el.offsetParent : null;
- while (op != null) {
- l += op.offsetLeft;
- t += op.offsetTop;
- op = relativeToRoot ? op.offsetParent :
- op.offsetParent == container ? null : op.offsetParent;
- }
- return {
- left:l, top:t
- };
- },
-
-
-
- getPositionOnElement:function(evt, el, zoom) {
- var box = typeof el.getBoundingClientRect !== "undefined" ? el.getBoundingClientRect() : { left:0, top:0, width:0, height:0 },
- body = document.body,
- docElem = document.documentElement,
- offPar = el.offsetParent,
- scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop,
- scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft,
- clientTop = docElem.clientTop || body.clientTop || 0,
- clientLeft = docElem.clientLeft || body.clientLeft || 0,
- pst = 0,
- psl = 0,
- top = box.top + scrollTop - clientTop + (pst * zoom),
- left = box.left + scrollLeft - clientLeft + (psl * zoom),
- cl = jsPlumbAdapter.pageLocation(evt),
- w = box.width || (el.offsetWidth * zoom),
- h = box.height || (el.offsetHeight * zoom),
- x = (cl[0] - left) / w,
- y = (cl[1] - top) / h;
- return [ x, y ];
- },
-
- getAbsolutePosition : function(el) {
- var _one = function(s) {
- var ss = el.style[s];
- if (ss) return parseFloat(ss.substring(0, ss.length - 2));
- };
- return [ _one("left"), _one("top") ];
- },
-
- setAbsolutePosition : function(el, xy, animateFrom, animateOptions) {
- if (animateFrom) {
- root.jsPlumb.animate(el, {
- left: "+=" + (xy[0] - animateFrom[0]),
- top: "+=" + (xy[1] - animateFrom[1])
- }, animateOptions);
- }
- else {
- el.style.left = xy[0] + "px";
- el.style.top = xy[1] + "px";
- }
- }
- };
- }).call(this);
- ;(function() {
-
- "use strict";
-
- var _ju = jsPlumbUtil,
- _getOffset = function(el, _instance, relativeToRoot) {
- return jsPlumbAdapter.getOffset(el, _instance, relativeToRoot);
- },
-
-
- _timestamp = function() { return "" + (new Date()).getTime(); },
-
-
-
- _updateHoverStyle = function(component) {
- if (component._jsPlumb.paintStyle && component._jsPlumb.hoverPaintStyle) {
- var mergedHoverStyle = {};
- jsPlumb.extend(mergedHoverStyle, component._jsPlumb.paintStyle);
- jsPlumb.extend(mergedHoverStyle, component._jsPlumb.hoverPaintStyle);
- delete component._jsPlumb.hoverPaintStyle;
-
- if (mergedHoverStyle.gradient && component._jsPlumb.paintStyle.fillStyle)
- delete mergedHoverStyle.gradient;
- component._jsPlumb.hoverPaintStyle = mergedHoverStyle;
- }
- },
-
- events = [ "click", "mouseover", "mouseout", "mousemove", "mousedown", "mouseup", "contextmenu", "touchmove" ],
- eventFilters = { "mouseout":"mouseleave", "mouseexit":"mouseleave" },
- _updateAttachedElements = function(component, state, timestamp, sourceElement) {
- var affectedElements = component.getAttachedElements();
- if (affectedElements) {
- for (var i = 0, j = affectedElements.length; i < j; i++) {
- if (!sourceElement || sourceElement != affectedElements[i])
- affectedElements[i].setHover(state, true, timestamp);
- }
- }
- },
- _splitType = function(t) { return t == null ? null : t.split(" "); },
- _applyTypes = function(component, params, doNotRepaint) {
- if (component.getDefaultType) {
- var td = component.getTypeDescriptor();
-
- var o = _ju.merge({}, component.getDefaultType());
- for (var i = 0, j = component._jsPlumb.types.length; i < j; i++)
- o = _ju.merge(o, component._jsPlumb.instance.getType(component._jsPlumb.types[i], td), [ "cssClass" ]);
-
- if (params) {
- o = _ju.populate(o, params);
- }
-
- component.applyType(o, doNotRepaint);
- if (!doNotRepaint) component.repaint();
- }
- },
- jsPlumbUIComponent = window.jsPlumbUIComponent = function(params) {
- jsPlumbUtil.EventGenerator.apply(this, arguments);
- var self = this,
- a = arguments,
- idPrefix = self.idPrefix,
- id = idPrefix + (new Date()).getTime();
- this._jsPlumb = {
- instance: params._jsPlumb,
- parameters:params.parameters || {},
- paintStyle:null,
- hoverPaintStyle:null,
- paintStyleInUse:null,
- hover:false,
- beforeDetach:params.beforeDetach,
- beforeDrop:params.beforeDrop,
- overlayPlacements : [],
- hoverClass: params.hoverClass || params._jsPlumb.Defaults.HoverClass,
- types:[]
- };
- this.getId = function() { return id; };
-
-
-
- if (params.events) {
- for (var i in params.events)
- self.bind(i, params.events[i]);
- }
-
-
-
-
-
-
- this.clone = function() {
- var o = {};
- this.constructor.apply(o, a);
- return o;
- }.bind(this);
-
-
-
- this.isDetachAllowed = function(connection) {
- var r = true;
- if (this._jsPlumb.beforeDetach) {
- try {
- r = this._jsPlumb.beforeDetach(connection);
- }
- catch (e) { _ju.log("jsPlumb: beforeDetach callback failed", e); }
- }
- return r;
- };
-
-
-
- this.isDropAllowed = function(sourceId, targetId, scope, connection, dropEndpoint, source, target) {
- var r = this._jsPlumb.instance.checkCondition("beforeDrop", {
- sourceId:sourceId,
- targetId:targetId,
- scope:scope,
- connection:connection,
- dropEndpoint:dropEndpoint,
- source:source, target:target
- });
- if (this._jsPlumb.beforeDrop) {
- try {
- r = this._jsPlumb.beforeDrop({
- sourceId:sourceId,
- targetId:targetId,
- scope:scope,
- connection:connection,
- dropEndpoint:dropEndpoint,
- source:source, target:target
- });
- }
- catch (e) { _ju.log("jsPlumb: beforeDrop callback failed", e); }
- }
- return r;
- };
- var boundListeners = [],
- bindAListener = function(obj, type, fn) {
- boundListeners.push([obj, type, fn]);
- obj.bind(type, fn);
- },
- domListeners = [];
-
-
-
- this.setListenerComponent = function(c) {
- for (var i = 0; i < domListeners.length; i++)
- domListeners[i][3] = c;
- };
-
- };
- var _removeTypeCssHelper = function(component, typeIndex) {
- var typeId = component._jsPlumb.types[typeIndex],
- type = component._jsPlumb.instance.getType(typeId, component.getTypeDescriptor());
- if (type != null) {
- if (type.cssClass && component.canvas)
- component._jsPlumb.instance.removeClass(component.canvas, type.cssClass);
- }
- };
- jsPlumbUtil.extend(jsPlumbUIComponent, jsPlumbUtil.EventGenerator, {
-
- getParameter : function(name) {
- return this._jsPlumb.parameters[name];
- },
-
- setParameter : function(name, value) {
- this._jsPlumb.parameters[name] = value;
- },
-
- getParameters : function() {
- return this._jsPlumb.parameters;
- },
-
- setParameters : function(p) {
- this._jsPlumb.parameters = p;
- },
-
- addClass : function(clazz) {
- jsPlumbAdapter.addClass(this.canvas, clazz);
- },
-
- removeClass : function(clazz) {
- jsPlumbAdapter.removeClass(this.canvas, clazz);
- },
- updateClasses : function(classesToAdd, classesToRemove) {
- jsPlumbAdapter.updateClasses(this.canvas, classesToAdd, classesToRemove);
- },
-
- setType : function(typeId, params, doNotRepaint) {
- this.clearTypes();
- this._jsPlumb.types = _splitType(typeId) || [];
- _applyTypes(this, params, doNotRepaint);
- },
-
- getType : function() {
- return this._jsPlumb.types;
- },
-
- reapplyTypes : function(params, doNotRepaint) {
- _applyTypes(this, params, doNotRepaint);
- },
-
- hasType : function(typeId) {
- return jsPlumbUtil.indexOf(this._jsPlumb.types, typeId) != -1;
- },
-
- addType : function(typeId, params, doNotRepaint) {
- var t = _splitType(typeId), _cont = false;
- if (t != null) {
- for (var i = 0, j = t.length; i < j; i++) {
- if (!this.hasType(t[i])) {
- this._jsPlumb.types.push(t[i]);
- _cont = true;
- }
- }
- if (_cont) _applyTypes(this, params, doNotRepaint);
- }
- },
-
- removeType : function(typeId, doNotRepaint) {
- var t = _splitType(typeId), _cont = false, _one = function(tt) {
- var idx = _ju.indexOf(this._jsPlumb.types, tt);
- if (idx != -1) {
-
- _removeTypeCssHelper(this, idx);
- this._jsPlumb.types.splice(idx, 1);
- return true;
- }
- return false;
- }.bind(this);
-
- if (t != null) {
- for (var i = 0,j = t.length; i < j; i++) {
- _cont = _one(t[i]) || _cont;
- }
- if (_cont) _applyTypes(this, null, doNotRepaint);
- }
- },
- clearTypes : function(doNotRepaint) {
- var i = this._jsPlumb.types.length;
- for (var j = 0; j < i; j++) {
- _removeTypeCssHelper(this, 0);
- this._jsPlumb.types.splice(0, 1);
- }
- _applyTypes(this, {}, doNotRepaint);
- },
-
- toggleType : function(typeId, params, doNotRepaint) {
- var t = _splitType(typeId);
- if (t != null) {
- for (var i = 0, j = t.length; i < j; i++) {
- var idx = jsPlumbUtil.indexOf(this._jsPlumb.types, t[i]);
- if (idx != -1) {
- _removeTypeCssHelper(this, idx);
- this._jsPlumb.types.splice(idx, 1);
- }
- else
- this._jsPlumb.types.push(t[i]);
- }
-
- _applyTypes(this, params, doNotRepaint);
- }
- },
- applyType : function(t, doNotRepaint) {
- this.setPaintStyle(t.paintStyle, doNotRepaint);
- this.setHoverPaintStyle(t.hoverPaintStyle, doNotRepaint);
- if (t.parameters){
- for (var i in t.parameters)
- this.setParameter(i, t.parameters[i]);
- }
- },
- setPaintStyle : function(style, doNotRepaint) {
- this._jsPlumb.paintStyle = style;
- this._jsPlumb.paintStyleInUse = this._jsPlumb.paintStyle;
- _updateHoverStyle(this);
- if (!doNotRepaint) this.repaint();
- },
- getPaintStyle : function() {
- return this._jsPlumb.paintStyle;
- },
- setHoverPaintStyle : function(style, doNotRepaint) {
-
- this._jsPlumb.hoverPaintStyle = style;
- _updateHoverStyle(this);
- if (!doNotRepaint) this.repaint();
- },
- getHoverPaintStyle : function() {
- return this._jsPlumb.hoverPaintStyle;
- },
- destroy:function() {
- this.cleanupListeners();
- this.clone = null;
- this._jsPlumb = null;
- },
-
- isHover : function() { return this._jsPlumb.hover; },
-
- setHover : function(hover, ignoreAttachedElements, timestamp) {
-
-
- if (this._jsPlumb && !this._jsPlumb.instance.currentlyDragging && !this._jsPlumb.instance.isHoverSuspended()) {
-
- this._jsPlumb.hover = hover;
-
- if (this.canvas != null) {
- if (this._jsPlumb.instance.hoverClass != null) {
- var method = hover ? "addClass" : "removeClass";
- this._jsPlumb.instance[method](this.canvas, this._jsPlumb.instance.hoverClass);
- }
- if (this._jsPlumb.hoverClass != null) {
- this._jsPlumb.instance[method](this.canvas, this._jsPlumb.hoverClass);
- }
- }
- if (this._jsPlumb.hoverPaintStyle != null) {
- this._jsPlumb.paintStyleInUse = hover ? this._jsPlumb.hoverPaintStyle : this._jsPlumb.paintStyle;
- if (!this._jsPlumb.instance.isSuspendDrawing()) {
- timestamp = timestamp || _timestamp();
- this.repaint({timestamp:timestamp, recalc:false});
- }
- }
-
-
- if (this.getAttachedElements && !ignoreAttachedElements)
- _updateAttachedElements(this, hover, _timestamp(), this);
- }
- }
- });
- var _internalLabelOverlayId = "__label",
-
- _getOverlayIndex = function(component, id) {
- var idx = -1;
- for (var i = 0, j = component._jsPlumb.overlays.length; i < j; i++) {
- if (id === component._jsPlumb.overlays[i].id) {
- idx = i;
- break;
- }
- }
- return idx;
- },
-
-
- _makeLabelOverlay = function(component, params) {
- var _params = {
- cssClass:params.cssClass,
- labelStyle : component.labelStyle,
- id:_internalLabelOverlayId,
- component:component,
- _jsPlumb:component._jsPlumb.instance
- },
- mergedParams = jsPlumb.extend(_params, params);
- return new jsPlumb.Overlays[component._jsPlumb.instance.getRenderMode()].Label( mergedParams );
- },
- _processOverlay = function(component, o) {
- var _newOverlay = null;
- if (_ju.isArray(o)) {
-
-
-
- var type = o[0],
-
- p = jsPlumb.extend({component:component, _jsPlumb:component._jsPlumb.instance}, o[1]);
- if (o.length == 3) jsPlumb.extend(p, o[2]);
- _newOverlay = new jsPlumb.Overlays[component._jsPlumb.instance.getRenderMode()][type](p);
- } else if (o.constructor == String) {
- _newOverlay = new jsPlumb.Overlays[component._jsPlumb.instance.getRenderMode()][o]({component:component, _jsPlumb:component._jsPlumb.instance});
- } else {
- _newOverlay = o;
- }
-
- component._jsPlumb.overlays.push(_newOverlay);
- },
- _calculateOverlaysToAdd = function(component, params) {
- var defaultKeys = component.defaultOverlayKeys || [], o = params.overlays,
- checkKey = function(k) {
- return component._jsPlumb.instance.Defaults[k] || jsPlumb.Defaults[k] || [];
- };
-
- if (!o) o = [];
- for (var i = 0, j = defaultKeys.length; i < j; i++)
- o.unshift.apply(o, checkKey(defaultKeys[i]));
-
- return o;
- },
- OverlayCapableJsPlumbUIComponent = window.OverlayCapableJsPlumbUIComponent = function(params) {
- jsPlumbUIComponent.apply(this, arguments);
- this._jsPlumb.overlays = [];
- var _overlays = _calculateOverlaysToAdd(this, params);
- if (_overlays) {
- for (var i = 0, j = _overlays.length; i < j; i++) {
- _processOverlay(this, _overlays[i]);
- }
- }
-
- if (params.label) {
- var loc = params.labelLocation || this.defaultLabelLocation || 0.5,
- labelStyle = params.labelStyle || this._jsPlumb.instance.Defaults.LabelStyle;
- this._jsPlumb.overlays.push(_makeLabelOverlay(this, {
- label:params.label,
- location:loc,
- labelStyle:labelStyle
- }));
- }
- this.setListenerComponent = function(c) {
- if (this._jsPlumb) {
- for (var i = 0; i < this._jsPlumb.overlays.length; i++)
- this._jsPlumb.overlays[i].setListenerComponent(c);
- }
- };
- };
- jsPlumbUtil.extend(OverlayCapableJsPlumbUIComponent, jsPlumbUIComponent, {
- applyType : function(t, doNotRepaint) {
- this.removeAllOverlays(doNotRepaint);
- if (t.overlays) {
- for (var i = 0, j = t.overlays.length; i < j; i++)
- this.addOverlay(t.overlays[i], true);
- }
- },
- setHover : function(hover, ignoreAttachedElements) {
- if (this._jsPlumb && !this._jsPlumb.instance.isConnectionBeingDragged()) {
- for (var i = 0, j = this._jsPlumb.overlays.length; i < j; i++) {
- this._jsPlumb.overlays[i][hover ? "addClass":"removeClass"](this._jsPlumb.instance.hoverClass);
- }
- }
- },
- addOverlay : function(overlay, doNotRepaint) {
- _processOverlay(this, overlay);
- if (!doNotRepaint) this.repaint();
- },
- getOverlay : function(id) {
- var idx = _getOverlayIndex(this, id);
- return idx >= 0 ? this._jsPlumb.overlays[idx] : null;
- },
- getOverlays : function() {
- return this._jsPlumb.overlays;
- },
- hideOverlay : function(id) {
- var o = this.getOverlay(id);
- if (o) o.hide();
- },
- hideOverlays : function() {
- for (var i = 0, j = this._jsPlumb.overlays.length; i < j; i++)
- this._jsPlumb.overlays[i].hide();
- },
- showOverlay : function(id) {
- var o = this.getOverlay(id);
- if (o) o.show();
- },
- showOverlays : function() {
- for (var i = 0, j = this._jsPlumb.overlays.length; i < j; i++)
- this._jsPlumb.overlays[i].show();
- },
- removeAllOverlays : function(doNotRepaint) {
- for (var i = 0, j = this._jsPlumb.overlays.length; i < j; i++) {
- if (this._jsPlumb.overlays[i].cleanup) this._jsPlumb.overlays[i].cleanup();
- }
- this._jsPlumb.overlays.splice(0, this._jsPlumb.overlays.length);
- this._jsPlumb.overlayPositions = null;
- if (!doNotRepaint)
- this.repaint();
- },
- removeOverlay : function(overlayId) {
- var idx = _getOverlayIndex(this, overlayId);
- if (idx != -1) {
- var o = this._jsPlumb.overlays[idx];
- if (o.cleanup) o.cleanup();
- this._jsPlumb.overlays.splice(idx, 1);
- if (this._jsPlumb.overlayPositions)
- delete this._jsPlumb.overlayPositions[overlayId];
- }
- },
- removeOverlays : function() {
- for (var i = 0, j = arguments.length; i < j; i++)
- this.removeOverlay(arguments[i]);
- },
- moveParent:function(newParent) {
- if (this.bgCanvas) {
- this.bgCanvas.parentNode.removeChild(this.bgCanvas);
- newParent.appendChild(this.bgCanvas);
- }
-
- this.canvas.parentNode.removeChild(this.canvas);
- newParent.appendChild(this.canvas);
- for (var i = 0; i < this._jsPlumb.overlays.length; i++) {
- if (this._jsPlumb.overlays[i].isAppendedAtTopLevel) {
- this._jsPlumb.overlays[i].canvas.parentNode.removeChild(this._jsPlumb.overlays[i].canvas);
- newParent.appendChild(this._jsPlumb.overlays[i].canvas);
- }
- }
- },
- getLabel : function() {
- var lo = this.getOverlay(_internalLabelOverlayId);
- return lo != null ? lo.getLabel() : null;
- },
- getLabelOverlay : function() {
- return this.getOverlay(_internalLabelOverlayId);
- },
- setLabel : function(l) {
- var lo = this.getOverlay(_internalLabelOverlayId);
- if (!lo) {
- var params = l.constructor == String || l.constructor == Function ? { label:l } : l;
- lo = _makeLabelOverlay(this, params);
- this._jsPlumb.overlays.push(lo);
- }
- else {
- if (l.constructor == String || l.constructor == Function) lo.setLabel(l);
- else {
- if (l.label) lo.setLabel(l.label);
- if (l.location) lo.setLocation(l.location);
- }
- }
-
- if (!this._jsPlumb.instance.isSuspendDrawing())
- this.repaint();
- },
- cleanup:function() {
- for (var i = 0; i < this._jsPlumb.overlays.length; i++) {
- this._jsPlumb.overlays[i].cleanup();
- this._jsPlumb.overlays[i].destroy();
- }
- this._jsPlumb.overlays.length = 0;
- this._jsPlumb.overlayPositions = null;
- },
- setVisible:function(v) {
- this[v ? "showOverlays" : "hideOverlays"]();
- },
- setAbsoluteOverlayPosition:function(overlay, xy) {
- this._jsPlumb.overlayPositions = this._jsPlumb.overlayPositions || {};
- this._jsPlumb.overlayPositions[overlay.id] = xy;
- },
- getAbsoluteOverlayPosition:function(overlay) {
- return this._jsPlumb.overlayPositions ? this._jsPlumb.overlayPositions[overlay.id] : null;
- }
- });
-
- var _jsPlumbInstanceIndex = 0,
- getInstanceIndex = function() {
- var i = _jsPlumbInstanceIndex + 1;
- _jsPlumbInstanceIndex++;
- return i;
- };
- var jsPlumbInstance = window.jsPlumbInstance = function(_defaults) {
-
- this.Defaults = {
- Anchor : "Bottom",
- Anchors : [ null, null ],
- ConnectionsDetachable : true,
- ConnectionOverlays : [ ],
- Connector : "Bezier",
- Container : null,
- DoNotThrowErrors:false,
- DragOptions : { },
- DropOptions : { },
- Endpoint : "Dot",
- EndpointOverlays : [ ],
- Endpoints : [ null, null ],
- EndpointStyle : { fillStyle : "#456" },
- EndpointStyles : [ null, null ],
- EndpointHoverStyle : null,
- EndpointHoverStyles : [ null, null ],
- HoverPaintStyle : null,
- LabelStyle : { color : "black" },
- LogEnabled : false,
- Overlays : [ ],
- MaxConnections : 1,
- PaintStyle : { lineWidth : 4, strokeStyle : "#456" },
- ReattachConnections:false,
- RenderMode : "svg",
- Scope : "jsPlumb_DefaultScope"
- };
- if (_defaults) jsPlumb.extend(this.Defaults, _defaults);
-
- this.logEnabled = this.Defaults.LogEnabled;
- this._connectionTypes = {};
- this._endpointTypes = {};
- jsPlumbUtil.EventGenerator.apply(this);
- var _currentInstance = this,
- _instanceIndex = getInstanceIndex(),
- _bb = _currentInstance.bind,
- _initialDefaults = {},
- _zoom = 1,
- _info = function(el) {
- var _el = _currentInstance.getDOMElement(el);
- return { el:_el, id:(jsPlumbUtil.isString(el) && _el == null) ? el : _getId(_el) };
- };
-
- this.getInstanceIndex = function() { return _instanceIndex; };
- this.setZoom = function(z, repaintEverything) {
- if (!jsPlumbUtil.oldIE) {
- _zoom = z;
- _currentInstance.fire("zoom", _zoom);
- if (repaintEverything) _currentInstance.repaintEverything();
- }
- return !jsPlumbUtil.oldIE;
- };
- this.getZoom = function() { return _zoom; };
-
- for (var i in this.Defaults)
- _initialDefaults[i] = this.Defaults[i];
- var _container;
- this.setContainer = function(c) {
-
- c = this.getDOMElement(c);
- this.select().each(function(conn) {
- conn.moveParent(c);
- });
- this.selectEndpoints().each(function(ep) {
- ep.moveParent(c);
- });
- _container = c;
- var _oneDelegateHandler = function(id, e) {
- var t = e.srcElement || e.target,
- jp = (t && t.parentNode ? t.parentNode._jsPlumb : null) || (t ? t._jsPlumb : null) || (t && t.parentNode && t.parentNode.parentNode ? t.parentNode.parentNode._jsPlumb : null);
- if (jp) {
- jp.fire(id, jp, e);
-
- _currentInstance.fire(id, jp, e);
- }
- };
-
-
-
-
- var _oneDelegate = function(id) {
-
- _currentInstance.on(_container, id, "._jsPlumb_connector, ._jsPlumb_connector > *", function(e) { _oneDelegateHandler(id, e); });
-
- _currentInstance.on(_container, id, "._jsPlumb_endpoint, ._jsPlumb_endpoint > *, ._jsPlumb_endpoint svg *", function(e) { _oneDelegateHandler(id, e); });
-
- _currentInstance.on(_container, id, "._jsPlumb_overlay, ._jsPlumb_overlay *", function(e) { _oneDelegateHandler(id, e); });
- };
- for (var i = 0; i < events.length; i++)
- _oneDelegate(events[i]);
- };
- this.getContainer = function() {
- return _container;
- };
-
- this.bind = function(event, fn) {
- if ("ready" === event && initialized) fn();
- else _bb.apply(_currentInstance,[event, fn]);
- };
- _currentInstance.importDefaults = function(d) {
- for (var i in d) {
- _currentInstance.Defaults[i] = d[i];
- }
- if (d.Container)
- _currentInstance.setContainer(d.Container);
- return _currentInstance;
- };
-
- _currentInstance.restoreDefaults = function() {
- _currentInstance.Defaults = jsPlumb.extend({}, _initialDefaults);
- return _currentInstance;
- };
-
-
- var log = null,
- initialized = false,
-
- connections = [],
-
-
-
- endpointsByElement = {},
- endpointsByUUID = {},
-
- managedElements = {},
- offsets = {},
- offsetTimestamps = {},
- draggableStates = {},
- connectionBeingDragged = false,
- sizes = [],
- _suspendDrawing = false,
- _suspendedAt = null,
- DEFAULT_SCOPE = this.Defaults.Scope,
- renderMode = null,
- _curIdStamp = 1,
- _idstamp = function() { return "" + _curIdStamp++; },
-
-
-
-
-
-
-
-
-
- _appendElement = function(el, parent) {
- if (_container)
- _container.appendChild(el);
- else if (!parent)
- this.appendToRoot(el);
- else
- this.getDOMElement(parent).appendChild(el);
- }.bind(this),
-
-
-
-
-
-
-
-
-
- _draw = function(element, ui, timestamp, clearEdits) {
-
- if (!jsPlumbAdapter.headless && !_suspendDrawing) {
- var id = _getId(element),
- repaintEls = _currentInstance.dragManager.getElementsForDraggable(id);
- if (timestamp == null) timestamp = _timestamp();
-
- var o = _updateOffset( { elId : id, offset : ui, recalc : false, timestamp : timestamp });
- if (repaintEls) {
- for (var i in repaintEls) {
-
-
- _updateOffset( {
- elId : repaintEls[i].id,
- offset : {
- left:o.o.left + repaintEls[i].offset.left,
- top:o.o.top + repaintEls[i].offset.top
- },
- recalc : false,
- timestamp : timestamp
- });
- }
- }
- _currentInstance.anchorManager.redraw(id, ui, timestamp, null, clearEdits);
-
- if (repaintEls) {
- for (var j in repaintEls) {
- _currentInstance.anchorManager.redraw(repaintEls[j].id, ui, timestamp, repaintEls[j].offset, clearEdits, true);
- }
- }
- }
- },
-
-
-
-
-
-
- _elementProxy = function(element, fn) {
- var retVal = null, el, id, del;
- if (_ju.isArray(element)) {
- retVal = [];
- for ( var i = 0, j = element.length; i < j; i++) {
- el = _currentInstance.getElementObject(element[i]);
- del = _currentInstance.getDOMElement(el);
- id = _currentInstance.getAttribute(del, "id");
- retVal.push(fn.apply(_currentInstance, [del, id]));
- }
- } else {
- el = _currentInstance.getDOMElement(element);
- id = _currentInstance.getId(el);
- retVal = fn.apply(_currentInstance, [el, id]);
- }
- return retVal;
- },
-
-
-
- _getEndpoint = function(uuid) { return endpointsByUUID[uuid]; },
-
- _initDraggableIfNecessary = function(element, isDraggable, dragOptions, id) {
-
- if (!jsPlumbAdapter.headless) {
- var _draggable = isDraggable == null ? false : isDraggable;
- if (_draggable) {
- if (jsPlumb.isDragSupported(element, _currentInstance) && !jsPlumb.isAlreadyDraggable(element, _currentInstance)) {
- var options = dragOptions || _currentInstance.Defaults.DragOptions;
- options = jsPlumb.extend( {}, options);
- var dragEvent = jsPlumb.dragEvents.drag,
- stopEvent = jsPlumb.dragEvents.stop,
- startEvent = jsPlumb.dragEvents.start,
- _del = _currentInstance.getDOMElement(element),
- _ancestor = _currentInstance.dragManager.getDragAncestor(_del),
- _noOffset = {left:0, top:0},
- _ancestorOffset = _noOffset,
- _started = false;
- _manage(id, element);
- options[startEvent] = _ju.wrap(options[startEvent], function() {
- _ancestorOffset = _ancestor != null ? jsPlumbAdapter.getOffset(_ancestor, _currentInstance) : _noOffset;
- _currentInstance.setHoverSuspended(true);
- _currentInstance.select({source:element}).addClass(_currentInstance.elementDraggingClass + " " + _currentInstance.sourceElementDraggingClass, true);
- _currentInstance.select({target:element}).addClass(_currentInstance.elementDraggingClass + " " + _currentInstance.targetElementDraggingClass, true);
- _currentInstance.setConnectionBeingDragged(true);
- if (options.canDrag) return dragOptions.canDrag();
- }, false);
-
- options[dragEvent] = _ju.wrap(options[dragEvent], function() {
-
-
-
- var ui = _currentInstance.getUIPosition(arguments, _currentInstance.getZoom());
-
-
- ui.left += _ancestorOffset.left;
- ui.top += _ancestorOffset.top;
- _draw(element, ui, null, true);
- if (_started) _currentInstance.addClass(element, "jsPlumb_dragged");
- _started = true;
- });
- options[stopEvent] = _ju.wrap(options[stopEvent], function() {
- var ui = _currentInstance.getUIPosition(arguments, _currentInstance.getZoom(), true);
- _draw(element, ui);
- _started = false;
- _currentInstance.removeClass(element, "jsPlumb_dragged");
- _currentInstance.setHoverSuspended(false);
- _currentInstance.select({source:element}).removeClass(_currentInstance.elementDraggingClass + " " + _currentInstance.sourceElementDraggingClass, true);
- _currentInstance.select({target:element}).removeClass(_currentInstance.elementDraggingClass + " " + _currentInstance.targetElementDraggingClass, true);
- _currentInstance.setConnectionBeingDragged(false);
- _currentInstance.dragManager.dragEnded(element);
- });
- var elId = _getId(element);
- draggableStates[elId] = true;
- var draggable = draggableStates[elId];
- options.disabled = draggable == null ? false : !draggable;
- _currentInstance.initDraggable(element, options);
- _currentInstance.dragManager.register(element);
- }
- }
- }
- },
- _scopeMatch = function(e1, e2) {
- var s1 = e1.scope.split(/\s/), s2 = e2.scope.split(/\s/);
- for (var i = 0; i < s1.length; i++)
- for (var j = 0; j < s2.length; j++)
- if (s2[j] == s1[i]) return true;
- return false;
- },
-
-
- _prepareConnectionParams = function(params, referenceParams) {
- var _p = jsPlumb.extend( { }, params);
- if (referenceParams) jsPlumb.extend(_p, referenceParams);
-
-
- if (_p.source) {
- if (_p.source.endpoint)
- _p.sourceEndpoint = _p.source;
- else
- _p.source = _currentInstance.getDOMElement(_p.source);
- }
- if (_p.target) {
- if (_p.target.endpoint)
- _p.targetEndpoint = _p.target;
- else
- _p.target = _currentInstance.getDOMElement(_p.target);
- }
-
-
- if (params.uuids) {
- _p.sourceEndpoint = _getEndpoint(params.uuids[0]);
- _p.targetEndpoint = _getEndpoint(params.uuids[1]);
- }
-
-
- if (_p.sourceEndpoint && _p.sourceEndpoint.isFull()) {
- _ju.log(_currentInstance, "could not add connection; source endpoint is full");
- return;
- }
-
- if (_p.targetEndpoint && _p.targetEndpoint.isFull()) {
- _ju.log(_currentInstance, "could not add connection; target endpoint is full");
- return;
- }
-
-
- if (!_p.type && _p.sourceEndpoint)
- _p.type = _p.sourceEndpoint.connectionType;
-
-
-
- if (_p.sourceEndpoint && _p.sourceEndpoint.connectorOverlays) {
- _p.overlays = _p.overlays || [];
- for (var i = 0, j = _p.sourceEndpoint.connectorOverlays.length; i < j; i++) {
- _p.overlays.push(_p.sourceEndpoint.connectorOverlays[i]);
- }
- }
-
-
- if (!_p["pointer-events"] && _p.sourceEndpoint && _p.sourceEndpoint.connectorPointerEvents)
- _p["pointer-events"] = _p.sourceEndpoint.connectorPointerEvents;
- var _mergeOverrides = function(def, values) {
- var m = jsPlumb.extend({}, def);
- for (var i in values) {
- if (values[i]) m[i] = values[i];
- }
- return m;
- };
- var _addEndpoint = function(el, def, idx) {
- return _currentInstance.addEndpoint(el, _mergeOverrides(def, {
- anchor:_p.anchors ? _p.anchors[idx] : _p.anchor,
- endpoint:_p.endpoints ? _p.endpoints[idx] : _p.endpoint,
- paintStyle:_p.endpointStyles ? _p.endpointStyles[idx] : _p.endpointStyle,
- hoverPaintStyle:_p.endpointHoverStyles ? _p.endpointHoverStyles[idx] : _p.endpointHoverStyle
- }));
- };
-
-
- var _oneElementDef = function(type, idx, defs) {
- if (_p[type] && !_p[type].endpoint && !_p[type + "Endpoint"] && !_p.newConnection) {
- var tid = _getId(_p[type]), tep = defs[tid];
- if (tep) {
-
- if (!tep.enabled) return false;
- var newEndpoint = tep.endpoint != null && tep.endpoint._jsPlumb ? tep.endpoint : _addEndpoint(_p[type], tep.def, idx);
- if (tep.uniqueEndpoint) tep.endpoint = newEndpoint;
- if (newEndpoint.isFull()) return false;
- _p[type + "Endpoint"] = newEndpoint;
- newEndpoint._doNotDeleteOnDetach = false;
- newEndpoint._deleteOnDetach = true;
- }
- }
- };
- if (_oneElementDef("source", 0, this.sourceEndpointDefinitions) === false) return;
- if (_oneElementDef("target", 1, this.targetEndpointDefinitions) === false) return;
-
- if (_p.sourceEndpoint && _p.targetEndpoint)
- if (!_scopeMatch(_p.sourceEndpoint, _p.targetEndpoint)) _p = null;
-
- return _p;
- }.bind(_currentInstance),
-
- _newConnection = function(params) {
- var connectionFunc = _currentInstance.Defaults.ConnectionType || _currentInstance.getDefaultConnectionType();
-
- params._jsPlumb = _currentInstance;
- params.newConnection = _newConnection;
- params.newEndpoint = _newEndpoint;
- params.endpointsByUUID = endpointsByUUID;
- params.endpointsByElement = endpointsByElement;
- params.finaliseConnection = _finaliseConnection;
- var con = new connectionFunc(params);
- con.id = "con_" + _idstamp();
-
-
- if (con.isDetachable()) {
- con.endpoints[0].initDraggable();
- con.endpoints[1].initDraggable();
- }
- return con;
- },
-
-
-
-
- _finaliseConnection = _currentInstance.finaliseConnection = function(jpc, params, originalEvent, doInformAnchorManager) {
- params = params || {};
-
- if (!jpc.suspendedEndpoint)
- connections.push(jpc);
-
- jpc.endpoints[0].isTemporarySource = false;
-
-
-
-
-
- if (jpc.suspendedEndpoint == null || doInformAnchorManager)
- _currentInstance.anchorManager.newConnection(jpc);
-
- _draw(jpc.source);
-
-
- if (!params.doNotFireConnectionEvent && params.fireEvent !== false) {
-
- var eventArgs = {
- connection:jpc,
- source : jpc.source, target : jpc.target,
- sourceId : jpc.sourceId, targetId : jpc.targetId,
- sourceEndpoint : jpc.endpoints[0], targetEndpoint : jpc.endpoints[1]
- };
-
- _currentInstance.fire("connection", eventArgs, originalEvent);
- }
- },
-
- _newEndpoint = function(params, id) {
- var endpointFunc = _currentInstance.Defaults.EndpointType || jsPlumb.Endpoint;
- var _p = jsPlumb.extend({}, params);
- _p._jsPlumb = _currentInstance;
- _p.newConnection = _newConnection;
- _p.newEndpoint = _newEndpoint;
- _p.endpointsByUUID = endpointsByUUID;
- _p.endpointsByElement = endpointsByElement;
- _p.fireDetachEvent = fireDetachEvent;
- _p.elementId = id || _getId(_p.source);
- var ep = new endpointFunc(_p);
- ep.id = "ep_" + _idstamp();
- _manage(_p.elementId, _p.source);
- if (!jsPlumbAdapter.headless)
- _currentInstance.dragManager.endpointAdded(_p.source, id);
- return ep;
- },
-
-
- _operation = function(elId, func, endpointFunc) {
- var endpoints = endpointsByElement[elId];
- if (endpoints && endpoints.length) {
- for ( var i = 0, ii = endpoints.length; i < ii; i++) {
- for ( var j = 0, jj = endpoints[i].connections.length; j < jj; j++) {
- var retVal = func(endpoints[i].connections[j]);
-
-
- if (retVal) return;
- }
- if (endpointFunc) endpointFunc(endpoints[i]);
- }
- }
- },
-
- _setDraggable = function(element, draggable) {
- return _elementProxy(element, function(el, id) {
- draggableStates[id] = draggable;
- if (this.isDragSupported(el)) {
- this.setElementDraggable(el, draggable);
- }
- });
- },
-
- _setVisible = function(el, state, alsoChangeEndpoints) {
- state = state === "block";
- var endpointFunc = null;
- if (alsoChangeEndpoints) {
- if (state) endpointFunc = function(ep) {
- ep.setVisible(true, true, true);
- };
- else endpointFunc = function(ep) {
- ep.setVisible(false, true, true);
- };
- }
- var info = _info(el);
- _operation(info.id, function(jpc) {
- if (state && alsoChangeEndpoints) {
-
-
- var oidx = jpc.sourceId === info.id ? 1 : 0;
- if (jpc.endpoints[oidx].isVisible()) jpc.setVisible(true);
- }
- else
- jpc.setVisible(state);
- }, endpointFunc);
- },
-
- _toggleDraggable = function(el) {
- return _elementProxy(el, function(el, elId) {
- var state = draggableStates[elId] == null ? false : draggableStates[elId];
- state = !state;
- draggableStates[elId] = state;
- this.setDraggable(el, state);
- return state;
- }.bind(this));
- },
-
- _toggleVisible = function(elId, changeEndpoints) {
- var endpointFunc = null;
- if (changeEndpoints) {
- endpointFunc = function(ep) {
- var state = ep.isVisible();
- ep.setVisible(!state);
- };
- }
- _operation(elId, function(jpc) {
- var state = jpc.isVisible();
- jpc.setVisible(!state);
- }, endpointFunc);
-
-
-
- },
-
- _getCachedData = function(elId) {
- var o = offsets[elId];
- if (!o)
- return _updateOffset({elId:elId});
- else
- return {o:o, s:sizes[elId]};
- },
-
- _getId = function(element, uuid, doNotCreateIfNotFound) {
- if (jsPlumbUtil.isString(element)) return element;
- if (element == null) return null;
- var id = _currentInstance.getAttribute(element, "id");
- if (!id || id === "undefined") {
-
- if (arguments.length == 2 && arguments[1] !== undefined)
- id = uuid;
- else if (arguments.length == 1 || (arguments.length == 3 && !arguments[2]))
- id = "jsPlumb_" + _instanceIndex + "_" + _idstamp();
-
- if (!doNotCreateIfNotFound) _currentInstance.setAttribute(element, "id", id);
- }
- return id;
- };
- this.setConnectionBeingDragged = function(v) {
- connectionBeingDragged = v;
- };
- this.isConnectionBeingDragged = function() {
- return connectionBeingDragged;
- };
-
- this.connectorClass = "_jsPlumb_connector";
- this.hoverClass = "_jsPlumb_hover";
- this.endpointClass = "_jsPlumb_endpoint";
- this.endpointConnectedClass = "_jsPlumb_endpoint_connected";
- this.endpointFullClass = "_jsPlumb_endpoint_full";
- this.endpointDropAllowedClass = "_jsPlumb_endpoint_drop_allowed";
- this.endpointDropForbiddenClass = "_jsPlumb_endpoint_drop_forbidden";
- this.overlayClass = "_jsPlumb_overlay";
- this.draggingClass = "_jsPlumb_dragging";
- this.elementDraggingClass = "_jsPlumb_element_dragging";
- this.sourceElementDraggingClass = "_jsPlumb_source_element_dragging";
- this.targetElementDraggingClass = "_jsPlumb_target_element_dragging";
- this.endpointAnchorClassPrefix = "_jsPlumb_endpoint_anchor";
- this.hoverSourceClass = "_jsPlumb_source_hover";
- this.hoverTargetClass = "_jsPlumb_target_hover";
- this.dragSelectClass = "_jsPlumb_drag_select";
- this.Anchors = {};
- this.Connectors = { "svg":{}, "vml":{} };
- this.Endpoints = { "svg":{}, "vml":{} };
- this.Overlays = { "svg":{}, "vml":{}};
- this.ConnectorRenderers = {};
- this.SVG = "svg";
- this.VML = "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;
- p.paintStyle = p.paintStyle || _currentInstance.Defaults.EndpointStyle;
- var results = [],
- inputs = (_ju.isArray(el) || (el.length != null && !_ju.isString(el))) ? el : [ el ];
- for (var i = 0, j = inputs.length; i < j; i++) {
- p.source = _currentInstance.getDOMElement(inputs[i]);
- _ensureContainer(p.source);
- var id = _getId(p.source), e = _newEndpoint(p, id);
-
-
-
- var myOffset = _manage(id, p.source).info.o;
- _ju.addToList(endpointsByElement, id, e);
- if (!_suspendDrawing) {
- e.paint({
- anchorLoc: e.anchor.compute({ xy: [ myOffset.left, myOffset.top ], wh: sizes[id], element: e, timestamp: _suspendedAt }),
- timestamp: _suspendedAt
- });
- }
- results.push(e);
- e._doNotDeleteOnDetach = true;
- }
- return results.length == 1 ? results[0] : results;
- };
- this.addEndpoints = function(el, endpoints, referenceParams) {
- var results = [];
- for ( var i = 0, j = endpoints.length; i < j; i++) {
- var e = _currentInstance.addEndpoint(el, endpoints[i], referenceParams);
- if (_ju.isArray(e))
- Array.prototype.push.apply(results, e);
- else results.push(e);
- }
- return results;
- };
-
- this.animate = function(el, properties, options) {
- options = options || {};
- var ele = _currentInstance.getElementObject(el),
- del = _currentInstance.getDOMElement(el),
- id = _getId(del),
- stepFunction = jsPlumb.animEvents.step,
- completeFunction = jsPlumb.animEvents.complete;
- options[stepFunction] = _ju.wrap(options[stepFunction], function() {
- _currentInstance.revalidate(id);
- });
-
- options[completeFunction] = _ju.wrap(options[completeFunction], function() {
- _currentInstance.revalidate(id);
- });
- _currentInstance.doAnimate(ele, properties, options);
- };
-
-
- this.checkCondition = function(conditionName, value) {
- var l = _currentInstance.getListener(conditionName),
- r = true;
-
- if (l && l.length > 0) {
- try {
- for (var i = 0, j = l.length; i < j; i++) {
- r = r && l[i](value);
- }
- }
- catch (e) {
- _ju.log(_currentInstance, "cannot check condition [" + conditionName + "]" + e);
- }
- }
- return r;
- };
-
- this.connect = function(params, referenceParams) {
-
- var _p = _prepareConnectionParams(params, referenceParams), jpc;
-
-
-
- if (_p) {
- if (_p.source == null && _p.sourceEndpoint == null) {
- jsPlumbUtil.log("Cannot establish connection - source does not exist");
- return;
- }
- if (_p.target == null && _p.targetEndpoint == null) {
- jsPlumbUtil.log("Cannot establish connection - target does not exist");
- return;
- }
- _ensureContainer(_p.source);
-
- jpc = _newConnection(_p);
-
- _finaliseConnection(jpc, _p);
- }
- return jpc;
- };
-
- var stTypes = [
- { el:"source", elId:"sourceId", epDefs:"sourceEndpointDefinitions" },
- { el:"target", elId:"targetId", epDefs:"targetEndpointDefinitions" }
- ];
-
- var _set = function(c, el, idx, doNotRepaint) {
- var ep, _st = stTypes[idx], cId = c[_st.elId], cEl = c[_st.el], sid, sep,
- oldEndpoint = c.endpoints[idx];
-
- var evtParams = {
- index:idx,
- originalSourceId:idx === 0 ? cId : c.sourceId,
- newSourceId:c.sourceId,
- originalTargetId:idx == 1 ? cId : c.targetId,
- newTargetId:c.targetId,
- connection:c
- };
- if (el.constructor == jsPlumb.Endpoint) {
- ep = el;
- ep.addConnection(c);
- }
- else {
- sid = _getId(el);
- sep = this[_st.epDefs][sid];
- if (sid === c[_st.elId])
- ep = null;
- else if (sep) {
- if (!sep.enabled) return;
- ep = sep.endpoint != null && sep.endpoint._jsPlumb ? sep.endpoint : this.addEndpoint(el, sep.def);
- if (sep.uniqueEndpoint) sep.endpoint = ep;
- ep._doNotDeleteOnDetach = false;
- ep._deleteOnDetach = true;
- ep.addConnection(c);
- }
- else {
- ep = c.makeEndpoint(idx === 0, el, sid);
- ep._doNotDeleteOnDetach = false;
- ep._deleteOnDetach = true;
- }
- }
-
- if (ep != null) {
- oldEndpoint.detachFromConnection(c);
- c.endpoints[idx] = ep;
- c[_st.el] = ep.element;
- c[_st.elId] = ep.elementId;
- evtParams[idx === 0 ? "newSourceId" : "newTargetId"] = ep.elementId;
- fireMoveEvent(evtParams);
-
- if (!doNotRepaint)
- c.repaint();
- }
- return evtParams;
-
- }.bind(this);
- this.setSource = function(connection, el, doNotRepaint) {
- var p = _set(connection, el, 0, doNotRepaint);
- this.anchorManager.sourceChanged(p.originalSourceId, p.newSourceId, connection);
- };
- this.setTarget = function(connection, el, doNotRepaint) {
- var p = _set(connection, el, 1, doNotRepaint);
- this.anchorManager.updateOtherEndpoint(p.originalSourceId, p.originalTargetId, p.newTargetId, connection);
- };
-
- this.deleteEndpoint = function(object, dontUpdateHover) {
- var endpoint = (typeof object === "string") ? endpointsByUUID[object] : object;
- if (endpoint) {
- _currentInstance.deleteObject({ endpoint:endpoint, dontUpdateHover:dontUpdateHover });
- }
- return _currentInstance;
- };
-
- this.deleteEveryEndpoint = function() {
- var _is = _currentInstance.setSuspendDrawing(true);
- for ( var id in endpointsByElement) {
- var endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0, j = endpoints.length; i < j; i++) {
- _currentInstance.deleteEndpoint(endpoints[i], true);
- }
- }
- }
- endpointsByElement = {};
-
- managedElements = {};
- endpointsByUUID = {};
- _currentInstance.anchorManager.reset();
- _currentInstance.dragManager.reset();
- if(!_is) _currentInstance.setSuspendDrawing(false);
- return _currentInstance;
- };
- var fireDetachEvent = function(jpc, doFireEvent, originalEvent) {
-
- var connType = _currentInstance.Defaults.ConnectionType || _currentInstance.getDefaultConnectionType(),
- argIsConnection = jpc.constructor == connType,
- params = argIsConnection ? {
- connection:jpc,
- source : jpc.source, target : jpc.target,
- sourceId : jpc.sourceId, targetId : jpc.targetId,
- sourceEndpoint : jpc.endpoints[0], targetEndpoint : jpc.endpoints[1]
- } : jpc;
- if (doFireEvent)
- _currentInstance.fire("connectionDetached", params, originalEvent);
-
- _currentInstance.anchorManager.connectionDetached(params);
- };
- var fireMoveEvent = _currentInstance.fireMoveEvent = function(params, evt) {
- _currentInstance.fire("connectionMoved", params, evt);
- };
- this.unregisterEndpoint = function(endpoint) {
-
- if (endpoint._jsPlumb.uuid) endpointsByUUID[endpoint._jsPlumb.uuid] = null;
- _currentInstance.anchorManager.deleteEndpoint(endpoint);
-
- for (var e in endpointsByElement) {
- var endpoints = endpointsByElement[e];
- if (endpoints) {
- var newEndpoints = [];
- for (var i = 0, j = endpoints.length; i < j; i++)
- if (endpoints[i] != endpoint) newEndpoints.push(endpoints[i]);
-
- endpointsByElement[e] = newEndpoints;
- }
- if(endpointsByElement[e].length <1){
- delete endpointsByElement[e];
- }
- }
- };
-
- this.detach = function() {
- if (arguments.length === 0) return;
- var connType = _currentInstance.Defaults.ConnectionType || _currentInstance.getDefaultConnectionType(),
- firstArgIsConnection = arguments[0].constructor == connType,
- params = arguments.length == 2 ? firstArgIsConnection ? (arguments[1] || {}) : arguments[0] : arguments[0],
- fireEvent = (params.fireEvent !== false),
- forceDetach = params.forceDetach,
- conn = firstArgIsConnection ? arguments[0] : params.connection;
-
- if (conn) {
- if (forceDetach || jsPlumbUtil.functionChain(true, false, [
- [ conn.endpoints[0], "isDetachAllowed", [ conn ] ],
- [ conn.endpoints[1], "isDetachAllowed", [ conn ] ],
- [ conn, "isDetachAllowed", [ conn ] ],
- [ _currentInstance, "checkCondition", [ "beforeDetach", conn ] ] ])) {
-
- conn.endpoints[0].detach(conn, false, true, fireEvent);
- }
- }
- else {
- var _p = jsPlumb.extend( {}, params);
-
- if (_p.uuids) {
- _getEndpoint(_p.uuids[0]).detachFrom(_getEndpoint(_p.uuids[1]), fireEvent);
- } else if (_p.sourceEndpoint && _p.targetEndpoint) {
- _p.sourceEndpoint.detachFrom(_p.targetEndpoint);
- } else {
- var sourceId = _getId(_currentInstance.getDOMElement(_p.source)),
- targetId = _getId(_currentInstance.getDOMElement(_p.target));
- _operation(sourceId, function(jpc) {
- if ((jpc.sourceId == sourceId && jpc.targetId == targetId) || (jpc.targetId == sourceId && jpc.sourceId == targetId)) {
- if (_currentInstance.checkCondition("beforeDetach", jpc)) {
- jpc.endpoints[0].detach(jpc, false, true, fireEvent);
- }
- }
- });
- }
- }
- };
- this.detachAllConnections = function(el, params) {
- params = params || {};
- el = _currentInstance.getDOMElement(el);
- var id = _getId(el),
- endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0, j = endpoints.length; i < j; i++) {
- endpoints[i].detachAll(params.fireEvent !== false);
- }
- }
- return _currentInstance;
- };
- this.detachEveryConnection = function(params) {
- params = params || {};
- _currentInstance.doWhileSuspended(function() {
- for ( var id in endpointsByElement) {
- var endpoints = endpointsByElement[id];
- if (endpoints && endpoints.length) {
- for ( var i = 0, j = endpoints.length; i < j; i++) {
- endpoints[i].detachAll(params.fireEvent !== false);
- }
- }
- }
- connections.length = 0;
- });
- return _currentInstance;
- };
-
- this.deleteObject = function(params) {
- var result = {
- endpoints : {},
- connections : {},
- endpointCount:0,
- connectionCount:0
- },
- fireEvent = params.fireEvent !== false,
- deleteAttachedObjects = params.deleteAttachedObjects !== false;
- var unravelConnection = function(connection) {
- if(connection != null && result.connections[connection.id] == null) {
- if (!params.dontUpdateHover && connection._jsPlumb != null) connection.setHover(false);
- result.connections[connection.id] = connection;
- result.connectionCount++;
- if (deleteAttachedObjects) {
- for (var j = 0; j < connection.endpoints.length; j++) {
- if (connection.endpoints[j]._deleteOnDetach)
- unravelEndpoint(connection.endpoints[j]);
- }
- }
- }
- };
- var unravelEndpoint = function(endpoint) {
- if(endpoint != null && result.endpoints[endpoint.id] == null) {
- if (!params.dontUpdateHover && endpoint._jsPlumb != null) endpoint.setHover(false);
- result.endpoints[endpoint.id] = endpoint;
- result.endpointCount++;
- if (deleteAttachedObjects) {
- for (var i = 0; i < endpoint.connections.length; i++) {
- var c = endpoint.connections[i];
- unravelConnection(c);
- }
- }
- }
- };
- if (params.connection)
- unravelConnection(params.connection);
- else unravelEndpoint(params.endpoint);
-
- for (var i in result.connections) {
- var c = result.connections[i];
- if (c._jsPlumb) {
- jsPlumbUtil.removeWithFunction(connections, function(_c) {
- return c.id == _c.id;
- });
- fireDetachEvent(c, fireEvent, params.originalEvent);
-
- c.endpoints[0].detachFromConnection(c);
- c.endpoints[1].detachFromConnection(c);
-
- c.cleanup();
- c.destroy();
- }
- }
-
- for (var j in result.endpoints) {
- var e = result.endpoints[j];
- if (e._jsPlumb) {
- _currentInstance.unregisterEndpoint(e);
-
- e.cleanup();
- e.destroy();
- }
- }
- return result;
- };
-
- this.draggable = function(el, options) {
- var i,j,info;
-
- if (typeof el == 'object' && el.length) {
- for (i = 0, j = el.length; i < j; i++) {
- info = _info(el[i]);
- if (info.el) _initDraggableIfNecessary(info.el, true, options, info.id);
- }
- }
- else {
-
- info = _info(el);
- if (info.el) _initDraggableIfNecessary(info.el, true, options, info.id);
- }
- return _currentInstance;
- };
-
- var _setOperation = function(list, func, args, selector) {
- for (var i = 0, j = list.length; i < j; i++) {
- list[i][func].apply(list[i], args);
- }
- return selector(list);
- },
- _getOperation = function(list, func, args) {
- var out = [];
- for (var i = 0, j = list.length; i < j; i++) {
- out.push([ list[i][func].apply(list[i], args), list[i] ]);
- }
- return out;
- },
- setter = function(list, func, selector) {
- return function() {
- return _setOperation(list, func, arguments, selector);
- };
- },
- getter = function(list, func) {
- return function() {
- return _getOperation(list, func, arguments);
- };
- },
- prepareList = function(input, doNotGetIds) {
- var r = [];
- if (input) {
- if (typeof input == 'string') {
- if (input === "*") return input;
- r.push(input);
- }
- else {
- if (doNotGetIds) r = input;
- else {
- if (input.length) {
- for (var i = 0, j = input.length; i < j; i++)
- r.push(_info(input[i]).id);
- }
- else
- r.push(_info(input).id);
- }
- }
- }
- return r;
- },
- filterList = function(list, value, missingIsFalse) {
- if (list === "*") return true;
- return list.length > 0 ? jsPlumbUtil.indexOf(list, value) != -1 : !missingIsFalse;
- };
-
- this.getConnections = function(options, flat) {
- if (!options) {
- options = {};
- } else if (options.constructor == String) {
- options = { "scope": options };
- }
- var scope = options.scope || _currentInstance.getDefaultScope(),
- scopes = prepareList(scope, true),
- sources = prepareList(options.source),
- targets = prepareList(options.target),
- results = (!flat && scopes.length > 1) ? {} : [],
- _addOne = function(scope, obj) {
- if (!flat && scopes.length > 1) {
- var ss = results[scope];
- if (ss == null) {
- ss = results[scope] = [];
- }
- ss.push(obj);
- } else results.push(obj);
- };
-
- for ( var j = 0, jj = connections.length; j < jj; j++) {
- var c = connections[j];
- if (filterList(scopes, c.scope) && filterList(sources, c.sourceId) && filterList(targets, c.targetId))
- _addOne(c.scope, c);
- }
-
- return results;
- };
-
- var _curryEach = function(list, executor) {
- return function(f) {
- for (var i = 0, ii = list.length; i < ii; i++) {
- f(list[i]);
- }
- return executor(list);
- };
- },
- _curryGet = function(list) {
- return function(idx) {
- return list[idx];
- };
- };
-
- var _makeCommonSelectHandler = function(list, executor) {
- var out = {
- length:list.length,
- each:_curryEach(list, executor),
- get:_curryGet(list)
- },
- setters = ["setHover", "removeAllOverlays", "setLabel", "addClass", "addOverlay", "removeOverlay",
- "removeOverlays", "showOverlay", "hideOverlay", "showOverlays", "hideOverlays", "setPaintStyle",
- "setHoverPaintStyle", "setSuspendEvents", "setParameter", "setParameters", "setVisible",
- "repaint", "addType", "toggleType", "removeType", "removeClass", "setType", "bind", "unbind" ],
-
- getters = ["getLabel", "getOverlay", "isHover", "getParameter", "getParameters", "getPaintStyle",
- "getHoverPaintStyle", "isVisible", "hasType", "getType", "isSuspendEvents" ],
- i, ii;
-
- for (i = 0, ii = setters.length; i < ii; i++)
- out[setters[i]] = setter(list, setters[i], executor);
-
- for (i = 0, ii = getters.length; i < ii; i++)
- out[getters[i]] = getter(list, getters[i]);
-
- return out;
- };
-
- var _makeConnectionSelectHandler = function(list) {
- var common = _makeCommonSelectHandler(list, _makeConnectionSelectHandler);
- return jsPlumb.extend(common, {
-
- setDetachable:setter(list, "setDetachable", _makeConnectionSelectHandler),
- setReattach:setter(list, "setReattach", _makeConnectionSelectHandler),
- setConnector:setter(list, "setConnector", _makeConnectionSelectHandler),
- detach:function() {
- for (var i = 0, ii = list.length; i < ii; i++)
- _currentInstance.detach(list[i]);
- },
-
- isDetachable:getter(list, "isDetachable"),
- isReattach:getter(list, "isReattach")
- });
- };
-
- var _makeEndpointSelectHandler = function(list) {
- var common = _makeCommonSelectHandler(list, _makeEndpointSelectHandler);
- return jsPlumb.extend(common, {
- setEnabled:setter(list, "setEnabled", _makeEndpointSelectHandler),
- setAnchor:setter(list, "setAnchor", _makeEndpointSelectHandler),
- isEnabled:getter(list, "isEnabled"),
- detachAll:function() {
- for (var i = 0, ii = list.length; i < ii; i++)
- list[i].detachAll();
- },
- "remove":function() {
- for (var i = 0, ii = list.length; i < ii; i++)
- _currentInstance.deleteObject({endpoint:list[i]});
- }
- });
- };
-
- this.select = function(params) {
- params = params || {};
- params.scope = params.scope || "*";
- return _makeConnectionSelectHandler(params.connections || _currentInstance.getConnections(params, true));
- };
- this.selectEndpoints = function(params) {
- params = params || {};
- params.scope = params.scope || "*";
- var noElementFilters = !params.element && !params.source && !params.target,
- elements = noElementFilters ? "*" : prepareList(params.element),
- sources = noElementFilters ? "*" : prepareList(params.source),
- targets = noElementFilters ? "*" : prepareList(params.target),
- scopes = prepareList(params.scope, true);
-
- var ep = [];
-
- for (var el in endpointsByElement) {
- var either = filterList(elements, el, true),
- source = filterList(sources, el, true),
- sourceMatchExact = sources != "*",
- target = filterList(targets, el, true),
- targetMatchExact = targets != "*";
-
-
- if ( either || source || target ) {
- inner:
- for (var i = 0, ii = endpointsByElement[el].length; i < ii; i++) {
- var _ep = endpointsByElement[el][i];
- if (filterList(scopes, _ep.scope, true)) {
-
- var noMatchSource = (sourceMatchExact && sources.length > 0 && !_ep.isSource),
- noMatchTarget = (targetMatchExact && targets.length > 0 && !_ep.isTarget);
-
- if (noMatchSource || noMatchTarget)
- continue inner;
-
- ep.push(_ep);
- }
- }
- }
- }
-
- return _makeEndpointSelectHandler(ep);
- };
-
- this.getAllConnections = function() { return connections; };
- this.getDefaultScope = function() { return DEFAULT_SCOPE; };
-
- this.getEndpoint = _getEndpoint;
-
- this.getEndpoints = function(el) { return endpointsByElement[_info(el).id]; };
-
- this.getDefaultEndpointType = function() { return jsPlumb.Endpoint; };
-
- this.getDefaultConnectionType = function() { return jsPlumb.Connection; };
-
- this.getId = _getId;
- this.getOffset = function(id) {
- return _updateOffset({elId:id}).o;
- };
-
- this.appendElement = _appendElement;
-
- var _hoverSuspended = false;
- this.isHoverSuspended = function() { return _hoverSuspended; };
- this.setHoverSuspended = function(s) { _hoverSuspended = s; };
- var _isAvailable = function(m) {
- return function() {
- return jsPlumbAdapter.isRenderModeAvailable(m);
- };
- };
- this.isSVGAvailable = _isAvailable("svg");
- this.isVMLAvailable = _isAvailable("vml");
-
- this.hide = function(el, changeEndpoints) {
- _setVisible(el, "none", changeEndpoints);
- return _currentInstance;
- };
-
-
- this.idstamp = _idstamp;
- this.connectorsInitialized = false;
- var connectorTypes = [], rendererTypes = ["svg", "vml"];
- this.registerConnectorType = function(connector, name) {
- connectorTypes.push([connector, name]);
- };
-
-
-
-
-
-
-
- var _ensureContainer = function(candidate) {
- if (!_container && candidate) {
- var can = _currentInstance.getDOMElement(candidate);
- if (can.offsetParent) _currentInstance.setContainer(can.offsetParent);
- }
- };
- var _getContainerFromDefaults = function() {
- if (_currentInstance.Defaults.Container)
- _currentInstance.setContainer(_currentInstance.Defaults.Container);
- };
-
-
-
- var _manage = _currentInstance.manage = function(id, element) {
- if (!managedElements[id]) {
- managedElements[id] = {
- el:element,
- endpoints:[],
- connections:[]
- };
- managedElements[id].info = _updateOffset({ elId: id, timestamp: _suspendedAt });
-
- }
- return managedElements[id];
- };
- var _unmanage = function(id) {
- delete managedElements[id];
- };
-
- var _updateOffset = this.updateOffset = function(params) {
- var timestamp = params.timestamp, recalc = params.recalc, offset = params.offset, elId = params.elId, s;
- if (_suspendDrawing && !timestamp) timestamp = _suspendedAt;
- if (!recalc) {
- if (timestamp && timestamp === offsetTimestamps[elId]) {
- return {o:params.offset || offsets[elId], s:sizes[elId]};
- }
- }
- if (recalc || (!offset && offsets[elId] == null)) {
-
- s = managedElements[elId] ? managedElements[elId].el : null;
- if (s != null) {
- sizes[elId] = _currentInstance.getSize(s);
- offsets[elId] = _getOffset(s, _currentInstance);
- offsetTimestamps[elId] = timestamp;
- }
- } else {
- offsets[elId] = offset || offsets[elId];
- if (sizes[elId] == null) {
-
- s = managedElements[elId].el;
- if (s != null) sizes[elId] = _currentInstance.getSize(s);
- }
- offsetTimestamps[elId] = timestamp;
- }
- if(offsets[elId] && !offsets[elId].right) {
- offsets[elId].right = offsets[elId].left + sizes[elId][0];
- offsets[elId].bottom = offsets[elId].top + sizes[elId][1];
- offsets[elId].width = sizes[elId][0];
- offsets[elId].height = sizes[elId][1];
- offsets[elId].centerx = offsets[elId].left + (offsets[elId].width / 2);
- offsets[elId].centery = offsets[elId].top + (offsets[elId].height / 2);
- }
- return {o:offsets[elId], s:sizes[elId]};
- };
-
-
- this.init = function() {
- var _oneType = function(renderer, name, fn) {
- jsPlumb.Connectors[renderer][name] = function() {
- fn.apply(this, arguments);
- jsPlumb.ConnectorRenderers[renderer].apply(this, arguments);
- };
- jsPlumbUtil.extend(jsPlumb.Connectors[renderer][name], [ fn, jsPlumb.ConnectorRenderers[renderer]]);
- };
- if (!jsPlumb.connectorsInitialized) {
- for (var i = 0; i < connectorTypes.length; i++) {
- for (var j = 0; j < rendererTypes.length; j++) {
- _oneType(rendererTypes[j], connectorTypes[i][1], connectorTypes[i][0]);
- }
- }
- jsPlumb.connectorsInitialized = true;
- }
-
- if (!initialized) {
- _getContainerFromDefaults();
- _currentInstance.anchorManager = new jsPlumb.AnchorManager({jsPlumbInstance:_currentInstance});
- _currentInstance.setRenderMode(_currentInstance.Defaults.RenderMode);
- initialized = true;
- _currentInstance.fire("ready", _currentInstance);
- }
- }.bind(this);
-
- this.log = log;
- this.jsPlumbUIComponent = jsPlumbUIComponent;
-
- this.makeAnchor = function() {
- var pp, _a = function(t, p) {
- if (jsPlumb.Anchors[t]) return new jsPlumb.Anchors[t](p);
- if (!_currentInstance.Defaults.DoNotThrowErrors)
- throw { msg:"jsPlumb: unknown anchor type '" + t + "'" };
- };
- if (arguments.length === 0) return null;
- var specimen = arguments[0], elementId = arguments[1], jsPlumbInstance = arguments[2], newAnchor = null;
-
- if (specimen.compute && specimen.getOrientation) return specimen;
-
- else if (typeof specimen == "string") {
- newAnchor = _a(arguments[0], {elementId:elementId, jsPlumbInstance:_currentInstance});
- }
-
-
-
-
- else if (_ju.isArray(specimen)) {
- if (_ju.isArray(specimen[0]) || _ju.isString(specimen[0])) {
-
- if (specimen.length == 2 && _ju.isObject(specimen[1])) {
-
- if (_ju.isString(specimen[0])) {
- pp = jsPlumb.extend({elementId:elementId, jsPlumbInstance:_currentInstance}, specimen[1]);
- newAnchor = _a(specimen[0], pp);
- }
-
-
- else {
- pp = jsPlumb.extend({elementId:elementId, jsPlumbInstance:_currentInstance, anchors:specimen[0]}, specimen[1]);
- newAnchor = new jsPlumb.DynamicAnchor(pp);
- }
- }
- else
- newAnchor = new jsPlumb.DynamicAnchor({anchors:specimen, selector:null, elementId:elementId, jsPlumbInstance:_currentInstance});
- }
- else {
- var anchorParams = {
- x:specimen[0], y:specimen[1],
- orientation : (specimen.length >= 4) ? [ specimen[2], specimen[3] ] : [0,0],
- offsets : (specimen.length >= 6) ? [ specimen[4], specimen[5] ] : [ 0, 0 ],
- elementId:elementId,
- jsPlumbInstance:_currentInstance,
- cssClass:specimen.length == 7 ? specimen[6] : null
- };
- newAnchor = new jsPlumb.Anchor(anchorParams);
- newAnchor.clone = function() { return new jsPlumb.Anchor(anchorParams); };
- }
- }
-
- if (!newAnchor.id) newAnchor.id = "anchor_" + _idstamp();
- return newAnchor;
- };
-
- this.makeAnchors = function(types, elementId, jsPlumbInstance) {
- var r = [];
- for ( var i = 0, ii = types.length; i < ii; i++) {
- if (typeof types[i] == "string")
- r.push(jsPlumb.Anchors[types[i]]({elementId:elementId, jsPlumbInstance:jsPlumbInstance}));
- else if (_ju.isArray(types[i]))
- r.push(_currentInstance.makeAnchor(types[i], elementId, jsPlumbInstance));
- }
- return r;
- };
-
- this.makeDynamicAnchor = function(anchors, anchorSelector) {
- return new jsPlumb.DynamicAnchor({anchors:anchors, selector:anchorSelector, elementId:null, jsPlumbInstance:_currentInstance});
- };
-
-
- this.targetEndpointDefinitions = {};
- var _setEndpointPaintStylesAndAnchor = function(ep, epIndex, _instance) {
- ep.paintStyle = ep.paintStyle ||
- _instance.Defaults.EndpointStyles[epIndex] ||
- _instance.Defaults.EndpointStyle;
-
- ep.hoverPaintStyle = ep.hoverPaintStyle ||
- _instance.Defaults.EndpointHoverStyles[epIndex] ||
- _instance.Defaults.EndpointHoverStyle;
- ep.anchor = ep.anchor ||
- _instance.Defaults.Anchors[epIndex] ||
- _instance.Defaults.Anchor;
-
- ep.endpoint = ep.endpoint ||
- _instance.Defaults.Endpoints[epIndex] ||
- _instance.Defaults.Endpoint;
- };
-
-
- this.sourceEndpointDefinitions = {};
-
- var selectorFilter = function(evt, _el, selector, _instance, negate) {
- var t = evt.target || evt.srcElement, ok = false,
- sel = _instance.getSelector(_el, selector);
- for (var j = 0; j < sel.length; j++) {
- if (sel[j] == t) {
- ok = true;
- break;
- }
- }
- return negate ? !ok : ok;
- };
-
-
- this.makeTarget = function(el, params, referenceParams) {
-
- var p = jsPlumb.extend({_jsPlumb:this}, referenceParams);
- jsPlumb.extend(p, params);
-
- _setEndpointPaintStylesAndAnchor(p, 1, this);
- var targetScope = p.scope || _currentInstance.Defaults.Scope,
- deleteEndpointsOnDetach = !(p.deleteEndpointsOnDetach === false),
- maxConnections = p.maxConnections || -1,
- onMaxConnections = p.onMaxConnections,
- _doOne = function(el) {
-
-
-
-
- var elInfo = _info(el),
- elid = elInfo.id,
- proxyComponent = new jsPlumbUIComponent(p),
- dropOptions = jsPlumb.extend({}, p.dropOptions || {});
- _ensureContainer(elid);
-
-
- var _def = {
- def:p,
- uniqueEndpoint:p.uniqueEndpoint,
- maxConnections:maxConnections,
- enabled:true
- };
- elInfo.el._jsPlumbTarget = _def;
- this.targetEndpointDefinitions[elid] = _def;
- var _drop = p._jsPlumb.EndpointDropHandler({
-
- jsPlumb: _currentInstance,
- enabled:function() {
- return elInfo.el._jsPlumbTarget.enabled;
- },
- isFull:function(originalEvent) {
- var targetCount = _currentInstance.select({target:elid}).length;
- var def = elInfo.el._jsPlumbTarget;
- var full = def.maxConnections > 0 && targetCount >= def.maxConnections;
- if (full && onMaxConnections) {
-
-
- onMaxConnections({
- element:elInfo.el,
- connection:jpc
- }, originalEvent);
- }
- return full;
- },
- element:elInfo.el,
- elementId:elid,
- isSource:false,
- isTarget:true,
- addClass:function(clazz) {
-
- _currentInstance.addClass(elInfo.el, clazz);
- },
- removeClass:function(clazz) {
-
- _currentInstance.removeClass(elInfo.el, clazz);
- },
- onDrop:function(jpc) {
- var source = jpc.endpoints[0];
- source.anchor.locked = false;
- },
- isDropAllowed:function() {
- return proxyComponent.isDropAllowed.apply(proxyComponent, arguments);
- },
- getEndpoint:function(jpc) {
-
-
- var _el = _currentInstance.getElementObject(elInfo.el),
- def = elInfo.el._jsPlumbTarget,
- newEndpoint = def.endpoint;
-
-
- if (newEndpoint == null || newEndpoint._jsPlumb == null)
- newEndpoint = _currentInstance.addEndpoint(_el, p);
- if (p.uniqueEndpoint) def.endpoint = newEndpoint;
-
- newEndpoint._doNotDeleteOnDetach = false;
- newEndpoint._deleteOnDetach = true;
-
- if (jpc.isDetachable())
- newEndpoint.initDraggable();
-
-
- if (newEndpoint.anchor.positionFinder != null) {
- var dropPosition = _currentInstance.getUIPosition(arguments, this.getZoom()),
- elPosition = _getOffset(_el, this),
- elSize = _currentInstance.getSize(_el),
- ap = newEndpoint.anchor.positionFinder(dropPosition, elPosition, elSize, newEndpoint.anchor.constructorParams);
- newEndpoint.anchor.x = ap[0];
- newEndpoint.anchor.y = ap[1];
-
-
-
-
-
- }
- return newEndpoint;
- }
- });
-
-
- var dropEvent = jsPlumb.dragEvents.drop;
- dropOptions.scope = dropOptions.scope || targetScope;
- dropOptions[dropEvent] = _ju.wrap(dropOptions[dropEvent], _drop);
-
- if (p.allowLoopback === false) {
- dropOptions.canDrop = function(_drag) {
- var de = _drag.getDragElement()._jsPlumbRelatedElement;
- return de != elInfo.el;
- };
- }
- this.initDroppable(this.getElementObject(elInfo.el), dropOptions, "internal");
- }.bind(this);
-
- var inputs = el.length && el.constructor != String ? el : [ el ];
-
-
- for (var i = 0, ii = inputs.length; i < ii; i++) {
- _doOne(inputs[i]);
- }
- return this;
- };
-
- this.unmakeTarget = function(el, doNotClearArrays) {
- var info = _info(el);
- jsPlumb.destroyDroppable(info.el);
-
-
- if (!doNotClearArrays) {
- delete this.targetEndpointDefinitions[info.id];
- }
- return this;
- };
-
- this.makeSource = function(el, params, referenceParams) {
- var p = jsPlumb.extend({}, referenceParams);
- jsPlumb.extend(p, params);
- _setEndpointPaintStylesAndAnchor(p, 0, this);
- var maxConnections = p.maxConnections || 1,
- onMaxConnections = p.onMaxConnections,
- _doOne = function(elInfo) {
-
-
- var elid = elInfo.id,
- _el = this.getElementObject(elInfo.el),
- _del = this.getDOMElement(_el),
- parentElement = function() {
- return p.parent == null ? null : p.parent === "parent" ? elInfo.el.parentNode : _currentInstance.getDOMElement(p.parent);
- },
- idToRegisterAgainst = p.parent != null ? this.getId(parentElement()) : elid;
- _ensureContainer(idToRegisterAgainst);
-
- this.sourceEndpointDefinitions[idToRegisterAgainst] = {
- def:p,
- uniqueEndpoint:p.uniqueEndpoint,
- maxConnections:maxConnections,
- enabled:true
- };
- var stopEvent = jsPlumb.dragEvents.stop,
- dragEvent = jsPlumb.dragEvents.drag,
- dragOptions = jsPlumb.extend({ }, p.dragOptions || {}),
- existingDrag = dragOptions.drag,
- existingStop = dragOptions.stop,
- ep = null,
- endpointAddedButNoDragYet = false;
-
- dragOptions.scope = dragOptions.scope || p.scope;
- dragOptions[dragEvent] = _ju.wrap(dragOptions[dragEvent], function() {
- if (existingDrag) existingDrag.apply(this, arguments);
- endpointAddedButNoDragYet = false;
- });
-
- dragOptions[stopEvent] = _ju.wrap(dragOptions[stopEvent], function() {
- if (existingStop) existingStop.apply(this, arguments);
- this.currentlyDragging = false;
- if (ep._jsPlumb != null) {
-
-
-
-
- var anchorDef = p.anchor || this.Defaults.Anchor,
- oldAnchor = ep.anchor,
- oldConnection = ep.connections[0],
- newAnchor = this.makeAnchor(anchorDef, elid, this),
- _el = ep.element;
-
-
- if (newAnchor.positionFinder != null) {
- var elPosition = _getOffset(_el, this),
- elSize = this.getSize(_el),
- dropPosition = { left:elPosition.left + (oldAnchor.x * elSize[0]), top:elPosition.top + (oldAnchor.y * elSize[1]) },
- ap = newAnchor.positionFinder(dropPosition, elPosition, elSize, newAnchor.constructorParams);
- newAnchor.x = ap[0];
- newAnchor.y = ap[1];
- }
- ep.setAnchor(newAnchor, true);
-
- if (p.parent) {
- var parent = parentElement();
- if (parent) {
- var potentialParent = p.container || _container;
- ep.setElement(parent, potentialParent);
- }
- }
-
- ep.repaint();
- this.repaint(ep.elementId);
- this.repaint(oldConnection.targetId);
- }
- }.bind(this));
-
-
- var mouseDownListener = function(e) {
- var evt = this.getOriginalEvent(e);
-
- if (e.which === 3 || e.button === 2) return;
- var def = this.sourceEndpointDefinitions[idToRegisterAgainst];
- elid = this.getId(this.getDOMElement(_el));
-
-
- if (!def.enabled) return;
-
-
- if (p.filter) {
- var r = jsPlumbUtil.isString(p.filter) ? selectorFilter(evt, _el, p.filter, this, p.filterExclude) : p.filter(evt, _el);
- if (r === false) return;
- }
-
-
- var sourceCount = this.select({source:idToRegisterAgainst}).length;
- if (def.maxConnections >= 0 && (def.uniqueEndpoint && sourceCount >= def.maxConnections)) {
- if (onMaxConnections) {
- onMaxConnections({
- element:_el,
- maxConnections:maxConnections
- }, e);
- }
- return false;
- }
-
-
- var elxy = jsPlumbAdapter.getPositionOnElement(evt, _del, _zoom), pelxy = elxy;
-
-
-
- var tempEndpointParams = {};
- jsPlumb.extend(tempEndpointParams, p);
- tempEndpointParams.isTemporarySource = true;
- tempEndpointParams.anchor = [ elxy[0], elxy[1] , 0,0];
- tempEndpointParams.dragOptions = dragOptions;
- ep = this.addEndpoint(elid, tempEndpointParams);
- endpointAddedButNoDragYet = true;
- ep.endpointWillMoveTo = p.parent ? parentElement() : null;
-
-
-
- if (def.uniqueEndpoint) {
- if (!def.endpoint)
- def.endpoint = ep;
- else
- ep.finalEndpoint = def.endpoint;
- }
-
- ep._doNotDeleteOnDetach = false;
- ep._deleteOnDetach = true;
- var _delTempEndpoint = function() {
-
-
-
-
- _currentInstance.off(ep.canvas, "mouseup", _delTempEndpoint);
- _currentInstance.off(_el, "mouseup", _delTempEndpoint);
- if(endpointAddedButNoDragYet) {
- endpointAddedButNoDragYet = false;
- _currentInstance.deleteEndpoint(ep);
- }
- };
- _currentInstance.on(ep.canvas, "mouseup", _delTempEndpoint);
- _currentInstance.on(_el, "mouseup", _delTempEndpoint);
-
-
-
- _currentInstance.trigger(ep.canvas, "mousedown", e);
- jsPlumbUtil.consume(e);
-
- }.bind(this);
-
- this.on(_el, "mousedown", mouseDownListener);
- this.sourceEndpointDefinitions[idToRegisterAgainst].trigger = mouseDownListener;
-
-
-
- if (p.filter && jsPlumbUtil.isString(p.filter)) {
- _currentInstance.setDragFilter(_el, p.filter);
- }
- }.bind(this);
-
- var inputs = el.length && el.constructor != String ? el : [ el ];
- for (var i = 0, ii = inputs.length; i < ii; i++) {
- _doOne(_info(inputs[i]));
- }
- return this;
- };
-
-
- this.unmakeSource = function(el, doNotClearArrays) {
- var info = _info(el),
- mouseDownListener = this.sourceEndpointDefinitions[info.id].trigger;
-
- if (mouseDownListener)
- _currentInstance.off(info.el, "mousedown", mouseDownListener);
- if (!doNotClearArrays) {
- delete this.sourceEndpointDefinitions[info.id];
- }
- return this;
- };
-
- this.unmakeEverySource = function() {
- for (var i in this.sourceEndpointDefinitions)
- _currentInstance.unmakeSource(i, true);
- this.sourceEndpointDefinitions = {};
- return this;
- };
- var _getScope = function(el, types) {
- types = jsPlumbUtil.isArray(types) ? types : [ types ];
- var id = _getId(el);
- for (var i = 0; i < types.length; i++) {
- var def = this[types[i]][id];
- if (def) return def.def.scope || this.Defaults.Scope;
- }
- }.bind(this);
- var _setScope = function(el, scope, types) {
- types = jsPlumbUtil.isArray(types) ? types : [ types ];
- var id = _getId(el);
- for (var i = 0; i < types.length; i++) {
- var def = this[types[i]][id];
- if (def) {
- def.def.scope = scope;
- if (this.scopeChange != null) this.scopeChange(el, id, endpointsByElement[id], scope, types[i]);
- }
- }
- }.bind(this);
- this.getScope = function(el, scope) { return _getScope(el, [ "sourceEndpointDefinitions", "targetEndpointDefinitions" ]); };
- this.getSourceScope = function(el) { return _getScope(el, "sourceEndpointDefinitions"); };
- this.getTargetScope = function(el) { return _getScope(el, "targetEndpointDefinitions"); };
- this.setScope = function(el, scope) { _setScope(el, scope, [ "sourceEndpointDefinitions", "targetEndpointDefinitions" ]); };
- this.setSourceScope = function(el, scope) { _setScope(el, scope, "sourceEndpointDefinitions"); };
- this.setTargetScope = function(el, scope) { _setScope(el, scope, "targetEndpointDefinitions"); };
-
-
- this.unmakeEveryTarget = function() {
- for (var i in this.targetEndpointDefinitions)
- _currentInstance.unmakeTarget(i, true);
-
- this.targetEndpointDefinitions = {};
- return this;
- };
-
- var _setEnabled = function(type, el, state, toggle) {
- var a = type == "source" ? this.sourceEndpointDefinitions : this.targetEndpointDefinitions;
- if (_ju.isString(el)) a[el].enabled = toggle ? !a[el].enabled : state;
- else if (el.length) {
- for (var i = 0, ii = el.length; i < ii; i++) {
- var info = _info(el[i]);
- if (a[info.id])
- a[info.id].enabled = toggle ? !a[info.id].enabled : state;
- }
- }
-
- else {
- var id = _info(el).id;
- a[id].enabled = toggle ? !a[id].enabled : state;
- }
- return this;
- }.bind(this);
-
- var _first = function(el, fn) {
- if (_ju.isString(el) || !el.length)
- return fn.apply(this, [ el ]);
- else if (el.length)
- return fn.apply(this, [ el[0] ]);
-
- }.bind(this);
- this.toggleSourceEnabled = function(el) {
- _setEnabled("source", el, null, true);
- return this.isSourceEnabled(el);
- };
- this.setSourceEnabled = function(el, state) { return _setEnabled("source", el, state); };
- this.isSource = function(el) {
- return _first(el, function(_el) {
- return this.sourceEndpointDefinitions[_info(_el).id] != null;
- }.bind(this));
- };
- this.isSourceEnabled = function(el) {
- return _first(el, function(_el) {
- var sep = this.sourceEndpointDefinitions[_info(_el).id];
- return sep && sep.enabled === true;
- }.bind(this));
- };
- this.toggleTargetEnabled = function(el) {
- _setEnabled("target", el, null, true);
- return this.isTargetEnabled(el);
- };
-
- this.isTarget = function(el) {
- return _first(el, function(_el) {
- return this.targetEndpointDefinitions[_info(_el).id] != null;
- }.bind(this));
- };
- this.isTargetEnabled = function(el) {
- return _first(el, function(_el) {
- var tep = this.targetEndpointDefinitions[_info(_el).id];
- return tep && tep.enabled === true;
- }.bind(this));
- };
- this.setTargetEnabled = function(el, state) { return _setEnabled("target", el, state); };
-
- this.ready = function(fn) {
- _currentInstance.bind("ready", fn);
- };
-
- this.repaint = function(el, ui, timestamp) {
-
- if (typeof el == 'object' && el.length)
- for ( var i = 0, ii = el.length; i < ii; i++) {
- _draw(el[i], ui, timestamp);
- }
- else
- _draw(el, ui, timestamp);
-
- return _currentInstance;
- };
- this.revalidate = function(el) {
- var elId = _currentInstance.getId(el);
- _currentInstance.updateOffset( { elId : elId, recalc : true } );
- return _currentInstance.repaint(el);
- };
-
- this.repaintEverything = function(clearEdits) {
-
-
-
-
- var timestamp = _timestamp(), elId;
- for (elId in endpointsByElement) {
- _currentInstance.updateOffset( { elId : elId, recalc : true, timestamp:timestamp } );
- }
- for (elId in endpointsByElement) {
- _draw(elId, null, timestamp, clearEdits);
- }
- return this;
- };
- this.removeAllEndpoints = function(el, recurse) {
- var _one = function(_el) {
- var info = _info(_el),
- ebe = endpointsByElement[info.id],
- i, ii;
- if (ebe) {
- for ( i = 0, ii = ebe.length; i < ii; i++)
- _currentInstance.deleteEndpoint(ebe[i]);
- }
- delete endpointsByElement[info.id];
-
- if (recurse) {
- if (info.el && info.el.nodeType != 3 && info.el.nodeType != 8 ) {
- for ( i = 0, ii = info.el.childNodes.length; i < ii; i++) {
- _one(info.el.childNodes[i]);
- }
- }
- }
-
- };
- _one(el);
- return this;
- };
-
-
- this.remove = function(el, doNotRepaint) {
- var info = _info(el);
- _currentInstance.doWhileSuspended(function() {
- _currentInstance.removeAllEndpoints(info.id, true);
- _currentInstance.dragManager.elementRemoved(info.id);
- delete _currentInstance.floatingConnections[info.id];
- _currentInstance.anchorManager.clearFor(info.id);
- _currentInstance.anchorManager.removeFloatingConnection(info.id);
- }, doNotRepaint === false);
- _unmanage(info.id);
- if (info.el){
- _currentInstance.removeElement(info.el);
- info.el._jsPlumb = null;
- }
- return _currentInstance;
- };
-
- this.reset = function() {
- _currentInstance.setSuspendEvents(true);
- _currentInstance.deleteEveryEndpoint();
- _currentInstance.unbind();
- this.targetEndpointDefinitions = {};
- this.sourceEndpointDefinitions = {};
- connections.length = 0;
- _currentInstance.setSuspendEvents(false);
- };
- var _clearObject = function(obj) {
- if(obj.canvas && obj.canvas.parentNode)
- obj.canvas.parentNode.removeChild(obj.canvas);
- obj.cleanup();
- obj.destroy();
- };
- var _clearOverlayObject = function(obj) {
- _clearObject(obj);
- };
- this.clear = function() {
- _currentInstance.select().each(_clearOverlayObject);
- _currentInstance.selectEndpoints().each(_clearOverlayObject);
- endpointsByElement = {};
- endpointsByUUID = {};
- };
- this.setDefaultScope = function(scope) {
- DEFAULT_SCOPE = scope;
- return _currentInstance;
- };
-
- this.setDraggable = _setDraggable;
-
- this.setId = function(el, newId, doNotSetAttribute) {
-
- var id;
- if (jsPlumbUtil.isString(el)) {
- id = el;
- }
- else {
- el = this.getDOMElement(el);
- id = this.getId(el);
- }
- var sConns = this.getConnections({source:id, scope:'*'}, true),
- tConns = this.getConnections({target:id, scope:'*'}, true);
- newId = "" + newId;
- if (!doNotSetAttribute) {
- el = this.getDOMElement(id);
- this.setAttribute(el, "id", newId);
- }
- else
- el = this.getDOMElement(newId);
- endpointsByElement[newId] = endpointsByElement[id] || [];
- for (var i = 0, ii = endpointsByElement[newId].length; i < ii; i++) {
- endpointsByElement[newId][i].setElementId(newId);
- endpointsByElement[newId][i].setReferenceElement(el);
- }
- delete endpointsByElement[id];
- this.anchorManager.changeId(id, newId);
- if (this.dragManager) this.dragManager.changeId(id, newId);
- managedElements[newId] = managedElements[id];
- delete managedElements[id];
- var _conns = function(list, epIdx, type) {
- for (var i = 0, ii = list.length; i < ii; i++) {
- list[i].endpoints[epIdx].setElementId(newId);
- list[i].endpoints[epIdx].setReferenceElement(el);
- list[i][type + "Id"] = newId;
- list[i][type] = el;
- }
- };
- _conns(sConns, 0, "source");
- _conns(tConns, 1, "target");
- this.repaint(newId);
- };
- this.setDebugLog = function(debugLog) {
- log = debugLog;
- };
- this.setSuspendDrawing = function(val, repaintAfterwards) {
- var curVal = _suspendDrawing;
- _suspendDrawing = val;
- if (val) _suspendedAt = new Date().getTime(); else _suspendedAt = null;
- if (repaintAfterwards) this.repaintEverything();
- return curVal;
- };
-
- this.isSuspendDrawing = function() {
- return _suspendDrawing;
- };
-
- this.getSuspendedAt = function() { return _suspendedAt; };
- this.doWhileSuspended = function(fn, doNotRepaintAfterwards) {
- var _wasSuspended = this.isSuspendDrawing();
- if (!_wasSuspended)
- this.setSuspendDrawing(true);
- try {
- fn();
- }
- catch (e) {
- _ju.log("Function run while suspended failed", e);
- }
- if (!_wasSuspended)
- this.setSuspendDrawing(false, !doNotRepaintAfterwards);
- };
- this.getOffset = function(elId) { return offsets[elId]; };
- this.getCachedData = _getCachedData;
- this.timestamp = _timestamp;
- this.setRenderMode = function(mode) {
- if (mode !== jsPlumb.SVG && mode !== jsPlumb.VML) throw new TypeError("Render mode [" + mode + "] not supported");
- renderMode = jsPlumbAdapter.setRenderMode(mode);
- return renderMode;
- };
- this.getRenderMode = function() { return renderMode; };
- this.show = function(el, changeEndpoints) {
- _setVisible(el, "block", changeEndpoints);
- return _currentInstance;
- };
-
- this.toggleVisible = _toggleVisible;
- this.toggleDraggable = _toggleDraggable;
- this.addListener = this.bind;
- if (!jsPlumbAdapter.headless) {
- _currentInstance.dragManager = jsPlumbAdapter.getDragManager(_currentInstance);
- _currentInstance.recalculateOffsets = _currentInstance.dragManager.updateOffsets;
- }
- };
- jsPlumbUtil.extend(jsPlumbInstance, jsPlumbUtil.EventGenerator, {
- setAttribute : function(el, a, v) {
- this.setAttribute(el, a, v);
- },
- getAttribute : function(el, a) {
- return this.getAttribute(jsPlumb.getDOMElement(el), a);
- },
- registerConnectionType : function(id, type) {
- this._connectionTypes[id] = jsPlumb.extend({}, type);
- },
- registerConnectionTypes : function(types) {
- for (var i in types)
- this._connectionTypes[i] = jsPlumb.extend({}, types[i]);
- },
- registerEndpointType : function(id, type) {
- this._endpointTypes[id] = jsPlumb.extend({}, type);
- },
- registerEndpointTypes : function(types) {
- for (var i in types)
- this._endpointTypes[i] = jsPlumb.extend({}, types[i]);
- },
- getType : function(id, typeDescriptor) {
- return typeDescriptor === "connection" ? this._connectionTypes[id] : this._endpointTypes[id];
- },
- setIdChanged : function(oldId, newId) {
- this.setId(oldId, newId, true);
- },
-
- setParent : function(el, newParent) {
- var _el = this.getElementObject(el),
- _dom = this.getDOMElement(_el),
- _id = this.getId(_dom),
- _pel = this.getElementObject(newParent),
- _pdom = this.getDOMElement(_pel),
- _pid = this.getId(_pdom);
- _dom.parentNode.removeChild(_dom);
- _pdom.appendChild(_dom);
- this.dragManager.setParent(_el, _id, _pel, _pid);
- },
-
- getSize : function(el) {
- return [ el.offsetWidth, el.offsetHeight ];
- },
- getWidth : function(el) {
- return el.offsetWidth;
- },
- getHeight : function(el) {
- return el.offsetHeight;
- },
- extend : function(o1, o2, names) {
- var i;
- if (names) {
- for (i = 0; i < names.length; i++)
- o1[names[i]] = o2[names[i]];
- }
- else
- for (i in o2) o1[i] = o2[i];
- return o1;
- },
- floatingConnections:{},
- getFloatingAnchorIndex : function(jpc) {
- return jpc.endpoints[0].isFloating() ? 0 : 1;
- }
- }, jsPlumbAdapter);
-
- var jsPlumb = new jsPlumbInstance();
-
- if (typeof window != 'undefined') window.jsPlumb = jsPlumb;
-
- jsPlumb.getInstance = function(_defaults) {
- var j = new jsPlumbInstance(_defaults);
- j.init();
- return j;
- };
- if ( typeof define === "function") {
- define( "jsplumb", [], function () { return jsPlumb; } );
- define( "jsplumbinstance", [], function () { return jsPlumb.getInstance(); } );
- }
-
- if (typeof exports !== 'undefined') {
- exports.jsPlumb = jsPlumb;
- }
-
-
-
- })();
- ;(function() {
-
- "use strict";
-
-
- var _makeConnectionDragHandler = function(placeholder, _jsPlumb) {
- var stopped = false;
- return {
- drag : function() {
- if (stopped) {
- stopped = false;
- return true;
- }
- var _ui = jsPlumb.getUIPosition(arguments, _jsPlumb.getZoom());
-
- if (placeholder.element) {
- jsPlumbAdapter.setPosition(placeholder.element, _ui);
- _jsPlumb.repaint(placeholder.element, _ui);
- }
- },
- stopDrag : function() {
- stopped = true;
- }
- };
- };
-
-
- var _makeDraggablePlaceholder = function(placeholder, _jsPlumb) {
- var n = document.createElement("div");
- n.style.position = "absolute";
- var parent = _jsPlumb.getContainer() || document.body;
- parent.appendChild(n);
- var id = _jsPlumb.getId(n);
-
- _jsPlumb.manage( id, n );
-
- placeholder.id = id;
- placeholder.element = n;
- };
-
-
- var _makeFloatingEndpoint = function(paintStyle, referenceAnchor, endpoint, referenceCanvas, sourceElement, _jsPlumb, _newEndpoint, scope) {
- var floatingAnchor = new jsPlumb.FloatingAnchor( { reference : referenceAnchor, referenceCanvas : referenceCanvas, jsPlumbInstance:_jsPlumb });
-
-
- return _newEndpoint({ paintStyle : paintStyle, endpoint : endpoint, anchor : floatingAnchor, source : sourceElement, scope:scope });
- };
- var typeParameters = [ "connectorStyle", "connectorHoverStyle", "connectorOverlays",
- "connector", "connectionType", "connectorClass", "connectorHoverClass" ];
-
-
- var findConnectionToUseForDynamicAnchor = function(ep, elementWithPrecedence) {
- var idx = 0;
- if (elementWithPrecedence != null) {
- for (var i = 0; i < ep.connections.length; i++) {
- if (ep.connections[i].sourceId == elementWithPrecedence || ep.connections[i].targetId == elementWithPrecedence) {
- idx = i;
- break;
- }
- }
- }
-
- return ep.connections[idx];
- };
- var findConnectionIndex = function(conn, ep) {
- return jsPlumbUtil.findWithFunction(ep.connections, function(c) { return c.id == conn.id; });
- };
- jsPlumb.Endpoint = function(params) {
- var _jsPlumb = params._jsPlumb,
- _gel = jsPlumb.getElementObject,
- _ju = jsPlumbUtil,
- _newConnection = params.newConnection,
- _newEndpoint = params.newEndpoint,
- _finaliseConnection = params.finaliseConnection,
- _fireMoveEvent = params.fireMoveEvent;
-
- this.idPrefix = "_jsplumb_e_";
- this.defaultLabelLocation = [ 0.5, 0.5 ];
- this.defaultOverlayKeys = ["Overlays", "EndpointOverlays"];
- OverlayCapableJsPlumbUIComponent.apply(this, arguments);
-
-
- this.getDefaultType = function() {
- return {
- parameters:{},
- scope:null,
- maxConnections:this._jsPlumb.instance.Defaults.MaxConnections,
- paintStyle:this._jsPlumb.instance.Defaults.EndpointStyle || jsPlumb.Defaults.EndpointStyle,
- endpoint:this._jsPlumb.instance.Defaults.Endpoint || jsPlumb.Defaults.Endpoint,
- hoverPaintStyle:this._jsPlumb.instance.Defaults.EndpointHoverStyle || jsPlumb.Defaults.EndpointHoverStyle,
- overlays:this._jsPlumb.instance.Defaults.EndpointOverlays || jsPlumb.Defaults.EndpointOverlays,
- connectorStyle:params.connectorStyle,
- connectorHoverStyle:params.connectorHoverStyle,
- connectorClass:params.connectorClass,
- connectorHoverClass:params.connectorHoverClass,
- connectorOverlays:params.connectorOverlays,
- connector:params.connector,
- connectorTooltip:params.connectorTooltip
- };
- };
-
-
- this._jsPlumb.enabled = !(params.enabled === false);
- this._jsPlumb.visible = true;
- this.element = jsPlumb.getDOMElement(params.source);
- this._jsPlumb.uuid = params.uuid;
- this._jsPlumb.floatingEndpoint = null;
- var inPlaceCopy = null;
- if (this._jsPlumb.uuid) params.endpointsByUUID[this._jsPlumb.uuid] = this;
- this.elementId = params.elementId;
-
- this._jsPlumb.connectionCost = params.connectionCost;
- this._jsPlumb.connectionsDirected = params.connectionsDirected;
- this._jsPlumb.currentAnchorClass = "";
- this._jsPlumb.events = {};
-
- var _updateAnchorClass = function() {
-
- var oldAnchorClass = this._jsPlumb.currentAnchorClass;
- this._jsPlumb.currentAnchorClass = this.anchor.getCssClass();
-
- jsPlumbAdapter.updateClasses(this.element, _jsPlumb.endpointAnchorClassPrefix + "_" + this._jsPlumb.currentAnchorClass, _jsPlumb.endpointAnchorClassPrefix + "_" + oldAnchorClass);
- this.updateClasses(_jsPlumb.endpointAnchorClassPrefix + "_" + this._jsPlumb.currentAnchorClass, _jsPlumb.endpointAnchorClassPrefix + "_" + oldAnchorClass);
- }.bind(this);
-
- this.setAnchor = function(anchorParams, doNotRepaint) {
- this._jsPlumb.instance.continuousAnchorFactory.clear(this.elementId);
- this.anchor = this._jsPlumb.instance.makeAnchor(anchorParams, this.elementId, _jsPlumb);
- _updateAnchorClass();
- this.anchor.bind("anchorChanged", function(currentAnchor) {
- this.fire("anchorChanged", {endpoint:this, anchor:currentAnchor});
- _updateAnchorClass();
- }.bind(this));
- if (!doNotRepaint)
- this._jsPlumb.instance.repaint(this.elementId);
- return this;
- };
- var anchorParamsToUse = params.anchor ? params.anchor : params.anchors ? params.anchors : (_jsPlumb.Defaults.Anchor || "Top");
- this.setAnchor(anchorParamsToUse, true);
- var internalHover = function(state) {
- if (this.connections.length > 0) {
- for (var i = 0; i < this.connections.length; i++)
- this.connections[i].setHover(state, false);
- }
- else
- this.setHover(state);
- }.bind(this);
- this.bind("mouseover", function() { internalHover(true); });
- this.bind("mouseout", function() { internalHover(false); });
-
-
- if (!params._transient)
- this._jsPlumb.instance.anchorManager.add(this, this.elementId);
-
- this.setEndpoint = function(ep) {
- if (this.endpoint != null) {
- this.endpoint.cleanup();
- this.endpoint.destroy();
- }
- var _e = function(t, p) {
- var rm = _jsPlumb.getRenderMode();
- if (jsPlumb.Endpoints[rm][t]) return new jsPlumb.Endpoints[rm][t](p);
- if (!_jsPlumb.Defaults.DoNotThrowErrors)
- throw { msg:"jsPlumb: unknown endpoint type '" + t + "'" };
- };
- var endpointArgs = {
- _jsPlumb:this._jsPlumb.instance,
- cssClass:params.cssClass,
- container:params.container,
- tooltip:params.tooltip,
- connectorTooltip:params.connectorTooltip,
- endpoint:this
- };
- if (_ju.isString(ep))
- this.endpoint = _e(ep, endpointArgs);
- else if (_ju.isArray(ep)) {
- endpointArgs = _ju.merge(ep[1], endpointArgs);
- this.endpoint = _e(ep[0], endpointArgs);
- }
- else {
- this.endpoint = ep.clone();
- }
-
-
-
-
-
- this.endpoint.clone = function() {
-
- if (_ju.isString(ep))
- return _e(ep, endpointArgs);
- else if (_ju.isArray(ep)) {
- endpointArgs = _ju.merge(ep[1], endpointArgs);
- return _e(ep[0], endpointArgs);
- }
- }.bind(this);
- this.type = this.endpoint.type;
- };
-
- this.setEndpoint(params.endpoint || _jsPlumb.Defaults.Endpoint || jsPlumb.Defaults.Endpoint || "Dot");
- this.setPaintStyle(params.endpointStyle || params.paintStyle || params.style || _jsPlumb.Defaults.EndpointStyle || jsPlumb.Defaults.EndpointStyle, true);
- this.setHoverPaintStyle(params.endpointHoverStyle || params.hoverPaintStyle || _jsPlumb.Defaults.EndpointHoverStyle || jsPlumb.Defaults.EndpointHoverStyle, true);
- this._jsPlumb.paintStyleInUse = this.getPaintStyle();
- jsPlumb.extend(this, params, typeParameters);
- this.isSource = params.isSource || false;
- this.isTemporarySource = params.isTemporarySource || false;
- this.isTarget = params.isTarget || false;
- this._jsPlumb.maxConnections = params.maxConnections || _jsPlumb.Defaults.MaxConnections;
- this.canvas = this.endpoint.canvas;
- this.canvas._jsPlumb = this;
-
- this.addClass(_jsPlumb.endpointAnchorClassPrefix + "_" + this._jsPlumb.currentAnchorClass);
- jsPlumbAdapter.addClass(this.element, _jsPlumb.endpointAnchorClassPrefix + "_" + this._jsPlumb.currentAnchorClass);
- this.connections = params.connections || [];
- this.connectorPointerEvents = params["connector-pointer-events"];
-
- this.scope = params.scope || _jsPlumb.getDefaultScope();
- this.timestamp = null;
- this.reattachConnections = params.reattach || _jsPlumb.Defaults.ReattachConnections;
- this.connectionsDetachable = _jsPlumb.Defaults.ConnectionsDetachable;
- if (params.connectionsDetachable === false || params.detachable === false)
- this.connectionsDetachable = false;
- this.dragAllowedWhenFull = params.dragAllowedWhenFull !== false;
-
- if (params.onMaxConnections)
- this.bind("maxConnections", params.onMaxConnections);
-
-
-
-
- this.addConnection = function(connection) {
- this.connections.push(connection);
- this[(this.connections.length > 0 ? "add" : "remove") + "Class"](_jsPlumb.endpointConnectedClass);
- this[(this.isFull() ? "add" : "remove") + "Class"](_jsPlumb.endpointFullClass);
- };
- this.detachFromConnection = function(connection, idx, doNotCleanup) {
- idx = idx == null ? findConnectionIndex(connection, this) : idx;
- if (idx >= 0) {
- this.connections.splice(idx, 1);
- this[(this.connections.length > 0 ? "add" : "remove") + "Class"](_jsPlumb.endpointConnectedClass);
- this[(this.isFull() ? "add" : "remove") + "Class"](_jsPlumb.endpointFullClass);
- }
-
- if (!doNotCleanup && this._deleteOnDetach && this.connections.length === 0) {
- _jsPlumb.deleteObject({
- endpoint:this,
- fireEvent:false,
- deleteAttachedObjects:false
- });
- }
- };
- this.detach = function(connection, ignoreTarget, forceDetach, fireEvent, originalEvent, endpointBeingDeleted, connectionIndex) {
- var idx = connectionIndex == null ? findConnectionIndex(connection, this) : connectionIndex,
- actuallyDetached = false;
- fireEvent = (fireEvent !== false);
- if (idx >= 0) {
- if (forceDetach || connection._forceDetach || (connection.isDetachable() && connection.isDetachAllowed(connection) && this.isDetachAllowed(connection) && _jsPlumb.checkCondition("beforeDetach", connection) )) {
- _jsPlumb.deleteObject({
- connection:connection,
- fireEvent:(!ignoreTarget && fireEvent),
- originalEvent:originalEvent,
- deleteAttachedObjects:false
- });
- actuallyDetached = true;
- }
- }
- return actuallyDetached;
- };
- this.detachAll = function(fireEvent, originalEvent) {
- while (this.connections.length > 0) {
-
- this.detach(this.connections[0], false, true, fireEvent !== false, originalEvent, this, 0);
- }
- return this;
- };
- this.detachFrom = function(targetEndpoint, fireEvent, originalEvent) {
- var c = [];
- for ( var i = 0; i < this.connections.length; i++) {
- if (this.connections[i].endpoints[1] == targetEndpoint || this.connections[i].endpoints[0] == targetEndpoint) {
- c.push(this.connections[i]);
- }
- }
- for ( var j = 0; j < c.length; j++) {
- this.detach(c[j], false, true, fireEvent, originalEvent);
- }
- return this;
- };
-
- this.getElement = function() {
- return this.element;
- };
-
- this.setElement = function(el) {
- var parentId = this._jsPlumb.instance.getId(el),
- curId = this.elementId;
-
- _ju.removeWithFunction(params.endpointsByElement[this.elementId], function(e) {
- return e.id == this.id;
- }.bind(this));
- this.element = jsPlumb.getDOMElement(el);
- this.elementId = _jsPlumb.getId(this.element);
- _jsPlumb.anchorManager.rehomeEndpoint(this, curId, this.element);
- _jsPlumb.dragManager.endpointAdded(this.element);
- _ju.addToList(params.endpointsByElement, parentId, this);
- return this;
- };
-
-
- this.makeInPlaceCopy = function() {
- var loc = this.anchor.getCurrentLocation({element:this}),
- o = this.anchor.getOrientation(this),
- acc = this.anchor.getCssClass(),
- inPlaceAnchor = {
- bind:function() { },
- compute:function() { return [ loc[0], loc[1] ]; },
- getCurrentLocation : function() { return [ loc[0], loc[1] ]; },
- getOrientation:function() { return o; },
- getCssClass:function() { return acc; }
- };
- return _newEndpoint( {
- dropOptions:params.dropOptions,
- anchor : inPlaceAnchor,
- source : this.element,
- paintStyle : this.getPaintStyle(),
- endpoint : params.hideOnDrag ? "Blank" : this.endpoint,
- _transient:true,
- scope:this.scope
- });
- };
-
-
- this.connectorSelector = function() {
- var candidate = this.connections[0];
- if (this.isTarget && candidate) return candidate;
- else {
- return (this.connections.length < this._jsPlumb.maxConnections) || this._jsPlumb.maxConnections == -1 ? null : candidate;
- }
- };
-
- this.setStyle = this.setPaintStyle;
-
- this.paint = function(params) {
- params = params || {};
- var timestamp = params.timestamp, recalc = !(params.recalc === false);
- if (!timestamp || this.timestamp !== timestamp) {
- var info = _jsPlumb.updateOffset({ elId:this.elementId, timestamp:timestamp });
- var xy = params.offset ? params.offset.o : info.o;
- if(xy != null) {
- var ap = params.anchorPoint,connectorPaintStyle = params.connectorPaintStyle;
- if (ap == null) {
- var wh = params.dimensions || info.s,
- anchorParams = { xy : [ xy.left, xy.top ], wh : wh, element : this, timestamp : timestamp };
- if (recalc && this.anchor.isDynamic && this.connections.length > 0) {
- var c = findConnectionToUseForDynamicAnchor(this, params.elementWithPrecedence),
- oIdx = c.endpoints[0] == this ? 1 : 0,
- oId = oIdx === 0 ? c.sourceId : c.targetId,
- oInfo = _jsPlumb.getCachedData(oId),
- oOffset = oInfo.o, oWH = oInfo.s;
- anchorParams.txy = [ oOffset.left, oOffset.top ];
- anchorParams.twh = oWH;
- anchorParams.tElement = c.endpoints[oIdx];
- }
- ap = this.anchor.compute(anchorParams);
- }
-
- this.endpoint.compute(ap, this.anchor.getOrientation(this), this._jsPlumb.paintStyleInUse, connectorPaintStyle || this.paintStyleInUse);
- this.endpoint.paint(this._jsPlumb.paintStyleInUse, this.anchor);
- this.timestamp = timestamp;
-
- for ( var i = 0; i < this._jsPlumb.overlays.length; i++) {
- var o = this._jsPlumb.overlays[i];
- if (o.isVisible()) {
- this._jsPlumb.overlayPlacements[i] = o.draw(this.endpoint, this._jsPlumb.paintStyleInUse);
- o.paint(this._jsPlumb.overlayPlacements[i]);
- }
- }
- }
- }
- };
- this.repaint = this.paint;
- var draggingInitialised = false;
- this.initDraggable = function() {
-
-
- if (!draggingInitialised && jsPlumb.isDragSupported(this.element)) {
- var placeholderInfo = { id:null, element:null },
- jpc = null,
- existingJpc = false,
- existingJpcParams = null,
- _dragHandler = _makeConnectionDragHandler(placeholderInfo, _jsPlumb),
- dragOptions = params.dragOptions || {},
- defaultOpts = {},
- startEvent = jsPlumb.dragEvents.start,
- stopEvent = jsPlumb.dragEvents.stop,
- dragEvent = jsPlumb.dragEvents.drag;
- var start = function() {
-
-
- jpc = this.connectorSelector();
- var _continue = true;
-
- if (!this.isEnabled()) _continue = false;
-
- if (jpc == null && !this.isSource && !this.isTemporarySource) _continue = false;
-
- if (this.isSource && this.isFull() && !this.dragAllowedWhenFull) _continue = false;
-
-
-
- if (jpc != null && !jpc.isDetachable()) _continue = false;
- if (_continue === false) {
-
-
-
- if (_jsPlumb.stopDrag) _jsPlumb.stopDrag(this.canvas);
- _dragHandler.stopDrag();
- return false;
- }
-
- for (var i = 0; i < this.connections.length; i++)
- this.connections[i].setHover(false);
- this.addClass("endpointDrag");
- _jsPlumb.setConnectionBeingDragged(true);
-
- if (jpc && !this.isFull() && this.isSource) jpc = null;
- _jsPlumb.updateOffset( { elId : this.elementId });
- inPlaceCopy = this.makeInPlaceCopy();
- inPlaceCopy.referenceEndpoint = this;
- inPlaceCopy.paint();
-
- _makeDraggablePlaceholder(placeholderInfo, _jsPlumb);
-
-
-
-
- var ipcoel = _gel(inPlaceCopy.canvas),
- ipco = jsPlumbAdapter.getOffset(ipcoel, this._jsPlumb.instance),
- canvasElement = _gel(this.canvas);
-
- jsPlumbAdapter.setPosition(placeholderInfo.element, ipco);
-
-
-
-
- if (this.parentAnchor) this.anchor = _jsPlumb.makeAnchor(this.parentAnchor, this.elementId, _jsPlumb);
-
-
- _jsPlumb.setAttribute(this.canvas, "dragId", placeholderInfo.id);
- _jsPlumb.setAttribute(this.canvas, "elId", this.elementId);
- this._jsPlumb.floatingEndpoint = _makeFloatingEndpoint(this.getPaintStyle(), this.anchor, this.endpoint, this.canvas, placeholderInfo.element, _jsPlumb, _newEndpoint, this.scope);
-
-
- this.canvas.style.visibility = "hidden";
-
- if (jpc == null) {
- this.anchor.locked = true;
- this.setHover(false, false);
-
- jpc = _newConnection({
- sourceEndpoint : this,
- targetEndpoint : this._jsPlumb.floatingEndpoint,
- source : this.endpointWillMoveTo || this.element,
- target : placeholderInfo.element,
- anchors : [ this.anchor, this._jsPlumb.floatingEndpoint.anchor ],
- paintStyle : params.connectorStyle,
- hoverPaintStyle:params.connectorHoverStyle,
- connector : params.connector,
- overlays : params.connectorOverlays,
- type:this.connectionType,
- cssClass:this.connectorClass,
- hoverClass:this.connectorHoverClass
- });
-
- jpc.addClass(_jsPlumb.draggingClass);
- this._jsPlumb.floatingEndpoint.addClass(_jsPlumb.draggingClass);
-
- _jsPlumb.fire("connectionDrag", jpc);
- } else {
- existingJpc = true;
- jpc.setHover(false);
-
- var anchorIdx = jpc.endpoints[0].id == this.id ? 0 : 1;
- this.detachFromConnection(jpc, null, true);
-
-
- var dragScope = _jsPlumb.getDragScope(canvasElement);
- _jsPlumb.setAttribute(this.canvas, "originalScope", dragScope);
-
-
- var dropScope = _jsPlumb.getDropScope(canvasElement);
- _jsPlumb.setDragScope(canvasElement, dropScope);
-
-
-
- _jsPlumb.fire("connectionDrag", jpc);
-
-
- if (anchorIdx === 0) {
- existingJpcParams = [ jpc.source, jpc.sourceId, canvasElement, dragScope ];
- jpc.source = placeholderInfo.element;
- jpc.sourceId = placeholderInfo.id;
- } else {
- existingJpcParams = [ jpc.target, jpc.targetId, canvasElement, dragScope ];
- jpc.target = placeholderInfo.element;
- jpc.targetId = placeholderInfo.id;
- }
-
- jpc.endpoints[anchorIdx === 0 ? 1 : 0].anchor.locked = true;
-
- jpc.suspendedEndpoint = jpc.endpoints[anchorIdx];
-
-
- jpc.suspendedElement = jpc.endpoints[anchorIdx].getElement();
- jpc.suspendedElementId = jpc.endpoints[anchorIdx].elementId;
- jpc.suspendedElementType = anchorIdx === 0 ? "source" : "target";
-
- jpc.suspendedEndpoint.setHover(false);
- this._jsPlumb.floatingEndpoint.referenceEndpoint = jpc.suspendedEndpoint;
- jpc.endpoints[anchorIdx] = this._jsPlumb.floatingEndpoint;
- jpc.addClass(_jsPlumb.draggingClass);
- this._jsPlumb.floatingEndpoint.addClass(_jsPlumb.draggingClass);
- }
-
-
- _jsPlumb.floatingConnections[placeholderInfo.id] = jpc;
- _jsPlumb.anchorManager.addFloatingConnection(placeholderInfo.id, jpc);
-
-
- _ju.addToList(params.endpointsByElement, placeholderInfo.id, this._jsPlumb.floatingEndpoint);
-
- _jsPlumb.currentlyDragging = true;
- }.bind(this);
- var stop = function() {
- _jsPlumb.setConnectionBeingDragged(false);
-
- if (jpc && jpc.endpoints != null) {
-
- var originalEvent = _jsPlumb.getDropEvent(arguments);
-
- var idx = _jsPlumb.getFloatingAnchorIndex(jpc);
- jpc.endpoints[idx === 0 ? 1 : 0].anchor.locked = false;
-
- jpc.removeClass(_jsPlumb.draggingClass);
-
-
-
-
- if (this._jsPlumb && (jpc.deleteConnectionNow || jpc.endpoints[idx] == this._jsPlumb.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];
- }
- var fe = this._jsPlumb.floatingEndpoint;
-
- _jsPlumb.setDragScope(existingJpcParams[2], existingJpcParams[3]);
- jpc.endpoints[idx] = jpc.suspendedEndpoint;
-
-
- if (jpc.isReattach() || jpc._forceReattach || jpc._forceDetach || !jpc.endpoints[idx === 0 ? 1 : 0].detach(jpc, false, false, true, originalEvent)) {
- jpc.setHover(false);
- jpc._forceDetach = null;
- jpc._forceReattach = null;
- this._jsPlumb.floatingEndpoint.detachFromConnection(jpc);
- jpc.suspendedEndpoint.addConnection(jpc);
- _jsPlumb.repaint(existingJpcParams[1]);
- }
- else
- _jsPlumb.deleteObject({endpoint:fe});
- }
- }
-
-
- _jsPlumb.remove(placeholderInfo.element, false);
-
- _jsPlumb.deleteObject({endpoint:inPlaceCopy});
-
- if (this.deleteAfterDragStop) {
- _jsPlumb.deleteObject({endpoint:this});
- }
- else {
- if (this._jsPlumb) {
- this._jsPlumb.floatingEndpoint = null;
-
-
- this.canvas.style.visibility = "visible";
-
- this.anchor.locked = false;
- this.paint({recalc:false});
- }
- }
-
- _jsPlumb.fire("connectionDragStop", jpc, originalEvent);
-
- _jsPlumb.currentlyDragging = false;
- jpc = null;
- }
- }.bind(this);
- dragOptions = jsPlumb.extend(defaultOpts, dragOptions);
- dragOptions.scope = this.scope || dragOptions.scope;
- dragOptions[startEvent] = _ju.wrap(dragOptions[startEvent], start, false);
-
- dragOptions[dragEvent] = _ju.wrap(dragOptions[dragEvent], _dragHandler.drag);
- dragOptions[stopEvent] = _ju.wrap(dragOptions[stopEvent], stop);
- dragOptions.canDrag = function() {
- return this.isSource || this.isTemporarySource || (this.isTarget && this.connections.length > 0);
- }.bind(this);
- _jsPlumb.initDraggable(this.canvas, dragOptions, "internal");
- this.canvas._jsPlumbRelatedElement = this.element;
- draggingInitialised = true;
- }
- };
-
- if (this.isSource || this.isTarget || this.isTemporarySource)
- this.initDraggable();
-
-
- var _initDropTarget = function(canvas, forceInit, isTransient, endpoint) {
- if ((this.isTarget || forceInit) && jsPlumb.isDropSupported(this.element)) {
- var dropOptions = params.dropOptions || _jsPlumb.Defaults.DropOptions || jsPlumb.Defaults.DropOptions;
- dropOptions = jsPlumb.extend( {}, dropOptions);
- dropOptions.scope = dropOptions.scope || this.scope;
- var dropEvent = jsPlumb.dragEvents.drop,
- overEvent = jsPlumb.dragEvents.over,
- outEvent = jsPlumb.dragEvents.out,
- _ep = this,
- drop = _jsPlumb.EndpointDropHandler({
- getEndpoint:function() { return _ep; },
- jsPlumb:_jsPlumb,
- enabled:function() {
- return endpoint != null ? endpoint.isEnabled() : true;
- },
- isFull:function() {
- return endpoint.isFull();
- },
- element:this.element,
- elementId:this.elementId,
- isSource:this.isSource,
- isTarget:this.isTarget,
- addClass:function(clazz) {
- _ep.addClass(clazz);
- },
- removeClass:function(clazz) {
- _ep.removeClass(clazz);
- },
- isDropAllowed:function() {
- return _ep.isDropAllowed.apply(_ep, arguments);
- }
- });
-
- dropOptions[dropEvent] = _ju.wrap(dropOptions[dropEvent], drop);
- dropOptions[overEvent] = _ju.wrap(dropOptions[overEvent], function() {
- var draggable = jsPlumb.getDragObject(arguments),
- id = _jsPlumb.getAttribute(jsPlumb.getDOMElement(draggable), "dragId"),
- _jpc = _jsPlumb.floatingConnections[id];
-
- if (_jpc != null) {
- var idx = _jsPlumb.getFloatingAnchorIndex(_jpc);
-
-
- var _cont = (this.isTarget && idx !== 0) || (_jpc.suspendedEndpoint && this.referenceEndpoint && this.referenceEndpoint.id == _jpc.suspendedEndpoint.id);
- if (_cont) {
- var bb = _jsPlumb.checkCondition("checkDropAllowed", {
- sourceEndpoint:_jpc.endpoints[idx],
- targetEndpoint:this,
- connection:_jpc
- });
- this[(bb ? "add" : "remove") + "Class"](_jsPlumb.endpointDropAllowedClass);
- this[(bb ? "remove" : "add") + "Class"](_jsPlumb.endpointDropForbiddenClass);
- _jpc.endpoints[idx].anchor.over(this.anchor, this);
- }
- }
- }.bind(this));
- dropOptions[outEvent] = _ju.wrap(dropOptions[outEvent], function() {
- var draggable = jsPlumb.getDragObject(arguments),
- id = draggable == null ? null : _jsPlumb.getAttribute( jsPlumb.getDOMElement(draggable), "dragId"),
- _jpc = id? _jsPlumb.floatingConnections[id] : null;
-
- if (_jpc != null) {
- var idx = _jsPlumb.getFloatingAnchorIndex(_jpc);
- var _cont = (this.isTarget && idx !== 0) || (_jpc.suspendedEndpoint && this.referenceEndpoint && this.referenceEndpoint.id == _jpc.suspendedEndpoint.id);
- if (_cont) {
- this.removeClass(_jsPlumb.endpointDropAllowedClass);
- this.removeClass(_jsPlumb.endpointDropForbiddenClass);
- _jpc.endpoints[idx].anchor.out();
- }
- }
- }.bind(this));
- _jsPlumb.initDroppable(canvas, dropOptions, "internal", isTransient);
- }
- }.bind(this);
-
-
- if (!this.anchor.isFloating)
- _initDropTarget(_gel(this.canvas), true, !(params._transient || this.anchor.isFloating), this);
-
- if (params.type)
- this.addType(params.type, params.data, _jsPlumb.isSuspendDrawing());
- return this;
- };
- jsPlumbUtil.extend(jsPlumb.Endpoint, OverlayCapableJsPlumbUIComponent, {
- getTypeDescriptor : function() { return "endpoint"; },
- isVisible : function() { return this._jsPlumb.visible; },
- setVisible : function(v, doNotChangeConnections, doNotNotifyOtherEndpoint) {
- this._jsPlumb.visible = v;
- if (this.canvas) this.canvas.style.display = v ? "block" : "none";
- this[v ? "showOverlays" : "hideOverlays"]();
- if (!doNotChangeConnections) {
- for (var i = 0; i < this.connections.length; i++) {
- this.connections[i].setVisible(v);
- if (!doNotNotifyOtherEndpoint) {
- var oIdx = this === this.connections[i].endpoints[0] ? 1 : 0;
-
- if (this.connections[i].endpoints[oIdx].connections.length == 1) this.connections[i].endpoints[oIdx].setVisible(v, true, true);
- }
- }
- }
- },
- getAttachedElements : function() {
- return this.connections;
- },
- applyType : function(t) {
- this.setPaintStyle(t.endpointStyle || t.paintStyle);
- this.setHoverPaintStyle(t.endpointHoverStyle || t.hoverPaintStyle);
- if (t.maxConnections != null) this._jsPlumb.maxConnections = t.maxConnections;
- if (t.scope) this.scope = t.scope;
- jsPlumb.extend(this, t, typeParameters);
- if (t.anchor) {
- this.anchor = this._jsPlumb.instance.makeAnchor(t.anchor);
- }
- if (t.cssClass != null && this.canvas) this._jsPlumb.instance.addClass(this.canvas, t.cssClass);
- },
- isEnabled : function() { return this._jsPlumb.enabled; },
- setEnabled : function(e) { this._jsPlumb.enabled = e; },
- cleanup : function() {
- jsPlumbAdapter.removeClass(this.element, this._jsPlumb.instance.endpointAnchorClassPrefix + "_" + this._jsPlumb.currentAnchorClass);
- this.anchor = null;
- this.endpoint.cleanup();
- this.endpoint.destroy();
- this.endpoint = null;
-
- var i = jsPlumb.getElementObject(this.canvas);
- this._jsPlumb.instance.destroyDraggable(i, "internal");
- this._jsPlumb.instance.destroyDroppable(i, "internal");
- },
- setHover : function(h) {
- if (this.endpoint && this._jsPlumb && !this._jsPlumb.instance.isConnectionBeingDragged())
- this.endpoint.setHover(h);
- },
- isFull : function() {
- return !(this.isFloating() || this._jsPlumb.maxConnections < 1 || this.connections.length < this._jsPlumb.maxConnections);
- },
-
- isFloating : function() {
- return this.anchor != null && this.anchor.isFloating;
- },
- isConnectedTo : function(endpoint) {
- var found = false;
- if (endpoint) {
- for ( var i = 0; i < this.connections.length; i++) {
- if (this.connections[i].endpoints[1] == endpoint || this.connections[i].endpoints[0] == endpoint) {
- found = true;
- break;
- }
- }
- }
- return found;
- },
- getConnectionCost : function() { return this._jsPlumb.connectionCost; },
- setConnectionCost : function(c) {
- this._jsPlumb.connectionCost = c;
- },
- areConnectionsDirected : function() { return this._jsPlumb.connectionsDirected; },
- setConnectionsDirected : function(b) { this._jsPlumb.connectionsDirected = b; },
- setElementId : function(_elId) {
- this.elementId = _elId;
- this.anchor.elementId = _elId;
- },
- setReferenceElement : function(_el) {
- this.element = jsPlumb.getDOMElement(_el);
- },
- setDragAllowedWhenFull : function(allowed) {
- this.dragAllowedWhenFull = allowed;
- },
- equals : function(endpoint) {
- return this.anchor.equals(endpoint.anchor);
- },
- getUuid : function() {
- return this._jsPlumb.uuid;
- },
- computeAnchor : function(params) {
- return this.anchor.compute(params);
- }
- });
- jsPlumbInstance.prototype.EndpointDropHandler = function(dhParams) {
- return function(e) {
- var _jsPlumb = dhParams.jsPlumb;
-
-
-
- dhParams.removeClass(_jsPlumb.endpointDropAllowedClass);
- dhParams.removeClass(_jsPlumb.endpointDropForbiddenClass);
- var originalEvent = _jsPlumb.getDropEvent(arguments),
- draggable = _jsPlumb.getDOMElement(_jsPlumb.getDragObject(arguments)),
- id = _jsPlumb.getAttribute(draggable, "dragId"),
- elId = _jsPlumb.getAttribute(draggable, "elId"),
- scope = _jsPlumb.getAttribute(draggable, "originalScope"),
- jpc = _jsPlumb.floatingConnections[id];
- if (jpc == null) return;
- var _ep = dhParams.getEndpoint(jpc);
- if (dhParams.onDrop) dhParams.onDrop(jpc);
-
-
- var redrop = jpc.suspendedEndpoint && (jpc.suspendedEndpoint.id == _ep.id ||
- _ep.referenceEndpoint && jpc.suspendedEndpoint.id == _ep.referenceEndpoint.id) ;
- if (redrop) {
- jpc._forceReattach = true;
- jpc.setHover(false);
- return;
- }
- var idx = _jsPlumb.getFloatingAnchorIndex(jpc);
-
- if (scope) _jsPlumb.setDragScope(draggable, scope);
-
-
- if (dhParams.isFull(e)) {
- _ep.fire("maxConnections", {
- endpoint:this,
- connection:jpc,
- maxConnections:_ep._jsPlumb.maxConnections
- }, originalEvent);
- }
- if (!dhParams.isFull() && !(idx === 0 && !dhParams.isSource) && !(idx == 1 && !dhParams.isTarget) && dhParams.enabled()) {
- var _doContinue = true;
-
-
- if (jpc.suspendedEndpoint && jpc.suspendedEndpoint.id != _ep.id) {
- if (!jpc.isDetachAllowed(jpc) || !jpc.endpoints[idx].isDetachAllowed(jpc) || !jpc.suspendedEndpoint.isDetachAllowed(jpc) || !_jsPlumb.checkCondition("beforeDetach", jpc))
- _doContinue = false;
- }
-
- if (idx === 0) {
- jpc.source = dhParams.element;
- jpc.sourceId = dhParams.elementId;
- } else {
- jpc.target = dhParams.element;
- jpc.targetId = dhParams.elementId;
- }
- var continueFunction = function() {
-
-
- jpc.endpoints[idx].detachFromConnection(jpc);
-
- if (jpc.suspendedEndpoint) jpc.suspendedEndpoint.detachFromConnection(jpc);
-
- jpc.endpoints[idx] = _ep;
- _ep.addConnection(jpc);
-
- var params = _ep.getParameters();
- for (var aParam in params)
- jpc.setParameter(aParam, params[aParam]);
- if (!jpc.suspendedEndpoint) {
-
- if (params.draggable)
- _jsPlumb.initDraggable(this.element, dragOptions, "internal", _jsPlumb);
- }
- else {
- var suspendedElementId = jpc.suspendedEndpoint.elementId;
- _jsPlumb.fireMoveEvent({
- index:idx,
- originalSourceId:idx === 0 ? suspendedElementId : jpc.sourceId,
- newSourceId:idx === 0 ? _ep.elementId : jpc.sourceId,
- originalTargetId:idx == 1 ? suspendedElementId : jpc.targetId,
- newTargetId:idx == 1 ? _ep.elementId : jpc.targetId,
- originalSourceEndpoint:idx === 0 ? jpc.suspendedEndpoint : jpc.endpoints[0],
- newSourceEndpoint:idx === 0 ? _ep : jpc.endpoints[0],
- originalTargetEndpoint:idx == 1 ? jpc.suspendedEndpoint : jpc.endpoints[1],
- newTargetEndpoint:idx == 1 ? _ep : jpc.endpoints[1],
- connection:jpc
- }, originalEvent);
- }
- if (idx == 1)
- _jsPlumb.anchorManager.updateOtherEndpoint(jpc.sourceId, jpc.suspendedElementId, jpc.targetId, jpc);
- else
- _jsPlumb.anchorManager.sourceChanged(jpc.suspendedEndpoint.elementId, jpc.sourceId, jpc);
-
-
-
-
- if (jpc.endpoints[0].finalEndpoint) {
- var _toDelete = jpc.endpoints[0];
- _toDelete.detachFromConnection(jpc);
- jpc.endpoints[0] = jpc.endpoints[0].finalEndpoint;
- jpc.endpoints[0].addConnection(jpc);
- }
-
-
-
-
-
-
- _jsPlumb.finaliseConnection(jpc, null, originalEvent);
- jpc.setHover(false);
- }.bind(this);
- var dontContinueFunction = function() {
-
- if (jpc.suspendedEndpoint) {
- jpc.endpoints[idx] = jpc.suspendedEndpoint;
- jpc.setHover(false);
- jpc._forceDetach = true;
- if (idx === 0) {
- jpc.source = jpc.suspendedEndpoint.element;
- jpc.sourceId = jpc.suspendedEndpoint.elementId;
- } else {
- jpc.target = jpc.suspendedEndpoint.element;
- jpc.targetId = jpc.suspendedEndpoint.elementId;
- }
- jpc.suspendedEndpoint.addConnection(jpc);
- _jsPlumb.repaint(jpc.sourceId);
- jpc._forceDetach = false;
- }
- };
-
-
-
-
- _doContinue = _doContinue && dhParams.isDropAllowed(jpc.sourceId, jpc.targetId, jpc.scope, jpc, _ep);
- if (_doContinue) {
- continueFunction();
- }
- else {
- dontContinueFunction();
- }
- }
- _jsPlumb.currentlyDragging = false;
- };
- };
- })();
- ;(function() {
-
- "use strict";
- var makeConnector = function(_jsPlumb, renderMode, connectorName, connectorArgs, forComponent) {
- if (!_jsPlumb.Defaults.DoNotThrowErrors && jsPlumb.Connectors[renderMode][connectorName] == null)
- throw { msg:"jsPlumb: unknown connector type '" + connectorName + "'" };
- return new jsPlumb.Connectors[renderMode][connectorName](connectorArgs, forComponent);
- },
- _makeAnchor = function(anchorParams, elementId, _jsPlumb) {
- return (anchorParams) ? _jsPlumb.makeAnchor(anchorParams, elementId, _jsPlumb) : null;
- };
-
- jsPlumb.Connection = function(params) {
- var _newEndpoint = params.newEndpoint, _ju = jsPlumbUtil;
- this.connector = null;
- this.idPrefix = "_jsplumb_c_";
- this.defaultLabelLocation = 0.5;
- this.defaultOverlayKeys = ["Overlays", "ConnectionOverlays"];
-
-
-
- this.previousConnection = params.previousConnection;
- this.source = jsPlumb.getDOMElement(params.source);
- this.target = jsPlumb.getDOMElement(params.target);
-
-
-
- if (params.sourceEndpoint) this.source = params.sourceEndpoint.endpointWillMoveTo || params.sourceEndpoint.getElement();
- if (params.targetEndpoint) this.target = params.targetEndpoint.getElement();
- OverlayCapableJsPlumbUIComponent.apply(this, arguments);
- this.sourceId = this._jsPlumb.instance.getId(this.source);
- this.targetId = this._jsPlumb.instance.getId(this.target);
- this.scope = params.scope;
- this.endpoints = [];
- this.endpointStyles = [];
-
- var _jsPlumb = this._jsPlumb.instance;
- _jsPlumb.manage(this.sourceId, this.source);
- _jsPlumb.manage(this.targetId, this.target);
- this._jsPlumb.visible = true;
- this._jsPlumb.editable = params.editable === true;
- this._jsPlumb.params = {
- cssClass:params.cssClass,
- container:params.container,
- "pointer-events":params["pointer-events"],
- editorParams:params.editorParams
- };
- this._jsPlumb.lastPaintedAt = null;
- this.getDefaultType = function() {
- return {
- parameters:{},
- scope:null,
- detachable:this._jsPlumb.instance.Defaults.ConnectionsDetachable,
- rettach:this._jsPlumb.instance.Defaults.ReattachConnections,
- paintStyle:this._jsPlumb.instance.Defaults.PaintStyle || jsPlumb.Defaults.PaintStyle,
- connector:this._jsPlumb.instance.Defaults.Connector || jsPlumb.Defaults.Connector,
- hoverPaintStyle:this._jsPlumb.instance.Defaults.HoverPaintStyle || jsPlumb.Defaults.HoverPaintStyle,
- overlays:this._jsPlumb.instance.Defaults.ConnectorOverlays || jsPlumb.Defaults.ConnectorOverlays
- };
- };
-
- this.bind("mouseover", function() { this.setHover(true);}.bind(this));
- this.bind("mouseout", function() { this.setHover(false);}.bind(this));
-
-
-
-
- this.makeEndpoint = function(isSource, el, elId, ep) {
- elId = elId || this._jsPlumb.instance.getId(el);
- return this.prepareEndpoint(_jsPlumb, _newEndpoint, this, ep, isSource ? 0 : 1, params, el, elId);
- };
-
- var eS = this.makeEndpoint(true, this.source, this.sourceId, params.sourceEndpoint),
- eT = this.makeEndpoint(false, this.target, this.targetId, params.targetEndpoint);
-
- if (eS) _ju.addToList(params.endpointsByElement, this.sourceId, eS);
- if (eT) _ju.addToList(params.endpointsByElement, this.targetId, eT);
-
- if (!this.scope) this.scope = this.endpoints[0].scope;
-
-
- if (params.deleteEndpointsOnDetach != null) {
- this.endpoints[0]._deleteOnDetach = params.deleteEndpointsOnDetach;
- this.endpoints[1]._deleteOnDetach = params.deleteEndpointsOnDetach;
- }
- else {
-
- if (!this.endpoints[0]._doNotDeleteOnDetach) this.endpoints[0]._deleteOnDetach = true;
- if (!this.endpoints[1]._doNotDeleteOnDetach) this.endpoints[1]._deleteOnDetach = true;
- }
-
-
- this.setConnector(this.endpoints[0].connector ||
- this.endpoints[1].connector ||
- params.connector ||
- _jsPlumb.Defaults.Connector ||
- jsPlumb.Defaults.Connector, true, true);
- if (params.path)
- this.connector.setPath(params.path);
-
- this.setPaintStyle(this.endpoints[0].connectorStyle ||
- this.endpoints[1].connectorStyle ||
- params.paintStyle ||
- _jsPlumb.Defaults.PaintStyle ||
- jsPlumb.Defaults.PaintStyle, true);
-
- this.setHoverPaintStyle(this.endpoints[0].connectorHoverStyle ||
- this.endpoints[1].connectorHoverStyle ||
- params.hoverPaintStyle ||
- _jsPlumb.Defaults.HoverPaintStyle ||
- jsPlumb.Defaults.HoverPaintStyle, true);
-
- this._jsPlumb.paintStyleInUse = this.getPaintStyle();
-
- var _suspendedAt = _jsPlumb.getSuspendedAt();
- if(!_jsPlumb.isSuspendDrawing()) {
-
- var myInfo = _jsPlumb.getCachedData(this.sourceId),
- myOffset = myInfo.o, myWH = myInfo.s,
- otherInfo = _jsPlumb.getCachedData(this.targetId),
- otherOffset = otherInfo.o,
- otherWH = otherInfo.s,
- initialTimestamp = _suspendedAt || _jsPlumb.timestamp(),
- anchorLoc = this.endpoints[0].anchor.compute( {
- xy : [ myOffset.left, myOffset.top ], wh : myWH, element : this.endpoints[0],
- elementId:this.endpoints[0].elementId,
- txy : [ otherOffset.left, otherOffset.top ], twh : otherWH, tElement : this.endpoints[1],
- timestamp:initialTimestamp
- });
- this.endpoints[0].paint( { anchorLoc : anchorLoc, timestamp:initialTimestamp });
- anchorLoc = this.endpoints[1].anchor.compute( {
- xy : [ otherOffset.left, otherOffset.top ], wh : otherWH, element : this.endpoints[1],
- elementId:this.endpoints[1].elementId,
- txy : [ myOffset.left, myOffset.top ], twh : myWH, tElement : this.endpoints[0],
- timestamp:initialTimestamp
- });
- this.endpoints[1].paint({ anchorLoc : anchorLoc, timestamp:initialTimestamp });
- }
-
-
-
- this._jsPlumb.detachable = _jsPlumb.Defaults.ConnectionsDetachable;
- if (params.detachable === false) this._jsPlumb.detachable = false;
- if(this.endpoints[0].connectionsDetachable === false) this._jsPlumb.detachable = false;
- if(this.endpoints[1].connectionsDetachable === false) this._jsPlumb.detachable = false;
- this._jsPlumb.reattach = params.reattach || this.endpoints[0].reattachConnections || this.endpoints[1].reattachConnections || _jsPlumb.Defaults.ReattachConnections;
-
- this._jsPlumb.cost = params.cost || this.endpoints[0].getConnectionCost();
- this._jsPlumb.directed = params.directed;
-
- if (params.directed == null) this._jsPlumb.directed = this.endpoints[0].areConnectionsDirected();
-
-
-
-
-
-
- var _p = jsPlumb.extend({}, this.endpoints[1].getParameters());
- jsPlumb.extend(_p, this.endpoints[0].getParameters());
- jsPlumb.extend(_p, this.getParameters());
- this.setParameters(_p);
-
-
- var _types = [params.type, this.endpoints[0].connectionType, this.endpoints[1].connectionType ].join(" ");
- if (/[^\s]/.test(_types))
- this.addType(_types, params.data, true);
-
- };
- jsPlumbUtil.extend(jsPlumb.Connection, OverlayCapableJsPlumbUIComponent, {
- applyType : function(t, doNotRepaint) {
- if (t.detachable != null) this.setDetachable(t.detachable);
- if (t.reattach != null) this.setReattach(t.reattach);
- if (t.scope) this.scope = t.scope;
- this.setConnector(t.connector, doNotRepaint);
- if (t.cssClass != null && this.canvas) this._jsPlumb.instance.addClass(this.canvas, t.cssClass);
- if (t.anchor) {
- this.endpoints[0].anchor = this._jsPlumb.instance.makeAnchor(t.anchor);
- this.endpoints[1].anchor = this._jsPlumb.instance.makeAnchor(t.anchor);
- }
- else if (t.anchors) {
- this.endpoints[0].anchor = this._jsPlumb.instance.makeAnchor(t.anchors[0]);
- this.endpoints[1].anchor = this._jsPlumb.instance.makeAnchor(t.anchors[1]);
- }
- },
- getTypeDescriptor : function() { return "connection"; },
- getAttachedElements : function() {
- return this.endpoints;
- },
- addClass : function(c, informEndpoints) {
- if (informEndpoints) {
- this.endpoints[0].addClass(c);
- this.endpoints[1].addClass(c);
- if (this.suspendedEndpoint) this.suspendedEndpoint.addClass(c);
- }
- if (this.connector) {
- this.connector.addClass(c);
- }
- },
- removeClass : function(c, informEndpoints) {
- if (informEndpoints) {
- this.endpoints[0].removeClass(c);
- this.endpoints[1].removeClass(c);
- if (this.suspendedEndpoint) this.suspendedEndpoint.removeClass(c);
- }
- if (this.connector) {
- this.connector.removeClass(c);
- }
- },
- isVisible : function() { return this._jsPlumb.visible; },
- setVisible : function(v) {
- this._jsPlumb.visible = v;
- if (this.connector)
- this.connector.setVisible(v);
- this.repaint();
- },
- cleanup:function() {
- this.endpoints = null;
- this.source = null;
- this.target = null;
- if (this.connector != null) {
- this.connector.cleanup();
- this.connector.destroy();
- }
- this.connector = null;
- },
- isDetachable : function() {
- return this._jsPlumb.detachable === true;
- },
- setDetachable : function(detachable) {
- this._jsPlumb.detachable = detachable === true;
- },
- isReattach : function() {
- return this._jsPlumb.reattach === true;
- },
- setReattach : function(reattach) {
- this._jsPlumb.reattach = reattach === true;
- },
- setHover : function(state) {
- if (this.connector && this._jsPlumb && !this._jsPlumb.instance.isConnectionBeingDragged()) {
- this.connector.setHover(state);
- jsPlumbAdapter[state ? "addClass" : "removeClass"](this.source, this._jsPlumb.instance.hoverSourceClass);
- jsPlumbAdapter[state ? "addClass" : "removeClass"](this.target, this._jsPlumb.instance.hoverTargetClass);
- }
- },
- getCost : function() { return this._jsPlumb.cost; },
- setCost : function(c) { this._jsPlumb.cost = c; },
- isDirected : function() { return this._jsPlumb.directed === true; },
- getConnector : function() { return this.connector; },
- setConnector : function(connectorSpec, doNotRepaint, doNotChangeListenerComponent) {
- var _ju = jsPlumbUtil;
- if (this.connector != null) {
- this.connector.cleanup();
- this.connector.destroy();
- }
- var connectorArgs = {
- _jsPlumb:this._jsPlumb.instance,
- cssClass:this._jsPlumb.params.cssClass,
- container:this._jsPlumb.params.container,
- "pointer-events":this._jsPlumb.params["pointer-events"]
- },
- renderMode = this._jsPlumb.instance.getRenderMode();
-
- if (_ju.isString(connectorSpec))
- this.connector = makeConnector(this._jsPlumb.instance, renderMode, connectorSpec, connectorArgs, this);
- else if (_ju.isArray(connectorSpec)) {
- if (connectorSpec.length == 1)
- this.connector = makeConnector(this._jsPlumb.instance, renderMode, connectorSpec[0], connectorArgs, this);
- else
- this.connector = makeConnector(this._jsPlumb.instance, renderMode, connectorSpec[0], _ju.merge(connectorSpec[1], connectorArgs), this);
- }
-
- this.canvas = this.connector.canvas;
- this.bgCanvas = this.connector.bgCanvas;
-
-
-
- if(this.canvas) this.canvas._jsPlumb = this;
- if(this.bgCanvas) this.bgCanvas._jsPlumb = this;
- if (!doNotChangeListenerComponent) this.setListenerComponent(this.connector);
- if (!doNotRepaint) this.repaint();
- },
- paint : function(params) {
-
- if (!this._jsPlumb.instance.isSuspendDrawing() && this._jsPlumb.visible) {
- params = params || {};
- var timestamp = params.timestamp,
-
- swap = false,
- tId = swap ? this.sourceId : this.targetId, sId = swap ? this.targetId : this.sourceId,
- tIdx = swap ? 0 : 1, sIdx = swap ? 1 : 0;
- if (timestamp == null || timestamp != this._jsPlumb.lastPaintedAt) {
- var sourceInfo = this._jsPlumb.instance.getOffset(sId),
- targetInfo = this._jsPlumb.instance.getOffset(tId),
- sE = this.endpoints[sIdx], tE = this.endpoints[tIdx];
- var sAnchorP = sE.anchor.getCurrentLocation({xy:[sourceInfo.left,sourceInfo.top], wh:[sourceInfo.width, sourceInfo.height], element:sE, timestamp:timestamp}),
- tAnchorP = tE.anchor.getCurrentLocation({xy:[targetInfo.left,targetInfo.top], wh:[targetInfo.width, targetInfo.height], element:tE, timestamp:timestamp});
-
- this.connector.resetBounds();
- this.connector.compute({
- sourcePos:sAnchorP,
- targetPos:tAnchorP,
- sourceEndpoint:this.endpoints[sIdx],
- targetEndpoint:this.endpoints[tIdx],
- lineWidth:this._jsPlumb.paintStyleInUse.lineWidth,
- sourceInfo:sourceInfo,
- targetInfo:targetInfo
- });
- var overlayExtents = { minX:Infinity, minY:Infinity, maxX:-Infinity, maxY:-Infinity };
-
-
- for ( var i = 0; i < this._jsPlumb.overlays.length; i++) {
- var o = this._jsPlumb.overlays[i];
- if (o.isVisible()) {
- this._jsPlumb.overlayPlacements[i] = o.draw(this.connector, this._jsPlumb.paintStyleInUse, this.getAbsoluteOverlayPosition(o));
- overlayExtents.minX = Math.min(overlayExtents.minX, this._jsPlumb.overlayPlacements[i].minX);
- overlayExtents.maxX = Math.max(overlayExtents.maxX, this._jsPlumb.overlayPlacements[i].maxX);
- overlayExtents.minY = Math.min(overlayExtents.minY, this._jsPlumb.overlayPlacements[i].minY);
- overlayExtents.maxY = Math.max(overlayExtents.maxY, this._jsPlumb.overlayPlacements[i].maxY);
- }
- }
- var lineWidth = parseFloat(this._jsPlumb.paintStyleInUse.lineWidth || 1) / 2,
- outlineWidth = parseFloat(this._jsPlumb.paintStyleInUse.lineWidth || 0),
- extents = {
- xmin : Math.min(this.connector.bounds.minX - (lineWidth + outlineWidth), overlayExtents.minX),
- ymin : Math.min(this.connector.bounds.minY - (lineWidth + outlineWidth), overlayExtents.minY),
- xmax : Math.max(this.connector.bounds.maxX + (lineWidth + outlineWidth), overlayExtents.maxX),
- ymax : Math.max(this.connector.bounds.maxY + (lineWidth + outlineWidth), overlayExtents.maxY)
- };
-
- this.connector.paint(this._jsPlumb.paintStyleInUse, null, extents);
-
- for ( var j = 0; j < this._jsPlumb.overlays.length; j++) {
- var p = this._jsPlumb.overlays[j];
- if (p.isVisible()) {
- p.paint(this._jsPlumb.overlayPlacements[j], extents);
- }
- }
- }
- this._jsPlumb.lastPaintedAt = timestamp;
- }
- },
- repaint : function(params) {
- params = params || {};
- this.paint({ elId : this.sourceId, recalc : !(params.recalc === false), timestamp:params.timestamp});
- },
- prepareEndpoint : function(_jsPlumb, _newEndpoint, conn, existing, index, params, element, elementId) {
- var e;
- if (existing) {
- conn.endpoints[index] = existing;
- existing.addConnection(conn);
- } else {
- if (!params.endpoints) params.endpoints = [ null, null ];
- var ep = params.endpoints[index] || params.endpoint || _jsPlumb.Defaults.Endpoints[index] || jsPlumb.Defaults.Endpoints[index] || _jsPlumb.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 || _jsPlumb.Defaults.EndpointStyles[index] || jsPlumb.Defaults.EndpointStyles[index] || _jsPlumb.Defaults.EndpointStyle || jsPlumb.Defaults.EndpointStyle;
-
- if (es.fillStyle == null && params.paintStyle != null)
- es.fillStyle = params.paintStyle.strokeStyle;
-
-
-
- if (es.outlineColor == null && params.paintStyle != null)
- es.outlineColor = params.paintStyle.outlineColor;
- if (es.outlineWidth == null && params.paintStyle != null)
- es.outlineWidth = params.paintStyle.outlineWidth;
-
-
- var ehs = params.endpointHoverStyles[index] || params.endpointHoverStyle || _jsPlumb.Defaults.EndpointHoverStyles[index] || jsPlumb.Defaults.EndpointHoverStyles[index] || _jsPlumb.Defaults.EndpointHoverStyle || jsPlumb.Defaults.EndpointHoverStyle;
-
- if (params.hoverPaintStyle != null) {
- if (ehs == null) ehs = {};
- if (ehs.fillStyle == null) {
- ehs.fillStyle = params.hoverPaintStyle.strokeStyle;
- }
- }
- var a = params.anchors ? params.anchors[index] :
- params.anchor ? params.anchor :
- _makeAnchor(_jsPlumb.Defaults.Anchors[index], elementId, _jsPlumb) ||
- _makeAnchor(jsPlumb.Defaults.Anchors[index], elementId,_jsPlumb) ||
- _makeAnchor(_jsPlumb.Defaults.Anchor, elementId,_jsPlumb) ||
- _makeAnchor(jsPlumb.Defaults.Anchor, elementId, _jsPlumb),
- u = params.uuids ? params.uuids[index] : null;
-
- e = _newEndpoint({
- paintStyle : es, hoverPaintStyle:ehs, endpoint : ep, connections : [ conn ],
- uuid : u, anchor : a, source : element, scope : params.scope,
- reattach:params.reattach || _jsPlumb.Defaults.ReattachConnections,
- detachable:params.detachable || _jsPlumb.Defaults.ConnectionsDetachable
- });
- conn.endpoints[index] = e;
-
- if (params.drawEndpoints === false) e.setVisible(false, true, true);
-
- }
- return e;
- }
-
- });
- })();
- ;(function() {
- "use strict";
-
-
-
- jsPlumb.AnchorManager = function(params) {
- var _amEndpoints = {},
- continuousAnchors = {},
- continuousAnchorLocations = {},
- userDefinedContinuousAnchorLocations = {},
- continuousAnchorOrientations = {},
- Orientation = { HORIZONTAL : "horizontal", VERTICAL : "vertical", DIAGONAL : "diagonal", IDENTITY:"identity" },
- axes = ["left", "top", "right", "bottom"],
- connectionsByElementId = {},
- self = this,
- anchorLists = {},
- jsPlumbInstance = params.jsPlumbInstance,
- floatingConnections = {},
- calculateOrientation = function(sourceId, targetId, sd, td, sourceAnchor, targetAnchor) {
-
- if (sourceId === targetId) return {
- orientation:Orientation.IDENTITY,
- a:["top", "top"]
- };
- var theta = Math.atan2((td.centery - sd.centery) , (td.centerx - sd.centerx)),
- theta2 = Math.atan2((sd.centery - td.centery) , (sd.centerx - td.centerx));
-
-
-
- var candidates = [], midpoints = { };
- (function(types, dim) {
- for (var i = 0; i < types.length; i++) {
- midpoints[types[i]] = {
- "left":[ dim[i].left, dim[i].centery ],
- "right":[ dim[i].right, dim[i].centery ],
- "top":[ dim[i].centerx, dim[i].top ],
- "bottom":[ dim[i].centerx , dim[i].bottom]
- };
- }
- })([ "source", "target" ], [ sd, td ]);
- for (var sf = 0; sf < axes.length; sf++) {
- for (var tf = 0; tf < axes.length; tf++) {
- if (sf != tf) {
- candidates.push({
- source:axes[sf],
- target:axes[tf],
- dist:Biltong.lineLength(midpoints.source[axes[sf]], midpoints.target[axes[tf]])
- });
- }
- }
- }
- candidates.sort(function(a, b) {
- return a.dist < b.dist ? -1 : a.dist > b.dist ? 1 : 0;
- });
-
-
- var sourceEdge = candidates[0].source, targetEdge = candidates[0].target;
- for (var i = 0; i < candidates.length; i++) {
-
- if (!sourceAnchor.isContinuous || sourceAnchor.isEdgeSupported(candidates[i].source))
- sourceEdge = candidates[i].source;
- else
- sourceEdge = null;
- if (!targetAnchor.isContinuous || targetAnchor.isEdgeSupported(candidates[i].target))
- targetEdge = candidates[i].target;
- else {
- targetEdge = null;
- }
- if (sourceEdge != null && targetEdge != null) break;
- }
- return {
- a : [ sourceEdge, targetEdge ],
- theta:theta,
- theta2:theta2
- };
- },
-
- placeAnchorsOnLine = function(desc, elementDimensions, elementPosition,
- connections, horizontal, otherMultiplier, reverse) {
- var a = [], step = elementDimensions[horizontal ? 0 : 1] / (connections.length + 1);
-
- for (var i = 0; i < connections.length; i++) {
- var val = (i + 1) * step, other = otherMultiplier * elementDimensions[horizontal ? 1 : 0];
- if (reverse)
- val = elementDimensions[horizontal ? 0 : 1] - val;
-
- var dx = (horizontal ? val : other), x = elementPosition[0] + dx, xp = dx / elementDimensions[0],
- dy = (horizontal ? other : val), y = elementPosition[1] + dy, yp = dy / elementDimensions[1];
-
- a.push([ x, y, xp, yp, connections[i][1], connections[i][2] ]);
- }
-
- return a;
- },
-
- currySort = function(reverseAngles) {
- return function(a,b) {
- var r = true;
- if (reverseAngles) {
- r = a[0][0] < b[0][0];
- }
- else {
- r = a[0][0] > b[0][0];
- }
- return r === false ? -1 : 1;
- };
- },
-
- leftSort = function(a,b) {
-
- var p1 = a[0][0] < 0 ? -Math.PI - a[0][0] : Math.PI - a[0][0],
- p2 = b[0][0] < 0 ? -Math.PI - b[0][0] : Math.PI - b[0][0];
- if (p1 > p2) return 1;
- else return a[0][1] > b[0][1] ? 1 : -1;
- },
-
- edgeSortFunctions = {
- "top":function(a, b) { return a[0] > b[0] ? 1 : -1; },
- "right":currySort(true),
- "bottom":currySort(true),
- "left":leftSort
- },
-
- _sortHelper = function(_array, _fn) { return _array.sort(_fn); },
-
- placeAnchors = function(elementId, _anchorLists) {
- var cd = jsPlumbInstance.getCachedData(elementId), sS = cd.s, sO = cd.o,
- placeSomeAnchors = function(desc, elementDimensions, elementPosition, unsortedConnections, isHorizontal, otherMultiplier, orientation) {
- if (unsortedConnections.length > 0) {
- var sc = _sortHelper(unsortedConnections, edgeSortFunctions[desc]),
- reverse = desc === "right" || desc === "top",
- anchors = placeAnchorsOnLine(desc, elementDimensions,
- elementPosition, sc,
- isHorizontal, otherMultiplier, reverse );
-
-
- var _setAnchorLocation = function(endpoint, anchorPos) {
- continuousAnchorLocations[endpoint.id] = [ anchorPos[0], anchorPos[1], anchorPos[2], anchorPos[3] ];
- continuousAnchorOrientations[endpoint.id] = orientation;
- };
-
- for (var i = 0; i < anchors.length; i++) {
- var c = anchors[i][4], weAreSource = c.endpoints[0].elementId === elementId, weAreTarget = c.endpoints[1].elementId === elementId;
- if (weAreSource)
- _setAnchorLocation(c.endpoints[0], anchors[i]);
- else if (weAreTarget)
- _setAnchorLocation(c.endpoints[1], anchors[i]);
- }
- }
- };
-
- placeSomeAnchors("bottom", sS, [sO.left,sO.top], _anchorLists.bottom, true, 1, [0,1]);
- placeSomeAnchors("top", sS, [sO.left,sO.top], _anchorLists.top, true, 0, [0,-1]);
- placeSomeAnchors("left", sS, [sO.left,sO.top], _anchorLists.left, false, 0, [-1,0]);
- placeSomeAnchors("right", sS, [sO.left,sO.top], _anchorLists.right, false, 1, [1,0]);
- };
- this.reset = function() {
- _amEndpoints = {};
- connectionsByElementId = {};
- anchorLists = {};
- };
- this.addFloatingConnection = function(key, conn) {
- floatingConnections[key] = conn;
- };
- this.removeFloatingConnection = function(key) {
- delete floatingConnections[key];
- };
- this.newConnection = function(conn) {
- var sourceId = conn.sourceId, targetId = conn.targetId,
- ep = conn.endpoints,
- doRegisterTarget = true,
- registerConnection = function(otherIndex, otherEndpoint, otherAnchor, elId, c) {
- if ((sourceId == targetId) && otherAnchor.isContinuous){
-
- conn._jsPlumb.instance.removeElement(ep[1].canvas);
- doRegisterTarget = false;
- }
- jsPlumbUtil.addToList(connectionsByElementId, elId, [c, otherEndpoint, otherAnchor.constructor == jsPlumb.DynamicAnchor]);
- };
- registerConnection(0, ep[0], ep[0].anchor, targetId, conn);
- if (doRegisterTarget)
- registerConnection(1, ep[1], ep[1].anchor, sourceId, conn);
- };
- var removeEndpointFromAnchorLists = function(endpoint) {
- (function(list, eId) {
- if (list) {
- var f = function(e) { return e[4] == eId; };
- jsPlumbUtil.removeWithFunction(list.top, f);
- jsPlumbUtil.removeWithFunction(list.left, f);
- jsPlumbUtil.removeWithFunction(list.bottom, f);
- jsPlumbUtil.removeWithFunction(list.right, f);
- }
- })(anchorLists[endpoint.elementId], endpoint.id);
- };
- this.connectionDetached = function(connInfo) {
- var connection = connInfo.connection || connInfo,
- sourceId = connInfo.sourceId,
- targetId = connInfo.targetId,
- ep = connection.endpoints,
- removeConnection = function(otherIndex, otherEndpoint, otherAnchor, elId, c) {
- if (otherAnchor != null && otherAnchor.constructor == jsPlumb.FloatingAnchor) {
-
- }
- else {
- jsPlumbUtil.removeWithFunction(connectionsByElementId[elId], function(_c) {
- return _c[0].id == c.id;
- });
- }
- };
-
- removeConnection(1, ep[1], ep[1].anchor, sourceId, connection);
- removeConnection(0, ep[0], ep[0].anchor, targetId, connection);
-
- removeEndpointFromAnchorLists(connection.endpoints[0]);
- removeEndpointFromAnchorLists(connection.endpoints[1]);
- self.redraw(connection.sourceId);
- self.redraw(connection.targetId);
- };
- this.add = function(endpoint, elementId) {
- jsPlumbUtil.addToList(_amEndpoints, elementId, endpoint);
- };
- this.changeId = function(oldId, newId) {
- connectionsByElementId[newId] = connectionsByElementId[oldId];
- _amEndpoints[newId] = _amEndpoints[oldId];
- delete connectionsByElementId[oldId];
- delete _amEndpoints[oldId];
- };
- this.getConnectionsFor = function(elementId) {
- return connectionsByElementId[elementId] || [];
- };
- this.getEndpointsFor = function(elementId) {
- return _amEndpoints[elementId] || [];
- };
- this.deleteEndpoint = function(endpoint) {
- jsPlumbUtil.removeWithFunction(_amEndpoints[endpoint.elementId], function(e) {
- return e.id == endpoint.id;
- });
- removeEndpointFromAnchorLists(endpoint);
- };
- this.clearFor = function(elementId) {
- delete _amEndpoints[elementId];
- _amEndpoints[elementId] = [];
- };
-
-
-
-
-
- var _updateAnchorList = function(lists, theta, order, conn, aBoolean, otherElId, idx, reverse, edgeId, elId, connsToPaint, endpointsToPaint) {
-
- var exactIdx = -1,
- firstMatchingElIdx = -1,
- endpoint = conn.endpoints[idx],
- endpointId = endpoint.id,
- oIdx = [1,0][idx],
- values = [ [ theta, order ], conn, aBoolean, otherElId, endpointId ],
- listToAddTo = lists[edgeId],
- listToRemoveFrom = endpoint._continuousAnchorEdge ? lists[endpoint._continuousAnchorEdge] : null,
- i;
- if (listToRemoveFrom) {
- var rIdx = jsPlumbUtil.findWithFunction(listToRemoveFrom, function(e) { return e[4] == endpointId; });
- if (rIdx != -1) {
- listToRemoveFrom.splice(rIdx, 1);
-
- for (i = 0; i < listToRemoveFrom.length; i++) {
- jsPlumbUtil.addWithFunction(connsToPaint, listToRemoveFrom[i][1], function(c) { return c.id == listToRemoveFrom[i][1].id; });
- jsPlumbUtil.addWithFunction(endpointsToPaint, listToRemoveFrom[i][1].endpoints[idx], function(e) { return e.id == listToRemoveFrom[i][1].endpoints[idx].id; });
- jsPlumbUtil.addWithFunction(endpointsToPaint, listToRemoveFrom[i][1].endpoints[oIdx], function(e) { return e.id == listToRemoveFrom[i][1].endpoints[oIdx].id; });
- }
- }
- }
- for (i = 0; i < listToAddTo.length; i++) {
- if (params.idx == 1 && listToAddTo[i][3] === otherElId && firstMatchingElIdx == -1)
- firstMatchingElIdx = i;
- jsPlumbUtil.addWithFunction(connsToPaint, listToAddTo[i][1], function(c) { return c.id == listToAddTo[i][1].id; });
- jsPlumbUtil.addWithFunction(endpointsToPaint, listToAddTo[i][1].endpoints[idx], function(e) { return e.id == listToAddTo[i][1].endpoints[idx].id; });
- jsPlumbUtil.addWithFunction(endpointsToPaint, listToAddTo[i][1].endpoints[oIdx], function(e) { return e.id == listToAddTo[i][1].endpoints[oIdx].id; });
- }
- if (exactIdx != -1) {
- listToAddTo[exactIdx] = values;
- }
- else {
- var insertIdx = reverse ? firstMatchingElIdx != -1 ? firstMatchingElIdx : 0 : listToAddTo.length;
- listToAddTo.splice(insertIdx, 0, values);
- }
-
- endpoint._continuousAnchorEdge = edgeId;
- };
-
-
-
-
-
- this.updateOtherEndpoint = function(elId, oldTargetId, newTargetId, connection) {
- var sIndex = jsPlumbUtil.findWithFunction(connectionsByElementId[elId], function(i) {
- return i[0].id === connection.id;
- }),
- tIndex = jsPlumbUtil.findWithFunction(connectionsByElementId[oldTargetId], function(i) {
- return i[0].id === connection.id;
- });
-
- if (sIndex != -1) {
- connectionsByElementId[elId][sIndex][0] = connection;
- connectionsByElementId[elId][sIndex][1] = connection.endpoints[1];
- connectionsByElementId[elId][sIndex][2] = connection.endpoints[1].anchor.constructor == jsPlumb.DynamicAnchor;
- }
-
- if (tIndex > -1) {
- connectionsByElementId[oldTargetId].splice(tIndex, 1);
-
- jsPlumbUtil.addToList(connectionsByElementId, newTargetId, [connection, connection.endpoints[0], connection.endpoints[0].anchor.constructor == jsPlumb.DynamicAnchor]);
- }
- };
-
-
-
-
-
-
-
-
- this.sourceChanged = function(originalId, newId, connection) {
- if (originalId !== newId) {
-
- jsPlumbUtil.removeWithFunction(connectionsByElementId[originalId], function(info) {
- return info[0].id === connection.id;
- });
-
- var tIdx = jsPlumbUtil.findWithFunction(connectionsByElementId[connection.targetId], function(i) {
- return i[0].id === connection.id;
- });
- if (tIdx > -1) {
- connectionsByElementId[connection.targetId][tIdx][0] = connection;
- connectionsByElementId[connection.targetId][tIdx][1] = connection.endpoints[0];
- connectionsByElementId[connection.targetId][tIdx][2] = connection.endpoints[0].anchor.constructor == jsPlumb.DynamicAnchor;
- }
-
- jsPlumbUtil.addToList(connectionsByElementId, newId, [connection, connection.endpoints[1], connection.endpoints[1].anchor.constructor == jsPlumb.DynamicAnchor]);
- }
- };
-
-
-
-
-
-
-
-
-
- this.rehomeEndpoint = function(ep, currentId, element) {
- var eps = _amEndpoints[currentId] || [],
- elementId = jsPlumbInstance.getId(element);
-
- if (elementId !== currentId) {
- var idx = jsPlumbUtil.indexOf(eps, ep);
- if (idx > -1) {
- var _ep = eps.splice(idx, 1)[0];
- self.add(_ep, elementId);
- }
- }
- for (var i = 0; i < ep.connections.length; i++) {
- if (ep.connections[i].sourceId == currentId) {
- ep.connections[i].sourceId = ep.elementId;
- ep.connections[i].source = ep.element;
- self.sourceChanged(currentId, ep.elementId, ep.connections[i]);
- }
- else if(ep.connections[i].targetId == currentId) {
- ep.connections[i].targetId = ep.elementId;
- ep.connections[i].target = ep.element;
- self.updateOtherEndpoint(ep.connections[i].sourceId, currentId, ep.elementId, ep.connections[i]);
- }
- }
- };
- this.redraw = function(elementId, ui, timestamp, offsetToUI, clearEdits, doNotRecalcEndpoint) {
-
- if (!jsPlumbInstance.isSuspendDrawing()) {
-
- var ep = _amEndpoints[elementId] || [],
- endpointConnections = connectionsByElementId[elementId] || [],
- connectionsToPaint = [],
- endpointsToPaint = [],
- anchorsToUpdate = [];
-
- timestamp = timestamp || jsPlumbInstance.timestamp();
-
-
-
- offsetToUI = offsetToUI || {left:0, top:0};
- if (ui) {
- ui = {
- left:ui.left + offsetToUI.left,
- top:ui.top + offsetToUI.top
- };
- }
-
- var myOffset = jsPlumbInstance.updateOffset( { elId : elementId, offset : ui, recalc : false, timestamp : timestamp }),
- orientationCache = {};
-
-
-
-
- for (var i = 0; i < endpointConnections.length; i++) {
- var conn = endpointConnections[i][0],
- sourceId = conn.sourceId,
- targetId = conn.targetId,
- sourceContinuous = conn.endpoints[0].anchor.isContinuous,
- targetContinuous = conn.endpoints[1].anchor.isContinuous;
-
- if (sourceContinuous || targetContinuous) {
- var oKey = sourceId + "_" + targetId,
- oKey2 = targetId + "_" + sourceId,
- o = orientationCache[oKey],
- oIdx = conn.sourceId == elementId ? 1 : 0;
-
- if (sourceContinuous && !anchorLists[sourceId]) anchorLists[sourceId] = { top:[], right:[], bottom:[], left:[] };
- if (targetContinuous && !anchorLists[targetId]) anchorLists[targetId] = { top:[], right:[], bottom:[], left:[] };
-
- if (elementId != targetId) jsPlumbInstance.updateOffset( { elId : targetId, timestamp : timestamp });
- if (elementId != sourceId) jsPlumbInstance.updateOffset( { elId : sourceId, timestamp : timestamp });
-
- var td = jsPlumbInstance.getCachedData(targetId),
- sd = jsPlumbInstance.getCachedData(sourceId);
-
- if (targetId == sourceId && (sourceContinuous || targetContinuous)) {
-
-
-
-
- _updateAnchorList(
- anchorLists[sourceId],
- -Math.PI / 2,
- 0,
- conn,
- false,
- targetId,
- 0, false, "top", sourceId, connectionsToPaint, endpointsToPaint);
- }
- else {
- if (!o) {
- o = calculateOrientation(sourceId, targetId, sd.o, td.o, conn.endpoints[0].anchor, conn.endpoints[1].anchor);
- orientationCache[oKey] = o;
-
-
-
- }
- if (sourceContinuous) _updateAnchorList(anchorLists[sourceId], o.theta, 0, conn, false, targetId, 0, false, o.a[0], sourceId, connectionsToPaint, endpointsToPaint);
- if (targetContinuous) _updateAnchorList(anchorLists[targetId], o.theta2, -1, conn, true, sourceId, 1, true, o.a[1], targetId, connectionsToPaint, endpointsToPaint);
- }
-
- if (sourceContinuous) jsPlumbUtil.addWithFunction(anchorsToUpdate, sourceId, function(a) { return a === sourceId; });
- if (targetContinuous) jsPlumbUtil.addWithFunction(anchorsToUpdate, targetId, function(a) { return a === targetId; });
- jsPlumbUtil.addWithFunction(connectionsToPaint, conn, function(c) { return c.id == conn.id; });
- if ((sourceContinuous && oIdx === 0) || (targetContinuous && oIdx === 1))
- jsPlumbUtil.addWithFunction(endpointsToPaint, conn.endpoints[oIdx], function(e) { return e.id == conn.endpoints[oIdx].id; });
- }
- }
-
- for (i = 0; i < ep.length; i++) {
- if (ep[i].connections.length === 0 && ep[i].anchor.isContinuous) {
- if (!anchorLists[elementId]) anchorLists[elementId] = { top:[], right:[], bottom:[], left:[] };
- _updateAnchorList(anchorLists[elementId], -Math.PI / 2, 0, {endpoints:[ep[i], ep[i]], paint:function(){}}, false, elementId, 0, false, ep[i].anchor.getDefaultFace(), elementId, connectionsToPaint, endpointsToPaint);
- jsPlumbUtil.addWithFunction(anchorsToUpdate, elementId, function(a) { return a === elementId; });
- }
- }
-
- for (i = 0; i < anchorsToUpdate.length; i++) {
- placeAnchors(anchorsToUpdate[i], anchorLists[anchorsToUpdate[i]]);
- }
-
-
-
- for (i = 0; i < ep.length; i++) {
- ep[i].paint( { timestamp : timestamp, offset : myOffset, dimensions : myOffset.s, recalc:doNotRecalcEndpoint !== true });
- }
-
- for (i = 0; i < endpointsToPaint.length; i++) {
- var cd = jsPlumbInstance.getCachedData(endpointsToPaint[i].elementId);
- endpointsToPaint[i].paint( { timestamp : timestamp, offset : cd, dimensions : cd.s });
- }
-
-
-
- for (i = 0; i < endpointConnections.length; i++) {
- var otherEndpoint = endpointConnections[i][1];
- if (otherEndpoint.anchor.constructor == jsPlumb.DynamicAnchor) {
- otherEndpoint.paint({ elementWithPrecedence:elementId, timestamp:timestamp });
- jsPlumbUtil.addWithFunction(connectionsToPaint, endpointConnections[i][0], function(c) { return c.id == endpointConnections[i][0].id; });
-
- for (var k = 0; k < otherEndpoint.connections.length; k++) {
- if (otherEndpoint.connections[k] !== endpointConnections[i][0])
- jsPlumbUtil.addWithFunction(connectionsToPaint, otherEndpoint.connections[k], function(c) { return c.id == otherEndpoint.connections[k].id; });
- }
- } else if (otherEndpoint.anchor.constructor == jsPlumb.Anchor) {
- jsPlumbUtil.addWithFunction(connectionsToPaint, endpointConnections[i][0], function(c) { return c.id == endpointConnections[i][0].id; });
- }
- }
-
- var fc = floatingConnections[elementId];
- if (fc)
- fc.paint({timestamp:timestamp, recalc:false, elId:elementId});
-
- for (i = 0; i < connectionsToPaint.length; i++) {
- connectionsToPaint[i].paint({elId:elementId, timestamp:timestamp, recalc:false, clearEdits:clearEdits});
- }
- }
- };
-
- var ContinuousAnchor = function(anchorParams) {
- jsPlumbUtil.EventGenerator.apply(this);
- this.type = "Continuous";
- this.isDynamic = true;
- this.isContinuous = true;
- var faces = anchorParams.faces || ["top", "right", "bottom", "left"],
- clockwise = !(anchorParams.clockwise === false),
- availableFaces = { },
- opposites = { "top":"bottom", "right":"left","left":"right","bottom":"top" },
- clockwiseOptions = { "top":"right", "right":"bottom","left":"top","bottom":"left" },
- antiClockwiseOptions = { "top":"left", "right":"top","left":"bottom","bottom":"right" },
- secondBest = clockwise ? clockwiseOptions : antiClockwiseOptions,
- lastChoice = clockwise ? antiClockwiseOptions : clockwiseOptions,
- cssClass = anchorParams.cssClass || "";
- for (var i = 0; i < faces.length; i++) { availableFaces[faces[i]] = true; }
- this.getDefaultFace = function() {
- return faces.length === 0 ? "top" : faces[0];
- };
-
-
- this.verifyEdge = function(edge) {
- if (availableFaces[edge]) return edge;
- else if (availableFaces[opposites[edge]]) return opposites[edge];
- else if (availableFaces[secondBest[edge]]) return secondBest[edge];
- else if (availableFaces[lastChoice[edge]]) return lastChoice[edge];
- return edge;
- };
- this.isEdgeSupported = function(edge) {
- return availableFaces[edge] === true;
- };
- this.compute = function(params) {
- return userDefinedContinuousAnchorLocations[params.element.id] || continuousAnchorLocations[params.element.id] || [0,0];
- };
- this.getCurrentLocation = function(params) {
- return userDefinedContinuousAnchorLocations[params.element.id] || continuousAnchorLocations[params.element.id] || [0,0];
- };
- this.getOrientation = function(endpoint) {
- return continuousAnchorOrientations[endpoint.id] || [0,0];
- };
- this.clearUserDefinedLocation = function() {
- delete userDefinedContinuousAnchorLocations[anchorParams.elementId];
- };
- this.setUserDefinedLocation = function(loc) {
- userDefinedContinuousAnchorLocations[anchorParams.elementId] = loc;
- };
- this.getCssClass = function() { return cssClass; };
- this.setCssClass = function(c) { cssClass = c; };
- };
-
-
- jsPlumbInstance.continuousAnchorFactory = {
- get:function(params) {
- return new ContinuousAnchor(params);
- },
- clear:function(elementId) {
- delete userDefinedContinuousAnchorLocations[elementId];
- delete continuousAnchorLocations[elementId];
- }
- };
- };
-
-
- jsPlumb.Anchor = function(params) {
- this.x = params.x || 0;
- this.y = params.y || 0;
- this.elementId = params.elementId;
- this.cssClass = params.cssClass || "";
- this.userDefinedLocation = null;
- this.orientation = params.orientation || [ 0, 0 ];
- jsPlumbUtil.EventGenerator.apply(this);
-
- var jsPlumbInstance = params.jsPlumbInstance;
-
-
- this.lastReturnValue = null;
- this.offsets = params.offsets || [ 0, 0 ];
- this.timestamp = null;
- this.compute = function(params) {
- var xy = params.xy, wh = params.wh, element = params.element, timestamp = params.timestamp;
- if(params.clearUserDefinedLocation)
- this.userDefinedLocation = null;
- if (timestamp && timestamp === self.timestamp)
- return this.lastReturnValue;
- if (this.userDefinedLocation != null) {
- this.lastReturnValue = this.userDefinedLocation;
- }
- else {
- this.lastReturnValue = [ xy[0] + (this.x * wh[0]) + this.offsets[0], xy[1] + (this.y * wh[1]) + this.offsets[1] ];
- }
- this.timestamp = timestamp;
- return this.lastReturnValue;
- };
- this.getCurrentLocation = function(params) {
- return (this.lastReturnValue == null || (params.timestamp != null && this.timestamp != params.timestamp)) ? this.compute(params) : this.lastReturnValue;
- };
- };
- jsPlumbUtil.extend(jsPlumb.Anchor, jsPlumbUtil.EventGenerator, {
- equals : function(anchor) {
- if (!anchor) return false;
- var ao = anchor.getOrientation(),
- 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];
- },
- getUserDefinedLocation : function() {
- return this.userDefinedLocation;
- },
- setUserDefinedLocation : function(l) {
- this.userDefinedLocation = l;
- },
- clearUserDefinedLocation : function() {
- this.userDefinedLocation = null;
- },
- getOrientation : function(_endpoint) { return this.orientation; },
- getCssClass : function() { return this.cssClass; }
- });
-
- jsPlumb.FloatingAnchor = function(params) {
-
- jsPlumb.Anchor.apply(this, arguments);
-
-
- var ref = params.reference,
- jsPlumbInstance = params.jsPlumbInstance,
-
- refCanvas = params.referenceCanvas,
- size = jsPlumb.getSize(refCanvas),
-
-
-
-
-
- xDir = 0, yDir = 0,
-
-
- orientation = null,
- _lastResult = null;
-
- this.orientation = null;
-
-
-
- this.x = 0; this.y = 0;
- this.isFloating = true;
- this.compute = function(params) {
- var xy = params.xy, element = params.element,
- result = [ xy[0] + (size[0] / 2), xy[1] + (size[1] / 2) ];
- _lastResult = result;
- return result;
- };
- this.getOrientation = function(_endpoint) {
- if (orientation) return orientation;
- else {
- var o = ref.getOrientation(_endpoint);
-
-
-
- return [ Math.abs(o[0]) * xDir * -1,
- Math.abs(o[1]) * yDir * -1 ];
- }
- };
-
- this.over = function(anchor, endpoint) {
- orientation = anchor.getOrientation(endpoint);
- };
-
- this.out = function() { orientation = null; };
- this.getCurrentLocation = function(params) { return _lastResult == null ? this.compute(params) : _lastResult; };
- };
- jsPlumbUtil.extend(jsPlumb.FloatingAnchor, jsPlumb.Anchor);
- var _convertAnchor = function(anchor, jsPlumbInstance, elementId) {
- return anchor.constructor == jsPlumb.Anchor ? anchor: jsPlumbInstance.makeAnchor(anchor, elementId, jsPlumbInstance);
- };
-
- jsPlumb.DynamicAnchor = function(params) {
- jsPlumb.Anchor.apply(this, arguments);
-
- this.isSelective = true;
- this.isDynamic = true;
- this.anchors = [];
- this.elementId = params.elementId;
- this.jsPlumbInstance = params.jsPlumbInstance;
- for (var i = 0; i < params.anchors.length; i++)
- this.anchors[i] = _convertAnchor(params.anchors[i], this.jsPlumbInstance, this.elementId);
- this.addAnchor = function(anchor) { this.anchors.push(_convertAnchor(anchor, this.jsPlumbInstance, this.elementId)); };
- this.getAnchors = function() { return this.anchors; };
- this.locked = false;
- var _curAnchor = this.anchors.length > 0 ? this.anchors[0] : null,
- _curIndex = this.anchors.length > 0 ? 0 : -1,
- _lastAnchor = _curAnchor,
- self = this,
-
-
- _distance = function(anchor, cx, cy, xy, wh) {
- var ax = xy[0] + (anchor.x * wh[0]), ay = xy[1] + (anchor.y * wh[1]),
- acx = xy[0] + (wh[0] / 2), acy = xy[1] + (wh[1] / 2);
- return (Math.sqrt(Math.pow(cx - ax, 2) + Math.pow(cy - ay, 2)) +
- Math.sqrt(Math.pow(acx - ax, 2) + Math.pow(acy - ay, 2)));
- },
-
-
-
-
-
-
-
- _anchorSelector = params.selector || 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;
- this.timestamp = timestamp;
-
- var udl = self.getUserDefinedLocation();
- if (udl != null) {
- return udl;
- }
-
-
-
-
- if (this.locked || txy == null || twh == null)
- return _curAnchor.compute(params);
- else
- params.timestamp = null;
-
- _curAnchor = _anchorSelector(xy, wh, txy, twh, this.anchors);
- this.x = _curAnchor.x;
- this.y = _curAnchor.y;
- if (_curAnchor != _lastAnchor)
- this.fire("anchorChanged", _curAnchor);
- _lastAnchor = _curAnchor;
-
- return _curAnchor.compute(params);
- };
- this.getCurrentLocation = function(params) {
- return this.getUserDefinedLocation() || (_curAnchor != null ? _curAnchor.getCurrentLocation(params) : null);
- };
- this.getOrientation = function(_endpoint) { return _curAnchor != null ? _curAnchor.getOrientation(_endpoint) : [ 0, 0 ]; };
- this.over = function(anchor, endpoint) { if (_curAnchor != null) _curAnchor.over(anchor, endpoint); };
- this.out = function() { if (_curAnchor != null) _curAnchor.out(); };
- this.getCssClass = function() { return (_curAnchor && _curAnchor.getCssClass()) || ""; };
- };
- jsPlumbUtil.extend(jsPlumb.DynamicAnchor, jsPlumb.Anchor);
-
- var _curryAnchor = function(x, y, ox, oy, type, fnInit) {
- jsPlumb.Anchors[type] = function(params) {
- var a = params.jsPlumbInstance.makeAnchor([ x, y, ox, oy, 0, 0 ], params.elementId, params.jsPlumbInstance);
- a.type = type;
- if (fnInit) fnInit(a, params);
- return a;
- };
- };
-
- _curryAnchor(0.5, 0, 0,-1, "TopCenter");
- _curryAnchor(0.5, 1, 0, 1, "BottomCenter");
- _curryAnchor(0, 0.5, -1, 0, "LeftMiddle");
- _curryAnchor(1, 0.5, 1, 0, "RightMiddle");
-
- _curryAnchor(0.5, 0, 0,-1, "Top");
- _curryAnchor(0.5, 1, 0, 1, "Bottom");
- _curryAnchor(0, 0.5, -1, 0, "Left");
- _curryAnchor(1, 0.5, 1, 0, "Right");
- _curryAnchor(0.5, 0.5, 0, 0, "Center");
- _curryAnchor(1, 0, 0,-1, "TopRight");
- _curryAnchor(1, 1, 0, 1, "BottomRight");
- _curryAnchor(0, 0, 0, -1, "TopLeft");
- _curryAnchor(0, 1, 0, 1, "BottomLeft");
-
-
-
- jsPlumb.Defaults.DynamicAnchors = function(params) {
- return params.jsPlumbInstance.makeAnchors(["TopCenter", "RightMiddle", "BottomCenter", "LeftMiddle"], params.elementId, params.jsPlumbInstance);
- };
-
-
- jsPlumb.Anchors.AutoDefault = function(params) {
- var a = params.jsPlumbInstance.makeDynamicAnchor(jsPlumb.Defaults.DynamicAnchors(params));
- a.type = "AutoDefault";
- return a;
- };
-
-
- var _curryContinuousAnchor = function(type, faces) {
- jsPlumb.Anchors[type] = function(params) {
- var a = params.jsPlumbInstance.makeAnchor(["Continuous", { faces:faces }], params.elementId, params.jsPlumbInstance);
- a.type = type;
- return a;
- };
- };
-
- jsPlumb.Anchors.Continuous = function(params) {
- return params.jsPlumbInstance.continuousAnchorFactory.get(params);
- };
-
- _curryContinuousAnchor("ContinuousLeft", ["left"]);
- _curryContinuousAnchor("ContinuousTop", ["top"]);
- _curryContinuousAnchor("ContinuousBottom", ["bottom"]);
- _curryContinuousAnchor("ContinuousRight", ["right"]);
-
-
-
- _curryAnchor(0, 0, 0, 0, "Assign", function(anchor, params) {
-
-
-
- var pf = params.position || "Fixed";
- anchor.positionFinder = pf.constructor == String ? params.jsPlumbInstance.AnchorPositionFinders[pf] : pf;
-
-
- anchor.constructorParams = params;
- });
-
-
-
- jsPlumbInstance.prototype.AnchorPositionFinders = {
- "Fixed": function(dp, ep, es, params) {
- return [ (dp.left - ep.left) / es[0], (dp.top - ep.top) / es[1] ];
- },
- "Grid":function(dp, ep, es, params) {
- var dx = dp.left - ep.left, dy = dp.top - ep.top,
- gx = es[0] / (params.grid[0]), gy = es[1] / (params.grid[1]),
- mx = Math.floor(dx / gx), my = Math.floor(dy / gy);
- return [ ((mx * gx) + (gx / 2)) / es[0], ((my * gy) + (gy / 2)) / es[1] ];
- }
- };
-
-
- jsPlumb.Anchors.Perimeter = function(params) {
- params = params || {};
- var anchorCount = params.anchorCount || 60,
- shape = params.shape;
-
- if (!shape) throw new Error("no shape supplied to Perimeter Anchor type");
-
- var _circle = function() {
- var r = 0.5, step = Math.PI * 2 / anchorCount, current = 0, a = [];
- for (var i = 0; i < anchorCount; i++) {
- var x = r + (r * Math.sin(current)),
- y = r + (r * Math.cos(current));
- a.push( [ x, y, 0, 0 ] );
- current += step;
- }
- return a;
- },
- _path = function(segments) {
- var anchorsPerFace = anchorCount / segments.length, a = [],
- _computeFace = function(x1, y1, x2, y2, fractionalLength) {
- anchorsPerFace = anchorCount * fractionalLength;
- var dx = (x2 - x1) / anchorsPerFace, dy = (y2 - y1) / anchorsPerFace;
- for (var i = 0; i < anchorsPerFace; i++) {
- a.push( [
- x1 + (dx * i),
- y1 + (dy * i),
- 0,
- 0
- ]);
- }
- };
-
- for (var i = 0; i < segments.length; i++)
- _computeFace.apply(null, segments[i]);
-
- return a;
- },
- _shape = function(faces) {
- var s = [];
- for (var i = 0; i < faces.length; i++) {
- s.push([faces[i][0], faces[i][1], faces[i][2], faces[i][3], 1 / faces.length]);
- }
- return _path(s);
- },
- _rectangle = function() {
- return _shape([
- [ 0, 0, 1, 0 ], [ 1, 0, 1, 1 ], [ 1, 1, 0, 1 ], [ 0, 1, 0, 0 ]
- ]);
- };
-
- var _shapes = {
- "Circle":_circle,
- "Ellipse":_circle,
- "Diamond":function() {
- return _shape([
- [ 0.5, 0, 1, 0.5 ], [ 1, 0.5, 0.5, 1 ], [ 0.5, 1, 0, 0.5 ], [ 0, 0.5, 0.5, 0 ]
- ]);
- },
- "Rectangle":_rectangle,
- "Square":_rectangle,
- "Triangle":function() {
- return _shape([
- [ 0.5, 0, 1, 1 ], [ 1, 1, 0, 1 ], [ 0, 1, 0.5, 0]
- ]);
- },
- "Path":function(params) {
- var points = params.points, p = [], tl = 0;
- for (var i = 0; i < points.length - 1; i++) {
- var l = Math.sqrt(Math.pow(points[i][2] - points[i][0]) + Math.pow(points[i][3] - points[i][1]));
- tl += l;
- p.push([points[i][0], points[i][1], points[i+1][0], points[i+1][1], l]);
- }
- for (var j = 0; j < p.length; j++) {
- p[j][4] = p[j][4] / tl;
- }
- return _path(p);
- }
- },
- _rotate = function(points, amountInDegrees) {
- var o = [], theta = amountInDegrees / 180 * Math.PI ;
- for (var i = 0; i < points.length; i++) {
- var _x = points[i][0] - 0.5,
- _y = points[i][1] - 0.5;
-
- o.push([
- 0.5 + ((_x * Math.cos(theta)) - (_y * Math.sin(theta))),
- 0.5 + ((_x * Math.sin(theta)) + (_y * Math.cos(theta))),
- points[i][2],
- points[i][3]
- ]);
- }
- return o;
- };
-
- if (!_shapes[shape]) throw new Error("Shape [" + shape + "] is unknown by Perimeter Anchor type");
-
- var da = _shapes[shape](params);
- if (params.rotation) da = _rotate(da, params.rotation);
- var a = params.jsPlumbInstance.makeDynamicAnchor(da);
- a.type = "Perimeter";
- return a;
- };
- })();
-
- ;(function() {
- "use strict";
- jsPlumb.Segments = {
-
-
- AbstractSegment : function(params) {
- this.params = params;
-
-
- this.findClosestPointOnPath = function(x, y) {
- return {
- d:Infinity,
- x:null,
- y:null,
- l:null
- };
- };
- this.getBounds = function() {
- return {
- minX:Math.min(params.x1, params.x2),
- minY:Math.min(params.y1, params.y2),
- maxX:Math.max(params.x1, params.x2),
- maxY:Math.max(params.y1, params.y2)
- };
- };
- },
- Straight : function(params) {
- var _super = jsPlumb.Segments.AbstractSegment.apply(this, arguments),
- length, m, m2, x1, x2, y1, y2,
- _recalc = function() {
- length = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
- m = Biltong.gradient({x:x1, y:y1}, {x:x2, y:y2});
- m2 = -1 / m;
- };
-
- this.type = "Straight";
-
- this.getLength = function() { return length; };
- this.getGradient = function() { return m; };
-
- this.getCoordinates = function() {
- return { x1:x1,y1:y1,x2:x2,y2:y2 };
- };
- this.setCoordinates = function(coords) {
- x1 = coords.x1; y1 = coords.y1; x2 = coords.x2; y2 = coords.y2;
- _recalc();
- };
- this.setCoordinates({x1:params.x1, y1:params.y1, x2:params.x2, y2:params.y2});
- this.getBounds = function() {
- return {
- minX:Math.min(x1, x2),
- minY:Math.min(y1, y2),
- maxX:Math.max(x1, x2),
- maxY:Math.max(y1, y2)
- };
- };
-
-
- this.pointOnPath = function(location, absolute) {
- if (location === 0 && !absolute)
- return { x:x1, y:y1 };
- else if (location == 1 && !absolute)
- return { x:x2, y:y2 };
- else {
- var l = absolute ? location > 0 ? location : length + location : location * length;
- return Biltong.pointOnLine({x:x1, y:y1}, {x:x2, y:y2}, l);
- }
- };
-
-
- this.gradientAtPoint = function(_) {
- return m;
- };
-
-
-
- this.pointAlongPathFrom = function(location, distance, absolute) {
- var p = this.pointOnPath(location, absolute),
- farAwayPoint = distance <= 0 ? {x:x1, y:y1} : {x:x2, y:y2 };
-
-
- if (distance <= 0 && Math.abs(distance) > 1) distance *= -1;
-
- return Biltong.pointOnLine(p, farAwayPoint, distance);
- };
-
-
- var within = function(a,b,c) {
- return c >= Math.min(a,b) && c <= Math.max(a,b);
- };
-
- var closest = function(a,b,c) {
- return Math.abs(c - a) < Math.abs(c - b) ? a : b;
- };
-
-
- this.findClosestPointOnPath = function(x, y) {
- var out = {
- d:Infinity,
- x:null,
- y:null,
- l:null,
- x1:x1,
- x2:x2,
- y1:y1,
- y2:y2
- };
- if (m === 0) {
- out.y = y1;
- out.x = within(x1, x2, x) ? x : closest(x1, x2, x);
- }
- else if (m == Infinity || m == -Infinity) {
- out.x = x1;
- out.y = within(y1, y2, y) ? y : closest(y1, y2, y);
- }
- else {
-
- var b = y1 - (m * x1),
- b2 = y - (m2 * x),
-
-
-
-
- _x1 = (b2 -b) / (m - m2),
- _y1 = (m * _x1) + b;
-
- out.x = within(x1,x2,_x1) ? _x1 : closest(x1,x2,_x1);
- out.y = within(y1,y2,_y1) ? _y1 : closest(y1,y2,_y1);
- }
- var fractionInSegment = Biltong.lineLength([ out.x, out.y ], [ x1, y1 ]);
- out.d = Biltong.lineLength([x,y], [out.x, out.y]);
- out.l = fractionInSegment / length;
- return out;
- };
- },
-
-
- Arc : function(params) {
- var _super = jsPlumb.Segments.AbstractSegment.apply(this, arguments),
- _calcAngle = function(_x, _y) {
- return Biltong.theta([params.cx, params.cy], [_x, _y]);
- },
- _calcAngleForLocation = function(segment, location) {
- if (segment.anticlockwise) {
- var sa = segment.startAngle < segment.endAngle ? segment.startAngle + TWO_PI : segment.startAngle,
- s = Math.abs(sa - segment.endAngle);
- return sa - (s * location);
- }
- else {
- var ea = segment.endAngle < segment.startAngle ? segment.endAngle + TWO_PI : segment.endAngle,
- ss = Math.abs (ea - segment.startAngle);
-
- return segment.startAngle + (ss * location);
- }
- },
- TWO_PI = 2 * Math.PI;
-
- this.radius = params.r;
- this.anticlockwise = params.ac;
- this.type = "Arc";
-
- if (params.startAngle && params.endAngle) {
- this.startAngle = params.startAngle;
- this.endAngle = params.endAngle;
- this.x1 = params.cx + (this.radius * Math.cos(params.startAngle));
- this.y1 = params.cy + (this.radius * Math.sin(params.startAngle));
- this.x2 = params.cx + (this.radius * Math.cos(params.endAngle));
- this.y2 = params.cy + (this.radius * Math.sin(params.endAngle));
- }
- else {
- this.startAngle = _calcAngle(params.x1, params.y1);
- this.endAngle = _calcAngle(params.x2, params.y2);
- this.x1 = params.x1;
- this.y1 = params.y1;
- this.x2 = params.x2;
- this.y2 = params.y2;
- }
-
- if (this.endAngle < 0) this.endAngle += TWO_PI;
- if (this.startAngle < 0) this.startAngle += TWO_PI;
-
- this.segment = Biltong.quadrant([this.x1, this.y1], [this.x2, this.y2]);
-
-
-
-
-
- var ea = this.endAngle < this.startAngle ? this.endAngle + TWO_PI : this.endAngle;
- this.sweep = Math.abs (ea - this.startAngle);
- if (this.anticlockwise) this.sweep = TWO_PI - this.sweep;
- var circumference = 2 * Math.PI * this.radius,
- frac = this.sweep / TWO_PI,
- length = circumference * frac;
-
- this.getLength = function() {
- return length;
- };
- this.getBounds = function() {
- return {
- minX:params.cx - params.r,
- maxX:params.cx + params.r,
- minY:params.cy - params.r,
- maxY:params.cy + params.r
- };
- };
-
- var VERY_SMALL_VALUE = 0.0000000001,
- gentleRound = function(n) {
- var f = Math.floor(n), r = Math.ceil(n);
- if (n - f < VERY_SMALL_VALUE)
- return f;
- else if (r - n < VERY_SMALL_VALUE)
- return r;
- return n;
- };
-
-
- this.pointOnPath = function(location, absolute) {
-
- if (location === 0) {
- return { x:this.x1, y:this.y1, theta:this.startAngle };
- }
- else if (location == 1) {
- return { x:this.x2, y:this.y2, theta:this.endAngle };
- }
-
- if (absolute) {
- location = location / length;
- }
-
- var angle = _calcAngleForLocation(this, location),
- _x = params.cx + (params.r * Math.cos(angle)),
- _y = params.cy + (params.r * Math.sin(angle));
-
- return { x:gentleRound(_x), y:gentleRound(_y), theta:angle };
- };
-
-
- this.gradientAtPoint = function(location, absolute) {
- var p = this.pointOnPath(location, absolute);
- var m = Biltong.normal( [ params.cx, params.cy ], [p.x, p.y ] );
- if (!this.anticlockwise && (m == Infinity || m == -Infinity)) m *= -1;
- return m;
- };
-
- this.pointAlongPathFrom = function(location, distance, absolute) {
- var p = this.pointOnPath(location, absolute),
- arcSpan = distance / circumference * 2 * Math.PI,
- dir = this.anticlockwise ? -1 : 1,
- startAngle = p.theta + (dir * arcSpan),
- startX = params.cx + (this.radius * Math.cos(startAngle)),
- startY = params.cy + (this.radius * Math.sin(startAngle));
-
- return {x:startX, y:startY};
- };
- },
-
- Bezier : function(params) {
- this.curve = [
- { x:params.x1, y:params.y1},
- { x:params.cp1x, y:params.cp1y },
- { x:params.cp2x, y:params.cp2y },
- { x:params.x2, y:params.y2 }
- ];
- var _super = jsPlumb.Segments.AbstractSegment.apply(this, arguments);
-
-
-
- this.bounds = {
- minX:Math.min(params.x1, params.x2, params.cp1x, params.cp2x),
- minY:Math.min(params.y1, params.y2, params.cp1y, params.cp2y),
- maxX:Math.max(params.x1, params.x2, params.cp1x, params.cp2x),
- maxY:Math.max(params.y1, params.y2, params.cp1y, params.cp2y)
- };
-
- this.type = "Bezier";
-
- var _translateLocation = function(_curve, location, absolute) {
- if (absolute)
- location = jsBezier.locationAlongCurveFrom(_curve, location > 0 ? 0 : 1, location);
-
- return location;
- };
-
-
- this.pointOnPath = function(location, absolute) {
- location = _translateLocation(this.curve, location, absolute);
- return jsBezier.pointOnCurve(this.curve, location);
- };
-
-
- this.gradientAtPoint = function(location, absolute) {
- location = _translateLocation(this.curve, location, absolute);
- return jsBezier.gradientAtPoint(this.curve, location);
- };
-
- this.pointAlongPathFrom = function(location, distance, absolute) {
- location = _translateLocation(this.curve, location, absolute);
- return jsBezier.pointAlongCurveFrom(this.curve, location, distance);
- };
-
- this.getLength = function() {
- return jsBezier.getLength(this.curve);
- };
- this.getBounds = function() {
- return this.bounds;
- };
- }
- };
-
- var AbstractComponent = function() {
- this.resetBounds = function() {
- this.bounds = { minX:Infinity, minY:Infinity, maxX:-Infinity, maxY:-Infinity };
- };
- this.resetBounds();
- };
-
-
- jsPlumb.Connectors.AbstractConnector = function(params) {
-
- AbstractComponent.apply(this, arguments);
- var segments = [],
- totalLength = 0,
- segmentProportions = [],
- segmentProportionalLengths = [],
- stub = params.stub || 0,
- sourceStub = jsPlumbUtil.isArray(stub) ? stub[0] : stub,
- targetStub = jsPlumbUtil.isArray(stub) ? stub[1] : stub,
- gap = params.gap || 0,
- sourceGap = jsPlumbUtil.isArray(gap) ? gap[0] : gap,
- targetGap = jsPlumbUtil.isArray(gap) ? gap[1] : gap,
- userProvidedSegments = null,
- edited = false,
- paintInfo = null;
-
- this.getPath = function() { };
- this.setPath = function(path) { };
-
-
-
- this.findSegmentForPoint = function(x, y) {
- var out = { d:Infinity, s:null, x:null, y:null, l:null };
- for (var i = 0; i < segments.length; i++) {
- var _s = segments[i].findClosestPointOnPath(x, y);
- if (_s.d < out.d) {
- out.d = _s.d;
- out.l = _s.l;
- out.x = _s.x;
- out.y = _s.y;
- out.s = segments[i];
- out.x1 = _s.x1;
- out.x2 = _s.x2;
- out.y1 = _s.y1;
- out.y2 = _s.y2;
- out.index = i;
- }
- }
-
- return out;
- };
- var _updateSegmentProportions = function() {
- var curLoc = 0;
- for (var i = 0; i < segments.length; i++) {
- var sl = segments[i].getLength();
- segmentProportionalLengths[i] = sl / totalLength;
- segmentProportions[i] = [curLoc, (curLoc += (sl / totalLength)) ];
- }
- },
-
-
- _findSegmentForLocation = function(location, absolute) {
- if (absolute) {
- location = location > 0 ? location / totalLength : (totalLength + location) / totalLength;
- }
- var idx = segmentProportions.length - 1, inSegmentProportion = 1;
- for (var i = 0; i < segmentProportions.length; i++) {
- if (segmentProportions[i][1] >= location) {
- idx = i;
-
- inSegmentProportion = location == 1 ? 1 : location === 0 ? 0 : (location - segmentProportions[i][0]) / segmentProportionalLengths[i];
- break;
- }
- }
- return { segment:segments[idx], proportion:inSegmentProportion, index:idx };
- },
- _addSegment = function(conn, type, params) {
- if (params.x1 == params.x2 && params.y1 == params.y2) return;
- var s = new jsPlumb.Segments[type](params);
- segments.push(s);
- totalLength += s.getLength();
- conn.updateBounds(s);
- },
- _clearSegments = function() {
- totalLength = segments.length = segmentProportions.length = segmentProportionalLengths.length = 0;
- };
- this.setSegments = function(_segs) {
- userProvidedSegments = [];
- totalLength = 0;
- for (var i = 0; i < _segs.length; i++) {
- userProvidedSegments.push(_segs[i]);
- totalLength += _segs[i].getLength();
- }
- };
- var _prepareCompute = function(params) {
- this.lineWidth = params.lineWidth;
- var segment = Biltong.quadrant(params.sourcePos, params.targetPos),
- swapX = params.targetPos[0] < params.sourcePos[0],
- swapY = params.targetPos[1] < params.sourcePos[1],
- lw = params.lineWidth || 1,
- so = params.sourceEndpoint.anchor.getOrientation(params.sourceEndpoint),
- to = params.targetEndpoint.anchor.getOrientation(params.targetEndpoint),
- x = swapX ? params.targetPos[0] : params.sourcePos[0],
- y = swapY ? params.targetPos[1] : params.sourcePos[1],
- w = Math.abs(params.targetPos[0] - params.sourcePos[0]),
- h = Math.abs(params.targetPos[1] - params.sourcePos[1]);
-
-
-
- if (so[0] === 0 && so[1] === 0 || to[0] === 0 && to[1] === 0) {
- var index = w > h ? 0 : 1, oIndex = [1,0][index];
- so = []; to = [];
- so[index] = params.sourcePos[index] > params.targetPos[index] ? -1 : 1;
- to[index] = params.sourcePos[index] > params.targetPos[index] ? 1 : -1;
- so[oIndex] = 0; to[oIndex] = 0;
- }
-
- var sx = swapX ? w + (sourceGap * so[0]) : sourceGap * so[0],
- sy = swapY ? h + (sourceGap * so[1]) : sourceGap * so[1],
- tx = swapX ? targetGap * to[0] : w + (targetGap * to[0]),
- ty = swapY ? targetGap * to[1] : h + (targetGap * to[1]),
- oProduct = ((so[0] * to[0]) + (so[1] * to[1]));
-
- var result = {
- sx:sx, sy:sy, tx:tx, ty:ty, lw:lw,
- xSpan:Math.abs(tx - sx),
- ySpan:Math.abs(ty - sy),
- mx:(sx + tx) / 2,
- my:(sy + ty) / 2,
- so:so, to:to, x:x, y:y, w:w, h:h,
- segment : segment,
- startStubX : sx + (so[0] * sourceStub),
- startStubY : sy + (so[1] * sourceStub),
- endStubX : tx + (to[0] * targetStub),
- endStubY : ty + (to[1] * targetStub),
- isXGreaterThanStubTimes2 : Math.abs(sx - tx) > (sourceStub + targetStub),
- isYGreaterThanStubTimes2 : Math.abs(sy - ty) > (sourceStub + targetStub),
- opposite:oProduct == -1,
- perpendicular:oProduct === 0,
- orthogonal:oProduct == 1,
- sourceAxis : so[0] === 0 ? "y" : "x",
- points:[x, y, w, h, sx, sy, tx, ty ]
- };
- result.anchorOrientation = result.opposite ? "opposite" : result.orthogonal ? "orthogonal" : "perpendicular";
- return result;
- };
-
- this.getSegments = function() { return segments; };
- this.updateBounds = function(segment) {
- var segBounds = segment.getBounds();
- this.bounds.minX = Math.min(this.bounds.minX, segBounds.minX);
- this.bounds.maxX = Math.max(this.bounds.maxX, segBounds.maxX);
- this.bounds.minY = Math.min(this.bounds.minY, segBounds.minY);
- this.bounds.maxY = Math.max(this.bounds.maxY, segBounds.maxY);
- };
-
- var dumpSegmentsToConsole = function() {
- console.log("SEGMENTS:");
- for (var i = 0; i < segments.length; i++) {
- console.log(segments[i].type, segments[i].getLength(), segmentProportions[i]);
- }
- };
- this.pointOnPath = function(location, absolute) {
- var seg = _findSegmentForLocation(location, absolute);
- return seg.segment && seg.segment.pointOnPath(seg.proportion, false) || [0,0];
- };
-
- this.gradientAtPoint = function(location, absolute) {
- var seg = _findSegmentForLocation(location, absolute);
- return seg.segment && seg.segment.gradientAtPoint(seg.proportion, false) || 0;
- };
-
- this.pointAlongPathFrom = function(location, distance, absolute) {
- var seg = _findSegmentForLocation(location, absolute);
-
- return seg.segment && seg.segment.pointAlongPathFrom(seg.proportion, distance, false) || [0,0];
- };
-
- this.compute = function(params) {
- if (!edited)
- paintInfo = _prepareCompute.call(this, params);
-
- _clearSegments();
- this._compute(paintInfo, params);
- this.x = paintInfo.points[0];
- this.y = paintInfo.points[1];
- this.w = paintInfo.points[2];
- this.h = paintInfo.points[3];
- this.segment = paintInfo.segment;
- _updateSegmentProportions();
- };
-
- return {
- addSegment:_addSegment,
- prepareCompute:_prepareCompute,
- sourceStub:sourceStub,
- targetStub:targetStub,
- maxStub:Math.max(sourceStub, targetStub),
- sourceGap:sourceGap,
- targetGap:targetGap,
- maxGap:Math.max(sourceGap, targetGap)
- };
- };
- jsPlumbUtil.extend(jsPlumb.Connectors.AbstractConnector, AbstractComponent);
-
-
- var Straight = jsPlumb.Connectors.Straight = function() {
- this.type = "Straight";
- var _super = jsPlumb.Connectors.AbstractConnector.apply(this, arguments);
- this._compute = function(paintInfo, _) {
- _super.addSegment(this, "Straight", {x1:paintInfo.sx, y1:paintInfo.sy, x2:paintInfo.startStubX, y2:paintInfo.startStubY});
- _super.addSegment(this, "Straight", {x1:paintInfo.startStubX, y1:paintInfo.startStubY, x2:paintInfo.endStubX, y2:paintInfo.endStubY});
- _super.addSegment(this, "Straight", {x1:paintInfo.endStubX, y1:paintInfo.endStubY, x2:paintInfo.tx, y2:paintInfo.ty});
- };
- };
- jsPlumbUtil.extend(jsPlumb.Connectors.Straight, jsPlumb.Connectors.AbstractConnector);
- jsPlumb.registerConnectorType(Straight, "Straight");
-
-
-
-
- jsPlumb.Endpoints.AbstractEndpoint = function(params) {
- AbstractComponent.apply(this, arguments);
- var compute = this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- var out = this._compute.apply(this, arguments);
- this.x = out[0];
- this.y = out[1];
- this.w = out[2];
- this.h = out[3];
- this.bounds.minX = this.x;
- this.bounds.minY = this.y;
- this.bounds.maxX = this.x + this.w;
- this.bounds.maxY = this.y + this.h;
- return out;
- };
- return {
- compute:compute,
- cssClass:params.cssClass
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.AbstractEndpoint, AbstractComponent);
-
-
-
-
-
- jsPlumb.Endpoints.Dot = function(params) {
- this.type = "Dot";
- var _super = jsPlumb.Endpoints.AbstractEndpoint.apply(this, arguments);
- params = params || {};
- this.radius = params.radius || 10;
- this.defaultOffset = 0.5 * this.radius;
- this.defaultInnerRadius = this.radius / 3;
-
- this._compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- this.radius = endpointStyle.radius || this.radius;
- var x = anchorPoint[0] - this.radius,
- y = anchorPoint[1] - this.radius,
- w = this.radius * 2,
- h = this.radius * 2;
- if (endpointStyle.strokeStyle) {
- var lw = endpointStyle.lineWidth || 1;
- x -= lw;
- y -= lw;
- w += (lw * 2);
- h += (lw * 2);
- }
- return [ x, y, w, h, this.radius ];
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.Dot, jsPlumb.Endpoints.AbstractEndpoint);
- jsPlumb.Endpoints.Rectangle = function(params) {
- this.type = "Rectangle";
- var _super = jsPlumb.Endpoints.AbstractEndpoint.apply(this, arguments);
- params = params || {};
- this.width = params.width || 20;
- this.height = params.height || 20;
- this._compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- var width = endpointStyle.width || this.width,
- height = endpointStyle.height || this.height,
- x = anchorPoint[0] - (width/2),
- y = anchorPoint[1] - (height/2);
- return [ x, y, width, height];
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.Rectangle, jsPlumb.Endpoints.AbstractEndpoint);
- var DOMElementEndpoint = function(params) {
- jsPlumb.jsPlumbUIComponent.apply(this, arguments);
- this._jsPlumb.displayElements = [];
- };
- jsPlumbUtil.extend(DOMElementEndpoint, jsPlumb.jsPlumbUIComponent, {
- getDisplayElements : function() {
- return this._jsPlumb.displayElements;
- },
- appendDisplayElement : function(el) {
- this._jsPlumb.displayElements.push(el);
- }
- });
-
-
- jsPlumb.Endpoints.Image = function(params) {
- this.type = "Image";
- DOMElementEndpoint.apply(this, arguments);
- jsPlumb.Endpoints.AbstractEndpoint.apply(this, arguments);
- var _onload = params.onload,
- src = params.src || params.url,
- clazz = params.cssClass ? " " + params.cssClass : "";
- this._jsPlumb.img = new Image();
- this._jsPlumb.ready = false;
- this._jsPlumb.initialized = false;
- this._jsPlumb.deleted = false;
- this._jsPlumb.widthToUse = params.width;
- this._jsPlumb.heightToUse = params.height;
- this._jsPlumb.endpoint = params.endpoint;
- this._jsPlumb.img.onload = function() {
- if (this._jsPlumb != null) {
- this._jsPlumb.ready = true;
- this._jsPlumb.widthToUse = this._jsPlumb.widthToUse || this._jsPlumb.img.width;
- this._jsPlumb.heightToUse = this._jsPlumb.heightToUse || this._jsPlumb.img.height;
- if (_onload) {
- _onload(this);
- }
- }
- }.bind(this);
-
- this._jsPlumb.endpoint.setImage = function(_img, onload) {
- var s = _img.constructor == String ? _img : _img.src;
- _onload = onload;
- this._jsPlumb.img.src = s;
- if (this.canvas != null)
- this.canvas.setAttribute("src", this._jsPlumb.img.src);
- }.bind(this);
- this._jsPlumb.endpoint.setImage(src, _onload);
- this._compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- this.anchorPoint = anchorPoint;
- if (this._jsPlumb.ready) return [anchorPoint[0] - this._jsPlumb.widthToUse / 2, anchorPoint[1] - this._jsPlumb.heightToUse / 2,
- this._jsPlumb.widthToUse, this._jsPlumb.heightToUse];
- else return [0,0,0,0];
- };
-
- this.canvas = document.createElement("img");
- this.canvas.style.margin = 0;
- this.canvas.style.padding = 0;
- this.canvas.style.outline = 0;
- this.canvas.style.position = "absolute";
- this.canvas.className = this._jsPlumb.instance.endpointClass + clazz;
- if (this._jsPlumb.widthToUse) this.canvas.setAttribute("width", this._jsPlumb.widthToUse);
- if (this._jsPlumb.heightToUse) this.canvas.setAttribute("height", this._jsPlumb.heightToUse);
- this._jsPlumb.instance.appendElement(this.canvas);
-
- this.actuallyPaint = function(d, style, anchor) {
- if (!this._jsPlumb.deleted) {
- if (!this._jsPlumb.initialized) {
- this.canvas.setAttribute("src", this._jsPlumb.img.src);
- this.appendDisplayElement(this.canvas);
- this._jsPlumb.initialized = true;
- }
- var x = this.anchorPoint[0] - (this._jsPlumb.widthToUse / 2),
- y = this.anchorPoint[1] - (this._jsPlumb.heightToUse / 2);
- jsPlumbUtil.sizeElement(this.canvas, x, y, this._jsPlumb.widthToUse, this._jsPlumb.heightToUse);
- }
- };
-
- this.paint = function(style, anchor) {
- if (this._jsPlumb != null) {
- if (this._jsPlumb.ready) {
- this.actuallyPaint(style, anchor);
- }
- else {
- window.setTimeout(function() {
- this.paint(style, anchor);
- }.bind(this), 200);
- }
- }
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.Image, [ DOMElementEndpoint, jsPlumb.Endpoints.AbstractEndpoint ], {
- cleanup : function() {
- this._jsPlumb.deleted = true;
- if (this.canvas) this.canvas.parentNode.removeChild(this.canvas);
- this.canvas = null;
- }
- });
-
-
- jsPlumb.Endpoints.Blank = function(params) {
- var _super = jsPlumb.Endpoints.AbstractEndpoint.apply(this, arguments);
- this.type = "Blank";
- DOMElementEndpoint.apply(this, arguments);
- this._compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- return [anchorPoint[0], anchorPoint[1],10,0];
- };
- var clazz = params.cssClass ? " " + params.cssClass : "";
-
- this.canvas = document.createElement("div");
- this.canvas.style.display = "block";
- this.canvas.style.width = "1px";
- this.canvas.style.height = "1px";
- this.canvas.style.background = "transparent";
- this.canvas.style.position = "absolute";
- this.canvas.className = this._jsPlumb.instance.endpointClass + clazz;
- this._jsPlumb.instance.appendElement(this.canvas);
-
- this.paint = function(style, anchor) {
- jsPlumbUtil.sizeElement(this.canvas, this.x, this.y, this.w, this.h);
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.Blank, [jsPlumb.Endpoints.AbstractEndpoint, DOMElementEndpoint], {
- cleanup:function() {
- if (this.canvas && this.canvas.parentNode) {
- this.canvas.parentNode.removeChild(this.canvas);
- }
- }
- });
-
-
-
- jsPlumb.Endpoints.Triangle = function(params) {
- this.type = "Triangle";
- jsPlumb.Endpoints.AbstractEndpoint.apply(this, arguments);
- params = params || { };
- params.width = params.width || 55;
- params.height = params.height || 55;
- this.width = params.width;
- this.height = params.height;
- this._compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
- var width = endpointStyle.width || self.width,
- height = endpointStyle.height || self.height,
- x = anchorPoint[0] - (width/2),
- y = anchorPoint[1] - (height/2);
- return [ x, y, width, height ];
- };
- };
-
- var AbstractOverlay = jsPlumb.Overlays.AbstractOverlay = function(params) {
- this.visible = true;
- this.isAppendedAtTopLevel = true;
- this.component = params.component;
- this.loc = params.location == null ? 0.5 : params.location;
- this.endpointLoc = params.endpointLocation == null ? [ 0.5, 0.5] : params.endpointLocation;
- };
- AbstractOverlay.prototype = {
- cleanup:function() {
- this.component = null;
- this.canvas = null;
- this.endpointLoc = null;
- },
- setVisible : function(val) {
- this.visible = val;
- this.component.repaint();
- },
- isVisible : function() { return this.visible; },
- hide : function() { this.setVisible(false); },
- show : function() { this.setVisible(true); },
- incrementLocation : function(amount) {
- this.loc += amount;
- this.component.repaint();
- },
- setLocation : function(l) {
- this.loc = l;
- this.component.repaint();
- },
- getLocation : function() {
- return this.loc;
- }
- };
-
-
-
-
- jsPlumb.Overlays.Arrow = function(params) {
- this.type = "Arrow";
- AbstractOverlay.apply(this, arguments);
- this.isAppendedAtTopLevel = false;
- params = params || {};
- var _ju = jsPlumbUtil, _jg = Biltong;
-
- this.length = params.length || 20;
- this.width = params.width || 20;
- this.id = params.id;
- var direction = (params.direction || 1) < 0 ? -1 : 1,
- paintStyle = params.paintStyle || { lineWidth:1 },
-
- foldback = params.foldback || 0.623;
-
- this.computeMaxSize = function() { return self.width * 1.5; };
- this.draw = function(component, currentConnectionPaintStyle) {
- var hxy, mid, txy, tail, cxy;
- if (component.pointAlongPathFrom) {
- if (_ju.isString(this.loc) || this.loc > 1 || this.loc < 0) {
- var l = parseInt(this.loc, 10),
- fromLoc = this.loc < 0 ? 1 : 0;
- hxy = component.pointAlongPathFrom(fromLoc, l, false);
- mid = component.pointAlongPathFrom(fromLoc, l - (direction * this.length / 2), false);
- txy = _jg.pointOnLine(hxy, mid, this.length);
- }
- else if (this.loc == 1) {
- hxy = component.pointOnPath(this.loc);
- mid = component.pointAlongPathFrom(this.loc, -(this.length));
- txy = _jg.pointOnLine(hxy, mid, this.length);
-
- if (direction == -1) {
- var _ = txy;
- txy = hxy;
- hxy = _;
- }
- }
- else if (this.loc === 0) {
- txy = component.pointOnPath(this.loc);
- mid = component.pointAlongPathFrom(this.loc, this.length);
- hxy = _jg.pointOnLine(txy, mid, this.length);
- if (direction == -1) {
- var __ = txy;
- txy = hxy;
- hxy = __;
- }
- }
- else {
- hxy = component.pointAlongPathFrom(this.loc, direction * this.length / 2);
- mid = component.pointOnPath(this.loc);
- txy = _jg.pointOnLine(hxy, mid, this.length);
- }
- tail = _jg.perpendicularLineTo(hxy, txy, this.width);
- cxy = _jg.pointOnLine(hxy, txy, foldback * this.length);
-
- var d = { hxy:hxy, tail:tail, cxy:cxy },
- strokeStyle = paintStyle.strokeStyle || currentConnectionPaintStyle.strokeStyle,
- fillStyle = paintStyle.fillStyle || currentConnectionPaintStyle.strokeStyle,
- lineWidth = paintStyle.lineWidth || currentConnectionPaintStyle.lineWidth;
- return {
- component:component,
- d:d,
- lineWidth:lineWidth,
- strokeStyle:strokeStyle,
- fillStyle:fillStyle,
- minX:Math.min(hxy.x, tail[0].x, tail[1].x),
- maxX:Math.max(hxy.x, tail[0].x, tail[1].x),
- minY:Math.min(hxy.y, tail[0].y, tail[1].y),
- maxY:Math.max(hxy.y, tail[0].y, tail[1].y)
- };
- }
- else return {component:component, minX:0,maxX:0,minY:0,maxY:0};
- };
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.Arrow, AbstractOverlay);
-
-
-
- jsPlumb.Overlays.PlainArrow = function(params) {
- params = params || {};
- var p = jsPlumb.extend(params, {foldback:1});
- jsPlumb.Overlays.Arrow.call(this, p);
- this.type = "PlainArrow";
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.PlainArrow, jsPlumb.Overlays.Arrow);
-
-
-
- jsPlumb.Overlays.Diamond = function(params) {
- params = params || {};
- var l = params.length || 40,
- p = jsPlumb.extend(params, {length:l/2, foldback:2});
- jsPlumb.Overlays.Arrow.call(this, p);
- this.type = "Diamond";
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.Diamond, jsPlumb.Overlays.Arrow);
- var _getDimensions = function(component, forceRefresh) {
- if (component._jsPlumb.cachedDimensions == null || forceRefresh)
- component._jsPlumb.cachedDimensions = component.getDimensions();
- return component._jsPlumb.cachedDimensions;
- };
-
-
- var AbstractDOMOverlay = function(params) {
- jsPlumb.jsPlumbUIComponent.apply(this, arguments);
- AbstractOverlay.apply(this, arguments);
-
- var _f = this.fire;
- this.fire = function() {
- _f.apply(this, arguments);
- if (this.component) this.component.fire.apply(this.component, arguments);
- };
- this.id = params.id;
- this._jsPlumb.div = null;
- this._jsPlumb.initialised = false;
- this._jsPlumb.component = params.component;
- this._jsPlumb.cachedDimensions = null;
- this._jsPlumb.create = params.create;
- this._jsPlumb.initiallyInvisible = params.visible === false;
- this.getElement = function() {
- if (this._jsPlumb.div == null) {
- var div = this._jsPlumb.div = jsPlumb.getDOMElement(this._jsPlumb.create(this._jsPlumb.component));
- div.style.position = "absolute";
- div.className = this._jsPlumb.instance.overlayClass + " " +
- (this.cssClass ? this.cssClass :
- params.cssClass ? params.cssClass : "");
- this._jsPlumb.instance.appendElement(div);
- this._jsPlumb.instance.getId(div);
- this.canvas = div;
-
-
- var ts = "translate(-50%, -50%)";
- div.style.webkitTransform = ts;
- div.style.mozTransform = ts;
- div.style.msTransform = ts;
- div.style.oTransform = ts;
- div.style.transform = ts;
-
- div._jsPlumb = this;
- if (params.visible === false)
- div.style.display = "none";
- }
- return this._jsPlumb.div;
- };
- this.draw = function(component, currentConnectionPaintStyle, absolutePosition) {
- var td = _getDimensions(this);
- if (td != null && td.length == 2) {
- var cxy = { x:0,y:0 };
-
- if (absolutePosition) {
- cxy = { x:absolutePosition[0], y:absolutePosition[1] };
- }
- else if (component.pointOnPath) {
- var loc = this.loc, absolute = false;
- if (jsPlumbUtil.isString(this.loc) || this.loc < 0 || this.loc > 1) {
- loc = parseInt(this.loc, 10);
- absolute = true;
- }
- cxy = component.pointOnPath(loc, absolute);
- }
- else {
- var locToUse = this.loc.constructor == Array ? this.loc : this.endpointLoc;
- cxy = { x:locToUse[0] * component.w,
- y:locToUse[1] * component.h };
- }
- var minx = cxy.x - (td[0] / 2),
- miny = cxy.y - (td[1] / 2);
- return {
- component:component,
- d:{ minx:minx, miny:miny, td:td, cxy:cxy },
- minX:minx,
- maxX:minx + td[0],
- minY:miny,
- maxY:miny + td[1]
- };
- }
- else return {minX:0,maxX:0,minY:0,maxY:0};
- };
- };
- jsPlumbUtil.extend(AbstractDOMOverlay, [jsPlumb.jsPlumbUIComponent, AbstractOverlay], {
- getDimensions : function() {
- return jsPlumbUtil.oldIE ? jsPlumb.getSize(this.getElement()) : [1,1];
- },
- setVisible : function(state) {
- this._jsPlumb.div.style.display = state ? "block" : "none";
-
- if (state && this._jsPlumb.initiallyInvisible) {
- _getDimensions(this, true);
- this.component.repaint();
- this._jsPlumb.initiallyInvisible = false;
- }
- },
-
- clearCachedDimensions : function() {
- this._jsPlumb.cachedDimensions = null;
- },
- cleanup : function() {
- if (this._jsPlumb.div != null) {
- this._jsPlumb.div._jsPlumb = null;
- this._jsPlumb.instance.removeElement(this._jsPlumb.div);
- }
- },
- computeMaxSize : function() {
- var td = _getDimensions(this);
- return Math.max(td[0], td[1]);
- },
- paint : function(p, containerExtents) {
- if (!this._jsPlumb.initialised) {
- this.getElement();
- p.component.appendDisplayElement(this._jsPlumb.div);
- this._jsPlumb.initialised = true;
- }
- this._jsPlumb.div.style.left = (p.component.x + p.d.minx) + "px";
- this._jsPlumb.div.style.top = (p.component.y + p.d.miny) + "px";
- }
- });
-
-
-
- jsPlumb.Overlays.Custom = function(params) {
- this.type = "Custom";
- AbstractDOMOverlay.apply(this, arguments);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.Custom, AbstractDOMOverlay);
- jsPlumb.Overlays.GuideLines = function() {
- var self = this;
- self.length = 50;
- self.lineWidth = 5;
- this.type = "GuideLines";
- AbstractOverlay.apply(this, arguments);
- jsPlumb.jsPlumbUIComponent.apply(this, arguments);
- this.draw = function(connector, currentConnectionPaintStyle) {
- var head = connector.pointAlongPathFrom(self.loc, self.length / 2),
- mid = connector.pointOnPath(self.loc),
- tail = Biltong.pointOnLine(head, mid, self.length),
- tailLine = Biltong.perpendicularLineTo(head, tail, 40),
- headLine = Biltong.perpendicularLineTo(tail, head, 20);
- return {
- connector:connector,
- head:head,
- tail:tail,
- headLine:headLine,
- tailLine:tailLine,
- minX:Math.min(head.x, tail.x, headLine[0].x, headLine[1].x),
- minY:Math.min(head.y, tail.y, headLine[0].y, headLine[1].y),
- maxX:Math.max(head.x, tail.x, headLine[0].x, headLine[1].x),
- maxY:Math.max(head.y, tail.y, headLine[0].y, headLine[1].y)
- };
- };
-
- };
-
-
-
- jsPlumb.Overlays.Label = function(params) {
- this.labelStyle = params.labelStyle;
-
- var labelWidth = null, labelHeight = null, labelText = null, labelPadding = null;
- this.cssClass = this.labelStyle != null ? this.labelStyle.cssClass : null;
- var p = jsPlumb.extend({
- create : function() {
- return document.createElement("div");
- }}, params);
- jsPlumb.Overlays.Custom.call(this, p);
- this.type = "Label";
- this.label = params.label || "";
- this.labelText = null;
- if (this.labelStyle) {
- var el = this.getElement();
- this.labelStyle.font = this.labelStyle.font || "12px sans-serif";
- el.style.font = this.labelStyle.font;
- el.style.color = this.labelStyle.color || "black";
- if (this.labelStyle.fillStyle) el.style.background = this.labelStyle.fillStyle;
- if (this.labelStyle.borderWidth > 0) {
- var dStyle = this.labelStyle.borderStyle ? this.labelStyle.borderStyle : "black";
- el.style.border = this.labelStyle.borderWidth + "px solid " + dStyle;
- }
- if (this.labelStyle.padding) el.style.padding = this.labelStyle.padding;
- }
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.Label, jsPlumb.Overlays.Custom, {
- cleanup:function() {
- this.div = null;
- this.label = null;
- this.labelText = null;
- this.cssClass = null;
- this.labelStyle = null;
- },
- getLabel : function() {
- return this.label;
- },
-
- setLabel : function(l) {
- this.label = l;
- this.labelText = null;
- this.clearCachedDimensions();
- this.update();
- this.component.repaint();
- },
- getDimensions : function() {
- this.update();
- return AbstractDOMOverlay.prototype.getDimensions.apply(this, arguments);
- },
- update : function() {
- if (typeof this.label == "function") {
- var lt = this.label(this);
- this.getElement().innerHTML = lt.replace(/\r\n/g, "<br/>");
- }
- else {
- if (this.labelText == null) {
- this.labelText = this.label;
- this.getElement().innerHTML = this.labelText.replace(/\r\n/g, "<br/>");
- }
- }
- }
- });
-
-
- })();
- ;(function() {
- "use strict";
- var _getEventManager = function(instance) {
- var e = instance._mottle;
- if (!e) {
- e = instance._mottle = new Mottle();
- }
- return e;
- };
- jsPlumb.extend(jsPlumbInstance.prototype, {
- getEventManager:function() {
- return _getEventManager(this);
- },
-
-
- on : function(el, event, callback) {
-
-
-
-
-
- this.getEventManager().on.apply(this, arguments);
- },
- off : function(el, event, callback) {
- this.getEventManager().off.apply(this, arguments);
- }
- });
- }).call(this);
- ;(function() {
-
- "use strict";
-
-
- var Flowchart = function(params) {
- this.type = "Flowchart";
- params = params || {};
- params.stub = params.stub == null ? 30 : params.stub;
- var self = this,
- _super = jsPlumb.Connectors.AbstractConnector.apply(this, arguments),
- midpoint = params.midpoint == null ? 0.5 : params.midpoint,
- points = [], segments = [],
- grid = params.grid,
- alwaysRespectStubs = params.alwaysRespectStubs,
- userSuppliedSegments = null,
- lastx = null, lasty = null, lastOrientation,
- cornerRadius = params.cornerRadius != null ? params.cornerRadius : 0,
- sgn = function(n) { return n < 0 ? -1 : n === 0 ? 0 : 1; },
-
- addSegment = function(segments, x, y, paintInfo) {
- if (lastx == x && lasty == y) return;
- var lx = lastx == null ? paintInfo.sx : lastx,
- ly = lasty == null ? paintInfo.sy : lasty,
- o = lx == x ? "v" : "h",
- sgnx = sgn(x - lx),
- sgny = sgn(y - ly);
-
- lastx = x;
- lasty = y;
- segments.push([lx, ly, x, y, o, sgnx, sgny]);
- },
- segLength = function(s) {
- return Math.sqrt(Math.pow(s[0] - s[2], 2) + Math.pow(s[1] - s[3], 2));
- },
- _cloneArray = function(a) { var _a = []; _a.push.apply(_a, a); return _a;},
- updateMinMax = function(a1) {
- self.bounds.minX = Math.min(self.bounds.minX, a1[2]);
- self.bounds.maxX = Math.max(self.bounds.maxX, a1[2]);
- self.bounds.minY = Math.min(self.bounds.minY, a1[3]);
- self.bounds.maxY = Math.max(self.bounds.maxY, a1[3]);
- },
- writeSegments = function(conn, segments, paintInfo) {
- var current, next;
- for (var i = 0; i < segments.length - 1; i++) {
-
- current = current || _cloneArray(segments[i]);
- next = _cloneArray(segments[i + 1]);
- if (cornerRadius > 0 && current[4] != next[4]) {
- var radiusToUse = Math.min(cornerRadius, segLength(current), segLength(next));
-
- current[2] -= current[5] * radiusToUse;
- current[3] -= current[6] * radiusToUse;
- next[0] += next[5] * radiusToUse;
- next[1] += next[6] * radiusToUse;
- var ac = (current[6] == next[5] && next[5] == 1) ||
- ((current[6] == next[5] && next[5] === 0) && current[5] != next[6]) ||
- (current[6] == next[5] && next[5] == -1),
- sgny = next[1] > current[3] ? 1 : -1,
- sgnx = next[0] > current[2] ? 1 : -1,
- sgnEqual = sgny == sgnx,
- cx = (sgnEqual && ac || (!sgnEqual && !ac)) ? next[0] : current[2],
- cy = (sgnEqual && ac || (!sgnEqual && !ac)) ? current[3] : next[1];
-
- _super.addSegment(conn, "Straight", {
- x1:current[0], y1:current[1], x2:current[2], y2:current[3]
- });
-
- _super.addSegment(conn, "Arc", {
- r:radiusToUse,
- x1:current[2],
- y1:current[3],
- x2:next[0],
- y2:next[1],
- cx:cx,
- cy:cy,
- ac:ac
- });
- }
- else {
-
- var dx = (current[2] == current[0]) ? 0 : (current[2] > current[0]) ? (paintInfo.lw / 2) : -(paintInfo.lw / 2),
- dy = (current[3] == current[1]) ? 0 : (current[3] > current[1]) ? (paintInfo.lw / 2) : -(paintInfo.lw / 2);
- _super.addSegment(conn, "Straight", {
- x1:current[0]- dx, y1:current[1]-dy, x2:current[2] + dx, y2:current[3] + dy
- });
- }
- current = next;
- }
- if (next != null) {
-
- _super.addSegment(conn, "Straight", {
- x1:next[0], y1:next[1], x2:next[2], y2:next[3]
- });
- }
- };
-
- this.setSegments = function(s) {
- userSuppliedSegments = s;
- };
-
- this.isEditable = function() { return true; };
-
-
- this.getOriginalSegments = function() {
- return userSuppliedSegments || segments;
- };
-
- this._compute = function(paintInfo, params) {
-
- if (params.clearEdits)
- userSuppliedSegments = null;
-
- if (userSuppliedSegments != null) {
- writeSegments(this, userSuppliedSegments, paintInfo);
- return;
- }
-
- segments = [];
- lastx = null; lasty = null;
- lastOrientation = null;
-
- var midx = paintInfo.startStubX + ((paintInfo.endStubX - paintInfo.startStubX) * midpoint),
- midy = paintInfo.startStubY + ((paintInfo.endStubY - paintInfo.startStubY) * midpoint);
-
- var findClearedLine = function(start, mult, anchorPos, dimension) {
- return start + (mult * (( 1 - anchorPos) * dimension) + _super.maxStub);
- },
- orientations = { x:[ 0, 1 ], y:[ 1, 0 ] },
- commonStubCalculator = function(axis) {
- return [ paintInfo.startStubX, paintInfo.startStubY, paintInfo.endStubX, paintInfo.endStubY ];
- },
- stubCalculators = {
- perpendicular:commonStubCalculator,
- orthogonal:commonStubCalculator,
- opposite:function(axis) {
- var pi = paintInfo,
- idx = axis == "x" ? 0 : 1,
- areInProximity = {
- "x":function() {
- return ( (pi.so[idx] == 1 && (
- ( (pi.startStubX > pi.endStubX) && (pi.tx > pi.startStubX) ) ||
- ( (pi.sx > pi.endStubX) && (pi.tx > pi.sx))))) ||
- ( (pi.so[idx] == -1 && (
- ( (pi.startStubX < pi.endStubX) && (pi.tx < pi.startStubX) ) ||
- ( (pi.sx < pi.endStubX) && (pi.tx < pi.sx)))));
- },
- "y":function() {
- return ( (pi.so[idx] == 1 && (
- ( (pi.startStubY > pi.endStubY) && (pi.ty > pi.startStubY) ) ||
- ( (pi.sy > pi.endStubY) && (pi.ty > pi.sy))))) ||
- ( (pi.so[idx] == -1 && (
- ( (pi.startStubY < pi.endStubY) && (pi.ty < pi.startStubY) ) ||
- ( (pi.sy < pi.endStubY) && (pi.ty < pi.sy)))));
- }
- };
- if (!alwaysRespectStubs && areInProximity[axis]()) {
- return {
- "x":[(paintInfo.sx + paintInfo.tx) / 2, paintInfo.startStubY, (paintInfo.sx + paintInfo.tx) / 2, paintInfo.endStubY],
- "y":[paintInfo.startStubX, (paintInfo.sy + paintInfo.ty) / 2, paintInfo.endStubX, (paintInfo.sy + paintInfo.ty) / 2]
- }[axis];
- }
- else {
- return [ paintInfo.startStubX, paintInfo.startStubY, paintInfo.endStubX, paintInfo.endStubY ];
- }
- }
- },
- lineCalculators = {
- perpendicular : function(axis, ss, oss, es, oes) {
- var pi = paintInfo,
- sis = {
- x:[ [ [ 1,2,3,4 ], null, [ 2,1,4,3 ] ], null, [ [ 4,3,2,1 ], null, [ 3,4,1,2 ] ] ],
- y:[ [ [ 3,2,1,4 ], null, [ 2,3,4,1 ] ], null, [ [ 4,1,2,3 ], null, [ 1,4,3,2 ] ] ]
- },
- stubs = {
- x:[ [ pi.startStubX, pi.endStubX ] , null, [ pi.endStubX, pi.startStubX ] ],
- y:[ [ pi.startStubY, pi.endStubY ] , null, [ pi.endStubY, pi.startStubY ] ]
- },
- midLines = {
- x:[ [ midx, pi.startStubY ], [ midx, pi.endStubY ] ],
- y:[ [ pi.startStubX, midy ], [ pi.endStubX, midy ] ]
- },
- linesToEnd = {
- x:[ [ pi.endStubX, pi.startStubY ] ],
- y:[ [ pi.startStubX, pi.endStubY ] ]
- },
- startToEnd = {
- x:[ [ pi.startStubX, pi.endStubY ], [ pi.endStubX, pi.endStubY ] ],
- y:[ [ pi.endStubX, pi.startStubY ], [ pi.endStubX, pi.endStubY ] ]
- },
- startToMidToEnd = {
- x:[ [ pi.startStubX, midy ], [ pi.endStubX, midy ], [ pi.endStubX, pi.endStubY ] ],
- y:[ [ midx, pi.startStubY ], [ midx, pi.endStubY ], [ pi.endStubX, pi.endStubY ] ]
- },
- otherStubs = {
- x:[ pi.startStubY, pi.endStubY ],
- y:[ pi.startStubX, pi.endStubX ]
- },
- soIdx = orientations[axis][0], toIdx = orientations[axis][1],
- _so = pi.so[soIdx] + 1,
- _to = pi.to[toIdx] + 1,
- otherFlipped = (pi.to[toIdx] == -1 && (otherStubs[axis][1] < otherStubs[axis][0])) || (pi.to[toIdx] == 1 && (otherStubs[axis][1] > otherStubs[axis][0])),
- stub1 = stubs[axis][_so][0],
- stub2 = stubs[axis][_so][1],
- segmentIndexes = sis[axis][_so][_to];
- if (pi.segment == segmentIndexes[3] || (pi.segment == segmentIndexes[2] && otherFlipped)) {
- return midLines[axis];
- }
- else if (pi.segment == segmentIndexes[2] && stub2 < stub1) {
- return linesToEnd[axis];
- }
- else if ((pi.segment == segmentIndexes[2] && stub2 >= stub1) || (pi.segment == segmentIndexes[1] && !otherFlipped)) {
- return startToMidToEnd[axis];
- }
- else if (pi.segment == segmentIndexes[0] || (pi.segment == segmentIndexes[1] && otherFlipped)) {
- return startToEnd[axis];
- }
- },
- orthogonal : function(axis, startStub, otherStartStub, endStub, otherEndStub) {
- var pi = paintInfo,
- extent = {
- "x":pi.so[0] == -1 ? Math.min(startStub, endStub) : Math.max(startStub, endStub),
- "y":pi.so[1] == -1 ? Math.min(startStub, endStub) : Math.max(startStub, endStub)
- }[axis];
-
- return {
- "x":[ [ extent, otherStartStub ],[ extent, otherEndStub ], [ endStub, otherEndStub ] ],
- "y":[ [ otherStartStub, extent ], [ otherEndStub, extent ], [ otherEndStub, endStub ] ]
- }[axis];
- },
- opposite : function(axis, ss, oss, es, oes) {
- var pi = paintInfo,
- otherAxis = {"x":"y","y":"x"}[axis],
- dim = {"x":"height","y":"width"}[axis],
- comparator = pi["is" + axis.toUpperCase() + "GreaterThanStubTimes2"];
- if (params.sourceEndpoint.elementId == params.targetEndpoint.elementId) {
- var _val = oss + ((1 - params.sourceEndpoint.anchor[otherAxis]) * params.sourceInfo[dim]) + _super.maxStub;
- return {
- "x":[ [ ss, _val ], [ es, _val ] ],
- "y":[ [ _val, ss ], [ _val, es ] ]
- }[axis];
-
- }
- else if (!comparator || (pi.so[idx] == 1 && ss > es) || (pi.so[idx] == -1 && ss < es)) {
- return {
- "x":[[ ss, midy ], [ es, midy ]],
- "y":[[ midx, ss ], [ midx, es ]]
- }[axis];
- }
- else if ((pi.so[idx] == 1 && ss < es) || (pi.so[idx] == -1 && ss > es)) {
- return {
- "x":[[ midx, pi.sy ], [ midx, pi.ty ]],
- "y":[[ pi.sx, midy ], [ pi.tx, midy ]]
- }[axis];
- }
- }
- };
- var stubs = stubCalculators[paintInfo.anchorOrientation](paintInfo.sourceAxis),
- idx = paintInfo.sourceAxis == "x" ? 0 : 1,
- oidx = paintInfo.sourceAxis == "x" ? 1 : 0,
- ss = stubs[idx],
- oss = stubs[oidx],
- es = stubs[idx + 2],
- oes = stubs[oidx + 2];
-
- addSegment(segments, stubs[0], stubs[1], paintInfo);
-
- var p = lineCalculators[paintInfo.anchorOrientation](paintInfo.sourceAxis, ss, oss, es, oes);
- if (p) {
- for (var i = 0; i < p.length; i++) {
- addSegment(segments, p[i][0], p[i][1], paintInfo);
- }
- }
-
-
- addSegment(segments, stubs[2], stubs[3], paintInfo);
-
-
- addSegment(segments, paintInfo.tx, paintInfo.ty, paintInfo);
-
- writeSegments(this, segments, paintInfo);
- };
- this.getPath = function() {
- var _last = null, _lastAxis = null, s = [], segs = userSuppliedSegments || segments;
- for (var i = 0; i < segs.length; i++) {
- var seg = segs[i], axis = seg[4], axisIndex = (axis == "v" ? 3 : 2);
- if (_last != null && _lastAxis === axis) {
- _last[axisIndex] = seg[axisIndex];
- }
- else {
- if (seg[0] != seg[2] || seg[1] != seg[3]) {
- s.push({
- start:[ seg[0], seg[1] ],
- end:[ seg[2], seg[3] ]
- });
- _last = seg;
- _lastAxis = seg[4];
- }
- }
- }
- return s;
- };
- this.setPath = function(path) {
- userSuppliedSegments = [];
- for (var i = 0; i < path.length; i++) {
- var lx = path[i].start[0],
- ly = path[i].start[1],
- x = path[i].end[0],
- y = path[i].end[1],
- o = lx == x ? "v" : "h",
- sgnx = sgn(x - lx),
- sgny = sgn(y - ly);
- userSuppliedSegments.push([lx, ly, x, y, o, sgnx, sgny]);
- }
- };
- };
- jsPlumbUtil.extend(Flowchart, jsPlumb.Connectors.AbstractConnector);
- jsPlumb.registerConnectorType(Flowchart, "Flowchart");
- })();
- ;(function() {
-
- "use strict";
- var Line = function(x1, y1, x2, y2) {
- this.m = (y2 - y1) / (x2 - x1);
- this.b = -1 * ((this.m * x1) - y1);
-
- this.rectIntersect = function(x,y,w,h) {
- var results = [], xInt, yInt;
-
-
-
- xInt = (y - this.b) / this.m;
-
- if (xInt >= x && xInt <= (x + w)) results.push([ xInt, (this.m * xInt) + this.b ]);
-
-
- yInt = (this.m * (x + w)) + this.b;
- if (yInt >= y && yInt <= (y + h)) results.push([ (yInt - this.b) / this.m, yInt ]);
-
-
- xInt = ((y + h) - this.b) / this.m;
-
- if (xInt >= x && xInt <= (x + w)) results.push([ xInt, (this.m * xInt) + this.b ]);
-
-
- yInt = (this.m * x) + this.b;
- if (yInt >= y && yInt <= (y + h)) results.push([ (yInt - this.b) / this.m, yInt ]);
- if (results.length == 2) {
- var midx = (results[0][0] + results[1][0]) / 2, midy = (results[0][1] + results[1][1]) / 2;
- results.push([ midx,midy ]);
-
- var xseg = midx <= x + (w / 2) ? -1 : 1,
- yseg = midy <= y + (h / 2) ? -1 : 1;
- results.push([xseg, yseg]);
- return results;
- }
-
- return null;
- };
- },
- _segment = function(x1, y1, x2, y2) {
- if (x1 <= x2 && y2 <= y1) return 1;
- else if (x1 <= x2 && y1 <= y2) return 2;
- else if (x2 <= x1 && y2 >= y1) return 3;
- return 4;
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- _findControlPoint = function(midx, midy, segment, sourceEdge, targetEdge, dx, dy, distance, proximityLimit) {
-
-
- if (distance <= proximityLimit) return [midx, midy];
- if (segment === 1) {
- if (sourceEdge[3] <= 0 && targetEdge[3] >= 1) return [ midx + (sourceEdge[2] < 0.5 ? -1 * dx : dx), midy ];
- else if (sourceEdge[2] >= 1 && targetEdge[2] <= 0) return [ midx, midy + (sourceEdge[3] < 0.5 ? -1 * dy : dy) ];
- else return [ midx + (-1 * dx) , midy + (-1 * dy) ];
- }
- else if (segment === 2) {
- if (sourceEdge[3] >= 1 && targetEdge[3] <= 0) return [ midx + (sourceEdge[2] < 0.5 ? -1 * dx : dx), midy ];
- else if (sourceEdge[2] >= 1 && targetEdge[2] <= 0) return [ midx, midy + (sourceEdge[3] < 0.5 ? -1 * dy : dy) ];
- else return [ midx + (1 * dx) , midy + (-1 * dy) ];
- }
- else if (segment === 3) {
- if (sourceEdge[3] >= 1 && targetEdge[3] <= 0) return [ midx + (sourceEdge[2] < 0.5 ? -1 * dx : dx), midy ];
- else if (sourceEdge[2] <= 0 && targetEdge[2] >= 1) return [ midx, midy + (sourceEdge[3] < 0.5 ? -1 * dy : dy) ];
- else return [ midx + (-1 * dx) , midy + (-1 * dy) ];
- }
- else if (segment === 4) {
- if (sourceEdge[3] <= 0 && targetEdge[3] >= 1) return [ midx + (sourceEdge[2] < 0.5 ? -1 * dx : dx), midy ];
- else if (sourceEdge[2] <= 0 && targetEdge[2] >= 1) return [ midx, midy + (sourceEdge[3] < 0.5 ? -1 * dy : dy) ];
- else return [ midx + (1 * dx) , midy + (-1 * dy) ];
- }
- };
-
-
-
- var StateMachine = function(params) {
- params = params || {};
- this.type = "StateMachine";
- var self = this,
- _super = jsPlumb.Connectors.AbstractConnector.apply(this, arguments),
- curviness = params.curviness || 10,
- margin = params.margin || 5,
- proximityLimit = params.proximityLimit || 80,
- clockwise = params.orientation && params.orientation === "clockwise",
- loopbackRadius = params.loopbackRadius || 25,
- showLoopback = params.showLoopback !== false;
-
- this._compute = function(paintInfo, params) {
- var w = Math.abs(params.sourcePos[0] - params.targetPos[0]),
- h = Math.abs(params.sourcePos[1] - params.targetPos[1]),
- x = Math.min(params.sourcePos[0], params.targetPos[0]),
- y = Math.min(params.sourcePos[1], params.targetPos[1]);
-
- if (!showLoopback || (params.sourceEndpoint.elementId !== params.targetEndpoint.elementId)) {
- var _sx = params.sourcePos[0] < params.targetPos[0] ? 0 : w,
- _sy = params.sourcePos[1] < params.targetPos[1] ? 0:h,
- _tx = params.sourcePos[0] < params.targetPos[0] ? w : 0,
- _ty = params.sourcePos[1] < params.targetPos[1] ? h : 0;
-
-
- if (params.sourcePos[2] === 0) _sx -= margin;
- if (params.sourcePos[2] === 1) _sx += margin;
- if (params.sourcePos[3] === 0) _sy -= margin;
- if (params.sourcePos[3] === 1) _sy += margin;
- if (params.targetPos[2] === 0) _tx -= margin;
- if (params.targetPos[2] === 1) _tx += margin;
- if (params.targetPos[3] === 0) _ty -= margin;
- if (params.targetPos[3] === 1) _ty += margin;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var _midx = (_sx + _tx) / 2, _midy = (_sy + _ty) / 2,
- m2 = (-1 * _midx) / _midy, theta2 = Math.atan(m2),
- dy = (m2 == Infinity || m2 == -Infinity) ? 0 : Math.abs(curviness / 2 * Math.sin(theta2)),
- dx = (m2 == Infinity || m2 == -Infinity) ? 0 : Math.abs(curviness / 2 * Math.cos(theta2)),
- segment = _segment(_sx, _sy, _tx, _ty),
- distance = Math.sqrt(Math.pow(_tx - _sx, 2) + Math.pow(_ty - _sy, 2)),
-
-
- _controlPoint = _findControlPoint(_midx,
- _midy,
- segment,
- params.sourcePos,
- params.targetPos,
- curviness, curviness,
- distance,
- proximityLimit);
- _super.addSegment(this, "Bezier", {
- x1:_tx, y1:_ty, x2:_sx, y2:_sy,
- cp1x:_controlPoint[0], cp1y:_controlPoint[1],
- cp2x:_controlPoint[0], cp2y:_controlPoint[1]
- });
- }
- else {
-
- var x1 = params.sourcePos[0], x2 = params.sourcePos[0], y1 = params.sourcePos[1] - margin, y2 = params.sourcePos[1] - margin,
- cx = x1, cy = y1 - loopbackRadius,
-
- _w = 2 * loopbackRadius,
- _h = 2 * loopbackRadius,
- _x = cx - loopbackRadius,
- _y = cy - loopbackRadius;
- paintInfo.points[0] = _x;
- paintInfo.points[1] = _y;
- paintInfo.points[2] = _w;
- paintInfo.points[3] = _h;
-
-
- _super.addSegment(this, "Arc", {
- loopback:true,
- x1:(x1 - _x) + 4,
- y1:y1 - _y,
- startAngle:0,
- endAngle: 2 * Math.PI,
- r:loopbackRadius,
- ac:!clockwise,
- x2:(x1 - _x) - 4,
- y2:y1 - _y,
- cx:cx - _x,
- cy:cy - _y
- });
- }
- };
- };
- jsPlumb.registerConnectorType(StateMachine, "StateMachine");
- })();
- ;(function() {
- var Bezier = function(params) {
- params = params || {};
- var _super = jsPlumb.Connectors.AbstractConnector.apply(this, arguments),
- stub = params.stub || 50,
- majorAnchor = params.curviness || 150,
- minorAnchor = 10;
- this.type = "Bezier";
- this.getCurviness = function() { return majorAnchor; };
- this._findControlPoint = function(point, sourceAnchorPosition, targetAnchorPosition, sourceEndpoint, targetEndpoint) {
-
-
- var soo = sourceEndpoint.anchor.getOrientation(sourceEndpoint),
- too = targetEndpoint.anchor.getOrientation(targetEndpoint),
- perpendicular = soo[0] != too[0] || soo[1] == too[1],
- p = [];
- if (!perpendicular) {
- if (soo[0] === 0)
- p.push(sourceAnchorPosition[0] < targetAnchorPosition[0] ? point[0] + minorAnchor : point[0] - minorAnchor);
- else p.push(point[0] - (majorAnchor * soo[0]));
- if (soo[1] === 0)
- p.push(sourceAnchorPosition[1] < targetAnchorPosition[1] ? point[1] + minorAnchor : point[1] - minorAnchor);
- else p.push(point[1] + (majorAnchor * too[1]));
- }
- else {
- if (too[0] === 0)
- p.push(targetAnchorPosition[0] < sourceAnchorPosition[0] ? point[0] + minorAnchor : point[0] - minorAnchor);
- else p.push(point[0] + (majorAnchor * too[0]));
- if (too[1] === 0)
- p.push(targetAnchorPosition[1] < sourceAnchorPosition[1] ? point[1] + minorAnchor : point[1] - minorAnchor);
- else p.push(point[1] + (majorAnchor * soo[1]));
- }
- return p;
- };
- this._compute = function(paintInfo, p) {
- var sp = p.sourcePos,
- tp = p.targetPos,
- _w = Math.abs(sp[0] - tp[0]),
- _h = Math.abs(sp[1] - tp[1]),
- _sx = sp[0] < tp[0] ? _w : 0,
- _sy = sp[1] < tp[1] ? _h : 0,
- _tx = sp[0] < tp[0] ? 0 : _w,
- _ty = sp[1] < tp[1] ? 0 : _h,
- _CP = this._findControlPoint([_sx, _sy], sp, tp, p.sourceEndpoint, p.targetEndpoint, paintInfo.so, paintInfo.to),
- _CP2 = this._findControlPoint([_tx, _ty], tp, sp, p.targetEndpoint, p.sourceEndpoint, paintInfo.so, paintInfo.to);
- _super.addSegment(this, "Bezier", {
- x1:_sx, y1:_sy, x2:_tx, y2:_ty,
- cp1x:_CP[0], cp1y:_CP[1], cp2x:_CP2[0], cp2y:_CP2[1]
- });
- };
- };
- jsPlumbUtil.extend(Bezier, jsPlumb.Connectors.AbstractConnector);
- jsPlumb.registerConnectorType(Bezier, "Bezier");
- })();
- ;(function() {
-
- "use strict";
-
- var svgAttributeMap = {
- "joinstyle":"stroke-linejoin",
- "stroke-linejoin":"stroke-linejoin",
- "stroke-dashoffset":"stroke-dashoffset",
- "stroke-linecap":"stroke-linecap"
- },
- STROKE_DASHARRAY = "stroke-dasharray",
- DASHSTYLE = "dashstyle",
- LINEAR_GRADIENT = "linearGradient",
- RADIAL_GRADIENT = "radialGradient",
- DEFS = "defs",
- FILL = "fill",
- STOP = "stop",
- STROKE = "stroke",
- STROKE_WIDTH = "stroke-width",
- STYLE = "style",
- NONE = "none",
- JSPLUMB_GRADIENT = "jsplumb_gradient_",
- LINE_WIDTH = "lineWidth",
- ns = {
- svg:"http://www.w3.org/2000/svg",
- xhtml:"http://www.w3.org/1999/xhtml"
- },
- _attr = function(node, attributes) {
- for (var i in attributes)
- node.setAttribute(i, "" + attributes[i]);
- },
- _node = function(name, attributes) {
- var n = document.createElementNS(ns.svg, name);
- attributes = attributes || {};
- attributes.version = "1.1";
- attributes.xmlns = ns.xhtml;
- _attr(n, attributes);
- return n;
- },
- _pos = function(d) { return "position:absolute;left:" + d[0] + "px;top:" + d[1] + "px"; },
- _clearGradient = function(parent) {
-
- for (var i = 0; i < parent.childNodes.length; i++) {
- if (parent.childNodes[i].tagName == DEFS || parent.childNodes[i].tagName == LINEAR_GRADIENT || parent.childNodes[i].tagName == RADIAL_GRADIENT)
- parent.removeChild(parent.childNodes[i]);
- }
- },
- _updateGradient = function(parent, node, style, dimensions, uiComponent) {
- var id = JSPLUMB_GRADIENT + uiComponent._jsPlumb.instance.idstamp();
-
- _clearGradient(parent);
-
-
-
-
-
-
-
- var g;
- if (!style.gradient.offset)
- g = _node(LINEAR_GRADIENT, {id:id, gradientUnits:"userSpaceOnUse"});
- else
- g = _node(RADIAL_GRADIENT, { id:id });
-
- var defs = _node(DEFS);
- parent.appendChild(defs);
- defs.appendChild(g);
-
-
-
-
-
- for (var i = 0; i < style.gradient.stops.length; i++) {
- var styleToUse = uiComponent.segment == 1 || uiComponent.segment == 2 ? i: style.gradient.stops.length - 1 - i,
- stopColor = jsPlumbUtil.convertStyle(style.gradient.stops[styleToUse][1], true),
- s = _node(STOP, {"offset":Math.floor(style.gradient.stops[i][0] * 100) + "%", "stop-color":stopColor});
- g.appendChild(s);
- }
- var applyGradientTo = style.strokeStyle ? STROKE : FILL;
-
-
-
- node.setAttribute(applyGradientTo, "url(#" + id + ")");
- },
- _applyStyles = function(parent, node, style, dimensions, uiComponent) {
-
- node.setAttribute(FILL, style.fillStyle ? jsPlumbUtil.convertStyle(style.fillStyle, true) : NONE);
- node.setAttribute(STROKE, style.strokeStyle ? jsPlumbUtil.convertStyle(style.strokeStyle, true) : NONE);
-
- if (style.gradient) {
- _updateGradient(parent, node, style, dimensions, uiComponent);
- }
- else {
-
- _clearGradient(parent);
- node.setAttribute(STYLE, "");
- }
-
-
- if (style.lineWidth) {
- node.setAttribute(STROKE_WIDTH, style.lineWidth);
- }
-
-
-
-
-
-
-
-
-
- if (style[DASHSTYLE] && style[LINE_WIDTH] && !style[STROKE_DASHARRAY]) {
- var sep = style[DASHSTYLE].indexOf(",") == -1 ? " " : ",",
- parts = style[DASHSTYLE].split(sep),
- styleToUse = "";
- parts.forEach(function(p) {
- styleToUse += (Math.floor(p * style.lineWidth) + sep);
- });
- node.setAttribute(STROKE_DASHARRAY, styleToUse);
- }
- else if(style[STROKE_DASHARRAY]) {
- node.setAttribute(STROKE_DASHARRAY, style[STROKE_DASHARRAY]);
- }
-
-
- for (var i in svgAttributeMap) {
- if (style[i]) {
- node.setAttribute(svgAttributeMap[i], style[i]);
- }
- }
- },
- _decodeFont = function(f) {
- var r = /([0-9].)(p[xt])\s(.*)/,
- bits = f.match(r);
- return {size:bits[1] + bits[2], font:bits[3]};
- },
- _appendAtIndex = function(svg, path, idx) {
- if (svg.childNodes.length > idx) {
- svg.insertBefore(path, svg.childNodes[idx]);
- }
- else svg.appendChild(path);
- };
-
-
- jsPlumbUtil.svg = {
- node:_node,
- attr:_attr,
- pos:_pos
- };
-
-
-
-
-
- var SvgComponent = function(params) {
- var pointerEventsSpec = params.pointerEventsSpec || "all", renderer = {};
-
- jsPlumb.jsPlumbUIComponent.apply(this, params.originalArgs);
- this.canvas = null;this.path = null;this.svg = null; this.bgCanvas = null;
-
- var clazz = params.cssClass + " " + (params.originalArgs[0].cssClass || ""),
- svgParams = {
- "style":"",
- "width":0,
- "height":0,
- "pointer-events":pointerEventsSpec,
- "position":"absolute"
- };
-
- this.svg = _node("svg", svgParams);
-
- if (params.useDivWrapper) {
- this.canvas = document.createElement("div");
- this.canvas.style.position = "absolute";
- jsPlumbUtil.sizeElement(this.canvas,0,0,1,1);
- this.canvas.className = clazz;
- }
- else {
- _attr(this.svg, { "class":clazz });
- this.canvas = this.svg;
- }
-
- params._jsPlumb.appendElement(this.canvas, params.originalArgs[0].parent);
- if (params.useDivWrapper) this.canvas.appendChild(this.svg);
-
-
-
- var displayElements = [ this.canvas ];
- this.getDisplayElements = function() {
- return displayElements;
- };
-
- this.appendDisplayElement = function(el) {
- displayElements.push(el);
- };
-
- this.paint = function(style, anchor, extents) {
- if (style != null) {
-
- var xy = [ this.x, this.y ], wh = [ this.w, this.h ], p;
- if (extents != null) {
- if (extents.xmin < 0) xy[0] += extents.xmin;
- if (extents.ymin < 0) xy[1] += extents.ymin;
- wh[0] = extents.xmax + ((extents.xmin < 0) ? -extents.xmin : 0);
- wh[1] = extents.ymax + ((extents.ymin < 0) ? -extents.ymin : 0);
- }
- if (params.useDivWrapper) {
- jsPlumbUtil.sizeElement(this.canvas, xy[0], xy[1], wh[0], wh[1]);
- xy[0] = 0; xy[1] = 0;
- p = _pos([ 0, 0 ]);
- }
- else
- p = _pos([ xy[0], xy[1] ]);
-
- renderer.paint.apply(this, arguments);
-
- _attr(this.svg, {
- "style":p,
- "width": wh[0],
- "height": wh[1]
- });
- }
- };
-
- return {
- renderer:renderer
- };
- };
-
- jsPlumbUtil.extend(SvgComponent, jsPlumb.jsPlumbUIComponent, {
- cleanup:function() {
- if (this.canvas) this.canvas._jsPlumb = null;
- if (this.svg) this.svg._jsPlumb = null;
- if (this.bgCanvas) this.bgCanvas._jsPlumb = null;
- if (this.canvas && this.canvas.parentNode) this.canvas.parentNode.removeChild(this.canvas);
- if (this.bgCanvas && this. bgCanvas.parentNode) this.canvas.parentNode.removeChild(this.canvas);
- this.svg = null;
- this.canvas = null;
- this.path = null;
- this.group = null;
- },
- setVisible:function(v) {
- if (this.canvas) {
- this.canvas.style.display = v ? "block" : "none";
- }
- }
- });
-
-
-
- jsPlumb.ConnectorRenderers.svg = function(params) {
- var self = this,
- _super = SvgComponent.apply(this, [ {
- cssClass:params._jsPlumb.connectorClass,
- originalArgs:arguments,
- pointerEventsSpec:"none",
- _jsPlumb:params._jsPlumb
- } ]);
-
-
- _super.renderer.paint = function(style, anchor, extents) {
-
- var segments = self.getSegments(), p = "", offset = [0,0];
- if (extents.xmin < 0) offset[0] = -extents.xmin;
- if (extents.ymin < 0) offset[1] = -extents.ymin;
- if (segments.length > 0) {
-
-
- for (var i = 0; i < segments.length; i++) {
- p += jsPlumb.Segments.svg.SegmentRenderer.getPath(segments[i]);
- p += " ";
- }
-
- var a = {
- d:p,
- transform:"translate(" + offset[0] + "," + offset[1] + ")",
- "pointer-events":params["pointer-events"] || "visibleStroke"
- },
- outlineStyle = null,
- d = [self.x,self.y,self.w,self.h];
-
- if (style.outlineColor) {
- var outlineWidth = style.outlineWidth || 1,
- outlineStrokeWidth = style.lineWidth + (2 * outlineWidth);
- outlineStyle = jsPlumb.extend({}, style);
- delete outlineStyle.gradient;
- outlineStyle.strokeStyle = jsPlumbUtil.convertStyle(style.outlineColor);
- outlineStyle.lineWidth = outlineStrokeWidth;
-
- if (self.bgPath == null) {
- self.bgPath = _node("path", a);
- _appendAtIndex(self.svg, self.bgPath, 0);
- }
- else {
- _attr(self.bgPath, a);
- }
-
- _applyStyles(self.svg, self.bgPath, outlineStyle, d, self);
- }
-
- if (self.path == null) {
- self.path = _node("path", a);
- _appendAtIndex(self.svg, self.path, style.outlineColor ? 1 : 0);
- }
- else {
- _attr(self.path, a);
- }
-
- _applyStyles(self.svg, self.path, style, d, self);
- }
- };
- };
- jsPlumbUtil.extend(jsPlumb.ConnectorRenderers.svg, SvgComponent);
-
- jsPlumb.Segments.svg = {
- SegmentRenderer : {
- getPath : function(segment) {
- return ({
- "Straight":function() {
- var d = segment.getCoordinates();
- return "M " + d.x1 + " " + d.y1 + " L " + d.x2 + " " + d.y2;
- },
- "Bezier":function() {
- var d = segment.params;
- return "M " + d.x1 + " " + d.y1 +
- " C " + d.cp1x + " " + d.cp1y + " " + d.cp2x + " " + d.cp2y + " " + d.x2 + " " + d.y2;
- },
- "Arc":function() {
- var d = segment.params,
- laf = segment.sweep > Math.PI ? 1 : 0,
- sf = segment.anticlockwise ? 0 : 1;
- return "M" + segment.x1 + " " + segment.y1 + " A " + segment.radius + " " + d.r + " 0 " + laf + "," + sf + " " + segment.x2 + " " + segment.y2;
- }
- })[segment.type]();
- }
- }
- };
-
-
-
- var SvgEndpoint = window.SvgEndpoint = function(params) {
- var _super = SvgComponent.apply(this, [ {
- cssClass:params._jsPlumb.endpointClass,
- originalArgs:arguments,
- pointerEventsSpec:"all",
- useDivWrapper:true,
- _jsPlumb:params._jsPlumb
- } ]);
-
- _super.renderer.paint = function(style) {
- var s = jsPlumb.extend({}, style);
- if (s.outlineColor) {
- s.strokeWidth = s.outlineWidth;
- s.strokeStyle = jsPlumbUtil.convertStyle(s.outlineColor, true);
- }
-
- if (this.node == null) {
- this.node = this.makeNode(s);
- this.svg.appendChild(this.node);
- }
- else if (this.updateNode != null) {
- this.updateNode(this.node);
- }
- _applyStyles(this.svg, this.node, s, [ this.x, this.y, this.w, this.h ], this);
- _pos(this.node, [ this.x, this.y ]);
- }.bind(this);
-
- };
- jsPlumbUtil.extend(SvgEndpoint, SvgComponent);
-
-
- jsPlumb.Endpoints.svg.Dot = function() {
- jsPlumb.Endpoints.Dot.apply(this, arguments);
- SvgEndpoint.apply(this, arguments);
- this.makeNode = function(style) {
- return _node("circle", {
- "cx" : this.w / 2,
- "cy" : this.h / 2,
- "r" : this.radius
- });
- };
- this.updateNode = function(node) {
- _attr(node, {
- "cx":this.w / 2,
- "cy":this.h / 2,
- "r":this.radius
- });
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.svg.Dot, [jsPlumb.Endpoints.Dot, SvgEndpoint]);
-
-
- jsPlumb.Endpoints.svg.Rectangle = function() {
- jsPlumb.Endpoints.Rectangle.apply(this, arguments);
- SvgEndpoint.apply(this, arguments);
- this.makeNode = function(style) {
- return _node("rect", {
- "width" : this.w,
- "height" : this.h
- });
- };
- this.updateNode = function(node) {
- _attr(node, {
- "width":this.w,
- "height":this.h
- });
- };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.svg.Rectangle, [jsPlumb.Endpoints.Rectangle, SvgEndpoint]);
-
-
- jsPlumb.Endpoints.svg.Image = jsPlumb.Endpoints.Image;
-
- jsPlumb.Endpoints.svg.Blank = jsPlumb.Endpoints.Blank;
-
- jsPlumb.Overlays.svg.Label = jsPlumb.Overlays.Label;
-
- jsPlumb.Overlays.svg.Custom = jsPlumb.Overlays.Custom;
-
- var AbstractSvgArrowOverlay = function(superclass, originalArgs) {
- superclass.apply(this, originalArgs);
- jsPlumb.jsPlumbUIComponent.apply(this, originalArgs);
- this.isAppendedAtTopLevel = false;
- var self = this;
- this.path = null;
- this.paint = function(params, containerExtents) {
-
- if (params.component.svg && containerExtents) {
- if (this.path == null) {
- this.path = _node("path", {
- "pointer-events":"all"
- });
- params.component.svg.appendChild(this.path);
-
- this.canvas = params.component.svg;
- }
- var clazz = originalArgs && (originalArgs.length == 1) ? (originalArgs[0].cssClass || "") : "",
- offset = [0,0];
- if (containerExtents.xmin < 0) offset[0] = -containerExtents.xmin;
- if (containerExtents.ymin < 0) offset[1] = -containerExtents.ymin;
-
- _attr(this.path, {
- "d" : makePath(params.d),
- "class" : clazz,
- stroke : params.strokeStyle ? params.strokeStyle : null,
- fill : params.fillStyle ? params.fillStyle : null,
- transform : "translate(" + offset[0] + "," + offset[1] + ")"
- });
- }
- };
- var makePath = function(d) {
- return "M" + d.hxy.x + "," + d.hxy.y +
- " L" + d.tail[0].x + "," + d.tail[0].y +
- " L" + d.cxy.x + "," + d.cxy.y +
- " L" + d.tail[1].x + "," + d.tail[1].y +
- " L" + d.hxy.x + "," + d.hxy.y;
- };
- };
- jsPlumbUtil.extend(AbstractSvgArrowOverlay, [jsPlumb.jsPlumbUIComponent, jsPlumb.Overlays.AbstractOverlay], {
- cleanup : function() {
- if (this.path != null) this._jsPlumb.instance.removeElement(this.path);
- },
- setVisible:function(v) {
- if(this.path != null) (this.path.style.display = (v ? "block" : "none"));
- }
- });
-
- jsPlumb.Overlays.svg.Arrow = function() {
- AbstractSvgArrowOverlay.apply(this, [jsPlumb.Overlays.Arrow, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.svg.Arrow, [ jsPlumb.Overlays.Arrow, AbstractSvgArrowOverlay ]);
-
- jsPlumb.Overlays.svg.PlainArrow = function() {
- AbstractSvgArrowOverlay.apply(this, [jsPlumb.Overlays.PlainArrow, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.svg.PlainArrow, [ jsPlumb.Overlays.PlainArrow, AbstractSvgArrowOverlay ]);
-
- jsPlumb.Overlays.svg.Diamond = function() {
- AbstractSvgArrowOverlay.apply(this, [jsPlumb.Overlays.Diamond, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.svg.Diamond, [ jsPlumb.Overlays.Diamond, AbstractSvgArrowOverlay ]);
-
- jsPlumb.Overlays.svg.GuideLines = function() {
- var path = null, self = this, p1_1, p1_2;
- jsPlumb.Overlays.GuideLines.apply(this, arguments);
- this.paint = function(params, containerExtents) {
- if (path == null) {
- path = _node("path");
- params.connector.svg.appendChild(path);
- self.attachListeners(path, params.connector);
- self.attachListeners(path, self);
- p1_1 = _node("path");
- params.connector.svg.appendChild(p1_1);
- self.attachListeners(p1_1, params.connector);
- self.attachListeners(p1_1, self);
- p1_2 = _node("path");
- params.connector.svg.appendChild(p1_2);
- self.attachListeners(p1_2, params.connector);
- self.attachListeners(p1_2, self);
- }
- var offset =[0,0];
- if (containerExtents.xmin < 0) offset[0] = -containerExtents.xmin;
- if (containerExtents.ymin < 0) offset[1] = -containerExtents.ymin;
- _attr(path, {
- "d" : makePath(params.head, params.tail),
- stroke : "red",
- fill : null,
- transform:"translate(" + offset[0] + "," + offset[1] + ")"
- });
- _attr(p1_1, {
- "d" : makePath(params.tailLine[0], params.tailLine[1]),
- stroke : "blue",
- fill : null,
- transform:"translate(" + offset[0] + "," + offset[1] + ")"
- });
- _attr(p1_2, {
- "d" : makePath(params.headLine[0], params.headLine[1]),
- stroke : "green",
- fill : null,
- transform:"translate(" + offset[0] + "," + offset[1] + ")"
- });
- };
- var makePath = function(d1, d2) {
- return "M " + d1.x + "," + d1.y +
- " L" + d2.x + "," + d2.y;
- };
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.svg.GuideLines, jsPlumb.Overlays.GuideLines);
- })();
- ;(function() {
-
- "use strict";
-
-
-
-
-
- var vmlAttributeMap = {
- "stroke-linejoin":"joinstyle",
- "joinstyle":"joinstyle",
- "endcap":"endcap",
- "miterlimit":"miterlimit"
- },
- jsPlumbStylesheet = null;
-
- if (document.createStyleSheet && document.namespaces) {
-
- var ruleClasses = [
- ".jsplumb_vml", "jsplumb\\:textbox", "jsplumb\\:oval", "jsplumb\\:rect",
- "jsplumb\\:stroke", "jsplumb\\:shape", "jsplumb\\:group"
- ],
- rule = "behavior:url(#default#VML);position:absolute;";
- jsPlumbStylesheet = document.createStyleSheet();
- for (var i = 0; i < ruleClasses.length; i++)
- jsPlumbStylesheet.addRule(ruleClasses[i], rule);
-
-
-
-
-
- document.namespaces.add("jsplumb", "urn:schemas-microsoft-com:vml");
-
-
- }
-
- jsPlumb.vml = {};
-
- var scale = 1000,
-
- _atts = function(o, atts) {
- for (var i in atts) {
-
-
-
-
- o[i] = atts[i];
- }
- },
- _node = function(name, d, atts, parent, _jsPlumb, deferToJsPlumbContainer) {
- atts = atts || {};
- var o = document.createElement("jsplumb:" + name);
- if (deferToJsPlumbContainer)
- _jsPlumb.appendElement(o, parent);
- else
-
-
- parent.appendChild(o);
-
-
- o.className = (atts["class"] ? atts["class"] + " " : "") + "jsplumb_vml";
- _pos(o, d);
- _atts(o, atts);
- return o;
- },
- _pos = function(o,d, zIndex) {
- o.style.left = d[0] + "px";
- o.style.top = d[1] + "px";
- o.style.width= d[2] + "px";
- o.style.height= d[3] + "px";
- o.style.position = "absolute";
- if (zIndex)
- o.style.zIndex = zIndex;
- },
- _conv = jsPlumb.vml.convertValue = function(v) {
- return Math.floor(v * scale);
- },
-
-
- _maybeSetOpacity = function(styleToWrite, styleToCheck, type, component) {
- if ("transparent" === styleToCheck)
- component.setOpacity(type, "0.0");
- else
- component.setOpacity(type, "1.0");
- },
- _applyStyles = function(node, style, component, _jsPlumb) {
- var styleToWrite = {};
- if (style.strokeStyle) {
- styleToWrite.stroked = "true";
- var strokeColor = jsPlumbUtil.convertStyle(style.strokeStyle, true);
- styleToWrite.strokecolor = strokeColor;
- _maybeSetOpacity(styleToWrite, strokeColor, "stroke", component);
- styleToWrite.strokeweight = style.lineWidth + "px";
- }
- else styleToWrite.stroked = "false";
-
- if (style.fillStyle) {
- styleToWrite.filled = "true";
- var fillColor = jsPlumbUtil.convertStyle(style.fillStyle, true);
- styleToWrite.fillcolor = fillColor;
- _maybeSetOpacity(styleToWrite, fillColor, "fill", component);
- }
- else styleToWrite.filled = "false";
-
- if(style.dashstyle) {
- if (component.strokeNode == null) {
- component.strokeNode = _node("stroke", [0,0,0,0], { dashstyle:style.dashstyle }, node, _jsPlumb);
- }
- else
- component.strokeNode.dashstyle = style.dashstyle;
- }
- else if (style["stroke-dasharray"] && style.lineWidth) {
- var sep = style["stroke-dasharray"].indexOf(",") == -1 ? " " : ",",
- parts = style["stroke-dasharray"].split(sep),
- styleToUse = "";
- for(var i = 0; i < parts.length; i++) {
- styleToUse += (Math.floor(parts[i] / style.lineWidth) + sep);
- }
- if (component.strokeNode == null) {
- component.strokeNode = _node("stroke", [0,0,0,0], { dashstyle:styleToUse }, node, _jsPlumb);
- }
- else
- component.strokeNode.dashstyle = styleToUse;
- }
-
- _atts(node, styleToWrite);
- },
-
- VmlComponent = function() {
- var self = this, renderer = {};
- jsPlumb.jsPlumbUIComponent.apply(this, arguments);
- this.opacityNodes = {
- "stroke":null,
- "fill":null
- };
- this.initOpacityNodes = function(vml) {
- self.opacityNodes.stroke = _node("stroke", [0,0,1,1], {opacity:"0.0"}, vml, self._jsPlumb.instance);
- self.opacityNodes.fill = _node("fill", [0,0,1,1], {opacity:"0.0"}, vml, self._jsPlumb.instance);
- };
- this.setOpacity = function(type, value) {
- var node = self.opacityNodes[type];
- if (node) node.opacity = "" + value;
- };
- var displayElements = [ ];
- this.getDisplayElements = function() {
- return displayElements;
- };
-
- this.appendDisplayElement = function(el, doNotAppendToCanvas) {
- if (!doNotAppendToCanvas) self.canvas.parentNode.appendChild(el);
- displayElements.push(el);
- };
- };
- jsPlumbUtil.extend(VmlComponent, jsPlumb.jsPlumbUIComponent, {
- cleanup:function() {
- if (this.bgCanvas) this.bgCanvas.parentNode.removeChild(this.bgCanvas);
- if (this.canvas) this.canvas.parentNode.removeChild(this.canvas);
- }
- });
-
- var VmlConnector = jsPlumb.ConnectorRenderers.vml = function(params, component) {
- this.strokeNode = null;
- this.canvas = null;
- VmlComponent.apply(this, arguments);
- var clazz = this._jsPlumb.instance.connectorClass + (params.cssClass ? (" " + params.cssClass) : "");
- this.paint = function(style) {
- if (style !== null) {
-
-
- this.w = Math.max(this.w, 1);
- this.h = Math.max(this.h, 1);
- var segments = this.getSegments(), p = { "path":"" },
- d = [this.x, this.y, this.w, this.h];
-
-
- for (var i = 0; i < segments.length; i++) {
- p.path += jsPlumb.Segments.vml.SegmentRenderer.getPath(segments[i]);
- p.path += " ";
- }
-
- if (style.outlineColor) {
- var outlineWidth = style.outlineWidth || 1,
- outlineStrokeWidth = style.lineWidth + (2 * outlineWidth),
- outlineStyle = {
- strokeStyle : jsPlumbUtil.convertStyle(style.outlineColor),
- lineWidth : outlineStrokeWidth
- };
- for (var aa in vmlAttributeMap) outlineStyle[aa] = style[aa];
-
- if (this.bgCanvas == null) {
- p["class"] = clazz;
- p.coordsize = (d[2] * scale) + "," + (d[3] * scale);
- this.bgCanvas = _node("shape", d, p, params.parent, this._jsPlumb.instance, true);
- _pos(this.bgCanvas, d);
- this.appendDisplayElement(this.bgCanvas, true);
- this.initOpacityNodes(this.bgCanvas, ["stroke"]);
- this.bgCanvas._jsPlumb = component;
- }
- else {
- p.coordsize = (d[2] * scale) + "," + (d[3] * scale);
- _pos(this.bgCanvas, d);
- _atts(this.bgCanvas, p);
- }
-
- _applyStyles(this.bgCanvas, outlineStyle, this);
- }
-
-
- if (this.canvas == null) {
- p["class"] = clazz;
- p.coordsize = (d[2] * scale) + "," + (d[3] * scale);
- this.canvas = _node("shape", d, p, params.parent, this._jsPlumb.instance, true);
- this.appendDisplayElement(this.canvas, true);
- this.initOpacityNodes(this.canvas, ["stroke"]);
- this.canvas._jsPlumb = component;
- }
- else {
- p.coordsize = (d[2] * scale) + "," + (d[3] * scale);
- _pos(this.canvas, d);
- _atts(this.canvas, p);
- }
-
- _applyStyles(this.canvas, style, this, this._jsPlumb.instance);
- }
- };
-
- };
- jsPlumbUtil.extend(VmlConnector, VmlComponent, {
- setVisible:function(v) {
- if (this.canvas) {
- this.canvas.style.display = v ? "block" : "none";
- }
- if (this.bgCanvas) {
- this.bgCanvas.style.display = v ? "block" : "none";
- }
- }
- });
-
-
- var VmlEndpoint = window.VmlEndpoint = function(params) {
- VmlComponent.apply(this, arguments);
- this._jsPlumb.vml = null;
- this.canvas = document.createElement("div");
- this.canvas.style.position = "absolute";
- this._jsPlumb.clazz = this._jsPlumb.instance.endpointClass + (params.cssClass ? (" " + params.cssClass) : "");
-
-
-
- params._jsPlumb.appendElement(this.canvas, params.parent);
- this.paint = function(style, anchor) {
- var p = { }, vml = this._jsPlumb.vml;
-
- jsPlumbUtil.sizeElement(this.canvas, this.x, this.y, this.w, this.h);
- if (this._jsPlumb.vml == null) {
- p["class"] = this._jsPlumb.clazz;
- vml = this._jsPlumb.vml = this.getVml([0,0, this.w, this.h], p, anchor, this.canvas, this._jsPlumb.instance);
- this.appendDisplayElement(vml, true);
- this.appendDisplayElement(this.canvas, true);
-
- this.initOpacityNodes(vml, ["fill"]);
- }
- else {
- _pos(vml, [0,0, this.w, this.h]);
- _atts(vml, p);
- }
-
- _applyStyles(vml, style, this);
- };
- };
- jsPlumbUtil.extend(VmlEndpoint, VmlComponent);
-
-
- jsPlumb.Segments.vml = {
- SegmentRenderer : {
- getPath : function(segment) {
- return ({
- "Straight":function(segment) {
- var d = segment.params;
- return "m" + _conv(d.x1) + "," + _conv(d.y1) + " l" + _conv(d.x2) + "," + _conv(d.y2) + " e";
- },
- "Bezier":function(segment) {
- var d = segment.params;
- return "m" + _conv(d.x1) + "," + _conv(d.y1) +
- " c" + _conv(d.cp1x) + "," + _conv(d.cp1y) + "," + _conv(d.cp2x) + "," + _conv(d.cp2y) + "," + _conv(d.x2) + "," + _conv(d.y2) + " e";
- },
- "Arc":function(segment) {
- var d = segment.params,
- xmin = Math.min(d.x1, d.x2),
- xmax = Math.max(d.x1, d.x2),
- ymin = Math.min(d.y1, d.y2),
- ymax = Math.max(d.y1, d.y2),
- sf = segment.anticlockwise ? 1 : 0,
- pathType = (segment.anticlockwise ? "at " : "wa "),
- makePosString = function() {
- if (d.loopback)
- return "0,0," + _conv(2*d.r) + "," + _conv(2 * d.r);
- var xy = [
- null,
- [ function() { return [xmin, ymin ];}, function() { return [xmin - d.r, ymin - d.r ];}],
- [ function() { return [xmin - d.r, ymin ];}, function() { return [xmin, ymin - d.r ];}],
- [ function() { return [xmin - d.r, ymin - d.r ];}, function() { return [xmin, ymin ];}],
- [ function() { return [xmin, ymin - d.r ];}, function() { return [xmin - d.r, ymin ];}]
- ][segment.segment][sf]();
- return _conv(xy[0]) + "," + _conv(xy[1]) + "," + _conv(xy[0] + (2*d.r)) + "," + _conv(xy[1] + (2*d.r));
- };
- return pathType + " " + makePosString() + "," + _conv(d.x1) + "," + _conv(d.y1) + "," + _conv(d.x2) + "," + _conv(d.y2) + " e";
- }
-
- })[segment.type](segment);
- }
- }
- };
-
-
- jsPlumb.Endpoints.vml.Dot = function() {
- jsPlumb.Endpoints.Dot.apply(this, arguments);
- VmlEndpoint.apply(this, arguments);
- this.getVml = function(d, atts, anchor, parent, _jsPlumb) { return _node("oval", d, atts, parent, _jsPlumb); };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.vml.Dot, VmlEndpoint);
-
- jsPlumb.Endpoints.vml.Rectangle = function() {
- jsPlumb.Endpoints.Rectangle.apply(this, arguments);
- VmlEndpoint.apply(this, arguments);
- this.getVml = function(d, atts, anchor, parent, _jsPlumb) { return _node("rect", d, atts, parent, _jsPlumb); };
- };
- jsPlumbUtil.extend(jsPlumb.Endpoints.vml.Rectangle, VmlEndpoint);
-
-
- jsPlumb.Endpoints.vml.Image = jsPlumb.Endpoints.Image;
-
-
- jsPlumb.Endpoints.vml.Blank = jsPlumb.Endpoints.Blank;
-
-
-
- jsPlumb.Overlays.vml.Label = jsPlumb.Overlays.Label;
-
-
- jsPlumb.Overlays.vml.Custom = jsPlumb.Overlays.Custom;
-
-
- var AbstractVmlArrowOverlay = function(superclass, originalArgs) {
- superclass.apply(this, originalArgs);
- VmlComponent.apply(this, originalArgs);
- var self = this, path = null;
- this.canvas = null;
- this.isAppendedAtTopLevel = true;
- var getPath = function(d) {
- return "m " + _conv(d.hxy.x) + "," + _conv(d.hxy.y) +
- " l " + _conv(d.tail[0].x) + "," + _conv(d.tail[0].y) +
- " " + _conv(d.cxy.x) + "," + _conv(d.cxy.y) +
- " " + _conv(d.tail[1].x) + "," + _conv(d.tail[1].y) +
- " x e";
- };
- this.paint = function(params, containerExtents) {
-
- if (params.component.canvas && containerExtents) {
- var p = {}, d = params.d, connector = params.component;
- if (params.strokeStyle) {
- p.stroked = "true";
- p.strokecolor = jsPlumbUtil.convertStyle(params.strokeStyle, true);
- }
- if (params.lineWidth) p.strokeweight = params.lineWidth + "px";
- if (params.fillStyle) {
- p.filled = "true";
- p.fillcolor = params.fillStyle;
- }
- var xmin = Math.min(d.hxy.x, d.tail[0].x, d.tail[1].x, d.cxy.x),
- ymin = Math.min(d.hxy.y, d.tail[0].y, d.tail[1].y, d.cxy.y),
- xmax = Math.max(d.hxy.x, d.tail[0].x, d.tail[1].x, d.cxy.x),
- ymax = Math.max(d.hxy.y, d.tail[0].y, d.tail[1].y, d.cxy.y),
- w = Math.abs(xmax - xmin),
- h = Math.abs(ymax - ymin),
- dim = [xmin, ymin, w, h];
-
-
-
-
- p.path = getPath(d);
- p.coordsize = (connector.w * scale) + "," + (connector.h * scale);
-
- dim[0] = connector.x;
- dim[1] = connector.y;
- dim[2] = connector.w;
- dim[3] = connector.h;
-
- if (self.canvas == null) {
- var overlayClass = connector._jsPlumb.overlayClass || "";
- var clazz = originalArgs && (originalArgs.length == 1) ? (originalArgs[0].cssClass || "") : "";
- p["class"] = clazz + " " + overlayClass;
- self.canvas = _node("shape", dim, p, connector.canvas.parentNode, connector._jsPlumb.instance, true);
- connector.appendDisplayElement(self.canvas, true);
- }
- else {
- _pos(self.canvas, dim);
- _atts(self.canvas, p);
- }
- }
- };
- this.cleanup = function() {
- if (this.canvas != null) this._jsPlumb.instance.removeElement(this.canvas);
- };
- };
- jsPlumbUtil.extend(AbstractVmlArrowOverlay, [VmlComponent, jsPlumb.Overlays.AbstractOverlay], {
- setVisible : function(state) {
- this.canvas.style.display = state ? "block" : "none";
- }
- });
-
- jsPlumb.Overlays.vml.Arrow = function() {
- AbstractVmlArrowOverlay.apply(this, [jsPlumb.Overlays.Arrow, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.vml.Arrow, [ jsPlumb.Overlays.Arrow, AbstractVmlArrowOverlay ]);
-
- jsPlumb.Overlays.vml.PlainArrow = function() {
- AbstractVmlArrowOverlay.apply(this, [jsPlumb.Overlays.PlainArrow, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.vml.PlainArrow, [ jsPlumb.Overlays.PlainArrow, AbstractVmlArrowOverlay ]);
-
- jsPlumb.Overlays.vml.Diamond = function() {
- AbstractVmlArrowOverlay.apply(this, [jsPlumb.Overlays.Diamond, arguments]);
- };
- jsPlumbUtil.extend(jsPlumb.Overlays.vml.Diamond, [ jsPlumb.Overlays.Diamond, AbstractVmlArrowOverlay ]);
-
-
- })();
-
- ;(function($) {
-
- "use strict";
- var _getElementObject = function(el) {
- return typeof(el) == "string" ? $("#" + el) : $(el);
- };
- $.extend(jsPlumbInstance.prototype, {
-
-
-
- getDOMElement : function(el) {
- if (el == null) return null;
- if (typeof(el) == "string") return document.getElementById(el);
- else if (el.context || el.length != null) return el[0];
- else return el;
- },
-
-
- getElementObject : _getElementObject,
-
- removeElement:function(element) {
- _getElementObject(element).remove();
- },
-
- doAnimate : function(el, properties, options) {
- el.animate(properties, options);
- },
- getSelector : function(context, spec) {
- if (arguments.length == 2)
- return _getElementObject(context).find(spec);
- else
- return $(context);
- },
-
- destroyDraggable : function(el) {
- if ($(el).data("draggable"))
- $(el).draggable("destroy");
- },
- destroyDroppable : function(el) {
- if ($(el).data("droppable"))
- $(el).droppable("destroy");
- },
-
- initDraggable : function(el, options, isPlumbedComponent) {
- options = options || {};
- el = $(el);
- options.start = jsPlumbUtil.wrap(options.start, function() {
- $("body").addClass(this.dragSelectClass);
- }, false);
- options.stop = jsPlumbUtil.wrap(options.stop, function() {
- $("body").removeClass(this.dragSelectClass);
- });
-
- if (!options.doNotRemoveHelper)
- options.helper = null;
- if (isPlumbedComponent == "internal")
- options.scope = options.scope || jsPlumb.Defaults.Scope;
- el.draggable(options);
- },
-
-
- initDroppable : function(el, options) {
- options.scope = options.scope || jsPlumb.Defaults.Scope;
- $(el).droppable(options);
- },
-
- isAlreadyDraggable : function(el) {
- return $(el).hasClass("ui-draggable");
- },
-
-
- isDragSupported : function(el, options) {
- return $(el).draggable;
- },
-
- isDropSupported : function(el, options) {
- return $(el).droppable;
- },
-
- getDragObject : function(eventArgs) {
-
- return eventArgs[1].helper || eventArgs[1].draggable;
- },
-
- getDragScope : function(el) {
- return $(el).draggable("option", "scope");
- },
- getDropEvent : function(args) {
- return args[0];
- },
-
- getDropScope : function(el) {
- return $(el).droppable("option", "scope");
- },
-
- getUIPosition : function(eventArgs, zoom, dontAdjustHelper) {
- var ret;
- zoom = zoom || 1;
- if (eventArgs.length == 1) {
- ret = { left: eventArgs[0].pageX, top:eventArgs[0].pageY };
- }
- else {
- var ui = eventArgs[1],
- _offset = ui.position;
-
- ret = _offset || ui.absolutePosition;
-
-
- if (!dontAdjustHelper) {
- ui.position.left /= zoom;
- ui.position.top /= zoom;
- }
- }
- return { left:ret.left, top: ret.top };
- },
-
- isDragFilterSupported:function() { return true; },
-
- setDragFilter : function(el, filter) {
- if (jsPlumb.isAlreadyDraggable(el))
- $(el).draggable("option", "cancel", filter);
- },
-
- setElementDraggable : function(el, draggable) {
- $(el).draggable("option", "disabled", !draggable);
- },
-
- setDragScope : function(el, scope) {
- $(el).draggable("option", "scope", scope);
- },
-
- dragEvents : {
- 'start':'start', 'stop':'stop', 'drag':'drag', 'step':'step',
- 'over':'over', 'out':'out', 'drop':'drop', 'complete':'complete'
- },
- animEvents:{
- 'step':"step", 'complete':'complete'
- },
- getOriginalEvent : function(e) { return e.originalEvent || e; },
-
- trigger : function(el, event, originalEvent) {
- var h = jQuery._data(_getElementObject(el)[0], "handle");
- h(originalEvent);
- }
-
- });
- $(document).ready(jsPlumb.init);
- })(jQuery);
|