EditorUi.js 160 KB

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