App.js 139 KB

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