App.js 138 KB

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