App.js 127 KB

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