App.js 184 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472
  1. /**
  2. * Copyright (c) 2006-2016, JGraph Ltd
  3. * Copyright (c) 2006-2016, Gaudenz Alder
  4. */
  5. /**
  6. * Constructs a new point for the optional x and y coordinates. If no
  7. * coordinates are given, then the default values for <x> and <y> are used.
  8. * @constructor
  9. * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
  10. * @param {number} x X-coordinate of the point.
  11. * @param {number} y Y-coordinate of the point.
  12. */
  13. App = function(editor, container, lightbox)
  14. {
  15. EditorUi.call(this, editor, container, (lightbox != null) ? lightbox : urlParams['lightbox'] == '1');
  16. // Pre-fetches images
  17. if (mxClient.IS_SVG)
  18. {
  19. mxGraph.prototype.warningImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAE7SURBVHjaYvz//z8DJQAggBjwGXDuHMP/tWuD/uPTCxBAOA0AaQRK/f/+XeJ/cbHlf1wGAAQQTgPu3QNLgfHSpZo4DQAIIKwGwGyH4e/fFbG6AiQJEEAs2Ew2NFzH8OOHBMO6dT/A/KCg7wxGRh+wuhQggDBcALMdFIAcHBxgDGJjcwVIIUAAYbhAUXEdVos4OO4DXcGBIQ4QQCguQPY7sgtgAYruCpAgQACx4LJdU1OCwctLEcyWlLwPJF+AXQE0EMUBAAEEdwF6yMOiD4RRY0QT7gqQAEAAseDzu6XldYYPH9DD4joQa8L5AAEENgWb7SBcXa0JDQMBrK4AcQACiAlfyOMCEFdAnAYQQEz4FLa0XGf4/v0H0IIPONUABBAjyBmMjIwMS5cK/L927QORbtBkaG29DtYLEGAAH6f7oq3Zc+kAAAAASUVORK5CYII=';
  20. }
  21. else
  22. {
  23. var img = new Image();
  24. img.src = mxGraph.prototype.warningImage.src;
  25. }
  26. // Global helper method to deal with popup blockers
  27. window.openWindow = mxUtils.bind(this, function(url, pre, fallback)
  28. {
  29. var wnd = window.open(url);
  30. if (wnd == null || wnd === undefined)
  31. {
  32. this.showDialog(new PopupDialog(this, url, pre, fallback).container, 320, 140, true, true);
  33. }
  34. else if (pre != null)
  35. {
  36. pre();
  37. }
  38. });
  39. // Initial state for toolbar items is disabled
  40. this.updateUi();
  41. // Checks if canvas is supported
  42. var cnv = document.createElement('canvas');
  43. this.canvasSupported = !!(cnv.getContext && cnv.getContext('2d'));
  44. // Global helper method to display error messages
  45. window.showOpenAlert = mxUtils.bind(this, function(message)
  46. {
  47. // Cancel must be called before showing error message
  48. if (window.openFile != null)
  49. {
  50. window.openFile.cancel(true);
  51. }
  52. this.handleError(message);
  53. });
  54. // Sets help link for placeholders
  55. if (!this.isOffline())
  56. {
  57. EditDataDialog.placeholderHelpLink = 'https://support.draw.io/questions/9338941';
  58. }
  59. // Handles opening files via drag and drop
  60. this.addFileDropHandler([document]);
  61. // Process the queue for waiting plugins
  62. if (App.DrawPlugins != null)
  63. {
  64. for (var i = 0; i < App.DrawPlugins.length; i++)
  65. {
  66. try
  67. {
  68. App.DrawPlugins[i](this);
  69. }
  70. catch (e)
  71. {
  72. if (window.console != null)
  73. {
  74. console.log('Plugin Error:', e, App.DrawPlugins[i]);
  75. }
  76. }
  77. }
  78. window.Draw.loadPlugin = function(callback)
  79. {
  80. callback(this);
  81. };
  82. }
  83. this.load();
  84. };
  85. /**
  86. * Executes the first step for connecting to Google Drive.
  87. */
  88. App.ERROR_TIMEOUT = 'timeout';
  89. /**
  90. * Executes the first step for connecting to Google Drive.
  91. */
  92. App.ERROR_BUSY = 'busy';
  93. /**
  94. * Executes the first step for connecting to Google Drive.
  95. */
  96. App.ERROR_UNKNOWN = 'unknown';
  97. /**
  98. * Sets the delay for autosave in milliseconds. Default is 2000.
  99. */
  100. App.MODE_GOOGLE = 'google';
  101. /**
  102. * Sets the delay for autosave in milliseconds. Default is 2000.
  103. */
  104. App.MODE_DROPBOX = 'dropbox';
  105. /**
  106. * Sets the delay for autosave in milliseconds. Default is 2000.
  107. */
  108. App.MODE_ONEDRIVE = 'onedrive';
  109. /**
  110. * Sets the delay for autosave in milliseconds. Default is 2000.
  111. */
  112. App.MODE_DEVICE = 'device';
  113. /**
  114. * Sets the delay for autosave in milliseconds. Default is 2000.
  115. */
  116. App.MODE_BROWSER = 'browser';
  117. /**
  118. * Sets the delay for autosave in milliseconds. Default is 2000.
  119. */
  120. App.DROPBOX_APPKEY = 'libwls2fa9szdji';
  121. /**
  122. * Defines plugin keys for loading via p URL parameter.
  123. */
  124. App.pluginRegistry = {'4xAKTrabTpTzahoLthkwPNUn': '/plugins/explore.js',
  125. 'ex': '/plugins/explore.js', 'p1': '/plugins/p1.js', 'ac': '/plugins/connect.js',
  126. 'acj': '/plugins/connectJira.js', 'voice': '/plugins/voice.js',
  127. 'tips': '/plugins/tooltips.js', 'svgdata': '/plugins/svgdata.js',
  128. 'doors': '/plugins/doors.js', 'electron': 'plugins/electron.js',
  129. 'tags': '/plugins/tags.js'};
  130. /**
  131. * Function: authorize
  132. *
  133. * Authorizes the client, gets the userId and calls <open>.
  134. */
  135. App.getStoredMode = function()
  136. {
  137. var mode = null;
  138. if (typeof(Storage) != 'undefined')
  139. {
  140. var cookies = document.cookie.split(";");
  141. for (var i = 0; i < cookies.length; i++)
  142. {
  143. // Removes spaces around cookie
  144. var cookie = mxUtils.trim(cookies[i]);
  145. if (cookie.substring(0, 5) == 'MODE=')
  146. {
  147. mode = cookie.substring(5);
  148. break;
  149. }
  150. }
  151. }
  152. return mode;
  153. };
  154. /**
  155. * Static Application initializer executed at load-time.
  156. */
  157. (function()
  158. {
  159. // Checks for local storage and SVG support
  160. window.isSvgBrowser = window.isSvgBrowser || (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 9);
  161. if (!mxClient.IS_CHROMEAPP)
  162. {
  163. if (urlParams['offline'] != '1')
  164. {
  165. // Switches to dropbox mode for db.draw.io
  166. if (window.location.hostname == 'db.draw.io' && urlParams['mode'] == null)
  167. {
  168. urlParams['mode'] = 'dropbox';
  169. }
  170. App.mode = urlParams['mode'];
  171. if (App.mode == null)
  172. {
  173. // Stored mode overrides preferred mode
  174. App.mode = App.getStoredMode();
  175. }
  176. }
  177. if (window.mxscript != null)
  178. {
  179. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  180. if (typeof window.DriveClient === 'function')
  181. {
  182. if (urlParams['gapi'] != '0' && isSvgBrowser &&
  183. (document.documentMode == null || document.documentMode >= 10))
  184. {
  185. // Immediately loads client
  186. if (App.mode == App.MODE_GOOGLE || (urlParams['state'] != null &&
  187. window.location.hash == '') || (window.location.hash != null &&
  188. window.location.hash.substring(0, 2) == '#G'))
  189. {
  190. mxscript('https://apis.google.com/js/api.js');
  191. }
  192. else if (urlParams['chrome'] == '0')
  193. {
  194. // Disables loading of client
  195. window.DriveClient = null;
  196. }
  197. }
  198. else
  199. {
  200. // Disables loading of client
  201. window.DriveClient = null;
  202. }
  203. }
  204. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  205. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  206. if (typeof window.DropboxClient === 'function')
  207. {
  208. if (urlParams['db'] != '0' && isSvgBrowser &&
  209. (document.documentMode == null || document.documentMode > 9))
  210. {
  211. // Immediately loads client
  212. if (App.mode == App.MODE_DROPBOX || (window.location.hash != null &&
  213. window.location.hash.substring(0, 2) == '#D'))
  214. {
  215. mxscript('https://www.dropbox.com/static/api/1/dropins.js', null, 'dropboxjs', App.DROPBOX_APPKEY);
  216. }
  217. else if (urlParams['chrome'] == '0')
  218. {
  219. // Disables loading of client
  220. window.DropboxClient = null;
  221. }
  222. }
  223. else
  224. {
  225. // Disables loading of client
  226. window.DropboxClient = null;
  227. }
  228. }
  229. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  230. if (typeof window.OneDriveClient === 'function')
  231. {
  232. if (urlParams['od'] != '0' && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  233. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))
  234. {
  235. // Immediately loads client
  236. if (App.mode == App.MODE_ONEDRIVE || (window.location.hash != null &&
  237. window.location.hash.substring(0, 2) == '#W'))
  238. {
  239. mxscript('https://js.live.net/v5.0/wl.js');
  240. }
  241. else if (urlParams['chrome'] == '0')
  242. {
  243. // Disables loading of client
  244. window.OneDriveClient = null;
  245. }
  246. }
  247. else
  248. {
  249. // Disables loading of client
  250. window.OneDriveClient = null;
  251. }
  252. }
  253. // Loads JSON for older browsers
  254. if (typeof(JSON) == 'undefined')
  255. {
  256. mxscript('js/json/json2.min.js');
  257. }
  258. }
  259. if (urlParams['plugins'] != '0' && urlParams['offline'] != '1')
  260. {
  261. var plugins = mxSettings.getPlugins();
  262. var temp = urlParams['p'];
  263. if ((temp != null) || (plugins != null && plugins.length > 0))
  264. {
  265. // Workaround for need to load plugins now but wait for UI instance
  266. App.DrawPlugins = [];
  267. // Global entry point for plugins is Draw.loadPlugin. This is the only
  268. // long-term supported solution for access to the EditorUi instance.
  269. window.Draw = new Object();
  270. window.Draw.loadPlugin = function(callback)
  271. {
  272. App.DrawPlugins.push(callback);
  273. };
  274. }
  275. if (temp != null)
  276. {
  277. // Mapping from key to URL in App.plugins
  278. var t = temp.split(';');
  279. for (var i = 0; i < t.length; i++)
  280. {
  281. var url = App.pluginRegistry[t[i]];
  282. if (url != null)
  283. {
  284. mxscript(url);
  285. }
  286. else if (window.console != null)
  287. {
  288. console.log('Unknown plugin:', t[i]);
  289. }
  290. }
  291. }
  292. if (plugins != null && plugins.length > 0 && urlParams['plugins'] != '0')
  293. {
  294. // Loading plugins inside the asynchronous block below stops the page from loading so a
  295. // hardcoded message for the warning dialog is used since the resources are loadd below
  296. 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';
  297. if (plugins.length == 1 && (plugins[0].charAt(0) == '/' ||
  298. plugins[0].indexOf(window.location.protocol + '//' + window.location.host) == 0))
  299. {
  300. mxscript(plugins[0]);
  301. }
  302. // Loads plugins asynchronously
  303. else if (mxUtils.confirm(mxResources.replacePlaceholders(warning, [plugins.join('\n')]).replace(/\\n/g, '\n')))
  304. {
  305. for (var i = 0; i < plugins.length; i++)
  306. {
  307. try
  308. {
  309. mxscript(plugins[i]);
  310. }
  311. catch (e)
  312. {
  313. // ignore
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. })();
  321. /**
  322. * Program flow starts here.
  323. *
  324. * Optional callback is called with the app instance.
  325. */
  326. App.main = function(callback)
  327. {
  328. var lastErrorMessage = null;
  329. // Changes top level error handling
  330. window.onerror = function(message, url, linenumber, colno, err)
  331. {
  332. try
  333. {
  334. if (message == lastErrorMessage || (message != null && url != null &&
  335. ((message.indexOf('Script error') != -1) || (message.indexOf('extension') != -1))))
  336. {
  337. // TODO log external domain script failure "Script error." is
  338. // reported when the error occurs in a script that is hosted
  339. // on a domain other than the domain of the current page
  340. }
  341. // DocumentClosedError seems to be an FF bug an can be ignored for now
  342. else if (message != null && message.indexOf('DocumentClosedError') < 0)
  343. {
  344. lastErrorMessage = message;
  345. var img = new Image();
  346. var severity = (message.indexOf('NetworkError') >= 0 || message.indexOf('SecurityError') >= 0 ||
  347. message.indexOf('NS_ERROR_FAILURE') >= 0 || message.indexOf('out of memory') >= 0) ?
  348. 'CONFIG' : 'SEVERE';
  349. img.src = 'https://log.draw.io/log?severity=' + severity + '&v=' + encodeURIComponent(EditorUi.VERSION) +
  350. '&msg=clientError:' + encodeURIComponent(message) + ':url:' + encodeURIComponent(window.location.href) +
  351. ':lnum:' + encodeURIComponent(linenumber) +
  352. ((colno != null) ? ':colno:' + encodeURIComponent(colno) : '') +
  353. ((err != null && err.stack != null) ? '&stack=' + encodeURIComponent(err.stack) : '');
  354. }
  355. }
  356. catch (err)
  357. {
  358. // do nothing
  359. }
  360. };
  361. /**
  362. * Lazy loading of additional CSS for atlas theme.
  363. */
  364. if (uiTheme == 'atlas')
  365. {
  366. mxClient.link('stylesheet', 'styles/atlas.css');
  367. }
  368. if (window.mxscript != null)
  369. {
  370. /**
  371. * Color dialog - Do not add to app.min.js due to path issues!
  372. */
  373. if (urlParams['chrome'] != '0')
  374. {
  375. mxscript('js/jscolor/jscolor.js');
  376. }
  377. /**
  378. * Injects offline dependencies
  379. */
  380. if (urlParams['offline'] == '1')
  381. {
  382. mxscript('js/shapes.min.js');
  383. var frame = document.createElement('iframe');
  384. frame.setAttribute('width', '0');
  385. frame.setAttribute('height', '0');
  386. frame.setAttribute('src', 'offline.html');
  387. document.body.appendChild(frame);
  388. // Precaching for stencils. Alternatively we could generate
  389. // a cache manifest with all stencil and shape files but this
  390. // simplifies the cache file, streamlines the shape loading
  391. // to a single loading point (here) vs dynamic loading in the
  392. // online version. It does slow down the startup time though.
  393. mxStencilRegistry.stencilSet = {};
  394. // Overrides dynamic loading (everything loaded at startup)
  395. mxStencilRegistry.getStencil = function(name)
  396. {
  397. return mxStencilRegistry.stencils[name];
  398. };
  399. // Takes stencil data from cache for populating sidebar
  400. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force)
  401. {
  402. var name = stencilFile.substring(stencilFile.indexOf('/') + 1);
  403. name = 'mxgraph.' + name.substring(0, name.length - 4).replace(/\//g, '.');
  404. var node = mxStencilRegistry.stencilSet[name];
  405. if (node != null)
  406. {
  407. mxStencilRegistry.parseStencilSet(node, postStencilLoad, false);
  408. }
  409. };
  410. // Preload all stencils from merged XML file
  411. var req2 = mxUtils.load('stencils.xml');
  412. var root = req2.getXml().documentElement;
  413. var node = root.firstChild;
  414. while (node != null)
  415. {
  416. if (node.nodeName == 'shapes' && node.getAttribute('name') != null)
  417. {
  418. mxStencilRegistry.stencilSet[node.getAttribute('name').toLowerCase()] = node;
  419. mxStencilRegistry.parseStencilSet(node);
  420. }
  421. node = node.nextSibling;
  422. }
  423. }
  424. /**
  425. * Loads Google Image Picker API
  426. */
  427. if (urlParams['picker'] != '0' && !mxClient.IS_QUIRKS && document.documentMode != 8)
  428. {
  429. 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');
  430. }
  431. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  432. // Special case: Cannot load in asynchronous code below
  433. if (typeof window.DriveClient === 'function' &&
  434. (typeof gapi === 'undefined' && (((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  435. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && isSvgBrowser &&
  436. isLocalStorage && (document.documentMode == null || document.documentMode >= 10))))
  437. {
  438. mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback');
  439. }
  440. }
  441. /**
  442. * Asynchronous MathJax extension.
  443. */
  444. if (urlParams['math'] != '0')
  445. {
  446. Editor.initMath();
  447. }
  448. // Adds required resources (disables loading of fallback properties, this can only
  449. // be used if we know that all keys are defined in the language specific file)
  450. mxResources.loadDefaultBundle = false;
  451. var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
  452. mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);
  453. // Prefetches asynchronous requests so that below code runs synchronous
  454. // Loading the correct bundle (one file) via the fallback system in mxResources. The stylesheet
  455. // is compiled into JS in the build process and is only needed for local development.
  456. mxUtils.getAll((urlParams['dev'] != '1') ? [bundle] : [bundle, STYLE_PATH + '/default.xml'], function(xhr)
  457. {
  458. // Adds bundle text to resources
  459. mxResources.parse(xhr[0].getText());
  460. // Prepares themes with mapping from old default-style to old XML file
  461. if (xhr.length > 1)
  462. {
  463. Graph.prototype.defaultThemes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();
  464. }
  465. // Main
  466. var ui = new App(new Editor(urlParams['chrome'] == '0'));
  467. if (window.mxscript != null)
  468. {
  469. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  470. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  471. if (typeof window.DropboxClient === 'function' &&
  472. (window.Dropbox != null && typeof Dropbox.choose === 'undefined' &&
  473. window.DrawDropboxClientCallback != null &&
  474. (((urlParams['embed'] != '1' && urlParams['db'] != '0') ||
  475. (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  476. isSvgBrowser && (document.documentMode == null || document.documentMode > 9))))
  477. {
  478. mxscript('https://www.dropbox.com/static/api/1/dropins.js', window.DrawDropboxClientCallback, 'dropboxjs', App.DROPBOX_APPKEY);
  479. }
  480. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  481. if (typeof window.OneDriveClient === 'function' &&
  482. (typeof WL === 'undefined' && window.DrawOneDriveClientCallback != null &&
  483. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  484. urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  485. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  486. {
  487. mxscript('https://js.live.net/v5.0/wl.js', window.DrawOneDriveClientCallback);
  488. }
  489. }
  490. if (callback != null)
  491. {
  492. callback(ui);
  493. }
  494. /**
  495. * For developers only
  496. */
  497. if (urlParams['chrome'] != '0' && urlParams['test'] == '1')
  498. {
  499. mxLog.show();
  500. mxLog.debug('Started in ' + (new Date().getTime() - t0.getTime()) + 'ms');
  501. mxLog.debug('Export:', EXPORT_URL);
  502. mxLog.debug('Development mode:', (urlParams['dev'] == '1') ? 'active' : 'inactive');
  503. mxLog.debug('Test mode:', (urlParams['test'] == '1') ? 'active' : 'inactive');
  504. }
  505. }, function()
  506. {
  507. document.getElementById('geStatus').innerHTML = 'Error loading page. <a href="javascript:void(0);" onclick="location.reload();">Please try refreshing.</a>';
  508. });
  509. };
  510. //Extends EditorUi
  511. mxUtils.extend(App, EditorUi);
  512. /**
  513. * Executes the first step for connecting to Google Drive.
  514. */
  515. App.prototype.defaultUserPicture = 'https://lh3.googleusercontent.com/-HIzvXUy6QUY/AAAAAAAAAAI/AAAAAAAAAAA/giuR7PQyjEk/photo.jpg?sz=30';
  516. /**
  517. * Executes the first step for connecting to Google Drive.
  518. */
  519. App.prototype.micImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA5UlEQVR4Xr3SMYrCQBTGcSfIQiAgRIS9hOANBCurPUAuIAp7A7FVsFkIbLGYA9gKtoKNYG3jll5AFNKG518YMD6SISD4wY9J4MvkMYwRkZqOMSZkifGFe1b4pnvW3TqK8oMo14twxUgXPRSlDxU7TcUNPqATlG7wCi93cA2Iq2x7l7IJsgofB6UTiEjKklFqsabQSdFA5jqDAzrYQGeNNv5d9yDBEAME6NreFmP8Yuma4A8hFpiLSFNAYYYYn0jwCIUnxMcER4h1whS+7hseXKcu9ifGeQ+qeO8GjN7DPve+Q6+oewPhmE63Qfsb6AAAAABJRU5ErkJggg==';
  520. /**
  521. * Contains the default XML for an empty diagram.
  522. */
  523. App.prototype.emptyDiagramXml = '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>';
  524. /**
  525. *
  526. */
  527. 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==';
  528. /**
  529. *
  530. */
  531. App.prototype.chevronUpImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-up.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUY1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NjA1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1RDUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1RTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pg+qUokAAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAAL0lEQVR42mJgRgMMRAswMKAKMDDARBjg8lARBoR6KImkH0wTbygT6YaS4DmAAAMAYPkClOEDDD0AAAAASUVORK5CYII=';
  532. /**
  533. *
  534. */
  535. 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';
  536. /**
  537. *
  538. */
  539. App.prototype.formatShowImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-show.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REY1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5RTA1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlERDU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlERTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlnMQ/8AAAAJUExURQAAAP///3FxcTfTiAsAAAACdFJOU/8A5bcwSgAAACFJREFUeNpiYEQDDEQJMMABTAAixcQ00ALoDiPRcwABBgB6DADly9Yx8wAAAABJRU5ErkJggg==';
  540. /**
  541. *
  542. */
  543. App.prototype.formatHideImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-hide.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REI1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5REM1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlEOTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlEQTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqjT9SMAAAAGUExURQAAAP///6XZn90AAAACdFJOU/8A5bcwSgAAAB9JREFUeNpiYEQDDEQJMMABTAAmNdAC6A4j0XMAAQYAcbwA1Xvj1CgAAAAASUVORK5CYII=';
  544. /**
  545. *
  546. */
  547. App.prototype.fullscreenImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/fullscreen.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAAAAAClZ7nPAAAAAXRSTlMAQObYZgAAABpJREFUCNdjgAAbGxAy4AEh5gNwBBGByoIBAIueBd12TUjqAAAAAElFTkSuQmCC';
  548. /**
  549. *
  550. */
  551. App.prototype.plusImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/plus.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MDdCMTdENjVCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MDdCMTdENjZCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowN0IxN0Q2M0I4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowN0IxN0Q2NEI4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtjrjmgAAAAtSURBVHjaYvz//z8DMigvLwcLdHZ2MiKLMzEQCaivkLGsrOw/dU0cAr4GCDAARQsQbTFrv10AAAAASUVORK5CYII=';
  552. /**
  553. *
  554. */
  555. App.prototype.spinImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/spin.gif' : 'data:image/gif;base64,R0lGODlhDAAMAPUxAEVriVp7lmCAmmGBm2OCnGmHn3OPpneSqYKbr4OcsIScsI2kto6kt46lt5KnuZmtvpquvpuvv56ywaCzwqK1xKu7yay9yq+/zLHAzbfF0bjG0bzJ1LzK1MDN18jT28nT3M3X3tHa4dTc49Xd5Njf5dng5t3k6d/l6uDm6uru8e7x8/Dz9fT29/b4+Pj5+fj5+vr6+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkKADEAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAADAAMAAAGR8CYcEgsOgYAIax4CCQuQldrCBEsiK8VS2hoFGOrlJDA+cZQwkLnqyoJFZKviSS0ICrE0ec0jDAwIiUeGyBFGhMPFBkhZo1BACH5BAkKAC4ALAAAAAAMAAwAhVB0kFR3k1V4k2CAmmWEnW6Lo3KOpXeSqH2XrIOcsISdsImhtIqhtJCmuJGnuZuwv52wwJ+ywZ+ywqm6yLHBzbLCzrXEz7fF0LnH0rrI0r7L1b/M1sXR2cfT28rV3czW3s/Z4Nfe5Nvi6ODm6uLn6+Ln7OLo7OXq7efs7+zw8u/y9PDy9PX3+Pr7+////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZDQJdwSCxGDAIAoVFkFBwYSyIwGE4OkCJxIdG6WkJEx8sSKj7elfBB0a5SQg1EQ0SVVMPKhDM6iUIkRR4ZFxsgJl6JQQAh+QQJCgAxACwAAAAADAAMAIVGa4lcfZdjgpxkg51nhp5ui6N3kqh5lKqFnbGHn7KIoLOQp7iRp7mSqLmTqbqarr6br7+fssGitcOitcSuvsuuv8uwwMyzw861xNC5x9K6x9K/zNbDztjE0NnG0drJ1NzQ2eDS2+LT2+LV3ePZ4Oba4ebb4ufc4+jm6+7t8PLt8PPt8fPx8/Xx9PX09vf19/j3+Pn///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CYcEgsUhQFggFSjCQmnE1jcBhqGBXiIuAQSi7FGEIgfIzCFoCXFCZiPO0hKBMiwl7ET6eUYqlWLkUnISImKC1xbUEAIfkECQoAMgAsAAAAAAwADACFTnKPT3KPVHaTYoKcb4yjcY6leZSpf5mtgZuvh5+yiqG0i6K1jqW3kae5nrHBnrLBn7LCoLPCobTDqbrIqrvIs8LOtMPPtcPPtcTPuMbRucfSvcrUvsvVwMzWxdHaydTcytXdzNbezdff0drh2ODl2+Ln3eTp4Obq4ujs5Ont5uvu6O3w6u7w6u7x7/L09vj5+vr7+vv7////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkdAmXBILHIcicOCUqxELKKPxKAYgiYd4oMAEWo8RVmjIMScwhmBcJMKXwLCECmMGAhPI1QRwBiaSixCMDFhLSorLi8wYYxCQQAh+QQJCgAxACwAAAAADAAMAIVZepVggJphgZtnhp5vjKN2kah3kqmBmq+KobSLorWNpLaRp7mWq7ybr7+gs8KitcSktsWnuManucexwM2ywc63xtG6yNO9ytS+ytW/zNbDz9jH0tvL1d3N197S2+LU3OPU3ePV3eTX3+Xa4efb4ufd5Onl6u7r7vHs7/Lt8PLw8/Xy9Pby9fb09ff2+Pn3+Pn6+vr///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGSMCYcEgseiwSR+RS7GA4JFGF8RiWNiEiJTERgkjFGAQh/KTCGoJwpApnBkITKrwoCFWnFlEhaAxXLC9CBwAGRS4wQgELYY1CQQAh+QQJCgAzACwAAAAADAAMAIVMcI5SdZFhgZtti6JwjaR4k6mAma6Cm6+KobSLorWLo7WNo7aPpredsMCescGitMOitcSmuMaqu8ixwc2zws63xdC4xtG5x9K9ytXAzdfCztjF0NnF0drK1d3M1t7P2N/P2eDT2+LX3+Xe5Onh5+vi5+vj6Ozk6e3n7O/o7O/q7vHs7/Lt8PPu8fPx8/X3+Pn6+vv7+/v8/Pz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRcCZcEgsmkIbTOZTLIlGqZNnchm2SCgiJ6IRqljFmQUiXIVnoITQde4chC9Y+LEQxmTFRkFSNFAqDAMIRQoCAAEEDmeLQQAh+QQJCgAwACwAAAAADAAMAIVXeZRefplff5lhgZtph59yjqV2kaeAmq6FnbGFnrGLorWNpLaQp7mRqLmYrb2essGgs8Klt8apusitvcquv8u2xNC7yNO8ydS8ytTAzdfBzdfM1t7N197Q2eDU3OPX3+XZ4ObZ4ebc4+jf5erg5erg5uvp7fDu8fPv8vTz9fb09vf19/j3+Pn4+fn5+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  556. /**
  557. *
  558. */
  559. App.prototype.emptyLibraryXml = '<mxlibrary>[]</mxlibrary>';
  560. /**
  561. * Sets the delay for autosave in milliseconds. Default is 2000.
  562. */
  563. App.prototype.mode = null;
  564. /**
  565. * Executes the first step for connecting to Google Drive.
  566. */
  567. App.prototype.timeout = 25000;
  568. /**
  569. * Switch to disable logging for mode and search terms.
  570. */
  571. App.prototype.enableLogging = true;
  572. // Restores app defaults for UI
  573. App.prototype.formatEnabled = urlParams['format'] != '0';
  574. App.prototype.formatWidth = (screen.width < 600) ? 0 : mxSettings.getFormatWidth();
  575. /**
  576. * Overriden UI settings depending on mode.
  577. */
  578. if (urlParams['embed'] != '1')
  579. {
  580. App.prototype.menubarHeight = 60;
  581. }
  582. /**
  583. * Executes the first step for connecting to Google Drive.
  584. */
  585. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  586. /**
  587. * Translates this point by the given vector.
  588. *
  589. * @param {number} dx X-coordinate of the translation.
  590. * @param {number} dy Y-coordinate of the translation.
  591. */
  592. App.prototype.init = function()
  593. {
  594. EditorUi.prototype.init.apply(this, arguments);
  595. /**
  596. * Overrides export dialog for using cloud storage save.
  597. */
  598. if (this.isLocalFileSave())
  599. {
  600. var ui = this;
  601. ExportDialog.saveLocalFile = function(data, filename, format)
  602. {
  603. var mime = 'text/xml';
  604. if (format === 'svg')
  605. {
  606. mime = 'image/svg+xml';
  607. }
  608. ui.saveLocalFile(data, filename, mime);
  609. };
  610. ExportDialog.saveRequest = function(data, filename, format, fn)
  611. {
  612. ui.saveRequest(data, filename, format, fn);
  613. };
  614. }
  615. /**
  616. * Specifies the default filename.
  617. */
  618. this.defaultLibraryName = mxResources.get('untitledLibrary');
  619. /**
  620. * Holds the listener for description changes.
  621. */
  622. this.descriptorChangedListener = mxUtils.bind(this, this.descriptorChanged);
  623. if (urlParams['embed'] != '1')
  624. {
  625. /**
  626. * Holds the background element.
  627. */
  628. this.bg = this.createBackground();
  629. document.body.appendChild(this.bg);
  630. this.diagramContainer.style.visibility = 'hidden';
  631. this.formatContainer.style.visibility = 'hidden';
  632. this.hsplit.style.display = 'none';
  633. this.sidebarContainer.style.display = 'none';
  634. this.sidebarFooterContainer.style.display = 'none';
  635. /**
  636. * Creates onedrive client if all required libraries are available.
  637. */
  638. var initOneDriveClient = mxUtils.bind(this, function()
  639. {
  640. if (typeof WL !== 'undefined')
  641. {
  642. /**
  643. * Holds the x-coordinate of the point.
  644. */
  645. this.oneDrive = new OneDriveClient(this);
  646. this.oneDrive.addListener('userChanged', mxUtils.bind(this, function()
  647. {
  648. this.updateUserElement();
  649. this.restoreLibraries();
  650. }))
  651. // Notifies listeners of new client
  652. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.oneDrive));
  653. }
  654. else if (window.DrawOneDriveClientCallback == null)
  655. {
  656. window.DrawOneDriveClientCallback = initOneDriveClient;
  657. }
  658. });
  659. initOneDriveClient();
  660. /**
  661. * Creates drive client with all required libraries are available.
  662. */
  663. var initDriveClient = mxUtils.bind(this, function()
  664. {
  665. /**
  666. * Creates google drive client if all required libraries are available.
  667. */
  668. if (typeof gapi !== 'undefined')
  669. {
  670. var doInit = mxUtils.bind(this, function()
  671. {
  672. /**
  673. * Holds the x-coordinate of the point.
  674. */
  675. this.drive = new DriveClient(this);
  676. /**
  677. * Adds important notice for new app if drive file is loaded in old app.
  678. */
  679. if (this.drive.appId == '420247213240')
  680. {
  681. this.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  682. {
  683. var file = this.getCurrentFile();
  684. if (file != null && file.constructor == DriveFile)
  685. {
  686. var td = document.getElementById('geFooterItem2');
  687. if (td != null)
  688. {
  689. td.innerHTML = '<a href="https://support.draw.io/display/DO/2014/11/27/Switching+application+in+Google+Drive" ' +
  690. 'target="_blank" title="IMPORTANT NOTICE" >IMPORTANT NOTICE</a>';
  691. }
  692. }
  693. }));
  694. }
  695. this.drive.addListener('userChanged', mxUtils.bind(this, function()
  696. {
  697. // Changes the footer ads for Google Accounts
  698. if (this.updateAd != null)
  699. {
  700. this.adsHtml = ['<a title="Quick start video" href="https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1" target="_blank">' +
  701. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Quick start video</a>',
  702. '<a title="Google Docs Add-on" href="https://chrome.google.com/webstore/detail/drawio-diagrams/clpbjldiohnnmfmkngmaohehlnfkmoea" target="_blank">' +
  703. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Google Docs Add-on</a>',
  704. '<a title="Google Chrome App" href="https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla" target="_blank">' +
  705. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Google Chrome App</a>',
  706. '<a title="Please help us to 5 stars" href="https://chrome.google.com/webstore/detail/drawio-pro/onlkggianjhjenigcpigpjehhpplldkc/reviews" target="_blank">' +
  707. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Please help us to 5 stars</a>'];
  708. this.updateAd(this.adsHtml.length - 1);
  709. }
  710. this.updateUserElement();
  711. this.restoreLibraries();
  712. this.checkLicense();
  713. }))
  714. // Notifies listeners of new client
  715. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.drive));
  716. });
  717. if (window.DrawGapiClientCallback != null)
  718. {
  719. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  720. {
  721. // Starts the app without the Google Option if the API fails to load
  722. if (gapi.drive != null && gapi.drive.realtime != null)
  723. {
  724. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  725. {
  726. this.defineCustomObjects();
  727. // Needed to avoid popup blocking for non-immediate authentication
  728. gapi.auth.init(mxUtils.bind(this, function()
  729. {
  730. if (gapi.client.drive != null)
  731. {
  732. doInit();
  733. }
  734. }));
  735. }));
  736. }
  737. }));
  738. /**
  739. * Clears any callbacks.
  740. */
  741. window.DrawGapiClientCallback = null;
  742. }
  743. else
  744. {
  745. doInit();
  746. }
  747. }
  748. else if (window.DrawGapiClientCallback == null)
  749. {
  750. window.DrawGapiClientCallback = initDriveClient;
  751. }
  752. });
  753. initDriveClient();
  754. /**
  755. * Creates dropbox client if all required libraries are available.
  756. */
  757. var initDropboxClient = mxUtils.bind(this, function()
  758. {
  759. if (window.Dropbox != null && typeof Dropbox.choose !== 'undefined')
  760. {
  761. /**
  762. * Clears dropbox client callback.
  763. */
  764. window.DrawDropboxClientCallback = null;
  765. /**
  766. * Holds the x-coordinate of the point.
  767. */
  768. this.dropbox = new DropboxClient(this);
  769. this.dropbox.addListener('userChanged', mxUtils.bind(this, function()
  770. {
  771. this.updateUserElement();
  772. this.restoreLibraries();
  773. }));
  774. // Notifies listeners of new client
  775. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.dropbox));
  776. }
  777. else if (window.DrawDropboxClientCallback == null)
  778. {
  779. window.DrawDropboxClientCallback = initDropboxClient;
  780. }
  781. });
  782. initDropboxClient();
  783. // Sets the initial mode
  784. if (urlParams['local'] == '1')
  785. {
  786. this.setMode(App.MODE_DEVICE);
  787. }
  788. else
  789. {
  790. this.mode = App.mode;
  791. }
  792. }
  793. else if (this.menubar != null)
  794. {
  795. this.menubar.container.style.paddingTop = '0px';
  796. }
  797. this.updateHeader();
  798. // Changes footer from time to time
  799. var td = document.getElementById('geFooterItem2');
  800. if (td != null)
  801. {
  802. this.adsHtml = ['<a title="Quick start video" href="https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1" target="_blank">' +
  803. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Quick start video</a>'];
  804. this.adsHtml.push(td.innerHTML);
  805. mxUtils.setPrefixedStyle(td.style, 'transition', 'all 1s ease');
  806. var lastAd = this.adsHtml.length - 1;
  807. this.updateAd = function(index)
  808. {
  809. if (index == lastAd)
  810. {
  811. index = this.adsHtml.length - 1;
  812. }
  813. if (index != lastAd)
  814. {
  815. mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(0)');
  816. td.style.opacity = '0';
  817. lastAd = index;
  818. window.setTimeout(mxUtils.bind(this, function()
  819. {
  820. td.innerHTML = this.adsHtml[index];
  821. mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(1)');
  822. td.style.opacity = '1';
  823. }), 1000);
  824. }
  825. };
  826. window.setInterval(mxUtils.bind(this, function()
  827. {
  828. if (this.adsHtml.length == 3)
  829. {
  830. this.updateAd(mxUtils.mod(lastAd + 1, 3));
  831. }
  832. else
  833. {
  834. var rnd = Math.random();
  835. this.updateAd(Math.round(rnd * (this.adsHtml.length - 1)));
  836. }
  837. }), 300000);
  838. }
  839. if (this.menubar != null)
  840. {
  841. this.buttonContainer = document.createElement('div');
  842. this.buttonContainer.style.display = 'inline-block';
  843. this.buttonContainer.style.paddingRight = '48px';
  844. this.buttonContainer.style.position = 'absolute';
  845. this.buttonContainer.style.right = '0px';
  846. this.menubar.container.appendChild(this.buttonContainer);
  847. }
  848. if (uiTheme == 'atlas' && this.menubar != null)
  849. {
  850. if (this.toggleElement != null)
  851. {
  852. this.toggleElement.click();
  853. this.toggleElement.style.display = 'none';
  854. }
  855. this.icon = document.createElement('img');
  856. this.icon.setAttribute('src', IMAGE_PATH + '/logo-flat-small.png');
  857. this.icon.setAttribute('title', mxResources.get('draw.io'));
  858. this.icon.style.paddingTop = '11px';
  859. this.icon.style.marginLeft = '4px';
  860. this.icon.style.marginRight = '6px';
  861. if (mxClient.IS_QUIRKS)
  862. {
  863. this.icon.style.marginTop = '12px';
  864. }
  865. this.menubar.container.insertBefore(this.icon, this.menubar.container.firstChild);
  866. }
  867. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  868. {
  869. /**
  870. * Persists current edge style.
  871. */
  872. this.editor.graph.currentEdgeStyle = mxSettings.getCurrentEdgeStyle();
  873. this.editor.graph.currentVertexStyle = mxSettings.getCurrentVertexStyle();
  874. // Updates UI to reflect current edge style
  875. this.fireEvent(new mxEventObject('styleChanged', 'keys', [], 'values', [], 'cells', []));
  876. this.addListener('styleChanged', mxUtils.bind(this, function(sender, evt)
  877. {
  878. mxSettings.setCurrentEdgeStyle(this.editor.graph.currentEdgeStyle);
  879. mxSettings.setCurrentVertexStyle(this.editor.graph.currentVertexStyle);
  880. mxSettings.save();
  881. }));
  882. /**
  883. * Persists copy on connect switch.
  884. */
  885. this.editor.graph.connectionHandler.setCreateTarget(mxSettings.isCreateTarget());
  886. this.fireEvent(new mxEventObject('copyConnectChanged'));
  887. this.addListener('copyConnectChanged', mxUtils.bind(this, function(sender, evt)
  888. {
  889. mxSettings.setCreateTarget(this.editor.graph.connectionHandler.isCreateTarget());
  890. mxSettings.save();
  891. }));
  892. /**
  893. * Persists default page format.
  894. */
  895. this.editor.graph.pageFormat = mxSettings.getPageFormat();
  896. this.addListener('pageFormatChanged', mxUtils.bind(this, function(sender, evt)
  897. {
  898. mxSettings.setPageFormat(this.editor.graph.pageFormat);
  899. mxSettings.save();
  900. }));
  901. /**
  902. * Persists default grid color.
  903. */
  904. this.editor.graph.view.gridColor = mxSettings.getGridColor();
  905. this.addListener('gridColorChanged', mxUtils.bind(this, function(sender, evt)
  906. {
  907. mxSettings.setGridColor(this.editor.graph.view.gridColor);
  908. mxSettings.save();
  909. }));
  910. /**
  911. * Persists autosave switch in Chrome app.
  912. */
  913. if (mxClient.IS_CHROMEAPP)
  914. {
  915. this.editor.addListener('autosaveChanged', mxUtils.bind(this, function(sender, evt)
  916. {
  917. mxSettings.setAutosave(this.editor.autosave);
  918. mxSettings.save();
  919. }));
  920. this.editor.autosave = mxSettings.getAutosave();
  921. }
  922. /**
  923. *
  924. */
  925. if (this.sidebar != null)
  926. {
  927. this.sidebar.showPalette('search', mxSettings.settings.search);
  928. }
  929. /**
  930. * Shows scratchpad if never shown.
  931. */
  932. if (!this.editor.chromeless && this.sidebar != null && (mxSettings.settings.isNew ||
  933. parseInt(mxSettings.settings.version || 0) <= 8))
  934. {
  935. this.toggleScratchpad();
  936. mxSettings.save();
  937. }
  938. // Saves app defaults for UI
  939. this.addListener('formatWidthChanged', function()
  940. {
  941. mxSettings.setFormatWidth(this.formatWidth);
  942. mxSettings.save();
  943. });
  944. }
  945. };
  946. /**
  947. * Returns true if the current domain is for the new drive app.
  948. */
  949. App.prototype.isDriveDomain = function()
  950. {
  951. return urlParams['drive'] != '0' &&
  952. (window.location.hostname == 'test.draw.io' ||
  953. window.location.hostname == 'cdn.draw.io' ||
  954. window.location.hostname == 'www.draw.io' ||
  955. window.location.hostname == 'drive.draw.io' ||
  956. window.location.hostname == 'jgraph.github.io');
  957. };
  958. /**
  959. * Returns true if the current domain is for the old drive app.
  960. */
  961. App.prototype.isLegacyDriveDomain = function()
  962. {
  963. return urlParams['drive'] == 0 || window.location.hostname == 'legacy.draw.io';
  964. };
  965. /**
  966. *
  967. */
  968. App.prototype.checkLicense = function()
  969. {
  970. var driveUser = this.drive.getUser();
  971. var email = ((urlParams['dev'] == '1') ? urlParams['lic'] : null) ||
  972. ((driveUser != null) ? driveUser.email : null);
  973. if (!this.isOffline() && !this.editor.chromeless && email != null)
  974. {
  975. // Anonymises the local part of the email address
  976. var at = email.lastIndexOf('@');
  977. var domain = email;
  978. if (at >= 0)
  979. {
  980. domain = email.substring(at + 1);
  981. email = this.crc32(email.substring(0, at)) + '@' + domain;
  982. }
  983. // Timestamp is workaround for cached response in certain environments
  984. mxUtils.post('/license', 'domain=' + encodeURIComponent(domain) + '&email=' +
  985. encodeURIComponent(email) + '&ts=' + new Date().getTime(),
  986. mxUtils.bind(this, function(req)
  987. {
  988. var registered = false;
  989. var exp = null;
  990. try
  991. {
  992. if (req.getStatus() == 200)
  993. {
  994. var value = req.getText();
  995. registered = true;
  996. if (value.length > 0)
  997. {
  998. var lic = JSON.parse(value);
  999. if (lic != null)
  1000. {
  1001. exp = this.handleLicense(lic, domain);
  1002. }
  1003. }
  1004. }
  1005. }
  1006. catch (e)
  1007. {
  1008. // ignore
  1009. }
  1010. }));
  1011. }
  1012. };
  1013. /**
  1014. * Returns true if the current domain is for the new drive app.
  1015. */
  1016. App.prototype.handleLicense = function(lic, domain)
  1017. {
  1018. var footer = document.getElementById('geFooter');
  1019. var expiry = null;
  1020. if (footer != null && lic != null)
  1021. {
  1022. expiry = lic.expiry;
  1023. if (lic.footer != null)
  1024. {
  1025. footer.innerHTML = decodeURIComponent(lic.footer);
  1026. }
  1027. else
  1028. {
  1029. this.hideFooter();
  1030. if (expiry != null && expiry != 'never')
  1031. {
  1032. var exp = new Date(Date.parse(expiry));
  1033. var diff = Math.round((exp - Date.now()) / (1000 * 60 * 60 * 24));
  1034. if (diff < 90)
  1035. {
  1036. var link = 'https://support.draw.io/display/DKB/draw.io+footer+state+that+license+is+expiring+on+Google+For+Work+account?domain=' + encodeURIComponent(domain);
  1037. footer.style.height = '100%';
  1038. footer.style.margin = '0px';
  1039. footer.style.display = '';
  1040. if (diff < 0)
  1041. {
  1042. this.footerHeight = 80;
  1043. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert geBlink">' +
  1044. '<a href="' + link + '" style="padding-top:16px;" target="_blank">' +
  1045. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1046. mxResources.get('licenseHasExpired', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1047. }
  1048. else
  1049. {
  1050. this.footerHeight = 46;
  1051. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert">' +
  1052. '<a href="' + link + '" target="_blank">' +
  1053. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1054. mxResources.get('licenseWillExpire', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1055. }
  1056. this.refresh();
  1057. }
  1058. }
  1059. }
  1060. }
  1061. return expiry;
  1062. };
  1063. /**
  1064. *
  1065. */
  1066. App.prototype.getEditBlankXml = function()
  1067. {
  1068. var file = this.getCurrentFile();
  1069. if (file != null && this.editor.chromeless && this.editor.graph.lightbox && file.realtime == null)
  1070. {
  1071. return file.getData();
  1072. }
  1073. else
  1074. {
  1075. return this.getFileData(true);
  1076. }
  1077. };
  1078. /**
  1079. * Updates action states depending on the selection.
  1080. */
  1081. App.prototype.updateActionStates = function()
  1082. {
  1083. EditorUi.prototype.updateActionStates.apply(this, arguments);
  1084. var file = this.getCurrentFile();
  1085. this.actions.get('revisionHistory').setEnabled(file != null && ((file.constructor == DriveFile &&
  1086. file.isEditable()) || file.constructor == DropboxFile));
  1087. };
  1088. /**
  1089. * Sets the onbeforeunload for the application
  1090. */
  1091. App.prototype.updateDraft = function()
  1092. {
  1093. if (isLocalStorage && localStorage != null)
  1094. {
  1095. localStorage.setItem('.draft', JSON.stringify({modified: new Date().getTime(), data: this.getFileData()}));
  1096. }
  1097. };
  1098. /**
  1099. * Sets the onbeforeunload for the application
  1100. */
  1101. App.prototype.getDraft = function()
  1102. {
  1103. // FIXME: Handle multiple tabs
  1104. // if (isLocalStorage && localStorage != null)
  1105. // {
  1106. // try
  1107. // {
  1108. // var draft = localStorage.getItem('.draft');
  1109. //
  1110. // if (draft != null)
  1111. // {
  1112. // return JSON.parse(draft);
  1113. // }
  1114. // }
  1115. // catch (e)
  1116. // {
  1117. // // ignore quota etc
  1118. // }
  1119. // }
  1120. return null;
  1121. };
  1122. /**
  1123. * Sets the onbeforeunload for the application
  1124. */
  1125. App.prototype.addRecent = function(entry)
  1126. {
  1127. if (isLocalStorage && localStorage != null)
  1128. {
  1129. var recent = this.getRecent();
  1130. if (recent == null)
  1131. {
  1132. recent = [];
  1133. }
  1134. else
  1135. {
  1136. for (var i = 0; i < recent.length; i++)
  1137. {
  1138. if (recent[i].id == entry.id)
  1139. {
  1140. recent.splice(i, 1);
  1141. }
  1142. }
  1143. }
  1144. if (recent != null)
  1145. {
  1146. recent.unshift(entry);
  1147. recent = recent.slice(0, 5);
  1148. localStorage.setItem('.recent', JSON.stringify(recent));
  1149. }
  1150. }
  1151. };
  1152. /**
  1153. * Sets the onbeforeunload for the application
  1154. */
  1155. App.prototype.getRecent = function()
  1156. {
  1157. if (isLocalStorage && localStorage != null)
  1158. {
  1159. try
  1160. {
  1161. var recent = localStorage.getItem('.recent');
  1162. if (recent != null)
  1163. {
  1164. return JSON.parse(recent);
  1165. }
  1166. }
  1167. catch (e)
  1168. {
  1169. // ignore
  1170. }
  1171. return null;
  1172. }
  1173. };
  1174. /**
  1175. * Sets the onbeforeunload for the application
  1176. */
  1177. App.prototype.resetRecent = function(entry)
  1178. {
  1179. if (isLocalStorage && localStorage != null)
  1180. {
  1181. try
  1182. {
  1183. localStorage.removeItem('.recent');
  1184. }
  1185. catch (e)
  1186. {
  1187. // ignore
  1188. }
  1189. }
  1190. };
  1191. /**
  1192. * Sets the onbeforeunload for the application
  1193. */
  1194. App.prototype.removeDraft = function()
  1195. {
  1196. if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
  1197. {
  1198. try
  1199. {
  1200. localStorage.removeItem('.draft');
  1201. }
  1202. catch (e)
  1203. {
  1204. // ignore quota etc
  1205. }
  1206. }
  1207. };
  1208. /**
  1209. * Sets the onbeforeunload for the application
  1210. */
  1211. App.prototype.onBeforeUnload = function()
  1212. {
  1213. var file = this.getCurrentFile();
  1214. if (file != null)
  1215. {
  1216. if (file.constructor == LocalFile && !file.isModified() && urlParams['nowarn'] != '1' &&
  1217. !this.isDiagramEmpty() && urlParams['url'] == null && !this.editor.chromeless)
  1218. {
  1219. return mxResources.get('ensureDataSaved');
  1220. }
  1221. else if (file.constructor != DriveFile && file.isModified())
  1222. {
  1223. return mxResources.get('allChangesLost');
  1224. }
  1225. else
  1226. {
  1227. file.close(true);
  1228. }
  1229. }
  1230. };
  1231. /**
  1232. * Translates this point by the given vector.
  1233. *
  1234. * @param {number} dx X-coordinate of the translation.
  1235. * @param {number} dy Y-coordinate of the translation.
  1236. */
  1237. App.prototype.updateDocumentTitle = function()
  1238. {
  1239. if (!this.editor.graph.lightbox)
  1240. {
  1241. var title = this.editor.appName;
  1242. var file = this.getCurrentFile();
  1243. if (file != null)
  1244. {
  1245. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1246. title = filename + ' - ' + title;
  1247. }
  1248. if (this.isOfflineApp())
  1249. {
  1250. title += ' [' + mxResources.get('offline') + ']';
  1251. }
  1252. document.title = title;
  1253. }
  1254. };
  1255. /**
  1256. * Authorizes the client, gets the userId and calls <open>.
  1257. */
  1258. App.prototype.createCrcTable = function()
  1259. {
  1260. var crcTable = [];
  1261. var c;
  1262. for (var n = 0; n < 256; n++)
  1263. {
  1264. c = n;
  1265. for (var k = 0; k < 8; k++)
  1266. {
  1267. c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  1268. }
  1269. crcTable[n] = c;
  1270. }
  1271. return crcTable;
  1272. };
  1273. /**
  1274. * Authorizes the client, gets the userId and calls <open>.
  1275. */
  1276. App.prototype.crc32 = function(str)
  1277. {
  1278. this.crcTable = this.crcTable || this.createCrcTable();
  1279. var crc = 0 ^ (-1);
  1280. for (var i = 0; i < str.length; i++ )
  1281. {
  1282. crc = (crc >>> 8) ^ this.crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
  1283. }
  1284. return (crc ^ (-1)) >>> 0;
  1285. };
  1286. /**
  1287. * Returns a thumbnail of the current file.
  1288. */
  1289. App.prototype.getThumbnail = function(width, success)
  1290. {
  1291. var result = false;
  1292. try
  1293. {
  1294. if (this.thumbImageCache == null)
  1295. {
  1296. this.thumbImageCache = new Object();
  1297. }
  1298. // Uses new client-side canvas export for Chrome, Firefox and Opera
  1299. if (this.isExportToCanvas())
  1300. {
  1301. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1302. {
  1303. success(canvas);
  1304. }), width, this.thumbImageCache, '#ffffff', function()
  1305. {
  1306. // Continues with null in error case
  1307. success();
  1308. });
  1309. result = true;
  1310. }
  1311. else if (this.canvasSupported && this.getCurrentFile() != null)
  1312. {
  1313. var graph = this.editor.graph;
  1314. var canvas = document.createElement('canvas');
  1315. var bounds = graph.getGraphBounds();
  1316. var scale = width / bounds.width;
  1317. // Limits scale to 1 or 2 * width / height
  1318. scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
  1319. var x0 = Math.floor(bounds.x);
  1320. var y0 = Math.floor(bounds.y);
  1321. canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
  1322. canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
  1323. var ctx = canvas.getContext('2d');
  1324. // Configures the canvas
  1325. ctx.scale(scale, scale);
  1326. ctx.translate(-x0, -y0);
  1327. // Paint white background instead of transparent
  1328. var bg = graph.background;
  1329. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1330. {
  1331. bg = '#ffffff';
  1332. }
  1333. // Paints background
  1334. ctx.save();
  1335. ctx.fillStyle = bg;
  1336. ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
  1337. ctx.restore();
  1338. var htmlCanvas = new mxJsCanvas(canvas);
  1339. // NOTE: htmlCanvas passed into async canvas is only used for image
  1340. // and canvas caching (canvas caching not used in this case as we do
  1341. // not render text). To reuse that cache via the thumbImageCache we
  1342. // pass that into the async canvas and override the image cache in
  1343. // the newly created html canvas with that of the thumbImageCache.
  1344. // LATER: Is clear thumbImageCache needed if file changes?
  1345. var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
  1346. htmlCanvas.images = this.thumbImageCache.images;
  1347. // Render graph
  1348. var imgExport = new mxImageExport();
  1349. imgExport.drawShape = function(state, canvas)
  1350. {
  1351. if (state.shape instanceof mxShape && state.shape.checkBounds())
  1352. {
  1353. canvas.save();
  1354. canvas.translate(0.5, 0.5);
  1355. state.shape.paint(canvas);
  1356. canvas.translate(-0.5, -0.5);
  1357. canvas.restore();
  1358. }
  1359. };
  1360. imgExport.drawText = function(state, canvas)
  1361. {
  1362. // No text output for thumbnails
  1363. };
  1364. imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
  1365. asynCanvas.finish(function()
  1366. {
  1367. imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
  1368. success(canvas);
  1369. });
  1370. result = true;
  1371. }
  1372. }
  1373. catch (e)
  1374. {
  1375. // ignore and use placeholder
  1376. }
  1377. return result;
  1378. };
  1379. /**
  1380. * Tries to find a public URL for the given file.
  1381. */
  1382. App.prototype.getPublicUrl = function(file, fn)
  1383. {
  1384. fn(null);
  1385. };
  1386. /**
  1387. * Translates this point by the given vector.
  1388. *
  1389. * @param {number} dx X-coordinate of the translation.
  1390. * @param {number} dy Y-coordinate of the translation.
  1391. */
  1392. App.prototype.createFileData = function(node, graph, file, url, forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection)
  1393. {
  1394. graph = (graph != null) ? graph : this.editor.graph;
  1395. forceXml = (forceXml != null) ? forceXml : false;
  1396. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1397. var editLink = null;
  1398. var redirect = null;
  1399. if (file == null || file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER)
  1400. {
  1401. editLink = '_blank';
  1402. }
  1403. else
  1404. {
  1405. editLink = url;
  1406. redirect = editLink;
  1407. }
  1408. if (node == null)
  1409. {
  1410. return '';
  1411. }
  1412. else
  1413. {
  1414. var fileNode = node;
  1415. // Ignores case for possible HTML or XML nodes
  1416. if (fileNode.nodeName.toLowerCase() != 'mxfile')
  1417. {
  1418. // Removes control chars in input for correct roundtrip check
  1419. var text = graph.zapGremlins(mxUtils.getXml(node));
  1420. var data = graph.compress(text);
  1421. // Fallback to plain XML for invalid compression
  1422. // TODO: Remove this fallback with active pages
  1423. if (graph.decompress(data) != text)
  1424. {
  1425. return text;
  1426. }
  1427. else
  1428. {
  1429. var diagramNode = node.ownerDocument.createElement('diagram');
  1430. mxUtils.setTextContent(diagramNode, data);
  1431. fileNode = node.ownerDocument.createElement('mxfile');
  1432. fileNode.appendChild(diagramNode);
  1433. }
  1434. }
  1435. fileNode.setAttribute('userAgent', navigator.userAgent);
  1436. fileNode.setAttribute('version', EditorUi.VERSION);
  1437. fileNode.setAttribute('editor', 'www.draw.io');
  1438. var md = (file != null) ? file.getMode() : this.mode;
  1439. if (md != null)
  1440. {
  1441. fileNode.setAttribute('type', md);
  1442. }
  1443. var xml = mxUtils.getXml(fileNode);
  1444. // Writes the file as an embedded HTML file
  1445. if (!forceSvg && !forceXml && (forceHtml || (file != null && /(\.html)$/i.test(file.getTitle()))))
  1446. {
  1447. xml = this.getHtml2(fileNode, graph, (file != null) ? file.getTitle() : null, editLink, redirect, ignoreSelection);
  1448. }
  1449. // Maps the XML data to the content attribute in the SVG node
  1450. else if (forceSvg || (!forceXml && file != null && /(\.svg)$/i.test(file.getTitle())))
  1451. {
  1452. if (file != null && (file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER))
  1453. {
  1454. url = null;
  1455. }
  1456. xml = this.getEmbeddedSvg(xml, graph, url, null, embeddedCallback, ignoreSelection, redirect);
  1457. }
  1458. return xml;
  1459. }
  1460. };
  1461. /**
  1462. * Translates this point by the given vector.
  1463. *
  1464. * @param {number} dx X-coordinate of the translation.
  1465. * @param {number} dy Y-coordinate of the translation.
  1466. */
  1467. App.prototype.getFileData = function(forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection, currentPage)
  1468. {
  1469. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1470. currentPage = (currentPage != null) ? currentPage : false;
  1471. var node = this.editor.getGraphXml(ignoreSelection);
  1472. if (ignoreSelection && this.fileNode != null && this.currentPage != null)
  1473. {
  1474. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(node)));
  1475. mxUtils.setTextContent(this.currentPage.node, data);
  1476. node = this.fileNode.cloneNode(false);
  1477. if (currentPage)
  1478. {
  1479. node.appendChild(this.currentPage.node);
  1480. }
  1481. else
  1482. {
  1483. // Restores order of pages
  1484. for (var i = 0; i < this.pages.length; i++)
  1485. {
  1486. var mapping = this.pages[i].mapping;
  1487. // Updates XML of all pages for realtime
  1488. if (this.currentPage != this.pages[i] && mapping != null && mapping.needsUpdate)
  1489. {
  1490. var enc = new mxCodec(mxUtils.createXmlDocument());
  1491. var temp = enc.encode(mapping.graphModel);
  1492. // Uses the graph state from the realtime model
  1493. mapping.writeRealtimeToNode(temp);
  1494. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(temp)));
  1495. mxUtils.setTextContent(this.pages[i].node, data);
  1496. // Marks the page as up-to-date
  1497. mapping.needsUpdate = false;
  1498. }
  1499. node.appendChild(this.pages[i].node);
  1500. }
  1501. }
  1502. }
  1503. var graph = this.editor.graph;
  1504. var file = this.getCurrentFile();
  1505. // Exports SVG for first page while other page is visible by creating a graph
  1506. // LATER: Add caching for the graph or SVG while not on first page
  1507. if (this.pages != null && this.currentPage != this.pages[0] && (forceSvg ||
  1508. (!forceXml && file != null && /(\.svg)$/i.test(file.getTitle()))))
  1509. {
  1510. graph = this.createTemporaryGraph(graph.getStylesheet());
  1511. var graphGetGlobalVariable = graph.getGlobalVariable;
  1512. var page = this.pages[0];
  1513. graph.getGlobalVariable = function(name)
  1514. {
  1515. if (name == 'page')
  1516. {
  1517. return page.getName();
  1518. }
  1519. else if (name == 'pagenumber')
  1520. {
  1521. return 1;
  1522. }
  1523. return graphGetGlobalVariable.apply(this, arguments);
  1524. };
  1525. document.body.appendChild(graph.container);
  1526. graph.model.setRoot(page.root);
  1527. }
  1528. var result = this.createFileData(node, graph, file, window.location.href,
  1529. forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection);
  1530. // Removes temporary graph from DOM
  1531. if (graph != this.editor.graph)
  1532. {
  1533. graph.container.parentNode.removeChild(graph.container);
  1534. }
  1535. return result;
  1536. };
  1537. /**
  1538. * Translates this point by the given vector.
  1539. *
  1540. * @param {number} dx X-coordinate of the translation.
  1541. * @param {number} dy Y-coordinate of the translation.
  1542. */
  1543. App.prototype.createBackground = function()
  1544. {
  1545. var bg = this.createDiv('background');
  1546. bg.style.position = 'absolute';
  1547. bg.style.background = 'white';
  1548. bg.style.left = '0px';
  1549. bg.style.top = '0px';
  1550. bg.style.bottom = '0px';
  1551. bg.style.right = '0px';
  1552. mxUtils.setOpacity(bg, 100);
  1553. if (mxClient.IS_QUIRKS)
  1554. {
  1555. new mxDivResizer(bg);
  1556. }
  1557. return bg;
  1558. };
  1559. /**
  1560. * Translates this point by the given vector.
  1561. *
  1562. * @param {number} dx X-coordinate of the translation.
  1563. * @param {number} dy Y-coordinate of the translation.
  1564. */
  1565. App.prototype.setMode = function(mode, remember)
  1566. {
  1567. this.mode = mode;
  1568. // Note: UseLocalStorage affects the file dialogs
  1569. // and should not be modified if mode is undefined
  1570. if (this.mode != null)
  1571. {
  1572. Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
  1573. }
  1574. if (typeof(Storage) != 'undefined' && remember)
  1575. {
  1576. var expiry = new Date();
  1577. expiry.setYear(expiry.getFullYear() + 1);
  1578. document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
  1579. }
  1580. if (this.appIcon != null)
  1581. {
  1582. var file = this.getCurrentFile();
  1583. var mode = (file != null) ? file.getMode() : null;
  1584. if (mode == App.MODE_GOOGLE)
  1585. {
  1586. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
  1587. this.appIcon.style.cursor = 'pointer';
  1588. }
  1589. else if (mode == App.MODE_DROPBOX)
  1590. {
  1591. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
  1592. this.appIcon.style.cursor = 'pointer';
  1593. }
  1594. else if (mode == App.MODE_ONEDRIVE)
  1595. {
  1596. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
  1597. this.appIcon.style.cursor = 'pointer';
  1598. }
  1599. else
  1600. {
  1601. this.appIcon.removeAttribute('title');
  1602. this.appIcon.style.cursor = 'default';
  1603. }
  1604. }
  1605. };
  1606. /**
  1607. * Function: authorize
  1608. *
  1609. * Authorizes the client, gets the userId and calls <open>.
  1610. */
  1611. App.prototype.appIconClicked = function(evt)
  1612. {
  1613. if (mxEvent.isAltDown(evt))
  1614. {
  1615. this.showSplash(true);
  1616. }
  1617. else
  1618. {
  1619. var file = this.getCurrentFile();
  1620. var mode = (file != null) ? file.getMode() : null;
  1621. if (mode == App.MODE_GOOGLE)
  1622. {
  1623. if (file.desc.parents.length > 0)
  1624. {
  1625. window.open('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
  1626. }
  1627. else
  1628. {
  1629. window.open('https://drive.google.com/?authuser=0');
  1630. }
  1631. }
  1632. else if (mode == App.MODE_DROPBOX)
  1633. {
  1634. window.open('https://www.dropbox.com/');
  1635. }
  1636. else if (mode == App.MODE_ONEDRIVE)
  1637. {
  1638. window.open('https://onedrive.live.com/');
  1639. }
  1640. }
  1641. mxEvent.consume(evt);
  1642. };
  1643. /**
  1644. * Function: authorize
  1645. *
  1646. * Authorizes the client, gets the userId and calls <open>.
  1647. */
  1648. App.prototype.clearMode = function()
  1649. {
  1650. if (typeof(Storage) != 'undefined')
  1651. {
  1652. var expiry = new Date();
  1653. expiry.setYear(expiry.getFullYear() - 1);
  1654. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  1655. }
  1656. };
  1657. /**
  1658. * Translates this point by the given vector.
  1659. *
  1660. * @param {number} dx X-coordinate of the translation.
  1661. * @param {number} dy Y-coordinate of the translation.
  1662. */
  1663. App.prototype.getDiagramId = function()
  1664. {
  1665. var id = window.location.hash;
  1666. // Strips the hash sign
  1667. if (id != null && id.length > 0)
  1668. {
  1669. id = id.substring(1);
  1670. }
  1671. return id;
  1672. };
  1673. /**
  1674. * Opens any file specified in the URL parameters.
  1675. */
  1676. App.prototype.open = function()
  1677. {
  1678. // Cross-domain window access is not allowed in FF, so if we
  1679. // were opened from another domain then this will fail.
  1680. try
  1681. {
  1682. // If the create URL param is used in embed mode then
  1683. // we try to open the XML from window.opener[value].
  1684. // Use this for embedding via tab to bypass the timing
  1685. // issues when passing messages without onload event.
  1686. if (window.opener != null)
  1687. {
  1688. var value = urlParams['create'];
  1689. if (value != null)
  1690. {
  1691. value = decodeURIComponent(value);
  1692. }
  1693. if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
  1694. value.substring(0, 8) != 'https://')
  1695. {
  1696. var doc = mxUtils.parseXml(window.opener[value]);
  1697. this.editor.setGraphXml(doc.documentElement);
  1698. }
  1699. else if (window.opener.openFile != null)
  1700. {
  1701. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  1702. {
  1703. this.spinner.stop();
  1704. if (filename == null)
  1705. {
  1706. var title = urlParams['title'];
  1707. if (title != null)
  1708. {
  1709. title = decodeURIComponent(title);
  1710. }
  1711. else
  1712. {
  1713. title = this.defaultFilename;
  1714. }
  1715. this.fileLoaded(new LocalFile(this, xml, title));
  1716. this.setMode(null);
  1717. }
  1718. else
  1719. {
  1720. // Replaces PNG with XML extension
  1721. var dot = filename.substring(filename.length - 4) == '.png';
  1722. if (dot > 0)
  1723. {
  1724. filename = filename.substring(0, filename.length - 4) + '.xml';
  1725. }
  1726. this.fileLoaded((mxClient.IS_IOS) ?
  1727. new StorageFile(this, xml, filename) :
  1728. new LocalFile(this, xml, filename));
  1729. }
  1730. }));
  1731. }
  1732. }
  1733. }
  1734. catch(e)
  1735. {
  1736. // ignore
  1737. }
  1738. };
  1739. /**
  1740. * Main function. Program starts here.
  1741. *
  1742. * @param {number} dx X-coordinate of the translation.
  1743. * @param {number} dy Y-coordinate of the translation.
  1744. */
  1745. App.prototype.load = function()
  1746. {
  1747. // Checks if we're running in embedded mode
  1748. if (urlParams['embed'] != '1')
  1749. {
  1750. if (this.spinner.spin(document.body, mxResources.get('starting')))
  1751. {
  1752. try
  1753. {
  1754. this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
  1755. }
  1756. catch (e)
  1757. {
  1758. // ignores invalid state args
  1759. }
  1760. this.editor.graph.setEnabled(this.getCurrentFile() != null);
  1761. // Passes the userId from the state parameter to the client
  1762. if ((window.location.hash == null || window.location.hash.length == 0) &&
  1763. this.drive != null && this.stateArg != null && this.stateArg.userId != null)
  1764. {
  1765. this.drive.setUserId(this.stateArg.userId);
  1766. }
  1767. // Legacy support for fileId parameter which is moved to the hash tag
  1768. if (urlParams['fileId'] != null)
  1769. {
  1770. window.location.hash = 'G' + urlParams['fileId'];
  1771. window.location.search = this.getSearch(['fileId']);
  1772. }
  1773. else
  1774. {
  1775. // Asynchronous or disabled loading of client
  1776. if (this.drive == null)
  1777. {
  1778. if (this.mode == App.MODE_GOOGLE)
  1779. {
  1780. this.mode = null;
  1781. }
  1782. this.start();
  1783. }
  1784. else
  1785. {
  1786. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  1787. {
  1788. // Starts the app without the Google Option if the API fails to load
  1789. if (gapi.drive == null || gapi.drive.realtime == null)
  1790. {
  1791. this.mode = null;
  1792. this.drive = null;
  1793. this.start();
  1794. }
  1795. else
  1796. {
  1797. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1798. {
  1799. // Needed to avoid popup blocking for non-immediate authentication
  1800. gapi.auth.init(mxUtils.bind(this, function()
  1801. {
  1802. if (gapi.client.drive == null)
  1803. {
  1804. this.mode = null;
  1805. this.drive = null;
  1806. }
  1807. this.start();
  1808. }));
  1809. }));
  1810. }
  1811. }));
  1812. }
  1813. }
  1814. }
  1815. }
  1816. else
  1817. {
  1818. this.restoreLibraries();
  1819. }
  1820. };
  1821. /**
  1822. * Called in start after the spinner stops.
  1823. */
  1824. App.prototype.showAlert = function(message)
  1825. {
  1826. if (message != null && message.length > 0)
  1827. {
  1828. var div = document.createElement('div');
  1829. div.className = 'geAlert';
  1830. div.style.zIndex = 2e9;
  1831. div.style.left = '50%';
  1832. div.style.top = '-100%';
  1833. mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
  1834. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
  1835. div.innerHTML = message;
  1836. var close = document.createElement('a');
  1837. close.className = 'geAlertLink';
  1838. close.style.textAlign = 'right';
  1839. close.style.marginTop = '20px';
  1840. close.style.display = 'block';
  1841. close.setAttribute('href', 'javascript:void(0);');
  1842. close.setAttribute('title', mxResources.get('close'));
  1843. close.innerHTML = mxResources.get('close');
  1844. div.appendChild(close);
  1845. mxEvent.addListener(close, 'click', function(evt)
  1846. {
  1847. if (div.parentNode != null)
  1848. {
  1849. div.parentNode.removeChild(div);
  1850. mxEvent.consume(evt);
  1851. }
  1852. });
  1853. document.body.appendChild(div);
  1854. // Delayed to get smoother animation after DOM rendering
  1855. window.setTimeout(function()
  1856. {
  1857. div.style.top = '30px';
  1858. }, 10);
  1859. // Fades out the alert after 15 secs
  1860. window.setTimeout(function()
  1861. {
  1862. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
  1863. div.style.opacity = '0';
  1864. window.setTimeout(function()
  1865. {
  1866. if (div.parentNode != null)
  1867. {
  1868. div.parentNode.removeChild(div);
  1869. }
  1870. }, 2000);
  1871. }, 15000);
  1872. }
  1873. };
  1874. /**
  1875. * Translates this point by the given vector.
  1876. *
  1877. * @param {number} dx X-coordinate of the translation.
  1878. * @param {number} dy Y-coordinate of the translation.
  1879. */
  1880. App.prototype.start = function()
  1881. {
  1882. this.bg.parentNode.removeChild(this.bg);
  1883. this.restoreLibraries();
  1884. this.spinner.stop();
  1885. // Uses proxy to avoid CORS issues
  1886. var loadTemplate = mxUtils.bind(this, function(url, onload, onerror)
  1887. {
  1888. this.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(url), mxUtils.bind(this, function(data)
  1889. {
  1890. if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  1891. {
  1892. // Asynchronous parsing via server
  1893. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  1894. {
  1895. if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText.substring(0, 13) == '<mxGraphModel')
  1896. {
  1897. onload(xhr.responseText);
  1898. }
  1899. }), url);
  1900. }
  1901. else
  1902. {
  1903. if (/(\.png)($|\?)/i.test(url))
  1904. {
  1905. data = this.extractGraphModelFromPng(data);
  1906. }
  1907. onload(data);
  1908. }
  1909. }), onerror, /(\.png)($|\?)/i.test(url));
  1910. });
  1911. // Listens to changes of the hash if not in embed or client mode
  1912. if (urlParams['client'] != '1' && urlParams['embed'] != '1')
  1913. {
  1914. // KNOWN: Does not work in quirks mode
  1915. mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
  1916. {
  1917. var id = this.getDiagramId();
  1918. var file = this.getCurrentFile();
  1919. if (file == null || file.getHash() != id)
  1920. {
  1921. this.loadFile(id, true);
  1922. }
  1923. }));
  1924. }
  1925. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  1926. urlParams['url'] != null && this.spinner.spin(document.body, mxResources.get('loading')))
  1927. {
  1928. try
  1929. {
  1930. var reconnect = mxUtils.bind(this, function()
  1931. {
  1932. // Removes URL parameter and reloads the page
  1933. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  1934. {
  1935. window.location.search = this.getSearch(['url']);
  1936. };
  1937. });
  1938. loadTemplate(decodeURIComponent(urlParams['url']), mxUtils.bind(this, function(text)
  1939. {
  1940. this.spinner.stop();
  1941. if (text != null && text.length > 0)
  1942. {
  1943. var filename = urlParams['title'];
  1944. if (filename == null && urlParams['notitle'] != '1')
  1945. {
  1946. var tmp = decodeURIComponent(urlParams['url']);
  1947. var slash = tmp.lastIndexOf('/');
  1948. if (slash >= 0)
  1949. {
  1950. tmp = tmp.substring(slash + 1);
  1951. }
  1952. filename = tmp;
  1953. // Replaces PNG with XML extension
  1954. var dot = filename.substring(filename.length - 4) == '.png';
  1955. if (dot > 0)
  1956. {
  1957. filename = filename.substring(0, filename.length - 4) + '.xml';
  1958. }
  1959. }
  1960. var file = new LocalFile(this, text, filename || this.defaultFilename);
  1961. this.fileLoaded(file);
  1962. this.setMode(null);
  1963. }
  1964. }), mxUtils.bind(this, function()
  1965. {
  1966. this.spinner.stop();
  1967. this.handleError({message: mxResources.get('fileNotFound')}, mxResources.get('errorLoadingFile'), reconnect);
  1968. }));
  1969. }
  1970. catch (e)
  1971. {
  1972. this.spinner.stop();
  1973. try
  1974. {
  1975. var img = new Image();
  1976. img.src = 'https://log.draw.io/log?v=' + encodeURIComponent(EditorUi.VERSION) +
  1977. '&msg=errorLoadingFile:url:' + encodeURIComponent(window.location.href) +
  1978. ((e != null && e.message != null) ? ':err:' + encodeURIComponent(e.message) : '') +
  1979. ((e != null && e.stack != null) ? '&stack=' + encodeURIComponent(e.stack) : '');
  1980. }
  1981. catch (err)
  1982. {
  1983. // do nothing
  1984. }
  1985. this.handleError(e, mxResources.get('errorLoadingFile'), reconnect);
  1986. }
  1987. }
  1988. else if (this.getCurrentFile() == null)
  1989. {
  1990. var done = mxUtils.bind(this, function()
  1991. {
  1992. // Starts in client mode and waits for data
  1993. if (urlParams['client'] == '1' && (window.location.hash == null ||
  1994. window.location.hash.length == 0))
  1995. {
  1996. var parent = window.opener || window.parent;
  1997. if (parent != window)
  1998. {
  1999. this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
  2000. {
  2001. // Ignores messages from other windows
  2002. if (evt.source == parent)
  2003. {
  2004. // Extracts graph model from PNG
  2005. if (xml.substring(0, 22) == 'data:image/png;base64,')
  2006. {
  2007. xml = this.extractGraphModelFromPng(xml);
  2008. }
  2009. var title = urlParams['title'];
  2010. if (title != null)
  2011. {
  2012. title = decodeURIComponent(title);
  2013. }
  2014. else
  2015. {
  2016. title = this.defaultFilename;
  2017. }
  2018. this.fileLoaded(new LocalFile(this, xml, title));
  2019. this.getCurrentFile().setModified(!this.editor.chromeless);
  2020. this.setMode(null);
  2021. }
  2022. }));
  2023. }
  2024. }
  2025. // Checks if no earlier loading errors are showing
  2026. else if (this.dialog == null)
  2027. {
  2028. if (urlParams['demo'] == '1')
  2029. {
  2030. var prev = Editor.useLocalStorage;
  2031. this.createFile(this.defaultFilename, null, null, App.MODE_DEVICE);
  2032. this.setMode(null);
  2033. Editor.useLocalStorage = prev;
  2034. }
  2035. else
  2036. {
  2037. var waiting = false;
  2038. // Checks if we're waiting for some asynchronous file to be loaded
  2039. // Cross-domain window access is not allowed in FF, so if we
  2040. // were opened from another domain then this will fail.
  2041. try
  2042. {
  2043. waiting = window.opener != null && window.opener.openFile != null;
  2044. }
  2045. catch(e)
  2046. {
  2047. // ignore
  2048. }
  2049. if (waiting)
  2050. {
  2051. // Spinner is stopped in App.open
  2052. this.spinner.spin(document.body, mxResources.get('loading'))
  2053. }
  2054. else
  2055. {
  2056. var id = this.getDiagramId();
  2057. if (urlParams['splash'] == '0' && (id == null || id.length == 0))
  2058. {
  2059. var draft = this.getDraft();
  2060. var fileData = (draft != null) ? draft.data : this.getFileData();
  2061. var prev = Editor.useLocalStorage;
  2062. this.createFile(this.defaultFilename, fileData, null, App.MODE_DEVICE);
  2063. this.setMode(null);
  2064. Editor.useLocalStorage = prev;
  2065. // Draft was used so the user should save the file
  2066. if (draft != null)
  2067. {
  2068. var file = this.getCurrentFile();
  2069. if (file != null)
  2070. {
  2071. file.addUnsavedStatus();
  2072. }
  2073. }
  2074. }
  2075. else
  2076. {
  2077. this.loadFile(this.getDiagramId());
  2078. }
  2079. }
  2080. }
  2081. }
  2082. });
  2083. // Defines custom classes for realtime in Google Drive
  2084. if (this.drive != null)
  2085. {
  2086. this.defineCustomObjects();
  2087. }
  2088. var value = decodeURIComponent(urlParams['create'] || '');
  2089. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2090. value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
  2091. {
  2092. var reconnect = mxUtils.bind(this, function()
  2093. {
  2094. // Removes URL parameter and reloads the page
  2095. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  2096. {
  2097. window.location.search = this.getSearch(['create', 'title']);
  2098. };
  2099. });
  2100. var showCreateDialog = mxUtils.bind(this, function(xml)
  2101. {
  2102. this.spinner.stop();
  2103. // Resets mode for dialog - local file is only for preview
  2104. if (urlParams['splash'] != '0')
  2105. {
  2106. this.fileLoaded(new LocalFile(this, xml, null));
  2107. this.editor.graph.setEnabled(false);
  2108. this.mode = urlParams['mode'];
  2109. var title = urlParams['title'];
  2110. if (title != null)
  2111. {
  2112. title = decodeURIComponent(title);
  2113. }
  2114. else
  2115. {
  2116. title = this.defaultFilename;
  2117. }
  2118. var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
  2119. {
  2120. if (mode == null)
  2121. {
  2122. this.hideDialog();
  2123. var prev = Editor.useLocalStorage;
  2124. this.createFile((filename.length > 0) ? filename : this.defaultFilename,
  2125. this.getFileData(), null, App.MODE_DEVICE);
  2126. this.setMode(null);
  2127. Editor.useLocalStorage = prev;
  2128. }
  2129. else
  2130. {
  2131. this.createFile(filename, this.getFileData(true), null, mode);
  2132. }
  2133. }));
  2134. this.showDialog(dlg.container, 380, 270, true, false, mxUtils.bind(this, function(cancel)
  2135. {
  2136. if (cancel && this.getCurrentFile() == null)
  2137. {
  2138. this.showSplash();
  2139. }
  2140. }));
  2141. dlg.init();
  2142. }
  2143. });
  2144. value = decodeURIComponent(value);
  2145. if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
  2146. {
  2147. // Cross-domain window access is not allowed in FF, so if we
  2148. // were opened from another domain then this will fail.
  2149. try
  2150. {
  2151. if (window.opener != null && window.opener[value] != null)
  2152. {
  2153. showCreateDialog(window.opener[value]);
  2154. }
  2155. else
  2156. {
  2157. this.handleError(null, mxResources.get('errorLoadingFile'));
  2158. }
  2159. }
  2160. catch (e)
  2161. {
  2162. this.handleError(e, mxResources.get('errorLoadingFile'));
  2163. }
  2164. }
  2165. else
  2166. {
  2167. loadTemplate(value, function(text)
  2168. {
  2169. showCreateDialog(text);
  2170. }, mxUtils.bind(this, function()
  2171. {
  2172. this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
  2173. }));
  2174. }
  2175. }
  2176. else
  2177. {
  2178. // Passes the fileId from the state parameter to the hash tag and reloads
  2179. // the page without the state parameter
  2180. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2181. urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
  2182. {
  2183. if (this.stateArg.ids != null)
  2184. {
  2185. window.location.hash = 'G' + this.stateArg.ids[0];
  2186. }
  2187. }
  2188. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2189. this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
  2190. {
  2191. this.setMode(App.MODE_GOOGLE);
  2192. this.actions.get('new').funct();
  2193. }
  2194. else
  2195. {
  2196. done();
  2197. }
  2198. }
  2199. }
  2200. };
  2201. /**
  2202. * Translates this point by the given vector.
  2203. *
  2204. * @param {number} dx X-coordinate of the translation.
  2205. * @param {number} dy Y-coordinate of the translation.
  2206. */
  2207. App.prototype.showSplash = function(force)
  2208. {
  2209. var showSecondDialog = mxUtils.bind(this, function()
  2210. {
  2211. var dlg = new SplashDialog(this);
  2212. this.showDialog(dlg.container, 340, (mxClient.IS_CHROMEAPP) ? 180 : 260, true, true,
  2213. mxUtils.bind(this, function(cancel)
  2214. {
  2215. // Creates a blank diagram if the dialog is closed
  2216. if (cancel && !mxClient.IS_CHROMEAPP)
  2217. {
  2218. var prev = Editor.useLocalStorage;
  2219. this.createFile(this.defaultFilename, null, null, App.MODE_DEVICE);
  2220. this.setMode(null);
  2221. Editor.useLocalStorage = prev;
  2222. }
  2223. }));
  2224. dlg.init();
  2225. });
  2226. if (this.editor.chromeless)
  2227. {
  2228. this.handleError({message: mxResources.get('noFileSelected')},
  2229. mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2230. {
  2231. this.showSplash();
  2232. }));
  2233. }
  2234. else if (this.mode == null || force)
  2235. {
  2236. var dlg = new StorageDialog(this, mxUtils.bind(this, function()
  2237. {
  2238. this.hideDialog();
  2239. showSecondDialog();
  2240. }));
  2241. this.showDialog(dlg.container, (isLocalStorage && urlParams['browser'] == '1') ? 480 : 380, 300, true, false);
  2242. dlg.init();
  2243. }
  2244. else if (urlParams['create'] == null)
  2245. {
  2246. showSecondDialog();
  2247. }
  2248. };
  2249. /**
  2250. * Translates this point by the given vector.
  2251. *
  2252. * @param {number} dx X-coordinate of the translation.
  2253. * @param {number} dy Y-coordinate of the translation.
  2254. */
  2255. App.prototype.addLanguageMenu = function(elt)
  2256. {
  2257. var img = null;
  2258. if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
  2259. {
  2260. var langMenu = this.menus.get('language');
  2261. if (langMenu != null)
  2262. {
  2263. img = document.createElement('div');
  2264. img.setAttribute('title', mxResources.get('language'));
  2265. img.className = 'geIcon geSprite geSprite-globe';
  2266. img.style.position = 'absolute';
  2267. img.style.cursor = 'pointer';
  2268. img.style.bottom = '20px';
  2269. img.style.right = '20px';
  2270. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  2271. {
  2272. this.editor.graph.popupMenuHandler.hideMenu();
  2273. var menu = new mxPopupMenu(this.menus.get('language').funct);
  2274. menu.div.className += ' geMenubarMenu';
  2275. menu.smartSeparators = true;
  2276. menu.showDisabled = true;
  2277. menu.autoExpand = true;
  2278. // Disables autoexpand and destroys menu when hidden
  2279. menu.hideMenu = mxUtils.bind(this, function()
  2280. {
  2281. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  2282. menu.destroy();
  2283. });
  2284. var offset = mxUtils.getOffset(img);
  2285. menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
  2286. // Allows hiding by clicking on document
  2287. this.setCurrentMenu(menu);
  2288. }));
  2289. elt.appendChild(img);
  2290. }
  2291. }
  2292. return img;
  2293. };
  2294. /**
  2295. * Translates this point by the given vector.
  2296. *
  2297. * @param {number} dx X-coordinate of the translation.
  2298. * @param {number} dy Y-coordinate of the translation.
  2299. */
  2300. App.prototype.defineCustomObjects = function()
  2301. {
  2302. if (gapi.drive.realtime != null && gapi.drive.realtime.custom != null)
  2303. {
  2304. gapi.drive.realtime.custom.registerType(mxRtCell, 'Cell');
  2305. mxRtCell.prototype.cellId = gapi.drive.realtime.custom.collaborativeField('cellId');
  2306. mxRtCell.prototype.type = gapi.drive.realtime.custom.collaborativeField('type');
  2307. mxRtCell.prototype.value = gapi.drive.realtime.custom.collaborativeField('value');
  2308. mxRtCell.prototype.xmlValue = gapi.drive.realtime.custom.collaborativeField('xmlValue');
  2309. mxRtCell.prototype.style = gapi.drive.realtime.custom.collaborativeField('style');
  2310. mxRtCell.prototype.geometry = gapi.drive.realtime.custom.collaborativeField('geometry');
  2311. mxRtCell.prototype.visible = gapi.drive.realtime.custom.collaborativeField('visible');
  2312. mxRtCell.prototype.collapsed = gapi.drive.realtime.custom.collaborativeField('collapsed');
  2313. mxRtCell.prototype.connectable = gapi.drive.realtime.custom.collaborativeField('connectable');
  2314. mxRtCell.prototype.parent = gapi.drive.realtime.custom.collaborativeField('parent');
  2315. mxRtCell.prototype.children = gapi.drive.realtime.custom.collaborativeField('children');
  2316. mxRtCell.prototype.source = gapi.drive.realtime.custom.collaborativeField('source');
  2317. mxRtCell.prototype.target = gapi.drive.realtime.custom.collaborativeField('target');
  2318. }
  2319. };
  2320. mxRtCell = function() {};
  2321. // Ignores rtCell property in codec and cloning
  2322. mxCodecRegistry.getCodec(mxCell).exclude.push('rtCell');
  2323. mxCell.prototype.mxTransient.push('rtCell');
  2324. /**
  2325. * Translates this point by the given vector.
  2326. *
  2327. * @param {number} dx X-coordinate of the translation.
  2328. * @param {number} dy Y-coordinate of the translation.
  2329. */
  2330. App.prototype.pickFile = function(mode)
  2331. {
  2332. mode = (mode != null) ? mode : this.mode;
  2333. if (mode == App.MODE_DROPBOX)
  2334. {
  2335. if (this.dropbox != null)
  2336. {
  2337. this.dropbox.pickFile();
  2338. }
  2339. }
  2340. else if (mode == App.MODE_ONEDRIVE)
  2341. {
  2342. if (this.oneDrive != null)
  2343. {
  2344. this.oneDrive.pickFile();
  2345. }
  2346. }
  2347. else if (mode == App.MODE_GOOGLE)
  2348. {
  2349. if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2350. {
  2351. this.drive.pickFile();
  2352. }
  2353. else
  2354. {
  2355. window.open('https://drive.google.com');
  2356. }
  2357. }
  2358. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2359. {
  2360. var input = document.createElement('input');
  2361. input.setAttribute('type', 'file');
  2362. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2363. {
  2364. if (input.files != null)
  2365. {
  2366. this.openFiles(input.files);
  2367. }
  2368. }));
  2369. input.click();
  2370. }
  2371. else
  2372. {
  2373. this.hideDialog();
  2374. window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
  2375. window.baseUrl = this.getUrl();
  2376. window.openKey = 'open';
  2377. var prevValue = Editor.useLocalStorage;
  2378. Editor.useLocalStorage = (mode == App.MODE_BROWSER);
  2379. this.openFile();
  2380. // Installs local handler for opened files in same window
  2381. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2382. {
  2383. // Replaces PNG with XML extension
  2384. var dot = filename.substring(filename.length - 4) == '.png';
  2385. if (dot > 0)
  2386. {
  2387. filename = filename.substring(0, filename.length - 4) + '.xml';
  2388. }
  2389. this.fileLoaded((mode == App.MODE_BROWSER) ?
  2390. new StorageFile(this, xml, filename) :
  2391. new LocalFile(this, xml, filename));
  2392. }));
  2393. // Extends dialog close to show splash screen
  2394. var dlg = this.dialog;
  2395. var dlgClose = dlg.close;
  2396. this.dialog.close = mxUtils.bind(this, function(cancel)
  2397. {
  2398. Editor.useLocalStorage = prevValue;
  2399. dlgClose.apply(dlg, arguments);
  2400. if (this.getCurrentFile() == null)
  2401. {
  2402. this.showSplash();
  2403. }
  2404. });
  2405. }
  2406. };
  2407. /**
  2408. * Translates this point by the given vector.
  2409. *
  2410. * @param {number} dx X-coordinate of the translation.
  2411. * @param {number} dy Y-coordinate of the translation.
  2412. */
  2413. App.prototype.pickLibrary = function(mode)
  2414. {
  2415. mode = (mode != null) ? mode : this.mode;
  2416. if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE)
  2417. {
  2418. var peer = (mode == App.MODE_GOOGLE) ? this.drive : ((mode == App.MODE_ONEDRIVE) ? this.oneDrive : this.dropbox);
  2419. if (peer != null)
  2420. {
  2421. peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
  2422. {
  2423. if (optionalFile != null)
  2424. {
  2425. this.loadLibrary(optionalFile);
  2426. }
  2427. else
  2428. {
  2429. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2430. {
  2431. peer.getLibrary(id, mxUtils.bind(this, function(file)
  2432. {
  2433. this.spinner.stop();
  2434. try
  2435. {
  2436. this.loadLibrary(file);
  2437. }
  2438. catch (e)
  2439. {
  2440. this.handleError(e, mxResources.get('errorLoadingFile'));
  2441. }
  2442. }), mxUtils.bind(this, function(resp)
  2443. {
  2444. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2445. }));
  2446. }
  2447. }
  2448. }));
  2449. }
  2450. }
  2451. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2452. {
  2453. var input = document.createElement('input');
  2454. input.setAttribute('type', 'file');
  2455. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2456. {
  2457. if (input.files != null)
  2458. {
  2459. for (var i = 0; i < input.files.length; i++)
  2460. {
  2461. (mxUtils.bind(this, function(file)
  2462. {
  2463. var reader = new FileReader();
  2464. reader.onload = mxUtils.bind(this, function(e)
  2465. {
  2466. try
  2467. {
  2468. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  2469. }
  2470. catch (e)
  2471. {
  2472. this.handleError(e, mxResources.get('errorLoadingFile'));
  2473. }
  2474. });
  2475. reader.readAsText(file);
  2476. }))(input.files[i]);
  2477. }
  2478. }
  2479. }));
  2480. input.click();
  2481. }
  2482. else
  2483. {
  2484. window.openNew = false;
  2485. window.openKey = 'open';
  2486. var prevValue = Editor.useLocalStorage;
  2487. Editor.useLocalStorage = mode == App.MODE_BROWSER;
  2488. // Closes dialog after open
  2489. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2490. {
  2491. this.hideDialog(cancel);
  2492. }));
  2493. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2494. {
  2495. try
  2496. {
  2497. this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
  2498. new LocalLibrary(this, xml, filename));
  2499. }
  2500. catch (e)
  2501. {
  2502. this.handleError(e, mxResources.get('errorLoadingFile'));
  2503. }
  2504. }));
  2505. // Removes openFile if dialog is closed
  2506. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
  2507. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2508. {
  2509. Editor.useLocalStorage = prevValue;
  2510. window.openFile = null;
  2511. });
  2512. }
  2513. };
  2514. /**
  2515. * Translates this point by the given vector.
  2516. *
  2517. * @param {number} dx X-coordinate of the translation.
  2518. * @param {number} dy Y-coordinate of the translation.
  2519. */
  2520. App.prototype.createLibraryDataFromImages = function(images)
  2521. {
  2522. var doc = mxUtils.createXmlDocument();
  2523. var library = doc.createElement('mxlibrary');
  2524. mxUtils.setTextContent(library, JSON.stringify(images));
  2525. doc.appendChild(library);
  2526. return mxUtils.getXml(doc);
  2527. };
  2528. /**
  2529. * Translates this point by the given vector.
  2530. *
  2531. * @param {number} dx X-coordinate of the translation.
  2532. * @param {number} dy Y-coordinate of the translation.
  2533. */
  2534. App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  2535. {
  2536. mode = (mode != null) ? mode : this.mode;
  2537. noSpin = (noSpin != null) ? noSpin : false;
  2538. noReload = (noReload != null) ? noReload : false;
  2539. var xml = this.createLibraryDataFromImages(images);
  2540. var error = mxUtils.bind(this, function(resp)
  2541. {
  2542. this.spinner.stop();
  2543. if (fn != null)
  2544. {
  2545. fn();
  2546. }
  2547. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  2548. });
  2549. // Handles special case for local libraries
  2550. if (file == null && mode == App.MODE_DEVICE)
  2551. {
  2552. file = new LocalLibrary(this, xml, name);
  2553. }
  2554. if (file == null)
  2555. {
  2556. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2557. {
  2558. if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2559. {
  2560. this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
  2561. {
  2562. this.spinner.stop();
  2563. this.hideDialog(true);
  2564. this.libraryLoaded(newFile, images);
  2565. }), error, this.drive.libraryMimeType);
  2566. }
  2567. else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2568. {
  2569. this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2570. {
  2571. this.spinner.stop();
  2572. this.hideDialog(true);
  2573. this.libraryLoaded(newFile, images);
  2574. }), error, folderId);
  2575. }
  2576. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2577. {
  2578. this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2579. {
  2580. this.spinner.stop();
  2581. this.hideDialog(true);
  2582. this.libraryLoaded(newFile, images);
  2583. }), error, folderId);
  2584. }
  2585. else if (mode == App.MODE_BROWSER)
  2586. {
  2587. var fn = mxUtils.bind(this, function()
  2588. {
  2589. var file = new StorageLibrary(this, xml, name);
  2590. // Inserts data into local storage
  2591. file.saveFile(name, false, mxUtils.bind(this, function()
  2592. {
  2593. this.hideDialog(true);
  2594. this.libraryLoaded(file, images);
  2595. }), error);
  2596. });
  2597. if (localStorage.getItem(name) == null)
  2598. {
  2599. fn();
  2600. }
  2601. else
  2602. {
  2603. this.confirm(mxResources.get('replaceIt', [name]), fn);
  2604. }
  2605. }
  2606. else
  2607. {
  2608. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  2609. }
  2610. }));
  2611. }
  2612. else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
  2613. {
  2614. file.setData(xml);
  2615. var doSave = mxUtils.bind(this, function()
  2616. {
  2617. file.save(true, mxUtils.bind(this, function(resp)
  2618. {
  2619. this.spinner.stop();
  2620. this.hideDialog(true);
  2621. if (!noReload)
  2622. {
  2623. this.libraryLoaded(file, images);
  2624. }
  2625. if (fn != null)
  2626. {
  2627. fn();
  2628. }
  2629. }), error);
  2630. });
  2631. if (name != file.getTitle())
  2632. {
  2633. var oldHash = file.getHash();
  2634. file.rename(name, mxUtils.bind(this, function(resp)
  2635. {
  2636. // Change hash in stored settings
  2637. if (file.constructor != LocalLibrary && oldHash != file.getHash())
  2638. {
  2639. mxSettings.removeCustomLibrary(oldHash);
  2640. mxSettings.addCustomLibrary(file.getHash());
  2641. }
  2642. // Workaround for library files changing hash so
  2643. // the old library cannot be removed from the
  2644. // sidebar using the updated file in libraryLoaded
  2645. this.removeLibrarySidebar(oldHash);
  2646. doSave();
  2647. }), error)
  2648. }
  2649. else
  2650. {
  2651. doSave();
  2652. }
  2653. }
  2654. };
  2655. /**
  2656. * Adds the label menu items to the given menu and parent.
  2657. */
  2658. App.prototype.saveFile = function(forceDialog)
  2659. {
  2660. var file = this.getCurrentFile();
  2661. if (file != null)
  2662. {
  2663. // FIXME: Invoke for local files
  2664. var done = mxUtils.bind(this, function()
  2665. {
  2666. this.removeDraft();
  2667. // Workaround for possible status update while save as dialog is showing
  2668. // is to show no saved status for device files
  2669. if (file.getMode() != App.MODE_DEVICE)
  2670. {
  2671. this.editor.setStatus(mxResources.get('allChangesSaved'));
  2672. }
  2673. else
  2674. {
  2675. this.editor.setStatus('');
  2676. }
  2677. });
  2678. if (!forceDialog && file.getTitle() != null && this.mode != null)
  2679. {
  2680. this.save(file.getTitle(), done);
  2681. }
  2682. else
  2683. {
  2684. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  2685. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2686. var prev = this.mode;
  2687. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
  2688. {
  2689. if (name != null && name.length > 0)
  2690. {
  2691. if (prev == null && mode == App.MODE_DEVICE)
  2692. {
  2693. this.setMode(App.MODE_DEVICE);
  2694. this.save(name, done);
  2695. }
  2696. else if (mode == 'download')
  2697. {
  2698. var tmp = new LocalFile(this, null, name);
  2699. tmp.save();
  2700. }
  2701. else if (mode == '_blank')
  2702. {
  2703. window.openFile = new OpenFile(function()
  2704. {
  2705. window.openFile = null;
  2706. });
  2707. // Do not use a filename to use undefined mode
  2708. window.openFile.setData(this.getFileData(true));
  2709. window.open(this.getUrl(window.location.pathname));
  2710. }
  2711. else if (prev != mode)
  2712. {
  2713. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2714. {
  2715. this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
  2716. name.indexOf('.') < 0, /(\.svg)$/i.test(name),
  2717. /(\.html)$/i.test(name)), null, mode, done,
  2718. this.mode == null, folderId);
  2719. }));
  2720. }
  2721. else if (mode != null)
  2722. {
  2723. this.save(name, done);
  2724. }
  2725. }
  2726. }), mxUtils.bind(this, function()
  2727. {
  2728. this.hideDialog();
  2729. }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
  2730. (this.isOffline()) ? null : 'https://support.draw.io/questions/9338901', true);
  2731. this.showDialog(dlg.container, 440, 380, true, true);
  2732. dlg.init();
  2733. }
  2734. }
  2735. };
  2736. /**
  2737. * Translates this point by the given vector.
  2738. *
  2739. * @param {number} dx X-coordinate of the translation.
  2740. * @param {number} dy Y-coordinate of the translation.
  2741. */
  2742. App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId)
  2743. {
  2744. mode = (mode != null) ? mode : this.mode;
  2745. if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2746. {
  2747. data = (data != null) ? data : this.emptyDiagramXml;
  2748. var error = mxUtils.bind(this, function(resp)
  2749. {
  2750. this.spinner.stop();
  2751. if (resp == null && this.getCurrentFile() == null && this.dialog == null)
  2752. {
  2753. this.showSplash();
  2754. }
  2755. else if (resp != null)
  2756. {
  2757. this.handleError(resp);
  2758. }
  2759. });
  2760. if (mode == App.MODE_GOOGLE && this.drive != null)
  2761. {
  2762. folderId = (this.stateArg != null) ? this.stateArg.folderId : folderId;
  2763. this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
  2764. {
  2765. this.spinner.stop();
  2766. this.fileCreated(file, libs, replace, done);
  2767. }), error);
  2768. }
  2769. else if (mode == App.MODE_DROPBOX && this.dropbox != null)
  2770. {
  2771. this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
  2772. {
  2773. this.spinner.stop();
  2774. this.fileCreated(file, libs, replace, done);
  2775. }), error);
  2776. }
  2777. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  2778. {
  2779. this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
  2780. {
  2781. this.spinner.stop();
  2782. this.fileCreated(file, libs, replace, done);
  2783. }), error, false, folderId);
  2784. }
  2785. else if (mode == App.MODE_BROWSER)
  2786. {
  2787. this.spinner.stop();
  2788. var fn = mxUtils.bind(this, function()
  2789. {
  2790. var file = new StorageFile(this, data, title);
  2791. // Inserts data into local storage
  2792. file.saveFile(title, false, mxUtils.bind(this, function()
  2793. {
  2794. this.fileCreated(file, libs, replace, done);
  2795. }), error);
  2796. });
  2797. if (localStorage.getItem(title) == null)
  2798. {
  2799. fn();
  2800. }
  2801. else
  2802. {
  2803. this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
  2804. {
  2805. if (this.getCurrentFile() == null && this.dialog == null)
  2806. {
  2807. this.showSplash();
  2808. }
  2809. }));
  2810. }
  2811. }
  2812. else
  2813. {
  2814. this.spinner.stop();
  2815. this.fileCreated(new LocalFile(this, data, title), libs, replace, done);
  2816. }
  2817. }
  2818. };
  2819. /**
  2820. * Translates this point by the given vector.
  2821. *
  2822. * @param {number} dx X-coordinate of the translation.
  2823. * @param {number} dy Y-coordinate of the translation.
  2824. */
  2825. App.prototype.fileCreated = function(file, libs, replace, done)
  2826. {
  2827. var url = window.location.pathname;
  2828. if (libs != null && libs.length > 0)
  2829. {
  2830. url += '?libs=' + libs;
  2831. }
  2832. url = this.getUrl(url);
  2833. // Always opens a new tab for local files to avoid losing changes
  2834. if (file.getMode() != App.MODE_DEVICE)
  2835. {
  2836. url += '#' + file.getHash();
  2837. }
  2838. // Makes sure to produce consistent output with finalized files via createFileData this needs
  2839. // to save the file again since it needs the newly created file ID for redirecting in HTML
  2840. if (this.spinner.spin(document.body, mxResources.get('inserting')))
  2841. {
  2842. var data = file.getData();
  2843. file.setData(this.createFileData((data.length > 0) ?
  2844. this.editor.extractGraphModel(mxUtils.parseXml(data).documentElement, true) : null,
  2845. null, file, window.location.protocol + '//' + window.location.hostname + url));
  2846. var fn = mxUtils.bind(this, function()
  2847. {
  2848. this.spinner.stop();
  2849. var fn2 = mxUtils.bind(this, function()
  2850. {
  2851. window.openFile = null;
  2852. this.fileLoaded(file);
  2853. if (libs != null)
  2854. {
  2855. this.sidebar.showEntries(libs);
  2856. }
  2857. if (done != null)
  2858. {
  2859. done();
  2860. }
  2861. });
  2862. // Updates the file if it has been overwritten
  2863. if (!replace && this.getCurrentFile() != null && this.mode != null)
  2864. {
  2865. // Opens local file in a new window
  2866. if (file.constructor == LocalFile)
  2867. {
  2868. window.openFile = new OpenFile(function()
  2869. {
  2870. window.openFile = null;
  2871. });
  2872. window.openFile.setData(file.getData(), file.getTitle());
  2873. }
  2874. window.openWindow(url, null, fn2);
  2875. }
  2876. else
  2877. {
  2878. fn2();
  2879. }
  2880. });
  2881. // Updates data in memory for local files and save is implicit
  2882. // via start of realtime for DriveFiles
  2883. if (file.constructor == LocalFile || file.constructor == DriveFile)
  2884. {
  2885. fn();
  2886. }
  2887. else
  2888. {
  2889. file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
  2890. {
  2891. fn();
  2892. }), mxUtils.bind(this, function(resp)
  2893. {
  2894. this.spinner.stop();
  2895. this.handleError(resp);
  2896. }));
  2897. }
  2898. }
  2899. };
  2900. /**
  2901. * Translates this point by the given vector.
  2902. *
  2903. * @param {number} dx X-coordinate of the translation.
  2904. * @param {number} dy Y-coordinate of the translation.
  2905. */
  2906. App.prototype.loadFile = function(id, sameWindow, file)
  2907. {
  2908. this.hideDialog();
  2909. var fn = mxUtils.bind(this, function()
  2910. {
  2911. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2912. {
  2913. // Handles files from localStorage
  2914. if (id.charAt(0) == 'L')
  2915. {
  2916. this.spinner.stop();
  2917. if (!isLocalStorage)
  2918. {
  2919. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2920. {
  2921. var file = this.getCurrentFile();
  2922. window.location.hash = (file != null) ? file.getHash() : '';
  2923. }));
  2924. }
  2925. else
  2926. {
  2927. try
  2928. {
  2929. id = decodeURIComponent(id.substring(1));
  2930. var data = localStorage.getItem(id);
  2931. if (data != null)
  2932. {
  2933. this.fileLoaded(new StorageFile(this, data, id));
  2934. }
  2935. else
  2936. {
  2937. throw {message: mxResources.get('fileNotFound')};
  2938. }
  2939. }
  2940. catch (e)
  2941. {
  2942. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2943. {
  2944. var file = this.getCurrentFile();
  2945. window.location.hash = (file != null) ? file.getHash() : '';
  2946. }));
  2947. }
  2948. }
  2949. }
  2950. else if (file != null)
  2951. {
  2952. // File already loaded
  2953. this.spinner.stop();
  2954. this.fileLoaded(file);
  2955. }
  2956. else
  2957. {
  2958. // Google Drive files are handled as default file types
  2959. var peer = null;
  2960. if (id.charAt(0) == 'G')
  2961. {
  2962. peer = this.drive;
  2963. }
  2964. else if (id.charAt(0) == 'D')
  2965. {
  2966. peer = this.dropbox;
  2967. }
  2968. else if (id.charAt(0) == 'W')
  2969. {
  2970. peer = this.oneDrive;
  2971. }
  2972. id = decodeURIComponent(id.substring(1));
  2973. if (peer == null)
  2974. {
  2975. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2976. {
  2977. var file = this.getCurrentFile();
  2978. window.location.hash = (file != null) ? file.getHash() : '';
  2979. }));
  2980. }
  2981. else
  2982. {
  2983. peer.getFile(id, mxUtils.bind(this, function(file)
  2984. {
  2985. this.spinner.stop();
  2986. this.fileLoaded(file);
  2987. }), mxUtils.bind(this, function(resp)
  2988. {
  2989. // Makes sure the file does not save the invalid UI model and overwrites anything important
  2990. if (window.console != null && resp != null)
  2991. {
  2992. console.log('error in loadFile:', id, resp);
  2993. }
  2994. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
  2995. {
  2996. var file = this.getCurrentFile();
  2997. if (file == null)
  2998. {
  2999. window.location.hash = '';
  3000. this.showSplash();
  3001. }
  3002. else
  3003. {
  3004. window.location.hash = file.getHash();
  3005. }
  3006. }));
  3007. }));
  3008. }
  3009. }
  3010. }
  3011. });
  3012. if (id == null || id.length == 0)
  3013. {
  3014. this.editor.setStatus('');
  3015. this.fileLoaded(null);
  3016. }
  3017. else if (this.getCurrentFile() != null && !this.isDiagramEmpty() && !sameWindow)
  3018. {
  3019. window.openWindow(this.getUrl() + '#' + id, null, fn);
  3020. }
  3021. else
  3022. {
  3023. fn();
  3024. }
  3025. };
  3026. /**
  3027. * Translates this point by the given vector.
  3028. *
  3029. * @param {number} dx X-coordinate of the translation.
  3030. * @param {number} dy Y-coordinate of the translation.
  3031. */
  3032. App.prototype.loadLibrary = function(file)
  3033. {
  3034. var doc = mxUtils.parseXml(file.getData());
  3035. if (doc.documentElement.nodeName == 'mxlibrary')
  3036. {
  3037. var images = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  3038. this.libraryLoaded(file, images);
  3039. }
  3040. else
  3041. {
  3042. throw {message: mxResources.get('notALibraryFile')};
  3043. }
  3044. };
  3045. /**
  3046. * Translates this point by the given vector.
  3047. *
  3048. * @param {number} dx X-coordinate of the translation.
  3049. * @param {number} dy Y-coordinate of the translation.
  3050. */
  3051. App.prototype.removeLibrarySidebar = function(id)
  3052. {
  3053. var elts = this.sidebar.palettes[id];
  3054. if (elts != null)
  3055. {
  3056. for (var i = 0; i < elts.length; i++)
  3057. {
  3058. elts[i].parentNode.removeChild(elts[i]);
  3059. }
  3060. delete this.sidebar.palettes[id];
  3061. }
  3062. };
  3063. /**
  3064. * Translates this point by the given vector.
  3065. *
  3066. * @param {number} dx X-coordinate of the translation.
  3067. * @param {number} dy Y-coordinate of the translation.
  3068. */
  3069. App.prototype.getLibraryStorageHint = function(file)
  3070. {
  3071. var tip = '';
  3072. if (file.constructor != LocalLibrary)
  3073. {
  3074. tip += file.getHash();
  3075. }
  3076. if (file.constructor == DriveLibrary)
  3077. {
  3078. tip += ' (' + mxResources.get('googleDrive') + ')';
  3079. }
  3080. else if (file.constructor == DropboxLibrary)
  3081. {
  3082. tip += ' (' + mxResources.get('dropbox') + ')';
  3083. }
  3084. else if (file.constructor == OneDriveLibrary)
  3085. {
  3086. tip += ' (' + mxResources.get('oneDrive') + ')';
  3087. }
  3088. else if (file.constructor == StorageLibrary)
  3089. {
  3090. tip += ' (' + mxResources.get('browser') + ')';
  3091. }
  3092. else if (file.constructor == LocalLibrary)
  3093. {
  3094. tip += ' (' + mxResources.get('device') + ')';
  3095. }
  3096. return tip;
  3097. };
  3098. /**
  3099. * Translates this point by the given vector.
  3100. *
  3101. * @param {number} dx X-coordinate of the translation.
  3102. * @param {number} dy Y-coordinate of the translation.
  3103. */
  3104. App.prototype.closeLibrary = function(file)
  3105. {
  3106. if (file != null)
  3107. {
  3108. this.removeLibrarySidebar(file.getHash());
  3109. if (file.constructor != LocalLibrary)
  3110. {
  3111. mxSettings.removeCustomLibrary(file.getHash());
  3112. }
  3113. if (file.title == '.scratchpad')
  3114. {
  3115. this.scratchpad = null;
  3116. }
  3117. }
  3118. };
  3119. /**
  3120. * Changes the position of the library in the sidebar
  3121. */
  3122. App.prototype.repositionLibrary = function(nextChild)
  3123. {
  3124. var c = this.sidebar.container;
  3125. nextChild = (nextChild != null) ? nextChild : c.firstChild.nextSibling.nextSibling;
  3126. var content = c.lastChild;
  3127. var title = content.previousSibling;
  3128. c.insertBefore(content, nextChild);
  3129. c.insertBefore(title, content);
  3130. }
  3131. /**
  3132. * Translates this point by the given vector.
  3133. *
  3134. * @param {number} dx X-coordinate of the translation.
  3135. * @param {number} dy Y-coordinate of the translation.
  3136. */
  3137. App.prototype.toggleScratchpad = function()
  3138. {
  3139. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3140. {
  3141. if (this.scratchpad == null)
  3142. {
  3143. this.getLocalData('.scratchpad', mxUtils.bind(this, function(xml)
  3144. {
  3145. if (xml == null)
  3146. {
  3147. xml = this.emptyLibraryXml;
  3148. }
  3149. this.loadLibrary(new StorageLibrary(this, xml, '.scratchpad'));
  3150. }));
  3151. }
  3152. else
  3153. {
  3154. this.closeLibrary(this.scratchpad);
  3155. }
  3156. }
  3157. };
  3158. /**
  3159. * Translates this point by the given vector.
  3160. *
  3161. * @param {number} dx X-coordinate of the translation.
  3162. * @param {number} dy Y-coordinate of the translation.
  3163. */
  3164. App.prototype.libraryLoaded = function(file, images)
  3165. {
  3166. if (file.constructor != LocalLibrary)
  3167. {
  3168. mxSettings.addCustomLibrary(file.getHash());
  3169. }
  3170. if (file.title == '.scratchpad')
  3171. {
  3172. this.scratchpad = file;
  3173. }
  3174. var elts = this.sidebar.palettes[file.getHash()];
  3175. var nextSibling = (elts != null) ? elts[elts.length - 1].nextSibling : null;
  3176. // Removes existing sidebar entry for this library
  3177. this.removeLibrarySidebar(file.getHash());
  3178. var dropTarget = null;
  3179. var addImages = mxUtils.bind(this, function(imgs, content)
  3180. {
  3181. if (imgs.length == 0 && file.isEditable())
  3182. {
  3183. if (dropTarget == null)
  3184. {
  3185. dropTarget = document.createElement('div');
  3186. mxUtils.setPrefixedStyle(dropTarget.style, 'borderRadius', '6px');
  3187. dropTarget.style.border = '3px dotted lightGray';
  3188. dropTarget.style.textAlign = 'center';
  3189. dropTarget.style.padding = '8px';
  3190. dropTarget.style.color = '#B3B3B3';
  3191. mxUtils.write(dropTarget, mxResources.get('dragElementsHere'));
  3192. }
  3193. content.appendChild(dropTarget);
  3194. }
  3195. else
  3196. {
  3197. for (var i = 0; i < imgs.length; i++)
  3198. {
  3199. var img = imgs[i];
  3200. var data = img.data;
  3201. if (data != null)
  3202. {
  3203. data = this.convertDataUri(data);
  3204. var s = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;';
  3205. if (img.aspect == 'fixed')
  3206. {
  3207. s += 'aspect=fixed;'
  3208. }
  3209. else
  3210. {
  3211. s += 'imageAspect=0;'
  3212. }
  3213. content.appendChild(this.sidebar.createVertexTemplate(s + 'image=' +
  3214. data, img.w, img.h, '', img.title || '', false, false, false));
  3215. }
  3216. else if (img.xml != null)
  3217. {
  3218. var cells = this.stringToCells(this.editor.graph.decompress(img.xml));
  3219. if (cells.length > 0)
  3220. {
  3221. content.appendChild(this.sidebar.createVertexTemplateFromCells(
  3222. cells, img.w, img.h, img.title || '', true, false, false));
  3223. }
  3224. }
  3225. }
  3226. }
  3227. });
  3228. // Adds new sidebar entry for this library
  3229. var contentDiv = this.sidebar.addPalette(file.getHash(), file.getTitle(), true, mxUtils.bind(this, function(content)
  3230. {
  3231. addImages(images, content);
  3232. }));
  3233. this.repositionLibrary(nextSibling);
  3234. // Adds tooltip for backend
  3235. var title = contentDiv.parentNode.previousSibling;
  3236. var tip = title.getAttribute('title');
  3237. if (tip != null && tip.length > 0 && file.title != '.scratchpad')
  3238. {
  3239. title.setAttribute('title', this.getLibraryStorageHint(file) + '\n' + tip);
  3240. }
  3241. var buttons = document.createElement('div');
  3242. buttons.style.position = 'absolute';
  3243. buttons.style.right = '0px';
  3244. buttons.style.top = '5px';
  3245. title.style.position = 'relative';
  3246. var btn = document.createElement('img');
  3247. btn.setAttribute('src', Dialog.prototype.closeImage);
  3248. btn.setAttribute('title', mxResources.get('close'));
  3249. btn.setAttribute('align', 'top');
  3250. btn.setAttribute('border', '0');
  3251. btn.style.cursor = 'pointer';
  3252. btn.style.marginRight = '8px';
  3253. btn.style.marginTop = '3px';
  3254. buttons.appendChild(btn);
  3255. var saveBtn = null;
  3256. mxEvent.addListener(btn, 'click', mxUtils.bind(this, function(evt)
  3257. {
  3258. // Workaround for close after any button click in IE8/quirks
  3259. if (!mxEvent.isConsumed(evt))
  3260. {
  3261. var fn = mxUtils.bind(this, function()
  3262. {
  3263. this.closeLibrary(file);
  3264. });
  3265. if (saveBtn != null)
  3266. {
  3267. this.confirm(mxResources.get('allChangesLost'), fn);
  3268. }
  3269. else
  3270. {
  3271. fn();
  3272. }
  3273. mxEvent.consume(evt);
  3274. }
  3275. }));
  3276. // Shows tooltip if mouse over background
  3277. mxEvent.addListener(contentDiv, 'mousemove', mxUtils.bind(this, function(evt)
  3278. {
  3279. if (mxEvent.getSource(evt) == contentDiv)
  3280. {
  3281. contentDiv.setAttribute('title', mxResources.get('libraryTooltip'));
  3282. }
  3283. else
  3284. {
  3285. contentDiv.removeAttribute('title');
  3286. }
  3287. }));
  3288. if (file.isEditable())
  3289. {
  3290. var graph = this.editor.graph;
  3291. var editLibrary = mxUtils.bind(this, function(evt)
  3292. {
  3293. this.showLibraryDialog(file.getTitle(), contentDiv, images, file, file.getMode());
  3294. mxEvent.consume(evt);
  3295. });
  3296. var saveLibrary = mxUtils.bind(this, function(evt)
  3297. {
  3298. if (file.constructor != LocalLibrary || file.isAutosave())
  3299. {
  3300. if (spinBtn != null && spinBtn.parentNode != null)
  3301. {
  3302. spinBtn.parentNode.removeChild(spinBtn);
  3303. }
  3304. spinBtn = btn.cloneNode(false);
  3305. spinBtn.setAttribute('src', App.prototype.spinImage);
  3306. spinBtn.setAttribute('title', mxResources.get('saving'));
  3307. spinBtn.style.cursor = 'default';
  3308. spinBtn.style.marginRight = '6px';
  3309. spinBtn.style.marginTop = '2px';
  3310. buttons.insertBefore(spinBtn, buttons.firstChild);
  3311. this.saveLibrary(file.getTitle(), images, file, file.getMode(), true, true, function()
  3312. {
  3313. if (spinBtn != null && spinBtn.parentNode != null)
  3314. {
  3315. spinBtn.parentNode.removeChild(spinBtn);
  3316. }
  3317. });
  3318. }
  3319. else if (saveBtn == null)
  3320. {
  3321. saveBtn = btn.cloneNode(false);
  3322. saveBtn.setAttribute('src', IMAGE_PATH + '/download.png');
  3323. saveBtn.setAttribute('title', mxResources.get('save'));
  3324. buttons.insertBefore(saveBtn, buttons.firstChild);
  3325. mxEvent.addListener(saveBtn, 'click', mxUtils.bind(this, function(evt)
  3326. {
  3327. this.saveLibrary(file.getTitle(), images, file, file.getMode(), true, true);
  3328. saveBtn.parentNode.removeChild(saveBtn);
  3329. saveBtn = null;
  3330. mxEvent.consume(evt);
  3331. }));
  3332. }
  3333. });
  3334. var addCells = mxUtils.bind(this, function(cells, bounds, evt, title)
  3335. {
  3336. cells = graph.cloneCells(graph.model.getTopmostCells(cells));
  3337. // Translates cells to origin
  3338. for (var i = 0; i < cells.length; i++)
  3339. {
  3340. var geo = graph.getCellGeometry(cells[i]);
  3341. if (geo != null)
  3342. {
  3343. geo.translate(-bounds.x, -bounds.y);
  3344. }
  3345. }
  3346. contentDiv.appendChild(this.sidebar.createVertexTemplateFromCells(
  3347. cells, bounds.width, bounds.height, title || '', true, false, false));
  3348. var xml = this.editor.graph.compress(mxUtils.getXml(this.editor.graph.encodeCells(cells)));
  3349. var entry = {xml: xml, w: bounds.width, h: bounds.height};
  3350. if (title != null)
  3351. {
  3352. entry.title = title;
  3353. }
  3354. images.push(entry);
  3355. saveLibrary(evt);
  3356. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  3357. {
  3358. dropTarget.parentNode.removeChild(dropTarget);
  3359. dropTarget = null;
  3360. }
  3361. });
  3362. var addSelection = mxUtils.bind(this, function(evt)
  3363. {
  3364. if (!graph.isSelectionEmpty())
  3365. {
  3366. var cells = graph.getSelectionCells();
  3367. var bounds = graph.view.getBounds(cells);
  3368. var s = graph.view.scale;
  3369. bounds.x /= s;
  3370. bounds.y /= s;
  3371. bounds.width /= s;
  3372. bounds.height /= s;
  3373. bounds.x -= graph.view.translate.x;
  3374. bounds.y -= graph.view.translate.y;
  3375. addCells(cells, bounds);
  3376. }
  3377. else
  3378. {
  3379. this.showError(mxResources.get('error'), mxResources.get('nothingIsSelected'), mxResources.get('ok'));
  3380. }
  3381. mxEvent.consume(evt);
  3382. });
  3383. // Defines inactive border state
  3384. contentDiv.style.border = '3px solid transparent';
  3385. // Adds drop handler from graph
  3386. mxEvent.addGestureListeners(contentDiv, function(){}, mxUtils.bind(this, function(evt)
  3387. {
  3388. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler.shape != null)
  3389. {
  3390. graph.graphHandler.shape.node.style.visibility = 'hidden';
  3391. if (dropTarget != null)
  3392. {
  3393. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  3394. }
  3395. else
  3396. {
  3397. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  3398. }
  3399. contentDiv.style.cursor = 'copy';
  3400. graph.panningManager.stop();
  3401. graph.autoScroll = false;
  3402. if (graph.graphHandler.guide != null)
  3403. {
  3404. graph.graphHandler.guide.setVisible(false);
  3405. }
  3406. if (graph.graphHandler.hint != null)
  3407. {
  3408. graph.graphHandler.hint.style.visibility = 'hidden';
  3409. }
  3410. mxEvent.consume(evt);
  3411. }
  3412. }), mxUtils.bind(this, function(evt)
  3413. {
  3414. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler != null)
  3415. {
  3416. contentDiv.style.border = '3px solid transparent';
  3417. if (dropTarget != null)
  3418. {
  3419. dropTarget.style.border = '3px dotted lightGray';
  3420. }
  3421. contentDiv.style.cursor = 'default';
  3422. this.sidebar.showTooltips = true;
  3423. graph.panningManager.stop();
  3424. graph.graphHandler.reset();
  3425. graph.isMouseDown = false;
  3426. graph.autoScroll = true;
  3427. addSelection(evt);
  3428. mxEvent.consume(evt);
  3429. }
  3430. }));
  3431. // Handles mouse leaving the library and restoring move
  3432. mxEvent.addListener(contentDiv, 'mouseleave', mxUtils.bind(this, function(evt)
  3433. {
  3434. if (graph.isMouseDown && graph.graphHandler.shape != null)
  3435. {
  3436. graph.graphHandler.shape.node.style.visibility = 'visible';
  3437. contentDiv.style.border = '3px solid transparent';
  3438. contentDiv.style.cursor = '';
  3439. graph.autoScroll = true;
  3440. if (graph.graphHandler.guide != null)
  3441. {
  3442. graph.graphHandler.guide.setVisible(true);
  3443. }
  3444. if (graph.graphHandler.hint != null)
  3445. {
  3446. graph.graphHandler.hint.style.visibility = 'visible';
  3447. }
  3448. if (dropTarget != null)
  3449. {
  3450. dropTarget.style.border = '3px dotted lightGray';
  3451. }
  3452. }
  3453. }));
  3454. // Adds drop handler from filesystem
  3455. if (Graph.fileSupport)
  3456. {
  3457. mxEvent.addListener(contentDiv, 'dragover', mxUtils.bind(this, function(evt)
  3458. {
  3459. if (dropTarget != null)
  3460. {
  3461. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  3462. }
  3463. else
  3464. {
  3465. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  3466. }
  3467. evt.dataTransfer.dropEffect = 'copy';
  3468. contentDiv.style.cursor = 'copy';
  3469. this.sidebar.hideTooltip();
  3470. evt.stopPropagation();
  3471. evt.preventDefault();
  3472. }));
  3473. mxEvent.addListener(contentDiv, 'drop', mxUtils.bind(this, function(evt)
  3474. {
  3475. contentDiv.style.border = '3px solid transparent';
  3476. contentDiv.style.cursor = '';
  3477. if (dropTarget != null)
  3478. {
  3479. dropTarget.style.border = '3px dotted lightGray';
  3480. }
  3481. if (evt.dataTransfer.files.length > 0)
  3482. {
  3483. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, mxUtils.bind(this, function(data, mimeType, x, y, w, h, img)
  3484. {
  3485. if (data != null && mimeType.substring(0, 6) == 'image/')
  3486. {
  3487. var style = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;image=' +
  3488. this.convertDataUri(data);
  3489. var cells = [new mxCell('', new mxGeometry(0, 0, w, h), style)];
  3490. cells[0].vertex = true;
  3491. addCells(cells, new mxRectangle(0, 0, w, h), evt, (mxEvent.isAltDown(evt)) ? null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  3492. }
  3493. else
  3494. {
  3495. var done = false;
  3496. if (data != null && mimeType == 'text/xml')
  3497. {
  3498. var doc = mxUtils.parseXml(data);
  3499. if (doc.documentElement.nodeName == 'mxlibrary')
  3500. {
  3501. try
  3502. {
  3503. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  3504. addImages(temp, contentDiv);
  3505. images = images.concat(temp);
  3506. saveLibrary(evt);
  3507. this.spinner.stop();
  3508. done = true;
  3509. }
  3510. catch (e)
  3511. {
  3512. // ignore
  3513. }
  3514. }
  3515. else if (doc.documentElement.nodeName == 'mxfile')
  3516. {
  3517. try
  3518. {
  3519. var temp = mxUtils.getTextContent(doc.documentElement.getElementsByTagName('diagram')[0]);
  3520. var cells = this.stringToCells(this.editor.graph.decompress(temp));
  3521. addCells(cells, new mxRectangle(0, 0, w, h), evt);
  3522. done = true;
  3523. }
  3524. catch (e)
  3525. {
  3526. // ignore
  3527. }
  3528. }
  3529. }
  3530. if (!done)
  3531. {
  3532. this.spinner.stop();
  3533. this.handleError({message: mxResources.get('errorLoadingFile')})
  3534. }
  3535. }
  3536. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  3537. {
  3538. dropTarget.parentNode.removeChild(dropTarget);
  3539. dropTarget = null;
  3540. }
  3541. }));
  3542. }
  3543. evt.stopPropagation();
  3544. evt.preventDefault();
  3545. }));
  3546. mxEvent.addListener(contentDiv, 'dragleave', function(evt)
  3547. {
  3548. if (dropTarget != null)
  3549. {
  3550. dropTarget.style.border = '3px dotted lightGray';
  3551. }
  3552. else
  3553. {
  3554. contentDiv.style.border = '3px solid transparent';
  3555. contentDiv.style.cursor = '';
  3556. }
  3557. evt.stopPropagation();
  3558. evt.preventDefault();
  3559. });
  3560. }
  3561. btn = btn.cloneNode(false);
  3562. btn.setAttribute('src', IMAGE_PATH + '/edit.gif');
  3563. btn.setAttribute('title', mxResources.get('edit'));
  3564. buttons.insertBefore(btn, buttons.firstChild);
  3565. mxEvent.addListener(btn, 'click', editLibrary);
  3566. mxEvent.addListener(contentDiv, 'dblclick', function(evt)
  3567. {
  3568. if (mxEvent.getSource(evt) == contentDiv)
  3569. {
  3570. editLibrary(evt);
  3571. }
  3572. });
  3573. btn = btn.cloneNode(false);
  3574. btn.setAttribute('src', App.prototype.plusImage);
  3575. btn.setAttribute('title', mxResources.get('add'));
  3576. buttons.insertBefore(btn, buttons.firstChild);
  3577. if (!this.isOffline())
  3578. {
  3579. var link = document.createElement('span');
  3580. link.setAttribute('title', mxResources.get('help'));
  3581. link.style.cssText = 'color:gray;text-decoration:none;margin-right:8px;';
  3582. mxUtils.write(link, '?');
  3583. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  3584. {
  3585. window.open('https://support.draw.io/questions/10420280');
  3586. mxEvent.consume(evt);
  3587. }));
  3588. buttons.insertBefore(link, buttons.firstChild);
  3589. }
  3590. var spinBtn = null;
  3591. mxEvent.addListener(btn, 'click', addSelection);
  3592. }
  3593. title.appendChild(buttons);
  3594. };
  3595. /**
  3596. * Translates this point by the given vector.
  3597. *
  3598. * @param {number} dx X-coordinate of the translation.
  3599. * @param {number} dy Y-coordinate of the translation.
  3600. */
  3601. App.prototype.fileLoaded = function(file)
  3602. {
  3603. this.hideDialog();
  3604. var oldFile = this.getCurrentFile();
  3605. this.setCurrentFile(null);
  3606. if (oldFile != null)
  3607. {
  3608. oldFile.removeListener(this.descriptorChangedListener);
  3609. oldFile.close();
  3610. }
  3611. this.editor.graph.model.clear();
  3612. this.editor.undoManager.clear();
  3613. var noFile = mxUtils.bind(this, function()
  3614. {
  3615. this.diagramContainer.style.visibility = 'hidden';
  3616. this.formatContainer.style.visibility = 'hidden';
  3617. this.hsplit.style.display = 'none';
  3618. this.sidebarContainer.style.display = 'none';
  3619. this.sidebarFooterContainer.style.display = 'none';
  3620. this.editor.graph.setEnabled(false);
  3621. // Keeps initial title if no file existed before
  3622. if (oldFile != null)
  3623. {
  3624. this.updateDocumentTitle();
  3625. }
  3626. // File might have been loaded halfway
  3627. this.editor.graph.model.clear();
  3628. this.editor.undoManager.clear();
  3629. // Avoids empty hash with no value
  3630. if (window.location.hash != null && window.location.hash.length > 0)
  3631. {
  3632. window.location.hash = '';
  3633. }
  3634. if (this.fname != null)
  3635. {
  3636. this.fnameWrapper.style.display = 'none';
  3637. this.fname.innerHTML = '';
  3638. this.fname.setAttribute('title', mxResources.get('rename'));
  3639. }
  3640. this.updateUi();
  3641. this.showSplash();
  3642. });
  3643. if (file != null)
  3644. {
  3645. try
  3646. {
  3647. // Order is significant, current file needed for correct
  3648. // file format for initial save after starting realtime
  3649. this.setCurrentFile(file);
  3650. file.addListener('descriptorChanged', this.descriptorChangedListener);
  3651. file.addListener('contentChanged', this.descriptorChangedListener);
  3652. this.setMode(file.getMode());
  3653. this.descriptorChanged();
  3654. file.open();
  3655. this.diagramContainer.style.visibility = '';
  3656. this.formatContainer.style.visibility = '';
  3657. this.hsplit.style.display = '';
  3658. this.sidebarContainer.style.display = '';
  3659. this.sidebarFooterContainer.style.display = '';
  3660. this.editor.undoManager.clear();
  3661. this.updateUi();
  3662. // Realtime files have a valid status message
  3663. if (file.realtime == null)
  3664. {
  3665. if (!file.isEditable())
  3666. {
  3667. this.editor.setStatus(mxResources.get('readOnly'));
  3668. }
  3669. else
  3670. {
  3671. this.editor.setStatus('');
  3672. }
  3673. }
  3674. if (!this.editor.chromeless)
  3675. {
  3676. this.showLayersDialog();
  3677. this.restoreLibraries();
  3678. }
  3679. else if (this.editor.graph.lightbox)
  3680. {
  3681. this.lightboxFit();
  3682. }
  3683. if (this.chromelessResize)
  3684. {
  3685. this.chromelessResize();
  3686. }
  3687. this.editor.fireEvent(new mxEventObject('fileLoaded'));
  3688. // if (this.enableLogging)
  3689. // {
  3690. // try
  3691. // {
  3692. // if (!this.isOffline())
  3693. // {
  3694. // var img = new Image();
  3695. // img.src = 'https://log.draw.io/log?msg=storageMode:' + encodeURIComponent(file.getMode()) +
  3696. // '&v=' + encodeURIComponent(EditorUi.VERSION);
  3697. // }
  3698. // }
  3699. // catch (e)
  3700. // {
  3701. // // ignore
  3702. // }
  3703. // }
  3704. if (this.mode == file.getMode() && file.getMode() != App.MODE_DEVICE)
  3705. {
  3706. try
  3707. {
  3708. this.addRecent({id: file.getHash(), title: file.getTitle(), mode: file.getMode()});
  3709. }
  3710. catch (e)
  3711. {
  3712. // ignore
  3713. }
  3714. }
  3715. }
  3716. catch (e)
  3717. {
  3718. // Makes sure the file does not save the invalid UI model and overwrites anything important
  3719. if (window.console != null)
  3720. {
  3721. console.log('error in fileLoaded:', file, e);
  3722. }
  3723. // Asynchronous handling of errors
  3724. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3725. {
  3726. // Removes URL parameter and reloads the page
  3727. if (urlParams['url'] != null && this.spinner.spin(document.body, mxResources.get('reconnecting')))
  3728. {
  3729. window.location.search = this.getSearch(['url']);
  3730. }
  3731. else if (oldFile != null)
  3732. {
  3733. this.fileLoaded(oldFile);
  3734. }
  3735. else
  3736. {
  3737. noFile();
  3738. }
  3739. }));
  3740. }
  3741. }
  3742. else
  3743. {
  3744. noFile();
  3745. }
  3746. };
  3747. /**
  3748. * Updates action states depending on the selection.
  3749. */
  3750. App.prototype.restoreLibraries = function()
  3751. {
  3752. if (this.sidebar != null)
  3753. {
  3754. if (this.pendingLibraries == null)
  3755. {
  3756. this.pendingLibraries = new Object();
  3757. }
  3758. // Ignores this library next time
  3759. var ignore = mxUtils.bind(this, function(id)
  3760. {
  3761. mxSettings.removeCustomLibrary(id);
  3762. delete this.pendingLibraries[id];
  3763. });
  3764. var load = mxUtils.bind(this, function(libs)
  3765. {
  3766. if (libs != null)
  3767. {
  3768. for (var i = 0; i < libs.length; i++)
  3769. {
  3770. var name = encodeURIComponent(decodeURIComponent(libs[i]));
  3771. (mxUtils.bind(this, function(id)
  3772. {
  3773. if (this.pendingLibraries[id] == null && this.sidebar.palettes[id] == null)
  3774. {
  3775. this.pendingLibraries[id] = true;
  3776. var service = id.substring(0, 1);
  3777. if (service == 'L')
  3778. {
  3779. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3780. {
  3781. try
  3782. {
  3783. var name = decodeURIComponent(id.substring(1));
  3784. var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
  3785. {
  3786. if (name == '.scratchpad' && xml == null)
  3787. {
  3788. xml = this.emptyLibraryXml;
  3789. }
  3790. if (xml != null)
  3791. {
  3792. this.loadLibrary(new StorageLibrary(this, xml, name));
  3793. }
  3794. else
  3795. {
  3796. ignore(id);
  3797. }
  3798. }));
  3799. }
  3800. catch (e)
  3801. {
  3802. ignore(id);
  3803. }
  3804. }
  3805. }
  3806. else if (service == 'U')
  3807. {
  3808. var url = decodeURIComponent(id.substring(1));
  3809. if (!this.isOffline())
  3810. {
  3811. // Uses proxy to avoid CORS issues
  3812. mxUtils.get(PROXY_URL + '?url=' + encodeURIComponent(url), mxUtils.bind(this, function(req)
  3813. {
  3814. if (req.getStatus() == 200)
  3815. {
  3816. try
  3817. {
  3818. this.loadLibrary(new UrlLibrary(this, req.getText(), url));
  3819. delete this.pendingLibraries[id];
  3820. }
  3821. catch (e)
  3822. {
  3823. ignore(id);
  3824. }
  3825. }
  3826. else
  3827. {
  3828. ignore(id);
  3829. }
  3830. }), function()
  3831. {
  3832. ignore(id);
  3833. });
  3834. }
  3835. }
  3836. else
  3837. {
  3838. var peer = null;
  3839. if (service == 'G')
  3840. {
  3841. if (this.drive != null && this.drive.user != null)
  3842. {
  3843. peer = this.drive;
  3844. }
  3845. }
  3846. else if (service == 'D')
  3847. {
  3848. if (this.dropbox != null && this.dropbox.getUser() != null)
  3849. {
  3850. peer = this.dropbox;
  3851. }
  3852. }
  3853. else if (service == 'W')
  3854. {
  3855. if (this.oneDrive != null && this.oneDrive.getUser() != null)
  3856. {
  3857. peer = this.oneDrive;
  3858. }
  3859. }
  3860. if (peer != null)
  3861. {
  3862. peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
  3863. {
  3864. try
  3865. {
  3866. this.loadLibrary(file);
  3867. delete this.pendingLibraries[id];
  3868. }
  3869. catch (e)
  3870. {
  3871. ignore(id);
  3872. }
  3873. }), function(resp)
  3874. {
  3875. ignore(id);
  3876. });
  3877. }
  3878. }
  3879. }
  3880. }))(name);
  3881. }
  3882. }
  3883. });
  3884. load(mxSettings.getCustomLibraries());
  3885. load((urlParams['clibs'] || '').split(';'));
  3886. }
  3887. };
  3888. /**
  3889. * Updates action and menu states depending on the file.
  3890. */
  3891. App.prototype.updateUi = function()
  3892. {
  3893. this.updateButtonContainer();
  3894. this.updateActionStates();
  3895. // Action states that only need update for new files
  3896. var file = this.getCurrentFile();
  3897. var active = file != null || urlParams['embed'] == '1';
  3898. this.menus.get('viewPanels').setEnabled(active);
  3899. this.menus.get('viewZoom').setEnabled(active);
  3900. var restricted = urlParams['embed'] != '1' && (file == null || file.isRestricted());
  3901. this.actions.get('makeCopy').setEnabled(!restricted);
  3902. this.actions.get('print').setEnabled(!restricted);
  3903. this.menus.get('exportAs').setEnabled(!restricted);
  3904. this.menus.get('embed').setEnabled(!restricted);
  3905. // Disables actions in the toolbar
  3906. var editable = (urlParams['embed'] == '1') || (file != null && file.isEditable());
  3907. this.actions.get('image').setEnabled(active);
  3908. this.actions.get('zoomIn').setEnabled(active);
  3909. this.actions.get('zoomOut').setEnabled(active);
  3910. this.actions.get('resetView').setEnabled(active);
  3911. // Disables menus
  3912. this.menus.get('edit').setEnabled(active);
  3913. this.menus.get('view').setEnabled(active);
  3914. this.menus.get('importFrom').setEnabled(editable);
  3915. this.menus.get('arrange').setEnabled(editable);
  3916. // Disables connection drop downs in toolbar
  3917. if (this.toolbar != null)
  3918. {
  3919. if (this.toolbar.edgeShapeMenu != null)
  3920. {
  3921. this.toolbar.edgeShapeMenu.setEnabled(editable);
  3922. }
  3923. if (this.toolbar.edgeStyleMenu != null)
  3924. {
  3925. this.toolbar.edgeStyleMenu.setEnabled(editable);
  3926. }
  3927. }
  3928. if (this.isOfflineApp())
  3929. {
  3930. // In FF, IE and Safari (desktop) the cache status never changes
  3931. if ((mxClient.IS_GC || (mxClient.IS_IOS && mxClient.IS_SF)) && applicationCache != null)
  3932. {
  3933. var appCache = applicationCache;
  3934. if (this.offlineStatus == null)
  3935. {
  3936. this.offlineStatus = document.createElement('div');
  3937. this.offlineStatus.className = 'geItem';
  3938. this.offlineStatus.style.position = 'absolute';
  3939. this.offlineStatus.style.fontSize = '8pt';
  3940. this.offlineStatus.style.top = '2px';
  3941. this.offlineStatus.style.right = '12px';
  3942. this.offlineStatus.style.color = '#666';
  3943. this.offlineStatus.style.margin = '4px';
  3944. this.offlineStatus.style.padding = '2px';
  3945. this.offlineStatus.style.verticalAlign = 'middle';
  3946. this.offlineStatus.innerHTML = '';
  3947. this.menubarContainer.appendChild(this.offlineStatus);
  3948. // Events are not working, use polling instead (10 secs interval)
  3949. var thread = window.setTimeout(mxUtils.bind(this, function()
  3950. {
  3951. if (appCache.status == appCache.IDLE)
  3952. {
  3953. this.offlineStatus.innerHTML = '[' + '<img title="Cached" border="0" src="' + IMAGE_PATH + '/checkmark.gif"/>]';
  3954. window.clearTimeout(thread);
  3955. }
  3956. }), 5000);
  3957. }
  3958. }
  3959. }
  3960. else
  3961. {
  3962. this.updateUserElement();
  3963. }
  3964. };
  3965. /**
  3966. *
  3967. */
  3968. App.prototype.exportImage = function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  3969. {
  3970. if (this.spinner.spin(document.body, mxResources.get('exporting')))
  3971. {
  3972. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  3973. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  3974. try
  3975. {
  3976. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  3977. {
  3978. this.spinner.stop();
  3979. try
  3980. {
  3981. // TODO: Should call App.getFileData here
  3982. this.saveCanvas(canvas, (editable) ? this.getFileData(true, null, null, null, ignoreSelection) : null);
  3983. }
  3984. catch (e)
  3985. {
  3986. // Fallback to server-side image export
  3987. if (e.message == 'Invalid image')
  3988. {
  3989. this.downloadFile('png');
  3990. }
  3991. else
  3992. {
  3993. this.handleError(e);
  3994. }
  3995. }
  3996. }), null, null, null, mxUtils.bind(this, function(e)
  3997. {
  3998. this.spinner.stop();
  3999. this.handleError(e);
  4000. }), null, ignoreSelection, scale || 1, transparentBackground, addShadow);
  4001. }
  4002. catch (e)
  4003. {
  4004. this.spinner.stop();
  4005. this.handleError(e);
  4006. }
  4007. }
  4008. };
  4009. /**
  4010. *
  4011. */
  4012. EditorUi.prototype.exportSvg = function(scale, transparentBackground, ignoreSelection, addShadow, editable, embedImages)
  4013. {
  4014. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  4015. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  4016. var bg = (transparentBackground) ? null : this.editor.graph.background;
  4017. if (bg == mxConstants.NONE)
  4018. {
  4019. bg = null;
  4020. }
  4021. // Handles special case where background is null but transparent is false
  4022. if (bg == null && transparentBackground == false)
  4023. {
  4024. bg = '#ffffff';
  4025. }
  4026. // Sets or disables alternate text for foreignObjects. Disabling is needed
  4027. // because PhantomJS seems to ignore switch statements and paint all text.
  4028. var svgRoot = this.editor.graph.getSvg(bg, scale, null, null, null, ignoreSelection);
  4029. if (addShadow)
  4030. {
  4031. this.editor.addSvgShadow(svgRoot);
  4032. }
  4033. var file = this.getCurrentFile();
  4034. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4035. var dot = filename.lastIndexOf('.');
  4036. if (dot > 0)
  4037. {
  4038. filename = filename.substring(0, dot);
  4039. }
  4040. filename += '.svg';
  4041. if (this.spinner.spin(document.body, mxResources.get('export')))
  4042. {
  4043. var doSave = mxUtils.bind(this, function(svgRoot)
  4044. {
  4045. this.spinner.stop();
  4046. if (editable)
  4047. {
  4048. svgRoot.setAttribute('content', this.getFileData(true, null, null, null, ignoreSelection));
  4049. }
  4050. var svg = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  4051. mxUtils.getXml(svgRoot);
  4052. // TODO: Depends on App
  4053. if (this.isLocalFileSave() || svg.length <= MAX_REQUEST_SIZE)
  4054. {
  4055. this.saveData(filename, 'svg', svg, 'image/svg+xml');
  4056. }
  4057. else
  4058. {
  4059. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  4060. {
  4061. mxUtils.popup(svg);
  4062. }));
  4063. }
  4064. });
  4065. this.convertMath(this.editor.graph, svgRoot, false, mxUtils.bind(this, function()
  4066. {
  4067. if (embedImages)
  4068. {
  4069. this.convertImages(svgRoot, doSave);
  4070. }
  4071. else
  4072. {
  4073. doSave(svgRoot);
  4074. }
  4075. }));
  4076. }
  4077. };
  4078. /**
  4079. * Translates this point by the given vector.
  4080. *
  4081. * @param {number} dx X-coordinate of the translation.
  4082. * @param {number} dy Y-coordinate of the translation.
  4083. */
  4084. App.prototype.updateButtonContainer = function()
  4085. {
  4086. if (this.buttonContainer != null)
  4087. {
  4088. var file = this.getCurrentFile();
  4089. if (file != null && file.constructor == DriveFile)
  4090. {
  4091. // Adds Share button
  4092. if (this.shareButton == null)
  4093. {
  4094. this.shareButton = document.createElement('div');
  4095. this.shareButton.className = 'geBtn gePrimaryBtn';
  4096. this.shareButton.style.display = 'inline-block';
  4097. this.shareButton.style.padding = '0 10px 0 10px';
  4098. this.shareButton.style.marginTop = '-4px';
  4099. this.shareButton.style.height = '28px';
  4100. this.shareButton.style.lineHeight = '28px';
  4101. this.shareButton.style.minWidth = '0px';
  4102. this.shareButton.style.cssFloat = 'right';
  4103. var icon = document.createElement('img');
  4104. icon.setAttribute('src', this.shareImage);
  4105. icon.setAttribute('align', 'absmiddle');
  4106. icon.style.marginRight = '4px';
  4107. icon.style.marginTop = '-3px';
  4108. this.shareButton.appendChild(icon);
  4109. mxUtils.write(this.shareButton, mxResources.get('share'));
  4110. mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
  4111. {
  4112. this.actions.get('share').funct();
  4113. }));
  4114. this.buttonContainer.appendChild(this.shareButton);
  4115. }
  4116. }
  4117. else if (this.shareButton != null)
  4118. {
  4119. this.shareButton.parentNode.removeChild(this.shareButton);
  4120. this.shareButton = null;
  4121. }
  4122. }
  4123. };
  4124. /**
  4125. * Translates this point by the given vector.
  4126. *
  4127. * @param {number} dx X-coordinate of the translation.
  4128. * @param {number} dy Y-coordinate of the translation.
  4129. */
  4130. App.prototype.save = function(name, done)
  4131. {
  4132. var file = this.getCurrentFile();
  4133. var msg = mxResources.get('saving');
  4134. if (file != null && file.constructor == DriveFile)
  4135. {
  4136. msg = mxResources.get('createRevision');
  4137. }
  4138. if (file != null && this.spinner.spin(document.body, msg))
  4139. {
  4140. this.editor.setStatus('');
  4141. if (this.editor.graph.isEditing())
  4142. {
  4143. this.editor.graph.stopEditing();
  4144. }
  4145. var success = mxUtils.bind(this, function(resp)
  4146. {
  4147. this.spinner.stop();
  4148. if (this.getCurrentFile() == file)
  4149. {
  4150. if (file.isModified())
  4151. {
  4152. if (!file.isAutosave())
  4153. {
  4154. file.addUnsavedStatus();
  4155. }
  4156. }
  4157. else
  4158. {
  4159. this.editor.setStatus(mxResources.get('allChangesSaved'));
  4160. }
  4161. }
  4162. if (done != null)
  4163. {
  4164. done();
  4165. }
  4166. });
  4167. var error = mxUtils.bind(this, function(resp)
  4168. {
  4169. // Spinner is paused and resumed in handleError
  4170. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  4171. });
  4172. if (name == file.getTitle())
  4173. {
  4174. file.save(true, success, error);
  4175. }
  4176. else
  4177. {
  4178. file.saveAs(name, success, error)
  4179. }
  4180. }
  4181. };
  4182. /**
  4183. * Translates this point by the given vector.
  4184. *
  4185. * @param {number} dx X-coordinate of the translation.
  4186. * @param {number} dy Y-coordinate of the translation.
  4187. */
  4188. App.prototype.base64ToBlob = function(base64Data, contentType)
  4189. {
  4190. contentType = contentType || '';
  4191. var sliceSize = 1024;
  4192. var byteCharacters = atob(base64Data);
  4193. var bytesLength = byteCharacters.length;
  4194. var slicesCount = Math.ceil(bytesLength / sliceSize);
  4195. var byteArrays = new Array(slicesCount);
  4196. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex)
  4197. {
  4198. var begin = sliceIndex * sliceSize;
  4199. var end = Math.min(begin + sliceSize, bytesLength);
  4200. var bytes = new Array(end - begin);
  4201. for (var offset = begin, i = 0 ; offset < end; ++i, ++offset)
  4202. {
  4203. bytes[i] = byteCharacters[offset].charCodeAt(0);
  4204. }
  4205. byteArrays[sliceIndex] = new Uint8Array(bytes);
  4206. }
  4207. return new Blob(byteArrays, {type: contentType});
  4208. };
  4209. /**
  4210. * Returns true if files should be saved using <saveLocalFile>.
  4211. */
  4212. App.prototype.isLocalFileSave = function()
  4213. {
  4214. return (urlParams['save'] != 'remote' && (mxClient.IS_IE ||
  4215. (typeof window.Blob !== 'undefined' && typeof window.URL !== 'undefined')) &&
  4216. document.documentMode != 9 && document.documentMode != 8 &&
  4217. document.documentMode != 7 && !mxClient.IS_QUIRKS) ||
  4218. this.isOfflineApp() || mxClient.IS_IOS;
  4219. };
  4220. /**
  4221. * Translates this point by the given vector.
  4222. *
  4223. * @param {number} dx X-coordinate of the translation.
  4224. * @param {number} dy Y-coordinate of the translation.
  4225. */
  4226. App.prototype.saveRequest = function(data, filename, format, fn)
  4227. {
  4228. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  4229. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  4230. {
  4231. if (mode == '_blank' || newTitle != null && newTitle.length > 0)
  4232. {
  4233. var base64 = (mode == App.MODE_DEVICE || mode == null || mode == '_blank') ? '0' : '1';
  4234. var xhr = fn((mode == '_blank') ? null : newTitle, base64);
  4235. if (mode == App.MODE_DEVICE || mode == '_blank')
  4236. {
  4237. xhr.simulate(document, '_blank');
  4238. }
  4239. else
  4240. {
  4241. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  4242. {
  4243. if (this.spinner.spin(document.body, mxResources.get('saving')))
  4244. {
  4245. // LATER: Catch possible mixed content error
  4246. // see http://stackoverflow.com/questions/30646417/catching-mixed-content-error
  4247. xhr.send(mxUtils.bind(this, function()
  4248. {
  4249. this.spinner.stop();
  4250. if (xhr.getStatus() < 200 || xhr.getStatus() > 299)
  4251. {
  4252. this.handleError({message: mxResources.get('errorSavingFile')});
  4253. }
  4254. else
  4255. {
  4256. try
  4257. {
  4258. var mimeType = (format == 'pdf') ? 'application/pdf' : 'image/' + format;
  4259. this.exportFile(xhr.getText(), newTitle, mimeType, true, mode, folderId);
  4260. }
  4261. catch (e)
  4262. {
  4263. this.handleError(e);
  4264. }
  4265. }
  4266. }), function(resp)
  4267. {
  4268. this.spinner.stop();
  4269. this.handleError(resp);
  4270. });
  4271. }
  4272. }));
  4273. }
  4274. }
  4275. }), mxUtils.bind(this, function()
  4276. {
  4277. this.hideDialog();
  4278. }), mxResources.get('saveAs'), mxResources.get('download'), false, false, allowTab);
  4279. this.showDialog(dlg.container, 380, 270, true, true);
  4280. dlg.init();
  4281. };
  4282. /**
  4283. * Invokes callback with null if mode does not support folder or not null
  4284. * if a valid folder was chosen for a mode that supports it. No callback
  4285. * is made if no folder was chosen for a mode that supports it.
  4286. */
  4287. App.prototype.pickFolder = function(mode, fn, enabled)
  4288. {
  4289. enabled = (enabled != null) ? enabled : true;
  4290. if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
  4291. {
  4292. // Shows a save dialog
  4293. this.drive.pickFolder(mxUtils.bind(this, function(evt)
  4294. {
  4295. if (evt.action == google.picker.Action.PICKED)
  4296. {
  4297. var folderId = null;
  4298. if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
  4299. {
  4300. folderId = evt.docs[0].id;
  4301. }
  4302. fn(folderId);
  4303. }
  4304. }));
  4305. }
  4306. else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  4307. {
  4308. this.oneDrive.pickFolder(mxUtils.bind(this, function(evt)
  4309. {
  4310. var folderId = null;
  4311. if (evt != null && evt.data != null && evt.data.folders != null &&
  4312. evt.data.folders.length > 0)
  4313. {
  4314. folderId = evt.data.folders[0].id;
  4315. folderId = folderId.substring(folderId.lastIndexOf('.') + 1);
  4316. fn(folderId);
  4317. }
  4318. }));
  4319. }
  4320. else
  4321. {
  4322. fn(null);
  4323. }
  4324. };
  4325. /**
  4326. *
  4327. */
  4328. App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  4329. {
  4330. if (mode == App.MODE_DROPBOX)
  4331. {
  4332. if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4333. {
  4334. // LATER: Add folder picker
  4335. this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4336. data, mxUtils.bind(this, function()
  4337. {
  4338. this.spinner.stop();
  4339. }), mxUtils.bind(this, function(resp)
  4340. {
  4341. this.spinner.stop();
  4342. this.handleError(resp);
  4343. }));
  4344. }
  4345. }
  4346. else if (mode == App.MODE_GOOGLE)
  4347. {
  4348. if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4349. {
  4350. this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
  4351. {
  4352. // TODO: Add callback with url param for clickable status message
  4353. // "File exported. Click here to open folder."
  4354. // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
  4355. // mxResources.get('saved') + '</div>');
  4356. //
  4357. // // Installs click handler for opening
  4358. // if (this.statusContainer != null)
  4359. // {
  4360. // var links = this.statusContainer.getElementsByTagName('div');
  4361. //
  4362. // if (links.length > 0)
  4363. // {
  4364. // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
  4365. // {
  4366. // if (resp != null && resp.parents != null && resp.parents.length > 0)
  4367. // {
  4368. // var id = resp.parents[0].id;
  4369. //
  4370. // if (id != null)
  4371. // {
  4372. // window.open('https://drive.google.com/drive/folders/' + id);
  4373. // }
  4374. // }
  4375. // }));
  4376. // }
  4377. // }
  4378. this.spinner.stop();
  4379. }), mxUtils.bind(this, function(resp)
  4380. {
  4381. this.spinner.stop();
  4382. this.handleError(resp);
  4383. }), mimeType, base64Encoded, false);
  4384. }
  4385. }
  4386. else if (mode == App.MODE_ONEDRIVE)
  4387. {
  4388. if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4389. {
  4390. // KNOWN: OneDrive does not show .svg extension
  4391. this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4392. data, mxUtils.bind(this, function()
  4393. {
  4394. this.spinner.stop();
  4395. }), mxUtils.bind(this, function(resp)
  4396. {
  4397. this.spinner.stop();
  4398. this.handleError(resp);
  4399. }), false, folderId);
  4400. }
  4401. }
  4402. };
  4403. /**
  4404. * Translates this point by the given vector.
  4405. *
  4406. * @param {number} dx X-coordinate of the translation.
  4407. * @param {number} dy Y-coordinate of the translation.
  4408. */
  4409. App.prototype.doSaveLocalFile = function(data, filename, mimeType, base64Encoded)
  4410. {
  4411. // Newer versions of IE
  4412. if (window.MSBlobBuilder && navigator.msSaveOrOpenBlob)
  4413. {
  4414. var builder = new MSBlobBuilder();
  4415. builder.append(data);
  4416. var blob = builder.getBlob(mimeType);
  4417. navigator.msSaveOrOpenBlob(blob, filename);
  4418. }
  4419. // Older versions of IE (binary not supported)
  4420. else if (mxClient.IS_IE)
  4421. {
  4422. var win = window.open('about:blank', '_blank');
  4423. if (win == null)
  4424. {
  4425. mxUtils.popup(data, true);
  4426. }
  4427. else
  4428. {
  4429. win.document.write(data);
  4430. win.document.close();
  4431. win.document.execCommand('SaveAs', true, filename);
  4432. win.close();
  4433. }
  4434. }
  4435. else if (mxClient.IS_IOS)
  4436. {
  4437. // Poor man's saveAs in iOS via context menu of selected output
  4438. var dlg = new TextareaDialog(this, filename + ':', data, null, null, mxResources.get('close'));
  4439. dlg.textarea.style.width = '600px';
  4440. dlg.textarea.style.height = '380px';
  4441. this.showDialog(dlg.container, 620, 460, true, true);
  4442. dlg.init();
  4443. document.execCommand('selectall', false, null);
  4444. }
  4445. else if (!this.isOffline() && mxClient.IS_SF)
  4446. {
  4447. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4448. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4449. new mxXmlRequest(SAVE_URL, 'mime=' + mimeType + '&filename=' +
  4450. encodeURIComponent(filename) +
  4451. param).simulate(document, '_blank');
  4452. }
  4453. else
  4454. {
  4455. var a = document.createElement('a');
  4456. a.href = URL.createObjectURL((base64Encoded) ?
  4457. this.base64ToBlob(data, mimeType) :
  4458. new Blob([data], {type: mimeType}));
  4459. a.download = filename;
  4460. document.body.appendChild(a);
  4461. // Workaround for link opens in same window in Safari
  4462. if (mxClient.IS_SF)
  4463. {
  4464. a.setAttribute('target', '_blank');
  4465. }
  4466. try
  4467. {
  4468. a.click();
  4469. window.setTimeout(function()
  4470. {
  4471. URL.revokeObjectURL(a.href);
  4472. }, 0);
  4473. a.parentNode.removeChild(a);
  4474. }
  4475. catch (e)
  4476. {
  4477. // ignore
  4478. }
  4479. }
  4480. };
  4481. /**
  4482. * Translates this point by the given vector.
  4483. *
  4484. * @param {number} dx X-coordinate of the translation.
  4485. * @param {number} dy Y-coordinate of the translation.
  4486. */
  4487. App.prototype.saveLocalFile = function(data, filename, mimeType, base64Encoded)
  4488. {
  4489. if (this.isOfflineApp() || this.isOffline())
  4490. {
  4491. this.doSaveLocalFile(data, filename, mimeType, base64Encoded);
  4492. }
  4493. else
  4494. {
  4495. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  4496. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  4497. {
  4498. try
  4499. {
  4500. // Opens a new window
  4501. if (mode == '_blank')
  4502. {
  4503. // Workaround for "Access denied" after URL.createObjectURL
  4504. // and blank window for window.open with data URI in MS Edge
  4505. // and empty window for IE 11 and 10
  4506. if (mxClient.IS_EDGE || document.documentMode == 11 || document.documentMode == 10)
  4507. {
  4508. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4509. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4510. new mxXmlRequest(SAVE_URL, 'mime=' + mimeType + param).simulate(document, '_blank');
  4511. }
  4512. else
  4513. {
  4514. // Cannot use URL.createObjectURL since it kills gradients in FF
  4515. window.open('data:' + mimeType + ((base64Encoded) ? ';base64,' +
  4516. data : ';charset=utf8,' + encodeURIComponent(data)));
  4517. }
  4518. }
  4519. else if (mode == App.MODE_DEVICE)
  4520. {
  4521. this.doSaveLocalFile(data, newTitle, mimeType, base64Encoded);
  4522. }
  4523. else if (newTitle != null && newTitle.length > 0)
  4524. {
  4525. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  4526. {
  4527. this.exportFile(data, newTitle, mimeType, base64Encoded, mode, folderId);
  4528. }));
  4529. }
  4530. }
  4531. catch (e)
  4532. {
  4533. this.handleError(e);
  4534. }
  4535. }), mxUtils.bind(this, function()
  4536. {
  4537. this.hideDialog();
  4538. }), mxResources.get('saveAs'), mxResources.get('download'), false, false, allowTab);
  4539. this.showDialog(dlg.container, 380, 280, true, true);
  4540. dlg.init();
  4541. }
  4542. };
  4543. /**
  4544. *
  4545. */
  4546. App.prototype.getHtml = function(node, graph, title, editLink, redirect, ignoreSelection)
  4547. {
  4548. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  4549. var bg = null;
  4550. var js = 'https://www.draw.io/js/embed-static.min.js';
  4551. var s = '';
  4552. // LATER: Merge common code with EmbedDialog
  4553. if (graph != null)
  4554. {
  4555. var bounds = (ignoreSelection) ? graph.getGraphBounds() : graph.getBoundingBox(graph.getSelectionCells());
  4556. var scale = graph.view.scale;
  4557. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  4558. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  4559. bg = graph.background;
  4560. // Embed script only used if no redirect
  4561. if (redirect == null)
  4562. {
  4563. var stencilNames = new Object();
  4564. var states = this.editor.graph.view.states.getValues();
  4565. // Scans shapes for stencils
  4566. for (var i = 0; i < states.length; i++)
  4567. {
  4568. var state = states[i];
  4569. var shape = state.style[mxConstants.STYLE_SHAPE];
  4570. var base = mxStencilRegistry.getBasenameForStencil(shape);
  4571. if (base != null)
  4572. {
  4573. if (stencilNames[base] == null)
  4574. {
  4575. stencilNames[base] = true;
  4576. s += base + ';';
  4577. }
  4578. }
  4579. }
  4580. if (s.length > 0)
  4581. {
  4582. js = 'https://www.draw.io/embed.js?s=' + s.substring(0, s.length - 1);
  4583. }
  4584. }
  4585. // Adds embed attributes
  4586. node.setAttribute('x0', x0);
  4587. node.setAttribute('y0', y0);
  4588. }
  4589. if (node != null)
  4590. {
  4591. node.setAttribute('pan', '1');
  4592. node.setAttribute('zoom', '1');
  4593. node.setAttribute('resize', '0');
  4594. node.setAttribute('fit', '0');
  4595. node.setAttribute('border', '20');
  4596. // Hidden attributes
  4597. node.setAttribute('links', '1');
  4598. if (editLink != null)
  4599. {
  4600. node.setAttribute('edit', editLink);
  4601. }
  4602. }
  4603. // Makes XHTML compatible
  4604. if (redirect != null)
  4605. {
  4606. redirect = redirect.replace(/&/g, '&amp;');
  4607. }
  4608. // Removes control chars in input for correct roundtrip check
  4609. var text = (node != null) ? this.editor.graph.zapGremlins(mxUtils.getXml(node)) : '';
  4610. // Double compression for mxfile not fixed since it may cause imcompatibilites with
  4611. // embed clients that rely on this format. HTML files and export use getHtml2.
  4612. var data = this.editor.graph.compress(text);
  4613. // Fallback to URI encoded XML for invalid compression
  4614. if (this.editor.graph.decompress(data) != text)
  4615. {
  4616. data = encodeURIComponent(text);
  4617. }
  4618. var style = 'position:relative;overflow:auto;width:100%;';
  4619. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  4620. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  4621. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  4622. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  4623. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  4624. '</head>\n<body' +
  4625. (((redirect == null && bg != null && bg != mxConstants.NONE) ? ' style="background-color:' + bg + ';">' : '>')) +
  4626. '\n<div class="mxgraph" style="' + style + '">\n' +
  4627. '<div style="width:1px;height:1px;overflow:hidden;">' + data + '</div>\n</div>\n' +
  4628. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  4629. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  4630. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  4631. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  4632. '\n</body>\n</html>\n';
  4633. };
  4634. /**
  4635. * Same as above but using the new embed code.
  4636. */
  4637. App.prototype.getHtml2 = function(node, graph, title, editLink, redirect, ignoreSelection)
  4638. {
  4639. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  4640. var bg = null;
  4641. var js = 'https://www.draw.io/js/viewer.min.js';
  4642. var s = '';
  4643. // LATER: Merge common code with EmbedDialog
  4644. if (graph != null)
  4645. {
  4646. // Embed script only used if no redirect
  4647. if (redirect == null)
  4648. {
  4649. var s = [];
  4650. // Scans shapes for stencils
  4651. var stencilNames = new Object();
  4652. var states = graph.view.states.getValues();
  4653. function addName(name)
  4654. {
  4655. if (name != null)
  4656. {
  4657. var dot = name.lastIndexOf('.');
  4658. if (dot > 0)
  4659. {
  4660. name = name.substring(dot + 1, name.length);
  4661. }
  4662. if (stencilNames[name] == null)
  4663. {
  4664. stencilNames[name] = true;
  4665. s.push(name);
  4666. }
  4667. }
  4668. }
  4669. for (var i = 0; i < states.length; i++)
  4670. {
  4671. var state = states[i];
  4672. var shape = state.style[mxConstants.STYLE_SHAPE];
  4673. addName(mxStencilRegistry.getBasenameForStencil(shape));
  4674. // Adds package names for markers in edges
  4675. if (state.view.graph.model.isEdge(state.cell))
  4676. {
  4677. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_STARTARROW]));
  4678. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_ENDARROW]));
  4679. }
  4680. }
  4681. if (s.length > 0)
  4682. {
  4683. js = 'https://www.draw.io/embed2.js?s=' + s.join(';');
  4684. }
  4685. }
  4686. }
  4687. // Makes XHTML compatible
  4688. if (redirect != null)
  4689. {
  4690. redirect = redirect.replace(/&/g, '&amp;');
  4691. }
  4692. var data = {highlight: '#0000ff', nav: this.editor.graph.foldingEnabled, resize: true,
  4693. xml: this.editor.graph.zapGremlins(mxUtils.getXml(node)), toolbar: 'zoom layers lightbox'};
  4694. var style = 'max-width:100%;border:1px solid transparent;';
  4695. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  4696. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  4697. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  4698. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  4699. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  4700. '<meta charset="utf-8"/>\n</head>\n<body>' +
  4701. '\n<div class="mxgraph" style="' + style + '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>\n' +
  4702. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  4703. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  4704. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  4705. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  4706. '\n</body>\n</html>\n';
  4707. };
  4708. /**
  4709. * Translates this point by the given vector.
  4710. *
  4711. * @param {number} dx X-coordinate of the translation.
  4712. * @param {number} dy Y-coordinate of the translation.
  4713. */
  4714. App.prototype.saveData = function(filename, format, data, mime)
  4715. {
  4716. if (this.isLocalFileSave())
  4717. {
  4718. this.saveLocalFile(data, filename, mime);
  4719. }
  4720. else
  4721. {
  4722. this.saveRequest(data, filename, format, mxUtils.bind(this, function(newTitle, base64)
  4723. {
  4724. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4725. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4726. return new mxXmlRequest(SAVE_URL, 'format=' + format + ((newTitle != null) ?
  4727. '&filename=' + encodeURIComponent(newTitle) : '') + param);
  4728. }));
  4729. }
  4730. };
  4731. /**
  4732. * Translates this point by the given vector.
  4733. *
  4734. * @param {number} dx X-coordinate of the translation.
  4735. * @param {number} dy Y-coordinate of the translation.
  4736. */
  4737. App.prototype.downloadFile = function(format, nonCompressed, addShadow, ignoreSelection, currentPage)
  4738. {
  4739. try
  4740. {
  4741. var file = this.getCurrentFile();
  4742. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : this.editor.graph.isSelectionEmpty();
  4743. // LATER: Double URI encoding for needed for newlines in simulate (truncates body otherwise).
  4744. var basename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4745. if (/(\.xml)$/i.test(basename) || /(\.html)$/i.test(basename) || /(\.svg)$/i.test(basename))
  4746. {
  4747. basename = basename.substring(0, basename.lastIndexOf('.'));
  4748. }
  4749. var filename = basename + '.' + format;
  4750. if (format == 'xml')
  4751. {
  4752. var data = '<?xml version="1.0" encoding="UTF-8"?>\n' +
  4753. ((nonCompressed) ? mxUtils.getXml(this.editor.getGraphXml(ignoreSelection)) :
  4754. this.getFileData(true, null, null, null, ignoreSelection, currentPage));
  4755. this.saveData(filename, format, data, 'text/xml');
  4756. }
  4757. else if (format == 'html')
  4758. {
  4759. var data = this.getHtml2(this.editor.getGraphXml(ignoreSelection),
  4760. this.editor.graph, basename, null, null, ignoreSelection);
  4761. this.saveData(filename, format, data, 'text/html');
  4762. }
  4763. else if ((format == 'svg' || format == 'xmlsvg') && this.spinner.spin(document.body, mxResources.get('export')))
  4764. {
  4765. var svg = null;
  4766. var saveSvg = mxUtils.bind(this, function(data)
  4767. {
  4768. if (data.length <= MAX_REQUEST_SIZE)
  4769. {
  4770. this.saveData(filename, 'svg', data, 'image/svg+xml');
  4771. }
  4772. else
  4773. {
  4774. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  4775. {
  4776. mxUtils.popup(svg);
  4777. }));
  4778. }
  4779. });
  4780. if (format == 'svg')
  4781. {
  4782. var bg = this.editor.graph.background;
  4783. if (bg == mxConstants.NONE)
  4784. {
  4785. bg = null;
  4786. }
  4787. // Sets or disables alternate text for foreignObjects. Disabling is needed
  4788. // because PhantomJS seems to ignore switch statements and paint all text.
  4789. var svgRoot = this.editor.graph.getSvg(bg, null, null, false, null, ignoreSelection);
  4790. if (addShadow)
  4791. {
  4792. this.editor.addSvgShadow(svgRoot);
  4793. }
  4794. // Embeds the images in the SVG output (async)
  4795. this.convertImages(svgRoot, mxUtils.bind(this, mxUtils.bind(this, function(svgRoot2)
  4796. {
  4797. this.spinner.stop();
  4798. saveSvg('<?xml version="1.0" encoding="UTF-8"?>\n' +
  4799. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  4800. mxUtils.getXml(svgRoot2));
  4801. })));
  4802. }
  4803. else
  4804. {
  4805. filename = basename + '.svg';
  4806. svg = this.getFileData(false, true, null, mxUtils.bind(this, function(svg)
  4807. {
  4808. this.spinner.stop();
  4809. saveSvg(svg);
  4810. }), ignoreSelection);
  4811. }
  4812. }
  4813. else
  4814. {
  4815. var bounds = this.editor.graph.getGraphBounds();
  4816. // Exports only current page for PDF since it does not contain file data, but for
  4817. // the other formats with XML included we need to send the complete data and use
  4818. // the from/to URL parameters to specify the page to be exported.
  4819. var data = this.getFileData(true, null, null, null, ignoreSelection, format != 'xmlpng');
  4820. var range = '';
  4821. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  4822. {
  4823. var embed = '0';
  4824. if (format == 'xmlpng')
  4825. {
  4826. embed = '1';
  4827. format = 'png';
  4828. filename = basename + '.' + format;
  4829. // Finds the current page number
  4830. if (this.pages != null && this.currentPage != null)
  4831. {
  4832. for (var i = 0; i < this.pages.length; i++)
  4833. {
  4834. if (this.pages[i] == this.currentPage)
  4835. {
  4836. range = '&from=' + i;
  4837. break;
  4838. }
  4839. }
  4840. }
  4841. }
  4842. this.saveRequest(data, filename, format, function(newTitle, base64)
  4843. {
  4844. return new mxXmlRequest(EXPORT_URL, 'format=' + format + range +
  4845. '&base64=' + base64 + '&embedXml=' + embed + '&xml=' +
  4846. encodeURIComponent(data) + ((newTitle != null) ?
  4847. '&filename=' + encodeURIComponent(newTitle) : ''));
  4848. });
  4849. }
  4850. else
  4851. {
  4852. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
  4853. }
  4854. }
  4855. }
  4856. catch (e)
  4857. {
  4858. this.handleError(e);
  4859. }
  4860. };
  4861. /**
  4862. * Translates this point by the given vector.
  4863. *
  4864. * @param {number} dx X-coordinate of the translation.
  4865. * @param {number} dy Y-coordinate of the translation.
  4866. */
  4867. App.prototype.formatFileSize = function(size)
  4868. {
  4869. var units = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
  4870. var i = -1;
  4871. do
  4872. {
  4873. size = size / 1024;
  4874. i++;
  4875. } while (size > 1024);
  4876. return Math.max(size, 0.1).toFixed(1) + units[i];
  4877. };
  4878. /**
  4879. * Translates this point by the given vector.
  4880. *
  4881. * @param {number} dx X-coordinate of the translation.
  4882. * @param {number} dy Y-coordinate of the translation.
  4883. */
  4884. App.prototype.descriptorChanged = function()
  4885. {
  4886. var file = this.getCurrentFile();
  4887. if (file != null)
  4888. {
  4889. if (this.fname != null)
  4890. {
  4891. this.fnameWrapper.style.display = 'block';
  4892. this.fname.innerHTML = '';
  4893. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4894. mxUtils.write(this.fname, filename);
  4895. this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
  4896. }
  4897. this.editor.graph.setEnabled(file.isEditable());
  4898. // Ignores title and hash for revisions
  4899. if (urlParams['rev'] == null)
  4900. {
  4901. this.updateDocumentTitle();
  4902. var newHash = file.getHash();
  4903. if (newHash.length > 0)
  4904. {
  4905. window.location.hash = newHash;
  4906. }
  4907. else if (window.location.hash.length > 0)
  4908. {
  4909. window.location.hash = '';
  4910. }
  4911. }
  4912. }
  4913. };
  4914. /**
  4915. * Translates this point by the given vector.
  4916. *
  4917. * @param {number} dx X-coordinate of the translation.
  4918. * @param {number} dy Y-coordinate of the translation.
  4919. */
  4920. App.prototype.handleError = function(resp, title, fn)
  4921. {
  4922. var resume = this.spinner.pause();
  4923. var e = (resp != null && resp.error != null) ? resp.error : resp;
  4924. if (e != null || title != null)
  4925. {
  4926. var msg = mxResources.get('unknownError');
  4927. var btn = mxResources.get('ok');
  4928. var retry = null;
  4929. title = (title != null) ? title : mxResources.get('error');
  4930. if (e != null)
  4931. {
  4932. if (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' && typeof(gapi.drive.realtime) != 'undefined' &&
  4933. e.type == gapi.drive.realtime.ErrorType.FORBIDDEN)
  4934. {
  4935. msg = mxResources.get('forbidden');
  4936. }
  4937. else if (e.code == 404 || e.status == 404 || (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' &&
  4938. typeof(gapi.drive.realtime) != 'undefined' && e.type == gapi.drive.realtime.ErrorType.NOT_FOUND))
  4939. {
  4940. msg = mxResources.get('fileNotFoundOrDenied');
  4941. var id = window.location.hash;
  4942. if (id != null && id.substring(0, 2) == '#G')
  4943. {
  4944. id = id.substring(2);
  4945. msg += ' <a href="https://drive.google.com/open?id=' + id + '" target="_blank">' +
  4946. mxResources.get('tryOpeningViaThisPage') + '</a>';
  4947. }
  4948. }
  4949. else if (e.code == App.ERROR_TIMEOUT)
  4950. {
  4951. msg = mxResources.get('timeout');
  4952. if (e.retry != null)
  4953. {
  4954. btn = mxResources.get('cancel');
  4955. retry = function()
  4956. {
  4957. resume();
  4958. e.retry();
  4959. };
  4960. }
  4961. }
  4962. else if (e.code == App.ERROR_BUSY)
  4963. {
  4964. msg = mxResources.get('busy');
  4965. }
  4966. else if (e.message != null)
  4967. {
  4968. msg = e.message;
  4969. }
  4970. else if (e.response != null && e.response.error != null)
  4971. {
  4972. msg = e.response.error;
  4973. }
  4974. }
  4975. this.showError(title, msg, btn, fn, retry);
  4976. }
  4977. else if (fn != null)
  4978. {
  4979. fn();
  4980. }
  4981. };
  4982. /**
  4983. * Translates this point by the given vector.
  4984. *
  4985. * @param {number} dx X-coordinate of the translation.
  4986. * @param {number} dy Y-coordinate of the translation.
  4987. */
  4988. App.prototype.showError = function(title, msg, btn, fn, retry, btn2, fn2)
  4989. {
  4990. var dlg = new ErrorDialog(this, title, msg, btn, fn, retry, btn2, fn2);
  4991. this.showDialog(dlg.container, 340, 150, true, false);
  4992. dlg.init();
  4993. };
  4994. /**
  4995. * Translates this point by the given vector.
  4996. *
  4997. * @param {number} dx X-coordinate of the translation.
  4998. * @param {number} dy Y-coordinate of the translation.
  4999. */
  5000. App.prototype.alert = function(msg, fn)
  5001. {
  5002. var dlg = new ErrorDialog(this, null, msg, mxResources.get('ok'), fn);
  5003. this.showDialog(dlg.container, 340, 100, true, false);
  5004. dlg.init();
  5005. };
  5006. /**
  5007. * Translates this point by the given vector.
  5008. *
  5009. * @param {number} dx X-coordinate of the translation.
  5010. * @param {number} dy Y-coordinate of the translation.
  5011. */
  5012. App.prototype.confirm = function(msg, okFn, cancelFn)
  5013. {
  5014. var resume = (this.spinner.pause != null) ? this.spinner.pause() : function() {};
  5015. this.showDialog(new ConfirmDialog(this, msg, function()
  5016. {
  5017. resume();
  5018. if (okFn != null)
  5019. {
  5020. okFn();
  5021. }
  5022. }, function()
  5023. {
  5024. resume();
  5025. if (cancelFn != null)
  5026. {
  5027. cancelFn();
  5028. }
  5029. }).container, 340, 90, true, false);
  5030. };
  5031. /**
  5032. * Translates this point by the given vector.
  5033. *
  5034. * @param {number} dx X-coordinate of the translation.
  5035. * @param {number} dy Y-coordinate of the translation.
  5036. */
  5037. App.prototype.toggleChat = function()
  5038. {
  5039. var file = this.getCurrentFile();
  5040. if (file != null)
  5041. {
  5042. if (file.chatWindow == null)
  5043. {
  5044. var cwLeft = document.body.offsetWidth - 300;
  5045. file.chatWindow = new ChatWindow(this, mxResources.get('chatWindowTitle'), document.getElementById('geChat'), cwLeft , 80, 250, 350, file.realtime);
  5046. file.chatWindow.window.setVisible(false);
  5047. }
  5048. file.chatWindow.window.setVisible(!file.chatWindow.window.isVisible());
  5049. }
  5050. };
  5051. /**
  5052. * Translates this point by the given vector.
  5053. *
  5054. * @param {number} dx X-coordinate of the translation.
  5055. * @param {number} dy Y-coordinate of the translation.
  5056. */
  5057. App.prototype.status = function(html)
  5058. {
  5059. this.editor.setStatus(html);
  5060. };
  5061. /**
  5062. * Adds the listener for automatically saving the diagram for local changes.
  5063. */
  5064. App.prototype.showAuthDialog = function(peer, showRememberOption, fn)
  5065. {
  5066. var resume = this.spinner.pause();
  5067. this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
  5068. {
  5069. try
  5070. {
  5071. if (fn != null)
  5072. {
  5073. fn(remember, function()
  5074. {
  5075. resume();
  5076. });
  5077. }
  5078. }
  5079. catch (e)
  5080. {
  5081. this.editor.setStatus(e.message);
  5082. }
  5083. })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
  5084. {
  5085. if (cancel && this.getCurrentFile() == null && this.dialog == null)
  5086. {
  5087. this.showSplash();
  5088. }
  5089. }));
  5090. };
  5091. /**
  5092. * Checks if the client is authorized and calls the next step.
  5093. */
  5094. App.prototype.loadUrl = function(url, success, error, forceBinary, retry)
  5095. {
  5096. try
  5097. {
  5098. var binary = (forceBinary || /(\.png)($|\?)/i.test(url));
  5099. retry = (retry != null) ? retry : true;
  5100. var fn = mxUtils.bind(this, function()
  5101. {
  5102. mxUtils.get(url, mxUtils.bind(this, function(req)
  5103. {
  5104. if (req.getStatus() == 200)
  5105. {
  5106. if (success != null)
  5107. {
  5108. var data = req.getText();
  5109. // Returns PNG as base64 encoded data URI
  5110. if (binary)
  5111. {
  5112. // NOTE: This requires BinaryToArray VB script in the page
  5113. if ((document.documentMode == 9 || document.documentMode == 10) &&
  5114. typeof window.mxUtilsBinaryToArray !== 'undefined')
  5115. {
  5116. var bin = mxUtilsBinaryToArray(req.request.responseBody).toArray();
  5117. var tmp = new Array(bin.length);
  5118. for (var i = 0; i < bin.length; i++)
  5119. {
  5120. tmp[i] = String.fromCharCode(bin[i]);
  5121. }
  5122. data = tmp.join('');
  5123. }
  5124. data = 'data:image/png;base64,' + this.base64Encode(data);
  5125. }
  5126. success(data);
  5127. }
  5128. }
  5129. else if (error != null)
  5130. {
  5131. error({code: App.ERROR_UNKNOWN});
  5132. }
  5133. }), function()
  5134. {
  5135. if (error != null)
  5136. {
  5137. error({code: App.ERROR_UNKNOWN});
  5138. }
  5139. }, binary, this.timeout, function()
  5140. {
  5141. if (retry && error != null)
  5142. {
  5143. error({code: App.ERROR_TIMEOUT, retry: fn});
  5144. }
  5145. });
  5146. });
  5147. fn();
  5148. }
  5149. catch (e)
  5150. {
  5151. if (error != null)
  5152. {
  5153. error(e);
  5154. }
  5155. }
  5156. };
  5157. /**
  5158. * Adds the listener for automatically saving the diagram for local changes.
  5159. */
  5160. App.prototype.updateHeader = function()
  5161. {
  5162. if (this.menubar != null)
  5163. {
  5164. this.appIcon = document.createElement('a');
  5165. this.appIcon.style.display = 'block';
  5166. this.appIcon.style.position = 'absolute';
  5167. this.appIcon.style.width = '40px';
  5168. this.appIcon.style.backgroundColor = '#f18808';
  5169. this.appIcon.style.height = this.menubarHeight + 'px';
  5170. mxEvent.disableContextMenu(this.appIcon);
  5171. mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
  5172. {
  5173. this.appIconClicked(evt);
  5174. }));
  5175. // LATER: Use Alpha image loader in IE6
  5176. // NOTE: This uses the diagram bit of the old logo as it looks better in this case
  5177. //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
  5178. var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
  5179. 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
  5180. this.appIcon.style.backgroundImage = logo;
  5181. this.appIcon.style.backgroundPosition = 'center center';
  5182. this.appIcon.style.backgroundRepeat = 'no-repeat';
  5183. mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
  5184. mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
  5185. {
  5186. var file = this.getCurrentFile();
  5187. if (file != null)
  5188. {
  5189. var mode = file.getMode();
  5190. if (mode == App.MODE_GOOGLE)
  5191. {
  5192. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
  5193. }
  5194. else if (mode == App.MODE_DROPBOX)
  5195. {
  5196. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
  5197. }
  5198. else if (mode == App.MODE_ONEDRIVE)
  5199. {
  5200. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
  5201. }
  5202. }
  5203. }));
  5204. mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
  5205. {
  5206. this.appIcon.style.backgroundImage = logo;
  5207. }));
  5208. if (urlParams['embed'] != '1')
  5209. {
  5210. this.menubarContainer.appendChild(this.appIcon);
  5211. }
  5212. this.fnameWrapper = document.createElement('div');
  5213. this.fnameWrapper.style.position = 'absolute';
  5214. this.fnameWrapper.style.right = '120px';
  5215. this.fnameWrapper.style.left = '50px';
  5216. this.fnameWrapper.style.top = '6px';
  5217. this.fnameWrapper.style.height = '26px';
  5218. this.fnameWrapper.style.display = 'none';
  5219. this.fnameWrapper.style.overflow = 'hidden';
  5220. this.fnameWrapper.style.textOverflow = 'ellipsis';
  5221. this.fname = document.createElement('a');
  5222. this.fname.setAttribute('href', 'javascript:void(0);');
  5223. this.fname.setAttribute('title', mxResources.get('rename'));
  5224. this.fname.className = 'geItem';
  5225. this.fname.style.padding = '2px 8px 2px 8px';
  5226. this.fname.style.display = 'inline';
  5227. this.fname.style.fontSize = '18px';
  5228. this.fname.style.whiteSpace = 'nowrap';
  5229. mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
  5230. {
  5231. var file = this.getCurrentFile();
  5232. if (file != null && file.isRenamable())
  5233. {
  5234. this.actions.get('rename').funct();
  5235. }
  5236. mxEvent.consume(evt);
  5237. }));
  5238. this.fnameWrapper.appendChild(this.fname);
  5239. if (urlParams['embed'] != '1')
  5240. {
  5241. this.menubarContainer.appendChild(this.fnameWrapper);
  5242. this.menubar.container.style.position = 'absolute';
  5243. this.menubar.container.style.paddingLeft = '52px';
  5244. this.menubar.container.style.boxSizing = 'border-box';
  5245. this.menubar.container.style.top = '29px';
  5246. this.toolbar.container.style.paddingLeft = '56px';
  5247. }
  5248. /**
  5249. * Adds format panel toggle.
  5250. */
  5251. this.toggleFormatElement = document.createElement('a');
  5252. this.toggleFormatElement.setAttribute('href', 'javascript:void(0);');
  5253. this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (Ctrl+Shift+P)');
  5254. this.toggleFormatElement.style.position = 'absolute';
  5255. this.toggleFormatElement.style.display = 'inline-block';
  5256. this.toggleFormatElement.style.top = '5px';
  5257. this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '26px' : '10px';
  5258. this.toggleFormatElement.style.padding = '2px';
  5259. this.toggleFormatElement.style.fontSize = '14px';
  5260. this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  5261. this.toggleFormatElement.style.width = '16px';
  5262. this.toggleFormatElement.style.height = '16px';
  5263. this.toggleFormatElement.style.backgroundPosition = '50% 50%';
  5264. this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
  5265. this.toolbarContainer.appendChild(this.toggleFormatElement);
  5266. mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
  5267. {
  5268. this.actions.get('formatPanel').funct();
  5269. mxEvent.consume(evt);
  5270. }));
  5271. var toggleFormatPanel = mxUtils.bind(this, function()
  5272. {
  5273. if (this.formatWidth > 0)
  5274. {
  5275. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
  5276. }
  5277. else
  5278. {
  5279. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
  5280. }
  5281. });
  5282. this.addListener('formatWidthChanged', toggleFormatPanel);
  5283. toggleFormatPanel();
  5284. this.fullscreenElement = document.createElement('a');
  5285. this.fullscreenElement.setAttribute('href', 'javascript:void(0);');
  5286. this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
  5287. this.fullscreenElement.style.position = 'absolute';
  5288. this.fullscreenElement.style.display = 'inline-block';
  5289. this.fullscreenElement.style.top = '5px';
  5290. this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '42px' : '26px';
  5291. this.fullscreenElement.style.padding = '2px';
  5292. this.fullscreenElement.style.fontSize = '14px';
  5293. this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  5294. this.fullscreenElement.style.width = '16px';
  5295. this.fullscreenElement.style.height = '16px';
  5296. this.fullscreenElement.style.backgroundPosition = '50% 50%';
  5297. this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
  5298. this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
  5299. this.toolbarContainer.appendChild(this.fullscreenElement);
  5300. var initialPosition = this.hsplitPosition;
  5301. var collapsed = false;
  5302. mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
  5303. {
  5304. if (uiTheme != 'atlas' && urlParams['embed'] != '1')
  5305. {
  5306. this.toggleCompactMode(!collapsed);
  5307. }
  5308. this.toggleFormatPanel(!collapsed);
  5309. this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
  5310. this.hideFooter();
  5311. collapsed = !collapsed;
  5312. mxEvent.consume(evt);
  5313. }));
  5314. // Some style changes in Atlas theme
  5315. if (uiTheme == 'atlas')
  5316. {
  5317. mxUtils.setOpacity(this.toggleFormatElement, 70);
  5318. mxUtils.setOpacity(this.fullscreenElement, 70);
  5319. this.toggleFormatElement.style.right = '6px';
  5320. this.fullscreenElement.style.right = '22px';
  5321. this.toggleFormatElement.style.top = '8px';
  5322. this.fullscreenElement.style.top = '8px';
  5323. }
  5324. /**
  5325. * Adds compact UI toggle.
  5326. */
  5327. if (urlParams['embed'] != '1')
  5328. {
  5329. this.toggleElement = document.createElement('a');
  5330. this.toggleElement.setAttribute('href', 'javascript:void(0);');
  5331. this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
  5332. this.toggleElement.className = 'geButton';
  5333. this.toggleElement.style.position = 'absolute';
  5334. this.toggleElement.style.display = 'inline-block';
  5335. this.toggleElement.style.width = '16px';
  5336. this.toggleElement.style.height = '16px';
  5337. this.toggleElement.style.color = '#666';
  5338. this.toggleElement.style.top = '5px';
  5339. this.toggleElement.style.right = '10px';
  5340. this.toggleElement.style.padding = '2px';
  5341. this.toggleElement.style.fontSize = '14px';
  5342. this.toggleElement.style.textDecoration = 'none';
  5343. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  5344. this.toggleElement.style.backgroundPosition = '50% 50%';
  5345. this.toggleElement.style.backgroundRepeat = 'no-repeat';
  5346. // Toggles compact mode
  5347. mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
  5348. {
  5349. this.toggleCompactMode();
  5350. mxEvent.consume(evt);
  5351. }));
  5352. if (uiTheme != 'atlas')
  5353. {
  5354. this.toolbarContainer.appendChild(this.toggleElement);
  5355. }
  5356. // Enable compact mode for small screens
  5357. if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
  5358. {
  5359. window.setTimeout(mxUtils.bind(this, function()
  5360. {
  5361. this.toggleElement.click();
  5362. }), 0);
  5363. }
  5364. }
  5365. }
  5366. };
  5367. /**
  5368. * Adds the listener for automatically saving the diagram for local changes.
  5369. */
  5370. App.prototype.toggleCompactMode = function(forceHide)
  5371. {
  5372. if (!forceHide && this.appIcon.style.display == 'none')
  5373. {
  5374. this.menubar.container.style.position = 'absolute';
  5375. this.menubar.container.style.paddingLeft = '52px';
  5376. this.menubar.container.style.paddingTop = '';
  5377. this.menubar.container.style.paddingBottom = '';
  5378. this.menubar.container.style.top = '29px';
  5379. this.toolbar.container.style.paddingLeft = '56px';
  5380. this.buttonContainer.style.visibility = 'visible';
  5381. this.appIcon.style.display = 'block';
  5382. this.fnameWrapper.style.display = 'block';
  5383. this.fnameWrapper.style.visibility = 'visible';
  5384. this.menubarHeight = App.prototype.menubarHeight;
  5385. this.refresh();
  5386. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  5387. }
  5388. else
  5389. {
  5390. this.menubar.container.style.position = 'relative';
  5391. this.menubar.container.style.paddingLeft = '4px';
  5392. this.menubar.container.style.paddingTop = '0px';
  5393. this.menubar.container.style.paddingBottom = '0px';
  5394. this.menubar.container.style.top = '0px';
  5395. this.toolbar.container.style.paddingLeft = '4px';
  5396. this.buttonContainer.style.visibility = 'hidden';
  5397. this.appIcon.style.display = 'none';
  5398. this.fnameWrapper.style.display = 'none';
  5399. this.fnameWrapper.style.visibility = 'hidden';
  5400. this.menubarHeight = EditorUi.prototype.menubarHeight;
  5401. this.refresh();
  5402. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
  5403. }
  5404. };
  5405. /**
  5406. * Adds the listener for automatically saving the diagram for local changes.
  5407. */
  5408. App.prototype.updateUserElement = function()
  5409. {
  5410. if ((this.drive == null || this.drive.getUser() == null) &&
  5411. (this.oneDrive == null || this.oneDrive.getUser() == null) &&
  5412. (this.dropbox == null || this.dropbox.getUser() == null))
  5413. {
  5414. if (this.userElement != null)
  5415. {
  5416. this.userElement.parentNode.removeChild(this.userElement);
  5417. this.userElement = null;
  5418. }
  5419. }
  5420. else
  5421. {
  5422. if (this.userElement == null)
  5423. {
  5424. this.userElement = document.createElement('a');
  5425. this.userElement.setAttribute('href', 'javascript:void(0);');
  5426. this.userElement.className = 'geItem';
  5427. this.userElement.style.position = 'absolute';
  5428. this.userElement.style.fontSize = '8pt';
  5429. this.userElement.style.top = '4px';
  5430. this.userElement.style.right = '30px';
  5431. this.userElement.style.color = '#666';
  5432. this.userElement.style.margin = '4px';
  5433. this.userElement.style.padding = '2px';
  5434. this.userElement.style.paddingRight = '16px';
  5435. this.userElement.style.verticalAlign = 'middle';
  5436. this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  5437. this.userElement.style.backgroundPosition = '100% 60%';
  5438. this.userElement.style.backgroundRepeat = 'no-repeat';
  5439. this.menubarContainer.appendChild(this.userElement);
  5440. mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
  5441. {
  5442. if (this.userPanel == null)
  5443. {
  5444. var div = document.createElement('div');
  5445. div.className = 'geDialog';
  5446. div.style.position = 'absolute';
  5447. div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
  5448. div.style.right = '36px';
  5449. div.style.padding = '0px';
  5450. this.userPanel = div;
  5451. }
  5452. if (this.userPanel.parentNode != null)
  5453. {
  5454. this.userPanel.parentNode.removeChild(this.userPanel);
  5455. }
  5456. else
  5457. {
  5458. var connected = false;
  5459. this.userPanel.innerHTML = '';
  5460. var img = document.createElement('img');
  5461. img.setAttribute('src', Dialog.prototype.closeImage);
  5462. img.setAttribute('title', mxResources.get('close'));
  5463. img.className = 'geDialogClose';
  5464. img.style.top = '8px';
  5465. img.style.right = '8px';
  5466. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  5467. {
  5468. if (this.userPanel.parentNode != null)
  5469. {
  5470. this.userPanel.parentNode.removeChild(this.userPanel);
  5471. }
  5472. }));
  5473. this.userPanel.appendChild(img);
  5474. if (this.drive != null)
  5475. {
  5476. var driveUser = this.drive.getUser();
  5477. if (driveUser != null)
  5478. {
  5479. connected = true;
  5480. this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
  5481. '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
  5482. '<tr><td valign="top">' +
  5483. ((driveUser.pictureUrl != null) ?
  5484. '<img style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
  5485. '<img style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
  5486. '</td><td valign="top" style="white-space:nowrap;' +
  5487. ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
  5488. '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
  5489. '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small></tr></table>';
  5490. var div = document.createElement('div');
  5491. div.style.textAlign = 'center';
  5492. div.style.padding = '12px';
  5493. div.style.background = 'whiteSmoke';
  5494. div.style.borderTop = '1px solid #e0e0e0';
  5495. div.style.whiteSpace = 'nowrap';
  5496. // LATER: Cannot change user while file is open since close will not work with new
  5497. // credentials and closing the file using fileLoaded(null) will show splash dialog.
  5498. div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
  5499. {
  5500. var file = this.getCurrentFile();
  5501. if (file != null && file.constructor == DriveFile)
  5502. {
  5503. this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
  5504. {
  5505. this.diagramContainer.style.visibility = 'hidden';
  5506. this.formatContainer.style.visibility = 'hidden';
  5507. this.hsplit.style.display = 'none';
  5508. this.sidebarContainer.style.display = 'none';
  5509. this.sidebarFooterContainer.style.display = 'none';
  5510. file.close();
  5511. // LATER: Use callback to wait for thumbnail update
  5512. window.setTimeout(mxUtils.bind(this, function()
  5513. {
  5514. // Workaround to disable the splash screen before reload
  5515. this.showDialog = function() {};
  5516. window.location.hash = '';
  5517. this.drive.clearUserId();
  5518. gapi.auth.signOut();
  5519. // Reload page to reset client auth
  5520. window.location.reload();
  5521. }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
  5522. }));
  5523. }
  5524. else
  5525. {
  5526. this.drive.clearUserId();
  5527. this.drive.setUser(null);
  5528. gapi.auth.signOut();
  5529. }
  5530. })));
  5531. this.userPanel.appendChild(div);
  5532. }
  5533. }
  5534. var addUser = mxUtils.bind(this, function(user, logo, logout)
  5535. {
  5536. if (user != null)
  5537. {
  5538. if (connected)
  5539. {
  5540. this.userPanel.appendChild(document.createElement('hr'));
  5541. }
  5542. connected = true;
  5543. this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
  5544. ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
  5545. '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
  5546. ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font></td>' : '') +
  5547. '</tr></table>';
  5548. var div = document.createElement('div');
  5549. div.style.textAlign = 'center';
  5550. div.style.padding = '12px';
  5551. div.style.background = 'whiteSmoke';
  5552. div.style.borderTop = '1px solid #e0e0e0';
  5553. div.style.whiteSpace = 'nowrap';
  5554. if (logout != null)
  5555. {
  5556. div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
  5557. }
  5558. this.userPanel.appendChild(div);
  5559. }
  5560. });
  5561. if (this.dropbox != null)
  5562. {
  5563. addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
  5564. {
  5565. var file = this.getCurrentFile();
  5566. if (file != null && file.constructor == DropboxFile)
  5567. {
  5568. var doLogout = mxUtils.bind(this, function()
  5569. {
  5570. this.dropbox.logout();
  5571. window.location.hash = '';
  5572. });
  5573. if (!file.isModified())
  5574. {
  5575. doLogout();
  5576. }
  5577. else
  5578. {
  5579. this.confirm(mxResources.get('allChangesLost'), doLogout);
  5580. }
  5581. }
  5582. else
  5583. {
  5584. this.dropbox.logout();
  5585. }
  5586. }));
  5587. }
  5588. if (this.oneDrive != null)
  5589. {
  5590. addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
  5591. {
  5592. var file = this.getCurrentFile();
  5593. if (file != null && file.constructor == OneDriveFile)
  5594. {
  5595. var doLogout = mxUtils.bind(this, function()
  5596. {
  5597. this.oneDrive.logout();
  5598. window.location.hash = '';
  5599. });
  5600. if (!file.isModified())
  5601. {
  5602. doLogout();
  5603. }
  5604. else
  5605. {
  5606. this.confirm(mxResources.get('allChangesLost'), doLogout);
  5607. }
  5608. }
  5609. else
  5610. {
  5611. this.oneDrive.logout();
  5612. }
  5613. }));
  5614. }
  5615. if (!connected)
  5616. {
  5617. var div = document.createElement('div');
  5618. div.style.textAlign = 'center';
  5619. div.style.padding = '20px 20px 10px 10px';
  5620. div.innerHTML = mxResources.get('notConnected');
  5621. this.userPanel.appendChild(div);
  5622. }
  5623. document.body.appendChild(this.userPanel);
  5624. }
  5625. mxEvent.consume(evt);
  5626. }));
  5627. mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
  5628. {
  5629. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5630. {
  5631. this.userPanel.parentNode.removeChild(this.userPanel);
  5632. }
  5633. }));
  5634. }
  5635. var user = null;
  5636. if (this.drive != null && this.drive.getUser() != null)
  5637. {
  5638. user = this.drive.getUser();
  5639. }
  5640. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5641. {
  5642. user = this.oneDrive.getUser();
  5643. }
  5644. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5645. {
  5646. user = this.dropbox.getUser();
  5647. }
  5648. if (user != null)
  5649. {
  5650. this.userElement.innerHTML = '';
  5651. mxUtils.write(this.userElement, user.displayName);
  5652. this.userElement.style.display = 'block';
  5653. }
  5654. else
  5655. {
  5656. this.userElement.style.display = 'none';
  5657. }
  5658. }
  5659. };
  5660. // Handles paste from lucid chart
  5661. (function()
  5662. {
  5663. var loading = false;
  5664. var editorUiPasteCells = EditorUi.prototype.pasteCells;
  5665. EditorUi.prototype.pasteCells = function(evt, elt)
  5666. {
  5667. var spans = elt.getElementsByTagName('span');
  5668. if (spans != null && spans.length > 0 && spans[0].getAttribute('data-lucid-type') ===
  5669. 'application/vnd.lucid.chart.objects')
  5670. {
  5671. var content = spans[0].getAttribute('data-lucid-content');
  5672. if (content != null && content.length > 0)
  5673. {
  5674. var delayed = mxUtils.bind(this, function()
  5675. {
  5676. // Checks for signature method
  5677. if (this.pasteLucidChart)
  5678. {
  5679. try
  5680. {
  5681. this.pasteLucidChart(JSON.parse(content))
  5682. mxEvent.consume(evt);
  5683. }
  5684. catch (e)
  5685. {
  5686. // ignore
  5687. }
  5688. }
  5689. });
  5690. if (!this.pasteLucidChart && !loading && !this.isOffline())
  5691. {
  5692. loading = true;
  5693. if (urlParams['dev'] == '1')
  5694. {
  5695. mxscript('/js/diagramly/Extensions.js', delayed);
  5696. }
  5697. else
  5698. {
  5699. mxscript('/js/extensions.min.js', delayed);
  5700. }
  5701. }
  5702. else
  5703. {
  5704. delayed();
  5705. }
  5706. }
  5707. }
  5708. editorUiPasteCells.apply(this, arguments);
  5709. };
  5710. })();