App.js 139 KB

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