App.js 138 KB

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