App.js 148 KB

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