App.js 129 KB

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