App.js 185 KB

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