EditorUi.js 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916
  1. /**
  2. * Copyright (c) 2006-2016, JGraph Ltd
  3. * Copyright (c) 2006-2016, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Version
  9. */
  10. EditorUi.VERSION = '@DRAWIO-VERSION@';
  11. /**
  12. * Overrides compact UI setting.
  13. */
  14. EditorUi.compactUi = uiTheme != 'atlas';
  15. /**
  16. *
  17. */
  18. if (urlParams['dev'] == '1')
  19. {
  20. Editor.prototype.editBlankUrl = Editor.prototype.editBlankUrl + '&dev=1';
  21. Editor.prototype.editBlankFallbackUrl = Editor.prototype.editBlankFallbackUrl + '&dev=1';
  22. }
  23. /**
  24. * Capability check for canvas export
  25. */
  26. (function()
  27. {
  28. EditorUi.prototype.useCanvasForExport = false;
  29. try
  30. {
  31. var canvas = document.createElement('canvas');
  32. var img = new Image();
  33. // LATER: Capability check should not be async
  34. img.onload = function()
  35. {
  36. try
  37. {
  38. var ctx = canvas.getContext('2d');
  39. ctx.drawImage(img, 0, 0);
  40. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  41. var result = canvas.toDataURL('image/png');
  42. EditorUi.prototype.useCanvasForExport = result != null && result.length > 6;
  43. }
  44. catch (e)
  45. {
  46. // ignore
  47. }
  48. };
  49. // Checks if SVG with foreignObject can be exported
  50. var svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1px" height="1px" version="1.1"><foreignObject pointer-events="all" width="1" height="1"><div xmlns="http://www.w3.org/1999/xhtml"></div></foreignObject></svg>';
  51. img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  52. }
  53. catch (e)
  54. {
  55. // ignore
  56. }
  57. })();
  58. /**
  59. * Initializes math typesetting and loads respective code.
  60. */
  61. Editor.initMath = function(src, config)
  62. {
  63. src = (src != null) ? src : 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  64. Editor.mathJaxQueue = [];
  65. Editor.doMathJaxRender = function(container)
  66. {
  67. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  68. }
  69. // Disables global typesetting and messages on startup, adds queue for
  70. // asynchronous rendering while MathJax is loading
  71. window.MathJax =
  72. {
  73. skipStartupTypeset: true,
  74. showMathMenu: false,
  75. messageStyle: 'none',
  76. AuthorInit: function ()
  77. {
  78. // Specification recommends using SVG over HTML-CSS if browser is known
  79. // Check if too inconsistent with image export and print output
  80. MathJax.Hub.Config(config || {
  81. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  82. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  83. TeX: {
  84. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  85. },
  86. // Ignores math in in-place editor
  87. tex2jax: {
  88. ignoreClass: 'mxCellEditor'
  89. },
  90. asciimath2jax: {
  91. ignoreClass: 'mxCellEditor'
  92. }
  93. });
  94. MathJax.Hub.Register.StartupHook('Begin', function()
  95. {
  96. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  97. {
  98. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  99. }
  100. });
  101. }
  102. };
  103. // Adds global enqueue method for async rendering
  104. Editor.MathJaxRender = function(container)
  105. {
  106. // Initial rendering when MathJax finished loading
  107. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  108. {
  109. Editor.doMathJaxRender(container);
  110. }
  111. else
  112. {
  113. Editor.mathJaxQueue.push(container);
  114. }
  115. };
  116. // Adds global clear queue method
  117. Editor.MathJaxClear = function()
  118. {
  119. Editor.mathJaxQueue = [];
  120. };
  121. // Updates typeset after changes
  122. var editorInit = Editor.prototype.init;
  123. Editor.prototype.init = function()
  124. {
  125. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  126. {
  127. if (this.graph.mathEnabled)
  128. {
  129. Editor.MathJaxRender(this.graph.container);
  130. }
  131. }));
  132. };
  133. var tags = document.getElementsByTagName('script');
  134. if (tags != null && tags.length > 0)
  135. {
  136. var script = document.createElement('script');
  137. script.type = 'text/javascript';
  138. script.src = src;
  139. tags[0].parentNode.appendChild(script);
  140. }
  141. };
  142. /**
  143. * Used in the GraphViewer lightbox.
  144. */
  145. Editor.closeImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8br9fdrftH0O2menfd7+AQfYM/lNjoDHAAAAAElFTkSuQmCC' : IMAGE_PATH + '/delete.png';
  146. /**
  147. * Adds a shadow filter to the given svg root.
  148. */
  149. Editor.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  150. {
  151. createOnly = (createOnly != null) ? createOnly : false;
  152. var svgDoc = svgRoot.ownerDocument;
  153. var filter = (svgDoc.createElementNS != null) ?
  154. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  155. filter.setAttribute('id', 'dropShadow');
  156. var blur = (svgDoc.createElementNS != null) ?
  157. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  158. blur.setAttribute('in', 'SourceAlpha');
  159. blur.setAttribute('stdDeviation', '1.7');
  160. blur.setAttribute('result', 'blur');
  161. filter.appendChild(blur);
  162. var offset = (svgDoc.createElementNS != null) ?
  163. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  164. offset.setAttribute('in', 'blur');
  165. offset.setAttribute('dx', '3');
  166. offset.setAttribute('dy', '3');
  167. offset.setAttribute('result', 'offsetBlur');
  168. filter.appendChild(offset);
  169. var flood = (svgDoc.createElementNS != null) ?
  170. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  171. flood.setAttribute('flood-color', '#3D4574');
  172. flood.setAttribute('flood-opacity', '0.4');
  173. flood.setAttribute('result', 'offsetColor');
  174. filter.appendChild(flood);
  175. var composite = (svgDoc.createElementNS != null) ?
  176. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  177. composite.setAttribute('in', 'offsetColor');
  178. composite.setAttribute('in2', 'offsetBlur');
  179. composite.setAttribute('operator', 'in');
  180. composite.setAttribute('result', 'offsetBlur');
  181. filter.appendChild(composite);
  182. var feBlend = (svgDoc.createElementNS != null) ?
  183. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  184. feBlend.setAttribute('in', 'SourceGraphic');
  185. feBlend.setAttribute('in2', 'offsetBlur');
  186. filter.appendChild(feBlend);
  187. // Creates defs element if not available
  188. var defs = svgRoot.getElementsByTagName('defs');
  189. var defsElt = null;
  190. if (defs.length == 0)
  191. {
  192. defsElt = (svgDoc.createElementNS != null) ?
  193. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  194. if (svgRoot.firstChild != null)
  195. {
  196. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  197. }
  198. else
  199. {
  200. svgRoot.appendChild(defsElt);
  201. }
  202. }
  203. else
  204. {
  205. defsElt = defs[0];
  206. }
  207. defsElt.appendChild(filter);
  208. if (!createOnly)
  209. {
  210. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#dropShadow)');
  211. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  212. {
  213. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  214. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  215. }
  216. }
  217. return filter;
  218. };
  219. /**
  220. * Math support.
  221. */
  222. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  223. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  224. Editor.prototype.updateGraphComponents = function()
  225. {
  226. editorUpdateGraphComponents.apply(this, arguments);
  227. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  228. };
  229. /**
  230. * Abstraction for local storage access.
  231. */
  232. EditorUi.prototype.getLocalData = function(key, fn)
  233. {
  234. fn(localStorage.getItem(key));
  235. };
  236. /**
  237. * Abstraction for local storage access.
  238. */
  239. EditorUi.prototype.setLocalData = function(key, data, fn)
  240. {
  241. localStorage.setItem(key, data);
  242. fn();
  243. };
  244. /**
  245. * Abstraction for local storage access.
  246. */
  247. EditorUi.prototype.removeLocalData = function(key, fn)
  248. {
  249. localStorage.removeItem(key)
  250. fn();
  251. };
  252. EditorUi.prototype.setMathEnabled = function(value)
  253. {
  254. this.editor.graph.mathEnabled = value;
  255. this.editor.updateGraphComponents();
  256. this.editor.graph.refresh();
  257. this.fireEvent(new mxEventObject('mathEnabledChanged'));
  258. };
  259. EditorUi.prototype.isMathEnabled = function(value)
  260. {
  261. return this.editor.graph.mathEnabled;
  262. };
  263. // Helper method to move picket to top
  264. EditorUi.prototype.movePickersToTop = function()
  265. {
  266. var divs = document.getElementsByTagName('div');
  267. for (var i = 0; i < divs.length; i++)
  268. {
  269. if (divs[i].className == 'picker modal-dialog picker-dialog')
  270. {
  271. divs[i].style.zIndex = mxPopupMenu.prototype.zIndex + 1;
  272. }
  273. }
  274. };
  275. // Overrides to call print asynchronously after (disables immediate print here)
  276. if (window.PrintDialog)
  277. {
  278. var printDialogShowPrintPreview = PrintDialog.showPreview;
  279. PrintDialog.showPreview = function(preview, print)
  280. {
  281. if (typeof(MathJax) !== 'undefined' && preview.graph.mathEnabled)
  282. {
  283. print = false;
  284. }
  285. return printDialogShowPrintPreview.apply(this, arguments);
  286. };
  287. // Adds MathJax to print preview
  288. var printDialogCreatePrintPreview = PrintDialog.createPrintPreview;
  289. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin, print)
  290. {
  291. var preview = printDialogCreatePrintPreview.apply(this, arguments);
  292. if (typeof(MathJax) !== 'undefined' && graph.mathEnabled)
  293. {
  294. // Using writePostfix is workaround for blocking of DOM processing
  295. // in Chrome if using writeHead for injecting async script tag
  296. var writePostfix = preview.writePostfix;
  297. preview.writePostfix = function(doc, css)
  298. {
  299. writePostfix.apply(this, arguments);
  300. // Disables status message in print output
  301. doc.writeln('<script type="text/x-mathjax-config">');
  302. doc.writeln('MathJax.Hub.Config({');
  303. doc.writeln('messageStyle: "none",');
  304. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  305. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  306. doc.writeln('TeX: {');
  307. doc.writeln(' extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  308. doc.writeln('}');
  309. doc.writeln('});');
  310. // Adds asynchronous printing when MathJax finished rendering
  311. if (print)
  312. {
  313. doc.writeln('MathJax.Hub.Queue(function () {');
  314. doc.writeln('window.print();');
  315. doc.writeln('});');
  316. }
  317. doc.writeln('</script>');
  318. doc.writeln('<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js"></script>');
  319. };
  320. }
  321. return preview;
  322. };
  323. }
  324. /**
  325. * Global switches for the export dialog.
  326. */
  327. if (window.ExportDialog)
  328. {
  329. ExportDialog.showXmlOption = false;
  330. ExportDialog.showGifOption = false;
  331. ExportDialog.getExportParameter = function(ui, format)
  332. {
  333. return function()
  334. {
  335. // LATER Fix decoding of HTML file in backend (remove argument in getFileData)
  336. return 'xml=' + encodeURIComponent(ui.getFileData(true));
  337. };
  338. };
  339. }
  340. /**
  341. * Specifies the app name. Default is document.title.
  342. */
  343. Editor.prototype.appName = 'draw.io';
  344. /**
  345. * Translates this point by the given vector.
  346. *
  347. * @param {number} dx X-coordinate of the translation.
  348. * @param {number} dy Y-coordinate of the translation.
  349. */
  350. EditorUi.prototype.isOfflineApp = function()
  351. {
  352. return (urlParams['offline'] == '1');
  353. };
  354. /**
  355. * Returns true if this offline app is offline.
  356. */
  357. EditorUi.prototype.isOffline = function()
  358. {
  359. // In FF navigator.onLine is always true
  360. return (mxClient.IS_FF && this.isOfflineApp()) || !navigator.onLine || urlParams['stealth'] == '1';
  361. };
  362. /**
  363. * Translates this point by the given vector.
  364. *
  365. * @param {number} dx X-coordinate of the translation.
  366. * @param {number} dy Y-coordinate of the translation.
  367. */
  368. EditorUi.prototype.createSpinner = function(x, y, size)
  369. {
  370. size = (size != null) ? size : 24;
  371. var spinner = new Spinner({
  372. lines: 12, // The number of lines to draw
  373. length: size, // The length of each line
  374. width: Math.round(size / 3), // The line thickness
  375. radius: Math.round(size / 2), // The radius of the inner circle
  376. rotate: 0, // The rotation offset
  377. color: '#000', // #rgb or #rrggbb
  378. speed: 1.5, // Rounds per second
  379. trail: 60, // Afterglow percentage
  380. shadow: false, // Whether to render a shadow
  381. hwaccel: false, // Whether to use hardware acceleration
  382. zIndex: 2e9 // The z-index (defaults to 2000000000)
  383. });
  384. // Extends spin method to include an optional label
  385. var oldSpin = spinner.spin;
  386. spinner.spin = function(container, label)
  387. {
  388. var result = false;
  389. if (!this.active)
  390. {
  391. oldSpin.call(this, container);
  392. this.active = true;
  393. if (label != null)
  394. {
  395. var status = document.createElement('div');
  396. status.style.position = 'absolute';
  397. status.style.whiteSpace = 'nowrap';
  398. status.style.background = '#4B4243';
  399. status.style.color = 'white';
  400. status.style.fontFamily = 'Helvetica, Arial';
  401. status.style.fontSize = '9pt';
  402. status.style.padding = '6px';
  403. status.style.paddingLeft = '10px';
  404. status.style.paddingRight = '10px';
  405. status.style.zIndex = 2e9;
  406. status.style.left = Math.max(0, x) + 'px';
  407. status.style.top = Math.max(0, y + 70) + 'px';
  408. mxUtils.setPrefixedStyle(status.style, 'borderRadius', '6px');
  409. mxUtils.setPrefixedStyle(status.style, 'boxShadow', '2px 2px 3px 0px #ddd');
  410. mxUtils.setPrefixedStyle(status.style, 'transform', 'translate(-50%,-50%)');
  411. status.innerHTML = label + '...';
  412. container.appendChild(status);
  413. spinner.status = status;
  414. // Centers the label in older IE versions
  415. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode <= 8))
  416. {
  417. status.style.left = Math.round(Math.max(0, x - status.offsetWidth / 2)) + 'px';
  418. status.style.top = Math.round(Math.max(0, y + 70 - status.offsetHeight / 2)) + 'px';
  419. }
  420. }
  421. // Pause returns a function to resume the spinner
  422. this.pause = mxUtils.bind(this, function()
  423. {
  424. var fn = function() { };
  425. if (this.active)
  426. {
  427. fn = mxUtils.bind(this, function()
  428. {
  429. this.spin(container, label);
  430. });
  431. }
  432. this.stop();
  433. return fn;
  434. });
  435. result = true;
  436. }
  437. return result;
  438. };
  439. // Extends stop method to remove the optional label
  440. var oldStop = spinner.stop;
  441. spinner.stop = function()
  442. {
  443. oldStop.call(this);
  444. this.active = false;
  445. if (spinner.status != null)
  446. {
  447. spinner.status.parentNode.removeChild(spinner.status);
  448. spinner.status = null;
  449. }
  450. };
  451. return spinner;
  452. };
  453. /**
  454. * Static method for pasing PNG files.
  455. */
  456. EditorUi.parsePng = function(f, fn, error)
  457. {
  458. var pos = 0;
  459. function fread(d, count)
  460. {
  461. var start = pos;
  462. pos += count;
  463. return d.substring(start, pos);
  464. };
  465. // Reads unsigned long 32 bit big endian
  466. function _freadint(d)
  467. {
  468. var bytes = fread(d, 4);
  469. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  470. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  471. };
  472. // Checks signature
  473. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  474. {
  475. if (error != null)
  476. {
  477. error();
  478. }
  479. return;
  480. }
  481. // Reads header chunk
  482. fread(f,4);
  483. if (fread(f,4) != 'IHDR')
  484. {
  485. if (error != null)
  486. {
  487. error();
  488. }
  489. return;
  490. }
  491. fread(f, 17);
  492. do
  493. {
  494. var n = _freadint(f);
  495. var type = fread(f,4);
  496. if (fn != null)
  497. {
  498. if (fn(pos - 8, type, n))
  499. {
  500. break;
  501. }
  502. }
  503. value = fread(f,n);
  504. fread(f,4);
  505. if (type == 'IEND')
  506. {
  507. break;
  508. }
  509. }
  510. while (n);
  511. };
  512. /**
  513. * Helper function to extract the graph model XML node.
  514. */
  515. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  516. {
  517. if (node != null && typeof(pako) !== 'undefined')
  518. {
  519. var tmp = node.ownerDocument.getElementsByTagName('div');
  520. var divs = [];
  521. if (tmp != null && tmp.length > 0)
  522. {
  523. for (var i = 0; i < tmp.length; i++)
  524. {
  525. if (tmp[i].getAttribute('class') == 'mxgraph')
  526. {
  527. divs.push(tmp[i]);
  528. break;
  529. }
  530. }
  531. }
  532. if (divs.length > 0)
  533. {
  534. var data = divs[0].getAttribute('data-mxgraph');
  535. if (data != null)
  536. {
  537. var config = JSON.parse(data);
  538. if (config != null && config.xml != null)
  539. {
  540. var doc2 = mxUtils.parseXml(config.xml);
  541. node = doc2.documentElement;
  542. }
  543. }
  544. else
  545. {
  546. var divs2 = divs[0].getElementsByTagName('div');
  547. if (divs2.length > 0)
  548. {
  549. var data = mxUtils.getTextContent(divs2[0]);
  550. data = this.graph.decompress(data);
  551. if (data.length > 0)
  552. {
  553. var doc2 = mxUtils.parseXml(data);
  554. node = doc2.documentElement;
  555. }
  556. }
  557. }
  558. }
  559. }
  560. if (node != null && node.nodeName == 'svg')
  561. {
  562. var tmp = node.getAttribute('content');
  563. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  564. {
  565. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  566. }
  567. if (tmp != null && tmp.charAt(0) == '%')
  568. {
  569. tmp = decodeURIComponent(tmp);
  570. }
  571. if (tmp != null && tmp.length > 0)
  572. {
  573. node = mxUtils.parseXml(tmp).documentElement;
  574. }
  575. else
  576. {
  577. throw {message: mxResources.get('notADiagramFile')};
  578. }
  579. }
  580. if (node != null && !allowMxFile)
  581. {
  582. var diagramNode = null;
  583. if (node.nodeName == 'diagram')
  584. {
  585. diagramNode = node;
  586. }
  587. else if (node.nodeName == 'mxfile')
  588. {
  589. var diagrams = node.getElementsByTagName('diagram');
  590. if (diagrams.length > 0)
  591. {
  592. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  593. }
  594. }
  595. if (diagramNode != null)
  596. {
  597. node = mxUtils.parseXml(this.graph.decompress(mxUtils.getTextContent(diagramNode))).documentElement;
  598. }
  599. }
  600. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  601. {
  602. node = null;
  603. }
  604. return node;
  605. };
  606. /**
  607. * Returns true if the given string contains a compatible graph model.
  608. */
  609. EditorUi.prototype.isCompatibleString = function(data)
  610. {
  611. try
  612. {
  613. var doc = mxUtils.parseXml(data);
  614. var node = this.editor.extractGraphModel(doc.documentElement);
  615. return node != null && node.getElementsByTagName('parsererror').length == 0;
  616. }
  617. catch (e)
  618. {
  619. // ignore
  620. }
  621. return false;
  622. };
  623. /**
  624. * Extracts the mxfile from the given HTML data from a data transfer event.
  625. */
  626. var editorUiExtractGraphModelFromHtml = EditorUi.prototype.extractGraphModelFromHtml;
  627. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  628. {
  629. var result = editorUiExtractGraphModelFromHtml.apply(this, arguments);
  630. if (result == null)
  631. {
  632. try
  633. {
  634. var idx = data.indexOf('&lt;mxfile ');
  635. if (idx >= 0)
  636. {
  637. var idx2 = data.lastIndexOf('&lt;/mxfile&gt;');
  638. if (idx2 > idx)
  639. {
  640. result = data.substring(idx, idx2 + 15).replace(/&gt;/g, '>').
  641. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  642. }
  643. }
  644. else
  645. {
  646. // Gets compressed data from mxgraph element in HTML document
  647. var doc = mxUtils.parseXml(data);
  648. var node = this.editor.extractGraphModel(doc.documentElement);
  649. result = (node != null) ? mxUtils.getXml(node) : '';
  650. }
  651. }
  652. catch (e)
  653. {
  654. // ignore
  655. }
  656. }
  657. return result;
  658. };
  659. /**
  660. * Workaround for malformed xhtml meta element bug 07.08.16. The trailing slash was missing causing
  661. * reopen to fail trying to parse. Used in replaceFileData, setFileData and importFile.
  662. */
  663. EditorUi.prototype.validateFileData = function(data)
  664. {
  665. if (data != null && data.length > 0)
  666. {
  667. var index = data.indexOf('<meta charset="utf-8">');
  668. if (index >= 0)
  669. {
  670. var replaceString = '<meta charset="utf-8"/>';
  671. var replaceStrLen = replaceString.length;
  672. data = data.slice(0, index) + replaceString + data.slice(index + replaceStrLen - 1, data.length);
  673. }
  674. }
  675. return data;
  676. };
  677. /**
  678. *
  679. */
  680. EditorUi.prototype.replaceFileData = function(data)
  681. {
  682. data = this.validateFileData(data);
  683. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  684. // Some nodes must be extracted here to find the mxfile node
  685. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  686. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  687. if (tmp != null)
  688. {
  689. node = tmp;
  690. }
  691. if (node != null)
  692. {
  693. var graph = this.editor.graph;
  694. graph.model.beginUpdate();
  695. try
  696. {
  697. var oldPages = (this.pages != null) ? this.pages.slice() : null;
  698. var nodes = node.getElementsByTagName('diagram');
  699. if (nodes.length > 1 || urlParams['pages'] == '1')
  700. {
  701. this.fileNode = node;
  702. this.pages = (this.pages != null) ? this.pages : [];
  703. // Wraps page nodes
  704. for (var i = nodes.length - 1; i >= 0; i--)
  705. {
  706. var page = this.updatePageRoot(new DiagramPage(nodes[i]));
  707. // Checks for invalid page names
  708. if (page.getName() == null)
  709. {
  710. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  711. }
  712. graph.model.execute(new ChangePage(this, page, (i == 0) ? page : null, 0));
  713. }
  714. }
  715. else
  716. {
  717. // Creates tabbed file structure if enforced by URL
  718. if (urlParams['pages'] == '1' && this.fileNode == null)
  719. {
  720. this.fileNode = node.ownerDocument.createElement('mxfile');
  721. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  722. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  723. graph.model.execute(new ChangePage(this, this.currentPage, this.currentPage, 0));
  724. }
  725. // Avoids scroll offset when switching page
  726. this.editor.setGraphXml(node);
  727. // Avoids duplicate parsing of the XML stored in the node
  728. if (this.currentPage != null)
  729. {
  730. this.currentPage.root = this.editor.graph.model.root;
  731. }
  732. }
  733. if (oldPages != null)
  734. {
  735. for (var i = 0; i < oldPages.length; i++)
  736. {
  737. graph.model.execute(new ChangePage(this, oldPages[i], null));
  738. }
  739. }
  740. }
  741. finally
  742. {
  743. graph.model.endUpdate();
  744. }
  745. }
  746. };
  747. /**
  748. *
  749. */
  750. EditorUi.prototype.setFileData = function(data)
  751. {
  752. data = this.validateFileData(data);
  753. this.currentPage = null;
  754. this.fileNode = null;
  755. this.pages = null;
  756. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  757. // Some nodes must be extracted here to find the mxfile node
  758. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  759. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  760. if (tmp != null)
  761. {
  762. node = tmp;
  763. }
  764. if (node != null && node.nodeName == 'mxfile')
  765. {
  766. var nodes = node.getElementsByTagName('diagram');
  767. if (nodes.length > 1 || urlParams['pages'] == '1')
  768. {
  769. this.fileNode = node;
  770. this.pages = [];
  771. // Wraps page nodes
  772. for (var i = 0; i < nodes.length; i++)
  773. {
  774. var page = new DiagramPage(nodes[i]);
  775. // Checks for invalid page names
  776. if (page.getName() == null)
  777. {
  778. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  779. }
  780. this.pages.push(page);
  781. }
  782. this.currentPage = this.pages[Math.max(0, Math.min(this.pages.length - 1, urlParams['page'] || 0))];
  783. node = this.currentPage.node;
  784. }
  785. }
  786. // Creates tabbed file structure if enforced by URL
  787. if (urlParams['pages'] == '1' && this.fileNode == null)
  788. {
  789. this.fileNode = node.ownerDocument.createElement('mxfile');
  790. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  791. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  792. this.pages = [this.currentPage];
  793. }
  794. // Avoids scroll offset when switching page
  795. this.editor.setGraphXml(node);
  796. // Avoids duplicate parsing of the XML stored in the node
  797. if (this.currentPage != null)
  798. {
  799. this.currentPage.root = this.editor.graph.model.root;
  800. }
  801. };
  802. /**
  803. * Adds support for old stylesheets and compressed files
  804. */
  805. var editorSetGraphXml = Editor.prototype.setGraphXml;
  806. Editor.prototype.setGraphXml = function(node)
  807. {
  808. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  809. if (node != null)
  810. {
  811. // Checks input for parser errors
  812. var errs = node.getElementsByTagName('parsererror');
  813. if (errs != null && errs.length > 0)
  814. {
  815. var elt = errs[0];
  816. var divs = elt.getElementsByTagName('div');
  817. if (divs != null && divs.length > 0)
  818. {
  819. elt = divs[0];
  820. }
  821. throw {message: mxUtils.getTextContent(elt)};
  822. }
  823. else if (node.nodeName == 'mxGraphModel')
  824. {
  825. var style = node.getAttribute('style') || 'default-style2';
  826. // Decodes the style if required
  827. if (urlParams['embed'] != '1' && (style == null || style == ''))
  828. {
  829. var node2 = (this.graph.themes != null) ?
  830. this.graph.themes['default-old'] :
  831. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  832. if (node2 != null)
  833. {
  834. var dec2 = new mxCodec(node2.ownerDocument);
  835. dec2.decode(node2, this.graph.getStylesheet());
  836. }
  837. }
  838. else if (style != this.graph.currentStyle)
  839. {
  840. var node2 = (this.graph.themes != null) ?
  841. this.graph.themes[style] :
  842. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  843. if (node2 != null)
  844. {
  845. var dec2 = new mxCodec(node2.ownerDocument);
  846. dec2.decode(node2, this.graph.getStylesheet());
  847. }
  848. }
  849. this.graph.currentStyle = style;
  850. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  851. var bgImg = node.getAttribute('backgroundImage');
  852. if (bgImg != null)
  853. {
  854. bgImg = JSON.parse(bgImg);
  855. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  856. }
  857. else
  858. {
  859. this.graph.setBackgroundImage(null);
  860. }
  861. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  862. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  863. }
  864. // Calls updateGraphComponents
  865. editorSetGraphXml.apply(this, arguments);
  866. }
  867. else
  868. {
  869. throw {
  870. message: mxResources.get('notADiagramFile') || 'Invalid data',
  871. toString: function() { return this.message; }
  872. };
  873. }
  874. };
  875. /**
  876. * Adds persistent style to file
  877. */
  878. var editorGetGraphXml = Editor.prototype.getGraphXml;
  879. Editor.prototype.getGraphXml = function(ignoreSelection)
  880. {
  881. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  882. var node = editorGetGraphXml.apply(this, arguments);
  883. // Adds the current style
  884. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  885. {
  886. node.setAttribute('style', this.graph.currentStyle);
  887. }
  888. // Adds the background image
  889. if (this.graph.backgroundImage != null)
  890. {
  891. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  892. }
  893. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  894. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  895. return node;
  896. };
  897. var editorResetGraph = Editor.prototype.resetGraph;
  898. Editor.prototype.resetGraph = function()
  899. {
  900. this.graph.mathEnabled = (urlParams['math'] == '1');
  901. this.graph.view.x0 = null;
  902. this.graph.view.y0 = null;
  903. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  904. editorResetGraph.apply(this, arguments);
  905. };
  906. /**
  907. * EditorUi Overrides
  908. */
  909. if (urlParams['offline'] == '1')
  910. {
  911. EditorUi.prototype.footerHeight = 4;
  912. }
  913. else
  914. {
  915. if (uiTheme == 'atlas')
  916. {
  917. if (typeof Toolbar !== 'undefined')
  918. {
  919. Toolbar.prototype.unselectedBackground = (mxClient.IS_QUIRKS) ? 'none' : 'linear-gradient(rgb(255, 255, 255) 0px, rgb(242, 242, 242) 100%)';
  920. Toolbar.prototype.selectedBackground = 'rgb(242, 242, 242)';
  921. }
  922. Editor.prototype.initialTopSpacing = 3;
  923. EditorUi.prototype.menubarHeight = 41;
  924. EditorUi.prototype.toolbarHeight = 38;
  925. EditorUi.prototype.hsplitPosition = 188;
  926. Sidebar.prototype.thumbWidth = 46;
  927. Sidebar.prototype.thumbHeight = 46;
  928. Sidebar.prototype.thumbPadding = (document.documentMode >= 5) ? 0 : 1;
  929. Sidebar.prototype.thumbBorder = 2;
  930. }
  931. else
  932. {
  933. if (urlParams['savesidebar'] == '1')
  934. {
  935. Sidebar.prototype.thumbWidth = 64;
  936. Sidebar.prototype.thumbHeight = 64;
  937. }
  938. }
  939. EditorUi.prototype.footerHeight = (screen.height <= 740) ? 5 : 46;
  940. // Fetches footer from page
  941. EditorUi.prototype.createFooter = function()
  942. {
  943. var footer = document.getElementById('geFooter');
  944. if (footer != null)
  945. {
  946. footer.style.visibility = 'visible';
  947. // Adds button to hide the footer
  948. var img = document.createElement('img');
  949. img.setAttribute('border', '0');
  950. img.setAttribute('src', Dialog.prototype.closeImage);
  951. img.setAttribute('title', mxResources.get('hide'));
  952. footer.appendChild(img)
  953. if (mxClient.IS_QUIRKS)
  954. {
  955. img.style.position = 'relative';
  956. img.style.styleFloat = 'right';
  957. img.style.top = '-30px';
  958. img.style.left = '164px';
  959. img.style.cursor = 'pointer';
  960. }
  961. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  962. {
  963. this.hideFooter();
  964. }));
  965. }
  966. return footer;
  967. };
  968. }
  969. /**
  970. * Hides the footer.
  971. */
  972. EditorUi.prototype.hideFooter = function()
  973. {
  974. var footer = document.getElementById('geFooter');
  975. if (footer != null)
  976. {
  977. this.footerHeight = 0;
  978. footer.style.display = 'none';
  979. this.refresh();
  980. }
  981. };
  982. /**
  983. * Overrides image dialog to add image search and Google+.
  984. */
  985. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting, convertDataUri)
  986. {
  987. // KNOWN: IE+FF don't return keyboard focus after image dialog (calling focus doesn't help)
  988. var dlg = new ImageDialog(this, title, value, fn, ignoreExisting, convertDataUri);
  989. this.showDialog(dlg.container, (Graph.fileSupport) ? 420 : 340, (Graph.fileSupport) ? 200 : 90, true, true);
  990. dlg.init();
  991. };
  992. /**
  993. * Hides the current menu.
  994. */
  995. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  996. {
  997. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  998. {
  999. this.setBackgroundImage(image);
  1000. });
  1001. var dlg = new BackgroundImageDialog(this, mxUtils.bind(this, function(image)
  1002. {
  1003. apply(image);
  1004. }));
  1005. this.showDialog(dlg.container, 360, 200, true, true);
  1006. dlg.init();
  1007. };
  1008. /**
  1009. * Hides the current menu.
  1010. */
  1011. EditorUi.prototype.showLibraryDialog = function(name, sidebar, images, file, mode)
  1012. {
  1013. var dlg = new LibraryDialog(this, name, sidebar, images, file, mode);
  1014. this.showDialog(dlg.container, 620, 440, true, true, mxUtils.bind(this, function(cancel)
  1015. {
  1016. if (cancel && this.getCurrentFile() == null)
  1017. {
  1018. this.showSplash();
  1019. }
  1020. }));
  1021. dlg.init();
  1022. };
  1023. /**
  1024. * Allows for two buttons in the sidebar footer.
  1025. */
  1026. EditorUi.prototype.sidebarFooterHeight = (uiTheme == 'atlas') ? 36 : 36;
  1027. /**
  1028. * Specifies the default custom shape style.
  1029. */
  1030. EditorUi.prototype.defaultCustomShapeStyle = 'shape=stencil(tZRtTsQgEEBPw1+DJR7AoN6DbWftpAgE0Ortd/jYRGq72R+YNE2YgTePloEJGWblgA18ZuKFDcMj5/Sm8boZq+BgjCX4pTyqk6ZlKROitwusOMXKQDODx5iy4pXxZ5qTHiFHawxB0JrQZH7lCabQ0Fr+XWC1/E8zcsT/gAi+Subo2/3Mh6d/oJb5nU1b5tW7r2knautaa3T+U32o7f7vZwpJkaNDLORJjcu7t59m2jXxqX9un+tt022acsfmoKaQZ+vhhswZtS6Ne/ThQGt0IV0N3Yyv6P3CeT9/tHO0XFI5cAE=);whiteSpace=wrap;html=1;';
  1031. /**
  1032. * Hook for sidebar footer container.
  1033. */
  1034. EditorUi.prototype.createSidebarFooterContainer = function()
  1035. {
  1036. var div = this.createDiv('geSidebarContainer');
  1037. div.style.position = 'absolute';
  1038. div.style.overflow = 'hidden';
  1039. div.style.borderWidth = '3px';
  1040. var elt2 = document.createElement('a');
  1041. elt2.setAttribute('href', 'javascript:void(0);');
  1042. elt2.className = 'geTitle';
  1043. elt2.style.height = '100%';
  1044. elt2.style.paddingTop = '9px';
  1045. mxUtils.write(elt2, mxResources.get('moreShapes') + '...');
  1046. mxEvent.addListener(elt2, 'click', mxUtils.bind(this, function(evt)
  1047. {
  1048. this.actions.get('shapes').funct();
  1049. mxEvent.consume(evt);
  1050. }));
  1051. div.appendChild(elt2);
  1052. return div;
  1053. };
  1054. /**
  1055. * Setting the current file.
  1056. */
  1057. /**
  1058. * Defines the maximum size for images.
  1059. */
  1060. EditorUi.prototype.maxBackgroundSize = 1600;
  1061. /**
  1062. * Defines the maximum size for images.
  1063. */
  1064. EditorUi.prototype.maxImageSize = 520;
  1065. /**
  1066. * Images above 100K should be resampled.
  1067. */
  1068. EditorUi.prototype.resampleThreshold = 100000;
  1069. /**
  1070. * Maximum allowed size for images is 1 MB.
  1071. */
  1072. EditorUi.prototype.maxImageBytes = 1000000;
  1073. /**
  1074. * Maximum size for background images is 2.5 MB.
  1075. */
  1076. EditorUi.prototype.maxBackgroundBytes = 2500000;
  1077. /**
  1078. * Holds the current file.
  1079. */
  1080. EditorUi.prototype.currentFile = null;
  1081. /**
  1082. * Translates this point by the given vector.
  1083. *
  1084. * @param {number} dx X-coordinate of the translation.
  1085. * @param {number} dy Y-coordinate of the translation.
  1086. */
  1087. EditorUi.prototype.setCurrentFile = function(file)
  1088. {
  1089. this.currentFile = file;
  1090. };
  1091. /**
  1092. * Translates this point by the given vector.
  1093. *
  1094. * @param {number} dx X-coordinate of the translation.
  1095. * @param {number} dy Y-coordinate of the translation.
  1096. */
  1097. EditorUi.prototype.getCurrentFile = function()
  1098. {
  1099. return this.currentFile;
  1100. };
  1101. /**
  1102. * Translates this point by the given vector.
  1103. *
  1104. * @param {number} dx X-coordinate of the translation.
  1105. * @param {number} dy Y-coordinate of the translation.
  1106. */
  1107. EditorUi.prototype.isDiagramEmpty = function()
  1108. {
  1109. var model = this.editor.graph.getModel();
  1110. return model.getChildCount(model.root) == 1 && model.getChildCount(model.getChildAt(model.root, 0)) == 0;
  1111. };
  1112. /**
  1113. * Handling for canvas export.
  1114. */
  1115. /**
  1116. *
  1117. */
  1118. EditorUi.prototype.isExportToCanvas = function()
  1119. {
  1120. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  1121. return mxClient.IS_CHROMEAPP || (!this.editor.graph.mathEnabled && this.useCanvasForExport);
  1122. };
  1123. /**
  1124. * Translates this point by the given vector.
  1125. *
  1126. * @param {number} dx X-coordinate of the translation.
  1127. * @param {number} dy Y-coordinate of the translation.
  1128. */
  1129. EditorUi.prototype.createSvgDataUri = function(svg)
  1130. {
  1131. return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  1132. };
  1133. /**
  1134. *
  1135. */
  1136. EditorUi.prototype.createPngDataUri = function(canvas, xml)
  1137. {
  1138. var data = canvas.toDataURL('image/png');
  1139. // Checks if output is invalid or empty
  1140. if (data.length <= 6 || data == canvas.cloneNode(false).toDataURL('image/png'))
  1141. {
  1142. throw {message: 'Invalid image'};
  1143. }
  1144. if (xml != null)
  1145. {
  1146. data = this.writeGraphModelToPng(data, 'zTXt', 'mxGraphModel', atob(this.editor.graph.compress(xml)));
  1147. }
  1148. return data;
  1149. };
  1150. /**
  1151. *
  1152. */
  1153. EditorUi.prototype.saveCanvas = function(canvas, xml)
  1154. {
  1155. var file = this.getCurrentFile();
  1156. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1157. var dot = filename.lastIndexOf('.');
  1158. if (dot > 0)
  1159. {
  1160. filename = filename.substring(0, dot);
  1161. }
  1162. filename += '.png';
  1163. var data = this.createPngDataUri(canvas, xml);
  1164. this.saveLocalFile(data.substring(data.lastIndexOf(',') + 1), filename, 'image/png', true);
  1165. };
  1166. /**
  1167. *
  1168. */
  1169. EditorUi.prototype.showRemoteExportDialog = function(btnLabel, helpLink, callback)
  1170. {
  1171. var graph = this.editor.graph;
  1172. var content = document.createElement('div');
  1173. content.style.padding = '6px';
  1174. var cb2 = document.createElement('input');
  1175. cb2.style.marginRight = '8px';
  1176. cb2.setAttribute('type', 'checkbox');
  1177. if (graph.isSelectionEmpty())
  1178. {
  1179. cb2.setAttribute('disabled', 'disabled');
  1180. }
  1181. content.appendChild(cb2);
  1182. mxUtils.write(content, mxResources.get('selectionOnly'));
  1183. mxUtils.br(content);
  1184. var cb = document.createElement('input');
  1185. cb.setAttribute('type', 'checkbox');
  1186. cb.setAttribute('checked', 'checked');
  1187. cb.defaultChecked = true;
  1188. cb.style.marginRight = '8px';
  1189. cb.style.marginTop = '16px';
  1190. content.appendChild(cb);
  1191. mxUtils.write(content, mxResources.get('includeCopyOfMyDiagram'));
  1192. var dlg = new CustomDialog(this, content, mxUtils.bind(this, function()
  1193. {
  1194. callback(!cb2.checked, cb.checked);
  1195. }), null, btnLabel, helpLink);
  1196. this.showDialog(dlg.container, 300, 120, true, true);
  1197. }
  1198. /**
  1199. *
  1200. */
  1201. EditorUi.prototype.showExportDialog = function(embedOption, btnLabel, helpLink, callback)
  1202. {
  1203. var graph = this.editor.graph;
  1204. var content = document.createElement('div');
  1205. content.style.paddingTop = '20px';
  1206. content.style.paddingRight = '8px';
  1207. var cb = document.createElement('input');
  1208. cb.style.marginRight = '8px';
  1209. cb.setAttribute('type', 'checkbox');
  1210. if (graph.background == mxConstants.NONE || graph.background == null)
  1211. {
  1212. cb.setAttribute('checked', 'checked');
  1213. cb.defaultChecked = true;
  1214. }
  1215. content.appendChild(cb);
  1216. mxUtils.write(content, mxResources.get('transparentBackground'));
  1217. mxUtils.br(content);
  1218. var cb2 = document.createElement('input');
  1219. cb2.style.marginTop = '16px';
  1220. cb2.style.marginRight = '8px';
  1221. cb2.setAttribute('type', 'checkbox');
  1222. if (graph.isSelectionEmpty())
  1223. {
  1224. cb2.setAttribute('disabled', 'disabled');
  1225. }
  1226. content.appendChild(cb2);
  1227. mxUtils.write(content, mxResources.get('selectionOnly'));
  1228. mxUtils.br(content);
  1229. var cb3 = document.createElement('input');
  1230. cb3.style.marginTop = '16px';
  1231. cb3.style.marginRight = '8px';
  1232. cb3.setAttribute('type', 'checkbox');
  1233. content.appendChild(cb3);
  1234. mxUtils.write(content, mxResources.get('shadow'));
  1235. mxUtils.br(content);
  1236. if (graph.shadowVisible)
  1237. {
  1238. cb3.setAttribute('checked', 'checked');
  1239. cb3.defaultChecked = true;
  1240. }
  1241. var cb5 = document.createElement('input');
  1242. cb5.style.marginTop = '16px';
  1243. cb5.style.marginRight = '8px';
  1244. cb5.setAttribute('type', 'checkbox');
  1245. if (this.isOffline() || !this.canvasSupported)
  1246. {
  1247. cb5.setAttribute('disabled', 'disabled');
  1248. }
  1249. if (embedOption)
  1250. {
  1251. content.appendChild(cb5);
  1252. mxUtils.write(content, mxResources.get('embedImages'));
  1253. mxUtils.br(content);
  1254. }
  1255. var cb4 = document.createElement('input');
  1256. cb4.style.marginTop = '16px';
  1257. cb4.style.marginRight = '8px';
  1258. cb4.setAttribute('type', 'checkbox');
  1259. cb4.style.marginBottom = '8px';
  1260. cb4.setAttribute('checked', 'checked');
  1261. cb4.defaultChecked = true;
  1262. content.appendChild(cb4);
  1263. mxUtils.write(content, mxResources.get('includeCopyOfMyDiagram'));
  1264. var dlg = new FilenameDialog(this, 100, btnLabel, mxUtils.bind(this, function(newValue)
  1265. {
  1266. callback(newValue, cb.checked, !cb2.checked, cb3.checked, cb4.checked, cb5.checked);
  1267. }), mxResources.get('zoom') + ' (%)', null, content, (!this.isOffline()) ? helpLink : null);
  1268. this.showDialog(dlg.container, 320, (embedOption) ? 266 : 240, true, true);
  1269. dlg.init();
  1270. }
  1271. /**
  1272. *
  1273. */
  1274. EditorUi.prototype.uploadToGithub = function(file, base64Data, editable)
  1275. {
  1276. var resume = this.spinner.pause();
  1277. var content = document.createElement('div');
  1278. content.style.paddingTop = '20px';
  1279. content.style.paddingRight = '8px';
  1280. var table = document.createElement('table');
  1281. var tbody = document.createElement('tbody');
  1282. var tr = document.createElement('tr');
  1283. var td = document.createElement('td');
  1284. var uname = document.createElement('input');
  1285. uname.setAttribute('type', 'text');
  1286. mxUtils.write(td, 'Username:');
  1287. tr.appendChild(td);
  1288. td = td.cloneNode(false);
  1289. td.appendChild(uname);
  1290. tr.appendChild(td);
  1291. tbody.appendChild(tr);
  1292. td = td.cloneNode(false);
  1293. var pword = document.createElement('input');
  1294. pword.setAttribute('type', 'password');
  1295. mxUtils.write(td, 'Password:');
  1296. tr = tr.cloneNode(false);
  1297. tr.appendChild(td);
  1298. td = td.cloneNode(false);
  1299. td.appendChild(pword);
  1300. tr.appendChild(td);
  1301. tbody.appendChild(tr);
  1302. td = td.cloneNode(false);
  1303. var org = document.createElement('input');
  1304. org.setAttribute('type', 'text');
  1305. mxUtils.write(td, 'Organisation:');
  1306. tr = tr.cloneNode(false);
  1307. tr.appendChild(td);
  1308. td = td.cloneNode(false);
  1309. td.appendChild(org);
  1310. tr.appendChild(td);
  1311. tbody.appendChild(tr);
  1312. td = td.cloneNode(false);
  1313. var repo = document.createElement('input');
  1314. repo.setAttribute('type', 'text');
  1315. mxUtils.write(td, 'Repository:');
  1316. tr = tr.cloneNode(false);
  1317. tr.appendChild(td);
  1318. td = td.cloneNode(false);
  1319. td.appendChild(repo);
  1320. tr.appendChild(td);
  1321. tbody.appendChild(tr);
  1322. td = td.cloneNode(false);
  1323. var path = document.createElement('input');
  1324. path.setAttribute('type', 'text');
  1325. mxUtils.write(td, 'Path:');
  1326. tr = tr.cloneNode(false);
  1327. tr.appendChild(td);
  1328. td = td.cloneNode(false);
  1329. td.appendChild(path);
  1330. tr.appendChild(td);
  1331. tbody.appendChild(tr);
  1332. td = td.cloneNode(false);
  1333. var file = this.getCurrentFile();
  1334. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1335. var dot = filename.lastIndexOf('.');
  1336. if (dot > 0)
  1337. {
  1338. filename = filename.substring(0, dot);
  1339. }
  1340. path.value = filename + '.png';
  1341. var ref = document.createElement('input');
  1342. ref.setAttribute('type', 'text');
  1343. mxUtils.write(td, 'Branch/Tag:');
  1344. ref.value = 'master';
  1345. tr = tr.cloneNode(false);
  1346. tr.appendChild(td);
  1347. td = td.cloneNode(false);
  1348. td.appendChild(ref);
  1349. tr.appendChild(td);
  1350. tbody.appendChild(tr);
  1351. td = td.cloneNode(false);
  1352. var msg = document.createElement('input');
  1353. msg.setAttribute('type', 'text');
  1354. mxUtils.write(td, 'Message:');
  1355. msg.value = 'Updated ' + filename + '.png';
  1356. tr = tr.cloneNode(false);
  1357. tr.appendChild(td);
  1358. td = td.cloneNode(false);
  1359. td.appendChild(msg);
  1360. tr.appendChild(td);
  1361. tbody.appendChild(tr);
  1362. td = td.cloneNode(false);
  1363. table.appendChild(tbody);
  1364. content.appendChild(table);
  1365. var dlg = new FilenameDialog(this, null, mxResources.get('publish'), mxUtils.bind(this, function()
  1366. {
  1367. var url = 'https://api.github.com/repos/' + org.value + '/' + repo.value +
  1368. '/contents/' + path.value + '?ref=' + encodeURIComponent(ref.value);
  1369. resume();
  1370. mxUtils.get(url, mxUtils.bind(this, function(req)
  1371. {
  1372. if (req.getStatus() == 200 || req.getStatus() == 404)
  1373. {
  1374. var obj = JSON.parse(req.getText());
  1375. var entity =
  1376. {
  1377. path: path.value,
  1378. message: msg.value,
  1379. content: base64Data
  1380. };
  1381. if (obj.sha != null)
  1382. {
  1383. entity.sha = obj.sha;
  1384. }
  1385. // Native PUT request
  1386. var req2 = new XMLHttpRequest();
  1387. req2.onreadystatechange = mxUtils.bind(this, function()
  1388. {
  1389. if (req2.readyState == 4)
  1390. {
  1391. if (req2.status >= 200 && req2.status < 300)
  1392. {
  1393. this.spinner.stop();
  1394. this.hideDialog();
  1395. url = 'https://github.com/' + org.value + '/' + repo.value + '/blob/' + ref.value + '/' + path.value;
  1396. var dlg = new ErrorDialog(this, mxResources.get('published'),
  1397. mxResources.get('publishedAt', ['<a href="' + url + '" target="_blank">' + url + '</a>']),
  1398. mxResources.get('close'), mxUtils.bind(this, function()
  1399. {
  1400. this.hideDialog();
  1401. }), null,
  1402. mxResources.get('openInNewWindow'), mxUtils.bind(this, function()
  1403. {
  1404. window.open(url);
  1405. }), false);
  1406. this.showDialog(dlg.container, 340, 170, true, false);
  1407. dlg.init();
  1408. }
  1409. else
  1410. {
  1411. resume = this.spinner.pause();
  1412. this.handleError(JSON.parse(req2.responseText));
  1413. }
  1414. }
  1415. });
  1416. req2.open('PUT', url, true);
  1417. req2.setRequestHeader('Authorization', 'Basic ' +
  1418. btoa(uname.value + ':' + pword.value));
  1419. req2.send(JSON.stringify(entity));
  1420. }
  1421. else
  1422. {
  1423. this.hideDialog();
  1424. this.spinner.stop();
  1425. this.handleError(JSON.parse(req.getText()));
  1426. }
  1427. }), mxUtils.bind(this, function(req)
  1428. {
  1429. this.hideDialog();
  1430. this.spinner.stop();
  1431. this.handleError({message: mxResources.get('unknownError')});
  1432. }));
  1433. }), null, null, content, null, false);
  1434. this.showDialog(dlg.container, 260, 260, true, false);
  1435. dlg.init();
  1436. };
  1437. /**
  1438. *
  1439. */
  1440. EditorUi.prototype.uploadToImgur = function(file, base64Data, editable, socialHandler)
  1441. {
  1442. var resume = this.spinner.pause();
  1443. // Shows a warning dialog before uploading
  1444. var dlg = new ErrorDialog(this, mxResources.get('warning'),
  1445. '<img style="max-width:300px;max-height:80px;margin-bottom:20px;padding:6px;border:1px solid gray;" ' +
  1446. 'src="data:image/png;base64,' + base64Data + '"/><br>' +
  1447. mxResources.get('publishConfirmation'),
  1448. mxResources.get('cancel'), mxUtils.bind(this, function()
  1449. {
  1450. // Do nothing
  1451. }), null,
  1452. mxResources.get('publish'), mxUtils.bind(this, function()
  1453. {
  1454. resume();
  1455. var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1456. var dot = title.lastIndexOf('.');
  1457. var filename = title;
  1458. if (dot > 0)
  1459. {
  1460. title = filename.substring(0, dot);
  1461. filename = title;
  1462. }
  1463. filename += '.png';
  1464. // Indirection via servlet for billing and hiding secrets
  1465. var req = new mxXmlRequest('/imgur', JSON.stringify({type: 'base64', image: base64Data,
  1466. name: filename, title: title, description: 'Made with https://www.draw.io'}), 'POST');
  1467. var extractAndHandleError = mxUtils.bind(this, function(req)
  1468. {
  1469. var e = {message: mxResources.get('unknownError')};
  1470. try
  1471. {
  1472. var res = JSON.parse(req.getText());
  1473. e = {message: res.message || res.data.error};
  1474. }
  1475. catch (err)
  1476. {
  1477. // ignore
  1478. }
  1479. this.handleError(e);
  1480. });
  1481. // First request to upload image to Imgur
  1482. req.send(mxUtils.bind(this, function(req)
  1483. {
  1484. if (req.getStatus() == 200)
  1485. {
  1486. try
  1487. {
  1488. var res = JSON.parse(req.getText());
  1489. // Logs publishing of diagrams
  1490. try
  1491. {
  1492. var img = new Image();
  1493. // Timestamp is added to bypass client-side cache
  1494. img.src = 'log?severity=CONFIG&msg=imgur-published:' + res.data.id + '&v=' +
  1495. encodeURIComponent(EditorUi.VERSION) + '&ts=' + new Date().getTime();
  1496. }
  1497. catch (e)
  1498. {
  1499. // ignore
  1500. }
  1501. var showResult = mxUtils.bind(this, function()
  1502. {
  1503. this.spinner.stop();
  1504. var url = 'http://i.imgur.com/' + res.data.id + '.png';
  1505. var deleteUrl = 'https://www.draw.io/imgur?delete=' + res.data.deletehash;
  1506. var dlg = new ErrorDialog(this, mxResources.get('published'),
  1507. mxResources.get('publishedAt', ['<a href="' + url + '" target="_blank">' + url + '</a>']) +
  1508. '<br>' + mxResources.get('deleteUrl', [deleteUrl]),
  1509. mxResources.get('close'), mxUtils.bind(this, function()
  1510. {
  1511. this.hideDialog();
  1512. }), null, mxResources.get('share'), function()
  1513. {
  1514. socialHandler(res.data.id);
  1515. }, false);
  1516. this.showDialog(dlg.container, 340, 170, true, false);
  1517. dlg.init();
  1518. });
  1519. if (!editable)
  1520. {
  1521. showResult();
  1522. }
  1523. else
  1524. {
  1525. // Second request to update the description with the edit link
  1526. // Replacing the .png is workaround for Imgur to handle it as an image
  1527. // Avoiding URL parameter avoids call to getParameter in the servlet
  1528. var url2 = '/imgur?' + res.data.deletehash;
  1529. var req2 = new mxXmlRequest(url2, JSON.stringify({
  1530. title: title, description: 'Edit a copy of this diagram at https://www.draw.io/i/' + res.data.id}), 'POST');
  1531. req2.send(mxUtils.bind(this, function()
  1532. {
  1533. if (req2.getStatus() == 200)
  1534. {
  1535. showResult();
  1536. }
  1537. else
  1538. {
  1539. extractAndHandleError(req2);
  1540. }
  1541. }), mxUtils.bind(this, function()
  1542. {
  1543. extractAndHandleError(req2);
  1544. }));
  1545. }
  1546. }
  1547. catch (e)
  1548. {
  1549. this.handleError(e);
  1550. }
  1551. }
  1552. else
  1553. {
  1554. extractAndHandleError(req);
  1555. }
  1556. }), mxUtils.bind(this, function(req)
  1557. {
  1558. extractAndHandleError(req);
  1559. }));
  1560. }));
  1561. this.showDialog(dlg.container, 320, 250, true, false);
  1562. dlg.init();
  1563. };
  1564. /**
  1565. *
  1566. */
  1567. EditorUi.prototype.publishImage = function(handler, socialHandler)
  1568. {
  1569. var file = this.getCurrentFile();
  1570. if (file != null)
  1571. {
  1572. if (this.isExportToCanvas())
  1573. {
  1574. this.showExportDialog(false, mxResources.get('publish'), 'https://support.draw.io/pages/viewpage.action?pageId=12222625', mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  1575. {
  1576. var val = parseInt(scale);
  1577. if (!isNaN(val) && val > 0)
  1578. {
  1579. var scale = val / 100;
  1580. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  1581. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  1582. if (this.spinner.spin(document.body, mxResources.get('publishing')))
  1583. {
  1584. try
  1585. {
  1586. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1587. {
  1588. try
  1589. {
  1590. var xml = (editable) ? mxUtils.getXml(this.editor.getGraphXml(ignoreSelection)) : null;
  1591. var data = this.createPngDataUri(canvas, xml);
  1592. handler(file, data.substring(data.lastIndexOf(',') + 1), editable, socialHandler);
  1593. }
  1594. catch (e)
  1595. {
  1596. this.handleError(e);
  1597. }
  1598. }), null, null, null, mxUtils.bind(this, function(e)
  1599. {
  1600. this.handleError(e);
  1601. }), null, ignoreSelection, scale || 1, transparentBackground, addShadow);
  1602. }
  1603. catch (e)
  1604. {
  1605. this.handleError(e);
  1606. }
  1607. }
  1608. }
  1609. }));
  1610. }
  1611. else
  1612. {
  1613. this.showRemoteExportDialog(mxResources.get('publish'), 'https://support.draw.io/pages/viewpage.action?pageId=12222625', mxUtils.bind(this, function(ignoreSelection, editable)
  1614. {
  1615. if (this.spinner.spin(document.body, mxResources.get('publishing')))
  1616. {
  1617. var bounds = this.editor.graph.getGraphBounds();
  1618. var data = this.getFileData(true, null, null, null, ignoreSelection);
  1619. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  1620. {
  1621. var embed = (editable) ? '1' : '0';
  1622. try
  1623. {
  1624. var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
  1625. '&base64=1&embedXml=' + embed + '&xml=' +
  1626. encodeURIComponent(data));
  1627. req.send(mxUtils.bind(this, function()
  1628. {
  1629. if (req.getStatus() == 200)
  1630. {
  1631. handler(file, req.getText(), editable, socialHandler);
  1632. }
  1633. else
  1634. {
  1635. this.handleError(req);
  1636. }
  1637. }));
  1638. }
  1639. catch (e)
  1640. {
  1641. this.handleError(e);
  1642. }
  1643. }
  1644. else
  1645. {
  1646. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
  1647. }
  1648. }
  1649. }));
  1650. }
  1651. }
  1652. };
  1653. /**
  1654. * Translates this point by the given vector.
  1655. *
  1656. * @param {number} dx X-coordinate of the translation.
  1657. * @param {number} dy Y-coordinate of the translation.
  1658. */
  1659. EditorUi.prototype.timeSince = function(date)
  1660. {
  1661. var seconds = Math.floor((new Date() - date) / 1000);
  1662. var interval = Math.floor(seconds / 31536000);
  1663. if (interval > 1)
  1664. {
  1665. return interval + ' ' + mxResources.get('years');
  1666. }
  1667. interval = Math.floor(seconds / 2592000);
  1668. if (interval > 1)
  1669. {
  1670. return interval + ' ' + mxResources.get('months');
  1671. }
  1672. interval = Math.floor(seconds / 86400);
  1673. if (interval > 1)
  1674. {
  1675. return interval + ' ' + mxResources.get('days');
  1676. }
  1677. interval = Math.floor(seconds / 3600);
  1678. if (interval > 1)
  1679. {
  1680. return interval + ' ' + mxResources.get('hours');
  1681. }
  1682. interval = Math.floor(seconds / 60);
  1683. if (interval > 1)
  1684. {
  1685. return interval + ' ' + mxResources.get('minutes');
  1686. }
  1687. if (interval == 1)
  1688. {
  1689. return interval + ' ' + mxResources.get('minute');
  1690. }
  1691. return null;
  1692. };
  1693. /**
  1694. * Converts math in the given SVG
  1695. */
  1696. EditorUi.prototype.convertMath = function(graph, svgRoot, fixPosition, callback)
  1697. {
  1698. // FIXME: Only horizontal dash in output so better no conversion at all
  1699. if (false && graph.mathEnabled && typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  1700. {
  1701. // Workaround for lost gradients in Chrome after remove from DOM
  1702. var elts = svgRoot.getElementsByTagName('*');
  1703. for (var i = 0; i < elts.length; i++)
  1704. {
  1705. if (elts[i].getAttribute('id') != null)
  1706. {
  1707. elts[i].setAttribute('id', 'mxTemporaryPrefix-' + elts[i].getAttribute('id'));
  1708. }
  1709. }
  1710. // Temporarily attaches to DOM for rendering
  1711. svgRoot.style.visibility = 'hidden';
  1712. document.body.appendChild(svgRoot);
  1713. Editor.MathJaxRender(svgRoot);
  1714. MathJax.Hub.Queue(mxUtils.bind(this, function ()
  1715. {
  1716. // Removes from DOM
  1717. svgRoot.parentNode.removeChild(svgRoot);
  1718. svgRoot.style.visibility = '';
  1719. // Restores original IDs
  1720. for (var i = 0; i < elts.length; i++)
  1721. {
  1722. if (elts[i].getAttribute('id') != null)
  1723. {
  1724. elts[i].setAttribute('id', elts[i].getAttribute('id').substring('mxTemporaryPrefix-'.length));
  1725. }
  1726. }
  1727. // Keeping scale but moving translate only works for image export which
  1728. // is fine since we do not want the SVG export to contain a workaround.
  1729. // See https://github.com/mathjax/MathJax/issues/279
  1730. if (fixPosition && navigator.userAgent.indexOf('AppleWebKit/') >= 0)
  1731. {
  1732. var fo = svgRoot.getElementsByTagName('foreignObject');
  1733. for (var i = 0; i < fo.length; i++)
  1734. {
  1735. var tr = fo[i].parentNode.parentNode.getAttribute('transform');
  1736. var translate = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(tr);
  1737. fo[i].setAttribute('x', Math.round(translate[1]));
  1738. fo[i].setAttribute('y', Math.round(translate[2]));
  1739. // Must use translate for crisp rendering
  1740. fo[i].parentNode.parentNode.setAttribute('transform', 'translate(0.5,0.5)' + tr.substring(tr.indexOf(')') + 1));
  1741. }
  1742. }
  1743. callback();
  1744. }));
  1745. }
  1746. else
  1747. {
  1748. callback();
  1749. }
  1750. };
  1751. /**
  1752. * Returns the SVG of the diagram with embedded XML. If a callback function is
  1753. * used, the images are converted to data URIs.
  1754. */
  1755. EditorUi.prototype.getEmbeddedSvg = function(xml, graph, url, noHeader, callback, ignoreSelection, redirect)
  1756. {
  1757. var bg = null;
  1758. if (graph != null)
  1759. {
  1760. bg = graph.background;
  1761. if (bg == mxConstants.NONE)
  1762. {
  1763. bg = null;
  1764. }
  1765. }
  1766. // Sets or disables alternate text for foreignObjects. Disabling is needed
  1767. // because PhantomJS seems to ignore switch statements and paint all text.
  1768. var svgRoot = this.editor.graph.getSvg(bg, null, null, null, null, ignoreSelection);
  1769. svgRoot.setAttribute('content', encodeURIComponent(xml));
  1770. if (url != null)
  1771. {
  1772. svgRoot.setAttribute('resource', url);
  1773. }
  1774. // LATER: Click on SVG content to start editing
  1775. // if (redirect != null)
  1776. // {
  1777. // // TODO: Ignore anchor tag source for click event
  1778. // svgRoot.setAttribute('style', 'cursor:pointer;');
  1779. // svgRoot.setAttribute('onclick', 'window.location.href=\'' + redirect + '\';');
  1780. // }
  1781. if (callback != null)
  1782. {
  1783. this.convertImages(svgRoot, mxUtils.bind(this, function(svgRoot)
  1784. {
  1785. callback(((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  1786. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  1787. mxUtils.getXml(svgRoot));
  1788. }));
  1789. }
  1790. else
  1791. {
  1792. return ((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  1793. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  1794. mxUtils.getXml(svgRoot);
  1795. }
  1796. };
  1797. /**
  1798. *
  1799. */
  1800. EditorUi.prototype.exportToCanvas = function(callback, width, imageCache, background, error, limitHeight,
  1801. ignoreSelection, scale, transparentBackground, addShadow, converter)
  1802. {
  1803. limitHeight = (limitHeight != null) ? limitHeight : true;
  1804. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1805. var bg = (transparentBackground) ? null : this.editor.graph.background;
  1806. if (bg == mxConstants.NONE)
  1807. {
  1808. bg = null;
  1809. }
  1810. if (bg == null)
  1811. {
  1812. bg = background;
  1813. }
  1814. // Handles special case where background is null but transparent is false
  1815. if (bg == null && transparentBackground == false)
  1816. {
  1817. bg = '#ffffff';
  1818. }
  1819. this.convertImages(this.editor.graph.getSvg(bg, null, null, null, null, ignoreSelection), mxUtils.bind(this, function(svgRoot)
  1820. {
  1821. var img = new Image();
  1822. img.onload = mxUtils.bind(this, function()
  1823. {
  1824. var canvas = document.createElement('canvas');
  1825. var w = parseInt(svgRoot.getAttribute('width'));
  1826. var h = parseInt(svgRoot.getAttribute('height'));
  1827. scale = (scale != null) ? scale : 1;
  1828. if (width != null)
  1829. {
  1830. scale = (!limitHeight) ? width / w : Math.min(1, Math.min((width * 3) / (h * 4), width / w));
  1831. }
  1832. canvas.setAttribute('width', Math.ceil(scale * w));
  1833. canvas.setAttribute('height', Math.ceil(scale * h));
  1834. var ctx = canvas.getContext('2d');
  1835. ctx.scale(scale, scale);
  1836. ctx.drawImage(img, 0, 0);
  1837. callback(canvas);
  1838. });
  1839. img.onerror = function(e)
  1840. {
  1841. //console.log('img', e, img.src);
  1842. if (error != null)
  1843. {
  1844. error(e);
  1845. }
  1846. };
  1847. try
  1848. {
  1849. if (addShadow)
  1850. {
  1851. this.editor.addSvgShadow(svgRoot);
  1852. }
  1853. this.convertMath(this.editor.graph, svgRoot, true, mxUtils.bind(this, function()
  1854. {
  1855. img.src = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  1856. }));
  1857. }
  1858. catch (e)
  1859. {
  1860. //console.log('src', e, img.src);
  1861. if (error != null)
  1862. {
  1863. error(e);
  1864. }
  1865. }
  1866. }), imageCache, converter);
  1867. };
  1868. /**
  1869. * Converts all images in the SVG output to data URIs for immediate rendering
  1870. */
  1871. EditorUi.prototype.createImageUrlConverter = function()
  1872. {
  1873. var converter = new mxUrlConverter();
  1874. converter.updateBaseUrl();
  1875. // Extends convert to avoid CORS using an image proxy server
  1876. // LATER: Use img.crossOrigin="anonymous" to avoid proxy
  1877. var convert = converter.convert;
  1878. converter.convert = function(src)
  1879. {
  1880. if (src != null)
  1881. {
  1882. if ((src.substring(0, 7) == 'http://' || src.substring(0, 8) == 'https://') &&
  1883. src.substring(0, converter.baseUrl.length) != converter.baseUrl)
  1884. {
  1885. src = PROXY_URL + '?url=' + encodeURIComponent(src);
  1886. }
  1887. else if (src.substring(0, 19) != 'chrome-extension://')
  1888. {
  1889. src = convert.apply(this, arguments);
  1890. }
  1891. }
  1892. return src;
  1893. };
  1894. return converter;
  1895. };
  1896. /**
  1897. * Converts all images in the SVG output to data URIs for immediate rendering
  1898. */
  1899. EditorUi.prototype.convertImages = function(svgRoot, callback, imageCache, converter)
  1900. {
  1901. // Converts images to data URLs for immediate painting
  1902. if (converter == null)
  1903. {
  1904. converter = this.createImageUrlConverter();
  1905. }
  1906. // Barrier for asynchronous image loading
  1907. var counter = 0;
  1908. function inc()
  1909. {
  1910. counter++;
  1911. };
  1912. function dec()
  1913. {
  1914. counter--;
  1915. if (counter == 0)
  1916. {
  1917. callback(svgRoot);
  1918. }
  1919. };
  1920. var cache = imageCache || new Object();
  1921. var convertImages = mxUtils.bind(this, function(tagName, srcAttr)
  1922. {
  1923. var images = svgRoot.getElementsByTagName(tagName);
  1924. for (var i = 0; i < images.length; i++)
  1925. {
  1926. (mxUtils.bind(this, function(img)
  1927. {
  1928. var src = converter.convert(img.getAttribute(srcAttr));
  1929. // Data URIs are pass-through
  1930. if (src != null && src.substring(0, 5) != 'data:')
  1931. {
  1932. var tmp = cache[src];
  1933. if (tmp == null)
  1934. {
  1935. inc();
  1936. this.convertImageToDataUri(src, function(uri)
  1937. {
  1938. if (uri != null)
  1939. {
  1940. cache[src] = uri;
  1941. img.setAttribute(srcAttr, uri);
  1942. }
  1943. dec();
  1944. });
  1945. }
  1946. else
  1947. {
  1948. img.setAttribute(srcAttr, tmp);
  1949. }
  1950. }
  1951. }))(images[i]);
  1952. }
  1953. });
  1954. // Converts all known image tags in output
  1955. // LATER: Add support for images in CSS
  1956. convertImages('image', 'xlink:href');
  1957. convertImages('img', 'src');
  1958. // All from cache or no images
  1959. if (counter == 0)
  1960. {
  1961. callback(svgRoot);
  1962. }
  1963. };
  1964. /**
  1965. * Translates this point by the given vector.
  1966. *
  1967. * @param {number} dx X-coordinate of the translation.
  1968. * @param {number} dy Y-coordinate of the translation.
  1969. */
  1970. EditorUi.prototype.convertImageToDataUri = function(url, callback)
  1971. {
  1972. if (/(\.svg)$/i.test(url))
  1973. {
  1974. mxUtils.get(url, mxUtils.bind(this, function(req)
  1975. {
  1976. callback(this.createSvgDataUri(req.getText()));
  1977. }),
  1978. function()
  1979. {
  1980. callback();
  1981. });
  1982. }
  1983. else
  1984. {
  1985. var img = new Image();
  1986. img.onload = function()
  1987. {
  1988. var canvas = document.createElement('canvas');
  1989. var ctx = canvas.getContext('2d');
  1990. canvas.height = img.height;
  1991. canvas.width = img.width;
  1992. ctx.drawImage(img, 0, 0);
  1993. callback(canvas.toDataURL());
  1994. };
  1995. img.onerror = function()
  1996. {
  1997. callback();
  1998. };
  1999. img.src = url;
  2000. }
  2001. };
  2002. /**
  2003. * Handling drag and drop and import.
  2004. */
  2005. /**
  2006. * Imports the given XML into the existing diagram.
  2007. */
  2008. EditorUi.prototype.importXml = function(xml, dx, dy, crop, noErrorHandling)
  2009. {
  2010. dx = (dx != null) ? dx : 0;
  2011. dy = (dy != null) ? dy : 0;
  2012. var cells = []
  2013. try
  2014. {
  2015. if (xml != null && xml.length > 0)
  2016. {
  2017. var doc = mxUtils.parseXml(xml);
  2018. var node = this.editor.extractGraphModel(doc.documentElement);
  2019. if (node != null)
  2020. {
  2021. var model = new mxGraphModel();
  2022. var codec = new mxCodec(node.ownerDocument);
  2023. codec.decode(node, model);
  2024. var graph = this.editor.graph;
  2025. var childCount = model.getChildCount(model.getRoot());
  2026. var targetChildCount = graph.model.getChildCount(graph.model.getRoot());
  2027. // Merges into active layer if one layer is pasted
  2028. graph.model.beginUpdate();
  2029. try
  2030. {
  2031. // Mapping for multiple calls to cloneCells with the same set of cells
  2032. var mapping = new Object();
  2033. for (var i = 0; i < childCount; i++)
  2034. {
  2035. var parent = model.getChildAt(model.getRoot(), i);
  2036. // Adds cells to existing layer if not locked
  2037. if (childCount == 1 && !graph.isCellLocked(graph.getDefaultParent()))
  2038. {
  2039. var children = model.getChildren(parent);
  2040. cells = cells.concat(graph.importCells(children, dx, dy, graph.getDefaultParent(), null, mapping));
  2041. }
  2042. else
  2043. {
  2044. // Delta is non cascading, needs separate move for layers
  2045. parent = graph.importCells([parent], 0, 0, graph.model.getRoot(), null, mapping)[0];
  2046. var children = graph.model.getChildren(parent);
  2047. graph.moveCells(children, dx, dy);
  2048. cells = cells.concat(children);
  2049. }
  2050. }
  2051. if (crop)
  2052. {
  2053. if (graph.isGridEnabled())
  2054. {
  2055. dx = graph.snap(dx);
  2056. dy = graph.snap(dy);
  2057. }
  2058. var bounds = graph.getBoundingBoxFromGeometry(cells, true);
  2059. if (bounds != null)
  2060. {
  2061. graph.moveCells(cells, dx - bounds.x, dy - bounds.y);
  2062. }
  2063. }
  2064. }
  2065. finally
  2066. {
  2067. graph.model.endUpdate();
  2068. }
  2069. }
  2070. }
  2071. }
  2072. catch (e)
  2073. {
  2074. if (!noErrorHandling)
  2075. {
  2076. this.handleError(e, mxResources.get('invalidOrMissingFile'));
  2077. }
  2078. throw e;
  2079. }
  2080. return cells;
  2081. };
  2082. /**
  2083. * Imports the given XML into the existing diagram.
  2084. * TODO: Make this function asynchronous
  2085. */
  2086. EditorUi.prototype.insertTextAt = function(text, dx, dy, html, asImage, crop)
  2087. {
  2088. crop = (crop != null) ? crop : true;
  2089. // Handles special case for Gliffy data which requires async server-side for parsing
  2090. if (text != null)
  2091. {
  2092. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(text))
  2093. {
  2094. // Fixes possible parsing problems with ASCII 160 (non-breaking space)
  2095. this.parseFile(new Blob([text.replace(/\s+/g,' ')], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2096. {
  2097. if (xhr.readyState == 4 && xhr.status == 200)
  2098. {
  2099. this.editor.graph.setSelectionCells(this.insertTextAt(xhr.responseText, dx, dy, true));
  2100. }
  2101. }));
  2102. // Returns empty cells array as it is aysynchronous
  2103. return [];
  2104. }
  2105. // Handles special case of data URI which requires async loading for finding size
  2106. else if (!this.isOffline() && (asImage || text.substring(0, 5) == 'data:' || (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(text)))
  2107. {
  2108. var graph = this.editor.graph;
  2109. // Checks for embedded XML in PNG
  2110. if (text.substring(0, 22) == 'data:image/png;base64,')
  2111. {
  2112. var xml = this.extractGraphModelFromPng(text);
  2113. var result = this.importXml(xml, dx, dy, crop, true);
  2114. if (result.length > 0)
  2115. {
  2116. return result;
  2117. }
  2118. }
  2119. // Tries to extract embedded XML from SVG data URI
  2120. if (text.substring(0, 19) == 'data:image/svg+xml;')
  2121. {
  2122. try
  2123. {
  2124. var xml = null;
  2125. if (text.substring(0, 26) == 'data:image/svg+xml;base64,')
  2126. {
  2127. xml = text.substring(text.indexOf(',') + 1);
  2128. xml = (window.atob && !mxClient.IS_SF) ? atob(xml) : Base64.decode(xml, true);
  2129. }
  2130. else
  2131. {
  2132. xml = decodeURIComponent(text.substring(text.indexOf(',') + 1));
  2133. }
  2134. var result = this.importXml(xml, dx, dy, crop, true);
  2135. if (result.length > 0)
  2136. {
  2137. return result;
  2138. }
  2139. }
  2140. catch (e)
  2141. {
  2142. // Ignore
  2143. }
  2144. }
  2145. this.loadImage(text, mxUtils.bind(this, function(img)
  2146. {
  2147. if (text.substring(0, 5) == 'data:')
  2148. {
  2149. this.resizeImage(img, text, mxUtils.bind(this, function(data2, w2, h2)
  2150. {
  2151. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  2152. w2, h2, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2153. 'verticalAlign=top;aspect=fixed;image=' + this.convertDataUri(data2) + ';'));
  2154. }), true, this.maxImageSize);
  2155. }
  2156. else
  2157. {
  2158. var s = Math.min(1, Math.min(this.maxImageSize / img.width, this.maxImageSize / img.height));
  2159. var w = Math.round(img.width * s);
  2160. var h = Math.round(img.height * s);
  2161. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  2162. w, h, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2163. 'verticalAlign=top;aspect=fixed;image=' + text + ';'));
  2164. }
  2165. }), mxUtils.bind(this, function()
  2166. {
  2167. var cell = null;
  2168. // Inserts invalid data URIs as text
  2169. graph.getModel().beginUpdate();
  2170. try
  2171. {
  2172. cell = graph.insertVertex(graph.getDefaultParent(), null, text,
  2173. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  2174. graph.updateCellSize(cell);
  2175. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  2176. }
  2177. finally
  2178. {
  2179. graph.getModel().endUpdate();
  2180. }
  2181. graph.setSelectionCell(cell);
  2182. }));
  2183. return [];
  2184. }
  2185. else
  2186. {
  2187. text = this.editor.graph.zapGremlins(mxUtils.trim(text));
  2188. if (this.isCompatibleString(text))
  2189. {
  2190. return this.importXml(text, dx, dy, crop);
  2191. }
  2192. else if (text.length > 0)
  2193. {
  2194. var graph = this.editor.graph;
  2195. var cell = null;
  2196. graph.getModel().beginUpdate();
  2197. try
  2198. {
  2199. // Fires cellsInserted to apply the current style to the inserted text.
  2200. // This requires the value to be empty when the event is fired.
  2201. cell = graph.insertVertex(graph.getDefaultParent(), null, '',
  2202. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  2203. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  2204. // Apply value and updates the cell size to fit the text block
  2205. cell.value = text;
  2206. graph.updateCellSize(cell);
  2207. // See http://stackoverflow.com/questions/6927719/url-regex-does-not-work-in-javascript
  2208. var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
  2209. if (regexp.test(cell.value))
  2210. {
  2211. graph.setLinkForCell(cell, cell.value);
  2212. }
  2213. // Adds spacing
  2214. cell.geometry.width += graph.gridSize;
  2215. cell.geometry.height += graph.gridSize;
  2216. }
  2217. finally
  2218. {
  2219. graph.getModel().endUpdate();
  2220. }
  2221. return [cell];
  2222. }
  2223. }
  2224. }
  2225. return [];
  2226. };
  2227. /**
  2228. * Formats the given file size.
  2229. */
  2230. EditorUi.prototype.formatFileSize = function(size)
  2231. {
  2232. var units = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
  2233. var i = -1;
  2234. do
  2235. {
  2236. size = size / 1024;
  2237. i++;
  2238. } while (size > 1024);
  2239. return Math.max(size, 0.1).toFixed(1) + units[i];
  2240. };
  2241. /**
  2242. * Imports the given XML into the existing diagram.
  2243. */
  2244. EditorUi.prototype.convertDataUri = function(uri)
  2245. {
  2246. // Handles special case of data URI which needs to be rewritten
  2247. // to be used in a cell style to remove the semicolon
  2248. if (uri.substring(0, 5) == 'data:')
  2249. {
  2250. var semi = uri.indexOf(';');
  2251. if (semi > 0)
  2252. {
  2253. uri = uri.substring(0, semi) + uri.substring(uri.indexOf(',', semi + 1));
  2254. }
  2255. }
  2256. return uri;
  2257. };
  2258. /**
  2259. * Returns true for Gliffy or GraphML data or .vsdx filenames.
  2260. */
  2261. EditorUi.prototype.isRemoteFileFormat = function(data, filename)
  2262. {
  2263. return /(\.*<graphml xmlns=\".*)/.test(data) ||
  2264. /(\"contentType\":\s*\"application\/gliffy\+json\")/.test(data) ||
  2265. (filename != null && /(\.vsdx)($|\?)/i.test(filename));
  2266. };
  2267. /**
  2268. * Imports the given XML into the existing diagram.
  2269. */
  2270. EditorUi.prototype.importFile = function(data, mimeType, dx, dy, w, h, filename, done, file, crop)
  2271. {
  2272. crop = (crop != null) ? crop : true;
  2273. var async = false;
  2274. var cells = null;
  2275. if (mimeType.substring(0, 5) == 'image')
  2276. {
  2277. var containsModel = false;
  2278. if (mimeType.substring(0, 9) == 'image/png')
  2279. {
  2280. var xml = this.extractGraphModelFromPng(data);
  2281. if (xml != null && xml.length > 0)
  2282. {
  2283. cells = this.importXml(xml, dx, dy, crop);
  2284. containsModel = true;
  2285. }
  2286. }
  2287. if (!containsModel)
  2288. {
  2289. var graph = this.editor.graph;
  2290. // Strips encoding bit (eg. ;base64,) for cell style
  2291. var semi = data.indexOf(';');
  2292. if (semi > 0)
  2293. {
  2294. data = data.substring(0, semi) + data.substring(data.indexOf(',', semi + 1));
  2295. }
  2296. if (crop && graph.isGridEnabled())
  2297. {
  2298. dx = graph.snap(dx);
  2299. dy = graph.snap(dy);
  2300. }
  2301. cells = [graph.insertVertex(null, null, '', dx, dy, w, h,
  2302. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2303. 'verticalAlign=top;aspect=fixed;image=' + data + ';')];
  2304. }
  2305. }
  2306. else if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, filename))
  2307. {
  2308. // LATER: done and async are a hack before making this asynchronous
  2309. async = true;
  2310. // Returns empty cells array as it is aysynchronous
  2311. this.parseFile((file != null) ? file : new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2312. {
  2313. if (xhr.readyState == 4)
  2314. {
  2315. var importedCells = null;
  2316. if (xhr.status == 200)
  2317. {
  2318. importedCells = this.importXml(xhr.responseText, dx, dy, crop);
  2319. }
  2320. if (done != null)
  2321. {
  2322. done(importedCells);
  2323. }
  2324. }
  2325. }), filename);
  2326. }
  2327. else
  2328. {
  2329. if (/(\.vsdx)($|\?)/i.test(filename))
  2330. {
  2331. var vsdxModel = new mxVsdxModel();
  2332. vsdxModel.decode(file);
  2333. }
  2334. else
  2335. {
  2336. cells = this.insertTextAt(this.validateFileData(data), dx, dy, true);
  2337. }
  2338. // else if (String.prototype.trim)
  2339. // {
  2340. // var trimmed = data.trim();
  2341. //
  2342. // if (trimmed.substring(0, 6) == 'strict ' || trimmed.substring(0, 5) == 'graph' || trimmed.substring(0, 7) == 'digraph')
  2343. // {
  2344. // // GraphViz dot format http://www.graphviz.org/content/dot-language
  2345. // //var digraph = graphlibDot.read("digraph { 1; 2; 1 -> 2 [label=\"label\"] }");
  2346. // }
  2347. // }
  2348. }
  2349. if (!async && done != null)
  2350. {
  2351. done(cells);
  2352. }
  2353. return cells;
  2354. };
  2355. /**
  2356. * Base64 encodes the given string. This method seems to be more
  2357. * robust for encoding PNG from binary AJAX responses.
  2358. */
  2359. EditorUi.prototype.base64Encode = function(str)
  2360. {
  2361. var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2362. var out = "", i = 0, len = str.length, c1, c2, c3;
  2363. while (i < len)
  2364. {
  2365. c1 = str.charCodeAt(i++) & 0xff;
  2366. if (i == len)
  2367. {
  2368. out += CHARS.charAt(c1 >> 2);
  2369. out += CHARS.charAt((c1 & 0x3) << 4);
  2370. out += "==";
  2371. break;
  2372. }
  2373. c2 = str.charCodeAt(i++);
  2374. if (i == len)
  2375. {
  2376. out += CHARS.charAt(c1 >> 2);
  2377. out += CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  2378. out += CHARS.charAt((c2 & 0xF) << 2);
  2379. out += "=";
  2380. break;
  2381. }
  2382. c3 = str.charCodeAt(i++);
  2383. out += CHARS.charAt(c1 >> 2);
  2384. out += CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  2385. out += CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  2386. out += CHARS.charAt(c3 & 0x3F);
  2387. }
  2388. return out;
  2389. };
  2390. /**
  2391. *
  2392. */
  2393. EditorUi.prototype.importFiles = function(files, x, y, maxSize, fn, resultFn, filterFn, barrierFn, resizeImages, maxBytes, resampleThreshold)
  2394. {
  2395. var crop = x != null && y != null;
  2396. x = (x != null) ? x : 0;
  2397. y = (y != null) ? y : 0;
  2398. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  2399. maxBytes = (maxBytes != null) ? maxBytes : this.maxImageBytes;
  2400. resizeImages = (resizeImages != null) ? resizeImages : true;
  2401. var graph = this.editor.graph;
  2402. var gs = graph.gridSize;
  2403. fn = (fn != null) ? fn : mxUtils.bind(this, function(data, mimeType, x, y, w, h, filename, done, file)
  2404. {
  2405. if (data != null && data.substring(0, 10) == '<mxlibrary')
  2406. {
  2407. this.spinner.stop();
  2408. this.loadLibrary(new LocalLibrary(this, data, filename));
  2409. return null;
  2410. }
  2411. else
  2412. {
  2413. return this.importFile(data, mimeType, x, y, w, h, filename, done, file, crop);
  2414. }
  2415. });
  2416. resultFn = (resultFn != null) ? resultFn : mxUtils.bind(this, function(cells)
  2417. {
  2418. graph.setSelectionCells(cells);
  2419. });
  2420. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2421. {
  2422. var count = files.length;
  2423. var remain = count;
  2424. var queue = [];
  2425. // Barrier waits for all files to be loaded asynchronously
  2426. var barrier = mxUtils.bind(this, function(index, fnc)
  2427. {
  2428. queue[index] = fnc;
  2429. if (--remain == 0)
  2430. {
  2431. this.spinner.stop();
  2432. if (barrierFn != null)
  2433. {
  2434. barrierFn(queue);
  2435. }
  2436. else
  2437. {
  2438. var cells = [];
  2439. graph.getModel().beginUpdate();
  2440. try
  2441. {
  2442. for (var j = 0; j < queue.length; j++)
  2443. {
  2444. var tmp = queue[j]();
  2445. if (tmp != null)
  2446. {
  2447. cells = cells.concat(tmp);
  2448. }
  2449. }
  2450. }
  2451. finally
  2452. {
  2453. graph.getModel().endUpdate();
  2454. }
  2455. }
  2456. resultFn(cells);
  2457. }
  2458. });
  2459. for (var i = 0; i < count; i++)
  2460. {
  2461. (mxUtils.bind(this, function(index)
  2462. {
  2463. var file = files[index];
  2464. var reader = new FileReader();
  2465. reader.onload = mxUtils.bind(this, function(e)
  2466. {
  2467. if (filterFn == null || filterFn(file))
  2468. {
  2469. if (file.type.substring(0, 6) == 'image/')
  2470. {
  2471. if (file.type.substring(0, 9) == 'image/svg')
  2472. {
  2473. // Checks if SVG contains content attribute
  2474. var data = e.target.result;
  2475. var comma = data.indexOf(',');
  2476. var svgText = atob(data.substring(comma + 1));
  2477. var root = mxUtils.parseXml(svgText);
  2478. var svgs = root.getElementsByTagName('svg');
  2479. if (svgs.length > 0)
  2480. {
  2481. var svgRoot = svgs[0];
  2482. var cont = svgRoot.getAttribute('content');
  2483. if (cont != null && cont.charAt(0) != '<' && cont.charAt(0) != '%')
  2484. {
  2485. cont = unescape((window.atob) ? atob(cont) : Base64.decode(cont, true));
  2486. }
  2487. if (cont != null && cont.charAt(0) == '%')
  2488. {
  2489. cont = decodeURIComponent(cont);
  2490. }
  2491. if (cont != null && (cont.substring(0, 8) === '<mxfile ' ||
  2492. cont.substring(0, 14) === '<mxGraphModel '))
  2493. {
  2494. barrier(index, mxUtils.bind(this, function()
  2495. {
  2496. return fn(cont, 'text/xml', x + index * gs, y + index * gs, 0, 0, file.name);
  2497. }));
  2498. }
  2499. else
  2500. {
  2501. // SVG needs special handling to add viewbox if missing and
  2502. // find initial size from SVG attributes (only for IE11)
  2503. barrier(index, mxUtils.bind(this, function()
  2504. {
  2505. try
  2506. {
  2507. var prefix = data.substring(0, comma + 1);
  2508. // Parses SVG and find width and height
  2509. if (root != null)
  2510. {
  2511. var svgs = root.getElementsByTagName('svg');
  2512. if (svgs.length > 0)
  2513. {
  2514. var svgRoot = svgs[0];
  2515. var w = parseFloat(svgRoot.getAttribute('width'));
  2516. var h = parseFloat(svgRoot.getAttribute('height'));
  2517. // Check if viewBox attribute already exists
  2518. var vb = svgRoot.getAttribute('viewBox');
  2519. if (vb == null || vb.length == 0)
  2520. {
  2521. svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  2522. }
  2523. // Uses width and height from viewbox for
  2524. // missing width and height attributes
  2525. else if (isNaN(w) || isNaN(h))
  2526. {
  2527. var tokens = vb.split(' ');
  2528. if (tokens.length > 3)
  2529. {
  2530. w = parseFloat(tokens[2]);
  2531. h = parseFloat(tokens[3]);
  2532. }
  2533. }
  2534. data = this.createSvgDataUri(mxUtils.getXml(svgs[0]));
  2535. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  2536. return fn(data, file.type, x + index * gs, y + index * gs,
  2537. Math.max(1, Math.round(w * s)), Math.max(1, Math.round(h * s)), file.name);
  2538. }
  2539. }
  2540. }
  2541. catch (e)
  2542. {
  2543. // ignores any SVG parsing errors
  2544. }
  2545. return null;
  2546. }));
  2547. }
  2548. }
  2549. }
  2550. else
  2551. {
  2552. // Checks if PNG+XML is available to bypass code below
  2553. var containsModel = false;
  2554. if (file.type == 'image/png')
  2555. {
  2556. var xml = this.extractGraphModelFromPng(e.target.result);
  2557. if (xml != null && xml.length > 0)
  2558. {
  2559. var img = new Image();
  2560. img.src = e.target.result;
  2561. barrier(index, mxUtils.bind(this, function()
  2562. {
  2563. return fn(xml, 'text/xml', x + index * gs, y + index * gs,
  2564. img.width, img.height, file.name);
  2565. }));
  2566. containsModel = true;
  2567. }
  2568. }
  2569. // Additional asynchronous step for finding image size
  2570. if (!containsModel)
  2571. {
  2572. // Cannot load local files in Chrome App
  2573. if (window.chrome != null && chrome.app != null && chrome.app.runtime != null)
  2574. {
  2575. this.spinner.stop();
  2576. this.showError(mxResources.get('error'), mxResources.get('dragAndDropNotSupported'),
  2577. mxResources.get('cancel'), mxUtils.bind(this, function()
  2578. {
  2579. // Hides the dialog
  2580. }), null, mxResources.get('ok'), mxUtils.bind(this, function()
  2581. {
  2582. // Redirects to import function
  2583. this.actions.get('import').funct();
  2584. })
  2585. );
  2586. }
  2587. else
  2588. {
  2589. this.loadImage(e.target.result, mxUtils.bind(this, function(img)
  2590. {
  2591. this.resizeImage(img, e.target.result, mxUtils.bind(this, function(data2, w2, h2)
  2592. {
  2593. barrier(index, mxUtils.bind(this, function()
  2594. {
  2595. // Refuses to insert images above a certain size as they kill the app
  2596. if (data2 != null && data2.length < maxBytes)
  2597. {
  2598. var s = (!resizeImages || !this.isResampleImage(e.target.result)) ? 1 : Math.min(1, Math.min(maxSize / w2, maxSize / h2));
  2599. return fn(data2, file.type, x + index * gs, y + index * gs, Math.round(w2 * s), Math.round(h2 * s), file.name);
  2600. }
  2601. else
  2602. {
  2603. this.handleError({message: mxResources.get('imageTooBig')});
  2604. return null;
  2605. }
  2606. }));
  2607. }), resizeImages, maxSize, resampleThreshold);
  2608. }));
  2609. }
  2610. }
  2611. }
  2612. }
  2613. else
  2614. {
  2615. fn(e.target.result, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  2616. {
  2617. barrier(index, function()
  2618. {
  2619. return cells;
  2620. });
  2621. });
  2622. }
  2623. }
  2624. });
  2625. // Handles special case of binary file where the reader should not be used
  2626. if (/(\.vsdx)($|\?)/i.test(file.name))
  2627. {
  2628. fn(null, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  2629. {
  2630. barrier(index, function()
  2631. {
  2632. return cells;
  2633. });
  2634. }, file);
  2635. }
  2636. else if (file.type.substring(0, 5) == 'image')
  2637. {
  2638. reader.readAsDataURL(file);
  2639. }
  2640. else
  2641. {
  2642. reader.readAsText(file);
  2643. }
  2644. }))(i);
  2645. }
  2646. }
  2647. };
  2648. /**
  2649. * Parses the file using XHR2 via the server. File can be a blob or file object.
  2650. * Filename is an optional parameter for blobs (that do not have a filename).
  2651. */
  2652. EditorUi.prototype.parseFile = function(file, fn, filename)
  2653. {
  2654. filename = (filename != null) ? filename : file.name;
  2655. var formData = new FormData();
  2656. formData.append('format', 'xml');
  2657. formData.append('upfile', file, filename);
  2658. var xhr = new XMLHttpRequest();
  2659. xhr.open('POST', OPEN_URL);
  2660. xhr.onreadystatechange = function()
  2661. {
  2662. fn(xhr);
  2663. };
  2664. xhr.send(formData);
  2665. };
  2666. /**
  2667. *
  2668. */
  2669. EditorUi.prototype.isResampleImage = function(data, thresh)
  2670. {
  2671. thresh = (thresh != null) ? thresh : this.resampleThreshold;
  2672. return data.length > thresh;
  2673. };
  2674. /**
  2675. * Resizes the given image if <maxImageBytes> is not null.
  2676. */
  2677. EditorUi.prototype.resizeImage = function(img, data, fn, enabled, maxSize, thresh)
  2678. {
  2679. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  2680. var w = Math.max(1, img.width);
  2681. var h = Math.max(1, img.height);
  2682. if (enabled && this.isResampleImage(data, thresh))
  2683. {
  2684. try
  2685. {
  2686. var factor = Math.max(w / maxSize, h / maxSize);
  2687. if (factor > 1)
  2688. {
  2689. var w2 = Math.round(w / factor);
  2690. var h2 = Math.round(h / factor);
  2691. var canvas = document.createElement('canvas');
  2692. canvas.width = w2;
  2693. canvas.height = h2;
  2694. var ctx = canvas.getContext('2d');
  2695. ctx.drawImage(img, 0, 0, w2, h2);
  2696. var tmp = canvas.toDataURL();
  2697. // Uses new image if smaller
  2698. if (tmp.length < data.length)
  2699. {
  2700. // Checks if the image is empty by comparing
  2701. // with an empty image of the same size
  2702. var canvas2 = document.createElement('canvas');
  2703. canvas2.width = w2;
  2704. canvas2.height = h2;
  2705. var tmp2 = canvas2.toDataURL();
  2706. if (tmp !== tmp2)
  2707. {
  2708. data = tmp;
  2709. w = w2;
  2710. h = h2;
  2711. }
  2712. }
  2713. }
  2714. }
  2715. catch (e)
  2716. {
  2717. // ignores image scaling errors
  2718. }
  2719. }
  2720. fn(data, w, h);
  2721. };
  2722. /**
  2723. * Initializes CRC table.
  2724. */
  2725. (function()
  2726. {
  2727. EditorUi.prototype.crcTable = [];
  2728. for (var n = 0; n < 256; n++)
  2729. {
  2730. var c = n;
  2731. for (var k = 0; k < 8; k++)
  2732. {
  2733. if ((c & 1) == 1)
  2734. {
  2735. c = 0xedb88320 ^ (c >>> 1);
  2736. }
  2737. else
  2738. {
  2739. c >>>= 1;
  2740. }
  2741. EditorUi.prototype.crcTable[n] = c;
  2742. }
  2743. }
  2744. EditorUi.prototype.updateCRC = function(crc, data, off, len)
  2745. {
  2746. var c = crc;
  2747. for (var n = 0; n < len; n++)
  2748. {
  2749. c = EditorUi.prototype.crcTable[(c ^ data[off + n]) & 0xff] ^ (c >>> 8);
  2750. }
  2751. return c;
  2752. };
  2753. })();
  2754. /**
  2755. * Adds the given text to the compressed or non-compressed text chunk.
  2756. */
  2757. EditorUi.prototype.writeGraphModelToPng = function(data, type, key, value, error)
  2758. {
  2759. var base64 = data.substring(data.indexOf(',') + 1);
  2760. var f = (window.atob) ? atob(base64) : Base64.decode(base64, true);
  2761. var pos = 0;
  2762. function fread(d, count)
  2763. {
  2764. var start = pos;
  2765. pos += count;
  2766. return d.substring(start, pos);
  2767. };
  2768. // Reads unsigned long 32 bit big endian
  2769. function _freadint(d)
  2770. {
  2771. var bytes = fread(d, 4);
  2772. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  2773. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  2774. };
  2775. function writeInt(num)
  2776. {
  2777. return String.fromCharCode((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff,
  2778. (num >> 8) & 0x000000ff, num & 0x000000ff);
  2779. };
  2780. // Checks signature
  2781. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  2782. {
  2783. if (error != null)
  2784. {
  2785. error();
  2786. }
  2787. return;
  2788. }
  2789. // Reads header chunk
  2790. fread(f,4);
  2791. if (fread(f,4) != 'IHDR')
  2792. {
  2793. if (error != null)
  2794. {
  2795. error();
  2796. }
  2797. return;
  2798. }
  2799. fread(f, 17);
  2800. var result = f.substring(0, pos);
  2801. do
  2802. {
  2803. var n = _freadint(f);
  2804. var chunk = fread(f,4);
  2805. if (chunk == 'IDAT')
  2806. {
  2807. result = f.substring(0, pos - 8);
  2808. var crc = 0xffffffff;
  2809. crc = this.updateCRC(crc, type, 0, 4);
  2810. crc = this.updateCRC(crc, value, 0, value.length);
  2811. result += writeInt(key.length + value.length + 1 + ((type == 'zTXt') ? 1 : 0)) +
  2812. type + key + String.fromCharCode(0) +
  2813. ((type == 'zTXt') ? String.fromCharCode(0) : '') +
  2814. value + writeInt(crc ^ 0xffffffff);
  2815. result += f.substring(pos - 8, f.length);
  2816. break;
  2817. }
  2818. result += f.substring(pos - 8, pos - 4 + n);
  2819. value = fread(f,n);
  2820. fread(f,4);
  2821. }
  2822. while (n);
  2823. return 'data:image/png;base64,' + ((window.btoa) ? btoa(result) : Base64.encode(result, true));
  2824. }
  2825. /**
  2826. * Extracts the XML from the compressed or non-compressed text chunk.
  2827. */
  2828. EditorUi.prototype.extractGraphModelFromPng = function(data)
  2829. {
  2830. var result = null;
  2831. try
  2832. {
  2833. var base64 = data.substring(data.indexOf(',') + 1);
  2834. // Workaround for invalid character error in Safari
  2835. var binary = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  2836. EditorUi.parsePng(binary, mxUtils.bind(this, function(pos, type, length)
  2837. {
  2838. var value = binary.substring(pos + 8, pos + 8 + length);
  2839. if (type == 'zTXt')
  2840. {
  2841. var idx = value.indexOf(String.fromCharCode(0));
  2842. if (value.substring(0, idx) == 'mxGraphModel')
  2843. {
  2844. // Workaround for Java URL Encoder using + for spaces, which isn't compatible with JS
  2845. var xmlData = this.editor.graph.bytesToString(pako.inflateRaw(
  2846. value.substring(idx + 2))).replace(/\+/g,' ');
  2847. if (xmlData != null && xmlData.length > 0)
  2848. {
  2849. result = xmlData;
  2850. }
  2851. }
  2852. }
  2853. // Uncompressed section is normally not used
  2854. else if (type == 'tEXt')
  2855. {
  2856. var vals = value.split(String.fromCharCode(0));
  2857. if (vals.length > 1 && vals[0] == 'mxGraphModel')
  2858. {
  2859. result = vals[1];
  2860. }
  2861. }
  2862. if (result != null || type == 'IDAT')
  2863. {
  2864. // Stops processing the file as our text chunks
  2865. // are always placed before the data section
  2866. return true;
  2867. }
  2868. }));
  2869. }
  2870. catch (e)
  2871. {
  2872. // ignores decoding errors
  2873. }
  2874. if (result != null && result.charAt(0) == '%')
  2875. {
  2876. result = decodeURIComponent(result);
  2877. }
  2878. // Workaround for double encoded content
  2879. if (result != null && result.charAt(0) == '%')
  2880. {
  2881. result = decodeURIComponent(result);
  2882. }
  2883. return result;
  2884. };
  2885. /**
  2886. * Loads the image from the given URI.
  2887. *
  2888. * @param {number} dx X-coordinate of the translation.
  2889. * @param {number} dy Y-coordinate of the translation.
  2890. */
  2891. EditorUi.prototype.loadImage = function(uri, onload, onerror)
  2892. {
  2893. var img = new Image();
  2894. img.onload = function()
  2895. {
  2896. onload(img);
  2897. }
  2898. if (onerror != null)
  2899. {
  2900. img.onerror = onerror;
  2901. }
  2902. img.src = uri;
  2903. };
  2904. // Initializes the user interface
  2905. var editorUiInit = EditorUi.prototype.init;
  2906. EditorUi.prototype.init = function()
  2907. {
  2908. editorUiInit.apply(this, arguments);
  2909. var graph = this.editor.graph;
  2910. var ui = this;
  2911. if (mxClient.IS_SVG)
  2912. {
  2913. // LATER: Add shadow for labels in graph.container (eg. math, NO_FO), scaling
  2914. this.editor.addSvgShadow(graph.view.canvas.ownerSVGElement, null, true);
  2915. }
  2916. /**
  2917. * Specifies the default filename.
  2918. */
  2919. this.defaultFilename = mxResources.get('untitledDiagram');
  2920. /**
  2921. * Adds placeholder for %page% and %pagenumber%
  2922. */
  2923. var graphGetGlobalVariable = graph.getGlobalVariable;
  2924. graph.getGlobalVariable = function(name)
  2925. {
  2926. if (name == 'page' && ui.currentPage != null)
  2927. {
  2928. return ui.currentPage.getName();
  2929. }
  2930. else if (name == 'pagenumber' && ui.currentPage != null && ui.pages != null)
  2931. {
  2932. return mxUtils.indexOf(ui.pages, ui.currentPage) + 1;
  2933. }
  2934. return graphGetGlobalVariable.apply(this, arguments);
  2935. };
  2936. /**
  2937. * Overrides editor filename.
  2938. */
  2939. this.editor.getOrCreateFilename = function()
  2940. {
  2941. var filename = ui.defaultFilename;
  2942. var file = ui.getCurrentFile();
  2943. if (file != null)
  2944. {
  2945. filename = (file.getTitle() != null) ? file.getTitle() : filename;
  2946. }
  2947. return filename;
  2948. };
  2949. // Disables print action for standalone apps on iOS
  2950. // because there is no way to close the new window
  2951. // LATER: Use iframe for print, disable preview
  2952. var printAction = this.actions.get('print');
  2953. printAction.setEnabled(!mxClient.IS_IOS || !navigator.standalone);
  2954. printAction.visible = printAction.isEnabled();
  2955. // Scales pages/graph to fit available size
  2956. if (!this.editor.chromeless)
  2957. {
  2958. // Defines additional hotkeys
  2959. this.keyHandler.bindAction(67, true, 'copyStyle', true); // Ctrl+Shift+C
  2960. this.keyHandler.bindAction(86, true, 'pasteStyle', true); // Ctrl+Shift+V
  2961. this.keyHandler.bindAction(77, true, 'editGeometry', true); // Ctrl+Shift+M
  2962. this.keyHandler.bindAction(88, true, 'insertText', true); // Ctrl+Shift+X
  2963. this.keyHandler.bindAction(75, true, 'insertRectangle'); // Ctrl+K
  2964. this.keyHandler.bindAction(75, true, 'insertEllipse', true); // Ctrl+Shift+K
  2965. // Handles copy paste of images from clipboard
  2966. if (!mxClient.IS_IE)
  2967. {
  2968. graph.container.addEventListener('paste', mxUtils.bind(this, function(evt)
  2969. {
  2970. var graph = this.editor.graph;
  2971. if (!mxEvent.isConsumed(evt) && !graph.isEditing())
  2972. {
  2973. try
  2974. {
  2975. var data = (evt.clipboardData || evt.originalEvent.clipboardData);
  2976. var containsText = false;
  2977. // Workaround for asynchronous paste event processing in textInput
  2978. // is to ignore this event if it contains text/html/rtf (see below).
  2979. // NOTE: Image is not pasted into textInput so can't listen there.
  2980. for (var i = 0; i < data.types.length; i++)
  2981. {
  2982. if (data.types[i].substring(0, 5) === 'text/')
  2983. {
  2984. containsText = true;
  2985. break;
  2986. }
  2987. }
  2988. if (!containsText)
  2989. {
  2990. var items = data.items;
  2991. for (index in items)
  2992. {
  2993. var item = items[index];
  2994. if (item.kind === 'file')
  2995. {
  2996. // LATER: Fix sanitizeHtml to allow for data URIs as image in labels
  2997. // if (graph.isEditing())
  2998. // {
  2999. // this.importFiles([item.getAsFile()], 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  3000. // {
  3001. // // Inserts image into current text box
  3002. // graph.insertImage(data, w, h);
  3003. // }, function()
  3004. // {
  3005. // // No post processing
  3006. // }, function(file)
  3007. // {
  3008. // // Handles only images
  3009. // return file.type.substring(0, 6) == 'image/';
  3010. // }, function(queue)
  3011. // {
  3012. // // Invokes elements of queue in order
  3013. // for (var i = 0; i < queue.length; i++)
  3014. // {
  3015. // queue[i]();
  3016. // }
  3017. // });
  3018. // }
  3019. // else
  3020. {
  3021. var pt = this.editor.graph.getInsertPoint();
  3022. this.importFiles([item.getAsFile()], pt.x, pt.y, this.maxImageSize);
  3023. mxEvent.consume(evt);
  3024. }
  3025. break;
  3026. }
  3027. }
  3028. }
  3029. }
  3030. catch (e)
  3031. {
  3032. // ignore
  3033. }
  3034. }
  3035. }), false);
  3036. }
  3037. // Focused but invisible textarea during control or meta key events
  3038. var textInput = document.createElement('div');
  3039. textInput.style.position = 'absolute';
  3040. textInput.style.whiteSpace = 'nowrap';
  3041. textInput.style.overflow = 'hidden';
  3042. textInput.style.display = 'block';
  3043. textInput.contentEditable = true;
  3044. mxUtils.setOpacity(textInput, 0);
  3045. textInput.style.width = '1px';
  3046. textInput.style.height = '1px';
  3047. textInput.innerHTML = '&nbsp;';
  3048. var restoreFocus = false;
  3049. // Disables built-in cut, copy and paste shortcuts
  3050. this.keyHandler.bindControlKey(88, null);
  3051. this.keyHandler.bindControlKey(67, null);
  3052. this.keyHandler.bindControlKey(86, null);
  3053. // Shows a textare when control/cmd is pressed to handle native clipboard actions
  3054. mxEvent.addListener(document, 'keydown', mxUtils.bind(this, function(evt)
  3055. {
  3056. // No dialog visible
  3057. var source = mxEvent.getSource(evt);
  3058. if (graph.container != null && graph.isEnabled() && !graph.isMouseDown && !graph.isEditing() &&
  3059. this.dialog == null && source.nodeName != 'INPUT' && source.nodeName != 'TEXTAREA')
  3060. {
  3061. if (evt.keyCode == 224 /* FF */ || (!mxClient.IS_MAC && evt.keyCode == 17 /* Control */) ||
  3062. (mxClient.IS_MAC && evt.keyCode == 91 /* Meta */))
  3063. {
  3064. // Cannot use parentNode for check in IE
  3065. if (!restoreFocus)
  3066. {
  3067. // Avoid autoscroll but allow handling of all pass-through ctrl shortcuts
  3068. textInput.style.left = (graph.container.scrollLeft + 10) + 'px';
  3069. textInput.style.top = (graph.container.scrollTop + 10) + 'px';
  3070. graph.container.appendChild(textInput);
  3071. restoreFocus = true;
  3072. // Workaround for selected document content in quirks mode
  3073. if (mxClient.IS_QUIRKS)
  3074. {
  3075. window.setTimeout(function()
  3076. {
  3077. textInput.focus();
  3078. document.execCommand('selectAll', false, null);
  3079. }, 0);
  3080. }
  3081. else
  3082. {
  3083. textInput.focus();
  3084. document.execCommand('selectAll', false, null);
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }));
  3090. // Clears input and restores focus and selection
  3091. function clearInput()
  3092. {
  3093. window.setTimeout(function()
  3094. {
  3095. textInput.innerHTML = '&nbsp;';
  3096. textInput.focus();
  3097. document.execCommand('selectAll', false, null);
  3098. }, 0);
  3099. };
  3100. mxEvent.addListener(document, 'keyup', mxUtils.bind(this, function(evt)
  3101. {
  3102. // Workaround for asynchronous event read invalid in IE quirks mode
  3103. var keyCode = evt.keyCode;
  3104. // Asynchronous workaround for scroll to origin after paste if the
  3105. // Ctrl-key is not pressed for long enough in FF on Windows
  3106. window.setTimeout(mxUtils.bind(this, function()
  3107. {
  3108. if (restoreFocus && (keyCode == 224 /* FF */ || keyCode == 17 /* Control */ ||
  3109. keyCode == 91 /* Meta */))
  3110. {
  3111. restoreFocus = false;
  3112. if (!graph.isEditing() && this.dialog == null && graph.container != null)
  3113. {
  3114. graph.container.focus();
  3115. }
  3116. textInput.parentNode.removeChild(textInput);
  3117. }
  3118. }), 0);
  3119. }));
  3120. mxEvent.addListener(textInput, 'copy', mxUtils.bind(this, function(evt)
  3121. {
  3122. if (graph.isEnabled())
  3123. {
  3124. mxClipboard.copy(graph);
  3125. this.copyCells(textInput);
  3126. clearInput();
  3127. }
  3128. }));
  3129. mxEvent.addListener(textInput, 'cut', mxUtils.bind(this, function(evt)
  3130. {
  3131. if (graph.isEnabled())
  3132. {
  3133. this.copyCells(textInput, true);
  3134. clearInput();
  3135. }
  3136. }));
  3137. mxEvent.addListener(textInput, 'paste', mxUtils.bind(this, function(evt)
  3138. {
  3139. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3140. {
  3141. textInput.innerHTML = '&nbsp;';
  3142. textInput.focus();
  3143. window.setTimeout(mxUtils.bind(this, function()
  3144. {
  3145. this.pasteCells(evt, textInput);
  3146. textInput.innerHTML = '&nbsp;';
  3147. }), 0);
  3148. }
  3149. }), true);
  3150. // Needed for IE11
  3151. var isSelectionAllowed2 = this.isSelectionAllowed;
  3152. this.isSelectionAllowed = function(evt)
  3153. {
  3154. if (mxEvent.getSource(evt) == textInput)
  3155. {
  3156. return true;
  3157. }
  3158. return isSelectionAllowed2.apply(this, arguments);
  3159. };
  3160. };
  3161. var y = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight || 0) / 2;
  3162. var x = document.body.clientWidth / 2 - 2;
  3163. // Holds the x-coordinate of the point
  3164. this.spinner = this.createSpinner(x, y, 24);
  3165. // Installs drag and drop handler for rich text editor
  3166. if (Graph.fileSupport)
  3167. {
  3168. this.editor.graph.addListener(mxEvent.EDITING_STARTED, mxUtils.bind(this, function(evt)
  3169. {
  3170. // Setup the dnd listeners
  3171. var graph = this.editor.graph;
  3172. var textElt = graph.cellEditor.text2;
  3173. var dropElt = null;
  3174. if (textElt != null)
  3175. {
  3176. mxEvent.addListener(textElt, 'dragleave', function(evt)
  3177. {
  3178. if (dropElt != null)
  3179. {
  3180. dropElt.parentNode.removeChild(dropElt);
  3181. dropElt = null;
  3182. }
  3183. evt.stopPropagation();
  3184. evt.preventDefault();
  3185. });
  3186. mxEvent.addListener(textElt, 'dragover', mxUtils.bind(this, function(evt)
  3187. {
  3188. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3189. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3190. {
  3191. dropElt = this.highlightElement(textElt);
  3192. }
  3193. evt.stopPropagation();
  3194. evt.preventDefault();
  3195. }));
  3196. mxEvent.addListener(textElt, 'drop', mxUtils.bind(this, function(evt)
  3197. {
  3198. if (dropElt != null)
  3199. {
  3200. dropElt.parentNode.removeChild(dropElt);
  3201. dropElt = null;
  3202. }
  3203. if (evt.dataTransfer.files.length > 0)
  3204. {
  3205. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  3206. {
  3207. // Inserts image into current text box
  3208. graph.insertImage(data, w, h);
  3209. }, function()
  3210. {
  3211. // No post processing
  3212. }, function(file)
  3213. {
  3214. // Handles only images
  3215. return file.type.substring(0, 6) == 'image/';
  3216. }, function(queue)
  3217. {
  3218. // Invokes elements of queue in order
  3219. for (var i = 0; i < queue.length; i++)
  3220. {
  3221. queue[i]();
  3222. }
  3223. }, !mxEvent.isControlDown(evt));
  3224. }
  3225. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3226. {
  3227. var uri = evt.dataTransfer.getData('text/uri-list');
  3228. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  3229. {
  3230. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  3231. {
  3232. var w = Math.max(1, img.width);
  3233. var h = Math.max(1, img.height);
  3234. var maxSize = this.maxImageSize;
  3235. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  3236. graph.insertImage(decodeURIComponent(uri), w * s, h * s);
  3237. }));
  3238. }
  3239. else
  3240. {
  3241. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  3242. }
  3243. }
  3244. else
  3245. {
  3246. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  3247. {
  3248. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/html'));
  3249. }
  3250. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  3251. {
  3252. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  3253. }
  3254. }
  3255. evt.stopPropagation();
  3256. evt.preventDefault();
  3257. }));
  3258. }
  3259. }));
  3260. }
  3261. // Adds an element to edit the style in the footer in test mode
  3262. if (urlParams['test'] == '1')
  3263. {
  3264. var footer = document.getElementById('geFooter');
  3265. if (footer != null)
  3266. {
  3267. this.styleInput = document.createElement('input');
  3268. this.styleInput.setAttribute('type', 'text');
  3269. this.styleInput.style.position = 'absolute';
  3270. this.styleInput.style.top = '14px';
  3271. this.styleInput.style.left = '2px';
  3272. // Workaround for ignore right CSS property in FF
  3273. this.styleInput.style.width = '98%';
  3274. this.styleInput.style.visibility = 'hidden';
  3275. this.styleInput.style.opacity = '0.9';
  3276. mxEvent.addListener(this.styleInput, 'change', mxUtils.bind(this, function()
  3277. {
  3278. this.editor.graph.getModel().setStyle(this.editor.graph.getSelectionCell(), this.styleInput.value);
  3279. }));
  3280. footer.appendChild(this.styleInput);
  3281. this.editor.graph.getSelectionModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function(sender, evt)
  3282. {
  3283. if (this.editor.graph.getSelectionCount() > 0)
  3284. {
  3285. var cell = this.editor.graph.getSelectionCell();
  3286. var style = this.editor.graph.getModel().getStyle(cell);
  3287. this.styleInput.value = style || '';
  3288. this.styleInput.style.visibility = 'visible';
  3289. } else
  3290. {
  3291. this.styleInput.style.visibility = 'hidden';
  3292. }
  3293. }));
  3294. }
  3295. var isSelectionAllowed = this.isSelectionAllowed;
  3296. this.isSelectionAllowed = function(evt)
  3297. {
  3298. if (mxEvent.getSource(evt) == this.styleInput)
  3299. {
  3300. return true;
  3301. }
  3302. return isSelectionAllowed.apply(this, arguments);
  3303. };
  3304. }
  3305. // Removes info text in page
  3306. var info = document.getElementById('geInfo');
  3307. if (info != null)
  3308. {
  3309. info.parentNode.removeChild(info);
  3310. }
  3311. // Installs drag and drop handler for files
  3312. // Enables dropping files
  3313. if (Graph.fileSupport)
  3314. {
  3315. // Setup the dnd listeners
  3316. var dropElt = null;
  3317. mxEvent.addListener(graph.container, 'dragleave', function(evt)
  3318. {
  3319. if (graph.isEnabled())
  3320. {
  3321. if (dropElt != null)
  3322. {
  3323. dropElt.parentNode.removeChild(dropElt);
  3324. dropElt = null;
  3325. }
  3326. evt.stopPropagation();
  3327. evt.preventDefault();
  3328. }
  3329. });
  3330. mxEvent.addListener(graph.container, 'dragover', mxUtils.bind(this, function(evt)
  3331. {
  3332. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3333. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3334. {
  3335. dropElt = this.highlightElement(graph.container);
  3336. }
  3337. if (this.sidebar != null)
  3338. {
  3339. this.sidebar.hideTooltip();
  3340. }
  3341. evt.stopPropagation();
  3342. evt.preventDefault();
  3343. }));
  3344. mxEvent.addListener(graph.container, 'drop', mxUtils.bind(this, function(evt)
  3345. {
  3346. if (dropElt != null)
  3347. {
  3348. dropElt.parentNode.removeChild(dropElt);
  3349. dropElt = null;
  3350. }
  3351. if (graph.isEnabled())
  3352. {
  3353. var pt = mxUtils.convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  3354. var tr = graph.view.translate;
  3355. var scale = graph.view.scale;
  3356. var x = pt.x / scale - tr.x;
  3357. var y = pt.y / scale - tr.y;
  3358. if (mxEvent.isAltDown(evt))
  3359. {
  3360. x = 0;
  3361. y = 0;
  3362. }
  3363. if (evt.dataTransfer.files.length > 0)
  3364. {
  3365. this.importFiles(evt.dataTransfer.files, x, y, this.maxImageSize, null, null,
  3366. null, null, !mxEvent.isControlDown(evt) && !mxEvent.isShiftDown(evt));
  3367. }
  3368. else
  3369. {
  3370. var uri = (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0) ?
  3371. evt.dataTransfer.getData('text/uri-list') : null;
  3372. var data = this.extractGraphModelFromEvent(evt);
  3373. if (data != null)
  3374. {
  3375. graph.setSelectionCells(this.importXml(data, x, y, true));
  3376. }
  3377. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  3378. {
  3379. var html = evt.dataTransfer.getData('text/html');
  3380. var div = document.createElement('div');
  3381. div.innerHTML = html;
  3382. // The default is based on the extension
  3383. var asImage = null;
  3384. // Extracts single image
  3385. var imgs = div.getElementsByTagName('img');
  3386. if (imgs != null && imgs.length == 1)
  3387. {
  3388. html = imgs[0].getAttribute('src');
  3389. // Handles special case where the src attribute has no valid extension
  3390. // in which case the text would be inserted as text with a link
  3391. if (!(/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(html))
  3392. {
  3393. asImage = true;
  3394. }
  3395. }
  3396. else
  3397. {
  3398. // Extracts single link
  3399. var a = div.getElementsByTagName('a');
  3400. if (a != null && a.length == 1)
  3401. {
  3402. html = a[0].getAttribute('href');
  3403. }
  3404. }
  3405. graph.setSelectionCells(this.insertTextAt(html, x, y, true, asImage));
  3406. }
  3407. else if (uri != null && (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  3408. {
  3409. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  3410. {
  3411. var w = Math.max(1, img.width);
  3412. var h = Math.max(1, img.height);
  3413. var maxSize = this.maxImageSize;
  3414. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  3415. graph.setSelectionCell(graph.insertVertex(null, null, '', x, y, w * s, h * s,
  3416. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  3417. 'verticalAlign=top;aspect=fixed;image=' + uri + ';'));
  3418. }), mxUtils.bind(this, function(img)
  3419. {
  3420. graph.setSelectionCells(this.insertTextAt(uri, x, y, true));
  3421. }));
  3422. }
  3423. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  3424. {
  3425. graph.setSelectionCells(this.insertTextAt(evt.dataTransfer.getData('text/plain'), x, y, true));
  3426. }
  3427. }
  3428. }
  3429. evt.stopPropagation();
  3430. evt.preventDefault();
  3431. }), false);
  3432. }
  3433. this.initPages();
  3434. // Embedded mode
  3435. if (urlParams['embed'] == '1')
  3436. {
  3437. this.initializeEmbedMode();
  3438. }
  3439. };
  3440. /**
  3441. * Creates the format panel and adds overrides.
  3442. */
  3443. EditorUi.prototype.copyCells = function(elt, removeCells)
  3444. {
  3445. var graph = this.editor.graph;
  3446. if (!graph.isSelectionEmpty())
  3447. {
  3448. var cells = mxUtils.sortCells(graph.model.getTopmostCells(graph.getSelectionCells()));
  3449. // LATER: Add span with XML in data attribute
  3450. // var span = document.createElement('span');
  3451. // span.setAttribute('data-jgraph-type', 'application/vnd.jgraph.xml');
  3452. // span.setAttribute('data-jgraph-content', mxUtils.getXml(graph.encodeCells(clones)));
  3453. // Fixes cross-platform clipboard UTF8 issues by encoding as URI
  3454. var xml = mxUtils.getXml(this.editor.graph.encodeCells(cells));
  3455. mxUtils.setTextContent(elt, encodeURIComponent(xml));
  3456. if (removeCells)
  3457. {
  3458. graph.removeCells(cells, false);
  3459. graph.lastPasteXml = null;
  3460. }
  3461. else
  3462. {
  3463. graph.lastPasteXml = xml;
  3464. graph.pasteCounter = 0;
  3465. }
  3466. elt.focus();
  3467. document.execCommand('selectAll', false, null);
  3468. }
  3469. else
  3470. {
  3471. // Disables copy on focused element
  3472. elt.innerHTML = '';
  3473. }
  3474. };
  3475. /**
  3476. * Creates the format panel and adds overrides.
  3477. */
  3478. EditorUi.prototype.pasteCells = function(evt, elt)
  3479. {
  3480. if (!mxEvent.isConsumed(evt))
  3481. {
  3482. var graph = this.editor.graph;
  3483. var xml = mxUtils.trim((mxClient.IS_QUIRKS || document.documentMode == 8) ?
  3484. mxUtils.getTextContent(elt) : elt.textContent);
  3485. var compat = false;
  3486. // Workaround for junk after XML in VM
  3487. try
  3488. {
  3489. var idx = xml.lastIndexOf('%3E');
  3490. if (idx < xml.length - 3)
  3491. {
  3492. xml = xml.substring(0, idx + 3);
  3493. }
  3494. }
  3495. catch (e)
  3496. {
  3497. // ignore
  3498. }
  3499. // Checks for embedded XML content
  3500. try
  3501. {
  3502. var spans = elt.getElementsByTagName('span');
  3503. var tmp = (spans != null && spans.length > 0) ?
  3504. mxUtils.trim(decodeURIComponent(spans[0].textContent)) :
  3505. decodeURIComponent(xml);
  3506. if (this.isCompatibleString(tmp))
  3507. {
  3508. compat = true;
  3509. xml = tmp;
  3510. }
  3511. }
  3512. catch (e)
  3513. {
  3514. // ignore
  3515. }
  3516. if (graph.lastPasteXml == xml)
  3517. {
  3518. graph.pasteCounter++;
  3519. }
  3520. else
  3521. {
  3522. graph.lastPasteXml = xml;
  3523. graph.pasteCounter = 0;
  3524. }
  3525. var dx = graph.pasteCounter * graph.gridSize;
  3526. if (xml != null && xml.length > 0)
  3527. {
  3528. if (compat || this.isCompatibleString(xml))
  3529. {
  3530. graph.setSelectionCells(this.importXml(xml, dx, dx));
  3531. }
  3532. else
  3533. {
  3534. var pt = graph.getInsertPoint();
  3535. graph.setSelectionCells(this.insertTextAt(xml, pt.x + dx, pt.y + dx, true));
  3536. }
  3537. if (!graph.isSelectionEmpty())
  3538. {
  3539. graph.scrollCellToVisible(graph.getSelectionCell());
  3540. if (this.hoverIcons != null)
  3541. {
  3542. this.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3543. }
  3544. try
  3545. {
  3546. mxEvent.consume(evt);
  3547. }
  3548. catch (e)
  3549. {
  3550. // ignore event no longer exists in async handler in IE8-
  3551. }
  3552. }
  3553. }
  3554. }
  3555. };
  3556. /**
  3557. * Creates the format panel and adds overrides.
  3558. */
  3559. var editorUiCreateFormat = EditorUi.prototype.createFormat;
  3560. EditorUi.prototype.createFormat = function(container)
  3561. {
  3562. /**
  3563. * Overrides for Format sidebar.
  3564. */
  3565. var formatInit = Format.prototype.init;
  3566. Format.prototype.init = function()
  3567. {
  3568. formatInit.apply(this, arguments);
  3569. var ui = this.editorUi;
  3570. ui.editor.addListener('fileLoaded', this.update);
  3571. };
  3572. var formatRefresh = Format.prototype.refresh;
  3573. Format.prototype.refresh = function()
  3574. {
  3575. var ui = this.editorUi;
  3576. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  3577. {
  3578. formatRefresh.apply(this, arguments);
  3579. }
  3580. else
  3581. {
  3582. this.clear();
  3583. }
  3584. };
  3585. /**
  3586. * Adds autosave and math typesetting options.
  3587. */
  3588. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  3589. DiagramFormatPanel.prototype.addOptions = function(div)
  3590. {
  3591. div = diagramFormatPanelAddOptions.apply(this, arguments);
  3592. var ui = this.editorUi;
  3593. var editor = ui.editor;
  3594. var graph = editor.graph;
  3595. if (graph.isEnabled())
  3596. {
  3597. var file = ui.getCurrentFile();
  3598. if (file != null && file.isAutosaveOptional())
  3599. {
  3600. var opt = this.createOption(mxResources.get('autosave'), function()
  3601. {
  3602. return ui.editor.autosave;
  3603. }, function(checked)
  3604. {
  3605. ui.editor.setAutosave(checked);
  3606. },
  3607. {
  3608. install: function(apply)
  3609. {
  3610. this.listener = function()
  3611. {
  3612. apply(ui.editor.autosave);
  3613. };
  3614. ui.editor.addListener('autosaveChanged', this.listener);
  3615. },
  3616. destroy: function()
  3617. {
  3618. ui.editor.removeListener(this.listener);
  3619. }
  3620. });
  3621. div.appendChild(opt);
  3622. }
  3623. }
  3624. return div;
  3625. };
  3626. /**
  3627. * Adds predefiend styles.
  3628. */
  3629. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  3630. StyleFormatPanel.prototype.init = function()
  3631. {
  3632. // TODO: Update sstate in Format
  3633. var sstate = this.format.createSelectionState();
  3634. if (sstate.style.shape != 'image')
  3635. {
  3636. this.container.appendChild(this.addStyles(this.createPanel()));
  3637. }
  3638. StyleFormatPanelInit.apply(this, arguments);
  3639. };
  3640. /**
  3641. * Overridden to add copy and paste style.
  3642. */
  3643. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  3644. StyleFormatPanel.prototype.addStyleOps = function(div)
  3645. {
  3646. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  3647. {
  3648. this.editorUi.actions.get('copyStyle').funct();
  3649. }));
  3650. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  3651. btn.style.marginBottom = '2px';
  3652. btn.style.width = '100px';
  3653. btn.style.marginRight = '2px';
  3654. div.appendChild(btn);
  3655. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  3656. {
  3657. this.editorUi.actions.get('pasteStyle').funct();
  3658. }));
  3659. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  3660. btn.style.marginBottom = '2px';
  3661. btn.style.width = '100px';
  3662. div.appendChild(btn);
  3663. mxUtils.br(div);
  3664. return styleFormatPanelAddStyleOps.apply(this, arguments);
  3665. };
  3666. /**
  3667. * Creates the buttons for the predefined styles.
  3668. */
  3669. StyleFormatPanel.prototype.addStyles = function(div)
  3670. {
  3671. var graph = this.editorUi.editor.graph;
  3672. var picker = document.createElement('div');
  3673. picker.style.whiteSpace = 'normal';
  3674. picker.style.paddingLeft = '24px';
  3675. picker.style.paddingRight = '20px';
  3676. div.style.paddingLeft = '16px';
  3677. div.style.paddingBottom = '6px';
  3678. div.style.position = 'relative';
  3679. div.appendChild(picker);
  3680. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-orange',
  3681. 'plain-yellow', 'plain-red', 'plain-purple', null];
  3682. function updateScheme(colorsets)
  3683. {
  3684. function addButton(colorset)
  3685. {
  3686. var btn = mxUtils.button('', function(evt)
  3687. {
  3688. graph.getModel().beginUpdate();
  3689. try
  3690. {
  3691. var cells = graph.getSelectionCells();
  3692. for (var i = 0; i < cells.length; i++)
  3693. {
  3694. var style = graph.getModel().getStyle(cells[i]);
  3695. for (var j = 0; j < stylenames.length; j++)
  3696. {
  3697. style = mxUtils.removeStylename(style, stylenames[j]);
  3698. }
  3699. if (colorset != null)
  3700. {
  3701. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  3702. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  3703. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  3704. }
  3705. else
  3706. {
  3707. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  3708. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  3709. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  3710. }
  3711. graph.getModel().setStyle(cells[i], style);
  3712. }
  3713. }
  3714. finally
  3715. {
  3716. graph.getModel().endUpdate();
  3717. }
  3718. })
  3719. btn.style.width = '36px';
  3720. btn.style.height = '30px';
  3721. btn.style.margin = '0px 6px 6px 0px';
  3722. if (colorset != null)
  3723. {
  3724. if (colorset['gradient'] != null)
  3725. {
  3726. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  3727. {
  3728. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  3729. 'StartColorStr=\'' + colorset['fill'] +
  3730. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  3731. }
  3732. else
  3733. {
  3734. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  3735. colorset['gradient'] + ' 100%)';
  3736. }
  3737. }
  3738. else
  3739. {
  3740. btn.style.backgroundColor = colorset['fill'];
  3741. }
  3742. btn.style.border = '1px solid ' + colorset['stroke'];
  3743. }
  3744. else
  3745. {
  3746. btn.style.backgroundColor = '#ffffff';
  3747. btn.style.border = '1px solid #000000';
  3748. }
  3749. picker.appendChild(btn);
  3750. };
  3751. picker.innerHTML = '';
  3752. for (var i = 0; i < colorsets.length; i++)
  3753. {
  3754. if (i > 0 && mxUtils.mod(i, 4) == 0)
  3755. {
  3756. mxUtils.br(picker);
  3757. }
  3758. addButton(colorsets[i]);
  3759. }
  3760. };
  3761. if (this.editorUi.currentScheme == null)
  3762. {
  3763. this.editorUi.currentScheme = 0;
  3764. }
  3765. var schemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  3766. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  3767. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  3768. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  3769. [null,
  3770. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  3771. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  3772. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  3773. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  3774. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  3775. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  3776. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}]];
  3777. var left = document.createElement('div');
  3778. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3779. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  3780. div.appendChild(left);
  3781. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  3782. {
  3783. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, schemes.length);
  3784. updateScheme(schemes[this.editorUi.currentScheme]);
  3785. }));
  3786. var right = document.createElement('div');
  3787. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3788. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  3789. div.appendChild(right);
  3790. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  3791. {
  3792. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, schemes.length);
  3793. updateScheme(schemes[this.editorUi.currentScheme]);
  3794. }));
  3795. // Hover state
  3796. function addHoverState(elt)
  3797. {
  3798. mxEvent.addListener(elt, 'mouseenter', function()
  3799. {
  3800. elt.style.opacity = '1';
  3801. });
  3802. mxEvent.addListener(elt, 'mouseleave', function()
  3803. {
  3804. elt.style.opacity = '0.5';
  3805. });
  3806. };
  3807. addHoverState(left);
  3808. addHoverState(right);
  3809. updateScheme(schemes[this.editorUi.currentScheme]);
  3810. return div;
  3811. };
  3812. return editorUiCreateFormat.apply(this, arguments);
  3813. };
  3814. // Overridden to add edit shape option
  3815. if (window.StyleFormatPanel != null)
  3816. {
  3817. StyleFormatPanel.prototype.addEditOps = function(div)
  3818. {
  3819. var ss = this.format.getSelectionState();
  3820. var btn = null;
  3821. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  3822. {
  3823. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  3824. {
  3825. this.editorUi.actions.get('editStyle').funct();
  3826. }));
  3827. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  3828. btn.style.width = '202px';
  3829. btn.style.marginBottom = '2px';
  3830. div.appendChild(btn);
  3831. }
  3832. var graph = this.editorUi.editor.graph;
  3833. var state = graph.view.getState(graph.getSelectionCell());
  3834. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  3835. {
  3836. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  3837. {
  3838. this.editorUi.actions.get('editShape').funct();
  3839. }));
  3840. btn2.setAttribute('title', mxResources.get('editShape'));
  3841. btn2.style.marginBottom = '2px';
  3842. if (btn == null)
  3843. {
  3844. btn2.style.width = '202px';
  3845. }
  3846. else
  3847. {
  3848. btn.style.width = '100px';
  3849. btn2.style.width = '100px';
  3850. btn2.style.marginLeft = '2px';
  3851. }
  3852. div.appendChild(btn2);
  3853. }
  3854. else if (ss.image)
  3855. {
  3856. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  3857. {
  3858. this.editorUi.actions.get('image').funct();
  3859. }));
  3860. btn2.setAttribute('title', mxResources.get('editImage'));
  3861. btn2.style.marginBottom = '2px';
  3862. if (btn == null)
  3863. {
  3864. btn2.style.width = '202px';
  3865. }
  3866. else
  3867. {
  3868. btn.style.width = '100px';
  3869. btn2.style.width = '100px';
  3870. btn2.style.marginLeft = '2px';
  3871. }
  3872. div.appendChild(btn2);
  3873. }
  3874. return div;
  3875. };
  3876. }
  3877. /**
  3878. * Adds a file drop handler for opening local files.
  3879. */
  3880. EditorUi.prototype.addFileDropHandler = function(elts)
  3881. {
  3882. // Installs drag and drop handler for files
  3883. if (Graph.fileSupport)
  3884. {
  3885. var dropElt = null;
  3886. for (var i = 0; i < elts.length; i++)
  3887. {
  3888. // Setup the dnd listeners
  3889. mxEvent.addListener(elts[i], 'dragleave', function(evt)
  3890. {
  3891. if (dropElt != null)
  3892. {
  3893. dropElt.parentNode.removeChild(dropElt);
  3894. dropElt = null;
  3895. }
  3896. evt.stopPropagation();
  3897. evt.preventDefault();
  3898. });
  3899. mxEvent.addListener(elts[i], 'dragover', mxUtils.bind(this, function(evt)
  3900. {
  3901. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3902. if (dropElt == null && (!mxClient.IS_IE || (document.documentMode > 10 && document.documentMode < 12)))
  3903. {
  3904. dropElt = this.highlightElement();
  3905. }
  3906. evt.stopPropagation();
  3907. evt.preventDefault();
  3908. }));
  3909. mxEvent.addListener(elts[i], 'drop', mxUtils.bind(this, function(evt)
  3910. {
  3911. if (dropElt != null)
  3912. {
  3913. dropElt.parentNode.removeChild(dropElt);
  3914. dropElt = null;
  3915. }
  3916. if (evt.dataTransfer.files.length > 0)
  3917. {
  3918. this.hideDialog();
  3919. this.openFiles(evt.dataTransfer.files);
  3920. }
  3921. else
  3922. {
  3923. // Handles open special files via text drag and drop
  3924. var data = this.extractGraphModelFromEvent(evt);
  3925. // Tries additional and async parsing of text content such as HTML, Gliffy data
  3926. if (data == null)
  3927. {
  3928. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  3929. if (provider != null)
  3930. {
  3931. if (document.documentMode == 10 || document.documentMode == 11)
  3932. {
  3933. data = provider.getData('Text');
  3934. }
  3935. else
  3936. {
  3937. var data = null;
  3938. if (mxUtils.indexOf(provider.types, 'text/uri-list') >= 0)
  3939. {
  3940. var data = evt.dataTransfer.getData('text/uri-list');
  3941. }
  3942. else
  3943. {
  3944. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  3945. }
  3946. if (data != null && data.length > 0)
  3947. {
  3948. var div = document.createElement('div');
  3949. div.innerHTML = data;
  3950. // Extracts single image
  3951. var imgs = div.getElementsByTagName('img');
  3952. if (imgs.length > 0)
  3953. {
  3954. data = imgs[0].getAttribute('src');
  3955. }
  3956. }
  3957. else if (mxUtils.indexOf(provider.types, 'text/plain') >= 0)
  3958. {
  3959. data = provider.getData('text/plain');
  3960. }
  3961. }
  3962. if (data != null)
  3963. {
  3964. // Checks for embedded XML in PNG
  3965. if (data.substring(0, 22) == 'data:image/png;base64,')
  3966. {
  3967. var xml = this.extractGraphModelFromPng(data);
  3968. if (xml != null && xml.length > 0)
  3969. {
  3970. this.openLocalFile(xml);
  3971. }
  3972. }
  3973. if (!this.isOffline() && this.isRemoteFileFormat(data))
  3974. {
  3975. new mxXmlRequest(OPEN_URL, 'format=xml&data=' + encodeURIComponent(data)).send(mxUtils.bind(this, function(req)
  3976. {
  3977. if (req.getStatus() == 200)
  3978. {
  3979. this.openLocalFile(req.getText());
  3980. }
  3981. }));
  3982. }
  3983. else if (/^https?:\/\//.test(data))
  3984. {
  3985. var url = this.getUrl(window.location.pathname + '?url=' + encodeURIComponent(data));
  3986. if (this.getCurrentFile() == null)
  3987. {
  3988. window.location.href = url;
  3989. }
  3990. else
  3991. {
  3992. window.openWindow(url);
  3993. }
  3994. }
  3995. }
  3996. }
  3997. }
  3998. else
  3999. {
  4000. this.openLocalFile(data);
  4001. }
  4002. }
  4003. evt.stopPropagation();
  4004. evt.preventDefault();
  4005. }));
  4006. }
  4007. }
  4008. };
  4009. /**
  4010. * Highlights the given element
  4011. */
  4012. EditorUi.prototype.highlightElement = function(elt)
  4013. {
  4014. var x = 0;
  4015. var y = 0;
  4016. var w = 0;
  4017. var h = 0;
  4018. if (elt == null)
  4019. {
  4020. var b = document.body;
  4021. var d = document.documentElement;
  4022. w = (b.clientWidth || d.clientWidth) - 3;
  4023. h = Math.max(b.clientHeight || 0, d.clientHeight) - 3;
  4024. }
  4025. else
  4026. {
  4027. x = elt.offsetTop;
  4028. y = elt.offsetLeft;
  4029. w = elt.clientWidth;
  4030. h = elt.clientHeight;
  4031. }
  4032. var hl = document.createElement('div');
  4033. hl.style.zIndex = mxPopupMenu.prototype.zIndex + 2;
  4034. hl.style.border = '3px dotted rgb(254, 137, 12)';
  4035. hl.style.pointerEvents = 'none';
  4036. hl.style.position = 'absolute';
  4037. hl.style.top = x + 'px';
  4038. hl.style.left = y + 'px';
  4039. hl.style.width = Math.max(0, w - 3) + 'px';
  4040. hl.style.height = Math.max(0, h - 3) + 'px';
  4041. if (elt != null && elt.parentNode == this.editor.graph.container)
  4042. {
  4043. this.editor.graph.container.appendChild(hl);
  4044. }
  4045. else
  4046. {
  4047. document.body.appendChild(hl);
  4048. }
  4049. return hl;
  4050. };
  4051. /**
  4052. * Highlights the given element
  4053. */
  4054. EditorUi.prototype.stringToCells = function(xml)
  4055. {
  4056. var doc = mxUtils.parseXml(xml);
  4057. var node = this.editor.extractGraphModel(doc.documentElement);
  4058. var cells = [];
  4059. if (node != null)
  4060. {
  4061. var codec = new mxCodec(node.ownerDocument);
  4062. var model = new mxGraphModel();
  4063. codec.decode(node, model);
  4064. var parent = model.getChildAt(model.getRoot(), 0);
  4065. for (var j = 0; j < model.getChildCount(parent); j++)
  4066. {
  4067. cells.push(model.getChildAt(parent, j));
  4068. }
  4069. }
  4070. return cells;
  4071. };
  4072. /**
  4073. * Opens the given files in the editor.
  4074. */
  4075. EditorUi.prototype.openFiles = function(files)
  4076. {
  4077. if (this.spinner.spin(document.body, mxResources.get('loading')))
  4078. {
  4079. for (var i = 0; i < files.length; i++)
  4080. {
  4081. (mxUtils.bind(this, function(file)
  4082. {
  4083. var reader = new FileReader();
  4084. reader.onload = mxUtils.bind(this, function(e)
  4085. {
  4086. var data = e.target.result;
  4087. var name = file.name;
  4088. if (name != null && name.length > 0)
  4089. {
  4090. if (/(\.png)$/i.test(name))
  4091. {
  4092. name = name.substring(0, name.length - 4) + '.xml';
  4093. }
  4094. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload &&
  4095. this.isRemoteFileFormat(data, name))
  4096. {
  4097. var dot = name.lastIndexOf('.');
  4098. if (dot >= 0)
  4099. {
  4100. name = name.substring(0, name.lastIndexOf('.')) + '.xml';
  4101. }
  4102. else
  4103. {
  4104. name = name + '.xml';
  4105. }
  4106. this.parseFile(file, mxUtils.bind(this, function(xhr)
  4107. {
  4108. if (xhr.readyState == 4)
  4109. {
  4110. this.spinner.stop();
  4111. if (xhr.status == 200)
  4112. {
  4113. this.openLocalFile(xhr.responseText, name);
  4114. }
  4115. else
  4116. {
  4117. this.handleError({message: mxResources.get((xhr.status == 413) ?
  4118. 'drawingTooLarge' : 'invalidOrMissingFile')},
  4119. mxResources.get('errorLoadingFile'));
  4120. }
  4121. }
  4122. }));
  4123. }
  4124. else if (e.target.result.substring(0, 10) == '<mxlibrary')
  4125. {
  4126. this.spinner.stop();
  4127. try
  4128. {
  4129. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  4130. }
  4131. catch (e)
  4132. {
  4133. this.handleError(e, mxResources.get('errorLoadingFile'));
  4134. }
  4135. }
  4136. else
  4137. {
  4138. if (file.type.substring(0, 9) == 'image/png')
  4139. {
  4140. data = this.extractGraphModelFromPng(data);
  4141. }
  4142. this.spinner.stop();
  4143. this.openLocalFile(data, name);
  4144. }
  4145. }
  4146. });
  4147. reader.onerror = mxUtils.bind(this, function(e)
  4148. {
  4149. this.spinner.stop();
  4150. this.handleError(e);
  4151. window.openFile = null;
  4152. });
  4153. if (file.type.substring(0, 5) === 'image' && file.type.substring(0, 9) !== 'image/svg')
  4154. {
  4155. reader.readAsDataURL(file);
  4156. }
  4157. else
  4158. {
  4159. reader.readAsText(file);
  4160. }
  4161. }))(files[i]);
  4162. }
  4163. }
  4164. };
  4165. /**
  4166. * Shows the layers dialog if the graph has more than one layer.
  4167. */
  4168. EditorUi.prototype.openLocalFile = function(data, name)
  4169. {
  4170. var fn = mxUtils.bind(this, function()
  4171. {
  4172. window.openFile = null;
  4173. if (name == null && this.getCurrentFile() != null && this.isDiagramEmpty())
  4174. {
  4175. var doc = mxUtils.parseXml(data);
  4176. if (doc != null)
  4177. {
  4178. this.editor.setGraphXml(doc.documentElement);
  4179. this.editor.graph.selectAll();
  4180. }
  4181. }
  4182. else
  4183. {
  4184. this.fileLoaded(new LocalFile(this, data, name || this.defaultFilename));
  4185. }
  4186. });
  4187. if (data != null && data.length > 0)
  4188. {
  4189. if (this.getCurrentFile() != null && !this.isDiagramEmpty())
  4190. {
  4191. window.openFile = new OpenFile(function()
  4192. {
  4193. window.openFile = null;
  4194. });
  4195. window.openFile.setData(data, name);
  4196. window.openWindow(this.getUrl(), null, fn);
  4197. }
  4198. else
  4199. {
  4200. fn();
  4201. }
  4202. }
  4203. };
  4204. /**
  4205. * Shows the layers dialog if the graph has more than one layer.
  4206. */
  4207. EditorUi.prototype.initializeEmbedMode = function()
  4208. {
  4209. this.diagramContainer.style.visibility = 'hidden';
  4210. this.formatContainer.style.visibility = 'hidden';
  4211. this.editor.graph.setEnabled(false);
  4212. var parent = window.opener || window.parent;
  4213. if (parent != window)
  4214. {
  4215. if (urlParams['spin'] != '1' || this.spinner.spin(document.body, mxResources.get('loading')))
  4216. {
  4217. this.installMessageHandler(mxUtils.bind(this, function(xml, evt, modified)
  4218. {
  4219. this.spinner.stop();
  4220. this.addEmbedButtons();
  4221. this.diagramContainer.style.visibility = '';
  4222. this.formatContainer.style.visibility = '';
  4223. this.editor.graph.setEnabled(true);
  4224. if (xml != null && xml.length > 0)
  4225. {
  4226. var doc = mxUtils.parseXml(xml);
  4227. this.editor.setGraphXml(doc.documentElement);
  4228. this.showLayersDialog();
  4229. }
  4230. else
  4231. {
  4232. this.editor.graph.model.clear();
  4233. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  4234. }
  4235. this.editor.undoManager.clear();
  4236. this.editor.modified = (modified != null) ? modified : false;
  4237. this.updateUi();
  4238. if (this.format != null)
  4239. {
  4240. this.format.refresh();
  4241. }
  4242. }));
  4243. }
  4244. }
  4245. };
  4246. /**
  4247. * Shows the layers dialog if the graph has more than one layer.
  4248. */
  4249. EditorUi.prototype.showLayersDialog = function()
  4250. {
  4251. if (this.editor.graph.getModel().getChildCount(this.editor.graph.getModel().getRoot()) > 1)
  4252. {
  4253. if (this.actions.layersWindow == null)
  4254. {
  4255. this.actions.get('layers').funct();
  4256. }
  4257. else
  4258. {
  4259. this.actions.layersWindow.window.setVisible(true);
  4260. }
  4261. }
  4262. };
  4263. /**
  4264. * Adds the buttons for embedded mode.
  4265. */
  4266. EditorUi.prototype.createLoadMessage = function(eventName)
  4267. {
  4268. var graph = this.editor.graph;
  4269. return {event: eventName, pageVisible: graph.pageVisible, translate: graph.view.translate,
  4270. scale: graph.view.scale, page: graph.view.getBackgroundPageBounds(), bounds: graph.getGraphBounds()};
  4271. };
  4272. /**
  4273. * Adds the buttons for embedded mode.
  4274. */
  4275. EditorUi.prototype.installMessageHandler = function(fn)
  4276. {
  4277. var autosave = false;
  4278. var updateStatus = mxUtils.bind(this, function(sender, eventObject)
  4279. {
  4280. if (urlParams['modified'] != null)
  4281. {
  4282. if (urlParams['modified'] == '0')
  4283. {
  4284. this.editor.setStatus('');
  4285. }
  4286. else
  4287. {
  4288. this.editor.setStatus(mxResources.get(urlParams['modified']));
  4289. }
  4290. }
  4291. });
  4292. this.editor.graph.model.addListener(mxEvent.CHANGE, updateStatus);
  4293. // Receives XML message from opener and puts it into the graph
  4294. mxEvent.addListener(window, 'message', mxUtils.bind(this, function(evt)
  4295. {
  4296. var data = evt.data;
  4297. if (urlParams['proto'] == 'json')
  4298. {
  4299. data = JSON.parse(data);
  4300. if (data.action == 'dialog')
  4301. {
  4302. this.showError((data.titleKey != null) ? mxResources.get(data.titleKey) : data.title,
  4303. (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message,
  4304. (data.buttonKey != null) ? mxResources.get(data.buttonKey) : data.button);
  4305. if (data.modified != null)
  4306. {
  4307. this.editor.modified = data.modified;
  4308. }
  4309. return;
  4310. }
  4311. else if (data.action == 'template')
  4312. {
  4313. this.spinner.stop();
  4314. var dlg = new NewDialog(this, false, false, mxUtils.bind(this, function(xml)
  4315. {
  4316. // LATER: Add autosave option in template message
  4317. fn(xml || '', evt, xml != null);
  4318. }));
  4319. this.showDialog(dlg.container, 620, 440, true, true, mxUtils.bind(this, function(cancel)
  4320. {
  4321. if (cancel)
  4322. {
  4323. this.actions.get('exit').funct();
  4324. }
  4325. }));
  4326. dlg.init();
  4327. return;
  4328. }
  4329. else if (data.action == 'status')
  4330. {
  4331. if (data.messageKey != null)
  4332. {
  4333. this.editor.setStatus(mxResources.get(data.messageKey));
  4334. }
  4335. else if (data.message != null)
  4336. {
  4337. this.editor.setStatus(data.message);
  4338. }
  4339. if (data.modified != null)
  4340. {
  4341. this.editor.modified = data.modified;
  4342. }
  4343. return;
  4344. }
  4345. else if (data.action == 'spinner')
  4346. {
  4347. var msg = (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message;
  4348. if (data.show != null && !data.show)
  4349. {
  4350. this.spinner.stop();
  4351. }
  4352. else
  4353. {
  4354. this.spinner.spin(document.body, msg)
  4355. }
  4356. return;
  4357. }
  4358. else if (data.action == 'export')
  4359. {
  4360. if (data.format == 'png' || data.format == 'xmlpng')
  4361. {
  4362. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  4363. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  4364. {
  4365. var xml = (data.xml != null) ? data.xml : this.getFileData(true);
  4366. this.editor.graph.setEnabled(false);
  4367. var postDataBack = mxUtils.bind(this, function(bin)
  4368. {
  4369. var msg = this.createLoadMessage('export');
  4370. msg.format = data.format;
  4371. msg.xml = encodeURIComponent(xml);
  4372. msg.data = 'data:image/png;base64,' + bin;
  4373. parent.postMessage(JSON.stringify(msg), '*');
  4374. this.editor.graph.setEnabled(true);
  4375. });
  4376. if (this.isExportToCanvas())
  4377. {
  4378. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  4379. {
  4380. var uri = canvas.toDataURL('image/png');
  4381. if (data.format == 'xmlpng')
  4382. {
  4383. uri = this.writeGraphModelToPng(uri, 'zTXt', 'mxGraphModel',
  4384. atob(this.editor.graph.compress(xml)));
  4385. }
  4386. postDataBack(uri.substring(uri.lastIndexOf(',') + 1));
  4387. }));
  4388. }
  4389. else
  4390. {
  4391. // Data from server is base64 encoded to avoid binary XHR
  4392. // Double encoding for XML arg is needed for UTF8 encoding
  4393. var req = new mxXmlRequest(EXPORT_URL, 'format=png&embedXml=' +
  4394. ((data.format == 'xmlpng') ? '1' : '0') + '&base64=1&xml=' +
  4395. encodeURIComponent(encodeURIComponent(xml)));
  4396. req.send(mxUtils.bind(this, function(req)
  4397. {
  4398. this.editor.graph.setEnabled(true);
  4399. this.spinner.stop();
  4400. if (req.getStatus() == 200)
  4401. {
  4402. postDataBack(req.getText());
  4403. }
  4404. }), mxUtils.bind(this, function()
  4405. {
  4406. this.spinner.stop();
  4407. }));
  4408. }
  4409. }
  4410. }
  4411. else
  4412. {
  4413. // SVG is generated from graph so parse optional XML
  4414. if (data.xml != null && data.xml.length > 0)
  4415. {
  4416. var doc = mxUtils.parseXml(data.xml);
  4417. this.editor.setGraphXml(doc.documentElement);
  4418. }
  4419. var msg = this.createLoadMessage('export');
  4420. if (data.format == 'html' || data.format == 'html2')
  4421. {
  4422. var xml = this.editor.getGraphXml();
  4423. msg.data = (data.format == 'html2') ? this.getHtml2(xml, this.editor.graph) :
  4424. this.getHtml(xml, this.editor.graph);
  4425. msg.xml = mxUtils.getXml(xml);
  4426. msg.format = data.format;
  4427. }
  4428. else
  4429. {
  4430. // Creates a preview with no alt text for unsupported browsers
  4431. mxSvgCanvas2D.prototype.foAltText = null;
  4432. var bg = this.editor.graph.background;
  4433. if (bg == mxConstants.NONE)
  4434. {
  4435. bg = null;
  4436. }
  4437. msg.xml = mxUtils.getXml(this.editor.getGraphXml());
  4438. msg.format = 'svg';
  4439. if (data.embedImages || data.embedImages == null)
  4440. {
  4441. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  4442. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  4443. {
  4444. this.editor.graph.setEnabled(false);
  4445. if (data.format == 'xmlsvg')
  4446. {
  4447. this.getEmbeddedSvg(msg.xml, this.editor.graph, null, true, mxUtils.bind(this, function(svg)
  4448. {
  4449. this.editor.graph.setEnabled(true);
  4450. this.spinner.stop();
  4451. msg.data = this.createSvgDataUri(svg);
  4452. parent.postMessage(JSON.stringify(msg), '*');
  4453. }));
  4454. }
  4455. else
  4456. {
  4457. this.convertImages(this.editor.graph.getSvg(bg), mxUtils.bind(this, function(svgRoot)
  4458. {
  4459. this.editor.graph.setEnabled(true);
  4460. this.spinner.stop();
  4461. msg.data = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  4462. parent.postMessage(JSON.stringify(msg), '*');
  4463. }));
  4464. }
  4465. }
  4466. return;
  4467. }
  4468. else
  4469. {
  4470. var svg = (data.format == 'xmlsvg') ? this.getEmbeddedSvg(mxUtils.getXml(this.editor.getGraphXml()),
  4471. this.editor.graph, null, true) : mxUtils.getXml(this.editor.graph.getSvg(bg));
  4472. msg.data = this.createSvgDataUri(svg);
  4473. }
  4474. }
  4475. parent.postMessage(JSON.stringify(msg), '*');
  4476. }
  4477. return;
  4478. }
  4479. else if (data.action == 'load')
  4480. {
  4481. autosave = data.autosave == 1;
  4482. if (data.modified != null && urlParams['modified'] == null)
  4483. {
  4484. urlParams['modified'] = data.modified;
  4485. }
  4486. if (data.saveAndExit != null && urlParams['saveAndExit'] == null)
  4487. {
  4488. urlParams['saveAndExit'] = data.saveAndExit;
  4489. }
  4490. if (data.title != null && this.buttonContainer != null)
  4491. {
  4492. var tmp = document.createElement('span');
  4493. mxUtils.write(tmp, data.title);
  4494. if (uiTheme == 'atlas')
  4495. {
  4496. this.buttonContainer.style.paddingRight = '12px';
  4497. this.buttonContainer.style.paddingTop = '12px';
  4498. }
  4499. else
  4500. {
  4501. this.buttonContainer.style.paddingRight = '38px';
  4502. this.buttonContainer.style.paddingTop = '6px';
  4503. }
  4504. this.buttonContainer.appendChild(tmp);
  4505. }
  4506. if (data.xmlpng != null)
  4507. {
  4508. data = this.extractGraphModelFromPng(data.xmlpng);
  4509. }
  4510. else
  4511. {
  4512. data = data.xml;
  4513. }
  4514. }
  4515. else
  4516. {
  4517. // Unknown message
  4518. data = null;
  4519. }
  4520. }
  4521. if (data != null && data.charAt(0) != '<')
  4522. {
  4523. try
  4524. {
  4525. if (data.substring(0, 26) == 'data:image/svg+xml;base64,')
  4526. {
  4527. data = atob(data.substring(26));
  4528. }
  4529. else if (data.substring(0, 24) == 'data:image/svg+xml;utf8,')
  4530. {
  4531. data = data.substring(24);
  4532. }
  4533. if (data != null)
  4534. {
  4535. if (data.charAt(0) == '%')
  4536. {
  4537. data = decodeURIComponent(data);
  4538. }
  4539. else if (data.charAt(0) != '<')
  4540. {
  4541. data = this.editor.graph.decompress(data);
  4542. }
  4543. }
  4544. }
  4545. catch (e)
  4546. {
  4547. // ignore compression errors and use empty data
  4548. }
  4549. }
  4550. fn(data, evt);
  4551. if (urlParams['modified'] != null)
  4552. {
  4553. this.editor.setStatus('');
  4554. }
  4555. if (autosave)
  4556. {
  4557. var changeListener = mxUtils.bind(this, function(sender, eventObject)
  4558. {
  4559. var data = mxUtils.getXml(this.editor.getGraphXml());
  4560. var msg = this.createLoadMessage('autosave');
  4561. msg.xml = data;
  4562. data = JSON.stringify(msg);
  4563. var parent = window.opener || window.parent;
  4564. parent.postMessage(data, '*');
  4565. });
  4566. this.editor.graph.model.addListener(mxEvent.CHANGE, changeListener);
  4567. // Some options trigger autosave
  4568. this.addListener('pageFormatChanged', changeListener);
  4569. this.addListener('backgroundColorChanged', changeListener);
  4570. this.addListener('backgroundImageChanged', changeListener);
  4571. this.addListener('foldingEnabledChanged', changeListener);
  4572. this.addListener('mathEnabledChanged', changeListener);
  4573. this.addListener('gridEnabledChanged', changeListener);
  4574. this.addListener('guidesEnabledChanged', changeListener);
  4575. this.addListener('pageViewChanged', changeListener);
  4576. }
  4577. // Sends the bounds of the graph to the host after parsing
  4578. if (urlParams['returnbounds'] == '1' || urlParams['proto'] == 'json')
  4579. {
  4580. parent.postMessage(JSON.stringify(this.createLoadMessage('load')), '*');
  4581. }
  4582. }));
  4583. // Requests data from the sender. This is a workaround for not allowing
  4584. // the opener to listen for the onload event if not in the same origin.
  4585. var parent = window.opener || window.parent;
  4586. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'init'}) : (urlParams['ready'] || 'ready');
  4587. parent.postMessage(msg, '*');
  4588. };
  4589. /**
  4590. * Adds the buttons for embedded mode.
  4591. */
  4592. EditorUi.prototype.addEmbedButtons = function()
  4593. {
  4594. if (this.menubar != null)
  4595. {
  4596. var div = document.createElement('div');
  4597. div.style.display = 'inline-block';
  4598. div.style.position = 'absolute';
  4599. div.style.paddingTop = (uiTheme == 'atlas') ? '2px' : '3px';
  4600. div.style.paddingLeft = '8px';
  4601. div.style.paddingBottom = '2px';
  4602. var button = document.createElement('button');
  4603. mxUtils.write(button, mxResources.get('save'));
  4604. button.className = 'geBigButton';
  4605. button.style.fontSize = '12px';
  4606. button.style.padding = '4px 6px 4px 6px';
  4607. button.style.borderRadius = '3px';
  4608. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4609. {
  4610. this.actions.get('save').funct();
  4611. }));
  4612. div.appendChild(button);
  4613. if (urlParams['saveAndExit'] == '1')
  4614. {
  4615. button = document.createElement('a');
  4616. mxUtils.write(button, mxResources.get('saveAndExit'));
  4617. button.style.fontSize = '12px';
  4618. button.style.marginLeft = '6px';
  4619. button.style.padding = '4px';
  4620. button.style.cursor = 'pointer';
  4621. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4622. {
  4623. this.actions.get('saveAndExit').funct();
  4624. }));
  4625. div.appendChild(button);
  4626. }
  4627. button = document.createElement('a');
  4628. mxUtils.write(button, mxResources.get('exit'));
  4629. button.style.fontSize = '12px';
  4630. button.style.marginLeft = '6px';
  4631. button.style.marginRight = '20px';
  4632. button.style.padding = '4px';
  4633. button.style.cursor = 'pointer';
  4634. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4635. {
  4636. this.actions.get('exit').funct();
  4637. }));
  4638. div.appendChild(button);
  4639. this.toolbar.container.appendChild(div);
  4640. this.toolbar.staticElements.push(div);
  4641. div.style.right = (uiTheme != 'atlas') ? '52px' : '42px';
  4642. }
  4643. };
  4644. /**
  4645. * Translates this point by the given vector.
  4646. *
  4647. * @param {number} dx X-coordinate of the translation.
  4648. * @param {number} dy Y-coordinate of the translation.
  4649. */
  4650. EditorUi.prototype.getSearch = function(exclude)
  4651. {
  4652. var result = '';
  4653. if (urlParams['offline'] != '1' && urlParams['demo'] != '1' && exclude != null && window.location.search.length > 0)
  4654. {
  4655. var amp = '?';
  4656. for (var key in urlParams)
  4657. {
  4658. if (mxUtils.indexOf(exclude, key) < 0 && urlParams[key] != null)
  4659. {
  4660. result += amp + key + '=' + urlParams[key];
  4661. amp = '&';
  4662. }
  4663. }
  4664. }
  4665. else
  4666. {
  4667. result = window.location.search;
  4668. }
  4669. return result;
  4670. };
  4671. /**
  4672. * Returns the URL for a copy of this editor with no state.
  4673. */
  4674. EditorUi.prototype.getUrl = function(pathname)
  4675. {
  4676. var href = (pathname != null) ? pathname : window.location.pathname;
  4677. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  4678. if (urlParams['offline'] == '1')
  4679. {
  4680. href += window.location.search;
  4681. }
  4682. else
  4683. {
  4684. var ignored = ['tmp', 'libs', 'clibs', 'state', 'fileId', 'code', 'share', 'notitle',
  4685. 'url', 'embed', 'client', 'create', 'title', 'splash'];
  4686. // Removes template URL parameter for new blank diagram
  4687. for (var key in urlParams)
  4688. {
  4689. if (mxUtils.indexOf(ignored, key) < 0)
  4690. {
  4691. if (parms == 0)
  4692. {
  4693. href += '?';
  4694. }
  4695. else
  4696. {
  4697. href += '&';
  4698. }
  4699. if (urlParams[key] != null)
  4700. {
  4701. href += key + '=' + urlParams[key];
  4702. parms++;
  4703. }
  4704. }
  4705. }
  4706. }
  4707. return href;
  4708. };
  4709. /**
  4710. * Overrides createOutline
  4711. */
  4712. var editorUiCreateOutline = EditorUi.prototype.createOutline;
  4713. EditorUi.prototype.createOutline = function(wnd)
  4714. {
  4715. var outline = editorUiCreateOutline.apply(this, arguments);
  4716. var graph = this.editor.graph;
  4717. var outlineGetSourceGraphBounds = outline.getSourceGraphBounds;
  4718. outline.getSourceGraphBounds = function()
  4719. {
  4720. if (mxUtils.hasScrollbars(graph.container) && graph.pageVisible && this.source.minimumGraphSize != null)
  4721. {
  4722. var pb = this.source.getPagePadding();
  4723. var s = this.source.view.scale;
  4724. var result = new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width - 2 * pb.x / s),
  4725. Math.ceil(this.source.minimumGraphSize.height - 2 * pb.y / s));
  4726. return result;
  4727. }
  4728. return outlineGetSourceGraphBounds.apply(this, arguments);
  4729. };
  4730. var outlineGetSourceContainerSize = outline.getSourceContainerSize;
  4731. outline.getSourceContainerSize = function()
  4732. {
  4733. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  4734. {
  4735. var pad = this.source.getPagePadding();
  4736. var s = this.source.view.scale;
  4737. return new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width * s - 2 * pad.x),
  4738. Math.ceil(this.source.minimumGraphSize.height * s - 2 * pad.y));
  4739. }
  4740. return outlineGetSourceContainerSize.apply(this, arguments);
  4741. };
  4742. outline.getOutlineOffset = function(scale)
  4743. {
  4744. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  4745. {
  4746. var pb = this.source.getPagePadding();
  4747. var dx = Math.max(0, (outline.outline.container.clientWidth / scale - (this.source.minimumGraphSize.width - 2 * pb.x)) / 2);
  4748. var dy = Math.max(0, (outline.outline.container.clientHeight / scale - (this.source.minimumGraphSize.height - 2 * pb.y)) / 2);
  4749. // Why is vertical offset negative relative to dy
  4750. return new mxPoint(Math.round(dx - pb.x), Math.round(dy - pb.y - 5 / scale));
  4751. }
  4752. return new mxPoint(8 / scale, 8 / scale);
  4753. };
  4754. var outlineInit = outline.init;
  4755. outline.init = function()
  4756. {
  4757. outlineInit.apply(this, arguments);
  4758. // Problem: Need to override a function in the view but the view is created
  4759. // with the graph so a refresh of the page is needed to see this change.
  4760. outline.outline.view.getBackgroundPageBounds = function()
  4761. {
  4762. var layout = graph.getPageLayout();
  4763. var page = graph.getPageSize();
  4764. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  4765. this.scale * (this.translate.y + layout.y * page.height),
  4766. this.scale * layout.width * page.width,
  4767. this.scale * layout.height * page.height);
  4768. };
  4769. outline.outline.view.validateBackgroundPage();
  4770. };
  4771. this.editor.addListener('pageSelected', function(sender, evt)
  4772. {
  4773. var change = evt.getProperty('change');
  4774. var graph = outline.source;
  4775. var g = outline.outline;
  4776. g.pageScale = graph.pageScale;
  4777. g.pageFormat = graph.pageFormat;
  4778. g.background = graph.background;
  4779. g.pageVisible = graph.pageVisible;
  4780. g.background = graph.background;
  4781. var current = mxUtils.getCurrentStyle(graph.container);
  4782. g.container.style.backgroundColor = current.backgroundColor;
  4783. if (graph.view.backgroundPageShape != null && g.view.backgroundPageShape != null)
  4784. {
  4785. g.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  4786. }
  4787. outline.outline.view.clear(change.previousPage.root, true);
  4788. outline.outline.view.validate();
  4789. });
  4790. return outline;
  4791. };
  4792. /**
  4793. * Updates action states depending on the selection.
  4794. */
  4795. var editorUiUpdateActionStates = EditorUi.prototype.updateActionStates;
  4796. EditorUi.prototype.updateActionStates = function()
  4797. {
  4798. editorUiUpdateActionStates.apply(this, arguments);
  4799. var graph = this.editor.graph;
  4800. var file = this.getCurrentFile();
  4801. var active = (file != null && file.isEditable()) || urlParams['embed'] == '1';
  4802. this.actions.get('pageSetup').setEnabled(active);
  4803. this.actions.get('autosave').setEnabled(file != null && file.isEditable() && file.isAutosaveOptional());
  4804. this.actions.get('guides').setEnabled(active);
  4805. this.actions.get('shadowVisible').setEnabled(active);
  4806. this.actions.get('connectionArrows').setEnabled(active);
  4807. this.actions.get('connectionPoints').setEnabled(active);
  4808. this.actions.get('copyStyle').setEnabled(active && !graph.isSelectionEmpty());
  4809. this.actions.get('pasteStyle').setEnabled(active && !graph.isSelectionEmpty());
  4810. this.actions.get('editGeometry').setEnabled(graph.getModel().isVertex(graph.getSelectionCell()));
  4811. this.actions.get('createShape').setEnabled(active);
  4812. this.actions.get('createRevision').setEnabled(active);
  4813. this.actions.get('moveToFolder').setEnabled(file != null);
  4814. this.actions.get('makeCopy').setEnabled(file != null && !file.isRestricted());
  4815. this.actions.get('editDiagram').setEnabled(urlParams['embed'] == '1' ||
  4816. (file != null && !file.isRestricted()));
  4817. this.actions.get('imgur').setEnabled(file != null && !file.isRestricted());
  4818. this.actions.get('twitter').setEnabled(file != null && !file.isRestricted());
  4819. this.actions.get('facebook').setEnabled(file != null && !file.isRestricted());
  4820. this.actions.get('github').setEnabled(file != null && !file.isRestricted());
  4821. this.actions.get('publishLink').setEnabled(file != null && !file.isRestricted());
  4822. this.menus.get('publish').setEnabled(file != null && !file.isRestricted());
  4823. var state = graph.view.getState(graph.getSelectionCell());
  4824. this.actions.get('editShape').setEnabled(active && state != null && state.shape != null && state.shape.stencil != null);
  4825. };
  4826. /**
  4827. * Changes the default stylename so that it matches the old named style
  4828. * if one was specified in the XML.
  4829. */
  4830. Graph.prototype.defaultThemeName = 'default-style2';
  4831. /**
  4832. * Contains the last XML that was pasted.
  4833. */
  4834. Graph.prototype.lastPasteXml = null;
  4835. /**
  4836. * Contains the number of times the last XML was pasted.
  4837. */
  4838. Graph.prototype.pasteCounter = 0;
  4839. // Experimental edge mode
  4840. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  4841. /**
  4842. * Sets default style (used in editor.get/setGraphXml below)
  4843. */
  4844. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  4845. Graph.prototype.loadStylesheet = function()
  4846. {
  4847. graphLoadStylesheet.apply(this, arguments);
  4848. this.currentStyle = 'default-style2';
  4849. };
  4850. /**
  4851. * Graph Overrides
  4852. */
  4853. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  4854. /**
  4855. * Specifies if the page should be visible for new files. Default is true.
  4856. */
  4857. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  4858. /**
  4859. * Loads the stylesheet for this graph.
  4860. */
  4861. Graph.prototype.setShadowVisible = function(value, fireEvent)
  4862. {
  4863. if (mxClient.IS_SVG)
  4864. {
  4865. fireEvent = (fireEvent != null) ? fireEvent : true;
  4866. this.shadowVisible = value;
  4867. if (this.shadowVisible)
  4868. {
  4869. this.view.getDrawPane().setAttribute('filter', 'url(#dropShadow)');
  4870. }
  4871. else
  4872. {
  4873. this.view.getDrawPane().removeAttribute('filter');
  4874. }
  4875. if (fireEvent)
  4876. {
  4877. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  4878. }
  4879. }
  4880. };
  4881. /**
  4882. * Adds rack child layout style.
  4883. */
  4884. var graphInit = Graph.prototype.init;
  4885. Graph.prototype.init = function()
  4886. {
  4887. graphInit.apply(this, arguments);
  4888. // Override insert location for current mouse point
  4889. var mouseEvent = null;
  4890. function setMouseEvent(evt)
  4891. {
  4892. mouseEvent = evt;
  4893. // Workaround for member not found in IE8-
  4894. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  4895. {
  4896. mouseEvent = mxUtils.clone(evt);
  4897. }
  4898. };
  4899. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  4900. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  4901. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  4902. {
  4903. mouseEvent = null;
  4904. });
  4905. // Extends getInsertPoint to use the current mouse location
  4906. this.isMouseInsertPoint = function()
  4907. {
  4908. return mouseEvent != null;
  4909. };
  4910. var getInsertPoint = this.getInsertPoint;
  4911. this.getInsertPoint = function()
  4912. {
  4913. if (mouseEvent != null)
  4914. {
  4915. return this.getPointForEvent(mouseEvent);
  4916. }
  4917. return getInsertPoint.apply(this, arguments);
  4918. };
  4919. var layoutManagerGetLayout = this.layoutManager.getLayout;
  4920. this.layoutManager.getLayout = function(cell)
  4921. {
  4922. var state = this.graph.view.getState(cell);
  4923. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  4924. // mxRackContainer may be undefined as it is dynamically loaded at render time
  4925. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  4926. {
  4927. var rackLayout = new mxStackLayout(this.graph, false);
  4928. rackLayout.setChildGeometry = function(child, geo)
  4929. {
  4930. var unitSize = 20;
  4931. geo.height = Math.max(geo.height, unitSize);
  4932. if (geo.height / unitSize > 1)
  4933. {
  4934. var mod = geo.height % unitSize;
  4935. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  4936. }
  4937. this.graph.getModel().setGeometry(child, geo);
  4938. };
  4939. rackLayout.fill = true;
  4940. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  4941. rackLayout.marginLeft = style['marginLeft'] || 0;
  4942. rackLayout.marginRight = style['marginRight'] || 0;
  4943. rackLayout.marginTop = style['marginTop'] || 0;
  4944. rackLayout.marginBottom = style['marginBottom'] || 0;
  4945. rackLayout.resizeParent = false;
  4946. return rackLayout;
  4947. }
  4948. return layoutManagerGetLayout.apply(this, arguments);
  4949. }
  4950. };
  4951. /**
  4952. * Specifies special libraries that are loaded via dynamic JS.
  4953. *
  4954. *************************************************************
  4955. * IMPORTANT: Add all special cases in EmbedServlet.java and *
  4956. * jgraphcms/js/Graph.js lines 102 ff. *
  4957. *************************************************************
  4958. */
  4959. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  4960. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  4961. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  4962. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  4963. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  4964. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  4965. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  4966. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  4967. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  4968. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  4969. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  4970. mxStencilRegistry.libraries['eeLogicGates'] = [STENCIL_PATH + '/electrical/logic_gates.xml'];
  4971. mxStencilRegistry.libraries['eeResistors'] = [STENCIL_PATH + '/electrical/resistors.xml'];
  4972. mxStencilRegistry.libraries['eeCapacitors'] = [STENCIL_PATH + '/electrical/capacitors.xml'];
  4973. mxStencilRegistry.libraries['eeInductors'] = [STENCIL_PATH + '/electrical/inductors.xml'];
  4974. mxStencilRegistry.libraries['eeSwitchesRelays'] = [STENCIL_PATH + '/electrical/switchesRelays.xml', STENCIL_PATH + '/electrical/electro-mechanical.xml'];
  4975. mxStencilRegistry.libraries['eeDiodes'] = [STENCIL_PATH + '/electrical/diodes.xml'];
  4976. mxStencilRegistry.libraries['eeSources'] = [STENCIL_PATH + '/electrical/signal_sources.xml'];
  4977. mxStencilRegistry.libraries['eeTransistors'] = [STENCIL_PATH + '/electrical/mosfets1.xml', STENCIL_PATH + '/electrical/mosfets2.xml', STENCIL_PATH + '/electrical/transistors.xml'];
  4978. mxStencilRegistry.libraries['eeMisc'] = [STENCIL_PATH + '/electrical/electro-mechanical.xml', STENCIL_PATH + '/electrical/miscellaneous.xml'];
  4979. mxStencilRegistry.libraries['eeAudio'] = [STENCIL_PATH + '/electrical/radio.xml'];
  4980. mxStencilRegistry.libraries['eePlcLadder'] = [STENCIL_PATH + '/electrical/plc_ladder.xml'];
  4981. mxStencilRegistry.libraries['eeAbstract'] = [STENCIL_PATH + '/electrical/abstract.xml', STENCIL_PATH + '/electrical/logic_gates.xml'];
  4982. mxStencilRegistry.libraries['eeOptical'] = [STENCIL_PATH + '/electrical/opto_electronics.xml'];
  4983. mxStencilRegistry.libraries['eeVacuumTubes'] = [STENCIL_PATH + '/electrical/vacuum_tubes.xml'];
  4984. mxStencilRegistry.libraries['eeWaveforms'] = [STENCIL_PATH + '/electrical/waveforms.xml'];
  4985. mxStencilRegistry.libraries['eeInstruments'] = [STENCIL_PATH + '/electrical/instruments.xml'];
  4986. mxStencilRegistry.libraries['mscae/cloud'] = [STENCIL_PATH + '/mscae/cloud.xml'];
  4987. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  4988. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  4989. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  4990. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  4991. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  4992. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  4993. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  4994. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  4995. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  4996. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  4997. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  4998. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  4999. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  5000. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  5001. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  5002. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  5003. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  5004. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  5005. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  5006. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  5007. mxStencilRegistry.libraries['citrix'] = [STENCIL_PATH + '/citrix.xml'];
  5008. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  5009. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  5010. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  5011. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  5012. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  5013. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  5014. // Triggers dynamic loading for markers
  5015. mxMarker.getPackageForType = function(type)
  5016. {
  5017. var name = null;
  5018. if (type != null && type.length > 0)
  5019. {
  5020. if (type.substring(0, 2) == 'ER')
  5021. {
  5022. name = 'mxgraph.er';
  5023. }
  5024. else if (type.substring(0, 5) == 'sysML')
  5025. {
  5026. name = 'mxgraph.sysml';
  5027. }
  5028. }
  5029. return name;
  5030. };
  5031. var mxMarkerCreateMarker = mxMarker.createMarker;
  5032. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  5033. {
  5034. if (type != null)
  5035. {
  5036. var f = mxMarker.markers[type];
  5037. if (f == null)
  5038. {
  5039. var name = this.getPackageForType(type);
  5040. if (name != null)
  5041. {
  5042. mxStencilRegistry.getStencil(name);
  5043. }
  5044. }
  5045. }
  5046. return mxMarkerCreateMarker.apply(this, arguments);
  5047. };
  5048. })();