Dialogs.js 210 KB

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