App.js 142 KB

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