Dialogs.js 212 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401
  1. /*
  2. * $Id: Dialogs.js,v 1.103 2014/02/11 14:08:15 gaudenz Exp $
  3. * Copyright (c) 2006-2010, JGraph Ltd
  4. */
  5. var StorageDialog = function(editorUi, fn)
  6. {
  7. var div = document.createElement('div');
  8. div.style.textAlign = 'center';
  9. div.style.whiteSpace = 'nowrap';
  10. var elt = editorUi.addLanguageMenu(div);
  11. var bottom = '28px';
  12. if (elt != null)
  13. {
  14. elt.style.bottom = bottom;
  15. }
  16. if (!editorUi.isOffline())
  17. {
  18. var help = document.createElement('a');
  19. help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
  20. help.setAttribute('title', mxResources.get('help'));
  21. help.setAttribute('target', '_blank');
  22. help.style.position = 'absolute';
  23. help.style.textDecoration = 'none';
  24. help.style.cursor = 'pointer';
  25. help.style.fontSize = '12px';
  26. help.style.bottom = bottom;
  27. help.style.left = '26px';
  28. help.style.color = 'gray';
  29. mxUtils.write(help, mxResources.get('help'));
  30. div.appendChild(help);
  31. }
  32. var demo = document.createElement('div');
  33. demo.style.position = 'absolute';
  34. demo.style.cursor = 'pointer';
  35. demo.style.fontSize = '12px';
  36. demo.style.bottom = bottom;
  37. demo.style.color = 'gray';
  38. mxUtils.write(demo, mxResources.get('decideLater'));
  39. if (editorUi.isOfflineApp())
  40. {
  41. demo.style.right = '20px';
  42. }
  43. else
  44. {
  45. mxUtils.setPrefixedStyle(demo.style, 'transform', 'translate(-50%,0)');
  46. demo.style.left = '50%';
  47. }
  48. this.init = function()
  49. {
  50. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  51. {
  52. demo.style.marginLeft = -Math.round(demo.clientWidth / 2) + 'px';
  53. }
  54. };
  55. div.appendChild(demo);
  56. mxEvent.addListener(demo, 'click', function()
  57. {
  58. editorUi.hideDialog();
  59. var prev = Editor.useLocalStorage;
  60. editorUi.createFile(editorUi.defaultFilename, null, null, App.MODE_DEVICE);
  61. editorUi.setMode(null);
  62. Editor.useLocalStorage = prev;
  63. });
  64. var buttons = document.createElement('div');
  65. if (mxClient.IS_QUIRKS)
  66. {
  67. buttons.style.whiteSpace = 'nowrap';
  68. buttons.style.cssFloat = 'left';
  69. }
  70. buttons.style.border = '1px solid #d3d3d3';
  71. buttons.style.borderWidth = '1px 0px 1px 0px';
  72. buttons.style.padding = '26px 0px 12px 0px';
  73. var cb = document.createElement('input');
  74. cb.setAttribute('type', 'checkbox');
  75. cb.setAttribute('checked', 'checked');
  76. cb.defaultChecked = true;
  77. function addLogo(img, title, mode, clientName)
  78. {
  79. var button = document.createElement('a');
  80. button.style.overflow = 'hidden';
  81. var logo = document.createElement('img');
  82. logo.setAttribute('src', img);
  83. logo.setAttribute('border', '0');
  84. logo.setAttribute('align', 'absmiddle');
  85. logo.style.width = '60px';
  86. logo.style.height = '60px';
  87. logo.style.paddingBottom = '6px';
  88. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  89. button.className = 'geBaseButton';
  90. button.style.position = 'relative';
  91. button.style.margin = '4px';
  92. button.style.padding = '8px 10px 12px 10px';
  93. button.style.whiteSpace = 'nowrap';
  94. // Workaround for quirks is a vertical list (limited to max 2 items)
  95. if (mxClient.IS_QUIRKS)
  96. {
  97. button.style.cssFloat = 'left';
  98. button.style.zoom = '1';
  99. }
  100. button.appendChild(logo);
  101. var label = document.createElement('div');
  102. button.appendChild(label);
  103. mxUtils.write(label, title);
  104. function initButton()
  105. {
  106. mxEvent.addListener(button, 'click', function()
  107. {
  108. // Special case: Redirect all drive users to draw.io pro
  109. if (mode == App.MODE_GOOGLE && !editorUi.isDriveDomain())
  110. {
  111. window.location.hostname = DriveClient.prototype.newAppHostname;
  112. }
  113. else if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  114. {
  115. // Tries immediate authentication
  116. editorUi.drive.checkToken(mxUtils.bind(this, function()
  117. {
  118. editorUi.spinner.stop();
  119. editorUi.setMode(mode, cb.checked);
  120. fn();
  121. }));
  122. }
  123. else
  124. {
  125. editorUi.setMode(mode, cb.checked);
  126. fn();
  127. }
  128. });
  129. };
  130. // Supports lazy loading
  131. if (clientName != null && editorUi[clientName] == null)
  132. {
  133. logo.style.visibility = 'hidden';
  134. mxUtils.setOpacity(label, 10);
  135. var size = 12;
  136. var spinner = new Spinner({
  137. lines: 12, // The number of lines to draw
  138. length: size, // The length of each line
  139. width: 5, // The line thickness
  140. radius: 10, // The radius of the inner circle
  141. rotate: 0, // The rotation offset
  142. color: '#000', // #rgb or #rrggbb
  143. speed: 1.5, // Rounds per second
  144. trail: 60, // Afterglow percentage
  145. shadow: false, // Whether to render a shadow
  146. hwaccel: false, // Whether to use hardware acceleration
  147. top: '40%',
  148. zIndex: 2e9 // The z-index (defaults to 2000000000)
  149. });
  150. spinner.spin(button);
  151. // Timeout after 30 secs
  152. var timeout = window.setTimeout(function()
  153. {
  154. if (editorUi[clientName] == null)
  155. {
  156. spinner.stop();
  157. button.style.display = 'none';
  158. }
  159. }, 30000);
  160. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  161. {
  162. if (editorUi[clientName] != null)
  163. {
  164. window.clearTimeout(timeout);
  165. mxUtils.setOpacity(label, 100);
  166. logo.style.visibility = '';
  167. spinner.stop();
  168. initButton();
  169. }
  170. }));
  171. }
  172. else
  173. {
  174. initButton();
  175. }
  176. buttons.appendChild(button);
  177. };
  178. var hd = document.createElement('p');
  179. hd.style.fontSize = '16pt';
  180. hd.style.padding = '0px';
  181. hd.style.paddingTop = '4px';
  182. hd.style.paddingBottom = '20px';
  183. hd.style.margin = '0px';
  184. hd.style.color = 'gray';
  185. mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
  186. div.appendChild(hd);
  187. if (typeof window.DriveClient === 'function')
  188. {
  189. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  190. }
  191. if (typeof window.DropboxClient === 'function')
  192. {
  193. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  194. }
  195. if (typeof window.OneDriveClient === 'function')
  196. {
  197. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  198. }
  199. if (!mxClient.IS_IOS || urlParams['storage'] == 'device')
  200. {
  201. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  202. }
  203. if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
  204. {
  205. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  206. }
  207. div.appendChild(buttons);
  208. var p2 = document.createElement('p');
  209. p2.style.paddingTop = '10px';
  210. p2.appendChild(cb);
  211. var span = document.createElement('span');
  212. span.style.color = 'gray';
  213. span.style.fontSize = '12px';
  214. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  215. p2.appendChild(span);
  216. buttons.appendChild(p2);
  217. mxEvent.addListener(span, 'click', function(evt)
  218. {
  219. cb.checked = !cb.checked;
  220. mxEvent.consume(evt);
  221. });
  222. // Checks if Google Drive is missing after a 5 sec delay
  223. if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
  224. (document.documentMode == null || document.documentMode >= 10))
  225. {
  226. window.setTimeout(function()
  227. {
  228. if (editorUi.drive == null)
  229. {
  230. // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
  231. // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
  232. var p3 = document.createElement('p');
  233. p3.style.padding = '8px';
  234. p3.style.fontSize = '9pt';
  235. p3.style.marginTop = '-14px';
  236. p3.innerHTML = '<a style="background-color:#dcdcdc;padding:5px;color:black;text-decoration:none;" ' +
  237. 'href="https://plus.google.com/u/0/+DrawIo1/posts/1HTrfsb5wDN" target="_blank">' +
  238. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top"> ' +
  239. mxResources.get('googleDriveMissing') + '</a>';
  240. div.appendChild(p3);
  241. }
  242. }, 5000);
  243. }
  244. this.container = div;
  245. };
  246. /**
  247. * Constructs a dialog for creating new files from templates.
  248. */
  249. var SplashDialog = function(editorUi)
  250. {
  251. var div = document.createElement('div');
  252. div.style.textAlign = 'center';
  253. editorUi.addLanguageMenu(div);
  254. var help = null;
  255. if (!editorUi.isOffline())
  256. {
  257. help = document.createElement('a');
  258. help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
  259. help.setAttribute('title', mxResources.get('help'));
  260. help.setAttribute('target', '_blank');
  261. help.style.position = 'absolute';
  262. help.style.fontSize = '12px';
  263. help.style.textDecoration = 'none';
  264. help.style.cursor = 'pointer';
  265. help.style.bottom = '22px';
  266. help.style.left = '26px';
  267. help.style.color = 'gray';
  268. mxUtils.write(help, mxResources.get('help'));
  269. div.appendChild(help);
  270. }
  271. var hd = document.createElement('p');
  272. hd.style.fontSize = '16pt';
  273. hd.style.padding = '0px';
  274. hd.style.paddingTop = '2px';
  275. hd.style.margin = '0px';
  276. hd.style.color = 'gray';
  277. var logo = document.createElement('img');
  278. logo.setAttribute('border', '0');
  279. logo.setAttribute('align', 'absmiddle');
  280. logo.style.width = '40px';
  281. logo.style.height = '40px';
  282. logo.style.marginRight = '12px';
  283. logo.style.paddingBottom = '4px';
  284. var service = '';
  285. if (editorUi.mode == App.MODE_GOOGLE)
  286. {
  287. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  288. service = mxResources.get('googleDrive');
  289. if (help != null)
  290. {
  291. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Google+Drive');
  292. }
  293. }
  294. else if (editorUi.mode == App.MODE_DROPBOX)
  295. {
  296. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  297. service = mxResources.get('dropbox');
  298. if (help != null)
  299. {
  300. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Dropbox');
  301. }
  302. }
  303. else if (editorUi.mode == App.MODE_ONEDRIVE)
  304. {
  305. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  306. service = mxResources.get('oneDrive');
  307. if (help != null)
  308. {
  309. help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+OneDrive');
  310. }
  311. }
  312. else if (editorUi.mode == App.MODE_BROWSER)
  313. {
  314. logo.src = IMAGE_PATH + '/osa_database.png';
  315. service = mxResources.get('browser');
  316. }
  317. else
  318. {
  319. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  320. service = mxResources.get('device');
  321. }
  322. hd.appendChild(logo);
  323. mxUtils.write(hd, service);
  324. div.appendChild(hd);
  325. var buttons = document.createElement('div');
  326. if (mxClient.IS_QUIRKS)
  327. {
  328. buttons.style.whiteSpace = 'nowrap';
  329. buttons.style.cssFloat = 'left';
  330. }
  331. buttons.style.border = '1px solid #d3d3d3';
  332. buttons.style.borderWidth = '1px 0px 1px 0px';
  333. buttons.style.padding = '18px 0px 24px 0px';
  334. buttons.style.margin = '4px 0px 0px 0px';
  335. var btn = document.createElement('button');
  336. btn.className = 'geBigButton';
  337. btn.style.marginBottom = '8px';
  338. btn.style.overflow = 'hidden';
  339. btn.style.width = '340px';
  340. if (mxClient.IS_QUIRKS)
  341. {
  342. btn.style.width = '340px';
  343. }
  344. mxUtils.write(btn, mxResources.get('createNewDiagram'));
  345. mxEvent.addListener(btn, 'click', function()
  346. {
  347. editorUi.hideDialog();
  348. editorUi.actions.get('new').funct();
  349. });
  350. buttons.appendChild(btn);
  351. mxUtils.br(buttons);
  352. var btn = document.createElement('button');
  353. btn.className = 'geBigButton';
  354. btn.style.marginBottom = '22px';
  355. btn.style.overflow = 'hidden';
  356. btn.style.width = '340px';
  357. if (mxClient.IS_QUIRKS)
  358. {
  359. btn.style.width = '340px';
  360. }
  361. mxUtils.write(btn, mxResources.get('openExistingDiagram'));
  362. mxEvent.addListener(btn, 'click', function()
  363. {
  364. editorUi.actions.get('open').funct();
  365. });
  366. buttons.appendChild(btn);
  367. var storage = 'undefined';
  368. if (editorUi.mode == App.MODE_GOOGLE)
  369. {
  370. storage = mxResources.get('googleDrive');
  371. }
  372. else if (editorUi.mode == App.MODE_DROPBOX)
  373. {
  374. storage = mxResources.get('dropbox');
  375. }
  376. else if (editorUi.mode == App.MODE_ONEDRIVE)
  377. {
  378. storage = mxResources.get('oneDrive');
  379. }
  380. else if (editorUi.mode == App.MODE_DEVICE)
  381. {
  382. storage = mxResources.get('device');
  383. }
  384. else if (editorUi.mode == App.MODE_BROWSER)
  385. {
  386. storage = mxResources.get('browser');
  387. }
  388. var serviceCount = 0;
  389. if (editorUi.drive != null)
  390. {
  391. serviceCount++
  392. }
  393. if (editorUi.dropbox != null)
  394. {
  395. serviceCount++
  396. }
  397. if (isLocalStorage)
  398. {
  399. serviceCount++
  400. }
  401. if (!mxClient.IS_IOS)
  402. {
  403. serviceCount++
  404. }
  405. if (serviceCount > 1)
  406. {
  407. var link = document.createElement('a');
  408. link.setAttribute('href', 'javascript:void(0)');
  409. link.style.display = 'block';
  410. link.style.marginTop = '6px';
  411. mxUtils.write(link, mxResources.get('notUsingService', [storage]));
  412. mxEvent.addListener(link, 'click', function()
  413. {
  414. editorUi.hideDialog(false);
  415. editorUi.clearMode();
  416. editorUi.showSplash(true);
  417. });
  418. buttons.appendChild(link);
  419. var driveUser = (editorUi.drive != null) ? editorUi.drive.getUser() : null;
  420. if (editorUi.mode == App.MODE_GOOGLE && driveUser != null)
  421. {
  422. btn.style.marginBottom = '24px';
  423. var link = document.createElement('a');
  424. link.setAttribute('href', 'javascript:void(0)');
  425. link.style.display = 'block';
  426. link.style.marginTop = '2px';
  427. mxUtils.write(link, mxResources.get('changeUser') + ' (' + driveUser.displayName + ')');
  428. // Makes room after last big buttons
  429. btn.style.marginBottom = '16px';
  430. buttons.style.paddingBottom = '18px';
  431. mxEvent.addListener(link, 'click', function()
  432. {
  433. editorUi.hideDialog();
  434. editorUi.drive.clearUserId();
  435. editorUi.drive.setUser(null);
  436. gapi.auth.signOut();
  437. // Restores current dialog after clearing user
  438. editorUi.setMode(App.MODE_GOOGLE);
  439. editorUi.hideDialog();
  440. editorUi.showSplash();
  441. // FIXME: Does not force showing the auth dialog if only one user is logged in
  442. editorUi.drive.authorize(false, mxUtils.bind(this, mxUtils.bind(this, function()
  443. {
  444. editorUi.hideDialog();
  445. editorUi.showSplash();
  446. })), mxUtils.bind(this, function(resp)
  447. {
  448. editorUi.handleError(resp, null, function()
  449. {
  450. editorUi.hideDialog();
  451. editorUi.showSplash();
  452. });
  453. }));
  454. });
  455. buttons.appendChild(link);
  456. }
  457. }
  458. div.appendChild(buttons);
  459. // Changes Chrome App dialog
  460. if (mxClient.IS_CHROMEAPP)
  461. {
  462. hd.style.paddingTop = '12px';
  463. hd.innerHTML = '';
  464. mxUtils.write(hd, mxResources.get('chooseAnOption') + ':');
  465. buttons.style.border = 'none';
  466. buttons.style.padding = '16px 0px 0px 0px';
  467. btn.style.marginBottom = '0px';
  468. }
  469. this.init = function()
  470. {
  471. if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  472. {
  473. var fn = function()
  474. {
  475. var oneDriveUser = editorUi.oneDrive.getUser();
  476. if (oneDriveUser != null)
  477. {
  478. btn.style.marginBottom = '24px';
  479. var link = document.createElement('a');
  480. link.setAttribute('href', 'javascript:void(0)');
  481. link.style.display = 'block';
  482. link.style.marginTop = '2px';
  483. mxUtils.write(link, mxResources.get('changeUser') + ' (' + oneDriveUser.displayName + ')');
  484. // Makes room after last big buttons
  485. btn.style.marginBottom = '16px';
  486. buttons.style.paddingBottom = '18px';
  487. mxEvent.addListener(link, 'click', function()
  488. {
  489. editorUi.oneDrive.logout();
  490. link.parentNode.removeChild(link);
  491. // NOTE: Could use userEvent=true here but it seems the logout
  492. // call is asynchronous and the client isn't fully logged out
  493. // when called immediately so we show the auth dialog to get
  494. // a delay (sometimes event that is not enough so should use
  495. // async callback on logout but that seems to be broken)
  496. editorUi.oneDrive.execute(fn);
  497. });
  498. buttons.appendChild(link);
  499. }
  500. };
  501. editorUi.oneDrive.execute(fn);
  502. }
  503. };
  504. this.container = div;
  505. };
  506. /**
  507. *
  508. */
  509. var ConfirmDialog = function(editorUi, message, okFn, cancelFn)
  510. {
  511. var div = document.createElement('div');
  512. div.style.textAlign = 'center';
  513. var p2 = document.createElement('div');
  514. p2.style.padding = '6px';
  515. p2.style.overflow = 'auto';
  516. p2.style.maxHeight = '40px';
  517. if (mxClient.IS_QUIRKS)
  518. {
  519. p2.style.height = '60px';
  520. }
  521. mxUtils.write(p2, message);
  522. div.appendChild(p2);
  523. var btns = document.createElement('div');
  524. btns.style.marginTop = '16px';
  525. btns.style.textAlign = 'center';
  526. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  527. {
  528. editorUi.hideDialog();
  529. if (cancelFn != null)
  530. {
  531. cancelFn();
  532. }
  533. });
  534. cancelBtn.className = 'geBtn';
  535. if (editorUi.editor.cancelFirst)
  536. {
  537. btns.appendChild(cancelBtn);
  538. }
  539. var okBtn = mxUtils.button(mxResources.get('ok'), function()
  540. {
  541. editorUi.hideDialog();
  542. if (okFn != null)
  543. {
  544. okFn();
  545. }
  546. });
  547. btns.appendChild(okBtn);
  548. okBtn.className = 'geBtn gePrimaryBtn';
  549. if (!editorUi.editor.cancelFirst)
  550. {
  551. btns.appendChild(cancelBtn);
  552. }
  553. div.appendChild(btns);
  554. this.container = div;
  555. };
  556. /**
  557. *
  558. */
  559. var ErrorDialog = function(editorUi, title, message, buttonText, fn, retry, buttonText2, fn2, hide)
  560. {
  561. hide = (hide != null) ? hide : true;
  562. var div = document.createElement('div');
  563. div.style.textAlign = 'center';
  564. if (title != null)
  565. {
  566. var hd = document.createElement('div');
  567. hd.style.padding = '0px';
  568. hd.style.margin = '0px';
  569. hd.style.fontSize = '18px';
  570. hd.style.paddingBottom = '16px';
  571. hd.style.marginBottom = '16px';
  572. hd.style.borderBottom = '1px solid #c0c0c0';
  573. hd.style.color = 'gray';
  574. mxUtils.write(hd, title);
  575. div.appendChild(hd);
  576. }
  577. var p2 = document.createElement('div');
  578. p2.style.padding = '6px';
  579. p2.innerHTML = message;
  580. div.appendChild(p2);
  581. var btns = document.createElement('div');
  582. btns.style.marginTop = '16px';
  583. btns.style.textAlign = 'right';
  584. if (retry != null)
  585. {
  586. var retryBtn = mxUtils.button(mxResources.get('tryAgain'), function()
  587. {
  588. editorUi.hideDialog();
  589. retry();
  590. });
  591. retryBtn.className = 'geBtn';
  592. btns.appendChild(retryBtn);
  593. btns.style.textAlign = 'center';
  594. }
  595. var btn = mxUtils.button(buttonText, function()
  596. {
  597. if (hide)
  598. {
  599. editorUi.hideDialog();
  600. }
  601. if (fn != null)
  602. {
  603. fn();
  604. }
  605. });
  606. btn.className = 'geBtn';
  607. btns.appendChild(btn);
  608. if (buttonText2 != null)
  609. {
  610. var mainBtn = mxUtils.button(buttonText2, function()
  611. {
  612. if (hide)
  613. {
  614. editorUi.hideDialog();
  615. }
  616. if (fn2 != null)
  617. {
  618. fn2();
  619. }
  620. });
  621. mainBtn.className = 'geBtn gePrimaryBtn';
  622. btns.appendChild(mainBtn);
  623. }
  624. this.init = function()
  625. {
  626. btn.focus();
  627. };
  628. div.appendChild(btns);
  629. this.container = div;
  630. };
  631. /**
  632. * Constructs a new embed dialog
  633. */
  634. var EmbedHtmlDialog = function(editorUi)
  635. {
  636. var file = editorUi.getCurrentFile();
  637. var div = document.createElement('div');
  638. var graph = editorUi.editor.graph;
  639. var bounds = graph.getGraphBounds();
  640. var scale = graph.view.scale;
  641. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  642. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  643. mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
  644. mxUtils.br(div);
  645. var textarea = document.createElement('textarea');
  646. textarea.style.marginTop = '6px';
  647. textarea.style.width = '550px';
  648. textarea.style.height = '160px';
  649. textarea.style.marginBottom = '10px';
  650. textarea.style.resize = 'none';
  651. div.appendChild(textarea);
  652. mxUtils.br(div);
  653. mxUtils.write(div, mxResources.get('embedNotice') + ': ');
  654. mxUtils.br(div);
  655. var textarea2 = document.createElement('textarea');
  656. textarea2.style.marginTop = '6px';
  657. textarea2.style.width = '550px';
  658. textarea2.style.height = '20px';
  659. textarea2.style.resize = 'none';
  660. textarea2.style.marginBottom = '10px';
  661. div.appendChild(textarea2);
  662. mxUtils.br(div);
  663. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ': ');
  664. var urlInput = document.createElement('input');
  665. urlInput.setAttribute('type', 'text');
  666. urlInput.setAttribute('size', '28');
  667. urlInput.style.width = '340px';
  668. urlInput.style.marginBottom = '8px';
  669. div.appendChild(urlInput);
  670. mxUtils.br(div);
  671. var options = document.createElement('div');
  672. options.style.paddingTop = '10px';
  673. options.style.textAlign = 'center';
  674. var fitCheckBox = document.createElement('input');
  675. fitCheckBox.setAttribute('type', 'checkbox');
  676. fitCheckBox.setAttribute('checked', 'checked');
  677. fitCheckBox.defaultChecked = true;
  678. options.appendChild(fitCheckBox);
  679. mxUtils.write(options, mxResources.get('fit'));
  680. var label = document.createElement('span');
  681. label.style.marginLeft = '10px';
  682. mxUtils.write(label, mxResources.get('zoom') + ': ');
  683. options.appendChild(label);
  684. var zoomInput = document.createElement('input');
  685. zoomInput.setAttribute('type', 'text');
  686. zoomInput.setAttribute('size', '4');
  687. zoomInput.style.width = '40px';
  688. zoomInput.value = '100%';
  689. options.appendChild(zoomInput);
  690. var label = document.createElement('span');
  691. label.style.marginLeft = '10px';
  692. mxUtils.write(label, mxResources.get('link') + ': ');
  693. options.appendChild(label);
  694. var borderColorInput = document.createElement('input');
  695. borderColorInput.setAttribute('type', 'text');
  696. borderColorInput.setAttribute('size', '8');
  697. borderColorInput.style.width = '50px';
  698. borderColorInput.value = '#0000ff';
  699. options.appendChild(borderColorInput);
  700. mxUtils.br(options);
  701. var lightboxCheckBox = document.createElement('input');
  702. lightboxCheckBox.setAttribute('type', 'checkbox');
  703. lightboxCheckBox.setAttribute('checked', 'checked');
  704. lightboxCheckBox.defaultChecked = true;
  705. lightboxCheckBox.style.marginTop = '14px';
  706. options.appendChild(lightboxCheckBox);
  707. mxUtils.write(options, mxResources.get('lightbox'));
  708. var editCheckBox = document.createElement('input');
  709. editCheckBox.setAttribute('type', 'checkbox');
  710. editCheckBox.setAttribute('checked', 'checked');
  711. editCheckBox.defaultChecked = true;
  712. editCheckBox.style.marginLeft = '10px';
  713. //options.appendChild(editCheckBox);
  714. //mxUtils.write(options, mxResources.get('edit'));
  715. var layersCheckBox = document.createElement('input');
  716. layersCheckBox.setAttribute('type', 'checkbox');
  717. layersCheckBox.style.marginLeft = '10px';
  718. var model = editorUi.editor.graph.getModel();
  719. if (editorUi.pages == null || editorUi.pages.length == 0 &&
  720. (model.getChildCount(model.getRoot()) <= 1))
  721. {
  722. layersCheckBox.setAttribute('disabled', 'disabled');
  723. }
  724. else
  725. {
  726. layersCheckBox.setAttribute('checked', 'checked');
  727. layersCheckBox.defaultChecked = true;
  728. }
  729. options.appendChild(layersCheckBox);
  730. mxUtils.write(options, mxResources.get('layers'));
  731. var zoomCheckBox = document.createElement('input');
  732. zoomCheckBox.setAttribute('type', 'checkbox');
  733. zoomCheckBox.style.marginLeft = '10px';
  734. options.appendChild(zoomCheckBox);
  735. mxUtils.write(options, mxResources.get('zoom'));
  736. zoomCheckBox.setAttribute('checked', 'checked');
  737. zoomCheckBox.defaultChecked = true;
  738. var pagesCheckBox = document.createElement('input');
  739. pagesCheckBox.setAttribute('type', 'checkbox');
  740. pagesCheckBox.style.marginLeft = '10px';
  741. if (editorUi.pages != null && editorUi.pages.length > 1)
  742. {
  743. pagesCheckBox.setAttribute('checked', 'checked');
  744. pagesCheckBox.defaultChecked = true;
  745. options.appendChild(pagesCheckBox);
  746. }
  747. mxUtils.write(options, mxResources.get('allPages'));
  748. div.appendChild(options);
  749. function update(force)
  750. {
  751. var s = [];
  752. // Scans shapes for stencils
  753. var stencilNames = new Object();
  754. var states = graph.view.states.getValues();
  755. function addName(name)
  756. {
  757. if (name != null)
  758. {
  759. var dot = name.lastIndexOf('.');
  760. if (dot > 0)
  761. {
  762. name = name.substring(dot + 1, name.length);
  763. }
  764. if (stencilNames[name] == null)
  765. {
  766. stencilNames[name] = true;
  767. s.push(name);
  768. }
  769. }
  770. }
  771. for (var i = 0; i < states.length; i++)
  772. {
  773. var state = states[i];
  774. var shape = state.style[mxConstants.STYLE_SHAPE];
  775. addName(mxStencilRegistry.getBasenameForStencil(shape));
  776. // Adds package names for markers in edges
  777. if (state.view.graph.model.isEdge(state.cell))
  778. {
  779. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_STARTARROW]));
  780. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_ENDARROW]));
  781. }
  782. }
  783. var data = {};
  784. if (borderColorInput.value != '' && borderColorInput.value != mxConstants.NONE)
  785. {
  786. data.highlight = borderColorInput.value;
  787. }
  788. if (!lightboxCheckBox.checked)
  789. {
  790. data.lightbox = false;
  791. }
  792. data.nav = graph.foldingEnabled;
  793. var zoom = parseInt(zoomInput.value);
  794. if (!isNaN(zoom) && zoom != 100)
  795. {
  796. data.zoom = zoom / 100;
  797. }
  798. var tb = [];
  799. if (pagesCheckBox.checked)
  800. {
  801. tb.push('pages');
  802. data.resize = true;
  803. if (editorUi.pages != null && editorUi.currentPage != null)
  804. {
  805. data.page = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
  806. }
  807. }
  808. if (zoomCheckBox.checked)
  809. {
  810. tb.push('zoom');
  811. data.resize = true;
  812. }
  813. if (layersCheckBox.checked)
  814. {
  815. tb.push('layers');
  816. }
  817. if (tb.length > 0)
  818. {
  819. if (lightboxCheckBox)
  820. {
  821. tb.push('lightbox');
  822. }
  823. data.toolbar = tb.join(' ');
  824. }
  825. if (editCheckBox.checked)
  826. {
  827. if (urlInput.value != '')
  828. {
  829. data.edit = urlInput.value;
  830. }
  831. else
  832. {
  833. data.edit = '_blank';
  834. }
  835. }
  836. if (urlInput.value != '')
  837. {
  838. data.url = urlInput.value;
  839. }
  840. else
  841. {
  842. data.xml = editorUi.getFileData(true, null, null, null, null, !pagesCheckBox.checked);
  843. }
  844. textarea.value = '<div class="mxgraph" style="' +
  845. ((fitCheckBox.checked) ? 'max-width:100%;' : '') +
  846. ((tb != '') ? 'border:1px solid transparent;' : '') +
  847. '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>';
  848. var s2 = (s.length > 0) ? (((urlParams['dev'] == '1') ?
  849. 'https://test.draw.io/embed2.js?dev=1&s=' :
  850. 'https://www.draw.io/embed2.js?s=') + s.join(';')) :
  851. (((urlParams['dev'] == '1') ?
  852. 'https://test.draw.io/js/viewer.min.js' :
  853. 'https://www.draw.io/js/viewer.min.js'));
  854. textarea2.value = '<script type="text/javascript" src="' + s2 + '"></script>';
  855. textarea.focus();
  856. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  857. {
  858. textarea.select();
  859. }
  860. else
  861. {
  862. document.execCommand('selectAll', false, null);
  863. }
  864. };
  865. this.init = function()
  866. {
  867. update();
  868. };
  869. mxEvent.addListener(urlInput, 'change', update);
  870. mxEvent.addListener(borderColorInput, 'change', update);
  871. mxEvent.addListener(zoomInput, 'change', update);
  872. mxEvent.addListener(layersCheckBox, 'change', update);
  873. mxEvent.addListener(editCheckBox, 'change', update);
  874. mxEvent.addListener(fitCheckBox, 'change', update);
  875. mxEvent.addListener(lightboxCheckBox, 'change', update);
  876. mxEvent.addListener(zoomCheckBox, 'change', update);
  877. mxEvent.addListener(pagesCheckBox, 'change', update);
  878. var buttons = document.createElement('div');
  879. buttons.style.paddingTop = '20px';
  880. buttons.style.textAlign = 'right';
  881. if (!editorUi.isOffline())
  882. {
  883. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  884. {
  885. window.open('https://support.draw.io/pages/viewpage.action?pageId=12878123');
  886. });
  887. helpBtn.className = 'geBtn';
  888. buttons.appendChild(helpBtn);
  889. }
  890. // Loads forever in IE9
  891. if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
  892. (document.documentMode == null || document.documentMode > 9))
  893. {
  894. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  895. {
  896. var wnd = window.open();
  897. var doc = wnd.document;
  898. if (document.compatMode === 'CSS1Compat')
  899. {
  900. doc.writeln('<!DOCTYPE html>');
  901. }
  902. doc.writeln('<html>');
  903. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  904. '</title><meta charset="utf-8"></head>');
  905. doc.writeln('<body>');
  906. doc.writeln(textarea.value);
  907. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  908. if (direct)
  909. {
  910. doc.writeln(textarea2.value);
  911. }
  912. doc.writeln('</body>');
  913. doc.writeln('</html>');
  914. doc.close();
  915. // Adds script tag after closing page and delay to fix timing issues
  916. if (!direct)
  917. {
  918. var info = wnd.document.createElement('div');
  919. info.marginLeft = '26px';
  920. info.marginTop = '26px';
  921. mxUtils.write(info, mxResources.get('updatingDocument'));
  922. var img = wnd.document.createElement('img');
  923. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  924. '/' + IMAGE_PATH + '/spin.gif');
  925. img.style.marginLeft = '6px';
  926. info.appendChild(img);
  927. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  928. window.setTimeout(function()
  929. {
  930. var script = document.createElement('script');
  931. script.type = 'text/javascript';
  932. script.src = /<script.*?src="(.*?)"/.exec(textarea2.value)[1];
  933. doc.body.appendChild(script);
  934. info.parentNode.removeChild(info);
  935. }, 20);
  936. }
  937. });
  938. previewBtn.className = 'geBtn';
  939. buttons.appendChild(previewBtn);
  940. }
  941. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  942. {
  943. editorUi.hideDialog();
  944. });
  945. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  946. {
  947. textarea.focus();
  948. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  949. {
  950. textarea.select();
  951. }
  952. else
  953. {
  954. document.execCommand('selectAll', false, null);
  955. }
  956. document.execCommand('copy');
  957. editorUi.alert(mxResources.get('copiedToClipboard'));
  958. });
  959. buttons.appendChild(closeBtn);
  960. // Does not work in Safari and shows annoying dialog for IE11-
  961. if (!mxClient.IS_SF && document.documentMode == null)
  962. {
  963. buttons.appendChild(copyBtn);
  964. copyBtn.className = 'geBtn gePrimaryBtn';
  965. closeBtn.className = 'geBtn';
  966. }
  967. else
  968. {
  969. closeBtn.className = 'geBtn gePrimaryBtn';
  970. }
  971. div.appendChild(buttons);
  972. this.container = div;
  973. };
  974. /**
  975. * Constructs a new embed dialog
  976. */
  977. var EmbedSvgDialog = function(editorUi, isImage)
  978. {
  979. var file = editorUi.getCurrentFile();
  980. var div = document.createElement('div');
  981. var graph = editorUi.editor.graph;
  982. var bounds = graph.getGraphBounds();
  983. var scale = graph.view.scale;
  984. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  985. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  986. mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
  987. mxUtils.br(div);
  988. var textarea = document.createElement('textarea');
  989. textarea.style.marginTop = '6px';
  990. textarea.style.width = '550px';
  991. textarea.style.height = '280px';
  992. textarea.style.resize = 'none';
  993. div.appendChild(textarea);
  994. mxUtils.br(div);
  995. var options = document.createElement('div');
  996. options.style.paddingTop = '16px';
  997. options.style.textAlign = 'center';
  998. var fitCheckBox = document.createElement('input');
  999. fitCheckBox.setAttribute('type', 'checkbox');
  1000. fitCheckBox.setAttribute('checked', 'checked');
  1001. fitCheckBox.defaultChecked = true;
  1002. options.appendChild(fitCheckBox);
  1003. mxUtils.write(options, mxResources.get('fit'));
  1004. var shadowCheckBox = document.createElement('input');
  1005. shadowCheckBox.setAttribute('type', 'checkbox');
  1006. shadowCheckBox.style.marginLeft = '30px';
  1007. if (graph.shadowVisible)
  1008. {
  1009. shadowCheckBox.setAttribute('checked', 'checked');
  1010. shadowCheckBox.defaultChecked = true;
  1011. }
  1012. if (!isImage || editorUi.isExportToCanvas())
  1013. {
  1014. options.appendChild(shadowCheckBox);
  1015. mxUtils.write(options, mxResources.get('shadow'));
  1016. }
  1017. var imageCheckBox = document.createElement('input');
  1018. imageCheckBox.setAttribute('type', 'checkbox');
  1019. imageCheckBox.style.marginLeft = '30px';
  1020. if (!isImage)
  1021. {
  1022. options.appendChild(imageCheckBox);
  1023. mxUtils.write(options, mxResources.get('image'));
  1024. }
  1025. var retinaCheckBox = document.createElement('input');
  1026. retinaCheckBox.setAttribute('type', 'checkbox');
  1027. retinaCheckBox.style.marginLeft = '30px';
  1028. if (isImage)
  1029. {
  1030. options.appendChild(retinaCheckBox);
  1031. mxUtils.write(options, mxResources.get('retina'));
  1032. }
  1033. var lightboxCheckBox = document.createElement('input');
  1034. lightboxCheckBox.setAttribute('type', 'checkbox');
  1035. lightboxCheckBox.setAttribute('checked', 'checked');
  1036. lightboxCheckBox.defaultChecked = true;
  1037. lightboxCheckBox.style.marginLeft = '30px';
  1038. options.appendChild(lightboxCheckBox);
  1039. mxUtils.write(options, mxResources.get('lightbox'));
  1040. var layersCheckBox = document.createElement('input');
  1041. layersCheckBox.setAttribute('type', 'checkbox');
  1042. layersCheckBox.style.marginLeft = '30px';
  1043. var model = editorUi.editor.graph.getModel();
  1044. if (model.getChildCount(model.getRoot()) > 1)
  1045. {
  1046. layersCheckBox.setAttribute('checked', 'checked');
  1047. layersCheckBox.defaultChecked = true;
  1048. }
  1049. else
  1050. {
  1051. layersCheckBox.setAttribute('disabled', 'disabled');
  1052. }
  1053. options.appendChild(layersCheckBox);
  1054. mxUtils.write(options, mxResources.get('layers'));
  1055. div.appendChild(options);
  1056. function update(force)
  1057. {
  1058. if (isImage)
  1059. {
  1060. var bounds = editorUi.editor.graph.getGraphBounds();
  1061. function doUpdate(dataUri)
  1062. {
  1063. var onclick = ' ';
  1064. var css = '';
  1065. // Adds double click handling
  1066. if (lightboxCheckBox.checked)
  1067. {
  1068. // KNOWN: Message passing does not seem to work in IE11
  1069. onclick = " onclick=\"(function(img){if(img.wnd!=null&&!img.wnd.closed){img.wnd.focus();}else{var r=function(evt){if(evt.data=='ready'&&evt.source==img.wnd){img.wnd.postMessage(decodeURIComponent(" +
  1070. "img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0&edit=_blank" +
  1071. ((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
  1072. css += 'cursor:pointer;';
  1073. }
  1074. if (fitCheckBox.checked)
  1075. {
  1076. css += 'max-width:100%;';
  1077. }
  1078. var atts = '';
  1079. if (retinaCheckBox.checked)
  1080. {
  1081. atts = ' width="' + Math.round(bounds.width) + '" height="' + Math.round(bounds.height) + '"';
  1082. }
  1083. textarea.value = '<img src="' + dataUri + '"' + atts +
  1084. ((css != '') ? ' style="' + css + '"' : '') +
  1085. onclick + '/>';
  1086. textarea.focus();
  1087. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1088. {
  1089. textarea.select();
  1090. }
  1091. else
  1092. {
  1093. document.execCommand('selectAll', false, null);
  1094. }
  1095. };
  1096. if (editorUi.isExportToCanvas())
  1097. {
  1098. var scale = 1;
  1099. var ignoreSelection = true;
  1100. textarea.value = mxResources.get('updatingDocument');
  1101. editorUi.exportToCanvas(mxUtils.bind(this, function(canvas)
  1102. {
  1103. var xml = (lightboxCheckBox.checked) ? editorUi.getFileData(true) : null;
  1104. var data = editorUi.createPngDataUri(canvas, xml);
  1105. doUpdate(data);
  1106. }), null, null, null, mxUtils.bind(this, function(e)
  1107. {
  1108. textarea.value = '';
  1109. editorUi.handleError({message: mxResources.get('unknownError')});
  1110. }), null, true, (retinaCheckBox.checked) ? 2 : 1, null, shadowCheckBox.checked);
  1111. }
  1112. else
  1113. {
  1114. var data = editorUi.getFileData(true);
  1115. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  1116. {
  1117. textarea.value = mxResources.get('updatingDocument');
  1118. var size = '';
  1119. if (retinaCheckBox.checked)
  1120. {
  1121. size = '&w=' + Math.round(2 * bounds.width) +
  1122. '&h=' + Math.round(2 * bounds.height);
  1123. }
  1124. var embed = (lightboxCheckBox.checked) ? '1' : '0';
  1125. var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
  1126. '&base64=1&embedXml=' + embed + size + '&xml=' +
  1127. encodeURIComponent(data));
  1128. // LATER: Updates on each change, add a delay
  1129. req.send(mxUtils.bind(this, function()
  1130. {
  1131. if (req.getStatus() == 200)
  1132. {
  1133. doUpdate('data:image/png;base64,' + req.getText());
  1134. }
  1135. else
  1136. {
  1137. textarea.value = '';
  1138. editorUi.handleError({message: mxResources.get('unknownError')});
  1139. }
  1140. }));
  1141. }
  1142. else
  1143. {
  1144. textarea.value = '';
  1145. editorUi.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. var svgRoot = editorUi.editor.graph.getSvg();
  1152. // Keeps hashtag links on same page
  1153. var links = svgRoot.getElementsByTagName('a');
  1154. if (links != null)
  1155. {
  1156. for (var i = 0; i < links.length; i++)
  1157. {
  1158. var href = links[i].getAttribute('href');
  1159. if (href != null && href.charAt(0) == '#' &&
  1160. links[i].getAttribute('target') == '_blank')
  1161. {
  1162. links[i].removeAttribute('target');
  1163. }
  1164. }
  1165. }
  1166. if (lightboxCheckBox.checked)
  1167. {
  1168. svgRoot.setAttribute('content', editorUi.getFileData(true));
  1169. }
  1170. // Adds shadow filter
  1171. if (shadowCheckBox.checked)
  1172. {
  1173. editorUi.editor.addSvgShadow(svgRoot);
  1174. }
  1175. // SVG inside image tag
  1176. if (imageCheckBox.checked)
  1177. {
  1178. var onclick = ' ';
  1179. var css = '';
  1180. // Adds double click handling
  1181. if (lightboxCheckBox.checked)
  1182. {
  1183. // KNOWN: Message passing does not seem to work in IE11
  1184. onclick = "onclick=\"(function(img){if(img.wnd!=null&&!img.wnd.closed){img.wnd.focus();}else{var r=function(evt){if(evt.data=='ready'&&evt.source==img.wnd){img.wnd.postMessage(decodeURIComponent(" +
  1185. "img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0&edit=_blank" +
  1186. ((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
  1187. css += 'cursor:pointer;';
  1188. }
  1189. if (fitCheckBox.checked)
  1190. {
  1191. css += 'max-width:100%;';
  1192. }
  1193. // Images inside IMG don't seem to work so embed them all
  1194. editorUi.convertImages(svgRoot, function(svgRoot)
  1195. {
  1196. textarea.value = '<img src="' + editorUi.createSvgDataUri(mxUtils.getXml(svgRoot)) + '"' +
  1197. ((css != '') ? ' style="' + css + '"' : '') + onclick + '/>';
  1198. });
  1199. }
  1200. else
  1201. {
  1202. var css = '';
  1203. // Adds double click handling
  1204. if (lightboxCheckBox.checked)
  1205. {
  1206. // KNOWN: Message passing does not seem to work in IE11
  1207. var js = "(function(svg){var src=window.event.target||window.event.srcElement;" +
  1208. // Ignores link events
  1209. "while (src!=null&&src.nodeName.toLowerCase()!='a'){src=src.parentNode;}if(src==null)" +
  1210. // Focus existing lightbox
  1211. "{if(svg.wnd!=null&&!svg.wnd.closed){svg.wnd.focus();}else{var r=function(evt){" +
  1212. // Message handling
  1213. "if(evt.data=='ready'&&evt.source==svg.wnd){svg.wnd.postMessage(decodeURIComponent(" +
  1214. "svg.getAttribute('content')),'*');window.removeEventListener('message',r);}};" +
  1215. "window.addEventListener('message',r);" +
  1216. // Opens lightbox window
  1217. "svg.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0&edit=_blank" +
  1218. ((layersCheckBox.checked) ? '&layers=1' : '') + "');}}})(this);";
  1219. svgRoot.setAttribute('onclick', js);
  1220. css += 'cursor:pointer;';
  1221. }
  1222. // Adds responsive size
  1223. if (fitCheckBox.checked)
  1224. {
  1225. var w = parseInt(svgRoot.getAttribute('width'));
  1226. var h = parseInt(svgRoot.getAttribute('height'));
  1227. svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  1228. css += 'max-width:100%;max-height:' + h + 'px;';
  1229. svgRoot.removeAttribute('height');
  1230. }
  1231. if (css != '')
  1232. {
  1233. svgRoot.setAttribute('style', css);
  1234. }
  1235. textarea.value = mxUtils.getXml(svgRoot);
  1236. }
  1237. textarea.focus();
  1238. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1239. {
  1240. textarea.select();
  1241. }
  1242. else
  1243. {
  1244. document.execCommand('selectAll', false, null);
  1245. }
  1246. }
  1247. };
  1248. this.init = function()
  1249. {
  1250. update();
  1251. };
  1252. mxEvent.addListener(imageCheckBox, 'change', update);
  1253. mxEvent.addListener(retinaCheckBox, 'change', update);
  1254. mxEvent.addListener(shadowCheckBox, 'change', update);
  1255. mxEvent.addListener(fitCheckBox, 'change', update);
  1256. mxEvent.addListener(lightboxCheckBox, 'change', update);
  1257. mxEvent.addListener(layersCheckBox, 'change', update);
  1258. var buttons = document.createElement('div');
  1259. buttons.style.paddingTop = '18px';
  1260. buttons.style.textAlign = 'right';
  1261. if (!editorUi.isOffline() && !isImage)
  1262. {
  1263. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1264. {
  1265. window.open('https://support.draw.io/pages/viewpage.action?pageId=12222606');
  1266. });
  1267. helpBtn.className = 'geBtn';
  1268. buttons.appendChild(helpBtn);
  1269. }
  1270. // Loads forever in IE9
  1271. if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
  1272. (document.documentMode == null || document.documentMode > 9))
  1273. {
  1274. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  1275. {
  1276. var wnd = window.open();
  1277. var doc = wnd.document;
  1278. doc.writeln('<html><head><title>' + encodeURIComponent(mxResources.get('preview')) +
  1279. '</title><meta charset="utf-8"></head>' +
  1280. '<body>' + textarea.value + '</body></html>');
  1281. doc.close();
  1282. });
  1283. previewBtn.className = 'geBtn';
  1284. buttons.appendChild(previewBtn);
  1285. }
  1286. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1287. {
  1288. editorUi.hideDialog();
  1289. });
  1290. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  1291. {
  1292. textarea.focus();
  1293. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1294. {
  1295. textarea.select();
  1296. }
  1297. else
  1298. {
  1299. document.execCommand('selectAll', false, null);
  1300. }
  1301. document.execCommand('copy');
  1302. editorUi.alert(mxResources.get('copiedToClipboard'));
  1303. });
  1304. buttons.appendChild(closeBtn);
  1305. // Does not work in Safari and shows annoying dialog for IE11-
  1306. if (!mxClient.IS_SF && document.documentMode == null)
  1307. {
  1308. buttons.appendChild(copyBtn);
  1309. copyBtn.className = 'geBtn gePrimaryBtn';
  1310. closeBtn.className = 'geBtn';
  1311. }
  1312. else
  1313. {
  1314. closeBtn.className = 'geBtn gePrimaryBtn';
  1315. }
  1316. div.appendChild(buttons);
  1317. this.container = div;
  1318. };
  1319. /**
  1320. * Constructs a dialog for embedding the diagram in Google Sites.
  1321. */
  1322. var GoogleSitesDialog = function(editorUi)
  1323. {
  1324. var div = document.createElement('div');
  1325. var graph = editorUi.editor.graph;
  1326. var bounds = graph.getGraphBounds();
  1327. var scale = graph.view.scale;
  1328. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  1329. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  1330. mxUtils.write(div, mxResources.get('googleGadget') + ':');
  1331. mxUtils.br(div);
  1332. var gadgetInput = document.createElement('input');
  1333. gadgetInput.setAttribute('type', 'text');
  1334. gadgetInput.style.marginBottom = '8px';
  1335. gadgetInput.style.marginTop = '2px';
  1336. gadgetInput.style.width = '410px';
  1337. div.appendChild(gadgetInput);
  1338. mxUtils.br(div);
  1339. this.init = function()
  1340. {
  1341. gadgetInput.focus();
  1342. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1343. {
  1344. gadgetInput.select();
  1345. }
  1346. else
  1347. {
  1348. document.execCommand('selectAll', false, null);
  1349. }
  1350. };
  1351. mxUtils.write(div, mxResources.get('top') + ':');
  1352. var topInput = document.createElement('input');
  1353. topInput.setAttribute('type', 'text');
  1354. topInput.setAttribute('size', '4');
  1355. topInput.style.marginRight = '16px';
  1356. topInput.style.marginLeft = '4px';
  1357. topInput.value = x0;
  1358. div.appendChild(topInput);
  1359. mxUtils.write(div, mxResources.get('height') + ':');
  1360. var heightInput = document.createElement('input');
  1361. heightInput.setAttribute('type', 'text');
  1362. heightInput.setAttribute('size', '4');
  1363. heightInput.style.marginLeft = '4px';
  1364. heightInput.value = Math.ceil(bounds.height / scale);
  1365. div.appendChild(heightInput);
  1366. mxUtils.br(div);
  1367. var hr = document.createElement('hr');
  1368. hr.setAttribute('size', '1');
  1369. hr.style.marginBottom = '16px';
  1370. hr.style.marginTop = '16px';
  1371. div.appendChild(hr);
  1372. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
  1373. mxUtils.br(div);
  1374. var urlInput = document.createElement('input');
  1375. urlInput.setAttribute('type', 'text');
  1376. urlInput.setAttribute('size', '28');
  1377. urlInput.style.marginBottom = '8px';
  1378. urlInput.style.marginTop = '2px';
  1379. urlInput.style.width = '410px';
  1380. div.appendChild(urlInput);
  1381. mxUtils.br(div);
  1382. mxUtils.write(div, mxResources.get('borderWidth') + ':');
  1383. var borderInput = document.createElement('input');
  1384. borderInput.setAttribute('type', 'text');
  1385. borderInput.setAttribute('size', '3');
  1386. borderInput.style.marginBottom = '8px';
  1387. borderInput.style.marginLeft = '4px';
  1388. borderInput.value = '0';
  1389. div.appendChild(borderInput);
  1390. mxUtils.br(div);
  1391. var panCheckBox = document.createElement('input');
  1392. panCheckBox.setAttribute('type', 'checkbox');
  1393. panCheckBox.setAttribute('checked', 'checked');
  1394. panCheckBox.defaultChecked = true;
  1395. panCheckBox.style.marginLeft = '16px';
  1396. div.appendChild(panCheckBox);
  1397. mxUtils.write(div, mxResources.get('pan') + ' ');
  1398. var zoomCheckBox = document.createElement('input');
  1399. zoomCheckBox.setAttribute('type', 'checkbox');
  1400. zoomCheckBox.setAttribute('checked', 'checked');
  1401. zoomCheckBox.defaultChecked = true;
  1402. zoomCheckBox.style.marginLeft = '8px';
  1403. div.appendChild(zoomCheckBox);
  1404. mxUtils.write(div, mxResources.get('zoom') + ' ');
  1405. var editCheckBox = document.createElement('input');
  1406. editCheckBox.setAttribute('type', 'checkbox');
  1407. editCheckBox.style.marginLeft = '8px';
  1408. editCheckBox.setAttribute('title', window.location.href);
  1409. div.appendChild(editCheckBox);
  1410. mxUtils.write(div, mxResources.get('edit') + ' ');
  1411. var editBlankCheckBox = document.createElement('input');
  1412. editBlankCheckBox.setAttribute('type', 'checkbox');
  1413. editBlankCheckBox.style.marginLeft = '8px';
  1414. div.appendChild(editBlankCheckBox);
  1415. mxUtils.write(div, mxResources.get('asNew') + ' ');
  1416. mxUtils.br(div);
  1417. var resizeCheckBox = document.createElement('input');
  1418. resizeCheckBox.setAttribute('type', 'checkbox');
  1419. resizeCheckBox.setAttribute('checked', 'checked');
  1420. resizeCheckBox.defaultChecked = true;
  1421. resizeCheckBox.style.marginLeft = '16px';
  1422. div.appendChild(resizeCheckBox);
  1423. mxUtils.write(div, mxResources.get('resize') + ' ');
  1424. var fitCheckBox = document.createElement('input');
  1425. fitCheckBox.setAttribute('type', 'checkbox');
  1426. fitCheckBox.style.marginLeft = '8px';
  1427. div.appendChild(fitCheckBox);
  1428. mxUtils.write(div, mxResources.get('fit') + ' ');
  1429. var embedCheckBox = document.createElement('input');
  1430. embedCheckBox.setAttribute('type', 'checkbox');
  1431. embedCheckBox.style.marginLeft = '8px';
  1432. div.appendChild(embedCheckBox);
  1433. mxUtils.write(div, mxResources.get('embed') + ' ');
  1434. var node = null;
  1435. var s = '';
  1436. // Scans shapes for stencils
  1437. var stencilNames = new Object();
  1438. var states = graph.view.states.getValues();
  1439. for (var i = 0; i < states.length; i++)
  1440. {
  1441. var state = states[i];
  1442. var shape = state.style[mxConstants.STYLE_SHAPE];
  1443. var basename = mxStencilRegistry.getBasenameForStencil(shape);
  1444. if (basename != null)
  1445. {
  1446. if (stencilNames[basename] == null)
  1447. {
  1448. stencilNames[basename] = true;
  1449. s += basename + ';';
  1450. }
  1451. }
  1452. }
  1453. var file = editorUi.getCurrentFile();
  1454. function update()
  1455. {
  1456. var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1457. if (embedCheckBox.checked && urlInput.value != '')
  1458. {
  1459. var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  1460. var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
  1461. if (title != null)
  1462. {
  1463. gurl += '&title=' + encodeURIComponent(title);
  1464. }
  1465. if (s.length > 0)
  1466. {
  1467. gurl += '&s=' + s;
  1468. }
  1469. if (borderInput.value != '' && borderInput.value != '0')
  1470. {
  1471. gurl += '&border=' + borderInput.value;
  1472. }
  1473. if (heightInput.value != '')
  1474. {
  1475. gurl += '&height=' + heightInput.value;
  1476. }
  1477. gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
  1478. gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
  1479. gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
  1480. gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
  1481. gurl += '&x0=' + Number(topInput.value);
  1482. gurl += '&y0=' + y0;
  1483. if (graph.mathEnabled)
  1484. {
  1485. gurl += '&math=1';
  1486. }
  1487. if (editBlankCheckBox.checked)
  1488. {
  1489. gurl += '&edit=_blank';
  1490. }
  1491. else if (editCheckBox.checked)
  1492. {
  1493. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
  1494. }
  1495. gadgetInput.value = gurl;
  1496. }
  1497. else if (file.constructor == DriveFile || file.constructor == DropboxFile)
  1498. {
  1499. var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
  1500. if (urlInput.value != '')
  1501. {
  1502. gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
  1503. }
  1504. else
  1505. {
  1506. gurl += file.getHash().substring(1);
  1507. if (file.constructor == DropboxFile)
  1508. {
  1509. gurl += '&type=2';
  1510. }
  1511. else
  1512. {
  1513. gurl += '&type=1';
  1514. }
  1515. }
  1516. if (title != null)
  1517. {
  1518. gurl += '&title=' + encodeURIComponent(title);
  1519. }
  1520. if (heightInput.value != '')
  1521. {
  1522. var h = parseInt(heightInput.value) + parseInt(topInput.value);
  1523. gurl += '&height=' + h;
  1524. }
  1525. gadgetInput.value = gurl;
  1526. }
  1527. else
  1528. {
  1529. gadgetInput.value = '';
  1530. }
  1531. };
  1532. // Tries to generate public image URL (only for Drive files)
  1533. update();
  1534. urlInput.setAttribute('placeholder', mxResources.get('loading') + '...');
  1535. editorUi.getPublicUrl(file, function(url)
  1536. {
  1537. urlInput.setAttribute('placeholder', '');
  1538. urlInput.value = (url != null) ? url : '';
  1539. update();
  1540. });
  1541. mxEvent.addListener(panCheckBox, 'change', update);
  1542. mxEvent.addListener(zoomCheckBox, 'change', update);
  1543. mxEvent.addListener(resizeCheckBox, 'change', update);
  1544. mxEvent.addListener(fitCheckBox, 'change', update);
  1545. mxEvent.addListener(editCheckBox, 'change', update);
  1546. mxEvent.addListener(editBlankCheckBox, 'change', update);
  1547. mxEvent.addListener(embedCheckBox, 'change', update);
  1548. mxEvent.addListener(heightInput, 'change', update);
  1549. mxEvent.addListener(topInput, 'change', update);
  1550. mxEvent.addListener(borderInput, 'change', update);
  1551. mxEvent.addListener(urlInput, 'change', update);
  1552. mxEvent.addListener(gadgetInput, 'click', function()
  1553. {
  1554. gadgetInput.focus();
  1555. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1556. {
  1557. gadgetInput.select();
  1558. }
  1559. else
  1560. {
  1561. document.execCommand('selectAll', false, null);
  1562. }
  1563. });
  1564. var buttons = document.createElement('div');
  1565. buttons.style.paddingTop = '12px';
  1566. buttons.style.textAlign = 'right';
  1567. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1568. {
  1569. editorUi.hideDialog();
  1570. });
  1571. closeBtn.className = 'geBtn gePrimaryBtn';
  1572. buttons.appendChild(closeBtn);
  1573. div.appendChild(buttons);
  1574. this.container = div;
  1575. };
  1576. /**
  1577. * Constructs a dialog for embedding the diagram in Google Sites.
  1578. */
  1579. var IframeDialog = function(editorUi, image, link)
  1580. {
  1581. var div = document.createElement('div');
  1582. var graph = editorUi.editor.graph;
  1583. var bounds = graph.getGraphBounds();
  1584. var scale = graph.view.scale;
  1585. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  1586. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  1587. mxUtils.write(div, mxResources.get((link) ? 'link' : 'mainEmbedNotice') + ': ');
  1588. mxUtils.br(div);
  1589. var iframeInput = document.createElement('input');
  1590. iframeInput.setAttribute('type', 'text');
  1591. iframeInput.style.marginBottom = '8px';
  1592. iframeInput.style.marginTop = '2px';
  1593. iframeInput.style.width = '410px';
  1594. div.appendChild(iframeInput);
  1595. mxUtils.br(div);
  1596. this.init = function()
  1597. {
  1598. if (iframeInput.getAttribute('disabled') != 'disabled')
  1599. {
  1600. iframeInput.focus();
  1601. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1602. {
  1603. iframeInput.select();
  1604. }
  1605. else
  1606. {
  1607. document.execCommand('selectAll', false, null);
  1608. }
  1609. }
  1610. };
  1611. var widthInput = document.createElement('input');
  1612. widthInput.setAttribute('type', 'text');
  1613. widthInput.style.marginRight = '16px';
  1614. widthInput.style.width = '60px';
  1615. widthInput.style.marginBottom = '8px';
  1616. widthInput.style.marginLeft = '4px';
  1617. widthInput.value = '100%';
  1618. if (!image && !link)
  1619. {
  1620. mxUtils.write(div, mxResources.get('width') + ':');
  1621. div.appendChild(widthInput);
  1622. }
  1623. var heightInput = document.createElement('input');
  1624. heightInput.setAttribute('type', 'text');
  1625. heightInput.style.width = '60px';
  1626. heightInput.style.marginLeft = '4px';
  1627. heightInput.value = (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / scale) + 2) + 'px';
  1628. var lightboxCheckBox = document.createElement('input');
  1629. lightboxCheckBox.setAttribute('type', 'checkbox');
  1630. var editCheckBox = document.createElement('input');
  1631. editCheckBox.setAttribute('type', 'checkbox');
  1632. var layersCheckBox = document.createElement('input');
  1633. layersCheckBox.setAttribute('type', 'checkbox');
  1634. if (!image)
  1635. {
  1636. if (!link)
  1637. {
  1638. mxUtils.write(div, mxResources.get('height') + ':');
  1639. div.appendChild(heightInput);
  1640. mxUtils.br(div);
  1641. }
  1642. lightboxCheckBox.setAttribute('checked', 'checked');
  1643. lightboxCheckBox.defaultChecked = true;
  1644. div.appendChild(lightboxCheckBox);
  1645. mxUtils.write(div, mxResources.get('lightbox'));
  1646. layersCheckBox.style.marginLeft = '16px';
  1647. var model = editorUi.editor.graph.getModel();
  1648. if (model.getChildCount(model.getRoot()) > 1)
  1649. {
  1650. layersCheckBox.setAttribute('checked', 'checked');
  1651. layersCheckBox.defaultChecked = true;
  1652. }
  1653. else
  1654. {
  1655. layersCheckBox.setAttribute('disabled', 'disabled');
  1656. }
  1657. div.appendChild(layersCheckBox);
  1658. mxUtils.write(div, mxResources.get('layers'));
  1659. editCheckBox.style.marginLeft = '16px';
  1660. editCheckBox.setAttribute('checked', 'checked');
  1661. editCheckBox.defaultChecked = true;
  1662. div.appendChild(editCheckBox);
  1663. mxUtils.write(div, mxResources.get('edit'));
  1664. mxUtils.br(div);
  1665. }
  1666. var hr = document.createElement('hr');
  1667. hr.setAttribute('size', '1');
  1668. hr.style.marginBottom = '16px';
  1669. hr.style.marginTop = '16px';
  1670. div.appendChild(hr);
  1671. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
  1672. mxUtils.br(div);
  1673. var urlInput = document.createElement('input');
  1674. urlInput.setAttribute('type', 'text');
  1675. urlInput.setAttribute('size', '28');
  1676. urlInput.style.marginBottom = '8px';
  1677. urlInput.style.marginTop = '2px';
  1678. urlInput.style.width = '410px';
  1679. div.appendChild(urlInput);
  1680. mxUtils.br(div);
  1681. var node = null;
  1682. var s = '';
  1683. // Scans shapes for stencils
  1684. var stencilNames = new Object();
  1685. var states = graph.view.states.getValues();
  1686. for (var i = 0; i < states.length; i++)
  1687. {
  1688. var state = states[i];
  1689. var shape = state.style[mxConstants.STYLE_SHAPE];
  1690. var basename = mxStencilRegistry.getBasenameForStencil(shape);
  1691. if (basename != null)
  1692. {
  1693. if (stencilNames[basename] == null)
  1694. {
  1695. stencilNames[basename] = true;
  1696. s += basename + ';';
  1697. }
  1698. }
  1699. }
  1700. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  1701. {
  1702. if (image || link)
  1703. {
  1704. window.open(iframeInput.value);
  1705. }
  1706. else
  1707. {
  1708. var wnd = window.open();
  1709. var doc = wnd.document;
  1710. if (document.compatMode === 'CSS1Compat')
  1711. {
  1712. doc.writeln('<!DOCTYPE html>');
  1713. }
  1714. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  1715. '</title><meta charset="utf-8"></head>');
  1716. doc.writeln('<body>');
  1717. doc.writeln(iframeInput.value);
  1718. doc.writeln('</body>');
  1719. doc.writeln('</html>');
  1720. doc.close();
  1721. }
  1722. });
  1723. previewBtn.className = 'geBtn';
  1724. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  1725. {
  1726. iframeInput.focus();
  1727. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1728. {
  1729. iframeInput.select();
  1730. }
  1731. else
  1732. {
  1733. document.execCommand('selectAll', false, null);
  1734. }
  1735. document.execCommand('copy');
  1736. editorUi.alert(mxResources.get('copiedToClipboard'));
  1737. });
  1738. var file = editorUi.getCurrentFile();
  1739. function update()
  1740. {
  1741. var title = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1742. if (link && file != null && (urlInput.value != '' || file.constructor == DriveFile ||
  1743. file.constructor == DropboxFile || file.constructor == OneDriveFile))
  1744. {
  1745. previewBtn.removeAttribute('disabled');
  1746. copyBtn.removeAttribute('disabled');
  1747. var gurl = 'https://www.draw.io/?chrome=0';
  1748. if (lightboxCheckBox.checked)
  1749. {
  1750. gurl += '&lightbox=1';
  1751. }
  1752. if (editCheckBox.checked)
  1753. {
  1754. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities('https://www.draw.io/#' + file.getHash()));
  1755. }
  1756. if (graph.foldingEnabled)
  1757. {
  1758. gurl += '&nav=1';
  1759. }
  1760. if (layersCheckBox.checked)
  1761. {
  1762. gurl += '&layers=1';
  1763. }
  1764. if (urlInput.value != '')
  1765. {
  1766. gurl += '&url=' + encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  1767. }
  1768. else
  1769. {
  1770. gurl += '#' + file.getHash();
  1771. }
  1772. iframeInput.value = gurl;
  1773. iframeInput.removeAttribute('disabled');
  1774. }
  1775. else if (urlInput.value != '')
  1776. {
  1777. previewBtn.removeAttribute('disabled');
  1778. copyBtn.removeAttribute('disabled');
  1779. var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  1780. if (image)
  1781. {
  1782. var gurl = EXPORT_URL + '?format=png&url=' + encUrl;
  1783. iframeInput.value = gurl;
  1784. }
  1785. else
  1786. {
  1787. var gurl = 'https://www.draw.io/?chrome=0';
  1788. if (lightboxCheckBox.checked)
  1789. {
  1790. gurl += '&lightbox=1';
  1791. }
  1792. if (editCheckBox.checked)
  1793. {
  1794. gurl += '&edit=' + encUrl;
  1795. }
  1796. if (graph.foldingEnabled)
  1797. {
  1798. gurl += '&nav=1';
  1799. }
  1800. if (layersCheckBox.checked)
  1801. {
  1802. gurl += '&layers=1';
  1803. }
  1804. gurl += '&url=' + encUrl;
  1805. iframeInput.value = '<iframe frameborder="0" style="width:' + widthInput.value + ';height:' +
  1806. heightInput.value + '" src="' + gurl + '"></iframe>';
  1807. }
  1808. iframeInput.removeAttribute('disabled');
  1809. }
  1810. else if (!image && !link && file != null && (file.constructor == DriveFile ||
  1811. file.constructor == DropboxFile || file.constructor == OneDriveFile))
  1812. {
  1813. previewBtn.removeAttribute('disabled');
  1814. copyBtn.removeAttribute('disabled');
  1815. var gurl = 'https://www.draw.io/?chrome=0';
  1816. if (lightboxCheckBox.checked)
  1817. {
  1818. gurl += '&lightbox=1';
  1819. }
  1820. if (editCheckBox.checked)
  1821. {
  1822. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities('https://www.draw.io/#' + file.getHash()));
  1823. }
  1824. if (graph.foldingEnabled)
  1825. {
  1826. gurl += '&nav=1';
  1827. }
  1828. if (layersCheckBox.checked)
  1829. {
  1830. gurl += '&layers=1';
  1831. }
  1832. gurl += '#' + file.getHash();
  1833. iframeInput.value = '<iframe frameborder="0" style="width:' + widthInput.value + ';height:' +
  1834. heightInput.value + '" src="' + gurl + '"></iframe>';
  1835. iframeInput.removeAttribute('disabled');
  1836. }
  1837. else
  1838. {
  1839. previewBtn.setAttribute('disabled', 'disabled');
  1840. copyBtn.setAttribute('disabled', 'disabled');
  1841. iframeInput.value = mxResources.get('invalidPublicUrl');
  1842. iframeInput.setAttribute('disabled', 'disabled');
  1843. }
  1844. };
  1845. // Tries to generate public image URL (only for Drive files)
  1846. update();
  1847. urlInput.setAttribute('placeholder', mxResources.get('loading') + '...');
  1848. editorUi.getPublicUrl(file, function(url)
  1849. {
  1850. urlInput.setAttribute('placeholder', '');
  1851. urlInput.value = (url != null) ? url : '';
  1852. update();
  1853. });
  1854. mxEvent.addListener(widthInput, 'change', update);
  1855. mxEvent.addListener(heightInput, 'change', update);
  1856. mxEvent.addListener(layersCheckBox, 'change', update);
  1857. mxEvent.addListener(lightboxCheckBox, 'change', update);
  1858. mxEvent.addListener(editCheckBox, 'change', update);
  1859. mxEvent.addListener(urlInput, 'change', update);
  1860. mxEvent.addListener(iframeInput, 'click', function()
  1861. {
  1862. iframeInput.focus();
  1863. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1864. {
  1865. iframeInput.select();
  1866. }
  1867. else
  1868. {
  1869. document.execCommand('selectAll', false, null);
  1870. }
  1871. });
  1872. var buttons = document.createElement('div');
  1873. buttons.style.paddingTop = '12px';
  1874. buttons.style.textAlign = 'right';
  1875. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1876. {
  1877. editorUi.hideDialog();
  1878. });
  1879. if (image || (!mxClient.IS_QUIRKS && !navigator.standalone &&
  1880. (!window.chrome || !chrome.app || !chrome.app.runtime) &&
  1881. (document.documentMode == null || document.documentMode >= 9)))
  1882. {
  1883. buttons.appendChild(previewBtn);
  1884. }
  1885. buttons.appendChild(closeBtn);
  1886. // Does not work in Safari and shows annoying dialog for IE11-
  1887. if (!mxClient.IS_SF && document.documentMode == null)
  1888. {
  1889. buttons.appendChild(copyBtn);
  1890. copyBtn.className = 'geBtn gePrimaryBtn';
  1891. closeBtn.className = 'geBtn';
  1892. }
  1893. else
  1894. {
  1895. closeBtn.className = 'geBtn gePrimaryBtn';
  1896. }
  1897. div.appendChild(buttons);
  1898. this.container = div;
  1899. };
  1900. /**
  1901. * Constructs a new parse dialog.
  1902. */
  1903. var CreateGraphDialog = function(editorUi, title, type)
  1904. {
  1905. var div = document.createElement('div');
  1906. div.style.textAlign = 'right';
  1907. this.init = function()
  1908. {
  1909. var container = document.createElement('div');
  1910. container.style.position = 'relative';
  1911. container.style.border = '1px solid gray';
  1912. container.style.width = '100%';
  1913. container.style.height = '360px';
  1914. container.style.overflow = 'hidden';
  1915. container.style.marginBottom = '16px';
  1916. mxEvent.disableContextMenu(container);
  1917. div.appendChild(container);
  1918. var graph = new Graph(container);
  1919. graph.setCellsCloneable(true);
  1920. graph.setPanning(true);
  1921. graph.setAllowDanglingEdges(false);
  1922. graph.connectionHandler.select = false;
  1923. graph.view.setTranslate(20, 20);
  1924. graph.border = 20;
  1925. graph.panningHandler.useLeftButtonForPanning = true;
  1926. var vertexStyle = 'rounded=1;';
  1927. var edgeStyle = 'curved=1;';
  1928. var startStyle = 'ellipse';
  1929. // FIXME: Does not work in iPad
  1930. var mxCellRendererInstallCellOverlayListeners = mxCellRenderer.prototype.installCellOverlayListeners;
  1931. graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
  1932. {
  1933. mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
  1934. mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
  1935. {
  1936. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1937. });
  1938. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  1939. {
  1940. mxEvent.addListener(shape.node, 'touchstart', function (evt)
  1941. {
  1942. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1943. });
  1944. }
  1945. };
  1946. graph.getAllConnectionConstraints = function()
  1947. {
  1948. return null;
  1949. };
  1950. // Keeps highlight behind overlays
  1951. graph.connectionHandler.marker.highlight.keepOnTop = false;
  1952. graph.connectionHandler.createEdgeState = function(me)
  1953. {
  1954. var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
  1955. return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  1956. };
  1957. // Gets the default parent for inserting new cells. This
  1958. // is normally the first child of the root (ie. layer 0).
  1959. var parent = graph.getDefaultParent();
  1960. var addOverlay = mxUtils.bind(this, function(cell)
  1961. {
  1962. // Creates a new overlay with an image and a tooltip
  1963. var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
  1964. overlay.cursor = 'hand';
  1965. // Installs a handler for clicks on the overlay
  1966. overlay.addListener(mxEvent.CLICK, function(sender, evt2)
  1967. {
  1968. // TODO: Add menu for picking next shape
  1969. graph.connectionHandler.reset();
  1970. graph.clearSelection();
  1971. var geo = graph.getCellGeometry(cell);
  1972. var v2;
  1973. executeLayout(function()
  1974. {
  1975. v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
  1976. addOverlay(v2);
  1977. graph.view.refresh(v2);
  1978. var e1 = graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
  1979. }, function()
  1980. {
  1981. graph.scrollCellToVisible(v2);
  1982. });
  1983. });
  1984. // FIXME: Does not work in iPad (inserts loop)
  1985. overlay.addListener('pointerdown', function(sender, eo)
  1986. {
  1987. var evt2 = eo.getProperty('event');
  1988. var state = eo.getProperty('state');
  1989. graph.popupMenuHandler.hideMenu();
  1990. graph.stopEditing(false);
  1991. var pt = mxUtils.convertPoint(graph.container,
  1992. mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
  1993. graph.connectionHandler.start(state, pt.x, pt.y);
  1994. graph.isMouseDown = true;
  1995. graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
  1996. mxEvent.consume(evt2);
  1997. });
  1998. // Sets the overlay for the cell in the graph
  1999. graph.addCellOverlay(cell, overlay);
  2000. });
  2001. // Adds cells to the model in a single step
  2002. graph.getModel().beginUpdate();
  2003. var v1;
  2004. try
  2005. {
  2006. v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
  2007. addOverlay(v1);
  2008. }
  2009. finally
  2010. {
  2011. // Updates the display
  2012. graph.getModel().endUpdate();
  2013. }
  2014. var layout;
  2015. if (type == 'horizontalTree')
  2016. {
  2017. layout = new mxCompactTreeLayout(graph);
  2018. layout.edgeRouting = false;
  2019. layout.levelDistance = 30;
  2020. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
  2021. }
  2022. else if (type == 'verticalTree')
  2023. {
  2024. layout = new mxCompactTreeLayout(graph, false);
  2025. layout.edgeRouting = false;
  2026. layout.levelDistance = 30;
  2027. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
  2028. }
  2029. else if (type == 'verticalFlow')
  2030. {
  2031. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
  2032. }
  2033. else if (type == 'horizontalFlow')
  2034. {
  2035. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
  2036. }
  2037. else if (type == 'organic')
  2038. {
  2039. layout = new mxFastOrganicLayout(graph, false);
  2040. layout.forceConstant = 80;
  2041. }
  2042. else if (type == 'circle')
  2043. {
  2044. layout = new mxCircleLayout(graph);
  2045. }
  2046. if (layout != null)
  2047. {
  2048. var executeLayout = function(change, post)
  2049. {
  2050. graph.getModel().beginUpdate();
  2051. try
  2052. {
  2053. if (change != null)
  2054. {
  2055. change();
  2056. }
  2057. layout.execute(graph.getDefaultParent(), v1);
  2058. }
  2059. catch (e)
  2060. {
  2061. throw e;
  2062. }
  2063. finally
  2064. {
  2065. // New API for animating graph layout results asynchronously
  2066. var morph = new mxMorphing(graph);
  2067. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  2068. {
  2069. graph.getModel().endUpdate();
  2070. if (post != null)
  2071. {
  2072. post();
  2073. }
  2074. }));
  2075. morph.startAnimation();
  2076. }
  2077. };
  2078. var edgeHandleConnect = mxEdgeHandler.prototype.connect;
  2079. mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  2080. {
  2081. edgeHandleConnect.apply(this, arguments);
  2082. executeLayout();
  2083. };
  2084. graph.resizeCell = function()
  2085. {
  2086. mxGraph.prototype.resizeCell.apply(this, arguments);
  2087. executeLayout();
  2088. };
  2089. graph.connectionHandler.addListener(mxEvent.CONNECT, function()
  2090. {
  2091. executeLayout();
  2092. });
  2093. }
  2094. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  2095. {
  2096. editorUi.confirm(mxResources.get('areYouSure'), function()
  2097. {
  2098. graph.destroy();
  2099. container.parentNode.removeChild(container);
  2100. editorUi.hideDialog();
  2101. });
  2102. })
  2103. cancelBtn.className = 'geBtn';
  2104. if (editorUi.editor.cancelFirst)
  2105. {
  2106. div.appendChild(cancelBtn);
  2107. }
  2108. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  2109. {
  2110. graph.clearCellOverlays();
  2111. var view = editorUi.editor.graph.view;
  2112. var bds = editorUi.editor.graph.getGraphBounds();
  2113. // Computes unscaled, untranslated graph bounds
  2114. var pt = editorUi.editor.graph.getInsertPoint();
  2115. var x = Math.max(pt.x, bds.x / view.scale - view.translate.x);
  2116. var y = Math.max(pt.y, editorUi.editor.graph.snap((bds.y + bds.height) /
  2117. view.scale - view.translate.y + 4 * graph.gridSize));
  2118. var cells = editorUi.editor.graph.importCells(graph.getModel().getChildren(graph.getDefaultParent()), x, y);
  2119. var temp = view.getBounds(cells);
  2120. temp.x -= view.translate.x;
  2121. temp.y -= view.translate.y;
  2122. editorUi.editor.graph.scrollRectToVisible(temp);
  2123. editorUi.editor.graph.setSelectionCells(cells);
  2124. graph.destroy();
  2125. container.parentNode.removeChild(container);
  2126. editorUi.hideDialog();
  2127. });
  2128. div.appendChild(okBtn);
  2129. okBtn.className = 'geBtn gePrimaryBtn';
  2130. if (!editorUi.editor.cancelFirst)
  2131. {
  2132. div.appendChild(cancelBtn);
  2133. }
  2134. };
  2135. this.container = div;
  2136. };
  2137. /**
  2138. *
  2139. */
  2140. CreateGraphDialog.prototype.connectImage = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjQ3OTk0QjMyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjQ3OTk0QjQyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyRjA0N0I2MjJENzExMUU1OEZBOEY0NUEyM0EyMUMzOSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGNDc5OTRCMjJENzIxMUU1OEZBOEY0NUEyM0EyMUMzOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjIf+MgAAATlSURBVHjanFZraFxFFD735u4ru3ls0yZG26ShgmJoKK1J2vhIYzBgRdtIURHyw1hQUH9IxIgI2h8iCEUF/1RRlNQYCsYfCTHVhiTtNolpZCEStqSC22xIsrs1bDfu7t37Gs/cO3Ozxs1DBw73zpk555vzmHNGgJ0NYatFgmNLYUHYUoHASMz5ijmgVLmxgfKCUiBxC4ACJAeSG8nb1dVVOTc3dyoSibwWDofPBIPBJzo7O8vpGtvjpDICGztxkciECpF2LS0tvZtOpwNkk5FKpcYXFxffwL1+JuPgllPj8nk1F6RoaGjoKCqZ5ApljZDZO4SMRA0SuG2QUJIQRV8HxMOM9vf3H0ZZH9Nhg20MMl2QkFwjIyNHWlpahtADnuUMwLcRHX5aNSBjCJYEsSSLUeLEbhGe3ytCmQtA1/XY+Pj46dbW1iDuyCJp9BC5ycBj4hoeHq5ra2sbw0Xn1ZgBZ+dVkA1Lc+6p0Ck2p0QS4Ox9EhwpEylYcmBg4LH29vYQLilIOt0u5FhDfevNZDI/u93uw6PLOrwTUtjxrbPYbhD42WgMrF8JmR894ICmCgnQjVe8Xu8pXEkzMJKbuo5oNPomBbm1ZsD7s2kwFA1JZ6QBUXWT1nmGNc/qoMgavDcrQzxjQGFh4aOYIJ0sFAXcEtui4uLiVjr5KpSBVFYDDZVrWUaKRRWSAYeK0fmKykgDXbVoNaPChRuyqdDv97czL5nXxQbq6empQmsaklkDBiNpSwFVrmr2P6UyicD5piI4f8wHh0oEm8/p4h8pyGiEWvVQd3e3nxtjAzU1NR2jP7NRBWQ8GbdEzzJAmc0V3RR4cI8Dvmwuhc8fKUFA0d6/ltHg5p+Kuaejo6OeY0jcNJ/PV00ZS0nFUoZRvvFS1bZFsKHCCQ2Pl8H0chY+C96B6ZUsrCQ1qKtwQVFRURW/QhIXMAzDPAZ6BgOr8tTa8dDxCmiYGApaJbJMxSzV+brE8pdgWkcpY5dbMF1AR9XH8/xu2ilef48bvn92n82ZwHh+8ssqTEXS9p7dHisiiURikd8PbpExNTU1UVNTA3V3Y7lC16n0gpB/NwpNcZjfa7dScC4Qh0kOQCwnlEgi3F/hMVl9fX0zvKrzSk2lfXjRhj0eT/2rvWG4+Pta3oJY7XfC3hInXAv/ldeFLx8shQ+eqQL0UAAz7ylkpej5eNZRVBWL6BU6ef14OYiY1oqyTtmsavr/5koaRucT1pzx+ZpL1+GV5nLutksUgIcmtwTRiuuVZXnU5XId7A2swJkfFsymRWC91hHg1Viw6x23+7vn9sPJ+j20BE1hCXqSWaNSQ8ScbknRZWxub1PGCw/fBV+c3AeijlUbY5bBjEqr9GuYZP4jP41WudGSC6erTRCqdGZm5i1WvXWeDHnbBCZGc2Nj4wBl/hZOwrmBBfgmlID1HmGJutHaF+tKoevp/XCgstDkjo2NtWKLuc6AVN4mNjY+s1XQxoenOoFuDPHGtnRbJj9ej5GvL0dI7+giuRyMk1giazc+DP6vgUDgOJVlOv7R+PJ12QIeL6SyeDz+Kfp8ZrNWjgDTsVjsQ7qXyTjztXJhm9ePxFLfMTg4eG9tbe1RTP9KFFYQfHliYmIS69kCC7jKYmKwxxD5P88tkVkqbPPcIps9t4T/+HjcuJ/s5BFJgf4WYABCtxGuxIZ90gAAAABJRU5ErkJggg==' :
  2141. IMAGE_PATH + '/handle-connect.png', 26, 26);
  2142. /**
  2143. * Constructs a new parse dialog.
  2144. */
  2145. var BackgroundImageDialog = function(editorUi, applyFn)
  2146. {
  2147. var div = document.createElement('div');
  2148. div.style.whiteSpace = 'nowrap';
  2149. var h3 = document.createElement('h2');
  2150. mxUtils.write(h3, mxResources.get('backgroundImage'));
  2151. h3.style.marginTop = '0px';
  2152. div.appendChild(h3);
  2153. mxUtils.write(div, mxResources.get('image') + ' ' + mxResources.get('url') + ':');
  2154. mxUtils.br(div);
  2155. var img = editorUi.editor.graph.backgroundImage;
  2156. var urlInput = document.createElement('input');
  2157. urlInput.setAttribute('type', 'text');
  2158. urlInput.style.marginTop = '4px';
  2159. urlInput.style.marginBottom = '4px';
  2160. urlInput.style.width = '350px';
  2161. urlInput.value = (img != null) ? img.src : '';
  2162. var resetting = false;
  2163. var urlChanged = function()
  2164. {
  2165. if (!resetting && urlInput.value != '' && !editorUi.isOffline())
  2166. {
  2167. editorUi.loadImage(mxUtils.trim(urlInput.value), function(img)
  2168. {
  2169. widthInput.value = img.width;
  2170. heightInput.value = img.height;
  2171. }, function()
  2172. {
  2173. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  2174. urlInput.value = '';
  2175. widthInput.value = '';
  2176. heightInput.value = '';
  2177. });
  2178. }
  2179. else
  2180. {
  2181. widthInput.value = '';
  2182. heightInput.value = '';
  2183. }
  2184. };
  2185. this.init = function()
  2186. {
  2187. urlInput.focus();
  2188. // Installs drag and drop handler for local images and links
  2189. if (Graph.fileSupport)
  2190. {
  2191. urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  2192. // Setup the dnd listeners
  2193. var dlg = div.parentNode;
  2194. var graph = editorUi.editor.graph;
  2195. var dropElt = null;
  2196. mxEvent.addListener(dlg, 'dragleave', function(evt)
  2197. {
  2198. if (dropElt != null)
  2199. {
  2200. dropElt.parentNode.removeChild(dropElt);
  2201. dropElt = null;
  2202. }
  2203. evt.stopPropagation();
  2204. evt.preventDefault();
  2205. });
  2206. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  2207. {
  2208. // IE 10 does not implement pointer-events so it can't have a drop highlight
  2209. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  2210. {
  2211. dropElt = editorUi.highlightElement(dlg);
  2212. }
  2213. evt.stopPropagation();
  2214. evt.preventDefault();
  2215. }));
  2216. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  2217. {
  2218. if (dropElt != null)
  2219. {
  2220. dropElt.parentNode.removeChild(dropElt);
  2221. dropElt = null;
  2222. }
  2223. if (evt.dataTransfer.files.length > 0)
  2224. {
  2225. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
  2226. {
  2227. urlInput.value = data;
  2228. urlChanged();
  2229. }, function()
  2230. {
  2231. // No post processing
  2232. }, function(file)
  2233. {
  2234. // Handles only images
  2235. return file.type.substring(0, 6) == 'image/';
  2236. }, function(queue)
  2237. {
  2238. // Invokes elements of queue in order
  2239. for (var i = 0; i < queue.length; i++)
  2240. {
  2241. queue[i]();
  2242. }
  2243. }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes);
  2244. }
  2245. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  2246. {
  2247. var uri = evt.dataTransfer.getData('text/uri-list');
  2248. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  2249. {
  2250. urlInput.value = decodeURIComponent(uri);
  2251. urlChanged();
  2252. }
  2253. }
  2254. evt.stopPropagation();
  2255. evt.preventDefault();
  2256. }), false);
  2257. }
  2258. };
  2259. div.appendChild(urlInput);
  2260. mxUtils.br(div);
  2261. mxUtils.br(div);
  2262. mxUtils.write(div, mxResources.get('width') + ':');
  2263. var widthInput = document.createElement('input');
  2264. widthInput.setAttribute('type', 'text');
  2265. widthInput.style.width = '60px';
  2266. widthInput.style.marginLeft = '4px';
  2267. widthInput.style.marginRight = '16px';
  2268. widthInput.value = (img != null) ? img.width : '';
  2269. div.appendChild(widthInput);
  2270. mxUtils.write(div, mxResources.get('height') + ':');
  2271. var heightInput = document.createElement('input');
  2272. heightInput.setAttribute('type', 'text');
  2273. heightInput.style.width = '60px';
  2274. heightInput.style.marginLeft = '4px';
  2275. heightInput.style.marginRight = '16px';
  2276. heightInput.value = (img != null) ? img.height : '';
  2277. div.appendChild(heightInput);
  2278. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  2279. {
  2280. urlInput.value = '';
  2281. widthInput.value = '';
  2282. heightInput.value = '';
  2283. resetting = false;
  2284. });
  2285. mxEvent.addListener(resetBtn, 'mousedown', function()
  2286. {
  2287. // Blocks processing a image URL while clicking reset
  2288. resetting = true;
  2289. });
  2290. mxEvent.addListener(resetBtn, 'touchstart', function()
  2291. {
  2292. // Blocks processing a image URL while clicking reset
  2293. resetting = true;
  2294. });
  2295. resetBtn.className = 'geBtn';
  2296. resetBtn.width = '100';
  2297. div.appendChild(resetBtn);
  2298. mxUtils.br(div);
  2299. mxEvent.addListener(urlInput, 'change', urlChanged);
  2300. ImageDialog.filePicked = function(data)
  2301. {
  2302. if (data.action == google.picker.Action.PICKED)
  2303. {
  2304. if (data.docs[0].thumbnails != null)
  2305. {
  2306. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  2307. if (thumb != null)
  2308. {
  2309. urlInput.value = thumb.url;
  2310. urlChanged();
  2311. }
  2312. }
  2313. }
  2314. urlInput.focus();
  2315. };
  2316. var btns = document.createElement('div');
  2317. btns.style.marginTop = '40px';
  2318. btns.style.textAlign = 'right';
  2319. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2320. {
  2321. editorUi.hideDialog();
  2322. });
  2323. cancelBtn.className = 'geBtn';
  2324. if (editorUi.editor.cancelFirst)
  2325. {
  2326. btns.appendChild(cancelBtn);
  2327. }
  2328. if (!editorUi.isOffline())
  2329. {
  2330. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2331. {
  2332. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  2333. {
  2334. // Creates one picker and reuses it to avoid polluting the DOM
  2335. if (editorUi.imageSearchPicker == null)
  2336. {
  2337. var picker = new google.picker.PickerBuilder()
  2338. .setLocale(mxLanguage)
  2339. .addView(google.picker.ViewId.IMAGE_SEARCH)
  2340. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  2341. editorUi.imageSearchPicker = picker.setCallback(function(data)
  2342. {
  2343. ImageDialog.filePicked(data);
  2344. }).build();
  2345. }
  2346. editorUi.imageSearchPicker.setVisible(true);
  2347. editorUi.movePickersToTop();
  2348. });
  2349. searchBtn.className = 'geBtn';
  2350. btns.appendChild(searchBtn);
  2351. if (editorUi.drive != null && urlParams['photos'] == '1')
  2352. {
  2353. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  2354. {
  2355. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  2356. {
  2357. editorUi.drive.checkToken(mxUtils.bind(this, function()
  2358. {
  2359. editorUi.spinner.stop();
  2360. // Creates one picker and reuses it to avoid polluting the DOM
  2361. if (editorUi.photoPicker == null)
  2362. {
  2363. var token = gapi.auth.getToken().access_token;
  2364. var picker = new google.picker.PickerBuilder()
  2365. .setAppId(editorUi.drive.appId)
  2366. .setLocale(mxLanguage)
  2367. .setOAuthToken(token)
  2368. .addView(google.picker.ViewId.PHOTOS)
  2369. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  2370. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  2371. editorUi.photoPicker = picker.setCallback(function(data)
  2372. {
  2373. ImageDialog.filePicked(data);
  2374. }).build();
  2375. }
  2376. editorUi.photoPicker.setVisible(true);
  2377. editorUi.movePickersToTop();
  2378. }));
  2379. }
  2380. });
  2381. gpBtn.className = 'geBtn';
  2382. btns.appendChild(gpBtn);
  2383. }
  2384. }
  2385. }
  2386. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  2387. {
  2388. editorUi.hideDialog();
  2389. applyFn((urlInput.value != '') ? new mxImage(mxUtils.trim(urlInput.value), widthInput.value, heightInput.value) : null);
  2390. });
  2391. applyBtn.className = 'geBtn gePrimaryBtn';
  2392. btns.appendChild(applyBtn);
  2393. if (!editorUi.editor.cancelFirst)
  2394. {
  2395. btns.appendChild(cancelBtn);
  2396. }
  2397. div.appendChild(btns);
  2398. this.container = div;
  2399. };
  2400. /**
  2401. * Constructs a new parse dialog.
  2402. */
  2403. var ParseDialog = function(editorUi, title)
  2404. {
  2405. function parse(text, asList)
  2406. {
  2407. var lines = text.split('\n');
  2408. if (asList)
  2409. {
  2410. if (lines.length > 0)
  2411. {
  2412. var graph = editorUi.editor.graph;
  2413. var listCell = new mxCell(lines[0], new mxGeometry(0, 0, 160, 26 + 4),
  2414. 'swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=none;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  2415. listCell.vertex = true;
  2416. var size = graph.getPreferredSizeForCell(listCell);
  2417. if (size != null && listCell.geometry.width < size.width + 10)
  2418. {
  2419. listCell.geometry.width = size.width + 10;
  2420. }
  2421. if (lines.length > 1)
  2422. {
  2423. for (var i = 1; i < lines.length; i++)
  2424. {
  2425. if (lines[i] == '--')
  2426. {
  2427. var divider = new mxCell('', new mxGeometry(0, 0, 40, 8), 'line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;');
  2428. divider.vertex = true;
  2429. listCell.geometry.height += divider.geometry.height;
  2430. listCell.insert(divider);
  2431. }
  2432. else if (lines[i].length > 0 && lines[i].charAt(0) != ';')
  2433. {
  2434. var field = new mxCell(lines[i], new mxGeometry(0, 0, 60, 26), 'text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;');
  2435. field.vertex = true;
  2436. var size = graph.getPreferredSizeForCell(field);
  2437. if (size != null && field.geometry.width < size.width)
  2438. {
  2439. field.geometry.width = size.width;
  2440. }
  2441. listCell.geometry.width = Math.max(listCell.geometry.width, field.geometry.width);
  2442. listCell.geometry.height += field.geometry.height;
  2443. listCell.insert(field);
  2444. }
  2445. }
  2446. }
  2447. var view = graph.view;
  2448. var bds = graph.getGraphBounds();
  2449. // Computes unscaled, untranslated graph bounds
  2450. var x = Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize);
  2451. var y = Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize);
  2452. graph.setSelectionCells(graph.importCells([listCell], x, y));
  2453. graph.scrollCellToVisible(graph.getSelectionCell());
  2454. }
  2455. }
  2456. else
  2457. {
  2458. var vertices = new Object();
  2459. var cells = [];
  2460. function getOrCreateVertex(id)
  2461. {
  2462. var vertex = vertices[id];
  2463. if (vertex == null)
  2464. {
  2465. vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30));
  2466. vertex.vertex = true;
  2467. vertices[id] = vertex;
  2468. cells.push(vertex);
  2469. }
  2470. return vertex;
  2471. };
  2472. for (var i = 0; i < lines.length; i++)
  2473. {
  2474. if (lines[i].charAt(0) != ';')
  2475. {
  2476. var values = lines[i].split('->');
  2477. if (values.length == 2)
  2478. {
  2479. var source = getOrCreateVertex(values[0]);
  2480. var target = getOrCreateVertex(values[1]);
  2481. var edge = new mxCell('', new mxGeometry());
  2482. edge.edge = true;
  2483. source.insertEdge(edge, true);
  2484. target.insertEdge(edge, false);
  2485. cells.push(edge);
  2486. }
  2487. }
  2488. }
  2489. if (cells.length > 0)
  2490. {
  2491. var container = document.createElement('div');
  2492. container.style.visibility = 'hidden';
  2493. document.body.appendChild(container);
  2494. var graph = new Graph(container);
  2495. graph.getModel().beginUpdate();
  2496. try
  2497. {
  2498. cells = graph.importCells(cells);
  2499. for (var i = 0; i < cells.length; i++)
  2500. {
  2501. if (graph.getModel().isVertex(cells[i]))
  2502. {
  2503. var size = graph.getPreferredSizeForCell(cells[i]);
  2504. cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
  2505. cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
  2506. }
  2507. }
  2508. var layout = new mxFastOrganicLayout(graph);
  2509. layout.disableEdgeStyle = false;
  2510. layout.forceConstant = 120;
  2511. layout.execute(graph.getDefaultParent());
  2512. graph.moveCells(cells, 20, 20);
  2513. }
  2514. finally
  2515. {
  2516. graph.getModel().endUpdate();
  2517. }
  2518. graph.clearCellOverlays();
  2519. var view = editorUi.editor.graph.view;
  2520. var bds = editorUi.editor.graph.getGraphBounds();
  2521. // Computes unscaled, untranslated graph bounds
  2522. var x = Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + graph.gridSize);
  2523. var y = Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize);
  2524. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(
  2525. graph.getModel().getChildren(graph.getDefaultParent()), x, y));
  2526. editorUi.editor.graph.scrollCellToVisible(editorUi.editor.graph.getSelectionCell());
  2527. graph.destroy();
  2528. container.parentNode.removeChild(container);
  2529. }
  2530. }
  2531. };
  2532. var div = document.createElement('div');
  2533. div.style.textAlign = 'right';
  2534. var textarea = document.createElement('textarea');
  2535. textarea.style.resize = 'none';
  2536. textarea.style.width = '100%';
  2537. textarea.style.height = '354px';
  2538. textarea.style.marginBottom = '16px';
  2539. var diagramCheckBox = document.createElement('input');
  2540. diagramCheckBox.setAttribute('type', 'checkbox');
  2541. function getDefaultValue()
  2542. {
  2543. return (!diagramCheckBox.checked) ?
  2544. 'Person\n-name: String\n-birthDate: Date\n--\n+getName(): String\n+setName(String): void\n+isBirthday(): boolean' :
  2545. ';Example:\na->b\nb->c\nc->a\n';
  2546. };
  2547. var defaultValue = getDefaultValue();
  2548. textarea.value = defaultValue;
  2549. div.appendChild(textarea);
  2550. this.init = function()
  2551. {
  2552. textarea.focus();
  2553. };
  2554. // Enables dropping files
  2555. if (Graph.fileSupport)
  2556. {
  2557. function handleDrop(evt)
  2558. {
  2559. evt.stopPropagation();
  2560. evt.preventDefault();
  2561. if (evt.dataTransfer.files.length > 0)
  2562. {
  2563. var file = evt.dataTransfer.files[0];
  2564. var reader = new FileReader();
  2565. reader.onload = function(e) { textarea.value = e.target.result; };
  2566. reader.readAsText(file);
  2567. }
  2568. };
  2569. function handleDragOver(evt)
  2570. {
  2571. evt.stopPropagation();
  2572. evt.preventDefault();
  2573. };
  2574. // Setup the dnd listeners.
  2575. textarea.addEventListener('dragover', handleDragOver, false);
  2576. textarea.addEventListener('drop', handleDrop, false);
  2577. }
  2578. div.appendChild(diagramCheckBox);
  2579. mxEvent.addListener(diagramCheckBox, 'change', function()
  2580. {
  2581. var newDefaultValue = getDefaultValue();
  2582. if (textarea.value.length == 0 || textarea.value == defaultValue)
  2583. {
  2584. defaultValue = newDefaultValue;
  2585. textarea.value = defaultValue;
  2586. }
  2587. });
  2588. var span = document.createElement('span');
  2589. mxUtils.write(span, ' ' + mxResources.get('diagram'));
  2590. span.style.marginRight = '10px';
  2591. div.appendChild(span);
  2592. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  2593. {
  2594. if (textarea.value == defaultValue)
  2595. {
  2596. editorUi.hideDialog();
  2597. }
  2598. else
  2599. {
  2600. editorUi.confirm(mxResources.get('areYouSure'), function()
  2601. {
  2602. editorUi.hideDialog();
  2603. });
  2604. }
  2605. });
  2606. cancelBtn.className = 'geBtn';
  2607. if (editorUi.editor.cancelFirst)
  2608. {
  2609. div.appendChild(cancelBtn);
  2610. }
  2611. var okBtn = mxUtils.button(mxResources.get('insert'), function()
  2612. {
  2613. editorUi.hideDialog();
  2614. parse(textarea.value, !diagramCheckBox.checked);
  2615. });
  2616. div.appendChild(okBtn);
  2617. okBtn.className = 'geBtn gePrimaryBtn';
  2618. if (!editorUi.editor.cancelFirst)
  2619. {
  2620. div.appendChild(cancelBtn);
  2621. }
  2622. this.container = div;
  2623. };
  2624. /**
  2625. * Constructs a new dialog for creating files from templates.
  2626. */
  2627. var NewDialog = function(editorUi, compact, showName, callback)
  2628. {
  2629. showName = (showName != null) ? showName : true;
  2630. var outer = document.createElement('div');
  2631. outer.style.height = '100%';
  2632. var header = document.createElement('div');
  2633. header.style.whiteSpace = 'nowrap';
  2634. header.style.height = '46px';
  2635. outer.appendChild(header);
  2636. var logo = document.createElement('img');
  2637. logo.setAttribute('border', '0');
  2638. logo.setAttribute('align', 'absmiddle');
  2639. logo.style.width = '40px';
  2640. logo.style.height = '40px';
  2641. logo.style.marginRight = '10px';
  2642. logo.style.paddingBottom = '4px';
  2643. if (editorUi.mode == App.MODE_GOOGLE)
  2644. {
  2645. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  2646. }
  2647. else if (editorUi.mode == App.MODE_DROPBOX)
  2648. {
  2649. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  2650. }
  2651. else if (editorUi.mode == App.MODE_ONEDRIVE)
  2652. {
  2653. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  2654. }
  2655. else if (editorUi.mode == App.MODE_BROWSER)
  2656. {
  2657. logo.src = IMAGE_PATH + '/osa_database.png';
  2658. }
  2659. else
  2660. {
  2661. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  2662. }
  2663. if (!compact && showName)
  2664. {
  2665. header.appendChild(logo);
  2666. }
  2667. if (showName)
  2668. {
  2669. mxUtils.write(header, ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
  2670. editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename')) + ':');
  2671. }
  2672. var ext = '.xml';
  2673. if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
  2674. {
  2675. ext = editorUi.drive.extension;
  2676. }
  2677. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  2678. {
  2679. ext = editorUi.dropbox.extension;
  2680. }
  2681. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  2682. {
  2683. ext = editorUi.oneDrive.extension;
  2684. }
  2685. var nameInput = document.createElement('input');
  2686. nameInput.setAttribute('value', editorUi.defaultFilename + ext);
  2687. nameInput.style.marginRight = '20px';
  2688. nameInput.style.marginLeft = '10px';
  2689. nameInput.style.width = (compact) ? '220px' : '450px';
  2690. this.init = function()
  2691. {
  2692. if (showName)
  2693. {
  2694. nameInput.focus();
  2695. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  2696. {
  2697. nameInput.select();
  2698. }
  2699. else
  2700. {
  2701. document.execCommand('selectAll', false, null);
  2702. }
  2703. }
  2704. };
  2705. if (showName)
  2706. {
  2707. header.appendChild(nameInput);
  2708. }
  2709. var templateLibs = null;
  2710. var templateXml = null;
  2711. var selectedElt = null;
  2712. function create()
  2713. {
  2714. if (callback)
  2715. {
  2716. editorUi.hideDialog();
  2717. callback(templateXml);
  2718. }
  2719. else
  2720. {
  2721. var title = nameInput.value;
  2722. if (title != null && title.length > 0)
  2723. {
  2724. var tempMode = (editorUi.mode == App.MODE_ONEDRIVE || (editorUi.mode == App.MODE_GOOGLE &&
  2725. (editorUi.stateArg == null || editorUi.stateArg.folderId == null))) ? editorUi.mode : null;
  2726. editorUi.pickFolder(tempMode, function(folderId)
  2727. {
  2728. editorUi.createFile(title, templateXml, (templateLibs != null && templateLibs.length > 0) ? templateLibs : null, null, function()
  2729. {
  2730. editorUi.hideDialog();
  2731. }, null, folderId);
  2732. }, tempMode != App.MODE_GOOGLE);
  2733. }
  2734. }
  2735. };
  2736. var createButton = mxUtils.button(mxResources.get('create'), function()
  2737. {
  2738. create();
  2739. });
  2740. createButton.className = 'geBtn gePrimaryBtn';
  2741. var div = document.createElement('div');
  2742. div.style.border = '1px solid #d3d3d3';
  2743. div.style.position = 'absolute';
  2744. div.style.left = '160px';
  2745. div.style.right = '34px';
  2746. div.style.top = (showName) ? '72px' : '40px';
  2747. div.style.bottom = '76px';
  2748. div.style.margin = '6px 0 0 -1px';
  2749. div.style.padding = '6px';
  2750. div.style.overflow = 'auto';
  2751. var list = document.createElement('div');
  2752. list.style.cssText = 'position:absolute;left:30px;width:128px;top:72px;bottom:76px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
  2753. if (!showName)
  2754. {
  2755. list.style.top = '40px';
  2756. }
  2757. var w = 140;
  2758. var h = 140;
  2759. function selectElement(elt, xml, libs)
  2760. {
  2761. if (selectedElt != null)
  2762. {
  2763. selectedElt.style.backgroundColor = 'transparent';
  2764. selectedElt.style.border = '1px solid transparent';
  2765. }
  2766. templateXml = xml;
  2767. templateLibs = libs;
  2768. selectedElt = elt;
  2769. selectedElt.style.backgroundColor = '#e6eff8';
  2770. selectedElt.style.border = '1px solid #ccd9ea';
  2771. };
  2772. function addButton(url, libs, title, tooltip, select)
  2773. {
  2774. var elt = document.createElement('div');
  2775. elt.className = 'geTemplate';
  2776. elt.style.height = w + 'px';
  2777. elt.style.width = h + 'px';
  2778. if (tooltip != null && tooltip.length > 0)
  2779. {
  2780. elt.setAttribute('title', tooltip);
  2781. }
  2782. if (url != null && url.length > 0)
  2783. {
  2784. var png = url.substring(0, url.length - 4) + '.png';
  2785. elt.style.backgroundImage = 'url(' + TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png)';
  2786. elt.style.backgroundPosition = 'center center';
  2787. elt.style.backgroundRepeat = 'no-repeat';
  2788. var createIt = false;
  2789. mxEvent.addListener(elt, 'click', function(evt)
  2790. {
  2791. createButton.setAttribute('disabled', 'disabled');
  2792. elt.style.backgroundColor = 'transparent';
  2793. elt.style.border = '1px solid transparent';
  2794. mxUtils.get(TEMPLATE_PATH + '/' + url, mxUtils.bind(this, function(req)
  2795. {
  2796. if (req.getStatus() == 200)
  2797. {
  2798. createButton.removeAttribute('disabled');
  2799. selectElement(elt, req.getText(), libs);
  2800. if (createIt)
  2801. {
  2802. create();
  2803. }
  2804. }
  2805. }));
  2806. });
  2807. mxEvent.addListener(elt, 'dblclick', function(evt)
  2808. {
  2809. // Asynchronous double click handling after loading template
  2810. createIt = true;
  2811. });
  2812. }
  2813. else
  2814. {
  2815. elt.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle">' +
  2816. mxResources.get(title) + '</td></tr></table>';
  2817. if (select)
  2818. {
  2819. selectElement(elt);
  2820. }
  2821. mxEvent.addListener(elt, 'click', function(evt)
  2822. {
  2823. selectElement(elt);
  2824. });
  2825. mxEvent.addListener(elt, 'dblclick', function(evt)
  2826. {
  2827. create();
  2828. });
  2829. }
  2830. div.appendChild(elt);
  2831. };
  2832. var categories = {};
  2833. var categoryCount = 1;
  2834. // Adds local basic templates
  2835. categories['basic'] = [{title: 'blankDiagram', select: true}];
  2836. var templates = categories['basic'];
  2837. function initUi()
  2838. {
  2839. var i0 = 0;
  2840. // Dynamic loading
  2841. function addTemplates()
  2842. {
  2843. var first = true;
  2844. while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
  2845. {
  2846. var tmp = templates[i0++];
  2847. addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip, tmp.select);
  2848. first = false;
  2849. }
  2850. };
  2851. mxEvent.addListener(div, 'scroll', function(evt)
  2852. {
  2853. if (div.scrollTop + div.clientHeight >= div.scrollHeight)
  2854. {
  2855. addTemplates();
  2856. mxEvent.consume(evt);
  2857. }
  2858. });
  2859. var currentEntry = null;
  2860. for (var cat in categories)
  2861. {
  2862. var entry = document.createElement('div');
  2863. var label = mxResources.get(cat);
  2864. var templateList = categories[cat];
  2865. if (label == null)
  2866. {
  2867. label = cat.substring(0, 1).toUpperCase() + cat.substring(1);
  2868. }
  2869. if (label.length > 18)
  2870. {
  2871. label = label.substring(0, 18) + '&hellip;';
  2872. }
  2873. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;';
  2874. entry.setAttribute('title', label + ' (' + templateList.length + ')');
  2875. mxUtils.write(entry, entry.getAttribute('title'));
  2876. list.appendChild(entry);
  2877. if (currentEntry == null)
  2878. {
  2879. currentEntry = entry;
  2880. currentEntry.style.backgroundColor = '#ebf2f9';
  2881. }
  2882. (function(cat2, entry2)
  2883. {
  2884. mxEvent.addListener(entry, 'click', function()
  2885. {
  2886. if (currentEntry != entry2)
  2887. {
  2888. currentEntry.style.backgroundColor = '';
  2889. currentEntry = entry2;
  2890. currentEntry.style.backgroundColor = '#ebf2f9';
  2891. div.scrollTop = 0;
  2892. div.innerHTML = '';
  2893. i0 = 0;
  2894. templates = categories[cat2];
  2895. addTemplates();
  2896. }
  2897. });
  2898. })(cat, entry);
  2899. }
  2900. addTemplates();
  2901. }
  2902. if (!compact)
  2903. {
  2904. outer.appendChild(list);
  2905. outer.appendChild(div);
  2906. var indexLoaded = false;
  2907. mxUtils.get(TEMPLATE_PATH + '/index.xml', function(req)
  2908. {
  2909. // Workaround for index loaded 3 times in iOS offline mode
  2910. if (!indexLoaded)
  2911. {
  2912. indexLoaded = true;
  2913. var tmpDoc = req.getXml();
  2914. var node = tmpDoc.documentElement.firstChild;
  2915. while (node != null)
  2916. {
  2917. if (typeof(node.getAttribute) !== 'undefined')
  2918. {
  2919. var url = node.getAttribute('url');
  2920. if (url != null)
  2921. {
  2922. var slash = url.indexOf('/');
  2923. var category = url.substring(0, slash);
  2924. var list = categories[category];
  2925. if (list == null)
  2926. {
  2927. categoryCount++;
  2928. list = [];
  2929. categories[category] = list;
  2930. }
  2931. list.push({url: node.getAttribute('url'), libs: node.getAttribute('libs'),
  2932. title: node.getAttribute('title'), tooltip: node.getAttribute('url')});
  2933. }
  2934. }
  2935. node = node.nextSibling;
  2936. }
  2937. initUi();
  2938. }
  2939. });
  2940. }
  2941. mxEvent.addListener(nameInput, 'keypress', function(e)
  2942. {
  2943. if (e.keyCode == 13)
  2944. {
  2945. editorUi.hideDialog();
  2946. create();
  2947. }
  2948. });
  2949. var btns = document.createElement('div');
  2950. btns.style.marginTop = (compact) ? '4px' : '16px';
  2951. btns.style.textAlign = 'right';
  2952. btns.style.position = 'absolute';
  2953. btns.style.left = '40px';
  2954. btns.style.bottom = '30px';
  2955. btns.style.right = '40px';
  2956. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  2957. {
  2958. editorUi.hideDialog(true);
  2959. });
  2960. cancelBtn.className = 'geBtn';
  2961. if (editorUi.editor.cancelFirst)
  2962. {
  2963. btns.appendChild(cancelBtn);
  2964. }
  2965. if (!compact && !editorUi.isOffline() && showName)
  2966. {
  2967. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  2968. {
  2969. window.open('https://support.draw.io/display/DO/Creating+and+Opening+Files');
  2970. });
  2971. helpBtn.className = 'geBtn';
  2972. btns.appendChild(helpBtn);
  2973. }
  2974. if (!compact)
  2975. {
  2976. var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
  2977. {
  2978. var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
  2979. {
  2980. if (fileUrl != null && fileUrl.length > 0)
  2981. {
  2982. var url = editorUi.getUrl(window.location.pathname + '?mode=' + editorUi.mode +
  2983. '&title=' + encodeURIComponent(nameInput.value) +
  2984. '&create=' + encodeURIComponent(fileUrl));
  2985. if (editorUi.getCurrentFile() == null)
  2986. {
  2987. window.location.href = url;
  2988. }
  2989. else
  2990. {
  2991. window.openWindow(url);
  2992. }
  2993. }
  2994. }, mxResources.get('url'));
  2995. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2996. dlg.init();
  2997. });
  2998. fromTmpBtn.className = 'geBtn';
  2999. btns.appendChild(fromTmpBtn);
  3000. }
  3001. btns.appendChild(createButton);
  3002. if (!editorUi.editor.cancelFirst)
  3003. {
  3004. btns.appendChild(cancelBtn);
  3005. }
  3006. outer.appendChild(btns);
  3007. this.container = outer;
  3008. };
  3009. /**
  3010. * Constructs a dialog for creating new files from a template URL.
  3011. */
  3012. var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension,
  3013. allowBrowser, allowTab, helpLink, showDeviceButton)
  3014. {
  3015. overrideExtension = (overrideExtension != null) ? overrideExtension : true;
  3016. allowBrowser = (allowBrowser != null) ? allowBrowser : true;
  3017. var div = document.createElement('div');
  3018. var showButtons = true;
  3019. if (cancelFn == null)
  3020. {
  3021. editorUi.addLanguageMenu(div);
  3022. }
  3023. var h3 = document.createElement('h2');
  3024. mxUtils.write(h3, dlgTitle || mxResources.get('create'));
  3025. h3.style.marginTop = '0px';
  3026. h3.style.marginBottom = '24px';
  3027. div.appendChild(h3);
  3028. mxUtils.write(div, mxResources.get('filename') + ':');
  3029. var nameInput = document.createElement('input');
  3030. nameInput.setAttribute('value', title);
  3031. nameInput.style.width = '280px';
  3032. nameInput.style.marginLeft = '10px';
  3033. nameInput.style.marginBottom = '20px';
  3034. this.init = function()
  3035. {
  3036. nameInput.focus();
  3037. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  3038. {
  3039. nameInput.select();
  3040. }
  3041. else
  3042. {
  3043. document.execCommand('selectAll', false, null);
  3044. }
  3045. };
  3046. div.appendChild(nameInput);
  3047. mxUtils.br(div);
  3048. var buttons = document.createElement('div');
  3049. buttons.style.textAlign = 'center';
  3050. function addLogo(img, title, mode, clientName)
  3051. {
  3052. var button = document.createElement('a');
  3053. button.style.overflow = 'hidden';
  3054. var logo = document.createElement('img');
  3055. logo.src = img;
  3056. logo.setAttribute('border', '0');
  3057. logo.setAttribute('align', 'absmiddle');
  3058. logo.style.width = '60px';
  3059. logo.style.height = '60px';
  3060. logo.style.paddingBottom = '6px';
  3061. button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  3062. button.className = 'geBaseButton';
  3063. button.style.position = 'relative';
  3064. button.style.margin = '4px';
  3065. button.style.padding = '8px 8px 10px 8px';
  3066. button.style.whiteSpace = 'nowrap';
  3067. button.appendChild(logo);
  3068. // Workaround for quirks is a vertical list (limited to max 2 items)
  3069. if (mxClient.IS_QUIRKS)
  3070. {
  3071. button.style.cssFloat = 'left';
  3072. button.style.zoom = '1';
  3073. }
  3074. button.style.color = 'gray';
  3075. button.style.fontSize = '11px';
  3076. var label = document.createElement('div');
  3077. button.appendChild(label);
  3078. mxUtils.write(label, title);
  3079. function initButton()
  3080. {
  3081. mxEvent.addListener(button, 'click', function()
  3082. {
  3083. // Updates extension
  3084. change(mode);
  3085. create(mode);
  3086. });
  3087. };
  3088. // Supports lazy loading
  3089. if (clientName != null && editorUi[clientName] == null)
  3090. {
  3091. logo.style.visibility = 'hidden';
  3092. mxUtils.setOpacity(label, 10);
  3093. var size = 12;
  3094. var spinner = new Spinner({
  3095. lines: 12, // The number of lines to draw
  3096. length: size, // The length of each line
  3097. width: 5, // The line thickness
  3098. radius: 10, // The radius of the inner circle
  3099. rotate: 0, // The rotation offset
  3100. color: '#000', // #rgb or #rrggbb
  3101. speed: 1.5, // Rounds per second
  3102. trail: 60, // Afterglow percentage
  3103. shadow: false, // Whether to render a shadow
  3104. hwaccel: false, // Whether to use hardware acceleration
  3105. top: '40%',
  3106. zIndex: 2e9 // The z-index (defaults to 2000000000)
  3107. });
  3108. spinner.spin(button);
  3109. // Timeout after 30 secs
  3110. var timeout = window.setTimeout(function()
  3111. {
  3112. if (editorUi[clientName] == null)
  3113. {
  3114. spinner.stop();
  3115. button.style.display = 'none';
  3116. }
  3117. }, 30000);
  3118. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  3119. {
  3120. if (editorUi[clientName] != null)
  3121. {
  3122. window.clearTimeout(timeout);
  3123. mxUtils.setOpacity(label, 100);
  3124. logo.style.visibility = '';
  3125. spinner.stop();
  3126. initButton();
  3127. }
  3128. }));
  3129. }
  3130. else
  3131. {
  3132. initButton();
  3133. }
  3134. buttons.appendChild(button);
  3135. };
  3136. if (!showButtons)
  3137. {
  3138. mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
  3139. }
  3140. else
  3141. {
  3142. buttons.style.marginTop = '6px';
  3143. div.appendChild(buttons);
  3144. }
  3145. // Adds all papersize options
  3146. var serviceSelect = document.createElement('select');
  3147. serviceSelect.style.marginLeft = '10px';
  3148. if (typeof window.DriveClient === 'function')
  3149. {
  3150. var googleOption = document.createElement('option');
  3151. googleOption.setAttribute('value', App.MODE_GOOGLE);
  3152. mxUtils.write(googleOption, mxResources.get('googleDrive'));
  3153. serviceSelect.appendChild(googleOption);
  3154. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  3155. }
  3156. if (typeof window.DropboxClient === 'function')
  3157. {
  3158. var dropboxOption = document.createElement('option');
  3159. dropboxOption.setAttribute('value', App.MODE_DROPBOX);
  3160. mxUtils.write(dropboxOption, mxResources.get('dropbox'));
  3161. serviceSelect.appendChild(dropboxOption);
  3162. if (editorUi.mode == App.MODE_DROPBOX)
  3163. {
  3164. dropboxOption.setAttribute('selected', 'selected');
  3165. }
  3166. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  3167. }
  3168. if (typeof window.OneDriveClient === 'function')
  3169. {
  3170. var oneDriveOption = document.createElement('option');
  3171. oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
  3172. mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
  3173. serviceSelect.appendChild(oneDriveOption);
  3174. if (editorUi.mode == App.MODE_ONEDRIVE)
  3175. {
  3176. oneDriveOption.setAttribute('selected', 'selected');
  3177. }
  3178. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  3179. }
  3180. if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
  3181. (editorUi.getCurrentFile() != null && !mxClient.IS_IOS))
  3182. {
  3183. var deviceOption = document.createElement('option');
  3184. deviceOption.setAttribute('value', App.MODE_DEVICE);
  3185. mxUtils.write(deviceOption, mxResources.get('device'));
  3186. serviceSelect.appendChild(deviceOption);
  3187. if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
  3188. {
  3189. deviceOption.setAttribute('selected', 'selected');
  3190. }
  3191. if (showDeviceButton)
  3192. {
  3193. mxUtils.br(buttons);
  3194. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  3195. }
  3196. }
  3197. if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
  3198. {
  3199. var browserOption = document.createElement('option');
  3200. browserOption.setAttribute('value', App.MODE_BROWSER);
  3201. mxUtils.write(browserOption, mxResources.get('browser'));
  3202. serviceSelect.appendChild(browserOption);
  3203. if (editorUi.mode == App.MODE_BROWSER)
  3204. {
  3205. browserOption.setAttribute('selected', 'selected');
  3206. }
  3207. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  3208. }
  3209. function change(newMode)
  3210. {
  3211. if (overrideExtension)
  3212. {
  3213. var fn = nameInput.value;
  3214. var idx = fn.lastIndexOf('.');
  3215. if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
  3216. {
  3217. newMode = (newMode != null) ? newMode : serviceSelect.value;
  3218. var ext = '';
  3219. if (newMode == App.MODE_GOOGLE)
  3220. {
  3221. ext = editorUi.drive.extension;
  3222. }
  3223. else if (newMode == App.MODE_DROPBOX)
  3224. {
  3225. ext = editorUi.dropbox.extension;
  3226. }
  3227. else if (newMode == App.MODE_ONEDRIVE)
  3228. {
  3229. ext = editorUi.oneDrive.extension;
  3230. }
  3231. else if (newMode == App.MODE_DEVICE)
  3232. {
  3233. ext = '.xml';
  3234. }
  3235. if (idx >= 0)
  3236. {
  3237. fn = fn.substring(0, idx);
  3238. }
  3239. nameInput.value = fn + ext;
  3240. }
  3241. }
  3242. };
  3243. var btns = document.createElement('div');
  3244. btns.style.marginTop = (showButtons) ? '26px' : '38px';
  3245. btns.style.textAlign = (showButtons) ? 'center' : 'right';
  3246. if (!showButtons)
  3247. {
  3248. div.appendChild(serviceSelect);
  3249. mxEvent.addListener(serviceSelect, 'change', change);
  3250. change();
  3251. }
  3252. if (helpLink != null)
  3253. {
  3254. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  3255. {
  3256. window.open(helpLink);
  3257. });
  3258. helpBtn.className = 'geBtn';
  3259. btns.appendChild(helpBtn);
  3260. }
  3261. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3262. {
  3263. if (cancelFn != null)
  3264. {
  3265. cancelFn();
  3266. }
  3267. else
  3268. {
  3269. editorUi.fileLoaded(null);
  3270. editorUi.hideDialog();
  3271. window.close();
  3272. window.location.href = editorUi.getUrl();
  3273. }
  3274. });
  3275. cancelBtn.className = 'geBtn';
  3276. if (editorUi.editor.cancelFirst)
  3277. {
  3278. btns.appendChild(cancelBtn);
  3279. }
  3280. function create(mode)
  3281. {
  3282. var title = nameInput.value;
  3283. if (mode == null || (title != null && title.length > 0))
  3284. {
  3285. editorUi.hideDialog();
  3286. createFn(title, mode);
  3287. };
  3288. }
  3289. if (cancelFn == null)
  3290. {
  3291. var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
  3292. {
  3293. create(null);
  3294. });
  3295. laterBtn.className = 'geBtn';
  3296. btns.appendChild(laterBtn);
  3297. }
  3298. if (allowTab)
  3299. {
  3300. var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  3301. {
  3302. create('_blank');
  3303. });
  3304. openBtn.className = 'geBtn';
  3305. btns.appendChild(openBtn);
  3306. }
  3307. if (!mxClient.IS_IOS || !showButtons)
  3308. {
  3309. var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
  3310. {
  3311. create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
  3312. });
  3313. createBtn.className = 'geBtn gePrimaryBtn';
  3314. btns.appendChild(createBtn);
  3315. }
  3316. if (!editorUi.editor.cancelFirst)
  3317. {
  3318. btns.appendChild(cancelBtn);
  3319. }
  3320. mxEvent.addListener(nameInput, 'keypress', function(e)
  3321. {
  3322. if (e.keyCode == 13)
  3323. {
  3324. create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
  3325. }
  3326. else if (e.keyCode == 27)
  3327. {
  3328. editorUi.fileLoaded(null);
  3329. editorUi.hideDialog();
  3330. window.close();
  3331. }
  3332. });
  3333. div.appendChild(btns);
  3334. this.container = div;
  3335. };
  3336. /**
  3337. * Constructs a new popup dialog.
  3338. */
  3339. var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
  3340. {
  3341. hideDialog = (hideDialog != null) ? hideDialog : true;
  3342. var div = document.createElement('div');
  3343. div.style.textAlign = 'left';
  3344. mxUtils.write(div, mxResources.get('fileOpenLocation'));
  3345. mxUtils.br(div);
  3346. mxUtils.br(div);
  3347. var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
  3348. {
  3349. if (hideDialog)
  3350. {
  3351. editorUi.hideDialog();
  3352. }
  3353. if (fallback != null)
  3354. {
  3355. fallback();
  3356. }
  3357. });
  3358. replaceBtn.className = 'geBtn';
  3359. replaceBtn.style.marginBottom = '8px';
  3360. replaceBtn.style.width = '280px';
  3361. div.appendChild(replaceBtn);
  3362. mxUtils.br(div);
  3363. var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  3364. {
  3365. if (hideDialog)
  3366. {
  3367. editorUi.hideDialog();
  3368. }
  3369. if (pre != null)
  3370. {
  3371. pre();
  3372. }
  3373. window.open(url);
  3374. });
  3375. wndBtn.className = 'geBtn gePrimaryBtn';
  3376. wndBtn.style.width = replaceBtn.style.width;
  3377. div.appendChild(wndBtn);
  3378. mxUtils.br(div);
  3379. mxUtils.br(div);
  3380. mxUtils.write(div, mxResources.get('allowPopups'));
  3381. this.container = div;
  3382. };
  3383. /**
  3384. * Constructs a new image dialog.
  3385. */
  3386. var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri)
  3387. {
  3388. convertDataUri = (convertDataUri != null) ? convertDataUri : true;
  3389. var graph = editorUi.editor.graph;
  3390. var div = document.createElement('div');
  3391. mxUtils.write(div, title);
  3392. var inner = document.createElement('div');
  3393. inner.className = 'geTitle';
  3394. inner.style.backgroundColor = 'transparent';
  3395. inner.style.borderColor = 'transparent';
  3396. inner.style.whiteSpace = 'nowrap';
  3397. inner.style.textOverflow = 'clip';
  3398. inner.style.cursor = 'default';
  3399. if (!mxClient.IS_VML)
  3400. {
  3401. inner.style.paddingRight = '20px';
  3402. }
  3403. var linkInput = document.createElement('input');
  3404. linkInput.setAttribute('value', initialValue);
  3405. linkInput.setAttribute('type', 'text');
  3406. linkInput.style.marginTop = '6px';
  3407. var realWidth = (Graph.fileSupport) ? 420 : 340;
  3408. linkInput.style.width = realWidth + ((mxClient.IS_QUIRKS) ? 20 : -20) + 'px';
  3409. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  3410. linkInput.style.backgroundRepeat = 'no-repeat';
  3411. linkInput.style.backgroundPosition = '100% 50%';
  3412. linkInput.style.paddingRight = '14px';
  3413. var cross = document.createElement('div');
  3414. cross.setAttribute('title', mxResources.get('reset'));
  3415. cross.style.position = 'relative';
  3416. cross.style.left = '-16px';
  3417. cross.style.width = '12px';
  3418. cross.style.height = '14px';
  3419. cross.style.cursor = 'pointer';
  3420. // Workaround for inline-block not supported in IE
  3421. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  3422. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  3423. // Needed to block event transparency in IE
  3424. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  3425. mxEvent.addListener(cross, 'click', function()
  3426. {
  3427. linkInput.value = '';
  3428. linkInput.focus();
  3429. });
  3430. inner.appendChild(linkInput);
  3431. inner.appendChild(cross);
  3432. div.appendChild(inner);
  3433. var insertImage = function(newValue, w, h)
  3434. {
  3435. var dataUri = newValue.substring(0, 5) == 'data:';
  3436. if ((!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined')) &&
  3437. editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  3438. {
  3439. var maxSize = 520;
  3440. editorUi.loadImage(newValue, function(img)
  3441. {
  3442. editorUi.spinner.stop();
  3443. editorUi.hideDialog();
  3444. var s = (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
  3445. Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
  3446. // Handles special case of data URI which needs to be rewritten
  3447. // to be used in a cell style to remove the semicolon
  3448. if (convertDataUri)
  3449. {
  3450. newValue = editorUi.convertDataUri(newValue);
  3451. }
  3452. fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s));
  3453. }, function()
  3454. {
  3455. editorUi.spinner.stop();
  3456. fn(null);
  3457. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  3458. });
  3459. }
  3460. else
  3461. {
  3462. newValue = editorUi.convertDataUri(newValue);
  3463. w = (w == null) ? 120 : w;
  3464. h = (h == null) ? 100 : h;
  3465. editorUi.hideDialog();
  3466. fn(newValue, w, h);
  3467. }
  3468. };
  3469. var apply = function(newValue)
  3470. {
  3471. if (newValue != null && newValue.length > 0)
  3472. {
  3473. var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
  3474. // Reuses width and height of existing cell
  3475. if (geo != null)
  3476. {
  3477. insertImage(newValue, geo.width, geo.height);
  3478. }
  3479. else
  3480. {
  3481. insertImage(newValue);
  3482. }
  3483. }
  3484. else
  3485. {
  3486. editorUi.hideDialog();
  3487. fn(null);
  3488. }
  3489. };
  3490. this.init = function()
  3491. {
  3492. linkInput.focus();
  3493. // Installs drag and drop handler for local images and links
  3494. if (Graph.fileSupport)
  3495. {
  3496. linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  3497. // Setup the dnd listeners
  3498. var dlg = div.parentNode;
  3499. var graph = editorUi.editor.graph;
  3500. var dropElt = null;
  3501. mxEvent.addListener(dlg, 'dragleave', function(evt)
  3502. {
  3503. if (dropElt != null)
  3504. {
  3505. dropElt.parentNode.removeChild(dropElt);
  3506. dropElt = null;
  3507. }
  3508. evt.stopPropagation();
  3509. evt.preventDefault();
  3510. });
  3511. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  3512. {
  3513. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3514. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3515. {
  3516. dropElt = editorUi.highlightElement(dlg);
  3517. }
  3518. evt.stopPropagation();
  3519. evt.preventDefault();
  3520. }));
  3521. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  3522. {
  3523. if (dropElt != null)
  3524. {
  3525. dropElt.parentNode.removeChild(dropElt);
  3526. dropElt = null;
  3527. }
  3528. if (evt.dataTransfer.files.length > 0)
  3529. {
  3530. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  3531. {
  3532. apply(data);
  3533. }, function()
  3534. {
  3535. // No post processing
  3536. }, function(file)
  3537. {
  3538. // Handles only images
  3539. return file.type.substring(0, 6) == 'image/';
  3540. }, function(queue)
  3541. {
  3542. // Invokes elements of queue in order
  3543. for (var i = 0; i < queue.length; i++)
  3544. {
  3545. queue[i]();
  3546. }
  3547. }, !mxEvent.isControlDown(evt));
  3548. }
  3549. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3550. {
  3551. var uri = evt.dataTransfer.getData('text/uri-list');
  3552. if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
  3553. {
  3554. apply(decodeURIComponent(uri));
  3555. }
  3556. }
  3557. evt.stopPropagation();
  3558. evt.preventDefault();
  3559. }), false);
  3560. }
  3561. };
  3562. var btns = document.createElement('div');
  3563. btns.style.marginTop = (mxClient.IS_QUIRKS) ? '22px' : '14px';
  3564. btns.style.textAlign = 'right';
  3565. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  3566. {
  3567. // Just in case a spinner is spinning, has no effect otherwise
  3568. editorUi.spinner.stop();
  3569. editorUi.hideDialog();
  3570. });
  3571. cancelBtn.className = 'geBtn';
  3572. if (editorUi.editor.cancelFirst)
  3573. {
  3574. btns.appendChild(cancelBtn);
  3575. }
  3576. ImageDialog.filePicked = function(data)
  3577. {
  3578. if (data.action == google.picker.Action.PICKED)
  3579. {
  3580. if (data.docs[0].thumbnails != null)
  3581. {
  3582. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  3583. if (thumb != null)
  3584. {
  3585. linkInput.value = thumb.url;
  3586. }
  3587. }
  3588. }
  3589. linkInput.focus();
  3590. };
  3591. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  3592. {
  3593. if (Graph.fileSupport)
  3594. {
  3595. var fileInput = document.createElement('input');
  3596. fileInput.setAttribute('multiple', 'multiple');
  3597. fileInput.setAttribute('type', 'file');
  3598. if (document.documentMode == null)
  3599. {
  3600. mxEvent.addListener(fileInput, 'change', function(evt)
  3601. {
  3602. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  3603. {
  3604. apply(data);
  3605. }, function()
  3606. {
  3607. // No post processing
  3608. }, function(file)
  3609. {
  3610. // Handles only images
  3611. return file.type.substring(0, 6) == 'image/';
  3612. }, function(queue)
  3613. {
  3614. // Invokes elements of queue in order
  3615. for (var i = 0; i < queue.length; i++)
  3616. {
  3617. queue[i]();
  3618. }
  3619. }, true);
  3620. });
  3621. var btn = mxUtils.button(mxResources.get('open'), function()
  3622. {
  3623. fileInput.click();
  3624. });
  3625. btn.className = 'geBtn';
  3626. btns.appendChild(btn);
  3627. }
  3628. }
  3629. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  3630. {
  3631. // Creates one picker and reuses it to avoid polluting the DOM
  3632. if (editorUi.imageSearchPicker == null)
  3633. {
  3634. var picker = new google.picker.PickerBuilder()
  3635. .setLocale(mxLanguage)
  3636. .addView(google.picker.ViewId.IMAGE_SEARCH)
  3637. .enableFeature(google.picker.Feature.NAV_HIDDEN);
  3638. editorUi.imageSearchPicker = picker.setCallback(function(data)
  3639. {
  3640. ImageDialog.filePicked(data);
  3641. }).build();
  3642. }
  3643. editorUi.imageSearchPicker.setVisible(true);
  3644. editorUi.movePickersToTop();
  3645. });
  3646. searchBtn.className = 'geBtn';
  3647. btns.appendChild(searchBtn);
  3648. if (editorUi.drive != null && urlParams['photos'] == '1')
  3649. {
  3650. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  3651. {
  3652. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  3653. {
  3654. editorUi.drive.checkToken(mxUtils.bind(this, function()
  3655. {
  3656. editorUi.spinner.stop();
  3657. // Creates one picker and reuses it to avoid polluting the DOM
  3658. if (editorUi.photoPicker == null)
  3659. {
  3660. var token = gapi.auth.getToken().access_token;
  3661. var picker = new google.picker.PickerBuilder()
  3662. .setAppId(editorUi.drive.appId)
  3663. .setLocale(mxLanguage)
  3664. .setOAuthToken(token)
  3665. .addView(google.picker.ViewId.PHOTOS)
  3666. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  3667. .addView(google.picker.ViewId.PHOTO_UPLOAD);
  3668. editorUi.photoPicker = picker.setCallback(function(data)
  3669. {
  3670. ImageDialog.filePicked(data);
  3671. }).build();
  3672. }
  3673. editorUi.photoPicker.setVisible(true);
  3674. editorUi.movePickersToTop();
  3675. }));
  3676. }
  3677. });
  3678. gpBtn.className = 'geBtn';
  3679. btns.appendChild(gpBtn);
  3680. }
  3681. }
  3682. mxEvent.addListener(linkInput, 'keypress', function(e)
  3683. {
  3684. if (e.keyCode == 13)
  3685. {
  3686. apply(linkInput.value);
  3687. }
  3688. });
  3689. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  3690. {
  3691. apply(linkInput.value);
  3692. });
  3693. applyBtn.className = 'geBtn gePrimaryBtn';
  3694. btns.appendChild(applyBtn);
  3695. if (!editorUi.editor.cancelFirst)
  3696. {
  3697. btns.appendChild(cancelBtn);
  3698. }
  3699. // Shows drop icon in dialog background
  3700. if (Graph.fileSupport)
  3701. {
  3702. btns.style.marginTop = '120px';
  3703. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  3704. div.style.backgroundPosition = 'center 65%';
  3705. div.style.backgroundRepeat = 'no-repeat';
  3706. var bg = document.createElement('div');
  3707. bg.style.position = 'absolute';
  3708. bg.style.width = '420px';
  3709. bg.style.top = '58%';
  3710. bg.style.textAlign = 'center';
  3711. bg.style.fontSize = '18px';
  3712. bg.style.color = '#a0c3ff';
  3713. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  3714. div.appendChild(bg);
  3715. }
  3716. div.appendChild(btns);
  3717. this.container = div;
  3718. };
  3719. /**
  3720. * Constructs a new print dialog.
  3721. */
  3722. PrintDialog.prototype.create = function(editorUi)
  3723. {
  3724. var graph = editorUi.editor.graph;
  3725. var div = document.createElement('div');
  3726. var title = document.createElement('h3');
  3727. title.style.marginTop = '0px';
  3728. mxUtils.write(title, mxResources.get('print'));
  3729. div.appendChild(title);
  3730. var pageCount = 1;
  3731. var currentPage = 1;
  3732. // Pages
  3733. var pagesSection = document.createElement('div');
  3734. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  3735. var allPagesRadio = document.createElement('input');
  3736. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  3737. allPagesRadio.setAttribute('value', 'all');
  3738. allPagesRadio.setAttribute('type', 'radio');
  3739. allPagesRadio.setAttribute('name', 'pages-printdialog');
  3740. pagesSection.appendChild(allPagesRadio);
  3741. var span = document.createElement('span');
  3742. mxUtils.write(span, mxResources.get('printAllPages'));
  3743. pagesSection.appendChild(span);
  3744. mxUtils.br(pagesSection);
  3745. // Pages ... to ...
  3746. var pagesRadio = allPagesRadio.cloneNode(true);
  3747. allPagesRadio.setAttribute('checked', 'checked');
  3748. pagesRadio.setAttribute('value', 'range');
  3749. pagesSection.appendChild(pagesRadio);
  3750. var span = document.createElement('span');
  3751. mxUtils.write(span, mxResources.get('pages') + ':');
  3752. pagesSection.appendChild(span);
  3753. var pagesFromInput = document.createElement('input');
  3754. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  3755. pagesFromInput.setAttribute('value', '1');
  3756. pagesFromInput.setAttribute('type', 'number');
  3757. pagesFromInput.setAttribute('min', '1');
  3758. pagesFromInput.style.width = '50px';
  3759. pagesSection.appendChild(pagesFromInput);
  3760. var span = document.createElement('span');
  3761. mxUtils.write(span, mxResources.get('to'));
  3762. pagesSection.appendChild(span);
  3763. var pagesToInput = pagesFromInput.cloneNode(true);
  3764. pagesSection.appendChild(pagesToInput);
  3765. mxEvent.addListener(pagesFromInput, 'focus', function()
  3766. {
  3767. pagesRadio.checked = true;
  3768. });
  3769. mxEvent.addListener(pagesToInput, 'focus', function()
  3770. {
  3771. pagesRadio.checked = true;
  3772. });
  3773. function validatePageRange()
  3774. {
  3775. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  3776. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  3777. };
  3778. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  3779. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  3780. if (editorUi.pages != null)
  3781. {
  3782. pageCount = editorUi.pages.length;
  3783. if (editorUi.currentPage != null)
  3784. {
  3785. for (var i = 0; i < editorUi.pages.length; i++)
  3786. {
  3787. if (editorUi.currentPage == editorUi.pages[i])
  3788. {
  3789. currentPage = i + 1;
  3790. pagesFromInput.value = currentPage;
  3791. pagesToInput.value = currentPage;
  3792. break;
  3793. }
  3794. }
  3795. }
  3796. }
  3797. pagesFromInput.setAttribute('max', pageCount);
  3798. pagesToInput.setAttribute('max', pageCount);
  3799. if (pageCount > 1)
  3800. {
  3801. div.appendChild(pagesSection);
  3802. }
  3803. // Adjust to ...
  3804. var adjustSection = document.createElement('div');
  3805. adjustSection.style.marginBottom = '10px';
  3806. var adjustRadio = document.createElement('input');
  3807. adjustRadio.style.marginRight = '8px';
  3808. adjustRadio.setAttribute('value', 'adjust');
  3809. adjustRadio.setAttribute('type', 'radio');
  3810. adjustRadio.setAttribute('name', 'printZoom');
  3811. adjustSection.appendChild(adjustRadio);
  3812. var span = document.createElement('span');
  3813. mxUtils.write(span, mxResources.get('adjustTo'));
  3814. adjustSection.appendChild(span);
  3815. var zoomInput = document.createElement('input');
  3816. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  3817. zoomInput.setAttribute('value', '100 %');
  3818. zoomInput.style.width = '50px';
  3819. adjustSection.appendChild(zoomInput);
  3820. mxEvent.addListener(zoomInput, 'focus', function()
  3821. {
  3822. adjustRadio.checked = true;
  3823. });
  3824. div.appendChild(adjustSection);
  3825. // Fit to ...
  3826. var fitSection = pagesSection.cloneNode(false);
  3827. var fitRadio = adjustRadio.cloneNode(true);
  3828. fitRadio.setAttribute('value', 'fit');
  3829. adjustRadio.setAttribute('checked', 'checked');
  3830. var spanFitRadio = document.createElement('div');
  3831. spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
  3832. spanFitRadio.appendChild(fitRadio);
  3833. fitSection.appendChild(spanFitRadio);
  3834. var table = document.createElement('table');
  3835. table.style.display = 'inline-block';
  3836. var tbody = document.createElement('tbody');
  3837. var row1 = document.createElement('tr');
  3838. var row2 = row1.cloneNode(true);
  3839. var td1 = document.createElement('td');
  3840. var td2 = td1.cloneNode(true);
  3841. var td3 = td1.cloneNode(true);
  3842. var td4 = td1.cloneNode(true);
  3843. var td5 = td1.cloneNode(true);
  3844. var td6 = td1.cloneNode(true);
  3845. td1.style.textAlign = 'right';
  3846. td4.style.textAlign = 'right';
  3847. mxUtils.write(td1, mxResources.get('fitTo'));
  3848. var sheetsAcrossInput = document.createElement('input');
  3849. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  3850. sheetsAcrossInput.setAttribute('value', '1');
  3851. sheetsAcrossInput.setAttribute('min', '1');
  3852. sheetsAcrossInput.setAttribute('type', 'number');
  3853. sheetsAcrossInput.style.width = '40px';
  3854. td2.appendChild(sheetsAcrossInput);
  3855. var span = document.createElement('span');
  3856. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  3857. td3.appendChild(span);
  3858. mxUtils.write(td4, mxResources.get('fitToBy'));
  3859. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  3860. td5.appendChild(sheetsDownInput);
  3861. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  3862. {
  3863. fitRadio.checked = true;
  3864. });
  3865. mxEvent.addListener(sheetsDownInput, 'focus', function()
  3866. {
  3867. fitRadio.checked = true;
  3868. });
  3869. var span = document.createElement('span');
  3870. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  3871. td6.appendChild(span);
  3872. row1.appendChild(td1);
  3873. row1.appendChild(td2);
  3874. row1.appendChild(td3);
  3875. row2.appendChild(td4);
  3876. row2.appendChild(td5);
  3877. row2.appendChild(td6);
  3878. tbody.appendChild(row1);
  3879. tbody.appendChild(row2);
  3880. table.appendChild(tbody);
  3881. fitSection.appendChild(table);
  3882. div.appendChild(fitSection);
  3883. // Page scale ...
  3884. var pageScaleSection = document.createElement('div');
  3885. var span = document.createElement('div');
  3886. span.style.fontWeight = 'bold';
  3887. span.style.marginBottom = '12px';
  3888. mxUtils.write(span, mxResources.get('paperSize'));
  3889. pageScaleSection.appendChild(span);
  3890. var span = document.createElement('div');
  3891. span.style.marginBottom = '12px';
  3892. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  3893. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  3894. pageScaleSection.appendChild(span);
  3895. var span = document.createElement('span');
  3896. mxUtils.write(span, mxResources.get('pageScale'));
  3897. pageScaleSection.appendChild(span);
  3898. var pageScaleInput = document.createElement('input');
  3899. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  3900. pageScaleInput.setAttribute('value', '100 %');
  3901. pageScaleInput.style.width = '60px';
  3902. pageScaleSection.appendChild(pageScaleInput);
  3903. div.appendChild(pageScaleSection);
  3904. // Buttons
  3905. var buttons = document.createElement('div');
  3906. buttons.style.cssText = 'text-align:right;margin:42px 0 0 0;';
  3907. // Overall scale for print-out to account for print borders in dialogs etc
  3908. function preview(print)
  3909. {
  3910. var printScale = parseInt(pageScaleInput.value) / 100;
  3911. if (isNaN(printScale))
  3912. {
  3913. printScale = 1;
  3914. pageScaleInput.value = '100 %';
  3915. }
  3916. // Workaround to match available paper size in actual print output
  3917. printScale *= 0.75;
  3918. function printGraph(thisGraph, pv, forcePageBreaks)
  3919. {
  3920. // Negative coordinates are cropped or shifted if page visible
  3921. var gb = thisGraph.getGraphBounds();
  3922. var border = 0;
  3923. var x0 = 0;
  3924. var y0 = 0;
  3925. var pf = accessor.get();
  3926. var scale = 1 / thisGraph.pageScale;
  3927. var autoOrigin = fitRadio.checked;
  3928. if (autoOrigin)
  3929. {
  3930. var h = parseInt(sheetsAcrossInput.value);
  3931. var v = parseInt(sheetsDownInput.value);
  3932. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  3933. (pf.width * h) / (gb.width / thisGraph.view.scale));
  3934. }
  3935. else
  3936. {
  3937. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  3938. if (isNaN(scale))
  3939. {
  3940. printScale = 1 / thisGraph.pageScale;
  3941. zoomInput.value = '100 %';
  3942. }
  3943. }
  3944. // Applies print scale
  3945. pf = mxRectangle.fromRectangle(pf);
  3946. pf.width = Math.ceil(pf.width * printScale);
  3947. pf.height = Math.ceil(pf.height * printScale);
  3948. scale *= printScale;
  3949. // Starts at first visible page
  3950. if (!autoOrigin && thisGraph.pageVisible)
  3951. {
  3952. var layout = thisGraph.getPageLayout();
  3953. x0 -= layout.x * pf.width;
  3954. y0 -= layout.y * pf.height;
  3955. }
  3956. else
  3957. {
  3958. autoOrigin = true;
  3959. }
  3960. if (pv == null)
  3961. {
  3962. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  3963. pv.pageSelector = false;
  3964. pv.mathEnabled = false;
  3965. if (typeof(MathJax) !== 'undefined')
  3966. {
  3967. // Adds class to ignore if math is disabled
  3968. var printPreviewRenderPage = pv.renderPage;
  3969. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  3970. {
  3971. var result = printPreviewRenderPage.apply(this, arguments);
  3972. if (this.graph.mathEnabled)
  3973. {
  3974. this.mathEnabled = true;
  3975. }
  3976. else
  3977. {
  3978. result.className = 'geDisableMathJax';
  3979. }
  3980. return result;
  3981. };
  3982. }
  3983. pv.open(null, null, forcePageBreaks, true);
  3984. }
  3985. else
  3986. {
  3987. var bg = thisGraph.background;
  3988. if (bg == null || bg == '' || bg == mxConstants.NONE)
  3989. {
  3990. bg = '#ffffff';
  3991. }
  3992. pv.backgroundColor = bg;
  3993. pv.autoOrigin = autoOrigin;
  3994. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  3995. }
  3996. return pv;
  3997. };
  3998. var pagesFrom = pagesFromInput.value;
  3999. var pagesTo = pagesToInput.value;
  4000. var ignorePages = !allPagesRadio.checked;
  4001. var pv = null;
  4002. if (ignorePages)
  4003. {
  4004. ignorePages = pagesFrom == currentPage && pagesTo == currentPage;
  4005. }
  4006. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  4007. {
  4008. var i0 = 0;
  4009. var imax = editorUi.pages.length - 1;
  4010. if (!allPagesRadio.checked)
  4011. {
  4012. i0 = parseInt(pagesFrom) - 1;
  4013. imax = parseInt(pagesTo) - 1;
  4014. }
  4015. for (var i = i0; i <= imax; i++)
  4016. {
  4017. var page = editorUi.pages[i];
  4018. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  4019. if (tempGraph == null)
  4020. {
  4021. tempGraph = editorUi.createTemporaryGraph(graph.getStylesheet());
  4022. // Restores graph settings that are relevant for printing
  4023. var pageVisible = true;
  4024. var mathEnabled = false;
  4025. var bg = null;
  4026. var bgImage = null;
  4027. if (page.viewState == null && page.mapping == null)
  4028. {
  4029. // Workaround to extract view state from XML node
  4030. // This changes the state of the page and parses
  4031. // the XML for the graph model even if not needed.
  4032. if (page.root == null)
  4033. {
  4034. editorUi.updatePageRoot(page);
  4035. }
  4036. }
  4037. if (page.viewState != null)
  4038. {
  4039. pageVisible = page.viewState.pageVisible;
  4040. mathEnabled = page.viewState.mathEnabled;
  4041. bg = page.viewState.background;
  4042. bgImage = page.viewState.backgroundImage;
  4043. }
  4044. else if (page.mapping != null && page.mapping.diagramMap != null)
  4045. {
  4046. // Default pageVisible in realtime is true
  4047. mathEnabled = page.mapping.diagramMap.get('mathEnabled') != '0';
  4048. bg = page.mapping.diagramMap.get('background');
  4049. var temp = page.mapping.diagramMap.get('backgroundImage');
  4050. bgImage = (temp != null && temp.length > 0) ? JSON.parse(temp) : null;
  4051. }
  4052. tempGraph.background = bg;
  4053. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(bgImage.src, bgImage.width, bgImage.height) : null;
  4054. tempGraph.pageVisible = pageVisible;
  4055. tempGraph.mathEnabled = mathEnabled;
  4056. // Redirects placeholders to current page
  4057. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  4058. tempGraph.getGlobalVariable = function(name)
  4059. {
  4060. if (name == 'page')
  4061. {
  4062. return page.getName();
  4063. }
  4064. else if (name == 'pagenumber')
  4065. {
  4066. return i + 1;
  4067. }
  4068. return graphGetGlobalVariable.apply(this, arguments);
  4069. };
  4070. document.body.appendChild(tempGraph.container);
  4071. editorUi.updatePageRoot(page);
  4072. tempGraph.model.setRoot(page.root);
  4073. }
  4074. pv = printGraph(tempGraph, pv, i != imax);
  4075. if (tempGraph != graph)
  4076. {
  4077. tempGraph.container.parentNode.removeChild(tempGraph.container);
  4078. }
  4079. }
  4080. }
  4081. else
  4082. {
  4083. pv = printGraph(graph);
  4084. }
  4085. if (pv.mathEnabled)
  4086. {
  4087. var doc = pv.wnd.document;
  4088. doc.writeln('<script type="text/x-mathjax-config">');
  4089. doc.writeln('MathJax.Hub.Config({');
  4090. doc.writeln('messageStyle: "none",');
  4091. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  4092. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  4093. doc.writeln('TeX: {');
  4094. doc.writeln('extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  4095. doc.writeln('},');
  4096. // Ignores math in in-place editor
  4097. doc.writeln('tex2jax: {');
  4098. doc.writeln(' ignoreClass: "geDisableMathJax"');
  4099. doc.writeln('},');
  4100. doc.writeln('asciimath2jax: {');
  4101. doc.writeln(' ignoreClass: "geDisableMathJax"');
  4102. doc.writeln('}');
  4103. doc.writeln('});');
  4104. // Adds asynchronous printing when MathJax finished rendering
  4105. if (print)
  4106. {
  4107. doc.writeln('MathJax.Hub.Queue(function () {');
  4108. doc.writeln('window.print();');
  4109. doc.writeln('});');
  4110. }
  4111. doc.writeln('</script>');
  4112. doc.writeln('<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js"></script>');
  4113. }
  4114. pv.closeDocument();
  4115. if (!pv.mathEnabled && print)
  4116. {
  4117. PrintDialog.printPreview(pv);
  4118. }
  4119. };
  4120. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4121. {
  4122. editorUi.hideDialog();
  4123. });
  4124. cancelBtn.className = 'geBtn';
  4125. if (editorUi.editor.cancelFirst)
  4126. {
  4127. buttons.appendChild(cancelBtn);
  4128. }
  4129. if (!mxClient.IS_CHROMEAPP)
  4130. {
  4131. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  4132. {
  4133. editorUi.hideDialog();
  4134. preview(false);
  4135. });
  4136. previewBtn.className = 'geBtn';
  4137. buttons.appendChild(previewBtn);
  4138. }
  4139. var printBtn = mxUtils.button(mxResources.get((mxClient.IS_CHROMEAPP) ? 'ok' : 'print'), function()
  4140. {
  4141. editorUi.hideDialog();
  4142. preview(true);
  4143. });
  4144. printBtn.className = 'geBtn gePrimaryBtn';
  4145. buttons.appendChild(printBtn);
  4146. if (!editorUi.editor.cancelFirst)
  4147. {
  4148. buttons.appendChild(cancelBtn);
  4149. }
  4150. div.appendChild(buttons);
  4151. this.container = div;
  4152. };
  4153. /**
  4154. * Overrides link dialog to add Google Picker.
  4155. */
  4156. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  4157. {
  4158. var div = document.createElement('div');
  4159. mxUtils.write(div, mxResources.get('editLink') + ':');
  4160. var inner = document.createElement('div');
  4161. inner.className = 'geTitle';
  4162. inner.style.backgroundColor = 'transparent';
  4163. inner.style.borderColor = 'transparent';
  4164. inner.style.whiteSpace = 'nowrap';
  4165. inner.style.textOverflow = 'clip';
  4166. inner.style.cursor = 'default';
  4167. if (!mxClient.IS_VML)
  4168. {
  4169. inner.style.paddingRight = '20px';
  4170. }
  4171. var linkInput = document.createElement('input');
  4172. linkInput.setAttribute('value', initialValue);
  4173. linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
  4174. linkInput.setAttribute('type', 'text');
  4175. linkInput.style.marginTop = '6px';
  4176. linkInput.style.width = '400px';
  4177. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  4178. linkInput.style.backgroundRepeat = 'no-repeat';
  4179. linkInput.style.backgroundPosition = '100% 50%';
  4180. linkInput.style.paddingRight = '14px';
  4181. var cross = document.createElement('div');
  4182. cross.setAttribute('title', mxResources.get('reset'));
  4183. cross.style.position = 'relative';
  4184. cross.style.left = '-16px';
  4185. cross.style.width = '12px';
  4186. cross.style.height = '14px';
  4187. cross.style.cursor = 'pointer';
  4188. // Workaround for inline-block not supported in IE
  4189. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  4190. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  4191. // Needed to block event transparency in IE
  4192. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  4193. mxEvent.addListener(cross, 'click', function()
  4194. {
  4195. linkInput.value = '';
  4196. linkInput.focus();
  4197. });
  4198. inner.appendChild(linkInput);
  4199. inner.appendChild(cross);
  4200. div.appendChild(inner);
  4201. var mainBtn = mxUtils.button(btnLabel, function()
  4202. {
  4203. editorUi.hideDialog();
  4204. fn(linkInput.value, LinkDialog.selectedDocs);
  4205. });
  4206. mainBtn.className = 'geBtn gePrimaryBtn';
  4207. this.init = function()
  4208. {
  4209. linkInput.focus();
  4210. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  4211. {
  4212. linkInput.select();
  4213. }
  4214. else
  4215. {
  4216. document.execCommand('selectAll', false, null);
  4217. }
  4218. // Installs drag and drop handler for links
  4219. if (Graph.fileSupport)
  4220. {
  4221. // Setup the dnd listeners
  4222. var dlg = div.parentNode;
  4223. var graph = editorUi.editor.graph;
  4224. var dropElt = null;
  4225. mxEvent.addListener(dlg, 'dragleave', function(evt)
  4226. {
  4227. if (dropElt != null)
  4228. {
  4229. dropElt.parentNode.removeChild(dropElt);
  4230. dropElt = null;
  4231. }
  4232. evt.stopPropagation();
  4233. evt.preventDefault();
  4234. });
  4235. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  4236. {
  4237. // IE 10 does not implement pointer-events so it can't have a drop highlight
  4238. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  4239. {
  4240. dropElt = editorUi.highlightElement(dlg);
  4241. }
  4242. evt.stopPropagation();
  4243. evt.preventDefault();
  4244. }));
  4245. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  4246. {
  4247. if (dropElt != null)
  4248. {
  4249. dropElt.parentNode.removeChild(dropElt);
  4250. dropElt = null;
  4251. }
  4252. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  4253. {
  4254. linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  4255. mainBtn.click();
  4256. }
  4257. evt.stopPropagation();
  4258. evt.preventDefault();
  4259. }), false);
  4260. }
  4261. };
  4262. var btns = document.createElement('div');
  4263. btns.style.marginTop = '14px';
  4264. btns.style.textAlign = 'right';
  4265. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4266. {
  4267. editorUi.hideDialog();
  4268. });
  4269. cancelBtn.className = 'geBtn';
  4270. if (editorUi.editor.cancelFirst)
  4271. {
  4272. btns.appendChild(cancelBtn);
  4273. }
  4274. LinkDialog.selectedDocs = null;
  4275. LinkDialog.filePicked = function(data)
  4276. {
  4277. if (data.action == google.picker.Action.PICKED)
  4278. {
  4279. LinkDialog.selectedDocs = data.docs;
  4280. var href = data.docs[0].url;
  4281. if (data.docs[0].mimeType == 'application/mxe' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile')
  4282. {
  4283. var domain = DriveClient.prototype.oldAppHostname;
  4284. href = 'https://' + domain + '/#G' + data.docs[0].id;
  4285. }
  4286. else if (data.docs[0].mimeType == 'application/mxr' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile.realtime')
  4287. {
  4288. var domain = DriveClient.prototype.newAppHostname;
  4289. href = 'https://' + domain + '/#G' + data.docs[0].id;
  4290. }
  4291. else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
  4292. {
  4293. // Do not use folderview in data.docs[0].url link to Google Drive instead
  4294. href = 'https://drive.google.com/#folders/' + data.docs[0].id;
  4295. }
  4296. linkInput.value = href;
  4297. }
  4298. else
  4299. {
  4300. LinkDialog.selectedDocs = null;
  4301. }
  4302. linkInput.focus();
  4303. };
  4304. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  4305. {
  4306. var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
  4307. {
  4308. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  4309. {
  4310. editorUi.drive.checkToken(mxUtils.bind(this, function()
  4311. {
  4312. editorUi.spinner.stop();
  4313. // Creates one picker and reuses it to avoid polluting the DOM
  4314. if (editorUi.linkPicker == null)
  4315. {
  4316. var token = gapi.auth.getToken().access_token;
  4317. var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
  4318. .setParent('root')
  4319. .setIncludeFolders(true)
  4320. .setSelectFolderEnabled(true);
  4321. var view2 = new google.picker.DocsView()
  4322. .setIncludeFolders(true)
  4323. .setSelectFolderEnabled(true);
  4324. var picker = new google.picker.PickerBuilder()
  4325. .setAppId(editorUi.drive.appId)
  4326. .setLocale(mxLanguage)
  4327. .setOAuthToken(token)
  4328. .addView(view)
  4329. .addView(view2)
  4330. .addView(google.picker.ViewId.RECENTLY_PICKED)
  4331. .addView(google.picker.ViewId.IMAGE_SEARCH)
  4332. .addView(google.picker.ViewId.VIDEO_SEARCH)
  4333. .addView(google.picker.ViewId.MAPS);
  4334. if (urlParams['photos'] == '1')
  4335. {
  4336. picker.addView(google.picker.ViewId.PHOTOS)
  4337. .addView(google.picker.ViewId.PHOTO_ALBUMS)
  4338. .addView(google.picker.ViewId.PHOTO_UPLOAD)
  4339. }
  4340. editorUi.linkPicker = picker.setCallback(function(data)
  4341. {
  4342. LinkDialog.filePicked(data);
  4343. }).build();
  4344. }
  4345. editorUi.linkPicker.setVisible(true);
  4346. editorUi.movePickersToTop();
  4347. }));
  4348. }
  4349. });
  4350. gpBtn.className = 'geBtn';
  4351. btns.appendChild(gpBtn);
  4352. }
  4353. if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
  4354. {
  4355. var dbBtn = mxUtils.button(mxResources.get('dropbox'), function()
  4356. {
  4357. // Authentication will be carried out on open to make sure the
  4358. // autosave does not show an auth dialog. Showing it here will
  4359. // block the second dialog (the file picker) so it's too early.
  4360. Dropbox.choose(
  4361. {
  4362. linkType : 'direct',
  4363. cancel: function()
  4364. {
  4365. // do nothing
  4366. },
  4367. success : function(files)
  4368. {
  4369. linkInput.value = files[0].link;
  4370. }
  4371. });
  4372. });
  4373. dbBtn.className = 'geBtn';
  4374. btns.appendChild(dbBtn);
  4375. }
  4376. if (typeof(WL) != 'undefined' && typeof(WL.fileDialog) != 'undefined' && editorUi.oneDrive != null)
  4377. {
  4378. var dbBtn = mxUtils.button(mxResources.get('oneDrive'), function()
  4379. {
  4380. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  4381. {
  4382. editorUi.oneDrive.execute(mxUtils.bind(this, function(token)
  4383. {
  4384. if (token != null)
  4385. {
  4386. editorUi.spinner.stop();
  4387. WL.fileDialog(
  4388. {
  4389. mode: 'open',
  4390. select: 'single'
  4391. }).then(
  4392. function (resp)
  4393. {
  4394. if (resp != null && resp.data != null && resp.data.files != null && resp.data.files.length > 0)
  4395. {
  4396. linkInput.value = resp.data.files[0].link;
  4397. }
  4398. },
  4399. function (responseFailed) {}
  4400. );
  4401. }
  4402. }));
  4403. }
  4404. });
  4405. dbBtn.className = 'geBtn';
  4406. btns.appendChild(dbBtn);
  4407. }
  4408. mxEvent.addListener(linkInput, 'keypress', function(e)
  4409. {
  4410. if (e.keyCode == 13)
  4411. {
  4412. editorUi.hideDialog();
  4413. fn(linkInput.value, LinkDialog.selectedDocs);
  4414. }
  4415. });
  4416. btns.appendChild(mainBtn);
  4417. if (!editorUi.editor.cancelFirst)
  4418. {
  4419. btns.appendChild(cancelBtn);
  4420. }
  4421. div.appendChild(btns);
  4422. this.container = div;
  4423. };
  4424. /**
  4425. * Constructs a new about dialog
  4426. */
  4427. var AboutDialog = function(editorUi)
  4428. {
  4429. var div = document.createElement('div');
  4430. div.style.marginTop = '6px';
  4431. div.setAttribute('align', 'center');
  4432. var img = document.createElement('img');
  4433. img.style.border = '0px';
  4434. img.setAttribute('width', '176');
  4435. img.setAttribute('width', '151');
  4436. img.style.width = '170px';
  4437. img.style.height = '219px';
  4438. img.setAttribute('src', IMAGE_PATH + '/logo-flat.png');
  4439. div.appendChild(img);
  4440. mxUtils.br(div);
  4441. var v = document.createElement('small');
  4442. v.innerHTML = 'v ' + EditorUi.VERSION;
  4443. v.style.color = '#505050';
  4444. div.appendChild(v);
  4445. mxUtils.br(div);
  4446. mxUtils.br(div);
  4447. var small = document.createElement('small');
  4448. small.style.color = '#505050';
  4449. small.innerHTML = '&copy; 2005-2016 <a href="https://www.jgraph.com/" style="color:inherit;" target="_blank">JGraph Ltd</a>.<br>All Rights Reserved.';
  4450. div.appendChild(small);
  4451. mxEvent.addListener(div, 'click', function(e)
  4452. {
  4453. if (mxEvent.getSource(e).nodeName != 'A')
  4454. {
  4455. editorUi.hideDialog();
  4456. }
  4457. });
  4458. this.container = div;
  4459. };
  4460. /**
  4461. * Constructs a new about dialog
  4462. */
  4463. var FeedbackDialog = function(editorUi)
  4464. {
  4465. var div = document.createElement('div');
  4466. var label = document.createElement('div');
  4467. mxUtils.write(label, mxResources.get('sendYourFeedbackToDrawIo'));
  4468. label.style.fontSize = '18px';
  4469. label.style.marginBottom = '18px';
  4470. div.appendChild(label);
  4471. label = document.createElement('div');
  4472. mxUtils.write(label, mxResources.get('yourEmailAddress') + ' (' + mxResources.get('required') + ')');
  4473. div.appendChild(label);
  4474. var email = document.createElement('input');
  4475. email.setAttribute('type', 'text');
  4476. email.style.marginTop = '6px';
  4477. email.style.width = '600px';
  4478. var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
  4479. {
  4480. var diagram = ((cb.checked) ? '\nDiagram:\n' + editorUi.getFileData() : '') +
  4481. '\nBrowser:\n' + navigator.userAgent;
  4482. if (diagram.length > FeedbackDialog.maxAttachmentSize)
  4483. {
  4484. editorUi.alert(mxResources.get('drawingTooLarge'));
  4485. }
  4486. else
  4487. {
  4488. editorUi.hideDialog();
  4489. if (editorUi.spinner.spin(document.body))
  4490. {
  4491. mxUtils.post('/email', 'email=' + encodeURIComponent(email.value) +
  4492. '&version=' + encodeURIComponent(EditorUi.VERSION) +
  4493. '&url=' + encodeURIComponent(window.location.href) +
  4494. '&body=' + encodeURIComponent('Feedback:\n' + textarea.value + diagram),
  4495. function(req)
  4496. {
  4497. editorUi.spinner.stop();
  4498. if (req.getStatus() == 200)
  4499. {
  4500. editorUi.alert(mxResources.get('feedbackSent'));
  4501. }
  4502. else
  4503. {
  4504. editorUi.alert(mxResources.get('errorSendingFeedback'));
  4505. }
  4506. },
  4507. function()
  4508. {
  4509. editorUi.spinner.stop();
  4510. editorUi.alert(mxResources.get('errorSendingFeedback'));
  4511. });
  4512. }
  4513. }
  4514. });
  4515. sendButton.className = 'geBtn gePrimaryBtn';
  4516. sendButton.setAttribute('disabled', 'disabled');
  4517. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  4518. mxEvent.addListener(email, 'change', function()
  4519. {
  4520. if (email.value.length > 0 && re.test(email.value) > 0)
  4521. {
  4522. sendButton.removeAttribute('disabled');
  4523. }
  4524. else
  4525. {
  4526. sendButton.setAttribute('disabled', 'disabled');
  4527. }
  4528. });
  4529. mxEvent.addListener(email, 'keyup', function()
  4530. {
  4531. if (email.value.length > 0 && re.test(email.value))
  4532. {
  4533. sendButton.removeAttribute('disabled');
  4534. }
  4535. else
  4536. {
  4537. sendButton.setAttribute('disabled', 'disabled');
  4538. }
  4539. });
  4540. div.appendChild(email);
  4541. this.init = function()
  4542. {
  4543. email.focus();
  4544. };
  4545. var cb = document.createElement('input');
  4546. cb.setAttribute('type', 'checkbox');
  4547. cb.setAttribute('checked', 'checked');
  4548. cb.defaultChecked = true;
  4549. var p2 = document.createElement('p');
  4550. p2.style.marginTop = '14px';
  4551. p2.appendChild(cb);
  4552. var span = document.createElement('span');
  4553. mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
  4554. p2.appendChild(span);
  4555. mxEvent.addListener(span, 'click', function(evt)
  4556. {
  4557. cb.checked = !cb.checked;
  4558. mxEvent.consume(evt);
  4559. });
  4560. div.appendChild(p2);
  4561. label = document.createElement('div');
  4562. mxUtils.write(label, mxResources.get('feedback'));
  4563. div.appendChild(label);
  4564. var textarea = document.createElement('textarea');
  4565. textarea.style.resize = 'none';
  4566. textarea.style.width = '600px';
  4567. textarea.style.height = '140px';
  4568. textarea.style.marginTop = '6px';
  4569. textarea.setAttribute('placeholder', mxResources.get('commentsNotes'));
  4570. div.appendChild(textarea);
  4571. var buttons = document.createElement('div');
  4572. buttons.style.marginTop = '26px';
  4573. buttons.style.textAlign = 'right';
  4574. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4575. {
  4576. editorUi.hideDialog();
  4577. });
  4578. cancelBtn.className = 'geBtn';
  4579. if (editorUi.editor.cancelFirst)
  4580. {
  4581. buttons.appendChild(cancelBtn);
  4582. buttons.appendChild(sendButton);
  4583. }
  4584. else
  4585. {
  4586. buttons.appendChild(sendButton);
  4587. buttons.appendChild(cancelBtn);
  4588. }
  4589. div.appendChild(buttons);
  4590. this.container = div;
  4591. };
  4592. /**
  4593. * Maximum size of attachments in bytes. Default is 1000000.
  4594. */
  4595. FeedbackDialog.maxAttachmentSize = 1000000;
  4596. /**
  4597. * Constructs a new revision dialog
  4598. */
  4599. var RevisionDialog = function(editorUi, revs)
  4600. {
  4601. var div = document.createElement('div');
  4602. var title = document.createElement('h3');
  4603. title.style.marginTop = '0px';
  4604. mxUtils.write(title, mxResources.get('revisionHistory'));
  4605. div.appendChild(title);
  4606. var list = document.createElement('div');
  4607. list.style.position = 'absolute';
  4608. list.style.overflow = 'auto';
  4609. list.style.width = '170px';
  4610. list.style.height = '378px';
  4611. div.appendChild(list);
  4612. var container = document.createElement('div');
  4613. container.style.position = 'absolute';
  4614. container.style.border = '1px solid lightGray';
  4615. container.style.left = '199px';
  4616. container.style.width = '470px';
  4617. container.style.height = '376px';
  4618. container.style.overflow = 'hidden';
  4619. mxEvent.disableContextMenu(container);
  4620. div.appendChild(container);
  4621. var graph = new Graph(container);
  4622. graph.setEnabled(false);
  4623. graph.setPanning(true);
  4624. graph.panningHandler.ignoreCell = true;
  4625. graph.panningHandler.useLeftButtonForPanning = true;
  4626. graph.minFitScale = null;
  4627. graph.maxFitScale = null;
  4628. graph.centerZoom = true;
  4629. // Handles placeholders for pages
  4630. var currentPage = 0;
  4631. var diagrams = null;
  4632. var realPage = 0;
  4633. var graphGetGlobalVariable = graph.getGlobalVariable;
  4634. graph.getGlobalVariable = function(name)
  4635. {
  4636. if (name == 'page' && diagrams != null && diagrams[realPage] != null)
  4637. {
  4638. return diagrams[currentPage].getAttribute('name');
  4639. }
  4640. else if (name == 'pagenumber')
  4641. {
  4642. return realPage + 1;
  4643. }
  4644. return graphGetGlobalVariable.apply(this, arguments);
  4645. };
  4646. // Disables hyperlinks
  4647. graph.getLinkForCell = function()
  4648. {
  4649. return null;
  4650. };
  4651. if (Editor.MathJaxRender)
  4652. {
  4653. graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  4654. {
  4655. // LATER: Math support is used if current graph has math enabled
  4656. // should use switch from history instead but requires setting the
  4657. // global mxClient.NO_FO switch
  4658. if (editorUi.editor.graph.mathEnabled)
  4659. {
  4660. Editor.MathJaxRender(graph.container);
  4661. }
  4662. }));
  4663. }
  4664. var opts = {
  4665. lines: 11, // The number of lines to draw
  4666. length: 15, // The length of each line
  4667. width: 6, // The line thickness
  4668. radius: 10, // The radius of the inner circle
  4669. corners: 1, // Corner roundness (0..1)
  4670. rotate: 0, // The rotation offset
  4671. direction: 1, // 1: clockwise, -1: counterclockwise
  4672. color: '#000', // #rgb or #rrggbb or array of colors
  4673. speed: 1.4, // Rounds per second
  4674. trail: 60, // Afterglow percentage
  4675. shadow: false, // Whether to render a shadow
  4676. hwaccel: false, // Whether to use hardware acceleration
  4677. className: 'spinner', // The CSS class to assign to the spinner
  4678. zIndex: 2e9, // The z-index (defaults to 2000000000)
  4679. top: '50%', // Top position relative to parent
  4680. left: '50%' // Left position relative to parent
  4681. };
  4682. var spinner = new Spinner(opts);
  4683. var file = editorUi.getCurrentFile();
  4684. var currentRow = null;
  4685. var currentRev = null;
  4686. var currentDoc = null;
  4687. var currentXml = null;
  4688. var zoomInBtn = mxUtils.button('', function()
  4689. {
  4690. if (currentDoc != null)
  4691. {
  4692. graph.zoomIn();
  4693. }
  4694. });
  4695. zoomInBtn.className = 'geSprite geSprite-zoomin';
  4696. zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
  4697. zoomInBtn.style.outline = 'none';
  4698. zoomInBtn.style.border = 'none';
  4699. zoomInBtn.style.margin = '2px';
  4700. zoomInBtn.setAttribute('disabled', 'disabled');
  4701. mxUtils.setOpacity(zoomInBtn, 20);
  4702. var zoomOutBtn = mxUtils.button('', function()
  4703. {
  4704. if (currentDoc != null)
  4705. {
  4706. graph.zoomOut();
  4707. }
  4708. });
  4709. zoomOutBtn.className = 'geSprite geSprite-zoomout';
  4710. zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
  4711. zoomOutBtn.style.outline = 'none';
  4712. zoomOutBtn.style.border = 'none';
  4713. zoomOutBtn.style.margin = '2px';
  4714. zoomOutBtn.setAttribute('disabled', 'disabled');
  4715. mxUtils.setOpacity(zoomOutBtn, 20);
  4716. var zoomFitBtn = mxUtils.button('', function()
  4717. {
  4718. if (currentDoc != null)
  4719. {
  4720. graph.maxFitScale = 8;
  4721. graph.fit(8);
  4722. graph.center();
  4723. }
  4724. });
  4725. zoomFitBtn.className = 'geSprite geSprite-fit';
  4726. zoomFitBtn.setAttribute('title', mxResources.get('fit'));
  4727. zoomFitBtn.style.outline = 'none';
  4728. zoomFitBtn.style.border = 'none';
  4729. zoomFitBtn.style.margin = '2px';
  4730. zoomFitBtn.setAttribute('disabled', 'disabled');
  4731. mxUtils.setOpacity(zoomFitBtn, 20);
  4732. var zoomActualBtn = mxUtils.button('', function()
  4733. {
  4734. if (currentDoc != null)
  4735. {
  4736. graph.zoomActual();
  4737. graph.center();
  4738. }
  4739. });
  4740. zoomActualBtn.className = 'geSprite geSprite-actualsize';
  4741. zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
  4742. zoomActualBtn.style.outline = 'none';
  4743. zoomActualBtn.style.border = 'none';
  4744. zoomActualBtn.style.margin = '2px';
  4745. zoomActualBtn.setAttribute('disabled', 'disabled');
  4746. mxUtils.setOpacity(zoomActualBtn, 20);
  4747. var fileInfo = document.createElement('div');
  4748. fileInfo.style.position = 'absolute';
  4749. fileInfo.style.textAlign = 'right';
  4750. fileInfo.style.color = 'gray';
  4751. fileInfo.style.marginTop = '10px';
  4752. fileInfo.style.backgroundColor = 'transparent';
  4753. fileInfo.style.top = '440px';
  4754. fileInfo.style.right = '32px';
  4755. fileInfo.style.maxWidth = '380px';
  4756. fileInfo.style.cursor = 'default';
  4757. var downloadBtn = mxUtils.button(mxResources.get('download'), function()
  4758. {
  4759. if (currentDoc != null)
  4760. {
  4761. var file = editorUi.getCurrentFile();
  4762. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  4763. var data = mxUtils.getXml(currentDoc.documentElement);
  4764. if (editorUi.isLocalFileSave())
  4765. {
  4766. editorUi.saveLocalFile(data, filename, 'text/xml');
  4767. }
  4768. else
  4769. {
  4770. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4771. '&data=' + encodeURIComponent(editorUi.editor.graph.compress(data));
  4772. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  4773. '&format=xml' + param).simulate(document, '_blank');
  4774. }
  4775. }
  4776. });
  4777. downloadBtn.className = 'geBtn';
  4778. downloadBtn.setAttribute('disabled', 'disabled');
  4779. var restoreBtn = mxUtils.button(mxResources.get('restore'), function()
  4780. {
  4781. if (currentDoc != null && currentXml != null)
  4782. {
  4783. editorUi.confirm(mxResources.get('areYouSure'), function()
  4784. {
  4785. if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
  4786. {
  4787. file.save(true, function(resp)
  4788. {
  4789. editorUi.spinner.stop();
  4790. editorUi.replaceFileData(currentXml);
  4791. editorUi.hideDialog();
  4792. }, function(resp)
  4793. {
  4794. editorUi.spinner.stop();
  4795. editorUi.editor.setStatus('');
  4796. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  4797. });
  4798. }
  4799. });
  4800. }
  4801. });
  4802. restoreBtn.className = 'geBtn';
  4803. restoreBtn.setAttribute('disabled', 'disabled');
  4804. var pageSelect = document.createElement('select');
  4805. pageSelect.setAttribute('disabled', 'disabled');
  4806. pageSelect.style.maxWidth = '80px';
  4807. pageSelect.style.position = 'relative';
  4808. pageSelect.style.top = '-2px';
  4809. pageSelect.style.verticalAlign = 'bottom';
  4810. pageSelect.style.marginRight = '6px';
  4811. pageSelect.style.display = 'none';
  4812. var pageSelectFunction = null;
  4813. mxEvent.addListener(pageSelect, 'change', function(evt)
  4814. {
  4815. if (pageSelectFunction != null)
  4816. {
  4817. pageSelectFunction(evt);
  4818. mxEvent.consume(evt);
  4819. }
  4820. });
  4821. var newBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  4822. {
  4823. if (currentDoc != null)
  4824. {
  4825. window.openFile = new OpenFile(function()
  4826. {
  4827. window.openFile = null;
  4828. });
  4829. window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
  4830. window.openWindow(editorUi.getUrl());
  4831. }
  4832. });
  4833. newBtn.className = 'geBtn';
  4834. newBtn.setAttribute('disabled', 'disabled');
  4835. var showBtn = mxUtils.button(mxResources.get('show'), function()
  4836. {
  4837. if (currentRev != null)
  4838. {
  4839. window.open(currentRev.getUrl());
  4840. }
  4841. });
  4842. showBtn.className = 'geBtn gePrimaryBtn';
  4843. showBtn.setAttribute('disabled', 'disabled');
  4844. var buttons = document.createElement('div');
  4845. buttons.style.position = 'absolute';
  4846. buttons.style.top = '482px';
  4847. buttons.style.width = '640px';
  4848. buttons.style.textAlign = 'right';
  4849. var tb = document.createElement('div');
  4850. tb.className = 'geToolbarContainer';
  4851. tb.style.backgroundColor = 'transparent';
  4852. tb.style.padding = '2px';
  4853. tb.style.border = 'none';
  4854. tb.style.left = '199px';
  4855. tb.style.top = '442px';
  4856. var currentElt = null;
  4857. if (file == null || (editorUi.drive == null && file.constructor == DriveFile) ||
  4858. (editorUi.dropbox == null && file.constructor == DropboxFile))
  4859. {
  4860. container.style.display = 'none';
  4861. tb.style.display = 'none';
  4862. mxUtils.write(list, mxResources.get('notAvailable'));
  4863. }
  4864. else
  4865. {
  4866. if (revs != null && revs.length > 0)
  4867. {
  4868. container.style.cursor = 'move';
  4869. var table = document.createElement('table');
  4870. table.style.border = '1px solid lightGray';
  4871. table.style.borderCollapse = 'collapse';
  4872. table.style.borderSpacing = '0px';
  4873. table.style.width = '100%';
  4874. var tbody = document.createElement('tbody');
  4875. var today = new Date().toDateString();
  4876. if (editorUi.currentPage != null && editorUi.pages != null)
  4877. {
  4878. currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
  4879. }
  4880. for (var i = revs.length - 1; i >= 0; i--)
  4881. {
  4882. var elt = (function(item)
  4883. {
  4884. var ts = new Date(item.modifiedDate);
  4885. var row = null;
  4886. var pd = '6px';
  4887. // Workaround for negative timestamps in Dropbox
  4888. if (ts.getTime() >= 0)
  4889. {
  4890. row = document.createElement('tr');
  4891. row.style.borderBottom = '1px solid lightGray';
  4892. row.style.fontSize = '12px';
  4893. row.style.cursor = 'pointer';
  4894. var date = document.createElement('td');
  4895. date.style.padding = pd;
  4896. date.style.whiteSpace = 'nowrap';
  4897. if (item == revs[revs.length - 1])
  4898. {
  4899. mxUtils.write(date, mxResources.get('current'));
  4900. }
  4901. else
  4902. {
  4903. if (ts.toDateString() === today)
  4904. {
  4905. mxUtils.write(date, ts.toLocaleTimeString());
  4906. }
  4907. else
  4908. {
  4909. mxUtils.write(date, ts.toLocaleDateString() + ' ' +
  4910. ts.toLocaleTimeString());
  4911. }
  4912. }
  4913. row.appendChild(date);
  4914. row.setAttribute('title', ts.toLocaleDateString() + ' ' +
  4915. ts.toLocaleTimeString() + ' ' +
  4916. editorUi.formatFileSize(parseInt(item.fileSize)) +
  4917. ((item.lastModifyingUserName != null) ? ' ' +
  4918. item.lastModifyingUserName : ''));
  4919. function updateGraph(xml)
  4920. {
  4921. spinner.stop();
  4922. var doc = mxUtils.parseXml(xml);
  4923. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  4924. if (node != null)
  4925. {
  4926. pageSelect.style.display = 'none';
  4927. pageSelect.innerHTML = '';
  4928. currentDoc = doc;
  4929. currentXml = xml;
  4930. parseSelectFunction = null;
  4931. diagrams = null;
  4932. realPage = 0;
  4933. function parseGraphModel(dataNode)
  4934. {
  4935. var bg = dataNode.getAttribute('background');
  4936. if (bg == null || bg == '' || bg == mxConstants.NONE)
  4937. {
  4938. bg = '#ffffff';
  4939. }
  4940. container.style.backgroundColor = bg;
  4941. var codec = new mxCodec(dataNode.ownerDocument);
  4942. codec.decode(dataNode, graph.getModel());
  4943. graph.maxFitScale = 1;
  4944. graph.fit(8);
  4945. graph.center();
  4946. return dataNode;
  4947. }
  4948. function parseDiagram(diagramNode)
  4949. {
  4950. if (diagramNode != null)
  4951. {
  4952. diagramNode = parseGraphModel(mxUtils.parseXml(editorUi.editor.graph.decompress(
  4953. mxUtils.getTextContent(diagramNode))).documentElement);
  4954. }
  4955. return diagramNode;
  4956. }
  4957. if (node.nodeName == 'mxfile')
  4958. {
  4959. // Workaround for "invalid calling object" error in IE
  4960. var tmp = node.getElementsByTagName('diagram');
  4961. diagrams = [];
  4962. for (var i = 0; i < tmp.length; i++)
  4963. {
  4964. diagrams.push(tmp[i]);
  4965. }
  4966. realPage = Math.min(currentPage, diagrams.length - 1);
  4967. if (diagrams.length > 0)
  4968. {
  4969. parseDiagram(diagrams[realPage]);
  4970. }
  4971. if (diagrams.length > 1)
  4972. {
  4973. pageSelect.removeAttribute('disabled');
  4974. pageSelect.style.display = '';
  4975. for (var i = 0; i < diagrams.length; i++)
  4976. {
  4977. var pageOption = document.createElement('option');
  4978. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  4979. mxResources.get('pageWithNumber', [i + 1]));
  4980. pageOption.setAttribute('value', i);
  4981. if (i == realPage)
  4982. {
  4983. pageOption.setAttribute('selected', 'selected');
  4984. }
  4985. pageSelect.appendChild(pageOption);
  4986. }
  4987. }
  4988. pageSelectFunction = function()
  4989. {
  4990. currentPage = parseInt(pageSelect.value);
  4991. realPage = currentPage;
  4992. parseDiagram(diagrams[currentPage]);
  4993. }
  4994. }
  4995. else
  4996. {
  4997. parseGraphModel(node);
  4998. }
  4999. fileInfo.innerHTML = '';
  5000. mxUtils.write(fileInfo, ts.toLocaleDateString() + ' ' +
  5001. ts.toLocaleTimeString());
  5002. fileInfo.setAttribute('title', row.getAttribute('title'));
  5003. zoomInBtn.removeAttribute('disabled');
  5004. zoomOutBtn.removeAttribute('disabled');
  5005. zoomFitBtn.removeAttribute('disabled');
  5006. zoomActualBtn.removeAttribute('disabled');
  5007. if (file == null || !file.isRestricted())
  5008. {
  5009. if (editorUi.editor.graph.isEnabled())
  5010. {
  5011. restoreBtn.removeAttribute('disabled');
  5012. }
  5013. downloadBtn.removeAttribute('disabled');
  5014. showBtn.removeAttribute('disabled');
  5015. newBtn.removeAttribute('disabled');
  5016. }
  5017. mxUtils.setOpacity(zoomInBtn, 60);
  5018. mxUtils.setOpacity(zoomOutBtn, 60);
  5019. mxUtils.setOpacity(zoomFitBtn, 60);
  5020. mxUtils.setOpacity(zoomActualBtn, 60);
  5021. }
  5022. else
  5023. {
  5024. pageSelect.style.display = 'none';
  5025. pageSelect.innerHTML = '';
  5026. fileInfo.innerHTML = '';
  5027. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  5028. }
  5029. };
  5030. mxEvent.addListener(row, 'click', function(evt)
  5031. {
  5032. if (currentRev != item)
  5033. {
  5034. spinner.stop();
  5035. if (currentRow != null)
  5036. {
  5037. currentRow.style.backgroundColor = '';
  5038. }
  5039. currentRev = item;
  5040. currentRow = row;
  5041. currentRow.style.backgroundColor = '#ebf2f9';
  5042. currentDoc = null;
  5043. currentXml = null;
  5044. fileInfo.removeAttribute('title');
  5045. fileInfo.innerHTML = mxResources.get('loading') + '...';
  5046. container.style.backgroundColor = '#ffffff';
  5047. graph.getModel().clear();
  5048. restoreBtn.setAttribute('disabled', 'disabled');
  5049. downloadBtn.setAttribute('disabled', 'disabled');
  5050. zoomInBtn.setAttribute('disabled', 'disabled');
  5051. zoomOutBtn.setAttribute('disabled', 'disabled');
  5052. zoomActualBtn.setAttribute('disabled', 'disabled');
  5053. zoomFitBtn.setAttribute('disabled', 'disabled');
  5054. newBtn.setAttribute('disabled', 'disabled');
  5055. showBtn.setAttribute('disabled', 'disabled');
  5056. pageSelect.setAttribute('disabled', 'disabled');
  5057. mxUtils.setOpacity(zoomInBtn, 20);
  5058. mxUtils.setOpacity(zoomOutBtn, 20);
  5059. mxUtils.setOpacity(zoomFitBtn, 20);
  5060. mxUtils.setOpacity(zoomActualBtn, 20);
  5061. spinner.spin(container);
  5062. item.getXml(function(xml)
  5063. {
  5064. if (currentRev == item)
  5065. {
  5066. updateGraph(xml);
  5067. }
  5068. }, function(err)
  5069. {
  5070. spinner.stop();
  5071. pageSelect.style.display = 'none';
  5072. pageSelect.innerHTML = '';
  5073. fileInfo.innerHTML = '';
  5074. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  5075. });
  5076. mxEvent.consume(evt);
  5077. }
  5078. });
  5079. mxEvent.addListener(row, 'dblclick', function(evt)
  5080. {
  5081. showBtn.click();
  5082. if (window.getSelection)
  5083. {
  5084. window.getSelection().removeAllRanges();
  5085. }
  5086. else if (document.selection)
  5087. {
  5088. document.selection.empty();
  5089. }
  5090. mxEvent.consume(evt);
  5091. }, false);
  5092. tbody.appendChild(row);
  5093. }
  5094. return row;
  5095. })(revs[i]);
  5096. // Selects and loads first element in list (ie current version) after
  5097. // graph container was initialized since there is no loading delay
  5098. if (elt != null && i == revs.length - 1)
  5099. {
  5100. currentElt = elt;
  5101. }
  5102. }
  5103. table.appendChild(tbody);
  5104. list.appendChild(table);
  5105. }
  5106. else
  5107. {
  5108. container.style.display = 'none';
  5109. tb.style.display = 'none';
  5110. mxUtils.write(list, mxResources.get('noRevisions'));
  5111. }
  5112. }
  5113. this.init = function()
  5114. {
  5115. if (currentElt != null)
  5116. {
  5117. currentElt.click();
  5118. }
  5119. };
  5120. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  5121. {
  5122. editorUi.hideDialog();
  5123. });
  5124. closeBtn.className = 'geBtn';
  5125. tb.appendChild(pageSelect);
  5126. tb.appendChild(zoomInBtn);
  5127. tb.appendChild(zoomOutBtn);
  5128. tb.appendChild(zoomActualBtn);
  5129. tb.appendChild(zoomFitBtn);
  5130. if (editorUi.editor.cancelFirst)
  5131. {
  5132. buttons.appendChild(closeBtn);
  5133. buttons.appendChild(downloadBtn);
  5134. buttons.appendChild(newBtn);
  5135. buttons.appendChild(restoreBtn);
  5136. buttons.appendChild(showBtn);
  5137. }
  5138. else
  5139. {
  5140. buttons.appendChild(downloadBtn);
  5141. buttons.appendChild(newBtn);
  5142. buttons.appendChild(restoreBtn);
  5143. buttons.appendChild(showBtn);
  5144. buttons.appendChild(closeBtn);
  5145. }
  5146. div.appendChild(buttons);
  5147. div.appendChild(tb);
  5148. div.appendChild(fileInfo);
  5149. this.container = div;
  5150. };
  5151. /**
  5152. *
  5153. */
  5154. var AnimationWindow = function(editorUi, x, y, w, h)
  5155. {
  5156. var table = document.createElement('table');
  5157. table.style.width = '100%';
  5158. table.style.height = '100%';
  5159. var tbody = document.createElement('tbody');
  5160. var tr1 = document.createElement('tr');
  5161. var td11 = document.createElement('td');
  5162. td11.style.width = '140px';
  5163. var td12 = document.createElement('td');
  5164. var tr2 = document.createElement('tr');
  5165. tr2.style.height = '40px';
  5166. var td21 = document.createElement('td');
  5167. td21.setAttribute('colspan', '2');
  5168. var list = document.createElement('textarea');
  5169. list.style.overflow = 'auto';
  5170. list.style.width = '100%';
  5171. list.style.height = '100%';
  5172. td11.appendChild(list);
  5173. var root = editorUi.editor.graph.getModel().getRoot();
  5174. if (root.value != null && typeof(root.value) == 'object')
  5175. {
  5176. list.value = root.value.getAttribute('animation');
  5177. }
  5178. var container = document.createElement('div');
  5179. container.style.border = '1px solid lightGray';
  5180. container.style.background = '#ffffff';
  5181. container.style.width = '100%';
  5182. container.style.height = '100%';
  5183. container.style.overflow = 'auto';
  5184. mxEvent.disableContextMenu(container);
  5185. td12.appendChild(container);
  5186. var graph = new Graph(container);
  5187. graph.setEnabled(false);
  5188. graph.setPanning(true);
  5189. graph.foldingEnabled = false;
  5190. graph.panningHandler.ignoreCell = true;
  5191. graph.panningHandler.useLeftButtonForPanning = true;
  5192. graph.minFitScale = null;
  5193. graph.maxFitScale = null;
  5194. graph.centerZoom = true;
  5195. // For animation and fading
  5196. function getNodesForCells(cells)
  5197. {
  5198. var nodes = [];
  5199. for (var i = 0; i < cells.length; i++)
  5200. {
  5201. var state = graph.view.getState(cells[i]);
  5202. if (state != null)
  5203. {
  5204. var shapes = graph.cellRenderer.getShapesForState(state);
  5205. for (var j = 0; j < shapes.length; j++)
  5206. {
  5207. if (shapes[j] != null && shapes[j].node != null)
  5208. {
  5209. nodes.push(shapes[j].node);
  5210. }
  5211. }
  5212. // Adds folding icon
  5213. if (state.control != null && state.control.node != null)
  5214. {
  5215. nodes.push(state.control.node);
  5216. }
  5217. }
  5218. }
  5219. return nodes;
  5220. };
  5221. function fadeIn(nodes)
  5222. {
  5223. if (nodes != null)
  5224. {
  5225. for (var i = 0; i < nodes.length; i++)
  5226. {
  5227. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', null);
  5228. nodes[i].style.opacity = '0';
  5229. }
  5230. window.setTimeout(function()
  5231. {
  5232. for (var i = 0; i < nodes.length; i++)
  5233. {
  5234. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', 'all 1s ease-in-out');
  5235. nodes[i].style.opacity = '1';
  5236. }
  5237. }, 0);
  5238. }
  5239. };
  5240. function fadeOut(nodes)
  5241. {
  5242. if (nodes != null)
  5243. {
  5244. for (var i = 0; i < nodes.length; i++)
  5245. {
  5246. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', null);
  5247. nodes[i].style.opacity = '1';
  5248. }
  5249. window.setTimeout(function()
  5250. {
  5251. for (var i = 0; i < nodes.length; i++)
  5252. {
  5253. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', 'all 1s ease-in-out');
  5254. nodes[i].style.opacity = '0';
  5255. }
  5256. }, 0);
  5257. }
  5258. };
  5259. function createEdgeAnimation(state)
  5260. {
  5261. var pts = state.absolutePoints.slice();
  5262. var segs = state.segments;
  5263. var total = state.length;
  5264. var n = pts.length;
  5265. return {
  5266. execute: function(step, steps)
  5267. {
  5268. if (state.shape != null)
  5269. {
  5270. var pts2 = [pts[0]];
  5271. var dist = total * step / steps;
  5272. for (var i = 1; i < n; i++)
  5273. {
  5274. if (dist <= segs[i - 1])
  5275. {
  5276. pts2.push(new mxPoint(pts[i - 1].x + (pts[i].x - pts[i - 1].x) * dist / segs[i - 1],
  5277. pts[i - 1].y + (pts[i].y - pts[i - 1].y) * dist / segs[i - 1]));
  5278. break;
  5279. }
  5280. else
  5281. {
  5282. dist -= segs[i - 1];
  5283. pts2.push(pts[i]);
  5284. }
  5285. }
  5286. state.shape.points = pts2;
  5287. state.shape.redraw();
  5288. }
  5289. },
  5290. stop: function()
  5291. {
  5292. if (state.shape != null)
  5293. {
  5294. state.shape.points = pts;
  5295. state.shape.redraw();
  5296. }
  5297. }
  5298. };
  5299. };
  5300. function createVertexAnimation(state)
  5301. {
  5302. var bds = new mxRectangle.fromRectangle(state.shape.bounds);
  5303. var ttr = null;
  5304. if (state.text != null && state.text.node != null && state.text.node.firstChild != null)
  5305. {
  5306. ttr = state.text.node.firstChild.getAttribute('transform');
  5307. }
  5308. return {
  5309. execute: function(step, steps)
  5310. {
  5311. if (state.shape != null)
  5312. {
  5313. var f = step / steps;
  5314. state.shape.bounds = new mxRectangle(bds.x, bds.y, bds.width * f, bds.height);
  5315. state.shape.redraw();
  5316. // Text is animated using CSS3 transitions
  5317. if (ttr != null)
  5318. {
  5319. state.text.node.firstChild.setAttribute('transform', ttr + ' scale(' + f + ',1)');
  5320. }
  5321. }
  5322. },
  5323. stop: function()
  5324. {
  5325. if (state.shape != null)
  5326. {
  5327. state.shape.bounds = bds;
  5328. state.shape.redraw();
  5329. if (ttr != null)
  5330. {
  5331. state.text.node.firstChild.setAttribute('transform', ttr);
  5332. }
  5333. }
  5334. }
  5335. };
  5336. };
  5337. function animateCells(cells, steps, delay)
  5338. {
  5339. steps = (steps != null) ? steps : 30;
  5340. delay = (delay != null) ? delay : 30;
  5341. var animations = [];
  5342. for (var i = 0; i < cells.length; i++)
  5343. {
  5344. var state = graph.view.getState(cells[i]);
  5345. if (state != null && state.shape != null && graph.model.isEdge(state.cell) &&
  5346. state.absolutePoints != null && state.absolutePoints.length > 1)
  5347. {
  5348. animations.push(createEdgeAnimation(state));
  5349. }
  5350. else if (state != null && graph.model.isVertex(state.cell) &&
  5351. state.shape != null && state.shape.bounds != null)
  5352. {
  5353. animations.push(createVertexAnimation(state));
  5354. // TODO: include descendants
  5355. }
  5356. }
  5357. var step = 0;
  5358. function animate()
  5359. {
  5360. if (step == steps)
  5361. {
  5362. window.clearInterval(thread);
  5363. for (var i = 0; i < animations.length; i++)
  5364. {
  5365. animations[i].stop();
  5366. }
  5367. }
  5368. else
  5369. {
  5370. for (var i = 0; i < animations.length; i++)
  5371. {
  5372. animations[i].execute(step, steps);
  5373. }
  5374. step++;
  5375. }
  5376. }
  5377. var thread = window.setInterval(animate, delay);
  5378. animate();
  5379. };
  5380. function mapCell(cell, clone, mapping)
  5381. {
  5382. mapping = (mapping != null) ? mapping : new Object();
  5383. mapping[cell.id] = clone;
  5384. var childCount = cell.getChildCount();
  5385. for (var i = 0; i < childCount; i++)
  5386. {
  5387. mapCell(cell.getChildAt(i), clone.getChildAt(i), mapping);
  5388. }
  5389. return mapping;
  5390. };
  5391. var allowedToRun = false;
  5392. var running = false;
  5393. function stop()
  5394. {
  5395. allowedToRun = false;
  5396. graph.getModel().clear();
  5397. };
  5398. function run()
  5399. {
  5400. if (!running)
  5401. {
  5402. allowedToRun = true;
  5403. running = true;
  5404. graph.getModel().clear();
  5405. graph.getModel().setRoot(graph.cloneCells([editorUi.editor.graph.getModel().getRoot()])[0]);
  5406. graph.maxFitScale = 1;
  5407. graph.fit(8);
  5408. graph.center();
  5409. graph.getModel().beginUpdate();
  5410. try
  5411. {
  5412. for (var id in graph.getModel().cells)
  5413. {
  5414. var cell = graph.getModel().cells[id];
  5415. if (graph.getModel().isVertex(cell) || graph.getModel().isEdge(cell))
  5416. {
  5417. graph.setCellStyles('opacity', '0', [cell]);
  5418. graph.setCellStyles('noLabel', '1', [cell]);
  5419. }
  5420. }
  5421. }
  5422. finally
  5423. {
  5424. graph.getModel().endUpdate();
  5425. }
  5426. var mapping = mapCell(editorUi.editor.graph.getModel().getRoot(), graph.getModel().getRoot());
  5427. var steps = list.value.split('\n');
  5428. var step = 0;
  5429. function next()
  5430. {
  5431. if (allowedToRun && step < steps.length)
  5432. {
  5433. var tokens = steps[step].split(' ');
  5434. if (tokens.length > 0)
  5435. {
  5436. if (tokens[0] == 'wait' && tokens.length > 1)
  5437. {
  5438. window.setTimeout(function()
  5439. {
  5440. step++;
  5441. next();
  5442. }, parseFloat(tokens[1]));
  5443. }
  5444. else
  5445. {
  5446. if (tokens.length > 1)
  5447. {
  5448. var cell = mapping[tokens[1]];
  5449. if (cell != null)
  5450. {
  5451. if (tokens[0] == 'show')
  5452. {
  5453. graph.setCellStyles('opacity', '100', [cell]);
  5454. graph.setCellStyles('noLabel', null, [cell]);
  5455. if (tokens.length > 2 && tokens[2] == 'fade')
  5456. {
  5457. fadeIn(getNodesForCells([cell]));
  5458. }
  5459. else
  5460. {
  5461. animateCells([cell]);
  5462. }
  5463. }
  5464. else if (tokens[0] == 'hide')
  5465. {
  5466. fadeOut(getNodesForCells([cell]));
  5467. }
  5468. }
  5469. else
  5470. {
  5471. console.log('cell not found', id, steps[step]);
  5472. }
  5473. }
  5474. step++;
  5475. next();
  5476. }
  5477. }
  5478. }
  5479. else
  5480. {
  5481. running = false;
  5482. }
  5483. };
  5484. next();
  5485. }
  5486. };
  5487. var fadeInBtn = mxUtils.button('Fade In', function()
  5488. {
  5489. var cells = editorUi.editor.graph.getSelectionCells();
  5490. if (cells.length > 0)
  5491. {
  5492. for (var i = 0; i < cells.length; i++)
  5493. {
  5494. list.value = list.value + 'show ' + cells[i].id + ' fade\n';
  5495. }
  5496. list.value = list.value + 'wait 1000\n';
  5497. }
  5498. });
  5499. td21.appendChild(fadeInBtn);
  5500. var animateBtn = mxUtils.button('Wipe In', function()
  5501. {
  5502. var cells = editorUi.editor.graph.getSelectionCells();
  5503. if (cells.length > 0)
  5504. {
  5505. for (var i = 0; i < cells.length; i++)
  5506. {
  5507. list.value = list.value + 'show ' + cells[i].id + '\n';
  5508. }
  5509. list.value = list.value + 'wait 1000\n';
  5510. }
  5511. });
  5512. td21.appendChild(animateBtn);
  5513. var addBtn = mxUtils.button('Fade Out', function()
  5514. {
  5515. var cells = editorUi.editor.graph.getSelectionCells();
  5516. if (cells.length > 0)
  5517. {
  5518. for (var i = 0; i < cells.length; i++)
  5519. {
  5520. list.value = list.value + 'hide ' + cells[i].id + '\n';
  5521. }
  5522. list.value = list.value + 'wait 1000\n';
  5523. }
  5524. });
  5525. td21.appendChild(addBtn);
  5526. var waitBtn = mxUtils.button('Wait', function()
  5527. {
  5528. list.value = list.value + 'wait 1000\n';
  5529. });
  5530. td21.appendChild(waitBtn);
  5531. var runBtn = mxUtils.button('Preview', function()
  5532. {
  5533. run();
  5534. });
  5535. td21.appendChild(runBtn);
  5536. var stopBtn = mxUtils.button('Stop', function()
  5537. {
  5538. stop();
  5539. });
  5540. td21.appendChild(stopBtn);
  5541. var applyBtn = mxUtils.button('Apply', function()
  5542. {
  5543. editorUi.editor.graph.setAttributeForCell(root, 'animation', list.value);
  5544. });
  5545. td21.appendChild(applyBtn);
  5546. var root = editorUi.editor.graph.getModel().getRoot();
  5547. tr1.appendChild(td11);
  5548. tr1.appendChild(td12);
  5549. tbody.appendChild(tr1);
  5550. tr2.appendChild(td21);
  5551. tbody.appendChild(tr2);
  5552. table.appendChild(tbody);
  5553. this.window = new mxWindow('Animation', table, x, y, w, h, true, true);
  5554. this.window.destroyOnClose = false;
  5555. this.window.setMaximizable(false);
  5556. this.window.setResizable(true);
  5557. this.window.setClosable(true);
  5558. this.window.setVisible(true);
  5559. };
  5560. /**
  5561. * Constructs a new auth dialog.
  5562. */
  5563. var AuthDialog = function(editorUi, peer, showRememberOption, fn)
  5564. {
  5565. var div = document.createElement('div');
  5566. div.style.textAlign = 'center';
  5567. var hd = document.createElement('p');
  5568. hd.style.fontSize = '16pt';
  5569. hd.style.padding = '0px';
  5570. hd.style.margin = '0px';
  5571. hd.style.color = 'gray';
  5572. mxUtils.write(hd, mxResources.get('authorizationRequired'));
  5573. var service = 'Unknown';
  5574. var img = document.createElement('img');
  5575. img.setAttribute('border', '0');
  5576. img.setAttribute('align', 'absmiddle');
  5577. img.style.marginRight = '10px';
  5578. if (peer == editorUi.drive)
  5579. {
  5580. service = mxResources.get('googleDrive');
  5581. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  5582. }
  5583. else if (peer == editorUi.dropbox)
  5584. {
  5585. service = mxResources.get('dropbox');
  5586. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  5587. }
  5588. else if (peer == editorUi.oneDrive)
  5589. {
  5590. service = mxResources.get('oneDrive');
  5591. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  5592. }
  5593. var p = document.createElement('p');
  5594. mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
  5595. var cb = document.createElement('input');
  5596. cb.setAttribute('type', 'checkbox');
  5597. var button = mxUtils.button(mxResources.get('authorize'), function()
  5598. {
  5599. editorUi.hideDialog(false);
  5600. fn(cb.checked);
  5601. });
  5602. button.insertBefore(img, button.firstChild);
  5603. button.style.marginTop = '6px';
  5604. button.className = 'geBigButton';
  5605. div.appendChild(hd);
  5606. div.appendChild(p);
  5607. div.appendChild(button);
  5608. if (showRememberOption)
  5609. {
  5610. var p2 = document.createElement('p');
  5611. p2.style.marginTop = '20px';
  5612. p2.appendChild(cb);
  5613. var span = document.createElement('span');
  5614. mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
  5615. p2.appendChild(span);
  5616. div.appendChild(p2);
  5617. cb.checked = true;
  5618. cb.defaultChecked = true;
  5619. mxEvent.addListener(span, 'click', function(evt)
  5620. {
  5621. cb.checked = !cb.checked;
  5622. mxEvent.consume(evt);
  5623. });
  5624. }
  5625. this.container = div;
  5626. };
  5627. var MoreShapesDialog = function(editorUi, expanded, entries)
  5628. {
  5629. entries = (entries != null) ? entries : editorUi.sidebar.entries;
  5630. var div = document.createElement('div');
  5631. if (expanded)
  5632. {
  5633. var hd = document.createElement('div');
  5634. hd.className = 'geDialogTitle';
  5635. mxUtils.write(hd, mxResources.get('shapes'));
  5636. hd.style.position = 'absolute';
  5637. hd.style.top = '0px';
  5638. hd.style.left = '0px';
  5639. hd.style.lineHeight = '40px';
  5640. hd.style.height = '40px';
  5641. hd.style.right = '0px';
  5642. if (mxClient.IS_QUIRKS)
  5643. {
  5644. hd.style.width = '718px';
  5645. }
  5646. var list = document.createElement('div');
  5647. var preview = document.createElement('div');
  5648. list.style.position = 'absolute';
  5649. list.style.top = '40px';
  5650. list.style.left = '0px';
  5651. list.style.width = '202px';
  5652. list.style.bottom = '60px';
  5653. list.style.overflow = 'auto';
  5654. if (mxClient.IS_QUIRKS)
  5655. {
  5656. list.style.height = '437px';
  5657. list.style.marginTop = '1px';
  5658. }
  5659. preview.style.position = 'absolute';
  5660. preview.style.left = '202px';
  5661. preview.style.right = '0px';
  5662. preview.style.top = '40px';
  5663. preview.style.bottom = '60px';
  5664. preview.style.overflow = 'auto';
  5665. preview.style.borderLeft = '1px solid rgb(211, 211, 211)';
  5666. preview.style.textAlign = 'center';
  5667. if (mxClient.IS_QUIRKS)
  5668. {
  5669. preview.style.width = parseInt(hd.style.width) - 202 + 'px';
  5670. preview.style.height = list.style.height;
  5671. preview.style.marginTop = list.style.marginTop;
  5672. }
  5673. var currentListItem = null;
  5674. var applyFunctions = [];
  5675. var listEntry = document.createElement('div');
  5676. listEntry.style.position = 'relative';
  5677. listEntry.style.left = '0px';
  5678. listEntry.style.right = '0px';
  5679. for (var i = 0; i < entries.length; i++)
  5680. {
  5681. (function(section)
  5682. {
  5683. var title = listEntry.cloneNode(false);
  5684. title.style.fontWeight = 'bold';
  5685. title.style.backgroundColor = '#e5e5e5';
  5686. title.style.padding = '6px 0px 6px 20px';
  5687. mxUtils.write(title, section.title);
  5688. list.appendChild(title);
  5689. for (var j = 0; j < section.entries.length; j++)
  5690. {
  5691. (function(entry)
  5692. {
  5693. var option = listEntry.cloneNode(false);
  5694. option.style.cursor = 'pointer';
  5695. option.style.padding = '4px 0px 4px 20px';
  5696. var checkbox = document.createElement('input');
  5697. checkbox.setAttribute('type', 'checkbox');
  5698. checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
  5699. checkbox.defaultChecked = checkbox.checked;
  5700. option.appendChild(checkbox);
  5701. mxUtils.write(option, ' ' + entry.title);
  5702. list.appendChild(option);
  5703. var itemClicked = function(evt)
  5704. {
  5705. if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
  5706. {
  5707. if (entry.imageCallback != null)
  5708. {
  5709. entry.imageCallback(preview);
  5710. }
  5711. else if (entry.image != null)
  5712. {
  5713. preview.innerHTML = '<img border="0" src="' + entry.image + '"/>';
  5714. }
  5715. else
  5716. {
  5717. preview.innerHTML = '<br>';
  5718. mxUtils.write(preview, mxResources.get('noPreview'));
  5719. }
  5720. if (currentListItem != null)
  5721. {
  5722. currentListItem.style.backgroundColor = '';
  5723. }
  5724. currentListItem = option;
  5725. currentListItem.style.backgroundColor = '#ebf2f9';
  5726. if (evt != null)
  5727. {
  5728. mxEvent.consume(evt);
  5729. }
  5730. }
  5731. };
  5732. mxEvent.addListener(option, 'click', itemClicked);
  5733. mxEvent.addListener(option, 'dblclick', function(evt)
  5734. {
  5735. checkbox.checked = !checkbox.checked;
  5736. mxEvent.consume(evt);
  5737. });
  5738. applyFunctions.push(function()
  5739. {
  5740. return (checkbox.checked) ? entry.id : null;
  5741. });
  5742. // Selects first entry
  5743. if (i == 0 && j == 0)
  5744. {
  5745. itemClicked();
  5746. }
  5747. })(section.entries[j]);
  5748. }
  5749. })(entries[i]);
  5750. }
  5751. div.style.padding = '30px';
  5752. div.appendChild(hd);
  5753. div.appendChild(list);
  5754. div.appendChild(preview);
  5755. var buttons = document.createElement('div');
  5756. buttons.className = 'geDialogFooter';
  5757. buttons.style.position = 'absolute';
  5758. buttons.style.paddingRight = '16px';
  5759. buttons.style.color = 'gray';
  5760. buttons.style.left = '0px';
  5761. buttons.style.right = '0px';
  5762. buttons.style.bottom = '0px';
  5763. buttons.style.height = '60px';
  5764. buttons.style.lineHeight = '52px';
  5765. if (mxClient.IS_QUIRKS)
  5766. {
  5767. buttons.style.width = hd.style.width;
  5768. buttons.style.paddingTop = '12px';
  5769. }
  5770. var cb = document.createElement('input');
  5771. cb.setAttribute('type', 'checkbox');
  5772. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  5773. {
  5774. var span = document.createElement('span');
  5775. span.style.paddingRight = '20px';
  5776. span.appendChild(cb);
  5777. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5778. cb.checked = true;
  5779. cb.defaultChecked = true;
  5780. mxEvent.addListener(span, 'click', function(evt)
  5781. {
  5782. if (mxEvent.getSource(evt) != cb)
  5783. {
  5784. cb.checked = !cb.checked;
  5785. mxEvent.consume(evt);
  5786. }
  5787. });
  5788. if (mxClient.IS_QUIRKS)
  5789. {
  5790. span.style.position = 'relative';
  5791. span.style.top = '-6px';
  5792. }
  5793. buttons.appendChild(span);
  5794. }
  5795. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5796. {
  5797. editorUi.hideDialog();
  5798. });
  5799. cancelBtn.className = 'geBtn';
  5800. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5801. {
  5802. editorUi.hideDialog();
  5803. var libs = [];
  5804. for (var i = 0; i < applyFunctions.length; i++)
  5805. {
  5806. var lib = applyFunctions[i].apply(this, arguments);
  5807. if (lib != null)
  5808. {
  5809. libs.push(lib);
  5810. }
  5811. }
  5812. editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
  5813. });
  5814. applyBtn.className = 'geBtn gePrimaryBtn';
  5815. if (editorUi.editor.cancelFirst)
  5816. {
  5817. buttons.appendChild(cancelBtn);
  5818. buttons.appendChild(applyBtn);
  5819. }
  5820. else
  5821. {
  5822. buttons.appendChild(applyBtn);
  5823. buttons.appendChild(cancelBtn);
  5824. }
  5825. div.appendChild(buttons);
  5826. }
  5827. else
  5828. {
  5829. var libFS = document.createElement('table');
  5830. var tbody = document.createElement('tbody');
  5831. div.style.height = '100%';
  5832. div.style.overflow = 'auto';
  5833. var row = document.createElement('tr');
  5834. libFS.style.width = '100%';
  5835. var leftDiv = document.createElement('td');
  5836. var midDiv = document.createElement('td');
  5837. var rightDiv = document.createElement('td');
  5838. var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
  5839. {
  5840. var libCB = document.createElement('input');
  5841. libCB.type = 'checkbox';
  5842. libFS.appendChild(libCB);
  5843. libCB.checked = editorUi.sidebar.isEntryVisible(key);
  5844. var libSpan = document.createElement('span');
  5845. mxUtils.write(libSpan, title);
  5846. var label = document.createElement('div');
  5847. label.style.display = 'block';
  5848. label.appendChild(libCB);
  5849. label.appendChild(libSpan);
  5850. mxEvent.addListener(libSpan, 'click', function(evt)
  5851. {
  5852. libCB.checked = !libCB.checked;
  5853. mxEvent.consume(evt);
  5854. });
  5855. wrapperDiv.appendChild(label);
  5856. return function()
  5857. {
  5858. return (libCB.checked) ? key : null;
  5859. };
  5860. });
  5861. row.appendChild(leftDiv);
  5862. row.appendChild(midDiv);
  5863. row.appendChild(rightDiv);
  5864. tbody.appendChild(row);
  5865. libFS.appendChild(tbody);
  5866. var applyFunctions = [];
  5867. var count = 0;
  5868. // Counts total number of entries
  5869. for (var i = 0; i < entries.length; i++)
  5870. {
  5871. for (var j = 0; j < entries[i].entries.length; j++)
  5872. {
  5873. count++;
  5874. }
  5875. }
  5876. // Distributes entries on columns
  5877. var cols = [leftDiv, midDiv, rightDiv];
  5878. var counter = 0;
  5879. for (var i = 0; i < entries.length; i++)
  5880. {
  5881. (function(section)
  5882. {
  5883. for (var j = 0; j < section.entries.length; j++)
  5884. {
  5885. (function(entry)
  5886. {
  5887. var index = Math.floor(counter / (count / 3));
  5888. applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
  5889. counter++;
  5890. })(section.entries[j]);
  5891. }
  5892. })(entries[i]);
  5893. }
  5894. div.appendChild(libFS);
  5895. var remember = document.createElement('div');
  5896. remember.style.marginTop = '18px';
  5897. remember.style.textAlign = 'center';
  5898. var cb = document.createElement('input');
  5899. if (isLocalStorage)
  5900. {
  5901. cb.setAttribute('type', 'checkbox');
  5902. cb.checked = true;
  5903. cb.defaultChecked = true;
  5904. remember.appendChild(cb);
  5905. var span = document.createElement('span');
  5906. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  5907. remember.appendChild(span);
  5908. mxEvent.addListener(span, 'click', function(evt)
  5909. {
  5910. cb.checked = !cb.checked;
  5911. mxEvent.consume(evt);
  5912. });
  5913. }
  5914. div.appendChild(remember);
  5915. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5916. {
  5917. editorUi.hideDialog();
  5918. });
  5919. cancelBtn.className = 'geBtn';
  5920. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5921. {
  5922. var libs = ['search'];
  5923. for (var i = 0; i < applyFunctions.length; i++)
  5924. {
  5925. var lib = applyFunctions[i].apply(this, arguments);
  5926. if (lib != null)
  5927. {
  5928. libs.push(lib);
  5929. }
  5930. }
  5931. editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
  5932. editorUi.hideDialog();
  5933. });
  5934. applyBtn.className = 'geBtn gePrimaryBtn';
  5935. var buttons = document.createElement('div');
  5936. buttons.style.marginTop = '26px';
  5937. buttons.style.textAlign = 'right';
  5938. if (editorUi.editor.cancelFirst)
  5939. {
  5940. buttons.appendChild(cancelBtn);
  5941. buttons.appendChild(applyBtn);
  5942. }
  5943. else
  5944. {
  5945. buttons.appendChild(applyBtn);
  5946. buttons.appendChild(cancelBtn);
  5947. }
  5948. div.appendChild(buttons);
  5949. }
  5950. this.container = div;
  5951. };
  5952. var PluginsDialog = function(editorUi)
  5953. {
  5954. var div = document.createElement('div');
  5955. var inner = document.createElement('div');
  5956. inner.style.height = '120px';
  5957. inner.style.overflow = 'auto';
  5958. var plugins = mxSettings.getPlugins().slice();
  5959. function refresh()
  5960. {
  5961. if (plugins.length == 0)
  5962. {
  5963. inner.innerHTML = mxResources.get('noPlugins');
  5964. }
  5965. else
  5966. {
  5967. inner.innerHTML = '';
  5968. for (var i = 0; i < plugins.length; i++)
  5969. {
  5970. var span = document.createElement('span');
  5971. span.style.whiteSpace = 'nowrap';
  5972. var img = document.createElement('span');
  5973. img.className = 'geSprite geSprite-delete';
  5974. img.style.position = 'relative';
  5975. img.style.cursor = 'pointer';
  5976. img.style.top = '5px';
  5977. img.style.marginRight = '4px';
  5978. img.style.display = 'inline-block';
  5979. span.appendChild(img);
  5980. mxUtils.write(span, plugins[i]);
  5981. inner.appendChild(span);
  5982. mxUtils.br(inner);
  5983. mxEvent.addListener(img, 'click', (function(index)
  5984. {
  5985. return function()
  5986. {
  5987. editorUi.confirm(window.parent.mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
  5988. {
  5989. plugins.splice(index, 1);
  5990. refresh();
  5991. });
  5992. };
  5993. })(i));
  5994. }
  5995. }
  5996. }
  5997. div.appendChild(inner);
  5998. refresh();
  5999. var addBtn = mxUtils.button(mxResources.get('add'), function()
  6000. {
  6001. var tmp = '';
  6002. var param = urlParams['p'];
  6003. if (param != null && param.length > 0)
  6004. {
  6005. var tokens = param.split(';');
  6006. for (var i = 0; i < tokens.length; i++)
  6007. {
  6008. var url = App.pluginRegistry[tokens[i]];
  6009. if (url != null)
  6010. {
  6011. tmp += url + ';';
  6012. }
  6013. }
  6014. if (tmp.charAt(tmp.length - 1) == ';')
  6015. {
  6016. tmp = tmp.substring(0, tmp.length - 1);
  6017. }
  6018. }
  6019. var dlg = new FilenameDialog(editorUi, tmp, mxResources.get('add'), function(newValue)
  6020. {
  6021. if (newValue != null && newValue.length > 0)
  6022. {
  6023. tokens = newValue.split(';');
  6024. for (var i = 0; i < tokens.length; i++)
  6025. {
  6026. if (tokens[i].length > 0 && mxUtils.indexOf(plugins, tokens[i]) < 0)
  6027. {
  6028. plugins.push(tokens[i]);
  6029. }
  6030. }
  6031. refresh();
  6032. }
  6033. }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
  6034. editorUi.showDialog(dlg.container, 300, 80, true, true);
  6035. dlg.init();
  6036. });
  6037. addBtn.className = 'geBtn';
  6038. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6039. {
  6040. editorUi.hideDialog();
  6041. });
  6042. cancelBtn.className = 'geBtn';
  6043. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6044. {
  6045. mxSettings.setPlugins(plugins);
  6046. mxSettings.save();
  6047. editorUi.hideDialog();
  6048. editorUi.alert(mxResources.get('restartForChangeRequired'));
  6049. });
  6050. applyBtn.className = 'geBtn gePrimaryBtn';
  6051. var buttons = document.createElement('div');
  6052. buttons.style.marginTop = '14px';
  6053. buttons.style.textAlign = 'right';
  6054. if (editorUi.editor.cancelFirst)
  6055. {
  6056. buttons.appendChild(cancelBtn);
  6057. buttons.appendChild(addBtn);
  6058. buttons.appendChild(applyBtn);
  6059. }
  6060. else
  6061. {
  6062. buttons.appendChild(addBtn);
  6063. buttons.appendChild(applyBtn);
  6064. buttons.appendChild(cancelBtn);
  6065. }
  6066. div.appendChild(buttons);
  6067. this.container = div;
  6068. };
  6069. var EditGeometryDialog = function(editorUi, vertices)
  6070. {
  6071. var graph = editorUi.editor.graph;
  6072. var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
  6073. var div = document.createElement('div');
  6074. var table = document.createElement('table');
  6075. var tbody = document.createElement('tbody');
  6076. var row = document.createElement('tr');
  6077. var left = document.createElement('td');
  6078. var right = document.createElement('td');
  6079. table.style.paddingLeft = '6px';
  6080. mxUtils.write(left, mxResources.get('left') + ':');
  6081. var xInput = document.createElement('input');
  6082. xInput.setAttribute('type', 'text');
  6083. xInput.style.width = '100px';
  6084. xInput.value = (geo != null) ? geo.x : '';
  6085. this.init = function()
  6086. {
  6087. xInput.focus();
  6088. xInput.select();
  6089. };
  6090. right.appendChild(xInput);
  6091. row.appendChild(left);
  6092. row.appendChild(right);
  6093. tbody.appendChild(row);
  6094. row = document.createElement('tr');
  6095. left = document.createElement('td');
  6096. right = document.createElement('td');
  6097. mxUtils.write(left, mxResources.get('top') + ':');
  6098. var yInput = document.createElement('input');
  6099. yInput.setAttribute('type', 'text');
  6100. yInput.style.width = '100px';
  6101. yInput.value = (geo != null) ? geo.y : '';
  6102. right.appendChild(yInput);
  6103. row.appendChild(left);
  6104. row.appendChild(right);
  6105. tbody.appendChild(row);
  6106. row = document.createElement('tr');
  6107. left = document.createElement('td');
  6108. right = document.createElement('td');
  6109. mxUtils.write(left, mxResources.get('width') + ':');
  6110. var wInput = document.createElement('input');
  6111. wInput.setAttribute('type', 'text');
  6112. wInput.style.width = '100px';
  6113. wInput.value = (geo != null) ? geo.width : '';
  6114. right.appendChild(wInput);
  6115. row.appendChild(left);
  6116. row.appendChild(right);
  6117. tbody.appendChild(row);
  6118. row = document.createElement('tr');
  6119. left = document.createElement('td');
  6120. right = document.createElement('td');
  6121. mxUtils.write(left, mxResources.get('height') + ':');
  6122. var hInput = document.createElement('input');
  6123. hInput.setAttribute('type', 'text');
  6124. hInput.style.width = '100px';
  6125. hInput.value = (geo != null) ? geo.height : '';
  6126. right.appendChild(hInput);
  6127. row.appendChild(left);
  6128. row.appendChild(right);
  6129. tbody.appendChild(row);
  6130. row = document.createElement('tr');
  6131. left = document.createElement('td');
  6132. right = document.createElement('td');
  6133. mxUtils.write(left, mxResources.get('rotation') + ':');
  6134. var rotInput = document.createElement('input');
  6135. rotInput.setAttribute('type', 'text');
  6136. rotInput.style.width = '100px';
  6137. rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
  6138. mxConstants.STYLE_ROTATION, 0) : '';
  6139. right.appendChild(rotInput);
  6140. row.appendChild(left);
  6141. row.appendChild(right);
  6142. tbody.appendChild(row);
  6143. table.appendChild(tbody);
  6144. div.appendChild(table);
  6145. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6146. {
  6147. editorUi.hideDialog();
  6148. });
  6149. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6150. {
  6151. editorUi.hideDialog();
  6152. graph.getModel().beginUpdate();
  6153. try
  6154. {
  6155. for (var i = 0; i < vertices.length; i++)
  6156. {
  6157. var g = graph.getCellGeometry(vertices[i]);
  6158. if (g != null)
  6159. {
  6160. g = g.clone();
  6161. if (graph.isCellMovable(vertices[i]))
  6162. {
  6163. if (mxUtils.trim(xInput.value).length > 0)
  6164. {
  6165. g.x = Number(xInput.value);
  6166. }
  6167. if (mxUtils.trim(yInput.value).length > 0)
  6168. {
  6169. g.y = Number(yInput.value);
  6170. }
  6171. }
  6172. if (graph.isCellResizable(vertices[i]))
  6173. {
  6174. if (mxUtils.trim(wInput.value).length > 0)
  6175. {
  6176. g.width = Number(wInput.value);
  6177. }
  6178. if (mxUtils.trim(hInput.value).length > 0)
  6179. {
  6180. g.height = Number(hInput.value);
  6181. }
  6182. }
  6183. graph.getModel().setGeometry(vertices[i], g);
  6184. }
  6185. if (mxUtils.trim(rotInput.value).length > 0)
  6186. {
  6187. graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
  6188. }
  6189. }
  6190. }
  6191. finally
  6192. {
  6193. graph.getModel().endUpdate();
  6194. }
  6195. });
  6196. mxEvent.addListener(div, 'keypress', function(e)
  6197. {
  6198. if (e.keyCode == 13)
  6199. {
  6200. applyBtn.click();
  6201. }
  6202. });
  6203. var buttons = document.createElement('div');
  6204. buttons.style.marginTop = '20px';
  6205. buttons.style.textAlign = 'right';
  6206. if (editorUi.editor.cancelFirst)
  6207. {
  6208. buttons.appendChild(cancelBtn);
  6209. buttons.appendChild(applyBtn);
  6210. }
  6211. else
  6212. {
  6213. buttons.appendChild(applyBtn);
  6214. buttons.appendChild(cancelBtn);
  6215. }
  6216. div.appendChild(buttons);
  6217. this.container = div;
  6218. };
  6219. /**
  6220. * Constructs a new dialog for creating files from templates.
  6221. */
  6222. var LibraryDialog = function(editorUi, name, library, initialImages, file, mode)
  6223. {
  6224. var images = [];
  6225. var graph = editorUi.editor.graph;
  6226. var outer = document.createElement('div');
  6227. outer.style.height = '100%';
  6228. var header = document.createElement('div');
  6229. header.style.whiteSpace = 'nowrap';
  6230. header.style.height = '40px';
  6231. outer.appendChild(header);
  6232. mxUtils.write(header, mxResources.get('filename') + ':');
  6233. var nameValue = name;
  6234. if (nameValue == null)
  6235. {
  6236. nameValue = editorUi.defaultLibraryName + '.xml';
  6237. }
  6238. var nameInput = document.createElement('input');
  6239. nameInput.setAttribute('value', nameValue);
  6240. nameInput.style.marginRight = '20px';
  6241. nameInput.style.marginLeft = '10px';
  6242. nameInput.style.width = '500px';
  6243. if (file != null && !file.isRenamable())
  6244. {
  6245. nameInput.setAttribute('disabled', 'true');
  6246. }
  6247. this.init = function()
  6248. {
  6249. if (file == null || file.isRenamable())
  6250. {
  6251. nameInput.focus();
  6252. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  6253. {
  6254. nameInput.select();
  6255. }
  6256. else
  6257. {
  6258. document.execCommand('selectAll', false, null);
  6259. }
  6260. }
  6261. };
  6262. header.appendChild(nameInput);
  6263. var div = document.createElement('div');
  6264. div.style.borderWidth = '1px 0px 1px 0px';
  6265. div.style.borderColor = '#d3d3d3';
  6266. div.style.borderStyle = 'solid';
  6267. div.style.marginTop = '6px';
  6268. div.style.overflow = 'auto';
  6269. div.style.height = '340px';
  6270. div.style.backgroundPosition = 'center center';
  6271. div.style.backgroundRepeat = 'no-repeat';
  6272. if (images.length == 0 && Graph.fileSupport)
  6273. {
  6274. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  6275. }
  6276. var bg = document.createElement('div');
  6277. bg.style.position = 'absolute';
  6278. bg.style.width = '640px';
  6279. bg.style.top = '260px';
  6280. bg.style.textAlign = 'center';
  6281. bg.style.fontSize = '22px';
  6282. bg.style.color = '#a0c3ff';
  6283. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  6284. outer.appendChild(bg);
  6285. var entries = {};
  6286. var ew = 100;
  6287. var eh = 100;
  6288. var dragSourceIndex = null;
  6289. var dropTargetIndex = null;
  6290. function getIndexForEvent(evt)
  6291. {
  6292. var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
  6293. while (dropTarget != null && dropTarget.parentNode != div)
  6294. {
  6295. dropTarget = dropTarget.parentNode;
  6296. }
  6297. var result = null;
  6298. if (dropTarget != null)
  6299. {
  6300. var tmp = div.firstChild;
  6301. result = 0;
  6302. while (tmp != null && tmp != dropTarget)
  6303. {
  6304. tmp = tmp.nextSibling;
  6305. result++;
  6306. }
  6307. }
  6308. return result;
  6309. };
  6310. var stopEditing = null;
  6311. var stopWrapper = function(evt)
  6312. {
  6313. var source = mxEvent.getSource(evt);
  6314. if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
  6315. {
  6316. stopEditing();
  6317. stopEditing = null;
  6318. mxEvent.consume(evt);
  6319. }
  6320. };
  6321. mxEvent.addListener(div, 'mousedown', stopWrapper);
  6322. mxEvent.addListener(div, 'pointerdown', stopWrapper);
  6323. mxEvent.addListener(div, 'touchstart', stopWrapper);
  6324. // For converting image URLs
  6325. var converter = new mxUrlConverter();
  6326. function addButton(data, mimeType, x, y, w, h, img, aspect, title)
  6327. {
  6328. // Ignores duplicates
  6329. try
  6330. {
  6331. if (mimeType == null || mimeType.substring(0, 6) == 'image/')
  6332. {
  6333. if ((data == null && img != null) || entries[data] == null)
  6334. {
  6335. div.style.backgroundImage = '';
  6336. bg.style.display = 'none';
  6337. var iw = w;
  6338. var ih = h;
  6339. if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
  6340. {
  6341. var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
  6342. editorUi.maxImageSize / Math.max(1, h));
  6343. w *= s;
  6344. h *= s;
  6345. }
  6346. if (iw > ih)
  6347. {
  6348. ih = Math.round(ih * ew / iw);
  6349. iw = ew;
  6350. }
  6351. else
  6352. {
  6353. iw = Math.round(iw * eh / ih);
  6354. ih = eh;
  6355. }
  6356. var wrapper = document.createElement('div');
  6357. wrapper.setAttribute('draggable', 'true');
  6358. wrapper.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  6359. wrapper.style.position = 'relative';
  6360. wrapper.style.cursor = 'move';
  6361. mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
  6362. if (data != null)
  6363. {
  6364. var elt = document.createElement('img');
  6365. elt.setAttribute('src', converter.convert(data));
  6366. elt.style.width = iw + 'px';
  6367. elt.style.height = ih + 'px';
  6368. elt.style.margin = '10px';
  6369. elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
  6370. elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
  6371. wrapper.appendChild(elt);
  6372. }
  6373. else if (img != null)
  6374. {
  6375. var cells = editorUi.stringToCells(editorUi.editor.graph.decompress(img.xml));
  6376. if (cells.length > 0)
  6377. {
  6378. editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null, true, false);
  6379. // Needs inline block on SVG for delete icon to appear on same line
  6380. wrapper.firstChild.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  6381. wrapper.firstChild.style.cursor = '';
  6382. }
  6383. }
  6384. var rem = document.createElement('img');
  6385. rem.setAttribute('src', Editor.closeImage);
  6386. rem.setAttribute('border', '0');
  6387. rem.setAttribute('title', mxResources.get('delete'));
  6388. rem.setAttribute('align', 'top');
  6389. rem.style.paddingTop = '4px';
  6390. rem.style.marginLeft = '-22px';
  6391. rem.style.cursor = 'pointer';
  6392. // Blocks dragging of remove icon
  6393. mxEvent.addListener(rem, 'dragstart', function(evt)
  6394. {
  6395. mxEvent.consume(evt);
  6396. });
  6397. // Seems to bring remove icon on top of graph
  6398. if (data == null && img != null)
  6399. {
  6400. rem.style.position = 'relative';
  6401. }
  6402. (function(wrapperDiv, dataParam)
  6403. {
  6404. mxEvent.addListener(rem, 'click', function(evt)
  6405. {
  6406. entries[data] = null;
  6407. for (var i = 0; i < images.length; i++)
  6408. {
  6409. if ((data != null && images[i].data == dataParam) ||
  6410. (img != null && images[i].xml == img.xml))
  6411. {
  6412. images.splice(i, 1);
  6413. break;
  6414. }
  6415. }
  6416. wrapper.parentNode.removeChild(wrapperDiv);
  6417. if (images.length == 0)
  6418. {
  6419. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  6420. bg.style.display = '';
  6421. }
  6422. mxEvent.consume(evt);
  6423. });
  6424. // Workaround for accidental select all
  6425. mxEvent.addListener(rem, 'dblclick', function(evt)
  6426. {
  6427. mxEvent.consume(evt);
  6428. });
  6429. })(wrapper, data, img);
  6430. wrapper.appendChild(rem);
  6431. wrapper.style.marginBottom = '30px';
  6432. var label = document.createElement('div');
  6433. label.style.position = 'absolute';
  6434. label.style.boxSizing = 'border-box';
  6435. label.style.bottom = '-18px';
  6436. label.style.left = '10px';
  6437. label.style.right = '10px';
  6438. label.style.backgroundColor = '#ffffff';
  6439. label.style.overflow = 'hidden';
  6440. label.style.textAlign = 'center';
  6441. var entry = null;
  6442. if (data != null)
  6443. {
  6444. entry = {data: data, w: w, h: h, title: title};
  6445. if (aspect != null)
  6446. {
  6447. entry.aspect = aspect;
  6448. }
  6449. entries[data] = elt;
  6450. images.push(entry);
  6451. }
  6452. else if (img != null)
  6453. {
  6454. img.aspect = 'fixed';
  6455. images.push(img);
  6456. entry = img;
  6457. }
  6458. function updateLabel()
  6459. {
  6460. label.innerHTML = '';
  6461. label.style.cursor = 'pointer';
  6462. label.style.whiteSpace = 'nowrap';
  6463. label.style.textOverflow = 'ellipsis';
  6464. mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
  6465. entry.title : mxResources.get('untitled'));
  6466. if (entry.title == null || entry.title.length == 0)
  6467. {
  6468. label.style.color = '#d0d0d0';
  6469. }
  6470. else
  6471. {
  6472. label.style.color = '';
  6473. }
  6474. };
  6475. mxEvent.addListener(label, 'keydown', function(evt)
  6476. {
  6477. if (evt.keyCode == 13 && stopEditing != null)
  6478. {
  6479. stopEditing();
  6480. stopEditing = null;
  6481. mxEvent.consume(evt);
  6482. }
  6483. });
  6484. updateLabel();
  6485. wrapper.appendChild(label);
  6486. // Blocks dragging of label
  6487. mxEvent.addListener(label, 'mousedown', function(evt)
  6488. {
  6489. mxEvent.consume(evt);
  6490. });
  6491. var startEditing = function(evt)
  6492. {
  6493. // Workaround for various issues in IE
  6494. if (!mxClient.IS_IOS && !mxClient.IS_QUIRKS && !mxClient.IS_FF &&
  6495. (document.documentMode == null || document.documentMode > 9))
  6496. {
  6497. if (label.getAttribute('contentEditable') != 'true')
  6498. {
  6499. if (stopEditing != null)
  6500. {
  6501. stopEditing();
  6502. stopEditing = null;
  6503. }
  6504. if (entry.title == null || entry.title.length == 0)
  6505. {
  6506. label.innerHTML = '';
  6507. }
  6508. label.style.textOverflow = '';
  6509. label.style.whiteSpace = '';
  6510. label.style.cursor = 'text';
  6511. label.style.color = '';
  6512. label.setAttribute('contentEditable', 'true');
  6513. label.focus();
  6514. document.execCommand('selectAll', false, null);
  6515. stopEditing = function()
  6516. {
  6517. label.removeAttribute('contentEditable');
  6518. label.style.cursor = 'pointer';
  6519. entry.title = label.innerHTML;
  6520. updateLabel();
  6521. }
  6522. }
  6523. }
  6524. else
  6525. {
  6526. var dlg = new FilenameDialog(editorUi, entry.title || '', mxResources.get('ok'), function(newTitle)
  6527. {
  6528. if (newTitle != null)
  6529. {
  6530. entry.title = newTitle;
  6531. updateLabel();
  6532. }
  6533. }, mxResources.get('enterValue'));
  6534. editorUi.showDialog(dlg.container, 300, 80, true, true);
  6535. dlg.init();
  6536. }
  6537. mxEvent.consume(evt);
  6538. };
  6539. mxEvent.addListener(label, 'click', startEditing);
  6540. mxEvent.addListener(wrapper, 'dblclick', startEditing);
  6541. div.appendChild(wrapper);
  6542. mxEvent.addListener(wrapper, 'dragstart', function(evt)
  6543. {
  6544. if (data == null && img != null)
  6545. {
  6546. rem.style.visibility = 'hidden';
  6547. label.style.visibility = 'hidden';
  6548. }
  6549. // Workaround for no DnD on DIV in FF
  6550. if (mxClient.IS_FF && img.xml != null)
  6551. {
  6552. evt.dataTransfer.setData('Text', img.xml);
  6553. }
  6554. dragSourceIndex = getIndexForEvent(evt);
  6555. // Workaround for missing drag preview in Google Chrome
  6556. if (mxClient.IS_GC)
  6557. {
  6558. wrapper.style.opacity = '0.9';
  6559. }
  6560. window.setTimeout(function()
  6561. {
  6562. mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
  6563. mxUtils.setOpacity(wrapper, 30);
  6564. rem.style.visibility = '';
  6565. label.style.visibility = '';
  6566. }, 0);
  6567. });
  6568. mxEvent.addListener(wrapper, 'dragend', function(evt)
  6569. {
  6570. if (rem.style.visibility == 'hidden')
  6571. {
  6572. rem.style.visibility = '';
  6573. label.style.visibility = '';
  6574. }
  6575. dragSourceIndex = null;
  6576. mxUtils.setOpacity(wrapper, 100);
  6577. mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
  6578. });
  6579. }
  6580. else
  6581. {
  6582. //editorUi.spinner.stop();
  6583. editorUi.handleError({message: mxResources.get('fileExists')})
  6584. }
  6585. }
  6586. else
  6587. {
  6588. var done = false;
  6589. try
  6590. {
  6591. if (data != null && data.substring(0, 10) == '<mxlibrary')
  6592. {
  6593. var doc = mxUtils.parseXml(data);
  6594. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  6595. if (temp != null && temp.length > 0)
  6596. {
  6597. for (var i = 0; i < temp.length; i++)
  6598. {
  6599. if (temp[i].xml != null)
  6600. {
  6601. addButton(null, null, 0, 0, 0, 0, temp[i]);
  6602. }
  6603. else
  6604. {
  6605. addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
  6606. }
  6607. }
  6608. }
  6609. editorUi.spinner.stop();
  6610. done = true;
  6611. }
  6612. }
  6613. catch (e)
  6614. {
  6615. // ignore
  6616. }
  6617. if (!done)
  6618. {
  6619. editorUi.spinner.stop();
  6620. editorUi.handleError({message: mxResources.get('errorLoadingFile')})
  6621. }
  6622. }
  6623. }
  6624. catch (e)
  6625. {
  6626. // ignore
  6627. console.log('e', e);
  6628. }
  6629. return null;
  6630. };
  6631. if (initialImages != null)
  6632. {
  6633. for (var i = 0; i < initialImages.length; i++)
  6634. {
  6635. var img = initialImages[i];
  6636. addButton(img.data, null, 0, 0, img.w, img.h, img);
  6637. }
  6638. }
  6639. // Setup the dnd listeners
  6640. mxEvent.addListener(div, 'dragleave', function(evt)
  6641. {
  6642. bg.style.cursor = '';
  6643. var source = mxEvent.getSource(evt);
  6644. while (source != null)
  6645. {
  6646. if (source == div || source == bg)
  6647. {
  6648. evt.stopPropagation();
  6649. evt.preventDefault();
  6650. break;
  6651. }
  6652. source = source.parentNode;
  6653. }
  6654. });
  6655. function dragOver(evt)
  6656. {
  6657. evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
  6658. evt.stopPropagation();
  6659. evt.preventDefault();
  6660. };
  6661. function dropHandler(evt)
  6662. {
  6663. evt.stopPropagation();
  6664. evt.preventDefault();
  6665. dropTargetIndex = getIndexForEvent(evt);
  6666. if (dragSourceIndex != null)
  6667. {
  6668. if (dropTargetIndex != null && dropTargetIndex < div.children.length)
  6669. {
  6670. images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
  6671. 0, images.splice(dragSourceIndex, 1)[0]);
  6672. div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
  6673. }
  6674. else
  6675. {
  6676. images.push(images.splice(dragSourceIndex, 1)[0]);
  6677. div.appendChild(div.children[dragSourceIndex]);
  6678. }
  6679. }
  6680. else if (evt.dataTransfer.files.length > 0)
  6681. {
  6682. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img)
  6683. {
  6684. addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ? null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  6685. });
  6686. }
  6687. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  6688. {
  6689. var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  6690. if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
  6691. /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
  6692. {
  6693. editorUi.loadImage(uri, function(img)
  6694. {
  6695. addButton(uri, null, 0, 0, img.width, img.height);
  6696. });
  6697. }
  6698. }
  6699. evt.stopPropagation();
  6700. evt.preventDefault();
  6701. };
  6702. mxEvent.addListener(div, 'dragover', dragOver);
  6703. mxEvent.addListener(div, 'drop', dropHandler);
  6704. mxEvent.addListener(bg, 'dragover', dragOver);
  6705. mxEvent.addListener(bg, 'drop', dropHandler);
  6706. outer.appendChild(div);
  6707. var btns = document.createElement('div');
  6708. btns.style.textAlign = 'right';
  6709. btns.style.marginTop = '20px';
  6710. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6711. {
  6712. editorUi.hideDialog(true);
  6713. });
  6714. cancelBtn.setAttribute('id', 'btnCancel');
  6715. cancelBtn.className = 'geBtn';
  6716. if (editorUi.editor.cancelFirst)
  6717. {
  6718. btns.appendChild(cancelBtn);
  6719. }
  6720. // Does not show download button, allow filename editing in Chrome Apps
  6721. if (!window.chrome || !chrome.app || !chrome.app.runtime)
  6722. {
  6723. var btn = mxUtils.button(mxResources.get('export'), function()
  6724. {
  6725. var data = editorUi.createLibraryDataFromImages(images);
  6726. var filename = nameInput.value;
  6727. if (!/(\.xml)$/i.test(filename))
  6728. {
  6729. filename += '.xml';
  6730. }
  6731. if (editorUi.isLocalFileSave())
  6732. {
  6733. editorUi.saveLocalFile(data, filename, 'text/xml');
  6734. }
  6735. else
  6736. {
  6737. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  6738. '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
  6739. }
  6740. });
  6741. btn.setAttribute('id', 'btnDownload');
  6742. btn.className = 'geBtn';
  6743. btns.appendChild(btn);
  6744. }
  6745. else
  6746. {
  6747. nameInput.setAttribute('disabled', 'disabled');
  6748. }
  6749. var fileInput = document.createElement('input');
  6750. fileInput.setAttribute('multiple', 'multiple');
  6751. fileInput.setAttribute('type', 'file');
  6752. if (document.documentMode == null)
  6753. {
  6754. mxEvent.addListener(fileInput, 'change', function(evt)
  6755. {
  6756. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img)
  6757. {
  6758. addButton(data, mimeType, x, y, w, h, img, 'fixed');
  6759. // Resets input to force change event for same file
  6760. fileInput.value = '';
  6761. });
  6762. });
  6763. var btn = mxUtils.button(mxResources.get('import'), function()
  6764. {
  6765. if (stopEditing != null)
  6766. {
  6767. stopEditing();
  6768. stopEditing = null;
  6769. }
  6770. fileInput.click();
  6771. });
  6772. btn.setAttribute('id', 'btnAddImage');
  6773. btn.className = 'geBtn';
  6774. btns.appendChild(btn);
  6775. }
  6776. var btn = mxUtils.button(mxResources.get('addImageUrl'), function()
  6777. {
  6778. if (stopEditing != null)
  6779. {
  6780. stopEditing();
  6781. stopEditing = null;
  6782. }
  6783. editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
  6784. {
  6785. if (url != null)
  6786. {
  6787. // Image dialog returns modified data URLs which
  6788. // must be converted back to real data URL
  6789. if (url.substring(0, 11) == 'data:image/')
  6790. {
  6791. var comma = url.indexOf(',');
  6792. if (comma > 0)
  6793. {
  6794. url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
  6795. }
  6796. }
  6797. addButton(url, null, 0, 0, w, h);
  6798. }
  6799. });
  6800. });
  6801. btn.setAttribute('id', 'btnAddImageUrl');
  6802. btn.className = 'geBtn';
  6803. btns.appendChild(btn);
  6804. // Indirection for overriding
  6805. this.saveBtnClickHandler = function(name, images, file, mode)
  6806. {
  6807. editorUi.saveLibrary(name, images, file, mode);
  6808. };
  6809. var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
  6810. {
  6811. if (stopEditing != null)
  6812. {
  6813. stopEditing();
  6814. stopEditing = null;
  6815. }
  6816. this.saveBtnClickHandler(nameInput.value, images, file, mode);
  6817. }));
  6818. btn.setAttribute('id', 'btnSave');
  6819. btn.className = 'geBtn gePrimaryBtn';
  6820. btns.appendChild(btn);
  6821. if (!editorUi.editor.cancelFirst)
  6822. {
  6823. btns.appendChild(cancelBtn);
  6824. }
  6825. outer.appendChild(btns);
  6826. this.container = outer;
  6827. };
  6828. /**
  6829. * Constructs a new textarea dialog.
  6830. */
  6831. var EditShapeDialog = function(editorUi, cell, title, w, h)
  6832. {
  6833. w = (w != null) ? w : 300;
  6834. h = (h != null) ? h : 120;
  6835. var row, td;
  6836. var table = document.createElement('table');
  6837. var tbody = document.createElement('tbody');
  6838. table.style.cellPadding = '4px';
  6839. row = document.createElement('tr');
  6840. td = document.createElement('td');
  6841. td.setAttribute('colspan', '2');
  6842. td.style.fontSize = '10pt';
  6843. mxUtils.write(td, title);
  6844. row.appendChild(td);
  6845. tbody.appendChild(row);
  6846. row = document.createElement('tr');
  6847. td = document.createElement('td');
  6848. var nameInput = document.createElement('textarea');
  6849. nameInput.style.outline = 'none';
  6850. nameInput.style.resize = 'none';
  6851. nameInput.style.width = (w - 200) + 'px';
  6852. nameInput.style.height = h + 'px';
  6853. this.textarea = nameInput;
  6854. this.init = function()
  6855. {
  6856. nameInput.focus();
  6857. nameInput.scrollTop = 0;
  6858. };
  6859. td.appendChild(nameInput);
  6860. row.appendChild(td);
  6861. td = document.createElement('td');
  6862. var container = document.createElement('div');
  6863. container.style.position = 'relative';
  6864. container.style.border = '1px solid gray';
  6865. container.style.top = '6px';
  6866. container.style.width = '200px';
  6867. container.style.height = (h + 4) + 'px';
  6868. container.style.overflow = 'hidden';
  6869. container.style.marginBottom = '16px';
  6870. mxEvent.disableContextMenu(container);
  6871. td.appendChild(container);
  6872. var graph = new Graph(container);
  6873. graph.setEnabled(false);
  6874. var clone = editorUi.editor.graph.cloneCells([cell])[0];
  6875. graph.addCells([clone]);
  6876. var state = graph.view.getState(clone);
  6877. var stencil = '';
  6878. if (state.shape != null && state.shape.stencil != null)
  6879. {
  6880. stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
  6881. }
  6882. mxUtils.write(nameInput, stencil || '');
  6883. var b = graph.getGraphBounds();
  6884. var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
  6885. graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
  6886. row.appendChild(td);
  6887. tbody.appendChild(row);
  6888. row = document.createElement('tr');
  6889. td = document.createElement('td');
  6890. td.setAttribute('colspan', '2');
  6891. td.style.paddingTop = '2px';
  6892. td.style.whiteSpace = 'nowrap';
  6893. td.setAttribute('align', 'right');
  6894. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6895. {
  6896. editorUi.hideDialog();
  6897. });
  6898. cancelBtn.className = 'geBtn';
  6899. if (editorUi.editor.cancelFirst)
  6900. {
  6901. td.appendChild(cancelBtn);
  6902. }
  6903. if (!editorUi.isOffline())
  6904. {
  6905. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  6906. {
  6907. window.open('https://support.draw.io/display/DO/Editing+Shapes');
  6908. });
  6909. helpBtn.className = 'geBtn';
  6910. td.appendChild(helpBtn);
  6911. }
  6912. var updateShape = function(targetGraph, targetCell, hide)
  6913. {
  6914. var newValue = nameInput.value;
  6915. // Checks if XML has changed (getPrettyXml "normalizes" DOM)
  6916. var doc = mxUtils.parseXml(newValue);
  6917. newValue = mxUtils.getPrettyXml(doc.documentElement);
  6918. // Checks for validation errors
  6919. // LATER: Validate against XSD
  6920. var errors = doc.documentElement.getElementsByTagName('parsererror');
  6921. if (errors != null && errors.length > 0)
  6922. {
  6923. editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
  6924. }
  6925. else
  6926. {
  6927. if (hide)
  6928. {
  6929. editorUi.hideDialog();
  6930. }
  6931. var isNew = !targetGraph.model.contains(targetCell);
  6932. if (!hide || isNew || newValue != stencil)
  6933. {
  6934. // Transform XML value to be used in cell style
  6935. newValue = editorUi.editor.graph.compress(newValue);
  6936. targetGraph.getModel().beginUpdate();
  6937. try
  6938. {
  6939. // Inserts cell if required
  6940. if (isNew)
  6941. {
  6942. var pt = editorUi.editor.graph.getInsertPoint();
  6943. targetCell.geometry.x = pt.x;
  6944. targetCell.geometry.y = pt.y;
  6945. targetGraph.addCell(targetCell)
  6946. }
  6947. targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
  6948. }
  6949. catch (e)
  6950. {
  6951. throw e;
  6952. }
  6953. finally
  6954. {
  6955. // Updates the display
  6956. targetGraph.getModel().endUpdate();
  6957. }
  6958. // Updates selection after stencil was created for rendering
  6959. if (isNew)
  6960. {
  6961. targetGraph.setSelectionCell(targetCell);
  6962. }
  6963. }
  6964. }
  6965. };
  6966. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  6967. {
  6968. updateShape(graph, clone, false);
  6969. });
  6970. previewBtn.className = 'geBtn';
  6971. td.appendChild(previewBtn);
  6972. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  6973. {
  6974. updateShape(editorUi.editor.graph, cell, true);
  6975. });
  6976. applyBtn.className = 'geBtn gePrimaryBtn';
  6977. td.appendChild(applyBtn);
  6978. if (!editorUi.editor.cancelFirst)
  6979. {
  6980. td.appendChild(cancelBtn);
  6981. }
  6982. row.appendChild(td);
  6983. tbody.appendChild(row);
  6984. table.appendChild(tbody);
  6985. this.container = table;
  6986. };
  6987. var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink)
  6988. {
  6989. var div = document.createElement('div');
  6990. div.appendChild(content);
  6991. var btns = document.createElement('div');
  6992. btns.style.marginTop = '16px';
  6993. btns.style.textAlign = 'center';
  6994. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6995. {
  6996. editorUi.hideDialog();
  6997. if (cancelFn != null)
  6998. {
  6999. cancelFn();
  7000. }
  7001. });
  7002. cancelBtn.className = 'geBtn';
  7003. if (editorUi.editor.cancelFirst)
  7004. {
  7005. btns.appendChild(cancelBtn);
  7006. }
  7007. if (!editorUi.isOffline() && helpLink != null)
  7008. {
  7009. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  7010. {
  7011. window.open(helpLink);
  7012. });
  7013. helpBtn.className = 'geBtn';
  7014. btns.appendChild(helpBtn);
  7015. }
  7016. var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), function()
  7017. {
  7018. editorUi.hideDialog();
  7019. if (okFn != null)
  7020. {
  7021. okFn();
  7022. }
  7023. });
  7024. btns.appendChild(okBtn);
  7025. okBtn.className = 'geBtn gePrimaryBtn';
  7026. if (!editorUi.editor.cancelFirst)
  7027. {
  7028. btns.appendChild(cancelBtn);
  7029. }
  7030. div.appendChild(btns);
  7031. this.container = div;
  7032. };