App.js 147 KB

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