EditorUi.js 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071
  1. /**
  2. * Copyright (c) 2006-2016, JGraph Ltd
  3. * Copyright (c) 2006-2016, 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. * Overrides compact UI setting.
  17. */
  18. EditorUi.isElectronApp = window && window.process && window.process.type; // https://github.com/electron/electron/issues/2288
  19. /**
  20. *
  21. */
  22. if (urlParams['dev'] == '1')
  23. {
  24. Editor.prototype.editBlankUrl = Editor.prototype.editBlankUrl + '&dev=1';
  25. Editor.prototype.editBlankFallbackUrl = Editor.prototype.editBlankFallbackUrl + '&dev=1';
  26. }
  27. /**
  28. * Capability check for canvas export
  29. */
  30. (function()
  31. {
  32. EditorUi.prototype.useCanvasForExport = false;
  33. try
  34. {
  35. var canvas = document.createElement('canvas');
  36. var img = new Image();
  37. // LATER: Capability check should not be async
  38. img.onload = function()
  39. {
  40. try
  41. {
  42. var ctx = canvas.getContext('2d');
  43. ctx.drawImage(img, 0, 0);
  44. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  45. var result = canvas.toDataURL('image/png');
  46. EditorUi.prototype.useCanvasForExport = result != null && result.length > 6;
  47. }
  48. catch (e)
  49. {
  50. // ignore
  51. }
  52. };
  53. // Checks if SVG with foreignObject can be exported
  54. 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>';
  55. img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  56. }
  57. catch (e)
  58. {
  59. // ignore
  60. }
  61. })();
  62. /**
  63. * Initializes math typesetting and loads respective code.
  64. */
  65. Editor.initMath = function(src, config)
  66. {
  67. src = (src != null) ? src : 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  68. Editor.mathJaxQueue = [];
  69. Editor.doMathJaxRender = function(container)
  70. {
  71. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  72. };
  73. // Disables global typesetting and messages on startup, adds queue for
  74. // asynchronous rendering while MathJax is loading
  75. window.MathJax =
  76. {
  77. skipStartupTypeset: true,
  78. showMathMenu: false,
  79. messageStyle: 'none',
  80. AuthorInit: function ()
  81. {
  82. // Specification recommends using SVG over HTML-CSS if browser is known
  83. // Check if too inconsistent with image export and print output
  84. MathJax.Hub.Config(config || {
  85. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  86. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  87. TeX: {
  88. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  89. },
  90. // Ignores math in in-place editor
  91. tex2jax: {
  92. ignoreClass: 'mxCellEditor'
  93. },
  94. asciimath2jax: {
  95. ignoreClass: 'mxCellEditor'
  96. }
  97. });
  98. MathJax.Hub.Register.StartupHook('Begin', function()
  99. {
  100. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  101. {
  102. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  103. }
  104. });
  105. }
  106. };
  107. // Adds global enqueue method for async rendering
  108. Editor.MathJaxRender = function(container)
  109. {
  110. // Initial rendering when MathJax finished loading
  111. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  112. {
  113. Editor.doMathJaxRender(container);
  114. }
  115. else
  116. {
  117. Editor.mathJaxQueue.push(container);
  118. }
  119. };
  120. // Adds global clear queue method
  121. Editor.MathJaxClear = function()
  122. {
  123. Editor.mathJaxQueue = [];
  124. };
  125. // Updates typeset after changes
  126. var editorInit = Editor.prototype.init;
  127. Editor.prototype.init = function()
  128. {
  129. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  130. {
  131. if (this.graph.mathEnabled)
  132. {
  133. Editor.MathJaxRender(this.graph.container);
  134. }
  135. }));
  136. };
  137. var tags = document.getElementsByTagName('script');
  138. if (tags != null && tags.length > 0)
  139. {
  140. var script = document.createElement('script');
  141. script.type = 'text/javascript';
  142. script.src = src;
  143. tags[0].parentNode.appendChild(script);
  144. }
  145. };
  146. /**
  147. * Used in the GraphViewer lightbox.
  148. */
  149. Editor.closeImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8br9fdrftH0O2menfd7+AQfYM/lNjoDHAAAAAElFTkSuQmCC' : IMAGE_PATH + '/delete.png';
  150. /**
  151. * Adds a shadow filter to the given svg root.
  152. */
  153. Editor.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  154. {
  155. createOnly = (createOnly != null) ? createOnly : false;
  156. var svgDoc = svgRoot.ownerDocument;
  157. var filter = (svgDoc.createElementNS != null) ?
  158. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  159. filter.setAttribute('id', this.graph.shadowId);
  160. var blur = (svgDoc.createElementNS != null) ?
  161. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  162. blur.setAttribute('in', 'SourceAlpha');
  163. blur.setAttribute('stdDeviation', '1.7');
  164. blur.setAttribute('result', 'blur');
  165. filter.appendChild(blur);
  166. var offset = (svgDoc.createElementNS != null) ?
  167. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  168. offset.setAttribute('in', 'blur');
  169. offset.setAttribute('dx', '3');
  170. offset.setAttribute('dy', '3');
  171. offset.setAttribute('result', 'offsetBlur');
  172. filter.appendChild(offset);
  173. var flood = (svgDoc.createElementNS != null) ?
  174. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  175. flood.setAttribute('flood-color', '#3D4574');
  176. flood.setAttribute('flood-opacity', '0.4');
  177. flood.setAttribute('result', 'offsetColor');
  178. filter.appendChild(flood);
  179. var composite = (svgDoc.createElementNS != null) ?
  180. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  181. composite.setAttribute('in', 'offsetColor');
  182. composite.setAttribute('in2', 'offsetBlur');
  183. composite.setAttribute('operator', 'in');
  184. composite.setAttribute('result', 'offsetBlur');
  185. filter.appendChild(composite);
  186. var feBlend = (svgDoc.createElementNS != null) ?
  187. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  188. feBlend.setAttribute('in', 'SourceGraphic');
  189. feBlend.setAttribute('in2', 'offsetBlur');
  190. filter.appendChild(feBlend);
  191. // Creates defs element if not available
  192. var defs = svgRoot.getElementsByTagName('defs');
  193. var defsElt = null;
  194. if (defs.length == 0)
  195. {
  196. defsElt = (svgDoc.createElementNS != null) ?
  197. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  198. if (svgRoot.firstChild != null)
  199. {
  200. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  201. }
  202. else
  203. {
  204. svgRoot.appendChild(defsElt);
  205. }
  206. }
  207. else
  208. {
  209. defsElt = defs[0];
  210. }
  211. defsElt.appendChild(filter);
  212. if (!createOnly)
  213. {
  214. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.graph.shadowId + ')');
  215. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  216. {
  217. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  218. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  219. }
  220. }
  221. return filter;
  222. };
  223. /**
  224. * Math support.
  225. */
  226. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  227. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  228. Editor.prototype.updateGraphComponents = function()
  229. {
  230. editorUpdateGraphComponents.apply(this, arguments);
  231. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  232. };
  233. /**
  234. * Abstraction for local storage access.
  235. */
  236. EditorUi.prototype.getLocalData = function(key, fn)
  237. {
  238. fn(localStorage.getItem(key));
  239. };
  240. /**
  241. * Abstraction for local storage access.
  242. */
  243. EditorUi.prototype.setLocalData = function(key, data, fn)
  244. {
  245. localStorage.setItem(key, data);
  246. fn();
  247. };
  248. /**
  249. * Abstraction for local storage access.
  250. */
  251. EditorUi.prototype.removeLocalData = function(key, fn)
  252. {
  253. localStorage.removeItem(key)
  254. fn();
  255. };
  256. EditorUi.prototype.setMathEnabled = function(value)
  257. {
  258. this.editor.graph.mathEnabled = value;
  259. this.editor.updateGraphComponents();
  260. this.editor.graph.refresh();
  261. this.fireEvent(new mxEventObject('mathEnabledChanged'));
  262. };
  263. EditorUi.prototype.isMathEnabled = function(value)
  264. {
  265. return this.editor.graph.mathEnabled;
  266. };
  267. // Helper method to move picket to top
  268. EditorUi.prototype.movePickersToTop = function()
  269. {
  270. var divs = document.getElementsByTagName('div');
  271. for (var i = 0; i < divs.length; i++)
  272. {
  273. if (divs[i].className == 'picker modal-dialog picker-dialog')
  274. {
  275. divs[i].style.zIndex = mxPopupMenu.prototype.zIndex + 1;
  276. }
  277. }
  278. };
  279. /**
  280. * Global switches for the export dialog.
  281. */
  282. if (window.ExportDialog)
  283. {
  284. ExportDialog.showXmlOption = false;
  285. ExportDialog.showGifOption = false;
  286. ExportDialog.getExportParameter = function(ui, format)
  287. {
  288. return function()
  289. {
  290. // LATER Fix decoding of HTML file in backend (remove argument in getFileData)
  291. return 'xml=' + encodeURIComponent(ui.getFileData(true));
  292. };
  293. };
  294. }
  295. /**
  296. * Specifies the app name. Default is document.title.
  297. */
  298. Editor.prototype.appName = 'draw.io';
  299. /**
  300. * Translates this point by the given vector.
  301. *
  302. * @param {number} dx X-coordinate of the translation.
  303. * @param {number} dy Y-coordinate of the translation.
  304. */
  305. EditorUi.prototype.isOfflineApp = function()
  306. {
  307. return (urlParams['offline'] == '1');
  308. };
  309. /**
  310. * Returns true if this offline app is offline.
  311. */
  312. EditorUi.prototype.isOffline = function()
  313. {
  314. // In FF navigator.onLine is always true
  315. return (mxClient.IS_FF && this.isOfflineApp()) || !navigator.onLine || urlParams['stealth'] == '1';
  316. };
  317. /**
  318. * Translates this point by the given vector.
  319. *
  320. * @param {number} dx X-coordinate of the translation.
  321. * @param {number} dy Y-coordinate of the translation.
  322. */
  323. EditorUi.prototype.createSpinner = function(x, y, size)
  324. {
  325. size = (size != null) ? size : 24;
  326. var spinner = new Spinner({
  327. lines: 12, // The number of lines to draw
  328. length: size, // The length of each line
  329. width: Math.round(size / 3), // The line thickness
  330. radius: Math.round(size / 2), // The radius of the inner circle
  331. rotate: 0, // The rotation offset
  332. color: '#000', // #rgb or #rrggbb
  333. speed: 1.5, // Rounds per second
  334. trail: 60, // Afterglow percentage
  335. shadow: false, // Whether to render a shadow
  336. hwaccel: false, // Whether to use hardware acceleration
  337. zIndex: 2e9 // The z-index (defaults to 2000000000)
  338. });
  339. // Extends spin method to include an optional label
  340. var oldSpin = spinner.spin;
  341. spinner.spin = function(container, label)
  342. {
  343. var result = false;
  344. if (!this.active)
  345. {
  346. oldSpin.call(this, container);
  347. this.active = true;
  348. if (label != null)
  349. {
  350. var status = document.createElement('div');
  351. status.style.position = 'absolute';
  352. status.style.whiteSpace = 'nowrap';
  353. status.style.background = '#4B4243';
  354. status.style.color = 'white';
  355. status.style.fontFamily = 'Helvetica, Arial';
  356. status.style.fontSize = '9pt';
  357. status.style.padding = '6px';
  358. status.style.paddingLeft = '10px';
  359. status.style.paddingRight = '10px';
  360. status.style.zIndex = 2e9;
  361. status.style.left = Math.max(0, x) + 'px';
  362. status.style.top = Math.max(0, y + 70) + 'px';
  363. mxUtils.setPrefixedStyle(status.style, 'borderRadius', '6px');
  364. mxUtils.setPrefixedStyle(status.style, 'boxShadow', '2px 2px 3px 0px #ddd');
  365. mxUtils.setPrefixedStyle(status.style, 'transform', 'translate(-50%,-50%)');
  366. status.innerHTML = label + '...';
  367. container.appendChild(status);
  368. spinner.status = status;
  369. // Centers the label in older IE versions
  370. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode <= 8))
  371. {
  372. status.style.left = Math.round(Math.max(0, x - status.offsetWidth / 2)) + 'px';
  373. status.style.top = Math.round(Math.max(0, y + 70 - status.offsetHeight / 2)) + 'px';
  374. }
  375. }
  376. // Pause returns a function to resume the spinner
  377. this.pause = mxUtils.bind(this, function()
  378. {
  379. var fn = function() { };
  380. if (this.active)
  381. {
  382. fn = mxUtils.bind(this, function()
  383. {
  384. this.spin(container, label);
  385. });
  386. }
  387. this.stop();
  388. return fn;
  389. });
  390. result = true;
  391. }
  392. return result;
  393. };
  394. // Extends stop method to remove the optional label
  395. var oldStop = spinner.stop;
  396. spinner.stop = function()
  397. {
  398. oldStop.call(this);
  399. this.active = false;
  400. if (spinner.status != null)
  401. {
  402. spinner.status.parentNode.removeChild(spinner.status);
  403. spinner.status = null;
  404. }
  405. };
  406. return spinner;
  407. };
  408. /**
  409. * Static method for pasing PNG files.
  410. */
  411. EditorUi.parsePng = function(f, fn, error)
  412. {
  413. var pos = 0;
  414. function fread(d, count)
  415. {
  416. var start = pos;
  417. pos += count;
  418. return d.substring(start, pos);
  419. };
  420. // Reads unsigned long 32 bit big endian
  421. function _freadint(d)
  422. {
  423. var bytes = fread(d, 4);
  424. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  425. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  426. };
  427. // Checks signature
  428. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  429. {
  430. if (error != null)
  431. {
  432. error();
  433. }
  434. return;
  435. }
  436. // Reads header chunk
  437. fread(f,4);
  438. if (fread(f,4) != 'IHDR')
  439. {
  440. if (error != null)
  441. {
  442. error();
  443. }
  444. return;
  445. }
  446. fread(f, 17);
  447. do
  448. {
  449. var n = _freadint(f);
  450. var type = fread(f,4);
  451. if (fn != null)
  452. {
  453. if (fn(pos - 8, type, n))
  454. {
  455. break;
  456. }
  457. }
  458. value = fread(f,n);
  459. fread(f,4);
  460. if (type == 'IEND')
  461. {
  462. break;
  463. }
  464. }
  465. while (n);
  466. };
  467. /**
  468. * Helper function to extract the graph model XML node.
  469. */
  470. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  471. {
  472. if (node != null && typeof(pako) !== 'undefined')
  473. {
  474. var tmp = node.ownerDocument.getElementsByTagName('div');
  475. var divs = [];
  476. if (tmp != null && tmp.length > 0)
  477. {
  478. for (var i = 0; i < tmp.length; i++)
  479. {
  480. if (tmp[i].getAttribute('class') == 'mxgraph')
  481. {
  482. divs.push(tmp[i]);
  483. break;
  484. }
  485. }
  486. }
  487. if (divs.length > 0)
  488. {
  489. var data = divs[0].getAttribute('data-mxgraph');
  490. if (data != null)
  491. {
  492. var config = JSON.parse(data);
  493. if (config != null && config.xml != null)
  494. {
  495. var doc2 = mxUtils.parseXml(config.xml);
  496. node = doc2.documentElement;
  497. }
  498. }
  499. else
  500. {
  501. var divs2 = divs[0].getElementsByTagName('div');
  502. if (divs2.length > 0)
  503. {
  504. var data = mxUtils.getTextContent(divs2[0]);
  505. data = this.graph.decompress(data);
  506. if (data.length > 0)
  507. {
  508. var doc2 = mxUtils.parseXml(data);
  509. node = doc2.documentElement;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. if (node != null && node.nodeName == 'svg')
  516. {
  517. var tmp = node.getAttribute('content');
  518. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  519. {
  520. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  521. }
  522. if (tmp != null && tmp.charAt(0) == '%')
  523. {
  524. tmp = decodeURIComponent(tmp);
  525. }
  526. if (tmp != null && tmp.length > 0)
  527. {
  528. node = mxUtils.parseXml(tmp).documentElement;
  529. }
  530. else
  531. {
  532. throw {message: mxResources.get('notADiagramFile')};
  533. }
  534. }
  535. if (node != null && !allowMxFile)
  536. {
  537. var diagramNode = null;
  538. if (node.nodeName == 'diagram')
  539. {
  540. diagramNode = node;
  541. }
  542. else if (node.nodeName == 'mxfile')
  543. {
  544. var diagrams = node.getElementsByTagName('diagram');
  545. if (diagrams.length > 0)
  546. {
  547. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  548. }
  549. }
  550. if (diagramNode != null)
  551. {
  552. node = mxUtils.parseXml(this.graph.decompress(mxUtils.getTextContent(diagramNode))).documentElement;
  553. }
  554. }
  555. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  556. {
  557. node = null;
  558. }
  559. return node;
  560. };
  561. /**
  562. * Returns true if the given string contains a compatible graph model.
  563. */
  564. EditorUi.prototype.isCompatibleString = function(data)
  565. {
  566. try
  567. {
  568. var doc = mxUtils.parseXml(data);
  569. var node = this.editor.extractGraphModel(doc.documentElement);
  570. return node != null && node.getElementsByTagName('parsererror').length == 0;
  571. }
  572. catch (e)
  573. {
  574. // ignore
  575. }
  576. return false;
  577. };
  578. /**
  579. * Extracts the mxfile from the given HTML data from a data transfer event.
  580. */
  581. var editorUiExtractGraphModelFromHtml = EditorUi.prototype.extractGraphModelFromHtml;
  582. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  583. {
  584. var result = editorUiExtractGraphModelFromHtml.apply(this, arguments);
  585. if (result == null)
  586. {
  587. try
  588. {
  589. var idx = data.indexOf('&lt;mxfile ');
  590. if (idx >= 0)
  591. {
  592. var idx2 = data.lastIndexOf('&lt;/mxfile&gt;');
  593. if (idx2 > idx)
  594. {
  595. result = data.substring(idx, idx2 + 15).replace(/&gt;/g, '>').
  596. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  597. }
  598. }
  599. else
  600. {
  601. // Gets compressed data from mxgraph element in HTML document
  602. var doc = mxUtils.parseXml(data);
  603. var node = this.editor.extractGraphModel(doc.documentElement);
  604. result = (node != null) ? mxUtils.getXml(node) : '';
  605. }
  606. }
  607. catch (e)
  608. {
  609. // ignore
  610. }
  611. }
  612. return result;
  613. };
  614. /**
  615. * Workaround for malformed xhtml meta element bug 07.08.16. The trailing slash was missing causing
  616. * reopen to fail trying to parse. Used in replaceFileData, setFileData and importFile.
  617. */
  618. EditorUi.prototype.validateFileData = function(data)
  619. {
  620. if (data != null && data.length > 0)
  621. {
  622. var index = data.indexOf('<meta charset="utf-8">');
  623. if (index >= 0)
  624. {
  625. var replaceString = '<meta charset="utf-8"/>';
  626. var replaceStrLen = replaceString.length;
  627. data = data.slice(0, index) + replaceString + data.slice(index + replaceStrLen - 1, data.length);
  628. }
  629. }
  630. return data;
  631. };
  632. /**
  633. *
  634. */
  635. EditorUi.prototype.replaceFileData = function(data)
  636. {
  637. data = this.validateFileData(data);
  638. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  639. // Some nodes must be extracted here to find the mxfile node
  640. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  641. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  642. if (tmp != null)
  643. {
  644. node = tmp;
  645. }
  646. if (node != null)
  647. {
  648. var graph = this.editor.graph;
  649. graph.model.beginUpdate();
  650. try
  651. {
  652. var oldPages = (this.pages != null) ? this.pages.slice() : null;
  653. var nodes = node.getElementsByTagName('diagram');
  654. if (urlParams['pages'] != '0' || nodes.length > 1 ||
  655. (nodes.length == 1 && nodes[0].hasAttribute('name')))
  656. {
  657. this.fileNode = node;
  658. this.pages = (this.pages != null) ? this.pages : [];
  659. // Wraps page nodes
  660. for (var i = nodes.length - 1; i >= 0; i--)
  661. {
  662. var page = this.updatePageRoot(new DiagramPage(nodes[i]));
  663. // Checks for invalid page names
  664. if (page.getName() == null)
  665. {
  666. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  667. }
  668. graph.model.execute(new ChangePage(this, page, (i == 0) ? page : null, 0));
  669. }
  670. }
  671. else
  672. {
  673. // Creates tabbed file structure if enforced by URL
  674. if (urlParams['pages'] != '0' && this.fileNode == null)
  675. {
  676. this.fileNode = node.ownerDocument.createElement('mxfile');
  677. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  678. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  679. graph.model.execute(new ChangePage(this, this.currentPage, this.currentPage, 0));
  680. }
  681. // Avoids scroll offset when switching page
  682. this.editor.setGraphXml(node);
  683. // Avoids duplicate parsing of the XML stored in the node
  684. if (this.currentPage != null)
  685. {
  686. this.currentPage.root = this.editor.graph.model.root;
  687. }
  688. }
  689. if (oldPages != null)
  690. {
  691. for (var i = 0; i < oldPages.length; i++)
  692. {
  693. graph.model.execute(new ChangePage(this, oldPages[i], null));
  694. }
  695. }
  696. }
  697. finally
  698. {
  699. graph.model.endUpdate();
  700. }
  701. }
  702. };
  703. /**
  704. *
  705. */
  706. EditorUi.prototype.setFileData = function(data)
  707. {
  708. data = this.validateFileData(data);
  709. this.currentPage = null;
  710. this.fileNode = null;
  711. this.pages = null;
  712. var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
  713. // Some nodes must be extracted here to find the mxfile node
  714. // LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
  715. var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
  716. if (tmp != null)
  717. {
  718. node = tmp;
  719. }
  720. if (node != null && node.nodeName == 'mxfile')
  721. {
  722. var nodes = node.getElementsByTagName('diagram');
  723. if (urlParams['pages'] != '0' || nodes.length > 1 ||
  724. (nodes.length == 1 && nodes[0].hasAttribute('name')))
  725. {
  726. this.fileNode = node;
  727. this.pages = [];
  728. // Wraps page nodes
  729. for (var i = 0; i < nodes.length; i++)
  730. {
  731. var page = new DiagramPage(nodes[i]);
  732. // Checks for invalid page names
  733. if (page.getName() == null)
  734. {
  735. page.setName(mxResources.get('pageWithNumber', [i + 1]));
  736. }
  737. this.pages.push(page);
  738. }
  739. this.currentPage = this.pages[Math.max(0, Math.min(this.pages.length - 1, urlParams['page'] || 0))];
  740. node = this.currentPage.node;
  741. }
  742. }
  743. // Creates tabbed file structure if enforced by URL
  744. if (urlParams['pages'] != '0' && this.fileNode == null)
  745. {
  746. this.fileNode = node.ownerDocument.createElement('mxfile');
  747. this.currentPage = new DiagramPage(node.ownerDocument.createElement('diagram'));
  748. this.currentPage.setName(mxResources.get('pageWithNumber', [1]));
  749. this.pages = [this.currentPage];
  750. }
  751. // Avoids scroll offset when switching page
  752. this.editor.setGraphXml(node);
  753. // Avoids duplicate parsing of the XML stored in the node
  754. if (this.currentPage != null)
  755. {
  756. this.currentPage.root = this.editor.graph.model.root;
  757. }
  758. };
  759. /**
  760. * Adds support for old stylesheets and compressed files
  761. */
  762. var editorSetGraphXml = Editor.prototype.setGraphXml;
  763. Editor.prototype.setGraphXml = function(node)
  764. {
  765. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  766. if (node != null)
  767. {
  768. // Checks input for parser errors
  769. var errs = node.getElementsByTagName('parsererror');
  770. if (errs != null && errs.length > 0)
  771. {
  772. var elt = errs[0];
  773. var divs = elt.getElementsByTagName('div');
  774. if (divs != null && divs.length > 0)
  775. {
  776. elt = divs[0];
  777. }
  778. throw {message: mxUtils.getTextContent(elt)};
  779. }
  780. else if (node.nodeName == 'mxGraphModel')
  781. {
  782. var style = node.getAttribute('style') || 'default-style2';
  783. // Decodes the style if required
  784. if (urlParams['embed'] != '1' && (style == null || style == ''))
  785. {
  786. var node2 = (this.graph.themes != null) ?
  787. this.graph.themes['default-old'] :
  788. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  789. if (node2 != null)
  790. {
  791. var dec2 = new mxCodec(node2.ownerDocument);
  792. dec2.decode(node2, this.graph.getStylesheet());
  793. }
  794. }
  795. else if (style != this.graph.currentStyle)
  796. {
  797. var node2 = (this.graph.themes != null) ?
  798. this.graph.themes[style] :
  799. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  800. if (node2 != null)
  801. {
  802. var dec2 = new mxCodec(node2.ownerDocument);
  803. dec2.decode(node2, this.graph.getStylesheet());
  804. }
  805. }
  806. this.graph.currentStyle = style;
  807. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  808. var bgImg = node.getAttribute('backgroundImage');
  809. if (bgImg != null)
  810. {
  811. bgImg = JSON.parse(bgImg);
  812. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  813. }
  814. else
  815. {
  816. this.graph.setBackgroundImage(null);
  817. }
  818. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  819. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  820. }
  821. // Calls updateGraphComponents
  822. editorSetGraphXml.apply(this, arguments);
  823. }
  824. else
  825. {
  826. throw {
  827. message: mxResources.get('notADiagramFile') || 'Invalid data',
  828. toString: function() { return this.message; }
  829. };
  830. }
  831. };
  832. /**
  833. * Adds persistent style to file
  834. */
  835. var editorGetGraphXml = Editor.prototype.getGraphXml;
  836. Editor.prototype.getGraphXml = function(ignoreSelection)
  837. {
  838. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  839. var node = editorGetGraphXml.apply(this, arguments);
  840. // Adds the current style
  841. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  842. {
  843. node.setAttribute('style', this.graph.currentStyle);
  844. }
  845. // Adds the background image
  846. if (this.graph.backgroundImage != null)
  847. {
  848. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  849. }
  850. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  851. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  852. return node;
  853. };
  854. var editorResetGraph = Editor.prototype.resetGraph;
  855. Editor.prototype.resetGraph = function()
  856. {
  857. this.graph.mathEnabled = (urlParams['math'] == '1');
  858. this.graph.view.x0 = null;
  859. this.graph.view.y0 = null;
  860. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  861. editorResetGraph.apply(this, arguments);
  862. };
  863. /**
  864. * EditorUi Overrides
  865. */
  866. if (urlParams['offline'] == '1')
  867. {
  868. EditorUi.prototype.footerHeight = 4;
  869. }
  870. else
  871. {
  872. if (uiTheme == 'atlas')
  873. {
  874. if (typeof Toolbar !== 'undefined')
  875. {
  876. Toolbar.prototype.unselectedBackground = (mxClient.IS_QUIRKS) ? 'none' : 'linear-gradient(rgb(255, 255, 255) 0px, rgb(242, 242, 242) 100%)';
  877. Toolbar.prototype.selectedBackground = 'rgb(242, 242, 242)';
  878. }
  879. Editor.prototype.initialTopSpacing = 3;
  880. EditorUi.prototype.menubarHeight = 41;
  881. EditorUi.prototype.toolbarHeight = 38;
  882. EditorUi.prototype.hsplitPosition = 188;
  883. Sidebar.prototype.thumbWidth = 46;
  884. Sidebar.prototype.thumbHeight = 46;
  885. Sidebar.prototype.thumbPadding = (document.documentMode >= 5) ? 0 : 1;
  886. Sidebar.prototype.thumbBorder = 2;
  887. }
  888. else
  889. {
  890. if (urlParams['savesidebar'] == '1')
  891. {
  892. Sidebar.prototype.thumbWidth = 64;
  893. Sidebar.prototype.thumbHeight = 64;
  894. }
  895. }
  896. EditorUi.prototype.footerHeight = (screen.height <= 740) ? 5 : 46;
  897. // Fetches footer from page
  898. EditorUi.prototype.createFooter = function()
  899. {
  900. var footer = document.getElementById('geFooter');
  901. if (footer != null)
  902. {
  903. footer.style.visibility = 'visible';
  904. // Adds button to hide the footer
  905. var img = document.createElement('img');
  906. img.setAttribute('border', '0');
  907. img.setAttribute('src', Dialog.prototype.closeImage);
  908. img.setAttribute('title', mxResources.get('hide'));
  909. footer.appendChild(img)
  910. if (mxClient.IS_QUIRKS)
  911. {
  912. img.style.position = 'relative';
  913. img.style.styleFloat = 'right';
  914. img.style.top = '-30px';
  915. img.style.left = '164px';
  916. img.style.cursor = 'pointer';
  917. }
  918. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  919. {
  920. this.hideFooter();
  921. }));
  922. }
  923. return footer;
  924. };
  925. }
  926. /**
  927. * Hides the footer.
  928. */
  929. EditorUi.prototype.hideFooter = function()
  930. {
  931. var footer = document.getElementById('geFooter');
  932. if (footer != null)
  933. {
  934. this.footerHeight = 0;
  935. footer.style.display = 'none';
  936. this.refresh();
  937. }
  938. };
  939. /**
  940. * Overrides image dialog to add image search and Google+.
  941. */
  942. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting, convertDataUri)
  943. {
  944. // KNOWN: IE+FF don't return keyboard focus after image dialog (calling focus doesn't help)
  945. var dlg = new ImageDialog(this, title, value, fn, ignoreExisting, convertDataUri);
  946. this.showDialog(dlg.container, (Graph.fileSupport) ? 420 : 340, (Graph.fileSupport) ? 200 : 90, true, true);
  947. dlg.init();
  948. };
  949. /**
  950. * Hides the current menu.
  951. */
  952. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  953. {
  954. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  955. {
  956. this.setBackgroundImage(image);
  957. });
  958. var dlg = new BackgroundImageDialog(this, mxUtils.bind(this, function(image)
  959. {
  960. apply(image);
  961. }));
  962. this.showDialog(dlg.container, 360, 200, true, true);
  963. dlg.init();
  964. };
  965. /**
  966. * Hides the current menu.
  967. */
  968. EditorUi.prototype.showLibraryDialog = function(name, sidebar, images, file, mode)
  969. {
  970. var dlg = new LibraryDialog(this, name, sidebar, images, file, mode);
  971. this.showDialog(dlg.container, 620, 440, true, true, mxUtils.bind(this, function(cancel)
  972. {
  973. if (cancel && this.getCurrentFile() == null)
  974. {
  975. this.showSplash();
  976. }
  977. }));
  978. dlg.init();
  979. };
  980. /**
  981. * Allows for two buttons in the sidebar footer.
  982. */
  983. EditorUi.prototype.sidebarFooterHeight = (uiTheme == 'atlas') ? 36 : 36;
  984. /**
  985. * Specifies the default custom shape style.
  986. */
  987. 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;';
  988. /**
  989. * Hook for sidebar footer container.
  990. */
  991. EditorUi.prototype.createSidebarFooterContainer = function()
  992. {
  993. var div = this.createDiv('geSidebarContainer');
  994. div.style.position = 'absolute';
  995. div.style.overflow = 'hidden';
  996. div.style.borderWidth = '3px';
  997. var elt2 = document.createElement('a');
  998. elt2.setAttribute('href', 'javascript:void(0);');
  999. elt2.className = 'geTitle';
  1000. elt2.style.height = '100%';
  1001. elt2.style.paddingTop = '9px';
  1002. mxUtils.write(elt2, mxResources.get('moreShapes') + '...');
  1003. mxEvent.addListener(elt2, 'click', mxUtils.bind(this, function(evt)
  1004. {
  1005. this.actions.get('shapes').funct();
  1006. mxEvent.consume(evt);
  1007. }));
  1008. div.appendChild(elt2);
  1009. return div;
  1010. };
  1011. /**
  1012. * Setting the current file.
  1013. */
  1014. /**
  1015. * Defines the maximum size for images.
  1016. */
  1017. EditorUi.prototype.maxBackgroundSize = 1600;
  1018. /**
  1019. * Defines the maximum size for images.
  1020. */
  1021. EditorUi.prototype.maxImageSize = 520;
  1022. /**
  1023. * Images above 100K should be resampled.
  1024. */
  1025. EditorUi.prototype.resampleThreshold = 100000;
  1026. /**
  1027. * Maximum allowed size for images is 1 MB.
  1028. */
  1029. EditorUi.prototype.maxImageBytes = 1000000;
  1030. /**
  1031. * Maximum size for background images is 2.5 MB.
  1032. */
  1033. EditorUi.prototype.maxBackgroundBytes = 2500000;
  1034. /**
  1035. * Holds the current file.
  1036. */
  1037. EditorUi.prototype.currentFile = null;
  1038. /**
  1039. * Translates this point by the given vector.
  1040. *
  1041. * @param {number} dx X-coordinate of the translation.
  1042. * @param {number} dy Y-coordinate of the translation.
  1043. */
  1044. EditorUi.prototype.setCurrentFile = function(file)
  1045. {
  1046. this.currentFile = file;
  1047. };
  1048. /**
  1049. * Translates this point by the given vector.
  1050. *
  1051. * @param {number} dx X-coordinate of the translation.
  1052. * @param {number} dy Y-coordinate of the translation.
  1053. */
  1054. EditorUi.prototype.getCurrentFile = function()
  1055. {
  1056. return this.currentFile;
  1057. };
  1058. /**
  1059. * Translates this point by the given vector.
  1060. *
  1061. * @param {number} dx X-coordinate of the translation.
  1062. * @param {number} dy Y-coordinate of the translation.
  1063. */
  1064. EditorUi.prototype.isDiagramEmpty = function()
  1065. {
  1066. var model = this.editor.graph.getModel();
  1067. return model.getChildCount(model.root) == 1 && model.getChildCount(model.getChildAt(model.root, 0)) == 0;
  1068. };
  1069. /**
  1070. * Handling for canvas export.
  1071. */
  1072. /**
  1073. *
  1074. */
  1075. EditorUi.prototype.isExportToCanvas = function()
  1076. {
  1077. // LATER: Fix security error caused by foreignObjects in Safari for toDataUri (tainted canvas)
  1078. return mxClient.IS_CHROMEAPP || (!this.editor.graph.mathEnabled && this.useCanvasForExport);
  1079. };
  1080. /**
  1081. * Translates this point by the given vector.
  1082. *
  1083. * @param {number} dx X-coordinate of the translation.
  1084. * @param {number} dy Y-coordinate of the translation.
  1085. */
  1086. EditorUi.prototype.createSvgDataUri = function(svg)
  1087. {
  1088. return 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
  1089. };
  1090. /**
  1091. *
  1092. */
  1093. EditorUi.prototype.createPngDataUri = function(canvas, xml)
  1094. {
  1095. var data = canvas.toDataURL('image/png');
  1096. // Checks if output is invalid or empty
  1097. if (data.length <= 6 || data == canvas.cloneNode(false).toDataURL('image/png'))
  1098. {
  1099. throw {message: 'Invalid image'};
  1100. }
  1101. if (xml != null)
  1102. {
  1103. data = this.writeGraphModelToPng(data, 'zTXt', 'mxGraphModel', atob(this.editor.graph.compress(xml)));
  1104. }
  1105. return data;
  1106. };
  1107. /**
  1108. *
  1109. */
  1110. EditorUi.prototype.saveCanvas = function(canvas, xml)
  1111. {
  1112. var file = this.getCurrentFile();
  1113. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1114. var dot = filename.lastIndexOf('.');
  1115. if (dot > 0)
  1116. {
  1117. filename = filename.substring(0, dot);
  1118. }
  1119. filename += '.png';
  1120. var data = this.createPngDataUri(canvas, xml);
  1121. this.saveLocalFile(data.substring(data.lastIndexOf(',') + 1), filename, 'image/png', true);
  1122. };
  1123. /**
  1124. *
  1125. */
  1126. EditorUi.prototype.showRemoteExportDialog = function(btnLabel, helpLink, callback)
  1127. {
  1128. var graph = this.editor.graph;
  1129. var content = document.createElement('div');
  1130. content.style.padding = '6px';
  1131. var cb2 = document.createElement('input');
  1132. cb2.style.marginRight = '8px';
  1133. cb2.setAttribute('type', 'checkbox');
  1134. if (graph.isSelectionEmpty())
  1135. {
  1136. cb2.setAttribute('disabled', 'disabled');
  1137. }
  1138. content.appendChild(cb2);
  1139. mxUtils.write(content, mxResources.get('selectionOnly'));
  1140. mxUtils.br(content);
  1141. var cb = document.createElement('input');
  1142. cb.setAttribute('type', 'checkbox');
  1143. cb.setAttribute('checked', 'checked');
  1144. cb.defaultChecked = true;
  1145. cb.style.marginRight = '8px';
  1146. cb.style.marginTop = '16px';
  1147. content.appendChild(cb);
  1148. mxUtils.write(content, mxResources.get('includeCopyOfMyDiagram'));
  1149. var dlg = new CustomDialog(this, content, mxUtils.bind(this, function()
  1150. {
  1151. callback(!cb2.checked, cb.checked);
  1152. }), null, btnLabel, helpLink);
  1153. this.showDialog(dlg.container, 300, 120, true, true);
  1154. }
  1155. /**
  1156. *
  1157. */
  1158. EditorUi.prototype.showExportDialog = function(embedOption, btnLabel, helpLink, callback)
  1159. {
  1160. var graph = this.editor.graph;
  1161. var content = document.createElement('div');
  1162. content.style.paddingTop = '20px';
  1163. content.style.paddingRight = '8px';
  1164. var cb = document.createElement('input');
  1165. cb.style.marginRight = '8px';
  1166. cb.setAttribute('type', 'checkbox');
  1167. if (graph.background == mxConstants.NONE || graph.background == null)
  1168. {
  1169. cb.setAttribute('checked', 'checked');
  1170. cb.defaultChecked = true;
  1171. }
  1172. content.appendChild(cb);
  1173. mxUtils.write(content, mxResources.get('transparentBackground'));
  1174. mxUtils.br(content);
  1175. var cb2 = document.createElement('input');
  1176. cb2.style.marginTop = '16px';
  1177. cb2.style.marginRight = '8px';
  1178. cb2.setAttribute('type', 'checkbox');
  1179. if (graph.isSelectionEmpty())
  1180. {
  1181. cb2.setAttribute('disabled', 'disabled');
  1182. }
  1183. content.appendChild(cb2);
  1184. mxUtils.write(content, mxResources.get('selectionOnly'));
  1185. mxUtils.br(content);
  1186. var cb3 = document.createElement('input');
  1187. cb3.style.marginTop = '16px';
  1188. cb3.style.marginRight = '8px';
  1189. cb3.setAttribute('type', 'checkbox');
  1190. content.appendChild(cb3);
  1191. mxUtils.write(content, mxResources.get('shadow'));
  1192. mxUtils.br(content);
  1193. if (graph.shadowVisible)
  1194. {
  1195. cb3.setAttribute('checked', 'checked');
  1196. cb3.defaultChecked = true;
  1197. }
  1198. var cb5 = document.createElement('input');
  1199. cb5.style.marginTop = '16px';
  1200. cb5.style.marginRight = '8px';
  1201. cb5.setAttribute('type', 'checkbox');
  1202. if (this.isOffline() || !this.canvasSupported)
  1203. {
  1204. cb5.setAttribute('disabled', 'disabled');
  1205. }
  1206. if (embedOption)
  1207. {
  1208. content.appendChild(cb5);
  1209. mxUtils.write(content, mxResources.get('embedImages'));
  1210. mxUtils.br(content);
  1211. }
  1212. var cb4 = document.createElement('input');
  1213. cb4.style.marginTop = '16px';
  1214. cb4.style.marginRight = '8px';
  1215. cb4.setAttribute('type', 'checkbox');
  1216. cb4.style.marginBottom = '8px';
  1217. cb4.setAttribute('checked', 'checked');
  1218. cb4.defaultChecked = true;
  1219. content.appendChild(cb4);
  1220. mxUtils.write(content, mxResources.get('includeCopyOfMyDiagram'));
  1221. var dlg = new FilenameDialog(this, 100, btnLabel, mxUtils.bind(this, function(newValue)
  1222. {
  1223. callback(newValue, cb.checked, !cb2.checked, cb3.checked, cb4.checked, cb5.checked);
  1224. }), mxResources.get('zoom') + ' (%)', null, content, (!this.isOffline()) ? helpLink : null);
  1225. this.showDialog(dlg.container, 320, (embedOption) ? 266 : 240, true, true);
  1226. dlg.init();
  1227. }
  1228. /**
  1229. *
  1230. */
  1231. EditorUi.prototype.uploadToGithub = function(file, base64Data, editable)
  1232. {
  1233. var resume = this.spinner.pause();
  1234. var content = document.createElement('div');
  1235. content.style.paddingTop = '20px';
  1236. content.style.paddingRight = '8px';
  1237. var table = document.createElement('table');
  1238. var tbody = document.createElement('tbody');
  1239. var tr = document.createElement('tr');
  1240. var td = document.createElement('td');
  1241. var uname = document.createElement('input');
  1242. uname.setAttribute('type', 'text');
  1243. mxUtils.write(td, 'Username:');
  1244. tr.appendChild(td);
  1245. td = td.cloneNode(false);
  1246. td.appendChild(uname);
  1247. tr.appendChild(td);
  1248. tbody.appendChild(tr);
  1249. td = td.cloneNode(false);
  1250. var pword = document.createElement('input');
  1251. pword.setAttribute('type', 'password');
  1252. mxUtils.write(td, 'Password:');
  1253. tr = tr.cloneNode(false);
  1254. tr.appendChild(td);
  1255. td = td.cloneNode(false);
  1256. td.appendChild(pword);
  1257. tr.appendChild(td);
  1258. tbody.appendChild(tr);
  1259. td = td.cloneNode(false);
  1260. var org = document.createElement('input');
  1261. org.setAttribute('type', 'text');
  1262. mxUtils.write(td, 'Organisation:');
  1263. tr = tr.cloneNode(false);
  1264. tr.appendChild(td);
  1265. td = td.cloneNode(false);
  1266. td.appendChild(org);
  1267. tr.appendChild(td);
  1268. tbody.appendChild(tr);
  1269. td = td.cloneNode(false);
  1270. var repo = document.createElement('input');
  1271. repo.setAttribute('type', 'text');
  1272. mxUtils.write(td, 'Repository:');
  1273. tr = tr.cloneNode(false);
  1274. tr.appendChild(td);
  1275. td = td.cloneNode(false);
  1276. td.appendChild(repo);
  1277. tr.appendChild(td);
  1278. tbody.appendChild(tr);
  1279. td = td.cloneNode(false);
  1280. var path = document.createElement('input');
  1281. path.setAttribute('type', 'text');
  1282. mxUtils.write(td, 'Path:');
  1283. tr = tr.cloneNode(false);
  1284. tr.appendChild(td);
  1285. td = td.cloneNode(false);
  1286. td.appendChild(path);
  1287. tr.appendChild(td);
  1288. tbody.appendChild(tr);
  1289. td = td.cloneNode(false);
  1290. var file = this.getCurrentFile();
  1291. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1292. var dot = filename.lastIndexOf('.');
  1293. if (dot > 0)
  1294. {
  1295. filename = filename.substring(0, dot);
  1296. }
  1297. path.value = filename + '.png';
  1298. var ref = document.createElement('input');
  1299. ref.setAttribute('type', 'text');
  1300. mxUtils.write(td, 'Branch/Tag:');
  1301. ref.value = 'master';
  1302. tr = tr.cloneNode(false);
  1303. tr.appendChild(td);
  1304. td = td.cloneNode(false);
  1305. td.appendChild(ref);
  1306. tr.appendChild(td);
  1307. tbody.appendChild(tr);
  1308. td = td.cloneNode(false);
  1309. var msg = document.createElement('input');
  1310. msg.setAttribute('type', 'text');
  1311. mxUtils.write(td, 'Message:');
  1312. msg.value = 'Updated ' + filename + '.png';
  1313. tr = tr.cloneNode(false);
  1314. tr.appendChild(td);
  1315. td = td.cloneNode(false);
  1316. td.appendChild(msg);
  1317. tr.appendChild(td);
  1318. tbody.appendChild(tr);
  1319. td = td.cloneNode(false);
  1320. table.appendChild(tbody);
  1321. content.appendChild(table);
  1322. var dlg = new FilenameDialog(this, null, mxResources.get('publish'), mxUtils.bind(this, function()
  1323. {
  1324. var url = 'https://api.github.com/repos/' + org.value + '/' + repo.value +
  1325. '/contents/' + path.value + '?ref=' + encodeURIComponent(ref.value);
  1326. resume();
  1327. mxUtils.get(url, mxUtils.bind(this, function(req)
  1328. {
  1329. if (req.getStatus() == 200 || req.getStatus() == 404)
  1330. {
  1331. var obj = JSON.parse(req.getText());
  1332. var entity =
  1333. {
  1334. path: path.value,
  1335. message: msg.value,
  1336. content: base64Data
  1337. };
  1338. if (obj.sha != null)
  1339. {
  1340. entity.sha = obj.sha;
  1341. }
  1342. // Native PUT request
  1343. var req2 = new XMLHttpRequest();
  1344. req2.onreadystatechange = mxUtils.bind(this, function()
  1345. {
  1346. if (req2.readyState == 4)
  1347. {
  1348. if (req2.status >= 200 && req2.status < 300)
  1349. {
  1350. this.spinner.stop();
  1351. this.hideDialog();
  1352. url = 'https://github.com/' + org.value + '/' + repo.value + '/blob/' + ref.value + '/' + path.value;
  1353. var dlg = new ErrorDialog(this, mxResources.get('published'),
  1354. mxResources.get('publishedAt', ['<a href="' + url + '" target="_blank">' + url + '</a>']),
  1355. mxResources.get('close'), mxUtils.bind(this, function()
  1356. {
  1357. this.hideDialog();
  1358. }), null,
  1359. mxResources.get('openInNewWindow'), mxUtils.bind(this, function()
  1360. {
  1361. window.open(url);
  1362. }), false);
  1363. this.showDialog(dlg.container, 340, 170, true, false);
  1364. dlg.init();
  1365. }
  1366. else
  1367. {
  1368. resume = this.spinner.pause();
  1369. this.handleError(JSON.parse(req2.responseText));
  1370. }
  1371. }
  1372. });
  1373. req2.open('PUT', url, true);
  1374. req2.setRequestHeader('Authorization', 'Basic ' +
  1375. btoa(uname.value + ':' + pword.value));
  1376. req2.send(JSON.stringify(entity));
  1377. }
  1378. else
  1379. {
  1380. this.hideDialog();
  1381. this.spinner.stop();
  1382. this.handleError(JSON.parse(req.getText()));
  1383. }
  1384. }), mxUtils.bind(this, function(req)
  1385. {
  1386. this.hideDialog();
  1387. this.spinner.stop();
  1388. this.handleError({message: mxResources.get('unknownError')});
  1389. }));
  1390. }), null, null, content, null, false);
  1391. this.showDialog(dlg.container, 260, 260, true, false);
  1392. dlg.init();
  1393. };
  1394. /**
  1395. *
  1396. */
  1397. EditorUi.prototype.uploadToImgur = function(file, base64Data, editable, socialHandler)
  1398. {
  1399. var resume = this.spinner.pause();
  1400. // Shows a warning dialog before uploading
  1401. var dlg = new ErrorDialog(this, mxResources.get('warning'),
  1402. '<img style="max-width:300px;max-height:80px;margin-bottom:20px;padding:6px;border:1px solid gray;" ' +
  1403. 'src="data:image/png;base64,' + base64Data + '"/><br>' +
  1404. mxResources.get('publishConfirmation'),
  1405. mxResources.get('cancel'), mxUtils.bind(this, function()
  1406. {
  1407. // Do nothing
  1408. }), null,
  1409. mxResources.get('publish'), mxUtils.bind(this, function()
  1410. {
  1411. resume();
  1412. var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1413. var dot = title.lastIndexOf('.');
  1414. var filename = title;
  1415. if (dot > 0)
  1416. {
  1417. title = filename.substring(0, dot);
  1418. filename = title;
  1419. }
  1420. filename += '.png';
  1421. // Indirection via servlet for billing and hiding secrets
  1422. var req = new mxXmlRequest('/imgur', JSON.stringify({type: 'base64', image: base64Data,
  1423. name: filename, title: title, description: 'Made with https://www.draw.io'}), 'POST');
  1424. var extractAndHandleError = mxUtils.bind(this, function(req)
  1425. {
  1426. var e = {message: mxResources.get('unknownError')};
  1427. try
  1428. {
  1429. var res = JSON.parse(req.getText());
  1430. e = {message: res.message || res.data.error};
  1431. }
  1432. catch (err)
  1433. {
  1434. // ignore
  1435. }
  1436. this.handleError(e);
  1437. });
  1438. // First request to upload image to Imgur
  1439. req.send(mxUtils.bind(this, function(req)
  1440. {
  1441. if (req.getStatus() == 200)
  1442. {
  1443. try
  1444. {
  1445. var res = JSON.parse(req.getText());
  1446. var viewUrl = 'https://www.draw.io/i/' + res.data.id;
  1447. // Logs publishing of diagrams
  1448. try
  1449. {
  1450. var img = new Image();
  1451. // Timestamp is added to bypass client-side cache
  1452. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  1453. img.src = logDomain + '/log?severity=CONFIG&msg=imgur-published:' + res.data.id + '&v=' +
  1454. encodeURIComponent(EditorUi.VERSION) + '&ts=' + new Date().getTime();
  1455. }
  1456. catch (e)
  1457. {
  1458. // ignore
  1459. }
  1460. var showResult = mxUtils.bind(this, function()
  1461. {
  1462. this.spinner.stop();
  1463. var url = 'https://imgur.com/' + res.data.id;
  1464. var deleteUrl = 'https://www.draw.io/imgur?delete=' + res.data.deletehash;
  1465. var dlg = new ErrorDialog(this, mxResources.get('published'),
  1466. ((editable) ? mxResources.get('viewUrl', ['<a href="' + viewUrl +
  1467. '" target="_blank">' + viewUrl + '</a>']) + '<br>' : '') +
  1468. mxResources.get('publishedAt', ['<a href="' + url + '" target="_blank">' + url + '</a>']) +
  1469. '<br>' + mxResources.get('deleteUrl', [deleteUrl]),
  1470. mxResources.get('close'), mxUtils.bind(this, function()
  1471. {
  1472. this.hideDialog();
  1473. }), null, mxResources.get('share'), function()
  1474. {
  1475. socialHandler(res.data.id, editable);
  1476. }, false);
  1477. this.showDialog(dlg.container, 340, 180, true, false);
  1478. dlg.init();
  1479. });
  1480. if (!editable)
  1481. {
  1482. showResult();
  1483. }
  1484. else
  1485. {
  1486. // Second request to update the description with the edit link
  1487. // Replacing the .png is workaround for Imgur to handle it as an image
  1488. // Avoiding URL parameter avoids call to getParameter in the servlet
  1489. var url2 = '/imgur?' + res.data.deletehash;
  1490. var req2 = new mxXmlRequest(url2, JSON.stringify({title: title,
  1491. description: mxResources.get('viewUrl', [viewUrl])}), 'POST');
  1492. req2.send(mxUtils.bind(this, function()
  1493. {
  1494. if (req2.getStatus() == 200)
  1495. {
  1496. showResult();
  1497. }
  1498. else
  1499. {
  1500. extractAndHandleError(req2);
  1501. }
  1502. }), mxUtils.bind(this, function()
  1503. {
  1504. extractAndHandleError(req2);
  1505. }));
  1506. }
  1507. }
  1508. catch (e)
  1509. {
  1510. this.handleError(e);
  1511. }
  1512. }
  1513. else
  1514. {
  1515. extractAndHandleError(req);
  1516. }
  1517. }), mxUtils.bind(this, function(req)
  1518. {
  1519. extractAndHandleError(req);
  1520. }));
  1521. }));
  1522. this.showDialog(dlg.container, 320, 250, true, false);
  1523. dlg.init();
  1524. };
  1525. /**
  1526. *
  1527. */
  1528. EditorUi.prototype.publishImage = function(handler, socialHandler)
  1529. {
  1530. var file = this.getCurrentFile();
  1531. if (file != null)
  1532. {
  1533. if (this.isExportToCanvas())
  1534. {
  1535. this.showExportDialog(false, mxResources.get('publish'), 'https://support.draw.io/pages/viewpage.action?pageId=12222625', mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  1536. {
  1537. var val = parseInt(scale);
  1538. if (!isNaN(val) && val > 0)
  1539. {
  1540. var scale = val / 100;
  1541. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  1542. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  1543. if (this.spinner.spin(document.body, mxResources.get('publishing')))
  1544. {
  1545. try
  1546. {
  1547. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1548. {
  1549. try
  1550. {
  1551. var xml = (editable) ? this.getFileData(true, null, null, null, ignoreSelection) : null;
  1552. var data = this.createPngDataUri(canvas, xml);
  1553. handler(file, data.substring(data.lastIndexOf(',') + 1), editable, socialHandler);
  1554. }
  1555. catch (e)
  1556. {
  1557. this.handleError(e);
  1558. }
  1559. }), null, null, null, mxUtils.bind(this, function(e)
  1560. {
  1561. this.handleError(e);
  1562. }), null, ignoreSelection, scale || 1, transparentBackground, addShadow);
  1563. }
  1564. catch (e)
  1565. {
  1566. this.handleError(e);
  1567. }
  1568. }
  1569. }
  1570. }));
  1571. }
  1572. else
  1573. {
  1574. this.showRemoteExportDialog(mxResources.get('publish'), 'https://support.draw.io/pages/viewpage.action?pageId=12222625', mxUtils.bind(this, function(ignoreSelection, editable)
  1575. {
  1576. if (this.spinner.spin(document.body, mxResources.get('publishing')))
  1577. {
  1578. var bounds = this.editor.graph.getGraphBounds();
  1579. var data = this.getFileData(true, null, null, null, ignoreSelection);
  1580. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  1581. {
  1582. var embed = (editable) ? '1' : '0';
  1583. try
  1584. {
  1585. var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
  1586. '&base64=1&embedXml=' + embed + '&xml=' +
  1587. encodeURIComponent(data));
  1588. req.send(mxUtils.bind(this, function()
  1589. {
  1590. if (req.getStatus() == 200)
  1591. {
  1592. handler(file, req.getText(), editable, socialHandler);
  1593. }
  1594. else
  1595. {
  1596. this.handleError(req);
  1597. }
  1598. }));
  1599. }
  1600. catch (e)
  1601. {
  1602. this.handleError(e);
  1603. }
  1604. }
  1605. else
  1606. {
  1607. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
  1608. }
  1609. }
  1610. }));
  1611. }
  1612. }
  1613. };
  1614. /**
  1615. * Translates this point by the given vector.
  1616. *
  1617. * @param {number} dx X-coordinate of the translation.
  1618. * @param {number} dy Y-coordinate of the translation.
  1619. */
  1620. EditorUi.prototype.timeSince = function(date)
  1621. {
  1622. var seconds = Math.floor((new Date() - date) / 1000);
  1623. var interval = Math.floor(seconds / 31536000);
  1624. if (interval > 1)
  1625. {
  1626. return interval + ' ' + mxResources.get('years');
  1627. }
  1628. interval = Math.floor(seconds / 2592000);
  1629. if (interval > 1)
  1630. {
  1631. return interval + ' ' + mxResources.get('months');
  1632. }
  1633. interval = Math.floor(seconds / 86400);
  1634. if (interval > 1)
  1635. {
  1636. return interval + ' ' + mxResources.get('days');
  1637. }
  1638. interval = Math.floor(seconds / 3600);
  1639. if (interval > 1)
  1640. {
  1641. return interval + ' ' + mxResources.get('hours');
  1642. }
  1643. interval = Math.floor(seconds / 60);
  1644. if (interval > 1)
  1645. {
  1646. return interval + ' ' + mxResources.get('minutes');
  1647. }
  1648. if (interval == 1)
  1649. {
  1650. return interval + ' ' + mxResources.get('minute');
  1651. }
  1652. return null;
  1653. };
  1654. /**
  1655. * Converts math in the given SVG
  1656. */
  1657. EditorUi.prototype.convertMath = function(graph, svgRoot, fixPosition, callback)
  1658. {
  1659. // FIXME: Only horizontal dash in output so better no conversion at all
  1660. if (false && graph.mathEnabled && typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  1661. {
  1662. // Workaround for lost gradients in Chrome after remove from DOM
  1663. var elts = svgRoot.getElementsByTagName('*');
  1664. for (var i = 0; i < elts.length; i++)
  1665. {
  1666. if (elts[i].getAttribute('id') != null)
  1667. {
  1668. elts[i].setAttribute('id', 'mxTemporaryPrefix-' + elts[i].getAttribute('id'));
  1669. }
  1670. }
  1671. // Temporarily attaches to DOM for rendering
  1672. svgRoot.style.visibility = 'hidden';
  1673. document.body.appendChild(svgRoot);
  1674. Editor.MathJaxRender(svgRoot);
  1675. MathJax.Hub.Queue(mxUtils.bind(this, function ()
  1676. {
  1677. // Removes from DOM
  1678. svgRoot.parentNode.removeChild(svgRoot);
  1679. svgRoot.style.visibility = '';
  1680. // Restores original IDs
  1681. for (var i = 0; i < elts.length; i++)
  1682. {
  1683. if (elts[i].getAttribute('id') != null)
  1684. {
  1685. elts[i].setAttribute('id', elts[i].getAttribute('id').substring('mxTemporaryPrefix-'.length));
  1686. }
  1687. }
  1688. // Keeping scale but moving translate only works for image export which
  1689. // is fine since we do not want the SVG export to contain a workaround.
  1690. // See https://github.com/mathjax/MathJax/issues/279
  1691. if (fixPosition && navigator.userAgent.indexOf('AppleWebKit/') >= 0)
  1692. {
  1693. var fo = svgRoot.getElementsByTagName('foreignObject');
  1694. for (var i = 0; i < fo.length; i++)
  1695. {
  1696. var tr = fo[i].parentNode.parentNode.getAttribute('transform');
  1697. var translate = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(tr);
  1698. fo[i].setAttribute('x', Math.round(translate[1]));
  1699. fo[i].setAttribute('y', Math.round(translate[2]));
  1700. // Must use translate for crisp rendering
  1701. fo[i].parentNode.parentNode.setAttribute('transform', 'translate(0.5,0.5)' + tr.substring(tr.indexOf(')') + 1));
  1702. }
  1703. }
  1704. callback();
  1705. }));
  1706. }
  1707. else
  1708. {
  1709. callback();
  1710. }
  1711. };
  1712. /**
  1713. * Returns the SVG of the diagram with embedded XML. If a callback function is
  1714. * used, the images are converted to data URIs.
  1715. */
  1716. EditorUi.prototype.getEmbeddedSvg = function(xml, graph, url, noHeader, callback, ignoreSelection, redirect)
  1717. {
  1718. var bg = null;
  1719. if (graph != null)
  1720. {
  1721. bg = graph.background;
  1722. if (bg == mxConstants.NONE)
  1723. {
  1724. bg = null;
  1725. }
  1726. }
  1727. // Sets or disables alternate text for foreignObjects. Disabling is needed
  1728. // because PhantomJS seems to ignore switch statements and paint all text.
  1729. var svgRoot = graph.getSvg(bg, null, null, null, null, ignoreSelection);
  1730. if (xml != null)
  1731. {
  1732. svgRoot.setAttribute('content', encodeURIComponent(xml));
  1733. }
  1734. if (url != null)
  1735. {
  1736. svgRoot.setAttribute('resource', url);
  1737. }
  1738. // LATER: Click on SVG content to start editing
  1739. // if (redirect != null)
  1740. // {
  1741. // // TODO: Ignore anchor tag source for click event
  1742. // svgRoot.setAttribute('style', 'cursor:pointer;');
  1743. // svgRoot.setAttribute('onclick', 'window.location.href=\'' + redirect + '\';');
  1744. // }
  1745. if (callback != null)
  1746. {
  1747. this.convertImages(svgRoot, mxUtils.bind(this, function(svgRoot)
  1748. {
  1749. callback(((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  1750. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  1751. mxUtils.getXml(svgRoot));
  1752. }));
  1753. }
  1754. else
  1755. {
  1756. return ((!noHeader) ? '<?xml version="1.0" encoding="UTF-8"?>\n' +
  1757. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' : '') +
  1758. mxUtils.getXml(svgRoot);
  1759. }
  1760. };
  1761. /**
  1762. *
  1763. */
  1764. EditorUi.prototype.exportToCanvas = function(callback, width, imageCache, background, error, limitHeight,
  1765. ignoreSelection, scale, transparentBackground, addShadow, converter, graph)
  1766. {
  1767. limitHeight = (limitHeight != null) ? limitHeight : true;
  1768. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1769. graph = (graph != null) ? graph : this.editor.graph;
  1770. var bg = (transparentBackground) ? null : graph.background;
  1771. if (bg == mxConstants.NONE)
  1772. {
  1773. bg = null;
  1774. }
  1775. if (bg == null)
  1776. {
  1777. bg = background;
  1778. }
  1779. // Handles special case where background is null but transparent is false
  1780. if (bg == null && transparentBackground == false)
  1781. {
  1782. bg = '#ffffff';
  1783. }
  1784. this.convertImages(graph.getSvg(bg, null, null, null, null, ignoreSelection), mxUtils.bind(this, function(svgRoot)
  1785. {
  1786. var img = new Image();
  1787. img.onload = mxUtils.bind(this, function()
  1788. {
  1789. var canvas = document.createElement('canvas');
  1790. var w = parseInt(svgRoot.getAttribute('width'));
  1791. var h = parseInt(svgRoot.getAttribute('height'));
  1792. scale = (scale != null) ? scale : 1;
  1793. if (width != null)
  1794. {
  1795. scale = (!limitHeight) ? width / w : Math.min(1, Math.min((width * 3) / (h * 4), width / w));
  1796. }
  1797. canvas.setAttribute('width', Math.ceil(scale * w));
  1798. canvas.setAttribute('height', Math.ceil(scale * h));
  1799. var ctx = canvas.getContext('2d');
  1800. ctx.scale(scale, scale);
  1801. ctx.drawImage(img, 0, 0);
  1802. callback(canvas);
  1803. });
  1804. img.onerror = function(e)
  1805. {
  1806. //console.log('img', e, img.src);
  1807. if (error != null)
  1808. {
  1809. error(e);
  1810. }
  1811. };
  1812. try
  1813. {
  1814. if (addShadow)
  1815. {
  1816. this.editor.addSvgShadow(svgRoot);
  1817. }
  1818. this.convertMath(graph, svgRoot, true, mxUtils.bind(this, function()
  1819. {
  1820. img.src = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  1821. }));
  1822. }
  1823. catch (e)
  1824. {
  1825. //console.log('src', e, img.src);
  1826. if (error != null)
  1827. {
  1828. error(e);
  1829. }
  1830. }
  1831. }), imageCache, converter);
  1832. };
  1833. /**
  1834. * Converts all images in the SVG output to data URIs for immediate rendering
  1835. */
  1836. EditorUi.prototype.createImageUrlConverter = function()
  1837. {
  1838. var converter = new mxUrlConverter();
  1839. converter.updateBaseUrl();
  1840. // Extends convert to avoid CORS using an image proxy server
  1841. // LATER: Use img.crossOrigin="anonymous" to avoid proxy
  1842. var convert = converter.convert;
  1843. converter.convert = function(src)
  1844. {
  1845. if (src != null)
  1846. {
  1847. if ((src.substring(0, 7) == 'http://' || src.substring(0, 8) == 'https://') &&
  1848. src.substring(0, converter.baseUrl.length) != converter.baseUrl)
  1849. {
  1850. src = PROXY_URL + '?url=' + encodeURIComponent(src);
  1851. }
  1852. else if (src.substring(0, 19) != 'chrome-extension://')
  1853. {
  1854. src = convert.apply(this, arguments);
  1855. }
  1856. }
  1857. return src;
  1858. };
  1859. return converter;
  1860. };
  1861. /**
  1862. * Converts all images in the SVG output to data URIs for immediate rendering
  1863. */
  1864. EditorUi.prototype.convertImages = function(svgRoot, callback, imageCache, converter)
  1865. {
  1866. // Converts images to data URLs for immediate painting
  1867. if (converter == null)
  1868. {
  1869. converter = this.createImageUrlConverter();
  1870. }
  1871. // Barrier for asynchronous image loading
  1872. var counter = 0;
  1873. function inc()
  1874. {
  1875. counter++;
  1876. };
  1877. function dec()
  1878. {
  1879. counter--;
  1880. if (counter == 0)
  1881. {
  1882. callback(svgRoot);
  1883. }
  1884. };
  1885. var cache = imageCache || new Object();
  1886. var convertImages = mxUtils.bind(this, function(tagName, srcAttr)
  1887. {
  1888. var images = svgRoot.getElementsByTagName(tagName);
  1889. for (var i = 0; i < images.length; i++)
  1890. {
  1891. (mxUtils.bind(this, function(img)
  1892. {
  1893. var src = converter.convert(img.getAttribute(srcAttr));
  1894. // Data URIs are pass-through
  1895. if (src != null && src.substring(0, 5) != 'data:')
  1896. {
  1897. var tmp = cache[src];
  1898. if (tmp == null)
  1899. {
  1900. inc();
  1901. this.convertImageToDataUri(src, function(uri)
  1902. {
  1903. if (uri != null)
  1904. {
  1905. cache[src] = uri;
  1906. img.setAttribute(srcAttr, uri);
  1907. }
  1908. dec();
  1909. });
  1910. }
  1911. else
  1912. {
  1913. img.setAttribute(srcAttr, tmp);
  1914. }
  1915. }
  1916. }))(images[i]);
  1917. }
  1918. });
  1919. // Converts all known image tags in output
  1920. // LATER: Add support for images in CSS
  1921. convertImages('image', 'xlink:href');
  1922. convertImages('img', 'src');
  1923. // All from cache or no images
  1924. if (counter == 0)
  1925. {
  1926. callback(svgRoot);
  1927. }
  1928. };
  1929. /**
  1930. * Translates this point by the given vector.
  1931. *
  1932. * @param {number} dx X-coordinate of the translation.
  1933. * @param {number} dy Y-coordinate of the translation.
  1934. */
  1935. EditorUi.prototype.convertImageToDataUri = function(url, callback)
  1936. {
  1937. if (/(\.svg)$/i.test(url))
  1938. {
  1939. mxUtils.get(url, mxUtils.bind(this, function(req)
  1940. {
  1941. callback(this.createSvgDataUri(req.getText()));
  1942. }),
  1943. function()
  1944. {
  1945. callback();
  1946. });
  1947. }
  1948. else
  1949. {
  1950. var img = new Image();
  1951. img.onload = function()
  1952. {
  1953. var canvas = document.createElement('canvas');
  1954. var ctx = canvas.getContext('2d');
  1955. canvas.height = img.height;
  1956. canvas.width = img.width;
  1957. ctx.drawImage(img, 0, 0);
  1958. callback(canvas.toDataURL());
  1959. };
  1960. img.onerror = function()
  1961. {
  1962. callback();
  1963. };
  1964. img.src = url;
  1965. }
  1966. };
  1967. /**
  1968. * Handling drag and drop and import.
  1969. */
  1970. /**
  1971. * Imports the given XML into the existing diagram.
  1972. */
  1973. EditorUi.prototype.importXml = function(xml, dx, dy, crop, noErrorHandling)
  1974. {
  1975. dx = (dx != null) ? dx : 0;
  1976. dy = (dy != null) ? dy : 0;
  1977. var cells = []
  1978. try
  1979. {
  1980. var graph = this.editor.graph;
  1981. if (xml != null && xml.length > 0)
  1982. {
  1983. var doc = mxUtils.parseXml(xml);
  1984. // Checks for mxfile with multiple pages
  1985. var node = this.editor.extractGraphModel(doc.documentElement, this.pages != null);
  1986. if (node != null && node.nodeName == 'mxfile' && this.pages != null)
  1987. {
  1988. var diagrams = node.getElementsByTagName('diagram');
  1989. if (diagrams.length == 1)
  1990. {
  1991. node = mxUtils.parseXml(graph.decompress(mxUtils.getTextContent(diagrams[0]))).documentElement;
  1992. }
  1993. else if (diagrams.length > 1)
  1994. {
  1995. // Adds pages
  1996. graph.model.beginUpdate();
  1997. try
  1998. {
  1999. for (var i = 0; i < diagrams.length; i++)
  2000. {
  2001. var page = this.updatePageRoot(new DiagramPage(diagrams[i]));
  2002. var index = this.pages.length;
  2003. // Checks for invalid page names
  2004. if (page.getName() == null)
  2005. {
  2006. page.setName(mxResources.get('pageWithNumber', [index + 1]));
  2007. }
  2008. graph.model.execute(new ChangePage(this, page, page, index));
  2009. }
  2010. }
  2011. finally
  2012. {
  2013. graph.model.endUpdate();
  2014. }
  2015. }
  2016. }
  2017. if (node != null && node.nodeName === 'mxGraphModel')
  2018. {
  2019. var model = new mxGraphModel();
  2020. var codec = new mxCodec(node.ownerDocument);
  2021. codec.decode(node, model);
  2022. var childCount = model.getChildCount(model.getRoot());
  2023. var targetChildCount = graph.model.getChildCount(graph.model.getRoot());
  2024. // Merges into active layer if one layer is pasted
  2025. graph.model.beginUpdate();
  2026. try
  2027. {
  2028. // Mapping for multiple calls to cloneCells with the same set of cells
  2029. var mapping = new Object();
  2030. for (var i = 0; i < childCount; i++)
  2031. {
  2032. var parent = model.getChildAt(model.getRoot(), i);
  2033. // Adds cells to existing layer if not locked
  2034. if (childCount == 1 && !graph.isCellLocked(graph.getDefaultParent()))
  2035. {
  2036. var children = model.getChildren(parent);
  2037. cells = cells.concat(graph.importCells(children, dx, dy, graph.getDefaultParent(), null, mapping));
  2038. }
  2039. else
  2040. {
  2041. // Delta is non cascading, needs separate move for layers
  2042. parent = graph.importCells([parent], 0, 0, graph.model.getRoot(), null, mapping)[0];
  2043. var children = graph.model.getChildren(parent);
  2044. graph.moveCells(children, dx, dy);
  2045. cells = cells.concat(children);
  2046. }
  2047. }
  2048. if (crop)
  2049. {
  2050. if (graph.isGridEnabled())
  2051. {
  2052. dx = graph.snap(dx);
  2053. dy = graph.snap(dy);
  2054. }
  2055. var bounds = graph.getBoundingBoxFromGeometry(cells, true);
  2056. if (bounds != null)
  2057. {
  2058. graph.moveCells(cells, dx - bounds.x, dy - bounds.y);
  2059. }
  2060. }
  2061. }
  2062. finally
  2063. {
  2064. graph.model.endUpdate();
  2065. }
  2066. }
  2067. }
  2068. }
  2069. catch (e)
  2070. {
  2071. if (!noErrorHandling)
  2072. {
  2073. this.handleError(e, mxResources.get('invalidOrMissingFile'));
  2074. }
  2075. throw e;
  2076. }
  2077. return cells;
  2078. };
  2079. /**
  2080. * Imports the given XML into the existing diagram.
  2081. * TODO: Make this function asynchronous
  2082. */
  2083. EditorUi.prototype.insertTextAt = function(text, dx, dy, html, asImage, crop)
  2084. {
  2085. crop = (crop != null) ? crop : true;
  2086. // Handles special case for Gliffy data which requires async server-side for parsing
  2087. if (text != null)
  2088. {
  2089. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(text))
  2090. {
  2091. // Fixes possible parsing problems with ASCII 160 (non-breaking space)
  2092. this.parseFile(new Blob([text.replace(/\s+/g,' ')], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2093. {
  2094. if (xhr.readyState == 4 && xhr.status == 200)
  2095. {
  2096. this.editor.graph.setSelectionCells(this.insertTextAt(xhr.responseText, dx, dy, true));
  2097. }
  2098. }));
  2099. // Returns empty cells array as it is aysynchronous
  2100. return [];
  2101. }
  2102. // Handles special case of data URI which requires async loading for finding size
  2103. else if (!this.isOffline() && (asImage || text.substring(0, 5) == 'data:' || (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(text)))
  2104. {
  2105. var graph = this.editor.graph;
  2106. // Checks for embedded XML in PNG
  2107. if (text.substring(0, 22) == 'data:image/png;base64,')
  2108. {
  2109. var xml = this.extractGraphModelFromPng(text);
  2110. var result = this.importXml(xml, dx, dy, crop, true);
  2111. if (result.length > 0)
  2112. {
  2113. return result;
  2114. }
  2115. }
  2116. // Tries to extract embedded XML from SVG data URI
  2117. if (text.substring(0, 19) == 'data:image/svg+xml;')
  2118. {
  2119. try
  2120. {
  2121. var xml = null;
  2122. if (text.substring(0, 26) == 'data:image/svg+xml;base64,')
  2123. {
  2124. xml = text.substring(text.indexOf(',') + 1);
  2125. xml = (window.atob && !mxClient.IS_SF) ? atob(xml) : Base64.decode(xml, true);
  2126. }
  2127. else
  2128. {
  2129. xml = decodeURIComponent(text.substring(text.indexOf(',') + 1));
  2130. }
  2131. var result = this.importXml(xml, dx, dy, crop, true);
  2132. if (result.length > 0)
  2133. {
  2134. return result;
  2135. }
  2136. }
  2137. catch (e)
  2138. {
  2139. // Ignore
  2140. }
  2141. }
  2142. this.loadImage(text, mxUtils.bind(this, function(img)
  2143. {
  2144. if (text.substring(0, 5) == 'data:')
  2145. {
  2146. this.resizeImage(img, text, mxUtils.bind(this, function(data2, w2, h2)
  2147. {
  2148. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  2149. w2, h2, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2150. 'verticalAlign=top;aspect=fixed;image=' + this.convertDataUri(data2) + ';'));
  2151. }), true, this.maxImageSize);
  2152. }
  2153. else
  2154. {
  2155. var s = Math.min(1, Math.min(this.maxImageSize / img.width, this.maxImageSize / img.height));
  2156. var w = Math.round(img.width * s);
  2157. var h = Math.round(img.height * s);
  2158. graph.setSelectionCell(graph.insertVertex(null, null, '', graph.snap(dx), graph.snap(dy),
  2159. w, h, 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2160. 'verticalAlign=top;aspect=fixed;image=' + text + ';'));
  2161. }
  2162. }), mxUtils.bind(this, function()
  2163. {
  2164. var cell = null;
  2165. // Inserts invalid data URIs as text
  2166. graph.getModel().beginUpdate();
  2167. try
  2168. {
  2169. cell = graph.insertVertex(graph.getDefaultParent(), null, text,
  2170. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  2171. graph.updateCellSize(cell);
  2172. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  2173. }
  2174. finally
  2175. {
  2176. graph.getModel().endUpdate();
  2177. }
  2178. graph.setSelectionCell(cell);
  2179. }));
  2180. return [];
  2181. }
  2182. else
  2183. {
  2184. text = this.editor.graph.zapGremlins(mxUtils.trim(text));
  2185. if (this.isCompatibleString(text))
  2186. {
  2187. return this.importXml(text, dx, dy, crop);
  2188. }
  2189. else if (text.length > 0)
  2190. {
  2191. var graph = this.editor.graph;
  2192. var cell = null;
  2193. graph.getModel().beginUpdate();
  2194. try
  2195. {
  2196. // Fires cellsInserted to apply the current style to the inserted text.
  2197. // This requires the value to be empty when the event is fired.
  2198. cell = graph.insertVertex(graph.getDefaultParent(), null, '',
  2199. graph.snap(dx), graph.snap(dy), 1, 1, 'text;' + ((html) ? 'html=1;' : ''));
  2200. graph.fireEvent(new mxEventObject('textInserted', 'cells', [cell]));
  2201. // Apply value and updates the cell size to fit the text block
  2202. cell.value = text;
  2203. graph.updateCellSize(cell);
  2204. // See http://stackoverflow.com/questions/6927719/url-regex-does-not-work-in-javascript
  2205. 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;
  2206. if (regexp.test(cell.value))
  2207. {
  2208. graph.setLinkForCell(cell, cell.value);
  2209. }
  2210. // Adds spacing
  2211. cell.geometry.width += graph.gridSize;
  2212. cell.geometry.height += graph.gridSize;
  2213. }
  2214. finally
  2215. {
  2216. graph.getModel().endUpdate();
  2217. }
  2218. return [cell];
  2219. }
  2220. }
  2221. }
  2222. return [];
  2223. };
  2224. /**
  2225. * Formats the given file size.
  2226. */
  2227. EditorUi.prototype.formatFileSize = function(size)
  2228. {
  2229. var units = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
  2230. var i = -1;
  2231. do
  2232. {
  2233. size = size / 1024;
  2234. i++;
  2235. } while (size > 1024);
  2236. return Math.max(size, 0.1).toFixed(1) + units[i];
  2237. };
  2238. /**
  2239. * Imports the given XML into the existing diagram.
  2240. */
  2241. EditorUi.prototype.convertDataUri = function(uri)
  2242. {
  2243. // Handles special case of data URI which needs to be rewritten
  2244. // to be used in a cell style to remove the semicolon
  2245. if (uri.substring(0, 5) == 'data:')
  2246. {
  2247. var semi = uri.indexOf(';');
  2248. if (semi > 0)
  2249. {
  2250. uri = uri.substring(0, semi) + uri.substring(uri.indexOf(',', semi + 1));
  2251. }
  2252. }
  2253. return uri;
  2254. };
  2255. /**
  2256. * Returns true for Gliffy or GraphML data or .vsdx filenames.
  2257. */
  2258. EditorUi.prototype.isRemoteFileFormat = function(data, filename)
  2259. {
  2260. return /(\.*<graphml xmlns=\".*)/.test(data) ||
  2261. /(\"contentType\":\s*\"application\/gliffy\+json\")/.test(data) ||
  2262. (filename != null && /(\.vsdx)($|\?)/i.test(filename));
  2263. };
  2264. /**
  2265. * Imports the given XML into the existing diagram.
  2266. */
  2267. EditorUi.prototype.importFile = function(data, mimeType, dx, dy, w, h, filename, done, file, crop)
  2268. {
  2269. crop = (crop != null) ? crop : true;
  2270. var async = false;
  2271. var cells = null;
  2272. if (mimeType.substring(0, 5) == 'image')
  2273. {
  2274. var containsModel = false;
  2275. if (mimeType.substring(0, 9) == 'image/png')
  2276. {
  2277. var xml = this.extractGraphModelFromPng(data);
  2278. if (xml != null && xml.length > 0)
  2279. {
  2280. cells = this.importXml(xml, dx, dy, crop);
  2281. containsModel = true;
  2282. }
  2283. }
  2284. if (!containsModel)
  2285. {
  2286. var graph = this.editor.graph;
  2287. // Strips encoding bit (eg. ;base64,) for cell style
  2288. var semi = data.indexOf(';');
  2289. if (semi > 0)
  2290. {
  2291. data = data.substring(0, semi) + data.substring(data.indexOf(',', semi + 1));
  2292. }
  2293. if (crop && graph.isGridEnabled())
  2294. {
  2295. dx = graph.snap(dx);
  2296. dy = graph.snap(dy);
  2297. }
  2298. cells = [graph.insertVertex(null, null, '', dx, dy, w, h,
  2299. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  2300. 'verticalAlign=top;aspect=fixed;image=' + data + ';')];
  2301. }
  2302. }
  2303. else if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, filename))
  2304. {
  2305. // LATER: done and async are a hack before making this asynchronous
  2306. async = true;
  2307. // Returns empty cells array as it is aysynchronous
  2308. this.parseFile((file != null) ? file : new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2309. {
  2310. if (xhr.readyState == 4)
  2311. {
  2312. var importedCells = null;
  2313. if (xhr.status == 200)
  2314. {
  2315. importedCells = this.importXml(xhr.responseText, dx, dy, crop);
  2316. }
  2317. if (done != null)
  2318. {
  2319. done(importedCells);
  2320. }
  2321. }
  2322. }), filename);
  2323. }
  2324. else
  2325. {
  2326. if (/(\.vsdx)($|\?)/i.test(filename))
  2327. {
  2328. var vsdxModel = new mxVsdxModel();
  2329. vsdxModel.decode(file);
  2330. }
  2331. else
  2332. {
  2333. cells = this.insertTextAt(this.validateFileData(data), dx, dy, true);
  2334. }
  2335. // else if (String.prototype.trim)
  2336. // {
  2337. // var trimmed = data.trim();
  2338. //
  2339. // if (trimmed.substring(0, 6) == 'strict ' || trimmed.substring(0, 5) == 'graph' || trimmed.substring(0, 7) == 'digraph')
  2340. // {
  2341. // // GraphViz dot format http://www.graphviz.org/content/dot-language
  2342. // //var digraph = graphlibDot.read("digraph { 1; 2; 1 -> 2 [label=\"label\"] }");
  2343. // }
  2344. // }
  2345. }
  2346. if (!async && done != null)
  2347. {
  2348. done(cells);
  2349. }
  2350. return cells;
  2351. };
  2352. /**
  2353. * Base64 encodes the given string. This method seems to be more
  2354. * robust for encoding PNG from binary AJAX responses.
  2355. */
  2356. EditorUi.prototype.base64Encode = function(str)
  2357. {
  2358. var CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2359. var out = "", i = 0, len = str.length, c1, c2, c3;
  2360. while (i < len)
  2361. {
  2362. c1 = str.charCodeAt(i++) & 0xff;
  2363. if (i == len)
  2364. {
  2365. out += CHARS.charAt(c1 >> 2);
  2366. out += CHARS.charAt((c1 & 0x3) << 4);
  2367. out += "==";
  2368. break;
  2369. }
  2370. c2 = str.charCodeAt(i++);
  2371. if (i == len)
  2372. {
  2373. out += CHARS.charAt(c1 >> 2);
  2374. out += CHARS.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  2375. out += CHARS.charAt((c2 & 0xF) << 2);
  2376. out += "=";
  2377. break;
  2378. }
  2379. c3 = str.charCodeAt(i++);
  2380. out += CHARS.charAt(c1 >> 2);
  2381. out += CHARS.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  2382. out += CHARS.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  2383. out += CHARS.charAt(c3 & 0x3F);
  2384. }
  2385. return out;
  2386. };
  2387. /**
  2388. *
  2389. */
  2390. EditorUi.prototype.importFiles = function(files, x, y, maxSize, fn, resultFn, filterFn, barrierFn, resizeImages, maxBytes, resampleThreshold)
  2391. {
  2392. var crop = x != null && y != null;
  2393. x = (x != null) ? x : 0;
  2394. y = (y != null) ? y : 0;
  2395. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  2396. maxBytes = (maxBytes != null) ? maxBytes : this.maxImageBytes;
  2397. resizeImages = (resizeImages != null) ? resizeImages : true;
  2398. var graph = this.editor.graph;
  2399. var gs = graph.gridSize;
  2400. fn = (fn != null) ? fn : mxUtils.bind(this, function(data, mimeType, x, y, w, h, filename, done, file)
  2401. {
  2402. if (data != null && data.substring(0, 10) == '<mxlibrary')
  2403. {
  2404. this.spinner.stop();
  2405. this.loadLibrary(new LocalLibrary(this, data, filename));
  2406. return null;
  2407. }
  2408. else
  2409. {
  2410. return this.importFile(data, mimeType, x, y, w, h, filename, done, file, crop);
  2411. }
  2412. });
  2413. resultFn = (resultFn != null) ? resultFn : mxUtils.bind(this, function(cells)
  2414. {
  2415. graph.setSelectionCells(cells);
  2416. });
  2417. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2418. {
  2419. var count = files.length;
  2420. var remain = count;
  2421. var queue = [];
  2422. // Barrier waits for all files to be loaded asynchronously
  2423. var barrier = mxUtils.bind(this, function(index, fnc)
  2424. {
  2425. queue[index] = fnc;
  2426. if (--remain == 0)
  2427. {
  2428. this.spinner.stop();
  2429. if (barrierFn != null)
  2430. {
  2431. barrierFn(queue);
  2432. }
  2433. else
  2434. {
  2435. var cells = [];
  2436. graph.getModel().beginUpdate();
  2437. try
  2438. {
  2439. for (var j = 0; j < queue.length; j++)
  2440. {
  2441. var tmp = queue[j]();
  2442. if (tmp != null)
  2443. {
  2444. cells = cells.concat(tmp);
  2445. }
  2446. }
  2447. }
  2448. finally
  2449. {
  2450. graph.getModel().endUpdate();
  2451. }
  2452. }
  2453. resultFn(cells);
  2454. }
  2455. });
  2456. for (var i = 0; i < count; i++)
  2457. {
  2458. (mxUtils.bind(this, function(index)
  2459. {
  2460. var file = files[index];
  2461. var reader = new FileReader();
  2462. reader.onload = mxUtils.bind(this, function(e)
  2463. {
  2464. if (filterFn == null || filterFn(file))
  2465. {
  2466. if (file.type.substring(0, 6) == 'image/')
  2467. {
  2468. if (file.type.substring(0, 9) == 'image/svg')
  2469. {
  2470. // Checks if SVG contains content attribute
  2471. var data = e.target.result;
  2472. var comma = data.indexOf(',');
  2473. var svgText = atob(data.substring(comma + 1));
  2474. var root = mxUtils.parseXml(svgText);
  2475. var svgs = root.getElementsByTagName('svg');
  2476. if (svgs.length > 0)
  2477. {
  2478. var svgRoot = svgs[0];
  2479. var cont = svgRoot.getAttribute('content');
  2480. if (cont != null && cont.charAt(0) != '<' && cont.charAt(0) != '%')
  2481. {
  2482. cont = unescape((window.atob) ? atob(cont) : Base64.decode(cont, true));
  2483. }
  2484. if (cont != null && cont.charAt(0) == '%')
  2485. {
  2486. cont = decodeURIComponent(cont);
  2487. }
  2488. if (cont != null && (cont.substring(0, 8) === '<mxfile ' ||
  2489. cont.substring(0, 14) === '<mxGraphModel '))
  2490. {
  2491. barrier(index, mxUtils.bind(this, function()
  2492. {
  2493. return fn(cont, 'text/xml', x + index * gs, y + index * gs, 0, 0, file.name);
  2494. }));
  2495. }
  2496. else
  2497. {
  2498. // SVG needs special handling to add viewbox if missing and
  2499. // find initial size from SVG attributes (only for IE11)
  2500. barrier(index, mxUtils.bind(this, function()
  2501. {
  2502. try
  2503. {
  2504. var prefix = data.substring(0, comma + 1);
  2505. // Parses SVG and find width and height
  2506. if (root != null)
  2507. {
  2508. var svgs = root.getElementsByTagName('svg');
  2509. if (svgs.length > 0)
  2510. {
  2511. var svgRoot = svgs[0];
  2512. var w = parseFloat(svgRoot.getAttribute('width'));
  2513. var h = parseFloat(svgRoot.getAttribute('height'));
  2514. // Check if viewBox attribute already exists
  2515. var vb = svgRoot.getAttribute('viewBox');
  2516. if (vb == null || vb.length == 0)
  2517. {
  2518. svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
  2519. }
  2520. // Uses width and height from viewbox for
  2521. // missing width and height attributes
  2522. else if (isNaN(w) || isNaN(h))
  2523. {
  2524. var tokens = vb.split(' ');
  2525. if (tokens.length > 3)
  2526. {
  2527. w = parseFloat(tokens[2]);
  2528. h = parseFloat(tokens[3]);
  2529. }
  2530. }
  2531. data = this.createSvgDataUri(mxUtils.getXml(svgs[0]));
  2532. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  2533. return fn(data, file.type, x + index * gs, y + index * gs,
  2534. Math.max(1, Math.round(w * s)), Math.max(1, Math.round(h * s)), file.name);
  2535. }
  2536. }
  2537. }
  2538. catch (e)
  2539. {
  2540. // ignores any SVG parsing errors
  2541. }
  2542. return null;
  2543. }));
  2544. }
  2545. }
  2546. }
  2547. else
  2548. {
  2549. // Checks if PNG+XML is available to bypass code below
  2550. var containsModel = false;
  2551. if (file.type == 'image/png')
  2552. {
  2553. var xml = this.extractGraphModelFromPng(e.target.result);
  2554. if (xml != null && xml.length > 0)
  2555. {
  2556. var img = new Image();
  2557. img.src = e.target.result;
  2558. barrier(index, mxUtils.bind(this, function()
  2559. {
  2560. return fn(xml, 'text/xml', x + index * gs, y + index * gs,
  2561. img.width, img.height, file.name);
  2562. }));
  2563. containsModel = true;
  2564. }
  2565. }
  2566. // Additional asynchronous step for finding image size
  2567. if (!containsModel)
  2568. {
  2569. // Cannot load local files in Chrome App
  2570. if (window.chrome != null && chrome.app != null && chrome.app.runtime != null)
  2571. {
  2572. this.spinner.stop();
  2573. this.showError(mxResources.get('error'), mxResources.get('dragAndDropNotSupported'),
  2574. mxResources.get('cancel'), mxUtils.bind(this, function()
  2575. {
  2576. // Hides the dialog
  2577. }), null, mxResources.get('ok'), mxUtils.bind(this, function()
  2578. {
  2579. // Redirects to import function
  2580. this.actions.get('import').funct();
  2581. })
  2582. );
  2583. }
  2584. else
  2585. {
  2586. this.loadImage(e.target.result, mxUtils.bind(this, function(img)
  2587. {
  2588. this.resizeImage(img, e.target.result, mxUtils.bind(this, function(data2, w2, h2)
  2589. {
  2590. barrier(index, mxUtils.bind(this, function()
  2591. {
  2592. // Refuses to insert images above a certain size as they kill the app
  2593. if (data2 != null && data2.length < maxBytes)
  2594. {
  2595. var s = (!resizeImages || !this.isResampleImage(e.target.result)) ? 1 : Math.min(1, Math.min(maxSize / w2, maxSize / h2));
  2596. return fn(data2, file.type, x + index * gs, y + index * gs, Math.round(w2 * s), Math.round(h2 * s), file.name);
  2597. }
  2598. else
  2599. {
  2600. this.handleError({message: mxResources.get('imageTooBig')});
  2601. return null;
  2602. }
  2603. }));
  2604. }), resizeImages, maxSize, resampleThreshold);
  2605. }));
  2606. }
  2607. }
  2608. }
  2609. }
  2610. else
  2611. {
  2612. fn(e.target.result, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  2613. {
  2614. barrier(index, function()
  2615. {
  2616. return cells;
  2617. });
  2618. });
  2619. }
  2620. }
  2621. });
  2622. // Handles special case of binary file where the reader should not be used
  2623. if (/(\.vsdx)($|\?)/i.test(file.name))
  2624. {
  2625. fn(null, file.type, x + index * gs, y + index * gs, 240, 160, file.name, function(cells)
  2626. {
  2627. barrier(index, function()
  2628. {
  2629. return cells;
  2630. });
  2631. }, file);
  2632. }
  2633. else if (file.type.substring(0, 5) == 'image')
  2634. {
  2635. reader.readAsDataURL(file);
  2636. }
  2637. else
  2638. {
  2639. reader.readAsText(file);
  2640. }
  2641. }))(i);
  2642. }
  2643. }
  2644. };
  2645. /**
  2646. * Parses the file using XHR2 via the server. File can be a blob or file object.
  2647. * Filename is an optional parameter for blobs (that do not have a filename).
  2648. */
  2649. EditorUi.prototype.parseFile = function(file, fn, filename)
  2650. {
  2651. filename = (filename != null) ? filename : file.name;
  2652. var formData = new FormData();
  2653. formData.append('format', 'xml');
  2654. formData.append('upfile', file, filename);
  2655. var xhr = new XMLHttpRequest();
  2656. xhr.open('POST', OPEN_URL);
  2657. xhr.onreadystatechange = function()
  2658. {
  2659. fn(xhr);
  2660. };
  2661. xhr.send(formData);
  2662. };
  2663. /**
  2664. *
  2665. */
  2666. EditorUi.prototype.isResampleImage = function(data, thresh)
  2667. {
  2668. thresh = (thresh != null) ? thresh : this.resampleThreshold;
  2669. return data.length > thresh;
  2670. };
  2671. /**
  2672. * Resizes the given image if <maxImageBytes> is not null.
  2673. */
  2674. EditorUi.prototype.resizeImage = function(img, data, fn, enabled, maxSize, thresh)
  2675. {
  2676. maxSize = (maxSize != null) ? maxSize : this.maxImageSize;
  2677. var w = Math.max(1, img.width);
  2678. var h = Math.max(1, img.height);
  2679. if (enabled && this.isResampleImage(data, thresh))
  2680. {
  2681. try
  2682. {
  2683. var factor = Math.max(w / maxSize, h / maxSize);
  2684. if (factor > 1)
  2685. {
  2686. var w2 = Math.round(w / factor);
  2687. var h2 = Math.round(h / factor);
  2688. var canvas = document.createElement('canvas');
  2689. canvas.width = w2;
  2690. canvas.height = h2;
  2691. var ctx = canvas.getContext('2d');
  2692. ctx.drawImage(img, 0, 0, w2, h2);
  2693. var tmp = canvas.toDataURL();
  2694. // Uses new image if smaller
  2695. if (tmp.length < data.length)
  2696. {
  2697. // Checks if the image is empty by comparing
  2698. // with an empty image of the same size
  2699. var canvas2 = document.createElement('canvas');
  2700. canvas2.width = w2;
  2701. canvas2.height = h2;
  2702. var tmp2 = canvas2.toDataURL();
  2703. if (tmp !== tmp2)
  2704. {
  2705. data = tmp;
  2706. w = w2;
  2707. h = h2;
  2708. }
  2709. }
  2710. }
  2711. }
  2712. catch (e)
  2713. {
  2714. // ignores image scaling errors
  2715. }
  2716. }
  2717. fn(data, w, h);
  2718. };
  2719. /**
  2720. * Initializes CRC table.
  2721. */
  2722. (function()
  2723. {
  2724. EditorUi.prototype.crcTable = [];
  2725. for (var n = 0; n < 256; n++)
  2726. {
  2727. var c = n;
  2728. for (var k = 0; k < 8; k++)
  2729. {
  2730. if ((c & 1) == 1)
  2731. {
  2732. c = 0xedb88320 ^ (c >>> 1);
  2733. }
  2734. else
  2735. {
  2736. c >>>= 1;
  2737. }
  2738. EditorUi.prototype.crcTable[n] = c;
  2739. }
  2740. }
  2741. EditorUi.prototype.updateCRC = function(crc, data, off, len)
  2742. {
  2743. var c = crc;
  2744. for (var n = 0; n < len; n++)
  2745. {
  2746. c = EditorUi.prototype.crcTable[(c ^ data[off + n]) & 0xff] ^ (c >>> 8);
  2747. }
  2748. return c;
  2749. };
  2750. })();
  2751. /**
  2752. * Adds the given text to the compressed or non-compressed text chunk.
  2753. */
  2754. EditorUi.prototype.writeGraphModelToPng = function(data, type, key, value, error)
  2755. {
  2756. var base64 = data.substring(data.indexOf(',') + 1);
  2757. var f = (window.atob) ? atob(base64) : Base64.decode(base64, true);
  2758. var pos = 0;
  2759. function fread(d, count)
  2760. {
  2761. var start = pos;
  2762. pos += count;
  2763. return d.substring(start, pos);
  2764. };
  2765. // Reads unsigned long 32 bit big endian
  2766. function _freadint(d)
  2767. {
  2768. var bytes = fread(d, 4);
  2769. return bytes.charCodeAt(3) + (bytes.charCodeAt(2) << 8) +
  2770. (bytes.charCodeAt(1) << 16) + (bytes.charCodeAt(0) << 24);
  2771. };
  2772. function writeInt(num)
  2773. {
  2774. return String.fromCharCode((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff,
  2775. (num >> 8) & 0x000000ff, num & 0x000000ff);
  2776. };
  2777. // Checks signature
  2778. if (fread(f,8) != String.fromCharCode(137) + 'PNG' + String.fromCharCode(13, 10, 26, 10))
  2779. {
  2780. if (error != null)
  2781. {
  2782. error();
  2783. }
  2784. return;
  2785. }
  2786. // Reads header chunk
  2787. fread(f,4);
  2788. if (fread(f,4) != 'IHDR')
  2789. {
  2790. if (error != null)
  2791. {
  2792. error();
  2793. }
  2794. return;
  2795. }
  2796. fread(f, 17);
  2797. var result = f.substring(0, pos);
  2798. do
  2799. {
  2800. var n = _freadint(f);
  2801. var chunk = fread(f,4);
  2802. if (chunk == 'IDAT')
  2803. {
  2804. result = f.substring(0, pos - 8);
  2805. var crc = 0xffffffff;
  2806. crc = this.updateCRC(crc, type, 0, 4);
  2807. crc = this.updateCRC(crc, value, 0, value.length);
  2808. result += writeInt(key.length + value.length + 1 + ((type == 'zTXt') ? 1 : 0)) +
  2809. type + key + String.fromCharCode(0) +
  2810. ((type == 'zTXt') ? String.fromCharCode(0) : '') +
  2811. value + writeInt(crc ^ 0xffffffff);
  2812. result += f.substring(pos - 8, f.length);
  2813. break;
  2814. }
  2815. result += f.substring(pos - 8, pos - 4 + n);
  2816. value = fread(f,n);
  2817. fread(f,4);
  2818. }
  2819. while (n);
  2820. return 'data:image/png;base64,' + ((window.btoa) ? btoa(result) : Base64.encode(result, true));
  2821. }
  2822. /**
  2823. * Extracts the XML from the compressed or non-compressed text chunk.
  2824. */
  2825. EditorUi.prototype.extractGraphModelFromPng = function(data)
  2826. {
  2827. var result = null;
  2828. try
  2829. {
  2830. var base64 = data.substring(data.indexOf(',') + 1);
  2831. // Workaround for invalid character error in Safari
  2832. var binary = (window.atob && !mxClient.IS_SF) ? atob(base64) : Base64.decode(base64, true);
  2833. EditorUi.parsePng(binary, mxUtils.bind(this, function(pos, type, length)
  2834. {
  2835. var value = binary.substring(pos + 8, pos + 8 + length);
  2836. if (type == 'zTXt')
  2837. {
  2838. var idx = value.indexOf(String.fromCharCode(0));
  2839. if (value.substring(0, idx) == 'mxGraphModel')
  2840. {
  2841. // Workaround for Java URL Encoder using + for spaces, which isn't compatible with JS
  2842. var xmlData = this.editor.graph.bytesToString(pako.inflateRaw(
  2843. value.substring(idx + 2))).replace(/\+/g,' ');
  2844. if (xmlData != null && xmlData.length > 0)
  2845. {
  2846. result = xmlData;
  2847. }
  2848. }
  2849. }
  2850. // Uncompressed section is normally not used
  2851. else if (type == 'tEXt')
  2852. {
  2853. var vals = value.split(String.fromCharCode(0));
  2854. if (vals.length > 1 && vals[0] == 'mxGraphModel')
  2855. {
  2856. result = vals[1];
  2857. }
  2858. }
  2859. if (result != null || type == 'IDAT')
  2860. {
  2861. // Stops processing the file as our text chunks
  2862. // are always placed before the data section
  2863. return true;
  2864. }
  2865. }));
  2866. }
  2867. catch (e)
  2868. {
  2869. // ignores decoding errors
  2870. }
  2871. if (result != null && result.charAt(0) == '%')
  2872. {
  2873. result = decodeURIComponent(result);
  2874. }
  2875. // Workaround for double encoded content
  2876. if (result != null && result.charAt(0) == '%')
  2877. {
  2878. result = decodeURIComponent(result);
  2879. }
  2880. return result;
  2881. };
  2882. /**
  2883. * Loads the image from the given URI.
  2884. *
  2885. * @param {number} dx X-coordinate of the translation.
  2886. * @param {number} dy Y-coordinate of the translation.
  2887. */
  2888. EditorUi.prototype.loadImage = function(uri, onload, onerror)
  2889. {
  2890. var img = new Image();
  2891. img.onload = function()
  2892. {
  2893. onload(img);
  2894. }
  2895. if (onerror != null)
  2896. {
  2897. img.onerror = onerror;
  2898. }
  2899. img.src = uri;
  2900. };
  2901. // Initializes the user interface
  2902. var editorUiInit = EditorUi.prototype.init;
  2903. EditorUi.prototype.init = function()
  2904. {
  2905. editorUiInit.apply(this, arguments);
  2906. var graph = this.editor.graph;
  2907. var ui = this;
  2908. if (mxClient.IS_SVG)
  2909. {
  2910. // LATER: Add shadow for labels in graph.container (eg. math, NO_FO), scaling
  2911. this.editor.addSvgShadow(graph.view.canvas.ownerSVGElement, null, true);
  2912. }
  2913. /**
  2914. * Specifies the default filename.
  2915. */
  2916. this.defaultFilename = mxResources.get('untitledDiagram');
  2917. /**
  2918. * Adds placeholder for %page% and %pagenumber%
  2919. */
  2920. var graphGetGlobalVariable = graph.getGlobalVariable;
  2921. graph.getGlobalVariable = function(name)
  2922. {
  2923. if (name == 'page' && ui.currentPage != null)
  2924. {
  2925. return ui.currentPage.getName();
  2926. }
  2927. else if (name == 'pagenumber')
  2928. {
  2929. if (ui.currentPage != null && ui.pages != null)
  2930. {
  2931. return mxUtils.indexOf(ui.pages, ui.currentPage) + 1;
  2932. }
  2933. else
  2934. {
  2935. return 1;
  2936. }
  2937. }
  2938. return graphGetGlobalVariable.apply(this, arguments);
  2939. };
  2940. /**
  2941. * Overrides editor filename.
  2942. */
  2943. this.editor.getOrCreateFilename = function()
  2944. {
  2945. var filename = ui.defaultFilename;
  2946. var file = ui.getCurrentFile();
  2947. if (file != null)
  2948. {
  2949. filename = (file.getTitle() != null) ? file.getTitle() : filename;
  2950. }
  2951. return filename;
  2952. };
  2953. // Disables print action for standalone apps on iOS
  2954. // because there is no way to close the new window
  2955. // LATER: Use iframe for print, disable preview
  2956. var printAction = this.actions.get('print');
  2957. printAction.setEnabled(!mxClient.IS_IOS || !navigator.standalone);
  2958. printAction.visible = printAction.isEnabled();
  2959. // Scales pages/graph to fit available size
  2960. if (!this.editor.chromeless)
  2961. {
  2962. // Defines additional hotkeys
  2963. this.keyHandler.bindAction(67, true, 'copyStyle', true); // Ctrl+Shift+C
  2964. this.keyHandler.bindAction(86, true, 'pasteStyle', true); // Ctrl+Shift+V
  2965. this.keyHandler.bindAction(77, true, 'editGeometry', true); // Ctrl+Shift+M
  2966. this.keyHandler.bindAction(88, true, 'insertText', true); // Ctrl+Shift+X
  2967. this.keyHandler.bindAction(75, true, 'insertRectangle'); // Ctrl+K
  2968. this.keyHandler.bindAction(75, true, 'insertEllipse', true); // Ctrl+Shift+K
  2969. // Handles copy paste of images from clipboard
  2970. if (!mxClient.IS_IE)
  2971. {
  2972. graph.container.addEventListener('paste', mxUtils.bind(this, function(evt)
  2973. {
  2974. var graph = this.editor.graph;
  2975. if (!mxEvent.isConsumed(evt) && !graph.isEditing())
  2976. {
  2977. try
  2978. {
  2979. var data = (evt.clipboardData || evt.originalEvent.clipboardData);
  2980. var containsText = false;
  2981. // Workaround for asynchronous paste event processing in textInput
  2982. // is to ignore this event if it contains text/html/rtf (see below).
  2983. // NOTE: Image is not pasted into textInput so can't listen there.
  2984. for (var i = 0; i < data.types.length; i++)
  2985. {
  2986. if (data.types[i].substring(0, 5) === 'text/')
  2987. {
  2988. containsText = true;
  2989. break;
  2990. }
  2991. }
  2992. if (!containsText)
  2993. {
  2994. var items = data.items;
  2995. for (index in items)
  2996. {
  2997. var item = items[index];
  2998. if (item.kind === 'file')
  2999. {
  3000. // LATER: Fix sanitizeHtml to allow for data URIs as image in labels
  3001. // if (graph.isEditing())
  3002. // {
  3003. // this.importFiles([item.getAsFile()], 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  3004. // {
  3005. // // Inserts image into current text box
  3006. // graph.insertImage(data, w, h);
  3007. // }, function()
  3008. // {
  3009. // // No post processing
  3010. // }, function(file)
  3011. // {
  3012. // // Handles only images
  3013. // return file.type.substring(0, 6) == 'image/';
  3014. // }, function(queue)
  3015. // {
  3016. // // Invokes elements of queue in order
  3017. // for (var i = 0; i < queue.length; i++)
  3018. // {
  3019. // queue[i]();
  3020. // }
  3021. // });
  3022. // }
  3023. // else
  3024. {
  3025. var pt = this.editor.graph.getInsertPoint();
  3026. this.importFiles([item.getAsFile()], pt.x, pt.y, this.maxImageSize);
  3027. mxEvent.consume(evt);
  3028. }
  3029. break;
  3030. }
  3031. }
  3032. }
  3033. }
  3034. catch (e)
  3035. {
  3036. // ignore
  3037. }
  3038. }
  3039. }), false);
  3040. }
  3041. // Focused but invisible textarea during control or meta key events
  3042. var textInput = document.createElement('div');
  3043. textInput.style.position = 'absolute';
  3044. textInput.style.whiteSpace = 'nowrap';
  3045. textInput.style.overflow = 'hidden';
  3046. textInput.style.display = 'block';
  3047. textInput.contentEditable = true;
  3048. mxUtils.setOpacity(textInput, 0);
  3049. textInput.style.width = '1px';
  3050. textInput.style.height = '1px';
  3051. textInput.innerHTML = '&nbsp;';
  3052. var restoreFocus = false;
  3053. // Disables built-in cut, copy and paste shortcuts
  3054. this.keyHandler.bindControlKey(88, null);
  3055. this.keyHandler.bindControlKey(67, null);
  3056. this.keyHandler.bindControlKey(86, null);
  3057. // Shows a textare when control/cmd is pressed to handle native clipboard actions
  3058. mxEvent.addListener(document, 'keydown', mxUtils.bind(this, function(evt)
  3059. {
  3060. // No dialog visible
  3061. var source = mxEvent.getSource(evt);
  3062. if (graph.container != null && graph.isEnabled() && !graph.isMouseDown && !graph.isEditing() &&
  3063. this.dialog == null && source.nodeName != 'INPUT' && source.nodeName != 'TEXTAREA')
  3064. {
  3065. if (evt.keyCode == 224 /* FF */ || (!mxClient.IS_MAC && evt.keyCode == 17 /* Control */) ||
  3066. (mxClient.IS_MAC && evt.keyCode == 91 /* Meta */))
  3067. {
  3068. // Cannot use parentNode for check in IE
  3069. if (!restoreFocus)
  3070. {
  3071. // Avoid autoscroll but allow handling of all pass-through ctrl shortcuts
  3072. textInput.style.left = (graph.container.scrollLeft + 10) + 'px';
  3073. textInput.style.top = (graph.container.scrollTop + 10) + 'px';
  3074. graph.container.appendChild(textInput);
  3075. restoreFocus = true;
  3076. // Workaround for selected document content in quirks mode
  3077. if (mxClient.IS_QUIRKS)
  3078. {
  3079. window.setTimeout(function()
  3080. {
  3081. textInput.focus();
  3082. document.execCommand('selectAll', false, null);
  3083. }, 0);
  3084. }
  3085. else
  3086. {
  3087. textInput.focus();
  3088. document.execCommand('selectAll', false, null);
  3089. }
  3090. }
  3091. }
  3092. }
  3093. }));
  3094. // Clears input and restores focus and selection
  3095. function clearInput()
  3096. {
  3097. window.setTimeout(function()
  3098. {
  3099. textInput.innerHTML = '&nbsp;';
  3100. textInput.focus();
  3101. document.execCommand('selectAll', false, null);
  3102. }, 0);
  3103. };
  3104. mxEvent.addListener(document, 'keyup', mxUtils.bind(this, function(evt)
  3105. {
  3106. // Workaround for asynchronous event read invalid in IE quirks mode
  3107. var keyCode = evt.keyCode;
  3108. // Asynchronous workaround for scroll to origin after paste if the
  3109. // Ctrl-key is not pressed for long enough in FF on Windows
  3110. window.setTimeout(mxUtils.bind(this, function()
  3111. {
  3112. if (restoreFocus && (keyCode == 224 /* FF */ || keyCode == 17 /* Control */ ||
  3113. keyCode == 91 /* Meta */))
  3114. {
  3115. restoreFocus = false;
  3116. if (!graph.isEditing() && this.dialog == null && graph.container != null)
  3117. {
  3118. graph.container.focus();
  3119. }
  3120. textInput.parentNode.removeChild(textInput);
  3121. }
  3122. }), 0);
  3123. }));
  3124. mxEvent.addListener(textInput, 'copy', mxUtils.bind(this, function(evt)
  3125. {
  3126. if (graph.isEnabled())
  3127. {
  3128. mxClipboard.copy(graph);
  3129. this.copyCells(textInput);
  3130. clearInput();
  3131. }
  3132. }));
  3133. mxEvent.addListener(textInput, 'cut', mxUtils.bind(this, function(evt)
  3134. {
  3135. if (graph.isEnabled())
  3136. {
  3137. this.copyCells(textInput, true);
  3138. clearInput();
  3139. }
  3140. }));
  3141. mxEvent.addListener(textInput, 'paste', mxUtils.bind(this, function(evt)
  3142. {
  3143. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3144. {
  3145. textInput.innerHTML = '&nbsp;';
  3146. textInput.focus();
  3147. window.setTimeout(mxUtils.bind(this, function()
  3148. {
  3149. this.pasteCells(evt, textInput);
  3150. textInput.innerHTML = '&nbsp;';
  3151. }), 0);
  3152. }
  3153. }), true);
  3154. // Needed for IE11
  3155. var isSelectionAllowed2 = this.isSelectionAllowed;
  3156. this.isSelectionAllowed = function(evt)
  3157. {
  3158. if (mxEvent.getSource(evt) == textInput)
  3159. {
  3160. return true;
  3161. }
  3162. return isSelectionAllowed2.apply(this, arguments);
  3163. };
  3164. };
  3165. var y = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight || 0) / 2;
  3166. var x = document.body.clientWidth / 2 - 2;
  3167. // Holds the x-coordinate of the point
  3168. this.spinner = this.createSpinner(x, y, 24);
  3169. // Installs drag and drop handler for rich text editor
  3170. if (Graph.fileSupport)
  3171. {
  3172. this.editor.graph.addListener(mxEvent.EDITING_STARTED, mxUtils.bind(this, function(evt)
  3173. {
  3174. // Setup the dnd listeners
  3175. var graph = this.editor.graph;
  3176. var textElt = graph.cellEditor.text2;
  3177. var dropElt = null;
  3178. if (textElt != null)
  3179. {
  3180. mxEvent.addListener(textElt, 'dragleave', function(evt)
  3181. {
  3182. if (dropElt != null)
  3183. {
  3184. dropElt.parentNode.removeChild(dropElt);
  3185. dropElt = null;
  3186. }
  3187. evt.stopPropagation();
  3188. evt.preventDefault();
  3189. });
  3190. mxEvent.addListener(textElt, 'dragover', mxUtils.bind(this, function(evt)
  3191. {
  3192. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3193. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3194. {
  3195. dropElt = this.highlightElement(textElt);
  3196. }
  3197. evt.stopPropagation();
  3198. evt.preventDefault();
  3199. }));
  3200. mxEvent.addListener(textElt, 'drop', mxUtils.bind(this, function(evt)
  3201. {
  3202. if (dropElt != null)
  3203. {
  3204. dropElt.parentNode.removeChild(dropElt);
  3205. dropElt = null;
  3206. }
  3207. if (evt.dataTransfer.files.length > 0)
  3208. {
  3209. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, function(data, mimeType, x, y, w, h)
  3210. {
  3211. // Inserts image into current text box
  3212. graph.insertImage(data, w, h);
  3213. }, function()
  3214. {
  3215. // No post processing
  3216. }, function(file)
  3217. {
  3218. // Handles only images
  3219. return file.type.substring(0, 6) == 'image/';
  3220. }, function(queue)
  3221. {
  3222. // Invokes elements of queue in order
  3223. for (var i = 0; i < queue.length; i++)
  3224. {
  3225. queue[i]();
  3226. }
  3227. }, !mxEvent.isControlDown(evt));
  3228. }
  3229. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  3230. {
  3231. var uri = evt.dataTransfer.getData('text/uri-list');
  3232. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  3233. {
  3234. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  3235. {
  3236. var w = Math.max(1, img.width);
  3237. var h = Math.max(1, img.height);
  3238. var maxSize = this.maxImageSize;
  3239. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  3240. graph.insertImage(decodeURIComponent(uri), w * s, h * s);
  3241. }));
  3242. }
  3243. else
  3244. {
  3245. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  3246. }
  3247. }
  3248. else
  3249. {
  3250. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  3251. {
  3252. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/html'));
  3253. }
  3254. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  3255. {
  3256. document.execCommand('insertHTML', false, evt.dataTransfer.getData('text/plain'));
  3257. }
  3258. }
  3259. evt.stopPropagation();
  3260. evt.preventDefault();
  3261. }));
  3262. }
  3263. }));
  3264. }
  3265. // Adds an element to edit the style in the footer in test mode
  3266. if (urlParams['test'] == '1')
  3267. {
  3268. var footer = document.getElementById('geFooter');
  3269. if (footer != null)
  3270. {
  3271. this.styleInput = document.createElement('input');
  3272. this.styleInput.setAttribute('type', 'text');
  3273. this.styleInput.style.position = 'absolute';
  3274. this.styleInput.style.top = '14px';
  3275. this.styleInput.style.left = '2px';
  3276. // Workaround for ignore right CSS property in FF
  3277. this.styleInput.style.width = '98%';
  3278. this.styleInput.style.visibility = 'hidden';
  3279. this.styleInput.style.opacity = '0.9';
  3280. mxEvent.addListener(this.styleInput, 'change', mxUtils.bind(this, function()
  3281. {
  3282. this.editor.graph.getModel().setStyle(this.editor.graph.getSelectionCell(), this.styleInput.value);
  3283. }));
  3284. footer.appendChild(this.styleInput);
  3285. this.editor.graph.getSelectionModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function(sender, evt)
  3286. {
  3287. if (this.editor.graph.getSelectionCount() > 0)
  3288. {
  3289. var cell = this.editor.graph.getSelectionCell();
  3290. var style = this.editor.graph.getModel().getStyle(cell);
  3291. this.styleInput.value = style || '';
  3292. this.styleInput.style.visibility = 'visible';
  3293. } else
  3294. {
  3295. this.styleInput.style.visibility = 'hidden';
  3296. }
  3297. }));
  3298. }
  3299. var isSelectionAllowed = this.isSelectionAllowed;
  3300. this.isSelectionAllowed = function(evt)
  3301. {
  3302. if (mxEvent.getSource(evt) == this.styleInput)
  3303. {
  3304. return true;
  3305. }
  3306. return isSelectionAllowed.apply(this, arguments);
  3307. };
  3308. }
  3309. // Removes info text in page
  3310. var info = document.getElementById('geInfo');
  3311. if (info != null)
  3312. {
  3313. info.parentNode.removeChild(info);
  3314. }
  3315. // Installs drag and drop handler for files
  3316. // Enables dropping files
  3317. if (Graph.fileSupport)
  3318. {
  3319. // Setup the dnd listeners
  3320. var dropElt = null;
  3321. mxEvent.addListener(graph.container, 'dragleave', function(evt)
  3322. {
  3323. if (graph.isEnabled())
  3324. {
  3325. if (dropElt != null)
  3326. {
  3327. dropElt.parentNode.removeChild(dropElt);
  3328. dropElt = null;
  3329. }
  3330. evt.stopPropagation();
  3331. evt.preventDefault();
  3332. }
  3333. });
  3334. mxEvent.addListener(graph.container, 'dragover', mxUtils.bind(this, function(evt)
  3335. {
  3336. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3337. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  3338. {
  3339. dropElt = this.highlightElement(graph.container);
  3340. }
  3341. if (this.sidebar != null)
  3342. {
  3343. this.sidebar.hideTooltip();
  3344. }
  3345. evt.stopPropagation();
  3346. evt.preventDefault();
  3347. }));
  3348. mxEvent.addListener(graph.container, 'drop', mxUtils.bind(this, function(evt)
  3349. {
  3350. if (dropElt != null)
  3351. {
  3352. dropElt.parentNode.removeChild(dropElt);
  3353. dropElt = null;
  3354. }
  3355. if (graph.isEnabled())
  3356. {
  3357. var pt = mxUtils.convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  3358. var tr = graph.view.translate;
  3359. var scale = graph.view.scale;
  3360. var x = pt.x / scale - tr.x;
  3361. var y = pt.y / scale - tr.y;
  3362. if (mxEvent.isAltDown(evt))
  3363. {
  3364. x = 0;
  3365. y = 0;
  3366. }
  3367. if (evt.dataTransfer.files.length > 0)
  3368. {
  3369. this.importFiles(evt.dataTransfer.files, x, y, this.maxImageSize, null, null,
  3370. null, null, !mxEvent.isControlDown(evt) && !mxEvent.isShiftDown(evt));
  3371. }
  3372. else
  3373. {
  3374. var uri = (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0) ?
  3375. evt.dataTransfer.getData('text/uri-list') : null;
  3376. var data = this.extractGraphModelFromEvent(evt);
  3377. if (data != null)
  3378. {
  3379. graph.setSelectionCells(this.importXml(data, x, y, true));
  3380. }
  3381. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/html') >= 0)
  3382. {
  3383. var html = evt.dataTransfer.getData('text/html');
  3384. var div = document.createElement('div');
  3385. div.innerHTML = html;
  3386. // The default is based on the extension
  3387. var asImage = null;
  3388. // Extracts single image
  3389. var imgs = div.getElementsByTagName('img');
  3390. if (imgs != null && imgs.length == 1)
  3391. {
  3392. html = imgs[0].getAttribute('src');
  3393. // Handles special case where the src attribute has no valid extension
  3394. // in which case the text would be inserted as text with a link
  3395. if (!(/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(html))
  3396. {
  3397. asImage = true;
  3398. }
  3399. }
  3400. else
  3401. {
  3402. // Extracts single link
  3403. var a = div.getElementsByTagName('a');
  3404. if (a != null && a.length == 1)
  3405. {
  3406. html = a[0].getAttribute('href');
  3407. }
  3408. }
  3409. graph.setSelectionCells(this.insertTextAt(html, x, y, true, asImage));
  3410. }
  3411. else if (uri != null && (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  3412. {
  3413. this.loadImage(decodeURIComponent(uri), mxUtils.bind(this, function(img)
  3414. {
  3415. var w = Math.max(1, img.width);
  3416. var h = Math.max(1, img.height);
  3417. var maxSize = this.maxImageSize;
  3418. var s = Math.min(1, Math.min(maxSize / Math.max(1, w)), maxSize / Math.max(1, h));
  3419. graph.setSelectionCell(graph.insertVertex(null, null, '', x, y, w * s, h * s,
  3420. 'shape=image;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;' +
  3421. 'verticalAlign=top;aspect=fixed;image=' + uri + ';'));
  3422. }), mxUtils.bind(this, function(img)
  3423. {
  3424. graph.setSelectionCells(this.insertTextAt(uri, x, y, true));
  3425. }));
  3426. }
  3427. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/plain') >= 0)
  3428. {
  3429. graph.setSelectionCells(this.insertTextAt(evt.dataTransfer.getData('text/plain'), x, y, true));
  3430. }
  3431. }
  3432. }
  3433. evt.stopPropagation();
  3434. evt.preventDefault();
  3435. }), false);
  3436. }
  3437. this.initPages();
  3438. // Embedded mode
  3439. if (urlParams['embed'] == '1')
  3440. {
  3441. this.initializeEmbedMode();
  3442. }
  3443. };
  3444. /**
  3445. * Creates the format panel and adds overrides.
  3446. */
  3447. EditorUi.prototype.copyCells = function(elt, removeCells)
  3448. {
  3449. var graph = this.editor.graph;
  3450. if (!graph.isSelectionEmpty())
  3451. {
  3452. var cells = mxUtils.sortCells(graph.model.getTopmostCells(graph.getSelectionCells()));
  3453. // LATER: Add span with XML in data attribute
  3454. // var span = document.createElement('span');
  3455. // span.setAttribute('data-jgraph-type', 'application/vnd.jgraph.xml');
  3456. // span.setAttribute('data-jgraph-content', mxUtils.getXml(graph.encodeCells(clones)));
  3457. // Fixes cross-platform clipboard UTF8 issues by encoding as URI
  3458. var xml = mxUtils.getXml(this.editor.graph.encodeCells(cells));
  3459. mxUtils.setTextContent(elt, encodeURIComponent(xml));
  3460. if (removeCells)
  3461. {
  3462. graph.removeCells(cells, false);
  3463. graph.lastPasteXml = null;
  3464. }
  3465. else
  3466. {
  3467. graph.lastPasteXml = xml;
  3468. graph.pasteCounter = 0;
  3469. }
  3470. elt.focus();
  3471. document.execCommand('selectAll', false, null);
  3472. }
  3473. else
  3474. {
  3475. // Disables copy on focused element
  3476. elt.innerHTML = '';
  3477. }
  3478. };
  3479. /**
  3480. * Creates the format panel and adds overrides.
  3481. */
  3482. EditorUi.prototype.pasteCells = function(evt, elt)
  3483. {
  3484. if (!mxEvent.isConsumed(evt))
  3485. {
  3486. var graph = this.editor.graph;
  3487. var xml = mxUtils.trim((mxClient.IS_QUIRKS || document.documentMode == 8) ?
  3488. mxUtils.getTextContent(elt) : elt.textContent);
  3489. var compat = false;
  3490. // Workaround for junk after XML in VM
  3491. try
  3492. {
  3493. var idx = xml.lastIndexOf('%3E');
  3494. if (idx >= 0 && idx < xml.length - 3)
  3495. {
  3496. xml = xml.substring(0, idx + 3);
  3497. }
  3498. }
  3499. catch (e)
  3500. {
  3501. // ignore
  3502. }
  3503. // Checks for embedded XML content
  3504. try
  3505. {
  3506. var spans = elt.getElementsByTagName('span');
  3507. var tmp = (spans != null && spans.length > 0) ?
  3508. mxUtils.trim(decodeURIComponent(spans[0].textContent)) :
  3509. decodeURIComponent(xml);
  3510. if (this.isCompatibleString(tmp))
  3511. {
  3512. compat = true;
  3513. xml = tmp;
  3514. }
  3515. }
  3516. catch (e)
  3517. {
  3518. // ignore
  3519. }
  3520. if (graph.lastPasteXml == xml)
  3521. {
  3522. graph.pasteCounter++;
  3523. }
  3524. else
  3525. {
  3526. graph.lastPasteXml = xml;
  3527. graph.pasteCounter = 0;
  3528. }
  3529. var dx = graph.pasteCounter * graph.gridSize;
  3530. if (xml != null && xml.length > 0)
  3531. {
  3532. if (compat || this.isCompatibleString(xml))
  3533. {
  3534. graph.setSelectionCells(this.importXml(xml, dx, dx));
  3535. }
  3536. else
  3537. {
  3538. var pt = graph.getInsertPoint();
  3539. if (graph.isMouseInsertPoint())
  3540. {
  3541. dx = 0;
  3542. // No offset for insert at mouse position
  3543. if (graph.lastPasteXml == xml && graph.pasteCounter > 0)
  3544. {
  3545. graph.pasteCounter--;
  3546. }
  3547. }
  3548. graph.setSelectionCells(this.insertTextAt(xml, pt.x + dx, pt.y + dx, true));
  3549. }
  3550. if (!graph.isSelectionEmpty())
  3551. {
  3552. graph.scrollCellToVisible(graph.getSelectionCell());
  3553. if (this.hoverIcons != null)
  3554. {
  3555. this.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3556. }
  3557. try
  3558. {
  3559. mxEvent.consume(evt);
  3560. }
  3561. catch (e)
  3562. {
  3563. // ignore event no longer exists in async handler in IE8-
  3564. }
  3565. }
  3566. }
  3567. }
  3568. };
  3569. /**
  3570. * Creates the format panel and adds overrides.
  3571. */
  3572. var editorUiCreateFormat = EditorUi.prototype.createFormat;
  3573. EditorUi.prototype.createFormat = function(container)
  3574. {
  3575. /**
  3576. * Overrides for Format sidebar.
  3577. */
  3578. var formatInit = Format.prototype.init;
  3579. Format.prototype.init = function()
  3580. {
  3581. formatInit.apply(this, arguments);
  3582. var ui = this.editorUi;
  3583. ui.editor.addListener('fileLoaded', this.update);
  3584. };
  3585. var formatRefresh = Format.prototype.refresh;
  3586. Format.prototype.refresh = function()
  3587. {
  3588. var ui = this.editorUi;
  3589. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  3590. {
  3591. formatRefresh.apply(this, arguments);
  3592. }
  3593. else
  3594. {
  3595. this.clear();
  3596. }
  3597. };
  3598. /**
  3599. * Adds autosave and math typesetting options.
  3600. */
  3601. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  3602. DiagramFormatPanel.prototype.addOptions = function(div)
  3603. {
  3604. div = diagramFormatPanelAddOptions.apply(this, arguments);
  3605. var ui = this.editorUi;
  3606. var editor = ui.editor;
  3607. var graph = editor.graph;
  3608. if (graph.isEnabled())
  3609. {
  3610. var file = ui.getCurrentFile();
  3611. if (file != null && file.isAutosaveOptional())
  3612. {
  3613. var opt = this.createOption(mxResources.get('autosave'), function()
  3614. {
  3615. return ui.editor.autosave;
  3616. }, function(checked)
  3617. {
  3618. ui.editor.setAutosave(checked);
  3619. },
  3620. {
  3621. install: function(apply)
  3622. {
  3623. this.listener = function()
  3624. {
  3625. apply(ui.editor.autosave);
  3626. };
  3627. ui.editor.addListener('autosaveChanged', this.listener);
  3628. },
  3629. destroy: function()
  3630. {
  3631. ui.editor.removeListener(this.listener);
  3632. }
  3633. });
  3634. div.appendChild(opt);
  3635. }
  3636. }
  3637. return div;
  3638. };
  3639. /**
  3640. * Adds predefiend styles.
  3641. */
  3642. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  3643. StyleFormatPanel.prototype.init = function()
  3644. {
  3645. // TODO: Update sstate in Format
  3646. var sstate = this.format.createSelectionState();
  3647. if (sstate.style.shape != 'image')
  3648. {
  3649. this.container.appendChild(this.addStyles(this.createPanel()));
  3650. }
  3651. StyleFormatPanelInit.apply(this, arguments);
  3652. };
  3653. /**
  3654. * Overridden to add copy and paste style.
  3655. */
  3656. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  3657. StyleFormatPanel.prototype.addStyleOps = function(div)
  3658. {
  3659. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  3660. {
  3661. this.editorUi.actions.get('copyStyle').funct();
  3662. }));
  3663. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  3664. btn.style.marginBottom = '2px';
  3665. btn.style.width = '100px';
  3666. btn.style.marginRight = '2px';
  3667. div.appendChild(btn);
  3668. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  3669. {
  3670. this.editorUi.actions.get('pasteStyle').funct();
  3671. }));
  3672. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  3673. btn.style.marginBottom = '2px';
  3674. btn.style.width = '100px';
  3675. div.appendChild(btn);
  3676. mxUtils.br(div);
  3677. return styleFormatPanelAddStyleOps.apply(this, arguments);
  3678. };
  3679. /**
  3680. * Creates the buttons for the predefined styles.
  3681. */
  3682. StyleFormatPanel.prototype.addStyles = function(div)
  3683. {
  3684. var graph = this.editorUi.editor.graph;
  3685. var picker = document.createElement('div');
  3686. picker.style.whiteSpace = 'normal';
  3687. picker.style.paddingLeft = '24px';
  3688. picker.style.paddingRight = '20px';
  3689. div.style.paddingLeft = '16px';
  3690. div.style.paddingBottom = '6px';
  3691. div.style.position = 'relative';
  3692. div.appendChild(picker);
  3693. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-orange',
  3694. 'plain-yellow', 'plain-red', 'plain-purple', null];
  3695. function updateScheme(colorsets)
  3696. {
  3697. function addButton(colorset)
  3698. {
  3699. var btn = mxUtils.button('', function(evt)
  3700. {
  3701. graph.getModel().beginUpdate();
  3702. try
  3703. {
  3704. var cells = graph.getSelectionCells();
  3705. for (var i = 0; i < cells.length; i++)
  3706. {
  3707. var style = graph.getModel().getStyle(cells[i]);
  3708. for (var j = 0; j < stylenames.length; j++)
  3709. {
  3710. style = mxUtils.removeStylename(style, stylenames[j]);
  3711. }
  3712. if (colorset != null)
  3713. {
  3714. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  3715. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  3716. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  3717. }
  3718. else
  3719. {
  3720. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  3721. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  3722. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  3723. }
  3724. graph.getModel().setStyle(cells[i], style);
  3725. }
  3726. }
  3727. finally
  3728. {
  3729. graph.getModel().endUpdate();
  3730. }
  3731. })
  3732. btn.style.width = '36px';
  3733. btn.style.height = '30px';
  3734. btn.style.margin = '0px 6px 6px 0px';
  3735. if (colorset != null)
  3736. {
  3737. if (colorset['gradient'] != null)
  3738. {
  3739. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  3740. {
  3741. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  3742. 'StartColorStr=\'' + colorset['fill'] +
  3743. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  3744. }
  3745. else
  3746. {
  3747. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  3748. colorset['gradient'] + ' 100%)';
  3749. }
  3750. }
  3751. else
  3752. {
  3753. btn.style.backgroundColor = colorset['fill'];
  3754. }
  3755. btn.style.border = '1px solid ' + colorset['stroke'];
  3756. }
  3757. else
  3758. {
  3759. btn.style.backgroundColor = '#ffffff';
  3760. btn.style.border = '1px solid #000000';
  3761. }
  3762. picker.appendChild(btn);
  3763. };
  3764. picker.innerHTML = '';
  3765. for (var i = 0; i < colorsets.length; i++)
  3766. {
  3767. if (i > 0 && mxUtils.mod(i, 4) == 0)
  3768. {
  3769. mxUtils.br(picker);
  3770. }
  3771. addButton(colorsets[i]);
  3772. }
  3773. };
  3774. if (this.editorUi.currentScheme == null)
  3775. {
  3776. this.editorUi.currentScheme = 0;
  3777. }
  3778. var schemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  3779. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  3780. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  3781. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  3782. [null,
  3783. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  3784. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  3785. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  3786. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  3787. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  3788. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  3789. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  3790. [null, {fill: '#eeeeee', stroke: '#36393d'},
  3791. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  3792. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  3793. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  3794. var left = document.createElement('div');
  3795. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3796. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  3797. div.appendChild(left);
  3798. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  3799. {
  3800. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, schemes.length);
  3801. updateScheme(schemes[this.editorUi.currentScheme]);
  3802. }));
  3803. var right = document.createElement('div');
  3804. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  3805. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  3806. div.appendChild(right);
  3807. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  3808. {
  3809. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, schemes.length);
  3810. updateScheme(schemes[this.editorUi.currentScheme]);
  3811. }));
  3812. // Hover state
  3813. function addHoverState(elt)
  3814. {
  3815. mxEvent.addListener(elt, 'mouseenter', function()
  3816. {
  3817. elt.style.opacity = '1';
  3818. });
  3819. mxEvent.addListener(elt, 'mouseleave', function()
  3820. {
  3821. elt.style.opacity = '0.5';
  3822. });
  3823. };
  3824. addHoverState(left);
  3825. addHoverState(right);
  3826. updateScheme(schemes[this.editorUi.currentScheme]);
  3827. return div;
  3828. };
  3829. return editorUiCreateFormat.apply(this, arguments);
  3830. };
  3831. // Overridden to add edit shape option
  3832. if (window.StyleFormatPanel != null)
  3833. {
  3834. StyleFormatPanel.prototype.addEditOps = function(div)
  3835. {
  3836. var ss = this.format.getSelectionState();
  3837. var btn = null;
  3838. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  3839. {
  3840. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  3841. {
  3842. this.editorUi.actions.get('editStyle').funct();
  3843. }));
  3844. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  3845. btn.style.width = '202px';
  3846. btn.style.marginBottom = '2px';
  3847. div.appendChild(btn);
  3848. }
  3849. var graph = this.editorUi.editor.graph;
  3850. var state = graph.view.getState(graph.getSelectionCell());
  3851. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  3852. {
  3853. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  3854. {
  3855. this.editorUi.actions.get('editShape').funct();
  3856. }));
  3857. btn2.setAttribute('title', mxResources.get('editShape'));
  3858. btn2.style.marginBottom = '2px';
  3859. if (btn == null)
  3860. {
  3861. btn2.style.width = '202px';
  3862. }
  3863. else
  3864. {
  3865. btn.style.width = '100px';
  3866. btn2.style.width = '100px';
  3867. btn2.style.marginLeft = '2px';
  3868. }
  3869. div.appendChild(btn2);
  3870. }
  3871. else if (ss.image)
  3872. {
  3873. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  3874. {
  3875. this.editorUi.actions.get('image').funct();
  3876. }));
  3877. btn2.setAttribute('title', mxResources.get('editImage'));
  3878. btn2.style.marginBottom = '2px';
  3879. if (btn == null)
  3880. {
  3881. btn2.style.width = '202px';
  3882. }
  3883. else
  3884. {
  3885. btn.style.width = '100px';
  3886. btn2.style.width = '100px';
  3887. btn2.style.marginLeft = '2px';
  3888. }
  3889. div.appendChild(btn2);
  3890. }
  3891. return div;
  3892. };
  3893. }
  3894. /**
  3895. * Adds a file drop handler for opening local files.
  3896. */
  3897. EditorUi.prototype.addFileDropHandler = function(elts)
  3898. {
  3899. // Installs drag and drop handler for files
  3900. if (Graph.fileSupport)
  3901. {
  3902. var dropElt = null;
  3903. for (var i = 0; i < elts.length; i++)
  3904. {
  3905. // Setup the dnd listeners
  3906. mxEvent.addListener(elts[i], 'dragleave', function(evt)
  3907. {
  3908. if (dropElt != null)
  3909. {
  3910. dropElt.parentNode.removeChild(dropElt);
  3911. dropElt = null;
  3912. }
  3913. evt.stopPropagation();
  3914. evt.preventDefault();
  3915. });
  3916. mxEvent.addListener(elts[i], 'dragover', mxUtils.bind(this, function(evt)
  3917. {
  3918. // IE 10 does not implement pointer-events so it can't have a drop highlight
  3919. if (dropElt == null && (!mxClient.IS_IE || (document.documentMode > 10 && document.documentMode < 12)))
  3920. {
  3921. dropElt = this.highlightElement();
  3922. }
  3923. evt.stopPropagation();
  3924. evt.preventDefault();
  3925. }));
  3926. mxEvent.addListener(elts[i], 'drop', mxUtils.bind(this, function(evt)
  3927. {
  3928. if (dropElt != null)
  3929. {
  3930. dropElt.parentNode.removeChild(dropElt);
  3931. dropElt = null;
  3932. }
  3933. if (evt.dataTransfer.files.length > 0)
  3934. {
  3935. this.hideDialog();
  3936. // Never open files in embed mode
  3937. if (urlParams['embed'] == '1')
  3938. {
  3939. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, null, null,
  3940. null, null, !mxEvent.isControlDown(evt) && !mxEvent.isShiftDown(evt));
  3941. }
  3942. else
  3943. {
  3944. this.openFiles(evt.dataTransfer.files);
  3945. }
  3946. }
  3947. else
  3948. {
  3949. // Handles open special files via text drag and drop
  3950. var data = this.extractGraphModelFromEvent(evt);
  3951. // Tries additional and async parsing of text content such as HTML, Gliffy data
  3952. if (data == null)
  3953. {
  3954. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  3955. if (provider != null)
  3956. {
  3957. if (document.documentMode == 10 || document.documentMode == 11)
  3958. {
  3959. data = provider.getData('Text');
  3960. }
  3961. else
  3962. {
  3963. var data = null;
  3964. if (mxUtils.indexOf(provider.types, 'text/uri-list') >= 0)
  3965. {
  3966. var data = evt.dataTransfer.getData('text/uri-list');
  3967. }
  3968. else
  3969. {
  3970. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  3971. }
  3972. if (data != null && data.length > 0)
  3973. {
  3974. var div = document.createElement('div');
  3975. div.innerHTML = data;
  3976. // Extracts single image
  3977. var imgs = div.getElementsByTagName('img');
  3978. if (imgs.length > 0)
  3979. {
  3980. data = imgs[0].getAttribute('src');
  3981. }
  3982. }
  3983. else if (mxUtils.indexOf(provider.types, 'text/plain') >= 0)
  3984. {
  3985. data = provider.getData('text/plain');
  3986. }
  3987. }
  3988. if (data != null)
  3989. {
  3990. // Checks for embedded XML in PNG
  3991. if (data.substring(0, 22) == 'data:image/png;base64,')
  3992. {
  3993. var xml = this.extractGraphModelFromPng(data);
  3994. if (xml != null && xml.length > 0)
  3995. {
  3996. this.openLocalFile(xml);
  3997. }
  3998. }
  3999. if (!this.isOffline() && this.isRemoteFileFormat(data))
  4000. {
  4001. new mxXmlRequest(OPEN_URL, 'format=xml&data=' + encodeURIComponent(data)).send(mxUtils.bind(this, function(req)
  4002. {
  4003. if (req.getStatus() == 200)
  4004. {
  4005. this.openLocalFile(req.getText());
  4006. }
  4007. }));
  4008. }
  4009. else if (/^https?:\/\//.test(data))
  4010. {
  4011. var url = this.getUrl(window.location.pathname + '?url=' + encodeURIComponent(data));
  4012. if (this.getCurrentFile() == null)
  4013. {
  4014. window.location.href = url;
  4015. }
  4016. else
  4017. {
  4018. window.openWindow(url);
  4019. }
  4020. }
  4021. }
  4022. }
  4023. }
  4024. else
  4025. {
  4026. this.openLocalFile(data);
  4027. }
  4028. }
  4029. evt.stopPropagation();
  4030. evt.preventDefault();
  4031. }));
  4032. }
  4033. }
  4034. };
  4035. /**
  4036. * Highlights the given element
  4037. */
  4038. EditorUi.prototype.highlightElement = function(elt)
  4039. {
  4040. var x = 0;
  4041. var y = 0;
  4042. var w = 0;
  4043. var h = 0;
  4044. if (elt == null)
  4045. {
  4046. var b = document.body;
  4047. var d = document.documentElement;
  4048. w = (b.clientWidth || d.clientWidth) - 3;
  4049. h = Math.max(b.clientHeight || 0, d.clientHeight) - 3;
  4050. }
  4051. else
  4052. {
  4053. x = elt.offsetTop;
  4054. y = elt.offsetLeft;
  4055. w = elt.clientWidth;
  4056. h = elt.clientHeight;
  4057. }
  4058. var hl = document.createElement('div');
  4059. hl.style.zIndex = mxPopupMenu.prototype.zIndex + 2;
  4060. hl.style.border = '3px dotted rgb(254, 137, 12)';
  4061. hl.style.pointerEvents = 'none';
  4062. hl.style.position = 'absolute';
  4063. hl.style.top = x + 'px';
  4064. hl.style.left = y + 'px';
  4065. hl.style.width = Math.max(0, w - 3) + 'px';
  4066. hl.style.height = Math.max(0, h - 3) + 'px';
  4067. if (elt != null && elt.parentNode == this.editor.graph.container)
  4068. {
  4069. this.editor.graph.container.appendChild(hl);
  4070. }
  4071. else
  4072. {
  4073. document.body.appendChild(hl);
  4074. }
  4075. return hl;
  4076. };
  4077. /**
  4078. * Highlights the given element
  4079. */
  4080. EditorUi.prototype.stringToCells = function(xml)
  4081. {
  4082. var doc = mxUtils.parseXml(xml);
  4083. var node = this.editor.extractGraphModel(doc.documentElement);
  4084. var cells = [];
  4085. if (node != null)
  4086. {
  4087. var codec = new mxCodec(node.ownerDocument);
  4088. var model = new mxGraphModel();
  4089. codec.decode(node, model);
  4090. var parent = model.getChildAt(model.getRoot(), 0);
  4091. for (var j = 0; j < model.getChildCount(parent); j++)
  4092. {
  4093. cells.push(model.getChildAt(parent, j));
  4094. }
  4095. }
  4096. return cells;
  4097. };
  4098. /**
  4099. * Opens the given files in the editor.
  4100. */
  4101. EditorUi.prototype.openFiles = function(files)
  4102. {
  4103. if (this.spinner.spin(document.body, mxResources.get('loading')))
  4104. {
  4105. for (var i = 0; i < files.length; i++)
  4106. {
  4107. (mxUtils.bind(this, function(file)
  4108. {
  4109. var reader = new FileReader();
  4110. reader.onload = mxUtils.bind(this, function(e)
  4111. {
  4112. var data = e.target.result;
  4113. var name = file.name;
  4114. if (name != null && name.length > 0)
  4115. {
  4116. if (/(\.png)$/i.test(name))
  4117. {
  4118. name = name.substring(0, name.length - 4) + '.xml';
  4119. }
  4120. if (Graph.fileSupport && !this.isOffline() && new XMLHttpRequest().upload &&
  4121. this.isRemoteFileFormat(data, name))
  4122. {
  4123. var dot = name.lastIndexOf('.');
  4124. if (dot >= 0)
  4125. {
  4126. name = name.substring(0, name.lastIndexOf('.')) + '.xml';
  4127. }
  4128. else
  4129. {
  4130. name = name + '.xml';
  4131. }
  4132. this.parseFile(file, mxUtils.bind(this, function(xhr)
  4133. {
  4134. if (xhr.readyState == 4)
  4135. {
  4136. this.spinner.stop();
  4137. if (xhr.status == 200)
  4138. {
  4139. this.openLocalFile(xhr.responseText, name);
  4140. }
  4141. else
  4142. {
  4143. this.handleError({message: mxResources.get((xhr.status == 413) ?
  4144. 'drawingTooLarge' : 'invalidOrMissingFile')},
  4145. mxResources.get('errorLoadingFile'));
  4146. }
  4147. }
  4148. }));
  4149. }
  4150. else if (e.target.result.substring(0, 10) == '<mxlibrary')
  4151. {
  4152. this.spinner.stop();
  4153. try
  4154. {
  4155. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  4156. }
  4157. catch (e)
  4158. {
  4159. this.handleError(e, mxResources.get('errorLoadingFile'));
  4160. }
  4161. }
  4162. else
  4163. {
  4164. if (file.type.substring(0, 9) == 'image/png')
  4165. {
  4166. data = this.extractGraphModelFromPng(data);
  4167. }
  4168. this.spinner.stop();
  4169. this.openLocalFile(data, name);
  4170. }
  4171. }
  4172. });
  4173. reader.onerror = mxUtils.bind(this, function(e)
  4174. {
  4175. this.spinner.stop();
  4176. this.handleError(e);
  4177. window.openFile = null;
  4178. });
  4179. if (file.type.substring(0, 5) === 'image' && file.type.substring(0, 9) !== 'image/svg')
  4180. {
  4181. reader.readAsDataURL(file);
  4182. }
  4183. else
  4184. {
  4185. reader.readAsText(file);
  4186. }
  4187. }))(files[i]);
  4188. }
  4189. }
  4190. };
  4191. /**
  4192. * Shows the layers dialog if the graph has more than one layer.
  4193. */
  4194. EditorUi.prototype.openLocalFile = function(data, name)
  4195. {
  4196. var fn = mxUtils.bind(this, function()
  4197. {
  4198. window.openFile = null;
  4199. if (name == null && this.getCurrentFile() != null && this.isDiagramEmpty())
  4200. {
  4201. var doc = mxUtils.parseXml(data);
  4202. if (doc != null)
  4203. {
  4204. this.editor.setGraphXml(doc.documentElement);
  4205. this.editor.graph.selectAll();
  4206. }
  4207. }
  4208. else
  4209. {
  4210. this.fileLoaded(new LocalFile(this, data, name || this.defaultFilename));
  4211. }
  4212. });
  4213. if (data != null && data.length > 0)
  4214. {
  4215. if (this.getCurrentFile() != null && !this.isDiagramEmpty())
  4216. {
  4217. window.openFile = new OpenFile(function()
  4218. {
  4219. window.openFile = null;
  4220. });
  4221. window.openFile.setData(data, name);
  4222. window.openWindow(this.getUrl(), null, fn);
  4223. }
  4224. else
  4225. {
  4226. fn();
  4227. }
  4228. }
  4229. };
  4230. /**
  4231. * Returns a list of all shapes used in the current file.
  4232. */
  4233. EditorUi.prototype.getBasenames = function()
  4234. {
  4235. var basenames = {};
  4236. if (this.pages != null)
  4237. {
  4238. for (var i = 0; i < this.pages.length; i++)
  4239. {
  4240. this.updatePageRoot(this.pages[i]);
  4241. this.addBasenamesForCell(this.pages[i].root, basenames);
  4242. }
  4243. }
  4244. else
  4245. {
  4246. this.addBasenamesForCell(this.editor.graph.model.getRoot(), basenames);
  4247. }
  4248. var result = [];
  4249. for (var key in basenames)
  4250. {
  4251. result.push(key);
  4252. }
  4253. return result;
  4254. };
  4255. /**
  4256. * Returns a list of all shapes used in the current file.
  4257. */
  4258. EditorUi.prototype.addBasenamesForCell = function(cell, basenames)
  4259. {
  4260. function addName(name)
  4261. {
  4262. if (name != null)
  4263. {
  4264. // LATER: Check if this case exists
  4265. var dot = name.lastIndexOf('.');
  4266. if (dot > 0)
  4267. {
  4268. name = name.substring(dot + 1, name.length);
  4269. }
  4270. if (basenames[name] == null)
  4271. {
  4272. basenames[name] = true;
  4273. }
  4274. }
  4275. };
  4276. var graph = this.editor.graph;
  4277. var style = graph.getCellStyle(cell);
  4278. var shape = style[mxConstants.STYLE_SHAPE];
  4279. addName(mxStencilRegistry.getBasenameForStencil(shape));
  4280. // Adds package names for markers in edges
  4281. if (graph.model.isEdge(cell))
  4282. {
  4283. addName(mxMarker.getPackageForType(style[mxConstants.STYLE_STARTARROW]));
  4284. addName(mxMarker.getPackageForType(style[mxConstants.STYLE_ENDARROW]));
  4285. }
  4286. var childCount = graph.model.getChildCount(cell);
  4287. for (var i = 0; i < childCount; i++)
  4288. {
  4289. this.addBasenamesForCell(graph.model.getChildAt(cell, i), basenames);
  4290. }
  4291. };
  4292. /**
  4293. * Shows the layers dialog if the graph has more than one layer.
  4294. */
  4295. EditorUi.prototype.initializeEmbedMode = function()
  4296. {
  4297. this.diagramContainer.style.visibility = 'hidden';
  4298. this.formatContainer.style.visibility = 'hidden';
  4299. this.editor.graph.setEnabled(false);
  4300. var parent = window.opener || window.parent;
  4301. if (parent != window)
  4302. {
  4303. if (urlParams['spin'] != '1' || this.spinner.spin(document.body, mxResources.get('loading')))
  4304. {
  4305. this.installMessageHandler(mxUtils.bind(this, function(xml, evt, modified)
  4306. {
  4307. this.spinner.stop();
  4308. this.addEmbedButtons();
  4309. this.diagramContainer.style.visibility = '';
  4310. this.formatContainer.style.visibility = '';
  4311. this.editor.graph.setEnabled(true);
  4312. if (xml != null && xml.length > 0)
  4313. {
  4314. this.setFileData(xml);
  4315. this.showLayersDialog();
  4316. }
  4317. else
  4318. {
  4319. this.editor.graph.model.clear();
  4320. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  4321. }
  4322. this.editor.undoManager.clear();
  4323. this.editor.modified = (modified != null) ? modified : false;
  4324. this.updateUi();
  4325. if (this.format != null)
  4326. {
  4327. this.format.refresh();
  4328. }
  4329. }));
  4330. }
  4331. }
  4332. };
  4333. /**
  4334. * Shows the layers dialog if the graph has more than one layer.
  4335. */
  4336. EditorUi.prototype.showLayersDialog = function()
  4337. {
  4338. if (this.editor.graph.getModel().getChildCount(this.editor.graph.getModel().getRoot()) > 1)
  4339. {
  4340. if (this.actions.layersWindow == null)
  4341. {
  4342. this.actions.get('layers').funct();
  4343. }
  4344. else
  4345. {
  4346. this.actions.layersWindow.window.setVisible(true);
  4347. }
  4348. }
  4349. };
  4350. /**
  4351. * Adds the buttons for embedded mode.
  4352. */
  4353. EditorUi.prototype.createLoadMessage = function(eventName)
  4354. {
  4355. var graph = this.editor.graph;
  4356. return {event: eventName, pageVisible: graph.pageVisible, translate: graph.view.translate,
  4357. scale: graph.view.scale, page: graph.view.getBackgroundPageBounds(), bounds: graph.getGraphBounds()};
  4358. };
  4359. /**
  4360. * Adds the buttons for embedded mode.
  4361. */
  4362. EditorUi.prototype.installMessageHandler = function(fn)
  4363. {
  4364. var autosave = false;
  4365. var updateStatus = mxUtils.bind(this, function(sender, eventObject)
  4366. {
  4367. if (urlParams['modified'] != null)
  4368. {
  4369. if (urlParams['modified'] == '0')
  4370. {
  4371. this.editor.setStatus('');
  4372. }
  4373. else
  4374. {
  4375. this.editor.setStatus(mxResources.get(urlParams['modified']));
  4376. }
  4377. }
  4378. });
  4379. this.editor.graph.model.addListener(mxEvent.CHANGE, updateStatus);
  4380. // Receives XML message from opener and puts it into the graph
  4381. mxEvent.addListener(window, 'message', mxUtils.bind(this, function(evt)
  4382. {
  4383. var data = evt.data;
  4384. if (urlParams['proto'] == 'json')
  4385. {
  4386. data = JSON.parse(data);
  4387. if (data.action == 'dialog')
  4388. {
  4389. this.showError((data.titleKey != null) ? mxResources.get(data.titleKey) : data.title,
  4390. (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message,
  4391. (data.buttonKey != null) ? mxResources.get(data.buttonKey) : data.button);
  4392. if (data.modified != null)
  4393. {
  4394. this.editor.modified = data.modified;
  4395. }
  4396. return;
  4397. }
  4398. else if (data.action == 'template')
  4399. {
  4400. this.spinner.stop();
  4401. var dlg = new NewDialog(this, false, false, mxUtils.bind(this, function(xml)
  4402. {
  4403. // LATER: Add autosave option in template message
  4404. fn(xml || '', evt, xml != null);
  4405. }));
  4406. this.showDialog(dlg.container, 620, 440, true, true, mxUtils.bind(this, function(cancel)
  4407. {
  4408. if (cancel)
  4409. {
  4410. this.actions.get('exit').funct();
  4411. }
  4412. }));
  4413. dlg.init();
  4414. return;
  4415. }
  4416. else if (data.action == 'status')
  4417. {
  4418. if (data.messageKey != null)
  4419. {
  4420. this.editor.setStatus(mxResources.get(data.messageKey));
  4421. }
  4422. else if (data.message != null)
  4423. {
  4424. this.editor.setStatus(data.message);
  4425. }
  4426. if (data.modified != null)
  4427. {
  4428. this.editor.modified = data.modified;
  4429. }
  4430. return;
  4431. }
  4432. else if (data.action == 'spinner')
  4433. {
  4434. var msg = (data.messageKey != null) ? mxResources.get(data.messageKey) : data.message;
  4435. if (data.show != null && !data.show)
  4436. {
  4437. this.spinner.stop();
  4438. }
  4439. else
  4440. {
  4441. this.spinner.spin(document.body, msg)
  4442. }
  4443. return;
  4444. }
  4445. else if (data.action == 'export')
  4446. {
  4447. if (data.format == 'png' || data.format == 'xmlpng')
  4448. {
  4449. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  4450. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  4451. {
  4452. var xml = (data.xml != null) ? data.xml : this.getFileData(true);
  4453. this.editor.graph.setEnabled(false);
  4454. var postDataBack = mxUtils.bind(this, function(bin)
  4455. {
  4456. var msg = this.createLoadMessage('export');
  4457. msg.format = data.format;
  4458. msg.xml = encodeURIComponent(xml);
  4459. msg.data = 'data:image/png;base64,' + bin;
  4460. parent.postMessage(JSON.stringify(msg), '*');
  4461. this.editor.graph.setEnabled(true);
  4462. });
  4463. if (this.isExportToCanvas())
  4464. {
  4465. var graph = this.editor.graph;
  4466. // Exports PNG for first page while other page is visible by creating a graph
  4467. // LATER: Add caching for the graph or SVG while not on first page
  4468. if (this.pages != null && this.currentPage != this.pages[0])
  4469. {
  4470. graph = this.createTemporaryGraph(graph.getStylesheet());
  4471. var graphGetGlobalVariable = graph.getGlobalVariable;
  4472. var page = this.pages[0];
  4473. graph.getGlobalVariable = function(name)
  4474. {
  4475. if (name == 'page')
  4476. {
  4477. return page.getName();
  4478. }
  4479. else if (name == 'pagenumber')
  4480. {
  4481. return 1;
  4482. }
  4483. return graphGetGlobalVariable.apply(this, arguments);
  4484. };
  4485. document.body.appendChild(graph.container);
  4486. graph.model.setRoot(page.root);
  4487. }
  4488. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  4489. {
  4490. var uri = canvas.toDataURL('image/png');
  4491. if (data.format == 'xmlpng')
  4492. {
  4493. uri = this.writeGraphModelToPng(uri, 'zTXt', 'mxGraphModel',
  4494. atob(this.editor.graph.compress(xml)));
  4495. }
  4496. // Removes temporary graph from DOM
  4497. if (graph != this.editor.graph)
  4498. {
  4499. graph.container.parentNode.removeChild(graph.container);
  4500. }
  4501. postDataBack(uri.substring(uri.lastIndexOf(',') + 1));
  4502. }), null, null, null, null, null, null, null, null, null, null, graph);
  4503. }
  4504. else
  4505. {
  4506. // Data from server is base64 encoded to avoid binary XHR
  4507. // Double encoding for XML arg is needed for UTF8 encoding
  4508. var req = new mxXmlRequest(EXPORT_URL, 'format=png&embedXml=' +
  4509. ((data.format == 'xmlpng') ? '1' : '0') + '&base64=1&xml=' +
  4510. encodeURIComponent(encodeURIComponent(xml)));
  4511. req.send(mxUtils.bind(this, function(req)
  4512. {
  4513. this.editor.graph.setEnabled(true);
  4514. this.spinner.stop();
  4515. if (req.getStatus() == 200)
  4516. {
  4517. postDataBack(req.getText());
  4518. }
  4519. }), mxUtils.bind(this, function()
  4520. {
  4521. this.spinner.stop();
  4522. }));
  4523. }
  4524. }
  4525. }
  4526. else
  4527. {
  4528. // SVG is generated from graph so parse optional XML
  4529. if (data.xml != null && data.xml.length > 0)
  4530. {
  4531. this.setFileData(data.xml);
  4532. }
  4533. var msg = this.createLoadMessage('export');
  4534. // Forces new HTML format if pages exists
  4535. if (data.format == 'html2' || (data.format == 'html' && (urlParams['pages'] != '0' ||
  4536. (this.pages != null && this.pages.length > 1))))
  4537. {
  4538. var node = this.getXmlFileData();
  4539. msg.xml = mxUtils.getXml(node);
  4540. msg.data = this.getFileData(null, null, true, null, null, null, node);
  4541. msg.format = data.format;
  4542. }
  4543. else if (data.format == 'html')
  4544. {
  4545. var xml = this.editor.getGraphXml();
  4546. msg.data = this.getHtml(xml, this.editor.graph);
  4547. msg.xml = mxUtils.getXml(xml);
  4548. msg.format = data.format;
  4549. }
  4550. else
  4551. {
  4552. // Creates a preview with no alt text for unsupported browsers
  4553. mxSvgCanvas2D.prototype.foAltText = null;
  4554. var bg = this.editor.graph.background;
  4555. if (bg == mxConstants.NONE)
  4556. {
  4557. bg = null;
  4558. }
  4559. msg.xml = this.getFileData(true);
  4560. msg.format = 'svg';
  4561. if (data.embedImages || data.embedImages == null)
  4562. {
  4563. if ((data.spin == null && data.spinKey == null) || this.spinner.spin(document.body,
  4564. (data.spinKey != null) ? mxResources.get(data.spinKey) : data.spin))
  4565. {
  4566. this.editor.graph.setEnabled(false);
  4567. if (data.format == 'xmlsvg')
  4568. {
  4569. this.getEmbeddedSvg(msg.xml, this.editor.graph, null, true, mxUtils.bind(this, function(svg)
  4570. {
  4571. this.editor.graph.setEnabled(true);
  4572. this.spinner.stop();
  4573. msg.data = this.createSvgDataUri(svg);
  4574. parent.postMessage(JSON.stringify(msg), '*');
  4575. }));
  4576. }
  4577. else
  4578. {
  4579. this.convertImages(this.editor.graph.getSvg(bg), mxUtils.bind(this, function(svgRoot)
  4580. {
  4581. this.editor.graph.setEnabled(true);
  4582. this.spinner.stop();
  4583. msg.data = this.createSvgDataUri(mxUtils.getXml(svgRoot));
  4584. parent.postMessage(JSON.stringify(msg), '*');
  4585. }));
  4586. }
  4587. }
  4588. return;
  4589. }
  4590. else
  4591. {
  4592. var svg = (data.format == 'xmlsvg') ? this.getEmbeddedSvg(this.getFileData(true),
  4593. this.editor.graph, null, true) : mxUtils.getXml(this.editor.graph.getSvg(bg));
  4594. msg.data = this.createSvgDataUri(svg);
  4595. }
  4596. }
  4597. parent.postMessage(JSON.stringify(msg), '*');
  4598. }
  4599. return;
  4600. }
  4601. else if (data.action == 'load')
  4602. {
  4603. autosave = data.autosave == 1;
  4604. if (data.modified != null && urlParams['modified'] == null)
  4605. {
  4606. urlParams['modified'] = data.modified;
  4607. }
  4608. if (data.saveAndExit != null && urlParams['saveAndExit'] == null)
  4609. {
  4610. urlParams['saveAndExit'] = data.saveAndExit;
  4611. }
  4612. if (data.title != null && this.buttonContainer != null)
  4613. {
  4614. var tmp = document.createElement('span');
  4615. mxUtils.write(tmp, data.title);
  4616. if (uiTheme == 'atlas')
  4617. {
  4618. this.buttonContainer.style.paddingRight = '12px';
  4619. this.buttonContainer.style.paddingTop = '12px';
  4620. }
  4621. else
  4622. {
  4623. this.buttonContainer.style.paddingRight = '38px';
  4624. this.buttonContainer.style.paddingTop = '6px';
  4625. }
  4626. this.buttonContainer.appendChild(tmp);
  4627. }
  4628. if (data.xmlpng != null)
  4629. {
  4630. data = this.extractGraphModelFromPng(data.xmlpng);
  4631. }
  4632. else
  4633. {
  4634. data = data.xml;
  4635. }
  4636. }
  4637. else
  4638. {
  4639. // Unknown message
  4640. data = null;
  4641. }
  4642. }
  4643. if (data != null && typeof data.charAt === 'function' && data.charAt(0) != '<')
  4644. {
  4645. try
  4646. {
  4647. if (data.substring(0, 26) == 'data:image/svg+xml;base64,')
  4648. {
  4649. data = atob(data.substring(26));
  4650. }
  4651. else if (data.substring(0, 24) == 'data:image/svg+xml;utf8,')
  4652. {
  4653. data = data.substring(24);
  4654. }
  4655. if (data != null)
  4656. {
  4657. if (data.charAt(0) == '%')
  4658. {
  4659. data = decodeURIComponent(data);
  4660. }
  4661. else if (data.charAt(0) != '<')
  4662. {
  4663. data = this.editor.graph.decompress(data);
  4664. }
  4665. }
  4666. }
  4667. catch (e)
  4668. {
  4669. // ignore compression errors and use empty data
  4670. }
  4671. }
  4672. fn(data, evt);
  4673. if (urlParams['modified'] != null)
  4674. {
  4675. this.editor.setStatus('');
  4676. }
  4677. if (autosave)
  4678. {
  4679. var changeListener = mxUtils.bind(this, function(sender, eventObject)
  4680. {
  4681. var data = (urlParams['pages'] != '0' || (this.pages != null && this.pages.length > 1)) ?
  4682. this.getFileData(true): mxUtils.getXml(this.editor.getGraphXml());
  4683. var msg = this.createLoadMessage('autosave');
  4684. msg.xml = data;
  4685. data = JSON.stringify(msg);
  4686. var parent = window.opener || window.parent;
  4687. parent.postMessage(data, '*');
  4688. });
  4689. this.editor.graph.model.addListener(mxEvent.CHANGE, changeListener);
  4690. // Some options trigger autosave
  4691. this.addListener('pageFormatChanged', changeListener);
  4692. this.addListener('backgroundColorChanged', changeListener);
  4693. this.addListener('backgroundImageChanged', changeListener);
  4694. this.addListener('foldingEnabledChanged', changeListener);
  4695. this.addListener('mathEnabledChanged', changeListener);
  4696. this.addListener('gridEnabledChanged', changeListener);
  4697. this.addListener('guidesEnabledChanged', changeListener);
  4698. this.addListener('pageViewChanged', changeListener);
  4699. }
  4700. // Sends the bounds of the graph to the host after parsing
  4701. if (urlParams['returnbounds'] == '1' || urlParams['proto'] == 'json')
  4702. {
  4703. parent.postMessage(JSON.stringify(this.createLoadMessage('load')), '*');
  4704. }
  4705. }));
  4706. // Requests data from the sender. This is a workaround for not allowing
  4707. // the opener to listen for the onload event if not in the same origin.
  4708. var parent = window.opener || window.parent;
  4709. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'init'}) : (urlParams['ready'] || 'ready');
  4710. parent.postMessage(msg, '*');
  4711. };
  4712. /**
  4713. * Adds the buttons for embedded mode.
  4714. */
  4715. EditorUi.prototype.addEmbedButtons = function()
  4716. {
  4717. if (this.menubar != null)
  4718. {
  4719. var div = document.createElement('div');
  4720. div.style.display = 'inline-block';
  4721. div.style.position = 'absolute';
  4722. div.style.paddingTop = (uiTheme == 'atlas') ? '2px' : '3px';
  4723. div.style.paddingLeft = '8px';
  4724. div.style.paddingBottom = '2px';
  4725. var button = document.createElement('button');
  4726. mxUtils.write(button, mxResources.get('save'));
  4727. button.className = 'geBigButton';
  4728. button.style.fontSize = '12px';
  4729. button.style.padding = '4px 6px 4px 6px';
  4730. button.style.borderRadius = '3px';
  4731. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4732. {
  4733. this.actions.get('save').funct();
  4734. }));
  4735. div.appendChild(button);
  4736. if (urlParams['saveAndExit'] == '1')
  4737. {
  4738. button = document.createElement('a');
  4739. mxUtils.write(button, mxResources.get('saveAndExit'));
  4740. button.style.fontSize = '12px';
  4741. button.style.marginLeft = '6px';
  4742. button.style.padding = '4px';
  4743. button.style.cursor = 'pointer';
  4744. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4745. {
  4746. this.actions.get('saveAndExit').funct();
  4747. }));
  4748. div.appendChild(button);
  4749. }
  4750. button = document.createElement('a');
  4751. mxUtils.write(button, mxResources.get('exit'));
  4752. button.style.fontSize = '12px';
  4753. button.style.marginLeft = '6px';
  4754. button.style.marginRight = '20px';
  4755. button.style.padding = '4px';
  4756. button.style.cursor = 'pointer';
  4757. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  4758. {
  4759. this.actions.get('exit').funct();
  4760. }));
  4761. div.appendChild(button);
  4762. this.toolbar.container.appendChild(div);
  4763. this.toolbar.staticElements.push(div);
  4764. div.style.right = (uiTheme != 'atlas') ? '52px' : '42px';
  4765. }
  4766. };
  4767. /**
  4768. * Translates this point by the given vector.
  4769. *
  4770. * @param {number} dx X-coordinate of the translation.
  4771. * @param {number} dy Y-coordinate of the translation.
  4772. */
  4773. EditorUi.prototype.getSearch = function(exclude)
  4774. {
  4775. var result = '';
  4776. if (urlParams['offline'] != '1' && urlParams['demo'] != '1' && exclude != null && window.location.search.length > 0)
  4777. {
  4778. var amp = '?';
  4779. for (var key in urlParams)
  4780. {
  4781. if (mxUtils.indexOf(exclude, key) < 0 && urlParams[key] != null)
  4782. {
  4783. result += amp + key + '=' + urlParams[key];
  4784. amp = '&';
  4785. }
  4786. }
  4787. }
  4788. else
  4789. {
  4790. result = window.location.search;
  4791. }
  4792. return result;
  4793. };
  4794. /**
  4795. * Returns the URL for a copy of this editor with no state.
  4796. */
  4797. EditorUi.prototype.getUrl = function(pathname)
  4798. {
  4799. var href = (pathname != null) ? pathname : window.location.pathname;
  4800. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  4801. if (urlParams['offline'] == '1')
  4802. {
  4803. href += window.location.search;
  4804. }
  4805. else
  4806. {
  4807. var ignored = ['tmp', 'libs', 'clibs', 'state', 'fileId', 'code', 'share', 'notitle',
  4808. 'url', 'embed', 'client', 'create', 'title', 'splash'];
  4809. // Removes template URL parameter for new blank diagram
  4810. for (var key in urlParams)
  4811. {
  4812. if (mxUtils.indexOf(ignored, key) < 0)
  4813. {
  4814. if (parms == 0)
  4815. {
  4816. href += '?';
  4817. }
  4818. else
  4819. {
  4820. href += '&';
  4821. }
  4822. if (urlParams[key] != null)
  4823. {
  4824. href += key + '=' + urlParams[key];
  4825. parms++;
  4826. }
  4827. }
  4828. }
  4829. }
  4830. return href;
  4831. };
  4832. /**
  4833. * Overrides createOutline
  4834. */
  4835. var editorUiCreateOutline = EditorUi.prototype.createOutline;
  4836. EditorUi.prototype.createOutline = function(wnd)
  4837. {
  4838. var outline = editorUiCreateOutline.apply(this, arguments);
  4839. var graph = this.editor.graph;
  4840. var outlineGetSourceGraphBounds = outline.getSourceGraphBounds;
  4841. outline.getSourceGraphBounds = function()
  4842. {
  4843. if (mxUtils.hasScrollbars(graph.container) && graph.pageVisible && this.source.minimumGraphSize != null)
  4844. {
  4845. var pb = this.source.getPagePadding();
  4846. var s = this.source.view.scale;
  4847. var result = new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width - 2 * pb.x / s),
  4848. Math.ceil(this.source.minimumGraphSize.height - 2 * pb.y / s));
  4849. return result;
  4850. }
  4851. return outlineGetSourceGraphBounds.apply(this, arguments);
  4852. };
  4853. var outlineGetSourceContainerSize = outline.getSourceContainerSize;
  4854. outline.getSourceContainerSize = function()
  4855. {
  4856. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  4857. {
  4858. var pad = this.source.getPagePadding();
  4859. var s = this.source.view.scale;
  4860. return new mxRectangle(0, 0, Math.ceil(this.source.minimumGraphSize.width * s - 2 * pad.x),
  4861. Math.ceil(this.source.minimumGraphSize.height * s - 2 * pad.y));
  4862. }
  4863. return outlineGetSourceContainerSize.apply(this, arguments);
  4864. };
  4865. outline.getOutlineOffset = function(scale)
  4866. {
  4867. if (mxUtils.hasScrollbars(graph.container) && this.source.minimumGraphSize != null)
  4868. {
  4869. var pb = this.source.getPagePadding();
  4870. var dx = Math.max(0, (outline.outline.container.clientWidth / scale - (this.source.minimumGraphSize.width - 2 * pb.x)) / 2);
  4871. var dy = Math.max(0, (outline.outline.container.clientHeight / scale - (this.source.minimumGraphSize.height - 2 * pb.y)) / 2);
  4872. // Why is vertical offset negative relative to dy
  4873. return new mxPoint(Math.round(dx - pb.x), Math.round(dy - pb.y - 5 / scale));
  4874. }
  4875. return new mxPoint(8 / scale, 8 / scale);
  4876. };
  4877. var outlineInit = outline.init;
  4878. outline.init = function()
  4879. {
  4880. outlineInit.apply(this, arguments);
  4881. // Problem: Need to override a function in the view but the view is created
  4882. // with the graph so a refresh of the page is needed to see this change.
  4883. outline.outline.view.getBackgroundPageBounds = function()
  4884. {
  4885. var layout = graph.getPageLayout();
  4886. var page = graph.getPageSize();
  4887. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  4888. this.scale * (this.translate.y + layout.y * page.height),
  4889. this.scale * layout.width * page.width,
  4890. this.scale * layout.height * page.height);
  4891. };
  4892. outline.outline.view.validateBackgroundPage();
  4893. };
  4894. this.editor.addListener('pageSelected', function(sender, evt)
  4895. {
  4896. var change = evt.getProperty('change');
  4897. var graph = outline.source;
  4898. var g = outline.outline;
  4899. g.pageScale = graph.pageScale;
  4900. g.pageFormat = graph.pageFormat;
  4901. g.background = graph.background;
  4902. g.pageVisible = graph.pageVisible;
  4903. g.background = graph.background;
  4904. var current = mxUtils.getCurrentStyle(graph.container);
  4905. g.container.style.backgroundColor = current.backgroundColor;
  4906. if (graph.view.backgroundPageShape != null && g.view.backgroundPageShape != null)
  4907. {
  4908. g.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  4909. }
  4910. outline.outline.view.clear(change.previousPage.root, true);
  4911. outline.outline.view.validate();
  4912. });
  4913. return outline;
  4914. };
  4915. /**
  4916. * Updates action states depending on the selection.
  4917. */
  4918. var editorUiUpdateActionStates = EditorUi.prototype.updateActionStates;
  4919. EditorUi.prototype.updateActionStates = function()
  4920. {
  4921. editorUiUpdateActionStates.apply(this, arguments);
  4922. var graph = this.editor.graph;
  4923. var file = this.getCurrentFile();
  4924. var active = (file != null && file.isEditable()) || urlParams['embed'] == '1';
  4925. this.actions.get('pageSetup').setEnabled(active);
  4926. this.actions.get('autosave').setEnabled(file != null && file.isEditable() && file.isAutosaveOptional());
  4927. this.actions.get('guides').setEnabled(active);
  4928. this.actions.get('shadowVisible').setEnabled(active);
  4929. this.actions.get('connectionArrows').setEnabled(active);
  4930. this.actions.get('connectionPoints').setEnabled(active);
  4931. this.actions.get('copyStyle').setEnabled(active && !graph.isSelectionEmpty());
  4932. this.actions.get('pasteStyle').setEnabled(active && !graph.isSelectionEmpty());
  4933. this.actions.get('editGeometry').setEnabled(graph.getModel().isVertex(graph.getSelectionCell()));
  4934. this.actions.get('createShape').setEnabled(active);
  4935. this.actions.get('createRevision').setEnabled(active);
  4936. this.actions.get('moveToFolder').setEnabled(file != null);
  4937. this.actions.get('makeCopy').setEnabled(file != null && !file.isRestricted());
  4938. this.actions.get('editDiagram').setEnabled(urlParams['embed'] == '1' ||
  4939. (file != null && !file.isRestricted()));
  4940. this.actions.get('imgur').setEnabled(file != null && !file.isRestricted());
  4941. this.actions.get('twitter').setEnabled(file != null && !file.isRestricted());
  4942. this.actions.get('facebook').setEnabled(file != null && !file.isRestricted());
  4943. this.actions.get('github').setEnabled(file != null && !file.isRestricted());
  4944. this.actions.get('publishLink').setEnabled(file != null && !file.isRestricted());
  4945. this.menus.get('publish').setEnabled(file != null && !file.isRestricted());
  4946. var state = graph.view.getState(graph.getSelectionCell());
  4947. this.actions.get('editShape').setEnabled(active && state != null && state.shape != null && state.shape.stencil != null);
  4948. };
  4949. /**
  4950. * Changes the default stylename so that it matches the old named style
  4951. * if one was specified in the XML.
  4952. */
  4953. Graph.prototype.defaultThemeName = 'default-style2';
  4954. /**
  4955. * Contains the last XML that was pasted.
  4956. */
  4957. Graph.prototype.lastPasteXml = null;
  4958. /**
  4959. * Contains the number of times the last XML was pasted.
  4960. */
  4961. Graph.prototype.pasteCounter = 0;
  4962. // Experimental edge mode
  4963. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  4964. /**
  4965. * Sets default style (used in editor.get/setGraphXml below)
  4966. */
  4967. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  4968. Graph.prototype.loadStylesheet = function()
  4969. {
  4970. graphLoadStylesheet.apply(this, arguments);
  4971. this.currentStyle = 'default-style2';
  4972. };
  4973. /**
  4974. * Graph Overrides
  4975. */
  4976. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  4977. /**
  4978. * Specifies if the page should be visible for new files. Default is true.
  4979. */
  4980. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  4981. /**
  4982. * Specifies if the page should be visible for new files. Default is true.
  4983. */
  4984. Graph.prototype.shadowId = 'dropShadow';
  4985. /**
  4986. * Loads the stylesheet for this graph.
  4987. */
  4988. Graph.prototype.setShadowVisible = function(value, fireEvent)
  4989. {
  4990. if (mxClient.IS_SVG)
  4991. {
  4992. fireEvent = (fireEvent != null) ? fireEvent : true;
  4993. this.shadowVisible = value;
  4994. if (this.shadowVisible)
  4995. {
  4996. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  4997. }
  4998. else
  4999. {
  5000. this.view.getDrawPane().removeAttribute('filter');
  5001. }
  5002. if (fireEvent)
  5003. {
  5004. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  5005. }
  5006. }
  5007. };
  5008. /**
  5009. * Selects first unlocked layer if one exists
  5010. */
  5011. Graph.prototype.selectUnlockedLayer = function()
  5012. {
  5013. if (this.defaultParent == null)
  5014. {
  5015. var childCount = this.model.getChildCount(this.model.root);
  5016. var cell = null;
  5017. var index = 0;
  5018. do
  5019. {
  5020. cell = this.model.getChildAt(this.model.root, index);
  5021. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  5022. if (cell != null && index > 1)
  5023. {
  5024. this.setDefaultParent(cell);
  5025. }
  5026. }
  5027. };
  5028. /**
  5029. * Adds rack child layout style.
  5030. */
  5031. var graphInit = Graph.prototype.init;
  5032. Graph.prototype.init = function()
  5033. {
  5034. graphInit.apply(this, arguments);
  5035. // Override insert location for current mouse point
  5036. var mouseEvent = null;
  5037. function setMouseEvent(evt)
  5038. {
  5039. mouseEvent = evt;
  5040. // Workaround for member not found in IE8-
  5041. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  5042. {
  5043. mouseEvent = mxUtils.clone(evt);
  5044. }
  5045. };
  5046. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  5047. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  5048. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  5049. {
  5050. mouseEvent = null;
  5051. });
  5052. // Extends getInsertPoint to use the current mouse location
  5053. this.isMouseInsertPoint = function()
  5054. {
  5055. return mouseEvent != null;
  5056. };
  5057. var getInsertPoint = this.getInsertPoint;
  5058. this.getInsertPoint = function()
  5059. {
  5060. if (mouseEvent != null)
  5061. {
  5062. return this.getPointForEvent(mouseEvent);
  5063. }
  5064. return getInsertPoint.apply(this, arguments);
  5065. };
  5066. var layoutManagerGetLayout = this.layoutManager.getLayout;
  5067. this.layoutManager.getLayout = function(cell)
  5068. {
  5069. var state = this.graph.view.getState(cell);
  5070. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  5071. // mxRackContainer may be undefined as it is dynamically loaded at render time
  5072. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  5073. {
  5074. var rackLayout = new mxStackLayout(this.graph, false);
  5075. rackLayout.setChildGeometry = function(child, geo)
  5076. {
  5077. var unitSize = 20;
  5078. geo.height = Math.max(geo.height, unitSize);
  5079. if (geo.height / unitSize > 1)
  5080. {
  5081. var mod = geo.height % unitSize;
  5082. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  5083. }
  5084. this.graph.getModel().setGeometry(child, geo);
  5085. };
  5086. rackLayout.fill = true;
  5087. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  5088. rackLayout.marginLeft = style['marginLeft'] || 0;
  5089. rackLayout.marginRight = style['marginRight'] || 0;
  5090. rackLayout.marginTop = style['marginTop'] || 0;
  5091. rackLayout.marginBottom = style['marginBottom'] || 0;
  5092. rackLayout.resizeParent = false;
  5093. return rackLayout;
  5094. }
  5095. return layoutManagerGetLayout.apply(this, arguments);
  5096. }
  5097. };
  5098. /**
  5099. * Specifies special libraries that are loaded via dynamic JS. Add cases
  5100. * where the filename cannot be worked out from the package name. The
  5101. * standard scheme for this mapping is stencils/packagename.xml. If there
  5102. * are multiple XML files, any JS files or any anomalies in the filename or
  5103. * directory that contains the file, then an entry must be added here and
  5104. * in EmbedServlet2 for the loading of the shapes to work.
  5105. */
  5106. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  5107. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  5108. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  5109. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  5110. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  5111. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  5112. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  5113. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  5114. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  5115. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  5116. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  5117. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  5118. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  5119. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  5120. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  5121. mxStencilRegistry.libraries['eeLogicGates'] = [STENCIL_PATH + '/electrical/logic_gates.xml'];
  5122. mxStencilRegistry.libraries['eeResistors'] = [STENCIL_PATH + '/electrical/resistors.xml'];
  5123. mxStencilRegistry.libraries['eeCapacitors'] = [STENCIL_PATH + '/electrical/capacitors.xml'];
  5124. mxStencilRegistry.libraries['eeInductors'] = [STENCIL_PATH + '/electrical/inductors.xml'];
  5125. mxStencilRegistry.libraries['eeSwitchesRelays'] = [STENCIL_PATH + '/electrical/switchesRelays.xml', STENCIL_PATH + '/electrical/electro-mechanical.xml'];
  5126. mxStencilRegistry.libraries['eeDiodes'] = [STENCIL_PATH + '/electrical/diodes.xml'];
  5127. mxStencilRegistry.libraries['eeSources'] = [STENCIL_PATH + '/electrical/signal_sources.xml'];
  5128. mxStencilRegistry.libraries['eeTransistors'] = [STENCIL_PATH + '/electrical/mosfets1.xml', STENCIL_PATH + '/electrical/mosfets2.xml', STENCIL_PATH + '/electrical/transistors.xml'];
  5129. mxStencilRegistry.libraries['eeMisc'] = [STENCIL_PATH + '/electrical/electro-mechanical.xml', STENCIL_PATH + '/electrical/miscellaneous.xml'];
  5130. mxStencilRegistry.libraries['eeAudio'] = [STENCIL_PATH + '/electrical/radio.xml'];
  5131. mxStencilRegistry.libraries['eePlcLadder'] = [STENCIL_PATH + '/electrical/plc_ladder.xml'];
  5132. mxStencilRegistry.libraries['eeAbstract'] = [STENCIL_PATH + '/electrical/abstract.xml', STENCIL_PATH + '/electrical/logic_gates.xml'];
  5133. mxStencilRegistry.libraries['eeOptical'] = [STENCIL_PATH + '/electrical/opto_electronics.xml'];
  5134. mxStencilRegistry.libraries['eeVacuumTubes'] = [STENCIL_PATH + '/electrical/vacuum_tubes.xml'];
  5135. mxStencilRegistry.libraries['eeWaveforms'] = [STENCIL_PATH + '/electrical/waveforms.xml'];
  5136. mxStencilRegistry.libraries['eeInstruments'] = [STENCIL_PATH + '/electrical/instruments.xml'];
  5137. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  5138. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  5139. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  5140. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  5141. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  5142. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  5143. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  5144. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  5145. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  5146. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  5147. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  5148. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  5149. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  5150. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  5151. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  5152. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  5153. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  5154. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  5155. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  5156. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  5157. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  5158. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  5159. // Triggers dynamic loading for markers
  5160. mxMarker.getPackageForType = function(type)
  5161. {
  5162. var name = null;
  5163. if (type != null && type.length > 0)
  5164. {
  5165. if (type.substring(0, 2) == 'ER')
  5166. {
  5167. name = 'mxgraph.er';
  5168. }
  5169. else if (type.substring(0, 5) == 'sysML')
  5170. {
  5171. name = 'mxgraph.sysml';
  5172. }
  5173. }
  5174. return name;
  5175. };
  5176. var mxMarkerCreateMarker = mxMarker.createMarker;
  5177. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  5178. {
  5179. if (type != null)
  5180. {
  5181. var f = mxMarker.markers[type];
  5182. if (f == null)
  5183. {
  5184. var name = this.getPackageForType(type);
  5185. if (name != null)
  5186. {
  5187. mxStencilRegistry.getStencil(name);
  5188. }
  5189. }
  5190. }
  5191. return mxMarkerCreateMarker.apply(this, arguments);
  5192. };
  5193. })();