1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032 |
- /*
- * $Id: Dialogs.js,v 1.103 2014/02/11 14:08:15 gaudenz Exp $
- * Copyright (c) 2006-2010, JGraph Ltd
- */
- var StorageDialog = function(editorUi, fn)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.whiteSpace = 'nowrap';
-
- var elt = editorUi.addLanguageMenu(div);
- var bottom = '28px';
-
- if (elt != null)
- {
- elt.style.bottom = bottom;
- }
-
- if (!editorUi.isOffline())
- {
- var help = document.createElement('a');
- help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
- help.setAttribute('title', mxResources.get('help'));
- help.setAttribute('target', '_blank');
- help.style.position = 'absolute';
- help.style.textDecoration = 'none';
- help.style.cursor = 'pointer';
- help.style.fontSize = '12px';
- help.style.bottom = bottom;
- help.style.left = '26px';
- help.style.color = 'gray';
- mxUtils.write(help, mxResources.get('help'));
-
- div.appendChild(help);
- }
- var demo = document.createElement('div');
- demo.style.position = 'absolute';
- demo.style.cursor = 'pointer';
- demo.style.fontSize = '12px';
- demo.style.bottom = bottom;
- demo.style.color = 'gray';
- mxUtils.write(demo, mxResources.get('decideLater'));
-
- if (editorUi.isOfflineApp())
- {
- demo.style.right = '20px';
- }
- else
- {
- mxUtils.setPrefixedStyle(demo.style, 'transform', 'translate(-50%,0)');
- demo.style.left = '50%';
- }
-
- this.init = function()
- {
- if (mxClient.IS_QUIRKS || document.documentMode == 8)
- {
- demo.style.marginLeft = -Math.round(demo.clientWidth / 2) + 'px';
- }
- };
-
- div.appendChild(demo);
-
- mxEvent.addListener(demo, 'click', function()
- {
- editorUi.hideDialog();
- var prev = Editor.useLocalStorage;
- editorUi.createFile(editorUi.defaultFilename, null, null, App.MODE_DEVICE);
- editorUi.setMode(null);
- Editor.useLocalStorage = prev;
- });
-
- var buttons = document.createElement('div');
-
- if (mxClient.IS_QUIRKS)
- {
- buttons.style.whiteSpace = 'nowrap';
- buttons.style.cssFloat = 'left';
- }
- buttons.style.border = '1px solid #d3d3d3';
- buttons.style.borderWidth = '1px 0px 1px 0px';
- buttons.style.padding = '26px 0px 12px 0px';
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
- cb.setAttribute('checked', 'checked');
- cb.defaultChecked = true;
-
- function addLogo(img, title, mode, clientName)
- {
- var button = document.createElement('a');
- button.style.overflow = 'hidden';
-
- var logo = document.createElement('img');
- logo.setAttribute('src', img);
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '60px';
- logo.style.height = '60px';
- logo.style.paddingBottom = '6px';
- button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
- button.className = 'geBaseButton';
- button.style.position = 'relative';
- button.style.margin = '4px';
- button.style.padding = '8px 10px 12px 10px';
- button.style.whiteSpace = 'nowrap';
-
- // Workaround for quirks is a vertical list (limited to max 2 items)
- if (mxClient.IS_QUIRKS)
- {
- button.style.cssFloat = 'left';
- button.style.zoom = '1';
- }
- button.appendChild(logo);
-
- var label = document.createElement('div');
- button.appendChild(label);
- mxUtils.write(label, title);
-
- function initButton()
- {
- mxEvent.addListener(button, 'click', function()
- {
- // Special case: Redirect all drive users to draw.io pro
- if (mode == App.MODE_GOOGLE && !editorUi.isDriveDomain())
- {
- window.location.hostname = DriveClient.prototype.newAppHostname;
- }
- else if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- // Tries immediate authentication
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
- editorUi.setMode(mode, cb.checked);
- fn();
- }));
- }
- else
- {
- editorUi.setMode(mode, cb.checked);
- fn();
- }
- });
- };
-
- // Supports lazy loading
- if (clientName != null && editorUi[clientName] == null)
- {
- logo.style.visibility = 'hidden';
- mxUtils.setOpacity(label, 10);
- var size = 12;
-
- var spinner = new Spinner({
- lines: 12, // The number of lines to draw
- length: size, // The length of each line
- width: 5, // The line thickness
- radius: 10, // The radius of the inner circle
- rotate: 0, // The rotation offset
- color: '#000', // #rgb or #rrggbb
- speed: 1.5, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- top: '40%',
- zIndex: 2e9 // The z-index (defaults to 2000000000)
- });
- spinner.spin(button);
-
- // Timeout after 30 secs
- var timeout = window.setTimeout(function()
- {
- if (editorUi[clientName] == null)
- {
- spinner.stop();
- button.style.display = 'none';
- }
- }, 30000);
-
- editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
- {
- if (editorUi[clientName] != null)
- {
- window.clearTimeout(timeout);
- mxUtils.setOpacity(label, 100);
- logo.style.visibility = '';
- spinner.stop();
- initButton();
- }
- }));
- }
- else
- {
- initButton();
- }
- buttons.appendChild(button);
- };
- var hd = document.createElement('p');
- hd.style.fontSize = '16pt';
- hd.style.padding = '0px';
- hd.style.paddingTop = '4px';
- hd.style.paddingBottom = '20px';
- hd.style.margin = '0px';
- hd.style.color = 'gray';
- mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
- div.appendChild(hd);
-
- if (typeof window.DriveClient === 'function')
- {
- addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
- }
- if (typeof window.DropboxClient === 'function')
- {
- addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
- }
-
- if (typeof window.OneDriveClient === 'function')
- {
- addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
- }
-
- if (!mxClient.IS_IOS || urlParams['storage'] == 'device')
- {
- addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
- }
-
- if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
- {
- addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
- }
-
- div.appendChild(buttons);
- var p2 = document.createElement('p');
- p2.style.paddingTop = '10px';
- p2.appendChild(cb);
-
- var span = document.createElement('span');
- span.style.color = 'gray';
- span.style.fontSize = '12px';
- mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
- p2.appendChild(span);
- buttons.appendChild(p2);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
- // Checks if Google Drive is missing after a 5 sec delay
- if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
- (document.documentMode == null || document.documentMode >= 10))
- {
- window.setTimeout(function()
- {
- if (editorUi.drive == null)
- {
- // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
- // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
- var p3 = document.createElement('p');
- p3.style.padding = '8px';
- p3.style.fontSize = '9pt';
- p3.style.marginTop = '-14px';
- p3.innerHTML = '<a style="background-color:#dcdcdc;padding:5px;color:black;text-decoration:none;" ' +
- 'href="https://plus.google.com/u/0/+DrawIo1/posts/1HTrfsb5wDN" target="_blank">' +
- '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top"> ' +
- mxResources.get('googleDriveMissing') + '</a>';
- div.appendChild(p3);
- }
- }, 5000);
- }
-
- this.container = div;
- };
- /**
- * Constructs a dialog for creating new files from templates.
- */
- var SplashDialog = function(editorUi)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- editorUi.addLanguageMenu(div);
- var help = null;
-
- if (!editorUi.isOffline())
- {
- help = document.createElement('a');
- help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
- help.setAttribute('title', mxResources.get('help'));
- help.setAttribute('target', '_blank');
- help.style.position = 'absolute';
- help.style.fontSize = '12px';
- help.style.textDecoration = 'none';
- help.style.cursor = 'pointer';
- help.style.bottom = '22px';
- help.style.left = '26px';
- help.style.color = 'gray';
- mxUtils.write(help, mxResources.get('help'));
-
- div.appendChild(help);
- }
- var hd = document.createElement('p');
- hd.style.fontSize = '16pt';
- hd.style.padding = '0px';
- hd.style.paddingTop = '2px';
- hd.style.margin = '0px';
- hd.style.color = 'gray';
-
- var logo = document.createElement('img');
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '40px';
- logo.style.height = '40px';
- logo.style.marginRight = '12px';
- logo.style.paddingBottom = '4px';
-
- var service = '';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- logo.src = IMAGE_PATH + '/google-drive-logo.svg';
- service = mxResources.get('googleDrive');
-
- if (help != null)
- {
- help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Google+Drive');
- }
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- logo.src = IMAGE_PATH + '/dropbox-logo.svg';
- service = mxResources.get('dropbox');
-
- if (help != null)
- {
- help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Dropbox');
- }
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- logo.src = IMAGE_PATH + '/onedrive-logo.svg';
- service = mxResources.get('oneDrive');
-
- if (help != null)
- {
- help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+OneDrive');
- }
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- logo.src = IMAGE_PATH + '/osa_database.png';
- service = mxResources.get('browser');
- }
- else
- {
- logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
- service = mxResources.get('device');
- }
- hd.appendChild(logo);
-
- mxUtils.write(hd, service);
-
- div.appendChild(hd);
- var buttons = document.createElement('div');
-
- if (mxClient.IS_QUIRKS)
- {
- buttons.style.whiteSpace = 'nowrap';
- buttons.style.cssFloat = 'left';
- }
- buttons.style.border = '1px solid #d3d3d3';
- buttons.style.borderWidth = '1px 0px 1px 0px';
- buttons.style.padding = '18px 0px 24px 0px';
- buttons.style.margin = '4px 0px 0px 0px';
-
- var btn = document.createElement('button');
- btn.className = 'geBigButton';
- btn.style.marginBottom = '8px';
- btn.style.overflow = 'hidden';
- btn.style.width = '340px';
-
- if (mxClient.IS_QUIRKS)
- {
- btn.style.width = '340px';
- }
-
- mxUtils.write(btn, mxResources.get('createNewDiagram'));
-
- mxEvent.addListener(btn, 'click', function()
- {
- editorUi.hideDialog();
- editorUi.actions.get('new').funct();
- });
-
- buttons.appendChild(btn);
- mxUtils.br(buttons);
-
- var btn = document.createElement('button');
- btn.className = 'geBigButton';
- btn.style.marginBottom = '22px';
- btn.style.overflow = 'hidden';
- btn.style.width = '340px';
-
- if (mxClient.IS_QUIRKS)
- {
- btn.style.width = '340px';
- }
-
- mxUtils.write(btn, mxResources.get('openExistingDiagram'));
-
- mxEvent.addListener(btn, 'click', function()
- {
- editorUi.actions.get('open').funct();
- });
-
- buttons.appendChild(btn);
- var storage = 'undefined';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- storage = mxResources.get('googleDrive');
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- storage = mxResources.get('dropbox');
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- storage = mxResources.get('oneDrive');
- }
- else if (editorUi.mode == App.MODE_DEVICE)
- {
- storage = mxResources.get('device');
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- storage = mxResources.get('browser');
- }
-
- var serviceCount = 0;
-
- if (editorUi.drive != null)
- {
- serviceCount++
- }
-
- if (editorUi.dropbox != null)
- {
- serviceCount++
- }
-
- if (isLocalStorage)
- {
- serviceCount++
- }
-
- if (!mxClient.IS_IOS)
- {
- serviceCount++
- }
- if (serviceCount > 1)
- {
- var link = document.createElement('a');
- link.setAttribute('href', 'javascript:void(0)');
- link.style.display = 'block';
- link.style.marginTop = '6px';
- mxUtils.write(link, mxResources.get('notUsingService', [storage]));
-
- mxEvent.addListener(link, 'click', function()
- {
- editorUi.hideDialog(false);
- editorUi.clearMode();
- editorUi.showSplash(true);
- });
-
- buttons.appendChild(link);
- var driveUser = (editorUi.drive != null) ? editorUi.drive.getUser() : null;
-
- if (editorUi.mode == App.MODE_GOOGLE && driveUser != null)
- {
- btn.style.marginBottom = '24px';
-
- var link = document.createElement('a');
- link.setAttribute('href', 'javascript:void(0)');
- link.style.display = 'block';
- link.style.marginTop = '2px';
- mxUtils.write(link, mxResources.get('changeUser') + ' (' + driveUser.displayName + ')');
- // Makes room after last big buttons
- btn.style.marginBottom = '16px';
- buttons.style.paddingBottom = '18px';
-
- mxEvent.addListener(link, 'click', function()
- {
- editorUi.hideDialog();
- editorUi.drive.clearUserId();
- editorUi.drive.setUser(null);
- gapi.auth.signOut();
- // Restores current dialog after clearing user
- editorUi.setMode(App.MODE_GOOGLE);
- editorUi.hideDialog();
- editorUi.showSplash();
-
- // FIXME: Does not force showing the auth dialog if only one user is logged in
- editorUi.drive.authorize(false, mxUtils.bind(this, mxUtils.bind(this, function()
- {
- editorUi.hideDialog();
- editorUi.showSplash();
- })), mxUtils.bind(this, function(resp)
- {
- editorUi.handleError(resp, null, function()
- {
- editorUi.hideDialog();
- editorUi.showSplash();
- });
- }));
- });
- buttons.appendChild(link);
- }
- }
-
- div.appendChild(buttons);
-
- // Changes Chrome App dialog
- if (mxClient.IS_CHROMEAPP)
- {
- hd.style.paddingTop = '12px';
- hd.innerHTML = '';
- mxUtils.write(hd, mxResources.get('chooseAnOption') + ':');
- buttons.style.border = 'none';
- buttons.style.padding = '16px 0px 0px 0px';
- btn.style.marginBottom = '0px';
- }
-
- this.init = function()
- {
- if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
- {
- var fn = function()
- {
- var oneDriveUser = editorUi.oneDrive.getUser();
-
- if (oneDriveUser != null)
- {
- btn.style.marginBottom = '24px';
-
- var link = document.createElement('a');
- link.setAttribute('href', 'javascript:void(0)');
- link.style.display = 'block';
- link.style.marginTop = '2px';
- mxUtils.write(link, mxResources.get('changeUser') + ' (' + oneDriveUser.displayName + ')');
- // Makes room after last big buttons
- btn.style.marginBottom = '16px';
- buttons.style.paddingBottom = '18px';
-
- mxEvent.addListener(link, 'click', function()
- {
- editorUi.oneDrive.logout();
- link.parentNode.removeChild(link);
-
- // NOTE: Could use userEvent=true here but it seems the logout
- // call is asynchronous and the client isn't fully logged out
- // when called immediately so we show the auth dialog to get
- // a delay (sometimes event that is not enough so should use
- // async callback on logout but that seems to be broken)
- editorUi.oneDrive.execute(fn);
- });
-
- buttons.appendChild(link);
- }
- };
-
- editorUi.oneDrive.execute(fn);
- }
- };
-
- this.container = div;
- };
- /**
- *
- */
- var ConfirmDialog = function(editorUi, message, okFn, cancelFn)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- var p2 = document.createElement('div');
- p2.style.padding = '6px';
- p2.style.overflow = 'auto';
- p2.style.maxHeight = '40px';
-
- if (mxClient.IS_QUIRKS)
- {
- p2.style.height = '60px';
- }
-
- mxUtils.write(p2, message);
- div.appendChild(p2);
-
- var btns = document.createElement('div');
- btns.style.marginTop = '16px';
- btns.style.textAlign = 'center';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
-
- if (cancelFn != null)
- {
- cancelFn();
- }
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- var okBtn = mxUtils.button(mxResources.get('ok'), function()
- {
- editorUi.hideDialog();
-
- if (okFn != null)
- {
- okFn();
- }
- });
- btns.appendChild(okBtn);
-
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- *
- */
- var ErrorDialog = function(editorUi, title, message, buttonText, fn, retry, buttonText2, fn2, hide)
- {
- hide = (hide != null) ? hide : true;
-
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- if (title != null)
- {
- var hd = document.createElement('div');
- hd.style.padding = '0px';
- hd.style.margin = '0px';
- hd.style.fontSize = '18px';
- hd.style.paddingBottom = '16px';
- hd.style.marginBottom = '16px';
- hd.style.borderBottom = '1px solid #c0c0c0';
- hd.style.color = 'gray';
- mxUtils.write(hd, title);
- div.appendChild(hd);
- }
- var p2 = document.createElement('div');
- p2.style.padding = '6px';
- p2.innerHTML = message;
- div.appendChild(p2);
-
- var btns = document.createElement('div');
- btns.style.marginTop = '16px';
- btns.style.textAlign = 'right';
-
- if (retry != null)
- {
- var retryBtn = mxUtils.button(mxResources.get('tryAgain'), function()
- {
- editorUi.hideDialog();
- retry();
- });
- retryBtn.className = 'geBtn';
- btns.appendChild(retryBtn);
-
- btns.style.textAlign = 'center';
- }
-
- var btn = mxUtils.button(buttonText, function()
- {
- if (hide)
- {
- editorUi.hideDialog();
- }
-
- if (fn != null)
- {
- fn();
- }
- });
- btn.className = 'geBtn';
-
- btns.appendChild(btn);
-
- if (buttonText2 != null)
- {
- var mainBtn = mxUtils.button(buttonText2, function()
- {
- if (hide)
- {
- editorUi.hideDialog();
- }
-
- if (fn2 != null)
- {
- fn2();
- }
- });
- mainBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(mainBtn);
- }
-
- this.init = function()
- {
- btn.focus();
- };
-
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new embed dialog
- */
- var EmbedHtmlDialog = function(editorUi)
- {
- var file = editorUi.getCurrentFile();
- var div = document.createElement('div');
- var graph = editorUi.editor.graph;
- var bounds = graph.getGraphBounds();
- var scale = graph.view.scale;
- var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
- var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
- mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
- mxUtils.br(div);
-
- var textarea = document.createElement('textarea');
- textarea.style.marginTop = '6px';
- textarea.style.width = '550px';
- textarea.style.height = '160px';
- textarea.style.marginBottom = '10px';
- textarea.style.resize = 'none';
-
- div.appendChild(textarea);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('embedNotice') + ': ');
- mxUtils.br(div);
- var textarea2 = document.createElement('textarea');
- textarea2.style.marginTop = '6px';
- textarea2.style.width = '550px';
- textarea2.style.height = '20px';
- textarea2.style.resize = 'none';
- textarea2.style.marginBottom = '10px';
- div.appendChild(textarea2);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('publicDiagramUrl') + ': ');
-
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.setAttribute('size', '28');
- urlInput.style.width = '340px';
- urlInput.style.marginBottom = '8px';
- div.appendChild(urlInput);
- mxUtils.br(div);
-
- var options = document.createElement('div');
- options.style.paddingTop = '10px';
- options.style.textAlign = 'center';
- var fitCheckBox = document.createElement('input');
- fitCheckBox.setAttribute('type', 'checkbox');
- fitCheckBox.setAttribute('checked', 'checked');
- fitCheckBox.defaultChecked = true;
- options.appendChild(fitCheckBox);
- mxUtils.write(options, mxResources.get('fit'));
- var label = document.createElement('span');
- label.style.marginLeft = '10px';
- mxUtils.write(label, mxResources.get('zoom') + ': ');
- options.appendChild(label);
-
- var zoomInput = document.createElement('input');
- zoomInput.setAttribute('type', 'text');
- zoomInput.setAttribute('size', '4');
- zoomInput.style.width = '40px';
- zoomInput.value = '100%';
- options.appendChild(zoomInput);
- var label = document.createElement('span');
- label.style.marginLeft = '10px';
- mxUtils.write(label, mxResources.get('link') + ': ');
- options.appendChild(label);
-
- var borderColorInput = document.createElement('input');
- borderColorInput.setAttribute('type', 'text');
- borderColorInput.setAttribute('size', '8');
- borderColorInput.style.width = '50px';
- borderColorInput.value = '#0000ff';
- options.appendChild(borderColorInput);
-
- mxUtils.br(options);
- var lightboxCheckBox = document.createElement('input');
- lightboxCheckBox.setAttribute('type', 'checkbox');
- lightboxCheckBox.setAttribute('checked', 'checked');
- lightboxCheckBox.defaultChecked = true;
- lightboxCheckBox.style.marginTop = '14px';
- options.appendChild(lightboxCheckBox);
- mxUtils.write(options, mxResources.get('lightbox'));
- var editCheckBox = document.createElement('input');
- editCheckBox.setAttribute('type', 'checkbox');
- editCheckBox.setAttribute('checked', 'checked');
- editCheckBox.defaultChecked = true;
- editCheckBox.style.marginLeft = '10px';
- //options.appendChild(editCheckBox);
- //mxUtils.write(options, mxResources.get('edit'));
- var layersCheckBox = document.createElement('input');
- layersCheckBox.setAttribute('type', 'checkbox');
- layersCheckBox.style.marginLeft = '10px';
-
- var model = editorUi.editor.graph.getModel();
-
- if (model.getChildCount(model.getRoot()) > 1)
- {
- layersCheckBox.setAttribute('checked', 'checked');
- layersCheckBox.defaultChecked = true;
- }
- else
- {
- layersCheckBox.setAttribute('disabled', 'disabled');
- }
-
- options.appendChild(layersCheckBox);
- mxUtils.write(options, mxResources.get('layers'));
-
- var zoomCheckBox = document.createElement('input');
- zoomCheckBox.setAttribute('type', 'checkbox');
- zoomCheckBox.style.marginLeft = '10px';
- options.appendChild(zoomCheckBox);
- mxUtils.write(options, mxResources.get('zoom'));
- div.appendChild(options);
- function update(force)
- {
- var s = [];
-
- // Scans shapes for stencils
- var stencilNames = new Object();
- var states = graph.view.states.getValues();
-
- function addName(name)
- {
- if (name != null)
- {
- var dot = name.lastIndexOf('.');
-
- if (dot > 0)
- {
- name = name.substring(dot + 1, name.length);
- }
-
- if (stencilNames[name] == null)
- {
- stencilNames[name] = true;
- s.push(name);
- }
- }
- }
-
- for (var i = 0; i < states.length; i++)
- {
- var state = states[i];
- var shape = state.style[mxConstants.STYLE_SHAPE];
- addName(mxStencilRegistry.getBasenameForStencil(shape));
-
- // Adds package names for markers in edges
- if (state.view.graph.model.isEdge(state.cell))
- {
- addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_STARTARROW]));
- addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_ENDARROW]));
- }
- }
-
- var data = {};
-
- if (borderColorInput.value != '' && borderColorInput.value != mxConstants.NONE)
- {
- data.highlight = borderColorInput.value;
- }
-
- if (!lightboxCheckBox.checked)
- {
- data.lightbox = false;
- }
-
- data.nav = graph.foldingEnabled;
- var zoom = parseInt(zoomInput.value);
-
- if (!isNaN(zoom) && zoom != 100)
- {
- data.zoom = zoom / 100;
- }
-
- var tb = [];
-
- if (zoomCheckBox.checked)
- {
- tb.push('zoom');
- data.resize = true;
- }
-
- if (layersCheckBox.checked)
- {
- tb.push('layers');
- }
-
- if (tb.length > 0)
- {
- if (lightboxCheckBox)
- {
- tb.push('lightbox');
- }
-
- data.toolbar = tb.join(' ');
- }
-
- if (editCheckBox.checked)
- {
- if (urlInput.value != '')
- {
- data.edit = urlInput.value;
- }
- else
- {
- data.edit = '_blank';
- }
- }
-
- if (urlInput.value != '')
- {
- data.url = urlInput.value;
- }
- else
- {
- data.xml = editorUi.getFileData(true);
- }
-
- textarea.value = '<div class="mxgraph" style="' +
- ((fitCheckBox.checked) ? 'max-width:100%;' : '') +
- ((tb != '') ? 'border:1px solid transparent;' : '') +
- '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>';
-
- var s2 = (s.length > 0) ? (((urlParams['dev'] == '1') ?
- 'https://test.draw.io/embed2.js?dev=1&s=' :
- 'https://www.draw.io/embed2.js?s=') + s.join(';')) :
- (((urlParams['dev'] == '1') ?
- 'https://test.draw.io/js/viewer.min.js' :
- 'https://www.draw.io/js/viewer.min.js'));
-
- textarea2.value = '<script type="text/javascript" src="' + s2 + '"></script>';
- textarea.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- textarea.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
-
- this.init = function()
- {
- update();
- };
- mxEvent.addListener(urlInput, 'change', update);
- mxEvent.addListener(borderColorInput, 'change', update);
- mxEvent.addListener(zoomInput, 'change', update);
- mxEvent.addListener(layersCheckBox, 'change', update);
- mxEvent.addListener(editCheckBox, 'change', update);
- mxEvent.addListener(fitCheckBox, 'change', update);
- mxEvent.addListener(lightboxCheckBox, 'change', update);
- mxEvent.addListener(zoomCheckBox, 'change', update);
-
- var buttons = document.createElement('div');
- buttons.style.paddingTop = '20px';
- buttons.style.textAlign = 'right';
-
- if (!editorUi.isOffline())
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open('https://support.draw.io/pages/viewpage.action?pageId=12878123');
- });
-
- helpBtn.className = 'geBtn';
- buttons.appendChild(helpBtn);
- }
- // Loads forever in IE9
- if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
- (document.documentMode == null || document.documentMode > 9))
- {
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- var wnd = window.open();
- var doc = wnd.document;
-
- if (document.compatMode === 'CSS1Compat')
- {
- doc.writeln('<!DOCTYPE html>');
- }
-
- doc.writeln('<html>');
- doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
- '</title><meta charset="utf-8"></head>');
- doc.writeln('<body>');
- doc.writeln(textarea.value);
-
- var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
-
- if (direct)
- {
- doc.writeln(textarea2.value);
- }
-
- doc.writeln('</body>');
- doc.writeln('</html>');
- doc.close();
-
- // Adds script tag after closing page and delay to fix timing issues
- if (!direct)
- {
- var info = wnd.document.createElement('div');
- info.marginLeft = '26px';
- info.marginTop = '26px';
- mxUtils.write(info, mxResources.get('updatingDocument'));
- var img = wnd.document.createElement('img');
- img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
- '/' + IMAGE_PATH + '/spin.gif');
- img.style.marginLeft = '6px';
- info.appendChild(img);
-
- wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
-
- window.setTimeout(function()
- {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = /<script.*?src="(.*?)"/.exec(textarea2.value)[1];
- doc.body.appendChild(script);
-
- info.parentNode.removeChild(info);
- }, 20);
- }
- });
-
- previewBtn.className = 'geBtn';
- buttons.appendChild(previewBtn);
- }
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
-
- var copyBtn = mxUtils.button(mxResources.get('copy'), function()
- {
- textarea.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- textarea.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- document.execCommand('copy');
- editorUi.alert(mxResources.get('copiedToClipboard'));
- });
- buttons.appendChild(closeBtn);
- // Does not work in Safari and shows annoying dialog for IE11-
- if (!mxClient.IS_SF && document.documentMode == null)
- {
- buttons.appendChild(copyBtn);
- copyBtn.className = 'geBtn gePrimaryBtn';
- closeBtn.className = 'geBtn';
- }
- else
- {
- closeBtn.className = 'geBtn gePrimaryBtn';
- }
-
- div.appendChild(buttons);
-
- this.container = div;
- };
- /**
- * Constructs a new embed dialog
- */
- var EmbedSvgDialog = function(editorUi, isImage)
- {
- var file = editorUi.getCurrentFile();
- var div = document.createElement('div');
- var graph = editorUi.editor.graph;
- var bounds = graph.getGraphBounds();
- var scale = graph.view.scale;
- var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
- var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
- mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
- mxUtils.br(div);
-
- var textarea = document.createElement('textarea');
- textarea.style.marginTop = '6px';
- textarea.style.width = '550px';
- textarea.style.height = '280px';
- textarea.style.resize = 'none';
- div.appendChild(textarea);
- mxUtils.br(div);
- var options = document.createElement('div');
- options.style.paddingTop = '16px';
- options.style.textAlign = 'center';
- var fitCheckBox = document.createElement('input');
- fitCheckBox.setAttribute('type', 'checkbox');
- fitCheckBox.setAttribute('checked', 'checked');
- fitCheckBox.defaultChecked = true;
- options.appendChild(fitCheckBox);
- mxUtils.write(options, mxResources.get('fit'));
- var shadowCheckBox = document.createElement('input');
- shadowCheckBox.setAttribute('type', 'checkbox');
- shadowCheckBox.style.marginLeft = '30px';
-
- if (graph.shadowVisible)
- {
- shadowCheckBox.setAttribute('checked', 'checked');
- shadowCheckBox.defaultChecked = true;
- }
-
- if (!isImage || editorUi.isExportToCanvas())
- {
- options.appendChild(shadowCheckBox);
- mxUtils.write(options, mxResources.get('shadow'));
- }
-
- var imageCheckBox = document.createElement('input');
- imageCheckBox.setAttribute('type', 'checkbox');
- imageCheckBox.style.marginLeft = '30px';
-
- if (!isImage)
- {
- options.appendChild(imageCheckBox);
- mxUtils.write(options, mxResources.get('image'));
- }
-
- var retinaCheckBox = document.createElement('input');
- retinaCheckBox.setAttribute('type', 'checkbox');
- retinaCheckBox.style.marginLeft = '30px';
-
- if (isImage)
- {
- options.appendChild(retinaCheckBox);
- mxUtils.write(options, mxResources.get('retina'));
- }
-
- var lightboxCheckBox = document.createElement('input');
- lightboxCheckBox.setAttribute('type', 'checkbox');
- lightboxCheckBox.setAttribute('checked', 'checked');
- lightboxCheckBox.defaultChecked = true;
- lightboxCheckBox.style.marginLeft = '30px';
- options.appendChild(lightboxCheckBox);
- mxUtils.write(options, mxResources.get('lightbox'));
-
- var layersCheckBox = document.createElement('input');
- layersCheckBox.setAttribute('type', 'checkbox');
- layersCheckBox.style.marginLeft = '30px';
-
- var model = editorUi.editor.graph.getModel();
-
- if (model.getChildCount(model.getRoot()) > 1)
- {
- layersCheckBox.setAttribute('checked', 'checked');
- layersCheckBox.defaultChecked = true;
- }
- else
- {
- layersCheckBox.setAttribute('disabled', 'disabled');
- }
- options.appendChild(layersCheckBox);
- mxUtils.write(options, mxResources.get('layers'));
-
- div.appendChild(options);
- function update(force)
- {
- if (isImage)
- {
- var bounds = editorUi.editor.graph.getGraphBounds();
-
- function doUpdate(dataUri)
- {
- var onclick = ' ';
- var css = '';
-
- // Adds double click handling
- if (lightboxCheckBox.checked)
- {
- // KNOWN: Message passing does not seem to work in IE11
- 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(" +
- "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" +
- ((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
- css += 'cursor:pointer;';
- }
-
- if (fitCheckBox.checked)
- {
- css += 'max-width:100%;';
- }
-
- var atts = '';
-
- if (retinaCheckBox.checked)
- {
- atts = ' width="' + Math.round(bounds.width) + '" height="' + Math.round(bounds.height) + '"';
- }
- textarea.value = '<img src="' + dataUri + '"' + atts +
- ((css != '') ? ' style="' + css + '"' : '') +
- onclick + '/>';
- textarea.focus();
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- textarea.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
-
- if (editorUi.isExportToCanvas())
- {
- var scale = 1;
- var ignoreSelection = true;
- textarea.value = mxResources.get('updatingDocument');
- editorUi.exportToCanvas(mxUtils.bind(this, function(canvas)
- {
- var xml = (lightboxCheckBox.checked) ? editorUi.getFileData(true) : null;
- var data = editorUi.createPngDataUri(canvas, xml);
- doUpdate(data);
- }), null, null, null, mxUtils.bind(this, function(e)
- {
- textarea.value = '';
- editorUi.handleError({message: mxResources.get('unknownError')});
- }), null, true, (retinaCheckBox.checked) ? 2 : 1, null, shadowCheckBox.checked);
- }
- else
- {
- var data = editorUi.getFileData(true);
-
- if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
- {
- textarea.value = mxResources.get('updatingDocument');
- var size = '';
-
- if (retinaCheckBox.checked)
- {
- size = '&w=' + Math.round(2 * bounds.width) +
- '&h=' + Math.round(2 * bounds.height);
- }
-
- var embed = (lightboxCheckBox.checked) ? '1' : '0';
- var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
- '&base64=1&embedXml=' + embed + size + '&xml=' +
- encodeURIComponent(data));
-
- // LATER: Updates on each change, add a delay
- req.send(mxUtils.bind(this, function()
- {
- if (req.getStatus() == 200)
- {
- doUpdate('data:image/png;base64,' + req.getText());
- }
- else
- {
- textarea.value = '';
- editorUi.handleError({message: mxResources.get('unknownError')});
- }
- }));
- }
- else
- {
- textarea.value = '';
- editorUi.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
- }
- }
- }
- else
- {
- var svgRoot = editorUi.editor.graph.getSvg();
-
- // Keeps hashtag links on same page
- var links = svgRoot.getElementsByTagName('a');
-
- if (links != null)
- {
- for (var i = 0; i < links.length; i++)
- {
- var href = links[i].getAttribute('href');
-
- if (href != null && href.charAt(0) == '#' &&
- links[i].getAttribute('target') == '_blank')
- {
- links[i].removeAttribute('target');
- }
- }
- }
-
- if (lightboxCheckBox.checked)
- {
- svgRoot.setAttribute('content', editorUi.getFileData(true));
- }
-
- // Adds shadow filter
- if (shadowCheckBox.checked)
- {
- editorUi.editor.addSvgShadow(svgRoot);
- }
-
- // SVG inside image tag
- if (imageCheckBox.checked)
- {
- var onclick = ' ';
- var css = '';
-
- // Adds double click handling
- if (lightboxCheckBox.checked)
- {
- // KNOWN: Message passing does not seem to work in IE11
- 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(" +
- "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" +
- ((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
- css += 'cursor:pointer;';
- }
-
- if (fitCheckBox.checked)
- {
- css += 'max-width:100%;';
- }
-
- // Images inside IMG don't seem to work so embed them all
- editorUi.convertImages(svgRoot, function(svgRoot)
- {
- textarea.value = '<img src="' + editorUi.createSvgDataUri(mxUtils.getXml(svgRoot)) + '"' +
- ((css != '') ? ' style="' + css + '"' : '') + onclick + '/>';
- });
- }
- else
- {
- var css = '';
-
- // Adds double click handling
- if (lightboxCheckBox.checked)
- {
- // KNOWN: Message passing does not seem to work in IE11
- var js = "(function(svg){var src=window.event.target||window.event.srcElement;" +
- // Ignores link events
- "while (src!=null&&src.nodeName.toLowerCase()!='a'){src=src.parentNode;}if(src==null)" +
- // Focus existing lightbox
- "{if(svg.wnd!=null&&!svg.wnd.closed){svg.wnd.focus();}else{var r=function(evt){" +
- // Message handling
- "if(evt.data=='ready'&&evt.source==svg.wnd){svg.wnd.postMessage(decodeURIComponent(" +
- "svg.getAttribute('content')),'*');window.removeEventListener('message',r);}};" +
- "window.addEventListener('message',r);" +
- // Opens lightbox window
- "svg.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0&edit=_blank" +
- ((layersCheckBox.checked) ? '&layers=1' : '') + "');}}})(this);";
- svgRoot.setAttribute('onclick', js);
- css += 'cursor:pointer;';
- }
-
- // Adds responsive size
- if (fitCheckBox.checked)
- {
- var w = parseInt(svgRoot.getAttribute('width'));
- var h = parseInt(svgRoot.getAttribute('height'));
- svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
- css += 'max-width:100%;max-height:' + h + 'px;';
- svgRoot.removeAttribute('height');
- }
-
- if (css != '')
- {
- svgRoot.setAttribute('style', css);
- }
- textarea.value = mxUtils.getXml(svgRoot);
- }
- textarea.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- textarea.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- };
-
- this.init = function()
- {
- update();
- };
-
- mxEvent.addListener(imageCheckBox, 'change', update);
- mxEvent.addListener(retinaCheckBox, 'change', update);
- mxEvent.addListener(shadowCheckBox, 'change', update);
- mxEvent.addListener(fitCheckBox, 'change', update);
- mxEvent.addListener(lightboxCheckBox, 'change', update);
- mxEvent.addListener(layersCheckBox, 'change', update);
-
- var buttons = document.createElement('div');
- buttons.style.paddingTop = '18px';
- buttons.style.textAlign = 'right';
-
- if (!editorUi.isOffline() && !isImage)
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open('https://support.draw.io/pages/viewpage.action?pageId=12222606');
- });
-
- helpBtn.className = 'geBtn';
- buttons.appendChild(helpBtn);
- }
- // Loads forever in IE9
- if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
- (document.documentMode == null || document.documentMode > 9))
- {
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- var wnd = window.open();
- var doc = wnd.document;
- doc.writeln('<html><head><title>' + encodeURIComponent(mxResources.get('preview')) +
- '</title><meta charset="utf-8"></head>' +
- '<body>' + textarea.value + '</body></html>');
- doc.close();
- });
-
- previewBtn.className = 'geBtn';
- buttons.appendChild(previewBtn);
- }
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
-
- var copyBtn = mxUtils.button(mxResources.get('copy'), function()
- {
- textarea.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- textarea.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- document.execCommand('copy');
- editorUi.alert(mxResources.get('copiedToClipboard'));
- });
- buttons.appendChild(closeBtn);
- // Does not work in Safari and shows annoying dialog for IE11-
- if (!mxClient.IS_SF && document.documentMode == null)
- {
- buttons.appendChild(copyBtn);
- copyBtn.className = 'geBtn gePrimaryBtn';
- closeBtn.className = 'geBtn';
- }
- else
- {
- closeBtn.className = 'geBtn gePrimaryBtn';
- }
-
- div.appendChild(buttons);
-
- this.container = div;
- };
- /**
- * Constructs a dialog for embedding the diagram in Google Sites.
- */
- var GoogleSitesDialog = function(editorUi)
- {
- var div = document.createElement('div');
- var graph = editorUi.editor.graph;
- var bounds = graph.getGraphBounds();
- var scale = graph.view.scale;
- var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
- var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
- mxUtils.write(div, mxResources.get('googleGadget') + ':');
- mxUtils.br(div);
-
- var gadgetInput = document.createElement('input');
- gadgetInput.setAttribute('type', 'text');
- gadgetInput.style.marginBottom = '8px';
- gadgetInput.style.marginTop = '2px';
- gadgetInput.style.width = '410px';
- div.appendChild(gadgetInput);
- mxUtils.br(div);
-
- this.init = function()
- {
- gadgetInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- gadgetInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
-
- mxUtils.write(div, mxResources.get('top') + ':');
- var topInput = document.createElement('input');
- topInput.setAttribute('type', 'text');
- topInput.setAttribute('size', '4');
- topInput.style.marginRight = '16px';
- topInput.style.marginLeft = '4px';
- topInput.value = x0;
- div.appendChild(topInput);
-
- mxUtils.write(div, mxResources.get('height') + ':');
- var heightInput = document.createElement('input');
- heightInput.setAttribute('type', 'text');
- heightInput.setAttribute('size', '4');
- heightInput.style.marginLeft = '4px';
- heightInput.value = Math.ceil(bounds.height / scale);
- div.appendChild(heightInput);
- mxUtils.br(div);
-
- var hr = document.createElement('hr');
- hr.setAttribute('size', '1');
- hr.style.marginBottom = '16px';
- hr.style.marginTop = '16px';
- div.appendChild(hr);
-
- mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
- mxUtils.br(div);
-
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.setAttribute('size', '28');
- urlInput.style.marginBottom = '8px';
- urlInput.style.marginTop = '2px';
- urlInput.style.width = '410px';
- div.appendChild(urlInput);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('borderWidth') + ':');
- var borderInput = document.createElement('input');
- borderInput.setAttribute('type', 'text');
- borderInput.setAttribute('size', '3');
- borderInput.style.marginBottom = '8px';
- borderInput.style.marginLeft = '4px';
- borderInput.value = '0';
- div.appendChild(borderInput);
- mxUtils.br(div);
- var panCheckBox = document.createElement('input');
- panCheckBox.setAttribute('type', 'checkbox');
- panCheckBox.setAttribute('checked', 'checked');
- panCheckBox.defaultChecked = true;
- panCheckBox.style.marginLeft = '16px';
- div.appendChild(panCheckBox);
- mxUtils.write(div, mxResources.get('pan') + ' ');
- var zoomCheckBox = document.createElement('input');
- zoomCheckBox.setAttribute('type', 'checkbox');
- zoomCheckBox.setAttribute('checked', 'checked');
- zoomCheckBox.defaultChecked = true;
- zoomCheckBox.style.marginLeft = '8px';
- div.appendChild(zoomCheckBox);
- mxUtils.write(div, mxResources.get('zoom') + ' ');
-
- var editCheckBox = document.createElement('input');
- editCheckBox.setAttribute('type', 'checkbox');
- editCheckBox.style.marginLeft = '8px';
- editCheckBox.setAttribute('title', window.location.href);
- div.appendChild(editCheckBox);
- mxUtils.write(div, mxResources.get('edit') + ' ');
-
- var editBlankCheckBox = document.createElement('input');
- editBlankCheckBox.setAttribute('type', 'checkbox');
- editBlankCheckBox.style.marginLeft = '8px';
- div.appendChild(editBlankCheckBox);
- mxUtils.write(div, mxResources.get('asNew') + ' ');
- mxUtils.br(div);
- var resizeCheckBox = document.createElement('input');
- resizeCheckBox.setAttribute('type', 'checkbox');
- resizeCheckBox.setAttribute('checked', 'checked');
- resizeCheckBox.defaultChecked = true;
- resizeCheckBox.style.marginLeft = '16px';
- div.appendChild(resizeCheckBox);
- mxUtils.write(div, mxResources.get('resize') + ' ');
-
- var fitCheckBox = document.createElement('input');
- fitCheckBox.setAttribute('type', 'checkbox');
- fitCheckBox.style.marginLeft = '8px';
- div.appendChild(fitCheckBox);
- mxUtils.write(div, mxResources.get('fit') + ' ');
-
- var embedCheckBox = document.createElement('input');
- embedCheckBox.setAttribute('type', 'checkbox');
- embedCheckBox.style.marginLeft = '8px';
- div.appendChild(embedCheckBox);
- mxUtils.write(div, mxResources.get('embed') + ' ');
- var node = null;
- var s = '';
-
- // Scans shapes for stencils
- var stencilNames = new Object();
- var states = graph.view.states.getValues();
-
- for (var i = 0; i < states.length; i++)
- {
- var state = states[i];
- var shape = state.style[mxConstants.STYLE_SHAPE];
- var basename = mxStencilRegistry.getBasenameForStencil(shape);
-
- if (basename != null)
- {
- if (stencilNames[basename] == null)
- {
- stencilNames[basename] = true;
- s += basename + ';';
- }
- }
- }
-
- var file = editorUi.getCurrentFile();
-
- function update()
- {
- var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
-
- if (embedCheckBox.checked && urlInput.value != '')
- {
- var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
- var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
-
- if (title != null)
- {
- gurl += '&title=' + encodeURIComponent(title);
- }
-
- if (s.length > 0)
- {
- gurl += '&s=' + s;
- }
-
- if (borderInput.value != '' && borderInput.value != '0')
- {
- gurl += '&border=' + borderInput.value;
- }
-
- if (heightInput.value != '')
- {
- gurl += '&height=' + heightInput.value;
- }
-
- gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
- gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
- gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
- gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
- gurl += '&x0=' + Number(topInput.value);
- gurl += '&y0=' + y0;
-
- if (graph.mathEnabled)
- {
- gurl += '&math=1';
- }
-
- if (editBlankCheckBox.checked)
- {
- gurl += '&edit=_blank';
- }
- else if (editCheckBox.checked)
- {
- gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
- }
-
- gadgetInput.value = gurl;
- }
- else if (file.constructor == DriveFile || file.constructor == DropboxFile)
- {
- var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
-
- if (urlInput.value != '')
- {
- gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
- }
- else
- {
- gurl += file.getHash().substring(1);
-
- if (file.constructor == DropboxFile)
- {
- gurl += '&type=2';
- }
- else
- {
- gurl += '&type=1';
- }
- }
-
- if (title != null)
- {
- gurl += '&title=' + encodeURIComponent(title);
- }
-
- if (heightInput.value != '')
- {
- var h = parseInt(heightInput.value) + parseInt(topInput.value);
- gurl += '&height=' + h;
- }
- gadgetInput.value = gurl;
- }
- else
- {
- gadgetInput.value = '';
- }
- };
-
- // Tries to generate public image URL (only for Drive files)
- update();
- urlInput.setAttribute('placeholder', mxResources.get('loading') + '...');
-
- editorUi.getPublicUrl(file, function(url)
- {
- urlInput.setAttribute('placeholder', '');
- urlInput.value = (url != null) ? url : '';
- update();
- });
-
- mxEvent.addListener(panCheckBox, 'change', update);
- mxEvent.addListener(zoomCheckBox, 'change', update);
- mxEvent.addListener(resizeCheckBox, 'change', update);
- mxEvent.addListener(fitCheckBox, 'change', update);
- mxEvent.addListener(editCheckBox, 'change', update);
- mxEvent.addListener(editBlankCheckBox, 'change', update);
- mxEvent.addListener(embedCheckBox, 'change', update);
- mxEvent.addListener(heightInput, 'change', update);
- mxEvent.addListener(topInput, 'change', update);
- mxEvent.addListener(borderInput, 'change', update);
- mxEvent.addListener(urlInput, 'change', update);
-
- mxEvent.addListener(gadgetInput, 'click', function()
- {
- gadgetInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- gadgetInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- });
-
- var buttons = document.createElement('div');
- buttons.style.paddingTop = '12px';
- buttons.style.textAlign = 'right';
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
- closeBtn.className = 'geBtn gePrimaryBtn';
- buttons.appendChild(closeBtn);
-
- div.appendChild(buttons);
-
- this.container = div;
- };
- /**
- * Constructs a dialog for embedding the diagram in Google Sites.
- */
- var IframeDialog = function(editorUi, image, link)
- {
- var div = document.createElement('div');
- var graph = editorUi.editor.graph;
- var bounds = graph.getGraphBounds();
- var scale = graph.view.scale;
- var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
- var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
- mxUtils.write(div, mxResources.get((link) ? 'link' : 'mainEmbedNotice') + ': ');
- mxUtils.br(div);
-
- var iframeInput = document.createElement('input');
- iframeInput.setAttribute('type', 'text');
- iframeInput.style.marginBottom = '8px';
- iframeInput.style.marginTop = '2px';
- iframeInput.style.width = '410px';
- div.appendChild(iframeInput);
- mxUtils.br(div);
-
- this.init = function()
- {
- if (iframeInput.getAttribute('disabled') != 'disabled')
- {
- iframeInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- iframeInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- };
- var widthInput = document.createElement('input');
- widthInput.setAttribute('type', 'text');
- widthInput.style.marginRight = '16px';
- widthInput.style.width = '60px';
- widthInput.style.marginBottom = '8px';
- widthInput.style.marginLeft = '4px';
- widthInput.value = '100%';
-
- if (!image && !link)
- {
- mxUtils.write(div, mxResources.get('width') + ':');
- div.appendChild(widthInput);
- }
-
- var heightInput = document.createElement('input');
- heightInput.setAttribute('type', 'text');
- heightInput.style.width = '60px';
- heightInput.style.marginLeft = '4px';
- heightInput.value = (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / scale) + 2) + 'px';
- var lightboxCheckBox = document.createElement('input');
- lightboxCheckBox.setAttribute('type', 'checkbox');
- var editCheckBox = document.createElement('input');
- editCheckBox.setAttribute('type', 'checkbox');
- var layersCheckBox = document.createElement('input');
- layersCheckBox.setAttribute('type', 'checkbox');
-
- if (!image)
- {
- if (!link)
- {
- mxUtils.write(div, mxResources.get('height') + ':');
- div.appendChild(heightInput);
-
- mxUtils.br(div);
- }
-
- lightboxCheckBox.setAttribute('checked', 'checked');
- lightboxCheckBox.defaultChecked = true;
- div.appendChild(lightboxCheckBox);
- mxUtils.write(div, mxResources.get('lightbox'));
- layersCheckBox.style.marginLeft = '16px';
- var model = editorUi.editor.graph.getModel();
-
- if (model.getChildCount(model.getRoot()) > 1)
- {
- layersCheckBox.setAttribute('checked', 'checked');
- layersCheckBox.defaultChecked = true;
- }
- else
- {
- layersCheckBox.setAttribute('disabled', 'disabled');
- }
-
- div.appendChild(layersCheckBox);
- mxUtils.write(div, mxResources.get('layers'));
- editCheckBox.style.marginLeft = '16px';
- editCheckBox.setAttribute('checked', 'checked');
- editCheckBox.defaultChecked = true;
- div.appendChild(editCheckBox);
- mxUtils.write(div, mxResources.get('edit'));
-
- mxUtils.br(div);
- }
-
- var hr = document.createElement('hr');
- hr.setAttribute('size', '1');
- hr.style.marginBottom = '16px';
- hr.style.marginTop = '16px';
- div.appendChild(hr);
- mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
- mxUtils.br(div);
-
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.setAttribute('size', '28');
- urlInput.style.marginBottom = '8px';
- urlInput.style.marginTop = '2px';
- urlInput.style.width = '410px';
- div.appendChild(urlInput);
- mxUtils.br(div);
- var node = null;
- var s = '';
-
- // Scans shapes for stencils
- var stencilNames = new Object();
- var states = graph.view.states.getValues();
-
- for (var i = 0; i < states.length; i++)
- {
- var state = states[i];
- var shape = state.style[mxConstants.STYLE_SHAPE];
- var basename = mxStencilRegistry.getBasenameForStencil(shape);
-
- if (basename != null)
- {
- if (stencilNames[basename] == null)
- {
- stencilNames[basename] = true;
- s += basename + ';';
- }
- }
- }
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- if (image || link)
- {
- window.open(iframeInput.value);
- }
- else
- {
- var wnd = window.open();
- var doc = wnd.document;
-
- if (document.compatMode === 'CSS1Compat')
- {
- doc.writeln('<!DOCTYPE html>');
- }
-
- doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
- '</title><meta charset="utf-8"></head>');
- doc.writeln('<body>');
- doc.writeln(iframeInput.value);
- doc.writeln('</body>');
- doc.writeln('</html>');
- doc.close();
- }
- });
-
- previewBtn.className = 'geBtn';
-
- var copyBtn = mxUtils.button(mxResources.get('copy'), function()
- {
- iframeInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- iframeInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- document.execCommand('copy');
- editorUi.alert(mxResources.get('copiedToClipboard'));
- });
- var file = editorUi.getCurrentFile();
-
- function update()
- {
- var title = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
-
- if (link && file != null && (urlInput.value != '' || file.constructor == DriveFile ||
- file.constructor == DropboxFile || file.constructor == OneDriveFile))
- {
- previewBtn.removeAttribute('disabled');
- copyBtn.removeAttribute('disabled');
- var gurl = 'https://www.draw.io/?chrome=0';
-
- if (lightboxCheckBox.checked)
- {
- gurl += '&lightbox=1';
- }
-
- if (editCheckBox.checked)
- {
- gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities('https://www.draw.io/#' + file.getHash()));
- }
-
- if (graph.foldingEnabled)
- {
- gurl += '&nav=1';
- }
-
- if (layersCheckBox.checked)
- {
- gurl += '&layers=1';
- }
- if (urlInput.value != '')
- {
- gurl += '&url=' + encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
- }
- else
- {
- gurl += '#' + file.getHash();
- }
-
- iframeInput.value = gurl;
- iframeInput.removeAttribute('disabled');
- }
- else if (urlInput.value != '')
- {
- previewBtn.removeAttribute('disabled');
- copyBtn.removeAttribute('disabled');
- var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
-
- if (image)
- {
- var gurl = EXPORT_URL + '?format=png&url=' + encUrl;
- iframeInput.value = gurl;
- }
- else
- {
- var gurl = 'https://www.draw.io/?chrome=0';
-
- if (lightboxCheckBox.checked)
- {
- gurl += '&lightbox=1';
- }
-
- if (editCheckBox.checked)
- {
- gurl += '&edit=' + encUrl;
- }
-
- if (graph.foldingEnabled)
- {
- gurl += '&nav=1';
- }
-
- if (layersCheckBox.checked)
- {
- gurl += '&layers=1';
- }
-
- gurl += '&url=' + encUrl;
- iframeInput.value = '<iframe frameborder="0" style="width:' + widthInput.value + ';height:' +
- heightInput.value + '" src="' + gurl + '"></iframe>';
- }
- iframeInput.removeAttribute('disabled');
- }
- else if (!image && !link && file != null && (file.constructor == DriveFile ||
- file.constructor == DropboxFile || file.constructor == OneDriveFile))
- {
- previewBtn.removeAttribute('disabled');
- copyBtn.removeAttribute('disabled');
- var gurl = 'https://www.draw.io/?chrome=0';
-
- if (lightboxCheckBox.checked)
- {
- gurl += '&lightbox=1';
- }
-
- if (editCheckBox.checked)
- {
- gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities('https://www.draw.io/#' + file.getHash()));
- }
-
- if (graph.foldingEnabled)
- {
- gurl += '&nav=1';
- }
-
- if (layersCheckBox.checked)
- {
- gurl += '&layers=1';
- }
- gurl += '#' + file.getHash();
-
- iframeInput.value = '<iframe frameborder="0" style="width:' + widthInput.value + ';height:' +
- heightInput.value + '" src="' + gurl + '"></iframe>';
- iframeInput.removeAttribute('disabled');
- }
- else
- {
- previewBtn.setAttribute('disabled', 'disabled');
- copyBtn.setAttribute('disabled', 'disabled');
- iframeInput.value = mxResources.get('invalidPublicUrl');
- iframeInput.setAttribute('disabled', 'disabled');
- }
- };
-
- // Tries to generate public image URL (only for Drive files)
- update();
- urlInput.setAttribute('placeholder', mxResources.get('loading') + '...');
-
- editorUi.getPublicUrl(file, function(url)
- {
- urlInput.setAttribute('placeholder', '');
- urlInput.value = (url != null) ? url : '';
- update();
- });
-
- mxEvent.addListener(widthInput, 'change', update);
- mxEvent.addListener(heightInput, 'change', update);
- mxEvent.addListener(layersCheckBox, 'change', update);
- mxEvent.addListener(lightboxCheckBox, 'change', update);
- mxEvent.addListener(editCheckBox, 'change', update);
- mxEvent.addListener(urlInput, 'change', update);
-
- mxEvent.addListener(iframeInput, 'click', function()
- {
- iframeInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- iframeInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- });
-
- var buttons = document.createElement('div');
- buttons.style.paddingTop = '12px';
- buttons.style.textAlign = 'right';
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
- if (image || (!mxClient.IS_QUIRKS && !navigator.standalone &&
- (!window.chrome || !chrome.app || !chrome.app.runtime) &&
- (document.documentMode == null || document.documentMode >= 9)))
- {
- buttons.appendChild(previewBtn);
- }
-
- buttons.appendChild(closeBtn);
- // Does not work in Safari and shows annoying dialog for IE11-
- if (!mxClient.IS_SF && document.documentMode == null)
- {
- buttons.appendChild(copyBtn);
- copyBtn.className = 'geBtn gePrimaryBtn';
- closeBtn.className = 'geBtn';
- }
- else
- {
- closeBtn.className = 'geBtn gePrimaryBtn';
- }
-
- div.appendChild(buttons);
-
- this.container = div;
- };
- /**
- * Constructs a new parse dialog.
- */
- var CreateGraphDialog = function(editorUi, title, type)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'right';
-
- this.init = function()
- {
- var container = document.createElement('div');
- container.style.position = 'relative';
- container.style.border = '1px solid gray';
- container.style.width = '100%';
- container.style.height = '360px';
- container.style.overflow = 'hidden';
- container.style.marginBottom = '16px';
- mxEvent.disableContextMenu(container);
- div.appendChild(container);
-
- var graph = new Graph(container);
-
- graph.setCellsCloneable(true);
- graph.setPanning(true);
- graph.setAllowDanglingEdges(false);
- graph.connectionHandler.select = false;
- graph.view.setTranslate(20, 20);
- graph.border = 20;
- graph.panningHandler.useLeftButtonForPanning = true;
-
- var vertexStyle = 'rounded=1;';
- var edgeStyle = 'curved=1;';
- var startStyle = 'ellipse';
-
- // FIXME: Does not work in iPad
- var mxCellRendererInstallCellOverlayListeners = mxCellRenderer.prototype.installCellOverlayListeners;
- graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
- {
- mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
-
- mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
- {
- overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
- });
-
- if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
- {
- mxEvent.addListener(shape.node, 'touchstart', function (evt)
- {
- overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
- });
- }
- };
- graph.getAllConnectionConstraints = function()
- {
- return null;
- };
- // Keeps highlight behind overlays
- graph.connectionHandler.marker.highlight.keepOnTop = false;
-
- graph.connectionHandler.createEdgeState = function(me)
- {
- var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
-
- return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
- };
-
- // Gets the default parent for inserting new cells. This
- // is normally the first child of the root (ie. layer 0).
- var parent = graph.getDefaultParent();
-
- var addOverlay = mxUtils.bind(this, function(cell)
- {
- // Creates a new overlay with an image and a tooltip
- var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
- overlay.cursor = 'hand';
-
- // Installs a handler for clicks on the overlay
- overlay.addListener(mxEvent.CLICK, function(sender, evt2)
- {
- // TODO: Add menu for picking next shape
- graph.connectionHandler.reset();
- graph.clearSelection();
- var geo = graph.getCellGeometry(cell);
-
- var v2;
-
- executeLayout(function()
- {
- v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
- addOverlay(v2);
- graph.view.refresh(v2);
- var e1 = graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
- }, function()
- {
- graph.scrollCellToVisible(v2);
- });
- });
-
- // FIXME: Does not work in iPad (inserts loop)
- overlay.addListener('pointerdown', function(sender, eo)
- {
- var evt2 = eo.getProperty('event');
- var state = eo.getProperty('state');
-
- graph.popupMenuHandler.hideMenu();
- graph.stopEditing(false);
-
- var pt = mxUtils.convertPoint(graph.container,
- mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
- graph.connectionHandler.start(state, pt.x, pt.y);
- graph.isMouseDown = true;
- graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
- mxEvent.consume(evt2);
- });
-
- // Sets the overlay for the cell in the graph
- graph.addCellOverlay(cell, overlay);
- });
-
- // Adds cells to the model in a single step
- graph.getModel().beginUpdate();
- var v1;
- try
- {
- v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
- addOverlay(v1);
- }
- finally
- {
- // Updates the display
- graph.getModel().endUpdate();
- }
-
- var layout;
-
- if (type == 'horizontalTree')
- {
- layout = new mxCompactTreeLayout(graph);
- layout.edgeRouting = false;
- layout.levelDistance = 30;
- edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
- }
- else if (type == 'verticalTree')
- {
- layout = new mxCompactTreeLayout(graph, false);
- layout.edgeRouting = false;
- layout.levelDistance = 30;
- edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
- }
- else if (type == 'verticalFlow')
- {
- layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
- }
- else if (type == 'horizontalFlow')
- {
- layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
- }
- else if (type == 'organic')
- {
- layout = new mxFastOrganicLayout(graph, false);
- layout.forceConstant = 80;
- }
- else if (type == 'circle')
- {
- layout = new mxCircleLayout(graph);
- }
-
- if (layout != null)
- {
- var executeLayout = function(change, post)
- {
- graph.getModel().beginUpdate();
- try
- {
- if (change != null)
- {
- change();
- }
-
- layout.execute(graph.getDefaultParent(), v1);
- }
- catch (e)
- {
- throw e;
- }
- finally
- {
- // New API for animating graph layout results asynchronously
- var morph = new mxMorphing(graph);
- morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
- {
- graph.getModel().endUpdate();
-
- if (post != null)
- {
- post();
- }
- }));
-
- morph.startAnimation();
- }
- };
-
- var edgeHandleConnect = mxEdgeHandler.prototype.connect;
- mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
- {
- edgeHandleConnect.apply(this, arguments);
- executeLayout();
- };
-
- graph.resizeCell = function()
- {
- mxGraph.prototype.resizeCell.apply(this, arguments);
-
- executeLayout();
- };
-
- graph.connectionHandler.addListener(mxEvent.CONNECT, function()
- {
- executeLayout();
- });
- }
- var cancelBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- graph.destroy();
- container.parentNode.removeChild(container);
-
- editorUi.hideDialog();
- });
- })
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
-
- var okBtn = mxUtils.button(mxResources.get('insert'), function()
- {
- graph.clearCellOverlays();
- var view = editorUi.editor.graph.view;
- var bds = editorUi.editor.graph.getGraphBounds();
-
- // Computes unscaled, untranslated graph bounds
- var pt = editorUi.editor.graph.getInsertPoint();
- var x = Math.max(pt.x, bds.x / view.scale - view.translate.x);
- var y = Math.max(pt.y, editorUi.editor.graph.snap((bds.y + bds.height) /
- view.scale - view.translate.y + 4 * graph.gridSize));
- var cells = editorUi.editor.graph.importCells(graph.getModel().getChildren(graph.getDefaultParent()), x, y);
- var temp = view.getBounds(cells);
- temp.x -= view.translate.x;
- temp.y -= view.translate.y;
- editorUi.editor.graph.scrollRectToVisible(temp);
- editorUi.editor.graph.setSelectionCells(cells);
-
- graph.destroy();
- container.parentNode.removeChild(container);
- editorUi.hideDialog();
- });
-
- div.appendChild(okBtn);
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
- };
- this.container = div;
- };
- /**
- *
- */
- 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==' :
- IMAGE_PATH + '/handle-connect.png', 26, 26);
- /**
- * Constructs a new parse dialog.
- */
- var BackgroundImageDialog = function(editorUi, applyFn)
- {
- var div = document.createElement('div');
- div.style.whiteSpace = 'nowrap';
- var h3 = document.createElement('h2');
- mxUtils.write(h3, mxResources.get('backgroundImage'));
- h3.style.marginTop = '0px';
- div.appendChild(h3);
-
- mxUtils.write(div, mxResources.get('image') + ' ' + mxResources.get('url') + ':');
- mxUtils.br(div);
-
- var img = editorUi.editor.graph.backgroundImage;
-
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.style.marginTop = '4px';
- urlInput.style.marginBottom = '4px';
- urlInput.style.width = '350px';
- urlInput.value = (img != null) ? img.src : '';
-
- var resetting = false;
-
- var urlChanged = function()
- {
- if (!resetting && urlInput.value != '' && !editorUi.isOffline())
- {
- editorUi.loadImage(mxUtils.trim(urlInput.value), function(img)
- {
- widthInput.value = img.width;
- heightInput.value = img.height;
- }, function()
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
- urlInput.value = '';
- widthInput.value = '';
- heightInput.value = '';
- });
- }
- else
- {
- widthInput.value = '';
- heightInput.value = '';
- }
- };
-
- this.init = function()
- {
- urlInput.focus();
-
- // Installs drag and drop handler for local images and links
- if (Graph.fileSupport)
- {
- urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
-
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var graph = editorUi.editor.graph;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (evt.dataTransfer.files.length > 0)
- {
- editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
- {
- urlInput.value = data;
- urlChanged();
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes);
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = evt.dataTransfer.getData('text/uri-list');
-
- if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
- {
- urlInput.value = decodeURIComponent(uri);
- urlChanged();
- }
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
- div.appendChild(urlInput);
- mxUtils.br(div);
- mxUtils.br(div);
-
- mxUtils.write(div, mxResources.get('width') + ':');
-
- var widthInput = document.createElement('input');
- widthInput.setAttribute('type', 'text');
- widthInput.style.width = '60px';
- widthInput.style.marginLeft = '4px';
- widthInput.style.marginRight = '16px';
- widthInput.value = (img != null) ? img.width : '';
-
- div.appendChild(widthInput);
-
- mxUtils.write(div, mxResources.get('height') + ':');
-
- var heightInput = document.createElement('input');
- heightInput.setAttribute('type', 'text');
- heightInput.style.width = '60px';
- heightInput.style.marginLeft = '4px';
- heightInput.style.marginRight = '16px';
- heightInput.value = (img != null) ? img.height : '';
-
- div.appendChild(heightInput);
-
- var resetBtn = mxUtils.button(mxResources.get('reset'), function()
- {
- urlInput.value = '';
- widthInput.value = '';
- heightInput.value = '';
- resetting = false;
- });
- mxEvent.addListener(resetBtn, 'mousedown', function()
- {
- // Blocks processing a image URL while clicking reset
- resetting = true;
- });
- mxEvent.addListener(resetBtn, 'touchstart', function()
- {
- // Blocks processing a image URL while clicking reset
- resetting = true;
- });
- resetBtn.className = 'geBtn';
- resetBtn.width = '100';
- div.appendChild(resetBtn);
- mxUtils.br(div);
- mxEvent.addListener(urlInput, 'change', urlChanged);
- ImageDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- if (data.docs[0].thumbnails != null)
- {
- var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
-
- if (thumb != null)
- {
- urlInput.value = thumb.url;
- urlChanged();
- }
- }
- }
-
- urlInput.focus();
- };
- var btns = document.createElement('div');
- btns.style.marginTop = '40px';
- btns.style.textAlign = 'right';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- if (!editorUi.isOffline())
- {
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- var searchBtn = mxUtils.button(mxResources.get('search'), function()
- {
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.imageSearchPicker == null)
- {
- var picker = new google.picker.PickerBuilder()
- .setLocale(mxLanguage)
- .addView(google.picker.ViewId.IMAGE_SEARCH)
- .enableFeature(google.picker.Feature.NAV_HIDDEN);
-
- editorUi.imageSearchPicker = picker.setCallback(function(data)
- {
- ImageDialog.filePicked(data);
- }).build();
- }
-
- editorUi.imageSearchPicker.setVisible(true);
- editorUi.movePickersToTop();
- });
-
- searchBtn.className = 'geBtn';
- btns.appendChild(searchBtn);
-
- if (editorUi.drive != null && urlParams['photos'] == '1')
- {
- var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
-
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.photoPicker == null)
- {
- var token = gapi.auth.getToken().access_token;
- var picker = new google.picker.PickerBuilder()
- .setAppId(editorUi.drive.appId)
- .setLocale(mxLanguage)
- .setOAuthToken(token)
- .addView(google.picker.ViewId.PHOTOS)
- .addView(google.picker.ViewId.PHOTO_ALBUMS)
- .addView(google.picker.ViewId.PHOTO_UPLOAD);
-
- editorUi.photoPicker = picker.setCallback(function(data)
- {
- ImageDialog.filePicked(data);
- }).build();
- }
-
- editorUi.photoPicker.setVisible(true);
- editorUi.movePickersToTop();
- }));
- }
- });
-
- gpBtn.className = 'geBtn';
- btns.appendChild(gpBtn);
- }
- }
- }
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
- applyFn((urlInput.value != '') ? new mxImage(mxUtils.trim(urlInput.value), widthInput.value, heightInput.value) : null);
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new parse dialog.
- */
- var ParseDialog = function(editorUi, title)
- {
- function parse(text)
- {
- var lines = text.split('\n');
- var vertices = new Object();
- var cells = [];
-
- function getOrCreateVertex(id)
- {
- var vertex = vertices[id];
- if (vertex == null)
- {
- vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30));
- vertex.vertex = true;
- vertices[id] = vertex;
- cells.push(vertex);
- }
-
- return vertex;
- };
-
- for (var i = 0; i < lines.length; i++)
- {
- if (lines[i].charAt(0) != ';')
- {
- var values = lines[i].split('->');
-
- if (values.length == 2)
- {
- var source = getOrCreateVertex(values[0]);
- var target = getOrCreateVertex(values[1]);
-
- var edge = new mxCell('', new mxGeometry());
- edge.edge = true;
- source.insertEdge(edge, true);
- target.insertEdge(edge, false);
- cells.push(edge);
- }
- }
- }
-
- if (cells.length > 0)
- {
- var container = document.createElement('div');
- container.style.visibility = 'hidden';
- document.body.appendChild(container);
- var graph = new Graph(container);
-
- graph.getModel().beginUpdate();
- try
- {
- cells = graph.importCells(cells);
-
- for (var i = 0; i < cells.length; i++)
- {
- if (graph.getModel().isVertex(cells[i]))
- {
- var size = graph.getPreferredSizeForCell(cells[i]);
- cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
- cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
- }
- }
- var layout = new mxFastOrganicLayout(graph);
- layout.disableEdgeStyle = false;
- layout.forceConstant = 120;
- layout.execute(graph.getDefaultParent());
-
- graph.moveCells(cells, 20, 20);
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- graph.clearCellOverlays();
- var view = editorUi.editor.graph.view;
- var bds = editorUi.editor.graph.getGraphBounds();
-
- // Computes unscaled, untranslated graph bounds
- var x = Math.max(0, bds.x / view.scale - view.translate.x) + graph.gridSize;
- var y = Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize;
- editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(
- graph.getModel().getChildren(graph.getDefaultParent()), x, y));
-
- graph.destroy();
- container.parentNode.removeChild(container);
- }
- };
-
- var div = document.createElement('div');
- div.style.textAlign = 'right';
-
- var textarea = document.createElement('textarea');
- textarea.style.resize = 'none';
- textarea.style.width = '100%';
- textarea.style.height = '354px';
- textarea.style.marginBottom = '16px';
-
- textarea.value = ';example\na->b\nb->c\nc->a\n';
- div.appendChild(textarea);
-
- this.init = function()
- {
- textarea.focus();
- };
-
- // Enables dropping files
- if (Graph.fileSupport)
- {
- function handleDrop(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
-
- if (evt.dataTransfer.files.length > 0)
- {
- var file = evt.dataTransfer.files[0];
-
- var reader = new FileReader();
- reader.onload = function(e) { textarea.value = e.target.result; };
- reader.readAsText(file);
- }
- };
-
- function handleDragOver(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
- };
- // Setup the dnd listeners.
- textarea.addEventListener('dragover', handleDragOver, false);
- textarea.addEventListener('drop', handleDrop, false);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- editorUi.hideDialog();
- });
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
-
- var okBtn = mxUtils.button(mxResources.get('insert'), function()
- {
- editorUi.hideDialog();
- parse(textarea.value);
- });
- div.appendChild(okBtn);
-
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
- this.container = div;
- };
- /**
- * Constructs a new dialog for creating files from templates.
- */
- var NewDialog = function(editorUi, compact, showName, callback)
- {
- showName = (showName != null) ? showName : true;
- var outer = document.createElement('div');
- outer.style.height = '100%';
-
- var header = document.createElement('div');
- header.style.whiteSpace = 'nowrap';
- header.style.height = '46px';
- outer.appendChild(header);
-
- var logo = document.createElement('img');
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '40px';
- logo.style.height = '40px';
- logo.style.marginRight = '10px';
- logo.style.paddingBottom = '4px';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- logo.src = IMAGE_PATH + '/google-drive-logo.svg';
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- logo.src = IMAGE_PATH + '/dropbox-logo.svg';
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- logo.src = IMAGE_PATH + '/onedrive-logo.svg';
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- logo.src = IMAGE_PATH + '/osa_database.png';
- }
- else
- {
- logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
- }
- if (!compact && showName)
- {
- header.appendChild(logo);
- }
-
- if (showName)
- {
- mxUtils.write(header, ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
- editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename')) + ':');
- }
-
- var ext = '.xml';
-
- if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
- {
- ext = editorUi.drive.extension;
- }
- else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
- {
- ext = editorUi.dropbox.extension;
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
- {
- ext = editorUi.oneDrive.extension;
- }
-
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', editorUi.defaultFilename + ext);
- nameInput.style.marginRight = '20px';
- nameInput.style.marginLeft = '10px';
- nameInput.style.width = (compact) ? '220px' : '450px';
-
- this.init = function()
- {
- if (showName)
- {
- nameInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- nameInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- };
- if (showName)
- {
- header.appendChild(nameInput);
- }
- var templateLibs = null;
- var templateXml = null;
- var selectedElt = null;
-
- function create()
- {
- if (callback)
- {
- editorUi.hideDialog();
- callback(templateXml);
- }
- else
- {
- var title = nameInput.value;
-
- if (title != null && title.length > 0)
- {
- var tempMode = (editorUi.mode == App.MODE_ONEDRIVE || (editorUi.mode == App.MODE_GOOGLE &&
- (editorUi.stateArg == null || editorUi.stateArg.folderId == null))) ? editorUi.mode : null;
-
- editorUi.pickFolder(tempMode, function(folderId)
- {
- editorUi.createFile(title, templateXml, (templateLibs != null && templateLibs.length > 0) ? templateLibs : null, null, function()
- {
- editorUi.hideDialog();
- }, null, folderId);
- }, tempMode != App.MODE_GOOGLE);
- }
- }
- };
-
- var createButton = mxUtils.button(mxResources.get('create'), function()
- {
- create();
- });
-
- createButton.className = 'geBtn gePrimaryBtn';
- var div = document.createElement('div');
- div.style.border = '1px solid #d3d3d3';
- div.style.position = 'absolute';
- div.style.left = '160px';
- div.style.right = '34px';
- div.style.top = (showName) ? '72px' : '40px';
- div.style.bottom = '76px';
- div.style.margin = '6px 0 0 -1px';
- div.style.padding = '6px';
- div.style.overflow = 'auto';
-
- var list = document.createElement('div');
- list.style.cssText = 'position:absolute;left:30px;width:128px;top:72px;bottom:76px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
-
- if (!showName)
- {
- list.style.top = '40px';
- }
-
- var w = 140;
- var h = 140;
- function selectElement(elt, xml, libs)
- {
- if (selectedElt != null)
- {
- selectedElt.style.backgroundColor = 'transparent';
- selectedElt.style.border = '1px solid transparent';
- }
-
- templateXml = xml;
- templateLibs = libs;
- selectedElt = elt;
-
- selectedElt.style.backgroundColor = '#e6eff8';
- selectedElt.style.border = '1px solid #ccd9ea';
- };
- function addButton(url, libs, title, tooltip, select)
- {
- var elt = document.createElement('div');
- elt.className = 'geTemplate';
- elt.style.height = w + 'px';
- elt.style.width = h + 'px';
-
- if (tooltip != null && tooltip.length > 0)
- {
- elt.setAttribute('title', tooltip);
- }
-
- if (url != null && url.length > 0)
- {
- var png = url.substring(0, url.length - 4) + '.png';
-
- elt.style.backgroundImage = 'url(' + TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png)';
- elt.style.backgroundPosition = 'center center';
- elt.style.backgroundRepeat = 'no-repeat';
-
- var createIt = false;
-
- mxEvent.addListener(elt, 'click', function(evt)
- {
- createButton.setAttribute('disabled', 'disabled');
- elt.style.backgroundColor = 'transparent';
- elt.style.border = '1px solid transparent';
-
- mxUtils.get(TEMPLATE_PATH + '/' + url, mxUtils.bind(this, function(req)
- {
- if (req.getStatus() == 200)
- {
- createButton.removeAttribute('disabled');
- selectElement(elt, req.getText(), libs);
-
- if (createIt)
- {
- create();
- }
- }
- }));
- });
-
- mxEvent.addListener(elt, 'dblclick', function(evt)
- {
- // Asynchronous double click handling after loading template
- createIt = true;
- });
- }
- else
- {
- elt.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle">' +
- mxResources.get(title) + '</td></tr></table>';
-
- if (select)
- {
- selectElement(elt);
- }
-
- mxEvent.addListener(elt, 'click', function(evt)
- {
- selectElement(elt);
- });
-
- mxEvent.addListener(elt, 'dblclick', function(evt)
- {
- create();
- });
- }
- div.appendChild(elt);
- };
- var categories = {};
- var categoryCount = 1;
-
- // Adds local basic templates
- categories['basic'] = [{title: 'blankDiagram', select: true}];
- var templates = categories['basic'];
-
- function initUi()
- {
- var i0 = 0;
-
- // Dynamic loading
- function addTemplates()
- {
- var first = true;
-
- while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
- {
- var tmp = templates[i0++];
- addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip, tmp.select);
- first = false;
- }
- };
- mxEvent.addListener(div, 'scroll', function(evt)
- {
- if (div.scrollTop + div.clientHeight >= div.scrollHeight)
- {
- addTemplates();
- mxEvent.consume(evt);
- }
- });
-
- var currentEntry = null;
-
- for (var cat in categories)
- {
- var entry = document.createElement('div');
- var label = mxResources.get(cat);
- var templateList = categories[cat];
-
- if (label == null)
- {
- label = cat.substring(0, 1).toUpperCase() + cat.substring(1);
- }
-
- if (label.length > 18)
- {
- label = label.substring(0, 18) + '…';
- }
- entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;';
- entry.setAttribute('title', label + ' (' + templateList.length + ')');
- mxUtils.write(entry, entry.getAttribute('title'));
- list.appendChild(entry);
-
- if (currentEntry == null)
- {
- currentEntry = entry;
- currentEntry.style.backgroundColor = '#ebf2f9';
- }
-
- (function(cat2, entry2)
- {
- mxEvent.addListener(entry, 'click', function()
- {
- if (currentEntry != entry2)
- {
- currentEntry.style.backgroundColor = '';
- currentEntry = entry2;
- currentEntry.style.backgroundColor = '#ebf2f9';
-
- div.scrollTop = 0;
- div.innerHTML = '';
- i0 = 0;
- templates = categories[cat2];
- addTemplates();
- }
- });
- })(cat, entry);
- }
-
- addTemplates();
- }
- if (!compact)
- {
- outer.appendChild(list);
- outer.appendChild(div);
- var indexLoaded = false;
-
- mxUtils.get(TEMPLATE_PATH + '/index.xml', function(req)
- {
- // Workaround for index loaded 3 times in iOS offline mode
- if (!indexLoaded)
- {
- indexLoaded = true;
- var tmpDoc = req.getXml();
- var node = tmpDoc.documentElement.firstChild;
-
- while (node != null)
- {
- if (typeof(node.getAttribute) !== 'undefined')
- {
- var url = node.getAttribute('url');
-
- if (url != null)
- {
- var slash = url.indexOf('/');
- var category = url.substring(0, slash);
-
- var list = categories[category];
-
- if (list == null)
- {
- categoryCount++;
- list = [];
- categories[category] = list;
- }
-
- list.push({url: node.getAttribute('url'), libs: node.getAttribute('libs'),
- title: node.getAttribute('title'), tooltip: node.getAttribute('url')});
- }
- }
-
- node = node.nextSibling;
- }
-
- initUi();
- }
- });
- }
-
- mxEvent.addListener(nameInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- editorUi.hideDialog();
- create();
- }
- });
-
- var btns = document.createElement('div');
- btns.style.marginTop = (compact) ? '4px' : '16px';
- btns.style.textAlign = 'right';
- btns.style.position = 'absolute';
- btns.style.left = '40px';
- btns.style.bottom = '30px';
- btns.style.right = '40px';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog(true);
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- if (!compact && !editorUi.isOffline() && showName)
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open('https://support.draw.io/display/DO/Creating+and+Opening+Files');
- });
-
- helpBtn.className = 'geBtn';
- btns.appendChild(helpBtn);
- }
- if (!compact)
- {
- var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
- {
- if (fileUrl != null && fileUrl.length > 0)
- {
- var url = editorUi.getUrl(window.location.pathname + '?mode=' + editorUi.mode +
- '&title=' + encodeURIComponent(nameInput.value) +
- '&create=' + encodeURIComponent(fileUrl));
-
- if (editorUi.getCurrentFile() == null)
- {
- window.location.href = url;
- }
- else
- {
- window.openWindow(url);
- }
- }
- }, mxResources.get('url'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- });
- fromTmpBtn.className = 'geBtn';
- btns.appendChild(fromTmpBtn);
- }
-
- btns.appendChild(createButton);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- outer.appendChild(btns);
-
- this.container = outer;
- };
- /**
- * Constructs a dialog for creating new files from a template URL.
- */
- var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension,
- allowBrowser, allowTab, helpLink, showDeviceButton)
- {
- overrideExtension = (overrideExtension != null) ? overrideExtension : true;
- allowBrowser = (allowBrowser != null) ? allowBrowser : true;
- var div = document.createElement('div');
- var showButtons = true;
-
- if (cancelFn == null)
- {
- editorUi.addLanguageMenu(div);
- }
- var h3 = document.createElement('h2');
- mxUtils.write(h3, dlgTitle || mxResources.get('create'));
- h3.style.marginTop = '0px';
- h3.style.marginBottom = '24px';
- div.appendChild(h3);
-
- mxUtils.write(div, mxResources.get('filename') + ':');
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', title);
- nameInput.style.width = '280px';
- nameInput.style.marginLeft = '10px';
- nameInput.style.marginBottom = '20px';
-
- this.init = function()
- {
- nameInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- nameInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
- div.appendChild(nameInput);
- mxUtils.br(div);
-
- var buttons = document.createElement('div');
- buttons.style.textAlign = 'center';
- function addLogo(img, title, mode, clientName)
- {
- var button = document.createElement('a');
- button.style.overflow = 'hidden';
-
- var logo = document.createElement('img');
- logo.src = img;
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '60px';
- logo.style.height = '60px';
- logo.style.paddingBottom = '6px';
- button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
- button.className = 'geBaseButton';
- button.style.position = 'relative';
- button.style.margin = '4px';
- button.style.padding = '8px 8px 10px 8px';
- button.style.whiteSpace = 'nowrap';
-
- button.appendChild(logo);
-
- // Workaround for quirks is a vertical list (limited to max 2 items)
- if (mxClient.IS_QUIRKS)
- {
- button.style.cssFloat = 'left';
- button.style.zoom = '1';
- }
-
- button.style.color = 'gray';
- button.style.fontSize = '11px';
-
- var label = document.createElement('div');
- button.appendChild(label);
- mxUtils.write(label, title);
-
- function initButton()
- {
- mxEvent.addListener(button, 'click', function()
- {
- // Updates extension
- change(mode);
- create(mode);
- });
- };
-
- // Supports lazy loading
- if (clientName != null && editorUi[clientName] == null)
- {
- logo.style.visibility = 'hidden';
- mxUtils.setOpacity(label, 10);
- var size = 12;
-
- var spinner = new Spinner({
- lines: 12, // The number of lines to draw
- length: size, // The length of each line
- width: 5, // The line thickness
- radius: 10, // The radius of the inner circle
- rotate: 0, // The rotation offset
- color: '#000', // #rgb or #rrggbb
- speed: 1.5, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- top: '40%',
- zIndex: 2e9 // The z-index (defaults to 2000000000)
- });
- spinner.spin(button);
-
- // Timeout after 30 secs
- var timeout = window.setTimeout(function()
- {
- if (editorUi[clientName] == null)
- {
- spinner.stop();
- button.style.display = 'none';
- }
- }, 30000);
-
- editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
- {
- if (editorUi[clientName] != null)
- {
- window.clearTimeout(timeout);
- mxUtils.setOpacity(label, 100);
- logo.style.visibility = '';
- spinner.stop();
- initButton();
- }
- }));
- }
- else
- {
- initButton();
- }
- buttons.appendChild(button);
- };
- if (!showButtons)
- {
- mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
- }
- else
- {
- buttons.style.marginTop = '6px';
- div.appendChild(buttons);
- }
-
- // Adds all papersize options
- var serviceSelect = document.createElement('select');
- serviceSelect.style.marginLeft = '10px';
- if (typeof window.DriveClient === 'function')
- {
- var googleOption = document.createElement('option');
- googleOption.setAttribute('value', App.MODE_GOOGLE);
- mxUtils.write(googleOption, mxResources.get('googleDrive'));
- serviceSelect.appendChild(googleOption);
-
- addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
- }
- if (typeof window.DropboxClient === 'function')
- {
- var dropboxOption = document.createElement('option');
- dropboxOption.setAttribute('value', App.MODE_DROPBOX);
- mxUtils.write(dropboxOption, mxResources.get('dropbox'));
- serviceSelect.appendChild(dropboxOption);
-
- if (editorUi.mode == App.MODE_DROPBOX)
- {
- dropboxOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
- }
- if (typeof window.OneDriveClient === 'function')
- {
- var oneDriveOption = document.createElement('option');
- oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
- mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
- serviceSelect.appendChild(oneDriveOption);
-
- if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- oneDriveOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
- }
-
- if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
- (editorUi.getCurrentFile() != null && !mxClient.IS_IOS))
- {
- var deviceOption = document.createElement('option');
- deviceOption.setAttribute('value', App.MODE_DEVICE);
- mxUtils.write(deviceOption, mxResources.get('device'));
- serviceSelect.appendChild(deviceOption);
-
- if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
- {
- deviceOption.setAttribute('selected', 'selected');
- }
-
- if (showDeviceButton)
- {
- mxUtils.br(buttons);
- addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
- }
- }
-
- if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
- {
- var browserOption = document.createElement('option');
- browserOption.setAttribute('value', App.MODE_BROWSER);
- mxUtils.write(browserOption, mxResources.get('browser'));
- serviceSelect.appendChild(browserOption);
-
- if (editorUi.mode == App.MODE_BROWSER)
- {
- browserOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
- }
- function change(newMode)
- {
- if (overrideExtension)
- {
- var fn = nameInput.value;
- var idx = fn.lastIndexOf('.');
-
- if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
- {
- newMode = (newMode != null) ? newMode : serviceSelect.value;
- var ext = '';
-
- if (newMode == App.MODE_GOOGLE)
- {
- ext = editorUi.drive.extension;
- }
- else if (newMode == App.MODE_DROPBOX)
- {
- ext = editorUi.dropbox.extension;
- }
- else if (newMode == App.MODE_ONEDRIVE)
- {
- ext = editorUi.oneDrive.extension;
- }
- else if (newMode == App.MODE_DEVICE)
- {
- ext = '.xml';
- }
-
- if (idx >= 0)
- {
- fn = fn.substring(0, idx);
- }
-
- nameInput.value = fn + ext;
- }
- }
- };
- var btns = document.createElement('div');
- btns.style.marginTop = (showButtons) ? '26px' : '38px';
- btns.style.textAlign = (showButtons) ? 'center' : 'right';
-
- if (!showButtons)
- {
- div.appendChild(serviceSelect);
- mxEvent.addListener(serviceSelect, 'change', change);
- change();
- }
-
- if (helpLink != null)
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open(helpLink);
- });
-
- helpBtn.className = 'geBtn';
- btns.appendChild(helpBtn);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- if (cancelFn != null)
- {
- cancelFn();
- }
- else
- {
- editorUi.fileLoaded(null);
- editorUi.hideDialog();
- window.close();
- window.location.href = editorUi.getUrl();
- }
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- function create(mode)
- {
- var title = nameInput.value;
-
- if (mode == null || (title != null && title.length > 0))
- {
- editorUi.hideDialog();
- createFn(title, mode);
- };
- }
-
- if (cancelFn == null)
- {
- var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
- {
- create(null);
- });
-
- laterBtn.className = 'geBtn';
- btns.appendChild(laterBtn);
- }
- if (allowTab)
- {
- var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
- {
- create('_blank');
- });
- openBtn.className = 'geBtn';
- btns.appendChild(openBtn);
- }
-
- if (!mxClient.IS_IOS || !showButtons)
- {
- var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
- {
- create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
- });
- createBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(createBtn);
- }
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- mxEvent.addListener(nameInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
- }
- else if (e.keyCode == 27)
- {
- editorUi.fileLoaded(null);
- editorUi.hideDialog();
- window.close();
- }
- });
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new popup dialog.
- */
- var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
- {
- hideDialog = (hideDialog != null) ? hideDialog : true;
-
- var div = document.createElement('div');
- div.style.textAlign = 'left';
-
- mxUtils.write(div, mxResources.get('fileOpenLocation'));
- mxUtils.br(div);
- mxUtils.br(div);
- var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
- {
- if (hideDialog)
- {
- editorUi.hideDialog();
- }
-
- if (fallback != null)
- {
- fallback();
- }
- });
- replaceBtn.className = 'geBtn';
- replaceBtn.style.marginBottom = '8px';
- replaceBtn.style.width = '280px';
- div.appendChild(replaceBtn);
-
- mxUtils.br(div);
-
- var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
- {
- if (hideDialog)
- {
- editorUi.hideDialog();
- }
- if (pre != null)
- {
- pre();
- }
-
- window.open(url);
- });
- wndBtn.className = 'geBtn gePrimaryBtn';
- wndBtn.style.width = replaceBtn.style.width;
- div.appendChild(wndBtn);
-
- mxUtils.br(div);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('allowPopups'));
-
- this.container = div;
- };
- /**
- * Constructs a new image dialog.
- */
- var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri)
- {
- convertDataUri = (convertDataUri != null) ? convertDataUri : true;
-
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- mxUtils.write(div, title);
-
- var inner = document.createElement('div');
- inner.className = 'geTitle';
- inner.style.backgroundColor = 'transparent';
- inner.style.borderColor = 'transparent';
- inner.style.whiteSpace = 'nowrap';
- inner.style.textOverflow = 'clip';
- inner.style.cursor = 'default';
-
- if (!mxClient.IS_VML)
- {
- inner.style.paddingRight = '20px';
- }
-
- var linkInput = document.createElement('input');
- linkInput.setAttribute('value', initialValue);
- linkInput.setAttribute('type', 'text');
- linkInput.style.marginTop = '6px';
- var realWidth = (Graph.fileSupport) ? 420 : 340;
- linkInput.style.width = realWidth + ((mxClient.IS_QUIRKS) ? 20 : -20) + 'px';
- linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
- linkInput.style.backgroundRepeat = 'no-repeat';
- linkInput.style.backgroundPosition = '100% 50%';
- linkInput.style.paddingRight = '14px';
-
- var cross = document.createElement('div');
- cross.setAttribute('title', mxResources.get('reset'));
- cross.style.position = 'relative';
- cross.style.left = '-16px';
- cross.style.width = '12px';
- cross.style.height = '14px';
- cross.style.cursor = 'pointer';
- // Workaround for inline-block not supported in IE
- cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
- cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
-
- // Needed to block event transparency in IE
- cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- mxEvent.addListener(cross, 'click', function()
- {
- linkInput.value = '';
- linkInput.focus();
- });
-
- inner.appendChild(linkInput);
- inner.appendChild(cross);
- div.appendChild(inner);
- var insertImage = function(newValue, w, h)
- {
- var dataUri = newValue.substring(0, 5) == 'data:';
-
- if ((!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined')) &&
- editorUi.spinner.spin(document.body, mxResources.get('inserting')))
- {
- var maxSize = 520;
-
- editorUi.loadImage(newValue, function(img)
- {
- editorUi.spinner.stop();
- editorUi.hideDialog();
- var s = (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
- Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
-
- // Handles special case of data URI which needs to be rewritten
- // to be used in a cell style to remove the semicolon
- if (convertDataUri)
- {
- newValue = editorUi.convertDataUri(newValue);
- }
-
- fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s));
- }, function()
- {
- editorUi.spinner.stop();
- fn(null);
- editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
- });
- }
- else
- {
- newValue = editorUi.convertDataUri(newValue);
- w = (w == null) ? 120 : w;
- h = (h == null) ? 100 : h;
-
- editorUi.hideDialog();
- fn(newValue, w, h);
- }
- };
-
- var apply = function(newValue)
- {
- if (newValue != null && newValue.length > 0)
- {
- var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
- // Reuses width and height of existing cell
- if (geo != null)
- {
- insertImage(newValue, geo.width, geo.height);
- }
- else
- {
- insertImage(newValue);
- }
- }
- else
- {
- editorUi.hideDialog();
- fn(null);
- }
- };
- this.init = function()
- {
- linkInput.focus();
-
- // Installs drag and drop handler for local images and links
- if (Graph.fileSupport)
- {
- linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
-
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var graph = editorUi.editor.graph;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (evt.dataTransfer.files.length > 0)
- {
- editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
- {
- apply(data);
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, !mxEvent.isControlDown(evt));
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = evt.dataTransfer.getData('text/uri-list');
-
- if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
- {
- apply(decodeURIComponent(uri));
- }
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
-
- var btns = document.createElement('div');
- btns.style.marginTop = (mxClient.IS_QUIRKS) ? '22px' : '14px';
- btns.style.textAlign = 'right';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- // Just in case a spinner is spinning, has no effect otherwise
- editorUi.spinner.stop();
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- ImageDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- if (data.docs[0].thumbnails != null)
- {
- var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
-
- if (thumb != null)
- {
- linkInput.value = thumb.url;
- }
- }
- }
-
- linkInput.focus();
- };
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- if (Graph.fileSupport)
- {
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- if (document.documentMode == null)
- {
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
- {
- apply(data);
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, true);
- });
-
- var btn = mxUtils.button(mxResources.get('open'), function()
- {
- fileInput.click();
- });
- btn.className = 'geBtn';
-
- btns.appendChild(btn);
- }
- }
-
- var searchBtn = mxUtils.button(mxResources.get('search'), function()
- {
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.imageSearchPicker == null)
- {
- var picker = new google.picker.PickerBuilder()
- .setLocale(mxLanguage)
- .addView(google.picker.ViewId.IMAGE_SEARCH)
- .enableFeature(google.picker.Feature.NAV_HIDDEN);
-
- editorUi.imageSearchPicker = picker.setCallback(function(data)
- {
- ImageDialog.filePicked(data);
- }).build();
- }
-
- editorUi.imageSearchPicker.setVisible(true);
- editorUi.movePickersToTop();
- });
- searchBtn.className = 'geBtn';
- btns.appendChild(searchBtn);
- if (editorUi.drive != null && urlParams['photos'] == '1')
- {
- var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
-
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.photoPicker == null)
- {
- var token = gapi.auth.getToken().access_token;
- var picker = new google.picker.PickerBuilder()
- .setAppId(editorUi.drive.appId)
- .setLocale(mxLanguage)
- .setOAuthToken(token)
- .addView(google.picker.ViewId.PHOTOS)
- .addView(google.picker.ViewId.PHOTO_ALBUMS)
- .addView(google.picker.ViewId.PHOTO_UPLOAD);
-
- editorUi.photoPicker = picker.setCallback(function(data)
- {
- ImageDialog.filePicked(data);
- }).build();
- }
-
- editorUi.photoPicker.setVisible(true);
- editorUi.movePickersToTop();
- }));
- }
- });
- gpBtn.className = 'geBtn';
- btns.appendChild(gpBtn);
- }
- }
- mxEvent.addListener(linkInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- apply(linkInput.value);
- }
- });
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- apply(linkInput.value);
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- // Shows drop icon in dialog background
- if (Graph.fileSupport)
- {
- btns.style.marginTop = '120px';
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- div.style.backgroundPosition = 'center 65%';
- div.style.backgroundRepeat = 'no-repeat';
-
- var bg = document.createElement('div');
- bg.style.position = 'absolute';
- bg.style.width = '420px';
- bg.style.top = '58%';
- bg.style.textAlign = 'center';
- bg.style.fontSize = '18px';
- bg.style.color = '#a0c3ff';
- mxUtils.write(bg, mxResources.get('dragImagesHere'));
- div.appendChild(bg);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new print dialog.
- */
- PrintDialog.prototype.create = function(editorUi)
- {
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
-
- var title = document.createElement('h3');
- title.style.marginTop = '0px';
- mxUtils.write(title, mxResources.get('print'));
- div.appendChild(title);
-
- var pageCount = 1;
- var currentPage = 1;
- // Pages
- var pagesSection = document.createElement('div');
- pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
-
- var allPagesRadio = document.createElement('input');
- allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
-
- allPagesRadio.setAttribute('value', 'all');
- allPagesRadio.setAttribute('type', 'radio');
- allPagesRadio.setAttribute('name', 'pages');
- pagesSection.appendChild(allPagesRadio);
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('printAllPages'));
- pagesSection.appendChild(span);
-
- mxUtils.br(pagesSection);
- // Pages ... to ...
- var pagesRadio = allPagesRadio.cloneNode(true);
- pagesRadio.setAttribute('value', 'range');pagesSection.appendChild(pagesRadio);
- allPagesRadio.setAttribute('checked', 'checked');
-
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('pages') + ':');
- pagesSection.appendChild(span);
-
- var pagesFromInput = document.createElement('input');
- pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
- pagesFromInput.setAttribute('value', '1');
- pagesFromInput.setAttribute('type', 'number');
- pagesFromInput.setAttribute('min', '1');
- pagesFromInput.style.width = '50px';
- pagesSection.appendChild(pagesFromInput);
-
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('to'));
- pagesSection.appendChild(span);
-
- var pagesToInput = pagesFromInput.cloneNode(true);
- pagesSection.appendChild(pagesToInput);
-
- mxEvent.addListener(pagesFromInput, 'focus', function()
- {
- pagesRadio.checked = true;
- });
-
- mxEvent.addListener(pagesToInput, 'focus', function()
- {
- pagesRadio.checked = true;
- });
-
- function validatePageRange()
- {
- pagesToInput.value = Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value)));
- pagesFromInput.value = Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value)));
- };
-
- mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
- mxEvent.addListener(pagesToInput, 'change', validatePageRange);
-
- if (false && editorUi.pages != null)
- {
- pageCount = editorUi.pages.length;
- if (editorUi.currentPage != null)
- {
- for (var i = 0; i < editorUi.pages.length; i++)
- {
- if (editorUi.currentPage == editorUi.pages[i])
- {
- currentPage = i + 1;
- pagesFromInput.value = currentPage;
- pagesToInput.value = currentPage;
- break;
- }
- }
- }
- }
-
- pagesFromInput.setAttribute('max', pageCount);
- pagesToInput.setAttribute('max', pageCount);
-
- if (pageCount > 1)
- {
- div.appendChild(pagesSection);
- }
-
- // Adjust to ...
- var adjustSection = document.createElement('div');
- adjustSection.style.marginBottom = '10px';
-
- var adjustRadio = document.createElement('input');
- adjustRadio.style.marginRight = '8px';
-
- adjustRadio.setAttribute('value', 'adjust');
- adjustRadio.setAttribute('type', 'radio');
- adjustRadio.setAttribute('name', 'printZoom');
- adjustSection.appendChild(adjustRadio);
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('adjustTo'));
- adjustSection.appendChild(span);
-
- var zoomInput = document.createElement('input');
- zoomInput.style.cssText = 'margin:0 8px 0 8px;';
- zoomInput.setAttribute('value', '100 %');
- zoomInput.style.width = '50px';
- adjustSection.appendChild(zoomInput);
-
- mxEvent.addListener(zoomInput, 'focus', function()
- {
- adjustRadio.checked = true;
- });
-
- div.appendChild(adjustSection);
- // Fit to ...
- var fitSection = pagesSection.cloneNode(false);
- var fitRadio = adjustRadio.cloneNode(true);
- fitRadio.setAttribute('value', 'fit');
- adjustRadio.setAttribute('checked', 'checked');
-
- var spanFitRadio = document.createElement('div');
- spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
- spanFitRadio.appendChild(fitRadio);
- fitSection.appendChild(spanFitRadio);
-
- var table = document.createElement('table');
- table.style.display = 'inline-block';
- var tbody = document.createElement('tbody');
-
- var row1 = document.createElement('tr');
- var row2 = row1.cloneNode(true);
-
- var td1 = document.createElement('td');
- var td2 = td1.cloneNode(true);
- var td3 = td1.cloneNode(true);
-
- var td4 = td1.cloneNode(true);
- var td5 = td1.cloneNode(true);
- var td6 = td1.cloneNode(true);
-
- td1.style.textAlign = 'right';
- td4.style.textAlign = 'right';
- mxUtils.write(td1, mxResources.get('fitTo'));
-
- var sheetsAcrossInput = document.createElement('input');
- sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
- sheetsAcrossInput.setAttribute('value', '1');
- sheetsAcrossInput.setAttribute('min', '1');
- sheetsAcrossInput.setAttribute('type', 'number');
- sheetsAcrossInput.style.width = '40px';
- td2.appendChild(sheetsAcrossInput);
-
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
- td3.appendChild(span);
- mxUtils.write(td4, mxResources.get('fitToBy'));
-
- var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
- td5.appendChild(sheetsDownInput);
-
- mxEvent.addListener(sheetsAcrossInput, 'focus', function()
- {
- fitRadio.checked = true;
- });
- mxEvent.addListener(sheetsDownInput, 'focus', function()
- {
- fitRadio.checked = true;
- });
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('fitToSheetsDown'));
- td6.appendChild(span);
-
- row1.appendChild(td1);
- row1.appendChild(td2);
- row1.appendChild(td3);
-
- row2.appendChild(td4);
- row2.appendChild(td5);
- row2.appendChild(td6);
-
- tbody.appendChild(row1);
- tbody.appendChild(row2);
- table.appendChild(tbody);
- fitSection.appendChild(table);
-
- div.appendChild(fitSection);
-
- // Page scale ...
- var pageScaleSection = document.createElement('div');
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('paperSize'));
- pageScaleSection.appendChild(span);
-
- var pageScaleInput = document.createElement('input');
- pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
- pageScaleInput.setAttribute('value', '100 %');
- pageScaleInput.style.width = '60px';
- pageScaleSection.appendChild(pageScaleInput);
-
- div.appendChild(pageScaleSection);
-
- // Buttons
- var buttons = document.createElement('div');
- buttons.style.cssText = 'text-align:right;margin:36px 0 0 0;';
-
- // Overall scale for print-out to account for print borders in dialogs etc
- function preview(print)
- {
- var printScale = parseInt(pageScaleInput.value) / 100;
-
- if (isNaN(printScale))
- {
- printScale = 1;
- pageScaleInput.value = '100 %';
- }
-
- // Workaround to match available paper size in actual print output
- printScale *= 0.75;
- // Negative coordinates are cropped or shifted if page visible
- var gb = graph.getGraphBounds();
- var border = 0;
- var x0 = 0;
- var y0 = 0;
- var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
- var scale = 1 / graph.pageScale;
- var autoOrigin = fitRadio.checked;
- if (autoOrigin)
- {
- var h = parseInt(sheetsAcrossInput.value);
- var v = parseInt(sheetsDownInput.value);
-
- scale = Math.min((pf.height * v) / (gb.height / graph.view.scale),
- (pf.width * h) / (gb.width / graph.view.scale));
- }
- else
- {
- scale = parseInt(zoomInput.value) / 100 * graph.pageScale;
-
- if (isNaN(scale))
- {
- printScale = 1 / graph.pageScale;
- zoomInput.value = '100 %';
- }
- }
- // Applies print scale
- pf = mxRectangle.fromRectangle(pf);
- pf.width = Math.ceil(pf.width * printScale);
- pf.height = Math.ceil(pf.height * printScale);
- scale *= printScale;
-
- // Starts at first visible page
- if (!autoOrigin && graph.pageVisible)
- {
- var layout = graph.getPageLayout();
- x0 -= layout.x * pf.width;
- y0 -= layout.y * pf.height;
- }
- else
- {
- autoOrigin = true;
- }
-
- return PrintDialog.showPreview(PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin, print), print);
- };
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- }
-
- if (!mxClient.IS_CHROMEAPP)
- {
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- editorUi.hideDialog();
- preview(false);
- });
- previewBtn.className = 'geBtn';
- buttons.appendChild(previewBtn);
- }
-
- var printBtn = mxUtils.button(mxResources.get((mxClient.IS_CHROMEAPP) ? 'ok' : 'print'), function()
- {
- editorUi.hideDialog();
- preview(true);
- });
- printBtn.className = 'geBtn gePrimaryBtn';
- buttons.appendChild(printBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Overrides link dialog to add Google Picker.
- */
- var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
- {
- var div = document.createElement('div');
- mxUtils.write(div, mxResources.get('editLink') + ':');
-
- var inner = document.createElement('div');
- inner.className = 'geTitle';
- inner.style.backgroundColor = 'transparent';
- inner.style.borderColor = 'transparent';
- inner.style.whiteSpace = 'nowrap';
- inner.style.textOverflow = 'clip';
- inner.style.cursor = 'default';
-
- if (!mxClient.IS_VML)
- {
- inner.style.paddingRight = '20px';
- }
-
- var linkInput = document.createElement('input');
- linkInput.setAttribute('value', initialValue);
- linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
- linkInput.setAttribute('type', 'text');
- linkInput.style.marginTop = '6px';
- linkInput.style.width = '400px';
- linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
- linkInput.style.backgroundRepeat = 'no-repeat';
- linkInput.style.backgroundPosition = '100% 50%';
- linkInput.style.paddingRight = '14px';
-
- var cross = document.createElement('div');
- cross.setAttribute('title', mxResources.get('reset'));
- cross.style.position = 'relative';
- cross.style.left = '-16px';
- cross.style.width = '12px';
- cross.style.height = '14px';
- cross.style.cursor = 'pointer';
- // Workaround for inline-block not supported in IE
- cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
- cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
-
- // Needed to block event transparency in IE
- cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- mxEvent.addListener(cross, 'click', function()
- {
- linkInput.value = '';
- linkInput.focus();
- });
-
- inner.appendChild(linkInput);
- inner.appendChild(cross);
- div.appendChild(inner);
-
- var mainBtn = mxUtils.button(btnLabel, function()
- {
- editorUi.hideDialog();
- fn(linkInput.value, LinkDialog.selectedDocs);
- });
- mainBtn.className = 'geBtn gePrimaryBtn';
-
- this.init = function()
- {
- linkInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- linkInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- // Installs drag and drop handler for links
- if (Graph.fileSupport)
- {
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var graph = editorUi.editor.graph;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
- mainBtn.click();
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
-
- var btns = document.createElement('div');
- btns.style.marginTop = '14px';
- btns.style.textAlign = 'right';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- LinkDialog.selectedDocs = null;
-
- LinkDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- LinkDialog.selectedDocs = data.docs;
- var href = data.docs[0].url;
-
- if (data.docs[0].mimeType == 'application/mxe' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile')
- {
- var domain = DriveClient.prototype.oldAppHostname;
- href = 'https://' + domain + '/#G' + data.docs[0].id;
- }
- else if (data.docs[0].mimeType == 'application/mxr' || data.docs[0].mimeType == 'application/vnd.jgraph.mxfile.realtime')
- {
- var domain = DriveClient.prototype.newAppHostname;
- href = 'https://' + domain + '/#G' + data.docs[0].id;
- }
- else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
- {
- // Do not use folderview in data.docs[0].url link to Google Drive instead
- href = 'https://drive.google.com/#folders/' + data.docs[0].id;
- }
-
- linkInput.value = href;
- }
- else
- {
- LinkDialog.selectedDocs = null;
- }
-
- linkInput.focus();
- };
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- var gpBtn = mxUtils.button(mxResources.get('googlePlus'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
-
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.linkPicker == null)
- {
- var token = gapi.auth.getToken().access_token;
- var view = new google.picker.DocsView()
- .setIncludeFolders(true)
- .setSelectFolderEnabled(true);
- var picker = new google.picker.PickerBuilder()
- .setAppId(editorUi.drive.appId)
- .setLocale(mxLanguage)
- .setOAuthToken(token)
- .addView(view)
- .addView(google.picker.ViewId.IMAGE_SEARCH)
- .addView(google.picker.ViewId.VIDEO_SEARCH)
- .addView(google.picker.ViewId.MAPS);
-
- if (urlParams['photos'] == '1')
- {
- picker.addView(google.picker.ViewId.PHOTOS)
- .addView(google.picker.ViewId.PHOTO_ALBUMS)
- .addView(google.picker.ViewId.PHOTO_UPLOAD)
- }
-
- editorUi.linkPicker = picker.setCallback(function(data)
- {
- LinkDialog.filePicked(data);
- }).build();
- }
-
- editorUi.linkPicker.setVisible(true);
- editorUi.movePickersToTop();
- }));
- }
- });
- gpBtn.className = 'geBtn';
- btns.appendChild(gpBtn);
- }
-
- if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
- {
- var dbBtn = mxUtils.button(mxResources.get('dropbox'), function()
- {
- // Authentication will be carried out on open to make sure the
- // autosave does not show an auth dialog. Showing it here will
- // block the second dialog (the file picker) so it's too early.
- Dropbox.choose(
- {
- linkType : 'direct',
- cancel: function()
- {
- // do nothing
- },
- success : function(files)
- {
- linkInput.value = files[0].link;
- }
- });
- });
- dbBtn.className = 'geBtn';
- btns.appendChild(dbBtn);
- }
-
- if (typeof(WL) != 'undefined' && typeof(WL.fileDialog) != 'undefined' && editorUi.oneDrive != null)
- {
- var dbBtn = mxUtils.button(mxResources.get('oneDrive'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- editorUi.oneDrive.execute(mxUtils.bind(this, function(token)
- {
- if (token != null)
- {
- editorUi.spinner.stop();
-
- WL.fileDialog(
- {
- mode: 'open',
- select: 'single'
- }).then(
- function (resp)
- {
- if (resp != null && resp.data != null && resp.data.files != null && resp.data.files.length > 0)
- {
- linkInput.value = resp.data.files[0].link;
- }
- },
- function (responseFailed) {}
- );
- }
- }));
- }
- });
- dbBtn.className = 'geBtn';
- btns.appendChild(dbBtn);
- }
- mxEvent.addListener(linkInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- editorUi.hideDialog();
- fn(linkInput.value, LinkDialog.selectedDocs);
- }
- });
- btns.appendChild(mainBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new about dialog
- */
- var AboutDialog = function(editorUi)
- {
- var div = document.createElement('div');
- div.style.marginTop = '6px';
- div.setAttribute('align', 'center');
-
- var img = document.createElement('img');
- img.style.border = '0px';
- img.setAttribute('width', '176');
- img.setAttribute('width', '151');
- img.style.width = '170px';
- img.style.height = '219px';
- img.setAttribute('src', IMAGE_PATH + '/logo-flat.png');
- div.appendChild(img);
- mxUtils.br(div);
-
- var v = document.createElement('small');
- v.innerHTML = 'v ' + EditorUi.VERSION;
- v.style.color = '#505050';
- div.appendChild(v);
-
- mxUtils.br(div);
- mxUtils.br(div);
- var small = document.createElement('small');
- small.style.color = '#505050';
- small.innerHTML = '© 2005-2016 <a href="https://www.jgraph.com/" style="color:inherit;" target="_blank">JGraph Ltd</a>.<br>All Rights Reserved.';
- div.appendChild(small);
-
- mxEvent.addListener(div, 'click', function(e)
- {
- if (mxEvent.getSource(e).nodeName != 'A')
- {
- editorUi.hideDialog();
- }
- });
-
- this.container = div;
- };
- /**
- * Constructs a new about dialog
- */
- var FeedbackDialog = function(editorUi)
- {
- var div = document.createElement('div');
-
- var label = document.createElement('div');
- mxUtils.write(label, mxResources.get('sendYourFeedbackToDrawIo'));
- label.style.fontSize = '18px';
- label.style.marginBottom = '18px';
-
- div.appendChild(label);
-
- label = document.createElement('div');
- mxUtils.write(label, mxResources.get('yourEmailAddress') + ' (' + mxResources.get('required') + ')');
-
- div.appendChild(label);
-
- var email = document.createElement('input');
- email.setAttribute('type', 'text');
- email.style.marginTop = '6px';
- email.style.width = '600px';
-
- var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
- {
- var diagram = ((cb.checked) ? '\nDiagram:\n' + editorUi.getFileData() : '') +
- '\nBrowser:\n' + navigator.userAgent;
-
- if (diagram.length > FeedbackDialog.maxAttachmentSize)
- {
- editorUi.alert(mxResources.get('drawingTooLarge'));
- }
- else
- {
- editorUi.hideDialog();
-
- if (editorUi.spinner.spin(document.body))
- {
- mxUtils.post('/email', 'email=' + encodeURIComponent(email.value) +
- '&version=' + encodeURIComponent(EditorUi.VERSION) +
- '&url=' + encodeURIComponent(window.location.href) +
- '&body=' + encodeURIComponent('Feedback:\n' + textarea.value + diagram),
- function(req)
- {
- editorUi.spinner.stop();
-
- if (req.getStatus() == 200)
- {
- editorUi.alert(mxResources.get('feedbackSent'));
- }
- else
- {
- editorUi.alert(mxResources.get('errorSendingFeedback'));
- }
- },
- function()
- {
- editorUi.spinner.stop();
- editorUi.alert(mxResources.get('errorSendingFeedback'));
- });
- }
- }
- });
- sendButton.className = 'geBtn gePrimaryBtn';
-
- sendButton.setAttribute('disabled', 'disabled');
- 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,}))$/;
-
- mxEvent.addListener(email, 'change', function()
- {
- if (email.value.length > 0 && re.test(email.value) > 0)
- {
- sendButton.removeAttribute('disabled');
- }
- else
- {
- sendButton.setAttribute('disabled', 'disabled');
- }
- });
-
- mxEvent.addListener(email, 'keyup', function()
- {
- if (email.value.length > 0 && re.test(email.value))
- {
- sendButton.removeAttribute('disabled');
- }
- else
- {
- sendButton.setAttribute('disabled', 'disabled');
- }
- });
-
- div.appendChild(email);
-
- this.init = function()
- {
- email.focus();
- };
-
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
- cb.setAttribute('checked', 'checked');
- cb.defaultChecked = true;
-
- var p2 = document.createElement('p');
- p2.style.marginTop = '14px';
- p2.appendChild(cb);
-
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
- p2.appendChild(span);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
-
- div.appendChild(p2);
-
- label = document.createElement('div');
- mxUtils.write(label, mxResources.get('feedback'));
-
- div.appendChild(label);
-
- var textarea = document.createElement('textarea');
- textarea.style.resize = 'none';
- textarea.style.width = '600px';
- textarea.style.height = '140px';
- textarea.style.marginTop = '6px';
-
- textarea.setAttribute('placeholder', mxResources.get('commentsNotes'));
-
- div.appendChild(textarea);
- var buttons = document.createElement('div');
- buttons.style.marginTop = '26px';
- buttons.style.textAlign = 'right';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(sendButton);
- }
- else
- {
- buttons.appendChild(sendButton);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Maximum size of attachments in bytes. Default is 1000000.
- */
- FeedbackDialog.maxAttachmentSize = 1000000;
- /**
- * Constructs a new revision dialog
- */
- var RevisionDialog = function(editorUi, revs)
- {
- var div = document.createElement('div');
-
- var title = document.createElement('h3');
- title.style.marginTop = '0px';
- mxUtils.write(title, mxResources.get('revisionHistory'));
- div.appendChild(title);
-
- var list = document.createElement('div');
- list.style.position = 'absolute';
- list.style.overflow = 'auto';
- list.style.width = '170px';
- list.style.height = '378px';
- div.appendChild(list);
-
- var container = document.createElement('div');
- container.style.position = 'absolute';
- container.style.border = '1px solid lightGray';
- container.style.left = '199px';
- container.style.width = '470px';
- container.style.height = '376px';
- container.style.overflow = 'hidden';
-
- mxEvent.disableContextMenu(container);
- div.appendChild(container);
- var graph = new Graph(container);
- graph.setEnabled(false);
- graph.setPanning(true);
- graph.panningHandler.ignoreCell = true;
- graph.panningHandler.useLeftButtonForPanning = true;
- graph.minFitScale = null;
- graph.maxFitScale = null;
- graph.centerZoom = true;
-
- // Disables hyperlinks
- graph.getLinkForCell = function()
- {
- return null;
- };
- if (Editor.MathJaxRender)
- {
- graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
- {
- // LATER: Math support is used if current graph has math enabled
- // should use switch from history instead but requires setting the
- // global mxClient.NO_FO switch
- if (editorUi.editor.graph.mathEnabled)
- {
- Editor.MathJaxRender(graph.container);
- }
- }));
- }
-
- var opts = {
- lines: 11, // The number of lines to draw
- length: 15, // The length of each line
- width: 6, // The line thickness
- radius: 10, // The radius of the inner circle
- corners: 1, // Corner roundness (0..1)
- rotate: 0, // The rotation offset
- direction: 1, // 1: clockwise, -1: counterclockwise
- color: '#000', // #rgb or #rrggbb or array of colors
- speed: 1.4, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- className: 'spinner', // The CSS class to assign to the spinner
- zIndex: 2e9, // The z-index (defaults to 2000000000)
- top: '50%', // Top position relative to parent
- left: '50%' // Left position relative to parent
- };
-
- var spinner = new Spinner(opts);
- var file = editorUi.getCurrentFile();
- var currentRow = null;
- var currentRev = null;
- var currentDoc = null;
- var currentXml = null;
-
- var zoomInBtn = mxUtils.button('', function()
- {
- if (currentDoc != null)
- {
- graph.zoomIn();
- }
- });
- zoomInBtn.className = 'geSprite geSprite-zoomin';
- zoomInBtn.setAttribute('title', mxResources.get('zoomIn'));
- zoomInBtn.style.outline = 'none';
- zoomInBtn.style.border = 'none';
- zoomInBtn.style.margin = '2px';
- zoomInBtn.setAttribute('disabled', 'disabled');
- mxUtils.setOpacity(zoomInBtn, 20);
-
- var zoomOutBtn = mxUtils.button('', function()
- {
- if (currentDoc != null)
- {
- graph.zoomOut();
- }
- });
- zoomOutBtn.className = 'geSprite geSprite-zoomout';
- zoomOutBtn.setAttribute('title', mxResources.get('zoomOut'));
- zoomOutBtn.style.outline = 'none';
- zoomOutBtn.style.border = 'none';
- zoomOutBtn.style.margin = '2px';
- zoomOutBtn.setAttribute('disabled', 'disabled');
- mxUtils.setOpacity(zoomOutBtn, 20);
- var zoomFitBtn = mxUtils.button('', function()
- {
- if (currentDoc != null)
- {
- graph.maxFitScale = 8;
- graph.fit(8);
- graph.center();
- }
- });
- zoomFitBtn.className = 'geSprite geSprite-fit';
- zoomFitBtn.setAttribute('title', mxResources.get('fit'));
- zoomFitBtn.style.outline = 'none';
- zoomFitBtn.style.border = 'none';
- zoomFitBtn.style.margin = '2px';
- zoomFitBtn.setAttribute('disabled', 'disabled');
- mxUtils.setOpacity(zoomFitBtn, 20);
-
- var zoomActualBtn = mxUtils.button('', function()
- {
- if (currentDoc != null)
- {
- graph.zoomActual();
- graph.center();
- }
- });
- zoomActualBtn.className = 'geSprite geSprite-actualsize';
- zoomActualBtn.setAttribute('title', mxResources.get('actualSize'));
- zoomActualBtn.style.outline = 'none';
- zoomActualBtn.style.border = 'none';
- zoomActualBtn.style.margin = '2px';
- zoomActualBtn.setAttribute('disabled', 'disabled');
- mxUtils.setOpacity(zoomActualBtn, 20);
-
- var fileInfo = document.createElement('div');
- fileInfo.style.position = 'absolute';
- fileInfo.style.textAlign = 'right';
- fileInfo.style.color = 'gray';
- fileInfo.style.marginTop = '10px';
- fileInfo.style.backgroundColor = 'transparent';
- fileInfo.style.top = '440px';
- fileInfo.style.right = '32px';
- fileInfo.style.maxWidth = '380px';
- fileInfo.style.cursor = 'default';
- var downloadBtn = mxUtils.button(mxResources.get('download'), function()
- {
- if (currentDoc != null)
- {
- var file = editorUi.getCurrentFile();
- var filename = (file != null && file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
- var data = mxUtils.getXml(currentDoc.documentElement);
- if (editorUi.isLocalFileSave())
- {
- editorUi.saveLocalFile(data, filename, 'text/xml');
- }
- else
- {
- var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
- '&data=' + encodeURIComponent(editorUi.editor.graph.compress(data));
- new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
- '&format=xml' + param).simulate(document, '_blank');
- }
- }
- });
- downloadBtn.className = 'geBtn';
- downloadBtn.setAttribute('disabled', 'disabled');
- var restoreBtn = mxUtils.button(mxResources.get('restore'), function()
- {
- if (currentDoc != null && currentXml != null)
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
- {
- file.save(true, function(resp)
- {
- editorUi.spinner.stop();
- editorUi.replaceFileData(currentXml);
- editorUi.hideDialog();
- }, function(resp)
- {
- editorUi.spinner.stop();
- editorUi.editor.setStatus('');
- editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
- });
- }
- });
- }
- });
- restoreBtn.className = 'geBtn';
- restoreBtn.setAttribute('disabled', 'disabled');
-
- var pageSelect = document.createElement('select');
- pageSelect.setAttribute('disabled', 'disabled');
- pageSelect.style.maxWidth = '80px';
- pageSelect.style.position = 'relative';
- pageSelect.style.top = '-2px';
- pageSelect.style.verticalAlign = 'bottom';
- pageSelect.style.marginRight = '6px';
- pageSelect.style.display = 'none';
-
- var pageSelectFunction = null;
-
- mxEvent.addListener(pageSelect, 'change', function(evt)
- {
- if (pageSelectFunction != null)
- {
- pageSelectFunction(evt);
- mxEvent.consume(evt);
- }
- });
-
- var newBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
- {
- if (currentDoc != null)
- {
- window.openFile = new OpenFile(function()
- {
- window.openFile = null;
- });
-
- window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
- window.openWindow(editorUi.getUrl());
- }
- });
- newBtn.className = 'geBtn';
- newBtn.setAttribute('disabled', 'disabled');
-
- var showBtn = mxUtils.button(mxResources.get('show'), function()
- {
- if (currentRev != null)
- {
- window.open(currentRev.getUrl());
- }
- });
- showBtn.className = 'geBtn gePrimaryBtn';
- showBtn.setAttribute('disabled', 'disabled');
- var buttons = document.createElement('div');
- buttons.style.position = 'absolute';
- buttons.style.top = '482px';
- buttons.style.width = '640px';
- buttons.style.textAlign = 'right';
- var tb = document.createElement('div');
- tb.className = 'geToolbarContainer';
- tb.style.backgroundColor = 'transparent';
- tb.style.padding = '2px';
- tb.style.border = 'none';
- tb.style.left = '199px';
- tb.style.top = '442px';
-
- var currentElt = null;
-
- if (file == null || (editorUi.drive == null && file.constructor == DriveFile) ||
- (editorUi.dropbox == null && file.constructor == DropboxFile))
- {
- container.style.display = 'none';
- tb.style.display = 'none';
- mxUtils.write(list, mxResources.get('notAvailable'));
- }
- else
- {
- if (revs != null && revs.length > 0)
- {
- container.style.cursor = 'move';
-
- var table = document.createElement('table');
- table.style.border = '1px solid lightGray';
- table.style.borderCollapse = 'collapse';
- table.style.borderSpacing = '0px';
- table.style.width = '100%';
- var tbody = document.createElement('tbody');
-
- var today = new Date().toDateString();
- var currentPage = 0;
-
- if (editorUi.currentPage != null && editorUi.pages != null)
- {
- currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
- }
-
- for (var i = revs.length - 1; i >= 0; i--)
- {
- var elt = (function(item)
- {
- var ts = new Date(item.modifiedDate);
- var row = null;
- var pd = '6px';
-
- // Workaround for negative timestamps in Dropbox
- if (ts.getTime() >= 0)
- {
- row = document.createElement('tr');
- row.style.borderBottom = '1px solid lightGray';
- row.style.fontSize = '12px';
- row.style.cursor = 'pointer';
-
- var date = document.createElement('td');
- date.style.padding = pd;
- date.style.whiteSpace = 'nowrap';
-
- if (item == revs[revs.length - 1])
- {
- mxUtils.write(date, mxResources.get('current'));
- }
- else
- {
- if (ts.toDateString() === today)
- {
- mxUtils.write(date, ts.toLocaleTimeString());
- }
- else
- {
- mxUtils.write(date, ts.toLocaleDateString() + ' ' +
- ts.toLocaleTimeString());
- }
- }
-
- row.appendChild(date);
-
- row.setAttribute('title', ts.toLocaleDateString() + ' ' +
- ts.toLocaleTimeString() + ' ' +
- editorUi.formatFileSize(parseInt(item.fileSize)) +
- ((item.lastModifyingUserName != null) ? ' ' +
- item.lastModifyingUserName : ''));
- function updateGraph(xml)
- {
- spinner.stop();
- var doc = mxUtils.parseXml(xml);
- var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
-
- if (node != null)
- {
- pageSelect.style.display = 'none';
- pageSelect.innerHTML = '';
- currentDoc = doc;
- currentXml = xml;
- parseSelectFunction = null;
-
- function parseGraphModel(dataNode)
- {
- var bg = dataNode.getAttribute('background');
-
- if (bg == null || bg == '' || bg == mxConstants.NONE)
- {
- bg = '#ffffff';
- }
-
- container.style.backgroundColor = bg;
-
- var codec = new mxCodec(dataNode.ownerDocument);
- codec.decode(dataNode, graph.getModel());
- graph.maxFitScale = 1;
- graph.fit(8);
- graph.center();
-
- return dataNode;
- }
-
- function parseDiagram(diagramNode)
- {
- if (diagramNode != null)
- {
- diagramNode = parseGraphModel(mxUtils.parseXml(editorUi.editor.graph.decompress(
- mxUtils.getTextContent(diagramNode))).documentElement);
- }
-
- return diagramNode;
- }
-
- if (node.nodeName == 'mxfile')
- {
- var diagrams = node.getElementsByTagName('diagram');
- var realPage = Math.min(currentPage, diagrams.length - 1);
-
- if (diagrams.length > 0)
- {
- parseDiagram(diagrams[realPage]);
- }
-
- if (diagrams.length > 1)
- {
- pageSelect.removeAttribute('disabled');
- pageSelect.style.display = '';
-
- for (var i = 0; i < diagrams.length; i++)
- {
- var pageOption = document.createElement('option');
- mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
- mxResources.get('pageWithNumber', [i + 1]));
- pageOption.setAttribute('value', i);
-
- if (i == realPage)
- {
- pageOption.setAttribute('selected', 'selected');
- }
-
- pageSelect.appendChild(pageOption);
- }
- }
-
- pageSelectFunction = function()
- {
- currentPage = pageSelect.value;
- parseDiagram(diagrams[currentPage]);
- }
- }
- else
- {
- parseGraphModel(node);
- }
-
- fileInfo.innerHTML = '';
- mxUtils.write(fileInfo, ts.toLocaleDateString() + ' ' +
- ts.toLocaleTimeString());
- fileInfo.setAttribute('title', row.getAttribute('title'));
- zoomInBtn.removeAttribute('disabled');
- zoomOutBtn.removeAttribute('disabled');
- zoomFitBtn.removeAttribute('disabled');
- zoomActualBtn.removeAttribute('disabled');
-
- if (file == null || !file.isRestricted())
- {
- if (editorUi.editor.graph.isEnabled())
- {
- restoreBtn.removeAttribute('disabled');
- }
-
- downloadBtn.removeAttribute('disabled');
- showBtn.removeAttribute('disabled');
- newBtn.removeAttribute('disabled');
- }
-
- mxUtils.setOpacity(zoomInBtn, 60);
- mxUtils.setOpacity(zoomOutBtn, 60);
- mxUtils.setOpacity(zoomFitBtn, 60);
- mxUtils.setOpacity(zoomActualBtn, 60);
- }
- else
- {
- pageSelect.style.display = 'none';
- pageSelect.innerHTML = '';
- fileInfo.innerHTML = '';
- mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
- }
- };
-
- mxEvent.addListener(row, 'click', function(evt)
- {
- if (currentRev != item)
- {
- spinner.stop();
-
- if (currentRow != null)
- {
- currentRow.style.backgroundColor = '';
- }
-
- currentRev = item;
- currentRow = row;
- currentRow.style.backgroundColor = '#ebf2f9';
- currentDoc = null;
- currentXml = null;
- fileInfo.removeAttribute('title');
- fileInfo.innerHTML = mxResources.get('loading') + '...';
- container.style.backgroundColor = '#ffffff';
- graph.getModel().clear();
-
- restoreBtn.setAttribute('disabled', 'disabled');
- downloadBtn.setAttribute('disabled', 'disabled');
- zoomInBtn.setAttribute('disabled', 'disabled');
- zoomOutBtn.setAttribute('disabled', 'disabled');
- zoomActualBtn.setAttribute('disabled', 'disabled');
- zoomFitBtn.setAttribute('disabled', 'disabled');
- newBtn.setAttribute('disabled', 'disabled');
- showBtn.setAttribute('disabled', 'disabled');
- pageSelect.setAttribute('disabled', 'disabled');
-
- mxUtils.setOpacity(zoomInBtn, 20);
- mxUtils.setOpacity(zoomOutBtn, 20);
- mxUtils.setOpacity(zoomFitBtn, 20);
- mxUtils.setOpacity(zoomActualBtn, 20);
-
- spinner.spin(container);
-
- item.getXml(function(xml)
- {
- if (currentRev == item)
- {
- updateGraph(xml);
- }
- }, function(err)
- {
- spinner.stop();
- pageSelect.style.display = 'none';
- pageSelect.innerHTML = '';
- fileInfo.innerHTML = '';
- mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
- });
- mxEvent.consume(evt);
- }
- });
-
- mxEvent.addListener(row, 'dblclick', function(evt)
- {
- showBtn.click();
-
- if (window.getSelection)
- {
- window.getSelection().removeAllRanges();
- }
- else if (document.selection)
- {
- document.selection.empty();
- }
-
- mxEvent.consume(evt);
- }, false);
-
- tbody.appendChild(row);
- }
- return row;
- })(revs[i]);
-
- // Selects and loads first element in list (ie current version) after
- // graph container was initialized since there is no loading delay
- if (elt != null && i == revs.length - 1)
- {
- currentElt = elt;
- }
- }
-
- table.appendChild(tbody);
- list.appendChild(table);
- }
- else
- {
- container.style.display = 'none';
- tb.style.display = 'none';
- mxUtils.write(list, mxResources.get('noRevisions'));
- }
- }
-
- this.init = function()
- {
- if (currentElt != null)
- {
- currentElt.click();
- }
- };
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
- closeBtn.className = 'geBtn';
- tb.appendChild(pageSelect);
- tb.appendChild(zoomInBtn);
- tb.appendChild(zoomOutBtn);
- tb.appendChild(zoomActualBtn);
- tb.appendChild(zoomFitBtn);
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(closeBtn);
- buttons.appendChild(downloadBtn);
- buttons.appendChild(newBtn);
- buttons.appendChild(restoreBtn);
- buttons.appendChild(showBtn);
- }
- else
- {
- buttons.appendChild(downloadBtn);
- buttons.appendChild(newBtn);
- buttons.appendChild(restoreBtn);
- buttons.appendChild(showBtn);
- buttons.appendChild(closeBtn);
- }
- div.appendChild(buttons);
- div.appendChild(tb);
- div.appendChild(fileInfo);
- this.container = div;
- };
- /**
- *
- */
- var AnimationWindow = function(editorUi, x, y, w, h)
- {
- var table = document.createElement('table');
- table.style.width = '100%';
- table.style.height = '100%';
- var tbody = document.createElement('tbody');
- var tr1 = document.createElement('tr');
- var td11 = document.createElement('td');
- td11.style.width = '140px';
- var td12 = document.createElement('td');
- var tr2 = document.createElement('tr');
- tr2.style.height = '40px';
- var td21 = document.createElement('td');
- td21.setAttribute('colspan', '2');
-
- var list = document.createElement('textarea');
- list.style.overflow = 'auto';
- list.style.width = '100%';
- list.style.height = '100%';
- td11.appendChild(list);
-
- var root = editorUi.editor.graph.getModel().getRoot();
-
- if (root.value != null && typeof(root.value) == 'object')
- {
- list.value = root.value.getAttribute('animation');
- }
-
- var container = document.createElement('div');
- container.style.border = '1px solid lightGray';
- container.style.background = '#ffffff';
- container.style.width = '100%';
- container.style.height = '100%';
- container.style.overflow = 'auto';
-
- mxEvent.disableContextMenu(container);
- td12.appendChild(container);
-
- var graph = new Graph(container);
- graph.setEnabled(false);
- graph.setPanning(true);
- graph.foldingEnabled = false;
- graph.panningHandler.ignoreCell = true;
- graph.panningHandler.useLeftButtonForPanning = true;
- graph.minFitScale = null;
- graph.maxFitScale = null;
- graph.centerZoom = true;
-
- // For animation and fading
- function getNodesForCells(cells)
- {
- var nodes = [];
-
- for (var i = 0; i < cells.length; i++)
- {
- var state = graph.view.getState(cells[i]);
-
- if (state != null)
- {
- var shapes = graph.cellRenderer.getShapesForState(state);
-
- for (var j = 0; j < shapes.length; j++)
- {
- if (shapes[j] != null && shapes[j].node != null)
- {
- nodes.push(shapes[j].node);
- }
- }
-
- // Adds folding icon
- if (state.control != null && state.control.node != null)
- {
- nodes.push(state.control.node);
- }
- }
- }
-
- return nodes;
- };
-
- function fadeIn(nodes)
- {
- if (nodes != null)
- {
- for (var i = 0; i < nodes.length; i++)
- {
- mxUtils.setPrefixedStyle(nodes[i].style, 'transition', null);
- nodes[i].style.opacity = '0';
- }
-
- window.setTimeout(function()
- {
- for (var i = 0; i < nodes.length; i++)
- {
- mxUtils.setPrefixedStyle(nodes[i].style, 'transition', 'all 1s ease-in-out');
- nodes[i].style.opacity = '1';
- }
- }, 0);
- }
- };
-
- function fadeOut(nodes)
- {
- if (nodes != null)
- {
- for (var i = 0; i < nodes.length; i++)
- {
- mxUtils.setPrefixedStyle(nodes[i].style, 'transition', null);
- nodes[i].style.opacity = '1';
- }
-
- window.setTimeout(function()
- {
- for (var i = 0; i < nodes.length; i++)
- {
- mxUtils.setPrefixedStyle(nodes[i].style, 'transition', 'all 1s ease-in-out');
- nodes[i].style.opacity = '0';
- }
- }, 0);
- }
- };
-
- function createEdgeAnimation(state)
- {
- var pts = state.absolutePoints.slice();
- var segs = state.segments;
- var total = state.length;
- var n = pts.length;
- return {
- execute: function(step, steps)
- {
- if (state.shape != null)
- {
- var pts2 = [pts[0]];
- var dist = total * step / steps;
-
- for (var i = 1; i < n; i++)
- {
- if (dist <= segs[i - 1])
- {
- pts2.push(new mxPoint(pts[i - 1].x + (pts[i].x - pts[i - 1].x) * dist / segs[i - 1],
- pts[i - 1].y + (pts[i].y - pts[i - 1].y) * dist / segs[i - 1]));
-
- break;
- }
- else
- {
- dist -= segs[i - 1];
- pts2.push(pts[i]);
- }
- }
-
- state.shape.points = pts2;
- state.shape.redraw();
- }
- },
- stop: function()
- {
- if (state.shape != null)
- {
- state.shape.points = pts;
- state.shape.redraw();
- }
- }
- };
- };
-
- function createVertexAnimation(state)
- {
- var bds = new mxRectangle.fromRectangle(state.shape.bounds);
- var ttr = null;
-
- if (state.text != null && state.text.node != null && state.text.node.firstChild != null)
- {
- ttr = state.text.node.firstChild.getAttribute('transform');
- }
-
- return {
- execute: function(step, steps)
- {
- if (state.shape != null)
- {
- var f = step / steps;
- state.shape.bounds = new mxRectangle(bds.x, bds.y, bds.width * f, bds.height);
- state.shape.redraw();
-
- // Text is animated using CSS3 transitions
- if (ttr != null)
- {
- state.text.node.firstChild.setAttribute('transform', ttr + ' scale(' + f + ',1)');
- }
- }
- },
- stop: function()
- {
- if (state.shape != null)
- {
- state.shape.bounds = bds;
- state.shape.redraw();
-
- if (ttr != null)
- {
- state.text.node.firstChild.setAttribute('transform', ttr);
- }
- }
- }
- };
- };
- function animateCells(cells, steps, delay)
- {
- steps = (steps != null) ? steps : 30;
- delay = (delay != null) ? delay : 30;
-
- var animations = [];
-
- for (var i = 0; i < cells.length; i++)
- {
- var state = graph.view.getState(cells[i]);
- if (state != null && state.shape != null && graph.model.isEdge(state.cell) &&
- state.absolutePoints != null && state.absolutePoints.length > 1)
- {
- animations.push(createEdgeAnimation(state));
- }
- else if (state != null && graph.model.isVertex(state.cell) &&
- state.shape != null && state.shape.bounds != null)
- {
- animations.push(createVertexAnimation(state));
- // TODO: include descendants
- }
- }
-
- var step = 0;
-
- function animate()
- {
- if (step == steps)
- {
- window.clearInterval(thread);
-
- for (var i = 0; i < animations.length; i++)
- {
- animations[i].stop();
- }
- }
- else
- {
- for (var i = 0; i < animations.length; i++)
- {
- animations[i].execute(step, steps);
- }
-
- step++;
- }
- }
-
- var thread = window.setInterval(animate, delay);
- animate();
- };
-
- function mapCell(cell, clone, mapping)
- {
- mapping = (mapping != null) ? mapping : new Object();
- mapping[cell.id] = clone;
-
- var childCount = cell.getChildCount();
-
- for (var i = 0; i < childCount; i++)
- {
- mapCell(cell.getChildAt(i), clone.getChildAt(i), mapping);
- }
-
- return mapping;
- };
-
- var allowedToRun = false;
- var running = false;
-
- function stop()
- {
- allowedToRun = false;
- graph.getModel().clear();
- };
-
- function run()
- {
- if (!running)
- {
- allowedToRun = true;
- running = true;
-
- graph.getModel().clear();
- graph.getModel().setRoot(graph.cloneCells([editorUi.editor.graph.getModel().getRoot()])[0]);
- graph.maxFitScale = 1;
- graph.fit(8);
- graph.center();
-
- graph.getModel().beginUpdate();
- try
- {
- for (var id in graph.getModel().cells)
- {
- var cell = graph.getModel().cells[id];
-
- if (graph.getModel().isVertex(cell) || graph.getModel().isEdge(cell))
- {
- graph.setCellStyles('opacity', '0', [cell]);
- graph.setCellStyles('noLabel', '1', [cell]);
- }
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- var mapping = mapCell(editorUi.editor.graph.getModel().getRoot(), graph.getModel().getRoot());
- var steps = list.value.split('\n');
- var step = 0;
-
- function next()
- {
- if (allowedToRun && step < steps.length)
- {
- var tokens = steps[step].split(' ');
-
- if (tokens.length > 0)
- {
- if (tokens[0] == 'wait' && tokens.length > 1)
- {
- window.setTimeout(function()
- {
- step++;
- next();
- }, parseFloat(tokens[1]));
- }
- else
- {
- if (tokens.length > 1)
- {
- var cell = mapping[tokens[1]];
-
- if (cell != null)
- {
- if (tokens[0] == 'show')
- {
- graph.setCellStyles('opacity', '100', [cell]);
- graph.setCellStyles('noLabel', null, [cell]);
-
- if (tokens.length > 2 && tokens[2] == 'fade')
- {
- fadeIn(getNodesForCells([cell]));
- }
- else
- {
- animateCells([cell]);
- }
- }
- else if (tokens[0] == 'hide')
- {
- fadeOut(getNodesForCells([cell]));
- }
- }
- else
- {
- console.log('cell not found', id, steps[step]);
- }
- }
-
- step++;
- next();
- }
- }
- }
- else
- {
- running = false;
- }
- };
-
- next();
- }
- };
-
- var fadeInBtn = mxUtils.button('Fade In', function()
- {
- var cells = editorUi.editor.graph.getSelectionCells();
-
- if (cells.length > 0)
- {
- for (var i = 0; i < cells.length; i++)
- {
- list.value = list.value + 'show ' + cells[i].id + ' fade\n';
- }
-
- list.value = list.value + 'wait 1000\n';
- }
- });
- td21.appendChild(fadeInBtn);
-
- var animateBtn = mxUtils.button('Wipe In', function()
- {
- var cells = editorUi.editor.graph.getSelectionCells();
-
- if (cells.length > 0)
- {
- for (var i = 0; i < cells.length; i++)
- {
- list.value = list.value + 'show ' + cells[i].id + '\n';
- }
-
- list.value = list.value + 'wait 1000\n';
- }
- });
- td21.appendChild(animateBtn);
-
- var addBtn = mxUtils.button('Fade Out', function()
- {
- var cells = editorUi.editor.graph.getSelectionCells();
-
- if (cells.length > 0)
- {
- for (var i = 0; i < cells.length; i++)
- {
- list.value = list.value + 'hide ' + cells[i].id + '\n';
- }
- list.value = list.value + 'wait 1000\n';
- }
- });
- td21.appendChild(addBtn);
-
- var waitBtn = mxUtils.button('Wait', function()
- {
- list.value = list.value + 'wait 1000\n';
- });
- td21.appendChild(waitBtn);
-
- var runBtn = mxUtils.button('Preview', function()
- {
- run();
- });
- td21.appendChild(runBtn);
-
- var stopBtn = mxUtils.button('Stop', function()
- {
- stop();
- });
- td21.appendChild(stopBtn);
-
- var applyBtn = mxUtils.button('Apply', function()
- {
- editorUi.editor.graph.setAttributeForCell(root, 'animation', list.value);
- });
- td21.appendChild(applyBtn);
-
- var root = editorUi.editor.graph.getModel().getRoot();
-
- tr1.appendChild(td11);
- tr1.appendChild(td12);
- tbody.appendChild(tr1);
- tr2.appendChild(td21);
- tbody.appendChild(tr2);
- table.appendChild(tbody);
- this.window = new mxWindow('Animation', table, x, y, w, h, true, true);
- this.window.destroyOnClose = false;
- this.window.setMaximizable(false);
- this.window.setResizable(true);
- this.window.setClosable(true);
- this.window.setVisible(true);
- };
- /**
- * Constructs a new auth dialog.
- */
- var AuthDialog = function(editorUi, peer, showRememberOption, fn)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- var hd = document.createElement('p');
- hd.style.fontSize = '16pt';
- hd.style.padding = '0px';
- hd.style.margin = '0px';
- hd.style.color = 'gray';
-
- mxUtils.write(hd, mxResources.get('authorizationRequired'));
-
- var service = 'Unknown';
-
- var img = document.createElement('img');
- img.setAttribute('border', '0');
- img.setAttribute('align', 'absmiddle');
- img.style.marginRight = '10px';
- if (peer == editorUi.drive)
- {
- service = mxResources.get('googleDrive');
- img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
- }
- else if (peer == editorUi.dropbox)
- {
- service = mxResources.get('dropbox');
- img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
- }
- else if (peer == editorUi.oneDrive)
- {
- service = mxResources.get('oneDrive');
- img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
- }
-
- var p = document.createElement('p');
- mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
-
- var button = mxUtils.button(mxResources.get('authorize'), function()
- {
- editorUi.hideDialog(false);
- fn(cb.checked);
- });
- button.insertBefore(img, button.firstChild);
- button.style.marginTop = '6px';
- button.className = 'geBigButton';
- div.appendChild(hd);
- div.appendChild(p);
- div.appendChild(button);
-
- if (showRememberOption)
- {
- var p2 = document.createElement('p');
- p2.style.marginTop = '20px';
- p2.appendChild(cb);
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
- p2.appendChild(span);
- div.appendChild(p2);
- cb.checked = true;
- cb.defaultChecked = true;
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
- }
-
- this.container = div;
- };
- var MoreShapesDialog = function(editorUi, expanded, entries)
- {
- entries = (entries != null) ? entries : editorUi.sidebar.entries;
- var div = document.createElement('div');
- if (expanded)
- {
- var hd = document.createElement('div');
- hd.className = 'geDialogTitle';
- mxUtils.write(hd, mxResources.get('shapes'));
- hd.style.position = 'absolute';
- hd.style.top = '0px';
- hd.style.left = '0px';
- hd.style.lineHeight = '40px';
- hd.style.height = '40px';
- hd.style.right = '0px';
-
- if (mxClient.IS_QUIRKS)
- {
- hd.style.width = '718px';
- }
-
- var list = document.createElement('div');
- var preview = document.createElement('div');
-
- list.style.position = 'absolute';
- list.style.top = '40px';
- list.style.left = '0px';
- list.style.width = '202px';
- list.style.bottom = '60px';
- list.style.overflow = 'auto';
-
- if (mxClient.IS_QUIRKS)
- {
- list.style.height = '437px';
- list.style.marginTop = '1px';
- }
-
- preview.style.position = 'absolute';
- preview.style.left = '202px';
- preview.style.right = '0px';
- preview.style.top = '40px';
- preview.style.bottom = '60px';
- preview.style.overflow = 'auto';
- preview.style.borderLeft = '1px solid rgb(211, 211, 211)';
- preview.style.textAlign = 'center';
-
- if (mxClient.IS_QUIRKS)
- {
- preview.style.width = parseInt(hd.style.width) - 202 + 'px';
- preview.style.height = list.style.height;
- preview.style.marginTop = list.style.marginTop;
- }
-
- var currentListItem = null;
- var applyFunctions = [];
-
- var listEntry = document.createElement('div');
- listEntry.style.position = 'relative';
- listEntry.style.left = '0px';
- listEntry.style.right = '0px';
-
- for (var i = 0; i < entries.length; i++)
- {
- (function(section)
- {
- var title = listEntry.cloneNode(false);
- title.style.fontWeight = 'bold';
- title.style.backgroundColor = '#e5e5e5';
- title.style.padding = '6px 0px 6px 20px';
- mxUtils.write(title, section.title);
- list.appendChild(title);
-
- for (var j = 0; j < section.entries.length; j++)
- {
- (function(entry)
- {
- var option = listEntry.cloneNode(false);
- option.style.cursor = 'pointer';
- option.style.padding = '4px 0px 4px 20px';
-
- var checkbox = document.createElement('input');
- checkbox.setAttribute('type', 'checkbox');
- checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
- checkbox.defaultChecked = checkbox.checked;
- option.appendChild(checkbox);
- mxUtils.write(option, ' ' + entry.title);
-
- list.appendChild(option);
-
- var itemClicked = function(evt)
- {
- if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
- {
- if (entry.imageCallback != null)
- {
- entry.imageCallback(preview);
- }
- else if (entry.image != null)
- {
- preview.innerHTML = '<img border="0" src="' + entry.image + '"/>';
- }
- else
- {
- preview.innerHTML = '<br>';
- mxUtils.write(preview, mxResources.get('noPreview'));
- }
-
- if (currentListItem != null)
- {
- currentListItem.style.backgroundColor = '';
- }
-
- currentListItem = option;
- currentListItem.style.backgroundColor = '#ebf2f9';
-
- if (evt != null)
- {
- mxEvent.consume(evt);
- }
- }
- };
-
- mxEvent.addListener(option, 'click', itemClicked);
- mxEvent.addListener(option, 'dblclick', function(evt)
- {
- checkbox.checked = !checkbox.checked;
- mxEvent.consume(evt);
- });
-
- applyFunctions.push(function()
- {
- return (checkbox.checked) ? entry.id : null;
- });
-
- // Selects first entry
- if (i == 0 && j == 0)
- {
- itemClicked();
- }
- })(section.entries[j]);
- }
- })(entries[i]);
- }
- div.style.padding = '30px';
-
- div.appendChild(hd);
- div.appendChild(list);
- div.appendChild(preview);
-
- var buttons = document.createElement('div');
- buttons.className = 'geDialogFooter';
- buttons.style.position = 'absolute';
- buttons.style.paddingRight = '16px';
- buttons.style.color = 'gray';
- buttons.style.left = '0px';
- buttons.style.right = '0px';
- buttons.style.bottom = '0px';
- buttons.style.height = '60px';
- buttons.style.lineHeight = '52px';
-
- if (mxClient.IS_QUIRKS)
- {
- buttons.style.width = hd.style.width;
- buttons.style.paddingTop = '12px';
- }
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
-
- if (isLocalStorage || mxClient.IS_CHROMEAPP)
- {
- var span = document.createElement('span');
- span.style.paddingRight = '20px';
- span.appendChild(cb);
- mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
- cb.checked = true;
- cb.defaultChecked = true;
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- if (mxEvent.getSource(evt) != cb)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- }
- });
-
- if (mxClient.IS_QUIRKS)
- {
- span.style.position = 'relative';
- span.style.top = '-6px';
- }
- buttons.appendChild(span);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
- var libs = [];
-
- for (var i = 0; i < applyFunctions.length; i++)
- {
- var lib = applyFunctions[i].apply(this, arguments);
-
- if (lib != null)
- {
- libs.push(lib);
- }
- }
-
- editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
-
- div.appendChild(buttons);
- }
- else
- {
- var libFS = document.createElement('table');
- var tbody = document.createElement('tbody');
- div.style.height = '100%';
- div.style.overflow = 'auto';
- var row = document.createElement('tr');
- libFS.style.width = '100%';
-
- var leftDiv = document.createElement('td');
- var midDiv = document.createElement('td');
- var rightDiv = document.createElement('td');
-
- var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
- {
- var libCB = document.createElement('input');
- libCB.type = 'checkbox';
- libFS.appendChild(libCB);
-
- libCB.checked = editorUi.sidebar.isEntryVisible(key);
-
- var libSpan = document.createElement('span');
- mxUtils.write(libSpan, title);
-
- var label = document.createElement('div');
- label.style.display = 'block';
- label.appendChild(libCB);
- label.appendChild(libSpan);
-
- mxEvent.addListener(libSpan, 'click', function(evt)
- {
- libCB.checked = !libCB.checked;
- mxEvent.consume(evt);
- });
-
- wrapperDiv.appendChild(label);
-
- return function()
- {
- return (libCB.checked) ? key : null;
- };
- });
-
- row.appendChild(leftDiv);
- row.appendChild(midDiv);
- row.appendChild(rightDiv);
-
- tbody.appendChild(row);
- libFS.appendChild(tbody);
-
- var applyFunctions = [];
- var count = 0;
-
- // Counts total number of entries
- for (var i = 0; i < entries.length; i++)
- {
- for (var j = 0; j < entries[i].entries.length; j++)
- {
- count++;
- }
- }
-
- // Distributes entries on columns
- var cols = [leftDiv, midDiv, rightDiv];
- var counter = 0;
-
- for (var i = 0; i < entries.length; i++)
- {
- (function(section)
- {
- for (var j = 0; j < section.entries.length; j++)
- {
- (function(entry)
- {
- var index = Math.floor(counter / (count / 3));
- applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
- counter++;
- })(section.entries[j]);
- }
- })(entries[i]);
- }
- div.appendChild(libFS);
-
- var remember = document.createElement('div');
- remember.style.marginTop = '18px';
- remember.style.textAlign = 'center';
-
- var cb = document.createElement('input');
-
- if (isLocalStorage)
- {
- cb.setAttribute('type', 'checkbox');
- cb.checked = true;
- cb.defaultChecked = true;
- remember.appendChild(cb);
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
- remember.appendChild(span);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
- }
-
- div.appendChild(remember);
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- var libs = ['search'];
-
- for (var i = 0; i < applyFunctions.length; i++)
- {
- var lib = applyFunctions[i].apply(this, arguments);
-
- if (lib != null)
- {
- libs.push(lib);
- }
- }
-
- editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
- editorUi.hideDialog();
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- var buttons = document.createElement('div');
- buttons.style.marginTop = '26px';
- buttons.style.textAlign = 'right';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
-
- div.appendChild(buttons);
- }
- this.container = div;
- };
- var PluginsDialog = function(editorUi)
- {
- var div = document.createElement('div');
- var inner = document.createElement('div');
-
- inner.style.height = '120px';
- inner.style.overflow = 'auto';
- var plugins = mxSettings.getPlugins().slice();
-
- function refresh()
- {
- if (plugins.length == 0)
- {
- inner.innerHTML = mxResources.get('noPlugins');
- }
- else
- {
- inner.innerHTML = '';
-
- for (var i = 0; i < plugins.length; i++)
- {
- var span = document.createElement('span');
- span.style.whiteSpace = 'nowrap';
- var img = document.createElement('span');
- img.className = 'geSprite geSprite-delete';
- img.style.position = 'relative';
- img.style.cursor = 'pointer';
- img.style.top = '5px';
- img.style.marginRight = '4px';
- img.style.display = 'inline-block';
- span.appendChild(img);
-
- mxUtils.write(span, plugins[i]);
- inner.appendChild(span);
-
- mxUtils.br(inner);
-
- mxEvent.addListener(img, 'click', (function(index)
- {
- return function()
- {
- editorUi.confirm(window.parent.mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
- {
- plugins.splice(index, 1);
- refresh();
- });
- };
- })(i));
- }
- }
- }
-
- div.appendChild(inner);
- refresh();
- var addBtn = mxUtils.button(mxResources.get('add'), function()
- {
- var tmp = '';
- var param = urlParams['p'];
-
- if (param != null && param.length > 0)
- {
- var tokens = param.split(';');
-
- for (var i = 0; i < tokens.length; i++)
- {
- var url = App.pluginRegistry[tokens[i]];
-
- if (url != null)
- {
- tmp += url + ';';
- }
- }
-
- if (tmp.charAt(tmp.length - 1) == ';')
- {
- tmp = tmp.substring(0, tmp.length - 1);
- }
- }
-
- var dlg = new FilenameDialog(editorUi, tmp, mxResources.get('add'), function(newValue)
- {
- if (newValue != null && newValue.length > 0)
- {
- tokens = newValue.split(';');
-
- for (var i = 0; i < tokens.length; i++)
- {
- if (tokens[i].length > 0 && mxUtils.indexOf(plugins, tokens[i]) < 0)
- {
- plugins.push(tokens[i]);
- }
- }
-
- refresh();
- }
- }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
-
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- });
- addBtn.className = 'geBtn';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- mxSettings.setPlugins(plugins);
- mxSettings.save();
- editorUi.hideDialog();
- editorUi.alert(mxResources.get('restartForChangeRequired'));
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
- var buttons = document.createElement('div');
- buttons.style.marginTop = '14px';
- buttons.style.textAlign = 'right';
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(addBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(addBtn);
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- var EditGeometryDialog = function(editorUi, vertices)
- {
- var graph = editorUi.editor.graph;
- var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
- var div = document.createElement('div');
-
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- var row = document.createElement('tr');
- var left = document.createElement('td');
- var right = document.createElement('td');
- table.style.paddingLeft = '6px';
-
- mxUtils.write(left, mxResources.get('left') + ':');
-
- var xInput = document.createElement('input');
- xInput.setAttribute('type', 'text');
- xInput.style.width = '100px';
- xInput.value = (geo != null) ? geo.x : '';
-
- this.init = function()
- {
- xInput.focus();
- xInput.select();
- };
- right.appendChild(xInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('top') + ':');
-
- var yInput = document.createElement('input');
- yInput.setAttribute('type', 'text');
- yInput.style.width = '100px';
- yInput.value = (geo != null) ? geo.y : '';
- right.appendChild(yInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('width') + ':');
-
- var wInput = document.createElement('input');
- wInput.setAttribute('type', 'text');
- wInput.style.width = '100px';
- wInput.value = (geo != null) ? geo.width : '';
- right.appendChild(wInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('height') + ':');
-
- var hInput = document.createElement('input');
- hInput.setAttribute('type', 'text');
- hInput.style.width = '100px';
- hInput.value = (geo != null) ? geo.height : '';
- right.appendChild(hInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('rotation') + ':');
-
- var rotInput = document.createElement('input');
- rotInput.setAttribute('type', 'text');
- rotInput.style.width = '100px';
- rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
- mxConstants.STYLE_ROTATION, 0) : '';
- right.appendChild(rotInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- table.appendChild(tbody);
- div.appendChild(table);
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
-
- graph.getModel().beginUpdate();
- try
- {
- for (var i = 0; i < vertices.length; i++)
- {
- var g = graph.getCellGeometry(vertices[i]);
-
- if (g != null)
- {
- g = g.clone();
-
- if (graph.isCellMovable(vertices[i]))
- {
- if (mxUtils.trim(xInput.value).length > 0)
- {
- g.x = Number(xInput.value);
- }
-
- if (mxUtils.trim(yInput.value).length > 0)
- {
- g.y = Number(yInput.value);
- }
- }
-
- if (graph.isCellResizable(vertices[i]))
- {
- if (mxUtils.trim(wInput.value).length > 0)
- {
- g.width = Number(wInput.value);
- }
-
- if (mxUtils.trim(hInput.value).length > 0)
- {
- g.height = Number(hInput.value);
- }
- }
-
- graph.getModel().setGeometry(vertices[i], g);
- }
-
- if (mxUtils.trim(rotInput.value).length > 0)
- {
- graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
- }
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
- });
- mxEvent.addListener(div, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- applyBtn.click();
- }
- });
-
- var buttons = document.createElement('div');
- buttons.style.marginTop = '20px';
- buttons.style.textAlign = 'right';
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Constructs a new dialog for creating files from templates.
- */
- var LibraryDialog = function(editorUi, name, library, initialImages, file, mode)
- {
- var images = [];
- var graph = editorUi.editor.graph;
- var outer = document.createElement('div');
- outer.style.height = '100%';
-
- var header = document.createElement('div');
- header.style.whiteSpace = 'nowrap';
- header.style.height = '40px';
- outer.appendChild(header);
- mxUtils.write(header, mxResources.get('filename') + ':');
-
- var nameValue = name;
-
- if (nameValue == null)
- {
- nameValue = editorUi.defaultLibraryName + '.xml';
- }
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', nameValue);
- nameInput.style.marginRight = '20px';
- nameInput.style.marginLeft = '10px';
- nameInput.style.width = '500px';
-
- if (file != null && !file.isRenamable())
- {
- nameInput.setAttribute('disabled', 'true');
- }
-
- this.init = function()
- {
- if (file == null || file.isRenamable())
- {
- nameInput.focus();
-
- if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
- {
- nameInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- };
- header.appendChild(nameInput);
- var div = document.createElement('div');
- div.style.borderWidth = '1px 0px 1px 0px';
- div.style.borderColor = '#d3d3d3';
- div.style.borderStyle = 'solid';
- div.style.marginTop = '6px';
- div.style.overflow = 'auto';
- div.style.height = '340px';
- div.style.backgroundPosition = 'center center';
- div.style.backgroundRepeat = 'no-repeat';
- if (images.length == 0 && Graph.fileSupport)
- {
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- }
- var bg = document.createElement('div');
- bg.style.position = 'absolute';
- bg.style.width = '640px';
- bg.style.top = '260px';
- bg.style.textAlign = 'center';
- bg.style.fontSize = '22px';
- bg.style.color = '#a0c3ff';
- mxUtils.write(bg, mxResources.get('dragImagesHere'));
- outer.appendChild(bg);
-
- var entries = {};
- var ew = 100;
- var eh = 100;
-
- var dragSourceIndex = null;
- var dropTargetIndex = null;
-
- function getIndexForEvent(evt)
- {
- var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
-
- while (dropTarget != null && dropTarget.parentNode != div)
- {
- dropTarget = dropTarget.parentNode;
- }
-
- var result = null;
-
- if (dropTarget != null)
- {
- var tmp = div.firstChild;
- result = 0;
-
- while (tmp != null && tmp != dropTarget)
- {
- tmp = tmp.nextSibling;
- result++;
- }
- }
-
- return result;
- };
-
- var stopEditing = null;
- var stopWrapper = function(evt)
- {
- var source = mxEvent.getSource(evt);
-
- if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
-
- mxEvent.consume(evt);
- }
- };
-
- mxEvent.addListener(div, 'mousedown', stopWrapper);
- mxEvent.addListener(div, 'pointerdown', stopWrapper);
- mxEvent.addListener(div, 'touchstart', stopWrapper);
- // For converting image URLs
- var converter = new mxUrlConverter();
-
- function addButton(data, mimeType, x, y, w, h, img, aspect, title)
- {
- // Ignores duplicates
- try
- {
- if (mimeType == null || mimeType.substring(0, 6) == 'image/')
- {
- if ((data == null && img != null) || entries[data] == null)
- {
- div.style.backgroundImage = '';
- bg.style.display = 'none';
-
- var iw = w;
- var ih = h;
-
- if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
- {
- var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
- editorUi.maxImageSize / Math.max(1, h));
- w *= s;
- h *= s;
- }
-
- if (iw > ih)
- {
- ih = Math.round(ih * ew / iw);
- iw = ew;
- }
- else
- {
- iw = Math.round(iw * eh / ih);
- ih = eh;
- }
-
- var wrapper = document.createElement('div');
- wrapper.setAttribute('draggable', 'true');
- wrapper.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
- wrapper.style.position = 'relative';
- wrapper.style.cursor = 'move';
- mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
-
- if (data != null)
- {
- var elt = document.createElement('img');
- elt.setAttribute('src', converter.convert(data));
- elt.style.width = iw + 'px';
- elt.style.height = ih + 'px';
- elt.style.margin = '10px';
-
- elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
- elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
-
- wrapper.appendChild(elt);
- }
- else if (img != null)
- {
- var cells = editorUi.stringToCells(editorUi.editor.graph.decompress(img.xml));
-
- if (cells.length > 0)
- {
- editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null, true, false);
-
- // Needs inline block on SVG for delete icon to appear on same line
- wrapper.firstChild.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
- wrapper.firstChild.style.cursor = '';
- }
- }
-
- var rem = document.createElement('img');
- rem.setAttribute('src', Editor.closeImage);
- rem.setAttribute('border', '0');
- rem.setAttribute('title', mxResources.get('delete'));
- rem.setAttribute('align', 'top');
- rem.style.paddingTop = '4px';
- rem.style.marginLeft = '-22px';
- rem.style.cursor = 'pointer';
-
- // Blocks dragging of remove icon
- mxEvent.addListener(rem, 'dragstart', function(evt)
- {
- mxEvent.consume(evt);
- });
-
- // Seems to bring remove icon on top of graph
- if (data == null && img != null)
- {
- rem.style.position = 'relative';
- }
-
- (function(wrapperDiv, dataParam)
- {
- mxEvent.addListener(rem, 'click', function(evt)
- {
- entries[data] = null;
-
- for (var i = 0; i < images.length; i++)
- {
- if ((data != null && images[i].data == dataParam) ||
- (img != null && images[i].xml == img.xml))
- {
- images.splice(i, 1);
- break;
- }
- }
-
- wrapper.parentNode.removeChild(wrapperDiv);
-
- if (images.length == 0)
- {
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- bg.style.display = '';
- }
-
- mxEvent.consume(evt);
- });
- // Workaround for accidental select all
- mxEvent.addListener(rem, 'dblclick', function(evt)
- {
- mxEvent.consume(evt);
- });
- })(wrapper, data, img);
-
- wrapper.appendChild(rem);
- wrapper.style.marginBottom = '30px';
-
- var label = document.createElement('div');
- label.style.position = 'absolute';
- label.style.boxSizing = 'border-box';
- label.style.bottom = '-18px';
- label.style.left = '10px';
- label.style.right = '10px';
- label.style.backgroundColor = '#ffffff';
- label.style.overflow = 'hidden';
- label.style.textAlign = 'center';
-
- var entry = null;
-
- if (data != null)
- {
- entry = {data: data, w: w, h: h, title: title};
-
- if (aspect != null)
- {
- entry.aspect = aspect;
- }
-
- entries[data] = elt;
- images.push(entry);
- }
- else if (img != null)
- {
- img.aspect = 'fixed';
- images.push(img);
- entry = img;
- }
-
- function updateLabel()
- {
- label.innerHTML = '';
- label.style.cursor = 'pointer';
- label.style.whiteSpace = 'nowrap';
- label.style.textOverflow = 'ellipsis';
- mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
- entry.title : mxResources.get('untitled'));
-
- if (entry.title == null || entry.title.length == 0)
- {
- label.style.color = '#d0d0d0';
- }
- else
- {
- label.style.color = '';
- }
- };
-
- mxEvent.addListener(label, 'keydown', function(evt)
- {
- if (evt.keyCode == 13 && stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
-
- mxEvent.consume(evt);
- }
- });
-
- updateLabel();
- wrapper.appendChild(label);
-
- // Blocks dragging of label
- mxEvent.addListener(label, 'mousedown', function(evt)
- {
- mxEvent.consume(evt);
- });
-
- var startEditing = function(evt)
- {
- // Workaround for various issues in IE
- if (!mxClient.IS_IOS && !mxClient.IS_QUIRKS && !mxClient.IS_FF &&
- (document.documentMode == null || document.documentMode > 9))
- {
- if (label.getAttribute('contentEditable') != 'true')
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- if (entry.title == null || entry.title.length == 0)
- {
- label.innerHTML = '';
- }
-
- label.style.textOverflow = '';
- label.style.whiteSpace = '';
- label.style.cursor = 'text';
- label.style.color = '';
- label.setAttribute('contentEditable', 'true');
- label.focus();
- document.execCommand('selectAll', false, null);
-
- stopEditing = function()
- {
- label.removeAttribute('contentEditable');
- label.style.cursor = 'pointer';
- entry.title = label.innerHTML;
- updateLabel();
- }
- }
- }
- else
- {
- var dlg = new FilenameDialog(editorUi, entry.title || '', mxResources.get('ok'), function(newTitle)
- {
- if (newTitle != null)
- {
- entry.title = newTitle;
- updateLabel();
- }
- }, mxResources.get('enterValue'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- }
-
- mxEvent.consume(evt);
- };
-
- mxEvent.addListener(label, 'click', startEditing);
- mxEvent.addListener(wrapper, 'dblclick', startEditing);
-
- div.appendChild(wrapper);
-
- mxEvent.addListener(wrapper, 'dragstart', function(evt)
- {
- if (data == null && img != null)
- {
- rem.style.visibility = 'hidden';
- label.style.visibility = 'hidden';
- }
-
- // Workaround for no DnD on DIV in FF
- if (mxClient.IS_FF && img.xml != null)
- {
- evt.dataTransfer.setData('Text', img.xml);
- }
- dragSourceIndex = getIndexForEvent(evt);
-
- // Workaround for missing drag preview in Google Chrome
- if (mxClient.IS_GC)
- {
- wrapper.style.opacity = '0.9';
- }
-
- window.setTimeout(function()
- {
- mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
- mxUtils.setOpacity(wrapper, 30);
- rem.style.visibility = '';
- label.style.visibility = '';
- }, 0);
- });
-
- mxEvent.addListener(wrapper, 'dragend', function(evt)
- {
- if (rem.style.visibility == 'hidden')
- {
- rem.style.visibility = '';
- label.style.visibility = '';
- }
-
- dragSourceIndex = null;
- mxUtils.setOpacity(wrapper, 100);
- mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
- });
- }
- else
- {
- //editorUi.spinner.stop();
- editorUi.handleError({message: mxResources.get('fileExists')})
- }
- }
- else
- {
- var done = false;
-
- try
- {
- if (data != null && data.substring(0, 10) == '<mxlibrary')
- {
- var doc = mxUtils.parseXml(data);
- var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
-
- if (temp != null && temp.length > 0)
- {
- for (var i = 0; i < temp.length; i++)
- {
- if (temp[i].xml != null)
- {
- addButton(null, null, 0, 0, 0, 0, temp[i]);
- }
- else
- {
- addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
- }
- }
- }
-
- editorUi.spinner.stop();
- done = true;
- }
- }
- catch (e)
- {
- // ignore
- }
- if (!done)
- {
- editorUi.spinner.stop();
- editorUi.handleError({message: mxResources.get('errorLoadingFile')})
- }
- }
- }
- catch (e)
- {
- // ignore
- console.log('e', e);
- }
-
- return null;
- };
-
- if (initialImages != null)
- {
- for (var i = 0; i < initialImages.length; i++)
- {
- var img = initialImages[i];
- addButton(img.data, null, 0, 0, img.w, img.h, img);
- }
- }
-
- // Setup the dnd listeners
- mxEvent.addListener(div, 'dragleave', function(evt)
- {
- bg.style.cursor = '';
- var source = mxEvent.getSource(evt);
-
- while (source != null)
- {
- if (source == div || source == bg)
- {
- evt.stopPropagation();
- evt.preventDefault();
- break;
- }
-
- source = source.parentNode;
- }
- });
-
- function dragOver(evt)
- {
- evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
- evt.stopPropagation();
- evt.preventDefault();
- };
-
- function dropHandler(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
-
- dropTargetIndex = getIndexForEvent(evt);
-
- if (dragSourceIndex != null)
- {
- if (dropTargetIndex != null && dropTargetIndex < div.children.length)
- {
- images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
- 0, images.splice(dragSourceIndex, 1)[0]);
- div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
- }
- else
- {
- images.push(images.splice(dragSourceIndex, 1)[0]);
- div.appendChild(div.children[dragSourceIndex]);
- }
- }
- else if (evt.dataTransfer.files.length > 0)
- {
- editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img)
- {
- addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ? null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
- });
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
-
- if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
- /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
- {
- editorUi.loadImage(uri, function(img)
- {
- addButton(uri, null, 0, 0, img.width, img.height);
- });
- }
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- };
-
- mxEvent.addListener(div, 'dragover', dragOver);
- mxEvent.addListener(div, 'drop', dropHandler);
- mxEvent.addListener(bg, 'dragover', dragOver);
- mxEvent.addListener(bg, 'drop', dropHandler);
- outer.appendChild(div);
- var btns = document.createElement('div');
- btns.style.textAlign = 'right';
- btns.style.marginTop = '20px';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog(true);
- });
- cancelBtn.setAttribute('id', 'btnCancel');
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- // Does not show download button, allow filename editing in Chrome Apps
- if (!window.chrome || !chrome.app || !chrome.app.runtime)
- {
- var btn = mxUtils.button(mxResources.get('export'), function()
- {
- var data = editorUi.createLibraryDataFromImages(images);
- var filename = nameInput.value;
-
- if (!/(\.xml)$/i.test(filename))
- {
- filename += '.xml';
- }
-
- if (editorUi.isLocalFileSave())
- {
- editorUi.saveLocalFile(data, filename, 'text/xml');
- }
- else
- {
- new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
- '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
- }
- });
- btn.setAttribute('id', 'btnDownload');
- btn.className = 'geBtn';
- btns.appendChild(btn);
- }
- else
- {
- nameInput.setAttribute('disabled', 'disabled');
- }
-
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- if (document.documentMode == null)
- {
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img)
- {
- addButton(data, mimeType, x, y, w, h, img, 'fixed');
-
- // Resets input to force change event for same file
- fileInput.value = '';
- });
- });
-
- var btn = mxUtils.button(mxResources.get('import'), function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- fileInput.click();
- });
- btn.setAttribute('id', 'btnAddImage');
- btn.className = 'geBtn';
-
- btns.appendChild(btn);
- }
- var btn = mxUtils.button(mxResources.get('addImageUrl'), function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
- {
- if (url != null)
- {
- // Image dialog returns modified data URLs which
- // must be converted back to real data URL
- if (url.substring(0, 11) == 'data:image/')
- {
- var comma = url.indexOf(',');
-
- if (comma > 0)
- {
- url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
- }
- }
-
- addButton(url, null, 0, 0, w, h);
- }
- });
- });
- btn.setAttribute('id', 'btnAddImageUrl');
- btn.className = 'geBtn';
- btns.appendChild(btn);
-
- // Indirection for overriding
- this.saveBtnClickHandler = function(name, images, file, mode)
- {
- editorUi.saveLibrary(name, images, file, mode);
- };
- var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- this.saveBtnClickHandler(nameInput.value, images, file, mode);
- }));
- btn.setAttribute('id', 'btnSave');
- btn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(btn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- outer.appendChild(btns);
-
- this.container = outer;
- };
- /**
- * Constructs a new textarea dialog.
- */
- var EditShapeDialog = function(editorUi, cell, title, w, h)
- {
- w = (w != null) ? w : 300;
- h = (h != null) ? h : 120;
- var row, td;
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- table.style.cellPadding = '4px';
-
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.setAttribute('colspan', '2');
- td.style.fontSize = '10pt';
- mxUtils.write(td, title);
-
- row.appendChild(td);
- tbody.appendChild(row);
- row = document.createElement('tr');
- td = document.createElement('td');
-
- var nameInput = document.createElement('textarea');
- nameInput.style.outline = 'none';
- nameInput.style.resize = 'none';
- nameInput.style.width = (w - 200) + 'px';
- nameInput.style.height = h + 'px';
-
- this.textarea = nameInput;
- this.init = function()
- {
- nameInput.focus();
- nameInput.scrollTop = 0;
- };
- td.appendChild(nameInput);
- row.appendChild(td);
-
- td = document.createElement('td');
-
- var container = document.createElement('div');
- container.style.position = 'relative';
- container.style.border = '1px solid gray';
- container.style.top = '6px';
- container.style.width = '200px';
- container.style.height = (h + 4) + 'px';
- container.style.overflow = 'hidden';
- container.style.marginBottom = '16px';
- mxEvent.disableContextMenu(container);
- td.appendChild(container);
- var graph = new Graph(container);
- graph.setEnabled(false);
-
- var clone = editorUi.editor.graph.cloneCells([cell])[0];
- graph.addCells([clone]);
-
- var state = graph.view.getState(clone);
- var stencil = '';
-
- if (state.shape != null && state.shape.stencil != null)
- {
- stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
- }
-
- mxUtils.write(nameInput, stencil || '');
- var b = graph.getGraphBounds();
- var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
- graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
-
- row.appendChild(td);
- tbody.appendChild(row);
- row = document.createElement('tr');
- td = document.createElement('td');
- td.setAttribute('colspan', '2');
- td.style.paddingTop = '2px';
- td.style.whiteSpace = 'nowrap';
- td.setAttribute('align', 'right');
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
-
- if (!editorUi.isOffline())
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open('https://support.draw.io/display/DO/Editing+Shapes');
- });
-
- helpBtn.className = 'geBtn';
- td.appendChild(helpBtn);
- }
-
- var updateShape = function(targetGraph, targetCell, hide)
- {
- var newValue = nameInput.value;
-
- // Checks if XML has changed (getPrettyXml "normalizes" DOM)
- var doc = mxUtils.parseXml(newValue);
- newValue = mxUtils.getPrettyXml(doc.documentElement);
-
- // Checks for validation errors
- // LATER: Validate against XSD
- var errors = doc.documentElement.getElementsByTagName('parsererror');
-
- if (errors != null && errors.length > 0)
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
- }
- else
- {
- if (hide)
- {
- editorUi.hideDialog();
- }
-
- var isNew = !targetGraph.model.contains(targetCell);
-
- if (!hide || isNew || newValue != stencil)
- {
- // Transform XML value to be used in cell style
- newValue = editorUi.editor.graph.compress(newValue);
-
- targetGraph.getModel().beginUpdate();
- try
- {
- // Inserts cell if required
- if (isNew)
- {
- var pt = editorUi.editor.graph.getInsertPoint();
- targetCell.geometry.x = pt.x;
- targetCell.geometry.y = pt.y;
- targetGraph.addCell(targetCell)
- }
-
- targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
- }
- catch (e)
- {
- throw e;
- }
- finally
- {
- // Updates the display
- targetGraph.getModel().endUpdate();
- }
-
- // Updates selection after stencil was created for rendering
- if (isNew)
- {
- targetGraph.setSelectionCell(targetCell);
- }
- }
- }
- };
-
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- updateShape(graph, clone, false);
- });
-
- previewBtn.className = 'geBtn';
- td.appendChild(previewBtn);
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- updateShape(editorUi.editor.graph, cell, true);
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
- td.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- row.appendChild(td);
- tbody.appendChild(row);
- table.appendChild(tbody);
- this.container = table;
- };
- var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink)
- {
- var div = document.createElement('div');
- div.appendChild(content);
-
- var btns = document.createElement('div');
- btns.style.marginTop = '16px';
- btns.style.textAlign = 'center';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
-
- if (cancelFn != null)
- {
- cancelFn();
- }
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- if (!editorUi.isOffline() && helpLink != null)
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- window.open(helpLink);
- });
-
- helpBtn.className = 'geBtn';
- btns.appendChild(helpBtn);
- }
-
- var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), function()
- {
- editorUi.hideDialog();
-
- if (okFn != null)
- {
- okFn();
- }
- });
- btns.appendChild(okBtn);
-
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
|