App.js 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422
  1. /**
  2. * Copyright (c) 2006-2016, JGraph Ltd
  3. * Copyright (c) 2006-2016, Gaudenz Alder
  4. */
  5. /**
  6. * Constructs a new point for the optional x and y coordinates. If no
  7. * coordinates are given, then the default values for <x> and <y> are used.
  8. * @constructor
  9. * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
  10. * @param {number} x X-coordinate of the point.
  11. * @param {number} y Y-coordinate of the point.
  12. */
  13. App = function(editor, container, lightbox)
  14. {
  15. EditorUi.call(this, editor, container, (lightbox != null) ? lightbox : urlParams['lightbox'] == '1');
  16. // Pre-fetches images
  17. if (mxClient.IS_SVG)
  18. {
  19. mxGraph.prototype.warningImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAE7SURBVHjaYvz//z8DJQAggBjwGXDuHMP/tWuD/uPTCxBAOA0AaQRK/f/+XeJ/cbHlf1wGAAQQTgPu3QNLgfHSpZo4DQAIIKwGwGyH4e/fFbG6AiQJEEAs2Ew2NFzH8OOHBMO6dT/A/KCg7wxGRh+wuhQggDBcALMdFIAcHBxgDGJjcwVIIUAAYbhAUXEdVos4OO4DXcGBIQ4QQCguQPY7sgtgAYruCpAgQACx4LJdU1OCwctLEcyWlLwPJF+AXQE0EMUBAAEEdwF6yMOiD4RRY0QT7gqQAEAAseDzu6XldYYPH9DD4joQa8L5AAEENgWb7SBcXa0JDQMBrK4AcQACiAlfyOMCEFdAnAYQQEz4FLa0XGf4/v0H0IIPONUABBAjyBmMjIwMS5cK/L927QORbtBkaG29DtYLEGAAH6f7oq3Zc+kAAAAASUVORK5CYII=';
  20. }
  21. else
  22. {
  23. var img = new Image();
  24. img.src = mxGraph.prototype.warningImage.src;
  25. }
  26. // Global helper method to deal with popup blockers
  27. window.openWindow = mxUtils.bind(this, function(url, pre, fallback)
  28. {
  29. var wnd = window.open(url);
  30. if (wnd == null || wnd === undefined)
  31. {
  32. this.showDialog(new PopupDialog(this, url, pre, fallback).container, 320, 140, true, true);
  33. }
  34. else if (pre != null)
  35. {
  36. pre();
  37. }
  38. });
  39. // Initial state for toolbar items is disabled
  40. this.updateUi();
  41. // Checks if canvas is supported
  42. var cnv = document.createElement('canvas');
  43. this.canvasSupported = !!(cnv.getContext && cnv.getContext('2d'));
  44. // Global helper method to display error messages
  45. window.showOpenAlert = mxUtils.bind(this, function(message)
  46. {
  47. // Cancel must be called before showing error message
  48. if (window.openFile != null)
  49. {
  50. window.openFile.cancel(true);
  51. }
  52. this.handleError(message);
  53. });
  54. // Sets help link for placeholders
  55. if (!this.isOffline())
  56. {
  57. EditDataDialog.placeholderHelpLink = 'https://support.draw.io/questions/9338941';
  58. }
  59. // Handles opening files via drag and drop
  60. this.addFileDropHandler([document]);
  61. // Process the queue for waiting plugins
  62. if (App.DrawPlugins != null)
  63. {
  64. for (var i = 0; i < App.DrawPlugins.length; i++)
  65. {
  66. App.DrawPlugins[i](this);
  67. }
  68. window.Draw.loadPlugin = function(callback)
  69. {
  70. callback(this);
  71. };
  72. }
  73. this.load();
  74. };
  75. /**
  76. * Executes the first step for connecting to Google Drive.
  77. */
  78. App.ERROR_TIMEOUT = 'timeout';
  79. /**
  80. * Executes the first step for connecting to Google Drive.
  81. */
  82. App.ERROR_BUSY = 'busy';
  83. /**
  84. * Executes the first step for connecting to Google Drive.
  85. */
  86. App.ERROR_UNKNOWN = 'unknown';
  87. /**
  88. * Sets the delay for autosave in milliseconds. Default is 2000.
  89. */
  90. App.MODE_GOOGLE = 'google';
  91. /**
  92. * Sets the delay for autosave in milliseconds. Default is 2000.
  93. */
  94. App.MODE_DROPBOX = 'dropbox';
  95. /**
  96. * Sets the delay for autosave in milliseconds. Default is 2000.
  97. */
  98. App.MODE_ONEDRIVE = 'onedrive';
  99. /**
  100. * Sets the delay for autosave in milliseconds. Default is 2000.
  101. */
  102. App.MODE_DEVICE = 'device';
  103. /**
  104. * Sets the delay for autosave in milliseconds. Default is 2000.
  105. */
  106. App.MODE_BROWSER = 'browser';
  107. /**
  108. * Sets the delay for autosave in milliseconds. Default is 2000.
  109. */
  110. App.DROPBOX_APPKEY = 'libwls2fa9szdji';
  111. /**
  112. * Defines plugin keys for loading via p URL parameter.
  113. */
  114. App.pluginRegistry = {'4xAKTrabTpTzahoLthkwPNUn': '/plugins/explore.js',
  115. 'ex': '/plugins/explore.js', 'p1': '/plugins/p1.js', 'ac': '/plugins/connect.js',
  116. 'acj': '/plugins/connectJira.js', 'voice': '/plugins/voice.js',
  117. 'tips': '/plugins/tooltips.js', 'svgdata': '/plugins/svgdata.js',
  118. 'doors': '/plugins/doors.js', 'electron': 'plugins/electron.js'};
  119. /**
  120. * Function: authorize
  121. *
  122. * Authorizes the client, gets the userId and calls <open>.
  123. */
  124. App.getStoredMode = function()
  125. {
  126. var mode = null;
  127. if (typeof(Storage) != 'undefined')
  128. {
  129. var cookies = document.cookie.split(";");
  130. for (var i = 0; i < cookies.length; i++)
  131. {
  132. // Removes spaces around cookie
  133. var cookie = mxUtils.trim(cookies[i]);
  134. if (cookie.substring(0, 5) == 'MODE=')
  135. {
  136. mode = cookie.substring(5);
  137. break;
  138. }
  139. }
  140. }
  141. return mode;
  142. };
  143. /**
  144. * Static Application initializer executed at load-time.
  145. */
  146. (function()
  147. {
  148. // Checks for local storage and SVG support
  149. window.isSvgBrowser = window.isSvgBrowser || (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 9);
  150. if (!mxClient.IS_CHROMEAPP)
  151. {
  152. if (urlParams['offline'] != '1')
  153. {
  154. // Switches to dropbox mode for db.draw.io
  155. if (window.location.hostname == 'db.draw.io' && urlParams['mode'] == null)
  156. {
  157. urlParams['mode'] = 'dropbox';
  158. }
  159. App.mode = urlParams['mode'];
  160. if (App.mode == null)
  161. {
  162. // Stored mode overrides preferred mode
  163. App.mode = App.getStoredMode();
  164. }
  165. }
  166. if (window.mxscript != null)
  167. {
  168. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  169. if (typeof window.DriveClient === 'function')
  170. {
  171. if (urlParams['gapi'] != '0' && isSvgBrowser &&
  172. (document.documentMode == null || document.documentMode >= 10))
  173. {
  174. // Immediately loads client
  175. if (App.mode == App.MODE_GOOGLE || (urlParams['state'] != null &&
  176. window.location.hash == '') || (window.location.hash != null &&
  177. window.location.hash.substring(0, 2) == '#G'))
  178. {
  179. mxscript('https://apis.google.com/js/api.js');
  180. }
  181. else if (urlParams['chrome'] == '0')
  182. {
  183. // Disables loading of client
  184. window.DriveClient = null;
  185. }
  186. }
  187. else
  188. {
  189. // Disables loading of client
  190. window.DriveClient = null;
  191. }
  192. }
  193. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  194. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  195. if (typeof window.DropboxClient === 'function')
  196. {
  197. if (urlParams['db'] != '0' && isSvgBrowser &&
  198. (document.documentMode == null || document.documentMode > 9))
  199. {
  200. // Immediately loads client
  201. if (App.mode == App.MODE_DROPBOX || (window.location.hash != null &&
  202. window.location.hash.substring(0, 2) == '#D'))
  203. {
  204. mxscript('https://www.dropbox.com/static/api/1/dropins.js', null, 'dropboxjs', App.DROPBOX_APPKEY);
  205. }
  206. else if (urlParams['chrome'] == '0')
  207. {
  208. // Disables loading of client
  209. window.DropboxClient = null;
  210. }
  211. }
  212. else
  213. {
  214. // Disables loading of client
  215. window.DropboxClient = null;
  216. }
  217. }
  218. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  219. if (typeof window.OneDriveClient === 'function')
  220. {
  221. if (urlParams['od'] != '0' && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  222. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))
  223. {
  224. // Immediately loads client
  225. if (App.mode == App.MODE_ONEDRIVE || (window.location.hash != null &&
  226. window.location.hash.substring(0, 2) == '#W'))
  227. {
  228. mxscript('https://js.live.net/v5.0/wl.js');
  229. }
  230. else if (urlParams['chrome'] == '0')
  231. {
  232. // Disables loading of client
  233. window.OneDriveClient = null;
  234. }
  235. }
  236. else
  237. {
  238. // Disables loading of client
  239. window.OneDriveClient = null;
  240. }
  241. }
  242. // Loads JSON for older browsers
  243. if (typeof(JSON) == 'undefined')
  244. {
  245. mxscript('js/json/json2.min.js');
  246. }
  247. }
  248. if (urlParams['plugins'] != '0' && urlParams['offline'] != '1')
  249. {
  250. var plugins = mxSettings.getPlugins();
  251. var temp = urlParams['p'];
  252. if ((temp != null) || (plugins != null && plugins.length > 0))
  253. {
  254. // Workaround for need to load plugins now but wait for UI instance
  255. App.DrawPlugins = [];
  256. // Global entry point for plugins is Draw.loadPlugin. This is the only
  257. // long-term supported solution for access to the EditorUi instance.
  258. window.Draw = new Object();
  259. window.Draw.loadPlugin = function(callback)
  260. {
  261. App.DrawPlugins.push(callback);
  262. };
  263. }
  264. if (temp != null)
  265. {
  266. // Mapping from key to URL in App.plugins
  267. var t = temp.split(';');
  268. for (var i = 0; i < t.length; i++)
  269. {
  270. var url = App.pluginRegistry[t[i]];
  271. if (url != null)
  272. {
  273. mxscript(url);
  274. }
  275. else if (window.console != null)
  276. {
  277. console.log('Unknown plugin:', t[i]);
  278. }
  279. }
  280. }
  281. if (plugins != null && plugins.length > 0 && urlParams['plugins'] != '0')
  282. {
  283. // Loading plugins inside the asynchronous block below stops the page from loading so a
  284. // hardcoded message for the warning dialog is used since the resources are loadd below
  285. var warning = 'The page has requested to load the following plugin(s):\n \n {1}\n \n Would you like to load these plugin(s) now?\n \n NOTE : Only allow plugins to run if you fully understand the security implications of doing so.\n';
  286. if (plugins.length == 1 && (plugins[0].charAt(0) == '/' ||
  287. plugins[0].indexOf(window.location.protocol + '//' + window.location.host) == 0))
  288. {
  289. mxscript(plugins[0]);
  290. }
  291. // Loads plugins asynchronously
  292. else if (mxUtils.confirm(mxResources.replacePlaceholders(warning, [plugins.join('\n')]).replace(/\\n/g, '\n')))
  293. {
  294. for (var i = 0; i < plugins.length; i++)
  295. {
  296. try
  297. {
  298. mxscript(plugins[i]);
  299. }
  300. catch (e)
  301. {
  302. // ignore
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. })();
  310. /**
  311. * Program flow starts here.
  312. *
  313. * Optional callback is called with the app instance.
  314. */
  315. App.main = function(callback)
  316. {
  317. var lastErrorMessage = null;
  318. // Changes top level error handling
  319. window.onerror = function(message, url, linenumber, colno, err)
  320. {
  321. try
  322. {
  323. if (message == lastErrorMessage || (message != null && url != null &&
  324. ((message.indexOf('Script error') != -1) || (message.indexOf('extension') != -1))))
  325. {
  326. // TODO log external domain script failure "Script error." is
  327. // reported when the error occurs in a script that is hosted
  328. // on a domain other than the domain of the current page
  329. }
  330. // DocumentClosedError seems to be an FF bug an can be ignored for now
  331. else if (message != null && message.indexOf('DocumentClosedError') < 0)
  332. {
  333. lastErrorMessage = message;
  334. var img = new Image();
  335. var severity = (message.indexOf('NetworkError') >= 0 || message.indexOf('SecurityError') >= 0 ||
  336. message.indexOf('NS_ERROR_FAILURE') >= 0 || message.indexOf('out of memory') >= 0) ?
  337. 'CONFIG' : 'SEVERE';
  338. img.src = 'log?severity=' + severity + '&v=' + encodeURIComponent(EditorUi.VERSION) +
  339. '&msg=clientError:' + encodeURIComponent(message) + ':url:' + encodeURIComponent(window.location.href) +
  340. ':lnum:' + encodeURIComponent(linenumber) +
  341. ((colno != null) ? ':colno:' + encodeURIComponent(colno) : '') +
  342. ((err != null && err.stack != null) ? '&stack=' + encodeURIComponent(err.stack) : '');
  343. }
  344. }
  345. catch (err)
  346. {
  347. // do nothing
  348. }
  349. };
  350. /**
  351. * Lazy loading of additional CSS for atlas theme.
  352. */
  353. if (uiTheme == 'atlas')
  354. {
  355. mxClient.link('stylesheet', 'styles/atlas.css');
  356. }
  357. if (window.mxscript != null)
  358. {
  359. /**
  360. * Color dialog - Do not add to app.min.js due to path issues!
  361. */
  362. if (urlParams['chrome'] != '0')
  363. {
  364. mxscript('js/jscolor/jscolor.js');
  365. }
  366. /**
  367. * Injects offline dependencies
  368. */
  369. if (urlParams['offline'] == '1')
  370. {
  371. mxscript('js/shapes.min.js');
  372. var frame = document.createElement('iframe');
  373. frame.setAttribute('width', '0');
  374. frame.setAttribute('height', '0');
  375. frame.setAttribute('src', 'offline.html');
  376. document.body.appendChild(frame);
  377. // Precaching for stencils. Alternatively we could generate
  378. // a cache manifest with all stencil and shape files but this
  379. // simplifies the cache file, streamlines the shape loading
  380. // to a single loading point (here) vs dynamic loading in the
  381. // online version. It does slow down the startup time though.
  382. mxStencilRegistry.stencilSet = {};
  383. // Overrides dynamic loading (everything loaded at startup)
  384. mxStencilRegistry.getStencil = function(name)
  385. {
  386. return mxStencilRegistry.stencils[name];
  387. };
  388. // Takes stencil data from cache for populating sidebar
  389. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force)
  390. {
  391. var name = stencilFile.substring(stencilFile.indexOf('/') + 1);
  392. name = 'mxgraph.' + name.substring(0, name.length - 4).replace(/\//g, '.');
  393. var node = mxStencilRegistry.stencilSet[name];
  394. if (node != null)
  395. {
  396. mxStencilRegistry.parseStencilSet(node, postStencilLoad, false);
  397. }
  398. };
  399. // Preload all stencils from merged XML file
  400. var req2 = mxUtils.load('stencils.xml');
  401. var root = req2.getXml().documentElement;
  402. var node = root.firstChild;
  403. while (node != null)
  404. {
  405. if (node.nodeName == 'shapes' && node.getAttribute('name') != null)
  406. {
  407. mxStencilRegistry.stencilSet[node.getAttribute('name').toLowerCase()] = node;
  408. mxStencilRegistry.parseStencilSet(node);
  409. }
  410. node = node.nextSibling;
  411. }
  412. }
  413. /**
  414. * Loads Google Image Picker API
  415. */
  416. if (urlParams['picker'] != '0' && !mxClient.IS_QUIRKS && document.documentMode != 8)
  417. {
  418. mxscript(document.location.protocol + '//www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22picker%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' + mxClient.language + '%22%7D%5D%7D');
  419. }
  420. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  421. // Special case: Cannot load in asynchronous code below
  422. if (typeof window.DriveClient === 'function' &&
  423. (typeof gapi === 'undefined' && (((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  424. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && isSvgBrowser &&
  425. isLocalStorage && (document.documentMode == null || document.documentMode >= 10))))
  426. {
  427. mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback');
  428. }
  429. }
  430. /**
  431. * Asynchronous MathJax extension.
  432. */
  433. if (urlParams['math'] != '0')
  434. {
  435. Editor.initMath();
  436. }
  437. // Adds required resources (disables loading of fallback properties, this can only
  438. // be used if we know that all keys are defined in the language specific file)
  439. mxResources.loadDefaultBundle = false;
  440. var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
  441. mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);
  442. // Prefetches asynchronous requests so that below code runs synchronous
  443. // Loading the correct bundle (one file) via the fallback system in mxResources. The stylesheet
  444. // is compiled into JS in the build process and is only needed for local development.
  445. mxUtils.getAll((urlParams['dev'] != '1') ? [bundle] : [bundle, STYLE_PATH + '/default.xml'], function(xhr)
  446. {
  447. // Adds bundle text to resources
  448. mxResources.parse(xhr[0].getText());
  449. // Prepares themes with mapping from old default-style to old XML file
  450. if (xhr.length > 1)
  451. {
  452. Graph.prototype.defaultThemes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();
  453. }
  454. // Main
  455. var ui = new App(new Editor(urlParams['chrome'] == '0'));
  456. if (window.mxscript != null)
  457. {
  458. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  459. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  460. if (typeof window.DropboxClient === 'function' &&
  461. (window.Dropbox != null && typeof Dropbox.choose === 'undefined' &&
  462. window.DrawDropboxClientCallback != null &&
  463. (((urlParams['embed'] != '1' && urlParams['db'] != '0') ||
  464. (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  465. isSvgBrowser && (document.documentMode == null || document.documentMode > 9))))
  466. {
  467. mxscript('https://www.dropbox.com/static/api/1/dropins.js', window.DrawDropboxClientCallback, 'dropboxjs', App.DROPBOX_APPKEY);
  468. }
  469. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  470. if (typeof window.OneDriveClient === 'function' &&
  471. (typeof WL === 'undefined' && window.DrawOneDriveClientCallback != null &&
  472. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  473. urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  474. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  475. {
  476. mxscript('https://js.live.net/v5.0/wl.js', window.DrawOneDriveClientCallback);
  477. }
  478. }
  479. if (callback != null)
  480. {
  481. callback(ui);
  482. }
  483. /**
  484. * For developers only
  485. */
  486. if (urlParams['chrome'] != '0' && urlParams['test'] == '1')
  487. {
  488. mxLog.show();
  489. mxLog.debug('Started in ' + (new Date().getTime() - t0.getTime()) + 'ms');
  490. mxLog.debug('Export:', EXPORT_URL);
  491. mxLog.debug('Development mode:', (urlParams['dev'] == '1') ? 'active' : 'inactive');
  492. mxLog.debug('Test mode:', (urlParams['test'] == '1') ? 'active' : 'inactive');
  493. }
  494. }, function()
  495. {
  496. document.getElementById('geStatus').innerHTML = 'Error loading page. <a href="javascript:void(0);" onclick="location.reload();">Please try refreshing.</a>';
  497. });
  498. };
  499. //Extends EditorUi
  500. mxUtils.extend(App, EditorUi);
  501. /**
  502. * Executes the first step for connecting to Google Drive.
  503. */
  504. App.prototype.defaultUserPicture = 'https://lh3.googleusercontent.com/-HIzvXUy6QUY/AAAAAAAAAAI/AAAAAAAAAAA/giuR7PQyjEk/photo.jpg?sz=30';
  505. /**
  506. * Executes the first step for connecting to Google Drive.
  507. */
  508. App.prototype.micImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA5UlEQVR4Xr3SMYrCQBTGcSfIQiAgRIS9hOANBCurPUAuIAp7A7FVsFkIbLGYA9gKtoKNYG3jll5AFNKG518YMD6SISD4wY9J4MvkMYwRkZqOMSZkifGFe1b4pnvW3TqK8oMo14twxUgXPRSlDxU7TcUNPqATlG7wCi93cA2Iq2x7l7IJsgofB6UTiEjKklFqsabQSdFA5jqDAzrYQGeNNv5d9yDBEAME6NreFmP8Yuma4A8hFpiLSFNAYYYYn0jwCIUnxMcER4h1whS+7hseXKcu9ifGeQ+qeO8GjN7DPve+Q6+oewPhmE63Qfsb6AAAAABJRU5ErkJggg==';
  509. /**
  510. * Contains the default XML for an empty diagram.
  511. */
  512. App.prototype.emptyDiagramXml = '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>';
  513. /**
  514. *
  515. */
  516. App.prototype.shareImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDowOTgwMTE3NDA3MjA2ODExODhDNkFGMDBEQkQ0RTgwOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxMjU2NzdEMTcwRDIxMUUxQjc0MDkxRDhCNUQzOEFGRCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxMjU2NzdEMDcwRDIxMUUxQjc0MDkxRDhCNUQzOEFGRCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowNjgwMTE3NDA3MjA2ODExODcxRkM4MUY1OTFDMjQ5OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowNzgwMTE3NDA3MjA2ODExODhDNkFGMDBEQkQ0RTgwOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrM/fs0AAADgSURBVHjaYmDAA/7//88MwgzkAKDGFiD+BsQ/QWxSNaf9RwN37twpI8WAS+gGfP78+RpQSoRYA36iG/D379+vQClNdLVMOMz4gi7w79+/n0CKg1gD9qELvH379hzIHGK9oA508ieY8//8+fO5rq4uFCilRKwL1JmYmNhhHEZGRiZ+fn6Q2meEbDYG4u3/cYCfP38uA7kOm0ZOIJ7zn0jw48ePPiDFhmzArv8kgi9fvuwB+w5qwH9ykjswbFSZyM4sEMDPBDTlL5BxkFSd7969OwZ2BZKYGhDzkmjOJ4AAAwBhpRqGnEFb8QAAAABJRU5ErkJggg==';
  517. /**
  518. *
  519. */
  520. App.prototype.chevronUpImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-up.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUY1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NjA1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1RDUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1RTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pg+qUokAAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAAL0lEQVR42mJgRgMMRAswMKAKMDDARBjg8lARBoR6KImkH0wTbygT6YaS4DmAAAMAYPkClOEDDD0AAAAASUVORK5CYII=';
  521. /**
  522. *
  523. */
  524. App.prototype.chevronDownImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-down.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUI1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NUM1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1OTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1QTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsCtve8AAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAALUlEQVR42mJgRgMMRAkwQEXBNAOcBSPhclB1cNVwfcxI+vEZykSpoSR6DiDAAF23ApT99bZ+AAAAAElFTkSuQmCC';
  525. /**
  526. *
  527. */
  528. App.prototype.formatShowImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-show.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REY1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5RTA1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlERDU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlERTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlnMQ/8AAAAJUExURQAAAP///3FxcTfTiAsAAAACdFJOU/8A5bcwSgAAACFJREFUeNpiYEQDDEQJMMABTAAixcQ00ALoDiPRcwABBgB6DADly9Yx8wAAAABJRU5ErkJggg==';
  529. /**
  530. *
  531. */
  532. App.prototype.formatHideImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-hide.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REI1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5REM1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlEOTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlEQTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqjT9SMAAAAGUExURQAAAP///6XZn90AAAACdFJOU/8A5bcwSgAAAB9JREFUeNpiYEQDDEQJMMABTAAmNdAC6A4j0XMAAQYAcbwA1Xvj1CgAAAAASUVORK5CYII=';
  533. /**
  534. *
  535. */
  536. App.prototype.fullscreenImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/fullscreen.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMAQMAAABsu86kAAAABlBMVEUAAABEREQ3UJNbAAAAAXRSTlMAQObYZgAAABxJREFUCNdj+PkBhA4YgNB5AwZ+BiACMiAiEFkA9QQNgW8IGoYAAAAASUVORK5CYII=';
  537. /**
  538. *
  539. */
  540. App.prototype.plusImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/plus.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MDdCMTdENjVCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MDdCMTdENjZCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowN0IxN0Q2M0I4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowN0IxN0Q2NEI4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtjrjmgAAAAtSURBVHjaYvz//z8DMigvLwcLdHZ2MiKLMzEQCaivkLGsrOw/dU0cAr4GCDAARQsQbTFrv10AAAAASUVORK5CYII=';
  541. /**
  542. *
  543. */
  544. App.prototype.spinImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/spin.gif' : 'data:image/gif;base64,R0lGODlhDAAMAPUxAEVriVp7lmCAmmGBm2OCnGmHn3OPpneSqYKbr4OcsIScsI2kto6kt46lt5KnuZmtvpquvpuvv56ywaCzwqK1xKu7yay9yq+/zLHAzbfF0bjG0bzJ1LzK1MDN18jT28nT3M3X3tHa4dTc49Xd5Njf5dng5t3k6d/l6uDm6uru8e7x8/Dz9fT29/b4+Pj5+fj5+vr6+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkKADEAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAADAAMAAAGR8CYcEgsOgYAIax4CCQuQldrCBEsiK8VS2hoFGOrlJDA+cZQwkLnqyoJFZKviSS0ICrE0ec0jDAwIiUeGyBFGhMPFBkhZo1BACH5BAkKAC4ALAAAAAAMAAwAhVB0kFR3k1V4k2CAmmWEnW6Lo3KOpXeSqH2XrIOcsISdsImhtIqhtJCmuJGnuZuwv52wwJ+ywZ+ywqm6yLHBzbLCzrXEz7fF0LnH0rrI0r7L1b/M1sXR2cfT28rV3czW3s/Z4Nfe5Nvi6ODm6uLn6+Ln7OLo7OXq7efs7+zw8u/y9PDy9PX3+Pr7+////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZDQJdwSCxGDAIAoVFkFBwYSyIwGE4OkCJxIdG6WkJEx8sSKj7elfBB0a5SQg1EQ0SVVMPKhDM6iUIkRR4ZFxsgJl6JQQAh+QQJCgAxACwAAAAADAAMAIVGa4lcfZdjgpxkg51nhp5ui6N3kqh5lKqFnbGHn7KIoLOQp7iRp7mSqLmTqbqarr6br7+fssGitcOitcSuvsuuv8uwwMyzw861xNC5x9K6x9K/zNbDztjE0NnG0drJ1NzQ2eDS2+LT2+LV3ePZ4Oba4ebb4ufc4+jm6+7t8PLt8PPt8fPx8/Xx9PX09vf19/j3+Pn///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CYcEgsUhQFggFSjCQmnE1jcBhqGBXiIuAQSi7FGEIgfIzCFoCXFCZiPO0hKBMiwl7ET6eUYqlWLkUnISImKC1xbUEAIfkECQoAMgAsAAAAAAwADACFTnKPT3KPVHaTYoKcb4yjcY6leZSpf5mtgZuvh5+yiqG0i6K1jqW3kae5nrHBnrLBn7LCoLPCobTDqbrIqrvIs8LOtMPPtcPPtcTPuMbRucfSvcrUvsvVwMzWxdHaydTcytXdzNbezdff0drh2ODl2+Ln3eTp4Obq4ujs5Ont5uvu6O3w6u7w6u7x7/L09vj5+vr7+vv7////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkdAmXBILHIcicOCUqxELKKPxKAYgiYd4oMAEWo8RVmjIMScwhmBcJMKXwLCECmMGAhPI1QRwBiaSixCMDFhLSorLi8wYYxCQQAh+QQJCgAxACwAAAAADAAMAIVZepVggJphgZtnhp5vjKN2kah3kqmBmq+KobSLorWNpLaRp7mWq7ybr7+gs8KitcSktsWnuManucexwM2ywc63xtG6yNO9ytS+ytW/zNbDz9jH0tvL1d3N197S2+LU3OPU3ePV3eTX3+Xa4efb4ufd5Onl6u7r7vHs7/Lt8PLw8/Xy9Pby9fb09ff2+Pn3+Pn6+vr///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGSMCYcEgseiwSR+RS7GA4JFGF8RiWNiEiJTERgkjFGAQh/KTCGoJwpApnBkITKrwoCFWnFlEhaAxXLC9CBwAGRS4wQgELYY1CQQAh+QQJCgAzACwAAAAADAAMAIVMcI5SdZFhgZtti6JwjaR4k6mAma6Cm6+KobSLorWLo7WNo7aPpredsMCescGitMOitcSmuMaqu8ixwc2zws63xdC4xtG5x9K9ytXAzdfCztjF0NnF0drK1d3M1t7P2N/P2eDT2+LX3+Xe5Onh5+vi5+vj6Ozk6e3n7O/o7O/q7vHs7/Lt8PPu8fPx8/X3+Pn6+vv7+/v8/Pz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRcCZcEgsmkIbTOZTLIlGqZNnchm2SCgiJ6IRqljFmQUiXIVnoITQde4chC9Y+LEQxmTFRkFSNFAqDAMIRQoCAAEEDmeLQQAh+QQJCgAwACwAAAAADAAMAIVXeZRefplff5lhgZtph59yjqV2kaeAmq6FnbGFnrGLorWNpLaQp7mRqLmYrb2essGgs8Klt8apusitvcquv8u2xNC7yNO8ydS8ytTAzdfBzdfM1t7N197Q2eDU3OPX3+XZ4ObZ4ebc4+jf5erg5erg5uvp7fDu8fPv8vTz9fb09vf19/j3+Pn4+fn5+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  545. /**
  546. *
  547. */
  548. App.prototype.emptyLibraryXml = '<mxlibrary>[]</mxlibrary>';
  549. /**
  550. * Sets the delay for autosave in milliseconds. Default is 2000.
  551. */
  552. App.prototype.mode = null;
  553. /**
  554. * Executes the first step for connecting to Google Drive.
  555. */
  556. App.prototype.timeout = 25000;
  557. /**
  558. * Switch to disable logging for mode and search terms.
  559. */
  560. App.prototype.enableLogging = true;
  561. // Restores app defaults for UI
  562. App.prototype.formatEnabled = urlParams['format'] != '0';
  563. App.prototype.formatWidth = (screen.width < 600) ? 0 : mxSettings.getFormatWidth();
  564. /**
  565. * Overriden UI settings depending on mode.
  566. */
  567. if (urlParams['embed'] != '1')
  568. {
  569. App.prototype.menubarHeight = 60;
  570. }
  571. /**
  572. * Executes the first step for connecting to Google Drive.
  573. */
  574. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  575. /**
  576. * Translates this point by the given vector.
  577. *
  578. * @param {number} dx X-coordinate of the translation.
  579. * @param {number} dy Y-coordinate of the translation.
  580. */
  581. App.prototype.init = function()
  582. {
  583. EditorUi.prototype.init.apply(this, arguments);
  584. /**
  585. * Overrides export dialog for using cloud storage save.
  586. */
  587. if (this.isLocalFileSave())
  588. {
  589. var ui = this;
  590. ExportDialog.saveLocalFile = function(data, filename, format)
  591. {
  592. var mime = 'text/xml';
  593. if (format === 'svg')
  594. {
  595. mime = 'image/svg+xml';
  596. }
  597. ui.saveLocalFile(data, filename, mime);
  598. };
  599. ExportDialog.saveRequest = function(data, filename, format, fn)
  600. {
  601. ui.saveRequest(data, filename, format, fn);
  602. };
  603. }
  604. /**
  605. * Specifies the default filename.
  606. */
  607. this.defaultLibraryName = mxResources.get('untitledLibrary');
  608. /**
  609. * Holds the listener for description changes.
  610. */
  611. this.descriptorChangedListener = mxUtils.bind(this, this.descriptorChanged);
  612. if (urlParams['embed'] != '1')
  613. {
  614. /**
  615. * Holds the background element.
  616. */
  617. this.bg = this.createBackground();
  618. document.body.appendChild(this.bg);
  619. this.diagramContainer.style.visibility = 'hidden';
  620. this.formatContainer.style.visibility = 'hidden';
  621. this.hsplit.style.display = 'none';
  622. this.sidebarContainer.style.display = 'none';
  623. this.sidebarFooterContainer.style.display = 'none';
  624. /**
  625. * Creates onedrive client if all required libraries are available.
  626. */
  627. var initOneDriveClient = mxUtils.bind(this, function()
  628. {
  629. if (typeof WL !== 'undefined')
  630. {
  631. /**
  632. * Holds the x-coordinate of the point.
  633. */
  634. this.oneDrive = new OneDriveClient(this);
  635. this.oneDrive.addListener('userChanged', mxUtils.bind(this, function()
  636. {
  637. this.updateUserElement();
  638. this.restoreLibraries();
  639. }))
  640. // Notifies listeners of new client
  641. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.oneDrive));
  642. }
  643. else if (window.DrawOneDriveClientCallback == null)
  644. {
  645. window.DrawOneDriveClientCallback = initOneDriveClient;
  646. }
  647. });
  648. initOneDriveClient();
  649. /**
  650. * Creates drive client with all required libraries are available.
  651. */
  652. var initDriveClient = mxUtils.bind(this, function()
  653. {
  654. /**
  655. * Creates google drive client if all required libraries are available.
  656. */
  657. if (typeof gapi !== 'undefined')
  658. {
  659. var doInit = mxUtils.bind(this, function()
  660. {
  661. /**
  662. * Holds the x-coordinate of the point.
  663. */
  664. this.drive = new DriveClient(this);
  665. /**
  666. * Adds important notice for new app if drive file is loaded in old app.
  667. */
  668. if (this.drive.appId == '420247213240')
  669. {
  670. this.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  671. {
  672. var file = this.getCurrentFile();
  673. if (file != null && file.constructor == DriveFile)
  674. {
  675. var td = document.getElementById('geFooterItem2');
  676. if (td != null)
  677. {
  678. td.innerHTML = '<a href="https://support.draw.io/display/DO/2014/11/27/Switching+application+in+Google+Drive" ' +
  679. 'target="_blank" title="IMPORTANT NOTICE" >IMPORTANT NOTICE</a>';
  680. }
  681. }
  682. }));
  683. }
  684. this.drive.addListener('userChanged', mxUtils.bind(this, function()
  685. {
  686. // Changes the footer ads for Google Accounts
  687. if (this.updateAd != null)
  688. {
  689. this.adsHtml = ['<a title="Quick start video" href="https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1" target="_blank">' +
  690. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Quick start video</a>',
  691. '<a title="Google Docs Add-on" href="https://chrome.google.com/webstore/detail/drawio-diagrams/clpbjldiohnnmfmkngmaohehlnfkmoea" target="_blank">' +
  692. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Google Docs Add-on</a>',
  693. '<a title="Google Chrome App" href="https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla" target="_blank">' +
  694. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Google Chrome App</a>',
  695. '<a title="Please help us to 5 stars" href="https://chrome.google.com/webstore/detail/drawio-pro/onlkggianjhjenigcpigpjehhpplldkc/reviews" target="_blank">' +
  696. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Please help us to 5 stars</a>'];
  697. this.updateAd(this.adsHtml.length - 1);
  698. }
  699. this.updateUserElement();
  700. this.restoreLibraries();
  701. this.checkLicense();
  702. }))
  703. // Notifies listeners of new client
  704. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.drive));
  705. });
  706. if (window.DrawGapiClientCallback != null)
  707. {
  708. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  709. {
  710. // Starts the app without the Google Option if the API fails to load
  711. if (gapi.drive != null && gapi.drive.realtime != null)
  712. {
  713. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  714. {
  715. this.defineCustomObjects();
  716. // Needed to avoid popup blocking for non-immediate authentication
  717. gapi.auth.init(mxUtils.bind(this, function()
  718. {
  719. if (gapi.client.drive != null)
  720. {
  721. doInit();
  722. }
  723. }));
  724. }));
  725. }
  726. }));
  727. /**
  728. * Clears any callbacks.
  729. */
  730. window.DrawGapiClientCallback = null;
  731. }
  732. else
  733. {
  734. doInit();
  735. }
  736. }
  737. else if (window.DrawGapiClientCallback == null)
  738. {
  739. window.DrawGapiClientCallback = initDriveClient;
  740. }
  741. });
  742. initDriveClient();
  743. /**
  744. * Creates dropbox client if all required libraries are available.
  745. */
  746. var initDropboxClient = mxUtils.bind(this, function()
  747. {
  748. if (window.Dropbox != null && typeof Dropbox.choose !== 'undefined')
  749. {
  750. /**
  751. * Clears dropbox client callback.
  752. */
  753. window.DrawDropboxClientCallback = null;
  754. /**
  755. * Holds the x-coordinate of the point.
  756. */
  757. this.dropbox = new DropboxClient(this);
  758. this.dropbox.addListener('userChanged', mxUtils.bind(this, function()
  759. {
  760. this.updateUserElement();
  761. this.restoreLibraries();
  762. }));
  763. // Notifies listeners of new client
  764. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.dropbox));
  765. }
  766. else if (window.DrawDropboxClientCallback == null)
  767. {
  768. window.DrawDropboxClientCallback = initDropboxClient;
  769. }
  770. });
  771. initDropboxClient();
  772. // Sets the initial mode
  773. if (urlParams['local'] == '1')
  774. {
  775. this.setMode(App.MODE_DEVICE);
  776. }
  777. else
  778. {
  779. this.mode = App.mode;
  780. }
  781. }
  782. else if (this.menubar != null)
  783. {
  784. this.menubar.container.style.paddingTop = '0px';
  785. }
  786. this.updateHeader();
  787. // Changes footer from time to time
  788. var td = document.getElementById('geFooterItem2');
  789. if (td != null)
  790. {
  791. this.adsHtml = ['<a title="Quick start video" href="https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1" target="_blank">' +
  792. '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/>&nbsp;&nbsp;Quick start video</a>'];
  793. this.adsHtml.push(td.innerHTML);
  794. mxUtils.setPrefixedStyle(td.style, 'transition', 'all 1s ease');
  795. var lastAd = this.adsHtml.length - 1;
  796. this.updateAd = function(index)
  797. {
  798. if (index == lastAd)
  799. {
  800. index = this.adsHtml.length - 1;
  801. }
  802. if (index != lastAd)
  803. {
  804. mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(0)');
  805. td.style.opacity = '0';
  806. lastAd = index;
  807. window.setTimeout(mxUtils.bind(this, function()
  808. {
  809. td.innerHTML = this.adsHtml[index];
  810. mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(1)');
  811. td.style.opacity = '1';
  812. }), 1000);
  813. }
  814. };
  815. window.setInterval(mxUtils.bind(this, function()
  816. {
  817. if (this.adsHtml.length == 3)
  818. {
  819. this.updateAd(mxUtils.mod(lastAd + 1, 3));
  820. }
  821. else
  822. {
  823. var rnd = Math.random();
  824. this.updateAd(Math.round(rnd * (this.adsHtml.length - 1)));
  825. }
  826. }), 300000);
  827. }
  828. if (this.menubar != null)
  829. {
  830. this.buttonContainer = document.createElement('div');
  831. this.buttonContainer.style.display = 'inline-block';
  832. this.buttonContainer.style.paddingRight = '48px';
  833. this.buttonContainer.style.position = 'absolute';
  834. this.buttonContainer.style.right = '0px';
  835. this.menubar.container.appendChild(this.buttonContainer);
  836. }
  837. if (uiTheme == 'atlas' && this.menubar != null)
  838. {
  839. if (this.toggleElement != null)
  840. {
  841. this.toggleElement.click();
  842. this.toggleElement.style.display = 'none';
  843. }
  844. this.icon = document.createElement('img');
  845. this.icon.setAttribute('src', IMAGE_PATH + '/logo-flat-small.png');
  846. this.icon.setAttribute('title', mxResources.get('draw.io'));
  847. this.icon.style.paddingTop = '11px';
  848. this.icon.style.marginLeft = '4px';
  849. this.icon.style.marginRight = '6px';
  850. if (mxClient.IS_QUIRKS)
  851. {
  852. this.icon.style.marginTop = '12px';
  853. }
  854. this.menubar.container.insertBefore(this.icon, this.menubar.container.firstChild);
  855. }
  856. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  857. {
  858. /**
  859. * Persists current edge style.
  860. */
  861. this.editor.graph.currentEdgeStyle = mxSettings.getCurrentEdgeStyle();
  862. this.editor.graph.currentVertexStyle = mxSettings.getCurrentVertexStyle();
  863. // Updates UI to reflect current edge style
  864. this.fireEvent(new mxEventObject('styleChanged', 'keys', [], 'values', [], 'cells', []));
  865. this.addListener('styleChanged', mxUtils.bind(this, function(sender, evt)
  866. {
  867. mxSettings.setCurrentEdgeStyle(this.editor.graph.currentEdgeStyle);
  868. mxSettings.setCurrentVertexStyle(this.editor.graph.currentVertexStyle);
  869. mxSettings.save();
  870. }));
  871. /**
  872. * Persists copy on connect switch.
  873. */
  874. this.editor.graph.connectionHandler.setCreateTarget(mxSettings.isCreateTarget());
  875. this.fireEvent(new mxEventObject('copyConnectChanged'));
  876. this.addListener('copyConnectChanged', mxUtils.bind(this, function(sender, evt)
  877. {
  878. mxSettings.setCreateTarget(this.editor.graph.connectionHandler.isCreateTarget());
  879. mxSettings.save();
  880. }));
  881. /**
  882. * Persists default page format.
  883. */
  884. this.editor.graph.pageFormat = mxSettings.getPageFormat();
  885. this.addListener('pageFormatChanged', mxUtils.bind(this, function(sender, evt)
  886. {
  887. mxSettings.setPageFormat(this.editor.graph.pageFormat);
  888. mxSettings.save();
  889. }));
  890. /**
  891. * Persists default grid color.
  892. */
  893. this.editor.graph.view.gridColor = mxSettings.getGridColor();
  894. this.addListener('gridColorChanged', mxUtils.bind(this, function(sender, evt)
  895. {
  896. mxSettings.setGridColor(this.editor.graph.view.gridColor);
  897. mxSettings.save();
  898. }));
  899. /**
  900. * Persists autosave switch in Chrome app.
  901. */
  902. if (mxClient.IS_CHROMEAPP)
  903. {
  904. this.editor.addListener('autosaveChanged', mxUtils.bind(this, function(sender, evt)
  905. {
  906. mxSettings.setAutosave(this.editor.autosave);
  907. mxSettings.save();
  908. }));
  909. this.editor.autosave = mxSettings.getAutosave();
  910. }
  911. /**
  912. *
  913. */
  914. if (this.sidebar != null)
  915. {
  916. this.sidebar.showPalette('search', mxSettings.settings.search);
  917. }
  918. /**
  919. * Shows scratchpad if never shown.
  920. */
  921. if (!this.editor.chromeless && this.sidebar != null && (mxSettings.settings.isNew ||
  922. parseInt(mxSettings.settings.version || 0) <= 8))
  923. {
  924. this.toggleScratchpad();
  925. mxSettings.save();
  926. }
  927. // Saves app defaults for UI
  928. this.addListener('formatWidthChanged', function()
  929. {
  930. mxSettings.setFormatWidth(this.formatWidth);
  931. mxSettings.save();
  932. });
  933. }
  934. };
  935. /**
  936. * Returns true if the current domain is for the new drive app.
  937. */
  938. App.prototype.isDriveDomain = function()
  939. {
  940. return urlParams['drive'] != '0' &&
  941. (window.location.hostname == 'test.draw.io' ||
  942. window.location.hostname == 'cdn.draw.io' ||
  943. window.location.hostname == 'www.draw.io' ||
  944. window.location.hostname == 'drive.draw.io' ||
  945. window.location.hostname == 'jgraph.github.io');
  946. };
  947. /**
  948. * Returns true if the current domain is for the old drive app.
  949. */
  950. App.prototype.isLegacyDriveDomain = function()
  951. {
  952. return urlParams['drive'] == 0 || window.location.hostname == 'legacy.draw.io';
  953. };
  954. /**
  955. *
  956. */
  957. App.prototype.checkLicense = function()
  958. {
  959. var driveUser = this.drive.getUser();
  960. var email = ((urlParams['dev'] == '1') ? urlParams['lic'] : null) ||
  961. ((driveUser != null) ? driveUser.email : null);
  962. if (!this.isOffline() && !this.editor.chromeless && email != null)
  963. {
  964. // Anonymises the local part of the email address
  965. var at = email.lastIndexOf('@');
  966. var domain = email;
  967. if (at >= 0)
  968. {
  969. domain = email.substring(at + 1);
  970. email = this.crc32(email.substring(0, at)) + '@' + domain;
  971. }
  972. // Timestamp is workaround for cached response in certain environments
  973. mxUtils.post('/license', 'domain=' + encodeURIComponent(domain) + '&email=' +
  974. encodeURIComponent(email) + '&ts=' + new Date().getTime(),
  975. mxUtils.bind(this, function(req)
  976. {
  977. var registered = false;
  978. var exp = null;
  979. try
  980. {
  981. if (req.getStatus() == 200)
  982. {
  983. var value = req.getText();
  984. registered = true;
  985. if (value.length > 0)
  986. {
  987. var lic = JSON.parse(value);
  988. if (lic != null)
  989. {
  990. exp = this.handleLicense(lic, domain);
  991. }
  992. }
  993. }
  994. }
  995. catch (e)
  996. {
  997. // ignore
  998. }
  999. }));
  1000. }
  1001. };
  1002. /**
  1003. * Returns true if the current domain is for the new drive app.
  1004. */
  1005. App.prototype.handleLicense = function(lic, domain)
  1006. {
  1007. var footer = document.getElementById('geFooter');
  1008. var expiry = null;
  1009. if (footer != null && lic != null)
  1010. {
  1011. expiry = lic.expiry;
  1012. if (lic.footer != null)
  1013. {
  1014. footer.innerHTML = decodeURIComponent(lic.footer);
  1015. }
  1016. else
  1017. {
  1018. this.hideFooter();
  1019. if (expiry != null && expiry != 'never')
  1020. {
  1021. var exp = new Date(Date.parse(expiry));
  1022. var diff = Math.round((exp - Date.now()) / (1000 * 60 * 60 * 24));
  1023. if (diff < 90)
  1024. {
  1025. var link = 'https://support.draw.io/display/DKB/draw.io+footer+state+that+license+is+expiring+on+Google+For+Work+account?domain=' + encodeURIComponent(domain);
  1026. footer.style.height = '100%';
  1027. footer.style.margin = '0px';
  1028. footer.style.display = '';
  1029. if (diff < 0)
  1030. {
  1031. this.footerHeight = 80;
  1032. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert geBlink">' +
  1033. '<a href="' + link + '" style="padding-top:16px;" target="_blank">' +
  1034. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1035. mxResources.get('licenseHasExpired', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1036. }
  1037. else
  1038. {
  1039. this.footerHeight = 46;
  1040. footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert">' +
  1041. '<a href="' + link + '" target="_blank">' +
  1042. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
  1043. mxResources.get('licenseWillExpire', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
  1044. }
  1045. this.refresh();
  1046. }
  1047. }
  1048. }
  1049. }
  1050. return expiry;
  1051. };
  1052. /**
  1053. *
  1054. */
  1055. App.prototype.getEditBlankXml = function()
  1056. {
  1057. var file = this.getCurrentFile();
  1058. if (file != null && this.editor.chromeless && this.editor.graph.lightbox && file.realtime == null)
  1059. {
  1060. return file.getData();
  1061. }
  1062. else
  1063. {
  1064. return this.getFileData(true);
  1065. }
  1066. };
  1067. /**
  1068. * Updates action states depending on the selection.
  1069. */
  1070. App.prototype.updateActionStates = function()
  1071. {
  1072. EditorUi.prototype.updateActionStates.apply(this, arguments);
  1073. var file = this.getCurrentFile();
  1074. this.actions.get('revisionHistory').setEnabled(file != null && ((file.constructor == DriveFile &&
  1075. file.isEditable()) || file.constructor == DropboxFile));
  1076. };
  1077. /**
  1078. * Sets the onbeforeunload for the application
  1079. */
  1080. App.prototype.updateDraft = function()
  1081. {
  1082. if (isLocalStorage && localStorage != null)
  1083. {
  1084. localStorage.setItem('.draft', JSON.stringify({modified: new Date().getTime(), data: this.getFileData()}));
  1085. }
  1086. };
  1087. /**
  1088. * Sets the onbeforeunload for the application
  1089. */
  1090. App.prototype.getDraft = function()
  1091. {
  1092. // FIXME: Handle multiple tabs
  1093. // if (isLocalStorage && localStorage != null)
  1094. // {
  1095. // try
  1096. // {
  1097. // var draft = localStorage.getItem('.draft');
  1098. //
  1099. // if (draft != null)
  1100. // {
  1101. // return JSON.parse(draft);
  1102. // }
  1103. // }
  1104. // catch (e)
  1105. // {
  1106. // // ignore quota etc
  1107. // }
  1108. // }
  1109. return null;
  1110. };
  1111. /**
  1112. * Sets the onbeforeunload for the application
  1113. */
  1114. App.prototype.addRecent = function(entry)
  1115. {
  1116. if (isLocalStorage && localStorage != null)
  1117. {
  1118. var recent = this.getRecent();
  1119. if (recent == null)
  1120. {
  1121. recent = [];
  1122. }
  1123. else
  1124. {
  1125. for (var i = 0; i < recent.length; i++)
  1126. {
  1127. if (recent[i].id == entry.id)
  1128. {
  1129. recent.splice(i, 1);
  1130. }
  1131. }
  1132. }
  1133. if (recent != null)
  1134. {
  1135. recent.unshift(entry);
  1136. recent = recent.slice(0, 5);
  1137. localStorage.setItem('.recent', JSON.stringify(recent));
  1138. }
  1139. }
  1140. };
  1141. /**
  1142. * Sets the onbeforeunload for the application
  1143. */
  1144. App.prototype.getRecent = function()
  1145. {
  1146. if (isLocalStorage && localStorage != null)
  1147. {
  1148. try
  1149. {
  1150. var recent = localStorage.getItem('.recent');
  1151. if (recent != null)
  1152. {
  1153. return JSON.parse(recent);
  1154. }
  1155. }
  1156. catch (e)
  1157. {
  1158. // ignore
  1159. }
  1160. return null;
  1161. }
  1162. };
  1163. /**
  1164. * Sets the onbeforeunload for the application
  1165. */
  1166. App.prototype.resetRecent = function(entry)
  1167. {
  1168. if (isLocalStorage && localStorage != null)
  1169. {
  1170. try
  1171. {
  1172. localStorage.removeItem('.recent');
  1173. }
  1174. catch (e)
  1175. {
  1176. // ignore
  1177. }
  1178. }
  1179. };
  1180. /**
  1181. * Sets the onbeforeunload for the application
  1182. */
  1183. App.prototype.removeDraft = function()
  1184. {
  1185. if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
  1186. {
  1187. try
  1188. {
  1189. localStorage.removeItem('.draft');
  1190. }
  1191. catch (e)
  1192. {
  1193. // ignore quota etc
  1194. }
  1195. }
  1196. };
  1197. /**
  1198. * Sets the onbeforeunload for the application
  1199. */
  1200. App.prototype.onBeforeUnload = function()
  1201. {
  1202. var file = this.getCurrentFile();
  1203. if (file != null)
  1204. {
  1205. if (file.constructor == LocalFile && !file.isModified() && urlParams['nowarn'] != '1' &&
  1206. !this.isDiagramEmpty() && urlParams['url'] == null && !this.editor.chromeless)
  1207. {
  1208. return mxResources.get('ensureDataSaved');
  1209. }
  1210. else if (file.constructor != DriveFile && file.isModified())
  1211. {
  1212. return mxResources.get('allChangesLost');
  1213. }
  1214. else
  1215. {
  1216. file.close(true);
  1217. }
  1218. }
  1219. };
  1220. /**
  1221. * Translates this point by the given vector.
  1222. *
  1223. * @param {number} dx X-coordinate of the translation.
  1224. * @param {number} dy Y-coordinate of the translation.
  1225. */
  1226. App.prototype.updateDocumentTitle = function()
  1227. {
  1228. if (!this.editor.graph.lightbox)
  1229. {
  1230. var title = this.editor.appName;
  1231. var file = this.getCurrentFile();
  1232. if (file != null)
  1233. {
  1234. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1235. title = filename + ' - ' + title;
  1236. }
  1237. if (this.isOfflineApp())
  1238. {
  1239. title += ' [' + mxResources.get('offline') + ']';
  1240. }
  1241. document.title = title;
  1242. }
  1243. };
  1244. /**
  1245. * Authorizes the client, gets the userId and calls <open>.
  1246. */
  1247. App.prototype.createCrcTable = function()
  1248. {
  1249. var crcTable = [];
  1250. var c;
  1251. for (var n = 0; n < 256; n++)
  1252. {
  1253. c = n;
  1254. for (var k = 0; k < 8; k++)
  1255. {
  1256. c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  1257. }
  1258. crcTable[n] = c;
  1259. }
  1260. return crcTable;
  1261. };
  1262. /**
  1263. * Authorizes the client, gets the userId and calls <open>.
  1264. */
  1265. App.prototype.crc32 = function(str)
  1266. {
  1267. this.crcTable = this.crcTable || this.createCrcTable();
  1268. var crc = 0 ^ (-1);
  1269. for (var i = 0; i < str.length; i++ )
  1270. {
  1271. crc = (crc >>> 8) ^ this.crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
  1272. }
  1273. return (crc ^ (-1)) >>> 0;
  1274. };
  1275. /**
  1276. * Returns a thumbnail of the current file.
  1277. */
  1278. App.prototype.getThumbnail = function(width, success)
  1279. {
  1280. var result = false;
  1281. try
  1282. {
  1283. if (this.thumbImageCache == null)
  1284. {
  1285. this.thumbImageCache = new Object();
  1286. }
  1287. // Uses new client-side canvas export for Chrome, Firefox and Opera
  1288. if (this.isExportToCanvas())
  1289. {
  1290. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1291. {
  1292. success(canvas);
  1293. }), width, this.thumbImageCache, '#ffffff', function()
  1294. {
  1295. // Continues with null in error case
  1296. success();
  1297. });
  1298. result = true;
  1299. }
  1300. else if (this.canvasSupported && this.getCurrentFile() != null)
  1301. {
  1302. var graph = this.editor.graph;
  1303. var canvas = document.createElement('canvas');
  1304. var bounds = graph.getGraphBounds();
  1305. var scale = width / bounds.width;
  1306. // Limits scale to 1 or 2 * width / height
  1307. scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
  1308. var x0 = Math.floor(bounds.x);
  1309. var y0 = Math.floor(bounds.y);
  1310. canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
  1311. canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
  1312. var ctx = canvas.getContext('2d');
  1313. // Configures the canvas
  1314. ctx.scale(scale, scale);
  1315. ctx.translate(-x0, -y0);
  1316. // Paint white background instead of transparent
  1317. var bg = graph.background;
  1318. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1319. {
  1320. bg = '#ffffff';
  1321. }
  1322. // Paints background
  1323. ctx.save();
  1324. ctx.fillStyle = bg;
  1325. ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
  1326. ctx.restore();
  1327. var htmlCanvas = new mxJsCanvas(canvas);
  1328. // NOTE: htmlCanvas passed into async canvas is only used for image
  1329. // and canvas caching (canvas caching not used in this case as we do
  1330. // not render text). To reuse that cache via the thumbImageCache we
  1331. // pass that into the async canvas and override the image cache in
  1332. // the newly created html canvas with that of the thumbImageCache.
  1333. // LATER: Is clear thumbImageCache needed if file changes?
  1334. var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
  1335. htmlCanvas.images = this.thumbImageCache.images;
  1336. // Render graph
  1337. var imgExport = new mxImageExport();
  1338. imgExport.drawShape = function(state, canvas)
  1339. {
  1340. if (state.shape instanceof mxShape && state.shape.checkBounds())
  1341. {
  1342. canvas.save();
  1343. canvas.translate(0.5, 0.5);
  1344. state.shape.paint(canvas);
  1345. canvas.translate(-0.5, -0.5);
  1346. canvas.restore();
  1347. }
  1348. };
  1349. imgExport.drawText = function(state, canvas)
  1350. {
  1351. // No text output for thumbnails
  1352. };
  1353. imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
  1354. asynCanvas.finish(function()
  1355. {
  1356. imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
  1357. success(canvas);
  1358. });
  1359. result = true;
  1360. }
  1361. }
  1362. catch (e)
  1363. {
  1364. // ignore and use placeholder
  1365. }
  1366. return result;
  1367. };
  1368. /**
  1369. * Tries to find a public URL for the given file.
  1370. */
  1371. App.prototype.getPublicUrl = function(file, fn)
  1372. {
  1373. fn(null);
  1374. };
  1375. /**
  1376. * Translates this point by the given vector.
  1377. *
  1378. * @param {number} dx X-coordinate of the translation.
  1379. * @param {number} dy Y-coordinate of the translation.
  1380. */
  1381. App.prototype.createFileData = function(node, graph, file, url, forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection)
  1382. {
  1383. forceXml = (forceXml != null) ? forceXml : false;
  1384. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1385. var editLink = null;
  1386. var redirect = null;
  1387. if (file == null || file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER)
  1388. {
  1389. editLink = '_blank';
  1390. }
  1391. else
  1392. {
  1393. editLink = url;
  1394. redirect = editLink;
  1395. }
  1396. if (node == null)
  1397. {
  1398. return '';
  1399. }
  1400. else
  1401. {
  1402. var fileNode = node;
  1403. // Ignores case for possible HTML or XML nodes
  1404. if (fileNode.nodeName.toLowerCase() != 'mxfile')
  1405. {
  1406. // Removes control chars in input for correct roundtrip check
  1407. var text = this.editor.graph.zapGremlins(mxUtils.getXml(node));
  1408. var data = this.editor.graph.compress(text);
  1409. // Fallback to plain XML for invalid compression
  1410. // TODO: Remove this fallback with active pages
  1411. if (this.editor.graph.decompress(data) != text)
  1412. {
  1413. return text;
  1414. }
  1415. else
  1416. {
  1417. var diagramNode = node.ownerDocument.createElement('diagram');
  1418. mxUtils.setTextContent(diagramNode, data);
  1419. fileNode = node.ownerDocument.createElement('mxfile');
  1420. fileNode.appendChild(diagramNode);
  1421. }
  1422. }
  1423. fileNode.setAttribute('userAgent', navigator.userAgent);
  1424. fileNode.setAttribute('version', EditorUi.VERSION);
  1425. fileNode.setAttribute('editor', 'www.draw.io');
  1426. var md = (file != null) ? file.getMode() : this.mode;
  1427. if (md != null)
  1428. {
  1429. fileNode.setAttribute('type', md);
  1430. }
  1431. var xml = mxUtils.getXml(fileNode);
  1432. // Writes the file as an embedded HTML file
  1433. if (!forceSvg && !forceXml && (forceHtml || (file != null && /(\.html)$/i.test(file.getTitle()))))
  1434. {
  1435. xml = this.getHtml2(fileNode, graph, file.getTitle(), editLink, redirect, ignoreSelection);
  1436. }
  1437. // Maps the XML data to the content attribute in the SVG node
  1438. else if (forceSvg || (!forceXml && file != null && /(\.svg)$/i.test(file.getTitle())))
  1439. {
  1440. if (file != null && (file.getMode() == App.MODE_DEVICE || file.getMode() == App.MODE_BROWSER))
  1441. {
  1442. url = null;
  1443. }
  1444. xml = this.getEmbeddedSvg(xml, graph, url, null, embeddedCallback, ignoreSelection, redirect);
  1445. }
  1446. return xml;
  1447. }
  1448. };
  1449. /**
  1450. * Translates this point by the given vector.
  1451. *
  1452. * @param {number} dx X-coordinate of the translation.
  1453. * @param {number} dy Y-coordinate of the translation.
  1454. */
  1455. App.prototype.getFileData = function(forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection, currentPage)
  1456. {
  1457. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  1458. currentPage = (currentPage != null) ? currentPage : false;
  1459. var node = this.editor.getGraphXml(ignoreSelection);
  1460. if (ignoreSelection && this.fileNode != null && this.currentPage != null)
  1461. {
  1462. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(node)));
  1463. mxUtils.setTextContent(this.currentPage.node, data);
  1464. node = this.fileNode.cloneNode(false);
  1465. if (currentPage)
  1466. {
  1467. node.appendChild(this.currentPage.node);
  1468. }
  1469. else
  1470. {
  1471. // Restores order of pages
  1472. for (var i = 0; i < this.pages.length; i++)
  1473. {
  1474. var mapping = this.pages[i].mapping;
  1475. // Updates XML of all pages for realtime
  1476. if (this.currentPage != this.pages[i] && mapping != null && mapping.needsUpdate)
  1477. {
  1478. var enc = new mxCodec(mxUtils.createXmlDocument());
  1479. var temp = enc.encode(mapping.graphModel);
  1480. // Uses the graph state from the realtime model
  1481. mapping.writeRealtimeToNode(temp);
  1482. var data = this.editor.graph.compress(this.editor.graph.zapGremlins(mxUtils.getXml(temp)));
  1483. mxUtils.setTextContent(this.pages[i].node, data);
  1484. // Marks the page as up-to-date
  1485. mapping.needsUpdate = false;
  1486. }
  1487. node.appendChild(this.pages[i].node);
  1488. }
  1489. }
  1490. }
  1491. return this.createFileData(node, this.editor.graph, this.getCurrentFile(), window.location.href,
  1492. forceXml, forceSvg, forceHtml, embeddedCallback, ignoreSelection);
  1493. };
  1494. /**
  1495. * Translates this point by the given vector.
  1496. *
  1497. * @param {number} dx X-coordinate of the translation.
  1498. * @param {number} dy Y-coordinate of the translation.
  1499. */
  1500. App.prototype.createBackground = function()
  1501. {
  1502. var bg = this.createDiv('background');
  1503. bg.style.position = 'absolute';
  1504. bg.style.background = 'white';
  1505. bg.style.left = '0px';
  1506. bg.style.top = '0px';
  1507. bg.style.bottom = '0px';
  1508. bg.style.right = '0px';
  1509. mxUtils.setOpacity(bg, 100);
  1510. if (mxClient.IS_QUIRKS)
  1511. {
  1512. new mxDivResizer(bg);
  1513. }
  1514. return bg;
  1515. };
  1516. /**
  1517. * Translates this point by the given vector.
  1518. *
  1519. * @param {number} dx X-coordinate of the translation.
  1520. * @param {number} dy Y-coordinate of the translation.
  1521. */
  1522. App.prototype.setMode = function(mode, remember)
  1523. {
  1524. this.mode = mode;
  1525. // Note: UseLocalStorage affects the file dialogs
  1526. // and should not be modified if mode is undefined
  1527. if (this.mode != null)
  1528. {
  1529. Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
  1530. }
  1531. if (typeof(Storage) != 'undefined' && remember)
  1532. {
  1533. var expiry = new Date();
  1534. expiry.setYear(expiry.getFullYear() + 1);
  1535. document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
  1536. }
  1537. if (this.appIcon != null)
  1538. {
  1539. var file = this.getCurrentFile();
  1540. var mode = (file != null) ? file.getMode() : null;
  1541. if (mode == App.MODE_GOOGLE)
  1542. {
  1543. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
  1544. this.appIcon.style.cursor = 'pointer';
  1545. }
  1546. else if (mode == App.MODE_DROPBOX)
  1547. {
  1548. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
  1549. this.appIcon.style.cursor = 'pointer';
  1550. }
  1551. else if (mode == App.MODE_ONEDRIVE)
  1552. {
  1553. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
  1554. this.appIcon.style.cursor = 'pointer';
  1555. }
  1556. else
  1557. {
  1558. this.appIcon.removeAttribute('title');
  1559. this.appIcon.style.cursor = 'default';
  1560. }
  1561. }
  1562. };
  1563. /**
  1564. * Function: authorize
  1565. *
  1566. * Authorizes the client, gets the userId and calls <open>.
  1567. */
  1568. App.prototype.appIconClicked = function(evt)
  1569. {
  1570. if (mxEvent.isAltDown(evt))
  1571. {
  1572. this.showSplash(true);
  1573. }
  1574. else
  1575. {
  1576. var file = this.getCurrentFile();
  1577. var mode = (file != null) ? file.getMode() : null;
  1578. if (mode == App.MODE_GOOGLE)
  1579. {
  1580. if (file.desc.parents.length > 0)
  1581. {
  1582. window.open('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
  1583. }
  1584. else
  1585. {
  1586. window.open('https://drive.google.com/?authuser=0');
  1587. }
  1588. }
  1589. else if (mode == App.MODE_DROPBOX)
  1590. {
  1591. window.open('https://www.dropbox.com/');
  1592. }
  1593. else if (mode == App.MODE_ONEDRIVE)
  1594. {
  1595. window.open('https://onedrive.live.com/');
  1596. }
  1597. }
  1598. mxEvent.consume(evt);
  1599. };
  1600. /**
  1601. * Function: authorize
  1602. *
  1603. * Authorizes the client, gets the userId and calls <open>.
  1604. */
  1605. App.prototype.clearMode = function()
  1606. {
  1607. if (typeof(Storage) != 'undefined')
  1608. {
  1609. var expiry = new Date();
  1610. expiry.setYear(expiry.getFullYear() - 1);
  1611. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  1612. }
  1613. };
  1614. /**
  1615. * Translates this point by the given vector.
  1616. *
  1617. * @param {number} dx X-coordinate of the translation.
  1618. * @param {number} dy Y-coordinate of the translation.
  1619. */
  1620. App.prototype.getDiagramId = function()
  1621. {
  1622. var id = window.location.hash;
  1623. // Strips the hash sign
  1624. if (id != null && id.length > 0)
  1625. {
  1626. id = id.substring(1);
  1627. }
  1628. return id;
  1629. };
  1630. /**
  1631. * Opens any file specified in the URL parameters.
  1632. */
  1633. App.prototype.open = function()
  1634. {
  1635. // Cross-domain window access is not allowed in FF, so if we
  1636. // were opened from another domain then this will fail.
  1637. try
  1638. {
  1639. // If the create URL param is used in embed mode then
  1640. // we try to open the XML from window.opener[value].
  1641. // Use this for embedding via tab to bypass the timing
  1642. // issues when passing messages without onload event.
  1643. if (window.opener != null)
  1644. {
  1645. var value = urlParams['create'];
  1646. if (value != null)
  1647. {
  1648. value = decodeURIComponent(value);
  1649. }
  1650. if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
  1651. value.substring(0, 8) != 'https://')
  1652. {
  1653. var doc = mxUtils.parseXml(window.opener[value]);
  1654. this.editor.setGraphXml(doc.documentElement);
  1655. }
  1656. else if (window.opener.openFile != null)
  1657. {
  1658. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  1659. {
  1660. this.spinner.stop();
  1661. if (filename == null)
  1662. {
  1663. var title = urlParams['title'];
  1664. if (title != null)
  1665. {
  1666. title = decodeURIComponent(title);
  1667. }
  1668. else
  1669. {
  1670. title = this.defaultFilename;
  1671. }
  1672. this.fileLoaded(new LocalFile(this, xml, title));
  1673. this.setMode(null);
  1674. }
  1675. else
  1676. {
  1677. // Replaces PNG with XML extension
  1678. var dot = filename.substring(filename.length - 4) == '.png';
  1679. if (dot > 0)
  1680. {
  1681. filename = filename.substring(0, filename.length - 4) + '.xml';
  1682. }
  1683. this.fileLoaded((mxClient.IS_IOS) ?
  1684. new StorageFile(this, xml, filename) :
  1685. new LocalFile(this, xml, filename));
  1686. }
  1687. }));
  1688. }
  1689. }
  1690. }
  1691. catch(e)
  1692. {
  1693. // ignore
  1694. }
  1695. };
  1696. /**
  1697. * Main function. Program starts here.
  1698. *
  1699. * @param {number} dx X-coordinate of the translation.
  1700. * @param {number} dy Y-coordinate of the translation.
  1701. */
  1702. App.prototype.load = function()
  1703. {
  1704. // Checks if we're running in embedded mode
  1705. if (urlParams['embed'] != '1')
  1706. {
  1707. if (this.spinner.spin(document.body, mxResources.get('starting')))
  1708. {
  1709. try
  1710. {
  1711. this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
  1712. }
  1713. catch (e)
  1714. {
  1715. // ignores invalid state args
  1716. }
  1717. this.editor.graph.setEnabled(this.getCurrentFile() != null);
  1718. // Passes the userId from the state parameter to the client
  1719. if ((window.location.hash == null || window.location.hash.length == 0) &&
  1720. this.drive != null && this.stateArg != null && this.stateArg.userId != null)
  1721. {
  1722. this.drive.setUserId(this.stateArg.userId);
  1723. }
  1724. // Legacy support for fileId parameter which is moved to the hash tag
  1725. if (urlParams['fileId'] != null)
  1726. {
  1727. window.location.hash = 'G' + urlParams['fileId'];
  1728. window.location.search = this.getSearch(['fileId']);
  1729. }
  1730. else
  1731. {
  1732. // Asynchronous or disabled loading of client
  1733. if (this.drive == null)
  1734. {
  1735. if (this.mode == App.MODE_GOOGLE)
  1736. {
  1737. this.mode = null;
  1738. }
  1739. this.start();
  1740. }
  1741. else
  1742. {
  1743. gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
  1744. {
  1745. // Starts the app without the Google Option if the API fails to load
  1746. if (gapi.drive == null || gapi.drive.realtime == null)
  1747. {
  1748. this.mode = null;
  1749. this.drive = null;
  1750. this.start();
  1751. }
  1752. else
  1753. {
  1754. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1755. {
  1756. // Needed to avoid popup blocking for non-immediate authentication
  1757. gapi.auth.init(mxUtils.bind(this, function()
  1758. {
  1759. if (gapi.client.drive == null)
  1760. {
  1761. this.mode = null;
  1762. this.drive = null;
  1763. }
  1764. this.start();
  1765. }));
  1766. }));
  1767. }
  1768. }));
  1769. }
  1770. }
  1771. }
  1772. }
  1773. else
  1774. {
  1775. this.restoreLibraries();
  1776. }
  1777. };
  1778. /**
  1779. * Called in start after the spinner stops.
  1780. */
  1781. App.prototype.showAlert = function(message)
  1782. {
  1783. if (message != null && message.length > 0)
  1784. {
  1785. var div = document.createElement('div');
  1786. div.className = 'geAlert';
  1787. div.style.zIndex = 2e9;
  1788. div.style.left = '50%';
  1789. div.style.top = '-100%';
  1790. mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
  1791. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
  1792. div.innerHTML = message;
  1793. var close = document.createElement('a');
  1794. close.className = 'geAlertLink';
  1795. close.style.textAlign = 'right';
  1796. close.style.marginTop = '20px';
  1797. close.style.display = 'block';
  1798. close.setAttribute('href', 'javascript:void(0);');
  1799. close.setAttribute('title', mxResources.get('close'));
  1800. close.innerHTML = mxResources.get('close');
  1801. div.appendChild(close);
  1802. mxEvent.addListener(close, 'click', function(evt)
  1803. {
  1804. if (div.parentNode != null)
  1805. {
  1806. div.parentNode.removeChild(div);
  1807. mxEvent.consume(evt);
  1808. }
  1809. });
  1810. document.body.appendChild(div);
  1811. // Delayed to get smoother animation after DOM rendering
  1812. window.setTimeout(function()
  1813. {
  1814. div.style.top = '30px';
  1815. }, 10);
  1816. // Fades out the alert after 15 secs
  1817. window.setTimeout(function()
  1818. {
  1819. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
  1820. div.style.opacity = '0';
  1821. window.setTimeout(function()
  1822. {
  1823. if (div.parentNode != null)
  1824. {
  1825. div.parentNode.removeChild(div);
  1826. }
  1827. }, 2000);
  1828. }, 15000);
  1829. }
  1830. };
  1831. /**
  1832. * Translates this point by the given vector.
  1833. *
  1834. * @param {number} dx X-coordinate of the translation.
  1835. * @param {number} dy Y-coordinate of the translation.
  1836. */
  1837. App.prototype.start = function()
  1838. {
  1839. this.bg.parentNode.removeChild(this.bg);
  1840. this.restoreLibraries();
  1841. this.spinner.stop();
  1842. // Uses proxy to avoid CORS issues
  1843. var loadTemplate = mxUtils.bind(this, function(url, onload, onerror)
  1844. {
  1845. this.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(url), mxUtils.bind(this, function(data)
  1846. {
  1847. if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  1848. {
  1849. // Asynchronous parsing via server
  1850. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  1851. {
  1852. if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText.substring(0, 13) == '<mxGraphModel')
  1853. {
  1854. onload(xhr.responseText);
  1855. }
  1856. }), url);
  1857. }
  1858. else
  1859. {
  1860. if (/(\.png)($|\?)/i.test(url))
  1861. {
  1862. data = this.extractGraphModelFromPng(data);
  1863. }
  1864. onload(data);
  1865. }
  1866. }), onerror, /(\.png)($|\?)/i.test(url));
  1867. });
  1868. // Listens to changes of the hash if not in embed or client mode
  1869. if (urlParams['client'] != '1' && urlParams['embed'] != '1')
  1870. {
  1871. // KNOWN: Does not work in quirks mode
  1872. mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
  1873. {
  1874. var id = this.getDiagramId();
  1875. var file = this.getCurrentFile();
  1876. if (file == null || file.getHash() != id)
  1877. {
  1878. this.loadFile(id, true);
  1879. }
  1880. }));
  1881. }
  1882. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  1883. urlParams['url'] != null && this.spinner.spin(document.body, mxResources.get('loading')))
  1884. {
  1885. try
  1886. {
  1887. var reconnect = mxUtils.bind(this, function()
  1888. {
  1889. // Removes URL parameter and reloads the page
  1890. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  1891. {
  1892. window.location.search = this.getSearch(['url']);
  1893. };
  1894. });
  1895. loadTemplate(decodeURIComponent(urlParams['url']), mxUtils.bind(this, function(text)
  1896. {
  1897. this.spinner.stop();
  1898. if (text != null && text.length > 0)
  1899. {
  1900. var filename = urlParams['title'];
  1901. if (filename == null && urlParams['notitle'] != '1')
  1902. {
  1903. var tmp = decodeURIComponent(urlParams['url']);
  1904. var slash = tmp.lastIndexOf('/');
  1905. if (slash >= 0)
  1906. {
  1907. tmp = tmp.substring(slash + 1);
  1908. }
  1909. filename = tmp;
  1910. // Replaces PNG with XML extension
  1911. var dot = filename.substring(filename.length - 4) == '.png';
  1912. if (dot > 0)
  1913. {
  1914. filename = filename.substring(0, filename.length - 4) + '.xml';
  1915. }
  1916. }
  1917. var file = new LocalFile(this, text, filename || this.defaultFilename);
  1918. this.fileLoaded(file);
  1919. this.setMode(null);
  1920. }
  1921. }), mxUtils.bind(this, function()
  1922. {
  1923. this.spinner.stop();
  1924. this.handleError({message: mxResources.get('fileNotFound')}, mxResources.get('errorLoadingFile'), reconnect);
  1925. }));
  1926. }
  1927. catch (e)
  1928. {
  1929. this.spinner.stop();
  1930. try
  1931. {
  1932. var img = new Image();
  1933. img.src = 'log?v=' + encodeURIComponent(EditorUi.VERSION) +
  1934. '&msg=errorLoadingFile:url:' + encodeURIComponent(window.location.href) +
  1935. ((e != null && e.message != null) ? ':err:' + encodeURIComponent(e.message) : '') +
  1936. ((e != null && e.stack != null) ? '&stack=' + encodeURIComponent(e.stack) : '');
  1937. }
  1938. catch (err)
  1939. {
  1940. // do nothing
  1941. }
  1942. this.handleError(e, mxResources.get('errorLoadingFile'), reconnect);
  1943. }
  1944. }
  1945. else if (this.getCurrentFile() == null)
  1946. {
  1947. var done = mxUtils.bind(this, function()
  1948. {
  1949. // Starts in client mode and waits for data
  1950. if (urlParams['client'] == '1' && (window.location.hash == null ||
  1951. window.location.hash.length == 0))
  1952. {
  1953. var parent = window.opener || window.parent;
  1954. if (parent != window)
  1955. {
  1956. this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
  1957. {
  1958. // Ignores messages from other windows
  1959. if (evt.source == parent)
  1960. {
  1961. // Extracts graph model from PNG
  1962. if (xml.substring(0, 22) == 'data:image/png;base64,')
  1963. {
  1964. xml = this.extractGraphModelFromPng(xml);
  1965. }
  1966. var title = urlParams['title'];
  1967. if (title != null)
  1968. {
  1969. title = decodeURIComponent(title);
  1970. }
  1971. else
  1972. {
  1973. title = this.defaultFilename;
  1974. }
  1975. this.fileLoaded(new LocalFile(this, xml, title));
  1976. this.getCurrentFile().setModified(!this.editor.chromeless);
  1977. this.setMode(null);
  1978. }
  1979. }));
  1980. }
  1981. }
  1982. // Checks if no earlier loading errors are showing
  1983. else if (this.dialog == null)
  1984. {
  1985. if (urlParams['demo'] == '1')
  1986. {
  1987. var prev = Editor.useLocalStorage;
  1988. this.createFile(this.defaultFilename, null, null, App.MODE_DEVICE);
  1989. this.setMode(null);
  1990. Editor.useLocalStorage = prev;
  1991. }
  1992. else
  1993. {
  1994. var waiting = false;
  1995. // Checks if we're waiting for some asynchronous file to be loaded
  1996. // Cross-domain window access is not allowed in FF, so if we
  1997. // were opened from another domain then this will fail.
  1998. try
  1999. {
  2000. waiting = window.opener != null && window.opener.openFile != null;
  2001. }
  2002. catch(e)
  2003. {
  2004. // ignore
  2005. }
  2006. if (waiting)
  2007. {
  2008. // Spinner is stopped in App.open
  2009. this.spinner.spin(document.body, mxResources.get('loading'))
  2010. }
  2011. else
  2012. {
  2013. var id = this.getDiagramId();
  2014. if (urlParams['splash'] == '0' && (id == null || id.length == 0))
  2015. {
  2016. var draft = this.getDraft();
  2017. var fileData = (draft != null) ? draft.data : this.getFileData();
  2018. var prev = Editor.useLocalStorage;
  2019. this.createFile(this.defaultFilename, fileData, null, App.MODE_DEVICE);
  2020. this.setMode(null);
  2021. Editor.useLocalStorage = prev;
  2022. // Draft was used so the user should save the file
  2023. if (draft != null)
  2024. {
  2025. var file = this.getCurrentFile();
  2026. if (file != null)
  2027. {
  2028. file.addUnsavedStatus();
  2029. }
  2030. }
  2031. }
  2032. else
  2033. {
  2034. this.loadFile(this.getDiagramId());
  2035. }
  2036. }
  2037. }
  2038. }
  2039. });
  2040. // Defines custom classes for realtime in Google Drive
  2041. if (this.drive != null)
  2042. {
  2043. this.defineCustomObjects();
  2044. }
  2045. var value = decodeURIComponent(urlParams['create'] || '');
  2046. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2047. value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
  2048. {
  2049. var reconnect = mxUtils.bind(this, function()
  2050. {
  2051. // Removes URL parameter and reloads the page
  2052. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  2053. {
  2054. window.location.search = this.getSearch(['create', 'title']);
  2055. };
  2056. });
  2057. var showCreateDialog = mxUtils.bind(this, function(xml)
  2058. {
  2059. this.spinner.stop();
  2060. // Resets mode for dialog - local file is only for preview
  2061. if (urlParams['splash'] != '0')
  2062. {
  2063. this.fileLoaded(new LocalFile(this, xml, null));
  2064. this.editor.graph.setEnabled(false);
  2065. this.mode = urlParams['mode'];
  2066. var title = urlParams['title'];
  2067. if (title != null)
  2068. {
  2069. title = decodeURIComponent(title);
  2070. }
  2071. else
  2072. {
  2073. title = this.defaultFilename;
  2074. }
  2075. var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
  2076. {
  2077. if (mode == null)
  2078. {
  2079. this.hideDialog();
  2080. var prev = Editor.useLocalStorage;
  2081. this.createFile((filename.length > 0) ? filename : this.defaultFilename,
  2082. this.getFileData(), null, App.MODE_DEVICE);
  2083. this.setMode(null);
  2084. Editor.useLocalStorage = prev;
  2085. }
  2086. else
  2087. {
  2088. this.createFile(filename, this.getFileData(true), null, mode);
  2089. }
  2090. }));
  2091. this.showDialog(dlg.container, 380, 270, true, false, mxUtils.bind(this, function(cancel)
  2092. {
  2093. if (cancel && this.getCurrentFile() == null)
  2094. {
  2095. this.showSplash();
  2096. }
  2097. }));
  2098. dlg.init();
  2099. }
  2100. });
  2101. value = decodeURIComponent(value);
  2102. if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
  2103. {
  2104. // Cross-domain window access is not allowed in FF, so if we
  2105. // were opened from another domain then this will fail.
  2106. try
  2107. {
  2108. if (window.opener != null && window.opener[value] != null)
  2109. {
  2110. showCreateDialog(window.opener[value]);
  2111. }
  2112. else
  2113. {
  2114. this.handleError(null, mxResources.get('errorLoadingFile'));
  2115. }
  2116. }
  2117. catch (e)
  2118. {
  2119. this.handleError(e, mxResources.get('errorLoadingFile'));
  2120. }
  2121. }
  2122. else
  2123. {
  2124. loadTemplate(value, function(text)
  2125. {
  2126. showCreateDialog(text);
  2127. }, mxUtils.bind(this, function()
  2128. {
  2129. this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
  2130. }));
  2131. }
  2132. }
  2133. else
  2134. {
  2135. // Passes the fileId from the state parameter to the hash tag and reloads
  2136. // the page without the state parameter
  2137. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2138. urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
  2139. {
  2140. if (this.stateArg.ids != null)
  2141. {
  2142. window.location.hash = 'G' + this.stateArg.ids[0];
  2143. }
  2144. }
  2145. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2146. this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
  2147. {
  2148. this.setMode(App.MODE_GOOGLE);
  2149. this.actions.get('new').funct();
  2150. }
  2151. else
  2152. {
  2153. done();
  2154. }
  2155. }
  2156. }
  2157. };
  2158. /**
  2159. * Translates this point by the given vector.
  2160. *
  2161. * @param {number} dx X-coordinate of the translation.
  2162. * @param {number} dy Y-coordinate of the translation.
  2163. */
  2164. App.prototype.showSplash = function(force)
  2165. {
  2166. var showSecondDialog = mxUtils.bind(this, function()
  2167. {
  2168. var dlg = new SplashDialog(this);
  2169. this.showDialog(dlg.container, 340, (mxClient.IS_CHROMEAPP) ? 180 : 260, true, true,
  2170. mxUtils.bind(this, function(cancel)
  2171. {
  2172. // Creates a blank diagram if the dialog is closed
  2173. if (cancel && !mxClient.IS_CHROMEAPP)
  2174. {
  2175. var prev = Editor.useLocalStorage;
  2176. this.createFile(this.defaultFilename, null, null, App.MODE_DEVICE);
  2177. this.setMode(null);
  2178. Editor.useLocalStorage = prev;
  2179. }
  2180. }));
  2181. dlg.init();
  2182. });
  2183. if (this.editor.chromeless)
  2184. {
  2185. this.handleError({message: mxResources.get('noFileSelected')},
  2186. mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2187. {
  2188. this.showSplash();
  2189. }));
  2190. }
  2191. else if (this.mode == null || force)
  2192. {
  2193. var dlg = new StorageDialog(this, mxUtils.bind(this, function()
  2194. {
  2195. this.hideDialog();
  2196. showSecondDialog();
  2197. }));
  2198. this.showDialog(dlg.container, (isLocalStorage && urlParams['browser'] == '1') ? 480 : 380, 300, true, false);
  2199. dlg.init();
  2200. }
  2201. else if (urlParams['create'] == null)
  2202. {
  2203. showSecondDialog();
  2204. }
  2205. };
  2206. /**
  2207. * Translates this point by the given vector.
  2208. *
  2209. * @param {number} dx X-coordinate of the translation.
  2210. * @param {number} dy Y-coordinate of the translation.
  2211. */
  2212. App.prototype.addLanguageMenu = function(elt)
  2213. {
  2214. var img = null;
  2215. if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
  2216. {
  2217. var langMenu = this.menus.get('language');
  2218. if (langMenu != null)
  2219. {
  2220. img = document.createElement('div');
  2221. img.setAttribute('title', mxResources.get('language'));
  2222. img.className = 'geIcon geSprite geSprite-globe';
  2223. img.style.position = 'absolute';
  2224. img.style.cursor = 'pointer';
  2225. img.style.bottom = '20px';
  2226. img.style.right = '20px';
  2227. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  2228. {
  2229. this.editor.graph.popupMenuHandler.hideMenu();
  2230. var menu = new mxPopupMenu(this.menus.get('language').funct);
  2231. menu.div.className += ' geMenubarMenu';
  2232. menu.smartSeparators = true;
  2233. menu.showDisabled = true;
  2234. menu.autoExpand = true;
  2235. // Disables autoexpand and destroys menu when hidden
  2236. menu.hideMenu = mxUtils.bind(this, function()
  2237. {
  2238. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  2239. menu.destroy();
  2240. });
  2241. var offset = mxUtils.getOffset(img);
  2242. menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
  2243. // Allows hiding by clicking on document
  2244. this.setCurrentMenu(menu);
  2245. }));
  2246. elt.appendChild(img);
  2247. }
  2248. }
  2249. return img;
  2250. };
  2251. /**
  2252. * Translates this point by the given vector.
  2253. *
  2254. * @param {number} dx X-coordinate of the translation.
  2255. * @param {number} dy Y-coordinate of the translation.
  2256. */
  2257. App.prototype.defineCustomObjects = function()
  2258. {
  2259. if (gapi.drive.realtime != null && gapi.drive.realtime.custom != null)
  2260. {
  2261. gapi.drive.realtime.custom.registerType(mxRtCell, 'Cell');
  2262. mxRtCell.prototype.cellId = gapi.drive.realtime.custom.collaborativeField('cellId');
  2263. mxRtCell.prototype.type = gapi.drive.realtime.custom.collaborativeField('type');
  2264. mxRtCell.prototype.value = gapi.drive.realtime.custom.collaborativeField('value');
  2265. mxRtCell.prototype.xmlValue = gapi.drive.realtime.custom.collaborativeField('xmlValue');
  2266. mxRtCell.prototype.style = gapi.drive.realtime.custom.collaborativeField('style');
  2267. mxRtCell.prototype.geometry = gapi.drive.realtime.custom.collaborativeField('geometry');
  2268. mxRtCell.prototype.visible = gapi.drive.realtime.custom.collaborativeField('visible');
  2269. mxRtCell.prototype.collapsed = gapi.drive.realtime.custom.collaborativeField('collapsed');
  2270. mxRtCell.prototype.connectable = gapi.drive.realtime.custom.collaborativeField('connectable');
  2271. mxRtCell.prototype.parent = gapi.drive.realtime.custom.collaborativeField('parent');
  2272. mxRtCell.prototype.children = gapi.drive.realtime.custom.collaborativeField('children');
  2273. mxRtCell.prototype.source = gapi.drive.realtime.custom.collaborativeField('source');
  2274. mxRtCell.prototype.target = gapi.drive.realtime.custom.collaborativeField('target');
  2275. }
  2276. };
  2277. mxRtCell = function() {};
  2278. // Ignores rtCell property in codec and cloning
  2279. mxCodecRegistry.getCodec(mxCell).exclude.push('rtCell');
  2280. mxCell.prototype.mxTransient.push('rtCell');
  2281. /**
  2282. * Translates this point by the given vector.
  2283. *
  2284. * @param {number} dx X-coordinate of the translation.
  2285. * @param {number} dy Y-coordinate of the translation.
  2286. */
  2287. App.prototype.pickFile = function(mode)
  2288. {
  2289. mode = (mode != null) ? mode : this.mode;
  2290. if (mode == App.MODE_DROPBOX)
  2291. {
  2292. if (this.dropbox != null)
  2293. {
  2294. this.dropbox.pickFile();
  2295. }
  2296. }
  2297. else if (mode == App.MODE_ONEDRIVE)
  2298. {
  2299. if (this.oneDrive != null)
  2300. {
  2301. this.oneDrive.pickFile();
  2302. }
  2303. }
  2304. else if (mode == App.MODE_GOOGLE)
  2305. {
  2306. if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2307. {
  2308. this.drive.pickFile();
  2309. }
  2310. else
  2311. {
  2312. window.open('https://drive.google.com');
  2313. }
  2314. }
  2315. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2316. {
  2317. var input = document.createElement('input');
  2318. input.setAttribute('type', 'file');
  2319. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2320. {
  2321. if (input.files != null)
  2322. {
  2323. this.openFiles(input.files);
  2324. }
  2325. }));
  2326. input.click();
  2327. }
  2328. else
  2329. {
  2330. this.hideDialog();
  2331. window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
  2332. window.baseUrl = this.getUrl();
  2333. window.openKey = 'open';
  2334. var prevValue = Editor.useLocalStorage;
  2335. Editor.useLocalStorage = (mode == App.MODE_BROWSER);
  2336. this.openFile();
  2337. // Installs local handler for opened files in same window
  2338. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2339. {
  2340. // Replaces PNG with XML extension
  2341. var dot = filename.substring(filename.length - 4) == '.png';
  2342. if (dot > 0)
  2343. {
  2344. filename = filename.substring(0, filename.length - 4) + '.xml';
  2345. }
  2346. this.fileLoaded((mode == App.MODE_BROWSER) ?
  2347. new StorageFile(this, xml, filename) :
  2348. new LocalFile(this, xml, filename));
  2349. }));
  2350. // Extends dialog close to show splash screen
  2351. var dlg = this.dialog;
  2352. var dlgClose = dlg.close;
  2353. this.dialog.close = mxUtils.bind(this, function(cancel)
  2354. {
  2355. Editor.useLocalStorage = prevValue;
  2356. dlgClose.apply(dlg, arguments);
  2357. if (this.getCurrentFile() == null)
  2358. {
  2359. this.showSplash();
  2360. }
  2361. });
  2362. }
  2363. };
  2364. /**
  2365. * Translates this point by the given vector.
  2366. *
  2367. * @param {number} dx X-coordinate of the translation.
  2368. * @param {number} dy Y-coordinate of the translation.
  2369. */
  2370. App.prototype.pickLibrary = function(mode)
  2371. {
  2372. mode = (mode != null) ? mode : this.mode;
  2373. if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE)
  2374. {
  2375. var peer = (mode == App.MODE_GOOGLE) ? this.drive : ((mode == App.MODE_ONEDRIVE) ? this.oneDrive : this.dropbox);
  2376. if (peer != null)
  2377. {
  2378. peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
  2379. {
  2380. if (optionalFile != null)
  2381. {
  2382. this.loadLibrary(optionalFile);
  2383. }
  2384. else
  2385. {
  2386. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2387. {
  2388. peer.getLibrary(id, mxUtils.bind(this, function(file)
  2389. {
  2390. this.spinner.stop();
  2391. try
  2392. {
  2393. this.loadLibrary(file);
  2394. }
  2395. catch (e)
  2396. {
  2397. this.handleError(e, mxResources.get('errorLoadingFile'));
  2398. }
  2399. }), mxUtils.bind(this, function(resp)
  2400. {
  2401. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2402. }));
  2403. }
  2404. }
  2405. }));
  2406. }
  2407. }
  2408. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2409. {
  2410. var input = document.createElement('input');
  2411. input.setAttribute('type', 'file');
  2412. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2413. {
  2414. if (input.files != null)
  2415. {
  2416. for (var i = 0; i < input.files.length; i++)
  2417. {
  2418. (mxUtils.bind(this, function(file)
  2419. {
  2420. var reader = new FileReader();
  2421. reader.onload = mxUtils.bind(this, function(e)
  2422. {
  2423. try
  2424. {
  2425. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  2426. }
  2427. catch (e)
  2428. {
  2429. this.handleError(e, mxResources.get('errorLoadingFile'));
  2430. }
  2431. });
  2432. reader.readAsText(file);
  2433. }))(input.files[i]);
  2434. }
  2435. }
  2436. }));
  2437. input.click();
  2438. }
  2439. else
  2440. {
  2441. window.openNew = false;
  2442. window.openKey = 'open';
  2443. var prevValue = Editor.useLocalStorage;
  2444. Editor.useLocalStorage = mode == App.MODE_BROWSER;
  2445. // Closes dialog after open
  2446. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2447. {
  2448. this.hideDialog(cancel);
  2449. }));
  2450. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2451. {
  2452. try
  2453. {
  2454. this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
  2455. new LocalLibrary(this, xml, filename));
  2456. }
  2457. catch (e)
  2458. {
  2459. this.handleError(e, mxResources.get('errorLoadingFile'));
  2460. }
  2461. }));
  2462. // Removes openFile if dialog is closed
  2463. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
  2464. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2465. {
  2466. Editor.useLocalStorage = prevValue;
  2467. window.openFile = null;
  2468. });
  2469. }
  2470. };
  2471. /**
  2472. * Translates this point by the given vector.
  2473. *
  2474. * @param {number} dx X-coordinate of the translation.
  2475. * @param {number} dy Y-coordinate of the translation.
  2476. */
  2477. App.prototype.createLibraryDataFromImages = function(images)
  2478. {
  2479. var doc = mxUtils.createXmlDocument();
  2480. var library = doc.createElement('mxlibrary');
  2481. mxUtils.setTextContent(library, JSON.stringify(images));
  2482. doc.appendChild(library);
  2483. return mxUtils.getXml(doc);
  2484. };
  2485. /**
  2486. * Translates this point by the given vector.
  2487. *
  2488. * @param {number} dx X-coordinate of the translation.
  2489. * @param {number} dy Y-coordinate of the translation.
  2490. */
  2491. App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  2492. {
  2493. mode = (mode != null) ? mode : this.mode;
  2494. noSpin = (noSpin != null) ? noSpin : false;
  2495. noReload = (noReload != null) ? noReload : false;
  2496. var xml = this.createLibraryDataFromImages(images);
  2497. var error = mxUtils.bind(this, function(resp)
  2498. {
  2499. this.spinner.stop();
  2500. if (fn != null)
  2501. {
  2502. fn();
  2503. }
  2504. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  2505. });
  2506. // Handles special case for local libraries
  2507. if (file == null && mode == App.MODE_DEVICE)
  2508. {
  2509. file = new LocalLibrary(this, xml, name);
  2510. }
  2511. if (file == null)
  2512. {
  2513. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2514. {
  2515. if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2516. {
  2517. this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
  2518. {
  2519. this.spinner.stop();
  2520. this.hideDialog(true);
  2521. this.libraryLoaded(newFile, images);
  2522. }), error, this.drive.libraryMimeType);
  2523. }
  2524. else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2525. {
  2526. this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2527. {
  2528. this.spinner.stop();
  2529. this.hideDialog(true);
  2530. this.libraryLoaded(newFile, images);
  2531. }), error, folderId);
  2532. }
  2533. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2534. {
  2535. this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2536. {
  2537. this.spinner.stop();
  2538. this.hideDialog(true);
  2539. this.libraryLoaded(newFile, images);
  2540. }), error, folderId);
  2541. }
  2542. else if (mode == App.MODE_BROWSER)
  2543. {
  2544. var fn = mxUtils.bind(this, function()
  2545. {
  2546. var file = new StorageLibrary(this, xml, name);
  2547. // Inserts data into local storage
  2548. file.saveFile(name, false, mxUtils.bind(this, function()
  2549. {
  2550. this.hideDialog(true);
  2551. this.libraryLoaded(file, images);
  2552. }), error);
  2553. });
  2554. if (localStorage.getItem(name) == null)
  2555. {
  2556. fn();
  2557. }
  2558. else
  2559. {
  2560. this.confirm(mxResources.get('replaceIt', [name]), fn);
  2561. }
  2562. }
  2563. else
  2564. {
  2565. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  2566. }
  2567. }));
  2568. }
  2569. else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
  2570. {
  2571. file.setData(xml);
  2572. var doSave = mxUtils.bind(this, function()
  2573. {
  2574. file.save(true, mxUtils.bind(this, function(resp)
  2575. {
  2576. this.spinner.stop();
  2577. this.hideDialog(true);
  2578. if (!noReload)
  2579. {
  2580. this.libraryLoaded(file, images);
  2581. }
  2582. if (fn != null)
  2583. {
  2584. fn();
  2585. }
  2586. }), error);
  2587. });
  2588. if (name != file.getTitle())
  2589. {
  2590. var oldHash = file.getHash();
  2591. file.rename(name, mxUtils.bind(this, function(resp)
  2592. {
  2593. // Change hash in stored settings
  2594. if (file.constructor != LocalLibrary && oldHash != file.getHash())
  2595. {
  2596. mxSettings.removeCustomLibrary(oldHash);
  2597. mxSettings.addCustomLibrary(file.getHash());
  2598. }
  2599. // Workaround for library files changing hash so
  2600. // the old library cannot be removed from the
  2601. // sidebar using the updated file in libraryLoaded
  2602. this.removeLibrarySidebar(oldHash);
  2603. doSave();
  2604. }), error)
  2605. }
  2606. else
  2607. {
  2608. doSave();
  2609. }
  2610. }
  2611. };
  2612. /**
  2613. * Adds the label menu items to the given menu and parent.
  2614. */
  2615. App.prototype.saveFile = function(forceDialog)
  2616. {
  2617. var file = this.getCurrentFile();
  2618. if (file != null)
  2619. {
  2620. // FIXME: Invoke for local files
  2621. var done = mxUtils.bind(this, function()
  2622. {
  2623. this.removeDraft();
  2624. // Workaround for possible status update while save as dialog is showing
  2625. // is to show no saved status for device files
  2626. if (file.getMode() != App.MODE_DEVICE)
  2627. {
  2628. this.editor.setStatus(mxResources.get('allChangesSaved'));
  2629. }
  2630. else
  2631. {
  2632. this.editor.setStatus('');
  2633. }
  2634. });
  2635. if (!forceDialog && file.getTitle() != null && this.mode != null)
  2636. {
  2637. this.save(file.getTitle(), done);
  2638. }
  2639. else
  2640. {
  2641. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  2642. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2643. var prev = this.mode;
  2644. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
  2645. {
  2646. if (name != null && name.length > 0)
  2647. {
  2648. if (prev == null && mode == App.MODE_DEVICE)
  2649. {
  2650. this.setMode(App.MODE_DEVICE);
  2651. this.save(name, done);
  2652. }
  2653. else if (mode == 'download')
  2654. {
  2655. var tmp = new LocalFile(this, null, name);
  2656. tmp.save();
  2657. }
  2658. else if (mode == '_blank')
  2659. {
  2660. window.openFile = new OpenFile(function()
  2661. {
  2662. window.openFile = null;
  2663. });
  2664. // Do not use a filename to use undefined mode
  2665. window.openFile.setData(this.getFileData(true));
  2666. window.open(this.getUrl(window.location.pathname));
  2667. }
  2668. else if (prev != mode)
  2669. {
  2670. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2671. {
  2672. this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
  2673. name.indexOf('.') < 0, /(\.svg)$/i.test(name),
  2674. /(\.html)$/i.test(name)), null, mode, done,
  2675. this.mode == null, folderId);
  2676. }));
  2677. }
  2678. else if (mode != null)
  2679. {
  2680. this.save(name, done);
  2681. }
  2682. }
  2683. }), mxUtils.bind(this, function()
  2684. {
  2685. this.hideDialog();
  2686. }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
  2687. (this.isOffline()) ? null : 'https://support.draw.io/questions/9338901', true);
  2688. this.showDialog(dlg.container, 440, 380, true, true);
  2689. dlg.init();
  2690. }
  2691. }
  2692. };
  2693. /**
  2694. * Translates this point by the given vector.
  2695. *
  2696. * @param {number} dx X-coordinate of the translation.
  2697. * @param {number} dy Y-coordinate of the translation.
  2698. */
  2699. App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId)
  2700. {
  2701. mode = (mode != null) ? mode : this.mode;
  2702. if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2703. {
  2704. data = (data != null) ? data : this.emptyDiagramXml;
  2705. var error = mxUtils.bind(this, function(resp)
  2706. {
  2707. this.spinner.stop();
  2708. if (resp == null && this.getCurrentFile() == null && this.dialog == null)
  2709. {
  2710. this.showSplash();
  2711. }
  2712. else if (resp != null)
  2713. {
  2714. this.handleError(resp);
  2715. }
  2716. });
  2717. if (mode == App.MODE_GOOGLE && this.drive != null)
  2718. {
  2719. folderId = (this.stateArg != null) ? this.stateArg.folderId : folderId;
  2720. this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
  2721. {
  2722. this.spinner.stop();
  2723. this.fileCreated(file, libs, replace, done);
  2724. }), error);
  2725. }
  2726. else if (mode == App.MODE_DROPBOX && this.dropbox != null)
  2727. {
  2728. this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
  2729. {
  2730. this.spinner.stop();
  2731. this.fileCreated(file, libs, replace, done);
  2732. }), error);
  2733. }
  2734. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  2735. {
  2736. this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
  2737. {
  2738. this.spinner.stop();
  2739. this.fileCreated(file, libs, replace, done);
  2740. }), error, false, folderId);
  2741. }
  2742. else if (mode == App.MODE_BROWSER)
  2743. {
  2744. this.spinner.stop();
  2745. var fn = mxUtils.bind(this, function()
  2746. {
  2747. var file = new StorageFile(this, data, title);
  2748. // Inserts data into local storage
  2749. file.saveFile(title, false, mxUtils.bind(this, function()
  2750. {
  2751. this.fileCreated(file, libs, replace, done);
  2752. }), error);
  2753. });
  2754. if (localStorage.getItem(title) == null)
  2755. {
  2756. fn();
  2757. }
  2758. else
  2759. {
  2760. this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
  2761. {
  2762. if (this.getCurrentFile() == null && this.dialog == null)
  2763. {
  2764. this.showSplash();
  2765. }
  2766. }));
  2767. }
  2768. }
  2769. else
  2770. {
  2771. this.spinner.stop();
  2772. this.fileCreated(new LocalFile(this, data, title), libs, replace, done);
  2773. }
  2774. }
  2775. };
  2776. /**
  2777. * Translates this point by the given vector.
  2778. *
  2779. * @param {number} dx X-coordinate of the translation.
  2780. * @param {number} dy Y-coordinate of the translation.
  2781. */
  2782. App.prototype.fileCreated = function(file, libs, replace, done)
  2783. {
  2784. var url = window.location.pathname;
  2785. if (libs != null && libs.length > 0)
  2786. {
  2787. url += '?libs=' + libs;
  2788. }
  2789. url = this.getUrl(url);
  2790. // Always opens a new tab for local files to avoid losing changes
  2791. if (file.getMode() != App.MODE_DEVICE)
  2792. {
  2793. url += '#' + file.getHash();
  2794. }
  2795. // Makes sure to produce consistent output with finalized files via createFileData this needs
  2796. // to save the file again since it needs the newly created file ID for redirecting in HTML
  2797. if (this.spinner.spin(document.body, mxResources.get('inserting')))
  2798. {
  2799. var data = file.getData();
  2800. file.setData(this.createFileData((data.length > 0) ?
  2801. this.editor.extractGraphModel(mxUtils.parseXml(data).documentElement, true) : null,
  2802. null, file, window.location.protocol + '//' + window.location.hostname + url));
  2803. var fn = mxUtils.bind(this, function()
  2804. {
  2805. this.spinner.stop();
  2806. var fn2 = mxUtils.bind(this, function()
  2807. {
  2808. window.openFile = null;
  2809. this.fileLoaded(file);
  2810. if (libs != null)
  2811. {
  2812. this.sidebar.showEntries(libs);
  2813. }
  2814. if (done != null)
  2815. {
  2816. done();
  2817. }
  2818. });
  2819. // Updates the file if it has been overwritten
  2820. if (!replace && this.getCurrentFile() != null && this.mode != null)
  2821. {
  2822. // Opens local file in a new window
  2823. if (file.constructor == LocalFile)
  2824. {
  2825. window.openFile = new OpenFile(function()
  2826. {
  2827. window.openFile = null;
  2828. });
  2829. window.openFile.setData(file.getData(), file.getTitle());
  2830. }
  2831. window.openWindow(url, null, fn2);
  2832. }
  2833. else
  2834. {
  2835. fn2();
  2836. }
  2837. });
  2838. // Updates data in memory for local files and save is implicit
  2839. // via start of realtime for DriveFiles
  2840. if (file.constructor == LocalFile || file.constructor == DriveFile)
  2841. {
  2842. fn();
  2843. }
  2844. else
  2845. {
  2846. file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
  2847. {
  2848. fn();
  2849. }), mxUtils.bind(this, function(resp)
  2850. {
  2851. this.spinner.stop();
  2852. this.handleError(resp);
  2853. }));
  2854. }
  2855. }
  2856. };
  2857. /**
  2858. * Translates this point by the given vector.
  2859. *
  2860. * @param {number} dx X-coordinate of the translation.
  2861. * @param {number} dy Y-coordinate of the translation.
  2862. */
  2863. App.prototype.loadFile = function(id, sameWindow, file)
  2864. {
  2865. this.hideDialog();
  2866. var fn = mxUtils.bind(this, function()
  2867. {
  2868. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2869. {
  2870. // Handles files from localStorage
  2871. if (id.charAt(0) == 'L')
  2872. {
  2873. this.spinner.stop();
  2874. if (!isLocalStorage)
  2875. {
  2876. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2877. {
  2878. var file = this.getCurrentFile();
  2879. window.location.hash = (file != null) ? file.getHash() : '';
  2880. }));
  2881. }
  2882. else
  2883. {
  2884. try
  2885. {
  2886. id = decodeURIComponent(id.substring(1));
  2887. var data = localStorage.getItem(id);
  2888. if (data != null)
  2889. {
  2890. this.fileLoaded(new StorageFile(this, data, id));
  2891. }
  2892. else
  2893. {
  2894. throw {message: mxResources.get('fileNotFound')};
  2895. }
  2896. }
  2897. catch (e)
  2898. {
  2899. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2900. {
  2901. var file = this.getCurrentFile();
  2902. window.location.hash = (file != null) ? file.getHash() : '';
  2903. }));
  2904. }
  2905. }
  2906. }
  2907. else if (file != null)
  2908. {
  2909. // File already loaded
  2910. this.spinner.stop();
  2911. this.fileLoaded(file);
  2912. }
  2913. else
  2914. {
  2915. // Google Drive files are handled as default file types
  2916. var peer = null;
  2917. if (id.charAt(0) == 'G')
  2918. {
  2919. peer = this.drive;
  2920. }
  2921. else if (id.charAt(0) == 'D')
  2922. {
  2923. peer = this.dropbox;
  2924. }
  2925. else if (id.charAt(0) == 'W')
  2926. {
  2927. peer = this.oneDrive;
  2928. }
  2929. id = decodeURIComponent(id.substring(1));
  2930. if (peer == null)
  2931. {
  2932. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2933. {
  2934. var file = this.getCurrentFile();
  2935. window.location.hash = (file != null) ? file.getHash() : '';
  2936. }));
  2937. }
  2938. else
  2939. {
  2940. peer.getFile(id, mxUtils.bind(this, function(file)
  2941. {
  2942. this.spinner.stop();
  2943. this.fileLoaded(file);
  2944. }), mxUtils.bind(this, function(resp)
  2945. {
  2946. // Makes sure the file does not save the invalid UI model and overwrites anything important
  2947. if (window.console != null && resp != null)
  2948. {
  2949. console.log('error in loadFile:', id, resp);
  2950. }
  2951. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
  2952. {
  2953. var file = this.getCurrentFile();
  2954. if (file == null)
  2955. {
  2956. window.location.hash = '';
  2957. this.showSplash();
  2958. }
  2959. else
  2960. {
  2961. window.location.hash = file.getHash();
  2962. }
  2963. }));
  2964. }));
  2965. }
  2966. }
  2967. }
  2968. });
  2969. if (id == null || id.length == 0)
  2970. {
  2971. this.editor.setStatus('');
  2972. this.fileLoaded(null);
  2973. }
  2974. else if (this.getCurrentFile() != null && !this.isDiagramEmpty() && !sameWindow)
  2975. {
  2976. window.openWindow(this.getUrl() + '#' + id, null, fn);
  2977. }
  2978. else
  2979. {
  2980. fn();
  2981. }
  2982. };
  2983. /**
  2984. * Translates this point by the given vector.
  2985. *
  2986. * @param {number} dx X-coordinate of the translation.
  2987. * @param {number} dy Y-coordinate of the translation.
  2988. */
  2989. App.prototype.loadLibrary = function(file)
  2990. {
  2991. var doc = mxUtils.parseXml(file.getData());
  2992. if (doc.documentElement.nodeName == 'mxlibrary')
  2993. {
  2994. var images = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  2995. this.libraryLoaded(file, images);
  2996. }
  2997. else
  2998. {
  2999. throw {message: mxResources.get('notALibraryFile')};
  3000. }
  3001. };
  3002. /**
  3003. * Translates this point by the given vector.
  3004. *
  3005. * @param {number} dx X-coordinate of the translation.
  3006. * @param {number} dy Y-coordinate of the translation.
  3007. */
  3008. App.prototype.removeLibrarySidebar = function(id)
  3009. {
  3010. var elts = this.sidebar.palettes[id];
  3011. if (elts != null)
  3012. {
  3013. for (var i = 0; i < elts.length; i++)
  3014. {
  3015. elts[i].parentNode.removeChild(elts[i]);
  3016. }
  3017. delete this.sidebar.palettes[id];
  3018. }
  3019. };
  3020. /**
  3021. * Translates this point by the given vector.
  3022. *
  3023. * @param {number} dx X-coordinate of the translation.
  3024. * @param {number} dy Y-coordinate of the translation.
  3025. */
  3026. App.prototype.getLibraryStorageHint = function(file)
  3027. {
  3028. var tip = '';
  3029. if (file.constructor != LocalLibrary)
  3030. {
  3031. tip += file.getHash();
  3032. }
  3033. if (file.constructor == DriveLibrary)
  3034. {
  3035. tip += ' (' + mxResources.get('googleDrive') + ')';
  3036. }
  3037. else if (file.constructor == DropboxLibrary)
  3038. {
  3039. tip += ' (' + mxResources.get('dropbox') + ')';
  3040. }
  3041. else if (file.constructor == OneDriveLibrary)
  3042. {
  3043. tip += ' (' + mxResources.get('oneDrive') + ')';
  3044. }
  3045. else if (file.constructor == StorageLibrary)
  3046. {
  3047. tip += ' (' + mxResources.get('browser') + ')';
  3048. }
  3049. else if (file.constructor == LocalLibrary)
  3050. {
  3051. tip += ' (' + mxResources.get('device') + ')';
  3052. }
  3053. return tip;
  3054. };
  3055. /**
  3056. * Translates this point by the given vector.
  3057. *
  3058. * @param {number} dx X-coordinate of the translation.
  3059. * @param {number} dy Y-coordinate of the translation.
  3060. */
  3061. App.prototype.closeLibrary = function(file)
  3062. {
  3063. if (file != null)
  3064. {
  3065. this.removeLibrarySidebar(file.getHash());
  3066. if (file.constructor != LocalLibrary)
  3067. {
  3068. mxSettings.removeCustomLibrary(file.getHash());
  3069. }
  3070. if (file.title == '.scratchpad')
  3071. {
  3072. this.scratchpad = null;
  3073. }
  3074. }
  3075. };
  3076. /**
  3077. * Changes the position of the library in the sidebar
  3078. */
  3079. App.prototype.repositionLibrary = function(nextChild)
  3080. {
  3081. var c = this.sidebar.container;
  3082. nextChild = (nextChild != null) ? nextChild : c.firstChild.nextSibling.nextSibling;
  3083. var content = c.lastChild;
  3084. var title = content.previousSibling;
  3085. c.insertBefore(content, nextChild);
  3086. c.insertBefore(title, content);
  3087. }
  3088. /**
  3089. * Translates this point by the given vector.
  3090. *
  3091. * @param {number} dx X-coordinate of the translation.
  3092. * @param {number} dy Y-coordinate of the translation.
  3093. */
  3094. App.prototype.toggleScratchpad = function()
  3095. {
  3096. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3097. {
  3098. if (this.scratchpad == null)
  3099. {
  3100. this.getLocalData('.scratchpad', mxUtils.bind(this, function(xml)
  3101. {
  3102. if (xml == null)
  3103. {
  3104. xml = this.emptyLibraryXml;
  3105. }
  3106. this.loadLibrary(new StorageLibrary(this, xml, '.scratchpad'));
  3107. }));
  3108. }
  3109. else
  3110. {
  3111. this.closeLibrary(this.scratchpad);
  3112. }
  3113. }
  3114. };
  3115. /**
  3116. * Translates this point by the given vector.
  3117. *
  3118. * @param {number} dx X-coordinate of the translation.
  3119. * @param {number} dy Y-coordinate of the translation.
  3120. */
  3121. App.prototype.libraryLoaded = function(file, images)
  3122. {
  3123. if (file.constructor != LocalLibrary)
  3124. {
  3125. mxSettings.addCustomLibrary(file.getHash());
  3126. }
  3127. if (file.title == '.scratchpad')
  3128. {
  3129. this.scratchpad = file;
  3130. }
  3131. var elts = this.sidebar.palettes[file.getHash()];
  3132. var nextSibling = (elts != null) ? elts[elts.length - 1].nextSibling : null;
  3133. // Removes existing sidebar entry for this library
  3134. this.removeLibrarySidebar(file.getHash());
  3135. var dropTarget = null;
  3136. var addImages = mxUtils.bind(this, function(imgs, content)
  3137. {
  3138. if (imgs.length == 0 && file.isEditable())
  3139. {
  3140. if (dropTarget == null)
  3141. {
  3142. dropTarget = document.createElement('div');
  3143. mxUtils.setPrefixedStyle(dropTarget.style, 'borderRadius', '6px');
  3144. dropTarget.style.border = '3px dotted lightGray';
  3145. dropTarget.style.textAlign = 'center';
  3146. dropTarget.style.padding = '8px';
  3147. dropTarget.style.color = '#B3B3B3';
  3148. mxUtils.write(dropTarget, mxResources.get('dragElementsHere'));
  3149. }
  3150. content.appendChild(dropTarget);
  3151. }
  3152. else
  3153. {
  3154. for (var i = 0; i < imgs.length; i++)
  3155. {
  3156. var img = imgs[i];
  3157. var data = img.data;
  3158. if (data != null)
  3159. {
  3160. data = this.convertDataUri(data);
  3161. var s = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;';
  3162. if (img.aspect == 'fixed')
  3163. {
  3164. s += 'aspect=fixed;'
  3165. }
  3166. else
  3167. {
  3168. s += 'imageAspect=0;'
  3169. }
  3170. content.appendChild(this.sidebar.createVertexTemplate(s + 'image=' +
  3171. data, img.w, img.h, '', img.title || '', false, false, false));
  3172. }
  3173. else if (img.xml != null)
  3174. {
  3175. var cells = this.stringToCells(this.editor.graph.decompress(img.xml));
  3176. if (cells.length > 0)
  3177. {
  3178. content.appendChild(this.sidebar.createVertexTemplateFromCells(
  3179. cells, img.w, img.h, img.title || '', true, false, false));
  3180. }
  3181. }
  3182. }
  3183. }
  3184. });
  3185. // Adds new sidebar entry for this library
  3186. var contentDiv = this.sidebar.addPalette(file.getHash(), file.getTitle(), true, mxUtils.bind(this, function(content)
  3187. {
  3188. addImages(images, content);
  3189. }));
  3190. this.repositionLibrary(nextSibling);
  3191. // Adds tooltip for backend
  3192. var title = contentDiv.parentNode.previousSibling;
  3193. var tip = title.getAttribute('title');
  3194. if (tip != null && tip.length > 0 && file.title != '.scratchpad')
  3195. {
  3196. title.setAttribute('title', this.getLibraryStorageHint(file) + '\n' + tip);
  3197. }
  3198. var buttons = document.createElement('div');
  3199. buttons.style.position = 'absolute';
  3200. buttons.style.right = '0px';
  3201. buttons.style.top = '5px';
  3202. title.style.position = 'relative';
  3203. var btn = document.createElement('img');
  3204. btn.setAttribute('src', Dialog.prototype.closeImage);
  3205. btn.setAttribute('title', mxResources.get('close'));
  3206. btn.setAttribute('align', 'top');
  3207. btn.setAttribute('border', '0');
  3208. btn.style.cursor = 'pointer';
  3209. btn.style.marginRight = '8px';
  3210. btn.style.marginTop = '3px';
  3211. buttons.appendChild(btn);
  3212. var saveBtn = null;
  3213. mxEvent.addListener(btn, 'click', mxUtils.bind(this, function(evt)
  3214. {
  3215. // Workaround for close after any button click in IE8/quirks
  3216. if (!mxEvent.isConsumed(evt))
  3217. {
  3218. var fn = mxUtils.bind(this, function()
  3219. {
  3220. this.closeLibrary(file);
  3221. });
  3222. if (saveBtn != null)
  3223. {
  3224. this.confirm(mxResources.get('allChangesLost'), fn);
  3225. }
  3226. else
  3227. {
  3228. fn();
  3229. }
  3230. mxEvent.consume(evt);
  3231. }
  3232. }));
  3233. // Shows tooltip if mouse over background
  3234. mxEvent.addListener(contentDiv, 'mousemove', mxUtils.bind(this, function(evt)
  3235. {
  3236. if (mxEvent.getSource(evt) == contentDiv)
  3237. {
  3238. contentDiv.setAttribute('title', mxResources.get('libraryTooltip'));
  3239. }
  3240. else
  3241. {
  3242. contentDiv.removeAttribute('title');
  3243. }
  3244. }));
  3245. if (file.isEditable())
  3246. {
  3247. var graph = this.editor.graph;
  3248. var editLibrary = mxUtils.bind(this, function(evt)
  3249. {
  3250. this.showLibraryDialog(file.getTitle(), contentDiv, images, file, file.getMode());
  3251. mxEvent.consume(evt);
  3252. });
  3253. var saveLibrary = mxUtils.bind(this, function(evt)
  3254. {
  3255. if (file.constructor != LocalLibrary || file.isAutosave())
  3256. {
  3257. if (spinBtn != null && spinBtn.parentNode != null)
  3258. {
  3259. spinBtn.parentNode.removeChild(spinBtn);
  3260. }
  3261. spinBtn = btn.cloneNode(false);
  3262. spinBtn.setAttribute('src', App.prototype.spinImage);
  3263. spinBtn.setAttribute('title', mxResources.get('saving'));
  3264. spinBtn.style.cursor = 'default';
  3265. spinBtn.style.marginRight = '6px';
  3266. spinBtn.style.marginTop = '2px';
  3267. buttons.insertBefore(spinBtn, buttons.firstChild);
  3268. this.saveLibrary(file.getTitle(), images, file, file.getMode(), true, true, function()
  3269. {
  3270. if (spinBtn != null && spinBtn.parentNode != null)
  3271. {
  3272. spinBtn.parentNode.removeChild(spinBtn);
  3273. }
  3274. });
  3275. }
  3276. else if (saveBtn == null)
  3277. {
  3278. saveBtn = btn.cloneNode(false);
  3279. saveBtn.setAttribute('src', IMAGE_PATH + '/download.png');
  3280. saveBtn.setAttribute('title', mxResources.get('save'));
  3281. buttons.insertBefore(saveBtn, buttons.firstChild);
  3282. mxEvent.addListener(saveBtn, 'click', mxUtils.bind(this, function(evt)
  3283. {
  3284. this.saveLibrary(file.getTitle(), images, file, file.getMode(), true, true);
  3285. saveBtn.parentNode.removeChild(saveBtn);
  3286. saveBtn = null;
  3287. mxEvent.consume(evt);
  3288. }));
  3289. }
  3290. });
  3291. var addCells = mxUtils.bind(this, function(cells, bounds, evt, title)
  3292. {
  3293. cells = graph.cloneCells(graph.model.getTopmostCells(cells));
  3294. // Translates cells to origin
  3295. for (var i = 0; i < cells.length; i++)
  3296. {
  3297. var geo = graph.getCellGeometry(cells[i]);
  3298. if (geo != null)
  3299. {
  3300. geo.translate(-bounds.x, -bounds.y);
  3301. }
  3302. }
  3303. contentDiv.appendChild(this.sidebar.createVertexTemplateFromCells(
  3304. cells, bounds.width, bounds.height, title || '', true, false, false));
  3305. var xml = this.editor.graph.compress(mxUtils.getXml(this.editor.graph.encodeCells(cells)));
  3306. var entry = {xml: xml, w: bounds.width, h: bounds.height};
  3307. if (title != null)
  3308. {
  3309. entry.title = title;
  3310. }
  3311. images.push(entry);
  3312. saveLibrary(evt);
  3313. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  3314. {
  3315. dropTarget.parentNode.removeChild(dropTarget);
  3316. dropTarget = null;
  3317. }
  3318. });
  3319. var addSelection = mxUtils.bind(this, function(evt)
  3320. {
  3321. if (!graph.isSelectionEmpty())
  3322. {
  3323. var cells = graph.getSelectionCells();
  3324. var bounds = graph.view.getBounds(cells);
  3325. var s = graph.view.scale;
  3326. bounds.x /= s;
  3327. bounds.y /= s;
  3328. bounds.width /= s;
  3329. bounds.height /= s;
  3330. bounds.x -= graph.view.translate.x;
  3331. bounds.y -= graph.view.translate.y;
  3332. addCells(cells, bounds);
  3333. }
  3334. else
  3335. {
  3336. this.showError(mxResources.get('error'), mxResources.get('nothingIsSelected'), mxResources.get('ok'));
  3337. }
  3338. mxEvent.consume(evt);
  3339. });
  3340. // Defines inactive border state
  3341. contentDiv.style.border = '3px solid transparent';
  3342. // Adds drop handler from graph
  3343. mxEvent.addGestureListeners(contentDiv, function(){}, mxUtils.bind(this, function(evt)
  3344. {
  3345. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler.shape != null)
  3346. {
  3347. graph.graphHandler.shape.node.style.visibility = 'hidden';
  3348. if (dropTarget != null)
  3349. {
  3350. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  3351. }
  3352. else
  3353. {
  3354. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  3355. }
  3356. contentDiv.style.cursor = 'copy';
  3357. graph.panningManager.stop();
  3358. graph.autoScroll = false;
  3359. if (graph.graphHandler.guide != null)
  3360. {
  3361. graph.graphHandler.guide.setVisible(false);
  3362. }
  3363. if (graph.graphHandler.hint != null)
  3364. {
  3365. graph.graphHandler.hint.style.visibility = 'hidden';
  3366. }
  3367. mxEvent.consume(evt);
  3368. }
  3369. }), mxUtils.bind(this, function(evt)
  3370. {
  3371. if (graph.isMouseDown && graph.panningManager != null && graph.graphHandler != null)
  3372. {
  3373. contentDiv.style.border = '3px solid transparent';
  3374. if (dropTarget != null)
  3375. {
  3376. dropTarget.style.border = '3px dotted lightGray';
  3377. }
  3378. contentDiv.style.cursor = 'default';
  3379. this.sidebar.showTooltips = true;
  3380. graph.panningManager.stop();
  3381. graph.graphHandler.reset();
  3382. graph.isMouseDown = false;
  3383. graph.autoScroll = true;
  3384. addSelection(evt);
  3385. mxEvent.consume(evt);
  3386. }
  3387. }));
  3388. // Handles mouse leaving the library and restoring move
  3389. mxEvent.addListener(contentDiv, 'mouseleave', mxUtils.bind(this, function(evt)
  3390. {
  3391. if (graph.isMouseDown && graph.graphHandler.shape != null)
  3392. {
  3393. graph.graphHandler.shape.node.style.visibility = 'visible';
  3394. contentDiv.style.border = '3px solid transparent';
  3395. contentDiv.style.cursor = '';
  3396. graph.autoScroll = true;
  3397. if (graph.graphHandler.guide != null)
  3398. {
  3399. graph.graphHandler.guide.setVisible(true);
  3400. }
  3401. if (graph.graphHandler.hint != null)
  3402. {
  3403. graph.graphHandler.hint.style.visibility = 'visible';
  3404. }
  3405. if (dropTarget != null)
  3406. {
  3407. dropTarget.style.border = '3px dotted lightGray';
  3408. }
  3409. }
  3410. }));
  3411. // Adds drop handler from filesystem
  3412. if (Graph.fileSupport)
  3413. {
  3414. mxEvent.addListener(contentDiv, 'dragover', mxUtils.bind(this, function(evt)
  3415. {
  3416. if (dropTarget != null)
  3417. {
  3418. dropTarget.style.border = '3px dotted rgb(254, 137, 12)';
  3419. }
  3420. else
  3421. {
  3422. contentDiv.style.border = '3px dotted rgb(254, 137, 12)';
  3423. }
  3424. evt.dataTransfer.dropEffect = 'copy';
  3425. contentDiv.style.cursor = 'copy';
  3426. this.sidebar.hideTooltip();
  3427. evt.stopPropagation();
  3428. evt.preventDefault();
  3429. }));
  3430. mxEvent.addListener(contentDiv, 'drop', mxUtils.bind(this, function(evt)
  3431. {
  3432. contentDiv.style.border = '3px solid transparent';
  3433. contentDiv.style.cursor = '';
  3434. if (dropTarget != null)
  3435. {
  3436. dropTarget.style.border = '3px dotted lightGray';
  3437. }
  3438. if (evt.dataTransfer.files.length > 0)
  3439. {
  3440. this.importFiles(evt.dataTransfer.files, 0, 0, this.maxImageSize, mxUtils.bind(this, function(data, mimeType, x, y, w, h, img)
  3441. {
  3442. if (data != null && mimeType.substring(0, 6) == 'image/')
  3443. {
  3444. var style = 'shape=image;verticalLabelPosition=bottom;verticalAlign=top;aspect=fixed;image=' +
  3445. this.convertDataUri(data);
  3446. var cells = [new mxCell('', new mxGeometry(0, 0, w, h), style)];
  3447. cells[0].vertex = true;
  3448. addCells(cells, new mxRectangle(0, 0, w, h), evt, (mxEvent.isAltDown(evt)) ? null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  3449. }
  3450. else
  3451. {
  3452. var done = false;
  3453. if (data != null && mimeType == 'text/xml')
  3454. {
  3455. var doc = mxUtils.parseXml(data);
  3456. if (doc.documentElement.nodeName == 'mxlibrary')
  3457. {
  3458. try
  3459. {
  3460. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  3461. addImages(temp, contentDiv);
  3462. images = images.concat(temp);
  3463. saveLibrary(evt);
  3464. this.spinner.stop();
  3465. done = true;
  3466. }
  3467. catch (e)
  3468. {
  3469. // ignore
  3470. }
  3471. }
  3472. else if (doc.documentElement.nodeName == 'mxfile')
  3473. {
  3474. try
  3475. {
  3476. var temp = mxUtils.getTextContent(doc.documentElement.getElementsByTagName('diagram')[0]);
  3477. var cells = this.stringToCells(this.editor.graph.decompress(temp));
  3478. addCells(cells, new mxRectangle(0, 0, w, h), evt);
  3479. done = true;
  3480. }
  3481. catch (e)
  3482. {
  3483. // ignore
  3484. }
  3485. }
  3486. }
  3487. if (!done)
  3488. {
  3489. this.spinner.stop();
  3490. this.handleError({message: mxResources.get('errorLoadingFile')})
  3491. }
  3492. }
  3493. if (dropTarget != null && dropTarget.parentNode != null && images.length > 0)
  3494. {
  3495. dropTarget.parentNode.removeChild(dropTarget);
  3496. dropTarget = null;
  3497. }
  3498. }));
  3499. }
  3500. evt.stopPropagation();
  3501. evt.preventDefault();
  3502. }));
  3503. mxEvent.addListener(contentDiv, 'dragleave', function(evt)
  3504. {
  3505. if (dropTarget != null)
  3506. {
  3507. dropTarget.style.border = '3px dotted lightGray';
  3508. }
  3509. else
  3510. {
  3511. contentDiv.style.border = '3px solid transparent';
  3512. contentDiv.style.cursor = '';
  3513. }
  3514. evt.stopPropagation();
  3515. evt.preventDefault();
  3516. });
  3517. }
  3518. btn = btn.cloneNode(false);
  3519. btn.setAttribute('src', IMAGE_PATH + '/edit.gif');
  3520. btn.setAttribute('title', mxResources.get('edit'));
  3521. buttons.insertBefore(btn, buttons.firstChild);
  3522. mxEvent.addListener(btn, 'click', editLibrary);
  3523. mxEvent.addListener(contentDiv, 'dblclick', function(evt)
  3524. {
  3525. if (mxEvent.getSource(evt) == contentDiv)
  3526. {
  3527. editLibrary(evt);
  3528. }
  3529. });
  3530. btn = btn.cloneNode(false);
  3531. btn.setAttribute('src', App.prototype.plusImage);
  3532. btn.setAttribute('title', mxResources.get('add'));
  3533. buttons.insertBefore(btn, buttons.firstChild);
  3534. if (!this.isOffline())
  3535. {
  3536. var link = document.createElement('span');
  3537. link.setAttribute('title', mxResources.get('help'));
  3538. link.style.cssText = 'color:gray;text-decoration:none;margin-right:8px;';
  3539. mxUtils.write(link, '?');
  3540. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  3541. {
  3542. window.open('https://support.draw.io/questions/10420280');
  3543. mxEvent.consume(evt);
  3544. }));
  3545. buttons.insertBefore(link, buttons.firstChild);
  3546. }
  3547. var spinBtn = null;
  3548. mxEvent.addListener(btn, 'click', addSelection);
  3549. }
  3550. title.appendChild(buttons);
  3551. };
  3552. /**
  3553. * Translates this point by the given vector.
  3554. *
  3555. * @param {number} dx X-coordinate of the translation.
  3556. * @param {number} dy Y-coordinate of the translation.
  3557. */
  3558. App.prototype.fileLoaded = function(file)
  3559. {
  3560. this.hideDialog();
  3561. var oldFile = this.getCurrentFile();
  3562. this.setCurrentFile(null);
  3563. if (oldFile != null)
  3564. {
  3565. oldFile.removeListener(this.descriptorChangedListener);
  3566. oldFile.close();
  3567. }
  3568. this.editor.graph.model.clear();
  3569. this.editor.undoManager.clear();
  3570. var noFile = mxUtils.bind(this, function()
  3571. {
  3572. this.diagramContainer.style.visibility = 'hidden';
  3573. this.formatContainer.style.visibility = 'hidden';
  3574. this.hsplit.style.display = 'none';
  3575. this.sidebarContainer.style.display = 'none';
  3576. this.sidebarFooterContainer.style.display = 'none';
  3577. this.editor.graph.setEnabled(false);
  3578. // Keeps initial title if no file existed before
  3579. if (oldFile != null)
  3580. {
  3581. this.updateDocumentTitle();
  3582. }
  3583. // File might have been loaded halfway
  3584. this.editor.graph.model.clear();
  3585. this.editor.undoManager.clear();
  3586. // Avoids empty hash with no value
  3587. if (window.location.hash != null && window.location.hash.length > 0)
  3588. {
  3589. window.location.hash = '';
  3590. }
  3591. if (this.fname != null)
  3592. {
  3593. this.fnameWrapper.style.display = 'none';
  3594. this.fname.innerHTML = '';
  3595. this.fname.setAttribute('title', mxResources.get('rename'));
  3596. }
  3597. this.updateUi();
  3598. this.showSplash();
  3599. });
  3600. if (file != null)
  3601. {
  3602. try
  3603. {
  3604. // Order is significant, current file needed for correct
  3605. // file format for initial save after starting realtime
  3606. this.setCurrentFile(file);
  3607. file.addListener('descriptorChanged', this.descriptorChangedListener);
  3608. file.addListener('contentChanged', this.descriptorChangedListener);
  3609. this.setMode(file.getMode());
  3610. this.descriptorChanged();
  3611. file.open();
  3612. this.diagramContainer.style.visibility = '';
  3613. this.formatContainer.style.visibility = '';
  3614. this.hsplit.style.display = '';
  3615. this.sidebarContainer.style.display = '';
  3616. this.sidebarFooterContainer.style.display = '';
  3617. this.editor.undoManager.clear();
  3618. this.updateUi();
  3619. // Realtime files have a valid status message
  3620. if (file.realtime == null)
  3621. {
  3622. if (!file.isEditable())
  3623. {
  3624. this.editor.setStatus(mxResources.get('readOnly'));
  3625. }
  3626. else
  3627. {
  3628. this.editor.setStatus('');
  3629. }
  3630. }
  3631. if (!this.editor.chromeless)
  3632. {
  3633. this.showLayersDialog();
  3634. this.restoreLibraries();
  3635. }
  3636. else if (this.editor.graph.lightbox)
  3637. {
  3638. this.lightboxFit();
  3639. }
  3640. if (this.chromelessResize)
  3641. {
  3642. this.chromelessResize();
  3643. }
  3644. this.editor.fireEvent(new mxEventObject('fileLoaded'));
  3645. // if (this.enableLogging)
  3646. // {
  3647. // try
  3648. // {
  3649. // if (!this.isOffline())
  3650. // {
  3651. // var img = new Image();
  3652. // img.src = 'log?msg=storageMode:' + encodeURIComponent(file.getMode()) +
  3653. // '&v=' + encodeURIComponent(EditorUi.VERSION);
  3654. // }
  3655. // }
  3656. // catch (e)
  3657. // {
  3658. // // ignore
  3659. // }
  3660. // }
  3661. if (this.mode == file.getMode() && file.getMode() != App.MODE_DEVICE)
  3662. {
  3663. try
  3664. {
  3665. this.addRecent({id: file.getHash(), title: file.getTitle(), mode: file.getMode()});
  3666. }
  3667. catch (e)
  3668. {
  3669. // ignore
  3670. }
  3671. }
  3672. }
  3673. catch (e)
  3674. {
  3675. // Makes sure the file does not save the invalid UI model and overwrites anything important
  3676. if (window.console != null)
  3677. {
  3678. console.log('error in fileLoaded:', file, e);
  3679. }
  3680. // Asynchronous handling of errors
  3681. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3682. {
  3683. // Removes URL parameter and reloads the page
  3684. if (urlParams['url'] != null && this.spinner.spin(document.body, mxResources.get('reconnecting')))
  3685. {
  3686. window.location.search = this.getSearch(['url']);
  3687. }
  3688. else if (oldFile != null)
  3689. {
  3690. this.fileLoaded(oldFile);
  3691. }
  3692. else
  3693. {
  3694. noFile();
  3695. }
  3696. }));
  3697. }
  3698. }
  3699. else
  3700. {
  3701. noFile();
  3702. }
  3703. };
  3704. /**
  3705. * Updates action states depending on the selection.
  3706. */
  3707. App.prototype.restoreLibraries = function()
  3708. {
  3709. if (this.sidebar != null)
  3710. {
  3711. if (this.pendingLibraries == null)
  3712. {
  3713. this.pendingLibraries = new Object();
  3714. }
  3715. // Ignores this library next time
  3716. var ignore = mxUtils.bind(this, function(id)
  3717. {
  3718. mxSettings.removeCustomLibrary(id);
  3719. delete this.pendingLibraries[id];
  3720. });
  3721. var load = mxUtils.bind(this, function(libs)
  3722. {
  3723. if (libs != null)
  3724. {
  3725. for (var i = 0; i < libs.length; i++)
  3726. {
  3727. var name = encodeURIComponent(decodeURIComponent(libs[i]));
  3728. (mxUtils.bind(this, function(id)
  3729. {
  3730. if (this.pendingLibraries[id] == null && this.sidebar.palettes[id] == null)
  3731. {
  3732. this.pendingLibraries[id] = true;
  3733. var service = id.substring(0, 1);
  3734. if (service == 'L')
  3735. {
  3736. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3737. {
  3738. try
  3739. {
  3740. var name = decodeURIComponent(id.substring(1));
  3741. var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
  3742. {
  3743. if (name == '.scratchpad' && xml == null)
  3744. {
  3745. xml = this.emptyLibraryXml;
  3746. }
  3747. if (xml != null)
  3748. {
  3749. this.loadLibrary(new StorageLibrary(this, xml, name));
  3750. }
  3751. else
  3752. {
  3753. ignore(id);
  3754. }
  3755. }));
  3756. }
  3757. catch (e)
  3758. {
  3759. ignore(id);
  3760. }
  3761. }
  3762. }
  3763. else if (service == 'U')
  3764. {
  3765. var url = decodeURIComponent(id.substring(1));
  3766. if (!this.isOffline())
  3767. {
  3768. // Uses proxy to avoid CORS issues
  3769. mxUtils.get(PROXY_URL + '?url=' + encodeURIComponent(url), mxUtils.bind(this, function(req)
  3770. {
  3771. if (req.getStatus() == 200)
  3772. {
  3773. try
  3774. {
  3775. this.loadLibrary(new UrlLibrary(this, req.getText(), url));
  3776. delete this.pendingLibraries[id];
  3777. }
  3778. catch (e)
  3779. {
  3780. ignore(id);
  3781. }
  3782. }
  3783. else
  3784. {
  3785. ignore(id);
  3786. }
  3787. }), function()
  3788. {
  3789. ignore(id);
  3790. });
  3791. }
  3792. }
  3793. else
  3794. {
  3795. var peer = null;
  3796. if (service == 'G')
  3797. {
  3798. if (this.drive != null && this.drive.user != null)
  3799. {
  3800. peer = this.drive;
  3801. }
  3802. }
  3803. else if (service == 'D')
  3804. {
  3805. if (this.dropbox != null && this.dropbox.getUser() != null)
  3806. {
  3807. peer = this.dropbox;
  3808. }
  3809. }
  3810. else if (service == 'W')
  3811. {
  3812. if (this.oneDrive != null && this.oneDrive.getUser() != null)
  3813. {
  3814. peer = this.oneDrive;
  3815. }
  3816. }
  3817. if (peer != null)
  3818. {
  3819. peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
  3820. {
  3821. try
  3822. {
  3823. this.loadLibrary(file);
  3824. delete this.pendingLibraries[id];
  3825. }
  3826. catch (e)
  3827. {
  3828. ignore(id);
  3829. }
  3830. }), function(resp)
  3831. {
  3832. ignore(id);
  3833. });
  3834. }
  3835. }
  3836. }
  3837. }))(name);
  3838. }
  3839. }
  3840. });
  3841. load(mxSettings.getCustomLibraries());
  3842. load((urlParams['clibs'] || '').split(';'));
  3843. }
  3844. };
  3845. /**
  3846. * Updates action and menu states depending on the file.
  3847. */
  3848. App.prototype.updateUi = function()
  3849. {
  3850. this.updateButtonContainer();
  3851. this.updateActionStates();
  3852. // Action states that only need update for new files
  3853. var file = this.getCurrentFile();
  3854. var active = file != null || urlParams['embed'] == '1';
  3855. this.menus.get('viewPanels').setEnabled(active);
  3856. this.menus.get('viewZoom').setEnabled(active);
  3857. var restricted = urlParams['embed'] != '1' && (file == null || file.isRestricted());
  3858. this.actions.get('makeCopy').setEnabled(!restricted);
  3859. this.actions.get('print').setEnabled(!restricted);
  3860. this.menus.get('exportAs').setEnabled(!restricted);
  3861. this.menus.get('embed').setEnabled(!restricted);
  3862. // Disables actions in the toolbar
  3863. var editable = (urlParams['embed'] == '1') || (file != null && file.isEditable());
  3864. this.actions.get('image').setEnabled(active);
  3865. this.actions.get('zoomIn').setEnabled(active);
  3866. this.actions.get('zoomOut').setEnabled(active);
  3867. this.actions.get('resetView').setEnabled(active);
  3868. // Disables menus
  3869. this.menus.get('edit').setEnabled(active);
  3870. this.menus.get('view').setEnabled(active);
  3871. this.menus.get('importFrom').setEnabled(editable);
  3872. this.menus.get('arrange').setEnabled(editable);
  3873. // Disables connection drop downs in toolbar
  3874. if (this.toolbar != null)
  3875. {
  3876. if (this.toolbar.edgeShapeMenu != null)
  3877. {
  3878. this.toolbar.edgeShapeMenu.setEnabled(editable);
  3879. }
  3880. if (this.toolbar.edgeStyleMenu != null)
  3881. {
  3882. this.toolbar.edgeStyleMenu.setEnabled(editable);
  3883. }
  3884. }
  3885. if (this.isOfflineApp())
  3886. {
  3887. // In FF, IE and Safari (desktop) the cache status never changes
  3888. if ((mxClient.IS_GC || (mxClient.IS_IOS && mxClient.IS_SF)) && applicationCache != null)
  3889. {
  3890. var appCache = applicationCache;
  3891. if (this.offlineStatus == null)
  3892. {
  3893. this.offlineStatus = document.createElement('div');
  3894. this.offlineStatus.className = 'geItem';
  3895. this.offlineStatus.style.position = 'absolute';
  3896. this.offlineStatus.style.fontSize = '8pt';
  3897. this.offlineStatus.style.top = '2px';
  3898. this.offlineStatus.style.right = '12px';
  3899. this.offlineStatus.style.color = '#666';
  3900. this.offlineStatus.style.margin = '4px';
  3901. this.offlineStatus.style.padding = '2px';
  3902. this.offlineStatus.style.verticalAlign = 'middle';
  3903. this.offlineStatus.innerHTML = '';
  3904. this.menubarContainer.appendChild(this.offlineStatus);
  3905. // Events are not working, use polling instead (10 secs interval)
  3906. var thread = window.setTimeout(mxUtils.bind(this, function()
  3907. {
  3908. if (appCache.status == appCache.IDLE)
  3909. {
  3910. this.offlineStatus.innerHTML = '[' + '<img title="Cached" border="0" src="' + IMAGE_PATH + '/checkmark.gif"/>]';
  3911. window.clearTimeout(thread);
  3912. }
  3913. }), 5000);
  3914. }
  3915. }
  3916. }
  3917. else
  3918. {
  3919. this.updateUserElement();
  3920. }
  3921. };
  3922. /**
  3923. *
  3924. */
  3925. App.prototype.exportImage = function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  3926. {
  3927. if (this.spinner.spin(document.body, mxResources.get('exporting')))
  3928. {
  3929. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  3930. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  3931. try
  3932. {
  3933. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  3934. {
  3935. this.spinner.stop();
  3936. try
  3937. {
  3938. // TODO: Should call App.getFileData here
  3939. this.saveCanvas(canvas, (editable) ? this.getFileData(true, null, null, null, ignoreSelection) : null);
  3940. }
  3941. catch (e)
  3942. {
  3943. // Fallback to server-side image export
  3944. if (e.message == 'Invalid image')
  3945. {
  3946. this.downloadFile('png');
  3947. }
  3948. else
  3949. {
  3950. this.handleError(e);
  3951. }
  3952. }
  3953. }), null, null, null, mxUtils.bind(this, function(e)
  3954. {
  3955. this.spinner.stop();
  3956. this.handleError(e);
  3957. }), null, ignoreSelection, scale || 1, transparentBackground, addShadow);
  3958. }
  3959. catch (e)
  3960. {
  3961. this.spinner.stop();
  3962. this.handleError(e);
  3963. }
  3964. }
  3965. };
  3966. /**
  3967. *
  3968. */
  3969. EditorUi.prototype.exportSvg = function(scale, transparentBackground, ignoreSelection, addShadow, editable, embedImages)
  3970. {
  3971. var selectionEmpty = this.editor.graph.isSelectionEmpty();
  3972. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : selectionEmpty;
  3973. var bg = (transparentBackground) ? null : this.editor.graph.background;
  3974. if (bg == mxConstants.NONE)
  3975. {
  3976. bg = null;
  3977. }
  3978. // Handles special case where background is null but transparent is false
  3979. if (bg == null && transparentBackground == false)
  3980. {
  3981. bg = '#ffffff';
  3982. }
  3983. // Sets or disables alternate text for foreignObjects. Disabling is needed
  3984. // because PhantomJS seems to ignore switch statements and paint all text.
  3985. var svgRoot = this.editor.graph.getSvg(bg, scale, null, null, null, ignoreSelection);
  3986. if (addShadow)
  3987. {
  3988. this.editor.addSvgShadow(svgRoot);
  3989. }
  3990. var file = this.getCurrentFile();
  3991. var filename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  3992. var dot = filename.lastIndexOf('.');
  3993. if (dot > 0)
  3994. {
  3995. filename = filename.substring(0, dot);
  3996. }
  3997. filename += '.svg';
  3998. if (this.spinner.spin(document.body, mxResources.get('export')))
  3999. {
  4000. var doSave = mxUtils.bind(this, function(svgRoot)
  4001. {
  4002. this.spinner.stop();
  4003. if (editable)
  4004. {
  4005. svgRoot.setAttribute('content', this.getFileData(true, null, null, null, ignoreSelection));
  4006. }
  4007. var svg = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  4008. mxUtils.getXml(svgRoot);
  4009. // TODO: Depends on App
  4010. if (this.isLocalFileSave() || svg.length <= MAX_REQUEST_SIZE)
  4011. {
  4012. this.saveData(filename, 'svg', svg, 'image/svg+xml');
  4013. }
  4014. else
  4015. {
  4016. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  4017. {
  4018. mxUtils.popup(svg);
  4019. }));
  4020. }
  4021. });
  4022. this.convertMath(this.editor.graph, svgRoot, false, mxUtils.bind(this, function()
  4023. {
  4024. if (embedImages)
  4025. {
  4026. this.convertImages(svgRoot, doSave);
  4027. }
  4028. else
  4029. {
  4030. doSave(svgRoot);
  4031. }
  4032. }));
  4033. }
  4034. };
  4035. /**
  4036. * Translates this point by the given vector.
  4037. *
  4038. * @param {number} dx X-coordinate of the translation.
  4039. * @param {number} dy Y-coordinate of the translation.
  4040. */
  4041. App.prototype.updateButtonContainer = function()
  4042. {
  4043. if (this.buttonContainer != null)
  4044. {
  4045. var file = this.getCurrentFile();
  4046. if (file != null && file.constructor == DriveFile)
  4047. {
  4048. // Adds Share button
  4049. if (this.shareButton == null)
  4050. {
  4051. this.shareButton = document.createElement('div');
  4052. this.shareButton.className = 'geBtn gePrimaryBtn';
  4053. this.shareButton.style.display = 'inline-block';
  4054. this.shareButton.style.padding = '0 10px 0 10px';
  4055. this.shareButton.style.marginTop = '-4px';
  4056. this.shareButton.style.height = '28px';
  4057. this.shareButton.style.lineHeight = '28px';
  4058. this.shareButton.style.minWidth = '0px';
  4059. this.shareButton.style.cssFloat = 'right';
  4060. var icon = document.createElement('img');
  4061. icon.setAttribute('src', this.shareImage);
  4062. icon.setAttribute('align', 'absmiddle');
  4063. icon.style.marginRight = '4px';
  4064. icon.style.marginTop = '-3px';
  4065. this.shareButton.appendChild(icon);
  4066. mxUtils.write(this.shareButton, mxResources.get('share'));
  4067. mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
  4068. {
  4069. this.actions.get('share').funct();
  4070. }));
  4071. this.buttonContainer.appendChild(this.shareButton);
  4072. }
  4073. }
  4074. else if (this.shareButton != null)
  4075. {
  4076. this.shareButton.parentNode.removeChild(this.shareButton);
  4077. this.shareButton = null;
  4078. }
  4079. }
  4080. };
  4081. /**
  4082. * Translates this point by the given vector.
  4083. *
  4084. * @param {number} dx X-coordinate of the translation.
  4085. * @param {number} dy Y-coordinate of the translation.
  4086. */
  4087. App.prototype.save = function(name, done)
  4088. {
  4089. var file = this.getCurrentFile();
  4090. var msg = mxResources.get('saving');
  4091. if (file != null && file.constructor == DriveFile)
  4092. {
  4093. msg = mxResources.get('createRevision');
  4094. }
  4095. if (file != null && this.spinner.spin(document.body, msg))
  4096. {
  4097. this.editor.setStatus('');
  4098. if (this.editor.graph.isEditing())
  4099. {
  4100. this.editor.graph.stopEditing();
  4101. }
  4102. var success = mxUtils.bind(this, function(resp)
  4103. {
  4104. this.spinner.stop();
  4105. if (this.getCurrentFile() == file)
  4106. {
  4107. if (file.isModified())
  4108. {
  4109. if (!file.isAutosave())
  4110. {
  4111. file.addUnsavedStatus();
  4112. }
  4113. }
  4114. else
  4115. {
  4116. this.editor.setStatus(mxResources.get('allChangesSaved'));
  4117. }
  4118. }
  4119. if (done != null)
  4120. {
  4121. done();
  4122. }
  4123. });
  4124. var error = mxUtils.bind(this, function(resp)
  4125. {
  4126. // Spinner is paused and resumed in handleError
  4127. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  4128. });
  4129. if (name == file.getTitle())
  4130. {
  4131. file.save(true, success, error);
  4132. }
  4133. else
  4134. {
  4135. file.saveAs(name, success, error)
  4136. }
  4137. }
  4138. };
  4139. /**
  4140. * Translates this point by the given vector.
  4141. *
  4142. * @param {number} dx X-coordinate of the translation.
  4143. * @param {number} dy Y-coordinate of the translation.
  4144. */
  4145. App.prototype.base64ToBlob = function(base64Data, contentType)
  4146. {
  4147. contentType = contentType || '';
  4148. var sliceSize = 1024;
  4149. var byteCharacters = atob(base64Data);
  4150. var bytesLength = byteCharacters.length;
  4151. var slicesCount = Math.ceil(bytesLength / sliceSize);
  4152. var byteArrays = new Array(slicesCount);
  4153. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex)
  4154. {
  4155. var begin = sliceIndex * sliceSize;
  4156. var end = Math.min(begin + sliceSize, bytesLength);
  4157. var bytes = new Array(end - begin);
  4158. for (var offset = begin, i = 0 ; offset < end; ++i, ++offset)
  4159. {
  4160. bytes[i] = byteCharacters[offset].charCodeAt(0);
  4161. }
  4162. byteArrays[sliceIndex] = new Uint8Array(bytes);
  4163. }
  4164. return new Blob(byteArrays, {type: contentType});
  4165. };
  4166. /**
  4167. * Returns true if files should be saved using <saveLocalFile>.
  4168. */
  4169. App.prototype.isLocalFileSave = function()
  4170. {
  4171. return (urlParams['save'] != 'remote' && (mxClient.IS_IE ||
  4172. (typeof window.Blob !== 'undefined' && typeof window.URL !== 'undefined')) &&
  4173. document.documentMode != 9 && document.documentMode != 8 &&
  4174. document.documentMode != 7 && !mxClient.IS_QUIRKS) ||
  4175. this.isOfflineApp() || mxClient.IS_IOS;
  4176. };
  4177. /**
  4178. * Translates this point by the given vector.
  4179. *
  4180. * @param {number} dx X-coordinate of the translation.
  4181. * @param {number} dy Y-coordinate of the translation.
  4182. */
  4183. App.prototype.saveRequest = function(data, filename, format, fn)
  4184. {
  4185. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  4186. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  4187. {
  4188. if (mode == '_blank' || newTitle != null && newTitle.length > 0)
  4189. {
  4190. var base64 = (mode == App.MODE_DEVICE || mode == null || mode == '_blank') ? '0' : '1';
  4191. var xhr = fn((mode == '_blank') ? null : newTitle, base64);
  4192. if (mode == App.MODE_DEVICE || mode == '_blank')
  4193. {
  4194. xhr.simulate(document, '_blank');
  4195. }
  4196. else
  4197. {
  4198. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  4199. {
  4200. if (this.spinner.spin(document.body, mxResources.get('saving')))
  4201. {
  4202. // LATER: Catch possible mixed content error
  4203. // see http://stackoverflow.com/questions/30646417/catching-mixed-content-error
  4204. xhr.send(mxUtils.bind(this, function()
  4205. {
  4206. this.spinner.stop();
  4207. if (xhr.getStatus() < 200 || xhr.getStatus() > 299)
  4208. {
  4209. this.handleError({message: mxResources.get('errorSavingFile')});
  4210. }
  4211. else
  4212. {
  4213. try
  4214. {
  4215. var mimeType = (format == 'pdf') ? 'application/pdf' : 'image/' + format;
  4216. this.exportFile(xhr.getText(), newTitle, mimeType, true, mode, folderId);
  4217. }
  4218. catch (e)
  4219. {
  4220. this.handleError(e);
  4221. }
  4222. }
  4223. }), function(resp)
  4224. {
  4225. this.spinner.stop();
  4226. this.handleError(resp);
  4227. });
  4228. }
  4229. }));
  4230. }
  4231. }
  4232. }), mxUtils.bind(this, function()
  4233. {
  4234. this.hideDialog();
  4235. }), mxResources.get('saveAs'), mxResources.get('download'), false, false, allowTab);
  4236. this.showDialog(dlg.container, 380, 270, true, true);
  4237. dlg.init();
  4238. };
  4239. /**
  4240. * Invokes callback with null if mode does not support folder or not null
  4241. * if a valid folder was chosen for a mode that supports it. No callback
  4242. * is made if no folder was chosen for a mode that supports it.
  4243. */
  4244. App.prototype.pickFolder = function(mode, fn, enabled)
  4245. {
  4246. enabled = (enabled != null) ? enabled : true;
  4247. if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
  4248. {
  4249. // Shows a save dialog
  4250. this.drive.pickFolder(mxUtils.bind(this, function(evt)
  4251. {
  4252. if (evt.action == google.picker.Action.PICKED)
  4253. {
  4254. var folderId = null;
  4255. if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
  4256. {
  4257. folderId = evt.docs[0].id;
  4258. }
  4259. fn(folderId);
  4260. }
  4261. }));
  4262. }
  4263. else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  4264. {
  4265. this.oneDrive.pickFolder(mxUtils.bind(this, function(evt)
  4266. {
  4267. var folderId = null;
  4268. if (evt != null && evt.data != null && evt.data.folders != null &&
  4269. evt.data.folders.length > 0)
  4270. {
  4271. folderId = evt.data.folders[0].id;
  4272. folderId = folderId.substring(folderId.lastIndexOf('.') + 1);
  4273. fn(folderId);
  4274. }
  4275. }));
  4276. }
  4277. else
  4278. {
  4279. fn(null);
  4280. }
  4281. };
  4282. /**
  4283. *
  4284. */
  4285. App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  4286. {
  4287. if (mode == App.MODE_DROPBOX)
  4288. {
  4289. if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4290. {
  4291. // LATER: Add folder picker
  4292. this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4293. data, mxUtils.bind(this, function()
  4294. {
  4295. this.spinner.stop();
  4296. }), mxUtils.bind(this, function(resp)
  4297. {
  4298. this.spinner.stop();
  4299. this.handleError(resp);
  4300. }));
  4301. }
  4302. }
  4303. else if (mode == App.MODE_GOOGLE)
  4304. {
  4305. if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4306. {
  4307. this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
  4308. {
  4309. // TODO: Add callback with url param for clickable status message
  4310. // "File exported. Click here to open folder."
  4311. // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
  4312. // mxResources.get('saved') + '</div>');
  4313. //
  4314. // // Installs click handler for opening
  4315. // if (this.statusContainer != null)
  4316. // {
  4317. // var links = this.statusContainer.getElementsByTagName('div');
  4318. //
  4319. // if (links.length > 0)
  4320. // {
  4321. // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
  4322. // {
  4323. // if (resp != null && resp.parents != null && resp.parents.length > 0)
  4324. // {
  4325. // var id = resp.parents[0].id;
  4326. //
  4327. // if (id != null)
  4328. // {
  4329. // window.open('https://drive.google.com/drive/folders/' + id);
  4330. // }
  4331. // }
  4332. // }));
  4333. // }
  4334. // }
  4335. this.spinner.stop();
  4336. }), mxUtils.bind(this, function(resp)
  4337. {
  4338. this.spinner.stop();
  4339. this.handleError(resp);
  4340. }), mimeType, base64Encoded, false);
  4341. }
  4342. }
  4343. else if (mode == App.MODE_ONEDRIVE)
  4344. {
  4345. if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4346. {
  4347. // KNOWN: OneDrive does not show .svg extension
  4348. this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4349. data, mxUtils.bind(this, function()
  4350. {
  4351. this.spinner.stop();
  4352. }), mxUtils.bind(this, function(resp)
  4353. {
  4354. this.spinner.stop();
  4355. this.handleError(resp);
  4356. }), false, folderId);
  4357. }
  4358. }
  4359. };
  4360. /**
  4361. * Translates this point by the given vector.
  4362. *
  4363. * @param {number} dx X-coordinate of the translation.
  4364. * @param {number} dy Y-coordinate of the translation.
  4365. */
  4366. App.prototype.doSaveLocalFile = function(data, filename, mimeType, base64Encoded)
  4367. {
  4368. // Newer versions of IE
  4369. if (window.MSBlobBuilder && navigator.msSaveOrOpenBlob)
  4370. {
  4371. var builder = new MSBlobBuilder();
  4372. builder.append(data);
  4373. var blob = builder.getBlob(mimeType);
  4374. navigator.msSaveOrOpenBlob(blob, filename);
  4375. }
  4376. // Older versions of IE (binary not supported)
  4377. else if (mxClient.IS_IE)
  4378. {
  4379. var win = window.open('about:blank', '_blank');
  4380. if (win == null)
  4381. {
  4382. mxUtils.popup(data, true);
  4383. }
  4384. else
  4385. {
  4386. win.document.write(data);
  4387. win.document.close();
  4388. win.document.execCommand('SaveAs', true, filename);
  4389. win.close();
  4390. }
  4391. }
  4392. else if (mxClient.IS_IOS)
  4393. {
  4394. // Poor man's saveAs in iOS via context menu of selected output
  4395. var dlg = new TextareaDialog(this, filename + ':', data, null, null, mxResources.get('close'));
  4396. dlg.textarea.style.width = '600px';
  4397. dlg.textarea.style.height = '380px';
  4398. this.showDialog(dlg.container, 620, 460, true, true);
  4399. dlg.init();
  4400. document.execCommand('selectall', false, null);
  4401. }
  4402. else if (!this.isOffline() && mxClient.IS_SF)
  4403. {
  4404. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4405. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4406. new mxXmlRequest(SAVE_URL, 'mime=' + mimeType + '&filename=' +
  4407. encodeURIComponent(filename) +
  4408. param).simulate(document, '_blank');
  4409. }
  4410. else
  4411. {
  4412. var a = document.createElement('a');
  4413. a.href = URL.createObjectURL((base64Encoded) ?
  4414. this.base64ToBlob(data, mimeType) :
  4415. new Blob([data], {type: mimeType}));
  4416. a.download = filename;
  4417. document.body.appendChild(a);
  4418. // Workaround for link opens in same window in Safari
  4419. if (mxClient.IS_SF)
  4420. {
  4421. a.setAttribute('target', '_blank');
  4422. }
  4423. try
  4424. {
  4425. a.click();
  4426. window.setTimeout(function()
  4427. {
  4428. URL.revokeObjectURL(a.href);
  4429. }, 0);
  4430. a.parentNode.removeChild(a);
  4431. }
  4432. catch (e)
  4433. {
  4434. // ignore
  4435. }
  4436. }
  4437. };
  4438. /**
  4439. * Translates this point by the given vector.
  4440. *
  4441. * @param {number} dx X-coordinate of the translation.
  4442. * @param {number} dy Y-coordinate of the translation.
  4443. */
  4444. App.prototype.saveLocalFile = function(data, filename, mimeType, base64Encoded)
  4445. {
  4446. if (this.isOfflineApp() || this.isOffline())
  4447. {
  4448. this.doSaveLocalFile(data, filename, mimeType, base64Encoded);
  4449. }
  4450. else
  4451. {
  4452. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  4453. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(newTitle, mode)
  4454. {
  4455. try
  4456. {
  4457. // Opens a new window
  4458. if (mode == '_blank')
  4459. {
  4460. // Workaround for "Access denied" after URL.createObjectURL
  4461. // and blank window for window.open with data URI in MS Edge
  4462. // and empty window for IE 11 and 10
  4463. if (mxClient.IS_EDGE || document.documentMode == 11 || document.documentMode == 10)
  4464. {
  4465. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4466. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4467. new mxXmlRequest(SAVE_URL, 'mime=' + mimeType + param).simulate(document, '_blank');
  4468. }
  4469. else
  4470. {
  4471. // Cannot use URL.createObjectURL since it kills gradients in FF
  4472. window.open('data:' + mimeType + ((base64Encoded) ? ';base64,' +
  4473. data : ';charset=utf8,' + encodeURIComponent(data)));
  4474. }
  4475. }
  4476. else if (mode == App.MODE_DEVICE)
  4477. {
  4478. this.doSaveLocalFile(data, newTitle, mimeType, base64Encoded);
  4479. }
  4480. else if (newTitle != null && newTitle.length > 0)
  4481. {
  4482. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  4483. {
  4484. this.exportFile(data, newTitle, mimeType, base64Encoded, mode, folderId);
  4485. }));
  4486. }
  4487. }
  4488. catch (e)
  4489. {
  4490. this.handleError(e);
  4491. }
  4492. }), mxUtils.bind(this, function()
  4493. {
  4494. this.hideDialog();
  4495. }), mxResources.get('saveAs'), mxResources.get('download'), false, false, allowTab);
  4496. this.showDialog(dlg.container, 380, 280, true, true);
  4497. dlg.init();
  4498. }
  4499. };
  4500. /**
  4501. *
  4502. */
  4503. App.prototype.getHtml = function(node, graph, title, editLink, redirect, ignoreSelection)
  4504. {
  4505. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  4506. var bg = null;
  4507. var js = 'https://www.draw.io/js/embed-static.min.js';
  4508. var s = '';
  4509. // LATER: Merge common code with EmbedDialog
  4510. if (graph != null)
  4511. {
  4512. var bounds = (ignoreSelection) ? graph.getGraphBounds() : graph.getBoundingBox(graph.getSelectionCells());
  4513. var scale = graph.view.scale;
  4514. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  4515. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  4516. bg = graph.background;
  4517. // Embed script only used if no redirect
  4518. if (redirect == null)
  4519. {
  4520. var stencilNames = new Object();
  4521. var states = this.editor.graph.view.states.getValues();
  4522. // Scans shapes for stencils
  4523. for (var i = 0; i < states.length; i++)
  4524. {
  4525. var state = states[i];
  4526. var shape = state.style[mxConstants.STYLE_SHAPE];
  4527. var base = mxStencilRegistry.getBasenameForStencil(shape);
  4528. if (base != null)
  4529. {
  4530. if (stencilNames[base] == null)
  4531. {
  4532. stencilNames[base] = true;
  4533. s += base + ';';
  4534. }
  4535. }
  4536. }
  4537. if (s.length > 0)
  4538. {
  4539. js = 'https://www.draw.io/embed.js?s=' + s.substring(0, s.length - 1);
  4540. }
  4541. }
  4542. // Adds embed attributes
  4543. node.setAttribute('x0', x0);
  4544. node.setAttribute('y0', y0);
  4545. }
  4546. if (node != null)
  4547. {
  4548. node.setAttribute('pan', '1');
  4549. node.setAttribute('zoom', '1');
  4550. node.setAttribute('resize', '0');
  4551. node.setAttribute('fit', '0');
  4552. node.setAttribute('border', '20');
  4553. // Hidden attributes
  4554. node.setAttribute('links', '1');
  4555. if (editLink != null)
  4556. {
  4557. node.setAttribute('edit', editLink);
  4558. }
  4559. }
  4560. // Makes XHTML compatible
  4561. if (redirect != null)
  4562. {
  4563. redirect = redirect.replace(/&/g, '&amp;');
  4564. }
  4565. // Removes control chars in input for correct roundtrip check
  4566. var text = (node != null) ? this.editor.graph.zapGremlins(mxUtils.getXml(node)) : '';
  4567. // Double compression for mxfile not fixed since it may cause imcompatibilites with
  4568. // embed clients that rely on this format. HTML files and export use getHtml2.
  4569. var data = this.editor.graph.compress(text);
  4570. // Fallback to URI encoded XML for invalid compression
  4571. if (this.editor.graph.decompress(data) != text)
  4572. {
  4573. data = encodeURIComponent(text);
  4574. }
  4575. var style = 'position:relative;overflow:auto;width:100%;';
  4576. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  4577. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  4578. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  4579. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  4580. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  4581. '</head>\n<body' +
  4582. (((redirect == null && bg != null && bg != mxConstants.NONE) ? ' style="background-color:' + bg + ';">' : '>')) +
  4583. '\n<div class="mxgraph" style="' + style + '">\n' +
  4584. '<div style="width:1px;height:1px;overflow:hidden;">' + data + '</div>\n</div>\n' +
  4585. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  4586. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  4587. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  4588. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  4589. '\n</body>\n</html>\n';
  4590. };
  4591. /**
  4592. * Same as above but using the new embed code.
  4593. */
  4594. App.prototype.getHtml2 = function(node, graph, title, editLink, redirect, ignoreSelection)
  4595. {
  4596. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  4597. var bg = null;
  4598. var js = 'https://www.draw.io/js/viewer.min.js';
  4599. var s = '';
  4600. // LATER: Merge common code with EmbedDialog
  4601. if (graph != null)
  4602. {
  4603. // Embed script only used if no redirect
  4604. if (redirect == null)
  4605. {
  4606. var s = [];
  4607. // Scans shapes for stencils
  4608. var stencilNames = new Object();
  4609. var states = graph.view.states.getValues();
  4610. function addName(name)
  4611. {
  4612. if (name != null)
  4613. {
  4614. var dot = name.lastIndexOf('.');
  4615. if (dot > 0)
  4616. {
  4617. name = name.substring(dot + 1, name.length);
  4618. }
  4619. if (stencilNames[name] == null)
  4620. {
  4621. stencilNames[name] = true;
  4622. s.push(name);
  4623. }
  4624. }
  4625. }
  4626. for (var i = 0; i < states.length; i++)
  4627. {
  4628. var state = states[i];
  4629. var shape = state.style[mxConstants.STYLE_SHAPE];
  4630. addName(mxStencilRegistry.getBasenameForStencil(shape));
  4631. // Adds package names for markers in edges
  4632. if (state.view.graph.model.isEdge(state.cell))
  4633. {
  4634. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_STARTARROW]));
  4635. addName(mxMarker.getPackageForType(state.style[mxConstants.STYLE_ENDARROW]));
  4636. }
  4637. }
  4638. if (s.length > 0)
  4639. {
  4640. js = 'https://www.draw.io/embed2.js?s=' + s.join(';');
  4641. }
  4642. }
  4643. }
  4644. // Makes XHTML compatible
  4645. if (redirect != null)
  4646. {
  4647. redirect = redirect.replace(/&/g, '&amp;');
  4648. }
  4649. var data = {highlight: '#0000ff', nav: this.editor.graph.foldingEnabled, resize: true,
  4650. xml: this.editor.graph.zapGremlins(mxUtils.getXml(node)), toolbar: 'zoom layers lightbox'};
  4651. var style = 'max-width:100%;border:1px solid transparent;';
  4652. return ((redirect == null) ? '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' : '') +
  4653. '<!DOCTYPE html>\n<html' + ((redirect != null) ? ' xmlns="http://www.w3.org/1999/xhtml">' : '>') +
  4654. '\n<head>\n' + ((redirect == null) ? ((title != null) ? '<title>' + mxUtils.htmlEntities(title) +
  4655. '</title>\n' : '') : '<title>Draw.io Diagram</title>\n') +
  4656. ((redirect != null) ? '<meta http-equiv="refresh" content="0;URL=\'' + redirect + '\'"/>\n' : '') +
  4657. '<meta charset="utf-8"/>\n</head>\n<body>' +
  4658. '\n<div class="mxgraph" style="' + style + '" data-mxgraph="' + mxUtils.htmlEntities(JSON.stringify(data)) + '"></div>\n' +
  4659. ((redirect == null) ? '<script type="text/javascript" src="' + js + '"></script>' :
  4660. '<a style="position:absolute;top:50%;left:50%;margin-top:-128px;margin-left:-64px;" ' +
  4661. 'href="' + redirect + '" target="_blank"><img border="0" ' +
  4662. 'src="https://www.draw.io/images/drawlogo128.png"/></a>') +
  4663. '\n</body>\n</html>\n';
  4664. };
  4665. /**
  4666. * Translates this point by the given vector.
  4667. *
  4668. * @param {number} dx X-coordinate of the translation.
  4669. * @param {number} dy Y-coordinate of the translation.
  4670. */
  4671. App.prototype.saveData = function(filename, format, data, mime)
  4672. {
  4673. if (this.isLocalFileSave())
  4674. {
  4675. this.saveLocalFile(data, filename, mime);
  4676. }
  4677. else
  4678. {
  4679. this.saveRequest(data, filename, format, mxUtils.bind(this, function(newTitle, base64)
  4680. {
  4681. var param = (typeof(pako) === 'undefined') ? '&xml=' + encodeURIComponent(data) :
  4682. '&data=' + encodeURIComponent(this.editor.graph.compress(data));
  4683. return new mxXmlRequest(SAVE_URL, 'format=' + format + ((newTitle != null) ?
  4684. '&filename=' + encodeURIComponent(newTitle) : '') + param);
  4685. }));
  4686. }
  4687. };
  4688. /**
  4689. * Translates this point by the given vector.
  4690. *
  4691. * @param {number} dx X-coordinate of the translation.
  4692. * @param {number} dy Y-coordinate of the translation.
  4693. */
  4694. App.prototype.downloadFile = function(format, nonCompressed, addShadow, ignoreSelection)
  4695. {
  4696. try
  4697. {
  4698. var file = this.getCurrentFile();
  4699. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : this.editor.graph.isSelectionEmpty();
  4700. // LATER: Double URI encoding for needed for newlines in simulate (truncates body otherwise).
  4701. var basename = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4702. if (/(\.xml)$/i.test(basename) || /(\.html)$/i.test(basename) || /(\.svg)$/i.test(basename))
  4703. {
  4704. basename = basename.substring(0, basename.lastIndexOf('.'));
  4705. }
  4706. var filename = basename + '.' + format;
  4707. if (format == 'xml')
  4708. {
  4709. var data = '<?xml version="1.0" encoding="UTF-8"?>\n' +
  4710. ((nonCompressed) ? mxUtils.getXml(this.editor.getGraphXml(ignoreSelection)) :
  4711. this.getFileData(true, null, null, null, ignoreSelection));
  4712. this.saveData(filename, format, data, 'text/xml');
  4713. }
  4714. else if (format == 'html')
  4715. {
  4716. var data = this.getHtml2(this.editor.getGraphXml(ignoreSelection),
  4717. this.editor.graph, basename, null, null, ignoreSelection);
  4718. this.saveData(filename, format, data, 'text/html');
  4719. }
  4720. else if ((format == 'svg' || format == 'xmlsvg') && this.spinner.spin(document.body, mxResources.get('export')))
  4721. {
  4722. var svg = null;
  4723. var saveSvg = mxUtils.bind(this, function(data)
  4724. {
  4725. if (data.length <= MAX_REQUEST_SIZE)
  4726. {
  4727. this.saveData(filename, 'svg', data, 'image/svg+xml');
  4728. }
  4729. else
  4730. {
  4731. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'), mxUtils.bind(this, function()
  4732. {
  4733. mxUtils.popup(svg);
  4734. }));
  4735. }
  4736. });
  4737. if (format == 'svg')
  4738. {
  4739. var bg = this.editor.graph.background;
  4740. if (bg == mxConstants.NONE)
  4741. {
  4742. bg = null;
  4743. }
  4744. // Sets or disables alternate text for foreignObjects. Disabling is needed
  4745. // because PhantomJS seems to ignore switch statements and paint all text.
  4746. var svgRoot = this.editor.graph.getSvg(bg, null, null, false, null, ignoreSelection);
  4747. if (addShadow)
  4748. {
  4749. this.editor.addSvgShadow(svgRoot);
  4750. }
  4751. // Embeds the images in the SVG output (async)
  4752. this.convertImages(svgRoot, mxUtils.bind(this, mxUtils.bind(this, function(svgRoot2)
  4753. {
  4754. this.spinner.stop();
  4755. saveSvg('<?xml version="1.0" encoding="UTF-8"?>\n' +
  4756. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  4757. mxUtils.getXml(svgRoot2));
  4758. })));
  4759. }
  4760. else
  4761. {
  4762. filename = basename + '.svg';
  4763. svg = this.getFileData(false, true, null, mxUtils.bind(this, function(svg)
  4764. {
  4765. this.spinner.stop();
  4766. saveSvg(svg);
  4767. }), ignoreSelection);
  4768. }
  4769. }
  4770. else
  4771. {
  4772. var bounds = this.editor.graph.getGraphBounds();
  4773. // Exports only current page for PDF since it does not contain file data, but for
  4774. // the other formats with XML included we need to send the complete data and use
  4775. // the from/to URL parameters to specify the page to be exported.
  4776. var data = this.getFileData(true, null, null, null, ignoreSelection, format != 'xmlpng');
  4777. var range = '';
  4778. if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
  4779. {
  4780. var embed = '0';
  4781. if (format == 'xmlpng')
  4782. {
  4783. embed = '1';
  4784. format = 'png';
  4785. filename = basename + '.' + format;
  4786. // Finds the current page number
  4787. if (this.pages != null && this.currentPage != null)
  4788. {
  4789. for (var i = 0; i < this.pages.length; i++)
  4790. {
  4791. if (this.pages[i] == this.currentPage)
  4792. {
  4793. range = '&from=' + i;
  4794. break;
  4795. }
  4796. }
  4797. }
  4798. }
  4799. this.saveRequest(data, filename, format, function(newTitle, base64)
  4800. {
  4801. return new mxXmlRequest(EXPORT_URL, 'format=' + format + range +
  4802. '&base64=' + base64 + '&embedXml=' + embed + '&xml=' +
  4803. encodeURIComponent(data) + ((newTitle != null) ?
  4804. '&filename=' + encodeURIComponent(newTitle) : ''));
  4805. });
  4806. }
  4807. else
  4808. {
  4809. this.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
  4810. }
  4811. }
  4812. }
  4813. catch (e)
  4814. {
  4815. this.handleError(e);
  4816. }
  4817. };
  4818. /**
  4819. * Translates this point by the given vector.
  4820. *
  4821. * @param {number} dx X-coordinate of the translation.
  4822. * @param {number} dy Y-coordinate of the translation.
  4823. */
  4824. App.prototype.formatFileSize = function(size)
  4825. {
  4826. var units = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
  4827. var i = -1;
  4828. do
  4829. {
  4830. size = size / 1024;
  4831. i++;
  4832. } while (size > 1024);
  4833. return Math.max(size, 0.1).toFixed(1) + units[i];
  4834. };
  4835. /**
  4836. * Translates this point by the given vector.
  4837. *
  4838. * @param {number} dx X-coordinate of the translation.
  4839. * @param {number} dy Y-coordinate of the translation.
  4840. */
  4841. App.prototype.descriptorChanged = function()
  4842. {
  4843. var file = this.getCurrentFile();
  4844. if (file != null)
  4845. {
  4846. if (this.fname != null)
  4847. {
  4848. this.fnameWrapper.style.display = 'block';
  4849. this.fname.innerHTML = '';
  4850. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4851. mxUtils.write(this.fname, filename);
  4852. this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
  4853. }
  4854. this.editor.graph.setEnabled(file.isEditable());
  4855. // Ignores title and hash for revisions
  4856. if (urlParams['rev'] == null)
  4857. {
  4858. this.updateDocumentTitle();
  4859. var newHash = file.getHash();
  4860. if (newHash.length > 0)
  4861. {
  4862. window.location.hash = newHash;
  4863. }
  4864. else if (window.location.hash.length > 0)
  4865. {
  4866. window.location.hash = '';
  4867. }
  4868. }
  4869. }
  4870. };
  4871. /**
  4872. * Translates this point by the given vector.
  4873. *
  4874. * @param {number} dx X-coordinate of the translation.
  4875. * @param {number} dy Y-coordinate of the translation.
  4876. */
  4877. App.prototype.handleError = function(resp, title, fn)
  4878. {
  4879. var resume = this.spinner.pause();
  4880. var e = (resp != null && resp.error != null) ? resp.error : resp;
  4881. if (e != null || title != null)
  4882. {
  4883. var msg = mxResources.get('unknownError');
  4884. var btn = mxResources.get('ok');
  4885. var retry = null;
  4886. title = (title != null) ? title : mxResources.get('error');
  4887. if (e != null)
  4888. {
  4889. if (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' && typeof(gapi.drive.realtime) != 'undefined' &&
  4890. e.type == gapi.drive.realtime.ErrorType.FORBIDDEN)
  4891. {
  4892. msg = mxResources.get('forbidden');
  4893. }
  4894. else if (e.code == 404 || e.status == 404 || (typeof(gapi) != 'undefined' && typeof(gapi.drive) != 'undefined' &&
  4895. typeof(gapi.drive.realtime) != 'undefined' && e.type == gapi.drive.realtime.ErrorType.NOT_FOUND))
  4896. {
  4897. msg = mxResources.get('fileNotFoundOrDenied');
  4898. var id = window.location.hash;
  4899. if (id != null && id.substring(0, 2) == '#G')
  4900. {
  4901. id = id.substring(2);
  4902. msg += ' <a href="https://drive.google.com/open?id=' + id + '" target="_blank">' +
  4903. mxResources.get('tryOpeningViaThisPage') + '</a>';
  4904. }
  4905. }
  4906. else if (e.code == App.ERROR_TIMEOUT)
  4907. {
  4908. msg = mxResources.get('timeout');
  4909. if (e.retry != null)
  4910. {
  4911. btn = mxResources.get('cancel');
  4912. retry = function()
  4913. {
  4914. resume();
  4915. e.retry();
  4916. };
  4917. }
  4918. }
  4919. else if (e.code == App.ERROR_BUSY)
  4920. {
  4921. msg = mxResources.get('busy');
  4922. }
  4923. else if (e.message != null)
  4924. {
  4925. msg = e.message;
  4926. }
  4927. else if (e.response != null && e.response.error != null)
  4928. {
  4929. msg = e.response.error;
  4930. }
  4931. }
  4932. this.showError(title, msg, btn, fn, retry);
  4933. }
  4934. else if (fn != null)
  4935. {
  4936. fn();
  4937. }
  4938. };
  4939. /**
  4940. * Translates this point by the given vector.
  4941. *
  4942. * @param {number} dx X-coordinate of the translation.
  4943. * @param {number} dy Y-coordinate of the translation.
  4944. */
  4945. App.prototype.showError = function(title, msg, btn, fn, retry, btn2, fn2)
  4946. {
  4947. var dlg = new ErrorDialog(this, title, msg, btn, fn, retry, btn2, fn2);
  4948. this.showDialog(dlg.container, 340, 150, true, false);
  4949. dlg.init();
  4950. };
  4951. /**
  4952. * Translates this point by the given vector.
  4953. *
  4954. * @param {number} dx X-coordinate of the translation.
  4955. * @param {number} dy Y-coordinate of the translation.
  4956. */
  4957. App.prototype.alert = function(msg, fn)
  4958. {
  4959. var dlg = new ErrorDialog(this, null, msg, mxResources.get('ok'), fn);
  4960. this.showDialog(dlg.container, 340, 100, true, false);
  4961. dlg.init();
  4962. };
  4963. /**
  4964. * Translates this point by the given vector.
  4965. *
  4966. * @param {number} dx X-coordinate of the translation.
  4967. * @param {number} dy Y-coordinate of the translation.
  4968. */
  4969. App.prototype.confirm = function(msg, okFn, cancelFn)
  4970. {
  4971. var resume = (this.spinner.pause != null) ? this.spinner.pause() : function() {};
  4972. this.showDialog(new ConfirmDialog(this, msg, function()
  4973. {
  4974. resume();
  4975. if (okFn != null)
  4976. {
  4977. okFn();
  4978. }
  4979. }, function()
  4980. {
  4981. resume();
  4982. if (cancelFn != null)
  4983. {
  4984. cancelFn();
  4985. }
  4986. }).container, 340, 90, true, false);
  4987. };
  4988. /**
  4989. * Translates this point by the given vector.
  4990. *
  4991. * @param {number} dx X-coordinate of the translation.
  4992. * @param {number} dy Y-coordinate of the translation.
  4993. */
  4994. App.prototype.toggleChat = function()
  4995. {
  4996. var file = this.getCurrentFile();
  4997. if (file != null)
  4998. {
  4999. if (file.chatWindow == null)
  5000. {
  5001. var cwLeft = document.body.offsetWidth - 300;
  5002. file.chatWindow = new ChatWindow(this, mxResources.get('chatWindowTitle'), document.getElementById('geChat'), cwLeft , 80, 250, 350, file.realtime);
  5003. file.chatWindow.window.setVisible(false);
  5004. }
  5005. file.chatWindow.window.setVisible(!file.chatWindow.window.isVisible());
  5006. }
  5007. };
  5008. /**
  5009. * Translates this point by the given vector.
  5010. *
  5011. * @param {number} dx X-coordinate of the translation.
  5012. * @param {number} dy Y-coordinate of the translation.
  5013. */
  5014. App.prototype.status = function(html)
  5015. {
  5016. this.editor.setStatus(html);
  5017. };
  5018. /**
  5019. * Adds the listener for automatically saving the diagram for local changes.
  5020. */
  5021. App.prototype.showAuthDialog = function(peer, showRememberOption, fn)
  5022. {
  5023. var resume = this.spinner.pause();
  5024. this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
  5025. {
  5026. try
  5027. {
  5028. if (fn != null)
  5029. {
  5030. fn(remember, function()
  5031. {
  5032. resume();
  5033. });
  5034. }
  5035. }
  5036. catch (e)
  5037. {
  5038. this.editor.setStatus(e.message);
  5039. }
  5040. })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
  5041. {
  5042. if (cancel && this.getCurrentFile() == null && this.dialog == null)
  5043. {
  5044. this.showSplash();
  5045. }
  5046. }));
  5047. };
  5048. /**
  5049. * Checks if the client is authorized and calls the next step.
  5050. */
  5051. App.prototype.loadUrl = function(url, success, error, forceBinary, retry)
  5052. {
  5053. try
  5054. {
  5055. var binary = (forceBinary || /(\.png)($|\?)/i.test(url));
  5056. retry = (retry != null) ? retry : true;
  5057. var fn = mxUtils.bind(this, function()
  5058. {
  5059. mxUtils.get(url, mxUtils.bind(this, function(req)
  5060. {
  5061. if (req.getStatus() == 200)
  5062. {
  5063. if (success != null)
  5064. {
  5065. var data = req.getText();
  5066. // Returns PNG as base64 encoded data URI
  5067. if (binary)
  5068. {
  5069. // NOTE: This requires BinaryToArray VB script in the page
  5070. if ((document.documentMode == 9 || document.documentMode == 10) &&
  5071. typeof window.mxUtilsBinaryToArray !== 'undefined')
  5072. {
  5073. var bin = mxUtilsBinaryToArray(req.request.responseBody).toArray();
  5074. var tmp = new Array(bin.length);
  5075. for (var i = 0; i < bin.length; i++)
  5076. {
  5077. tmp[i] = String.fromCharCode(bin[i]);
  5078. }
  5079. data = tmp.join('');
  5080. }
  5081. data = 'data:image/png;base64,' + this.base64Encode(data);
  5082. }
  5083. success(data);
  5084. }
  5085. }
  5086. else if (error != null)
  5087. {
  5088. error({code: App.ERROR_UNKNOWN});
  5089. }
  5090. }), function()
  5091. {
  5092. if (error != null)
  5093. {
  5094. error({code: App.ERROR_UNKNOWN});
  5095. }
  5096. }, binary, this.timeout, function()
  5097. {
  5098. if (retry && error != null)
  5099. {
  5100. error({code: App.ERROR_TIMEOUT, retry: fn});
  5101. }
  5102. });
  5103. });
  5104. fn();
  5105. }
  5106. catch (e)
  5107. {
  5108. if (error != null)
  5109. {
  5110. error(e);
  5111. }
  5112. }
  5113. };
  5114. /**
  5115. * Adds the listener for automatically saving the diagram for local changes.
  5116. */
  5117. App.prototype.updateHeader = function()
  5118. {
  5119. if (this.menubar != null)
  5120. {
  5121. this.appIcon = document.createElement('a');
  5122. this.appIcon.style.display = 'block';
  5123. this.appIcon.style.position = 'absolute';
  5124. this.appIcon.style.width = '40px';
  5125. this.appIcon.style.backgroundColor = '#f18808';
  5126. this.appIcon.style.height = this.menubarHeight + 'px';
  5127. mxEvent.disableContextMenu(this.appIcon);
  5128. mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
  5129. {
  5130. this.appIconClicked(evt);
  5131. }));
  5132. // LATER: Use Alpha image loader in IE6
  5133. // NOTE: This uses the diagram bit of the old logo as it looks better in this case
  5134. //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
  5135. var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
  5136. 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
  5137. this.appIcon.style.backgroundImage = logo;
  5138. this.appIcon.style.backgroundPosition = 'center center';
  5139. this.appIcon.style.backgroundRepeat = 'no-repeat';
  5140. mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
  5141. mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
  5142. {
  5143. var file = this.getCurrentFile();
  5144. if (file != null)
  5145. {
  5146. var mode = file.getMode();
  5147. if (mode == App.MODE_GOOGLE)
  5148. {
  5149. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
  5150. }
  5151. else if (mode == App.MODE_DROPBOX)
  5152. {
  5153. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
  5154. }
  5155. else if (mode == App.MODE_ONEDRIVE)
  5156. {
  5157. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
  5158. }
  5159. }
  5160. }));
  5161. mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
  5162. {
  5163. this.appIcon.style.backgroundImage = logo;
  5164. }));
  5165. if (urlParams['embed'] != '1')
  5166. {
  5167. this.menubarContainer.appendChild(this.appIcon);
  5168. }
  5169. this.fnameWrapper = document.createElement('div');
  5170. this.fnameWrapper.style.position = 'absolute';
  5171. this.fnameWrapper.style.right = '120px';
  5172. this.fnameWrapper.style.left = '50px';
  5173. this.fnameWrapper.style.top = '6px';
  5174. this.fnameWrapper.style.height = '26px';
  5175. this.fnameWrapper.style.display = 'none';
  5176. this.fnameWrapper.style.overflow = 'hidden';
  5177. this.fnameWrapper.style.textOverflow = 'ellipsis';
  5178. this.fname = document.createElement('a');
  5179. this.fname.setAttribute('href', 'javascript:void(0);');
  5180. this.fname.setAttribute('title', mxResources.get('rename'));
  5181. this.fname.className = 'geItem';
  5182. this.fname.style.padding = '2px 8px 2px 8px';
  5183. this.fname.style.display = 'inline';
  5184. this.fname.style.fontSize = '18px';
  5185. this.fname.style.whiteSpace = 'nowrap';
  5186. mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
  5187. {
  5188. var file = this.getCurrentFile();
  5189. if (file != null && file.isRenamable())
  5190. {
  5191. this.actions.get('rename').funct();
  5192. }
  5193. mxEvent.consume(evt);
  5194. }));
  5195. this.fnameWrapper.appendChild(this.fname);
  5196. if (urlParams['embed'] != '1')
  5197. {
  5198. this.menubarContainer.appendChild(this.fnameWrapper);
  5199. this.menubar.container.style.position = 'absolute';
  5200. this.menubar.container.style.paddingLeft = '52px';
  5201. this.menubar.container.style.boxSizing = 'border-box';
  5202. this.menubar.container.style.top = '29px';
  5203. this.toolbar.container.style.paddingLeft = '56px';
  5204. }
  5205. /**
  5206. * Adds format panel toggle.
  5207. */
  5208. this.toggleFormatElement = document.createElement('a');
  5209. this.toggleFormatElement.setAttribute('href', 'javascript:void(0);');
  5210. this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (Ctrl+Shift+P)');
  5211. this.toggleFormatElement.style.position = 'absolute';
  5212. this.toggleFormatElement.style.display = 'inline-block';
  5213. this.toggleFormatElement.style.top = '5px';
  5214. this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '26px' : '10px';
  5215. this.toggleFormatElement.style.padding = '2px';
  5216. this.toggleFormatElement.style.fontSize = '14px';
  5217. this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  5218. this.toggleFormatElement.style.width = '16px';
  5219. this.toggleFormatElement.style.height = '16px';
  5220. this.toggleFormatElement.style.backgroundPosition = '50% 50%';
  5221. this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
  5222. this.toolbarContainer.appendChild(this.toggleFormatElement);
  5223. mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
  5224. {
  5225. this.actions.get('formatPanel').funct();
  5226. mxEvent.consume(evt);
  5227. }));
  5228. var toggleFormatPanel = mxUtils.bind(this, function()
  5229. {
  5230. if (this.formatWidth > 0)
  5231. {
  5232. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
  5233. }
  5234. else
  5235. {
  5236. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
  5237. }
  5238. });
  5239. this.addListener('formatWidthChanged', toggleFormatPanel);
  5240. toggleFormatPanel();
  5241. this.fullscreenElement = document.createElement('a');
  5242. this.fullscreenElement.setAttribute('href', 'javascript:void(0);');
  5243. this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
  5244. this.fullscreenElement.style.position = 'absolute';
  5245. this.fullscreenElement.style.display = 'inline-block';
  5246. this.fullscreenElement.style.top = '5px';
  5247. this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '42px' : '26px';
  5248. this.fullscreenElement.style.padding = '2px';
  5249. this.fullscreenElement.style.fontSize = '14px';
  5250. this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  5251. this.fullscreenElement.style.width = '16px';
  5252. this.fullscreenElement.style.height = '16px';
  5253. this.fullscreenElement.style.backgroundPosition = '50% 50%';
  5254. this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
  5255. this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
  5256. this.toolbarContainer.appendChild(this.fullscreenElement);
  5257. var initialPosition = this.hsplitPosition;
  5258. var collapsed = false;
  5259. mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
  5260. {
  5261. if (uiTheme != 'atlas' && urlParams['embed'] != '1')
  5262. {
  5263. this.toggleCompactMode(!collapsed);
  5264. }
  5265. this.toggleFormatPanel(!collapsed);
  5266. this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
  5267. this.hideFooter();
  5268. collapsed = !collapsed;
  5269. mxEvent.consume(evt);
  5270. }));
  5271. // Some style changes in Atlas theme
  5272. if (uiTheme == 'atlas')
  5273. {
  5274. mxUtils.setOpacity(this.toggleFormatElement, 70);
  5275. mxUtils.setOpacity(this.fullscreenElement, 70);
  5276. this.toggleFormatElement.style.right = '6px';
  5277. this.fullscreenElement.style.right = '22px';
  5278. this.toggleFormatElement.style.top = '8px';
  5279. this.fullscreenElement.style.top = '8px';
  5280. }
  5281. /**
  5282. * Adds compact UI toggle.
  5283. */
  5284. if (urlParams['embed'] != '1')
  5285. {
  5286. this.toggleElement = document.createElement('a');
  5287. this.toggleElement.setAttribute('href', 'javascript:void(0);');
  5288. this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
  5289. this.toggleElement.className = 'geButton';
  5290. this.toggleElement.style.position = 'absolute';
  5291. this.toggleElement.style.display = 'inline-block';
  5292. this.toggleElement.style.width = '16px';
  5293. this.toggleElement.style.height = '16px';
  5294. this.toggleElement.style.color = '#666';
  5295. this.toggleElement.style.top = '5px';
  5296. this.toggleElement.style.right = '10px';
  5297. this.toggleElement.style.padding = '2px';
  5298. this.toggleElement.style.fontSize = '14px';
  5299. this.toggleElement.style.textDecoration = 'none';
  5300. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  5301. this.toggleElement.style.backgroundPosition = '50% 50%';
  5302. this.toggleElement.style.backgroundRepeat = 'no-repeat';
  5303. // Toggles compact mode
  5304. mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
  5305. {
  5306. this.toggleCompactMode();
  5307. mxEvent.consume(evt);
  5308. }));
  5309. if (uiTheme != 'atlas')
  5310. {
  5311. this.toolbarContainer.appendChild(this.toggleElement);
  5312. }
  5313. // Enable compact mode for small screens
  5314. if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
  5315. {
  5316. window.setTimeout(mxUtils.bind(this, function()
  5317. {
  5318. this.toggleElement.click();
  5319. }), 0);
  5320. }
  5321. }
  5322. }
  5323. };
  5324. /**
  5325. * Adds the listener for automatically saving the diagram for local changes.
  5326. */
  5327. App.prototype.toggleCompactMode = function(forceHide)
  5328. {
  5329. if (!forceHide && this.appIcon.style.display == 'none')
  5330. {
  5331. this.menubar.container.style.position = 'absolute';
  5332. this.menubar.container.style.paddingLeft = '52px';
  5333. this.menubar.container.style.paddingTop = '';
  5334. this.menubar.container.style.paddingBottom = '';
  5335. this.menubar.container.style.top = '29px';
  5336. this.toolbar.container.style.paddingLeft = '56px';
  5337. this.buttonContainer.style.visibility = 'visible';
  5338. this.appIcon.style.display = 'block';
  5339. this.fnameWrapper.style.display = 'block';
  5340. this.fnameWrapper.style.visibility = 'visible';
  5341. this.menubarHeight = App.prototype.menubarHeight;
  5342. this.refresh();
  5343. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  5344. }
  5345. else
  5346. {
  5347. this.menubar.container.style.position = 'relative';
  5348. this.menubar.container.style.paddingLeft = '4px';
  5349. this.menubar.container.style.paddingTop = '0px';
  5350. this.menubar.container.style.paddingBottom = '0px';
  5351. this.menubar.container.style.top = '0px';
  5352. this.toolbar.container.style.paddingLeft = '4px';
  5353. this.buttonContainer.style.visibility = 'hidden';
  5354. this.appIcon.style.display = 'none';
  5355. this.fnameWrapper.style.display = 'none';
  5356. this.fnameWrapper.style.visibility = 'hidden';
  5357. this.menubarHeight = EditorUi.prototype.menubarHeight;
  5358. this.refresh();
  5359. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
  5360. }
  5361. };
  5362. /**
  5363. * Adds the listener for automatically saving the diagram for local changes.
  5364. */
  5365. App.prototype.updateUserElement = function()
  5366. {
  5367. if ((this.drive == null || this.drive.getUser() == null) &&
  5368. (this.oneDrive == null || this.oneDrive.getUser() == null) &&
  5369. (this.dropbox == null || this.dropbox.getUser() == null))
  5370. {
  5371. if (this.userElement != null)
  5372. {
  5373. this.userElement.parentNode.removeChild(this.userElement);
  5374. this.userElement = null;
  5375. }
  5376. }
  5377. else
  5378. {
  5379. if (this.userElement == null)
  5380. {
  5381. this.userElement = document.createElement('a');
  5382. this.userElement.setAttribute('href', 'javascript:void(0);');
  5383. this.userElement.className = 'geItem';
  5384. this.userElement.style.position = 'absolute';
  5385. this.userElement.style.fontSize = '8pt';
  5386. this.userElement.style.top = '4px';
  5387. this.userElement.style.right = '30px';
  5388. this.userElement.style.color = '#666';
  5389. this.userElement.style.margin = '4px';
  5390. this.userElement.style.padding = '2px';
  5391. this.userElement.style.paddingRight = '16px';
  5392. this.userElement.style.verticalAlign = 'middle';
  5393. this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  5394. this.userElement.style.backgroundPosition = '100% 60%';
  5395. this.userElement.style.backgroundRepeat = 'no-repeat';
  5396. this.menubarContainer.appendChild(this.userElement);
  5397. mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
  5398. {
  5399. if (this.userPanel == null)
  5400. {
  5401. var div = document.createElement('div');
  5402. div.className = 'geDialog';
  5403. div.style.position = 'absolute';
  5404. div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
  5405. div.style.right = '36px';
  5406. div.style.padding = '0px';
  5407. this.userPanel = div;
  5408. }
  5409. if (this.userPanel.parentNode != null)
  5410. {
  5411. this.userPanel.parentNode.removeChild(this.userPanel);
  5412. }
  5413. else
  5414. {
  5415. var connected = false;
  5416. this.userPanel.innerHTML = '';
  5417. var img = document.createElement('img');
  5418. img.setAttribute('src', Dialog.prototype.closeImage);
  5419. img.setAttribute('title', mxResources.get('close'));
  5420. img.className = 'geDialogClose';
  5421. img.style.top = '8px';
  5422. img.style.right = '8px';
  5423. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  5424. {
  5425. if (this.userPanel.parentNode != null)
  5426. {
  5427. this.userPanel.parentNode.removeChild(this.userPanel);
  5428. }
  5429. }));
  5430. this.userPanel.appendChild(img);
  5431. if (this.drive != null)
  5432. {
  5433. var driveUser = this.drive.getUser();
  5434. if (driveUser != null)
  5435. {
  5436. connected = true;
  5437. this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
  5438. '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
  5439. '<tr><td valign="top">' +
  5440. ((driveUser.pictureUrl != null) ?
  5441. '<img style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
  5442. '<img style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
  5443. '</td><td valign="top" style="white-space:nowrap;' +
  5444. ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
  5445. '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
  5446. '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small></tr></table>';
  5447. var div = document.createElement('div');
  5448. div.style.textAlign = 'center';
  5449. div.style.padding = '12px';
  5450. div.style.background = 'whiteSmoke';
  5451. div.style.borderTop = '1px solid #e0e0e0';
  5452. div.style.whiteSpace = 'nowrap';
  5453. // LATER: Cannot change user while file is open since close will not work with new
  5454. // credentials and closing the file using fileLoaded(null) will show splash dialog.
  5455. div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
  5456. {
  5457. var file = this.getCurrentFile();
  5458. if (file != null && file.constructor == DriveFile)
  5459. {
  5460. this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
  5461. {
  5462. this.diagramContainer.style.visibility = 'hidden';
  5463. this.formatContainer.style.visibility = 'hidden';
  5464. this.hsplit.style.display = 'none';
  5465. this.sidebarContainer.style.display = 'none';
  5466. this.sidebarFooterContainer.style.display = 'none';
  5467. file.close();
  5468. // LATER: Use callback to wait for thumbnail update
  5469. window.setTimeout(mxUtils.bind(this, function()
  5470. {
  5471. // Workaround to disable the splash screen before reload
  5472. this.showDialog = function() {};
  5473. window.location.hash = '';
  5474. this.drive.clearUserId();
  5475. gapi.auth.signOut();
  5476. // Reload page to reset client auth
  5477. window.location.reload();
  5478. }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
  5479. }));
  5480. }
  5481. else
  5482. {
  5483. this.drive.clearUserId();
  5484. this.drive.setUser(null);
  5485. gapi.auth.signOut();
  5486. }
  5487. })));
  5488. this.userPanel.appendChild(div);
  5489. }
  5490. }
  5491. var addUser = mxUtils.bind(this, function(user, logo, logout)
  5492. {
  5493. if (user != null)
  5494. {
  5495. if (connected)
  5496. {
  5497. this.userPanel.appendChild(document.createElement('hr'));
  5498. }
  5499. connected = true;
  5500. this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
  5501. ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
  5502. '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
  5503. ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font></td>' : '') +
  5504. '</tr></table>';
  5505. var div = document.createElement('div');
  5506. div.style.textAlign = 'center';
  5507. div.style.padding = '12px';
  5508. div.style.background = 'whiteSmoke';
  5509. div.style.borderTop = '1px solid #e0e0e0';
  5510. div.style.whiteSpace = 'nowrap';
  5511. if (logout != null)
  5512. {
  5513. div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
  5514. }
  5515. this.userPanel.appendChild(div);
  5516. }
  5517. });
  5518. if (this.dropbox != null)
  5519. {
  5520. addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
  5521. {
  5522. var file = this.getCurrentFile();
  5523. if (file != null && file.constructor == DropboxFile)
  5524. {
  5525. var doLogout = mxUtils.bind(this, function()
  5526. {
  5527. this.dropbox.logout();
  5528. window.location.hash = '';
  5529. });
  5530. if (!file.isModified())
  5531. {
  5532. doLogout();
  5533. }
  5534. else
  5535. {
  5536. this.confirm(mxResources.get('allChangesLost'), doLogout);
  5537. }
  5538. }
  5539. else
  5540. {
  5541. this.dropbox.logout();
  5542. }
  5543. }));
  5544. }
  5545. if (this.oneDrive != null)
  5546. {
  5547. addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
  5548. {
  5549. var file = this.getCurrentFile();
  5550. if (file != null && file.constructor == OneDriveFile)
  5551. {
  5552. var doLogout = mxUtils.bind(this, function()
  5553. {
  5554. this.oneDrive.logout();
  5555. window.location.hash = '';
  5556. });
  5557. if (!file.isModified())
  5558. {
  5559. doLogout();
  5560. }
  5561. else
  5562. {
  5563. this.confirm(mxResources.get('allChangesLost'), doLogout);
  5564. }
  5565. }
  5566. else
  5567. {
  5568. this.oneDrive.logout();
  5569. }
  5570. }));
  5571. }
  5572. if (!connected)
  5573. {
  5574. var div = document.createElement('div');
  5575. div.style.textAlign = 'center';
  5576. div.style.padding = '20px 20px 10px 10px';
  5577. div.innerHTML = mxResources.get('notConnected');
  5578. this.userPanel.appendChild(div);
  5579. }
  5580. document.body.appendChild(this.userPanel);
  5581. }
  5582. mxEvent.consume(evt);
  5583. }));
  5584. mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
  5585. {
  5586. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5587. {
  5588. this.userPanel.parentNode.removeChild(this.userPanel);
  5589. }
  5590. }));
  5591. }
  5592. var user = null;
  5593. if (this.drive != null && this.drive.getUser() != null)
  5594. {
  5595. user = this.drive.getUser();
  5596. }
  5597. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5598. {
  5599. user = this.oneDrive.getUser();
  5600. }
  5601. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5602. {
  5603. user = this.dropbox.getUser();
  5604. }
  5605. if (user != null)
  5606. {
  5607. this.userElement.innerHTML = '';
  5608. mxUtils.write(this.userElement, user.displayName);
  5609. this.userElement.style.display = 'block';
  5610. }
  5611. else
  5612. {
  5613. this.userElement.style.display = 'none';
  5614. }
  5615. }
  5616. };
  5617. // Handles paste from lucid chart
  5618. (function()
  5619. {
  5620. var loading = false;
  5621. var editorUiPasteCells = EditorUi.prototype.pasteCells;
  5622. EditorUi.prototype.pasteCells = function(evt, elt)
  5623. {
  5624. var spans = elt.getElementsByTagName('span');
  5625. if (spans != null && spans.length > 0 && spans[0].getAttribute('data-lucid-type') ===
  5626. 'application/vnd.lucid.chart.objects')
  5627. {
  5628. var content = spans[0].getAttribute('data-lucid-content');
  5629. if (content != null && content.length > 0)
  5630. {
  5631. var delayed = mxUtils.bind(this, function()
  5632. {
  5633. // Checks for signature method
  5634. if (this.pasteLucidChart)
  5635. {
  5636. try
  5637. {
  5638. this.pasteLucidChart(JSON.parse(content))
  5639. mxEvent.consume(evt);
  5640. }
  5641. catch (e)
  5642. {
  5643. // ignore
  5644. }
  5645. }
  5646. });
  5647. if (!this.pasteLucidChart && !loading && !this.isOffline())
  5648. {
  5649. loading = true;
  5650. if (urlParams['dev'] == '1')
  5651. {
  5652. mxscript('/js/diagramly/Extensions.js', delayed);
  5653. }
  5654. else
  5655. {
  5656. mxscript('/js/extensions.min.js', delayed);
  5657. }
  5658. }
  5659. else
  5660. {
  5661. delayed();
  5662. }
  5663. }
  5664. }
  5665. editorUiPasteCells.apply(this, arguments);
  5666. };
  5667. })();