App.js 144 KB

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