App.js 139 KB

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