App.js 145 KB

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