App.js 147 KB

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