App.js 137 KB

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