App.js 185 KB

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