App.js 139 KB

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