App.js 137 KB

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