App.js 140 KB

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