App.js 125 KB

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