EditorUi.js 252 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Version
  9. */
  10. EditorUi.VERSION = '@DRAWIO-VERSION@';
  11. /**
  12. * Overrides compact UI setting.
  13. */
  14. EditorUi.compactUi = uiTheme != 'atlas';
  15. /**
  16. * Switch to disable logging for mode and search terms.
  17. */
  18. EditorUi.enableLogging = /.*\.draw\.io$/.test(window.location.hostname);
  19. /**
  20. * https://github.com/electron/electron/issues/2288
  21. */
  22. EditorUi.isElectronApp = window != null && window.process != null &&
  23. window.process.versions != null && window.process.versions['electron'] != null;
  24. /**
  25. * Contains the default XML for an empty diagram.
  26. */
  27. EditorUi.prototype.emptyDiagramXml = '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>';
  28. /**
  29. *
  30. */
  31. EditorUi.prototype.emptyLibraryXml = '<mxlibrary>[]</mxlibrary>';
  32. /**
  33. * Sets the delay for autosave in milliseconds. Default is 2000.
  34. */
  35. EditorUi.prototype.mode = null;
  36. /**
  37. * Allows for two buttons in the sidebar footer.
  38. */
  39. EditorUi.prototype.sidebarFooterHeight = 36;
  40. /**
  41. * Specifies the default custom shape style.
  42. */
  43. EditorUi.prototype.defaultCustomShapeStyle = 'shape=stencil(tZRtTsQgEEBPw1+DJR7AoN6DbWftpAgE0Ortd/jYRGq72R+YNE2YgTePloEJGWblgA18ZuKFDcMj5/Sm8boZq+BgjCX4pTyqk6ZlKROitwusOMXKQDODx5iy4pXxZ5qTHiFHawxB0JrQZH7lCabQ0Fr+XWC1/E8zcsT/gAi+Subo2/3Mh6d/oJb5nU1b5tW7r2knautaa3T+U32o7f7vZwpJkaNDLORJjcu7t59m2jXxqX9un+tt022acsfmoKaQZ+vhhswZtS6Ne/ThQGt0IV0N3Yyv6P3CeT9/tHO0XFI5cAE=);whiteSpace=wrap;html=1;';
  44. /**
  45. * Defines the maximum size for images.
  46. */
  47. EditorUi.prototype.maxBackgroundSize = 1600;
  48. /**
  49. * Defines the maximum size for images.
  50. */
  51. EditorUi.prototype.maxImageSize = 520;
  52. /**
  53. * Images above 100K should be resampled.
  54. */
  55. EditorUi.prototype.resampleThreshold = 100000;
  56. /**
  57. * Maximum allowed size for images is 1 MB.
  58. */
  59. EditorUi.prototype.maxImageBytes = 1000000;
  60. /**
  61. * Maximum size for background images is 2.5 MB.
  62. */
  63. EditorUi.prototype.maxBackgroundBytes = 2500000;
  64. /**
  65. * Holds the current file.
  66. */
  67. EditorUi.prototype.currentFile = null;
  68. /**
  69. * Specifies if PDF export should be done via print dialog. Default is
  70. * false which uses the PhantomJS backend to create the PDF.
  71. */
  72. EditorUi.prototype.printPdfExport = false;
  73. /**
  74. * Specifies if PDF export with pages is enabled.
  75. */
  76. EditorUi.prototype.pdfPageExport = true;
  77. /**
  78. * Restores app defaults for UI
  79. */
  80. EditorUi.prototype.formatEnabled = urlParams['format'] != '0';
  81. /**
  82. * Capability check for canvas export
  83. */
  84. (function()
  85. {
  86. EditorUi.prototype.useCanvasForExport = false;
  87. EditorUi.prototype.jpgSupported = false;
  88. try
  89. {
  90. var canvas = document.createElement('canvas');
  91. var img = new Image();
  92. // LATER: Capability check should not be async
  93. img.onload = function()
  94. {
  95. try
  96. {
  97. var ctx = canvas.getContext('2d');
  98. ctx.drawImage(img, 0, 0);
  99. // Works in Chrome, Firefox, Edge and Opera
  100. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  101. var result = canvas.toDataURL('image/png');
  102. EditorUi.prototype.useCanvasForExport = result != null && result.length > 6;
  103. }
  104. catch (e)
  105. {
  106. // ignore
  107. }
  108. };
  109. // Checks if SVG with foreignObject can be exported
  110. var svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1px" height="1px" version="1.1"><foreignObject pointer-events="all" width="1" height="1"><div xmlns="http://www.w3.org/1999/xhtml"></div></foreignObject></svg>';
  111. img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  112. }
  113. catch (e)
  114. {
  115. // ignore
  116. }
  117. // Checks for client-side JPG support
  118. try
  119. {
  120. var canvas = document.createElement('canvas');
  121. canvas.width = canvas.height = 1;
  122. var uri = canvas.toDataURL('image/jpeg');
  123. EditorUi.prototype.jpgSupported = (uri.match('image/jpeg') !== null);
  124. }
  125. catch (e)
  126. {
  127. // ignore
  128. }
  129. })();
  130. /**
  131. * Abstraction for local storage access.
  132. */
  133. EditorUi.prototype.getLocalData = function(key, fn)
  134. {
  135. fn(localStorage.getItem(key));
  136. };
  137. /**
  138. * Abstraction for local storage access.
  139. */
  140. EditorUi.prototype.setLocalData = function(key, data, fn)
  141. {
  142. localStorage.setItem(key, data);
  143. fn();
  144. };
  145. /**
  146. * Abstraction for local storage access.
  147. */
  148. EditorUi.prototype.removeLocalData = function(key, fn)
  149. {
  150. localStorage.removeItem(key)
  151. fn();
  152. };
  153. EditorUi.prototype.setMathEnabled = function(value)
  154. {
  155. this.editor.graph.mathEnabled = value;
  156. this.editor.updateGraphComponents();
  157. this.editor.graph.refresh();
  158. this.fireEvent(new mxEventObject('mathEnabledChanged'));
  159. };
  160. EditorUi.prototype.isMathEnabled = function(value)
  161. {
  162. return this.editor.graph.mathEnabled;
  163. };
  164. // Helper method to move picket to top
  165. EditorUi.prototype.movePickersToTop = function()
  166. {
  167. var divs = document.getElementsByTagName('div');
  168. for (var i = 0; i < divs.length; i++)
  169. {
  170. if (divs[i].className == 'picker modal-dialog picker-dialog')
  171. {
  172. divs[i].style.zIndex = mxPopupMenu.prototype.zIndex + 1;
  173. }
  174. }
  175. };
  176. /**
  177. * Translates this point by the given vector.
  178. *
  179. * @param {number} dx X-coordinate of the translation.
  180. * @param {number} dy Y-coordinate of the translation.
  181. */
  182. EditorUi.prototype.isOfflineApp = function()
  183. {
  184. return (urlParams['offline'] == '1');
  185. };
  186. /**
  187. * Returns true if this offline app is offline.
  188. */
  189. EditorUi.prototype.isOffline = function()
  190. {
  191. return this.isOfflineApp() || !navigator.onLine || urlParams['stealth'] == '1';
  192. };
  193. /**
  194. * Translates this point by the given vector.
  195. *
  196. * @param {number} dx X-coordinate of the translation.
  197. * @param {number} dy Y-coordinate of the translation.
  198. */
  199. EditorUi.prototype.createSpinner = function(x, y, size)
  200. {
  201. size = (size != null) ? size : 24;
  202. var spinner = new Spinner({
  203. lines: 12, // The number of lines to draw
  204. length: size, // The length of each line
  205. width: Math.round(size / 3), // The line thickness
  206. radius: Math.round(size / 2), // The radius of the inner circle
  207. rotate: 0, // The rotation offset
  208. color: '#000', // #rgb or #rrggbb
  209. speed: 1.5, // Rounds per second
  210. trail: 60, // Afterglow percentage
  211. shadow: false, // Whether to render a shadow
  212. hwaccel: false, // Whether to use hardware acceleration
  213. zIndex: 2e9 // The z-index (defaults to 2000000000)
  214. });
  215. // Extends spin method to include an optional label
  216. var oldSpin = spinner.spin;
  217. spinner.spin = function(container, label)
  218. {
  219. var result = false;
  220. if (!this.active)
  221. {
  222. oldSpin.call(this, container);
  223. this.active = true;
  224. if (label != null)
  225. {
  226. var status = document.createElement('div');
  227. status.style.position = 'absolute';
  228. status.style.whiteSpace = 'nowrap';
  229. status.style.background = '#4B4243';
  230. status.style.color = 'white';
  231. status.style.fontFamily = 'Helvetica, Arial';
  232. status.style.fontSize = '9pt';
  233. status.style.padding = '6px';
  234. status.style.paddingLeft = '10px';
  235. status.style.paddingRight = '10px';
  236. status.style.zIndex = 2e9;
  237. status.style.left = Math.max(0, x) + 'px';
  238. status.style.top = Math.max(0, y + 70) + 'px';
  239. mxUtils.setPrefixedStyle(status.style, 'borderRadius', '6px');
  240. mxUtils.setPrefixedStyle(status.style, 'boxShadow', '2px 2px 3px 0px #ddd');
  241. mxUtils.setPrefixedStyle(status.style, 'transform', 'translate(-50%,-50%)');
  242. status.innerHTML = label + '...';
  243. container.appendChild(status);
  244. spinner.status = status;
  245. // Centers the label in older IE versions
  246. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode <= 8))
  247. {
  248. status.style.left = Math.round(Math.max(0, x - status.offsetWidth / 2)) + 'px';
  249. status.style.top = Math.round(Math.max(0, y + 70 - status.offsetHeight / 2)) + 'px';
  250. }
  251. }
  252. // Pause returns a function to resume the spinner
  253. this.pause = mxUtils.bind(this, function()
  254. {
  255. var fn = function() { };
  256. if (this.active)
  257. {
  258. fn = mxUtils.bind(this, function()
  259. {
  260. this.spin(container, label);
  261. });
  262. }
  263. this.stop();
  264. return fn;
  265. });
  266. result = true;
  267. }
  268. return result;
  269. };
  270. // Extends stop method to remove the optional label
  271. var oldStop = spinner.stop;
  272. spinner.stop = function()
  273. {
  274. oldStop.call(this);
  275. this.active = false;
  276. if (spinner.status != null)
  277. {
  278. spinner.status.parentNode.removeChild(spinner.status);
  279. spinner.status = null;
  280. }
  281. };
  282. spinner.pause = function()
  283. {
  284. return function() {};
  285. };
  286. return spinner;
  287. };
  288. /**
  289. * Static method for pasing PNG files.
  290. */
  291. EditorUi.parsePng = function(f, fn, error)
  292. {
  293. var pos = 0;
  294. function fread(d, count)
  295. {
  296. var start = pos;
  297. pos += count;
  298. return d.substring(start, pos);
  299. };
  300. // Reads unsigned long 32 bit big endian
  301. function _freadint(d)
  302. {
  303. var bytes = fread(d, 4);
  304. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  305. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  306. };
  307. // Checks signature
  308. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  309. {
  310. if (error != null)
  311. {
  312. error();
  313. }
  314. return;
  315. }
  316. // Reads header chunk
  317. fread(f,4);
  318. if (fread(f,4) != 'IHDR')
  319. {
  320. if (error != null)
  321. {
  322. error();
  323. }
  324. return;
  325. }
  326. fread(f, 17);
  327. do
  328. {
  329. var n = _freadint(f);
  330. var type = fread(f,4);
  331. if (fn != null)
  332. {
  333. if (fn(pos - 8, type, n))
  334. {
  335. break;
  336. }
  337. }
  338. value = fread(f,n);
  339. fread(f,4);
  340. if (type == 'IEND')
  341. {
  342. break;
  343. }
  344. }
  345. while (n);
  346. };
  347. /**
  348. * Returns true if the given string contains a compatible graph model.
  349. */
  350. EditorUi.prototype.isCompatibleString = function(data)
  351. {
  352. try
  353. {
  354. var doc = mxUtils.parseXml(data);
  355. var node = this.editor.extractGraphModel(doc.documentElement, true);
  356. return node != null && node.getElementsByTagName('parsererror').length == 0;
  357. }
  358. catch (e)
  359. {
  360. // ignore
  361. }
  362. return false;
  363. };
  364. /**
  365. * Extracts the mxfile from the given HTML data from a data transfer event.
  366. */
  367. var editorUiExtractGraphModelFromHtml = EditorUi.prototype.extractGraphModelFromHtml;
  368. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  369. {
  370. var result = editorUiExtractGraphModelFromHtml.apply(this, arguments);
  371. if (result == null)
  372. {
  373. try
  374. {
  375. var idx = data.indexOf('&lt;mxfile ');
  376. if (idx >= 0)
  377. {
  378. var idx2 = data.lastIndexOf('&lt;/mxfile&gt;');
  379. if (idx2 > idx)
  380. {
  381. result = data.substring(idx, idx2 + 15).replace(/&gt;/g, '>').
  382. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  383. }
  384. }
  385. else
  386. {
  387. // Gets compressed data from mxgraph element in HTML document
  388. var doc = mxUtils.parseXml(data);
  389. var node = this.editor.extractGraphModel(doc.documentElement, this.pages != null);
  390. result = (node != null) ? mxUtils.getXml(node) : '';
  391. }
  392. }
  393. catch (e)
  394. {
  395. // ignore
  396. }
  397. }
  398. return result;
  399. };
  400. /**
  401. * Workaround for malformed xhtml meta element bug 07.08.16. The trailing slash was missing causing
  402. * reopen to fail trying to parse. Used in replaceFileData, setFileData and importFile.
  403. */
  404. EditorUi.prototype.validateFileData = function(data)
  405. {
  406. if (data != null && data.length > 0)
  407. {
  408. var index = data.indexOf('<meta charset="utf-8">');
  409. if (index >= 0)
  410. {
  411. var replaceString = '<meta charset="utf-8"/>';
  412. var replaceStrLen = replaceString.length;
  413. data = data.slice(0, index) + replaceString + data.slice(index + replaceStrLen - 1, data.length);
  414. }
  415. }
  416. return data;
  417. };
  418. /**
  419. *
  420. */
  421. EditorUi.prototype.replaceFileData = function(data)
  422. {
  423. data = this.validateFileData(data);
  424. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  425. // Some nodes must be extracted here to find the mxfile node
  426. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  427. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  428. if (tmp != null)
  429. {
  430. node = tmp;
  431. }
  432. if (node != null)
  433. {
  434. var graph = this.editor.graph;
  435. graph.model.beginUpdate();
  436. try
  437. {
  438. var oldPages = (this.pages != null) ? this.pages.slice() : null;
  439. var nodes = node.getElementsByTagName('diagram');
  440. if (urlParams['pages'] != '0' || nodes.length > 1 ||
  441. (nodes.length == 1 && nodes[0].hasAttribute('name')))
  442. {
  443. this.fileNode = node;
  444. this.pages = (this.pages != null) ? this.pages : [];
  445. // Wraps page nodes
  446. for (var i = nodes.length - 1; i >= 0; i--)
  447. {
  448. var page = this.updatePageRoot(new DiagramPage(nodes[i]));
  449. // Checks for invalid page names
  450. if (page.getName() == null)
  451. {
  452. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  453. }
  454. graph.model.execute(new ChangePage(this, page, (i == 0) ? page : null, 0));
  455. }
  456. }
  457. else
  458. {
  459. // Creates tabbed file structure if enforced by URL
  460. if (urlParams['pages'] != '0' && this.fileNode == null)
  461. {
  462. this.fileNode = node.ownerDocument.createElement('mxfile');
  463. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  464. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  465. graph.model.execute(new ChangePage(this, this.currentPage, this.currentPage, 0));
  466. }
  467. // Avoids scroll offset when switching page
  468. this.editor.setGraphXml(node);
  469. // Avoids duplicate parsing of the XML stored in the node
  470. if (this.currentPage != null)
  471. {
  472. this.currentPage.root = this.editor.graph.model.root;
  473. }
  474. }
  475. if (oldPages != null)
  476. {
  477. for (var i = 0; i < oldPages.length; i++)
  478. {
  479. graph.model.execute(new ChangePage(this, oldPages[i], null));
  480. }
  481. }
  482. }
  483. finally
  484. {
  485. graph.model.endUpdate();
  486. }
  487. }
  488. };
  489. /**
  490. * Translates this point by the given vector.
  491. *
  492. * @param {number} dx X-coordinate of the translation.
  493. * @param {number} dy Y-coordinate of the translation.
  494. */
  495. EditorUi.prototype.createFileData = function(node, graph, file, url, forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection, compact)
  496. {
  497. graph = (graph != null) ? graph : this.editor.graph;
  498. forceXml = (forceXml != null) ? forceXml : false;
  499. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  500. var editLink = null;
  501. var redirect = null;
  502. if (file == null || file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER)
  503. {
  504. editLink = '_blank';
  505. }
  506. else
  507. {
  508. editLink = url;
  509. redirect = editLink;
  510. }
  511. if (node == null)
  512. {
  513. return '';
  514. }
  515. else
  516. {
  517. var fileNode = node;
  518. // Ignores case for possible HTML or XML nodes
  519. if (fileNode.nodeName.toLowerCase() != 'mxfile')
  520. {
  521. // Removes control chars in input for correct roundtrip check
  522. var text = graph.zapGremlins(mxUtils.getXml(node));
  523. var data = graph.compress(text);
  524. // Fallback to plain XML for invalid compression
  525. // TODO: Remove this fallback with active pages
  526. if (graph.decompress(data) != text)
  527. {
  528. return text;
  529. }
  530. else
  531. {
  532. var diagramNode = node.ownerDocument.createElement('diagram');
  533. mxUtils.setTextContent(diagramNode, data);
  534. fileNode = node.ownerDocument.createElement('mxfile');
  535. fileNode.appendChild(diagramNode);
  536. }
  537. }
  538. if (!compact)
  539. {
  540. fileNode.setAttribute('userAgent', navigator.userAgent);
  541. fileNode.setAttribute('version', EditorUi.VERSION);
  542. fileNode.setAttribute('editor', 'www.draw.io');
  543. var md = (file != null) ? file.getMode() : this.mode;
  544. if (md != null)
  545. {
  546. fileNode.setAttribute('type', md);
  547. }
  548. }
  549. else
  550. {
  551. fileNode = fileNode.cloneNode(true);
  552. fileNode.removeAttribute('userAgent');
  553. fileNode.removeAttribute('version');
  554. fileNode.removeAttribute('editor');
  555. fileNode.removeAttribute('type');
  556. }
  557. var xml = mxUtils.getXml(fileNode);
  558. // Writes the file as an embedded HTML file
  559. if (!forceSvg && !forceXml && (forceHtml || (file != null && /(\.html)$/i.test(file.getTitle()))))
  560. {
  561. xml = this.getHtml2(mxUtils.getXml(fileNode), graph, (file != null) ? file.getTitle() : null, editLink, redirect);
  562. }
  563. // Maps the XML data to the content attribute in the SVG node
  564. else if (forceSvg || (!forceXml && file != null && /(\.svg)$/i.test(file.getTitle())))
  565. {
  566. if (file != null && (file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER))
  567. {
  568. url = null;
  569. }
  570. xml = this.getEmbeddedSvg(xml, graph, url, null, embeddedCallback, ignoreSelection, redirect);
  571. }
  572. return xml;
  573. }
  574. };
  575. /**
  576. * Translates this point by the given vector.
  577. *
  578. * @param {number} dx X-coordinate of the translation.
  579. * @param {number} dy Y-coordinate of the translation.
  580. */
  581. EditorUi.prototype.getXmlFileData = function(ignoreSelection, currentPage)
  582. {
  583. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  584. currentPage = (currentPage != null) ? currentPage : false;
  585. var node = this.editor.getGraphXml(ignoreSelection);
  586. if (ignoreSelection && this.fileNode != null && this.currentPage != null)
  587. {
  588. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(node)));
  589. mxUtils.setTextContent(this.currentPage.node, data);
  590. node = this.fileNode.cloneNode(false);
  591. if (currentPage)
  592. {
  593. node.appendChild(this.currentPage.node);
  594. }
  595. else
  596. {
  597. // Restores order of pages
  598. for (var i = 0; i < this.pages.length; i++)
  599. {
  600. var mapping = this.pages[i].mapping;
  601. // Updates XML of all pages for realtime
  602. if (this.currentPage != this.pages[i] && mapping != null && mapping.needsUpdate)
  603. {
  604. var enc = new mxCodec(mxUtils.createXmlDocument());
  605. var temp = enc.encode(mapping.graphModel);
  606. // Uses the graph state from the realtime model
  607. mapping.writeRealtimeToNode(temp);
  608. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(temp)));
  609. mxUtils.setTextContent(this.pages[i].node, data);
  610. // Marks the page as up-to-date
  611. mapping.needsUpdate = false;
  612. }
  613. node.appendChild(this.pages[i].node);
  614. }
  615. }
  616. }
  617. return node;
  618. };
  619. /**
  620. * Translates this point by the given vector.
  621. *
  622. * @param {number} dx X-coordinate of the translation.
  623. * @param {number} dy Y-coordinate of the translation.
  624. */
  625. EditorUi.prototype.getFileData = function(forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection, currentPage, node, compact)
  626. {
  627. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  628. currentPage = (currentPage != null) ? currentPage : false;
  629. node = (node != null) ? node : this.getXmlFileData(ignoreSelection, currentPage);
  630. var graph = this.editor.graph;
  631. var file = this.getCurrentFile();
  632. // Exports SVG for first page while other page is visible by creating a graph
  633. // LATER: Add caching for the graph or SVG while not on first page
  634. if (this.pages != null && this.currentPage != this.pages[0] && (forceSvg ||
  635. (!forceXml && file != null && /(\.svg)$/i.test(file.getTitle()))))
  636. {
  637. graph = this.createTemporaryGraph(graph.getStylesheet());
  638. var graphGetGlobalVariable = graph.getGlobalVariable;
  639. var page = this.pages[0];
  640. graph.getGlobalVariable = function(name)
  641. {
  642. if (name == 'page')
  643. {
  644. return page.getName();
  645. }
  646. else if (name == 'pagenumber')
  647. {
  648. return 1;
  649. }
  650. return graphGetGlobalVariable.apply(this, arguments);
  651. };
  652. document.body.appendChild(graph.container);
  653. graph.model.setRoot(page.root);
  654. }
  655. var result = this.createFileData(node, graph, file, window.location.href,
  656. forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection, compact);
  657. // Removes temporary graph from DOM
  658. if (graph != this.editor.graph)
  659. {
  660. graph.container.parentNode.removeChild(graph.container);
  661. }
  662. return result;
  663. };
  664. /**
  665. *
  666. */
  667. EditorUi.prototype.getHtml = function(node, graph, title, editLink, redirect, ignoreSelection)
  668. {
  669. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  670. var bg = null;
  671. var js = 'https://www.draw.io/js/embed-static.min.js';
  672. // LATER: Merge common code with EmbedDialog
  673. if (graph != null)
  674. {
  675. var bounds = (ignoreSelection) ? graph.getGraphBounds() : graph.getBoundingBox(graph.getSelectionCells());
  676. var scale = graph.view.scale;
  677. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  678. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  679. bg = graph.background;
  680. // Embed script only used if no redirect
  681. if (redirect == null)
  682. {
  683. var s = this.getBasenames().join(';');
  684. if (s.length > 0)
  685. {
  686. js = 'https://www.draw.io/embed.js?s=' + s;
  687. }
  688. }
  689. // Adds embed attributes
  690. node.setAttribute('x0', x0);
  691. node.setAttribute('y0', y0);
  692. }
  693. if (node != null)
  694. {
  695. node.setAttribute('pan', '1');
  696. node.setAttribute('zoom', '1');
  697. node.setAttribute('resize', '0');
  698. node.setAttribute('fit', '0');
  699. node.setAttribute('border', '20');
  700. // Hidden attributes
  701. node.setAttribute('links', '1');
  702. if (editLink != null)
  703. {
  704. node.setAttribute('edit', editLink);
  705. }
  706. }
  707. // Makes XHTML compatible
  708. if (redirect != null)
  709. {
  710. redirect = redirect.replace(/&/g, '&amp;');
  711. }
  712. // Removes control chars in input for correct roundtrip check
  713. var text = (node != null) ? this.editor.graph.zapGremlins(mxUtils.getXml(node)) : '';
  714. // Double compression for mxfile not fixed since it may cause imcompatibilites with
  715. // embed clients that rely on this format. HTML files and export use getHtml2.
  716. var data = this.editor.graph.compress(text);
  717. // Fallback to URI encoded XML for invalid compression
  718. if (this.editor.graph.decompress(data) != text)
  719. {
  720. data = encodeURIComponent(text);
  721. }
  722. var style = 'position:relative;overflow:auto;width:100%;';
  723. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  724. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  725. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  726. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  727. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  728. '</head>\n<body' +
  729. (((redirect == null && bg != null && bg != mxConstants.NONE) ? ' style="background-color:' + bg + ';">' : '>')) +
  730. '\n<div class="mxgraph" style="' + style + '">\n' +
  731. '<div style="width:1px;height:1px;overflow:hidden;">' + data + '</div>\n</div>\n' +
  732. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  733. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  734. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  735. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  736. '\n</body>\n</html>\n';
  737. };
  738. /**
  739. * Same as above but using the new embed code.
  740. */
  741. EditorUi.prototype.getHtml2 = function(xml, graph, title, editLink, redirect)
  742. {
  743. var bg = null;
  744. var js = 'https://www.draw.io/js/viewer.min.js';
  745. var s = '';
  746. // LATER: Merge common code with EmbedDialog
  747. if (graph != null)
  748. {
  749. // Embed script only used if no redirect
  750. if (redirect == null)
  751. {
  752. var s = this.getBasenames().join(';');
  753. if (s.length > 0)
  754. {
  755. js = 'https://www.draw.io/embed2.js?s=' + s;
  756. }
  757. }
  758. }
  759. // Makes XHTML compatible
  760. if (redirect != null)
  761. {
  762. redirect = redirect.replace(/&/g, '&amp;');
  763. }
  764. var data = {highlight: '#0000ff', nav: this.editor.graph.foldingEnabled, resize: true,
  765. xml: this.editor.graph.zapGremlins(xml), toolbar: 'pages zoom layers lightbox'};
  766. if (this.pages != null && this.currentPage != null)
  767. {
  768. data.page = mxUtils.indexOf(this.pages, this.currentPage);
  769. }
  770. var style = 'max-width:100%;border:1px solid transparent;';
  771. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  772. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  773. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  774. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  775. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  776. '<meta charset="utf-8"/>\n</head>\n<body>' +
  777. '\n<div class="mxgraph" style="' + style + '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>\n' +
  778. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  779. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  780. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  781. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  782. '\n</body>\n</html>\n';
  783. };
  784. /**
  785. *
  786. */
  787. EditorUi.prototype.setFileData = function(data)
  788. {
  789. data = this.validateFileData(data);
  790. this.currentPage = null;
  791. this.fileNode = null;
  792. this.pages = null;
  793. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  794. // Some nodes must be extracted here to find the mxfile node
  795. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  796. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  797. if (tmp != null)
  798. {
  799. node = tmp;
  800. }
  801. if (node != null && node.nodeName == 'mxfile')
  802. {
  803. var nodes = node.getElementsByTagName('diagram');
  804. if (urlParams['pages'] != '0' || nodes.length > 1 ||
  805. (nodes.length == 1 && nodes[0].hasAttribute('name')))
  806. {
  807. this.fileNode = node;
  808. this.pages = [];
  809. // Wraps page nodes
  810. for (var i = 0; i < nodes.length; i++)
  811. {
  812. var page = new DiagramPage(nodes[i]);
  813. // Checks for invalid page names
  814. if (page.getName() == null)
  815. {
  816. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  817. }
  818. this.pages.push(page);
  819. }
  820. this.currentPage = this.pages[Math.max(0, Math.min(this.pages.length - 1, urlParams['page'] || 0))];
  821. node = this.currentPage.node;
  822. }
  823. }
  824. // Creates tabbed file structure if enforced by URL
  825. if (urlParams['pages'] != '0' && this.fileNode == null && node != null)
  826. {
  827. this.fileNode = node.ownerDocument.createElement('mxfile');
  828. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  829. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  830. this.pages = [this.currentPage];
  831. }
  832. // Avoids scroll offset when switching page
  833. this.editor.setGraphXml(node);
  834. // Avoids duplicate parsing of the XML stored in the node
  835. if (this.currentPage != null)
  836. {
  837. this.currentPage.root = this.editor.graph.model.root;
  838. }
  839. };
  840. /**
  841. * Translates this point by the given vector.
  842. *
  843. * @param {number} dx X-coordinate of the translation.
  844. * @param {number} dy Y-coordinate of the translation.
  845. */
  846. EditorUi.prototype.getBaseFilename = function()
  847. {
  848. var file = this.getCurrentFile();
  849. var basename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  850. if (/(\.xml)$/i.test(basename) || /(\.html)$/i.test(basename) || /(\.svg)$/i.test(basename))
  851. {
  852. basename = basename.substring(0, basename.lastIndexOf('.'));
  853. }
  854. return basename;
  855. };
  856. /**
  857. * Translates this point by the given vector.
  858. *
  859. * @param {number} dx X-coordinate of the translation.
  860. * @param {number} dy Y-coordinate of the translation.
  861. */
  862. EditorUi.prototype.downloadFile = function(format, nonCompressed, addShadow, ignoreSelection, currentPage, pageVisible)
  863. {
  864. try
  865. {
  866. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : this.editor.graph.isSelectionEmpty();
  867. var basename = this.getBaseFilename();
  868. var filename = basename + '.' + format;
  869. if (format == 'xml')
  870. {
  871. var data = '<?xml version="1.0" encoding="UTF-8"?>\n' +
  872. ((nonCompressed) ? mxUtils.getXml(this.editor.getGraphXml(ignoreSelection)) :
  873. this.getFileData(true, null, null, null, ignoreSelection, currentPage));
  874. this.saveData(filename, format, data, 'text/xml');
  875. }
  876. else if (format == 'html')
  877. {
  878. var data = this.getHtml2(this.getFileData(true), this.editor.graph, basename);
  879. this.saveData(filename, format, data, 'text/html');
  880. }
  881. else if ((format == 'svg' || format == 'xmlsvg') && this.spinner.spin(document.body, mxResources.get('export')))
  882. {
  883. var svg = null;
  884. var saveSvg = mxUtils.bind(this, function(data)
  885. {
  886. if (data.length <= MAX_REQUEST_SIZE)
  887. {
  888. this.saveData(filename, 'svg', data, 'image/svg+xml');
  889. }
  890. else
  891. {
  892. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  893. {
  894. mxUtils.popup(svg);
  895. }));
  896. }
  897. });
  898. if (format == 'svg')
  899. {
  900. var bg = this.editor.graph.background;
  901. if (bg == mxConstants.NONE)
  902. {
  903. bg = null;
  904. }
  905. // Sets or disables alternate text for foreignObjects. Disabling is needed
  906. // because PhantomJS seems to ignore switch statements and paint all text.
  907. var svgRoot = this.editor.graph.getSvg(bg, null, null, null, null, ignoreSelection);
  908. if (addShadow)
  909. {
  910. this.editor.graph.addSvgShadow(svgRoot);
  911. }
  912. // Embeds the images in the SVG output (async)
  913. this.convertImages(svgRoot, mxUtils.bind(this, mxUtils.bind(this, function(svgRoot2)
  914. {
  915. this.spinner.stop();
  916. saveSvg('<?xml version="1.0" encoding="UTF-8"?>\n' +
  917. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  918. mxUtils.getXml(svgRoot2));
  919. })));
  920. }
  921. else
  922. {
  923. filename = basename + '.svg';
  924. svg = this.getFileData(false, true, null, mxUtils.bind(this, function(svg)
  925. {
  926. this.spinner.stop();
  927. saveSvg(svg);
  928. }), ignoreSelection);
  929. }
  930. }
  931. else
  932. {
  933. if (format == 'xmlpng')
  934. {
  935. filename = basename + '.png';
  936. }
  937. else if (format == 'jpeg')
  938. {
  939. filename = basename + '.jpg';
  940. }
  941. this.saveRequest(filename, format, mxUtils.bind(this, function(newTitle, base64)
  942. {
  943. try
  944. {
  945. var prev = this.editor.graph.pageVisible;
  946. if (pageVisible != null)
  947. {
  948. this.editor.graph.pageVisible = pageVisible;
  949. }
  950. var req = this.createDownloadRequest(newTitle, format, ignoreSelection, base64);
  951. this.editor.graph.pageVisible = prev;
  952. return req;
  953. }
  954. catch (e)
  955. {
  956. this.handleError(e);
  957. }
  958. }));
  959. }
  960. }
  961. catch (e)
  962. {
  963. this.handleError(e);
  964. }
  965. };
  966. /**
  967. * Translates this point by the given vector.
  968. *
  969. * @param {number} dx X-coordinate of the translation.
  970. * @param {number} dy Y-coordinate of the translation.
  971. */
  972. EditorUi.prototype.createDownloadRequest = function(filename, format, ignoreSelection, base64)
  973. {
  974. var bounds = this.editor.graph.getGraphBounds();
  975. // Exports only current page for PDF since it does not contain file data, but for
  976. // the other formats with XML included we need to send the complete data and use
  977. // the from/to URL parameters to specify the page to be exported.
  978. var data = this.getFileData(true, null, null, null, ignoreSelection, format != 'xmlpng');
  979. var range = '';
  980. if (bounds.width * bounds.height > MAX_AREA || data.length > MAX_REQUEST_SIZE)
  981. {
  982. throw {message: mxResources.get('drawingTooLarge')};
  983. }
  984. var embed = '0';
  985. if (format == 'xmlpng')
  986. {
  987. embed = '1';
  988. format = 'png';
  989. // Finds the current page number
  990. if (this.pages != null && this.currentPage != null)
  991. {
  992. for (var i = 0; i < this.pages.length; i++)
  993. {
  994. if (this.pages[i] == this.currentPage)
  995. {
  996. range = '&from=' + i;
  997. break;
  998. }
  999. }
  1000. }
  1001. }
  1002. return new mxXmlRequest(EXPORT_URL, 'format=' + format + range +
  1003. '&base64=' + base64 + '&embedXml=' + embed + '&xml=' +
  1004. encodeURIComponent(data) + ((filename != null) ?
  1005. '&filename=' + encodeURIComponent(filename) : ''));
  1006. };
  1007. /**
  1008. * Translates this point by the given vector.
  1009. *
  1010. * @param {number} dx X-coordinate of the translation.
  1011. * @param {number} dy Y-coordinate of the translation.
  1012. */
  1013. EditorUi.prototype.setMode = function(mode, remember)
  1014. {
  1015. this.mode = mode;
  1016. };
  1017. /**
  1018. * Translates this point by the given vector.
  1019. *
  1020. * @param {number} dx X-coordinate of the translation.
  1021. * @param {number} dy Y-coordinate of the translation.
  1022. */
  1023. EditorUi.prototype.fileLoaded = function(file)
  1024. {
  1025. var result = false;
  1026. this.hideDialog();
  1027. var oldFile = this.getCurrentFile();
  1028. this.setCurrentFile(null);
  1029. if (oldFile != null)
  1030. {
  1031. oldFile.removeListener(this.descriptorChangedListener);
  1032. oldFile.close();
  1033. }
  1034. this.editor.graph.model.clear();
  1035. this.editor.undoManager.clear();
  1036. var noFile = mxUtils.bind(this, function()
  1037. {
  1038. this.setGraphEnabled(false);
  1039. this.setCurrentFile(null);
  1040. // Keeps initial title if no file existed before
  1041. if (oldFile != null)
  1042. {
  1043. this.updateDocumentTitle();
  1044. }
  1045. // File might have been loaded halfway
  1046. this.editor.graph.model.clear();
  1047. this.editor.undoManager.clear();
  1048. // Avoids empty hash with no value
  1049. if (window.location.hash != null && window.location.hash.length > 0)
  1050. {
  1051. window.location.hash = '';
  1052. }
  1053. if (this.fname != null)
  1054. {
  1055. this.fnameWrapper.style.display = 'none';
  1056. this.fname.innerHTML = '';
  1057. this.fname.setAttribute('title', mxResources.get('rename'));
  1058. }
  1059. this.updateUi();
  1060. this.showSplash();
  1061. });
  1062. if (file != null)
  1063. {
  1064. try
  1065. {
  1066. // Order is significant, current file needed for correct
  1067. // file format for initial save after starting realtime
  1068. this.setCurrentFile(file);
  1069. file.addListener('descriptorChanged', this.descriptorChangedListener);
  1070. file.addListener('contentChanged', this.descriptorChangedListener);
  1071. this.descriptorChanged();
  1072. file.open();
  1073. this.setGraphEnabled(true);
  1074. this.setMode(file.getMode());
  1075. this.editor.undoManager.clear();
  1076. this.updateUi();
  1077. // Realtime files have a valid status message
  1078. if (file.realtime == null)
  1079. {
  1080. if (!file.isEditable())
  1081. {
  1082. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('readOnly')));
  1083. }
  1084. else
  1085. {
  1086. this.editor.setStatus('');
  1087. }
  1088. }
  1089. if (!this.editor.chromeless)
  1090. {
  1091. this.editor.graph.selectUnlockedLayer();
  1092. this.showLayersDialog();
  1093. this.restoreLibraries();
  1094. // Workaround for no initial focus in FF
  1095. if (window.self !== window.top)
  1096. {
  1097. window.focus();
  1098. }
  1099. }
  1100. else if (this.editor.graph.lightbox)
  1101. {
  1102. this.lightboxFit();
  1103. }
  1104. if (this.chromelessResize)
  1105. {
  1106. this.chromelessResize();
  1107. }
  1108. this.editor.fireEvent(new mxEventObject('fileLoaded'));
  1109. result = true;
  1110. if (EditorUi.enableLogging && !this.isOffline() && file.getMode() != null)
  1111. {
  1112. try
  1113. {
  1114. if (typeof window.ga === 'function')
  1115. {
  1116. ga('send', 'event', 'File', 'open', file.getMode());
  1117. }
  1118. }
  1119. catch (e)
  1120. {
  1121. // ignore
  1122. }
  1123. }
  1124. if (this.mode == file.getMode() && file.getMode() != App.MODE_DEVICE && file.getMode() != null)
  1125. {
  1126. try
  1127. {
  1128. this.addRecent({id: file.getHash(), title: file.getTitle(), mode: file.getMode()});
  1129. }
  1130. catch (e)
  1131. {
  1132. // ignore
  1133. }
  1134. }
  1135. try
  1136. {
  1137. mxSettings.setOpenCounter(mxSettings.getOpenCounter() + 1);
  1138. mxSettings.save();
  1139. }
  1140. catch (e)
  1141. {
  1142. // ignore
  1143. }
  1144. }
  1145. catch (e)
  1146. {
  1147. // Makes sure the file does not save the invalid UI model and overwrites anything important
  1148. if (window.console != null)
  1149. {
  1150. console.log('error in fileLoaded:', file, e);
  1151. }
  1152. if (EditorUi.enableLogging && !this.isOffline())
  1153. {
  1154. try
  1155. {
  1156. var img = new Image();
  1157. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  1158. img.src = logDomain + '/log?v=' + encodeURIComponent(EditorUi.VERSION) +
  1159. '&msg=errorInFileLoaded:url:' + encodeURIComponent(window.location.href) +
  1160. ((e != null && e.message != null) ? ':err:' + encodeURIComponent(e.message) : '') +
  1161. ((e != null && e.stack != null) ? '&stack=' + encodeURIComponent(e.stack) : '');
  1162. }
  1163. catch (e)
  1164. {
  1165. // ignore
  1166. }
  1167. }
  1168. // Asynchronous handling of errors
  1169. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  1170. {
  1171. // Removes URL parameter and reloads the page
  1172. if (urlParams['url'] != null && this.spinner.spin(document.body, mxResources.get('reconnecting')))
  1173. {
  1174. window.location.search = this.getSearch(['url']);
  1175. }
  1176. else if (oldFile != null)
  1177. {
  1178. // Workaround for close realtime model is to reload the file from scratch
  1179. if (oldFile.constructor == DriveFile)
  1180. {
  1181. this.loadFile(oldFile.getHash());
  1182. }
  1183. else
  1184. {
  1185. this.fileLoaded(oldFile);
  1186. }
  1187. }
  1188. else
  1189. {
  1190. noFile();
  1191. }
  1192. }));
  1193. }
  1194. }
  1195. else
  1196. {
  1197. noFile();
  1198. }
  1199. return result;
  1200. };
  1201. /**
  1202. * Updates action states depending on the selection.
  1203. */
  1204. EditorUi.prototype.restoreLibraries = function()
  1205. {
  1206. // hook for subclassers
  1207. };
  1208. /**
  1209. * Translates this point by the given vector.
  1210. *
  1211. * @param {number} dx X-coordinate of the translation.
  1212. * @param {number} dy Y-coordinate of the translation.
  1213. */
  1214. EditorUi.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  1215. {
  1216. // hook for subclassers
  1217. };
  1218. /**
  1219. * Shows or hides the scratchpad library.
  1220. */
  1221. EditorUi.prototype.toggleScratchpad = function()
  1222. {
  1223. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  1224. {
  1225. if (this.scratchpad == null)
  1226. {
  1227. this.getLocalData('.scratchpad', mxUtils.bind(this, function(xml)
  1228. {
  1229. if (xml == null)
  1230. {
  1231. xml = this.emptyLibraryXml;
  1232. }
  1233. this.loadLibrary(new StorageLibrary(this, xml, '.scratchpad'));
  1234. }));
  1235. }
  1236. else
  1237. {
  1238. this.closeLibrary(this.scratchpad);
  1239. }
  1240. }
  1241. };
  1242. /**
  1243. * Translates this point by the given vector.
  1244. *
  1245. * @param {number} dx X-coordinate of the translation.
  1246. * @param {number} dy Y-coordinate of the translation.
  1247. */
  1248. EditorUi.prototype.createLibraryDataFromImages = function(images)
  1249. {
  1250. var doc = mxUtils.createXmlDocument();
  1251. var library = doc.createElement('mxlibrary');
  1252. mxUtils.setTextContent(library, JSON.stringify(images));
  1253. doc.appendChild(library);
  1254. return mxUtils.getXml(doc);
  1255. };
  1256. /**
  1257. * Translates this point by the given vector.
  1258. *
  1259. * @param {number} dx X-coordinate of the translation.
  1260. * @param {number} dy Y-coordinate of the translation.
  1261. */
  1262. EditorUi.prototype.closeLibrary = function(file)
  1263. {
  1264. if (file != null)
  1265. {
  1266. this.removeLibrarySidebar(file.getHash());
  1267. if (file.constructor != LocalLibrary)
  1268. {
  1269. mxSettings.removeCustomLibrary(file.getHash());
  1270. }
  1271. if (file.title == '.scratchpad')
  1272. {
  1273. this.scratchpad = null;
  1274. }
  1275. }
  1276. };
  1277. /**
  1278. * Translates this point by the given vector.
  1279. *
  1280. * @param {number} dx X-coordinate of the translation.
  1281. * @param {number} dy Y-coordinate of the translation.
  1282. */
  1283. EditorUi.prototype.removeLibrarySidebar = function(id)
  1284. {
  1285. var elts = this.sidebar.palettes[id];
  1286. if (elts != null)
  1287. {
  1288. for (var i = 0; i < elts.length; i++)
  1289. {
  1290. elts[i].parentNode.removeChild(elts[i]);
  1291. }
  1292. delete this.sidebar.palettes[id];
  1293. }
  1294. };
  1295. /**
  1296. * Changes the position of the library in the sidebar
  1297. */
  1298. EditorUi.prototype.repositionLibrary = function(nextChild)
  1299. {
  1300. var c = this.sidebar.container;
  1301. if (nextChild == null)
  1302. {
  1303. var elts = this.sidebar.palettes['L.scratchpad'];
  1304. if (elts == null)
  1305. {
  1306. elts = this.sidebar.palettes['search'];
  1307. }
  1308. if (elts != null)
  1309. {
  1310. nextChild = elts[elts.length - 1].nextSibling;
  1311. }
  1312. }
  1313. nextChild = (nextChild != null) ? nextChild : c.firstChild.nextSibling.nextSibling;
  1314. var content = c.lastChild;
  1315. var title = content.previousSibling;
  1316. c.insertBefore(content, nextChild);
  1317. c.insertBefore(title, content);
  1318. }
  1319. /**
  1320. * Translates this point by the given vector.
  1321. *
  1322. * @param {number} dx X-coordinate of the translation.
  1323. * @param {number} dy Y-coordinate of the translation.
  1324. */
  1325. EditorUi.prototype.loadLibrary = function(file)
  1326. {
  1327. var doc = mxUtils.parseXml(file.getData());
  1328. if (doc.documentElement.nodeName == 'mxlibrary')
  1329. {
  1330. var images = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  1331. this.libraryLoaded(file, images, doc.documentElement.getAttribute('title'));
  1332. }
  1333. else
  1334. {
  1335. throw {message: mxResources.get('notALibraryFile')};
  1336. }
  1337. };
  1338. /**
  1339. * Translates this point by the given vector.
  1340. *
  1341. * @param {number} dx X-coordinate of the translation.
  1342. * @param {number} dy Y-coordinate of the translation.
  1343. */
  1344. EditorUi.prototype.getLibraryStorageHint = function(file)
  1345. {
  1346. return '';
  1347. };
  1348. /**
  1349. * Translates this point by the given vector.
  1350. *
  1351. * @param {number} dx X-coordinate of the translation.
  1352. * @param {number} dy Y-coordinate of the translation.
  1353. */
  1354. EditorUi.prototype.libraryLoaded = function(file, images, optionalTitle)
  1355. {
  1356. if (file.constructor != LocalLibrary)
  1357. {
  1358. mxSettings.addCustomLibrary(file.getHash());
  1359. }
  1360. if (file.title == '.scratchpad')
  1361. {
  1362. this.scratchpad = file;
  1363. }
  1364. var elts = this.sidebar.palettes[file.getHash()];
  1365. var nextSibling = (elts != null) ? elts[elts.length - 1].nextSibling : null;
  1366. // Removes existing sidebar entry for this library
  1367. this.removeLibrarySidebar(file.getHash());
  1368. var dropTarget = null;
  1369. var addImages = mxUtils.bind(this, function(imgs, content)
  1370. {
  1371. if (imgs.length == 0 && file.isEditable())
  1372. {
  1373. if (dropTarget == null)
  1374. {
  1375. dropTarget = document.createElement('div');
  1376. mxUtils.setPrefixedStyle(dropTarget.style, 'borderRadius', '6px');
  1377. dropTarget.style.border = '3px dotted lightGray';
  1378. dropTarget.style.textAlign = 'center';
  1379. dropTarget.style.padding = '8px';
  1380. dropTarget.style.color = '#B3B3B3';
  1381. mxUtils.write(dropTarget, mxResources.get('dragElementsHere'));
  1382. }
  1383. content.appendChild(dropTarget);
  1384. }
  1385. else
  1386. {
  1387. for (var i = 0; i < imgs.length; i++)
  1388. {
  1389. var img = imgs[i];
  1390. var data = img.data;
  1391. if (data != null)
  1392. {
  1393. data = this.convertDataUri(data);
  1394. var s = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;imageAspect=0;';
  1395. if (img.aspect == 'fixed')
  1396. {
  1397. s += 'aspect=fixed;'
  1398. }
  1399. content.appendChild(this.sidebar.createVertexTemplate(s + 'image=' +
  1400. data, img.w, img.h, '', img.title || '', false, false, false));
  1401. }
  1402. else if (img.xml != null)
  1403. {
  1404. var cells = this.stringToCells(this.editor.graph.decompress(img.xml));
  1405. if (cells.length > 0)
  1406. {
  1407. content.appendChild(this.sidebar.createVertexTemplateFromCells(
  1408. cells, img.w, img.h, img.title || '', true, false, false));
  1409. }
  1410. }
  1411. }
  1412. }
  1413. });
  1414. // Adds new sidebar entry for this library
  1415. var tmp = (optionalTitle != null && optionalTitle.length > 0) ? optionalTitle : file.getTitle();
  1416. var contentDiv = this.sidebar.addPalette(file.getHash(), tmp, true, mxUtils.bind(this, function(content)
  1417. {
  1418. addImages(images, content);
  1419. }));
  1420. this.repositionLibrary(nextSibling);
  1421. // Adds tooltip for backend
  1422. var title = contentDiv.parentNode.previousSibling;
  1423. var tip = title.getAttribute('title');
  1424. if (tip != null && tip.length > 0 && file.title != '.scratchpad')
  1425. {
  1426. title.setAttribute('title', this.getLibraryStorageHint(file) + '\n' + tip);
  1427. }
  1428. var buttons = document.createElement('div');
  1429. buttons.style.position = 'absolute';
  1430. buttons.style.right = '0px';
  1431. buttons.style.top = '5px';
  1432. // Workaround for CSS error in IE8 (standards and quirks)
  1433. if (!mxClient.IS_QUIRKS && document.documentMode != 8)
  1434. {
  1435. buttons.style.backgroundColor = 'inherit';
  1436. }
  1437. title.style.position = 'relative';
  1438. var btnWidth = 18;
  1439. var btn = document.createElement('img');
  1440. btn.setAttribute('src', Dialog.prototype.closeImage);
  1441. btn.setAttribute('title', mxResources.get('close'));
  1442. btn.setAttribute('align', 'top');
  1443. btn.setAttribute('border', '0');
  1444. btn.className = 'geButton';
  1445. btn.style.marginRight = '1px';
  1446. btn.style.marginTop = '-1px';
  1447. buttons.appendChild(btn);
  1448. var saveBtn = null;
  1449. mxEvent.addListener(btn, 'click', mxUtils.bind(this, function(evt)
  1450. {
  1451. // Workaround for close after any button click in IE8/quirks
  1452. if (!mxEvent.isConsumed(evt))
  1453. {
  1454. var fn = mxUtils.bind(this, function()
  1455. {
  1456. this.closeLibrary(file);
  1457. });
  1458. if (saveBtn != null)
  1459. {
  1460. this.confirm(mxResources.get('allChangesLost'), null, fn,
  1461. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1462. }
  1463. else
  1464. {
  1465. fn();
  1466. }
  1467. mxEvent.consume(evt);
  1468. }
  1469. }));
  1470. // Shows tooltip if mouse over background
  1471. mxEvent.addListener(contentDiv, 'mousemove', mxUtils.bind(this, function(evt)
  1472. {
  1473. if (mxEvent.getSource(evt) == contentDiv)
  1474. {
  1475. contentDiv.setAttribute('title', mxResources.get('libraryTooltip'));
  1476. }
  1477. else
  1478. {
  1479. contentDiv.removeAttribute('title');
  1480. }
  1481. }));
  1482. if (file.isEditable())
  1483. {
  1484. var graph = this.editor.graph;
  1485. var editLibrary = mxUtils.bind(this, function(evt)
  1486. {
  1487. this.showLibraryDialog(file.getTitle(), contentDiv, images, file, file.getMode());
  1488. mxEvent.consume(evt);
  1489. });
  1490. var saveLibrary = mxUtils.bind(this, function(evt)
  1491. {
  1492. file.setModified(true);
  1493. if (file.isAutosave())
  1494. {
  1495. if (spinBtn != null && spinBtn.parentNode != null)
  1496. {
  1497. spinBtn.parentNode.removeChild(spinBtn);
  1498. }
  1499. spinBtn = btn.cloneNode(false);
  1500. spinBtn.setAttribute('src', Editor.spinImage);
  1501. spinBtn.setAttribute('title', mxResources.get('saving'));
  1502. spinBtn.style.cursor = 'default';
  1503. spinBtn.style.marginRight = '2px';
  1504. spinBtn.style.marginTop = '-2px';
  1505. buttons.insertBefore(spinBtn, buttons.firstChild);
  1506. title.style.paddingRight = (buttons.childNodes.length * btnWidth) + 'px';
  1507. this.saveLibrary(file.getTitle(), images, file, file.getMode(), true, true, function()
  1508. {
  1509. if (spinBtn != null && spinBtn.parentNode != null)
  1510. {
  1511. spinBtn.parentNode.removeChild(spinBtn);
  1512. title.style.paddingRight = (buttons.childNodes.length * btnWidth) + 'px';
  1513. }
  1514. });
  1515. }
  1516. else if (saveBtn == null)
  1517. {
  1518. saveBtn = btn.cloneNode(false);
  1519. saveBtn.setAttribute('src', IMAGE_PATH + '/download.png');
  1520. saveBtn.setAttribute('title', mxResources.get('save'));
  1521. buttons.insertBefore(saveBtn, buttons.firstChild);
  1522. mxEvent.addListener(saveBtn, 'click', mxUtils.bind(this, function(evt)
  1523. {
  1524. this.saveLibrary(file.getTitle(), images, file, file.getMode(),
  1525. file.constructor == LocalLibrary, true, function()
  1526. {
  1527. if (saveBtn != null && !file.isModified())
  1528. {
  1529. title.style.paddingRight = (buttons.childNodes.length * btnWidth) + 'px';
  1530. saveBtn.parentNode.removeChild(saveBtn);
  1531. saveBtn = null;
  1532. }
  1533. });
  1534. mxEvent.consume(evt);
  1535. }));
  1536. title.style.paddingRight = (buttons.childNodes.length * btnWidth) + 'px';
  1537. }
  1538. });
  1539. var addCells = mxUtils.bind(this, function(cells, bounds, evt, title)
  1540. {
  1541. cells = graph.cloneCells(mxUtils.sortCells(graph.model.getTopmostCells(cells)));
  1542. // Translates cells to origin
  1543. for (var i = 0; i < cells.length; i++)
  1544. {
  1545. var geo = graph.getCellGeometry(cells[i]);
  1546. if (geo != null)
  1547. {
  1548. geo.translate(-bounds.x, -bounds.y);
  1549. }
  1550. }
  1551. contentDiv.appendChild(this.sidebar.createVertexTemplateFromCells(
  1552. cells, bounds.width, bounds.height, title || '', true, false, false));
  1553. var xml = this.editor.graph.compress(mxUtils.getXml(this.editor.graph.encodeCells(cells)));
  1554. var entry = {xml: xml, w: bounds.width, h: bounds.height};
  1555. if (title != null)
  1556. {
  1557. entry.title = title;
  1558. }
  1559. images.push(entry);
  1560. saveLibrary(evt);
  1561. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  1562. {
  1563. dropTarget.parentNode.removeChild(dropTarget);
  1564. dropTarget = null;
  1565. }
  1566. });
  1567. var addSelection = mxUtils.bind(this, function(evt)
  1568. {
  1569. if (!graph.isSelectionEmpty())
  1570. {
  1571. var cells = graph.getSelectionCells();
  1572. var bounds = graph.view.getBounds(cells);
  1573. var s = graph.view.scale;
  1574. bounds.x /= s;
  1575. bounds.y /= s;
  1576. bounds.width /= s;
  1577. bounds.height /= s;
  1578. bounds.x -= graph.view.translate.x;
  1579. bounds.y -= graph.view.translate.y;
  1580. addCells(cells, bounds);
  1581. }
  1582. else if (graph.getRubberband().isActive())
  1583. {
  1584. graph.getRubberband().execute(evt);
  1585. graph.getRubberband().reset();
  1586. }
  1587. else
  1588. {
  1589. this.showError(mxResources.get('error'), mxResources.get('nothingIsSelected'), mxResources.get('ok'));
  1590. }
  1591. mxEvent.consume(evt);
  1592. });
  1593. // Defines inactive border state
  1594. contentDiv.style.border = '3px solid transparent';
  1595. // Adds drop handler from graph
  1596. mxEvent.addGestureListeners(contentDiv, function(){}, mxUtils.bind(this, function(evt)
  1597. {
  1598. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler.shape != null)
  1599. {
  1600. graph.graphHandler.shape.node.style.visibility = 'hidden';
  1601. if (dropTarget != null)
  1602. {
  1603. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  1604. }
  1605. else
  1606. {
  1607. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  1608. }
  1609. contentDiv.style.cursor = 'copy';
  1610. graph.panningManager.stop();
  1611. graph.autoScroll = false;
  1612. if (graph.graphHandler.guide != null)
  1613. {
  1614. graph.graphHandler.guide.setVisible(false);
  1615. }
  1616. if (graph.graphHandler.hint != null)
  1617. {
  1618. graph.graphHandler.hint.style.visibility = 'hidden';
  1619. }
  1620. mxEvent.consume(evt);
  1621. }
  1622. }), mxUtils.bind(this, function(evt)
  1623. {
  1624. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler != null)
  1625. {
  1626. contentDiv.style.border = '3px solid transparent';
  1627. if (dropTarget != null)
  1628. {
  1629. dropTarget.style.border = '3px dotted lightGray';
  1630. }
  1631. contentDiv.style.cursor = 'default';
  1632. this.sidebar.showTooltips = true;
  1633. graph.panningManager.stop();
  1634. graph.graphHandler.reset();
  1635. graph.isMouseDown = false;
  1636. graph.autoScroll = true;
  1637. addSelection(evt);
  1638. mxEvent.consume(evt);
  1639. }
  1640. }));
  1641. // Handles mouse leaving the library and restoring move
  1642. mxEvent.addListener(contentDiv, 'mouseleave', mxUtils.bind(this, function(evt)
  1643. {
  1644. if (graph.isMouseDown && graph.graphHandler.shape != null)
  1645. {
  1646. graph.graphHandler.shape.node.style.visibility = 'visible';
  1647. contentDiv.style.border = '3px solid transparent';
  1648. contentDiv.style.cursor = '';
  1649. graph.autoScroll = true;
  1650. if (graph.graphHandler.guide != null)
  1651. {
  1652. graph.graphHandler.guide.setVisible(true);
  1653. }
  1654. if (graph.graphHandler.hint != null)
  1655. {
  1656. graph.graphHandler.hint.style.visibility = 'visible';
  1657. }
  1658. if (dropTarget != null)
  1659. {
  1660. dropTarget.style.border = '3px dotted lightGray';
  1661. }
  1662. }
  1663. }));
  1664. // Adds drop handler from filesystem
  1665. if (Graph.fileSupport)
  1666. {
  1667. mxEvent.addListener(contentDiv, 'dragover', mxUtils.bind(this, function(evt)
  1668. {
  1669. if (dropTarget != null)
  1670. {
  1671. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  1672. }
  1673. else
  1674. {
  1675. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  1676. }
  1677. evt.dataTransfer.dropEffect = 'copy';
  1678. contentDiv.style.cursor = 'copy';
  1679. this.sidebar.hideTooltip();
  1680. evt.stopPropagation();
  1681. evt.preventDefault();
  1682. }));
  1683. mxEvent.addListener(contentDiv, 'drop', mxUtils.bind(this, function(evt)
  1684. {
  1685. contentDiv.style.border = '3px solid transparent';
  1686. contentDiv.style.cursor = '';
  1687. if (dropTarget != null)
  1688. {
  1689. dropTarget.style.border = '3px dotted lightGray';
  1690. }
  1691. if (evt.dataTransfer.files.length > 0)
  1692. {
  1693. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, mxUtils.bind(this, function(data, mimeType, x, y, w, h, img, doneFn, file)
  1694. {
  1695. if (data != null && mimeType.substring(0, 6) == 'image/')
  1696. {
  1697. var style = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;image=' +
  1698. this.convertDataUri(data);
  1699. var cells = [new mxCell('', new mxGeometry(0, 0, w, h), style)];
  1700. cells[0].vertex = true;
  1701. addCells(cells, new mxRectangle(0, 0, w, h), evt, (mxEvent.isAltDown(evt)) ? null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  1702. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  1703. {
  1704. dropTarget.parentNode.removeChild(dropTarget);
  1705. dropTarget = null;
  1706. }
  1707. }
  1708. else
  1709. {
  1710. var done = false;
  1711. var doImport = mxUtils.bind(this, function(theData, theMimeType)
  1712. {
  1713. if (theData != null && theMimeType == 'text/xml')
  1714. {
  1715. var doc = mxUtils.parseXml(theData);
  1716. if (doc.documentElement.nodeName == 'mxlibrary')
  1717. {
  1718. try
  1719. {
  1720. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  1721. addImages(temp, contentDiv);
  1722. images = images.concat(temp);
  1723. saveLibrary(evt);
  1724. this.spinner.stop();
  1725. done = true;
  1726. }
  1727. catch (e)
  1728. {
  1729. // ignore
  1730. }
  1731. }
  1732. else if (doc.documentElement.nodeName == 'mxfile')
  1733. {
  1734. try
  1735. {
  1736. var pages = doc.documentElement.getElementsByTagName('diagram');
  1737. for (var i = 0; i < pages.length; i++)
  1738. {
  1739. var temp = mxUtils.getTextContent(pages[i]);
  1740. var cells = this.stringToCells(this.editor.graph.decompress(temp));
  1741. var size = this.editor.graph.getBoundingBoxFromGeometry(cells);
  1742. addCells(cells, new mxRectangle(0, 0, size.width, size.height), evt);
  1743. }
  1744. done = true;
  1745. }
  1746. catch (e)
  1747. {
  1748. if (window.console != null)
  1749. {
  1750. console.log('error in drop handler:', e);
  1751. }
  1752. }
  1753. }
  1754. }
  1755. if (!done)
  1756. {
  1757. this.spinner.stop();
  1758. this.handleError({message: mxResources.get('errorLoadingFile')})
  1759. }
  1760. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  1761. {
  1762. dropTarget.parentNode.removeChild(dropTarget);
  1763. dropTarget = null;
  1764. }
  1765. });
  1766. if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, img) && file != null)
  1767. {
  1768. this.parseFile(file, mxUtils.bind(this, function(xhr)
  1769. {
  1770. if (xhr.readyState == 4)
  1771. {
  1772. this.spinner.stop();
  1773. if (xhr.status >= 200 && xhr.status <= 299)
  1774. {
  1775. doImport(xhr.responseText, 'text/xml');
  1776. }
  1777. else
  1778. {
  1779. this.handleError({message: mxResources.get((xhr.status == 413) ?
  1780. 'drawingTooLarge' : 'invalidOrMissingFile')},
  1781. mxResources.get('errorLoadingFile'));
  1782. }
  1783. }
  1784. }));
  1785. }
  1786. else
  1787. {
  1788. doImport(data, mimeType);
  1789. }
  1790. }
  1791. }));
  1792. }
  1793. evt.stopPropagation();
  1794. evt.preventDefault();
  1795. }));
  1796. mxEvent.addListener(contentDiv, 'dragleave', function(evt)
  1797. {
  1798. if (dropTarget != null)
  1799. {
  1800. dropTarget.style.border = '3px dotted lightGray';
  1801. }
  1802. else
  1803. {
  1804. contentDiv.style.border = '3px solid transparent';
  1805. contentDiv.style.cursor = '';
  1806. }
  1807. evt.stopPropagation();
  1808. evt.preventDefault();
  1809. });
  1810. }
  1811. btn = btn.cloneNode(false);
  1812. btn.setAttribute('src', IMAGE_PATH + '/edit.gif');
  1813. btn.setAttribute('title', mxResources.get('edit'));
  1814. buttons.insertBefore(btn, buttons.firstChild);
  1815. mxEvent.addListener(btn, 'click', editLibrary);
  1816. mxEvent.addListener(contentDiv, 'dblclick', function(evt)
  1817. {
  1818. if (mxEvent.getSource(evt) == contentDiv)
  1819. {
  1820. editLibrary(evt);
  1821. }
  1822. });
  1823. btn = btn.cloneNode(false);
  1824. btn.setAttribute('src', Editor.plusImage);
  1825. btn.setAttribute('title', mxResources.get('add'));
  1826. buttons.insertBefore(btn, buttons.firstChild);
  1827. if (!this.isOffline() && file.title == '.scratchpad')
  1828. {
  1829. var link = document.createElement('span');
  1830. link.setAttribute('title', mxResources.get('help'));
  1831. link.style.cssText = 'color:gray;text-decoration:none;';
  1832. link.className = 'geButton';
  1833. mxUtils.write(link, '?');
  1834. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  1835. {
  1836. window.open('https://desk.draw.io/support/solutions/articles/16000042367');
  1837. mxEvent.consume(evt);
  1838. }));
  1839. buttons.insertBefore(link, buttons.firstChild);
  1840. }
  1841. var spinBtn = null;
  1842. mxEvent.addListener(btn, 'click', addSelection);
  1843. }
  1844. title.appendChild(buttons);
  1845. title.style.paddingRight = (buttons.childNodes.length * btnWidth) + 'px';
  1846. };
  1847. /**
  1848. * EditorUi Overrides
  1849. */
  1850. if (urlParams['offline'] == '1')
  1851. {
  1852. EditorUi.prototype.footerHeight = 4;
  1853. }
  1854. else
  1855. {
  1856. if (uiTheme == 'atlas')
  1857. {
  1858. if (typeof Toolbar !== 'undefined')
  1859. {
  1860. Toolbar.prototype.unselectedBackground = (mxClient.IS_QUIRKS) ? 'none' : 'linear-gradient(rgb(255, 255, 255) 0px, rgb(242, 242, 242) 100%)';
  1861. Toolbar.prototype.selectedBackground = 'rgb(242, 242, 242)';
  1862. }
  1863. Editor.prototype.initialTopSpacing = 3;
  1864. EditorUi.prototype.menubarHeight = 41;
  1865. EditorUi.prototype.toolbarHeight = 38;
  1866. EditorUi.prototype.hsplitPosition = 188;
  1867. Sidebar.prototype.thumbWidth = 46;
  1868. Sidebar.prototype.thumbHeight = 46;
  1869. Sidebar.prototype.thumbPadding = (document.documentMode >= 5) ? 0 : 1;
  1870. Sidebar.prototype.thumbBorder = 2;
  1871. }
  1872. else
  1873. {
  1874. if (urlParams['savesidebar'] == '1')
  1875. {
  1876. Sidebar.prototype.thumbWidth = 64;
  1877. Sidebar.prototype.thumbHeight = 64;
  1878. }
  1879. }
  1880. EditorUi.prototype.footerHeight = (screen.width >= 760 && screen.height >= 240) ? 46 : 0;
  1881. // Fetches footer from page
  1882. EditorUi.prototype.createFooter = function()
  1883. {
  1884. var footer = document.getElementById('geFooter');
  1885. if (footer != null)
  1886. {
  1887. footer.style.visibility = 'visible';
  1888. // Adds button to hide the footer
  1889. var img = document.createElement('img');
  1890. img.setAttribute('border', '0');
  1891. img.setAttribute('src', Dialog.prototype.closeImage);
  1892. img.setAttribute('title', mxResources.get('hide'));
  1893. footer.appendChild(img)
  1894. if (mxClient.IS_QUIRKS)
  1895. {
  1896. img.style.position = 'relative';
  1897. img.style.styleFloat = 'right';
  1898. img.style.top = '-30px';
  1899. img.style.left = '164px';
  1900. img.style.cursor = 'pointer';
  1901. }
  1902. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  1903. {
  1904. this.hideFooter();
  1905. }));
  1906. }
  1907. return footer;
  1908. };
  1909. }
  1910. /**
  1911. * Hides the footer.
  1912. */
  1913. EditorUi.prototype.hideFooter = function()
  1914. {
  1915. var footer = document.getElementById('geFooter');
  1916. if (footer != null)
  1917. {
  1918. this.footerHeight = 0;
  1919. footer.style.display = 'none';
  1920. this.refresh();
  1921. }
  1922. };
  1923. /**
  1924. * Overrides image dialog to add image search and Google+.
  1925. */
  1926. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting, convertDataUri)
  1927. {
  1928. // KNOWN: IE+FF don't return keyboard focus after image dialog (calling focus doesn't help)
  1929. var dlg = new ImageDialog(this, title, value, fn, ignoreExisting, convertDataUri);
  1930. this.showDialog(dlg.container, (Graph.fileSupport) ? 440 : 360, (Graph.fileSupport) ? 200 : 90, true, true);
  1931. dlg.init();
  1932. };
  1933. /**
  1934. * Hides the current menu.
  1935. */
  1936. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  1937. {
  1938. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  1939. {
  1940. var change = new ChangePageSetup(this, null, image);
  1941. change.ignoreColor = true;
  1942. this.editor.graph.model.execute(change);
  1943. });
  1944. var dlg = new BackgroundImageDialog(this, mxUtils.bind(this, function(image)
  1945. {
  1946. apply(image);
  1947. }));
  1948. this.showDialog(dlg.container, 360, 200, true, true);
  1949. dlg.init();
  1950. };
  1951. /**
  1952. * Hides the current menu.
  1953. */
  1954. EditorUi.prototype.showLibraryDialog = function(name, sidebar, images, file, mode)
  1955. {
  1956. var dlg = new LibraryDialog(this, name, sidebar, images, file, mode);
  1957. this.showDialog(dlg.container, 620, 440, true, false, mxUtils.bind(this, function(cancel)
  1958. {
  1959. if (cancel && this.getCurrentFile() == null && urlParams['embed'] != '1')
  1960. {
  1961. this.showSplash();
  1962. }
  1963. }));
  1964. dlg.init();
  1965. };
  1966. /**
  1967. * Hook for sidebar footer container.
  1968. */
  1969. EditorUi.prototype.createSidebarFooterContainer = function()
  1970. {
  1971. var div = this.createDiv('geSidebarContainer');
  1972. div.style.position = 'absolute';
  1973. div.style.overflow = 'hidden';
  1974. div.style.borderWidth = '3px';
  1975. var elt2 = document.createElement('a');
  1976. elt2.setAttribute('href', 'javascript:void(0);');
  1977. elt2.className = 'geTitle';
  1978. elt2.style.height = '100%';
  1979. elt2.style.paddingTop = '9px';
  1980. mxUtils.write(elt2, mxResources.get('moreShapes') + '...');
  1981. mxEvent.addListener(elt2, 'click', mxUtils.bind(this, function(evt)
  1982. {
  1983. this.actions.get('shapes').funct();
  1984. mxEvent.consume(evt);
  1985. }));
  1986. div.appendChild(elt2);
  1987. return div;
  1988. };
  1989. /**
  1990. * Translates this point by the given vector.
  1991. *
  1992. * @param {number} dx X-coordinate of the translation.
  1993. * @param {number} dy Y-coordinate of the translation.
  1994. */
  1995. EditorUi.prototype.handleError = function(resp, title, fn)
  1996. {
  1997. var resume = (this.spinner != null && this.spinner.pause != null) ? this.spinner.pause() : function() {};
  1998. var e = (resp != null && resp.error != null) ? resp.error : resp;
  1999. if (e != null || title != null)
  2000. {
  2001. var msg = mxUtils.htmlEntities(mxResources.get('unknownError'));
  2002. var btn = mxResources.get('ok');
  2003. var retry = null;
  2004. title = (title != null) ? title : mxResources.get('error');
  2005. if (e != null)
  2006. {
  2007. if (e.retry != null)
  2008. {
  2009. btn = mxResources.get('cancel');
  2010. retry = function()
  2011. {
  2012. resume();
  2013. e.retry();
  2014. };
  2015. }
  2016. if (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' && typeof(gapi.drive.realtime) != 'undefined' &&
  2017. e.type == gapi.drive.realtime.ErrorType.FORBIDDEN)
  2018. {
  2019. msg = mxUtils.htmlEntities(mxResources.get('forbidden'));
  2020. }
  2021. else if (e.code == 404 || e.status == 404 || (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' &&
  2022. typeof(gapi.drive.realtime) != 'undefined' && e.type == gapi.drive.realtime.ErrorType.NOT_FOUND))
  2023. {
  2024. msg = mxUtils.htmlEntities(mxResources.get('fileNotFoundOrDenied'));
  2025. var id = window.location.hash;
  2026. if (id != null && id.substring(0, 2) == '#G')
  2027. {
  2028. id = id.substring(2);
  2029. msg += ' <a href="https://drive.google.com/open?id=' + id + '" target="_blank">' +
  2030. mxUtils.htmlEntities(mxResources.get('tryOpeningViaThisPage')) + '</a>';
  2031. }
  2032. }
  2033. else if (e.code == App.ERROR_TIMEOUT)
  2034. {
  2035. msg = mxUtils.htmlEntities(mxResources.get('timeout'));
  2036. }
  2037. else if (e.code == App.ERROR_BUSY)
  2038. {
  2039. msg = mxUtils.htmlEntities(mxResources.get('busy'));
  2040. }
  2041. else if (e.message != null)
  2042. {
  2043. msg = mxUtils.htmlEntities(e.message);
  2044. }
  2045. else if (e.response != null && e.response.error != null)
  2046. {
  2047. msg = mxUtils.htmlEntities(e.response.error);
  2048. }
  2049. }
  2050. this.showError(title, msg, btn, fn, retry);
  2051. }
  2052. else if (fn != null)
  2053. {
  2054. fn();
  2055. }
  2056. };
  2057. /**
  2058. * Translates this point by the given vector.
  2059. *
  2060. * @param {number} dx X-coordinate of the translation.
  2061. * @param {number} dy Y-coordinate of the translation.
  2062. */
  2063. EditorUi.prototype.showError = function(title, msg, btn, fn, retry, btn2, fn2)
  2064. {
  2065. var dlg = new ErrorDialog(this, title, msg, btn, fn, retry, btn2, fn2);
  2066. this.showDialog(dlg.container, 340, 150, true, false);
  2067. dlg.init();
  2068. };
  2069. /**
  2070. * Translates this point by the given vector.
  2071. *
  2072. * @param {number} dx X-coordinate of the translation.
  2073. * @param {number} dy Y-coordinate of the translation.
  2074. */
  2075. EditorUi.prototype.alert = function(msg, fn)
  2076. {
  2077. var dlg = new ErrorDialog(this, null, msg, mxResources.get('ok'), fn);
  2078. this.showDialog(dlg.container, 340, 100, true, false);
  2079. dlg.init();
  2080. };
  2081. /**
  2082. * Translates this point by the given vector.
  2083. *
  2084. * @param {number} dx X-coordinate of the translation.
  2085. * @param {number} dy Y-coordinate of the translation.
  2086. */
  2087. EditorUi.prototype.confirm = function(msg, okFn, cancelFn, okLabel, cancelLabel)
  2088. {
  2089. var resume = (this.spinner != null && this.spinner.pause != null) ? this.spinner.pause() : function() {};
  2090. this.showDialog(new ConfirmDialog(this, msg, function()
  2091. {
  2092. resume();
  2093. if (okFn != null)
  2094. {
  2095. okFn();
  2096. }
  2097. }, function()
  2098. {
  2099. resume();
  2100. if (cancelFn != null)
  2101. {
  2102. cancelFn();
  2103. }
  2104. }, okLabel, cancelLabel).container, 340, 90, true, false);
  2105. };
  2106. /**
  2107. * Translates this point by the given vector.
  2108. *
  2109. * @param {number} dx X-coordinate of the translation.
  2110. * @param {number} dy Y-coordinate of the translation.
  2111. */
  2112. EditorUi.prototype.setCurrentFile = function(file)
  2113. {
  2114. this.currentFile = file;
  2115. };
  2116. /**
  2117. * Translates this point by the given vector.
  2118. *
  2119. * @param {number} dx X-coordinate of the translation.
  2120. * @param {number} dy Y-coordinate of the translation.
  2121. */
  2122. EditorUi.prototype.getCurrentFile = function()
  2123. {
  2124. return this.currentFile;
  2125. };
  2126. /**
  2127. * Translates this point by the given vector.
  2128. *
  2129. * @param {number} dx X-coordinate of the translation.
  2130. * @param {number} dy Y-coordinate of the translation.
  2131. */
  2132. EditorUi.prototype.isDiagramEmpty = function()
  2133. {
  2134. var model = this.editor.graph.getModel();
  2135. return model.getChildCount(model.root) == 1 && model.getChildCount(model.getChildAt(model.root, 0)) == 0;
  2136. };
  2137. /**
  2138. * Handling for canvas export.
  2139. */
  2140. /**
  2141. *
  2142. */
  2143. EditorUi.prototype.isExportToCanvas = function()
  2144. {
  2145. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  2146. return mxClient.IS_CHROMEAPP || (!this.editor.graph.mathEnabled && this.useCanvasForExport);
  2147. };
  2148. /**
  2149. * Translates this point by the given vector.
  2150. *
  2151. * @param {number} dx X-coordinate of the translation.
  2152. * @param {number} dy Y-coordinate of the translation.
  2153. */
  2154. EditorUi.prototype.createSvgDataUri = function(svg)
  2155. {
  2156. return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  2157. };
  2158. /**
  2159. *
  2160. */
  2161. EditorUi.prototype.createImageDataUri = function(canvas, xml, format)
  2162. {
  2163. var data = canvas.toDataURL('image/' + format);
  2164. // Checks if output is invalid or empty
  2165. if (data.length <= 6 || data == canvas.cloneNode(false).toDataURL('image/' + format))
  2166. {
  2167. throw {message: 'Invalid image'};
  2168. }
  2169. if (xml != null)
  2170. {
  2171. data = this.writeGraphModelToPng(data, 'zTXt', 'mxGraphModel', atob(this.editor.graph.compress(xml)));
  2172. }
  2173. return data;
  2174. };
  2175. /**
  2176. *
  2177. */
  2178. EditorUi.prototype.saveCanvas = function(canvas, xml, format)
  2179. {
  2180. var ext = ((format == 'jpeg') ? 'jpg' : format);
  2181. var filename = this.getBaseFilename() + '.' + ext;
  2182. var data = this.createImageDataUri(canvas, xml, format);
  2183. this.saveData(filename, ext, data.substring(data.lastIndexOf(',') + 1), 'image/' + format, true);
  2184. };
  2185. /**
  2186. * Returns true if files should be saved using <saveLocalFile>.
  2187. */
  2188. EditorUi.prototype.isLocalFileSave = function()
  2189. {
  2190. return ((urlParams['save'] != 'remote' && (mxClient.IS_IE ||
  2191. (typeof window.Blob !== 'undefined' && typeof window.URL !== 'undefined')) &&
  2192. document.documentMode != 9 && document.documentMode != 8 &&
  2193. document.documentMode != 7 && !mxClient.IS_QUIRKS) ||
  2194. this.isOfflineApp() || mxClient.IS_IOS);
  2195. };
  2196. /**
  2197. * Translates this point by the given vector.
  2198. *
  2199. * @param {number} dx X-coordinate of the translation.
  2200. * @param {number} dy Y-coordinate of the translation.
  2201. */
  2202. EditorUi.prototype.doSaveLocalFile = function(data, filename, mimeType, base64Encoded, format)
  2203. {
  2204. // Newer versions of IE
  2205. if (window.Blob && navigator.msSaveOrOpenBlob)
  2206. {
  2207. var blob = (base64Encoded) ?
  2208. this.base64ToBlob(data, mimeType) :
  2209. new Blob([data], {type: mimeType})
  2210. navigator.msSaveOrOpenBlob(blob, filename);
  2211. }
  2212. // Older versions of IE (binary not supported)
  2213. else if (mxClient.IS_IE)
  2214. {
  2215. var win = window.open('about:blank', '_blank');
  2216. if (win == null)
  2217. {
  2218. mxUtils.popup(data, true);
  2219. }
  2220. else
  2221. {
  2222. win.document.write(data);
  2223. win.document.close();
  2224. win.document.execCommand('SaveAs', true, filename);
  2225. win.close();
  2226. }
  2227. }
  2228. else if (mxClient.IS_IOS)
  2229. {
  2230. // Poor man's saveAs in iOS via context menu of selected output
  2231. var dlg = new TextareaDialog(this, filename + ':', data, null, null, mxResources.get('close'));
  2232. dlg.textarea.style.width = '600px';
  2233. dlg.textarea.style.height = '380px';
  2234. this.showDialog(dlg.container, 620, 460, true, true);
  2235. dlg.init();
  2236. document.execCommand('selectall', false, null);
  2237. }
  2238. else
  2239. {
  2240. var a = document.createElement('a');
  2241. // Workaround for mxXmlRequest.simulate no longer working in Safari
  2242. // if this is used (ie PNG export broken after XML export in Safari).
  2243. var useDownload = !mxClient.IS_SF && typeof a.download !== 'undefined';
  2244. if (useDownload || this.isOffline())
  2245. {
  2246. a.href = URL.createObjectURL((base64Encoded) ?
  2247. this.base64ToBlob(data, mimeType) :
  2248. new Blob([data], {type: mimeType}));
  2249. if (useDownload)
  2250. {
  2251. a.download = filename;
  2252. }
  2253. else
  2254. {
  2255. // Workaround for same window in Safari
  2256. a.setAttribute('target', '_blank');
  2257. }
  2258. document.body.appendChild(a);
  2259. try
  2260. {
  2261. window.setTimeout(function()
  2262. {
  2263. URL.revokeObjectURL(a.href);
  2264. }, 0);
  2265. a.click();
  2266. a.parentNode.removeChild(a);
  2267. }
  2268. catch (e)
  2269. {
  2270. // ignore
  2271. }
  2272. }
  2273. else
  2274. {
  2275. var req = this.createEchoRequest(data, filename, mimeType, base64Encoded, format);
  2276. req.simulate(document, '_blank');
  2277. }
  2278. }
  2279. };
  2280. /**
  2281. * Translates this point by the given vector.
  2282. *
  2283. * @param {number} dx X-coordinate of the translation.
  2284. * @param {number} dy Y-coordinate of the translation.
  2285. */
  2286. EditorUi.prototype.createEchoRequest = function(data, filename, mimeType, base64Encoded, format, base64Response)
  2287. {
  2288. var param = (typeof(pako) === 'undefined' || true) ? 'xml=' + encodeURIComponent(data) :
  2289. 'data=' + encodeURIComponent(this.editor.graph.compress(data));
  2290. return new mxXmlRequest(SAVE_URL, param +
  2291. ((mimeType != null) ? '&mime=' + mimeType : '') +
  2292. ((format != null) ? '&format=' + format : '') +
  2293. ((base64Response != null) ? '&base64=' + base64Response : '') +
  2294. ((filename != null) ? '&filename=' + encodeURIComponent(filename) : '') +
  2295. ((base64Encoded) ? '&binary=1' : ''));
  2296. };
  2297. /**
  2298. * Translates this point by the given vector.
  2299. *
  2300. * @param {number} dx X-coordinate of the translation.
  2301. * @param {number} dy Y-coordinate of the translation.
  2302. */
  2303. EditorUi.prototype.base64ToBlob = function(base64Data, contentType)
  2304. {
  2305. contentType = contentType || '';
  2306. var sliceSize = 1024;
  2307. var byteCharacters = atob(base64Data);
  2308. var bytesLength = byteCharacters.length;
  2309. var slicesCount = Math.ceil(bytesLength / sliceSize);
  2310. var byteArrays = new Array(slicesCount);
  2311. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex)
  2312. {
  2313. var begin = sliceIndex * sliceSize;
  2314. var end = Math.min(begin + sliceSize, bytesLength);
  2315. var bytes = new Array(end - begin);
  2316. for (var offset = begin, i = 0 ; offset < end; ++i, ++offset)
  2317. {
  2318. bytes[i] = byteCharacters[offset].charCodeAt(0);
  2319. }
  2320. byteArrays[sliceIndex] = new Uint8Array(bytes);
  2321. }
  2322. return new Blob(byteArrays, {type: contentType});
  2323. };
  2324. /**
  2325. * Translates this point by the given vector.
  2326. *
  2327. * @param {number} dx X-coordinate of the translation.
  2328. * @param {number} dy Y-coordinate of the translation.
  2329. */
  2330. EditorUi.prototype.saveLocalFile = function(data, filename, mimeType, base64Encoded, format, allowBrowser)
  2331. {
  2332. allowBrowser = (allowBrowser != null) ? allowBrowser : false;
  2333. var allowTab = (format != 'vsdx') && (!mxClient.IS_IOS || !navigator.standalone);
  2334. var count = this.getServiceCount(allowBrowser);
  2335. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  2336. {
  2337. try
  2338. {
  2339. // Opens a new window
  2340. if (mode == '_blank')
  2341. {
  2342. if (mimeType != null && mimeType.substring(0, 6) == 'image/' &&
  2343. (mimeType.substring(0, 9) != 'image/svg' || mxClient.IS_SVG))
  2344. {
  2345. // In Google Chrome 60 the code from below produces a blank window
  2346. if (mxClient.IS_GC || mxClient.IS_EDGE || document.documentMode == 11 || document.documentMode == 10)
  2347. {
  2348. var win = window.open('about:blank');
  2349. if (win == null)
  2350. {
  2351. mxUtils.popup(data, true);
  2352. }
  2353. else
  2354. {
  2355. win.document.write('<html><img src="data:' +
  2356. mimeType + ((base64Encoded) ? ';base64,' +
  2357. data : ';charset=utf8,' + encodeURIComponent(data)) +
  2358. '"/></html>');
  2359. win.document.close();
  2360. }
  2361. }
  2362. else
  2363. {
  2364. // win.open is workaround for cleared contents in Chrome after delay
  2365. // when using location.replace
  2366. var win = window.open('data:' + mimeType + ((base64Encoded) ? ';base64,' +
  2367. data : ';charset=utf8,' + encodeURIComponent(data)));
  2368. if (win == null)
  2369. {
  2370. mxUtils.popup(data, true);
  2371. }
  2372. }
  2373. }
  2374. else
  2375. {
  2376. var win = window.open('about:blank');
  2377. if (win == null)
  2378. {
  2379. mxUtils.popup(data, true);
  2380. }
  2381. else
  2382. {
  2383. win.document.write(mxUtils.htmlEntities(data, false));
  2384. win.document.close();
  2385. }
  2386. }
  2387. }
  2388. else if (mode == App.MODE_DEVICE)
  2389. {
  2390. this.doSaveLocalFile(data, newTitle, mimeType, base64Encoded);
  2391. }
  2392. else if (newTitle != null && newTitle.length > 0)
  2393. {
  2394. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2395. {
  2396. try
  2397. {
  2398. this.exportFile(data, newTitle, mimeType, base64Encoded, mode, folderId);
  2399. }
  2400. catch (e)
  2401. {
  2402. this.handleError(e);
  2403. }
  2404. }));
  2405. }
  2406. }
  2407. catch (e)
  2408. {
  2409. this.handleError(e);
  2410. }
  2411. }), mxUtils.bind(this, function()
  2412. {
  2413. this.hideDialog();
  2414. }), mxResources.get('saveAs'), mxResources.get('download'), false, allowBrowser, allowTab,
  2415. null, null, (count > 4) ? 3 : 4, data, mimeType, base64Encoded);
  2416. this.showDialog(dlg.container, 380, (count > 4) ? 390 : 270, true, true);
  2417. dlg.init();
  2418. };
  2419. /**
  2420. * Translates this point by the given vector.
  2421. *
  2422. * @param {number} dx X-coordinate of the translation.
  2423. * @param {number} dy Y-coordinate of the translation.
  2424. */
  2425. EditorUi.prototype.saveData = function(filename, format, data, mime, base64Encoded)
  2426. {
  2427. if (this.isLocalFileSave())
  2428. {
  2429. this.saveLocalFile(data, filename, mime, base64Encoded, format);
  2430. }
  2431. else
  2432. {
  2433. this.saveRequest(filename, format, mxUtils.bind(this, function(newTitle, base64)
  2434. {
  2435. return this.createEchoRequest(data, newTitle, mime, base64Encoded, format, base64);
  2436. }), data, base64Encoded, mime);
  2437. }
  2438. };
  2439. /**
  2440. * Translates this point by the given vector.
  2441. *
  2442. * Last 3 argument are optional and must only be used if the data can be stored as is on the client
  2443. * side without requiring a server roundtrip.
  2444. *
  2445. * @param {number} dx X-coordinate of the translation.
  2446. * @param {number} dy Y-coordinate of the translation.
  2447. */
  2448. EditorUi.prototype.saveRequest = function(filename, format, fn, data, base64Encoded, mimeType)
  2449. {
  2450. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2451. var count = this.getServiceCount(false);
  2452. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  2453. {
  2454. if (mode == '_blank' || newTitle != null && newTitle.length > 0)
  2455. {
  2456. var base64 = (mode == App.MODE_DEVICE || mode == null || mode == '_blank') ? '0' : '1';
  2457. var xhr = fn((mode == '_blank') ? null : newTitle, base64);
  2458. if (xhr != null)
  2459. {
  2460. if (mode == App.MODE_DEVICE || mode == '_blank')
  2461. {
  2462. xhr.simulate(document, '_blank');
  2463. }
  2464. else
  2465. {
  2466. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2467. {
  2468. mimeType = (mimeType != null) ? mimeType : ((format == 'pdf') ?
  2469. 'application/pdf' : 'image/' + format);
  2470. // Workaround for no roundtrip required if data is available on client-side
  2471. // TODO: Refactor the saveData/saveRequest call chain for local data
  2472. if (data != null)
  2473. {
  2474. try
  2475. {
  2476. this.exportFile(data, newTitle, mimeType, true, mode, folderId);
  2477. }
  2478. catch (e)
  2479. {
  2480. this.handleError(e);
  2481. }
  2482. }
  2483. else if (this.spinner.spin(document.body, mxResources.get('saving')))
  2484. {
  2485. // LATER: Catch possible mixed content error
  2486. // see http://stackoverflow.com/questions/30646417/catching-mixed-content-error
  2487. xhr.send(mxUtils.bind(this, function()
  2488. {
  2489. this.spinner.stop();
  2490. if (xhr.getStatus() >= 200 && xhr.getStatus() <= 299)
  2491. {
  2492. try
  2493. {
  2494. this.exportFile(xhr.getText(), newTitle, mimeType, true, mode, folderId);
  2495. }
  2496. catch (e)
  2497. {
  2498. this.handleError(e);
  2499. }
  2500. }
  2501. else
  2502. {
  2503. this.handleError({message: mxResources.get('errorSavingFile')});
  2504. }
  2505. }), function(resp)
  2506. {
  2507. this.spinner.stop();
  2508. this.handleError(resp);
  2509. });
  2510. }
  2511. }));
  2512. }
  2513. }
  2514. }
  2515. }), mxUtils.bind(this, function()
  2516. {
  2517. this.hideDialog();
  2518. }), mxResources.get('saveAs'), mxResources.get('download'), false, false, allowTab,
  2519. null, null, (count > 4) ? 3 : 4, data, mimeType, base64Encoded);
  2520. this.showDialog(dlg.container, 380, (count > 4) ? 390 : 270, true, true);
  2521. dlg.init();
  2522. };
  2523. /**
  2524. * Hook for subclassers.
  2525. */
  2526. EditorUi.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  2527. {
  2528. // do nothing
  2529. };
  2530. /**
  2531. * Hook for subclassers.
  2532. */
  2533. EditorUi.prototype.pickFolder = function(mode, fn, enabled)
  2534. {
  2535. fn(null);
  2536. };
  2537. /**
  2538. *
  2539. */
  2540. EditorUi.prototype.exportSvg = function(scale, transparentBackground, ignoreSelection, addShadow, editable, embedImages, border, noCrop, currentPage)
  2541. {
  2542. if (this.spinner.spin(document.body, mxResources.get('export')))
  2543. {
  2544. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  2545. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  2546. var bg = (transparentBackground) ? null : this.editor.graph.background;
  2547. if (bg == mxConstants.NONE)
  2548. {
  2549. bg = null;
  2550. }
  2551. // Handles special case where background is null but transparent is false
  2552. if (bg == null && transparentBackground == false)
  2553. {
  2554. bg = '#ffffff';
  2555. }
  2556. // Sets or disables alternate text for foreignObjects. Disabling is needed
  2557. // because PhantomJS seems to ignore switch statements and paint all text.
  2558. var svgRoot = this.editor.graph.getSvg(bg, scale, border, noCrop, null, ignoreSelection);
  2559. if (addShadow)
  2560. {
  2561. this.editor.graph.addSvgShadow(svgRoot);
  2562. }
  2563. var filename = this.getBaseFilename() + '.svg';
  2564. var doSave = mxUtils.bind(this, function(svgRoot)
  2565. {
  2566. this.spinner.stop();
  2567. if (editable)
  2568. {
  2569. svgRoot.setAttribute('content', this.getFileData(true, null, null, null, ignoreSelection, currentPage));
  2570. }
  2571. var svg = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  2572. mxUtils.getXml(svgRoot);
  2573. if (this.isLocalFileSave() || svg.length <= MAX_REQUEST_SIZE)
  2574. {
  2575. this.saveData(filename, 'svg', svg, 'image/svg+xml');
  2576. }
  2577. else
  2578. {
  2579. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  2580. {
  2581. mxUtils.popup(svg);
  2582. }));
  2583. }
  2584. });
  2585. this.convertMath(this.editor.graph, svgRoot, false, mxUtils.bind(this, function()
  2586. {
  2587. if (embedImages)
  2588. {
  2589. // Caches images
  2590. if (this.thumbImageCache == null)
  2591. {
  2592. this.thumbImageCache = new Object();
  2593. }
  2594. this.convertImages(svgRoot, doSave, this.thumbImageCache);
  2595. }
  2596. else
  2597. {
  2598. doSave(svgRoot);
  2599. }
  2600. }));
  2601. }
  2602. };
  2603. /**
  2604. *
  2605. */
  2606. EditorUi.prototype.addCheckbox = function(div, label, checked, disabled, disableNewline, visible)
  2607. {
  2608. visible = (visible != null) ? visible : true;
  2609. var cb = document.createElement('input');
  2610. cb.style.marginRight = '8px';
  2611. cb.style.marginTop = '16px';
  2612. cb.setAttribute('type', 'checkbox');
  2613. if (checked)
  2614. {
  2615. cb.setAttribute('checked', 'checked');
  2616. cb.defaultChecked = true;
  2617. }
  2618. if (disabled)
  2619. {
  2620. cb.setAttribute('disabled', 'disabled');
  2621. }
  2622. if (visible)
  2623. {
  2624. div.appendChild(cb);
  2625. mxUtils.write(div, label);
  2626. if (!disableNewline)
  2627. {
  2628. mxUtils.br(div);
  2629. }
  2630. }
  2631. return cb;
  2632. };
  2633. /**
  2634. *
  2635. */
  2636. EditorUi.prototype.addEditButton = function(div, lightbox)
  2637. {
  2638. var edit = this.addCheckbox(div, mxResources.get('edit') + ':', true, null, true);
  2639. edit.style.marginLeft = '24px';
  2640. var file = this.getCurrentFile();
  2641. var editUrl = '';
  2642. if (file != null && file.getMode() != App.MODE_DEVICE && file.getMode() != App.MODE_BROWSER)
  2643. {
  2644. editUrl = window.location.href;
  2645. }
  2646. var editSelect = document.createElement('select');
  2647. editSelect.style.width = '120px';
  2648. editSelect.style.marginLeft = '8px';
  2649. editSelect.style.marginRight = '10px';
  2650. editSelect.className = 'geBtn';
  2651. var blankOption = document.createElement('option');
  2652. blankOption.setAttribute('value', 'blank');
  2653. mxUtils.write(blankOption, mxResources.get('makeCopy'));
  2654. editSelect.appendChild(blankOption);
  2655. var customOption = document.createElement('option');
  2656. customOption.setAttribute('value', 'custom');
  2657. mxUtils.write(customOption, mxResources.get('custom') + '...');
  2658. editSelect.appendChild(customOption);
  2659. div.appendChild(editSelect);
  2660. mxEvent.addListener(editSelect, 'change', mxUtils.bind(this, function()
  2661. {
  2662. if (editSelect.value == 'custom')
  2663. {
  2664. var dlg2 = new FilenameDialog(this, editUrl, mxResources.get('ok'), function(value)
  2665. {
  2666. if (value != null)
  2667. {
  2668. editUrl = value;
  2669. }
  2670. else
  2671. {
  2672. editSelect.value = 'blank';
  2673. }
  2674. }, mxResources.get('url'), null, null, null, null, function()
  2675. {
  2676. editSelect.value = 'blank';
  2677. });
  2678. this.showDialog(dlg2.container, 300, 80, true, false);
  2679. dlg2.init();
  2680. }
  2681. }));
  2682. mxEvent.addListener(edit, 'change', mxUtils.bind(this, function()
  2683. {
  2684. if (edit.checked && (lightbox == null || lightbox.checked))
  2685. {
  2686. editSelect.removeAttribute('disabled');
  2687. }
  2688. else
  2689. {
  2690. editSelect.setAttribute('disabled', 'disabled');
  2691. }
  2692. }));
  2693. mxUtils.br(div);
  2694. return {
  2695. getLink: function()
  2696. {
  2697. return (edit.checked) ? ((editSelect.value === 'blank') ? '_blank' : editUrl) : null;
  2698. },
  2699. getEditInput: function()
  2700. {
  2701. return edit;
  2702. },
  2703. getEditSelect: function()
  2704. {
  2705. return editSelect;
  2706. }
  2707. };
  2708. }
  2709. /**
  2710. *
  2711. */
  2712. EditorUi.prototype.addLinkSection = function(div, showFrameOption)
  2713. {
  2714. mxUtils.write(div, mxResources.get('links') + ':');
  2715. var linkSelect = document.createElement('select');
  2716. linkSelect.style.width = '100px';
  2717. linkSelect.style.marginLeft = '8px';
  2718. linkSelect.style.marginRight = '10px';
  2719. linkSelect.className = 'geBtn';
  2720. var autoOption = document.createElement('option');
  2721. autoOption.setAttribute('value', 'auto');
  2722. mxUtils.write(autoOption, mxResources.get('automatic'));
  2723. linkSelect.appendChild(autoOption);
  2724. var blankOption = document.createElement('option');
  2725. blankOption.setAttribute('value', 'blank');
  2726. mxUtils.write(blankOption, mxResources.get('openInNewWindow'));
  2727. linkSelect.appendChild(blankOption);
  2728. var selfOption = document.createElement('option');
  2729. selfOption.setAttribute('value', 'self');
  2730. mxUtils.write(selfOption, mxResources.get('openInThisWindow'));
  2731. linkSelect.appendChild(selfOption);
  2732. if (showFrameOption)
  2733. {
  2734. var frameOption = document.createElement('option');
  2735. frameOption.setAttribute('value', 'frame');
  2736. mxUtils.write(frameOption, mxResources.get('openInThisWindow') +
  2737. ' (' + mxResources.get('iframe') + ')');
  2738. linkSelect.appendChild(frameOption);
  2739. }
  2740. div.appendChild(linkSelect);
  2741. mxUtils.write(div, mxResources.get('borderColor') + ':');
  2742. var linkColor = '#0000ff';
  2743. var linkButton = null;
  2744. function updateLinkColor()
  2745. {
  2746. linkButton.innerHTML = '<div style="width:100%;height:100%;box-sizing:border-box;' +
  2747. ((linkColor != null && linkColor != mxConstants.NONE) ?
  2748. 'border:1px solid black;background-color:' + linkColor :
  2749. 'background-position:center center;background-repeat:no-repeat;' +
  2750. 'background-image:url(\'' + Dialog.prototype.closeImage + '\')') + ';"></div>';
  2751. };
  2752. linkButton = mxUtils.button('', mxUtils.bind(this, function(evt)
  2753. {
  2754. this.pickColor(linkColor || 'none', function(color)
  2755. {
  2756. linkColor = color;
  2757. updateLinkColor();
  2758. });
  2759. mxEvent.consume(evt);
  2760. }));
  2761. updateLinkColor();
  2762. linkButton.style.padding = (mxClient.IS_FF) ? '4px 2px 4px 2px' : '4px';
  2763. linkButton.style.marginLeft = '4px';
  2764. linkButton.style.height = '22px';
  2765. linkButton.style.width = '22px';
  2766. linkButton.style.position = 'relative';
  2767. linkButton.style.top = (mxClient.IS_IE || mxClient.IS_IE11 || mxClient.IS_EDGE) ? '6px' : '1px';
  2768. linkButton.className = 'geColorBtn';
  2769. div.appendChild(linkButton);
  2770. mxUtils.br(div);
  2771. return {
  2772. getColor: function()
  2773. {
  2774. return linkColor;
  2775. },
  2776. getTarget: function()
  2777. {
  2778. return linkSelect.value;
  2779. },
  2780. focus: function()
  2781. {
  2782. linkSelect.focus();
  2783. }
  2784. };
  2785. }
  2786. /**
  2787. *
  2788. */
  2789. EditorUi.prototype.createLink = function(linkTarget, linkColor, allPages, lightbox, editLink, layers, url, ignoreFile)
  2790. {
  2791. var file = this.getCurrentFile();
  2792. var params = [];
  2793. if (lightbox)
  2794. {
  2795. params.push('lightbox=1');
  2796. if (linkTarget != 'auto')
  2797. {
  2798. params.push('target=' + linkTarget);
  2799. }
  2800. if (linkColor != null && linkColor != mxConstants.NONE)
  2801. {
  2802. params.push('highlight=' + ((linkColor.charAt(0) == '#') ? linkColor.substring(1) : linkColor));
  2803. }
  2804. if (editLink != null && editLink.length > 0)
  2805. {
  2806. params.push('edit=' + encodeURIComponent(editLink));
  2807. }
  2808. if (layers)
  2809. {
  2810. params.push('layers=1');
  2811. }
  2812. if (this.editor.graph.foldingEnabled)
  2813. {
  2814. params.push('nav=1');
  2815. }
  2816. }
  2817. if (allPages && this.pages != null && this.currentPage != null)
  2818. {
  2819. for (var i = 0; i < this.pages.length; i++)
  2820. {
  2821. if (this.pages[i] == this.currentPage)
  2822. {
  2823. if (i > 0)
  2824. {
  2825. params.push('page=' + i);
  2826. }
  2827. break;
  2828. }
  2829. }
  2830. }
  2831. var data = '';
  2832. var addTitle = true;
  2833. if (url != null)
  2834. {
  2835. data = '#U' + encodeURIComponent(url);
  2836. }
  2837. else
  2838. {
  2839. var file = this.getCurrentFile();
  2840. // Fallback to non-public URL for Drive files
  2841. if (!ignoreFile && file != null && file.constructor == window.DriveFile)
  2842. {
  2843. data = '#' + file.getHash();
  2844. addTitle = false;
  2845. }
  2846. else
  2847. {
  2848. data = '#R' + encodeURIComponent((allPages) ?
  2849. this.getFileData(true, null, null, null, null, null, null, true) :
  2850. this.editor.graph.compress(mxUtils.getXml(this.editor.getGraphXml())))
  2851. }
  2852. }
  2853. if (addTitle && file != null && file.getTitle() != null && file.getTitle() != this.defaultFilename)
  2854. {
  2855. params.push('title=' + encodeURIComponent(file.getTitle()));
  2856. }
  2857. return ((mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) ? 'https://www.draw.io/' : 'https://' + location.host + '/') +
  2858. ((params.length > 0) ? '?' + params.join('&') : '') + data;
  2859. };
  2860. /**
  2861. *
  2862. */
  2863. EditorUi.prototype.createHtml = function(publicUrl, zoomEnabled, initialZoom, linkTarget,
  2864. linkColor, fit, allPages, layers, lightbox, editLink, fn)
  2865. {
  2866. var s = this.getBasenames();
  2867. var data = {};
  2868. if (linkColor != '' && linkColor != mxConstants.NONE)
  2869. {
  2870. data.highlight = linkColor;
  2871. }
  2872. if (linkTarget !== 'auto')
  2873. {
  2874. data.target = linkTarget;
  2875. }
  2876. if (!lightbox)
  2877. {
  2878. data.lightbox = false;
  2879. }
  2880. data.nav = this.editor.graph.foldingEnabled;
  2881. var zoom = parseInt(initialZoom);
  2882. if (!isNaN(zoom) && zoom != 100)
  2883. {
  2884. data.zoom = zoom / 100;
  2885. }
  2886. var tb = [];
  2887. if (allPages)
  2888. {
  2889. tb.push('pages');
  2890. data.resize = true;
  2891. if (this.pages != null && this.currentPage != null)
  2892. {
  2893. data.page = mxUtils.indexOf(this.pages, this.currentPage);
  2894. }
  2895. }
  2896. if (zoomEnabled)
  2897. {
  2898. tb.push('zoom');
  2899. data.resize = true;
  2900. }
  2901. if (layers)
  2902. {
  2903. tb.push('layers');
  2904. }
  2905. if (tb.length > 0)
  2906. {
  2907. if (lightbox)
  2908. {
  2909. tb.push('lightbox');
  2910. }
  2911. data.toolbar = tb.join(' ');
  2912. }
  2913. if (editLink != null && editLink.length > 0)
  2914. {
  2915. data.edit = editLink;
  2916. }
  2917. if (publicUrl != null)
  2918. {
  2919. data.url = publicUrl;
  2920. }
  2921. else
  2922. {
  2923. data.xml = this.getFileData(true, null, null, null, null, !allPages);
  2924. }
  2925. var value = '<div class="mxgraph" style="' +
  2926. ((fit) ? 'max-width:100%;' : '') +
  2927. ((tb != '') ? 'border:1px solid transparent;' : '') +
  2928. '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>';
  2929. var sParam = (s.length > 0) ? 's=' + s.join(';') : '';
  2930. var fetchParam = (publicUrl != null) ? 'fetch=' + encodeURIComponent(publicUrl) : '';
  2931. var s2 = (sParam.length > 0 || fetchParam.length > 0) ?
  2932. (((urlParams['dev'] == '1') ?
  2933. 'https://test.draw.io/embed2.js?dev=1&' + sParam :
  2934. 'https://www.draw.io/embed2.js?' + sParam)) + '&' + fetchParam :
  2935. (((urlParams['dev'] == '1') ?
  2936. 'https://test.draw.io/js/viewer.min.js' :
  2937. 'https://www.draw.io/js/viewer.min.js'));
  2938. var scr = '<script type="text/javascript" src="' + s2 + '"></script>';
  2939. fn(value, scr);
  2940. };
  2941. /**
  2942. *
  2943. */
  2944. EditorUi.prototype.showHtmlDialog = function(btnLabel, helpLink, publicUrl, fn)
  2945. {
  2946. var div = document.createElement('div');
  2947. div.style.whiteSpace = 'nowrap';
  2948. var graph = this.editor.graph;
  2949. var hd = document.createElement('h3');
  2950. mxUtils.write(hd, mxResources.get('html'));
  2951. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:12px';
  2952. div.appendChild(hd);
  2953. var radioSection = document.createElement('div');
  2954. radioSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:8px;margin-bottom:12px;';
  2955. var publicUrlRadio = document.createElement('input');
  2956. publicUrlRadio.style.cssText = 'margin-right:8px;margin-top:8px;margin-bottom:8px;';
  2957. publicUrlRadio.setAttribute('value', 'url');
  2958. publicUrlRadio.setAttribute('type', 'radio');
  2959. publicUrlRadio.setAttribute('name', 'type-embedhtmldialog');
  2960. var copyRadio = publicUrlRadio.cloneNode(true);
  2961. copyRadio.setAttribute('value', 'copy');
  2962. radioSection.appendChild(copyRadio);
  2963. var span = document.createElement('span');
  2964. mxUtils.write(span, mxResources.get('includeCopyOfMyDiagram'));
  2965. radioSection.appendChild(span);
  2966. mxUtils.br(radioSection);
  2967. radioSection.appendChild(publicUrlRadio);
  2968. var span = document.createElement('span');
  2969. mxUtils.write(span, mxResources.get('publicDiagramUrl'));
  2970. radioSection.appendChild(span);
  2971. var file = this.getCurrentFile();
  2972. if (publicUrl == null && file != null && file.constructor == window.DriveFile)
  2973. {
  2974. var testLink = document.createElement('a');
  2975. testLink.style.paddingLeft = '12px';
  2976. testLink.style.color = 'gray';
  2977. testLink.setAttribute('href', 'javascript:void(0);');
  2978. mxUtils.write(testLink, mxResources.get('share'));
  2979. radioSection.appendChild(testLink);
  2980. mxEvent.addListener(testLink, 'click', mxUtils.bind(this, function()
  2981. {
  2982. this.hideDialog();
  2983. this.drive.showPermissions(file.getId());
  2984. }));
  2985. }
  2986. copyRadio.setAttribute('checked', 'checked');
  2987. if (publicUrl == null)
  2988. {
  2989. publicUrlRadio.setAttribute('disabled', 'disabled');
  2990. }
  2991. div.appendChild(radioSection);
  2992. var linkSection = this.addLinkSection(div);
  2993. var zoom = this.addCheckbox(div, mxResources.get('zoom'), true, null, true);
  2994. mxUtils.write(div, ':');
  2995. var zoomInput = document.createElement('input');
  2996. zoomInput.setAttribute('type', 'text');
  2997. zoomInput.style.marginRight = '16px';
  2998. zoomInput.style.width = '60px';
  2999. zoomInput.style.marginLeft = '4px';
  3000. zoomInput.style.marginRight = '12px';
  3001. zoomInput.value = '100%';
  3002. div.appendChild(zoomInput);
  3003. var fit = this.addCheckbox(div, mxResources.get('fit'), true);
  3004. var hasPages = this.pages != null && this.pages.length > 1;
  3005. var allPages = allPages = this.addCheckbox(div, mxResources.get('allPages'), hasPages, !hasPages);
  3006. var layers = this.addCheckbox(div, mxResources.get('layers'), true);
  3007. var lightbox = this.addCheckbox(div, mxResources.get('lightbox'), true);
  3008. var editSection = this.addEditButton(div, lightbox);
  3009. var edit = editSection.getEditInput();
  3010. edit.style.marginBottom = '16px';
  3011. mxEvent.addListener(lightbox, 'change', function()
  3012. {
  3013. if (lightbox.checked)
  3014. {
  3015. edit.removeAttribute('disabled');
  3016. }
  3017. else
  3018. {
  3019. edit.setAttribute('disabled', 'disabled');
  3020. }
  3021. if (edit.checked && lightbox.checked)
  3022. {
  3023. editSection.getEditSelect().removeAttribute('disabled');
  3024. }
  3025. else
  3026. {
  3027. editSection.getEditSelect().setAttribute('disabled', 'disabled');
  3028. }
  3029. });
  3030. var dlg = new CustomDialog(this, div, mxUtils.bind(this, function()
  3031. {
  3032. fn((publicUrlRadio.checked) ? publicUrl : null, zoom.checked, zoomInput.value, linkSection.getTarget(),
  3033. linkSection.getColor(), fit.checked, allPages.checked, layers.checked, lightbox.checked,
  3034. editSection.getLink());
  3035. }), null, btnLabel, helpLink);
  3036. this.showDialog(dlg.container, 340, 360, true, true);
  3037. copyRadio.focus();
  3038. };
  3039. /**
  3040. *
  3041. */
  3042. EditorUi.prototype.showPublishLinkDialog = function(title, hideShare, width, height, fn, showFrameOption)
  3043. {
  3044. var div = document.createElement('div');
  3045. div.style.whiteSpace = 'nowrap';
  3046. var graph = this.editor.graph;
  3047. var hd = document.createElement('h3');
  3048. mxUtils.write(hd, title || mxResources.get('link'));
  3049. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:12px';
  3050. div.appendChild(hd);
  3051. var file = this.getCurrentFile();
  3052. var helpLink = 'https://desk.draw.io/support/solutions/articles/16000051941';
  3053. var dy = 0;
  3054. if (file != null && file.constructor == window.DriveFile && !hideShare)
  3055. {
  3056. dy = 80;
  3057. helpLink = 'https://desk.draw.io/support/solutions/articles/16000039384';
  3058. var hintSection = document.createElement('div');
  3059. hintSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:14px;padding-top:6px;margin-bottom:14px;text-align:center;';
  3060. var text = document.createElement('div');
  3061. text.style.whiteSpace = 'normal';
  3062. mxUtils.write(text, mxResources.get('linkAccountRequired'));
  3063. hintSection.appendChild(text);
  3064. var shareBtn = mxUtils.button(mxResources.get('share'), mxUtils.bind(this, function()
  3065. {
  3066. this.drive.showPermissions(file.getId());
  3067. }));
  3068. shareBtn.style.marginTop = '12px';
  3069. shareBtn.className = 'geBtn';
  3070. hintSection.appendChild(shareBtn);
  3071. div.appendChild(hintSection);
  3072. var testLink = document.createElement('a');
  3073. testLink.style.paddingLeft = '12px';
  3074. testLink.style.color = 'gray';
  3075. testLink.style.fontSize = '11px';
  3076. testLink.setAttribute('href', 'javascript:void(0);');
  3077. mxUtils.write(testLink, mxResources.get('check'));
  3078. hintSection.appendChild(testLink);
  3079. mxEvent.addListener(testLink, 'click', mxUtils.bind(this, function()
  3080. {
  3081. if (this.spinner.spin(document.body, mxResources.get('loading')))
  3082. {
  3083. this.getPublicUrl(this.getCurrentFile(), mxUtils.bind(this, function(url)
  3084. {
  3085. this.spinner.stop();
  3086. var dlg = new ErrorDialog(this, null, mxResources.get((url != null) ?
  3087. 'diagramIsPublic' : 'diagramIsNotPublic'), mxResources.get('ok'));
  3088. this.showDialog(dlg.container, 300, 80, true, false);
  3089. dlg.init();
  3090. }));
  3091. }
  3092. }));
  3093. }
  3094. var widthInput = null;
  3095. var heightInput = null;
  3096. if (width != null || height != null)
  3097. {
  3098. dy += 30;
  3099. mxUtils.write(div, mxResources.get('width') + ':');
  3100. widthInput = document.createElement('input');
  3101. widthInput.setAttribute('type', 'text');
  3102. widthInput.style.marginRight = '16px';
  3103. widthInput.style.width = '50px';
  3104. widthInput.style.marginLeft = '6px';
  3105. widthInput.style.marginRight = '16px';
  3106. widthInput.style.marginBottom = '10px';
  3107. widthInput.value = '100%';
  3108. div.appendChild(widthInput);
  3109. mxUtils.write(div, mxResources.get('height') + ':');
  3110. heightInput = document.createElement('input');
  3111. heightInput.setAttribute('type', 'text');
  3112. heightInput.style.width = '50px';
  3113. heightInput.style.marginLeft = '6px';
  3114. heightInput.style.marginBottom = '10px';
  3115. heightInput.value = height + 'px';
  3116. div.appendChild(heightInput);
  3117. mxUtils.br(div);
  3118. }
  3119. var linkSection = this.addLinkSection(div, showFrameOption);
  3120. var hasPages = this.pages != null && this.pages.length > 1;
  3121. var allPages = null;
  3122. if (file == null || file.constructor != window.DriveFile || hideShare)
  3123. {
  3124. allPages = this.addCheckbox(div, mxResources.get('allPages'), hasPages, !hasPages);
  3125. }
  3126. var lightbox = this.addCheckbox(div, mxResources.get('lightbox'), true);
  3127. var editSection = this.addEditButton(div, lightbox);
  3128. var edit = editSection.getEditInput();
  3129. var layers = this.addCheckbox(div, mxResources.get('layers'), true);
  3130. layers.style.marginLeft = edit.style.marginLeft;
  3131. layers.style.marginBottom = '16px';
  3132. layers.style.marginTop = '8px';
  3133. mxEvent.addListener(lightbox, 'change', function()
  3134. {
  3135. if (lightbox.checked)
  3136. {
  3137. layers.removeAttribute('disabled');
  3138. edit.removeAttribute('disabled');
  3139. }
  3140. else
  3141. {
  3142. layers.setAttribute('disabled', 'disabled');
  3143. edit.setAttribute('disabled', 'disabled');
  3144. }
  3145. if (edit.checked && lightbox.checked)
  3146. {
  3147. editSection.getEditSelect().removeAttribute('disabled');
  3148. }
  3149. else
  3150. {
  3151. editSection.getEditSelect().setAttribute('disabled', 'disabled');
  3152. }
  3153. });
  3154. var dlg = new CustomDialog(this, div, mxUtils.bind(this, function()
  3155. {
  3156. fn(linkSection.getTarget(), linkSection.getColor(),
  3157. (allPages == null) ? true : allPages.checked,
  3158. lightbox.checked, editSection.getLink(),
  3159. layers.checked, (widthInput != null) ? widthInput.value : null,
  3160. (heightInput != null) ? heightInput.value : null);
  3161. }), null, mxResources.get('create'), helpLink);
  3162. this.showDialog(dlg.container, 340, 246 + dy, true, true);
  3163. if (widthInput != null)
  3164. {
  3165. widthInput.focus();
  3166. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  3167. {
  3168. widthInput.select();
  3169. }
  3170. else
  3171. {
  3172. document.execCommand('selectAll', false, null);
  3173. }
  3174. }
  3175. else
  3176. {
  3177. linkSection.focus();
  3178. }
  3179. };
  3180. /**
  3181. *
  3182. */
  3183. EditorUi.prototype.showRemoteExportDialog = function(btnLabel, helpLink, callback, hideInclude)
  3184. {
  3185. var div = document.createElement('div');
  3186. div.style.whiteSpace = 'nowrap';
  3187. var hd = document.createElement('h3');
  3188. mxUtils.write(hd, mxResources.get('image'));
  3189. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  3190. div.appendChild(hd);
  3191. var selection = this.addCheckbox(div, mxResources.get('selectionOnly'), false,
  3192. this.editor.graph.isSelectionEmpty());
  3193. var include = (hideInclude) ? null : this.addCheckbox(div, mxResources.get('includeCopyOfMyDiagram'), true);
  3194. if (include != null)
  3195. {
  3196. include.style.marginBottom = '16px';
  3197. }
  3198. var dlg = new CustomDialog(this, div, mxUtils.bind(this, function()
  3199. {
  3200. callback(!selection.checked, (include != null) ? include.checked : false);
  3201. }), null, btnLabel, helpLink);
  3202. this.showDialog(dlg.container, 300, (hideInclude) ? 100 : 146, true, true);
  3203. };
  3204. /**
  3205. *
  3206. */
  3207. EditorUi.prototype.showExportDialog = function(title, embedOption, btnLabel, helpLink, callback,
  3208. cropOption, defaultInclude, format)
  3209. {
  3210. defaultInclude = (defaultInclude != null) ? defaultInclude : true;
  3211. var div = document.createElement('div');
  3212. div.style.whiteSpace = 'nowrap';
  3213. var graph = this.editor.graph;
  3214. var height = (format == 'jpeg') ? 170 : 280;
  3215. var hd = document.createElement('h3');
  3216. mxUtils.write(hd, title);
  3217. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:10px';
  3218. div.appendChild(hd);
  3219. mxUtils.write(div, mxResources.get('zoom') + ':');
  3220. var zoomInput = document.createElement('input');
  3221. zoomInput.setAttribute('type', 'text');
  3222. zoomInput.style.marginRight = '16px';
  3223. zoomInput.style.width = '60px';
  3224. zoomInput.style.marginLeft = '4px';
  3225. zoomInput.style.marginRight = '12px';
  3226. zoomInput.value = this.lastExportZoom || '100%';
  3227. div.appendChild(zoomInput);
  3228. mxUtils.write(div, mxResources.get('borderWidth') + ':');
  3229. var borderInput = document.createElement('input');
  3230. borderInput.setAttribute('type', 'text');
  3231. borderInput.style.marginRight = '16px';
  3232. borderInput.style.width = '60px';
  3233. borderInput.style.marginLeft = '4px';
  3234. borderInput.value = this.lastExportBorder || '0';
  3235. div.appendChild(borderInput);
  3236. mxUtils.br(div);
  3237. var transparent = this.addCheckbox(div, mxResources.get('transparentBackground'),
  3238. graph.background == mxConstants.NONE || graph.background == null, null, null, format != 'jpeg');
  3239. var selection = this.addCheckbox(div, mxResources.get('selectionOnly'),
  3240. false, graph.isSelectionEmpty());
  3241. var cb6 = document.createElement('input');
  3242. cb6.style.marginTop = '16px';
  3243. cb6.style.marginRight = '8px';
  3244. cb6.style.marginLeft = '24px';
  3245. cb6.setAttribute('disabled', 'disabled');
  3246. cb6.setAttribute('type', 'checkbox');
  3247. if (cropOption)
  3248. {
  3249. div.appendChild(cb6);
  3250. mxUtils.write(div, mxResources.get('crop'));
  3251. mxUtils.br(div);
  3252. height += 26;
  3253. mxEvent.addListener(selection, 'change', function()
  3254. {
  3255. if (selection.checked)
  3256. {
  3257. cb6.removeAttribute('disabled');
  3258. }
  3259. else
  3260. {
  3261. cb6.setAttribute('disabled', 'disabled');
  3262. }
  3263. });
  3264. }
  3265. if (!graph.isSelectionEmpty())
  3266. {
  3267. cb6.setAttribute('checked', 'checked');
  3268. cb6.defaultChecked = true;
  3269. }
  3270. var shadow = this.addCheckbox(div, mxResources.get('shadow'), graph.shadowVisible);
  3271. var cb5 = document.createElement('input');
  3272. cb5.style.marginTop = '16px';
  3273. cb5.style.marginRight = '8px';
  3274. cb5.setAttribute('type', 'checkbox');
  3275. if (this.isOffline() || !this.canvasSupported)
  3276. {
  3277. cb5.setAttribute('disabled', 'disabled');
  3278. }
  3279. if (embedOption)
  3280. {
  3281. div.appendChild(cb5);
  3282. mxUtils.write(div, mxResources.get('embedImages'));
  3283. mxUtils.br(div);
  3284. height += 26;
  3285. }
  3286. var include = this.addCheckbox(div, mxResources.get('includeCopyOfMyDiagram'), defaultInclude, null, null, format != 'jpeg');
  3287. var hasPages = this.pages != null && this.pages.length > 1;
  3288. var allPages = this.addCheckbox(div, (hasPages) ? mxResources.get('allPages') : '', hasPages, !hasPages, null, format != 'jpeg');
  3289. allPages.style.marginLeft = '24px';
  3290. allPages.style.marginBottom = '16px';
  3291. if (!hasPages)
  3292. {
  3293. allPages.style.visibility = 'hidden';
  3294. }
  3295. mxEvent.addListener(include, 'change', function()
  3296. {
  3297. if (include.checked && hasPages)
  3298. {
  3299. allPages.removeAttribute('disabled');
  3300. }
  3301. else
  3302. {
  3303. allPages.setAttribute('disabled', 'disabled');
  3304. }
  3305. });
  3306. if (!defaultInclude || !hasPages)
  3307. {
  3308. allPages.setAttribute('disabled', 'disabled');
  3309. }
  3310. var dlg = new CustomDialog(this, div, mxUtils.bind(this, function()
  3311. {
  3312. this.lastExportBorder = borderInput.value;
  3313. this.lastExportZoom = zoomInput.value;
  3314. callback(zoomInput.value, transparent.checked, !selection.checked, shadow.checked,
  3315. include.checked, cb5.checked, borderInput.value, cb6.checked, !allPages.checked);
  3316. }), null, btnLabel, helpLink);
  3317. this.showDialog(dlg.container, 320, height, true, true);
  3318. zoomInput.focus();
  3319. if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  3320. {
  3321. zoomInput.select();
  3322. }
  3323. else
  3324. {
  3325. document.execCommand('selectAll', false, null);
  3326. }
  3327. };
  3328. /**
  3329. *
  3330. */
  3331. EditorUi.prototype.showEmbedImageDialog = function(fn, title, imageLabel, shadowEnabled, helpLink)
  3332. {
  3333. var div = document.createElement('div');
  3334. div.style.whiteSpace = 'nowrap';
  3335. var graph = this.editor.graph;
  3336. if (title != null)
  3337. {
  3338. var hd = document.createElement('h3');
  3339. mxUtils.write(hd, title);
  3340. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  3341. div.appendChild(hd);
  3342. }
  3343. var fit = this.addCheckbox(div, mxResources.get('fit'), true);
  3344. var shadow = this.addCheckbox(div, mxResources.get('shadow'),
  3345. graph.shadowVisible && shadowEnabled, !shadowEnabled);
  3346. var image = this.addCheckbox(div, imageLabel);
  3347. var lightbox = this.addCheckbox(div, mxResources.get('lightbox'), true);
  3348. var editSection = this.addEditButton(div, lightbox);
  3349. var edit = editSection.getEditInput();
  3350. var hasLayers = graph.model.getChildCount(graph.model.getRoot()) > 1;
  3351. var layers = this.addCheckbox(div, mxResources.get('layers'), hasLayers, !hasLayers);
  3352. layers.style.marginLeft = edit.style.marginLeft;
  3353. layers.style.marginBottom = '12px';
  3354. layers.style.marginTop = '8px';
  3355. mxEvent.addListener(lightbox, 'change', function()
  3356. {
  3357. if (lightbox.checked)
  3358. {
  3359. if (hasLayers)
  3360. {
  3361. layers.removeAttribute('disabled');
  3362. }
  3363. edit.removeAttribute('disabled');
  3364. }
  3365. else
  3366. {
  3367. layers.setAttribute('disabled', 'disabled');
  3368. edit.setAttribute('disabled', 'disabled');
  3369. }
  3370. if (edit.checked && lightbox.checked)
  3371. {
  3372. editSection.getEditSelect().removeAttribute('disabled');
  3373. }
  3374. else
  3375. {
  3376. editSection.getEditSelect().setAttribute('disabled', 'disabled');
  3377. }
  3378. });
  3379. var dlg = new CustomDialog(this, div, mxUtils.bind(this, function()
  3380. {
  3381. fn(fit.checked, shadow.checked, image.checked, lightbox.checked,
  3382. editSection.getLink(), layers.checked);
  3383. }), null, mxResources.get('embed'), helpLink);
  3384. this.showDialog(dlg.container, 280, 280, true, true);
  3385. };
  3386. /**
  3387. *
  3388. */
  3389. EditorUi.prototype.createEmbedImage = function(fit, shadow, retina, lightbox, edit, layers, fn, err)
  3390. {
  3391. var bounds = this.editor.graph.getGraphBounds();
  3392. function doUpdate(dataUri)
  3393. {
  3394. var onclick = ' ';
  3395. var css = '';
  3396. // Adds double click handling
  3397. if (lightbox)
  3398. {
  3399. // KNOWN: Message passing does not seem to work in IE11
  3400. 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(" +
  3401. "img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1" +
  3402. ((edit) ? "&edit=_blank" : "") +
  3403. ((layers) ? '&layers=1' : '') + "');}})(this);\"";
  3404. css += 'cursor:pointer;';
  3405. }
  3406. if (fit)
  3407. {
  3408. css += 'max-width:100%;';
  3409. }
  3410. var atts = '';
  3411. if (retina)
  3412. {
  3413. atts = ' width="' + Math.round(bounds.width) + '" height="' + Math.round(bounds.height) + '"';
  3414. }
  3415. fn('<img src="' + dataUri + '"' + atts + ((css != '') ? ' style="' + css + '"' : '') + onclick + '/>');
  3416. };
  3417. if (this.isExportToCanvas())
  3418. {
  3419. var scale = 1;
  3420. var ignoreSelection = true;
  3421. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  3422. {
  3423. var xml = (lightbox) ? this.getFileData(true) : null;
  3424. var data = this.createImageDataUri(canvas, xml, 'png');
  3425. doUpdate(data);
  3426. }), null, null, null, mxUtils.bind(this, function(e)
  3427. {
  3428. err({message: mxResources.get('unknownError')});
  3429. }), null, true, (retina) ? 2 : 1, null, shadow);
  3430. }
  3431. else
  3432. {
  3433. var data = this.getFileData(true);
  3434. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  3435. {
  3436. var size = '';
  3437. if (retina)
  3438. {
  3439. size = '&w=' + Math.round(2 * bounds.width) +
  3440. '&h=' + Math.round(2 * bounds.height);
  3441. }
  3442. var embed = (lightbox) ? '1' : '0';
  3443. var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
  3444. '&base64=1&embedXml=' + embed + size + '&xml=' +
  3445. encodeURIComponent(data));
  3446. // LATER: Updates on each change, add a delay
  3447. req.send(mxUtils.bind(this, function()
  3448. {
  3449. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3450. {
  3451. // Fixes possible "incorrect function" for select() on
  3452. // DOM node which is no longer in document with IE11
  3453. doUpdate('data:image/png;base64,' + req.getText());
  3454. }
  3455. else
  3456. {
  3457. err({message: mxResources.get('unknownError')});
  3458. }
  3459. }));
  3460. }
  3461. else
  3462. {
  3463. err({message: mxResources.get('drawingTooLarge')});
  3464. }
  3465. }
  3466. };
  3467. /**
  3468. *
  3469. */
  3470. EditorUi.prototype.createEmbedSvg = function(fit, shadow, image, lightbox, edit, layers, fn)
  3471. {
  3472. var svgRoot = this.editor.graph.getSvg();
  3473. // Keeps hashtag links on same page
  3474. var links = svgRoot.getElementsByTagName('a');
  3475. if (links != null)
  3476. {
  3477. for (var i = 0; i < links.length; i++)
  3478. {
  3479. var href = links[i].getAttribute('href');
  3480. if (href != null && href.charAt(0) == '#' &&
  3481. links[i].getAttribute('target') == '_blank')
  3482. {
  3483. links[i].removeAttribute('target');
  3484. }
  3485. }
  3486. }
  3487. if (lightbox)
  3488. {
  3489. svgRoot.setAttribute('content', this.getFileData(true));
  3490. }
  3491. // Adds shadow filter
  3492. if (shadow)
  3493. {
  3494. this.editor.graph.addSvgShadow(svgRoot);
  3495. }
  3496. // SVG inside image tag
  3497. if (image)
  3498. {
  3499. var onclick = ' ';
  3500. var css = '';
  3501. // Adds double click handling
  3502. if (lightbox)
  3503. {
  3504. // KNOWN: Message passing does not seem to work in IE11
  3505. 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(" +
  3506. "img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1" +
  3507. ((edit) ? "&edit=_blank" : "") + ((layers) ? '&layers=1' : '') + "');}})(this);\"";
  3508. css += 'cursor:pointer;';
  3509. }
  3510. if (fit)
  3511. {
  3512. css += 'max-width:100%;';
  3513. }
  3514. // Images inside IMG don't seem to work so embed them all
  3515. this.convertImages(svgRoot, mxUtils.bind(this, function(svgRoot)
  3516. {
  3517. fn('<img src="' + this.createSvgDataUri(mxUtils.getXml(svgRoot)) + '"' +
  3518. ((css != '') ? ' style="' + css + '"' : '') + onclick + '/>');
  3519. }));
  3520. }
  3521. else
  3522. {
  3523. var css = '';
  3524. // Adds double click handling
  3525. if (lightbox)
  3526. {
  3527. // KNOWN: Message passing does not seem to work in IE11
  3528. var js = "(function(svg){var src=window.event.target||window.event.srcElement;" +
  3529. // Ignores link events
  3530. "while (src!=null&&src.nodeName.toLowerCase()!='a'){src=src.parentNode;}if(src==null)" +
  3531. // Focus existing lightbox
  3532. "{if(svg.wnd!=null&&!svg.wnd.closed){svg.wnd.focus();}else{var r=function(evt){" +
  3533. // Message handling
  3534. "if(evt.data=='ready'&&evt.source==svg.wnd){svg.wnd.postMessage(decodeURIComponent(" +
  3535. "svg.getAttribute('content')),'*');window.removeEventListener('message',r);}};" +
  3536. "window.addEventListener('message',r);" +
  3537. // Opens lightbox window
  3538. "svg.wnd=window.open('https://www.draw.io/?client=1&lightbox=1" +
  3539. ((edit) ? "&edit=_blank" : "") + ((layers) ? '&layers=1' : '') + "');}}})(this);";
  3540. svgRoot.setAttribute('onclick', js);
  3541. css += 'cursor:pointer;';
  3542. }
  3543. // Adds responsive size
  3544. if (fit)
  3545. {
  3546. var w = parseInt(svgRoot.getAttribute('width'));
  3547. var h = parseInt(svgRoot.getAttribute('height'));
  3548. svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  3549. css += 'max-width:100%;max-height:' + h + 'px;';
  3550. svgRoot.removeAttribute('height');
  3551. }
  3552. if (css != '')
  3553. {
  3554. svgRoot.setAttribute('style', css);
  3555. }
  3556. fn(mxUtils.getXml(svgRoot));
  3557. }
  3558. };
  3559. /**
  3560. * Translates this point by the given vector.
  3561. *
  3562. * @param {number} dx X-coordinate of the translation.
  3563. * @param {number} dy Y-coordinate of the translation.
  3564. */
  3565. EditorUi.prototype.timeSince = function(date)
  3566. {
  3567. var seconds = Math.floor((new Date() - date) / 1000);
  3568. var interval = Math.floor(seconds / 31536000);
  3569. if (interval > 1)
  3570. {
  3571. return interval + ' ' + mxResources.get('years');
  3572. }
  3573. interval = Math.floor(seconds / 2592000);
  3574. if (interval > 1)
  3575. {
  3576. return interval + ' ' + mxResources.get('months');
  3577. }
  3578. interval = Math.floor(seconds / 86400);
  3579. if (interval > 1)
  3580. {
  3581. return interval + ' ' + mxResources.get('days');
  3582. }
  3583. interval = Math.floor(seconds / 3600);
  3584. if (interval > 1)
  3585. {
  3586. return interval + ' ' + mxResources.get('hours');
  3587. }
  3588. interval = Math.floor(seconds / 60);
  3589. if (interval > 1)
  3590. {
  3591. return interval + ' ' + mxResources.get('minutes');
  3592. }
  3593. if (interval == 1)
  3594. {
  3595. return interval + ' ' + mxResources.get('minute');
  3596. }
  3597. return null;
  3598. };
  3599. /**
  3600. * Converts math in the given SVG
  3601. */
  3602. EditorUi.prototype.convertMath = function(graph, svgRoot, fixPosition, callback)
  3603. {
  3604. // FIXME: Only horizontal dash in output so better no conversion at all
  3605. if (false && graph.mathEnabled && typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  3606. {
  3607. // Workaround for lost gradients in Chrome after remove from DOM
  3608. var elts = svgRoot.getElementsByTagName('*');
  3609. for (var i = 0; i < elts.length; i++)
  3610. {
  3611. if (elts[i].getAttribute('id') != null)
  3612. {
  3613. elts[i].setAttribute('id', 'mxTemporaryPrefix-' + elts[i].getAttribute('id'));
  3614. }
  3615. }
  3616. // Temporarily attaches to DOM for rendering
  3617. svgRoot.style.visibility = 'hidden';
  3618. document.body.appendChild(svgRoot);
  3619. Editor.MathJaxRender(svgRoot);
  3620. MathJax.Hub.Queue(mxUtils.bind(this, function ()
  3621. {
  3622. // Removes from DOM
  3623. svgRoot.parentNode.removeChild(svgRoot);
  3624. svgRoot.style.visibility = '';
  3625. // Restores original IDs
  3626. for (var i = 0; i < elts.length; i++)
  3627. {
  3628. if (elts[i].getAttribute('id') != null)
  3629. {
  3630. elts[i].setAttribute('id', elts[i].getAttribute('id').substring('mxTemporaryPrefix-'.length));
  3631. }
  3632. }
  3633. // Keeping scale but moving translate only works for image export which
  3634. // is fine since we do not want the SVG export to contain a workaround.
  3635. // See https://github.com/mathjax/MathJax/issues/279
  3636. if (fixPosition && navigator.userAgent.indexOf('AppleWebKit/') >= 0)
  3637. {
  3638. var fo = svgRoot.getElementsByTagName('foreignObject');
  3639. for (var i = 0; i < fo.length; i++)
  3640. {
  3641. var tr = fo[i].parentNode.parentNode.getAttribute('transform');
  3642. var translate = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(tr);
  3643. fo[i].setAttribute('x', Math.round(translate[1]));
  3644. fo[i].setAttribute('y', Math.round(translate[2]));
  3645. // Must use translate for crisp rendering
  3646. fo[i].parentNode.parentNode.setAttribute('transform', 'translate(0.5,0.5)' + tr.substring(tr.indexOf(')') + 1));
  3647. }
  3648. }
  3649. callback();
  3650. }));
  3651. }
  3652. else
  3653. {
  3654. callback();
  3655. }
  3656. };
  3657. /**
  3658. * Returns the SVG of the diagram with embedded XML. If a callback function is
  3659. * used, the images are converted to data URIs.
  3660. */
  3661. EditorUi.prototype.getEmbeddedSvg = function(xml, graph, url, noHeader, callback, ignoreSelection, redirect)
  3662. {
  3663. var bg = graph.background;
  3664. if (bg == mxConstants.NONE)
  3665. {
  3666. bg = null;
  3667. }
  3668. // Sets or disables alternate text for foreignObjects. Disabling is needed
  3669. // because PhantomJS seems to ignore switch statements and paint all text.
  3670. var svgRoot = graph.getSvg(bg, null, null, null, null, ignoreSelection);
  3671. if (xml != null)
  3672. {
  3673. svgRoot.setAttribute('content', xml);
  3674. }
  3675. if (url != null)
  3676. {
  3677. svgRoot.setAttribute('resource', url);
  3678. }
  3679. // LATER: Click on SVG content to start editing
  3680. // if (redirect != null)
  3681. // {
  3682. // // TODO: Ignore anchor tag source for click event
  3683. // svgRoot.setAttribute('style', 'cursor:pointer;');
  3684. // svgRoot.setAttribute('onclick', 'window.location.href=\'' + redirect + '\';');
  3685. // }
  3686. if (callback != null)
  3687. {
  3688. this.convertImages(svgRoot, mxUtils.bind(this, function(svgRoot)
  3689. {
  3690. callback(((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  3691. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  3692. mxUtils.getXml(svgRoot));
  3693. }));
  3694. }
  3695. else
  3696. {
  3697. return ((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  3698. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  3699. mxUtils.getXml(svgRoot);
  3700. }
  3701. };
  3702. /**
  3703. *
  3704. */
  3705. EditorUi.prototype.exportImage = function(scale, transparentBackground, ignoreSelection, addShadow, editable, border, noCrop, currentPage, format)
  3706. {
  3707. format = (format != null) ? format : 'png';
  3708. if (this.spinner.spin(document.body, mxResources.get('exporting')))
  3709. {
  3710. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  3711. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  3712. // Caches images
  3713. if (this.thumbImageCache == null)
  3714. {
  3715. this.thumbImageCache = new Object();
  3716. }
  3717. try
  3718. {
  3719. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  3720. {
  3721. this.spinner.stop();
  3722. try
  3723. {
  3724. this.saveCanvas(canvas, (editable) ? this.getFileData(true, null,
  3725. null, null, ignoreSelection, currentPage) : null, format);
  3726. }
  3727. catch (e)
  3728. {
  3729. // Fallback to server-side image export
  3730. if (e.message == 'Invalid image')
  3731. {
  3732. this.downloadFile(format);
  3733. }
  3734. else
  3735. {
  3736. this.handleError(e);
  3737. }
  3738. }
  3739. }), null, this.thumbImageCache, null, mxUtils.bind(this, function(e)
  3740. {
  3741. this.spinner.stop();
  3742. this.handleError(e);
  3743. }), null, ignoreSelection, scale || 1, transparentBackground,
  3744. addShadow, null, null, border, noCrop);
  3745. }
  3746. catch (e)
  3747. {
  3748. this.spinner.stop();
  3749. this.handleError(e);
  3750. }
  3751. }
  3752. };
  3753. /**
  3754. * For the fontCSS to be applied when rendering images on canvas, the actual
  3755. * font data must be made available via a data URI encoding of the file.
  3756. */
  3757. EditorUi.prototype.loadFonts = function(then)
  3758. {
  3759. if (this.editor.fontCss != null && this.editor.resolvedFontCss == null)
  3760. {
  3761. var parts = this.editor.fontCss.split('url(');
  3762. var waiting = 0;
  3763. var fonts = {};
  3764. var finish = mxUtils.bind(this, function()
  3765. {
  3766. if (waiting == 0)
  3767. {
  3768. // Constructs string
  3769. var result = [parts[0]];
  3770. for (var j = 1; j < parts.length; j++)
  3771. {
  3772. var idx = parts[j].indexOf(')');
  3773. result.push('url(');
  3774. result.push(fonts[parts[j].substring(0, idx)]);
  3775. result.push(parts[j].substring(idx));
  3776. }
  3777. this.editor.resolvedFontCss = result.join('');
  3778. then();
  3779. }
  3780. });
  3781. if (parts.length > 0)
  3782. {
  3783. for (var i = 1; i < parts.length; i++)
  3784. {
  3785. var idx = parts[i].indexOf(')');
  3786. (mxUtils.bind(this, function(url)
  3787. {
  3788. if (fonts[url] == null)
  3789. {
  3790. // Mark font es being fetched and fetch it
  3791. fonts[url] = url;
  3792. waiting++;
  3793. var mime = 'application/x-font-ttf';
  3794. // See https://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts
  3795. if (/(\.svg)($|\?)/i.test(url))
  3796. {
  3797. mime = 'image/svg+xml';
  3798. }
  3799. else if (/(\.otf)($|\?)/i.test(url))
  3800. {
  3801. mime = 'application/x-font-opentype';
  3802. }
  3803. else if (/(\.woff)($|\?)/i.test(url))
  3804. {
  3805. mime = 'application/font-woff';
  3806. }
  3807. else if (/(\.woff2)($|\?)/i.test(url))
  3808. {
  3809. mime = 'application/font-woff2';
  3810. }
  3811. else if (/(\.eot)($|\?)/i.test(url))
  3812. {
  3813. mime = 'application/vnd.ms-fontobject';
  3814. }
  3815. else if (/(\.sfnt)($|\?)/i.test(url))
  3816. {
  3817. mime = 'application/font-sfnt';
  3818. }
  3819. var realUrl = url;
  3820. if ((/^https?:\/\//.test(realUrl)) && !this.isCorsEnabledForUrl(realUrl))
  3821. {
  3822. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
  3823. }
  3824. // LATER: Remove cache-control header
  3825. this.loadUrl(realUrl, mxUtils.bind(this, function(uri)
  3826. {
  3827. fonts[url] = uri;
  3828. waiting--;
  3829. finish();
  3830. }), mxUtils.bind(this, function(err)
  3831. {
  3832. // LATER: handle error
  3833. waiting--;
  3834. finish();
  3835. }), true, null, 'data:' + mime + ';charset=utf-8;base64,');
  3836. }
  3837. }))(parts[i].substring(0, idx));
  3838. }
  3839. }
  3840. }
  3841. else
  3842. {
  3843. then();
  3844. }
  3845. };
  3846. /**
  3847. *
  3848. */
  3849. EditorUi.prototype.exportToCanvas = function(callback, width, imageCache, background, error, limitHeight,
  3850. ignoreSelection, scale, transparentBackground, addShadow, converter, graph, border, noCrop)
  3851. {
  3852. limitHeight = (limitHeight != null) ? limitHeight : true;
  3853. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  3854. graph = (graph != null) ? graph : this.editor.graph;
  3855. border = (border != null) ? border : 0;
  3856. var bg = (transparentBackground) ? null : graph.background;
  3857. if (bg == mxConstants.NONE)
  3858. {
  3859. bg = null;
  3860. }
  3861. if (bg == null)
  3862. {
  3863. bg = background;
  3864. }
  3865. // Handles special case where background is null but transparent is false
  3866. if (bg == null && transparentBackground == false)
  3867. {
  3868. bg = '#ffffff';
  3869. }
  3870. this.convertImages(graph.getSvg(bg, null, null, noCrop, null, ignoreSelection), mxUtils.bind(this, function(svgRoot)
  3871. {
  3872. var img = new Image();
  3873. img.onload = mxUtils.bind(this, function()
  3874. {
  3875. try
  3876. {
  3877. var canvas = document.createElement('canvas');
  3878. var w = parseInt(svgRoot.getAttribute('width'));
  3879. var h = parseInt(svgRoot.getAttribute('height'));
  3880. scale = (scale != null) ? scale : 1;
  3881. if (width != null)
  3882. {
  3883. scale = (!limitHeight) ? width / w : Math.min(1, Math.min((width * 3) / (h * 4), width / w));
  3884. }
  3885. w = Math.ceil(scale * w) + 2 * border;
  3886. h = Math.ceil(scale * h) + 2 * border;
  3887. canvas.setAttribute('width', w);
  3888. canvas.setAttribute('height', h);
  3889. var ctx = canvas.getContext('2d');
  3890. if (bg != null)
  3891. {
  3892. ctx.beginPath();
  3893. ctx.rect(0, 0, w, h);
  3894. ctx.fillStyle = bg;
  3895. ctx.fill();
  3896. }
  3897. ctx.scale(scale, scale);
  3898. ctx.drawImage(img, border / scale, border / scale);
  3899. callback(canvas);
  3900. }
  3901. catch (e)
  3902. {
  3903. if (error != null)
  3904. {
  3905. error(e);
  3906. }
  3907. }
  3908. });
  3909. img.onerror = function(e)
  3910. {
  3911. //console.log('img', e, img.src);
  3912. if (error != null)
  3913. {
  3914. error(e);
  3915. }
  3916. };
  3917. try
  3918. {
  3919. if (addShadow)
  3920. {
  3921. this.editor.graph.addSvgShadow(svgRoot);
  3922. }
  3923. var done = mxUtils.bind(this, function()
  3924. {
  3925. if (this.editor.resolvedFontCss != null)
  3926. {
  3927. var st = document.createElement('style');
  3928. st.setAttribute('type', 'text/css');
  3929. st.innerHTML = this.editor.resolvedFontCss;
  3930. // Must be in defs section for FF to work
  3931. var defs = svgRoot.getElementsByTagName('defs');
  3932. defs[0].appendChild(st);
  3933. }
  3934. this.convertMath(graph, svgRoot, true, mxUtils.bind(this, function()
  3935. {
  3936. img.src = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  3937. }));
  3938. });
  3939. this.loadFonts(done);
  3940. }
  3941. catch (e)
  3942. {
  3943. //console.log('src', e, img.src);
  3944. if (error != null)
  3945. {
  3946. error(e);
  3947. }
  3948. }
  3949. }), imageCache, converter);
  3950. };
  3951. /**
  3952. * Converts all images in the SVG output to data URIs for immediate rendering
  3953. */
  3954. EditorUi.prototype.createImageUrlConverter = function()
  3955. {
  3956. var converter = new mxUrlConverter();
  3957. converter.updateBaseUrl();
  3958. // Extends convert to avoid CORS using an image proxy server
  3959. // LATER: Use img.crossOrigin="anonymous" to avoid proxy
  3960. var convert = converter.convert;
  3961. converter.convert = function(src)
  3962. {
  3963. if (src != null)
  3964. {
  3965. if ((src.substring(0, 7) == 'http://' || src.substring(0, 8) == 'https://') &&
  3966. src.substring(0, converter.baseUrl.length) != converter.baseUrl)
  3967. {
  3968. src = PROXY_URL + '?url=' + encodeURIComponent(src);
  3969. }
  3970. else if (src.substring(0, 19) != 'chrome-extension://')
  3971. {
  3972. src = convert.apply(this, arguments);
  3973. }
  3974. }
  3975. return src;
  3976. };
  3977. return converter;
  3978. };
  3979. /**
  3980. * Converts all images in the SVG output to data URIs for immediate rendering
  3981. */
  3982. EditorUi.prototype.convertImages = function(svgRoot, callback, imageCache, converter)
  3983. {
  3984. // Converts images to data URLs for immediate painting
  3985. if (converter == null)
  3986. {
  3987. converter = this.createImageUrlConverter();
  3988. }
  3989. // Barrier for asynchronous image loading
  3990. var counter = 0;
  3991. function inc()
  3992. {
  3993. counter++;
  3994. };
  3995. function dec()
  3996. {
  3997. counter--;
  3998. if (counter == 0)
  3999. {
  4000. callback(svgRoot);
  4001. }
  4002. };
  4003. var cache = imageCache || new Object();
  4004. var convertImages = mxUtils.bind(this, function(tagName, srcAttr)
  4005. {
  4006. var images = svgRoot.getElementsByTagName(tagName);
  4007. for (var i = 0; i < images.length; i++)
  4008. {
  4009. (mxUtils.bind(this, function(img)
  4010. {
  4011. var src = converter.convert(img.getAttribute(srcAttr));
  4012. // Data URIs are pass-through
  4013. if (src != null && src.substring(0, 5) != 'data:')
  4014. {
  4015. var tmp = cache[src];
  4016. if (tmp == null)
  4017. {
  4018. inc();
  4019. this.convertImageToDataUri(src, function(uri)
  4020. {
  4021. if (uri != null)
  4022. {
  4023. cache[src] = uri;
  4024. img.setAttribute(srcAttr, uri);
  4025. }
  4026. dec();
  4027. });
  4028. }
  4029. else
  4030. {
  4031. img.setAttribute(srcAttr, tmp);
  4032. }
  4033. }
  4034. }))(images[i]);
  4035. }
  4036. });
  4037. // Converts all known image tags in output
  4038. // LATER: Add support for images in CSS
  4039. convertImages('image', 'xlink:href');
  4040. convertImages('img', 'src');
  4041. // All from cache or no images
  4042. if (counter == 0)
  4043. {
  4044. callback(svgRoot);
  4045. }
  4046. };
  4047. /**
  4048. * Checks if the client is authorized and calls the next step.
  4049. */
  4050. EditorUi.prototype.loadUrl = function(url, success, error, forceBinary, retry, dataUriPrefix)
  4051. {
  4052. try
  4053. {
  4054. var binary = forceBinary || /(\.png)($|\?)/i.test(url) ||
  4055. /(\.jpe?g)($|\?)/i.test(url) || /(\.gif)($|\?)/i.test(url);
  4056. retry = (retry != null) ? retry : true;
  4057. var fn = mxUtils.bind(this, function()
  4058. {
  4059. mxUtils.get(url, mxUtils.bind(this, function(req)
  4060. {
  4061. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  4062. {
  4063. if (success != null)
  4064. {
  4065. var data = req.getText();
  4066. // Returns PNG as base64 encoded data URI
  4067. if (binary)
  4068. {
  4069. // NOTE: This requires BinaryToArray VB script in the page
  4070. if ((document.documentMode == 9 || document.documentMode == 10) &&
  4071. typeof window.mxUtilsBinaryToArray !== 'undefined')
  4072. {
  4073. var bin = mxUtilsBinaryToArray(req.request.responseBody).toArray();
  4074. var tmp = new Array(bin.length);
  4075. for (var i = 0; i < bin.length; i++)
  4076. {
  4077. tmp[i] = String.fromCharCode(bin[i]);
  4078. }
  4079. data = tmp.join('');
  4080. }
  4081. // LATER: Could be JPG but modern browsers
  4082. // ignore the mime type in the data URI
  4083. dataUriPrefix = (dataUriPrefix != null) ? dataUriPrefix : 'data:image/png;base64,';
  4084. data = dataUriPrefix + this.base64Encode(data);
  4085. }
  4086. success(data);
  4087. }
  4088. }
  4089. else if (error != null)
  4090. {
  4091. error({code: App.ERROR_UNKNOWN});
  4092. }
  4093. }), function()
  4094. {
  4095. if (error != null)
  4096. {
  4097. error({code: App.ERROR_UNKNOWN});
  4098. }
  4099. }, binary, this.timeout, function()
  4100. {
  4101. if (retry && error != null)
  4102. {
  4103. error({code: App.ERROR_TIMEOUT, retry: fn});
  4104. }
  4105. });
  4106. });
  4107. fn();
  4108. }
  4109. catch (e)
  4110. {
  4111. if (error != null)
  4112. {
  4113. error(e);
  4114. }
  4115. }
  4116. };
  4117. /**
  4118. * Returns true if the given URL is known to have CORS headers.
  4119. */
  4120. EditorUi.prototype.isCorsEnabledForUrl = function(url)
  4121. {
  4122. return url.substring(0, 34) === 'https?://raw.githubusercontent.com/' ||
  4123. /^https?:\/\/.*\.github\.io\//.test(url) ||
  4124. /^https?:\/\/(.*\.)?rawgit\.com\//.test(url);
  4125. };
  4126. /**
  4127. * Translates this point by the given vector.
  4128. *
  4129. * @param {number} dx X-coordinate of the translation.
  4130. * @param {number} dy Y-coordinate of the translation.
  4131. */
  4132. EditorUi.prototype.convertImageToDataUri = function(url, callback)
  4133. {
  4134. if (/(\.svg)$/i.test(url))
  4135. {
  4136. mxUtils.get(url, mxUtils.bind(this, function(req)
  4137. {
  4138. callback(this.createSvgDataUri(req.getText()));
  4139. }),
  4140. function()
  4141. {
  4142. callback();
  4143. });
  4144. }
  4145. else
  4146. {
  4147. var img = new Image();
  4148. img.onload = function()
  4149. {
  4150. var canvas = document.createElement('canvas');
  4151. var ctx = canvas.getContext('2d');
  4152. canvas.height = img.height;
  4153. canvas.width = img.width;
  4154. ctx.drawImage(img, 0, 0);
  4155. callback(canvas.toDataURL());
  4156. };
  4157. img.onerror = function()
  4158. {
  4159. callback();
  4160. };
  4161. img.src = url;
  4162. }
  4163. };
  4164. /**
  4165. * Handling drag and drop and import.
  4166. */
  4167. /**
  4168. * Imports the given XML into the existing diagram.
  4169. */
  4170. EditorUi.prototype.importXml = function(xml, dx, dy, crop, noErrorHandling)
  4171. {
  4172. dx = (dx != null) ? dx : 0;
  4173. dy = (dy != null) ? dy : 0;
  4174. var cells = []
  4175. try
  4176. {
  4177. var graph = this.editor.graph;
  4178. if (xml != null && xml.length > 0)
  4179. {
  4180. var doc = mxUtils.parseXml(xml);
  4181. // Checks for mxfile with multiple pages
  4182. var node = this.editor.extractGraphModel(doc.documentElement, this.pages != null);
  4183. if (node != null && node.nodeName == 'mxfile' && this.pages != null)
  4184. {
  4185. var diagrams = node.getElementsByTagName('diagram');
  4186. if (diagrams.length == 1)
  4187. {
  4188. node = mxUtils.parseXml(graph.decompress(mxUtils.getTextContent(diagrams[0]))).documentElement;
  4189. }
  4190. else if (diagrams.length > 1)
  4191. {
  4192. // Adds pages
  4193. graph.model.beginUpdate();
  4194. try
  4195. {
  4196. for (var i = 0; i < diagrams.length; i++)
  4197. {
  4198. var page = this.updatePageRoot(new DiagramPage(diagrams[i]));
  4199. var index = this.pages.length;
  4200. // Checks for invalid page names
  4201. if (page.getName() == null)
  4202. {
  4203. page.setName(mxResources.get('pageWithNumber', [index + 1]));
  4204. }
  4205. graph.model.execute(new ChangePage(this, page, page, index));
  4206. }
  4207. }
  4208. finally
  4209. {
  4210. graph.model.endUpdate();
  4211. }
  4212. }
  4213. }
  4214. if (node != null && node.nodeName === 'mxGraphModel')
  4215. {
  4216. var model = new mxGraphModel();
  4217. var codec = new mxCodec(node.ownerDocument);
  4218. codec.decode(node, model);
  4219. var childCount = model.getChildCount(model.getRoot());
  4220. var targetChildCount = graph.model.getChildCount(graph.model.getRoot());
  4221. // Merges into active layer if one layer is pasted
  4222. graph.model.beginUpdate();
  4223. try
  4224. {
  4225. // Mapping for multiple calls to cloneCells with the same set of cells
  4226. var mapping = new Object();
  4227. for (var i = 0; i < childCount; i++)
  4228. {
  4229. var parent = model.getChildAt(model.getRoot(), i);
  4230. // Adds cells to existing layer if not locked
  4231. if (childCount == 1 && !graph.isCellLocked(graph.getDefaultParent()))
  4232. {
  4233. var children = model.getChildren(parent);
  4234. cells = cells.concat(graph.importCells(children, dx, dy, graph.getDefaultParent(), null, mapping));
  4235. }
  4236. else
  4237. {
  4238. // Delta is non cascading, needs separate move for layers
  4239. parent = graph.importCells([parent], 0, 0, graph.model.getRoot(), null, mapping)[0];
  4240. var children = graph.model.getChildren(parent);
  4241. graph.moveCells(children, dx, dy);
  4242. cells = cells.concat(children);
  4243. }
  4244. }
  4245. if (crop)
  4246. {
  4247. if (graph.isGridEnabled())
  4248. {
  4249. dx = graph.snap(dx);
  4250. dy = graph.snap(dy);
  4251. }
  4252. var bounds = graph.getBoundingBoxFromGeometry(cells, true);
  4253. if (bounds != null)
  4254. {
  4255. graph.moveCells(cells, dx - bounds.x, dy - bounds.y);
  4256. }
  4257. }
  4258. }
  4259. finally
  4260. {
  4261. graph.model.endUpdate();
  4262. }
  4263. }
  4264. }
  4265. }
  4266. catch (e)
  4267. {
  4268. if (!noErrorHandling)
  4269. {
  4270. this.handleError(e, mxResources.get('invalidOrMissingFile'));
  4271. }
  4272. throw e;
  4273. }
  4274. return cells;
  4275. };
  4276. /**
  4277. * Imports the given Lucidchart data.
  4278. */
  4279. EditorUi.prototype.importLucidChart = function(data, dx, dy, crop, done)
  4280. {
  4281. var delayed = mxUtils.bind(this, function()
  4282. {
  4283. // Checks for signature method
  4284. if (this.pasteLucidChart)
  4285. {
  4286. try
  4287. {
  4288. this.insertLucidChart(data, dx, dy, crop, done);
  4289. if (this.updateAd != null && !this.lucidchartTweetShown && urlParams['embed'] != '1')
  4290. {
  4291. this.adsHtml.push('<a title="' + mxResources.get('loveIt', ['draw.io']) +
  4292. '" target="_blank" href="https://twitter.com/intent/tweet?text=' +
  4293. encodeURIComponent('I\'ve just copy and pasted my Lucidchart diagram into www.draw.io') +
  4294. '" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' +
  4295. 'left=\'+((screen.width-640)/2)+\',top=\'+((screen.height-280)/3)+\',height=280,width=640\');return false;"\'>' +
  4296. '<img border="0" width="18" height="18" align="absmiddle" style="margin-top:-2px;padding-right:8px;" src="' +
  4297. Editor.tweetImage + '"/>Paste from Lucidchart?</a>');
  4298. this.updateAd(this.adsHtml.length - 1, 200);
  4299. this.lucidchartTweetShown = true;
  4300. }
  4301. }
  4302. catch (e)
  4303. {
  4304. this.handleError(e);
  4305. }
  4306. finally
  4307. {
  4308. if (done != null)
  4309. {
  4310. done();
  4311. }
  4312. }
  4313. }
  4314. });
  4315. if (!this.pasteLucidChart && !this.loadingExtensions && !this.isOffline())
  4316. {
  4317. this.loadingExtensions = true;
  4318. if (urlParams['dev'] == '1')
  4319. {
  4320. mxscript('js/diagramly/Extensions.js', delayed);
  4321. }
  4322. else
  4323. {
  4324. mxscript('js/extensions.min.js', delayed);
  4325. }
  4326. }
  4327. else
  4328. {
  4329. // Must be async for cell selection
  4330. window.setTimeout(delayed, 0);
  4331. }
  4332. };
  4333. /**
  4334. * Automatic loading for lucidchart import.
  4335. */
  4336. EditorUi.prototype.insertLucidChart = function(data, dx, dy, crop, done)
  4337. {
  4338. var state = JSON.parse(data);
  4339. // Extracts and sorts all pages
  4340. var pages = [];
  4341. if (state.state != null)
  4342. {
  4343. state = JSON.parse(state.state);
  4344. for (var id in state.Pages)
  4345. {
  4346. pages.push(state.Pages[id]);
  4347. }
  4348. pages.sort(function(a, b)
  4349. {
  4350. if (a.Properties.Order < b.Properties.Order)
  4351. {
  4352. return -1;
  4353. }
  4354. else if (a.Properties.Order > b.Properties.Order)
  4355. {
  4356. return 1;
  4357. }
  4358. else
  4359. {
  4360. return 0;
  4361. }
  4362. });
  4363. }
  4364. else
  4365. {
  4366. pages.push(state);
  4367. }
  4368. if (pages.length > 0)
  4369. {
  4370. this.editor.graph.getModel().beginUpdate();
  4371. try
  4372. {
  4373. this.pasteLucidChart(pages[0], dx, dy, crop);
  4374. // If pages are enabled add more pages
  4375. if (this.pages != null)
  4376. {
  4377. var current = this.currentPage;
  4378. for (var i = 1; i < pages.length; i++)
  4379. {
  4380. this.insertPage();
  4381. this.pasteLucidChart(pages[i]);
  4382. }
  4383. this.selectPage(current);
  4384. }
  4385. }
  4386. finally
  4387. {
  4388. this.editor.graph.getModel().endUpdate();
  4389. }
  4390. }
  4391. };
  4392. /**
  4393. * Imports the given XML into the existing diagram.
  4394. * TODO: Make this function asynchronous
  4395. */
  4396. EditorUi.prototype.insertTextAt = function(text, dx, dy, html, asImage, crop, resizeImages)
  4397. {
  4398. crop = (crop != null) ? crop : true;
  4399. resizeImages = (resizeImages != null) ? resizeImages : true;
  4400. // Handles special case for Gliffy data which requires async server-side for parsing
  4401. if (text != null)
  4402. {
  4403. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(text))
  4404. {
  4405. // Fixes possible parsing problems with ASCII 160 (non-breaking space)
  4406. this.parseFile(new Blob([text.replace(/\s+/g,' ')], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  4407. {
  4408. if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status <= 299)
  4409. {
  4410. this.editor.graph.setSelectionCells(this.insertTextAt(xhr.responseText, dx, dy, true));
  4411. }
  4412. }));
  4413. // Returns empty cells array as it is aysynchronous
  4414. return [];
  4415. }
  4416. // Handles special case of data URI which requires async loading for finding size
  4417. else if (text.substring(0, 5) == 'data:' || (!this.isOffline() && (asImage || (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(text))))
  4418. {
  4419. var graph = this.editor.graph;
  4420. // Checks for embedded XML in PNG
  4421. if (text.substring(0, 22) == 'data:image/png;base64,')
  4422. {
  4423. var xml = this.extractGraphModelFromPng(text);
  4424. var result = this.importXml(xml, dx, dy, crop, true);
  4425. if (result.length > 0)
  4426. {
  4427. return result;
  4428. }
  4429. }
  4430. // Tries to extract embedded XML from SVG data URI
  4431. if (text.substring(0, 19) == 'data:image/svg+xml;')
  4432. {
  4433. try
  4434. {
  4435. var xml = null;
  4436. if (text.substring(0, 26) == 'data:image/svg+xml;base64,')
  4437. {
  4438. xml = text.substring(text.indexOf(',') + 1);
  4439. xml = (window.atob && !mxClient.IS_SF) ? atob(xml) : Base64.decode(xml, true);
  4440. }
  4441. else
  4442. {
  4443. xml = decodeURIComponent(text.substring(text.indexOf(',') + 1));
  4444. }
  4445. var result = this.importXml(xml, dx, dy, crop, true);
  4446. if (result.length > 0)
  4447. {
  4448. return result;
  4449. }
  4450. }
  4451. catch (e)
  4452. {
  4453. // Ignore
  4454. }
  4455. }
  4456. this.loadImage(text, mxUtils.bind(this, function(img)
  4457. {
  4458. if (text.substring(0, 5) == 'data:')
  4459. {
  4460. this.resizeImage(img, text, mxUtils.bind(this, function(data2, w2, h2)
  4461. {
  4462. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  4463. w2, h2, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  4464. 'verticalAlign=top;aspect=fixed;imageAspect=0;image=' + this.convertDataUri(data2) + ';'));
  4465. }), resizeImages, this.maxImageSize);
  4466. }
  4467. else
  4468. {
  4469. var s = Math.min(1, Math.min(this.maxImageSize / img.width, this.maxImageSize / img.height));
  4470. var w = Math.round(img.width * s);
  4471. var h = Math.round(img.height * s);
  4472. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  4473. w, h, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  4474. 'verticalAlign=top;aspect=fixed;imageAspect=0;image=' + text + ';'));
  4475. }
  4476. }), mxUtils.bind(this, function()
  4477. {
  4478. var cell = null;
  4479. // Inserts invalid data URIs as text
  4480. graph.getModel().beginUpdate();
  4481. try
  4482. {
  4483. cell = graph.insertVertex(graph.getDefaultParent(), null, text,
  4484. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  4485. graph.updateCellSize(cell);
  4486. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  4487. }
  4488. finally
  4489. {
  4490. graph.getModel().endUpdate();
  4491. }
  4492. graph.setSelectionCell(cell);
  4493. }));
  4494. return [];
  4495. }
  4496. else
  4497. {
  4498. text = this.editor.graph.zapGremlins(mxUtils.trim(text));
  4499. if (this.isCompatibleString(text))
  4500. {
  4501. return this.importXml(text, dx, dy, crop);
  4502. }
  4503. else if (text.length > 0)
  4504. {
  4505. if (text.substring(0, 26) == '{"state":"{\\"Properties\\":')
  4506. {
  4507. this.importLucidChart(text, dx, dy, crop);
  4508. }
  4509. else
  4510. {
  4511. var graph = this.editor.graph;
  4512. var cell = null;
  4513. graph.getModel().beginUpdate();
  4514. try
  4515. {
  4516. // Fires cellsInserted to apply the current style to the inserted text.
  4517. // This requires the value to be empty when the event is fired.
  4518. cell = graph.insertVertex(graph.getDefaultParent(), null, '',
  4519. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  4520. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  4521. // Apply value and updates the cell size to fit the text block
  4522. cell.value = text;
  4523. graph.updateCellSize(cell);
  4524. // See http://stackoverflow.com/questions/6927719/url-regex-does-not-work-in-javascript
  4525. var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
  4526. if (regexp.test(cell.value))
  4527. {
  4528. graph.setLinkForCell(cell, cell.value);
  4529. }
  4530. // Adds spacing
  4531. cell.geometry.width += graph.gridSize;
  4532. cell.geometry.height += graph.gridSize;
  4533. }
  4534. finally
  4535. {
  4536. graph.getModel().endUpdate();
  4537. }
  4538. return [cell];
  4539. }
  4540. }
  4541. }
  4542. }
  4543. return [];
  4544. };
  4545. /**
  4546. * Formats the given file size.
  4547. */
  4548. EditorUi.prototype.formatFileSize = function(size)
  4549. {
  4550. var units = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
  4551. var i = -1;
  4552. do
  4553. {
  4554. size = size / 1024;
  4555. i++;
  4556. } while (size > 1024);
  4557. return Math.max(size, 0.1).toFixed(1) + units[i];
  4558. };
  4559. /**
  4560. * Imports the given XML into the existing diagram.
  4561. */
  4562. EditorUi.prototype.convertDataUri = function(uri)
  4563. {
  4564. // Handles special case of data URI which needs to be rewritten
  4565. // to be used in a cell style to remove the semicolon
  4566. if (uri.substring(0, 5) == 'data:')
  4567. {
  4568. var semi = uri.indexOf(';');
  4569. if (semi > 0)
  4570. {
  4571. uri = uri.substring(0, semi) + uri.substring(uri.indexOf(',', semi + 1));
  4572. }
  4573. }
  4574. return uri;
  4575. };
  4576. /**
  4577. * Returns true for Gliffy or GraphML data or .vsdx filenames.
  4578. */
  4579. EditorUi.prototype.isRemoteFileFormat = function(data, filename)
  4580. {
  4581. return /(\.*<graphml xmlns=\".*)/.test(data) ||
  4582. /(\"contentType\":\s*\"application\/gliffy\+json\")/.test(data) ||
  4583. (filename != null && /(\.vsdx)($|\?)/i.test(filename)) ||
  4584. (filename != null && /(\.vssx)($|\?)/i.test(filename));
  4585. };
  4586. /**
  4587. * Imports the given XML into the existing diagram.
  4588. */
  4589. EditorUi.prototype.importFile = function(data, mimeType, dx, dy, w, h, filename, done, file, crop, ignoreEmbeddedXml)
  4590. {
  4591. crop = (crop != null) ? crop : true;
  4592. var async = false;
  4593. var cells = null;
  4594. if (mimeType.substring(0, 5) == 'image')
  4595. {
  4596. var containsModel = false;
  4597. if (mimeType.substring(0, 9) == 'image/png')
  4598. {
  4599. var xml = (ignoreEmbeddedXml) ? null : this.extractGraphModelFromPng(data);
  4600. if (xml != null && xml.length > 0)
  4601. {
  4602. cells = this.importXml(xml, dx, dy, crop);
  4603. containsModel = true;
  4604. }
  4605. }
  4606. if (!containsModel)
  4607. {
  4608. var graph = this.editor.graph;
  4609. // Strips encoding bit (eg. ;base64,) for cell style
  4610. var semi = data.indexOf(';');
  4611. if (semi > 0)
  4612. {
  4613. data = data.substring(0, semi) + data.substring(data.indexOf(',', semi + 1));
  4614. }
  4615. if (crop && graph.isGridEnabled())
  4616. {
  4617. dx = graph.snap(dx);
  4618. dy = graph.snap(dy);
  4619. }
  4620. cells = [graph.insertVertex(null, null, '', dx, dy, w, h,
  4621. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  4622. 'verticalAlign=top;aspect=fixed;imageAspect=0;image=' + data + ';')];
  4623. }
  4624. }
  4625. else if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, filename))
  4626. {
  4627. // LATER: done and async are a hack before making this asynchronous
  4628. async = true;
  4629. // Returns empty cells array as it is aysynchronous
  4630. this.parseFile((file != null) ? file : new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  4631. {
  4632. if (xhr.readyState == 4)
  4633. {
  4634. var importedCells = null;
  4635. if (xhr.status >= 200 && xhr.status <= 299)
  4636. {
  4637. var xml = xhr.responseText;
  4638. if (xml != null && xml.substring(0, 10) == '<mxlibrary')
  4639. {
  4640. if (filename != null && filename.toLowerCase().substring(filename.length - 5) == '.vssx')
  4641. {
  4642. filename = filename.substring(0, filename.length - 5) + '.xml';
  4643. }
  4644. this.loadLibrary(new LocalLibrary(this, xml, filename));
  4645. }
  4646. else
  4647. {
  4648. importedCells = this.importXml(xml, dx, dy, crop);
  4649. }
  4650. }
  4651. if (done != null)
  4652. {
  4653. done(importedCells);
  4654. }
  4655. }
  4656. }), filename);
  4657. }
  4658. else if (!/(\.vsd)($|\?)/i.test(filename))
  4659. {
  4660. cells = this.insertTextAt(this.validateFileData(data), dx, dy, true, null, crop);
  4661. }
  4662. if (!async && done != null)
  4663. {
  4664. done(cells);
  4665. }
  4666. return cells;
  4667. };
  4668. /**
  4669. * Base64 encodes the given string. This method seems to be more
  4670. * robust for encoding PNG from binary AJAX responses.
  4671. */
  4672. EditorUi.prototype.base64Encode = function(str)
  4673. {
  4674. var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  4675. var out = "", i = 0, len = str.length, c1, c2, c3;
  4676. while (i < len)
  4677. {
  4678. c1 = str.charCodeAt(i++) & 0xff;
  4679. if (i == len)
  4680. {
  4681. out += CHARS.charAt(c1 >> 2);
  4682. out += CHARS.charAt((c1 & 0x3) << 4);
  4683. out += "==";
  4684. break;
  4685. }
  4686. c2 = str.charCodeAt(i++);
  4687. if (i == len)
  4688. {
  4689. out += CHARS.charAt(c1 >> 2);
  4690. out += CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  4691. out += CHARS.charAt((c2 & 0xF) << 2);
  4692. out += "=";
  4693. break;
  4694. }
  4695. c3 = str.charCodeAt(i++);
  4696. out += CHARS.charAt(c1 >> 2);
  4697. out += CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  4698. out += CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  4699. out += CHARS.charAt(c3 & 0x3F);
  4700. }
  4701. return out;
  4702. };
  4703. /**
  4704. *
  4705. */
  4706. EditorUi.prototype.importFiles = function(files, x, y, maxSize, fn, resultFn, filterFn, barrierFn, resizeDialog, maxBytes, resampleThreshold, ignoreEmbeddedXml)
  4707. {
  4708. x = (x != null) ? x : 0;
  4709. y = (y != null) ? y : 0;
  4710. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  4711. maxBytes = (maxBytes != null) ? maxBytes : this.maxImageBytes;
  4712. var crop = x != null && y != null;
  4713. var resizeImages = true;
  4714. // Checks if large images are imported
  4715. var largeImages = false;
  4716. if (!mxClient.IS_CHROMEAPP && files != null)
  4717. {
  4718. var thresh = resampleThreshold || this.resampleThreshold;
  4719. for (var i = 0; i < files.length; i++)
  4720. {
  4721. if (files[i].type.substring(0, 6) == 'image/' && files[i].size > thresh)
  4722. {
  4723. largeImages = true;
  4724. break;
  4725. }
  4726. }
  4727. }
  4728. var doImportFiles = mxUtils.bind(this, function()
  4729. {
  4730. var graph = this.editor.graph;
  4731. var gs = graph.gridSize;
  4732. fn = (fn != null) ? fn : mxUtils.bind(this, function(data, mimeType, x, y, w, h, filename, done, file)
  4733. {
  4734. if (data != null && data.substring(0, 10) == '<mxlibrary')
  4735. {
  4736. this.spinner.stop();
  4737. this.loadLibrary(new LocalLibrary(this, data, filename));
  4738. return null;
  4739. }
  4740. else
  4741. {
  4742. return this.importFile(data, mimeType, x, y, w, h, filename, done, file, crop, ignoreEmbeddedXml);
  4743. }
  4744. });
  4745. resultFn = (resultFn != null) ? resultFn : mxUtils.bind(this, function(cells)
  4746. {
  4747. graph.setSelectionCells(cells);
  4748. });
  4749. if (this.spinner.spin(document.body, mxResources.get('loading')))
  4750. {
  4751. var count = files.length;
  4752. var remain = count;
  4753. var queue = [];
  4754. // Barrier waits for all files to be loaded asynchronously
  4755. var barrier = mxUtils.bind(this, function(index, fnc)
  4756. {
  4757. queue[index] = fnc;
  4758. if (--remain == 0)
  4759. {
  4760. this.spinner.stop();
  4761. if (barrierFn != null)
  4762. {
  4763. barrierFn(queue);
  4764. }
  4765. else
  4766. {
  4767. var cells = [];
  4768. graph.getModel().beginUpdate();
  4769. try
  4770. {
  4771. for (var j = 0; j < queue.length; j++)
  4772. {
  4773. var tmp = queue[j]();
  4774. if (tmp != null)
  4775. {
  4776. cells = cells.concat(tmp);
  4777. }
  4778. }
  4779. }
  4780. finally
  4781. {
  4782. graph.getModel().endUpdate();
  4783. }
  4784. }
  4785. resultFn(cells);
  4786. }
  4787. });
  4788. for (var i = 0; i < count; i++)
  4789. {
  4790. (mxUtils.bind(this, function(index)
  4791. {
  4792. var file = files[index];
  4793. var reader = new FileReader();
  4794. reader.onload = mxUtils.bind(this, function(e)
  4795. {
  4796. if (filterFn == null || filterFn(file))
  4797. {
  4798. if (file.type.substring(0, 6) == 'image/')
  4799. {
  4800. if (file.type.substring(0, 9) == 'image/svg')
  4801. {
  4802. // Checks if SVG contains content attribute
  4803. var data = e.target.result;
  4804. var comma = data.indexOf(',');
  4805. var svgText = atob(data.substring(comma + 1));
  4806. var root = mxUtils.parseXml(svgText);
  4807. var svgs = root.getElementsByTagName('svg');
  4808. if (svgs.length > 0)
  4809. {
  4810. var svgRoot = svgs[0];
  4811. var cont = (ignoreEmbeddedXml) ? null : svgRoot.getAttribute('content');
  4812. if (cont != null && cont.charAt(0) != '<' && cont.charAt(0) != '%')
  4813. {
  4814. cont = unescape((window.atob) ? atob(cont) : Base64.decode(cont, true));
  4815. }
  4816. if (cont != null && cont.charAt(0) == '%')
  4817. {
  4818. cont = decodeURIComponent(cont);
  4819. }
  4820. if (cont != null && (cont.substring(0, 8) === '<mxfile ' ||
  4821. cont.substring(0, 14) === '<mxGraphModel '))
  4822. {
  4823. barrier(index, mxUtils.bind(this, function()
  4824. {
  4825. return fn(cont, 'text/xml', x + index * gs, y + index * gs, 0, 0, file.name);
  4826. }));
  4827. }
  4828. else
  4829. {
  4830. // SVG needs special handling to add viewbox if missing and
  4831. // find initial size from SVG attributes (only for IE11)
  4832. barrier(index, mxUtils.bind(this, function()
  4833. {
  4834. try
  4835. {
  4836. var prefix = data.substring(0, comma + 1);
  4837. // Parses SVG and find width and height
  4838. if (root != null)
  4839. {
  4840. var svgs = root.getElementsByTagName('svg');
  4841. if (svgs.length > 0)
  4842. {
  4843. var svgRoot = svgs[0];
  4844. var w = parseFloat(svgRoot.getAttribute('width'));
  4845. var h = parseFloat(svgRoot.getAttribute('height'));
  4846. // Check if viewBox attribute already exists
  4847. var vb = svgRoot.getAttribute('viewBox');
  4848. if (vb == null || vb.length == 0)
  4849. {
  4850. svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  4851. }
  4852. // Uses width and height from viewbox for
  4853. // missing width and height attributes
  4854. else if (isNaN(w) || isNaN(h))
  4855. {
  4856. var tokens = vb.split(' ');
  4857. if (tokens.length > 3)
  4858. {
  4859. w = parseFloat(tokens[2]);
  4860. h = parseFloat(tokens[3]);
  4861. }
  4862. }
  4863. data = this.createSvgDataUri(mxUtils.getXml(svgs[0]));
  4864. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  4865. return fn(data, file.type, x + index * gs, y + index * gs,
  4866. Math.max(1, Math.round(w * s)), Math.max(1, Math.round(h * s)), file.name);
  4867. }
  4868. }
  4869. }
  4870. catch (e)
  4871. {
  4872. // ignores any SVG parsing errors
  4873. }
  4874. return null;
  4875. }));
  4876. }
  4877. }
  4878. }
  4879. else
  4880. {
  4881. // Checks if PNG+XML is available to bypass code below
  4882. var containsModel = false;
  4883. if (file.type == 'image/png')
  4884. {
  4885. var xml = (ignoreEmbeddedXml) ? null : this.extractGraphModelFromPng(e.target.result);
  4886. if (xml != null && xml.length > 0)
  4887. {
  4888. var img = new Image();
  4889. img.src = e.target.result;
  4890. barrier(index, mxUtils.bind(this, function()
  4891. {
  4892. return fn(xml, 'text/xml', x + index * gs, y + index * gs,
  4893. img.width, img.height, file.name);
  4894. }));
  4895. containsModel = true;
  4896. }
  4897. }
  4898. // Additional asynchronous step for finding image size
  4899. if (!containsModel)
  4900. {
  4901. // Cannot load local files in Chrome App
  4902. if (mxClient.IS_CHROMEAPP)
  4903. {
  4904. this.spinner.stop();
  4905. this.showError(mxResources.get('error'), mxResources.get('dragAndDropNotSupported'),
  4906. mxResources.get('cancel'), mxUtils.bind(this, function()
  4907. {
  4908. // Hides the dialog
  4909. }), null, mxResources.get('ok'), mxUtils.bind(this, function()
  4910. {
  4911. // Redirects to import function
  4912. this.actions.get('import').funct();
  4913. })
  4914. );
  4915. }
  4916. else
  4917. {
  4918. this.loadImage(e.target.result, mxUtils.bind(this, function(img)
  4919. {
  4920. this.resizeImage(img, e.target.result, mxUtils.bind(this, function(data2, w2, h2)
  4921. {
  4922. barrier(index, mxUtils.bind(this, function()
  4923. {
  4924. // Refuses to insert images above a certain size as they kill the app
  4925. if (data2 != null && data2.length < maxBytes)
  4926. {
  4927. var s = (!resizeImages || !this.isResampleImage(e.target.result, resampleThreshold)) ? 1 : Math.min(1, Math.min(maxSize / w2, maxSize / h2));
  4928. return fn(data2, file.type, x + index * gs, y + index * gs, Math.round(w2 * s), Math.round(h2 * s), file.name);
  4929. }
  4930. else
  4931. {
  4932. this.handleError({message: mxResources.get('imageTooBig')});
  4933. return null;
  4934. }
  4935. }));
  4936. }), resizeImages, maxSize, resampleThreshold);
  4937. }));
  4938. }
  4939. }
  4940. }
  4941. }
  4942. else
  4943. {
  4944. fn(e.target.result, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  4945. {
  4946. barrier(index, function()
  4947. {
  4948. return cells;
  4949. });
  4950. });
  4951. }
  4952. }
  4953. });
  4954. // Handles special case of binary file where the reader should not be used
  4955. if (/(\.vsdx)($|\?)/i.test(file.name) || /(\.vssx)($|\?)/i.test(file.name))
  4956. {
  4957. fn(null, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  4958. {
  4959. barrier(index, function()
  4960. {
  4961. return cells;
  4962. });
  4963. }, file);
  4964. }
  4965. else if (file.type.substring(0, 5) == 'image')
  4966. {
  4967. reader.readAsDataURL(file);
  4968. }
  4969. else
  4970. {
  4971. reader.readAsText(file);
  4972. }
  4973. }))(i);
  4974. }
  4975. }
  4976. });
  4977. if (largeImages)
  4978. {
  4979. this.confirmImageResize(function(doResize)
  4980. {
  4981. resizeImages = doResize;
  4982. doImportFiles();
  4983. }, resizeDialog);
  4984. }
  4985. else
  4986. {
  4987. doImportFiles();
  4988. }
  4989. };
  4990. /**
  4991. * Parses the file using XHR2 via the server. File can be a blob or file object.
  4992. * Filename is an optional parameter for blobs (that do not have a filename).
  4993. */
  4994. EditorUi.prototype.confirmImageResize = function(fn, force)
  4995. {
  4996. force = (force != null) ? force : false;
  4997. var resume = (this.spinner != null && this.spinner.pause != null) ? this.spinner.pause() : function() {};
  4998. var resizeImages = (isLocalStorage || mxClient.IS_CHROMEAPP) ? mxSettings.getResizeImages() : null;
  4999. var wrapper = function(remember, resize)
  5000. {
  5001. if (remember || force)
  5002. {
  5003. mxSettings.setResizeImages((remember) ? resize : null);
  5004. mxSettings.save();
  5005. }
  5006. resume();
  5007. fn(resize);
  5008. };
  5009. if (resizeImages != null && !force)
  5010. {
  5011. wrapper(false, resizeImages);
  5012. }
  5013. else
  5014. {
  5015. this.showDialog(new ConfirmDialog(this, mxResources.get('resizeLargeImages'),
  5016. function(remember)
  5017. {
  5018. wrapper(remember, true);
  5019. },
  5020. function(remember)
  5021. {
  5022. wrapper(remember, false);
  5023. }, mxResources.get('resize'), mxResources.get('actualSize'),
  5024. '<img style="margin-top:8px;" src="' + Editor.loResImage + '"/>',
  5025. '<img style="margin-top:8px;" src="' + Editor.hiResImage + '"/>',
  5026. isLocalStorage || mxClient.IS_CHROMEAPP).container, 340,
  5027. (isLocalStorage || mxClient.IS_CHROMEAPP) ? 220 : 200, true, true);
  5028. }
  5029. };
  5030. /**
  5031. * Parses the file using XHR2 via the server. File can be a blob or file object.
  5032. * Filename is an optional parameter for blobs (that do not have a filename).
  5033. */
  5034. EditorUi.prototype.parseFile = function(file, fn, filename)
  5035. {
  5036. filename = (filename != null) ? filename : file.name;
  5037. var formData = new FormData();
  5038. formData.append('format', 'xml');
  5039. formData.append('upfile', file, filename);
  5040. var xhr = new XMLHttpRequest();
  5041. xhr.open('POST', OPEN_URL);
  5042. xhr.onreadystatechange = function()
  5043. {
  5044. fn(xhr);
  5045. };
  5046. xhr.send(formData);
  5047. };
  5048. /**
  5049. *
  5050. */
  5051. EditorUi.prototype.isResampleImage = function(data, thresh)
  5052. {
  5053. thresh = (thresh != null) ? thresh : this.resampleThreshold;
  5054. return data.length > thresh;
  5055. };
  5056. /**
  5057. * Resizes the given image if <maxImageBytes> is not null.
  5058. */
  5059. EditorUi.prototype.resizeImage = function(img, data, fn, enabled, maxSize, thresh)
  5060. {
  5061. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  5062. var w = Math.max(1, img.width);
  5063. var h = Math.max(1, img.height);
  5064. if (enabled && this.isResampleImage(data, thresh))
  5065. {
  5066. try
  5067. {
  5068. var factor = Math.max(w / maxSize, h / maxSize);
  5069. if (factor > 1)
  5070. {
  5071. var w2 = Math.round(w / factor);
  5072. var h2 = Math.round(h / factor);
  5073. var canvas = document.createElement('canvas');
  5074. canvas.width = w2;
  5075. canvas.height = h2;
  5076. var ctx = canvas.getContext('2d');
  5077. ctx.drawImage(img, 0, 0, w2, h2);
  5078. var tmp = canvas.toDataURL();
  5079. // Uses new image if smaller
  5080. if (tmp.length < data.length)
  5081. {
  5082. // Checks if the image is empty by comparing
  5083. // with an empty image of the same size
  5084. var canvas2 = document.createElement('canvas');
  5085. canvas2.width = w2;
  5086. canvas2.height = h2;
  5087. var tmp2 = canvas2.toDataURL();
  5088. if (tmp !== tmp2)
  5089. {
  5090. data = tmp;
  5091. w = w2;
  5092. h = h2;
  5093. }
  5094. }
  5095. }
  5096. }
  5097. catch (e)
  5098. {
  5099. // ignores image scaling errors
  5100. }
  5101. }
  5102. fn(data, w, h);
  5103. };
  5104. EditorUi.prototype.crcTable = [];
  5105. for (var n = 0; n < 256; n++)
  5106. {
  5107. var c = n;
  5108. for (var k = 0; k < 8; k++)
  5109. {
  5110. if ((c & 1) == 1)
  5111. {
  5112. c = 0xedb88320 ^ (c >>> 1);
  5113. }
  5114. else
  5115. {
  5116. c >>>= 1;
  5117. }
  5118. EditorUi.prototype.crcTable[n] = c;
  5119. }
  5120. }
  5121. EditorUi.prototype.updateCRC = function(crc, data, off, len)
  5122. {
  5123. var c = crc;
  5124. for (var n = 0; n < len; n++)
  5125. {
  5126. c = EditorUi.prototype.crcTable[(c ^ data[off + n]) & 0xff] ^ (c >>> 8);
  5127. }
  5128. return c;
  5129. };
  5130. /**
  5131. * Adds the given text to the compressed or non-compressed text chunk.
  5132. */
  5133. EditorUi.prototype.writeGraphModelToPng = function(data, type, key, value, error)
  5134. {
  5135. var base64 = data.substring(data.indexOf(',') + 1);
  5136. var f = (window.atob) ? atob(base64) : Base64.decode(base64, true);
  5137. var pos = 0;
  5138. function fread(d, count)
  5139. {
  5140. var start = pos;
  5141. pos += count;
  5142. return d.substring(start, pos);
  5143. };
  5144. // Reads unsigned long 32 bit big endian
  5145. function _freadint(d)
  5146. {
  5147. var bytes = fread(d, 4);
  5148. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  5149. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  5150. };
  5151. function writeInt(num)
  5152. {
  5153. return String.fromCharCode((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff,
  5154. (num >> 8) & 0x000000ff, num & 0x000000ff);
  5155. };
  5156. // Checks signature
  5157. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  5158. {
  5159. if (error != null)
  5160. {
  5161. error();
  5162. }
  5163. return;
  5164. }
  5165. // Reads header chunk
  5166. fread(f,4);
  5167. if (fread(f,4) != 'IHDR')
  5168. {
  5169. if (error != null)
  5170. {
  5171. error();
  5172. }
  5173. return;
  5174. }
  5175. fread(f, 17);
  5176. var result = f.substring(0, pos);
  5177. do
  5178. {
  5179. var n = _freadint(f);
  5180. var chunk = fread(f,4);
  5181. if (chunk == 'IDAT')
  5182. {
  5183. result = f.substring(0, pos - 8);
  5184. var chunkData = key + String.fromCharCode(0) +
  5185. ((type == 'zTXt') ? String.fromCharCode(0) : '') +
  5186. value;
  5187. // FIXME: Wrong crc
  5188. var crc = 0xffffffff;
  5189. crc = this.updateCRC(crc, type, 0, 4);
  5190. crc = this.updateCRC(crc, chunkData, 0, chunkData.length);
  5191. result += writeInt(chunkData.length) + type + chunkData + writeInt(crc ^ 0xffffffff);
  5192. result += f.substring(pos - 8, f.length);
  5193. break;
  5194. }
  5195. result += f.substring(pos - 8, pos - 4 + n);
  5196. value = fread(f,n);
  5197. fread(f,4);
  5198. }
  5199. while (n);
  5200. return 'data:image/png;base64,' + ((window.btoa) ? btoa(result) : Base64.encode(result, true));
  5201. }
  5202. /**
  5203. * Extracts the XML from the compressed or non-compressed text chunk.
  5204. */
  5205. EditorUi.prototype.extractGraphModelFromPng = function(data)
  5206. {
  5207. var result = null;
  5208. try
  5209. {
  5210. var base64 = data.substring(data.indexOf(',') + 1);
  5211. // Workaround for invalid character error in Safari
  5212. var binary = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  5213. EditorUi.parsePng(binary, mxUtils.bind(this, function(pos, type, length)
  5214. {
  5215. var value = binary.substring(pos + 8, pos + 8 + length);
  5216. if (type == 'zTXt')
  5217. {
  5218. var idx = value.indexOf(String.fromCharCode(0));
  5219. if (value.substring(0, idx) == 'mxGraphModel')
  5220. {
  5221. // Workaround for Java URL Encoder using + for spaces, which isn't compatible with JS
  5222. var xmlData = this.editor.graph.bytesToString(pako.inflateRaw(
  5223. value.substring(idx + 2))).replace(/\+/g,' ');
  5224. if (xmlData != null && xmlData.length > 0)
  5225. {
  5226. result = xmlData;
  5227. }
  5228. }
  5229. }
  5230. // Uncompressed section is normally not used
  5231. else if (type == 'tEXt')
  5232. {
  5233. var vals = value.split(String.fromCharCode(0));
  5234. if (vals.length > 1 && vals[0] == 'mxGraphModel')
  5235. {
  5236. result = vals[1];
  5237. }
  5238. }
  5239. if (result != null || type == 'IDAT')
  5240. {
  5241. // Stops processing the file as our text chunks
  5242. // are always placed before the data section
  5243. return true;
  5244. }
  5245. }));
  5246. }
  5247. catch (e)
  5248. {
  5249. // ignores decoding errors
  5250. }
  5251. if (result != null && result.charAt(0) == '%')
  5252. {
  5253. result = decodeURIComponent(result);
  5254. }
  5255. // Workaround for double encoded content
  5256. if (result != null && result.charAt(0) == '%')
  5257. {
  5258. result = decodeURIComponent(result);
  5259. }
  5260. return result;
  5261. };
  5262. /**
  5263. * Loads the image from the given URI.
  5264. *
  5265. * @param {number} dx X-coordinate of the translation.
  5266. * @param {number} dy Y-coordinate of the translation.
  5267. */
  5268. EditorUi.prototype.loadImage = function(uri, onload, onerror)
  5269. {
  5270. var img = new Image();
  5271. img.onload = function()
  5272. {
  5273. onload(img);
  5274. }
  5275. if (onerror != null)
  5276. {
  5277. img.onerror = onerror;
  5278. }
  5279. img.src = uri;
  5280. };
  5281. // Initializes the user interface
  5282. var editorUiInit = EditorUi.prototype.init;
  5283. EditorUi.prototype.init = function()
  5284. {
  5285. // Must be set before UI is created in superclass
  5286. if (typeof window.mxSettings !== 'undefined')
  5287. {
  5288. this.formatWidth = mxSettings.getFormatWidth();
  5289. }
  5290. var ui = this;
  5291. var graph = this.editor.graph;
  5292. function pageLinkClicked(href)
  5293. {
  5294. var comma = href.indexOf(',');
  5295. if (comma > 0)
  5296. {
  5297. var page = ui.getPageById(href.substring(comma + 1));
  5298. if (page)
  5299. {
  5300. ui.selectPage(page)
  5301. }
  5302. }
  5303. };
  5304. // For chromeless mode and lightbox mode in viewer
  5305. // Must be overridden before supercall to be applied
  5306. // in case of chromeless initialization
  5307. var graphAddClickHandler = graph.addClickHandler;
  5308. graph.addClickHandler = function(highlight, beforeClick, onClick)
  5309. {
  5310. var tmp = beforeClick;
  5311. beforeClick = function(evt, href)
  5312. {
  5313. if (href == null)
  5314. {
  5315. var source = mxEvent.getSource(evt);
  5316. if (source.nodeName.toLowerCase() == 'a')
  5317. {
  5318. href = source.getAttribute('href');
  5319. }
  5320. }
  5321. if (href != null && graph.isPageLink(href))
  5322. {
  5323. pageLinkClicked(href);
  5324. mxEvent.consume(evt);
  5325. }
  5326. if (tmp != null)
  5327. {
  5328. tmp(evt, href);
  5329. }
  5330. };
  5331. // For some reason, local argument override is not enough in this case...
  5332. graphAddClickHandler.call(this, highlight, beforeClick, onClick);
  5333. };
  5334. editorUiInit.apply(this, arguments);
  5335. if (mxClient.IS_SVG)
  5336. {
  5337. // LATER: Add shadow for labels in graph.container (eg. math, NO_FO), scaling
  5338. this.editor.graph.addSvgShadow(graph.view.canvas.ownerSVGElement, null, true);
  5339. }
  5340. // Overrides print dialog size
  5341. ui.actions.get('print').funct = function()
  5342. {
  5343. ui.showDialog(new PrintDialog(ui).container, 360,
  5344. (ui.pages != null && ui.pages.length > 1) ?
  5345. 420 : 360, true, true);
  5346. };
  5347. // Specifies the default filename
  5348. this.defaultFilename = mxResources.get('untitledDiagram');
  5349. // Adds placeholder for %page% and %pagenumber%
  5350. var graphGetGlobalVariable = graph.getGlobalVariable;
  5351. graph.getGlobalVariable = function(name)
  5352. {
  5353. if (name == 'page' && ui.currentPage != null)
  5354. {
  5355. return ui.currentPage.getName();
  5356. }
  5357. else if (name == 'pagenumber')
  5358. {
  5359. if (ui.currentPage != null && ui.pages != null)
  5360. {
  5361. return mxUtils.indexOf(ui.pages, ui.currentPage) + 1;
  5362. }
  5363. else
  5364. {
  5365. return 1;
  5366. }
  5367. }
  5368. return graphGetGlobalVariable.apply(this, arguments);
  5369. };
  5370. var graphCreateLinkForHint = graph.createLinkForHint;
  5371. graph.createLinkForHint = function(href, label)
  5372. {
  5373. var pageLink = graph.isPageLink(href);
  5374. if (pageLink)
  5375. {
  5376. var comma = href.indexOf(',');
  5377. if (comma > 0)
  5378. {
  5379. var page = ui.getPageById(href.substring(comma + 1));
  5380. if (page != null)
  5381. {
  5382. label = page.getName();
  5383. }
  5384. else
  5385. {
  5386. label = mxResources.get('pageNotFound');
  5387. }
  5388. }
  5389. }
  5390. var a = graphCreateLinkForHint.apply(this, arguments);
  5391. if (pageLink)
  5392. {
  5393. mxEvent.addListener(a, 'click', function(evt)
  5394. {
  5395. pageLinkClicked(href);
  5396. mxEvent.consume(evt);
  5397. });
  5398. }
  5399. return a;
  5400. };
  5401. var graphLabelLinkClicked = graph.labelLinkClicked;
  5402. graph.labelLinkClicked = function(state, elt, evt)
  5403. {
  5404. var href = elt.getAttribute('href');
  5405. if (graph.isPageLink(href))
  5406. {
  5407. pageLinkClicked(href);
  5408. mxEvent.consume(evt);
  5409. }
  5410. else
  5411. {
  5412. graphLabelLinkClicked.apply(this, arguments);
  5413. }
  5414. };
  5415. // Overrides editor filename
  5416. this.editor.getOrCreateFilename = function()
  5417. {
  5418. var filename = ui.defaultFilename;
  5419. var file = ui.getCurrentFile();
  5420. if (file != null)
  5421. {
  5422. filename = (file.getTitle() != null) ? file.getTitle() : filename;
  5423. }
  5424. return filename;
  5425. };
  5426. // Disables print action for standalone apps on iOS
  5427. // because there is no way to close the new window
  5428. // LATER: Use iframe for print, disable preview
  5429. var printAction = this.actions.get('print');
  5430. printAction.setEnabled(!mxClient.IS_IOS || !navigator.standalone);
  5431. printAction.visible = printAction.isEnabled();
  5432. // Scales pages/graph to fit available size
  5433. if (!this.editor.chromeless)
  5434. {
  5435. // Defines additional hotkeys
  5436. this.keyHandler.bindAction(70, true, 'find'); // Ctrl+F
  5437. this.keyHandler.bindAction(67, true, 'copyStyle', true); // Ctrl+Shift+C
  5438. this.keyHandler.bindAction(86, true, 'pasteStyle', true); // Ctrl+Shift+V
  5439. this.keyHandler.bindAction(77, true, 'editGeometry', true); // Ctrl+Shift+M
  5440. this.keyHandler.bindAction(88, true, 'insertText', true); // Ctrl+Shift+X
  5441. this.keyHandler.bindAction(75, true, 'insertRectangle'); // Ctrl+K
  5442. this.keyHandler.bindAction(75, true, 'insertEllipse', true); // Ctrl+Shift+K
  5443. // Handles copy paste of images from clipboard
  5444. if (!mxClient.IS_IE)
  5445. {
  5446. graph.container.addEventListener('paste', mxUtils.bind(this, function(evt)
  5447. {
  5448. var graph = this.editor.graph;
  5449. if (!mxEvent.isConsumed(evt))
  5450. {
  5451. try
  5452. {
  5453. var data = (evt.clipboardData || evt.originalEvent.clipboardData);
  5454. var containsText = false;
  5455. // Workaround for asynchronous paste event processing in textInput
  5456. // is to ignore this event if it contains text/html/rtf (see below).
  5457. // NOTE: Image is not pasted into textInput so can't listen there.
  5458. for (var i = 0; i < data.types.length; i++)
  5459. {
  5460. if (data.types[i].substring(0, 5) === 'text/')
  5461. {
  5462. containsText = true;
  5463. break;
  5464. }
  5465. }
  5466. if (!containsText)
  5467. {
  5468. var items = data.items;
  5469. for (index in items)
  5470. {
  5471. var item = items[index];
  5472. if (item.kind === 'file')
  5473. {
  5474. if (graph.isEditing())
  5475. {
  5476. this.importFiles([item.getAsFile()], 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  5477. {
  5478. // Inserts image into current text box
  5479. graph.insertImage(data, w, h);
  5480. }, function()
  5481. {
  5482. // No post processing
  5483. }, function(file)
  5484. {
  5485. // Handles only images
  5486. return file.type.substring(0, 6) == 'image/';
  5487. }, function(queue)
  5488. {
  5489. // Invokes elements of queue in order
  5490. for (var i = 0; i < queue.length; i++)
  5491. {
  5492. queue[i]();
  5493. }
  5494. });
  5495. }
  5496. else
  5497. {
  5498. var pt = this.editor.graph.getInsertPoint();
  5499. this.importFiles([item.getAsFile()], pt.x, pt.y, this.maxImageSize);
  5500. mxEvent.consume(evt);
  5501. }
  5502. break;
  5503. }
  5504. }
  5505. }
  5506. }
  5507. catch (e)
  5508. {
  5509. // ignore
  5510. }
  5511. }
  5512. }), false);
  5513. }
  5514. // Focused but invisible textarea during control or meta key events
  5515. var textInput = document.createElement('div');
  5516. textInput.style.position = 'absolute';
  5517. textInput.style.whiteSpace = 'nowrap';
  5518. textInput.style.overflow = 'hidden';
  5519. textInput.style.display = 'block';
  5520. textInput.contentEditable = true;
  5521. mxUtils.setOpacity(textInput, 0);
  5522. textInput.style.width = '1px';
  5523. textInput.style.height = '1px';
  5524. textInput.innerHTML = '&nbsp;';
  5525. var restoreFocus = false;
  5526. // Disables built-in cut, copy and paste shortcuts
  5527. this.keyHandler.bindControlKey(88, null);
  5528. this.keyHandler.bindControlKey(67, null);
  5529. this.keyHandler.bindControlKey(86, null);
  5530. // Shows a textare when control/cmd is pressed to handle native clipboard actions
  5531. mxEvent.addListener(document, 'keydown', mxUtils.bind(this, function(evt)
  5532. {
  5533. // No dialog visible
  5534. var source = mxEvent.getSource(evt);
  5535. if (graph.container != null && graph.isEnabled() && !graph.isMouseDown && !graph.isEditing() &&
  5536. this.dialog == null && source.nodeName != 'INPUT' && source.nodeName != 'TEXTAREA')
  5537. {
  5538. if (evt.keyCode == 224 /* FF */ || (!mxClient.IS_MAC && evt.keyCode == 17 /* Control */) ||
  5539. (mxClient.IS_MAC && evt.keyCode == 91 /* Meta */))
  5540. {
  5541. // Cannot use parentNode for check in IE
  5542. if (!restoreFocus)
  5543. {
  5544. // Avoid autoscroll but allow handling of all pass-through ctrl shortcuts
  5545. textInput.style.left = (graph.container.scrollLeft + 10) + 'px';
  5546. textInput.style.top = (graph.container.scrollTop + 10) + 'px';
  5547. graph.container.appendChild(textInput);
  5548. restoreFocus = true;
  5549. // Workaround for selected document content in quirks mode
  5550. if (mxClient.IS_QUIRKS)
  5551. {
  5552. window.setTimeout(function()
  5553. {
  5554. textInput.focus();
  5555. document.execCommand('selectAll', false, null);
  5556. }, 0);
  5557. }
  5558. else
  5559. {
  5560. textInput.focus();
  5561. document.execCommand('selectAll', false, null);
  5562. }
  5563. }
  5564. }
  5565. }
  5566. }));
  5567. // Clears input and restores focus and selection
  5568. function clearInput()
  5569. {
  5570. window.setTimeout(function()
  5571. {
  5572. textInput.innerHTML = '&nbsp;';
  5573. textInput.focus();
  5574. document.execCommand('selectAll', false, null);
  5575. }, 0);
  5576. };
  5577. mxEvent.addListener(document, 'keyup', mxUtils.bind(this, function(evt)
  5578. {
  5579. // Workaround for asynchronous event read invalid in IE quirks mode
  5580. var keyCode = evt.keyCode;
  5581. // Asynchronous workaround for scroll to origin after paste if the
  5582. // Ctrl-key is not pressed for long enough in FF on Windows
  5583. window.setTimeout(mxUtils.bind(this, function()
  5584. {
  5585. if (restoreFocus && (keyCode == 224 /* FF */ || keyCode == 17 /* Control */ ||
  5586. keyCode == 91 /* Meta */))
  5587. {
  5588. restoreFocus = false;
  5589. if (!graph.isEditing() && this.dialog == null && graph.container != null)
  5590. {
  5591. graph.container.focus();
  5592. }
  5593. textInput.parentNode.removeChild(textInput);
  5594. }
  5595. }), 0);
  5596. }));
  5597. mxEvent.addListener(textInput, 'copy', mxUtils.bind(this, function(evt)
  5598. {
  5599. if (graph.isEnabled())
  5600. {
  5601. mxClipboard.copy(graph);
  5602. this.copyCells(textInput);
  5603. clearInput();
  5604. }
  5605. }));
  5606. mxEvent.addListener(textInput, 'cut', mxUtils.bind(this, function(evt)
  5607. {
  5608. if (graph.isEnabled())
  5609. {
  5610. this.copyCells(textInput, true);
  5611. clearInput();
  5612. }
  5613. }));
  5614. mxEvent.addListener(textInput, 'paste', mxUtils.bind(this, function(evt)
  5615. {
  5616. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  5617. {
  5618. textInput.innerHTML = '&nbsp;';
  5619. textInput.focus();
  5620. window.setTimeout(mxUtils.bind(this, function()
  5621. {
  5622. this.pasteCells(evt, textInput);
  5623. textInput.innerHTML = '&nbsp;';
  5624. }), 0);
  5625. }
  5626. }), true);
  5627. // Needed for IE11
  5628. var isSelectionAllowed2 = this.isSelectionAllowed;
  5629. this.isSelectionAllowed = function(evt)
  5630. {
  5631. if (mxEvent.getSource(evt) == textInput)
  5632. {
  5633. return true;
  5634. }
  5635. return isSelectionAllowed2.apply(this, arguments);
  5636. };
  5637. };
  5638. var y = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight || 0) / 2;
  5639. var x = document.body.clientWidth / 2 - 2;
  5640. // Holds the x-coordinate of the point
  5641. this.spinner = this.createSpinner(x, y, 24);
  5642. // Installs drag and drop handler for rich text editor
  5643. if (Graph.fileSupport)
  5644. {
  5645. this.editor.graph.addListener(mxEvent.EDITING_STARTED, mxUtils.bind(this, function(evt)
  5646. {
  5647. // Setup the dnd listeners
  5648. var graph = this.editor.graph;
  5649. var textElt = graph.cellEditor.text2;
  5650. var dropElt = null;
  5651. if (textElt != null)
  5652. {
  5653. mxEvent.addListener(textElt, 'dragleave', function(evt)
  5654. {
  5655. if (dropElt != null)
  5656. {
  5657. dropElt.parentNode.removeChild(dropElt);
  5658. dropElt = null;
  5659. }
  5660. evt.stopPropagation();
  5661. evt.preventDefault();
  5662. });
  5663. mxEvent.addListener(textElt, 'dragover', mxUtils.bind(this, function(evt)
  5664. {
  5665. // IE 10 does not implement pointer-events so it can't have a drop highlight
  5666. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  5667. {
  5668. dropElt = this.highlightElement(textElt);
  5669. }
  5670. evt.stopPropagation();
  5671. evt.preventDefault();
  5672. }));
  5673. mxEvent.addListener(textElt, 'drop', mxUtils.bind(this, function(evt)
  5674. {
  5675. if (dropElt != null)
  5676. {
  5677. dropElt.parentNode.removeChild(dropElt);
  5678. dropElt = null;
  5679. }
  5680. if (evt.dataTransfer.files.length > 0)
  5681. {
  5682. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  5683. {
  5684. // Inserts image into current text box
  5685. graph.insertImage(data, w, h);
  5686. }, function()
  5687. {
  5688. // No post processing
  5689. }, function(file)
  5690. {
  5691. // Handles only images
  5692. return file.type.substring(0, 6) == 'image/';
  5693. }, function(queue)
  5694. {
  5695. // Invokes elements of queue in order
  5696. for (var i = 0; i < queue.length; i++)
  5697. {
  5698. queue[i]();
  5699. }
  5700. }, mxEvent.isControlDown(evt));
  5701. }
  5702. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  5703. {
  5704. var uri = evt.dataTransfer.getData('text/uri-list');
  5705. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  5706. {
  5707. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  5708. {
  5709. var w = Math.max(1, img.width);
  5710. var h = Math.max(1, img.height);
  5711. var maxSize = this.maxImageSize;
  5712. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  5713. graph.insertImage(decodeURIComponent(uri), w * s, h * s);
  5714. }));
  5715. }
  5716. else
  5717. {
  5718. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  5719. }
  5720. }
  5721. else
  5722. {
  5723. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  5724. {
  5725. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/html'));
  5726. }
  5727. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  5728. {
  5729. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  5730. }
  5731. }
  5732. evt.stopPropagation();
  5733. evt.preventDefault();
  5734. }));
  5735. }
  5736. }));
  5737. }
  5738. //Add ruler in test mode only
  5739. //TODO add the ruler containers correctly and make the vertical one dynamic as the side panel size can change
  5740. if (urlParams['ruler'] == '1' && typeof mxRuler !== 'undefined')
  5741. {
  5742. var hRulerDiv = document.createElement('div');
  5743. hRulerDiv.style.position = 'absolute';
  5744. hRulerDiv.style.top = '95px';
  5745. hRulerDiv.style.left = '250px';
  5746. hRulerDiv.style.width = '2000px';
  5747. hRulerDiv.style.height = '30px';
  5748. hRulerDiv.style.background = 'whiteSmoke';
  5749. document.body.appendChild(hRulerDiv);
  5750. var vRulerDiv = document.createElement('div');
  5751. vRulerDiv.style.position = 'absolute';
  5752. vRulerDiv.style.top = '125px';
  5753. vRulerDiv.style.left = '220px';
  5754. vRulerDiv.style.width = '30px';
  5755. vRulerDiv.style.height = '1000px';
  5756. vRulerDiv.style.background = 'whiteSmoke';
  5757. document.body.appendChild(vRulerDiv);
  5758. var square = document.createElement('div');
  5759. square.style.position = 'absolute';
  5760. square.style.top = '95px';
  5761. square.style.left = '220px';
  5762. square.style.width = '30px';
  5763. square.style.height = '30px';
  5764. square.style.background = 'whiteSmoke';
  5765. document.body.appendChild(square);
  5766. this.vRuler = new mxRuler(this.editor.graph, vRulerDiv, true);
  5767. this.hRuler = new mxRuler(this.editor.graph, hRulerDiv, false);
  5768. }
  5769. // Adds an element to edit the style in the footer in test mode
  5770. if (urlParams['test'] == '1')
  5771. {
  5772. var footer = document.getElementById('geFooter');
  5773. if (footer != null)
  5774. {
  5775. this.styleInput = document.createElement('input');
  5776. this.styleInput.setAttribute('type', 'text');
  5777. this.styleInput.style.position = 'absolute';
  5778. this.styleInput.style.top = '14px';
  5779. this.styleInput.style.left = '2px';
  5780. // Workaround for ignore right CSS property in FF
  5781. this.styleInput.style.width = '98%';
  5782. this.styleInput.style.visibility = 'hidden';
  5783. this.styleInput.style.opacity = '0.9';
  5784. mxEvent.addListener(this.styleInput, 'change', mxUtils.bind(this, function()
  5785. {
  5786. this.editor.graph.getModel().setStyle(this.editor.graph.getSelectionCell(), this.styleInput.value);
  5787. }));
  5788. footer.appendChild(this.styleInput);
  5789. this.editor.graph.getSelectionModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function(sender, evt)
  5790. {
  5791. if (this.editor.graph.getSelectionCount() > 0)
  5792. {
  5793. var cell = this.editor.graph.getSelectionCell();
  5794. var style = this.editor.graph.getModel().getStyle(cell);
  5795. this.styleInput.value = style || '';
  5796. this.styleInput.style.visibility = 'visible';
  5797. } else
  5798. {
  5799. this.styleInput.style.visibility = 'hidden';
  5800. }
  5801. }));
  5802. }
  5803. var isSelectionAllowed = this.isSelectionAllowed;
  5804. this.isSelectionAllowed = function(evt)
  5805. {
  5806. if (mxEvent.getSource(evt) == this.styleInput)
  5807. {
  5808. return true;
  5809. }
  5810. return isSelectionAllowed.apply(this, arguments);
  5811. };
  5812. }
  5813. // Removes info text in page
  5814. var info = document.getElementById('geInfo');
  5815. if (info != null)
  5816. {
  5817. info.parentNode.removeChild(info);
  5818. }
  5819. // Installs drag and drop handler for files
  5820. // Enables dropping files
  5821. if (Graph.fileSupport)
  5822. {
  5823. // Setup the dnd listeners
  5824. var dropElt = null;
  5825. mxEvent.addListener(graph.container, 'dragleave', function(evt)
  5826. {
  5827. if (graph.isEnabled())
  5828. {
  5829. if (dropElt != null)
  5830. {
  5831. dropElt.parentNode.removeChild(dropElt);
  5832. dropElt = null;
  5833. }
  5834. evt.stopPropagation();
  5835. evt.preventDefault();
  5836. }
  5837. });
  5838. mxEvent.addListener(graph.container, 'dragover', mxUtils.bind(this, function(evt)
  5839. {
  5840. // IE 10 does not implement pointer-events so it can't have a drop highlight
  5841. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  5842. {
  5843. dropElt = this.highlightElement(graph.container);
  5844. }
  5845. if (this.sidebar != null)
  5846. {
  5847. this.sidebar.hideTooltip();
  5848. }
  5849. evt.stopPropagation();
  5850. evt.preventDefault();
  5851. }));
  5852. mxEvent.addListener(graph.container, 'drop', mxUtils.bind(this, function(evt)
  5853. {
  5854. if (dropElt != null)
  5855. {
  5856. dropElt.parentNode.removeChild(dropElt);
  5857. dropElt = null;
  5858. }
  5859. if (graph.isEnabled())
  5860. {
  5861. var pt = mxUtils.convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  5862. var tr = graph.view.translate;
  5863. var scale = graph.view.scale;
  5864. var x = pt.x / scale - tr.x;
  5865. var y = pt.y / scale - tr.y;
  5866. if (mxEvent.isAltDown(evt))
  5867. {
  5868. x = 0;
  5869. y = 0;
  5870. }
  5871. if (evt.dataTransfer.files.length > 0)
  5872. {
  5873. this.importFiles(evt.dataTransfer.files, x, y, this.maxImageSize, null, null, null, null,
  5874. mxEvent.isControlDown(evt), null, null, mxEvent.isShiftDown(evt));
  5875. }
  5876. else
  5877. {
  5878. var uri = (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0) ?
  5879. evt.dataTransfer.getData('text/uri-list') : null;
  5880. var data = this.extractGraphModelFromEvent(evt, this.pages != null);
  5881. if (data != null)
  5882. {
  5883. graph.setSelectionCells(this.importXml(data, x, y, true));
  5884. }
  5885. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  5886. {
  5887. var html = evt.dataTransfer.getData('text/html');
  5888. var div = document.createElement('div');
  5889. div.innerHTML = html;
  5890. // The default is based on the extension
  5891. var asImage = null;
  5892. // Extracts single image
  5893. var imgs = div.getElementsByTagName('img');
  5894. if (imgs != null && imgs.length == 1)
  5895. {
  5896. html = imgs[0].getAttribute('src');
  5897. // Handles special case where the src attribute has no valid extension
  5898. // in which case the text would be inserted as text with a link
  5899. if (!(/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(html))
  5900. {
  5901. asImage = true;
  5902. }
  5903. }
  5904. else
  5905. {
  5906. // Extracts single link
  5907. var a = div.getElementsByTagName('a');
  5908. if (a != null && a.length == 1)
  5909. {
  5910. html = a[0].getAttribute('href');
  5911. }
  5912. }
  5913. var resizeImages = true;
  5914. var doInsert = mxUtils.bind(this, function()
  5915. {
  5916. graph.setSelectionCells(this.insertTextAt(html, x, y, true, asImage, null, resizeImages));
  5917. });
  5918. if (asImage && html.length > this.resampleThreshold)
  5919. {
  5920. this.confirmImageResize(function(doResize)
  5921. {
  5922. resizeImages = doResize;
  5923. doInsert();
  5924. }, mxEvent.isControlDown(evt));
  5925. }
  5926. else
  5927. {
  5928. doInsert();
  5929. }
  5930. }
  5931. else if (uri != null && (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  5932. {
  5933. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  5934. {
  5935. var w = Math.max(1, img.width);
  5936. var h = Math.max(1, img.height);
  5937. var maxSize = this.maxImageSize;
  5938. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  5939. graph.setSelectionCell(graph.insertVertex(null, null, '', x, y, w * s, h * s,
  5940. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  5941. 'verticalAlign=top;aspect=fixed;imageAspect=0;image=' + uri + ';'));
  5942. }), mxUtils.bind(this, function(img)
  5943. {
  5944. graph.setSelectionCells(this.insertTextAt(uri, x, y, true));
  5945. }));
  5946. }
  5947. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  5948. {
  5949. graph.setSelectionCells(this.insertTextAt(evt.dataTransfer.getData('text/plain'), x, y, true));
  5950. }
  5951. }
  5952. }
  5953. evt.stopPropagation();
  5954. evt.preventDefault();
  5955. }), false);
  5956. }
  5957. this.initPages();
  5958. // Embedded mode
  5959. if (urlParams['embed'] == '1')
  5960. {
  5961. this.initializeEmbedMode();
  5962. }
  5963. if (typeof window.mxSettings !== 'undefined')
  5964. {
  5965. this.installSettings();
  5966. }
  5967. };
  5968. /**
  5969. * Creates the format panel and adds overrides.
  5970. */
  5971. EditorUi.prototype.installSettings = function()
  5972. {
  5973. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  5974. {
  5975. // Gets recent colors from settings
  5976. ColorDialog.recentColors = mxSettings.getRecentColors();
  5977. /**
  5978. * Persists current edge style.
  5979. */
  5980. this.editor.graph.currentEdgeStyle = mxSettings.getCurrentEdgeStyle();
  5981. this.editor.graph.currentVertexStyle = mxSettings.getCurrentVertexStyle();
  5982. // Updates UI to reflect current edge style
  5983. this.fireEvent(new mxEventObject('styleChanged', 'keys', [], 'values', [], 'cells', []));
  5984. this.addListener('styleChanged', mxUtils.bind(this, function(sender, evt)
  5985. {
  5986. mxSettings.setCurrentEdgeStyle(this.editor.graph.currentEdgeStyle);
  5987. mxSettings.setCurrentVertexStyle(this.editor.graph.currentVertexStyle);
  5988. mxSettings.save();
  5989. }));
  5990. /**
  5991. * Persists copy on connect switch.
  5992. */
  5993. this.editor.graph.connectionHandler.setCreateTarget(mxSettings.isCreateTarget());
  5994. this.fireEvent(new mxEventObject('copyConnectChanged'));
  5995. this.addListener('copyConnectChanged', mxUtils.bind(this, function(sender, evt)
  5996. {
  5997. mxSettings.setCreateTarget(this.editor.graph.connectionHandler.isCreateTarget());
  5998. mxSettings.save();
  5999. }));
  6000. /**
  6001. * Persists default page format.
  6002. */
  6003. this.editor.graph.pageFormat = mxSettings.getPageFormat();
  6004. this.addListener('pageFormatChanged', mxUtils.bind(this, function(sender, evt)
  6005. {
  6006. mxSettings.setPageFormat(this.editor.graph.pageFormat);
  6007. mxSettings.save();
  6008. }));
  6009. /**
  6010. * Persists default grid color.
  6011. */
  6012. this.editor.graph.view.gridColor = mxSettings.getGridColor();
  6013. this.addListener('gridColorChanged', mxUtils.bind(this, function(sender, evt)
  6014. {
  6015. mxSettings.setGridColor(this.editor.graph.view.gridColor);
  6016. mxSettings.save();
  6017. }));
  6018. /**
  6019. * Persists autosave switch in Chrome app.
  6020. */
  6021. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  6022. {
  6023. this.editor.addListener('autosaveChanged', mxUtils.bind(this, function(sender, evt)
  6024. {
  6025. mxSettings.setAutosave(this.editor.autosave);
  6026. mxSettings.save();
  6027. }));
  6028. this.editor.autosave = mxSettings.getAutosave();
  6029. }
  6030. /**
  6031. *
  6032. */
  6033. if (this.sidebar != null)
  6034. {
  6035. this.sidebar.showPalette('search', mxSettings.settings.search);
  6036. }
  6037. /**
  6038. * Shows scratchpad if never shown.
  6039. */
  6040. if (!this.editor.chromeless && this.sidebar != null && (mxSettings.settings.isNew ||
  6041. parseInt(mxSettings.settings.version || 0) <= 8))
  6042. {
  6043. this.toggleScratchpad();
  6044. mxSettings.save();
  6045. }
  6046. // Saves app defaults for UI
  6047. this.addListener('formatWidthChanged', function()
  6048. {
  6049. mxSettings.setFormatWidth(this.formatWidth);
  6050. mxSettings.save();
  6051. });
  6052. }
  6053. };
  6054. /**
  6055. * Creates the format panel and adds overrides.
  6056. */
  6057. EditorUi.prototype.copyCells = function(elt, removeCells)
  6058. {
  6059. var graph = this.editor.graph;
  6060. if (!graph.isSelectionEmpty())
  6061. {
  6062. var cells = mxUtils.sortCells(graph.model.getTopmostCells(graph.getSelectionCells()));
  6063. // LATER: Add span with XML in data attribute
  6064. // var span = document.createElement('span');
  6065. // span.setAttribute('data-jgraph-type', 'application/vnd.jgraph.xml');
  6066. // span.setAttribute('data-jgraph-content', mxUtils.getXml(graph.encodeCells(clones)));
  6067. // Fixes cross-platform clipboard UTF8 issues by encoding as URI
  6068. var xml = mxUtils.getXml(this.editor.graph.encodeCells(cells));
  6069. mxUtils.setTextContent(elt, encodeURIComponent(xml));
  6070. if (removeCells)
  6071. {
  6072. graph.removeCells(cells, false);
  6073. graph.lastPasteXml = null;
  6074. }
  6075. else
  6076. {
  6077. graph.lastPasteXml = xml;
  6078. graph.pasteCounter = 0;
  6079. }
  6080. elt.focus();
  6081. document.execCommand('selectAll', false, null);
  6082. }
  6083. else
  6084. {
  6085. // Disables copy on focused element
  6086. elt.innerHTML = '';
  6087. }
  6088. };
  6089. /**
  6090. * Creates the format panel and adds overrides.
  6091. */
  6092. EditorUi.prototype.pasteCells = function(evt, elt)
  6093. {
  6094. if (!mxEvent.isConsumed(evt))
  6095. {
  6096. var spans = elt.getElementsByTagName('span');
  6097. if (spans != null && spans.length > 0 && spans[0].getAttribute('data-lucid-type') ===
  6098. 'application/vnd.lucid.chart.objects')
  6099. {
  6100. var content = spans[0].getAttribute('data-lucid-content');
  6101. if (content != null && content.length > 0)
  6102. {
  6103. this.importLucidChart(content, 0, 0);
  6104. mxEvent.consume(evt);
  6105. }
  6106. }
  6107. else
  6108. {
  6109. var graph = this.editor.graph;
  6110. var xml = mxUtils.trim((mxClient.IS_QUIRKS || document.documentMode == 8) ?
  6111. mxUtils.getTextContent(elt) : elt.textContent);
  6112. var compat = false;
  6113. // Workaround for junk after XML in VM
  6114. try
  6115. {
  6116. var idx = xml.lastIndexOf('%3E');
  6117. if (idx >= 0 && idx < xml.length - 3)
  6118. {
  6119. xml = xml.substring(0, idx + 3);
  6120. }
  6121. }
  6122. catch (e)
  6123. {
  6124. // ignore
  6125. }
  6126. // Checks for embedded XML content
  6127. try
  6128. {
  6129. var spans = elt.getElementsByTagName('span');
  6130. var tmp = (spans != null && spans.length > 0) ?
  6131. mxUtils.trim(decodeURIComponent(spans[0].textContent)) :
  6132. decodeURIComponent(xml);
  6133. if (this.isCompatibleString(tmp))
  6134. {
  6135. compat = true;
  6136. xml = tmp;
  6137. }
  6138. }
  6139. catch (e)
  6140. {
  6141. // ignore
  6142. }
  6143. if (graph.lastPasteXml == xml)
  6144. {
  6145. graph.pasteCounter++;
  6146. }
  6147. else
  6148. {
  6149. graph.lastPasteXml = xml;
  6150. graph.pasteCounter = 0;
  6151. }
  6152. var dx = graph.pasteCounter * graph.gridSize;
  6153. if (xml != null && xml.length > 0)
  6154. {
  6155. if (compat || this.isCompatibleString(xml))
  6156. {
  6157. graph.setSelectionCells(this.importXml(xml, dx, dx));
  6158. }
  6159. else
  6160. {
  6161. var pt = graph.getInsertPoint();
  6162. if (graph.isMouseInsertPoint())
  6163. {
  6164. dx = 0;
  6165. // No offset for insert at mouse position
  6166. if (graph.lastPasteXml == xml && graph.pasteCounter > 0)
  6167. {
  6168. graph.pasteCounter--;
  6169. }
  6170. }
  6171. graph.setSelectionCells(this.insertTextAt(xml, pt.x + dx, pt.y + dx, true));
  6172. }
  6173. if (!graph.isSelectionEmpty())
  6174. {
  6175. graph.scrollCellToVisible(graph.getSelectionCell());
  6176. if (this.hoverIcons != null)
  6177. {
  6178. this.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  6179. }
  6180. try
  6181. {
  6182. mxEvent.consume(evt);
  6183. }
  6184. catch (e)
  6185. {
  6186. // ignore event no longer exists in async handler in IE8-
  6187. }
  6188. }
  6189. }
  6190. }
  6191. }
  6192. };
  6193. /**
  6194. * Adds a file drop handler for opening local files.
  6195. */
  6196. EditorUi.prototype.addFileDropHandler = function(elts)
  6197. {
  6198. // Installs drag and drop handler for files
  6199. if (Graph.fileSupport)
  6200. {
  6201. var dropElt = null;
  6202. for (var i = 0; i < elts.length; i++)
  6203. {
  6204. // Setup the dnd listeners
  6205. mxEvent.addListener(elts[i], 'dragleave', function(evt)
  6206. {
  6207. if (dropElt != null)
  6208. {
  6209. dropElt.parentNode.removeChild(dropElt);
  6210. dropElt = null;
  6211. }
  6212. evt.stopPropagation();
  6213. evt.preventDefault();
  6214. });
  6215. mxEvent.addListener(elts[i], 'dragover', mxUtils.bind(this, function(evt)
  6216. {
  6217. if (this.editor.graph.isEnabled() || urlParams['embed'] != '1')
  6218. {
  6219. // IE 10 does not implement pointer-events so it can't have a drop highlight
  6220. if (dropElt == null && (!mxClient.IS_IE || (document.documentMode > 10 && document.documentMode < 12)))
  6221. {
  6222. dropElt = this.highlightElement();
  6223. }
  6224. }
  6225. evt.stopPropagation();
  6226. evt.preventDefault();
  6227. }));
  6228. mxEvent.addListener(elts[i], 'drop', mxUtils.bind(this, function(evt)
  6229. {
  6230. if (dropElt != null)
  6231. {
  6232. dropElt.parentNode.removeChild(dropElt);
  6233. dropElt = null;
  6234. }
  6235. if (this.editor.graph.isEnabled() || urlParams['embed'] != '1')
  6236. {
  6237. if (evt.dataTransfer.files.length > 0)
  6238. {
  6239. this.hideDialog();
  6240. // Never open files in embed mode
  6241. if (urlParams['embed'] == '1')
  6242. {
  6243. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, null, null,
  6244. null, null, !mxEvent.isControlDown(evt) && !mxEvent.isShiftDown(evt));
  6245. }
  6246. else
  6247. {
  6248. this.openFiles(evt.dataTransfer.files, true);
  6249. }
  6250. }
  6251. else
  6252. {
  6253. // Handles open special files via text drag and drop
  6254. var data = this.extractGraphModelFromEvent(evt);
  6255. // Tries additional and async parsing of text content such as HTML, Gliffy data
  6256. if (data == null)
  6257. {
  6258. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  6259. if (provider != null)
  6260. {
  6261. if (document.documentMode == 10 || document.documentMode == 11)
  6262. {
  6263. data = provider.getData('Text');
  6264. }
  6265. else
  6266. {
  6267. var data = null;
  6268. if (mxUtils.indexOf(provider.types, 'text/uri-list') >= 0)
  6269. {
  6270. var data = evt.dataTransfer.getData('text/uri-list');
  6271. }
  6272. else
  6273. {
  6274. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  6275. }
  6276. if (data != null && data.length > 0)
  6277. {
  6278. var div = document.createElement('div');
  6279. div.innerHTML = data;
  6280. // Extracts single image
  6281. var imgs = div.getElementsByTagName('img');
  6282. if (imgs.length > 0)
  6283. {
  6284. data = imgs[0].getAttribute('src');
  6285. }
  6286. }
  6287. else if (mxUtils.indexOf(provider.types, 'text/plain') >= 0)
  6288. {
  6289. data = provider.getData('text/plain');
  6290. }
  6291. }
  6292. if (data != null)
  6293. {
  6294. // Checks for embedded XML in PNG
  6295. if (data.substring(0, 22) == 'data:image/png;base64,')
  6296. {
  6297. var xml = this.extractGraphModelFromPng(data);
  6298. if (xml != null && xml.length > 0)
  6299. {
  6300. this.openLocalFile(xml, null, true);
  6301. }
  6302. }
  6303. else if (!this.isOffline() && this.isRemoteFileFormat(data))
  6304. {
  6305. new mxXmlRequest(OPEN_URL, 'format=xml&data=' + encodeURIComponent(data)).send(mxUtils.bind(this, function(req)
  6306. {
  6307. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  6308. {
  6309. this.openLocalFile(req.getText(), null, true);
  6310. }
  6311. }));
  6312. }
  6313. else if (/^https?:\/\//.test(data))
  6314. {
  6315. if (this.getCurrentFile() == null)
  6316. {
  6317. window.location.hash = '#U' + encodeURIComponent(data);
  6318. }
  6319. else
  6320. {
  6321. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  6322. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  6323. window.location.search + '#U' + encodeURIComponent(data));
  6324. }
  6325. }
  6326. }
  6327. }
  6328. }
  6329. else
  6330. {
  6331. this.openLocalFile(data, null, true);
  6332. }
  6333. }
  6334. }
  6335. evt.stopPropagation();
  6336. evt.preventDefault();
  6337. }));
  6338. }
  6339. }
  6340. };
  6341. /**
  6342. * Highlights the given element
  6343. */
  6344. EditorUi.prototype.highlightElement = function(elt)
  6345. {
  6346. var x = 0;
  6347. var y = 0;
  6348. var w = 0;
  6349. var h = 0;
  6350. if (elt == null)
  6351. {
  6352. var b = document.body;
  6353. var d = document.documentElement;
  6354. w = (b.clientWidth || d.clientWidth) - 3;
  6355. h = Math.max(b.clientHeight || 0, d.clientHeight) - 3;
  6356. }
  6357. else
  6358. {
  6359. x = elt.offsetTop;
  6360. y = elt.offsetLeft;
  6361. w = elt.clientWidth;
  6362. h = elt.clientHeight;
  6363. }
  6364. var hl = document.createElement('div');
  6365. hl.style.zIndex = mxPopupMenu.prototype.zIndex + 2;
  6366. hl.style.border = '3px dotted rgb(254, 137, 12)';
  6367. hl.style.pointerEvents = 'none';
  6368. hl.style.position = 'absolute';
  6369. hl.style.top = x + 'px';
  6370. hl.style.left = y + 'px';
  6371. hl.style.width = Math.max(0, w - 3) + 'px';
  6372. hl.style.height = Math.max(0, h - 3) + 'px';
  6373. if (elt != null && elt.parentNode == this.editor.graph.container)
  6374. {
  6375. this.editor.graph.container.appendChild(hl);
  6376. }
  6377. else
  6378. {
  6379. document.body.appendChild(hl);
  6380. }
  6381. return hl;
  6382. };
  6383. /**
  6384. * Highlights the given element
  6385. */
  6386. EditorUi.prototype.stringToCells = function(xml)
  6387. {
  6388. var doc = mxUtils.parseXml(xml);
  6389. var node = this.editor.extractGraphModel(doc.documentElement);
  6390. var cells = [];
  6391. if (node != null)
  6392. {
  6393. var codec = new mxCodec(node.ownerDocument);
  6394. var model = new mxGraphModel();
  6395. codec.decode(node, model);
  6396. var parent = model.getChildAt(model.getRoot(), 0);
  6397. for (var j = 0; j < model.getChildCount(parent); j++)
  6398. {
  6399. cells.push(model.getChildAt(parent, j));
  6400. }
  6401. }
  6402. return cells;
  6403. };
  6404. /**
  6405. * Opens the given files in the editor.
  6406. */
  6407. EditorUi.prototype.openFiles = function(files, temp)
  6408. {
  6409. if (this.spinner.spin(document.body, mxResources.get('loading')))
  6410. {
  6411. for (var i = 0; i < files.length; i++)
  6412. {
  6413. (mxUtils.bind(this, function(file)
  6414. {
  6415. var reader = new FileReader();
  6416. reader.onload = mxUtils.bind(this, function(e)
  6417. {
  6418. var data = e.target.result;
  6419. var name = file.name;
  6420. if (name != null && name.length > 0)
  6421. {
  6422. if (/(\.png)$/i.test(name))
  6423. {
  6424. name = name.substring(0, name.length - 4) + '.xml';
  6425. }
  6426. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload &&
  6427. this.isRemoteFileFormat(data, name))
  6428. {
  6429. var dot = name.lastIndexOf('.');
  6430. if (dot >= 0)
  6431. {
  6432. name = name.substring(0, name.lastIndexOf('.')) + '.xml';
  6433. }
  6434. else
  6435. {
  6436. name = name + '.xml';
  6437. }
  6438. this.parseFile(file, mxUtils.bind(this, function(xhr)
  6439. {
  6440. if (xhr.readyState == 4)
  6441. {
  6442. this.spinner.stop();
  6443. if (xhr.status >= 200 && xhr.status <= 299)
  6444. {
  6445. var xml = xhr.responseText;
  6446. if (xml.substring(0, 10) == '<mxlibrary')
  6447. {
  6448. // Creates new temporary file if library is dropped in splash screen
  6449. if (this.getCurrentFile() == null && urlParams['embed'] != '1')
  6450. {
  6451. this.openLocalFile(this.emptyDiagramXml, this.defaultFilename, temp);
  6452. }
  6453. if (name != null && name.toLowerCase().substring(name.length - 5) == '.vssx')
  6454. {
  6455. name = name.substring(0, filename.length - 5) + '.xml';
  6456. }
  6457. try
  6458. {
  6459. this.loadLibrary(new LocalLibrary(this, xml, name));
  6460. }
  6461. catch (e)
  6462. {
  6463. this.handleError(e, mxResources.get('errorLoadingFile'));
  6464. }
  6465. }
  6466. else
  6467. {
  6468. this.openLocalFile(xml, name, temp);
  6469. }
  6470. }
  6471. else
  6472. {
  6473. this.handleError({message: mxResources.get((xhr.status == 413) ?
  6474. 'drawingTooLarge' : 'invalidOrMissingFile')},
  6475. mxResources.get('errorLoadingFile'));
  6476. }
  6477. }
  6478. }));
  6479. }
  6480. else if (data.substring(0, 26) == '{"state":"{\\"Properties\\":')
  6481. {
  6482. if (/(\.json)$/i.test(name))
  6483. {
  6484. name = name.substring(0, name.length - 5) + '.xml';
  6485. }
  6486. // LATER: Add import step that produces cells and use callback
  6487. this.openLocalFile(this.emptyDiagramXml, name, temp);
  6488. this.importLucidChart(data, 0, 0, null, mxUtils.bind(this, function()
  6489. {
  6490. this.editor.undoManager.clear();
  6491. this.spinner.stop();
  6492. }));
  6493. }
  6494. else if (e.target.result.substring(0, 10) == '<mxlibrary')
  6495. {
  6496. this.spinner.stop();
  6497. // Creates new temporary file if library is dropped in splash screen
  6498. if (this.getCurrentFile() == null && urlParams['embed'] != '1')
  6499. {
  6500. this.openLocalFile(this.emptyDiagramXml, this.defaultFilename, temp);
  6501. }
  6502. try
  6503. {
  6504. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  6505. }
  6506. catch (e)
  6507. {
  6508. this.handleError(e, mxResources.get('errorLoadingFile'));
  6509. }
  6510. }
  6511. else
  6512. {
  6513. if (file.type.substring(0, 9) == 'image/png')
  6514. {
  6515. data = this.extractGraphModelFromPng(data);
  6516. }
  6517. this.spinner.stop();
  6518. this.openLocalFile(data, name, temp);
  6519. }
  6520. }
  6521. });
  6522. reader.onerror = mxUtils.bind(this, function(e)
  6523. {
  6524. this.spinner.stop();
  6525. this.handleError(e);
  6526. window.openFile = null;
  6527. });
  6528. if (file.type.substring(0, 5) === 'image' && file.type.substring(0, 9) !== 'image/svg')
  6529. {
  6530. reader.readAsDataURL(file);
  6531. }
  6532. else
  6533. {
  6534. reader.readAsText(file);
  6535. }
  6536. }))(files[i]);
  6537. }
  6538. }
  6539. };
  6540. /**
  6541. * Shows the layers dialog if the graph has more than one layer.
  6542. */
  6543. EditorUi.prototype.openLocalFile = function(data, name, temp)
  6544. {
  6545. var currentFile = this.getCurrentFile();
  6546. var fn = mxUtils.bind(this, function()
  6547. {
  6548. window.openFile = null;
  6549. if (name == null && this.getCurrentFile() != null && this.isDiagramEmpty())
  6550. {
  6551. var doc = mxUtils.parseXml(data);
  6552. if (doc != null)
  6553. {
  6554. this.editor.setGraphXml(doc.documentElement);
  6555. this.editor.graph.selectAll();
  6556. }
  6557. }
  6558. else
  6559. {
  6560. this.fileLoaded(new LocalFile(this, data, name || this.defaultFilename, temp));
  6561. }
  6562. });
  6563. if (data != null && data.length > 0)
  6564. {
  6565. if (currentFile == null || (!currentFile.isModified() &&
  6566. (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)))
  6567. {
  6568. fn();
  6569. }
  6570. else if ((mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) &&
  6571. currentFile != null && currentFile.isModified())
  6572. {
  6573. this.confirm(mxResources.get('allChangesLost'), null, fn,
  6574. mxResources.get('cancel'), mxResources.get('discardChanges'));
  6575. }
  6576. else
  6577. {
  6578. window.openFile = new OpenFile(function()
  6579. {
  6580. window.openFile = null;
  6581. });
  6582. window.openFile.setData(data, name);
  6583. window.openWindow(this.getUrl(), null, mxUtils.bind(this, function()
  6584. {
  6585. this.confirm(mxResources.get('allChangesLost'), null, fn,
  6586. mxResources.get('cancel'), mxResources.get('discardChanges'));
  6587. }));
  6588. }
  6589. }
  6590. };
  6591. /**
  6592. * Returns a list of all shapes used in the current file.
  6593. */
  6594. EditorUi.prototype.getBasenames = function()
  6595. {
  6596. var basenames = {};
  6597. if (this.pages != null)
  6598. {
  6599. for (var i = 0; i < this.pages.length; i++)
  6600. {
  6601. this.updatePageRoot(this.pages[i]);
  6602. this.addBasenamesForCell(this.pages[i].root, basenames);
  6603. }
  6604. }
  6605. else
  6606. {
  6607. this.addBasenamesForCell(this.editor.graph.model.getRoot(), basenames);
  6608. }
  6609. var result = [];
  6610. for (var key in basenames)
  6611. {
  6612. result.push(key);
  6613. }
  6614. return result;
  6615. };
  6616. /**
  6617. * Returns a list of all shapes used in the current file.
  6618. */
  6619. EditorUi.prototype.addBasenamesForCell = function(cell, basenames)
  6620. {
  6621. function addName(name)
  6622. {
  6623. if (name != null)
  6624. {
  6625. // LATER: Check if this case exists
  6626. var dot = name.lastIndexOf('.');
  6627. if (dot > 0)
  6628. {
  6629. name = name.substring(dot + 1, name.length);
  6630. }
  6631. if (basenames[name] == null)
  6632. {
  6633. basenames[name] = true;
  6634. }
  6635. }
  6636. };
  6637. var graph = this.editor.graph;
  6638. var style = graph.getCellStyle(cell);
  6639. var shape = style[mxConstants.STYLE_SHAPE];
  6640. addName(mxStencilRegistry.getBasenameForStencil(shape));
  6641. // Adds package names for markers in edges
  6642. if (graph.model.isEdge(cell))
  6643. {
  6644. addName(mxMarker.getPackageForType(style[mxConstants.STYLE_STARTARROW]));
  6645. addName(mxMarker.getPackageForType(style[mxConstants.STYLE_ENDARROW]));
  6646. }
  6647. var childCount = graph.model.getChildCount(cell);
  6648. for (var i = 0; i < childCount; i++)
  6649. {
  6650. this.addBasenamesForCell(graph.model.getChildAt(cell, i), basenames);
  6651. }
  6652. };
  6653. /**
  6654. * Shows the layers dialog if the graph has more than one layer.
  6655. */
  6656. EditorUi.prototype.setGraphEnabled = function(enabled)
  6657. {
  6658. this.diagramContainer.style.visibility = (enabled) ? '' : 'hidden';
  6659. this.formatContainer.style.visibility = (enabled) ? '' : 'hidden';
  6660. this.sidebarFooterContainer.style.display = (enabled) ? '' : 'none';
  6661. this.sidebarContainer.style.display = (enabled) ? '' : 'none';
  6662. this.hsplit.style.display = (enabled) ? '' : 'none';
  6663. this.editor.graph.setEnabled(enabled);
  6664. if (this.tabContainer != null)
  6665. {
  6666. this.tabContainer.style.visibility = (enabled) ? '' : 'hidden';
  6667. }
  6668. };
  6669. /**
  6670. * Shows the layers dialog if the graph has more than one layer.
  6671. */
  6672. EditorUi.prototype.initializeEmbedMode = function()
  6673. {
  6674. this.setGraphEnabled(false);
  6675. var parent = window.opener || window.parent;
  6676. if (parent != window)
  6677. {
  6678. if (urlParams['spin'] != '1' || this.spinner.spin(document.body, mxResources.get('loading')))
  6679. {
  6680. this.installMessageHandler(mxUtils.bind(this, function(xml, evt, modified)
  6681. {
  6682. this.spinner.stop();
  6683. this.addEmbedButtons();
  6684. this.setGraphEnabled(true);
  6685. if (xml != null && xml.length > 0)
  6686. {
  6687. this.setFileData(xml);
  6688. this.showLayersDialog();
  6689. }
  6690. else
  6691. {
  6692. this.editor.graph.model.clear();
  6693. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  6694. }
  6695. this.editor.undoManager.clear();
  6696. this.editor.modified = (modified != null) ? modified : false;
  6697. this.updateUi();
  6698. // Workaround for no initial focus in FF
  6699. // (does not work in Conf Cloud with FF)
  6700. if (window.self !== window.top)
  6701. {
  6702. window.focus();
  6703. }
  6704. if (this.format != null)
  6705. {
  6706. this.format.refresh();
  6707. }
  6708. }));
  6709. }
  6710. }
  6711. };
  6712. /**
  6713. * Shows the layers dialog if the graph has more than one layer.
  6714. */
  6715. EditorUi.prototype.showLayersDialog = function()
  6716. {
  6717. if (this.editor.graph.getModel().getChildCount(this.editor.graph.getModel().getRoot()) > 1)
  6718. {
  6719. if (this.actions.layersWindow == null)
  6720. {
  6721. this.actions.get('layers').funct();
  6722. }
  6723. else
  6724. {
  6725. this.actions.layersWindow.window.setVisible(true);
  6726. }
  6727. }
  6728. };
  6729. /**
  6730. * Tries to find a public URL for the given file.
  6731. */
  6732. EditorUi.prototype.getPublicUrl = function(file, fn)
  6733. {
  6734. if (file != null)
  6735. {
  6736. file.getPublicUrl(fn);
  6737. }
  6738. else
  6739. {
  6740. fn(null);
  6741. }
  6742. };
  6743. /**
  6744. * Adds the buttons for embedded mode.
  6745. */
  6746. EditorUi.prototype.createLoadMessage = function(eventName)
  6747. {
  6748. var graph = this.editor.graph;
  6749. return {event: eventName, pageVisible: graph.pageVisible, translate: graph.view.translate,
  6750. scale: graph.view.scale, page: graph.view.getBackgroundPageBounds(), bounds: graph.getGraphBounds()};
  6751. };
  6752. /**
  6753. * Adds the buttons for embedded mode.
  6754. */
  6755. EditorUi.prototype.installMessageHandler = function(fn)
  6756. {
  6757. var changeListener = null;
  6758. var ignoreChange = false;
  6759. var autosave = false;
  6760. var lastData = null;
  6761. var updateStatus = mxUtils.bind(this, function(sender, eventObject)
  6762. {
  6763. if (!this.editor.modified || urlParams['modified'] == '0')
  6764. {
  6765. this.editor.setStatus('');
  6766. }
  6767. else if (urlParams['modified'] != null)
  6768. {
  6769. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get(urlParams['modified'])));
  6770. }
  6771. });
  6772. this.editor.graph.model.addListener(mxEvent.CHANGE, updateStatus);
  6773. // Receives XML message from opener and puts it into the graph
  6774. mxEvent.addListener(window, 'message', mxUtils.bind(this, function(evt)
  6775. {
  6776. var data = evt.data;
  6777. function extractDiagramXml(data)
  6778. {
  6779. if (data != null && typeof data.charAt === 'function' && data.charAt(0) != '<')
  6780. {
  6781. try
  6782. {
  6783. if (data.substring(0, 26) == 'data:image/svg+xml;base64,')
  6784. {
  6785. data = atob(data.substring(26));
  6786. }
  6787. else if (data.substring(0, 24) == 'data:image/svg+xml;utf8,')
  6788. {
  6789. data = data.substring(24);
  6790. }
  6791. if (data != null)
  6792. {
  6793. if (data.charAt(0) == '%')
  6794. {
  6795. data = decodeURIComponent(data);
  6796. }
  6797. else if (data.charAt(0) != '<')
  6798. {
  6799. data = this.editor.graph.decompress(data);
  6800. }
  6801. }
  6802. }
  6803. catch (e)
  6804. {
  6805. // ignore compression errors and use empty data
  6806. }
  6807. }
  6808. return data;
  6809. };
  6810. if (urlParams['proto'] == 'json')
  6811. {
  6812. try
  6813. {
  6814. data = JSON.parse(data);
  6815. }
  6816. catch (e)
  6817. {
  6818. data = null;
  6819. }
  6820. if (data == null)
  6821. {
  6822. // Ignore
  6823. return;
  6824. }
  6825. else if (data.action == 'dialog')
  6826. {
  6827. this.showError((data.titleKey != null) ? mxResources.get(data.titleKey) : data.title,
  6828. (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message,
  6829. (data.buttonKey != null) ? mxResources.get(data.buttonKey) : data.button);
  6830. if (data.modified != null)
  6831. {
  6832. this.editor.modified = data.modified;
  6833. }
  6834. return;
  6835. }
  6836. else if (data.action == 'prompt')
  6837. {
  6838. this.spinner.stop();
  6839. var dlg = new FilenameDialog(this, data.defaultValue || '',
  6840. (data.okKey != null) ? mxResources.get(data.okKey) : null, function(value)
  6841. {
  6842. if (value != null)
  6843. {
  6844. parent.postMessage(JSON.stringify({event: 'prompt', value: value, message: data}), '*');
  6845. }
  6846. }, (data.titleKey != null) ? mxResources.get(data.titleKey) : data.title);
  6847. this.showDialog(dlg.container, 300, 80, true, false);
  6848. dlg.init();
  6849. return;
  6850. }
  6851. else if (data.action == 'draft')
  6852. {
  6853. var tmp = null;
  6854. if (data.xml.substring(0, 22) == 'data:image/png;base64,')
  6855. {
  6856. tmp = this.extractGraphModelFromPng(data.xml);
  6857. }
  6858. else
  6859. {
  6860. tmp = extractDiagramXml(data.xml);
  6861. }
  6862. this.spinner.stop();
  6863. var dlg = new DraftDialog(this, mxResources.get('draftFound', [data.name || this.defaultFilename]),
  6864. tmp, mxUtils.bind(this, function()
  6865. {
  6866. this.hideDialog();
  6867. parent.postMessage(JSON.stringify({event: 'draft', result: 'edit', message: data}), '*');
  6868. }), mxUtils.bind(this, function()
  6869. {
  6870. this.hideDialog();
  6871. parent.postMessage(JSON.stringify({event: 'draft', result: 'discard', message: data}), '*');
  6872. }), (data.editKey) ? mxResources.get(data.editKey) : null,
  6873. (data.discardKey) ? mxResources.get(data.discardKey) : null,
  6874. (data.ignore) ? mxUtils.bind(this, function()
  6875. {
  6876. this.hideDialog();
  6877. parent.postMessage(JSON.stringify({event: 'draft', result: 'ignore', message: data}), '*');
  6878. }) : null);
  6879. this.showDialog(dlg.container, 640, 480, true, false, mxUtils.bind(this, function(cancel)
  6880. {
  6881. if (cancel)
  6882. {
  6883. this.actions.get('exit').funct();
  6884. }
  6885. }));
  6886. try
  6887. {
  6888. dlg.init();
  6889. }
  6890. catch (e)
  6891. {
  6892. parent.postMessage(JSON.stringify({event: 'draft', error: e.toString(), message: data}), '*');
  6893. }
  6894. return;
  6895. }
  6896. else if (data.action == 'template')
  6897. {
  6898. this.spinner.stop();
  6899. var dlg = new NewDialog(this, false, data.callback != null, mxUtils.bind(this, function(xml, name)
  6900. {
  6901. xml = xml || this.emptyDiagramXml;
  6902. // LATER: Add autosave option in template message
  6903. if (data.callback != null)
  6904. {
  6905. parent.postMessage(JSON.stringify({event: 'template', xml: xml,
  6906. blank: xml == this.emptyDiagramXml, name: name}), '*');
  6907. }
  6908. else
  6909. {
  6910. fn(xml, evt, xml != this.emptyDiagramXml);
  6911. // Workaround for status updated before modified applied
  6912. if (!this.editor.modified)
  6913. {
  6914. this.editor.setStatus('');
  6915. }
  6916. }
  6917. }));
  6918. this.showDialog(dlg.container, 620, 440, true, false, mxUtils.bind(this, function(cancel)
  6919. {
  6920. if (cancel)
  6921. {
  6922. this.actions.get('exit').funct();
  6923. }
  6924. }));
  6925. dlg.init();
  6926. return;
  6927. }
  6928. else if (data.action == 'status')
  6929. {
  6930. if (data.messageKey != null)
  6931. {
  6932. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get(data.messageKey)));
  6933. }
  6934. else if (data.message != null)
  6935. {
  6936. this.editor.setStatus(mxUtils.htmlEntities(data.message));
  6937. }
  6938. if (data.modified != null)
  6939. {
  6940. this.editor.modified = data.modified;
  6941. }
  6942. return;
  6943. }
  6944. else if (data.action == 'spinner')
  6945. {
  6946. var msg = (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message;
  6947. if (data.show != null && !data.show)
  6948. {
  6949. this.spinner.stop();
  6950. }
  6951. else
  6952. {
  6953. this.spinner.spin(document.body, msg)
  6954. }
  6955. return;
  6956. }
  6957. else if (data.action == 'export')
  6958. {
  6959. if (data.format == 'png' || data.format == 'xmlpng')
  6960. {
  6961. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  6962. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  6963. {
  6964. var xml = (data.xml != null) ? data.xml : this.getFileData(true);
  6965. this.editor.graph.setEnabled(false);
  6966. var graph = this.editor.graph;
  6967. var postDataBack = mxUtils.bind(this, function(uri)
  6968. {
  6969. this.editor.graph.setEnabled(true);
  6970. this.spinner.stop();
  6971. var msg = this.createLoadMessage('export');
  6972. msg.format = data.format;
  6973. msg.message = data;
  6974. msg.data = uri;
  6975. msg.xml = encodeURIComponent(xml);
  6976. parent.postMessage(JSON.stringify(msg), '*');
  6977. });
  6978. var processUri = mxUtils.bind(this, function(uri)
  6979. {
  6980. if (uri == null)
  6981. {
  6982. uri = Editor.blankImage;
  6983. }
  6984. if (data.format == 'xmlpng')
  6985. {
  6986. uri = this.writeGraphModelToPng(uri, 'zTXt', 'mxGraphModel',
  6987. atob(this.editor.graph.compress(xml)));
  6988. }
  6989. // Removes temporary graph from DOM
  6990. if (graph != this.editor.graph)
  6991. {
  6992. graph.container.parentNode.removeChild(graph.container);
  6993. }
  6994. postDataBack(uri);
  6995. });
  6996. // LATER: Uses external export if current page (not first page) has mathEnabled
  6997. if (this.isExportToCanvas())
  6998. {
  6999. // Exports PNG for first page while other page is visible by creating a graph
  7000. // LATER: Add caching for the graph or SVG while not on first page
  7001. if (this.pages != null && this.currentPage != this.pages[0])
  7002. {
  7003. graph = this.createTemporaryGraph(graph.getStylesheet());
  7004. var graphGetGlobalVariable = graph.getGlobalVariable;
  7005. var page = this.pages[0];
  7006. graph.getGlobalVariable = function(name)
  7007. {
  7008. if (name == 'page')
  7009. {
  7010. return page.getName();
  7011. }
  7012. else if (name == 'pagenumber')
  7013. {
  7014. return 1;
  7015. }
  7016. return graphGetGlobalVariable.apply(this, arguments);
  7017. };
  7018. document.body.appendChild(graph.container);
  7019. graph.model.setRoot(page.root);
  7020. }
  7021. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  7022. {
  7023. processUri(canvas.toDataURL('image/png'));
  7024. }), null, null, null, mxUtils.bind(this, function()
  7025. {
  7026. processUri(null);
  7027. }), null, null, null, null, null, null, graph);
  7028. }
  7029. else
  7030. {
  7031. // Data from server is base64 encoded to avoid binary XHR
  7032. // Double encoding for XML arg is needed for UTF8 encoding
  7033. var req = new mxXmlRequest(EXPORT_URL, 'format=png&embedXml=' +
  7034. ((data.format == 'xmlpng') ? '1' : '0') + '&base64=1&xml=' +
  7035. encodeURIComponent(encodeURIComponent(xml)));
  7036. req.send(mxUtils.bind(this, function(req)
  7037. {
  7038. // Temp graph was never created at this point so we can
  7039. // skip processUri since it already contains the XML
  7040. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  7041. {
  7042. postDataBack('data:image/png;base64,' + req.getText());
  7043. }
  7044. else
  7045. {
  7046. processUri(null);
  7047. }
  7048. }), mxUtils.bind(this, function()
  7049. {
  7050. processUri(null);
  7051. }));
  7052. }
  7053. }
  7054. }
  7055. else
  7056. {
  7057. // SVG is generated from graph so parse optional XML
  7058. if (data.xml != null && data.xml.length > 0)
  7059. {
  7060. this.setFileData(data.xml);
  7061. }
  7062. var msg = this.createLoadMessage('export');
  7063. // Forces new HTML format if pages exists
  7064. if (data.format == 'html2' || (data.format == 'html' && (urlParams['pages'] != '0' ||
  7065. (this.pages != null && this.pages.length > 1))))
  7066. {
  7067. var node = this.getXmlFileData();
  7068. msg.xml = mxUtils.getXml(node);
  7069. msg.data = this.getFileData(null, null, true, null, null, null, node);
  7070. msg.format = data.format;
  7071. }
  7072. else if (data.format == 'html')
  7073. {
  7074. var xml = this.editor.getGraphXml();
  7075. msg.data = this.getHtml(xml, this.editor.graph);
  7076. msg.xml = mxUtils.getXml(xml);
  7077. msg.format = data.format;
  7078. }
  7079. else
  7080. {
  7081. // Creates a preview with no alt text for unsupported browsers
  7082. mxSvgCanvas2D.prototype.foAltText = null;
  7083. var bg = this.editor.graph.background;
  7084. if (bg == mxConstants.NONE)
  7085. {
  7086. bg = null;
  7087. }
  7088. msg.xml = this.getFileData(true);
  7089. msg.format = 'svg';
  7090. if (data.embedImages || data.embedImages == null)
  7091. {
  7092. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  7093. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  7094. {
  7095. this.editor.graph.setEnabled(false);
  7096. if (data.format == 'xmlsvg')
  7097. {
  7098. this.getEmbeddedSvg(msg.xml, this.editor.graph, null, true, mxUtils.bind(this, function(svg)
  7099. {
  7100. this.editor.graph.setEnabled(true);
  7101. this.spinner.stop();
  7102. msg.data = this.createSvgDataUri(svg);
  7103. parent.postMessage(JSON.stringify(msg), '*');
  7104. }));
  7105. }
  7106. else
  7107. {
  7108. this.convertImages(this.editor.graph.getSvg(bg), mxUtils.bind(this, function(svgRoot)
  7109. {
  7110. this.editor.graph.setEnabled(true);
  7111. this.spinner.stop();
  7112. msg.data = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  7113. parent.postMessage(JSON.stringify(msg), '*');
  7114. }));
  7115. }
  7116. }
  7117. return;
  7118. }
  7119. else
  7120. {
  7121. var svg = (data.format == 'xmlsvg') ? this.getEmbeddedSvg(this.getFileData(true),
  7122. this.editor.graph, null, true) : mxUtils.getXml(this.editor.graph.getSvg(bg));
  7123. msg.data = this.createSvgDataUri(svg);
  7124. }
  7125. }
  7126. parent.postMessage(JSON.stringify(msg), '*');
  7127. }
  7128. return;
  7129. }
  7130. else if (data.action == 'load')
  7131. {
  7132. autosave = data.autosave == 1;
  7133. this.hideDialog();
  7134. if (data.modified != null && urlParams['modified'] == null)
  7135. {
  7136. urlParams['modified'] = data.modified;
  7137. }
  7138. if (data.saveAndExit != null && urlParams['saveAndExit'] == null)
  7139. {
  7140. urlParams['saveAndExit'] = data.saveAndExit;
  7141. }
  7142. if (data.title != null && this.buttonContainer != null)
  7143. {
  7144. var tmp = document.createElement('span');
  7145. mxUtils.write(tmp, data.title);
  7146. if (uiTheme == 'atlas')
  7147. {
  7148. this.buttonContainer.style.paddingRight = '12px';
  7149. this.buttonContainer.style.paddingTop = '12px';
  7150. }
  7151. else
  7152. {
  7153. this.buttonContainer.style.paddingRight = '38px';
  7154. this.buttonContainer.style.paddingTop = '6px';
  7155. }
  7156. if (this.embedFilenameSpan != null)
  7157. {
  7158. this.embedFilenameSpan.parentNode.removeChild(this.embedFilenameSpan);
  7159. }
  7160. this.buttonContainer.appendChild(tmp);
  7161. this.embedFilenameSpan = tmp;
  7162. }
  7163. if (data.xmlpng != null)
  7164. {
  7165. data = this.extractGraphModelFromPng(data.xmlpng);
  7166. }
  7167. else if (data.xml != null && data.xml.substring(0, 22) == 'data:image/png;base64,')
  7168. {
  7169. data = this.extractGraphModelFromPng(data.xml);
  7170. }
  7171. else
  7172. {
  7173. data = data.xml;
  7174. }
  7175. }
  7176. else
  7177. {
  7178. // Unknown message must stop execution
  7179. parent.postMessage(JSON.stringify({error: 'unknownMessage', data: JSON.stringify(data)}), '*');
  7180. return;
  7181. }
  7182. }
  7183. data = extractDiagramXml(data);
  7184. ignoreChange = true;
  7185. try
  7186. {
  7187. fn(data, evt);
  7188. }
  7189. catch (e)
  7190. {
  7191. this.handleError(e);
  7192. }
  7193. ignoreChange = false;
  7194. if (urlParams['modified'] != null)
  7195. {
  7196. this.editor.setStatus('');
  7197. }
  7198. var getData = mxUtils.bind(this, function()
  7199. {
  7200. return (urlParams['pages'] != '0' || (this.pages != null && this.pages.length > 1)) ?
  7201. this.getFileData(true): mxUtils.getXml(this.editor.getGraphXml());
  7202. });;
  7203. lastData = getData();
  7204. if (autosave && changeListener == null)
  7205. {
  7206. changeListener = mxUtils.bind(this, function(sender, eventObject)
  7207. {
  7208. var data = getData();
  7209. if (data != lastData && !ignoreChange)
  7210. {
  7211. var msg = this.createLoadMessage('autosave');
  7212. msg.xml = data;
  7213. data = JSON.stringify(msg);
  7214. var parent = window.opener || window.parent;
  7215. parent.postMessage(data, '*');
  7216. }
  7217. lastData = data;
  7218. });
  7219. this.editor.graph.model.addListener(mxEvent.CHANGE, changeListener);
  7220. // Some options trigger autosave
  7221. this.editor.graph.addListener('gridSizeChanged', changeListener);
  7222. this.editor.graph.addListener('shadowVisibleChanged', changeListener);
  7223. this.addListener('pageFormatChanged', changeListener);
  7224. this.addListener('pageScaleChanged', changeListener);
  7225. this.addListener('backgroundColorChanged', changeListener);
  7226. this.addListener('backgroundImageChanged', changeListener);
  7227. this.addListener('foldingEnabledChanged', changeListener);
  7228. this.addListener('mathEnabledChanged', changeListener);
  7229. this.addListener('gridEnabledChanged', changeListener);
  7230. this.addListener('guidesEnabledChanged', changeListener);
  7231. this.addListener('pageViewChanged', changeListener);
  7232. }
  7233. // Sends the bounds of the graph to the host after parsing
  7234. if (urlParams['returnbounds'] == '1' || urlParams['proto'] == 'json')
  7235. {
  7236. parent.postMessage(JSON.stringify(this.createLoadMessage('load')), '*');
  7237. }
  7238. }));
  7239. // Requests data from the sender. This is a workaround for not allowing
  7240. // the opener to listen for the onload event if not in the same origin.
  7241. var parent = window.opener || window.parent;
  7242. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'init'}) : (urlParams['ready'] || 'ready');
  7243. parent.postMessage(msg, '*');
  7244. };
  7245. /**
  7246. * Adds the buttons for embedded mode.
  7247. */
  7248. EditorUi.prototype.addEmbedButtons = function()
  7249. {
  7250. if (this.menubar != null)
  7251. {
  7252. var div = document.createElement('div');
  7253. div.style.display = 'inline-block';
  7254. div.style.position = 'absolute';
  7255. div.style.paddingTop = (uiTheme == 'atlas') ? '2px' : '3px';
  7256. div.style.paddingLeft = '8px';
  7257. div.style.paddingBottom = '2px';
  7258. var button = document.createElement('button');
  7259. mxUtils.write(button, mxResources.get('save'));
  7260. button.setAttribute('title', mxResources.get('save') + ' (' + Editor.ctrlKey + '+S)');
  7261. button.className = 'geBigButton';
  7262. button.style.fontSize = '12px';
  7263. button.style.padding = '4px 6px 4px 6px';
  7264. button.style.borderRadius = '3px';
  7265. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  7266. {
  7267. this.actions.get('save').funct();
  7268. }));
  7269. div.appendChild(button);
  7270. if (urlParams['saveAndExit'] == '1')
  7271. {
  7272. button = document.createElement('a');
  7273. mxUtils.write(button, mxResources.get('saveAndExit'));
  7274. button.setAttribute('title', mxResources.get('saveAndExit'));
  7275. button.style.fontSize = '12px';
  7276. button.style.marginLeft = '6px';
  7277. button.style.padding = '4px';
  7278. button.style.cursor = 'pointer';
  7279. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  7280. {
  7281. this.actions.get('saveAndExit').funct();
  7282. }));
  7283. div.appendChild(button);
  7284. }
  7285. button = document.createElement('a');
  7286. mxUtils.write(button, mxResources.get('exit'));
  7287. button.setAttribute('title', mxResources.get('exit'));
  7288. button.style.fontSize = '12px';
  7289. button.style.marginLeft = '6px';
  7290. button.style.marginRight = '20px';
  7291. button.style.padding = '4px';
  7292. button.style.cursor = 'pointer';
  7293. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  7294. {
  7295. this.actions.get('exit').funct();
  7296. }));
  7297. div.appendChild(button);
  7298. this.toolbar.container.appendChild(div);
  7299. this.toolbar.staticElements.push(div);
  7300. div.style.right = (uiTheme != 'atlas') ? '52px' : '42px';
  7301. }
  7302. };
  7303. /**
  7304. *
  7305. */
  7306. EditorUi.prototype.showImportCsvDialog = function()
  7307. {
  7308. if (this.importCsvDialog == null)
  7309. {
  7310. this.importCsvDialog = new TextareaDialog(this, mxResources.get('csv') + ':',
  7311. Editor.defaultCsvValue, mxUtils.bind(this, function(newValue)
  7312. {
  7313. this.importCsv(newValue);
  7314. }), null, null, 620, 430, null, true, true, mxResources.get('import'));
  7315. }
  7316. this.showDialog(this.importCsvDialog.container, 640, 520, true, true);
  7317. this.importCsvDialog.init();
  7318. };
  7319. /**
  7320. * TODO: Move to Editor
  7321. */
  7322. EditorUi.prototype.importCsv = function(text)
  7323. {
  7324. try
  7325. {
  7326. var lines = text.split('\n');
  7327. var cells = [];
  7328. if (lines.length > 0)
  7329. {
  7330. // Internal lookup table
  7331. var lookups = {};
  7332. // Default values
  7333. var style = null;
  7334. var identity = null;
  7335. var width = 'auto';
  7336. var height = 'auto';
  7337. var edgespacing = 40;
  7338. var nodespacing = 40;
  7339. var padding = 0;
  7340. var graph = this.editor.graph;
  7341. var view = graph.view;
  7342. var bds = graph.getGraphBounds();
  7343. // Delayed after optional layout
  7344. var afterInsert = function()
  7345. {
  7346. graph.setSelectionCells(select);
  7347. graph.scrollCellToVisible(graph.getSelectionCell());
  7348. };
  7349. // Computes unscaled, untranslated graph bounds
  7350. var pt = graph.getFreeInsertPoint();
  7351. var x0 = pt.x;
  7352. var y0 = pt.y;
  7353. var y = y0;
  7354. // Default label value depends on column names
  7355. var label = null;
  7356. // Default layout to run.
  7357. var layout = 'auto';
  7358. // Name of the attribute that contains the parent reference
  7359. var parent = null;
  7360. // Name of the attribute that contains the references for creating edges
  7361. var edges = [];
  7362. // Name of the column for hyperlinks
  7363. var link = null;
  7364. // String array of names to remove from metadata
  7365. var ignore = null;
  7366. // Read processing instructions first
  7367. var index = 0;
  7368. while (index < lines.length && lines[index].charAt(0) == '#')
  7369. {
  7370. var text = lines[index];
  7371. index++;
  7372. while (index < lines.length && text.charAt(text.length - 1) == '\\' &&
  7373. lines[index].charAt(0) == '#')
  7374. {
  7375. text = text.substring(0, text.length - 1) + mxUtils.trim(lines[index].substring(1));
  7376. index++;
  7377. }
  7378. if (text.charAt(1) != '#')
  7379. {
  7380. // Processing instruction
  7381. var idx = text.indexOf(':');
  7382. if (idx > 0)
  7383. {
  7384. var key = mxUtils.trim(text.substring(1, idx));
  7385. var value = mxUtils.trim(text.substring(idx + 1));
  7386. if (key == 'label')
  7387. {
  7388. label = graph.sanitizeHtml(value);
  7389. }
  7390. else if (key == 'style')
  7391. {
  7392. style = value;
  7393. }
  7394. else if (key == 'identity' && value.length > 0 && value != '-')
  7395. {
  7396. identity = value;
  7397. }
  7398. else if (key == 'width')
  7399. {
  7400. width = value;
  7401. }
  7402. else if (key == 'height')
  7403. {
  7404. height = value;
  7405. }
  7406. else if (key == 'ignore')
  7407. {
  7408. ignore = value.split(',');
  7409. }
  7410. else if (key == 'connect')
  7411. {
  7412. edges.push(JSON.parse(value));
  7413. }
  7414. else if (key == 'link')
  7415. {
  7416. link = value;
  7417. }
  7418. else if (key == 'padding')
  7419. {
  7420. padding = parseFloat(value);
  7421. }
  7422. else if (key == 'edgespacing')
  7423. {
  7424. edgespacing = parseFloat(value);
  7425. }
  7426. else if (key == 'nodespacing')
  7427. {
  7428. nodespacing = parseFloat(value);
  7429. }
  7430. else if (key == 'layout')
  7431. {
  7432. layout = value;
  7433. }
  7434. }
  7435. }
  7436. }
  7437. var keys = this.editor.csvToArray(lines[index]);
  7438. // Converts name of identity to index of column
  7439. var identityIndex = null;
  7440. if (identity != null)
  7441. {
  7442. for (var i = 0; i < keys.length; i++)
  7443. {
  7444. if (identity == keys[i])
  7445. {
  7446. identityIndex = i;
  7447. break;
  7448. }
  7449. }
  7450. }
  7451. if (label == null)
  7452. {
  7453. label = '%' + keys[0] + '%';
  7454. }
  7455. if (edges != null)
  7456. {
  7457. for (var e = 0; e < edges.length; e++)
  7458. {
  7459. if (lookups[edges[e].to] == null)
  7460. {
  7461. lookups[edges[e].to] = {};
  7462. }
  7463. }
  7464. }
  7465. graph.model.beginUpdate();
  7466. try
  7467. {
  7468. for (var i = index + 1; i < lines.length; i++)
  7469. {
  7470. var values = this.editor.csvToArray(lines[i]);
  7471. if (values.length == keys.length)
  7472. {
  7473. var cell = null;
  7474. var id = (identityIndex != null) ? values[identityIndex] : null;
  7475. if (id != null)
  7476. {
  7477. cell = graph.model.getCell(id);
  7478. }
  7479. if (cell == null)
  7480. {
  7481. var cell = new mxCell(label, new mxGeometry(x0, y,
  7482. 0, 0), style || 'whiteSpace=wrap;html=1;');
  7483. cell.vertex = true;
  7484. cell.id = id;
  7485. }
  7486. for (var j = 0; j < values.length; j++)
  7487. {
  7488. graph.setAttributeForCell(cell, keys[j], values[j]);
  7489. }
  7490. graph.setAttributeForCell(cell, 'placeholders', '1');
  7491. cell.style = graph.replacePlaceholders(cell, cell.style);
  7492. for (var e = 0; e < edges.length; e++)
  7493. {
  7494. lookups[edges[e].to][cell.getAttribute(edges[e].to)] = cell;
  7495. }
  7496. if (link != null && link != 'link')
  7497. {
  7498. graph.setLinkForCell(cell, cell.getAttribute(link));
  7499. // Removes attribute
  7500. graph.setAttributeForCell(cell, link, null);
  7501. }
  7502. // Sets the size
  7503. var size = this.editor.graph.getPreferredSizeForCell(cell);
  7504. cell.geometry.width = (width == 'auto') ? size.width + padding : parseFloat(width);
  7505. cell.geometry.height = (height == 'auto') ? size.height + padding : parseFloat(height);
  7506. y += cell.geometry.height + nodespacing;
  7507. cells.push(graph.addCell(cell));
  7508. }
  7509. }
  7510. if (style == null)
  7511. {
  7512. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', cells));
  7513. }
  7514. var roots = cells.slice();
  7515. var select = cells.slice();
  7516. for (var e = 0; e < edges.length; e++)
  7517. {
  7518. var edge = edges[e];
  7519. for (var i = 0; i < cells.length; i++)
  7520. {
  7521. var cell = cells[i];
  7522. var tmp = cell.getAttribute(edge.from);
  7523. if (tmp != null)
  7524. {
  7525. // Removes attribute
  7526. graph.setAttributeForCell(cell, edge.from, null);
  7527. var refs = tmp.split(',');
  7528. for (var j = 0; j < refs.length; j++)
  7529. {
  7530. var ref = lookups[edge.to][refs[j]];
  7531. if (ref != null)
  7532. {
  7533. select.push(graph.insertEdge(null, null, edge.label || '',
  7534. (edge.invert) ? ref : cell, (edge.invert) ? cell : ref,
  7535. edge.style || graph.createCurrentEdgeStyle()));
  7536. mxUtils.remove((edge.invert) ? cell : ref, roots);
  7537. }
  7538. }
  7539. }
  7540. }
  7541. }
  7542. // Removes ignored attributes after processing above
  7543. if (ignore != null)
  7544. {
  7545. for (var i = 0; i < cells.length; i++)
  7546. {
  7547. var cell = cells[i];
  7548. for (var j = 0; j < ignore.length; j++)
  7549. {
  7550. graph.setAttributeForCell(cell, mxUtils.trim(ignore[j]), null);
  7551. }
  7552. }
  7553. }
  7554. var edgeLayout = new mxParallelEdgeLayout(graph);
  7555. edgeLayout.spacing = edgespacing;
  7556. var postProcess = function()
  7557. {
  7558. edgeLayout.execute(graph.getDefaultParent());
  7559. // Aligns cells to grid and/or rounds positions
  7560. for (var i = 0; i < cells.length; i++)
  7561. {
  7562. var geo = graph.getCellGeometry(cells[i]);
  7563. geo.x = Math.round(graph.snap(geo.x));
  7564. geo.y = Math.round(graph.snap(geo.y));
  7565. if (width == 'auto')
  7566. {
  7567. geo.width = Math.round(graph.snap(geo.width));
  7568. }
  7569. if (height == 'auto')
  7570. {
  7571. geo.height = Math.round(graph.snap(geo.height));
  7572. }
  7573. }
  7574. };
  7575. if (layout == 'circle')
  7576. {
  7577. var circleLayout = new mxCircleLayout(graph);
  7578. circleLayout.resetEdges = false;
  7579. var circleLayoutIsVertexIgnored = circleLayout.isVertexIgnored;
  7580. // Ignore other cells
  7581. circleLayout.isVertexIgnored = function(vertex)
  7582. {
  7583. return circleLayoutIsVertexIgnored.apply(this, arguments) ||
  7584. mxUtils.indexOf(cells, vertex) < 0;
  7585. };
  7586. this.executeLayout(function()
  7587. {
  7588. circleLayout.execute(graph.getDefaultParent());
  7589. postProcess();
  7590. }, true, afterInsert);
  7591. afterInsert = null;
  7592. }
  7593. else if (layout == 'horizontaltree' || layout == 'verticaltree' ||
  7594. (layout == 'auto' && select.length == 2 * cells.length - 1 && roots.length == 1))
  7595. {
  7596. // Required for layouts to work with new cells
  7597. graph.view.validate();
  7598. var treeLayout = new mxCompactTreeLayout(graph, layout == 'horizontaltree');
  7599. treeLayout.levelDistance = nodespacing;
  7600. treeLayout.edgeRouting = false;
  7601. treeLayout.resetEdges = false;
  7602. this.executeLayout(function()
  7603. {
  7604. treeLayout.execute(graph.getDefaultParent(), (roots.length > 0) ? roots[0] : null);
  7605. }, true, afterInsert);
  7606. afterInsert = null;
  7607. }
  7608. else if (layout == 'horizontalflow' || layout == 'verticalflow' ||
  7609. (layout == 'auto' && roots.length == 1))
  7610. {
  7611. // Required for layouts to work with new cells
  7612. graph.view.validate();
  7613. var flowLayout = new mxHierarchicalLayout(graph,
  7614. (layout == 'horizontalflow') ? mxConstants.DIRECTION_WEST : mxConstants.DIRECTION_NORTH);
  7615. flowLayout.intraCellSpacing = nodespacing;
  7616. flowLayout.disableEdgeStyle = false;
  7617. this.executeLayout(function()
  7618. {
  7619. flowLayout.execute(graph.getDefaultParent(), select);
  7620. // Workaround for flow layout moving cells to origin
  7621. graph.moveCells(select, x0, y0);
  7622. }, true, afterInsert);
  7623. afterInsert = null;
  7624. }
  7625. else if (layout == 'organic' || (layout == 'auto' &&
  7626. select.length > cells.length))
  7627. {
  7628. // Required for layouts to work with new cells
  7629. graph.view.validate();
  7630. var organicLayout = new mxFastOrganicLayout(graph);
  7631. organicLayout.forceConstant = nodespacing * 3;
  7632. organicLayout.resetEdges = false;
  7633. var organicLayoutIsVertexIgnored = organicLayout.isVertexIgnored;
  7634. // Ignore other cells
  7635. organicLayout.isVertexIgnored = function(vertex)
  7636. {
  7637. return organicLayoutIsVertexIgnored.apply(this, arguments) ||
  7638. mxUtils.indexOf(cells, vertex) < 0;
  7639. };
  7640. var edgeLayout = new mxParallelEdgeLayout(graph);
  7641. edgeLayout.spacing = edgespacing;
  7642. this.executeLayout(function()
  7643. {
  7644. organicLayout.execute(graph.getDefaultParent());
  7645. postProcess();
  7646. }, true, afterInsert);
  7647. afterInsert = null;
  7648. }
  7649. this.hideDialog();
  7650. }
  7651. finally
  7652. {
  7653. graph.model.endUpdate();
  7654. }
  7655. if (afterInsert != null)
  7656. {
  7657. afterInsert();
  7658. }
  7659. }
  7660. }
  7661. catch (e)
  7662. {
  7663. this.handleError(e);
  7664. }
  7665. };
  7666. /**
  7667. * Translates this point by the given vector.
  7668. *
  7669. * @param {number} dx X-coordinate of the translation.
  7670. * @param {number} dy Y-coordinate of the translation.
  7671. */
  7672. EditorUi.prototype.getSearch = function(exclude)
  7673. {
  7674. var result = '';
  7675. if (urlParams['offline'] != '1' && urlParams['demo'] != '1' && exclude != null && window.location.search.length > 0)
  7676. {
  7677. var amp = '?';
  7678. for (var key in urlParams)
  7679. {
  7680. if (mxUtils.indexOf(exclude, key) < 0 && urlParams[key] != null)
  7681. {
  7682. result += amp + key + '=' + urlParams[key];
  7683. amp = '&';
  7684. }
  7685. }
  7686. }
  7687. else
  7688. {
  7689. result = window.location.search;
  7690. }
  7691. return result;
  7692. };
  7693. /**
  7694. * Returns the URL for a copy of this editor with no state.
  7695. */
  7696. EditorUi.prototype.getUrl = function(pathname)
  7697. {
  7698. var href = (pathname != null) ? pathname : window.location.pathname;
  7699. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  7700. if (urlParams['offline'] == '1')
  7701. {
  7702. href += window.location.search;
  7703. }
  7704. else
  7705. {
  7706. var ignored = ['tmp', 'libs', 'clibs', 'state', 'fileId', 'code', 'share', 'notitle',
  7707. 'data', 'url', 'embed', 'client', 'create', 'title', 'splash'];
  7708. // Removes template URL parameter for new blank diagram
  7709. for (var key in urlParams)
  7710. {
  7711. if (mxUtils.indexOf(ignored, key) < 0)
  7712. {
  7713. if (parms == 0)
  7714. {
  7715. href += '?';
  7716. }
  7717. else
  7718. {
  7719. href += '&';
  7720. }
  7721. if (urlParams[key] != null)
  7722. {
  7723. href += key + '=' + urlParams[key];
  7724. parms++;
  7725. }
  7726. }
  7727. }
  7728. }
  7729. return href;
  7730. };
  7731. /**
  7732. * Overrides link dialog.
  7733. */
  7734. EditorUi.prototype.showLinkDialog = function(value, btnLabel, fn)
  7735. {
  7736. var dlg = new LinkDialog(this, value, btnLabel, fn, true);
  7737. this.showDialog(dlg.container, 420, 120, true, true);
  7738. dlg.init();
  7739. };
  7740. /**
  7741. * Overrides createOutline
  7742. */
  7743. var editorUiCreateOutline = EditorUi.prototype.createOutline;
  7744. EditorUi.prototype.createOutline = function(wnd)
  7745. {
  7746. var outline = editorUiCreateOutline.apply(this, arguments);
  7747. var graph = this.editor.graph;
  7748. var outlineGetSourceGraphBounds = outline.getSourceGraphBounds;
  7749. outline.getSourceGraphBounds = function()
  7750. {
  7751. if (mxUtils.hasScrollbars(graph.container) && graph.pageVisible && this.source.minimumGraphSize != null)
  7752. {
  7753. var pb = this.source.getPagePadding();
  7754. var s = this.source.view.scale;
  7755. var result = new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width - 2 * pb.x / s),
  7756. Math.ceil(this.source.minimumGraphSize.height - 2 * pb.y / s));
  7757. return result;
  7758. }
  7759. return outlineGetSourceGraphBounds.apply(this, arguments);
  7760. };
  7761. var outlineGetSourceContainerSize = outline.getSourceContainerSize;
  7762. outline.getSourceContainerSize = function()
  7763. {
  7764. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  7765. {
  7766. var pad = this.source.getPagePadding();
  7767. var s = this.source.view.scale;
  7768. return new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width * s - 2 * pad.x),
  7769. Math.ceil(this.source.minimumGraphSize.height * s - 2 * pad.y));
  7770. }
  7771. return outlineGetSourceContainerSize.apply(this, arguments);
  7772. };
  7773. outline.getOutlineOffset = function(scale)
  7774. {
  7775. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  7776. {
  7777. var pb = this.source.getPagePadding();
  7778. var dx = Math.max(0, (outline.outline.container.clientWidth / scale - (this.source.minimumGraphSize.width - 2 * pb.x)) / 2);
  7779. var dy = Math.max(0, (outline.outline.container.clientHeight / scale - (this.source.minimumGraphSize.height - 2 * pb.y)) / 2);
  7780. // Why is vertical offset negative relative to dy
  7781. return new mxPoint(Math.round(dx - pb.x), Math.round(dy - pb.y - 5 / scale));
  7782. }
  7783. return new mxPoint(8 / scale, 8 / scale);
  7784. };
  7785. var outlineInit = outline.init;
  7786. outline.init = function()
  7787. {
  7788. outlineInit.apply(this, arguments);
  7789. // Problem: Need to override a function in the view but the view is created
  7790. // with the graph so a refresh of the page is needed to see this change.
  7791. outline.outline.view.getBackgroundPageBounds = function()
  7792. {
  7793. var layout = graph.getPageLayout();
  7794. var page = graph.getPageSize();
  7795. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  7796. this.scale * (this.translate.y + layout.y * page.height),
  7797. this.scale * layout.width * page.width,
  7798. this.scale * layout.height * page.height);
  7799. };
  7800. outline.outline.view.validateBackgroundPage();
  7801. };
  7802. this.editor.addListener('pageSelected', function(sender, evt)
  7803. {
  7804. var change = evt.getProperty('change');
  7805. var graph = outline.source;
  7806. var g = outline.outline;
  7807. g.pageScale = graph.pageScale;
  7808. g.pageFormat = graph.pageFormat;
  7809. g.background = graph.background;
  7810. g.pageVisible = graph.pageVisible;
  7811. g.background = graph.background;
  7812. var current = mxUtils.getCurrentStyle(graph.container);
  7813. g.container.style.backgroundColor = current.backgroundColor;
  7814. if (graph.view.backgroundPageShape != null && g.view.backgroundPageShape != null)
  7815. {
  7816. g.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  7817. }
  7818. outline.outline.view.clear(change.previousPage.root, true);
  7819. outline.outline.view.validate();
  7820. });
  7821. return outline;
  7822. };
  7823. /**
  7824. * Returns the number of storage options enabled
  7825. */
  7826. EditorUi.prototype.getServiceCount = function(allowBrowser)
  7827. {
  7828. var serviceCount = 0;
  7829. if (this.drive != null || typeof window.DriveClient === 'function')
  7830. {
  7831. serviceCount++
  7832. }
  7833. if (this.dropbox != null || typeof window.DropboxClient === 'function')
  7834. {
  7835. serviceCount++
  7836. }
  7837. if (this.oneDrive != null || typeof window.OneDriveClient === 'function')
  7838. {
  7839. serviceCount++
  7840. }
  7841. if (this.gitHub != null)
  7842. {
  7843. serviceCount++
  7844. }
  7845. if (this.trello != null || typeof window.TrelloClient === 'function')
  7846. {
  7847. serviceCount++
  7848. }
  7849. if (allowBrowser && isLocalStorage && (urlParams['browser'] == '1' || mxClient.IS_IOS))
  7850. {
  7851. serviceCount++
  7852. }
  7853. if (!mxClient.IS_IOS)
  7854. {
  7855. serviceCount++
  7856. }
  7857. return serviceCount;
  7858. }
  7859. /**
  7860. * Updates action and menu states depending on the file.
  7861. */
  7862. EditorUi.prototype.updateUi = function()
  7863. {
  7864. this.updateButtonContainer();
  7865. this.updateActionStates();
  7866. // Action states that only need update for new files
  7867. var file = this.getCurrentFile();
  7868. var active = file != null || (urlParams['embed'] == '1' &&
  7869. this.editor.graph.isEnabled());
  7870. this.menus.get('viewPanels').setEnabled(active);
  7871. this.menus.get('viewZoom').setEnabled(active);
  7872. var restricted = (urlParams['embed'] != '1' ||
  7873. !this.editor.graph.isEnabled()) &&
  7874. (file == null || file.isRestricted());
  7875. this.actions.get('makeCopy').setEnabled(!restricted);
  7876. this.actions.get('print').setEnabled(!restricted);
  7877. this.menus.get('exportAs').setEnabled(!restricted);
  7878. this.menus.get('embed').setEnabled(!restricted);
  7879. // Disables libraries and extras menu in embed mode
  7880. // while waiting for file data
  7881. var libsEnabled = urlParams['embed'] != '1' ||
  7882. this.editor.graph.isEnabled();
  7883. this.menus.get('openLibraryFrom').setEnabled(libsEnabled);
  7884. this.menus.get('newLibrary').setEnabled(libsEnabled);
  7885. this.menus.get('extras').setEnabled(libsEnabled);
  7886. // Disables actions in the toolbar
  7887. var editable = (urlParams['embed'] == '1' &&
  7888. this.editor.graph.isEnabled()) ||
  7889. (file != null && file.isEditable());
  7890. this.actions.get('image').setEnabled(active);
  7891. this.actions.get('zoomIn').setEnabled(active);
  7892. this.actions.get('zoomOut').setEnabled(active);
  7893. this.actions.get('resetView').setEnabled(active);
  7894. // Disables menus
  7895. this.menus.get('edit').setEnabled(active);
  7896. this.menus.get('view').setEnabled(active);
  7897. this.menus.get('importFrom').setEnabled(editable);
  7898. this.menus.get('arrange').setEnabled(editable);
  7899. // Disables connection drop downs in toolbar
  7900. if (this.toolbar != null)
  7901. {
  7902. if (this.toolbar.edgeShapeMenu != null)
  7903. {
  7904. this.toolbar.edgeShapeMenu.setEnabled(editable);
  7905. }
  7906. if (this.toolbar.edgeStyleMenu != null)
  7907. {
  7908. this.toolbar.edgeStyleMenu.setEnabled(editable);
  7909. }
  7910. }
  7911. if (this.isOfflineApp())
  7912. {
  7913. var appCache = applicationCache;
  7914. // NOTE: HTML5 Cache is deprecated
  7915. if (appCache != null && this.offlineStatus == null)
  7916. {
  7917. this.offlineStatus = document.createElement('div');
  7918. this.offlineStatus.className = 'geItem';
  7919. this.offlineStatus.style.position = 'absolute';
  7920. this.offlineStatus.style.fontSize = '8pt';
  7921. this.offlineStatus.style.top = '2px';
  7922. this.offlineStatus.style.right = '12px';
  7923. this.offlineStatus.style.color = '#666';
  7924. this.offlineStatus.style.margin = '4px';
  7925. this.offlineStatus.style.padding = '2px';
  7926. this.offlineStatus.style.verticalAlign = 'middle';
  7927. this.offlineStatus.innerHTML = '';
  7928. this.menubarContainer.appendChild(this.offlineStatus);
  7929. mxEvent.addListener(this.offlineStatus, 'click', mxUtils.bind(this, function()
  7930. {
  7931. var img = this.offlineStatus.getElementsByTagName('img');
  7932. if (img != null && img.length > 0)
  7933. {
  7934. this.alert(img[0].getAttribute('title'));
  7935. }
  7936. }));
  7937. var appCache = window.applicationCache;
  7938. var lastStatus = null;
  7939. var updateStatus = mxUtils.bind(this, function()
  7940. {
  7941. var newStatus = appCache.status;
  7942. var html = '';
  7943. if (newStatus == appCache.CHECKING)
  7944. {
  7945. newStatus = appCache.DOWNLOADING;
  7946. }
  7947. switch (newStatus)
  7948. {
  7949. case appCache.UNCACHED: // UNCACHED == 0
  7950. html = '';
  7951. break;
  7952. case appCache.IDLE: // IDLE == 1
  7953. html = '<img title="draw.io is up to date." border="0" src="' + IMAGE_PATH + '/checkmark.gif"/>';
  7954. break;
  7955. case appCache.DOWNLOADING: // DOWNLOADING == 3
  7956. html = '<img title="Downloading new version..." border="0" src="' + IMAGE_PATH + '/spin.gif"/>';
  7957. break;
  7958. case appCache.UPDATEREADY: // UPDATEREADY == 4
  7959. html = '<img title="' + mxUtils.htmlEntities(mxResources.get('restartForChangeRequired')) +
  7960. '" border="0" src="' + IMAGE_PATH + '/download.png"/>';
  7961. break;
  7962. case appCache.OBSOLETE: // OBSOLETE == 5
  7963. html = '<img title="Obsolete" border="0" src="' + IMAGE_PATH + '/clear.gif"/>';
  7964. break;
  7965. default:
  7966. html = '<img title="Unknown" border="0" src="' + IMAGE_PATH + '/clear.gif"/>';
  7967. break;
  7968. }
  7969. if (newStatus != lastStatus)
  7970. {
  7971. this.offlineStatus.innerHTML = html;
  7972. lastStatus = newStatus;
  7973. }
  7974. });
  7975. mxEvent.addListener(appCache, 'checking', updateStatus);
  7976. mxEvent.addListener(appCache, 'noupdate', updateStatus);
  7977. mxEvent.addListener(appCache, 'downloading', updateStatus);
  7978. mxEvent.addListener(appCache, 'progress', updateStatus);
  7979. mxEvent.addListener(appCache, 'cached', updateStatus);
  7980. mxEvent.addListener(appCache, 'updateready', updateStatus);
  7981. mxEvent.addListener(appCache, 'obsolete', updateStatus);
  7982. mxEvent.addListener(appCache, 'error', updateStatus);
  7983. updateStatus();
  7984. }
  7985. }
  7986. else
  7987. {
  7988. this.updateUserElement();
  7989. }
  7990. };
  7991. /**
  7992. * Hook for subclassers
  7993. */
  7994. EditorUi.prototype.updateButtonContainer = function()
  7995. {
  7996. // do nothing
  7997. };
  7998. /**
  7999. * Hook for subclassers
  8000. */
  8001. EditorUi.prototype.updateUserElement = function()
  8002. {
  8003. // do nothing
  8004. };
  8005. /**
  8006. * Updates action states depending on the selection.
  8007. */
  8008. var editorUiUpdateActionStates = EditorUi.prototype.updateActionStates;
  8009. EditorUi.prototype.updateActionStates = function()
  8010. {
  8011. editorUiUpdateActionStates.apply(this, arguments);
  8012. var graph = this.editor.graph;
  8013. var file = this.getCurrentFile();
  8014. var active = (file != null && file.isEditable()) ||
  8015. (urlParams['embed'] == '1' && this.editor.graph.isEnabled());
  8016. this.actions.get('pageSetup').setEnabled(active);
  8017. this.actions.get('autosave').setEnabled(file != null && file.isEditable() && file.isAutosaveOptional());
  8018. this.actions.get('guides').setEnabled(active);
  8019. this.actions.get('shadowVisible').setEnabled(active);
  8020. this.actions.get('connectionArrows').setEnabled(active);
  8021. this.actions.get('connectionPoints').setEnabled(active);
  8022. this.actions.get('copyStyle').setEnabled(active && !graph.isSelectionEmpty());
  8023. this.actions.get('pasteStyle').setEnabled(active && !graph.isSelectionEmpty());
  8024. this.actions.get('editGeometry').setEnabled(graph.getModel().isVertex(graph.getSelectionCell()));
  8025. this.actions.get('createShape').setEnabled(active);
  8026. this.actions.get('createRevision').setEnabled(active);
  8027. this.actions.get('moveToFolder').setEnabled(file != null);
  8028. this.actions.get('makeCopy').setEnabled(file != null && !file.isRestricted());
  8029. this.actions.get('editDiagram').setEnabled((urlParams['embed'] == '1' &&
  8030. this.editor.graph.isEnabled()) || (file != null && !file.isRestricted()));
  8031. this.actions.get('publishLink').setEnabled(file != null && !file.isRestricted());
  8032. this.actions.get('tags').setEnabled((urlParams['embed'] == '1' &&
  8033. this.editor.graph.isEnabled()) || (file != null && !file.isRestricted()));
  8034. this.actions.get('close').setEnabled(file != null);
  8035. this.menus.get('publish').setEnabled(file != null && !file.isRestricted());
  8036. var state = graph.view.getState(graph.getSelectionCell());
  8037. this.actions.get('editShape').setEnabled(active && state != null && state.shape != null && state.shape.stencil != null);
  8038. };
  8039. /**
  8040. * Overrides export dialog for using ui functions for save and setting global switches.
  8041. */
  8042. if (window.ExportDialog != null)
  8043. {
  8044. ExportDialog.showXmlOption = false;
  8045. ExportDialog.showGifOption = false;
  8046. ExportDialog.exportFile = function(editorUi, name, format, bg, s, b)
  8047. {
  8048. var graph = editorUi.editor.graph;
  8049. if (format == 'xml')
  8050. {
  8051. editorUi.hideDialog();
  8052. editorUi.saveData(name, 'xml', mxUtils.getXml(editorUi.editor.getGraphXml()), 'text/xml');
  8053. }
  8054. else if (format == 'svg')
  8055. {
  8056. editorUi.hideDialog();
  8057. editorUi.saveData(name, 'svg', mxUtils.getXml(graph.getSvg(bg, s, b)), 'image/svg+xml');
  8058. }
  8059. else
  8060. {
  8061. var data = editorUi.getFileData(true, null, null, null, null, true);
  8062. var bounds = graph.getGraphBounds();
  8063. var w = Math.floor(bounds.width * s / graph.view.scale);
  8064. var h = Math.floor(bounds.height * s / graph.view.scale);
  8065. if (data.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  8066. {
  8067. editorUi.hideDialog();
  8068. editorUi.saveRequest(name, format,
  8069. function(newTitle, base64)
  8070. {
  8071. return new mxXmlRequest(EXPORT_URL, 'format=' + format + '&base64=' + (base64 || '0') +
  8072. ((newTitle != null) ? '&filename=' + encodeURIComponent(newTitle) : '') +
  8073. '&bg=' + ((bg != null) ? bg : 'none') + '&w=' + w + '&h=' + h +
  8074. '&border=' + b + '&xml=' + encodeURIComponent(data));
  8075. });
  8076. }
  8077. else
  8078. {
  8079. mxUtils.alert(mxResources.get('drawingTooLarge'));
  8080. }
  8081. }
  8082. };
  8083. }
  8084. })();