App.js 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. /**
  6. * Constructs a new point for the optional x and y coordinates. If no
  7. * coordinates are given, then the default values for <x> and <y> are used.
  8. * @constructor
  9. * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
  10. * @param {number} x X-coordinate of the point.
  11. * @param {number} y Y-coordinate of the point.
  12. */
  13. App = function(editor, container, lightbox)
  14. {
  15. EditorUi.call(this, editor, container, (lightbox != null) ? lightbox : urlParams['lightbox'] == '1');
  16. // Pre-fetches images
  17. if (mxClient.IS_SVG)
  18. {
  19. mxGraph.prototype.warningImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAE7SURBVHjaYvz//z8DJQAggBjwGXDuHMP/tWuD/uPTCxBAOA0AaQRK/f/+XeJ/cbHlf1wGAAQQTgPu3QNLgfHSpZo4DQAIIKwGwGyH4e/fFbG6AiQJEEAs2Ew2NFzH8OOHBMO6dT/A/KCg7wxGRh+wuhQggDBcALMdFIAcHBxgDGJjcwVIIUAAYbhAUXEdVos4OO4DXcGBIQ4QQCguQPY7sgtgAYruCpAgQACx4LJdU1OCwctLEcyWlLwPJF+AXQE0EMUBAAEEdwF6yMOiD4RRY0QT7gqQAEAAseDzu6XldYYPH9DD4joQa8L5AAEENgWb7SBcXa0JDQMBrK4AcQACiAlfyOMCEFdAnAYQQEz4FLa0XGf4/v0H0IIPONUABBAjyBmMjIwMS5cK/L927QORbtBkaG29DtYLEGAAH6f7oq3Zc+kAAAAASUVORK5CYII=';
  20. }
  21. else
  22. {
  23. var img = new Image();
  24. img.src = mxGraph.prototype.warningImage.src;
  25. }
  26. // Global helper method to deal with popup blockers
  27. window.openWindow = mxUtils.bind(this, function(url, pre, fallback)
  28. {
  29. var wnd = null;
  30. try
  31. {
  32. wnd = window.open(url);
  33. }
  34. catch (e)
  35. {
  36. // ignore
  37. }
  38. if (wnd == null || wnd === undefined)
  39. {
  40. this.showDialog(new PopupDialog(this, url, pre, fallback).container, 320, 140, true, true);
  41. }
  42. else if (pre != null)
  43. {
  44. pre();
  45. }
  46. });
  47. // Initial state for toolbar items is disabled
  48. this.updateDocumentTitle();
  49. this.updateUi();
  50. // Checks if canvas is supported
  51. var cnv = document.createElement('canvas');
  52. this.canvasSupported = !!(cnv.getContext && cnv.getContext('2d'));
  53. // Global helper method to display error messages
  54. window.showOpenAlert = mxUtils.bind(this, function(message)
  55. {
  56. // Cancel must be called before showing error message
  57. if (window.openFile != null)
  58. {
  59. window.openFile.cancel(true);
  60. }
  61. this.handleError(message);
  62. });
  63. // Sets help link for placeholders
  64. if (!this.isOffline())
  65. {
  66. EditDataDialog.placeholderHelpLink = 'https://desk.draw.io/support/solutions/articles/16000051979';
  67. }
  68. // Handles opening files via drag and drop
  69. this.addFileDropHandler([document]);
  70. // Process the queue for waiting plugins
  71. if (App.DrawPlugins != null)
  72. {
  73. for (var i = 0; i < App.DrawPlugins.length; i++)
  74. {
  75. try
  76. {
  77. App.DrawPlugins[i](this);
  78. }
  79. catch (e)
  80. {
  81. if (window.console != null)
  82. {
  83. console.log('Plugin Error:', e, App.DrawPlugins[i]);
  84. }
  85. }
  86. }
  87. // Installs global callback for plugins
  88. window.Draw.loadPlugin = mxUtils.bind(this, function(callback)
  89. {
  90. callback(this);
  91. });
  92. }
  93. this.load();
  94. };
  95. /**
  96. * Executes the first step for connecting to Google Drive.
  97. */
  98. App.ERROR_TIMEOUT = 'timeout';
  99. /**
  100. * Executes the first step for connecting to Google Drive.
  101. */
  102. App.ERROR_BUSY = 'busy';
  103. /**
  104. * Executes the first step for connecting to Google Drive.
  105. */
  106. App.ERROR_UNKNOWN = 'unknown';
  107. /**
  108. * Sets the delay for autosave in milliseconds. Default is 2000.
  109. */
  110. App.MODE_GOOGLE = 'google';
  111. /**
  112. * Sets the delay for autosave in milliseconds. Default is 2000.
  113. */
  114. App.MODE_DROPBOX = 'dropbox';
  115. /**
  116. * Sets the delay for autosave in milliseconds. Default is 2000.
  117. */
  118. App.MODE_ONEDRIVE = 'onedrive';
  119. /**
  120. * Sets the delay for autosave in milliseconds. Default is 2000.
  121. */
  122. App.MODE_GITHUB = 'github';
  123. /**
  124. * Sets the delay for autosave in milliseconds. Default is 2000.
  125. */
  126. App.MODE_DEVICE = 'device';
  127. /**
  128. * Sets the delay for autosave in milliseconds. Default is 2000.
  129. */
  130. App.MODE_BROWSER = 'browser';
  131. /**
  132. * Trello App Mode
  133. */
  134. App.MODE_TRELLO = 'trello';
  135. /**
  136. * Sets the delay for autosave in milliseconds. Default is 2000.
  137. */
  138. App.DROPBOX_APPKEY = 'libwls2fa9szdji';
  139. /**
  140. * Sets the delay for autosave in milliseconds. Default is 2000.
  141. */
  142. App.DROPBOX_URL = 'https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js';
  143. /**
  144. * Sets the delay for autosave in milliseconds. Default is 2000.
  145. */
  146. App.DROPINS_URL = 'https://www.dropbox.com/static/api/2/dropins.js';
  147. /**
  148. * Sets the delay for autosave in milliseconds. Default is 2000.
  149. */
  150. App.ONEDRIVE_URL = 'https://js.live.net/v7.2/OneDrive.js';
  151. /**
  152. * Trello URL
  153. */
  154. App.TRELLO_URL = 'https://api.trello.com/1/client.js';
  155. /**
  156. * Trello JQuery dependency
  157. */
  158. App.TRELLO_JQUERY_URL = 'https://code.jquery.com/jquery-1.7.1.min.js';
  159. /**
  160. * Defines plugin IDs for loading via p URL parameter. Update the table at
  161. * https://desk.draw.io/solution/articles/16000042546
  162. */
  163. App.pluginRegistry = {'4xAKTrabTpTzahoLthkwPNUn': '/plugins/explore.js',
  164. 'ex': '/plugins/explore.js', 'p1': '/plugins/p1.js', 'ac': '/plugins/connect.js',
  165. 'acj': '/plugins/connectJira.js', 'voice': '/plugins/voice.js',
  166. 'tips': '/plugins/tooltips.js', 'svgdata': '/plugins/svgdata.js',
  167. 'doors': '/plugins/doors.js', 'electron': 'plugins/electron.js',
  168. 'number': '/plugins/number.js', 'sql': '/plugins/sql.js',
  169. 'props': '/plugins/props.js', 'text': '/plugins/text.js',
  170. 'anim': '/plugins/animation.js', 'update': '/plugins/update.js',
  171. 'trees': '/plugins/trees/trees.js', 'import': '/plugins/import.js',
  172. 'replay': '/plugins/replay.js', 'anon': '/plugins/anonymize.js'};
  173. /**
  174. * Function: authorize
  175. *
  176. * Authorizes the client, gets the userId and calls <open>.
  177. */
  178. App.getStoredMode = function()
  179. {
  180. var mode = null;
  181. if (mode == null && isLocalStorage)
  182. {
  183. mode = localStorage.getItem('.mode');
  184. }
  185. if (mode == null && typeof(Storage) != 'undefined')
  186. {
  187. var cookies = document.cookie.split(";");
  188. for (var i = 0; i < cookies.length; i++)
  189. {
  190. // Removes spaces around cookie
  191. var cookie = mxUtils.trim(cookies[i]);
  192. if (cookie.substring(0, 5) == 'MODE=')
  193. {
  194. mode = cookie.substring(5);
  195. break;
  196. }
  197. }
  198. if (mode != null && isLocalStorage)
  199. {
  200. // Moves to local storage
  201. var expiry = new Date();
  202. expiry.setYear(expiry.getFullYear() - 1);
  203. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  204. localStorage.setItem('.mode', mode);
  205. }
  206. }
  207. return mode;
  208. };
  209. /**
  210. * Static Application initializer executed at load-time.
  211. */
  212. (function()
  213. {
  214. if (!mxClient.IS_CHROMEAPP)
  215. {
  216. if (urlParams['offline'] != '1')
  217. {
  218. // Switches to dropbox mode for db.draw.io
  219. if (window.location.hostname == 'db.draw.io' && urlParams['mode'] == null)
  220. {
  221. urlParams['mode'] = 'dropbox';
  222. }
  223. App.mode = urlParams['mode'];
  224. if (App.mode == null)
  225. {
  226. // Stored mode overrides preferred mode
  227. App.mode = App.getStoredMode();
  228. }
  229. }
  230. /**
  231. * Lazy loading backends.
  232. */
  233. if (window.mxscript != null)
  234. {
  235. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  236. if (urlParams['embed'] != '1')
  237. {
  238. if (typeof window.DriveClient === 'function')
  239. {
  240. if (urlParams['gapi'] != '0' && isSvgBrowser &&
  241. (document.documentMode == null || document.documentMode >= 10))
  242. {
  243. // Immediately loads client
  244. if (App.mode == App.MODE_GOOGLE || (urlParams['state'] != null &&
  245. window.location.hash == '') || (window.location.hash != null &&
  246. window.location.hash.substring(0, 2) == '#G'))
  247. {
  248. mxscript('https://apis.google.com/js/api.js');
  249. }
  250. // Keeps lazy loading for fallback to authenticated Google file if not public in loadFile
  251. else if (urlParams['chrome'] == '0' && (window.location.hash == null ||
  252. window.location.hash.substring(0, 45) !== '#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D'))
  253. {
  254. // Disables loading of client
  255. window.DriveClient = null;
  256. }
  257. }
  258. else
  259. {
  260. // Disables loading of client
  261. window.DriveClient = null;
  262. }
  263. }
  264. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  265. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  266. if (typeof window.DropboxClient === 'function')
  267. {
  268. if (urlParams['db'] != '0' && isSvgBrowser &&
  269. (document.documentMode == null || document.documentMode > 9))
  270. {
  271. // Immediately loads client
  272. if (App.mode == App.MODE_DROPBOX || (window.location.hash != null &&
  273. window.location.hash.substring(0, 2) == '#D'))
  274. {
  275. mxscript(App.DROPBOX_URL);
  276. // Must load this after the dropbox SDK since they use the same namespace
  277. mxscript(App.DROPINS_URL, null, 'dropboxjs', App.DROPBOX_APPKEY);
  278. }
  279. else if (urlParams['chrome'] == '0')
  280. {
  281. window.DropboxClient = null;
  282. }
  283. }
  284. else
  285. {
  286. // Disables loading of client
  287. window.DropboxClient = null;
  288. }
  289. }
  290. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  291. if (typeof window.OneDriveClient === 'function')
  292. {
  293. if (urlParams['od'] != '0' && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))
  294. {
  295. // Immediately loads client
  296. if (App.mode == App.MODE_ONEDRIVE || (window.location.hash != null &&
  297. window.location.hash.substring(0, 2) == '#W'))
  298. {
  299. mxscript(App.ONEDRIVE_URL);
  300. }
  301. else if (urlParams['chrome'] == '0')
  302. {
  303. window.OneDriveClient = null;
  304. }
  305. }
  306. else
  307. {
  308. // Disables loading of client
  309. window.OneDriveClient = null;
  310. }
  311. }
  312. // Loads Trello for all browsers but < IE10 if not disabled or if enabled and in embed mode
  313. if (typeof window.TrelloClient === 'function')
  314. {
  315. if (urlParams['tr'] != '0' && isSvgBrowser &&
  316. (document.documentMode == null || document.documentMode >= 10))
  317. {
  318. // Immediately loads client
  319. if (App.mode == App.MODE_TRELLO || (window.location.hash != null &&
  320. window.location.hash.substring(0, 2) == '#T'))
  321. {
  322. mxscript(App.TRELLO_JQUERY_URL);
  323. mxscript(App.TRELLO_URL);
  324. }
  325. else if (urlParams['chrome'] == '0')
  326. {
  327. window.TrelloClient = null;
  328. }
  329. }
  330. else
  331. {
  332. // Disables loading of client
  333. window.TrelloClient = null;
  334. }
  335. }
  336. }
  337. // Loads JSON for older browsers
  338. if (typeof(JSON) == 'undefined')
  339. {
  340. mxscript('js/json/json2.min.js');
  341. }
  342. }
  343. }
  344. })();
  345. /**
  346. * Program flow starts here.
  347. *
  348. * Optional callback is called with the app instance.
  349. */
  350. App.main = function(callback)
  351. {
  352. var lastErrorMessage = null;
  353. // Changes top level error handling
  354. if (EditorUi.enableLogging)
  355. {
  356. window.onerror = function(message, url, linenumber, colno, err)
  357. {
  358. try
  359. {
  360. if (message == lastErrorMessage || (message != null && url != null &&
  361. ((message.indexOf('Script error') != -1) || (message.indexOf('extension') != -1))))
  362. {
  363. // TODO log external domain script failure "Script error." is
  364. // reported when the error occurs in a script that is hosted
  365. // on a domain other than the domain of the current page
  366. }
  367. // DocumentClosedError seems to be an FF bug an can be ignored for now
  368. else if (message != null && message.indexOf('DocumentClosedError') < 0)
  369. {
  370. lastErrorMessage = message;
  371. var img = new Image();
  372. var severity = (message.indexOf('NetworkError') >= 0 || message.indexOf('SecurityError') >= 0 ||
  373. message.indexOf('NS_ERROR_FAILURE') >= 0 || message.indexOf('out of memory') >= 0) ?
  374. 'CONFIG' : 'SEVERE';
  375. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  376. img.src = logDomain + '/log?severity=' + severity + '&v=' + encodeURIComponent(EditorUi.VERSION) +
  377. '&msg=clientError:' + encodeURIComponent(message) + ':url:' + encodeURIComponent(window.location.href) +
  378. ':lnum:' + encodeURIComponent(linenumber) +
  379. ((colno != null) ? ':colno:' + encodeURIComponent(colno) : '') +
  380. ((err != null && err.stack != null) ? '&stack=' + encodeURIComponent(err.stack) : '');
  381. }
  382. }
  383. catch (err)
  384. {
  385. // do nothing
  386. }
  387. };
  388. }
  389. /**
  390. * Lazy loading of additional CSS for atlas theme.
  391. */
  392. if (uiTheme == 'atlas')
  393. {
  394. mxClient.link('stylesheet', 'styles/atlas.css');
  395. }
  396. if (window.mxscript != null)
  397. {
  398. /**
  399. * Color dialog - Do not add to app.min.js due to path issues!
  400. */
  401. if (urlParams['chrome'] != '0')
  402. {
  403. mxscript('js/jscolor/jscolor.js');
  404. }
  405. /**
  406. * Injects offline dependencies
  407. */
  408. if (urlParams['offline'] == '1')
  409. {
  410. mxscript('js/shapes.min.js');
  411. var frame = document.createElement('iframe');
  412. frame.setAttribute('width', '0');
  413. frame.setAttribute('height', '0');
  414. frame.setAttribute('src', 'offline.html');
  415. document.body.appendChild(frame);
  416. // Precaching for stencils. Alternatively we could generate
  417. // a cache manifest with all stencil and shape files but this
  418. // simplifies the cache file, streamlines the shape loading
  419. // to a single loading point (here) vs dynamic loading in the
  420. // online version. It does slow down the startup time though.
  421. mxStencilRegistry.stencilSet = {};
  422. // Overrides dynamic loading (everything loaded at startup)
  423. mxStencilRegistry.getStencil = function(name)
  424. {
  425. return mxStencilRegistry.stencils[name];
  426. };
  427. // Takes stencil data from cache for populating sidebar
  428. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force)
  429. {
  430. var name = stencilFile.substring(stencilFile.indexOf('/') + 1);
  431. name = 'mxgraph.' + name.substring(0, name.length - 4).replace(/\//g, '.');
  432. var node = mxStencilRegistry.stencilSet[name];
  433. if (node != null)
  434. {
  435. mxStencilRegistry.parseStencilSet(node, postStencilLoad, false);
  436. }
  437. };
  438. // Preload all stencils from merged XML file
  439. var req2 = mxUtils.load('stencils.xml');
  440. var root = req2.getXml().documentElement;
  441. var node = root.firstChild;
  442. while (node != null)
  443. {
  444. if (node.nodeName == 'shapes' && node.getAttribute('name') != null)
  445. {
  446. mxStencilRegistry.stencilSet[node.getAttribute('name').toLowerCase()] = node;
  447. mxStencilRegistry.parseStencilSet(node);
  448. }
  449. node = node.nextSibling;
  450. }
  451. }
  452. /**
  453. * Loads Google Image Picker API (not allowed inside iframes)
  454. */
  455. if (urlParams['picker'] != '0' && !mxClient.IS_QUIRKS && document.documentMode != 8)
  456. {
  457. mxscript(document.location.protocol + '//www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22picker%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' + mxClient.language + '%22%7D%5D%7D');
  458. }
  459. /**
  460. * Loading plugins.
  461. */
  462. if (urlParams['plugins'] != '0' && urlParams['offline'] != '1')
  463. {
  464. var plugins = mxSettings.getPlugins();
  465. var temp = urlParams['p'];
  466. if ((temp != null) || (plugins != null && plugins.length > 0))
  467. {
  468. App.initPluginCallback();
  469. }
  470. if (temp != null)
  471. {
  472. // Used to request draw.io sources in dev mode
  473. var drawDevUrl = '';
  474. if (urlParams['drawdev'] == '1')
  475. {
  476. drawDevUrl = document.location.protocol + '//drawhost.jgraph.com/';
  477. }
  478. // Mapping from key to URL in App.plugins
  479. var t = temp.split(';');
  480. for (var i = 0; i < t.length; i++)
  481. {
  482. var url = App.pluginRegistry[t[i]];
  483. if (url != null)
  484. {
  485. mxscript(drawDevUrl + url);
  486. }
  487. else if (window.console != null)
  488. {
  489. console.log('Unknown plugin:', t[i]);
  490. }
  491. }
  492. }
  493. if (plugins != null && plugins.length > 0 && urlParams['plugins'] != '0')
  494. {
  495. // Loading plugins inside the asynchronous block below stops the page from loading so a
  496. // hardcoded message for the warning dialog is used since the resources are loadd below
  497. var warning = 'The page has requested to load the following plugin(s):\n \n {1}\n \n Would you like to load these plugin(s) now?\n \n NOTE : Only allow plugins to run if you fully understand the security implications of doing so.\n';
  498. var tmp = window.location.protocol + '//' + window.location.host;
  499. var local = true;
  500. for (var i = 0; i < plugins.length && local; i++)
  501. {
  502. if (plugins[i].charAt(0) != '/' && plugins[i].substring(0, tmp.length) != tmp)
  503. {
  504. local = false;
  505. }
  506. }
  507. if (local || mxUtils.confirm(mxResources.replacePlaceholders(warning, [plugins.join('\n')]).replace(/\\n/g, '\n')))
  508. {
  509. for (var i = 0; i < plugins.length; i++)
  510. {
  511. try
  512. {
  513. mxscript(plugins[i]);
  514. }
  515. catch (e)
  516. {
  517. // ignore
  518. }
  519. }
  520. }
  521. }
  522. }
  523. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  524. // Special case: Cannot load in asynchronous code below
  525. if (typeof window.DriveClient === 'function' &&
  526. (typeof gapi === 'undefined' && (((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  527. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && isSvgBrowser &&
  528. isLocalStorage && (document.documentMode == null || document.documentMode >= 10))))
  529. {
  530. mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback');
  531. }
  532. // Disables client
  533. else if (typeof window.gapi === 'undefined')
  534. {
  535. window.DriveClient = null;
  536. }
  537. }
  538. /**
  539. * Asynchronous MathJax extension.
  540. */
  541. if (urlParams['math'] != '0')
  542. {
  543. Editor.initMath();
  544. }
  545. // Adds required resources (disables loading of fallback properties, this can only
  546. // be used if we know that all keys are defined in the language specific file)
  547. mxResources.loadDefaultBundle = false;
  548. var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
  549. mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);
  550. // Prefetches asynchronous requests so that below code runs synchronous
  551. // Loading the correct bundle (one file) via the fallback system in mxResources. The stylesheet
  552. // is compiled into JS in the build process and is only needed for local development.
  553. mxUtils.getAll((urlParams['dev'] != '1') ? [bundle] : [bundle, STYLE_PATH + '/default.xml'], function(xhr)
  554. {
  555. // Adds bundle text to resources
  556. mxResources.parse(xhr[0].getText());
  557. // Prepares themes with mapping from old default-style to old XML file
  558. if (xhr.length > 1)
  559. {
  560. Graph.prototype.defaultThemes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();
  561. }
  562. // Main
  563. var ui = new App(new Editor(urlParams['chrome'] == '0'));
  564. if (window.mxscript != null)
  565. {
  566. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  567. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  568. if (typeof window.DropboxClient === 'function' &&
  569. (window.Dropbox == null && window.DrawDropboxClientCallback != null &&
  570. (((urlParams['embed'] != '1' && urlParams['db'] != '0') ||
  571. (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  572. isSvgBrowser && (document.documentMode == null || document.documentMode > 9))))
  573. {
  574. mxscript(App.DROPBOX_URL, function()
  575. {
  576. // Must load this after the dropbox SDK since they use the same namespace
  577. mxscript(App.DROPINS_URL, function()
  578. {
  579. DrawDropboxClientCallback();
  580. }, 'dropboxjs', App.DROPBOX_APPKEY);
  581. });
  582. }
  583. // Disables client
  584. else if (typeof window.Dropbox === 'undefined' || typeof window.Dropbox.choose === 'undefined')
  585. {
  586. window.DropboxClient = null;
  587. }
  588. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  589. if (typeof window.OneDriveClient === 'function' &&
  590. (typeof OneDrive === 'undefined' && window.DrawOneDriveClientCallback != null &&
  591. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  592. urlParams['od'] == '1')) && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  593. {
  594. mxscript(App.ONEDRIVE_URL, window.DrawOneDriveClientCallback);
  595. }
  596. // Disables client
  597. else if (typeof window.OneDrive === 'undefined')
  598. {
  599. window.OneDriveClient = null;
  600. }
  601. // Loads Trello for all browsers but < IE10 if not disabled or if enabled and in embed mode
  602. if (typeof window.TrelloClient === 'function' &&
  603. (typeof window.Trello === 'undefined' && window.DrawTrelloClientCallback != null &&
  604. (((urlParams['embed'] != '1' && urlParams['tr'] != '0') || (urlParams['embed'] == '1' &&
  605. urlParams['tr'] == '1')) && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  606. {
  607. mxscript(App.TRELLO_JQUERY_URL, function()
  608. {
  609. // Must load this after the dropbox SDK since they use the same namespace
  610. mxscript(App.TRELLO_URL, function()
  611. {
  612. DrawTrelloClientCallback();
  613. });
  614. });
  615. }
  616. // Disables client
  617. else if (typeof window.Trello === 'undefined')
  618. {
  619. window.TrelloClient = null;
  620. }
  621. }
  622. if (callback != null)
  623. {
  624. callback(ui);
  625. }
  626. /**
  627. * For developers only
  628. */
  629. if (urlParams['chrome'] != '0' && urlParams['test'] == '1')
  630. {
  631. mxLog.show();
  632. mxLog.debug('Started in ' + (new Date().getTime() - t0.getTime()) + 'ms');
  633. mxLog.debug('Export:', EXPORT_URL);
  634. mxLog.debug('Development mode:', (urlParams['dev'] == '1') ? 'active' : 'inactive');
  635. mxLog.debug('Test mode:', (urlParams['test'] == '1') ? 'active' : 'inactive');
  636. }
  637. }, function()
  638. {
  639. document.getElementById('geStatus').innerHTML = 'Error loading page. <a href="javascript:void(0);" onclick="location.reload();">Please try refreshing.</a>';
  640. });
  641. };
  642. //Extends EditorUi
  643. mxUtils.extend(App, EditorUi);
  644. /**
  645. * Executes the first step for connecting to Google Drive.
  646. */
  647. App.prototype.defaultUserPicture = 'https://lh3.googleusercontent.com/-HIzvXUy6QUY/AAAAAAAAAAI/AAAAAAAAAAA/giuR7PQyjEk/photo.jpg?sz=30';
  648. /**
  649. *
  650. */
  651. App.prototype.shareImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDowOTgwMTE3NDA3MjA2ODExODhDNkFGMDBEQkQ0RTgwOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxMjU2NzdEMTcwRDIxMUUxQjc0MDkxRDhCNUQzOEFGRCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxMjU2NzdEMDcwRDIxMUUxQjc0MDkxRDhCNUQzOEFGRCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowNjgwMTE3NDA3MjA2ODExODcxRkM4MUY1OTFDMjQ5OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowNzgwMTE3NDA3MjA2ODExODhDNkFGMDBEQkQ0RTgwOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrM/fs0AAADgSURBVHjaYmDAA/7//88MwgzkAKDGFiD+BsQ/QWxSNaf9RwN37twpI8WAS+gGfP78+RpQSoRYA36iG/D379+vQClNdLVMOMz4gi7w79+/n0CKg1gD9qELvH379hzIHGK9oA508ieY8//8+fO5rq4uFCilRKwL1JmYmNhhHEZGRiZ+fn6Q2meEbDYG4u3/cYCfP38uA7kOm0ZOIJ7zn0jw48ePPiDFhmzArv8kgi9fvuwB+w5qwH9ykjswbFSZyM4sEMDPBDTlL5BxkFSd7969OwZ2BZKYGhDzkmjOJ4AAAwBhpRqGnEFb8QAAAABJRU5ErkJggg==';
  652. /**
  653. *
  654. */
  655. App.prototype.chevronUpImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-up.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUY1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NjA1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1RDUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1RTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pg+qUokAAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAAL0lEQVR42mJgRgMMRAswMKAKMDDARBjg8lARBoR6KImkH0wTbygT6YaS4DmAAAMAYPkClOEDDD0AAAAASUVORK5CYII=';
  656. /**
  657. *
  658. */
  659. App.prototype.chevronDownImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-down.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUI1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NUM1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1OTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1QTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsCtve8AAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAALUlEQVR42mJgRgMMRAkwQEXBNAOcBSPhclB1cNVwfcxI+vEZykSpoSR6DiDAAF23ApT99bZ+AAAAAElFTkSuQmCC';
  660. /**
  661. *
  662. */
  663. App.prototype.formatShowImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-show.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REY1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5RTA1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlERDU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlERTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlnMQ/8AAAAJUExURQAAAP///3FxcTfTiAsAAAACdFJOU/8A5bcwSgAAACFJREFUeNpiYEQDDEQJMMABTAAixcQ00ALoDiPRcwABBgB6DADly9Yx8wAAAABJRU5ErkJggg==';
  664. /**
  665. *
  666. */
  667. App.prototype.formatHideImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-hide.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REI1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5REM1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlEOTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlEQTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqjT9SMAAAAGUExURQAAAP///6XZn90AAAACdFJOU/8A5bcwSgAAAB9JREFUeNpiYEQDDEQJMMABTAAmNdAC6A4j0XMAAQYAcbwA1Xvj1CgAAAAASUVORK5CYII=';
  668. /**
  669. *
  670. */
  671. App.prototype.fullscreenImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/fullscreen.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAAAAAClZ7nPAAAAAXRSTlMAQObYZgAAABpJREFUCNdjgAAbGxAy4AEh5gNwBBGByoIBAIueBd12TUjqAAAAAElFTkSuQmCC';
  672. /**
  673. * Executes the first step for connecting to Google Drive.
  674. */
  675. App.prototype.timeout = 25000;
  676. /**
  677. * Overriden UI settings depending on mode.
  678. */
  679. if (urlParams['embed'] != '1')
  680. {
  681. App.prototype.menubarHeight = 60;
  682. }
  683. /**
  684. * Queue for loading plugins and wait for UI instance
  685. */
  686. App.initPluginCallback = function()
  687. {
  688. if (App.DrawPlugins == null)
  689. {
  690. // Workaround for need to load plugins now but wait for UI instance
  691. App.DrawPlugins = [];
  692. // Global entry point for plugins is Draw.loadPlugin. This is the only
  693. // long-term supported solution for access to the EditorUi instance.
  694. window.Draw = new Object();
  695. window.Draw.loadPlugin = function(callback)
  696. {
  697. App.DrawPlugins.push(callback);
  698. };
  699. }
  700. };
  701. /**
  702. * Translates this point by the given vector.
  703. *
  704. * @param {number} dx X-coordinate of the translation.
  705. * @param {number} dy Y-coordinate of the translation.
  706. */
  707. App.prototype.init = function()
  708. {
  709. EditorUi.prototype.init.apply(this, arguments);
  710. /**
  711. * Specifies the default filename.
  712. */
  713. this.defaultLibraryName = mxResources.get('untitledLibrary');
  714. /**
  715. * Holds the listener for description changes.
  716. */
  717. this.descriptorChangedListener = mxUtils.bind(this, this.descriptorChanged);
  718. /**
  719. * Basic adds for all backends.
  720. */
  721. this.basicAds = ['<a title="' + mxResources.get('loveIt', ['draw.io']) +
  722. '" target="_blank" href="https://twitter.com/intent/tweet?text=' +
  723. encodeURIComponent(mxResources.get('loveIt', ['www.draw.io'])) +
  724. '" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' +
  725. 'left=\'+((screen.width-640)/2)+\',top=\'+((screen.height-280)/3)+\',height=280,width=640\');return false;"\'>' +
  726. '<img border="0" align="absmiddle" width="18" height="18" style="margin-top:-2px;padding-right:8px;" src="' +
  727. Editor.tweetImage + '"/>' + mxResources.get('loveIt', ['draw.io']) + '</a>',
  728. '<a title="Share on Facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=' +
  729. encodeURIComponent('https://www.draw.io') +
  730. '" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' +
  731. 'left=\'+((screen.width-640)/2)+\',top=\'+((screen.height-520)/3)+\',height=520,width=640\');return false;"\'>' +
  732. '<img border="0" align="absmiddle" width="18" height="18" style="margin-top:-2px;padding-right:8px;" src="' +
  733. Editor.facebookImage + '"/>Share on Facebook</a>',
  734. '<a title="draw.io Offline" href="https://www.draw.io/app" target="_blank">' +
  735. '<img border="0" align="absmiddle" style="margin-top:-1px;padding-right:8px;" src="images/download.png"/>' +
  736. 'draw.io Offline</a>'];
  737. /**
  738. * Creates github client.
  739. */
  740. this.gitHub = (!mxClient.IS_IE || document.documentMode == 10 ||
  741. mxClient.IS_IE11 || mxClient.IS_EDGE) &&
  742. (urlParams['gh'] != '0' && (urlParams['embed'] != '1' ||
  743. urlParams['gh'] == '1')) ? new GitHubClient(this) : null;
  744. if (this.gitHub != null)
  745. {
  746. this.gitHub.addListener('userChanged', mxUtils.bind(this, function()
  747. {
  748. this.updateUserElement();
  749. this.restoreLibraries();
  750. }))
  751. }
  752. /**
  753. * Lazy-loading for individual backends
  754. */
  755. if (urlParams['embed'] != '1' || urlParams['od'] == '1')
  756. {
  757. /**
  758. * Creates onedrive client if all required libraries are available.
  759. */
  760. var initOneDriveClient = mxUtils.bind(this, function()
  761. {
  762. if (typeof OneDrive !== 'undefined')
  763. {
  764. /**
  765. * Holds the x-coordinate of the point.
  766. */
  767. this.oneDrive = new OneDriveClient(this);
  768. this.oneDrive.addListener('userChanged', mxUtils.bind(this, function()
  769. {
  770. this.updateUserElement();
  771. this.restoreLibraries();
  772. }));
  773. // Notifies listeners of new client
  774. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.oneDrive));
  775. }
  776. else if (window.DrawOneDriveClientCallback == null)
  777. {
  778. window.DrawOneDriveClientCallback = initOneDriveClient;
  779. }
  780. });
  781. initOneDriveClient();
  782. }
  783. /**
  784. * Lazy-loading for Trello
  785. */
  786. if (urlParams['embed'] != '1' || urlParams['tr'] == '1')
  787. {
  788. /**
  789. * Creates Trello client if all required libraries are available.
  790. */
  791. var initTrelloClient = mxUtils.bind(this, function()
  792. {
  793. if (typeof window.Trello !== 'undefined')
  794. {
  795. this.trello = new TrelloClient(this);
  796. //TODO we have no user info from Trello so we don't set a user
  797. this.trello.addListener('userChanged', mxUtils.bind(this, function()
  798. {
  799. this.updateUserElement();
  800. this.restoreLibraries();
  801. }));
  802. // Notifies listeners of new client
  803. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.trello));
  804. }
  805. else if (window.DrawTrelloClientCallback == null)
  806. {
  807. window.DrawTrelloClientCallback = initTrelloClient;
  808. }
  809. });
  810. initTrelloClient();
  811. }
  812. /**
  813. * Creates drive client with all required libraries are available.
  814. */
  815. if (urlParams['embed'] != '1' || urlParams['gapi'] == '1')
  816. {
  817. var initDriveClient = mxUtils.bind(this, function()
  818. {
  819. /**
  820. * Creates google drive client if all required libraries are available.
  821. */
  822. if (typeof gapi !== 'undefined')
  823. {
  824. var doInit = mxUtils.bind(this, function()
  825. {
  826. /**
  827. * Holds the x-coordinate of the point.
  828. */
  829. this.drive = new DriveClient(this);
  830. /**
  831. * Adds important notice for new app if drive file is loaded in old app.
  832. */
  833. if (this.drive.appId == '420247213240')
  834. {
  835. this.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  836. {
  837. var file = this.getCurrentFile();
  838. if (file != null && file.constructor == DriveFile)
  839. {
  840. var td = document.getElementById('geFooterItem2');
  841. if (td != null)
  842. {
  843. td.innerHTML = '<a href="https://support.draw.io/display/DO/2014/11/27/Switching+application+in+Google+Drive" ' +
  844. 'target="_blank" title="IMPORTANT NOTICE" >IMPORTANT NOTICE</a>';
  845. }
  846. }
  847. }));
  848. }
  849. this.drive.addListener('userChanged', mxUtils.bind(this, function()
  850. {
  851. // Changes the footer ads for Google Accounts
  852. // if (this.updateAd != null)
  853. // {
  854. // this.adsHtml = this.basicAds.concat([
  855. // '<a title="Google Docs Add-on" href="https://chrome.google.com/webstore/detail/drawio-diagrams/clpbjldiohnnmfmkngmaohehlnfkmoea" target="_blank">' +
  856. // '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Google Docs Add-on</a>',
  857. // '<a title="Please help us to 5 stars" href="https://chrome.google.com/webstore/detail/drawio-pro/onlkggianjhjenigcpigpjehhpplldkc/reviews" target="_blank">' +
  858. // '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Please help us to 5 stars</a>']);
  859. // this.updateAd(this.adsHtml.length - 1);
  860. // }
  861. this.updateUserElement();
  862. this.restoreLibraries();
  863. this.checkLicense();
  864. }))
  865. // Notifies listeners of new client
  866. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.drive));
  867. });
  868. if (window.DrawGapiClientCallback != null)
  869. {
  870. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  871. {
  872. // Starts the app without the Google Option if the API fails to load
  873. if (gapi.drive != null && gapi.drive.realtime != null)
  874. {
  875. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  876. {
  877. this.defineCustomObjects();
  878. // Needed to avoid popup blocking for non-immediate authentication
  879. gapi.auth.init(mxUtils.bind(this, function()
  880. {
  881. if (gapi.client.drive != null)
  882. {
  883. doInit();
  884. }
  885. }));
  886. }));
  887. }
  888. }));
  889. /**
  890. * Clears any callbacks.
  891. */
  892. window.DrawGapiClientCallback = null;
  893. }
  894. else
  895. {
  896. doInit();
  897. }
  898. }
  899. else if (window.DrawGapiClientCallback == null)
  900. {
  901. window.DrawGapiClientCallback = initDriveClient;
  902. }
  903. });
  904. initDriveClient();
  905. }
  906. if (urlParams['embed'] != '1' || urlParams['db'] == '1')
  907. {
  908. /**
  909. * Creates dropbox client if all required libraries are available.
  910. */
  911. var initDropboxClient = mxUtils.bind(this, function()
  912. {
  913. if (typeof Dropbox === 'function' && typeof Dropbox.choose !== 'undefined')
  914. {
  915. /**
  916. * Clears dropbox client callback.
  917. */
  918. window.DrawDropboxClientCallback = null;
  919. /**
  920. * Holds the x-coordinate of the point.
  921. */
  922. this.dropbox = new DropboxClient(this);
  923. this.dropbox.addListener('userChanged', mxUtils.bind(this, function()
  924. {
  925. this.updateUserElement();
  926. this.restoreLibraries();
  927. }));
  928. // Notifies listeners of new client
  929. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.dropbox));
  930. }
  931. else if (window.DrawDropboxClientCallback == null)
  932. {
  933. window.DrawDropboxClientCallback = initDropboxClient;
  934. }
  935. });
  936. initDropboxClient();
  937. }
  938. if (urlParams['embed'] != '1')
  939. {
  940. /**
  941. * Holds the background element.
  942. */
  943. this.bg = this.createBackground();
  944. document.body.appendChild(this.bg);
  945. this.diagramContainer.style.visibility = 'hidden';
  946. this.formatContainer.style.visibility = 'hidden';
  947. this.hsplit.style.display = 'none';
  948. this.sidebarContainer.style.display = 'none';
  949. this.sidebarFooterContainer.style.display = 'none';
  950. // Sets the initial mode
  951. if (urlParams['local'] == '1')
  952. {
  953. this.setMode(App.MODE_DEVICE);
  954. }
  955. else
  956. {
  957. this.mode = App.mode;
  958. }
  959. }
  960. else if (this.menubar != null)
  961. {
  962. this.menubar.container.style.paddingTop = '0px';
  963. }
  964. this.updateHeader();
  965. var rotate = mxUtils.bind(this, function(elt, html, delay, fn)
  966. {
  967. delay = (delay != null) ? delay : 1000;
  968. mxUtils.setPrefixedStyle(elt.style, 'transition', 'all ' + (delay / 1000) + 's ease');
  969. mxUtils.setPrefixedStyle(elt.style, 'transform', 'scale(0)');
  970. elt.style.visibility = 'visible';
  971. elt.style.opacity = '0';
  972. window.setTimeout(mxUtils.bind(this, function()
  973. {
  974. elt.innerHTML = html;
  975. mxUtils.setPrefixedStyle(elt.style, 'transform', 'scale(1)');
  976. elt.style.opacity = '1';
  977. if (fn != null)
  978. {
  979. fn();
  980. }
  981. }), delay);
  982. });
  983. // Announce Desktop Apps
  984. var td2 = document.getElementById('geFooterItem1');
  985. if (td2 != null)
  986. {
  987. mxEvent.addListener(td2, 'click', mxUtils.bind(this, function()
  988. {
  989. if (typeof window.ga === 'function' && !this.isOffline())
  990. {
  991. ga('send', 'event', 'Footer', 'click', 'Confluence');
  992. }
  993. }));
  994. }
  995. // var link = 'https://download.draw.io/';
  996. // var lastHtml = td2.innerHTML;
  997. // var os = 'draw.io';
  998. //
  999. // if (['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].indexOf(navigator.platform) >= 0)
  1000. // {
  1001. // os += ' for macOS';
  1002. // }
  1003. // else if (['Win32', 'Win64', 'Windows', 'WinCE'].indexOf(navigator.platform) >= 0)
  1004. // {
  1005. // os += ' for Windows';
  1006. // }
  1007. // else if (/\bCrOS\b/.test(navigator.userAgent))
  1008. // {
  1009. // os += ' for Chrome OS';
  1010. // }
  1011. // else if (/Linux/.test(navigator.platform))
  1012. // {
  1013. // os += ' for Linux';
  1014. // }
  1015. // else
  1016. // {
  1017. // os += ' Desktop';
  1018. // }
  1019. //
  1020. // td2.innerHTML = '<a title="' + os + '" href="' + link + '" target="_blank">' +
  1021. // '<img border="0" align="absmiddle" style="margin-top:-4px;" width="24" height="24" ' +
  1022. // 'src="images/drawlogo48.png"/>&nbsp;&nbsp;' + os + '</a>';
  1023. //
  1024. // window.setInterval(mxUtils.bind(this, function()
  1025. // {
  1026. // var temp = lastHtml;
  1027. // lastHtml = td2.innerHTML;
  1028. // rotate(td2, temp);
  1029. // }), 300000);
  1030. // }
  1031. // Changes footer from time to time
  1032. var td = document.getElementById('geFooterItem2');
  1033. if (td != null && mxClient.IS_SVG)
  1034. {
  1035. td.innerHTML = '<a title="Collaborate on diagrams in Samepage" target="_blank" ' +
  1036. ((mxClient.IS_SF) ? 'style="margin-top:-22px;" ' : '') +
  1037. 'href="https://www.samepage.io/draw-diagram-online?SPcid=SIOF%2BDraw%2Breferral%2BDraw%2Bv1%2BNA"\>' +
  1038. '<img border="0" align="absmiddle" width="24" height="24" style="margin-top:-2px;padding-right:8px;" ' +
  1039. 'src="' + IMAGE_PATH + '/samepage-icon-color.svg"/>Collaborate on diagrams in Samepage</a>';
  1040. mxEvent.addListener(td, 'click', mxUtils.bind(this, function()
  1041. {
  1042. if (typeof window.ga === 'function' && !this.isOffline())
  1043. {
  1044. ga('send', 'event', 'Footer', 'click', 'Samepage');
  1045. }
  1046. }));
  1047. // this.basicAds.push(td.innerHTML);
  1048. // this.adsHtml = this.basicAds;
  1049. // var lastAd = this.adsHtml.length - 1;
  1050. // var thread2 = null;
  1051. // var thread = null;
  1052. //
  1053. // this.updateAd = function(index, delay)
  1054. // {
  1055. // if (thread != null)
  1056. // {
  1057. // window.clearTimeout(thread);
  1058. // thread = null;
  1059. // }
  1060. //
  1061. // if (thread2 != null)
  1062. // {
  1063. // window.clearTimeout(thread2);
  1064. // thread2 = null;
  1065. // }
  1066. //
  1067. // if (this.adsHtml.length == 0)
  1068. // {
  1069. // td.style.display = 'none';
  1070. // td.innerHTML = '';
  1071. // }
  1072. // else
  1073. // {
  1074. // var schedule = mxUtils.bind(this, function()
  1075. // {
  1076. // if (this.adsHtml.length > 0)
  1077. // {
  1078. // thread = window.setTimeout(mxUtils.bind(this, function()
  1079. // {
  1080. // var tmp = 0;
  1081. //
  1082. // if (this.adsHtml.length > 1)
  1083. // {
  1084. // tmp = Math.round(Math.random() * (this.adsHtml.length - 2));
  1085. //
  1086. // if (tmp == lastAd)
  1087. // {
  1088. // tmp++;
  1089. // }
  1090. // }
  1091. //
  1092. // this.updateAd(tmp);
  1093. // }), 180000);
  1094. // }
  1095. // });
  1096. //
  1097. // if (index != lastAd)
  1098. // {
  1099. // rotate(td, this.adsHtml[index], delay, function()
  1100. // {
  1101. // lastAd = index;
  1102. // schedule();
  1103. // });
  1104. // }
  1105. // else
  1106. // {
  1107. // schedule();
  1108. // }
  1109. // }
  1110. // };
  1111. //
  1112. // mxEvent.addListener(td, 'click', mxUtils.bind(this, function()
  1113. // {
  1114. // this.adsHtml.splice(lastAd, 1);
  1115. // lastAd = null;
  1116. // this.updateAd(0);
  1117. // }));
  1118. //
  1119. // if (mxSettings.getOpenCounter() > 10 && urlParams['embed'] != '1')
  1120. // {
  1121. // thread2 = window.setTimeout(mxUtils.bind(this, function()
  1122. // {
  1123. // this.updateAd(0);
  1124. // }), 15000);
  1125. // }
  1126. // else
  1127. // {
  1128. // this.updateAd(this.adsHtml.length - 1);
  1129. // }
  1130. }
  1131. if (this.menubar != null)
  1132. {
  1133. this.buttonContainer = document.createElement('div');
  1134. this.buttonContainer.style.display = 'inline-block';
  1135. this.buttonContainer.style.paddingRight = '48px';
  1136. this.buttonContainer.style.position = 'absolute';
  1137. this.buttonContainer.style.right = '0px';
  1138. this.menubar.container.appendChild(this.buttonContainer);
  1139. }
  1140. if (uiTheme == 'atlas' && this.menubar != null)
  1141. {
  1142. if (this.toggleElement != null)
  1143. {
  1144. this.toggleElement.click();
  1145. this.toggleElement.style.display = 'none';
  1146. }
  1147. this.icon = document.createElement('img');
  1148. this.icon.setAttribute('src', IMAGE_PATH + '/logo-flat-small.png');
  1149. this.icon.setAttribute('title', mxResources.get('draw.io'));
  1150. this.icon.style.paddingTop = '11px';
  1151. this.icon.style.marginLeft = '4px';
  1152. this.icon.style.marginRight = '6px';
  1153. if (mxClient.IS_QUIRKS)
  1154. {
  1155. this.icon.style.marginTop = '12px';
  1156. }
  1157. this.menubar.container.insertBefore(this.icon, this.menubar.container.firstChild);
  1158. }
  1159. };
  1160. /**
  1161. * Returns true if the current domain is for the new drive app.
  1162. */
  1163. App.prototype.isDriveDomain = function()
  1164. {
  1165. return urlParams['drive'] != '0' &&
  1166. (window.location.hostname == 'test.draw.io' ||
  1167. window.location.hostname == 'cdn.draw.io' ||
  1168. window.location.hostname == 'www.draw.io' ||
  1169. window.location.hostname == 'drive.draw.io' ||
  1170. window.location.hostname == 'jgraph.github.io');
  1171. };
  1172. /**
  1173. * Returns true if the current domain is for the old drive app.
  1174. */
  1175. App.prototype.isLegacyDriveDomain = function()
  1176. {
  1177. return urlParams['drive'] == 0 || window.location.hostname == 'legacy.draw.io';
  1178. };
  1179. /**
  1180. *
  1181. */
  1182. App.prototype.checkLicense = function()
  1183. {
  1184. var driveUser = this.drive.getUser();
  1185. var email = ((urlParams['dev'] == '1') ? urlParams['lic'] : null) ||
  1186. ((driveUser != null) ? driveUser.email : null);
  1187. if (!this.isOffline() && !this.editor.chromeless && email != null)
  1188. {
  1189. // Anonymises the local part of the email address
  1190. var at = email.lastIndexOf('@');
  1191. var domain = email;
  1192. if (at >= 0)
  1193. {
  1194. domain = email.substring(at + 1);
  1195. //email = this.crc32(email.substring(0, at)) + '@' + domain;
  1196. }
  1197. // Timestamp is workaround for cached response in certain environments
  1198. mxUtils.post('/license', 'domain=' + encodeURIComponent(domain) + '&email=' + encodeURIComponent(email) +
  1199. '&ds=' + encodeURIComponent(driveUser.displayName) + '&lc=' + encodeURIComponent(driveUser.locale) +
  1200. '&ts=' + new Date().getTime(),
  1201. mxUtils.bind(this, function(req)
  1202. {
  1203. var registered = false;
  1204. var exp = null;
  1205. try
  1206. {
  1207. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1208. {
  1209. var value = req.getText();
  1210. registered = true;
  1211. if (value.length > 0)
  1212. {
  1213. var lic = JSON.parse(value);
  1214. if (lic != null)
  1215. {
  1216. exp = this.handleLicense(lic, domain);
  1217. }
  1218. }
  1219. }
  1220. }
  1221. catch (e)
  1222. {
  1223. // ignore
  1224. }
  1225. }));
  1226. }
  1227. };
  1228. /**
  1229. * Returns true if the current domain is for the new drive app.
  1230. */
  1231. App.prototype.handleLicense = function(lic, domain)
  1232. {
  1233. var footer = document.getElementById('geFooter');
  1234. var expiry = null;
  1235. if (footer != null && lic != null)
  1236. {
  1237. expiry = lic.expiry;
  1238. if (lic.footer != null)
  1239. {
  1240. footer.innerHTML = decodeURIComponent(lic.footer);
  1241. }
  1242. else
  1243. {
  1244. this.hideFooter();
  1245. if (expiry != null && expiry != 'never')
  1246. {
  1247. var exp = new Date(Date.parse(expiry));
  1248. var diff = Math.round((exp - Date.now()) / (1000 * 60 * 60 * 24));
  1249. if (diff < 90)
  1250. {
  1251. var link = 'https://support.draw.io/display/DKB/draw.io+footer+state+that+license+is+expiring+on+Google+For+Work+account?domain=' + encodeURIComponent(domain);
  1252. footer.style.height = '100%';
  1253. footer.style.margin = '0px';
  1254. footer.style.display = '';
  1255. if (diff < 0)
  1256. {
  1257. this.footerHeight = 80;
  1258. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert geBlink">' +
  1259. '<a href="' + link + '" style="padding-top:16px;" target="_blank">' +
  1260. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1261. mxResources.get('licenseHasExpired', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1262. }
  1263. else
  1264. {
  1265. this.footerHeight = 46;
  1266. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert">' +
  1267. '<a href="' + link + '" target="_blank">' +
  1268. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1269. mxResources.get('licenseWillExpire', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1270. }
  1271. this.refresh();
  1272. }
  1273. }
  1274. }
  1275. }
  1276. return expiry;
  1277. };
  1278. /**
  1279. *
  1280. */
  1281. App.prototype.getEditBlankXml = function()
  1282. {
  1283. var file = this.getCurrentFile();
  1284. if (file != null && this.editor.chromeless && this.editor.graph.lightbox && file.realtime == null)
  1285. {
  1286. return file.getData();
  1287. }
  1288. else
  1289. {
  1290. return this.getFileData(true);
  1291. }
  1292. };
  1293. /**
  1294. * Updates action states depending on the selection.
  1295. */
  1296. App.prototype.updateActionStates = function()
  1297. {
  1298. EditorUi.prototype.updateActionStates.apply(this, arguments);
  1299. var file = this.getCurrentFile();
  1300. this.actions.get('revisionHistory').setEnabled(file != null && ((file.constructor == DriveFile &&
  1301. file.isEditable()) || file.constructor == DropboxFile));
  1302. };
  1303. /**
  1304. * Updates draft in local storage
  1305. */
  1306. App.prototype.updateDraft = function()
  1307. {
  1308. if (isLocalStorage && localStorage != null)
  1309. {
  1310. localStorage.setItem('.draft', JSON.stringify({modified: new Date().getTime(), data: this.getFileData()}));
  1311. }
  1312. };
  1313. /**
  1314. * Returns the draft in local storage
  1315. */
  1316. App.prototype.getDraft = function()
  1317. {
  1318. // FIXME: Handle multiple tabs
  1319. // if (isLocalStorage && localStorage != null)
  1320. // {
  1321. // try
  1322. // {
  1323. // var draft = localStorage.getItem('.draft');
  1324. //
  1325. // if (draft != null)
  1326. // {
  1327. // return JSON.parse(draft);
  1328. // }
  1329. // }
  1330. // catch (e)
  1331. // {
  1332. // // ignore quota etc
  1333. // }
  1334. // }
  1335. return null;
  1336. };
  1337. /**
  1338. * Adds the specified entry to the recent file list in local storage
  1339. */
  1340. App.prototype.addRecent = function(entry)
  1341. {
  1342. if (isLocalStorage && localStorage != null)
  1343. {
  1344. var recent = this.getRecent();
  1345. if (recent == null)
  1346. {
  1347. recent = [];
  1348. }
  1349. else
  1350. {
  1351. for (var i = 0; i < recent.length; i++)
  1352. {
  1353. if (recent[i].id == entry.id)
  1354. {
  1355. recent.splice(i, 1);
  1356. }
  1357. }
  1358. }
  1359. if (recent != null)
  1360. {
  1361. recent.unshift(entry);
  1362. recent = recent.slice(0, 5);
  1363. localStorage.setItem('.recent', JSON.stringify(recent));
  1364. }
  1365. }
  1366. };
  1367. /**
  1368. * Returns the recent file list from local storage
  1369. */
  1370. App.prototype.getRecent = function()
  1371. {
  1372. if (isLocalStorage && localStorage != null)
  1373. {
  1374. try
  1375. {
  1376. var recent = localStorage.getItem('.recent');
  1377. if (recent != null)
  1378. {
  1379. return JSON.parse(recent);
  1380. }
  1381. }
  1382. catch (e)
  1383. {
  1384. // ignore
  1385. }
  1386. return null;
  1387. }
  1388. };
  1389. /**
  1390. * Clears the recent file list in local storage
  1391. */
  1392. App.prototype.resetRecent = function(entry)
  1393. {
  1394. if (isLocalStorage && localStorage != null)
  1395. {
  1396. try
  1397. {
  1398. localStorage.removeItem('.recent');
  1399. }
  1400. catch (e)
  1401. {
  1402. // ignore
  1403. }
  1404. }
  1405. };
  1406. /**
  1407. * Clears the draft save in local storage
  1408. */
  1409. App.prototype.removeDraft = function()
  1410. {
  1411. if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
  1412. {
  1413. try
  1414. {
  1415. localStorage.removeItem('.draft');
  1416. }
  1417. catch (e)
  1418. {
  1419. // ignore quota etc
  1420. }
  1421. }
  1422. };
  1423. /**
  1424. * Sets the onbeforeunload for the application
  1425. */
  1426. App.prototype.onBeforeUnload = function()
  1427. {
  1428. if (urlParams['embed'] == '1' && this.editor.modified)
  1429. {
  1430. return mxResources.get('allChangesLost');
  1431. }
  1432. else
  1433. {
  1434. var file = this.getCurrentFile();
  1435. if (file != null)
  1436. {
  1437. // KNOWN: Message is ignored by most browsers
  1438. if (file.constructor == LocalFile && file.getHash() == '' && !file.isModified() &&
  1439. urlParams['nowarn'] != '1' && !this.isDiagramEmpty() && urlParams['url'] == null &&
  1440. !this.editor.chromeless)
  1441. {
  1442. return mxResources.get('ensureDataSaved');
  1443. }
  1444. else if (file.constructor != DriveFile && file.isModified())
  1445. {
  1446. return mxResources.get('allChangesLost');
  1447. }
  1448. else
  1449. {
  1450. file.close(true);
  1451. }
  1452. }
  1453. }
  1454. };
  1455. /**
  1456. * Translates this point by the given vector.
  1457. *
  1458. * @param {number} dx X-coordinate of the translation.
  1459. * @param {number} dy Y-coordinate of the translation.
  1460. */
  1461. App.prototype.updateDocumentTitle = function()
  1462. {
  1463. if (!this.editor.graph.lightbox)
  1464. {
  1465. var title = this.editor.appName;
  1466. var file = this.getCurrentFile();
  1467. if (this.isOfflineApp())
  1468. {
  1469. title += ' app';
  1470. }
  1471. if (file != null)
  1472. {
  1473. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1474. title = filename + ' - ' + title;
  1475. }
  1476. document.title = title;
  1477. }
  1478. };
  1479. /**
  1480. * Authorizes the client, gets the userId and calls <open>.
  1481. */
  1482. App.prototype.createCrcTable = function()
  1483. {
  1484. var crcTable = [];
  1485. var c;
  1486. for (var n = 0; n < 256; n++)
  1487. {
  1488. c = n;
  1489. for (var k = 0; k < 8; k++)
  1490. {
  1491. c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  1492. }
  1493. crcTable[n] = c;
  1494. }
  1495. return crcTable;
  1496. };
  1497. /**
  1498. * Authorizes the client, gets the userId and calls <open>.
  1499. */
  1500. App.prototype.crc32 = function(str)
  1501. {
  1502. this.crcTable = this.crcTable || this.createCrcTable();
  1503. var crc = 0 ^ (-1);
  1504. for (var i = 0; i < str.length; i++ )
  1505. {
  1506. crc = (crc >>> 8) ^ this.crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
  1507. }
  1508. return (crc ^ (-1)) >>> 0;
  1509. };
  1510. /**
  1511. * Returns a thumbnail of the current file.
  1512. */
  1513. App.prototype.getThumbnail = function(width, success)
  1514. {
  1515. var result = false;
  1516. try
  1517. {
  1518. if (this.thumbImageCache == null)
  1519. {
  1520. this.thumbImageCache = new Object();
  1521. }
  1522. var graph = this.editor.graph;
  1523. // Exports PNG for first page while other page is visible by creating a graph
  1524. // LATER: Add caching for the graph or SVG while not on first page
  1525. if (this.pages != null && this.currentPage != this.pages[0])
  1526. {
  1527. graph = this.createTemporaryGraph(graph.getStylesheet());
  1528. var graphGetGlobalVariable = graph.getGlobalVariable;
  1529. var page = this.pages[0];
  1530. graph.getGlobalVariable = function(name)
  1531. {
  1532. if (name == 'page')
  1533. {
  1534. return page.getName();
  1535. }
  1536. else if (name == 'pagenumber')
  1537. {
  1538. return 1;
  1539. }
  1540. return graphGetGlobalVariable.apply(this, arguments);
  1541. };
  1542. document.body.appendChild(graph.container);
  1543. graph.model.setRoot(page.root);
  1544. }
  1545. // Uses client-side canvas export
  1546. if (mxClient.IS_CHROMEAPP || (!graph.mathEnabled && this.useCanvasForExport))
  1547. {
  1548. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1549. {
  1550. // Removes temporary graph from DOM
  1551. if (graph != this.editor.graph)
  1552. {
  1553. graph.container.parentNode.removeChild(graph.container);
  1554. }
  1555. success(canvas);
  1556. }), width, this.thumbImageCache, '#ffffff', function()
  1557. {
  1558. // Continues with null in error case
  1559. success();
  1560. }, null, null, null, null, null, null, graph);
  1561. result = true;
  1562. }
  1563. else if (this.canvasSupported && this.getCurrentFile() != null)
  1564. {
  1565. var canvas = document.createElement('canvas');
  1566. var bounds = graph.getGraphBounds();
  1567. var scale = width / bounds.width;
  1568. // Limits scale to 1 or 2 * width / height
  1569. scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
  1570. var x0 = Math.floor(bounds.x);
  1571. var y0 = Math.floor(bounds.y);
  1572. canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
  1573. canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
  1574. var ctx = canvas.getContext('2d');
  1575. // Configures the canvas
  1576. ctx.scale(scale, scale);
  1577. ctx.translate(-x0, -y0);
  1578. // Paint white background instead of transparent
  1579. var bg = graph.background;
  1580. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1581. {
  1582. bg = '#ffffff';
  1583. }
  1584. // Paints background
  1585. ctx.save();
  1586. ctx.fillStyle = bg;
  1587. ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
  1588. ctx.restore();
  1589. var htmlCanvas = new mxJsCanvas(canvas);
  1590. // NOTE: htmlCanvas passed into async canvas is only used for image
  1591. // and canvas caching (canvas caching not used in this case as we do
  1592. // not render text). To reuse that cache via the thumbImageCache we
  1593. // pass that into the async canvas and override the image cache in
  1594. // the newly created html canvas with that of the thumbImageCache.
  1595. // LATER: Is clear thumbImageCache needed if file changes?
  1596. var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
  1597. htmlCanvas.images = this.thumbImageCache.images;
  1598. // Render graph
  1599. var imgExport = new mxImageExport();
  1600. imgExport.drawShape = function(state, canvas)
  1601. {
  1602. if (state.shape instanceof mxShape && state.shape.checkBounds())
  1603. {
  1604. canvas.save();
  1605. canvas.translate(0.5, 0.5);
  1606. state.shape.paint(canvas);
  1607. canvas.translate(-0.5, -0.5);
  1608. canvas.restore();
  1609. }
  1610. };
  1611. imgExport.drawText = function(state, canvas)
  1612. {
  1613. // No text output for thumbnails
  1614. };
  1615. imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
  1616. asynCanvas.finish(mxUtils.bind(this, function()
  1617. {
  1618. imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
  1619. // Removes temporary graph from DOM
  1620. if (graph != this.editor.graph)
  1621. {
  1622. graph.container.parentNode.removeChild(graph.container);
  1623. }
  1624. success(canvas);
  1625. }));
  1626. result = true;
  1627. }
  1628. }
  1629. catch (e)
  1630. {
  1631. // ignore and use placeholder
  1632. // Removes temporary graph from DOM
  1633. if (graph != this.editor.graph)
  1634. {
  1635. graph.container.parentNode.removeChild(graph.container);
  1636. }
  1637. }
  1638. return result;
  1639. };
  1640. /**
  1641. * Translates this point by the given vector.
  1642. *
  1643. * @param {number} dx X-coordinate of the translation.
  1644. * @param {number} dy Y-coordinate of the translation.
  1645. */
  1646. App.prototype.createBackground = function()
  1647. {
  1648. var bg = this.createDiv('background');
  1649. bg.style.position = 'absolute';
  1650. bg.style.background = 'white';
  1651. bg.style.left = '0px';
  1652. bg.style.top = '0px';
  1653. bg.style.bottom = '0px';
  1654. bg.style.right = '0px';
  1655. mxUtils.setOpacity(bg, 100);
  1656. if (mxClient.IS_QUIRKS)
  1657. {
  1658. new mxDivResizer(bg);
  1659. }
  1660. return bg;
  1661. };
  1662. /**
  1663. * Translates this point by the given vector.
  1664. *
  1665. * @param {number} dx X-coordinate of the translation.
  1666. * @param {number} dy Y-coordinate of the translation.
  1667. */
  1668. (function()
  1669. {
  1670. var editorUiSetMode = EditorUi.prototype.setMode;
  1671. App.prototype.setMode = function(mode, remember)
  1672. {
  1673. editorUiSetMode.apply(this, arguments);
  1674. // Note: UseLocalStorage affects the file dialogs
  1675. // and should not be modified if mode is undefined
  1676. if (this.mode != null)
  1677. {
  1678. Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
  1679. }
  1680. if (remember)
  1681. {
  1682. if (isLocalStorage)
  1683. {
  1684. localStorage.setItem('.mode', mode);
  1685. }
  1686. else if (typeof(Storage) != 'undefined')
  1687. {
  1688. var expiry = new Date();
  1689. expiry.setYear(expiry.getFullYear() + 1);
  1690. document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
  1691. }
  1692. }
  1693. if (this.appIcon != null)
  1694. {
  1695. var file = this.getCurrentFile();
  1696. var mode = (file != null) ? file.getMode() : null;
  1697. if (mode == App.MODE_GOOGLE)
  1698. {
  1699. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
  1700. this.appIcon.style.cursor = 'pointer';
  1701. }
  1702. else if (mode == App.MODE_DROPBOX)
  1703. {
  1704. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
  1705. this.appIcon.style.cursor = 'pointer';
  1706. }
  1707. else if (mode == App.MODE_ONEDRIVE)
  1708. {
  1709. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
  1710. this.appIcon.style.cursor = 'pointer';
  1711. }
  1712. else
  1713. {
  1714. this.appIcon.removeAttribute('title');
  1715. this.appIcon.style.cursor = 'default';
  1716. }
  1717. }
  1718. };
  1719. })();
  1720. /**
  1721. * Function: authorize
  1722. *
  1723. * Authorizes the client, gets the userId and calls <open>.
  1724. */
  1725. App.prototype.appIconClicked = function(evt)
  1726. {
  1727. if (mxEvent.isAltDown(evt))
  1728. {
  1729. this.showSplash(true);
  1730. }
  1731. else
  1732. {
  1733. var file = this.getCurrentFile();
  1734. var mode = (file != null) ? file.getMode() : null;
  1735. if (mode == App.MODE_GOOGLE)
  1736. {
  1737. if (file.desc.parents.length > 0)
  1738. {
  1739. window.open('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
  1740. }
  1741. else
  1742. {
  1743. window.open('https://drive.google.com/?authuser=0');
  1744. }
  1745. }
  1746. else if (mode == App.MODE_DROPBOX)
  1747. {
  1748. window.open('https://www.dropbox.com/');
  1749. }
  1750. else if (mode == App.MODE_ONEDRIVE)
  1751. {
  1752. window.open('https://onedrive.live.com/');
  1753. }
  1754. else if (mode == App.MODE_TRELLO)
  1755. {
  1756. window.open('https://trello.com/');
  1757. }
  1758. else if (mode == App.MODE_GITHUB)
  1759. {
  1760. if (file != null && file.constructor == GitHubFile)
  1761. {
  1762. window.open(file.meta.html_url);
  1763. }
  1764. else
  1765. {
  1766. window.open('https://github.com/');
  1767. }
  1768. }
  1769. }
  1770. mxEvent.consume(evt);
  1771. };
  1772. /**
  1773. * Function: authorize
  1774. *
  1775. * Authorizes the client, gets the userId and calls <open>.
  1776. */
  1777. App.prototype.clearMode = function()
  1778. {
  1779. if (isLocalStorage)
  1780. {
  1781. localStorage.removeItem('.mode');
  1782. }
  1783. else if (typeof(Storage) != 'undefined')
  1784. {
  1785. var expiry = new Date();
  1786. expiry.setYear(expiry.getFullYear() - 1);
  1787. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  1788. }
  1789. };
  1790. /**
  1791. * Translates this point by the given vector.
  1792. *
  1793. * @param {number} dx X-coordinate of the translation.
  1794. * @param {number} dy Y-coordinate of the translation.
  1795. */
  1796. App.prototype.getDiagramId = function()
  1797. {
  1798. var id = window.location.hash;
  1799. // Strips the hash sign
  1800. if (id != null && id.length > 0)
  1801. {
  1802. id = id.substring(1);
  1803. }
  1804. return id;
  1805. };
  1806. /**
  1807. * Opens any file specified in the URL parameters.
  1808. */
  1809. App.prototype.open = function()
  1810. {
  1811. // Cross-domain window access is not allowed in FF, so if we
  1812. // were opened from another domain then this will fail.
  1813. try
  1814. {
  1815. // If the create URL param is used in embed mode then
  1816. // we try to open the XML from window.opener[value].
  1817. // Use this for embedding via tab to bypass the timing
  1818. // issues when passing messages without onload event.
  1819. if (window.opener != null)
  1820. {
  1821. var value = urlParams['create'];
  1822. if (value != null)
  1823. {
  1824. value = decodeURIComponent(value);
  1825. }
  1826. if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
  1827. value.substring(0, 8) != 'https://')
  1828. {
  1829. var doc = mxUtils.parseXml(window.opener[value]);
  1830. this.editor.setGraphXml(doc.documentElement);
  1831. }
  1832. else if (window.opener.openFile != null)
  1833. {
  1834. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename, temp)
  1835. {
  1836. this.spinner.stop();
  1837. if (filename == null)
  1838. {
  1839. var title = urlParams['title'];
  1840. temp = true;
  1841. if (title != null)
  1842. {
  1843. filename = decodeURIComponent(title);
  1844. }
  1845. else
  1846. {
  1847. filename = this.defaultFilename;
  1848. }
  1849. }
  1850. // Replaces PNG with XML extension
  1851. var dot = filename.substring(filename.length - 4) == '.png';
  1852. if (dot > 0)
  1853. {
  1854. filename = filename.substring(0, filename.length - 4) + '.xml';
  1855. }
  1856. this.fileLoaded((mxClient.IS_IOS) ?
  1857. new StorageFile(this, xml, filename) :
  1858. new LocalFile(this, xml, filename, temp));
  1859. }));
  1860. }
  1861. }
  1862. }
  1863. catch(e)
  1864. {
  1865. // ignore
  1866. }
  1867. };
  1868. /**
  1869. * Main function. Program starts here.
  1870. *
  1871. * @param {number} dx X-coordinate of the translation.
  1872. * @param {number} dy Y-coordinate of the translation.
  1873. */
  1874. App.prototype.load = function()
  1875. {
  1876. // Checks if we're running in embedded mode
  1877. if (urlParams['embed'] != '1')
  1878. {
  1879. if (this.spinner.spin(document.body, mxResources.get('starting')))
  1880. {
  1881. try
  1882. {
  1883. this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
  1884. }
  1885. catch (e)
  1886. {
  1887. // ignores invalid state args
  1888. }
  1889. this.editor.graph.setEnabled(this.getCurrentFile() != null);
  1890. // Passes the userId from the state parameter to the client
  1891. if ((window.location.hash == null || window.location.hash.length == 0) &&
  1892. this.drive != null && this.stateArg != null && this.stateArg.userId != null)
  1893. {
  1894. this.drive.setUserId(this.stateArg.userId);
  1895. }
  1896. // Legacy support for fileId parameter which is moved to the hash tag
  1897. if (urlParams['fileId'] != null)
  1898. {
  1899. window.location.hash = 'G' + urlParams['fileId'];
  1900. window.location.search = this.getSearch(['fileId']);
  1901. }
  1902. else
  1903. {
  1904. // Asynchronous or disabled loading of client
  1905. if (this.drive == null)
  1906. {
  1907. if (this.mode == App.MODE_GOOGLE)
  1908. {
  1909. this.mode = null;
  1910. }
  1911. this.start();
  1912. }
  1913. else
  1914. {
  1915. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  1916. {
  1917. // Starts the app without the Google Option if the API fails to load
  1918. if (gapi.drive == null || gapi.drive.realtime == null)
  1919. {
  1920. this.mode = null;
  1921. this.drive = null;
  1922. this.start();
  1923. }
  1924. else
  1925. {
  1926. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1927. {
  1928. // Needed to avoid popup blocking for non-immediate authentication
  1929. gapi.auth.init(mxUtils.bind(this, function()
  1930. {
  1931. if (gapi.client.drive == null)
  1932. {
  1933. this.mode = null;
  1934. this.drive = null;
  1935. }
  1936. this.start();
  1937. }));
  1938. }));
  1939. }
  1940. }));
  1941. }
  1942. }
  1943. }
  1944. }
  1945. else
  1946. {
  1947. this.restoreLibraries();
  1948. }
  1949. };
  1950. /**
  1951. * Called in start after the spinner stops.
  1952. */
  1953. App.prototype.showAlert = function(message)
  1954. {
  1955. if (message != null && message.length > 0)
  1956. {
  1957. var div = document.createElement('div');
  1958. div.className = 'geAlert';
  1959. div.style.zIndex = 2e9;
  1960. div.style.left = '50%';
  1961. div.style.top = '-100%';
  1962. mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
  1963. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
  1964. div.innerHTML = message;
  1965. var close = document.createElement('a');
  1966. close.className = 'geAlertLink';
  1967. close.style.textAlign = 'right';
  1968. close.style.marginTop = '20px';
  1969. close.style.display = 'block';
  1970. close.setAttribute('href', 'javascript:void(0);');
  1971. close.setAttribute('title', mxResources.get('close'));
  1972. close.innerHTML = mxResources.get('close');
  1973. div.appendChild(close);
  1974. mxEvent.addListener(close, 'click', function(evt)
  1975. {
  1976. if (div.parentNode != null)
  1977. {
  1978. div.parentNode.removeChild(div);
  1979. mxEvent.consume(evt);
  1980. }
  1981. });
  1982. document.body.appendChild(div);
  1983. // Delayed to get smoother animation after DOM rendering
  1984. window.setTimeout(function()
  1985. {
  1986. div.style.top = '30px';
  1987. }, 10);
  1988. // Fades out the alert after 15 secs
  1989. window.setTimeout(function()
  1990. {
  1991. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
  1992. div.style.opacity = '0';
  1993. window.setTimeout(function()
  1994. {
  1995. if (div.parentNode != null)
  1996. {
  1997. div.parentNode.removeChild(div);
  1998. }
  1999. }, 2000);
  2000. }, 15000);
  2001. }
  2002. };
  2003. /**
  2004. * Translates this point by the given vector.
  2005. *
  2006. * @param {number} dx X-coordinate of the translation.
  2007. * @param {number} dy Y-coordinate of the translation.
  2008. */
  2009. App.prototype.start = function()
  2010. {
  2011. this.bg.parentNode.removeChild(this.bg);
  2012. this.restoreLibraries();
  2013. this.spinner.stop();
  2014. try
  2015. {
  2016. // Listens to changes of the hash if not in embed or client mode
  2017. if (urlParams['client'] != '1' && urlParams['embed'] != '1')
  2018. {
  2019. // KNOWN: Does not work in quirks mode
  2020. mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
  2021. {
  2022. try
  2023. {
  2024. var id = this.getDiagramId();
  2025. var file = this.getCurrentFile();
  2026. if (file == null || file.getHash() != id)
  2027. {
  2028. this.loadFile(id, true);
  2029. }
  2030. }
  2031. catch (e)
  2032. {
  2033. // Workaround for possible scrollWidth of null in Dialog ctor
  2034. if (document.body != null)
  2035. {
  2036. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2037. {
  2038. var file = this.getCurrentFile();
  2039. window.location.hash = (file != null) ? file.getHash() : '';
  2040. }));
  2041. }
  2042. }
  2043. }));
  2044. }
  2045. // Redirects old url URL parameter to new #U format
  2046. if ((window.location.hash == null || window.location.hash.length <= 1) && urlParams['url'] != null)
  2047. {
  2048. this.loadFile('U' + urlParams['url'], true);
  2049. }
  2050. else if (this.getCurrentFile() == null)
  2051. {
  2052. var done = mxUtils.bind(this, function()
  2053. {
  2054. // Starts in client mode and waits for data
  2055. if (urlParams['client'] == '1' && (window.location.hash == null ||
  2056. window.location.hash.length == 0))
  2057. {
  2058. var parent = window.opener || window.parent;
  2059. if (parent != window)
  2060. {
  2061. this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
  2062. {
  2063. // Ignores messages from other windows
  2064. if (evt.source == parent)
  2065. {
  2066. // Extracts graph model from PNG
  2067. if (xml.substring(0, 22) == 'data:image/png;base64,')
  2068. {
  2069. xml = this.extractGraphModelFromPng(xml);
  2070. }
  2071. var title = urlParams['title'];
  2072. if (title != null)
  2073. {
  2074. title = decodeURIComponent(title);
  2075. }
  2076. else
  2077. {
  2078. title = this.defaultFilename;
  2079. }
  2080. this.fileLoaded(new LocalFile(this, xml, title, true));
  2081. this.getCurrentFile().setModified(!this.editor.chromeless);
  2082. }
  2083. }));
  2084. }
  2085. }
  2086. // Checks if no earlier loading errors are showing
  2087. else if (this.dialog == null)
  2088. {
  2089. if (urlParams['demo'] == '1')
  2090. {
  2091. var prev = Editor.useLocalStorage;
  2092. this.createFile(this.defaultFilename, null, null, null, null, null, null, true);
  2093. Editor.useLocalStorage = prev;
  2094. }
  2095. else
  2096. {
  2097. var waiting = false;
  2098. // Checks if we're waiting for some asynchronous file to be loaded
  2099. // Cross-domain window access is not allowed in FF, so if we
  2100. // were opened from another domain then this will fail.
  2101. try
  2102. {
  2103. waiting = window.opener != null && window.opener.openFile != null;
  2104. }
  2105. catch(e)
  2106. {
  2107. // ignore
  2108. }
  2109. if (waiting)
  2110. {
  2111. // Spinner is stopped in App.open
  2112. this.spinner.spin(document.body, mxResources.get('loading'))
  2113. }
  2114. else
  2115. {
  2116. var id = this.getDiagramId();
  2117. if (urlParams['splash'] == '0' && (id == null || id.length == 0))
  2118. {
  2119. var draft = this.getDraft();
  2120. var fileData = (draft != null) ? draft.data : this.getFileData();
  2121. var prev = Editor.useLocalStorage;
  2122. this.createFile(this.defaultFilename, fileData, null, null, null, null, null, true);
  2123. Editor.useLocalStorage = prev;
  2124. // Draft was used so the user should save the file
  2125. if (draft != null)
  2126. {
  2127. var file = this.getCurrentFile();
  2128. if (file != null)
  2129. {
  2130. file.addUnsavedStatus();
  2131. }
  2132. }
  2133. }
  2134. else
  2135. {
  2136. this.loadFile(this.getDiagramId());
  2137. }
  2138. }
  2139. }
  2140. }
  2141. });
  2142. // Defines custom classes for realtime in Google Drive
  2143. if (this.drive != null)
  2144. {
  2145. this.defineCustomObjects();
  2146. }
  2147. var value = decodeURIComponent(urlParams['create'] || '');
  2148. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2149. value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
  2150. {
  2151. var reconnect = mxUtils.bind(this, function()
  2152. {
  2153. // Removes URL parameter and reloads the page
  2154. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  2155. {
  2156. window.location.search = this.getSearch(['create', 'title']);
  2157. };
  2158. });
  2159. var showCreateDialog = mxUtils.bind(this, function(xml)
  2160. {
  2161. this.spinner.stop();
  2162. // Resets mode for dialog - local file is only for preview
  2163. if (urlParams['splash'] != '0')
  2164. {
  2165. this.fileLoaded(new LocalFile(this, xml, null));
  2166. this.editor.graph.setEnabled(false);
  2167. this.mode = urlParams['mode'];
  2168. var title = urlParams['title'];
  2169. if (title != null)
  2170. {
  2171. title = decodeURIComponent(title);
  2172. }
  2173. else
  2174. {
  2175. title = this.defaultFilename;
  2176. }
  2177. var serviceCount = this.getServiceCount(true);
  2178. var rowLimit = (serviceCount <= 4) ? 4 : 3;
  2179. var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
  2180. {
  2181. if (mode == null)
  2182. {
  2183. this.hideDialog();
  2184. var prev = Editor.useLocalStorage;
  2185. this.createFile((filename.length > 0) ? filename : this.defaultFilename,
  2186. this.getFileData(), null, null, null, null, null, true);
  2187. Editor.useLocalStorage = prev;
  2188. }
  2189. else
  2190. {
  2191. this.createFile(filename, this.getFileData(true), null, mode);
  2192. }
  2193. }), null, null, null, null, urlParams['browser'] == '1', null, null, true, rowLimit);
  2194. this.showDialog(dlg.container, 380, (serviceCount > rowLimit) ? 390 : 270,
  2195. true, false, mxUtils.bind(this, function(cancel)
  2196. {
  2197. if (cancel && this.getCurrentFile() == null)
  2198. {
  2199. this.showSplash();
  2200. }
  2201. }));
  2202. dlg.init();
  2203. }
  2204. });
  2205. value = decodeURIComponent(value);
  2206. if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
  2207. {
  2208. // Cross-domain window access is not allowed in FF, so if we
  2209. // were opened from another domain then this will fail.
  2210. try
  2211. {
  2212. if (window.opener != null && window.opener[value] != null)
  2213. {
  2214. showCreateDialog(window.opener[value]);
  2215. }
  2216. else
  2217. {
  2218. this.handleError(null, mxResources.get('errorLoadingFile'));
  2219. }
  2220. }
  2221. catch (e)
  2222. {
  2223. this.handleError(e, mxResources.get('errorLoadingFile'));
  2224. }
  2225. }
  2226. else
  2227. {
  2228. this.loadTemplate(value, function(text)
  2229. {
  2230. showCreateDialog(text);
  2231. }, mxUtils.bind(this, function()
  2232. {
  2233. this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
  2234. }));
  2235. }
  2236. }
  2237. else
  2238. {
  2239. // Passes the fileId from the state parameter to the hash tag and reloads
  2240. // the page without the state parameter
  2241. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2242. urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
  2243. {
  2244. if (this.stateArg.ids != null)
  2245. {
  2246. window.location.hash = 'G' + this.stateArg.ids[0];
  2247. }
  2248. }
  2249. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2250. this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
  2251. {
  2252. this.setMode(App.MODE_GOOGLE);
  2253. this.actions.get('new').funct();
  2254. }
  2255. else
  2256. {
  2257. done();
  2258. }
  2259. }
  2260. }
  2261. }
  2262. catch (e)
  2263. {
  2264. this.handleError(e);
  2265. }
  2266. };
  2267. /**
  2268. * Translates this point by the given vector.
  2269. *
  2270. * @param {number} dx X-coordinate of the translation.
  2271. * @param {number} dy Y-coordinate of the translation.
  2272. */
  2273. App.prototype.showSplash = function(force)
  2274. {
  2275. var serviceCount = this.getServiceCount(false) + 1;
  2276. var showSecondDialog = mxUtils.bind(this, function()
  2277. {
  2278. var dlg = new SplashDialog(this);
  2279. this.showDialog(dlg.container, 340, (serviceCount < 2 ||
  2280. mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) ? 200 : 260, true, true,
  2281. mxUtils.bind(this, function(cancel)
  2282. {
  2283. // Creates a blank diagram if the dialog is closed
  2284. if (cancel && !mxClient.IS_CHROMEAPP)
  2285. {
  2286. var prev = Editor.useLocalStorage;
  2287. this.createFile(this.defaultFilename, null, null, null, null, null, null,
  2288. urlParams['local'] != '1');
  2289. Editor.useLocalStorage = prev;
  2290. }
  2291. }));
  2292. });
  2293. if (this.editor.chromeless)
  2294. {
  2295. this.handleError({message: mxResources.get('noFileSelected')},
  2296. mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2297. {
  2298. this.showSplash();
  2299. }));
  2300. }
  2301. else if (this.mode == null || force)
  2302. {
  2303. var rowLimit = (serviceCount <= 4) ? 2 : 3;
  2304. var dlg = new StorageDialog(this, mxUtils.bind(this, function()
  2305. {
  2306. this.hideDialog();
  2307. showSecondDialog();
  2308. }), rowLimit);
  2309. this.showDialog(dlg.container, (rowLimit < 3) ? 260 : 300,
  2310. (serviceCount > rowLimit) ? 420 : 300, true, false);
  2311. dlg.init();
  2312. }
  2313. else if (urlParams['create'] == null)
  2314. {
  2315. showSecondDialog();
  2316. }
  2317. };
  2318. /**
  2319. * Translates this point by the given vector.
  2320. *
  2321. * @param {number} dx X-coordinate of the translation.
  2322. * @param {number} dy Y-coordinate of the translation.
  2323. */
  2324. App.prototype.addLanguageMenu = function(elt)
  2325. {
  2326. var img = null;
  2327. if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
  2328. {
  2329. var langMenu = this.menus.get('language');
  2330. if (langMenu != null)
  2331. {
  2332. img = document.createElement('div');
  2333. img.setAttribute('title', mxResources.get('language'));
  2334. img.className = 'geIcon geSprite geSprite-globe';
  2335. img.style.position = 'absolute';
  2336. img.style.cursor = 'pointer';
  2337. img.style.bottom = '20px';
  2338. img.style.right = '20px';
  2339. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  2340. {
  2341. this.editor.graph.popupMenuHandler.hideMenu();
  2342. var menu = new mxPopupMenu(this.menus.get('language').funct);
  2343. menu.div.className += ' geMenubarMenu';
  2344. menu.smartSeparators = true;
  2345. menu.showDisabled = true;
  2346. menu.autoExpand = true;
  2347. // Disables autoexpand and destroys menu when hidden
  2348. menu.hideMenu = mxUtils.bind(this, function()
  2349. {
  2350. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  2351. menu.destroy();
  2352. });
  2353. var offset = mxUtils.getOffset(img);
  2354. menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
  2355. // Allows hiding by clicking on document
  2356. this.setCurrentMenu(menu);
  2357. }));
  2358. elt.appendChild(img);
  2359. }
  2360. }
  2361. return img;
  2362. };
  2363. /**
  2364. * Translates this point by the given vector.
  2365. *
  2366. * @param {number} dx X-coordinate of the translation.
  2367. * @param {number} dy Y-coordinate of the translation.
  2368. */
  2369. App.prototype.defineCustomObjects = function()
  2370. {
  2371. if (gapi.drive.realtime != null && gapi.drive.realtime.custom != null)
  2372. {
  2373. gapi.drive.realtime.custom.registerType(mxRtCell, 'Cell');
  2374. mxRtCell.prototype.cellId = gapi.drive.realtime.custom.collaborativeField('cellId');
  2375. mxRtCell.prototype.type = gapi.drive.realtime.custom.collaborativeField('type');
  2376. mxRtCell.prototype.value = gapi.drive.realtime.custom.collaborativeField('value');
  2377. mxRtCell.prototype.xmlValue = gapi.drive.realtime.custom.collaborativeField('xmlValue');
  2378. mxRtCell.prototype.style = gapi.drive.realtime.custom.collaborativeField('style');
  2379. mxRtCell.prototype.geometry = gapi.drive.realtime.custom.collaborativeField('geometry');
  2380. mxRtCell.prototype.visible = gapi.drive.realtime.custom.collaborativeField('visible');
  2381. mxRtCell.prototype.collapsed = gapi.drive.realtime.custom.collaborativeField('collapsed');
  2382. mxRtCell.prototype.connectable = gapi.drive.realtime.custom.collaborativeField('connectable');
  2383. mxRtCell.prototype.parent = gapi.drive.realtime.custom.collaborativeField('parent');
  2384. mxRtCell.prototype.children = gapi.drive.realtime.custom.collaborativeField('children');
  2385. mxRtCell.prototype.source = gapi.drive.realtime.custom.collaborativeField('source');
  2386. mxRtCell.prototype.target = gapi.drive.realtime.custom.collaborativeField('target');
  2387. }
  2388. };
  2389. mxRtCell = function() {};
  2390. // Ignores rtCell property in codec and cloning
  2391. mxCodecRegistry.getCodec(mxCell).exclude.push('rtCell');
  2392. mxCell.prototype.mxTransient.push('rtCell');
  2393. /**
  2394. * Translates this point by the given vector.
  2395. *
  2396. * @param {number} dx X-coordinate of the translation.
  2397. * @param {number} dy Y-coordinate of the translation.
  2398. */
  2399. App.prototype.pickFile = function(mode)
  2400. {
  2401. mode = (mode != null) ? mode : this.mode;
  2402. if (mode == App.MODE_GOOGLE)
  2403. {
  2404. if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2405. {
  2406. this.drive.pickFile();
  2407. }
  2408. else
  2409. {
  2410. window.open('https://drive.google.com');
  2411. }
  2412. }
  2413. else
  2414. {
  2415. var peer = this.getPeerForMode(mode);
  2416. if (peer != null)
  2417. {
  2418. peer.pickFile();
  2419. }
  2420. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2421. {
  2422. var input = document.createElement('input');
  2423. input.setAttribute('type', 'file');
  2424. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2425. {
  2426. if (input.files != null)
  2427. {
  2428. this.openFiles(input.files);
  2429. }
  2430. }));
  2431. input.click();
  2432. }
  2433. else
  2434. {
  2435. this.hideDialog();
  2436. window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
  2437. window.baseUrl = this.getUrl();
  2438. window.openKey = 'open';
  2439. var prevValue = Editor.useLocalStorage;
  2440. Editor.useLocalStorage = (mode == App.MODE_BROWSER);
  2441. this.openFile();
  2442. // Installs local handler for opened files in same window
  2443. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2444. {
  2445. // Replaces PNG with XML extension
  2446. var dot = filename.substring(filename.length - 4) == '.png';
  2447. if (dot > 0)
  2448. {
  2449. filename = filename.substring(0, filename.length - 4) + '.xml';
  2450. }
  2451. this.fileLoaded((mode == App.MODE_BROWSER) ?
  2452. new StorageFile(this, xml, filename) :
  2453. new LocalFile(this, xml, filename));
  2454. }));
  2455. // Extends dialog close to show splash screen
  2456. var dlg = this.dialog;
  2457. var dlgClose = dlg.close;
  2458. this.dialog.close = mxUtils.bind(this, function(cancel)
  2459. {
  2460. Editor.useLocalStorage = prevValue;
  2461. dlgClose.apply(dlg, arguments);
  2462. if (this.getCurrentFile() == null)
  2463. {
  2464. this.showSplash();
  2465. }
  2466. });
  2467. }
  2468. }
  2469. };
  2470. /**
  2471. * Translates this point by the given vector.
  2472. *
  2473. * @param {number} dx X-coordinate of the translation.
  2474. * @param {number} dy Y-coordinate of the translation.
  2475. */
  2476. App.prototype.pickLibrary = function(mode)
  2477. {
  2478. mode = (mode != null) ? mode : this.mode;
  2479. if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE || mode == App.MODE_GITHUB || mode == App.MODE_TRELLO)
  2480. {
  2481. var peer = (mode == App.MODE_GOOGLE) ? this.drive :
  2482. ((mode == App.MODE_ONEDRIVE) ? this.oneDrive :
  2483. ((mode == App.MODE_GITHUB) ? this.gitHub :
  2484. ((mode == App.MODE_TRELLO) ? this.trello :
  2485. this.dropbox)));
  2486. if (peer != null)
  2487. {
  2488. peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
  2489. {
  2490. if (optionalFile != null)
  2491. {
  2492. try
  2493. {
  2494. this.loadLibrary(optionalFile);
  2495. }
  2496. catch (e)
  2497. {
  2498. this.handleError(e, mxResources.get('errorLoadingFile'));
  2499. }
  2500. }
  2501. else
  2502. {
  2503. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2504. {
  2505. peer.getLibrary(id, mxUtils.bind(this, function(file)
  2506. {
  2507. this.spinner.stop();
  2508. try
  2509. {
  2510. this.loadLibrary(file);
  2511. }
  2512. catch (e)
  2513. {
  2514. this.handleError(e, mxResources.get('errorLoadingFile'));
  2515. }
  2516. }), mxUtils.bind(this, function(resp)
  2517. {
  2518. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2519. }));
  2520. }
  2521. }
  2522. }));
  2523. }
  2524. }
  2525. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2526. {
  2527. var input = document.createElement('input');
  2528. input.setAttribute('type', 'file');
  2529. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2530. {
  2531. if (input.files != null)
  2532. {
  2533. for (var i = 0; i < input.files.length; i++)
  2534. {
  2535. (mxUtils.bind(this, function(file)
  2536. {
  2537. var reader = new FileReader();
  2538. reader.onload = mxUtils.bind(this, function(e)
  2539. {
  2540. try
  2541. {
  2542. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  2543. }
  2544. catch (e)
  2545. {
  2546. this.handleError(e, mxResources.get('errorLoadingFile'));
  2547. }
  2548. });
  2549. reader.readAsText(file);
  2550. }))(input.files[i]);
  2551. }
  2552. }
  2553. }));
  2554. input.click();
  2555. }
  2556. else
  2557. {
  2558. window.openNew = false;
  2559. window.openKey = 'open';
  2560. var prevValue = Editor.useLocalStorage;
  2561. Editor.useLocalStorage = mode == App.MODE_BROWSER;
  2562. // Closes dialog after open
  2563. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2564. {
  2565. this.hideDialog(cancel);
  2566. }));
  2567. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2568. {
  2569. try
  2570. {
  2571. this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
  2572. new LocalLibrary(this, xml, filename));
  2573. }
  2574. catch (e)
  2575. {
  2576. this.handleError(e, mxResources.get('errorLoadingFile'));
  2577. }
  2578. }));
  2579. // Removes openFile if dialog is closed
  2580. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
  2581. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2582. {
  2583. Editor.useLocalStorage = prevValue;
  2584. window.openFile = null;
  2585. });
  2586. }
  2587. };
  2588. /**
  2589. * Translates this point by the given vector.
  2590. *
  2591. * @param {number} dx X-coordinate of the translation.
  2592. * @param {number} dy Y-coordinate of the translation.
  2593. */
  2594. App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  2595. {
  2596. mode = (mode != null) ? mode : this.mode;
  2597. noSpin = (noSpin != null) ? noSpin : false;
  2598. noReload = (noReload != null) ? noReload : false;
  2599. var xml = this.createLibraryDataFromImages(images);
  2600. var error = mxUtils.bind(this, function(resp)
  2601. {
  2602. this.spinner.stop();
  2603. if (fn != null)
  2604. {
  2605. fn();
  2606. }
  2607. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  2608. });
  2609. // Handles special case for local libraries
  2610. if (file == null && mode == App.MODE_DEVICE)
  2611. {
  2612. file = new LocalLibrary(this, xml, name);
  2613. }
  2614. if (file == null)
  2615. {
  2616. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2617. {
  2618. if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2619. {
  2620. this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
  2621. {
  2622. this.spinner.stop();
  2623. this.hideDialog(true);
  2624. this.libraryLoaded(newFile, images);
  2625. }), error, this.drive.libraryMimeType);
  2626. }
  2627. else if (mode == App.MODE_GITHUB && this.gitHub != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2628. {
  2629. this.gitHub.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2630. {
  2631. this.spinner.stop();
  2632. this.hideDialog(true);
  2633. this.libraryLoaded(newFile, images);
  2634. }), error, folderId);
  2635. }
  2636. else if (mode == App.MODE_TRELLO && this.trello != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2637. {
  2638. this.trello.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2639. {
  2640. this.spinner.stop();
  2641. this.hideDialog(true);
  2642. this.libraryLoaded(newFile, images);
  2643. }), error, folderId);
  2644. }
  2645. else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2646. {
  2647. this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2648. {
  2649. this.spinner.stop();
  2650. this.hideDialog(true);
  2651. this.libraryLoaded(newFile, images);
  2652. }), error, folderId);
  2653. }
  2654. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2655. {
  2656. this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2657. {
  2658. this.spinner.stop();
  2659. this.hideDialog(true);
  2660. this.libraryLoaded(newFile, images);
  2661. }), error, folderId);
  2662. }
  2663. else if (mode == App.MODE_BROWSER)
  2664. {
  2665. var fn = mxUtils.bind(this, function()
  2666. {
  2667. var file = new StorageLibrary(this, xml, name);
  2668. // Inserts data into local storage
  2669. file.saveFile(name, false, mxUtils.bind(this, function()
  2670. {
  2671. this.hideDialog(true);
  2672. this.libraryLoaded(file, images);
  2673. }), error);
  2674. });
  2675. if (localStorage.getItem(name) == null)
  2676. {
  2677. fn();
  2678. }
  2679. else
  2680. {
  2681. this.confirm(mxResources.get('replaceIt', [name]), fn);
  2682. }
  2683. }
  2684. else
  2685. {
  2686. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  2687. }
  2688. }));
  2689. }
  2690. else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
  2691. {
  2692. file.setData(xml);
  2693. var doSave = mxUtils.bind(this, function()
  2694. {
  2695. file.save(true, mxUtils.bind(this, function(resp)
  2696. {
  2697. this.spinner.stop();
  2698. this.hideDialog(true);
  2699. if (!noReload)
  2700. {
  2701. this.libraryLoaded(file, images);
  2702. }
  2703. if (fn != null)
  2704. {
  2705. fn();
  2706. }
  2707. }), error);
  2708. });
  2709. if (name != file.getTitle())
  2710. {
  2711. var oldHash = file.getHash();
  2712. file.rename(name, mxUtils.bind(this, function(resp)
  2713. {
  2714. // Change hash in stored settings
  2715. if (file.constructor != LocalLibrary && oldHash != file.getHash())
  2716. {
  2717. mxSettings.removeCustomLibrary(oldHash);
  2718. mxSettings.addCustomLibrary(file.getHash());
  2719. }
  2720. // Workaround for library files changing hash so
  2721. // the old library cannot be removed from the
  2722. // sidebar using the updated file in libraryLoaded
  2723. this.removeLibrarySidebar(oldHash);
  2724. doSave();
  2725. }), error)
  2726. }
  2727. else
  2728. {
  2729. doSave();
  2730. }
  2731. }
  2732. };
  2733. /**
  2734. * Adds the label menu items to the given menu and parent.
  2735. */
  2736. App.prototype.saveFile = function(forceDialog)
  2737. {
  2738. var file = this.getCurrentFile();
  2739. if (file != null)
  2740. {
  2741. // FIXME: Invoke for local files
  2742. var done = mxUtils.bind(this, function()
  2743. {
  2744. this.removeDraft();
  2745. // Workaround for possible status update while save as dialog is showing
  2746. // is to show no saved status for device files
  2747. if (file.getMode() != App.MODE_DEVICE)
  2748. {
  2749. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
  2750. }
  2751. else
  2752. {
  2753. this.editor.setStatus('');
  2754. }
  2755. });
  2756. if (!forceDialog && file.getTitle() != null && this.mode != null)
  2757. {
  2758. this.save(file.getTitle(), done);
  2759. }
  2760. else
  2761. {
  2762. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  2763. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2764. var prev = this.mode;
  2765. var serviceCount = this.getServiceCount(true);
  2766. if (isLocalStorage)
  2767. {
  2768. serviceCount++;
  2769. }
  2770. var rowLimit = (serviceCount <= 4) ? 2 : (serviceCount > 6 ? 4 : 3);
  2771. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
  2772. {
  2773. if (name != null && name.length > 0)
  2774. {
  2775. if (prev == null && mode == App.MODE_DEVICE)
  2776. {
  2777. this.setMode(App.MODE_DEVICE);
  2778. this.save(name, done);
  2779. }
  2780. else if (mode == 'download')
  2781. {
  2782. var tmp = new LocalFile(this, null, name);
  2783. tmp.save();
  2784. }
  2785. else if (mode == '_blank')
  2786. {
  2787. window.openFile = new OpenFile(function()
  2788. {
  2789. window.openFile = null;
  2790. });
  2791. // Do not use a filename to use undefined mode
  2792. window.openFile.setData(this.getFileData(true));
  2793. window.open(this.getUrl(window.location.pathname));
  2794. }
  2795. else if (prev != mode)
  2796. {
  2797. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2798. {
  2799. this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
  2800. name.indexOf('.') < 0, /(\.svg)$/i.test(name),
  2801. /(\.html)$/i.test(name)), null, mode, done,
  2802. this.mode == null, folderId);
  2803. }), mode !== App.MODE_GITHUB);
  2804. }
  2805. else if (mode != null)
  2806. {
  2807. this.save(name, done);
  2808. }
  2809. }
  2810. }), mxUtils.bind(this, function()
  2811. {
  2812. this.hideDialog();
  2813. }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
  2814. (this.isOffline()) ? null :
  2815. 'https://desk.draw.io/support/solutions/articles/16000042485',
  2816. true, rowLimit);
  2817. this.showDialog(dlg.container, 460, (serviceCount > rowLimit) ? 390 : 270, true, true);
  2818. dlg.init();
  2819. }
  2820. }
  2821. };
  2822. /**
  2823. * Translates this point by the given vector.
  2824. *
  2825. * @param {number} dx X-coordinate of the translation.
  2826. * @param {number} dy Y-coordinate of the translation.
  2827. */
  2828. EditorUi.prototype.loadTemplate = function(url, onload, onerror)
  2829. {
  2830. var realUrl = url;
  2831. if (!this.isCorsEnabledForUrl(realUrl))
  2832. {
  2833. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
  2834. }
  2835. this.loadUrl(realUrl, mxUtils.bind(this, function(data)
  2836. {
  2837. if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  2838. {
  2839. // Asynchronous parsing via server
  2840. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2841. {
  2842. if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status <= 299 &&
  2843. xhr.responseText.substring(0, 13) == '<mxGraphModel')
  2844. {
  2845. onload(xhr.responseText);
  2846. }
  2847. }), url);
  2848. }
  2849. else
  2850. {
  2851. if (/(\.png)($|\?)/i.test(url))
  2852. {
  2853. data = this.extractGraphModelFromPng(data);
  2854. }
  2855. onload(data);
  2856. }
  2857. }), onerror, /(\.png)($|\?)/i.test(url));
  2858. };
  2859. /**
  2860. * Translates this point by the given vector.
  2861. *
  2862. * @param {number} dx X-coordinate of the translation.
  2863. * @param {number} dy Y-coordinate of the translation.
  2864. */
  2865. App.prototype.getPeerForMode = function(mode)
  2866. {
  2867. if (mode == App.MODE_GOOGLE)
  2868. {
  2869. return this.drive;
  2870. }
  2871. else if (mode == App.MODE_GITHUB)
  2872. {
  2873. return this.gitHub;
  2874. }
  2875. else if (mode == App.MODE_DROPBOX)
  2876. {
  2877. return this.dropbox;
  2878. }
  2879. else if (mode == App.MODE_ONEDRIVE)
  2880. {
  2881. return this.oneDrive;
  2882. }
  2883. else if (mode == App.MODE_TRELLO)
  2884. {
  2885. return this.trello;
  2886. }
  2887. else
  2888. {
  2889. return null;
  2890. }
  2891. };
  2892. /**
  2893. * Translates this point by the given vector.
  2894. *
  2895. * @param {number} dx X-coordinate of the translation.
  2896. * @param {number} dy Y-coordinate of the translation.
  2897. */
  2898. App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId, tempFile)
  2899. {
  2900. mode = (tempFile) ? null : ((mode != null) ? mode : this.mode);
  2901. if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2902. {
  2903. data = (data != null) ? data : this.emptyDiagramXml;
  2904. var complete = mxUtils.bind(this, function()
  2905. {
  2906. this.spinner.stop();
  2907. });
  2908. var error = mxUtils.bind(this, function(resp)
  2909. {
  2910. complete();
  2911. if (resp == null && this.getCurrentFile() == null && this.dialog == null)
  2912. {
  2913. this.showSplash();
  2914. }
  2915. else if (resp != null)
  2916. {
  2917. this.handleError(resp);
  2918. }
  2919. });
  2920. if (mode == App.MODE_GOOGLE && this.drive != null)
  2921. {
  2922. folderId = (this.stateArg != null) ? this.stateArg.folderId : folderId;
  2923. this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
  2924. {
  2925. complete();
  2926. this.fileCreated(file, libs, replace, done);
  2927. }), error);
  2928. }
  2929. else if (mode == App.MODE_GITHUB && this.gitHub != null)
  2930. {
  2931. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2932. {
  2933. this.gitHub.insertFile(title, data, mxUtils.bind(this, function(file)
  2934. {
  2935. complete();
  2936. this.fileCreated(file, libs, replace, done);
  2937. }), error, false, folderId);
  2938. }));
  2939. }
  2940. else if (mode == App.MODE_TRELLO && this.trello != null)
  2941. {
  2942. this.trello.insertFile(title, data, mxUtils.bind(this, function(file)
  2943. {
  2944. complete();
  2945. this.fileCreated(file, libs, replace, done);
  2946. }), error, false, folderId);
  2947. }
  2948. else if (mode == App.MODE_DROPBOX && this.dropbox != null)
  2949. {
  2950. this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
  2951. {
  2952. complete();
  2953. this.fileCreated(file, libs, replace, done);
  2954. }), error);
  2955. }
  2956. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  2957. {
  2958. this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
  2959. {
  2960. complete();
  2961. this.fileCreated(file, libs, replace, done);
  2962. }), error, false, folderId);
  2963. }
  2964. else if (mode == App.MODE_BROWSER)
  2965. {
  2966. complete();
  2967. var fn = mxUtils.bind(this, function()
  2968. {
  2969. var file = new StorageFile(this, data, title);
  2970. // Inserts data into local storage
  2971. file.saveFile(title, false, mxUtils.bind(this, function()
  2972. {
  2973. this.fileCreated(file, libs, replace, done);
  2974. }), error);
  2975. });
  2976. if (localStorage.getItem(title) == null)
  2977. {
  2978. fn();
  2979. }
  2980. else
  2981. {
  2982. this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
  2983. {
  2984. if (this.getCurrentFile() == null && this.dialog == null)
  2985. {
  2986. this.showSplash();
  2987. }
  2988. }));
  2989. }
  2990. }
  2991. else
  2992. {
  2993. complete();
  2994. this.fileCreated(new LocalFile(this, data, title, mode == null), libs, replace, done);
  2995. }
  2996. }
  2997. };
  2998. /**
  2999. * Translates this point by the given vector.
  3000. *
  3001. * @param {number} dx X-coordinate of the translation.
  3002. * @param {number} dy Y-coordinate of the translation.
  3003. */
  3004. App.prototype.fileCreated = function(file, libs, replace, done)
  3005. {
  3006. var url = window.location.pathname;
  3007. if (libs != null && libs.length > 0)
  3008. {
  3009. url += '?libs=' + libs;
  3010. }
  3011. url = this.getUrl(url);
  3012. // Always opens a new tab for local files to avoid losing changes
  3013. if (file.getMode() != App.MODE_DEVICE)
  3014. {
  3015. url += '#' + file.getHash();
  3016. }
  3017. // Makes sure to produce consistent output with finalized files via createFileData this needs
  3018. // to save the file again since it needs the newly created file ID for redirecting in HTML
  3019. if (this.spinner.spin(document.body, mxResources.get('inserting')))
  3020. {
  3021. var data = file.getData();
  3022. var dataNode = (data.length > 0) ? this.editor.extractGraphModel(
  3023. mxUtils.parseXml(data).documentElement, true) : null;
  3024. var redirect = window.location.protocol + '//' + window.location.hostname + url;
  3025. var graph = null;
  3026. // Handles special case where SVG files need a rendered graph to be saved
  3027. if (dataNode != null && /\.svg$/i.test(file.getTitle()))
  3028. {
  3029. graph = this.createTemporaryGraph(this.editor.graph.getStylesheet());
  3030. document.body.appendChild(graph.container);
  3031. node = dataNode;
  3032. if (node != null)
  3033. {
  3034. var diagramNode = null;
  3035. if (node.nodeName == 'diagram')
  3036. {
  3037. diagramNode = node;
  3038. }
  3039. else if (node.nodeName == 'mxfile')
  3040. {
  3041. var diagrams = node.getElementsByTagName('diagram');
  3042. if (diagrams.length > 0)
  3043. {
  3044. diagramNode = diagrams[0];
  3045. var graphGetGlobalVariable = graph.getGlobalVariable;
  3046. graph.getGlobalVariable = function(name)
  3047. {
  3048. if (name == 'page')
  3049. {
  3050. return diagramNode.getAttribute('name') || mxResources.get('pageWithNumber', [1])
  3051. }
  3052. else if (name == 'pagenumber')
  3053. {
  3054. return 1;
  3055. }
  3056. return graphGetGlobalVariable.apply(this, arguments);
  3057. };
  3058. }
  3059. }
  3060. if (diagramNode != null)
  3061. {
  3062. var tmp = graph.decompress(mxUtils.getTextContent(diagramNode));
  3063. if (tmp != null && tmp.length > 0)
  3064. {
  3065. node = mxUtils.parseXml(tmp).documentElement;
  3066. }
  3067. }
  3068. }
  3069. // Hack to decode XML into temp graph via editor
  3070. var prev = this.editor.graph;
  3071. try
  3072. {
  3073. this.editor.graph = graph;
  3074. this.editor.setGraphXml(node);
  3075. }
  3076. catch (e)
  3077. {
  3078. // ignore
  3079. }
  3080. finally
  3081. {
  3082. this.editor.graph = prev;
  3083. }
  3084. }
  3085. file.setData(this.createFileData(dataNode, graph, file, redirect));
  3086. if (graph != null)
  3087. {
  3088. graph.container.parentNode.removeChild(graph.container);
  3089. }
  3090. var complete = mxUtils.bind(this, function()
  3091. {
  3092. this.spinner.stop();
  3093. });
  3094. var fn = mxUtils.bind(this, function()
  3095. {
  3096. complete();
  3097. var currentFile = this.getCurrentFile();
  3098. if (replace == null && currentFile != null)
  3099. {
  3100. replace = !currentFile.isModified() && currentFile.getMode() == null;
  3101. }
  3102. var fn3 = mxUtils.bind(this, function()
  3103. {
  3104. window.openFile = null;
  3105. this.fileLoaded(file);
  3106. if (replace)
  3107. {
  3108. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
  3109. }
  3110. if (libs != null)
  3111. {
  3112. this.sidebar.showEntries(libs);
  3113. }
  3114. });
  3115. var fn2 = mxUtils.bind(this, function()
  3116. {
  3117. if (replace || currentFile == null || !currentFile.isModified())
  3118. {
  3119. fn3();
  3120. }
  3121. else
  3122. {
  3123. this.confirm(mxResources.get('allChangesLost'), null, fn3,
  3124. mxResources.get('cancel'), mxResources.get('discardChanges'));
  3125. }
  3126. });
  3127. if (done != null)
  3128. {
  3129. done();
  3130. }
  3131. // Opens the file in a new window
  3132. if (replace != null && !replace)
  3133. {
  3134. // Opens local file in a new window
  3135. if (file.constructor == LocalFile)
  3136. {
  3137. window.openFile = new OpenFile(function()
  3138. {
  3139. window.openFile = null;
  3140. });
  3141. window.openFile.setData(file.getData(), file.getTitle(), file.getMode() == null);
  3142. }
  3143. if (done != null)
  3144. {
  3145. done();
  3146. }
  3147. window.openWindow(url, null, fn2);
  3148. }
  3149. else
  3150. {
  3151. fn2();
  3152. }
  3153. });
  3154. // Updates data in memory for local files and save is implicit
  3155. // via start of realtime for DriveFiles
  3156. if (file.constructor == LocalFile || file.constructor == DriveFile)
  3157. {
  3158. fn();
  3159. }
  3160. else
  3161. {
  3162. file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
  3163. {
  3164. fn();
  3165. }), mxUtils.bind(this, function(resp)
  3166. {
  3167. complete();
  3168. this.handleError(resp);
  3169. }));
  3170. }
  3171. }
  3172. };
  3173. /**
  3174. * Translates this point by the given vector.
  3175. *
  3176. * @param {number} dx X-coordinate of the translation.
  3177. * @param {number} dy Y-coordinate of the translation.
  3178. */
  3179. App.prototype.loadFile = function(id, sameWindow, file)
  3180. {
  3181. this.hideDialog();
  3182. var fn2 = mxUtils.bind(this, function()
  3183. {
  3184. if (id == null || id.length == 0)
  3185. {
  3186. this.editor.setStatus('');
  3187. this.fileLoaded(null);
  3188. }
  3189. else if (this.spinner.spin(document.body, mxResources.get('loading')))
  3190. {
  3191. // Handles files from localStorage
  3192. if (id.charAt(0) == 'L')
  3193. {
  3194. this.spinner.stop();
  3195. if (!isLocalStorage)
  3196. {
  3197. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3198. {
  3199. var tempFile = this.getCurrentFile();
  3200. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3201. }));
  3202. }
  3203. else
  3204. {
  3205. try
  3206. {
  3207. id = decodeURIComponent(id.substring(1));
  3208. var data = localStorage.getItem(id);
  3209. if (data != null)
  3210. {
  3211. this.fileLoaded(new StorageFile(this, data, id));
  3212. }
  3213. else
  3214. {
  3215. throw {message: mxResources.get('fileNotFound')};
  3216. }
  3217. }
  3218. catch (e)
  3219. {
  3220. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3221. {
  3222. var tempFile = this.getCurrentFile();
  3223. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3224. }));
  3225. }
  3226. }
  3227. }
  3228. else if (file != null)
  3229. {
  3230. // File already loaded
  3231. this.spinner.stop();
  3232. this.fileLoaded(file);
  3233. }
  3234. else if (id.charAt(0) == 'R')
  3235. {
  3236. // Raw file encoded into URL
  3237. this.spinner.stop();
  3238. var data = decodeURIComponent(id.substring(1));
  3239. if (data.charAt(0) != '<')
  3240. {
  3241. data = this.editor.graph.decompress(data);
  3242. }
  3243. var tempFile = new LocalFile(this, data, (urlParams['title'] != null) ?
  3244. decodeURIComponent(urlParams['title']) : this.defaultFilename, true);
  3245. tempFile.getHash = function()
  3246. {
  3247. return id;
  3248. };
  3249. this.fileLoaded(tempFile);
  3250. }
  3251. else if (id.charAt(0) == 'U')
  3252. {
  3253. var url = decodeURIComponent(id.substring(1));
  3254. this.loadTemplate(url, mxUtils.bind(this, function(text)
  3255. {
  3256. this.spinner.stop();
  3257. if (text != null && text.length > 0)
  3258. {
  3259. var filename = this.defaultFilename;
  3260. // Tries to find name from URL with valid extensions
  3261. if (urlParams['title'] == null && urlParams['notitle'] != '1')
  3262. {
  3263. var tmp = url;
  3264. var dot = url.lastIndexOf('.');
  3265. var slash = tmp.lastIndexOf('/');
  3266. if (dot > slash && slash > 0)
  3267. {
  3268. tmp = tmp.substring(slash + 1, dot);
  3269. var ext = url.substring(dot);
  3270. if (ext == '.png')
  3271. {
  3272. ext = '.xml';
  3273. }
  3274. if (ext === '.svg' || ext === '.xml' || ext === '.html')
  3275. {
  3276. filename = tmp + ext;
  3277. }
  3278. }
  3279. }
  3280. var tempFile = new LocalFile(this, text, (urlParams['title'] != null) ?
  3281. decodeURIComponent(urlParams['title']) : filename, true);
  3282. tempFile.getHash = function()
  3283. {
  3284. return id;
  3285. };
  3286. if (!this.fileLoaded(tempFile))
  3287. {
  3288. // Fallback for non-public Google Drive diagrams
  3289. if (url.substring(0, 31) == 'https://drive.google.com/uc?id=' &&
  3290. (this.drive != null || typeof window.DriveClient === 'function'))
  3291. {
  3292. this.hideDialog();
  3293. var fallback = mxUtils.bind(this, function()
  3294. {
  3295. if (this.drive != null)
  3296. {
  3297. this.spinner.stop();
  3298. this.loadFile('G' + url.substring(31, url.lastIndexOf('&')), sameWindow);
  3299. return true;
  3300. }
  3301. else
  3302. {
  3303. return false;
  3304. }
  3305. });
  3306. if (!fallback() && this.spinner.spin(document.body, mxResources.get('loading')))
  3307. {
  3308. this.addListener('clientLoaded', fallback);
  3309. }
  3310. }
  3311. }
  3312. }
  3313. }), mxUtils.bind(this, function()
  3314. {
  3315. this.spinner.stop();
  3316. this.handleError({message: mxResources.get('fileNotFound')}, mxResources.get('errorLoadingFile'));
  3317. }));
  3318. }
  3319. else
  3320. {
  3321. // Google Drive files are handled as default file types
  3322. var peer = null;
  3323. if (id.charAt(0) == 'G')
  3324. {
  3325. peer = this.drive;
  3326. }
  3327. else if (id.charAt(0) == 'D')
  3328. {
  3329. peer = this.dropbox;
  3330. }
  3331. else if (id.charAt(0) == 'W')
  3332. {
  3333. peer = this.oneDrive;
  3334. }
  3335. else if (id.charAt(0) == 'H')
  3336. {
  3337. peer = this.gitHub;
  3338. }
  3339. else if (id.charAt(0) == 'T')
  3340. {
  3341. peer = this.trello;
  3342. }
  3343. if (peer == null)
  3344. {
  3345. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3346. {
  3347. var file = this.getCurrentFile();
  3348. window.location.hash = (file != null) ? file.getHash() : '';
  3349. }));
  3350. }
  3351. else
  3352. {
  3353. id = decodeURIComponent(id.substring(1));
  3354. peer.getFile(id, mxUtils.bind(this, function(file)
  3355. {
  3356. this.spinner.stop();
  3357. this.fileLoaded(file);
  3358. }), mxUtils.bind(this, function(resp)
  3359. {
  3360. // Makes sure the file does not save the invalid UI model and overwrites anything important
  3361. if (window.console != null && resp != null)
  3362. {
  3363. console.log('error in loadFile:', id, resp);
  3364. }
  3365. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
  3366. {
  3367. var file = this.getCurrentFile();
  3368. if (file == null)
  3369. {
  3370. window.location.hash = '';
  3371. this.showSplash();
  3372. }
  3373. else
  3374. {
  3375. window.location.hash = file.getHash();
  3376. }
  3377. }));
  3378. }));
  3379. }
  3380. }
  3381. }
  3382. });
  3383. var currentFile = this.getCurrentFile();
  3384. var fn = mxUtils.bind(this, function()
  3385. {
  3386. if (currentFile == null || !currentFile.isModified())
  3387. {
  3388. fn2();
  3389. }
  3390. else
  3391. {
  3392. this.confirm(mxResources.get('allChangesLost'), mxUtils.bind(this, function()
  3393. {
  3394. if (currentFile != null)
  3395. {
  3396. window.location.hash = currentFile.getHash();
  3397. }
  3398. }), fn2, mxResources.get('cancel'), mxResources.get('discardChanges'));
  3399. }
  3400. });
  3401. if (id == null || id.length == 0)
  3402. {
  3403. fn();
  3404. }
  3405. else if (currentFile != null && currentFile.isModified() && !sameWindow)
  3406. {
  3407. window.openWindow(this.getUrl() + '#' + id, null, fn);
  3408. }
  3409. else
  3410. {
  3411. fn();
  3412. }
  3413. };
  3414. /**
  3415. * Translates this point by the given vector.
  3416. *
  3417. * @param {number} dx X-coordinate of the translation.
  3418. * @param {number} dy Y-coordinate of the translation.
  3419. */
  3420. App.prototype.getLibraryStorageHint = function(file)
  3421. {
  3422. var tip = file.getTitle();
  3423. if (file.constructor != LocalLibrary)
  3424. {
  3425. tip += '\n' + file.getHash();
  3426. }
  3427. if (file.constructor == DriveLibrary)
  3428. {
  3429. tip += ' (' + mxResources.get('googleDrive') + ')';
  3430. }
  3431. else if (file.constructor == GitHubLibrary)
  3432. {
  3433. tip += ' (' + mxResources.get('github') + ')';
  3434. }
  3435. else if (file.constructor == TrelloLibrary)
  3436. {
  3437. tip += ' (' + mxResources.get('trello') + ')';
  3438. }
  3439. else if (file.constructor == DropboxLibrary)
  3440. {
  3441. tip += ' (' + mxResources.get('dropbox') + ')';
  3442. }
  3443. else if (file.constructor == OneDriveLibrary)
  3444. {
  3445. tip += ' (' + mxResources.get('oneDrive') + ')';
  3446. }
  3447. else if (file.constructor == StorageLibrary)
  3448. {
  3449. tip += ' (' + mxResources.get('browser') + ')';
  3450. }
  3451. else if (file.constructor == LocalLibrary)
  3452. {
  3453. tip += ' (' + mxResources.get('device') + ')';
  3454. }
  3455. return tip;
  3456. };
  3457. /**
  3458. * Updates action states depending on the selection.
  3459. */
  3460. App.prototype.restoreLibraries = function()
  3461. {
  3462. if (this.sidebar != null)
  3463. {
  3464. if (this.pendingLibraries == null)
  3465. {
  3466. this.pendingLibraries = new Object();
  3467. }
  3468. // Ignores this library next time
  3469. var ignore = mxUtils.bind(this, function(id)
  3470. {
  3471. mxSettings.removeCustomLibrary(id);
  3472. delete this.pendingLibraries[id];
  3473. });
  3474. var load = mxUtils.bind(this, function(libs)
  3475. {
  3476. if (libs != null)
  3477. {
  3478. for (var i = 0; i < libs.length; i++)
  3479. {
  3480. var name = encodeURIComponent(decodeURIComponent(libs[i]));
  3481. (mxUtils.bind(this, function(id)
  3482. {
  3483. if (id != null && id.length > 0 && this.pendingLibraries[id] == null &&
  3484. this.sidebar.palettes[id] == null)
  3485. {
  3486. this.pendingLibraries[id] = true;
  3487. var service = id.substring(0, 1);
  3488. if (service == 'L')
  3489. {
  3490. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3491. {
  3492. try
  3493. {
  3494. var name = decodeURIComponent(id.substring(1));
  3495. var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
  3496. {
  3497. if (name == '.scratchpad' && xml == null)
  3498. {
  3499. xml = this.emptyLibraryXml;
  3500. }
  3501. if (xml != null)
  3502. {
  3503. this.loadLibrary(new StorageLibrary(this, xml, name));
  3504. }
  3505. else
  3506. {
  3507. ignore(id);
  3508. }
  3509. }));
  3510. }
  3511. catch (e)
  3512. {
  3513. ignore(id);
  3514. }
  3515. }
  3516. }
  3517. else if (service == 'U')
  3518. {
  3519. var url = decodeURIComponent(id.substring(1));
  3520. if (!this.isOffline())
  3521. {
  3522. var realUrl = url;
  3523. if (!this.isCorsEnabledForUrl(realUrl))
  3524. {
  3525. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
  3526. }
  3527. // Uses proxy to avoid CORS issues
  3528. mxUtils.get(realUrl, mxUtils.bind(this, function(req)
  3529. {
  3530. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3531. {
  3532. try
  3533. {
  3534. this.loadLibrary(new UrlLibrary(this, req.getText(), url));
  3535. delete this.pendingLibraries[id];
  3536. }
  3537. catch (e)
  3538. {
  3539. ignore(id);
  3540. }
  3541. }
  3542. else
  3543. {
  3544. ignore(id);
  3545. }
  3546. }), function()
  3547. {
  3548. ignore(id);
  3549. });
  3550. }
  3551. }
  3552. else
  3553. {
  3554. var peer = null;
  3555. if (service == 'G')
  3556. {
  3557. if (this.drive != null && this.drive.user != null)
  3558. {
  3559. peer = this.drive;
  3560. }
  3561. }
  3562. else if (service == 'H')
  3563. {
  3564. if (this.gitHub != null && this.gitHub.getUser() != null)
  3565. {
  3566. peer = this.gitHub;
  3567. }
  3568. }
  3569. else if (service == 'T')
  3570. {
  3571. if (this.trello != null && this.trello.isAuthorized())
  3572. {
  3573. peer = this.trello;
  3574. }
  3575. }
  3576. else if (service == 'D')
  3577. {
  3578. if (this.dropbox != null && this.dropbox.getUser() != null)
  3579. {
  3580. peer = this.dropbox;
  3581. }
  3582. }
  3583. else if (service == 'W')
  3584. {
  3585. if (this.oneDrive != null && this.oneDrive.getUser() != null)
  3586. {
  3587. peer = this.oneDrive;
  3588. }
  3589. }
  3590. if (peer != null)
  3591. {
  3592. peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
  3593. {
  3594. try
  3595. {
  3596. this.loadLibrary(file);
  3597. delete this.pendingLibraries[id];
  3598. }
  3599. catch (e)
  3600. {
  3601. ignore(id);
  3602. }
  3603. }), function(resp)
  3604. {
  3605. ignore(id);
  3606. });
  3607. }
  3608. else
  3609. {
  3610. delete this.pendingLibraries[id];
  3611. }
  3612. }
  3613. }
  3614. }))(name);
  3615. }
  3616. }
  3617. });
  3618. load(mxSettings.getCustomLibraries());
  3619. load((urlParams['clibs'] || '').split(';'));
  3620. }
  3621. };
  3622. /**
  3623. * Translates this point by the given vector.
  3624. *
  3625. * @param {number} dx X-coordinate of the translation.
  3626. * @param {number} dy Y-coordinate of the translation.
  3627. */
  3628. App.prototype.updateButtonContainer = function()
  3629. {
  3630. if (this.buttonContainer != null)
  3631. {
  3632. var file = this.getCurrentFile();
  3633. if (file != null && file.constructor == DriveFile)
  3634. {
  3635. // Adds Share button
  3636. if (this.shareButton == null)
  3637. {
  3638. this.shareButton = document.createElement('div');
  3639. this.shareButton.className = 'geBtn gePrimaryBtn';
  3640. this.shareButton.style.display = 'inline-block';
  3641. this.shareButton.style.padding = '0 10px 0 10px';
  3642. this.shareButton.style.marginTop = '-4px';
  3643. this.shareButton.style.height = '28px';
  3644. this.shareButton.style.lineHeight = '28px';
  3645. this.shareButton.style.minWidth = '0px';
  3646. this.shareButton.style.cssFloat = 'right';
  3647. var icon = document.createElement('img');
  3648. icon.setAttribute('src', this.shareImage);
  3649. icon.setAttribute('align', 'absmiddle');
  3650. icon.style.marginRight = '4px';
  3651. icon.style.marginTop = '-3px';
  3652. this.shareButton.appendChild(icon);
  3653. mxUtils.write(this.shareButton, mxResources.get('share'));
  3654. mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
  3655. {
  3656. this.actions.get('share').funct();
  3657. }));
  3658. this.buttonContainer.appendChild(this.shareButton);
  3659. }
  3660. }
  3661. else if (this.shareButton != null)
  3662. {
  3663. this.shareButton.parentNode.removeChild(this.shareButton);
  3664. this.shareButton = null;
  3665. }
  3666. }
  3667. };
  3668. /**
  3669. * Translates this point by the given vector.
  3670. *
  3671. * @param {number} dx X-coordinate of the translation.
  3672. * @param {number} dy Y-coordinate of the translation.
  3673. */
  3674. App.prototype.save = function(name, done)
  3675. {
  3676. var file = this.getCurrentFile();
  3677. var msg = mxResources.get('saving');
  3678. if (file != null && file.constructor == DriveFile)
  3679. {
  3680. msg = mxResources.get('createRevision');
  3681. }
  3682. if (file != null && this.spinner.spin(document.body, msg))
  3683. {
  3684. this.editor.setStatus('');
  3685. if (this.editor.graph.isEditing())
  3686. {
  3687. this.editor.graph.stopEditing();
  3688. }
  3689. var success = mxUtils.bind(this, function(resp)
  3690. {
  3691. this.spinner.stop();
  3692. if (this.getCurrentFile() == file)
  3693. {
  3694. if (file.isModified())
  3695. {
  3696. if (!file.isAutosave())
  3697. {
  3698. file.addUnsavedStatus();
  3699. }
  3700. }
  3701. else
  3702. {
  3703. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
  3704. }
  3705. }
  3706. if (done != null)
  3707. {
  3708. done();
  3709. }
  3710. });
  3711. var error = mxUtils.bind(this, function(resp)
  3712. {
  3713. // Spinner is paused and resumed in handleError
  3714. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  3715. });
  3716. if (name == file.getTitle())
  3717. {
  3718. file.save(true, success, error);
  3719. }
  3720. else
  3721. {
  3722. file.saveAs(name, success, error)
  3723. }
  3724. }
  3725. };
  3726. /**
  3727. * Invokes callback with null if mode does not support folder or not null
  3728. * if a valid folder was chosen for a mode that supports it. No callback
  3729. * is made if no folder was chosen for a mode that supports it.
  3730. */
  3731. App.prototype.pickFolder = function(mode, fn, enabled)
  3732. {
  3733. enabled = (enabled != null) ? enabled : true;
  3734. var resume = this.spinner.pause();
  3735. if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
  3736. {
  3737. // Shows a save dialog
  3738. this.drive.pickFolder(mxUtils.bind(this, function(evt)
  3739. {
  3740. resume();
  3741. if (evt.action == google.picker.Action.PICKED)
  3742. {
  3743. var folderId = null;
  3744. if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
  3745. {
  3746. folderId = evt.docs[0].id;
  3747. }
  3748. fn(folderId);
  3749. }
  3750. }));
  3751. }
  3752. else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  3753. {
  3754. this.oneDrive.pickFolder(mxUtils.bind(this, function(files)
  3755. {
  3756. var folderId = null;
  3757. resume();
  3758. if (files != null && files.value != null && files.value.length > 0)
  3759. {
  3760. folderId = files.value[0].id;
  3761. fn(folderId);
  3762. }
  3763. }));
  3764. }
  3765. else if (enabled && mode == App.MODE_GITHUB && this.gitHub != null)
  3766. {
  3767. this.gitHub.pickFolder(mxUtils.bind(this, function(folderPath)
  3768. {
  3769. resume();
  3770. fn(folderPath);
  3771. }));
  3772. }
  3773. else if (enabled && mode == App.MODE_TRELLO && this.trello != null)
  3774. {
  3775. this.trello.pickFolder(mxUtils.bind(this, function(cardId)
  3776. {
  3777. resume();
  3778. fn(cardId);
  3779. }));
  3780. }
  3781. else
  3782. {
  3783. EditorUi.prototype.pickFolder.apply(this, arguments);
  3784. }
  3785. };
  3786. /**
  3787. *
  3788. */
  3789. App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  3790. {
  3791. if (mode == App.MODE_DROPBOX)
  3792. {
  3793. if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
  3794. {
  3795. // LATER: Add folder picker
  3796. this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  3797. data, mxUtils.bind(this, function()
  3798. {
  3799. this.spinner.stop();
  3800. }), mxUtils.bind(this, function(resp)
  3801. {
  3802. this.spinner.stop();
  3803. this.handleError(resp);
  3804. }));
  3805. }
  3806. }
  3807. else if (mode == App.MODE_GOOGLE)
  3808. {
  3809. if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  3810. {
  3811. this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
  3812. {
  3813. // TODO: Add callback with url param for clickable status message
  3814. // "File exported. Click here to open folder."
  3815. // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
  3816. // mxResources.get('saved') + '</div>');
  3817. //
  3818. // // Installs click handler for opening
  3819. // if (this.statusContainer != null)
  3820. // {
  3821. // var links = this.statusContainer.getElementsByTagName('div');
  3822. //
  3823. // if (links.length > 0)
  3824. // {
  3825. // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
  3826. // {
  3827. // if (resp != null && resp.parents != null && resp.parents.length > 0)
  3828. // {
  3829. // var id = resp.parents[0].id;
  3830. //
  3831. // if (id != null)
  3832. // {
  3833. // window.open('https://drive.google.com/drive/folders/' + id);
  3834. // }
  3835. // }
  3836. // }));
  3837. // }
  3838. // }
  3839. this.spinner.stop();
  3840. }), mxUtils.bind(this, function(resp)
  3841. {
  3842. this.spinner.stop();
  3843. this.handleError(resp);
  3844. }), mimeType, base64Encoded, false);
  3845. }
  3846. }
  3847. else if (mode == App.MODE_ONEDRIVE)
  3848. {
  3849. if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  3850. {
  3851. // KNOWN: OneDrive does not show .svg extension
  3852. this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  3853. data, mxUtils.bind(this, function()
  3854. {
  3855. this.spinner.stop();
  3856. }), mxUtils.bind(this, function(resp)
  3857. {
  3858. this.spinner.stop();
  3859. this.handleError(resp);
  3860. }), false, folderId);
  3861. }
  3862. }
  3863. else if (mode == App.MODE_GITHUB)
  3864. {
  3865. if (this.gitHub != null && this.spinner.spin(document.body, mxResources.get('saving')))
  3866. {
  3867. // Must insert file as library to force the file to be written
  3868. this.gitHub.insertFile(filename, data, mxUtils.bind(this, function()
  3869. {
  3870. this.spinner.stop();
  3871. }), mxUtils.bind(this, function(resp)
  3872. {
  3873. this.spinner.stop();
  3874. this.handleError(resp);
  3875. }), true, folderId, base64Encoded);
  3876. }
  3877. }
  3878. else if (mode == App.MODE_TRELLO)
  3879. {
  3880. if (this.trello != null && this.spinner.spin(document.body, mxResources.get('saving')))
  3881. {
  3882. this.trello.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  3883. data, mxUtils.bind(this, function()
  3884. {
  3885. this.spinner.stop();
  3886. }), mxUtils.bind(this, function(resp)
  3887. {
  3888. this.spinner.stop();
  3889. this.handleError(resp);
  3890. }), false, folderId);
  3891. }
  3892. }
  3893. else if (mode == App.MODE_BROWSER)
  3894. {
  3895. var fn = mxUtils.bind(this, function()
  3896. {
  3897. localStorage.setItem(filename, data);
  3898. });
  3899. if (localStorage.getItem(filename) == null)
  3900. {
  3901. fn();
  3902. }
  3903. else
  3904. {
  3905. this.confirm(mxResources.get('replaceIt', [filename]), fn);
  3906. }
  3907. }
  3908. };
  3909. /**
  3910. * Translates this point by the given vector.
  3911. *
  3912. * @param {number} dx X-coordinate of the translation.
  3913. * @param {number} dy Y-coordinate of the translation.
  3914. */
  3915. App.prototype.descriptorChanged = function()
  3916. {
  3917. var file = this.getCurrentFile();
  3918. if (file != null)
  3919. {
  3920. if (this.fname != null)
  3921. {
  3922. this.fnameWrapper.style.display = 'block';
  3923. this.fname.innerHTML = '';
  3924. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  3925. mxUtils.write(this.fname, filename);
  3926. this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
  3927. }
  3928. this.editor.graph.setEnabled(file.isEditable());
  3929. // Ignores title and hash for revisions
  3930. if (urlParams['rev'] == null)
  3931. {
  3932. this.updateDocumentTitle();
  3933. var newHash = file.getHash();
  3934. if (newHash.length > 0)
  3935. {
  3936. window.location.hash = newHash;
  3937. }
  3938. else if (window.location.hash.length > 0)
  3939. {
  3940. window.location.hash = '';
  3941. }
  3942. }
  3943. }
  3944. };
  3945. /**
  3946. * Translates this point by the given vector.
  3947. *
  3948. * @param {number} dx X-coordinate of the translation.
  3949. * @param {number} dy Y-coordinate of the translation.
  3950. */
  3951. App.prototype.toggleChat = function()
  3952. {
  3953. var file = this.getCurrentFile();
  3954. if (file != null)
  3955. {
  3956. if (file.chatWindow == null)
  3957. {
  3958. var cwLeft = document.body.offsetWidth - 300;
  3959. file.chatWindow = new ChatWindow(this, mxResources.get('chatWindowTitle'), document.getElementById('geChat'), cwLeft , 80, 250, 350, file.realtime);
  3960. file.chatWindow.window.setVisible(false);
  3961. }
  3962. file.chatWindow.window.setVisible(!file.chatWindow.window.isVisible());
  3963. }
  3964. };
  3965. /**
  3966. * Adds the listener for automatically saving the diagram for local changes.
  3967. */
  3968. App.prototype.showAuthDialog = function(peer, showRememberOption, fn, closeFn)
  3969. {
  3970. var resume = this.spinner.pause();
  3971. this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
  3972. {
  3973. try
  3974. {
  3975. if (fn != null)
  3976. {
  3977. fn(remember, mxUtils.bind(this, function()
  3978. {
  3979. this.hideDialog();
  3980. resume();
  3981. }));
  3982. }
  3983. }
  3984. catch (e)
  3985. {
  3986. this.editor.setStatus(mxUtils.htmlEntities(e.message));
  3987. }
  3988. })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
  3989. {
  3990. if (closeFn != null)
  3991. {
  3992. closeFn();
  3993. }
  3994. if (cancel && this.getCurrentFile() == null && this.dialog == null)
  3995. {
  3996. this.showSplash();
  3997. }
  3998. }));
  3999. };
  4000. /**
  4001. * Checks if the client is authorized and calls the next step. The optional
  4002. * readXml argument is used for import. Default is false. The optional
  4003. * readLibrary argument is used for reading libraries. Default is false.
  4004. */
  4005. App.prototype.convertFile = function(url, filename, mimeType, extension, success, error)
  4006. {
  4007. var name = filename;
  4008. // SVG file extensions are valid and needed for image import
  4009. if (!/\.svg$/i.test(name))
  4010. {
  4011. name = name.substring(0, filename.lastIndexOf('.')) + extension;
  4012. }
  4013. var gitHubUrl = false;
  4014. if (this.gitHub != null && url.substring(0, this.gitHub.baseUrl.length) == this.gitHub.baseUrl)
  4015. {
  4016. gitHubUrl = true;
  4017. }
  4018. // Workaround for wrong binary response with VSDX files
  4019. if (/\.vsdx$/i.test(filename) && Graph.fileSupport && new XMLHttpRequest().upload &&
  4020. typeof new XMLHttpRequest().responseType === 'string')
  4021. {
  4022. var req = new XMLHttpRequest();
  4023. req.open('GET', url, true);
  4024. if (!gitHubUrl)
  4025. {
  4026. req.responseType = 'blob';
  4027. }
  4028. req.onload = mxUtils.bind(this, function()
  4029. {
  4030. var blob = null;
  4031. if (gitHubUrl)
  4032. {
  4033. var file = JSON.parse(req.responseText);
  4034. blob = this.base64ToBlob(file.content, 'application/octet-stream');
  4035. }
  4036. else
  4037. {
  4038. blob = new Blob([req.response], {type: 'application/octet-stream'});
  4039. }
  4040. this.parseFile(blob, mxUtils.bind(this, function(xhr)
  4041. {
  4042. if (xhr.readyState == 4)
  4043. {
  4044. if (xhr.status >= 200 && xhr.status <= 299)
  4045. {
  4046. success(new LocalFile(this, xhr.responseText, name, true));
  4047. }
  4048. else if (error != null)
  4049. {
  4050. error({message: mxResources.get('errorLoadingFile')});
  4051. }
  4052. }
  4053. }), filename);
  4054. });
  4055. req.send();
  4056. }
  4057. else
  4058. {
  4059. var handleData = mxUtils.bind(this, function(data)
  4060. {
  4061. try
  4062. {
  4063. if (/\.png$/i.test(filename))
  4064. {
  4065. temp = this.extractGraphModelFromPng(data);
  4066. if (temp != null)
  4067. {
  4068. success(new LocalFile(this, temp, name, true));
  4069. }
  4070. else
  4071. {
  4072. success(new LocalFile(this, data, filename, true));
  4073. }
  4074. }
  4075. else if (Graph.fileSupport && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  4076. {
  4077. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  4078. {
  4079. if (xhr.readyState == 4)
  4080. {
  4081. if (xhr.status >= 200 && xhr.status <= 299)
  4082. {
  4083. success(new LocalFile(this, xhr.responseText, name, true));
  4084. }
  4085. else if (error != null)
  4086. {
  4087. error({message: mxResources.get('errorLoadingFile')});
  4088. }
  4089. }
  4090. }), filename);
  4091. }
  4092. else
  4093. {
  4094. success(new LocalFile(this, data, name, true));
  4095. }
  4096. }
  4097. catch (e)
  4098. {
  4099. if (error != null)
  4100. {
  4101. error(e);
  4102. }
  4103. }
  4104. });
  4105. var binary = /\.png$/i.test(filename) || /\.jpe?g$/i.test(filename) || (mimeType != null &&
  4106. mimeType.substring(0, 6) == 'image/');
  4107. // NOTE: Cannot force non-binary request via loadUrl so needs separate
  4108. // code as decoding twice on content with binary data did not work
  4109. if (gitHubUrl)
  4110. {
  4111. mxUtils.get(url, mxUtils.bind(this, function(req)
  4112. {
  4113. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  4114. {
  4115. if (success != null)
  4116. {
  4117. var file = JSON.parse(req.getText());
  4118. var data = file.content;
  4119. if (file.encoding === 'base64')
  4120. {
  4121. if (/\.png$/i.test(filename))
  4122. {
  4123. data = 'data:image/png;base64,' + data;
  4124. }
  4125. else
  4126. {
  4127. // Workaround for character encoding issues in IE10/11
  4128. data = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ? atob(data) : Base64.decode(data);
  4129. }
  4130. }
  4131. handleData(data);
  4132. }
  4133. }
  4134. else if (error != null)
  4135. {
  4136. error({code: App.ERROR_UNKNOWN});
  4137. }
  4138. }), function()
  4139. {
  4140. if (error != null)
  4141. {
  4142. error({code: App.ERROR_UNKNOWN});
  4143. }
  4144. }, false, this.timeout, function()
  4145. {
  4146. if (error != null)
  4147. {
  4148. error({code: App.ERROR_TIMEOUT, retry: fn});
  4149. }
  4150. });
  4151. }
  4152. else
  4153. {
  4154. this.loadUrl(url, handleData, error, binary);
  4155. }
  4156. }
  4157. };
  4158. /**
  4159. * Adds the listener for automatically saving the diagram for local changes.
  4160. */
  4161. App.prototype.updateHeader = function()
  4162. {
  4163. if (this.menubar != null)
  4164. {
  4165. this.appIcon = document.createElement('a');
  4166. this.appIcon.style.display = 'block';
  4167. this.appIcon.style.position = 'absolute';
  4168. this.appIcon.style.width = '40px';
  4169. this.appIcon.style.backgroundColor = '#f18808';
  4170. this.appIcon.style.height = this.menubarHeight + 'px';
  4171. mxEvent.disableContextMenu(this.appIcon);
  4172. mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
  4173. {
  4174. this.appIconClicked(evt);
  4175. }));
  4176. // LATER: Use Alpha image loader in IE6
  4177. // NOTE: This uses the diagram bit of the old logo as it looks better in this case
  4178. //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
  4179. var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
  4180. 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
  4181. this.appIcon.style.backgroundImage = logo;
  4182. this.appIcon.style.backgroundPosition = 'center center';
  4183. this.appIcon.style.backgroundRepeat = 'no-repeat';
  4184. mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
  4185. mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
  4186. {
  4187. var file = this.getCurrentFile();
  4188. if (file != null)
  4189. {
  4190. var mode = file.getMode();
  4191. if (mode == App.MODE_GOOGLE)
  4192. {
  4193. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
  4194. }
  4195. else if (mode == App.MODE_DROPBOX)
  4196. {
  4197. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
  4198. }
  4199. else if (mode == App.MODE_ONEDRIVE)
  4200. {
  4201. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
  4202. }
  4203. else if (mode == App.MODE_GITHUB)
  4204. {
  4205. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/github-logo-white.svg)';
  4206. }
  4207. else if (mode == App.MODE_TRELLO)
  4208. {
  4209. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/trello-logo-white.svg)';
  4210. }
  4211. }
  4212. }));
  4213. mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
  4214. {
  4215. this.appIcon.style.backgroundImage = logo;
  4216. }));
  4217. if (urlParams['embed'] != '1')
  4218. {
  4219. this.menubarContainer.appendChild(this.appIcon);
  4220. }
  4221. this.fnameWrapper = document.createElement('div');
  4222. this.fnameWrapper.style.position = 'absolute';
  4223. this.fnameWrapper.style.right = '120px';
  4224. this.fnameWrapper.style.left = '50px';
  4225. this.fnameWrapper.style.top = '6px';
  4226. this.fnameWrapper.style.height = '26px';
  4227. this.fnameWrapper.style.display = 'none';
  4228. this.fnameWrapper.style.overflow = 'hidden';
  4229. this.fnameWrapper.style.textOverflow = 'ellipsis';
  4230. this.fname = document.createElement('a');
  4231. this.fname.setAttribute('href', 'javascript:void(0);');
  4232. this.fname.setAttribute('title', mxResources.get('rename'));
  4233. this.fname.className = 'geItem';
  4234. this.fname.style.padding = '2px 8px 2px 8px';
  4235. this.fname.style.display = 'inline';
  4236. this.fname.style.fontSize = '18px';
  4237. this.fname.style.whiteSpace = 'nowrap';
  4238. mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
  4239. {
  4240. var file = this.getCurrentFile();
  4241. if (file != null && file.isRenamable())
  4242. {
  4243. this.actions.get('rename').funct();
  4244. }
  4245. mxEvent.consume(evt);
  4246. }));
  4247. this.fnameWrapper.appendChild(this.fname);
  4248. if (urlParams['embed'] != '1')
  4249. {
  4250. this.menubarContainer.appendChild(this.fnameWrapper);
  4251. this.menubar.container.style.position = 'absolute';
  4252. this.menubar.container.style.paddingLeft = '52px';
  4253. this.menubar.container.style.boxSizing = 'border-box';
  4254. this.menubar.container.style.top = '29px';
  4255. this.toolbar.container.style.paddingLeft = '56px';
  4256. }
  4257. /**
  4258. * Adds format panel toggle.
  4259. */
  4260. this.toggleFormatElement = document.createElement('a');
  4261. this.toggleFormatElement.setAttribute('href', 'javascript:void(0);');
  4262. this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (' + Editor.ctrlKey + '+Shift+P)');
  4263. this.toggleFormatElement.style.position = 'absolute';
  4264. this.toggleFormatElement.style.display = 'inline-block';
  4265. this.toggleFormatElement.style.top = '5px';
  4266. this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '26px' : '10px';
  4267. this.toggleFormatElement.style.padding = '2px';
  4268. this.toggleFormatElement.style.fontSize = '14px';
  4269. this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4270. this.toggleFormatElement.style.width = '16px';
  4271. this.toggleFormatElement.style.height = '16px';
  4272. this.toggleFormatElement.style.backgroundPosition = '50% 50%';
  4273. this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
  4274. this.toolbarContainer.appendChild(this.toggleFormatElement);
  4275. mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
  4276. {
  4277. this.actions.get('formatPanel').funct();
  4278. mxEvent.consume(evt);
  4279. }));
  4280. var toggleFormatPanel = mxUtils.bind(this, function()
  4281. {
  4282. if (this.formatWidth > 0)
  4283. {
  4284. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
  4285. }
  4286. else
  4287. {
  4288. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
  4289. }
  4290. });
  4291. this.addListener('formatWidthChanged', toggleFormatPanel);
  4292. toggleFormatPanel();
  4293. this.fullscreenElement = document.createElement('a');
  4294. this.fullscreenElement.setAttribute('href', 'javascript:void(0);');
  4295. this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
  4296. this.fullscreenElement.style.position = 'absolute';
  4297. this.fullscreenElement.style.display = 'inline-block';
  4298. this.fullscreenElement.style.top = '5px';
  4299. this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '42px' : '26px';
  4300. this.fullscreenElement.style.padding = '2px';
  4301. this.fullscreenElement.style.fontSize = '14px';
  4302. this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4303. this.fullscreenElement.style.width = '16px';
  4304. this.fullscreenElement.style.height = '16px';
  4305. this.fullscreenElement.style.backgroundPosition = '50% 50%';
  4306. this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
  4307. this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
  4308. this.toolbarContainer.appendChild(this.fullscreenElement);
  4309. var initialPosition = this.hsplitPosition;
  4310. var collapsed = false;
  4311. mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
  4312. {
  4313. if (uiTheme != 'atlas' && urlParams['embed'] != '1')
  4314. {
  4315. this.toggleCompactMode(!collapsed);
  4316. }
  4317. this.toggleFormatPanel(!collapsed);
  4318. this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
  4319. this.hideFooter();
  4320. collapsed = !collapsed;
  4321. mxEvent.consume(evt);
  4322. }));
  4323. // Some style changes in Atlas theme
  4324. if (uiTheme == 'atlas')
  4325. {
  4326. mxUtils.setOpacity(this.toggleFormatElement, 70);
  4327. mxUtils.setOpacity(this.fullscreenElement, 70);
  4328. this.toggleFormatElement.style.right = '6px';
  4329. this.fullscreenElement.style.right = '22px';
  4330. this.toggleFormatElement.style.top = '8px';
  4331. this.fullscreenElement.style.top = '8px';
  4332. }
  4333. /**
  4334. * Adds compact UI toggle.
  4335. */
  4336. if (urlParams['embed'] != '1')
  4337. {
  4338. this.toggleElement = document.createElement('a');
  4339. this.toggleElement.setAttribute('href', 'javascript:void(0);');
  4340. this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
  4341. this.toggleElement.className = 'geButton';
  4342. this.toggleElement.style.position = 'absolute';
  4343. this.toggleElement.style.display = 'inline-block';
  4344. this.toggleElement.style.width = '16px';
  4345. this.toggleElement.style.height = '16px';
  4346. this.toggleElement.style.color = '#666';
  4347. this.toggleElement.style.top = '5px';
  4348. this.toggleElement.style.right = '10px';
  4349. this.toggleElement.style.padding = '2px';
  4350. this.toggleElement.style.fontSize = '14px';
  4351. this.toggleElement.style.textDecoration = 'none';
  4352. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4353. this.toggleElement.style.backgroundPosition = '50% 50%';
  4354. this.toggleElement.style.backgroundRepeat = 'no-repeat';
  4355. // Toggles compact mode
  4356. mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
  4357. {
  4358. this.toggleCompactMode();
  4359. mxEvent.consume(evt);
  4360. }));
  4361. if (uiTheme != 'atlas')
  4362. {
  4363. this.toolbarContainer.appendChild(this.toggleElement);
  4364. }
  4365. // Enable compact mode for small screens
  4366. if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
  4367. {
  4368. window.setTimeout(mxUtils.bind(this, function()
  4369. {
  4370. this.toggleElement.click();
  4371. }), 0);
  4372. }
  4373. }
  4374. }
  4375. };
  4376. /**
  4377. * Adds the listener for automatically saving the diagram for local changes.
  4378. */
  4379. App.prototype.toggleCompactMode = function(forceHide)
  4380. {
  4381. if (!forceHide && this.appIcon.style.display == 'none')
  4382. {
  4383. this.menubar.container.style.position = 'absolute';
  4384. this.menubar.container.style.paddingLeft = '52px';
  4385. this.menubar.container.style.paddingTop = '';
  4386. this.menubar.container.style.paddingBottom = '';
  4387. this.menubar.container.style.top = '29px';
  4388. this.toolbar.container.style.paddingLeft = '56px';
  4389. this.buttonContainer.style.visibility = 'visible';
  4390. this.appIcon.style.display = 'block';
  4391. this.fnameWrapper.style.display = 'block';
  4392. this.fnameWrapper.style.visibility = 'visible';
  4393. this.menubarHeight = App.prototype.menubarHeight;
  4394. this.refresh();
  4395. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4396. }
  4397. else
  4398. {
  4399. this.menubar.container.style.position = 'relative';
  4400. this.menubar.container.style.paddingLeft = '4px';
  4401. this.menubar.container.style.paddingTop = '0px';
  4402. this.menubar.container.style.paddingBottom = '0px';
  4403. this.menubar.container.style.top = '0px';
  4404. this.toolbar.container.style.paddingLeft = '4px';
  4405. this.buttonContainer.style.visibility = 'hidden';
  4406. this.appIcon.style.display = 'none';
  4407. this.fnameWrapper.style.display = 'none';
  4408. this.fnameWrapper.style.visibility = 'hidden';
  4409. this.menubarHeight = EditorUi.prototype.menubarHeight;
  4410. this.refresh();
  4411. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
  4412. }
  4413. };
  4414. /**
  4415. * Adds the listener for automatically saving the diagram for local changes.
  4416. */
  4417. App.prototype.updateUserElement = function()
  4418. {
  4419. if ((this.drive == null || this.drive.getUser() == null) &&
  4420. (this.oneDrive == null || this.oneDrive.getUser() == null) &&
  4421. (this.dropbox == null || this.dropbox.getUser() == null) &&
  4422. (this.gitHub == null || this.gitHub.getUser() == null) &&
  4423. (this.trello == null || !this.trello.isAuthorized())) //TODO Trello no user issue
  4424. {
  4425. if (this.userElement != null)
  4426. {
  4427. this.userElement.parentNode.removeChild(this.userElement);
  4428. this.userElement = null;
  4429. }
  4430. }
  4431. else
  4432. {
  4433. if (this.userElement == null)
  4434. {
  4435. this.userElement = document.createElement('a');
  4436. this.userElement.setAttribute('href', 'javascript:void(0);');
  4437. this.userElement.className = 'geItem';
  4438. this.userElement.style.position = 'absolute';
  4439. this.userElement.style.fontSize = '8pt';
  4440. this.userElement.style.top = '4px';
  4441. this.userElement.style.right = '30px';
  4442. this.userElement.style.color = '#666';
  4443. this.userElement.style.margin = '4px';
  4444. this.userElement.style.padding = '2px';
  4445. this.userElement.style.paddingRight = '16px';
  4446. this.userElement.style.verticalAlign = 'middle';
  4447. this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  4448. this.userElement.style.backgroundPosition = '100% 60%';
  4449. this.userElement.style.backgroundRepeat = 'no-repeat';
  4450. this.menubarContainer.appendChild(this.userElement);
  4451. mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
  4452. {
  4453. if (this.userPanel == null)
  4454. {
  4455. var div = document.createElement('div');
  4456. div.className = 'geDialog';
  4457. div.style.position = 'absolute';
  4458. div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
  4459. div.style.right = '36px';
  4460. div.style.padding = '0px';
  4461. this.userPanel = div;
  4462. }
  4463. if (this.userPanel.parentNode != null)
  4464. {
  4465. this.userPanel.parentNode.removeChild(this.userPanel);
  4466. }
  4467. else
  4468. {
  4469. var connected = false;
  4470. this.userPanel.innerHTML = '';
  4471. var img = document.createElement('img');
  4472. img.setAttribute('src', Dialog.prototype.closeImage);
  4473. img.setAttribute('title', mxResources.get('close'));
  4474. img.className = 'geDialogClose';
  4475. img.style.top = '8px';
  4476. img.style.right = '8px';
  4477. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  4478. {
  4479. if (this.userPanel.parentNode != null)
  4480. {
  4481. this.userPanel.parentNode.removeChild(this.userPanel);
  4482. }
  4483. }));
  4484. this.userPanel.appendChild(img);
  4485. if (this.drive != null)
  4486. {
  4487. var driveUser = this.drive.getUser();
  4488. if (driveUser != null)
  4489. {
  4490. connected = true;
  4491. this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
  4492. '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
  4493. '<tr><td valign="top">' +
  4494. ((driveUser.pictureUrl != null) ?
  4495. '<img style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
  4496. '<img style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
  4497. '</td><td valign="top" style="white-space:nowrap;' +
  4498. ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
  4499. '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
  4500. '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small></tr></table>';
  4501. var div = document.createElement('div');
  4502. div.style.textAlign = 'center';
  4503. div.style.padding = '12px';
  4504. div.style.background = 'whiteSmoke';
  4505. div.style.borderTop = '1px solid #e0e0e0';
  4506. div.style.whiteSpace = 'nowrap';
  4507. // LATER: Cannot change user while file is open since close will not work with new
  4508. // credentials and closing the file using fileLoaded(null) will show splash dialog.
  4509. div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
  4510. {
  4511. var file = this.getCurrentFile();
  4512. if (file != null && file.constructor == DriveFile)
  4513. {
  4514. this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
  4515. {
  4516. this.spinner.spin(document.body, mxResources.get('signOut'));
  4517. this.diagramContainer.style.display = 'none';
  4518. this.formatContainer.style.display = 'none';
  4519. this.hsplit.style.display = 'none';
  4520. this.sidebarContainer.style.display = 'none';
  4521. this.sidebarFooterContainer.style.display = 'none';
  4522. if (this.tabContainer != null)
  4523. {
  4524. this.tabContainer.style.display = 'none';
  4525. }
  4526. file.close();
  4527. // LATER: Use callback to wait for thumbnail update
  4528. window.setTimeout(mxUtils.bind(this, function()
  4529. {
  4530. // Workaround to disable the splash screen before reload
  4531. this.showDialog = function() {};
  4532. window.location.hash = '';
  4533. this.drive.clearUserId();
  4534. gapi.auth.signOut();
  4535. // Reload page to reset client auth
  4536. window.location.reload();
  4537. }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
  4538. }));
  4539. }
  4540. else
  4541. {
  4542. this.drive.clearUserId();
  4543. this.drive.setUser(null);
  4544. gapi.auth.signOut();
  4545. }
  4546. })));
  4547. this.userPanel.appendChild(div);
  4548. }
  4549. }
  4550. var addUser = mxUtils.bind(this, function(user, logo, logout)
  4551. {
  4552. if (user != null)
  4553. {
  4554. if (connected)
  4555. {
  4556. this.userPanel.appendChild(document.createElement('hr'));
  4557. }
  4558. connected = true;
  4559. this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
  4560. ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
  4561. '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
  4562. ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font></td>' : '') +
  4563. '</tr></table>';
  4564. var div = document.createElement('div');
  4565. div.style.textAlign = 'center';
  4566. div.style.padding = '12px';
  4567. div.style.background = 'whiteSmoke';
  4568. div.style.borderTop = '1px solid #e0e0e0';
  4569. div.style.whiteSpace = 'nowrap';
  4570. if (logout != null)
  4571. {
  4572. div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
  4573. }
  4574. this.userPanel.appendChild(div);
  4575. }
  4576. });
  4577. if (this.dropbox != null)
  4578. {
  4579. addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
  4580. {
  4581. var file = this.getCurrentFile();
  4582. if (file != null && file.constructor == DropboxFile)
  4583. {
  4584. var doLogout = mxUtils.bind(this, function()
  4585. {
  4586. this.dropbox.logout();
  4587. window.location.hash = '';
  4588. });
  4589. if (!file.isModified())
  4590. {
  4591. doLogout();
  4592. }
  4593. else
  4594. {
  4595. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4596. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4597. }
  4598. }
  4599. else
  4600. {
  4601. this.dropbox.logout();
  4602. }
  4603. }));
  4604. }
  4605. if (this.oneDrive != null)
  4606. {
  4607. addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
  4608. {
  4609. var file = this.getCurrentFile();
  4610. if (file != null && file.constructor == OneDriveFile)
  4611. {
  4612. var doLogout = mxUtils.bind(this, function()
  4613. {
  4614. this.oneDrive.logout();
  4615. window.location.hash = '';
  4616. });
  4617. if (!file.isModified())
  4618. {
  4619. doLogout();
  4620. }
  4621. else
  4622. {
  4623. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4624. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4625. }
  4626. }
  4627. else
  4628. {
  4629. this.oneDrive.logout();
  4630. }
  4631. }));
  4632. }
  4633. if (this.gitHub != null)
  4634. {
  4635. addUser(this.gitHub.getUser(), IMAGE_PATH + '/github-logo.svg', mxUtils.bind(this, function()
  4636. {
  4637. var file = this.getCurrentFile();
  4638. if (file != null && file.constructor == GitHubFile)
  4639. {
  4640. var doLogout = mxUtils.bind(this, function()
  4641. {
  4642. this.gitHub.logout();
  4643. window.location.hash = '';
  4644. });
  4645. if (!file.isModified())
  4646. {
  4647. doLogout();
  4648. }
  4649. else
  4650. {
  4651. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4652. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4653. }
  4654. }
  4655. else
  4656. {
  4657. this.gitHub.logout();
  4658. }
  4659. }));
  4660. }
  4661. //TODO We have no user info from Trello, how we can create a user?
  4662. if (this.trello != null)
  4663. {
  4664. addUser(this.trello.getUser(), IMAGE_PATH + '/trello-logo.svg', mxUtils.bind(this, function()
  4665. {
  4666. var file = this.getCurrentFile();
  4667. if (file != null && file.constructor == TrelloFile)
  4668. {
  4669. var doLogout = mxUtils.bind(this, function()
  4670. {
  4671. this.trello.logout();
  4672. window.location.hash = '';
  4673. });
  4674. if (!file.isModified())
  4675. {
  4676. doLogout();
  4677. }
  4678. else
  4679. {
  4680. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4681. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4682. }
  4683. }
  4684. else
  4685. {
  4686. this.trello.logout();
  4687. }
  4688. }));
  4689. }
  4690. if (!connected)
  4691. {
  4692. var div = document.createElement('div');
  4693. div.style.textAlign = 'center';
  4694. div.style.padding = '20px 20px 10px 10px';
  4695. div.innerHTML = mxResources.get('notConnected');
  4696. this.userPanel.appendChild(div);
  4697. }
  4698. document.body.appendChild(this.userPanel);
  4699. }
  4700. mxEvent.consume(evt);
  4701. }));
  4702. mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
  4703. {
  4704. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  4705. {
  4706. this.userPanel.parentNode.removeChild(this.userPanel);
  4707. }
  4708. }));
  4709. }
  4710. var user = null;
  4711. if (this.drive != null && this.drive.getUser() != null)
  4712. {
  4713. user = this.drive.getUser();
  4714. }
  4715. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  4716. {
  4717. user = this.oneDrive.getUser();
  4718. }
  4719. else if (this.dropbox != null && this.dropbox.getUser() != null)
  4720. {
  4721. user = this.dropbox.getUser();
  4722. }
  4723. else if (this.gitHub != null && this.gitHub.getUser() != null)
  4724. {
  4725. user = this.gitHub.getUser();
  4726. }
  4727. //TODO Trello no user issue
  4728. if (user != null)
  4729. {
  4730. this.userElement.innerHTML = '';
  4731. if (screen.width > 560)
  4732. {
  4733. mxUtils.write(this.userElement, user.displayName);
  4734. this.userElement.style.display = 'block';
  4735. }
  4736. }
  4737. else
  4738. {
  4739. this.userElement.style.display = 'none';
  4740. }
  4741. }
  4742. };
  4743. /**
  4744. * Override depends on mxSettings which is not defined in the minified viewer.
  4745. */
  4746. var editorResetGraph = Editor.prototype.resetGraph;
  4747. Editor.prototype.resetGraph = function()
  4748. {
  4749. editorResetGraph.apply(this, arguments);
  4750. // Overrides default with persisted value
  4751. this.graph.pageFormat = mxSettings.getPageFormat();
  4752. };