App.js 154 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762
  1. /**
  2. * Copyright (c) 2006-2018, JGraph Ltd
  3. * Copyright (c) 2006-2018, 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 :
  16. (urlParams['lightbox'] == '1' || (uiTheme == 'min' &&
  17. urlParams['chrome'] != '0')));
  18. // Logs unloading of window with modifications for Google Drive file
  19. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  20. {
  21. window.onunload = mxUtils.bind(this, function()
  22. {
  23. var file = this.getCurrentFile();
  24. if (file != null && file.constructor == DriveFile && file.isModified() && this.drive != null)
  25. {
  26. EditorUi.logEvent({category: 'DISCARD-SAVE-FILE-' + file.getHash() + '.' +
  27. file.desc.headRevisionId + '.' + file.desc.modifiedDate + '-size-' + file.getSize(),
  28. action: 'time-' + new Date().toISOString() + '-saved-' +
  29. ((file.lastSaved != null) ? file.lastSaved.toISOString() : 'never') +
  30. ((this.editor.autosave) ? '-autosave-on' : '-autosave-off'),
  31. label: (this.drive.user != null) ? this.drive.user.id : 'unknown-user'});
  32. }
  33. else if (file != null && file.isModified())
  34. {
  35. EditorUi.logEvent({category: 'DISCARD-SAVE-FILE-' + file.getHash(), action: 'unload',
  36. label: ((this.editor.autosave) ? 'autosave-on' : 'autosave-off')});
  37. }
  38. });
  39. }
  40. // Pre-fetches images
  41. if (mxClient.IS_SVG)
  42. {
  43. 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=';
  44. }
  45. else
  46. {
  47. var img = new Image();
  48. img.src = mxGraph.prototype.warningImage.src;
  49. }
  50. // Global helper method to deal with popup blockers
  51. window.openWindow = mxUtils.bind(this, function(url, pre, fallback)
  52. {
  53. var wnd = null;
  54. try
  55. {
  56. wnd = window.open(url);
  57. }
  58. catch (e)
  59. {
  60. // ignore
  61. }
  62. if (wnd == null || wnd === undefined)
  63. {
  64. this.showDialog(new PopupDialog(this, url, pre, fallback).container, 320, 140, true, true);
  65. }
  66. else if (pre != null)
  67. {
  68. pre();
  69. }
  70. });
  71. // Initial state for toolbar items is disabled
  72. this.updateDocumentTitle();
  73. this.updateUi();
  74. // Global helper method to display error messages
  75. window.showOpenAlert = mxUtils.bind(this, function(message)
  76. {
  77. // Cancel must be called before showing error message
  78. if (window.openFile != null)
  79. {
  80. window.openFile.cancel(true);
  81. }
  82. this.handleError(message);
  83. });
  84. // Handles opening files via drag and drop
  85. if (!this.editor.chromeless || this.editor.editable)
  86. {
  87. this.addFileDropHandler([document]);
  88. }
  89. // Process the queue for waiting plugins
  90. if (App.DrawPlugins != null)
  91. {
  92. for (var i = 0; i < App.DrawPlugins.length; i++)
  93. {
  94. try
  95. {
  96. App.DrawPlugins[i](this);
  97. }
  98. catch (e)
  99. {
  100. if (window.console != null)
  101. {
  102. console.log('Plugin Error:', e, App.DrawPlugins[i]);
  103. }
  104. }
  105. finally
  106. {
  107. App.embedModePluginsCount--;
  108. this.initializeEmbedMode();
  109. }
  110. }
  111. // Installs global callback for plugins
  112. window.Draw.loadPlugin = mxUtils.bind(this, function(callback)
  113. {
  114. try
  115. {
  116. callback(this);
  117. }
  118. finally
  119. {
  120. App.embedModePluginsCount--;
  121. this.initializeEmbedMode();
  122. }
  123. });
  124. //Set a timeout in case a plugin doesn't load quickly or doesn't load at all
  125. setTimeout(mxUtils.bind(this, function()
  126. {
  127. //Force finish loading if its not yet called
  128. if (App.embedModePluginsCount > 0)
  129. {
  130. App.embedModePluginsCount = 0;
  131. this.initializeEmbedMode();
  132. }
  133. }), 5000); //5 sec timeout
  134. }
  135. this.load();
  136. };
  137. /**
  138. * Executes the first step for connecting to Google Drive.
  139. */
  140. App.ERROR_TIMEOUT = 'timeout';
  141. /**
  142. * Executes the first step for connecting to Google Drive.
  143. */
  144. App.ERROR_BUSY = 'busy';
  145. /**
  146. * Executes the first step for connecting to Google Drive.
  147. */
  148. App.ERROR_UNKNOWN = 'unknown';
  149. /**
  150. * Sets the delay for autosave in milliseconds. Default is 2000.
  151. */
  152. App.MODE_GOOGLE = 'google';
  153. /**
  154. * Sets the delay for autosave in milliseconds. Default is 2000.
  155. */
  156. App.MODE_DROPBOX = 'dropbox';
  157. /**
  158. * Sets the delay for autosave in milliseconds. Default is 2000.
  159. */
  160. App.MODE_ONEDRIVE = 'onedrive';
  161. /**
  162. * Sets the delay for autosave in milliseconds. Default is 2000.
  163. */
  164. App.MODE_GITHUB = 'github';
  165. /**
  166. * Sets the delay for autosave in milliseconds. Default is 2000.
  167. */
  168. App.MODE_DEVICE = 'device';
  169. /**
  170. * Sets the delay for autosave in milliseconds. Default is 2000.
  171. */
  172. App.MODE_BROWSER = 'browser';
  173. /**
  174. * Trello App Mode
  175. */
  176. App.MODE_TRELLO = 'trello';
  177. /**
  178. * Sets the delay for autosave in milliseconds. Default is 2000.
  179. */
  180. App.DROPBOX_APPKEY = 'libwls2fa9szdji';
  181. /**
  182. * Sets URL to load the Dropbox SDK from
  183. */
  184. App.DROPBOX_URL = 'js/dropbox/Dropbox-sdk.min.js';
  185. /**
  186. * Sets the delay for autosave in milliseconds. Default is 2000.
  187. */
  188. App.DROPINS_URL = 'https://www.dropbox.com/static/api/2/dropins.js';
  189. /**
  190. * OneDrive Client JS (file/folder picker). This is a slightly modified version to allow using accessTokens
  191. * But it doesn't work for IE11, so we fallback to the original one
  192. */
  193. App.ONEDRIVE_URL = mxClient.IS_IE11? 'https://js.live.net/v7.2/OneDrive.js' : 'js/onedrive/OneDrive.js';
  194. /**
  195. * Trello URL
  196. */
  197. App.TRELLO_URL = 'https://api.trello.com/1/client.js';
  198. /**
  199. * Trello JQuery dependency
  200. */
  201. App.TRELLO_JQUERY_URL = 'https://code.jquery.com/jquery-1.7.1.min.js';
  202. /**
  203. * Trello JQuery dependency
  204. */
  205. App.FOOTER_PLUGIN_URL = 'https://www.jgraph.com/drawio-footer.js';
  206. /**
  207. * Specifies the key for the pusher project.
  208. */
  209. App.PUSHER_KEY = '1e756b07a690c5bdb054';
  210. /**
  211. * Specifies the key for the pusher project.
  212. */
  213. App.PUSHER_CLUSTER = 'eu';
  214. /**
  215. * Specifies the URL for the pusher API.
  216. */
  217. App.PUSHER_URL = 'https://js.pusher.com/4.3/pusher.min.js';
  218. /**
  219. * Google APIs to load. The realtime API is needed to notify collaborators of conversion
  220. * of the realtime files, but after Dec 11 it's read-only and hence no longer needed.
  221. */
  222. App.GOOGLE_APIS = 'client,drive-share';
  223. /**
  224. * Defines plugin IDs for loading via p URL parameter. Update the table at
  225. * https://desk.draw.io/solution/articles/16000042546
  226. */
  227. App.pluginRegistry = {'4xAKTrabTpTzahoLthkwPNUn': '/plugins/explore.js',
  228. 'ex': '/plugins/explore.js', 'p1': '/plugins/p1.js',
  229. 'ac': '/plugins/connect.js', 'acj': '/plugins/connectJira.js',
  230. 'ac148': '/plugins/cConf-1-4-8.js', 'voice': '/plugins/voice.js',
  231. 'tips': '/plugins/tooltips.js', 'svgdata': '/plugins/svgdata.js',
  232. 'electron': 'plugins/electron.js',
  233. 'number': '/plugins/number.js', 'sql': '/plugins/sql.js',
  234. 'props': '/plugins/props.js', 'text': '/plugins/text.js',
  235. 'anim': '/plugins/animation.js', 'update': '/plugins/update.js',
  236. 'trees': '/plugins/trees/trees.js', 'import': '/plugins/import.js',
  237. 'replay': '/plugins/replay.js', 'anon': '/plugins/anonymize.js',
  238. 'tr': '/plugins/trello.js', 'f5': '/plugins/rackF5.js',
  239. 'tickets': '/plugins/tickets.js', 'flow': '/plugins/flow.js',
  240. 'webcola': '/plugins/webcola/webcola.js', 'rnd': '/plugins/random.js',
  241. 'page': '/plugins/page.js', 'gd': '/plugins/googledrive.js'};
  242. /**
  243. * Function: authorize
  244. *
  245. * Authorizes the client, gets the userId and calls <open>.
  246. */
  247. App.getStoredMode = function()
  248. {
  249. var mode = null;
  250. if (mode == null && isLocalStorage)
  251. {
  252. mode = localStorage.getItem('.mode');
  253. }
  254. if (mode == null && typeof(Storage) != 'undefined')
  255. {
  256. var cookies = document.cookie.split(";");
  257. for (var i = 0; i < cookies.length; i++)
  258. {
  259. // Removes spaces around cookie
  260. var cookie = mxUtils.trim(cookies[i]);
  261. if (cookie.substring(0, 5) == 'MODE=')
  262. {
  263. mode = cookie.substring(5);
  264. break;
  265. }
  266. }
  267. if (mode != null && isLocalStorage)
  268. {
  269. // Moves to local storage
  270. var expiry = new Date();
  271. expiry.setYear(expiry.getFullYear() - 1);
  272. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  273. localStorage.setItem('.mode', mode);
  274. }
  275. }
  276. return mode;
  277. };
  278. /**
  279. * Static Application initializer executed at load-time.
  280. */
  281. (function()
  282. {
  283. if (!mxClient.IS_CHROMEAPP)
  284. {
  285. if (urlParams['offline'] != '1')
  286. {
  287. // Switches to dropbox mode for db.draw.io
  288. if (window.location.hostname == 'db.draw.io' && urlParams['mode'] == null)
  289. {
  290. urlParams['mode'] = 'dropbox';
  291. }
  292. App.mode = urlParams['mode'];
  293. if (App.mode == null)
  294. {
  295. // Stored mode overrides preferred mode
  296. App.mode = App.getStoredMode();
  297. }
  298. }
  299. /**
  300. * Lazy loading backends.
  301. */
  302. if (window.mxscript != null)
  303. {
  304. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  305. if (urlParams['embed'] != '1')
  306. {
  307. if (typeof window.DriveClient === 'function')
  308. {
  309. if (urlParams['gapi'] != '0' && isSvgBrowser &&
  310. (document.documentMode == null || document.documentMode >= 10))
  311. {
  312. // Immediately loads client
  313. if (App.mode == App.MODE_GOOGLE || (urlParams['state'] != null &&
  314. window.location.hash == '') || (window.location.hash != null &&
  315. window.location.hash.substring(0, 2) == '#G'))
  316. {
  317. mxscript('https://apis.google.com/js/api.js');
  318. }
  319. // Keeps lazy loading for fallback to authenticated Google file if not public in loadFile
  320. else if (urlParams['chrome'] == '0' && (window.location.hash == null ||
  321. window.location.hash.substring(0, 45) !== '#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D'))
  322. {
  323. // Disables loading of client
  324. window.DriveClient = null;
  325. }
  326. }
  327. else
  328. {
  329. // Disables loading of client
  330. window.DriveClient = null;
  331. }
  332. }
  333. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  334. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  335. if (typeof window.DropboxClient === 'function')
  336. {
  337. if (urlParams['db'] != '0' && isSvgBrowser &&
  338. (document.documentMode == null || document.documentMode > 9))
  339. {
  340. // Immediately loads client
  341. if (App.mode == App.MODE_DROPBOX || (window.location.hash != null &&
  342. window.location.hash.substring(0, 2) == '#D'))
  343. {
  344. mxscript(App.DROPBOX_URL);
  345. // Must load this after the dropbox SDK since they use the same namespace
  346. mxscript(App.DROPINS_URL, null, 'dropboxjs', App.DROPBOX_APPKEY);
  347. }
  348. else if (urlParams['chrome'] == '0')
  349. {
  350. window.DropboxClient = null;
  351. }
  352. }
  353. else
  354. {
  355. // Disables loading of client
  356. window.DropboxClient = null;
  357. }
  358. }
  359. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  360. if (typeof window.OneDriveClient === 'function')
  361. {
  362. if (urlParams['od'] != '0' && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))
  363. {
  364. // Immediately loads client
  365. if (App.mode == App.MODE_ONEDRIVE || (window.location.hash != null &&
  366. window.location.hash.substring(0, 2) == '#W'))
  367. {
  368. mxscript(App.ONEDRIVE_URL);
  369. }
  370. else if (urlParams['chrome'] == '0')
  371. {
  372. window.OneDriveClient = null;
  373. }
  374. }
  375. else
  376. {
  377. // Disables loading of client
  378. window.OneDriveClient = null;
  379. }
  380. }
  381. // Loads Trello for all browsers but < IE10 if not disabled or if enabled and in embed mode
  382. if (typeof window.TrelloClient === 'function')
  383. {
  384. if (urlParams['tr'] != '0' && isSvgBrowser &&
  385. (document.documentMode == null || document.documentMode >= 10))
  386. {
  387. // Immediately loads client
  388. if (App.mode == App.MODE_TRELLO || (window.location.hash != null &&
  389. window.location.hash.substring(0, 2) == '#T'))
  390. {
  391. mxscript(App.TRELLO_JQUERY_URL);
  392. mxscript(App.TRELLO_URL);
  393. }
  394. else if (urlParams['chrome'] == '0')
  395. {
  396. window.TrelloClient = null;
  397. }
  398. }
  399. else
  400. {
  401. // Disables loading of client
  402. window.TrelloClient = null;
  403. }
  404. }
  405. }
  406. // Loads JSON for older browsers
  407. if (typeof(JSON) == 'undefined')
  408. {
  409. mxscript('js/json/json2.min.js');
  410. }
  411. }
  412. }
  413. })();
  414. /**
  415. * Program flow starts here.
  416. *
  417. * Optional callback is called with the app instance.
  418. */
  419. App.main = function(callback, createUi)
  420. {
  421. // Logs uncaught errors
  422. window.onerror = function(message, url, linenumber, colno, err)
  423. {
  424. EditorUi.logError(message, url, linenumber, colno, err);
  425. };
  426. // Removes info text in embed mode
  427. if (urlParams['embed'] == '1' || urlParams['lightbox'] == '1')
  428. {
  429. var geInfo = document.getElementById('geInfo');
  430. if (geInfo != null)
  431. {
  432. geInfo.parentNode.removeChild(geInfo);
  433. }
  434. }
  435. // Redirects to the latest AWS icons
  436. if (document.referrer != null && urlParams['libs'] == 'aws3' &&
  437. document.referrer.substring(0, 42) == 'https://aws.amazon.com/architecture/icons/')
  438. {
  439. urlParams['libs'] = 'aws4';
  440. }
  441. if (window.mxscript != null)
  442. {
  443. // Injects offline dependencies
  444. if (urlParams['offline'] == '1' || urlParams['appcache'] == '1')
  445. {
  446. mxscript('js/shapes.min.js');
  447. mxscript('js/stencils.min.js');
  448. mxscript('js/extensions.min.js');
  449. var frame = document.createElement('iframe');
  450. frame.setAttribute('width', '0');
  451. frame.setAttribute('height', '0');
  452. frame.setAttribute('src', 'offline.html');
  453. document.body.appendChild(frame);
  454. }
  455. // Loads Pusher API
  456. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && DrawioFile.SYNC == 'auto' &&
  457. urlParams['stealth'] != '1' && urlParams['offline'] != '1')
  458. {
  459. // TODO: Check if async loading is fast enough
  460. mxscript(App.PUSHER_URL);
  461. }
  462. // Loads plugins
  463. if (urlParams['plugins'] != '0' && urlParams['offline'] != '1')
  464. {
  465. // mxSettings is not yet initialized in configure mode, redirect parameter
  466. // to p URL parameter in caller for plugins in embed mode
  467. var plugins = (mxSettings.settings != null) ? mxSettings.getPlugins() : null;
  468. var temp = urlParams['p'];
  469. App.initPluginCallback();
  470. if (temp != null)
  471. {
  472. // Mapping from key to URL in App.plugins
  473. App.loadPlugins(temp.split(';'));
  474. }
  475. if (plugins != null && plugins.length > 0 && urlParams['plugins'] != '0')
  476. {
  477. // Loading plugins inside the asynchronous block below stops the page from loading so a
  478. // hardcoded message for the warning dialog is used since the resources are loadd below
  479. 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';
  480. var tmp = window.location.protocol + '//' + window.location.host;
  481. var local = true;
  482. for (var i = 0; i < plugins.length && local; i++)
  483. {
  484. if (plugins[i].charAt(0) != '/' && plugins[i].substring(0, tmp.length) != tmp)
  485. {
  486. local = false;
  487. }
  488. }
  489. if (local || mxUtils.confirm(mxResources.replacePlaceholders(warning, [plugins.join('\n')]).replace(/\\n/g, '\n')))
  490. {
  491. for (var i = 0; i < plugins.length; i++)
  492. {
  493. try
  494. {
  495. if (App.pluginsLoaded[plugins[i]] == null)
  496. {
  497. App.pluginsLoaded[plugins[i]] = true;
  498. App.embedModePluginsCount++;
  499. mxscript(plugins[i]);
  500. }
  501. }
  502. catch (e)
  503. {
  504. // ignore
  505. }
  506. }
  507. }
  508. }
  509. }
  510. // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
  511. // Special case: Cannot load in asynchronous code below
  512. if (typeof window.DriveClient === 'function' &&
  513. (typeof gapi === 'undefined' && (((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  514. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && isSvgBrowser &&
  515. isLocalStorage && (document.documentMode == null || document.documentMode >= 10))))
  516. {
  517. mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback', null, null, null, mxClient.IS_SVG);
  518. }
  519. // Disables client
  520. else if (typeof window.gapi === 'undefined')
  521. {
  522. window.DriveClient = null;
  523. }
  524. }
  525. /**
  526. * Asynchronous MathJax extension.
  527. */
  528. if (urlParams['math'] != '0')
  529. {
  530. Editor.initMath();
  531. }
  532. function doLoad(bundle)
  533. {
  534. // Prefetches asynchronous requests so that below code runs synchronous
  535. // Loading the correct bundle (one file) via the fallback system in mxResources. The stylesheet
  536. // is compiled into JS in the build process and is only needed for local development.
  537. mxUtils.getAll((urlParams['dev'] != '1') ? [bundle] : [bundle,
  538. STYLE_PATH + '/default.xml', STYLE_PATH + '/dark-default.xml'], function(xhr)
  539. {
  540. // Adds bundle text to resources
  541. mxResources.parse(xhr[0].getText());
  542. // Prepares themes with mapping from old default-style to old XML file
  543. if (xhr.length > 2)
  544. {
  545. Graph.prototype.defaultThemes['default-style2'] = xhr[1].getDocumentElement();
  546. Graph.prototype.defaultThemes['darkTheme'] = xhr[2].getDocumentElement();
  547. }
  548. // Main
  549. var ui = (createUi != null) ? createUi() : new App(new Editor(
  550. urlParams['chrome'] == '0' || uiTheme == 'min',
  551. null, null, null, urlParams['chrome'] != '0'));
  552. if (window.mxscript != null)
  553. {
  554. // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
  555. // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
  556. if (typeof window.DropboxClient === 'function' &&
  557. (window.Dropbox == null && window.DrawDropboxClientCallback != null &&
  558. (((urlParams['embed'] != '1' && urlParams['db'] != '0') ||
  559. (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  560. isSvgBrowser && (document.documentMode == null || document.documentMode > 9))))
  561. {
  562. mxscript(App.DROPBOX_URL, function()
  563. {
  564. // Must load this after the dropbox SDK since they use the same namespace
  565. mxscript(App.DROPINS_URL, function()
  566. {
  567. DrawDropboxClientCallback();
  568. }, 'dropboxjs', App.DROPBOX_APPKEY);
  569. });
  570. }
  571. // Disables client
  572. else if (typeof window.Dropbox === 'undefined' || typeof window.Dropbox.choose === 'undefined')
  573. {
  574. window.DropboxClient = null;
  575. }
  576. // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
  577. if (typeof window.OneDriveClient === 'function' &&
  578. (typeof OneDrive === 'undefined' && window.DrawOneDriveClientCallback != null &&
  579. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  580. urlParams['od'] == '1')) && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  581. {
  582. mxscript(App.ONEDRIVE_URL, window.DrawOneDriveClientCallback);
  583. }
  584. // Disables client
  585. else if (typeof window.OneDrive === 'undefined')
  586. {
  587. window.OneDriveClient = null;
  588. }
  589. // Loads Trello for all browsers but < IE10 if not disabled or if enabled and in embed mode
  590. if (typeof window.TrelloClient === 'function' &&
  591. (typeof window.Trello === 'undefined' && window.DrawTrelloClientCallback != null &&
  592. (((urlParams['embed'] != '1' && urlParams['tr'] != '0') || (urlParams['embed'] == '1' &&
  593. urlParams['tr'] == '1')) && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
  594. {
  595. mxscript(App.TRELLO_JQUERY_URL, function()
  596. {
  597. // Must load this after the dropbox SDK since they use the same namespace
  598. mxscript(App.TRELLO_URL, function()
  599. {
  600. DrawTrelloClientCallback();
  601. });
  602. });
  603. }
  604. // Disables client
  605. else if (typeof window.Trello === 'undefined')
  606. {
  607. window.TrelloClient = null;
  608. }
  609. }
  610. if (callback != null)
  611. {
  612. callback(ui);
  613. }
  614. /**
  615. * For developers only
  616. */
  617. if (urlParams['chrome'] != '0' && urlParams['test'] == '1')
  618. {
  619. EditorUi.debug('Started in ' + (new Date().getTime() - t0.getTime()) + 'ms');
  620. if (urlParams['export'] != null)
  621. {
  622. EditorUi.debug('Export:', EXPORT_URL);
  623. }
  624. }
  625. }, function(xhr)
  626. {
  627. var st = document.getElementById('geStatus');
  628. if (st != null)
  629. {
  630. st.innerHTML = 'Error loading page. <a>Please try refreshing.</a>';
  631. // Tries reload with default resources in case any language resources were not available
  632. st.getElementsByTagName('a')[0].onclick = function()
  633. {
  634. mxLanguage = 'en';
  635. doLoad(mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
  636. mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage));
  637. };
  638. }
  639. });
  640. };
  641. function doMain()
  642. {
  643. // Adds required resources (disables loading of fallback properties, this can only
  644. // be used if we know that all keys are defined in the language specific file)
  645. mxResources.loadDefaultBundle = false;
  646. doLoad(mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
  647. mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage));
  648. };
  649. // Optional override for autosaveDelay and defaultEdgeLength
  650. try
  651. {
  652. if (mxSettings.settings != null)
  653. {
  654. if (mxSettings.settings.autosaveDelay != null)
  655. {
  656. var val = parseInt(mxSettings.settings.autosaveDelay);
  657. if (!isNaN(val) && val > 0)
  658. {
  659. DrawioFile.prototype.autosaveDelay = val;
  660. if (window.console != null)
  661. {
  662. console.log('Setting autosaveDelay to ' + DrawioFile.prototype.autosaveDelay);
  663. }
  664. }
  665. else
  666. {
  667. if (window.console != null)
  668. {
  669. console.log('Invalid value for autosaveDelay');
  670. }
  671. }
  672. }
  673. if (mxSettings.settings.defaultEdgeLength != null)
  674. {
  675. var val = parseInt(mxSettings.settings.defaultEdgeLength);
  676. if (!isNaN(val) && val > 0)
  677. {
  678. Graph.prototype.defaultEdgeLength = val;
  679. if (window.console != null)
  680. {
  681. console.log('Setting defaultEdgeLength to ' + Graph.prototype.defaultEdgeLength);
  682. }
  683. }
  684. else
  685. {
  686. if (window.console != null)
  687. {
  688. console.log('Invalid value for defaultEdgeLength');
  689. }
  690. }
  691. }
  692. }
  693. }
  694. catch (e)
  695. {
  696. if (window.console != null)
  697. {
  698. console.error(e);
  699. }
  700. }
  701. // Sends load event if configuration is requested and waits for configure action
  702. if (urlParams['configure'] == '1')
  703. {
  704. var op = window.opener || window.parent;
  705. var configHandler = function(evt)
  706. {
  707. if (evt.source == op)
  708. {
  709. try
  710. {
  711. var data = JSON.parse(evt.data);
  712. if (data != null && data.action == 'configure')
  713. {
  714. mxEvent.removeListener(window, 'message', configHandler);
  715. Editor.configure(data.config, true);
  716. mxSettings.load();
  717. doMain();
  718. }
  719. }
  720. catch (e)
  721. {
  722. if (window.console != null)
  723. {
  724. console.log('Error in configuration: ' + e);
  725. }
  726. }
  727. }
  728. };
  729. // Receives XML message from opener and puts it into the graph
  730. mxEvent.addListener(window, 'message', configHandler);
  731. op.postMessage(JSON.stringify({event: 'configure'}), '*');
  732. }
  733. else
  734. {
  735. doMain();
  736. }
  737. };
  738. //Extends EditorUi
  739. mxUtils.extend(App, EditorUi);
  740. /**
  741. * Executes the first step for connecting to Google Drive.
  742. */
  743. App.prototype.defaultUserPicture = 'https://lh3.googleusercontent.com/-HIzvXUy6QUY/AAAAAAAAAAI/AAAAAAAAAAA/giuR7PQyjEk/photo.jpg?sz=30';
  744. /**
  745. *
  746. */
  747. 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==';
  748. /**
  749. *
  750. */
  751. App.prototype.chevronUpImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-up.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUY1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NjA1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1RDUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1RTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pg+qUokAAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAAL0lEQVR42mJgRgMMRAswMKAKMDDARBjg8lARBoR6KImkH0wTbygT6YaS4DmAAAMAYPkClOEDDD0AAAAASUVORK5CYII=';
  752. /**
  753. *
  754. */
  755. 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';
  756. /**
  757. *
  758. */
  759. App.prototype.formatShowImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-show.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REY1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5RTA1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlERDU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlERTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlnMQ/8AAAAJUExURQAAAP///3FxcTfTiAsAAAACdFJOU/8A5bcwSgAAACFJREFUeNpiYEQDDEQJMMABTAAixcQ00ALoDiPRcwABBgB6DADly9Yx8wAAAABJRU5ErkJggg==';
  760. /**
  761. *
  762. */
  763. App.prototype.formatHideImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-hide.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REI1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5REM1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlEOTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlEQTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqjT9SMAAAAGUExURQAAAP///6XZn90AAAACdFJOU/8A5bcwSgAAAB9JREFUeNpiYEQDDEQJMMABTAAmNdAC6A4j0XMAAQYAcbwA1Xvj1CgAAAAASUVORK5CYII=';
  764. /**
  765. *
  766. */
  767. App.prototype.fullscreenImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/fullscreen.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAAAAAClZ7nPAAAAAXRSTlMAQObYZgAAABpJREFUCNdjgAAbGxAy4AEh5gNwBBGByoIBAIueBd12TUjqAAAAAElFTkSuQmCC';
  768. /**
  769. * Overriden UI settings depending on mode.
  770. */
  771. if (urlParams['embed'] != '1')
  772. {
  773. App.prototype.menubarHeight = 60;
  774. }
  775. else
  776. {
  777. App.prototype.footerHeight = 0;
  778. }
  779. /**
  780. * Queue for loading plugins and wait for UI instance
  781. */
  782. App.initPluginCallback = function()
  783. {
  784. if (App.DrawPlugins == null)
  785. {
  786. // Workaround for need to load plugins now but wait for UI instance
  787. App.DrawPlugins = [];
  788. // Global entry point for plugins is Draw.loadPlugin. This is the only
  789. // long-term supported solution for access to the EditorUi instance.
  790. window.Draw = new Object();
  791. window.Draw.loadPlugin = function(callback)
  792. {
  793. App.DrawPlugins.push(callback);
  794. };
  795. }
  796. };
  797. /**
  798. *
  799. */
  800. App.pluginsLoaded = {};
  801. App.embedModePluginsCount = 0;
  802. /**
  803. * Queue for loading plugins and wait for UI instance
  804. */
  805. App.loadPlugins = function(plugins, useInclude)
  806. {
  807. for (var i = 0; i < plugins.length; i++)
  808. {
  809. if (plugins[i] != null && plugins[i].length > 0)
  810. {
  811. try
  812. {
  813. var url = App.pluginRegistry[plugins[i]];
  814. if (url != null)
  815. {
  816. if (App.pluginsLoaded[url] == null)
  817. {
  818. App.pluginsLoaded[url] = true;
  819. App.embedModePluginsCount++;
  820. if (typeof window.drawDevUrl === 'undefined')
  821. {
  822. if (useInclude)
  823. {
  824. mxinclude(url);
  825. }
  826. else
  827. {
  828. mxscript(url);
  829. }
  830. }
  831. else
  832. {
  833. if (useInclude)
  834. {
  835. mxinclude(url);
  836. }
  837. else
  838. {
  839. mxscript(drawDevUrl + url);
  840. }
  841. }
  842. }
  843. }
  844. else if (window.console != null)
  845. {
  846. console.log('Unknown plugin:', plugins[i]);
  847. }
  848. }
  849. catch (e)
  850. {
  851. if (window.console != null)
  852. {
  853. console.log('Error loading plugin:', plugins[i], e);
  854. }
  855. }
  856. }
  857. }
  858. };
  859. /**
  860. * Delay embed mode initialization until all plugins are loaded
  861. */
  862. App.prototype.initializeEmbedMode = function()
  863. {
  864. if (urlParams['embed'] == '1')
  865. {
  866. if (App.embedModePluginsCount > 0 || this.initEmbedDone)
  867. {
  868. return; //Wait for plugins to load, or this is a duplicate call due to timeout
  869. }
  870. else
  871. {
  872. this.initEmbedDone = true;
  873. }
  874. EditorUi.prototype.initializeEmbedMode.apply(this, arguments);
  875. }
  876. };
  877. /**
  878. * Translates this point by the given vector.
  879. *
  880. * @param {number} dx X-coordinate of the translation.
  881. * @param {number} dy Y-coordinate of the translation.
  882. */
  883. App.prototype.init = function()
  884. {
  885. EditorUi.prototype.init.apply(this, arguments);
  886. /**
  887. * Specifies the default filename.
  888. */
  889. this.defaultLibraryName = mxResources.get('untitledLibrary');
  890. /**
  891. * Holds the listener for description changes.
  892. */
  893. this.descriptorChangedListener = mxUtils.bind(this, this.descriptorChanged);
  894. /**
  895. * Creates github client.
  896. */
  897. this.gitHub = (!mxClient.IS_IE || document.documentMode == 10 ||
  898. mxClient.IS_IE11 || mxClient.IS_EDGE) &&
  899. (urlParams['gh'] != '0' && (urlParams['embed'] != '1' ||
  900. urlParams['gh'] == '1')) ? new GitHubClient(this) : null;
  901. if (this.gitHub != null)
  902. {
  903. this.gitHub.addListener('userChanged', mxUtils.bind(this, function()
  904. {
  905. this.updateUserElement();
  906. this.restoreLibraries();
  907. }))
  908. }
  909. /**
  910. * Lazy-loading for individual backends
  911. */
  912. if (urlParams['embed'] != '1' || urlParams['od'] == '1')
  913. {
  914. /**
  915. * Creates onedrive client if all required libraries are available.
  916. */
  917. var initOneDriveClient = mxUtils.bind(this, function()
  918. {
  919. if (typeof OneDrive !== 'undefined')
  920. {
  921. /**
  922. * Holds the x-coordinate of the point.
  923. */
  924. this.oneDrive = new OneDriveClient(this);
  925. this.oneDrive.addListener('userChanged', mxUtils.bind(this, function()
  926. {
  927. this.updateUserElement();
  928. this.restoreLibraries();
  929. }));
  930. // Notifies listeners of new client
  931. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.oneDrive));
  932. }
  933. else if (window.DrawOneDriveClientCallback == null)
  934. {
  935. window.DrawOneDriveClientCallback = initOneDriveClient;
  936. }
  937. });
  938. initOneDriveClient();
  939. }
  940. /**
  941. * Lazy-loading for Trello
  942. */
  943. if (urlParams['embed'] != '1' || urlParams['tr'] == '1')
  944. {
  945. /**
  946. * Creates Trello client if all required libraries are available.
  947. */
  948. var initTrelloClient = mxUtils.bind(this, function()
  949. {
  950. if (typeof window.Trello !== 'undefined')
  951. {
  952. this.trello = new TrelloClient(this);
  953. //TODO we have no user info from Trello so we don't set a user
  954. this.trello.addListener('userChanged', mxUtils.bind(this, function()
  955. {
  956. this.updateUserElement();
  957. this.restoreLibraries();
  958. }));
  959. // Notifies listeners of new client
  960. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.trello));
  961. }
  962. else if (window.DrawTrelloClientCallback == null)
  963. {
  964. window.DrawTrelloClientCallback = initTrelloClient;
  965. }
  966. });
  967. initTrelloClient();
  968. }
  969. /**
  970. * Creates drive client with all required libraries are available.
  971. */
  972. if (urlParams['embed'] != '1' || urlParams['gapi'] == '1')
  973. {
  974. var initDriveClient = mxUtils.bind(this, function()
  975. {
  976. /**
  977. * Creates google drive client if all required libraries are available.
  978. */
  979. if (typeof gapi !== 'undefined')
  980. {
  981. var doInit = mxUtils.bind(this, function()
  982. {
  983. /**
  984. * Holds the x-coordinate of the point.
  985. */
  986. this.drive = new DriveClient(this);
  987. /**
  988. * Adds important notice for new app if drive file is loaded in old app.
  989. */
  990. if (this.drive.appId == '420247213240')
  991. {
  992. this.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  993. {
  994. var file = this.getCurrentFile();
  995. if (file != null && file.constructor == DriveFile)
  996. {
  997. var td = document.getElementById('geFooterItem2');
  998. if (td != null)
  999. {
  1000. td.innerHTML = '<a href="https://support.draw.io/display/DO/2014/11/27/Switching+application+in+Google+Drive" ' +
  1001. 'target="_blank" title="IMPORTANT NOTICE">IMPORTANT NOTICE</a>';
  1002. }
  1003. }
  1004. }));
  1005. }
  1006. this.drive.addListener('userChanged', mxUtils.bind(this, function()
  1007. {
  1008. this.updateUserElement();
  1009. this.restoreLibraries();
  1010. this.checkLicense();
  1011. if (this.drive.user != null && (!isLocalStorage || mxSettings.settings == null ||
  1012. mxSettings.settings.closeRealtimeWarning == null) &&
  1013. (!this.editor.chromeless || this.editor.editable))
  1014. {
  1015. this.drive.checkRealtimeFiles(mxUtils.bind(this, function()
  1016. {
  1017. var footer = document.createElement('div');
  1018. footer.style.cssText = 'position:absolute;bottom:0px;max-width:90%;padding:10px;padding-right:26px;' +
  1019. 'white-space:nowrap;left:50%;bottom:2px;';
  1020. footer.className = 'geStatusAlert';
  1021. mxUtils.setPrefixedStyle(footer.style, 'transform', 'translate(-50%,110%)');
  1022. mxUtils.setPrefixedStyle(footer.style, 'transition', 'all 1s ease');
  1023. footer.style.whiteSpace = 'nowrap';
  1024. footer.innerHTML = '<a href="https://desk.draw.io/support/solutions/articles/16000092210" ' +
  1025. 'target="_blank" style="display:inline;text-decoration:none;font-weight:700;font-size:13px;opacity:1;">' +
  1026. '<img src="' + this.editor.graph.warningImage.src + '" border="0" style="margin-top:-4px;margin-right:2px;" valign="middle"/>&nbsp;' +
  1027. 'You need to take action to convert legacy files. Click here.&nbsp;' +
  1028. '<img src="' + this.editor.graph.warningImage.src + '" border="0" style="margin-top:-4px;margin-left:2px;" valign="middle"/></a>';
  1029. var img = document.createElement('img');
  1030. img.setAttribute('src', Dialog.prototype.closeImage);
  1031. img.setAttribute('title', mxResources.get('close'));
  1032. img.style.position = 'absolute';
  1033. img.style.cursor = 'pointer';
  1034. img.style.right = '10px';
  1035. img.style.top = '12px';
  1036. footer.appendChild(img);
  1037. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  1038. {
  1039. footer.parentNode.removeChild(footer);
  1040. this.hideFooter();
  1041. // Close permanently
  1042. if (isLocalStorage && mxSettings.settings != null)
  1043. {
  1044. mxSettings.settings.closeRealtimeWarning = Date.now();
  1045. mxSettings.save();
  1046. }
  1047. }));
  1048. document.body.appendChild(footer);
  1049. window.setTimeout(mxUtils.bind(this, function()
  1050. {
  1051. mxUtils.setPrefixedStyle(footer.style, 'transform', 'translate(-50%,0%)');
  1052. }), 1500);
  1053. }));
  1054. }
  1055. }))
  1056. // Notifies listeners of new client
  1057. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.drive));
  1058. });
  1059. if (window.DrawGapiClientCallback != null)
  1060. {
  1061. gapi.load(((urlParams['picker'] != '0') ? 'picker,': '') + 'auth:' + App.GOOGLE_APIS, mxUtils.bind(this, function(resp)
  1062. {
  1063. // Starts the app without the Google Option if the API fails to load
  1064. if (gapi.client != null)
  1065. {
  1066. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1067. {
  1068. // Needed to avoid popup blocking for non-immediate authentication
  1069. gapi.auth.init(mxUtils.bind(this, function()
  1070. {
  1071. if (gapi.client.drive != null)
  1072. {
  1073. doInit();
  1074. }
  1075. }));
  1076. }));
  1077. }
  1078. }));
  1079. /**
  1080. * Clears any callbacks.
  1081. */
  1082. window.DrawGapiClientCallback = null;
  1083. }
  1084. else
  1085. {
  1086. doInit();
  1087. }
  1088. }
  1089. else if (window.DrawGapiClientCallback == null)
  1090. {
  1091. window.DrawGapiClientCallback = initDriveClient;
  1092. }
  1093. });
  1094. initDriveClient();
  1095. }
  1096. if (urlParams['embed'] != '1' || urlParams['db'] == '1')
  1097. {
  1098. /**
  1099. * Creates dropbox client if all required libraries are available.
  1100. */
  1101. var initDropboxClient = mxUtils.bind(this, function()
  1102. {
  1103. if (typeof Dropbox === 'function' && typeof Dropbox.choose !== 'undefined')
  1104. {
  1105. /**
  1106. * Clears dropbox client callback.
  1107. */
  1108. window.DrawDropboxClientCallback = null;
  1109. /**
  1110. * Holds the x-coordinate of the point.
  1111. */
  1112. this.dropbox = new DropboxClient(this);
  1113. this.dropbox.addListener('userChanged', mxUtils.bind(this, function()
  1114. {
  1115. this.updateUserElement();
  1116. this.restoreLibraries();
  1117. }));
  1118. // Notifies listeners of new client
  1119. this.fireEvent(new mxEventObject('clientLoaded', 'client', this.dropbox));
  1120. }
  1121. else if (window.DrawDropboxClientCallback == null)
  1122. {
  1123. window.DrawDropboxClientCallback = initDropboxClient;
  1124. }
  1125. });
  1126. initDropboxClient();
  1127. }
  1128. if (urlParams['embed'] != '1')
  1129. {
  1130. /**
  1131. * Holds the background element.
  1132. */
  1133. this.bg = this.createBackground();
  1134. document.body.appendChild(this.bg);
  1135. this.diagramContainer.style.visibility = 'hidden';
  1136. this.formatContainer.style.visibility = 'hidden';
  1137. this.hsplit.style.display = 'none';
  1138. this.sidebarContainer.style.display = 'none';
  1139. this.sidebarFooterContainer.style.display = 'none';
  1140. // Sets the initial mode
  1141. if (urlParams['local'] == '1')
  1142. {
  1143. this.setMode(App.MODE_DEVICE);
  1144. }
  1145. else
  1146. {
  1147. this.mode = App.mode;
  1148. }
  1149. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && urlParams['embed'] != '1' &&
  1150. urlParams['stealth'] != '1' && urlParams['offline'] != '1' &&
  1151. (!this.editor.chromeless || this.editor.editable))
  1152. {
  1153. // Checks if the cache is alive
  1154. var acceptResponse = true;
  1155. var timeoutThread = window.setTimeout(mxUtils.bind(this, function()
  1156. {
  1157. acceptResponse = false;
  1158. EditorUi.logEvent({category: 'TIMEOUT-CACHE-CHECK', action: 'timeout', label: 408});
  1159. }), this.timeout);
  1160. var t0 = new Date().getTime();
  1161. mxUtils.get(EditorUi.cacheUrl + '?alive', mxUtils.bind(this, function(req)
  1162. {
  1163. window.clearTimeout(timeoutThread);
  1164. if (acceptResponse)
  1165. {
  1166. EditorUi.logEvent({category: 'ALIVE-CACHE-CHECK', action: 'alive', label:
  1167. req.getStatus() + '.' + (new Date().getTime() - t0)});
  1168. }
  1169. }));
  1170. }
  1171. }
  1172. else if (this.menubar != null)
  1173. {
  1174. this.menubar.container.style.paddingTop = '0px';
  1175. }
  1176. this.updateHeader();
  1177. if (this.menubar != null)
  1178. {
  1179. this.buttonContainer = document.createElement('div');
  1180. this.buttonContainer.style.display = 'inline-block';
  1181. this.buttonContainer.style.paddingRight = '48px';
  1182. this.buttonContainer.style.position = 'absolute';
  1183. this.buttonContainer.style.right = '0px';
  1184. this.menubar.container.appendChild(this.buttonContainer);
  1185. }
  1186. if (uiTheme == 'atlas' && this.menubar != null)
  1187. {
  1188. if (this.toggleElement != null)
  1189. {
  1190. this.toggleElement.click();
  1191. this.toggleElement.style.display = 'none';
  1192. }
  1193. this.icon = document.createElement('img');
  1194. this.icon.setAttribute('src', IMAGE_PATH + '/logo-flat-small.png');
  1195. this.icon.setAttribute('title', mxResources.get('draw.io'));
  1196. this.icon.style.padding = '6px';
  1197. this.icon.style.cursor = 'pointer';
  1198. mxEvent.addListener(this.icon, 'click', mxUtils.bind(this, function(evt)
  1199. {
  1200. this.appIconClicked(evt);
  1201. }));
  1202. if (mxClient.IS_QUIRKS)
  1203. {
  1204. this.icon.style.marginTop = '12px';
  1205. }
  1206. this.menubar.container.insertBefore(this.icon, this.menubar.container.firstChild);
  1207. }
  1208. };
  1209. /**
  1210. * Returns true if the current domain is for the new drive app.
  1211. */
  1212. App.prototype.isDriveDomain = function()
  1213. {
  1214. return urlParams['drive'] != '0' &&
  1215. (window.location.hostname == 'test.draw.io' ||
  1216. window.location.hostname == 'cdn.draw.io' ||
  1217. window.location.hostname == 'www.draw.io' ||
  1218. window.location.hostname == 'drive.draw.io' ||
  1219. window.location.hostname == 'jgraph.github.io');
  1220. };
  1221. /**
  1222. * Returns true if the current domain is for the old drive app.
  1223. */
  1224. App.prototype.isLegacyDriveDomain = function()
  1225. {
  1226. return urlParams['drive'] == 0 || window.location.hostname == 'legacy.draw.io';
  1227. };
  1228. /**
  1229. * Returns the pusher instance for notifications. Creates the instance of none exists.
  1230. */
  1231. App.prototype.getPusher = function()
  1232. {
  1233. if (this.pusher == null && typeof window.Pusher === 'function')
  1234. {
  1235. this.pusher = new Pusher(App.PUSHER_KEY,
  1236. {
  1237. cluster: App.PUSHER_CLUSTER,
  1238. encrypted: true
  1239. });
  1240. }
  1241. return this.pusher;
  1242. };
  1243. /**
  1244. *
  1245. */
  1246. App.prototype.checkLicense = function()
  1247. {
  1248. var driveUser = this.drive.getUser();
  1249. var email = ((urlParams['dev'] == '1') ? urlParams['lic'] : null) ||
  1250. ((driveUser != null) ? driveUser.email : null);
  1251. if (!this.isOffline() && !this.editor.chromeless && email != null)
  1252. {
  1253. // Anonymises the local part of the email address
  1254. var at = email.lastIndexOf('@');
  1255. var domain = email;
  1256. if (at >= 0)
  1257. {
  1258. domain = email.substring(at + 1);
  1259. email = this.crc32(email.substring(0, at)) + '@' + domain;
  1260. }
  1261. // Timestamp is workaround for cached response in certain environments
  1262. mxUtils.post('/license', 'domain=' + encodeURIComponent(domain) + '&email=' + encodeURIComponent(email) +
  1263. '&ds=' + encodeURIComponent(driveUser.displayName) + '&lc=' + encodeURIComponent(driveUser.locale) +
  1264. '&ts=' + new Date().getTime(),
  1265. mxUtils.bind(this, function(req)
  1266. {
  1267. try
  1268. {
  1269. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1270. {
  1271. var value = req.getText();
  1272. if (value.length > 0)
  1273. {
  1274. var lic = JSON.parse(value);
  1275. if (lic != null)
  1276. {
  1277. this.handleLicense(lic, domain);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. catch (e)
  1283. {
  1284. // ignore
  1285. }
  1286. }));
  1287. }
  1288. };
  1289. /**
  1290. * Returns true if the current domain is for the new drive app.
  1291. */
  1292. App.prototype.handleLicense = function(lic, domain)
  1293. {
  1294. if (lic != null && lic.plugins != null)
  1295. {
  1296. App.loadPlugins(lic.plugins.split(';'), true);
  1297. }
  1298. };
  1299. /**
  1300. *
  1301. */
  1302. App.prototype.getEditBlankXml = function()
  1303. {
  1304. var file = this.getCurrentFile();
  1305. if (file != null && this.editor.isChromelessView() && this.editor.graph.isLightboxView())
  1306. {
  1307. return file.getData();
  1308. }
  1309. else
  1310. {
  1311. return this.getFileData(true);
  1312. }
  1313. };
  1314. /**
  1315. * Updates action states depending on the selection.
  1316. */
  1317. App.prototype.updateActionStates = function()
  1318. {
  1319. EditorUi.prototype.updateActionStates.apply(this, arguments);
  1320. var file = this.getCurrentFile();
  1321. this.actions.get('revisionHistory').setEnabled(file != null &&
  1322. ((file.constructor == DriveFile && file.isEditable()) ||
  1323. file.constructor == DropboxFile));
  1324. };
  1325. /**
  1326. * Updates draft in local storage
  1327. */
  1328. App.prototype.updateDraft = function()
  1329. {
  1330. if (isLocalStorage && localStorage != null)
  1331. {
  1332. localStorage.setItem('.draft', JSON.stringify({modified:
  1333. new Date().getTime(), data: this.getFileData()}));
  1334. }
  1335. };
  1336. /**
  1337. * Returns the draft in local storage
  1338. */
  1339. App.prototype.getDraft = function()
  1340. {
  1341. // FIXME: Handle multiple tabs
  1342. // if (isLocalStorage && localStorage != null)
  1343. // {
  1344. // try
  1345. // {
  1346. // var draft = localStorage.getItem('.draft');
  1347. //
  1348. // if (draft != null)
  1349. // {
  1350. // return JSON.parse(draft);
  1351. // }
  1352. // }
  1353. // catch (e)
  1354. // {
  1355. // // ignore quota etc
  1356. // }
  1357. // }
  1358. return null;
  1359. };
  1360. /**
  1361. * Adds the specified entry to the recent file list in local storage
  1362. */
  1363. App.prototype.addRecent = function(entry)
  1364. {
  1365. if (isLocalStorage && localStorage != null)
  1366. {
  1367. var recent = this.getRecent();
  1368. if (recent == null)
  1369. {
  1370. recent = [];
  1371. }
  1372. else
  1373. {
  1374. for (var i = 0; i < recent.length; i++)
  1375. {
  1376. if (recent[i].id == entry.id)
  1377. {
  1378. recent.splice(i, 1);
  1379. }
  1380. }
  1381. }
  1382. if (recent != null)
  1383. {
  1384. recent.unshift(entry);
  1385. recent = recent.slice(0, 10);
  1386. localStorage.setItem('.recent', JSON.stringify(recent));
  1387. }
  1388. }
  1389. };
  1390. /**
  1391. * Returns the recent file list from local storage
  1392. */
  1393. App.prototype.getRecent = function()
  1394. {
  1395. if (isLocalStorage && localStorage != null)
  1396. {
  1397. try
  1398. {
  1399. var recent = localStorage.getItem('.recent');
  1400. if (recent != null)
  1401. {
  1402. return JSON.parse(recent);
  1403. }
  1404. }
  1405. catch (e)
  1406. {
  1407. // ignore
  1408. }
  1409. return null;
  1410. }
  1411. };
  1412. /**
  1413. * Clears the recent file list in local storage
  1414. */
  1415. App.prototype.resetRecent = function(entry)
  1416. {
  1417. if (isLocalStorage && localStorage != null)
  1418. {
  1419. try
  1420. {
  1421. localStorage.removeItem('.recent');
  1422. }
  1423. catch (e)
  1424. {
  1425. // ignore
  1426. }
  1427. }
  1428. };
  1429. /**
  1430. * Clears the draft save in local storage
  1431. */
  1432. App.prototype.removeDraft = function()
  1433. {
  1434. if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
  1435. {
  1436. try
  1437. {
  1438. localStorage.removeItem('.draft');
  1439. }
  1440. catch (e)
  1441. {
  1442. // ignore quota etc
  1443. }
  1444. }
  1445. };
  1446. /**
  1447. * Sets the onbeforeunload for the application
  1448. */
  1449. App.prototype.onBeforeUnload = function()
  1450. {
  1451. if (urlParams['embed'] == '1' && this.editor.modified)
  1452. {
  1453. return mxResources.get('allChangesLost');
  1454. }
  1455. else
  1456. {
  1457. var file = this.getCurrentFile();
  1458. if (file != null)
  1459. {
  1460. // KNOWN: Message is ignored by most browsers
  1461. if (file.constructor == LocalFile && file.getHash() == '' && !file.isModified() &&
  1462. urlParams['nowarn'] != '1' && !this.isDiagramEmpty() && urlParams['url'] == null &&
  1463. !this.editor.isChromelessView())
  1464. {
  1465. return mxResources.get('ensureDataSaved');
  1466. }
  1467. else if (file.isModified())
  1468. {
  1469. return mxResources.get('allChangesLost');
  1470. }
  1471. else
  1472. {
  1473. file.close(true);
  1474. }
  1475. }
  1476. }
  1477. };
  1478. /**
  1479. * Translates this point by the given vector.
  1480. *
  1481. * @param {number} dx X-coordinate of the translation.
  1482. * @param {number} dy Y-coordinate of the translation.
  1483. */
  1484. App.prototype.updateDocumentTitle = function()
  1485. {
  1486. if (!this.editor.graph.isLightboxView())
  1487. {
  1488. var title = this.editor.appName;
  1489. var file = this.getCurrentFile();
  1490. if (this.isOfflineApp())
  1491. {
  1492. title += ' app';
  1493. }
  1494. if (file != null)
  1495. {
  1496. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1497. title = filename + ' - ' + title;
  1498. }
  1499. document.title = title;
  1500. }
  1501. };
  1502. /**
  1503. * Authorizes the client, gets the userId and calls <open>.
  1504. */
  1505. App.prototype.createCrcTable = function()
  1506. {
  1507. var crcTable = [];
  1508. var c;
  1509. for (var n = 0; n < 256; n++)
  1510. {
  1511. c = n;
  1512. for (var k = 0; k < 8; k++)
  1513. {
  1514. c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  1515. }
  1516. crcTable[n] = c;
  1517. }
  1518. return crcTable;
  1519. };
  1520. /**
  1521. * Returns a thumbnail of the current file.
  1522. */
  1523. App.prototype.getThumbnail = function(width, success)
  1524. {
  1525. var result = false;
  1526. try
  1527. {
  1528. if (this.thumbImageCache == null)
  1529. {
  1530. this.thumbImageCache = new Object();
  1531. }
  1532. var graph = this.editor.graph;
  1533. // Exports PNG for first page while other page is visible by creating a graph
  1534. // LATER: Add caching for the graph or SVG while not on first page
  1535. if (this.pages != null && this.currentPage != this.pages[0])
  1536. {
  1537. graph = this.createTemporaryGraph(graph.getStylesheet());
  1538. var graphGetGlobalVariable = graph.getGlobalVariable;
  1539. var page = this.pages[0];
  1540. graph.getGlobalVariable = function(name)
  1541. {
  1542. if (name == 'page')
  1543. {
  1544. return page.getName();
  1545. }
  1546. else if (name == 'pagenumber')
  1547. {
  1548. return 1;
  1549. }
  1550. return graphGetGlobalVariable.apply(this, arguments);
  1551. };
  1552. document.body.appendChild(graph.container);
  1553. graph.model.setRoot(page.root);
  1554. }
  1555. // Uses client-side canvas export
  1556. if (mxClient.IS_CHROMEAPP || (!graph.mathEnabled && this.useCanvasForExport))
  1557. {
  1558. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1559. {
  1560. try
  1561. {
  1562. // Removes temporary graph from DOM
  1563. if (graph != this.editor.graph && graph.container.parentNode != null)
  1564. {
  1565. graph.container.parentNode.removeChild(graph.container);
  1566. }
  1567. }
  1568. catch (e)
  1569. {
  1570. canvas = null;
  1571. }
  1572. success(canvas);
  1573. }), width, this.thumbImageCache, '#ffffff', function()
  1574. {
  1575. // Continues with null in error case
  1576. success();
  1577. }, null, null, null, null, null, null, graph);
  1578. result = true;
  1579. }
  1580. else if (this.canvasSupported && this.getCurrentFile() != null)
  1581. {
  1582. var canvas = document.createElement('canvas');
  1583. var bounds = graph.getGraphBounds();
  1584. var scale = width / bounds.width;
  1585. // Limits scale to 1 or 2 * width / height
  1586. scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
  1587. var x0 = Math.floor(bounds.x);
  1588. var y0 = Math.floor(bounds.y);
  1589. canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
  1590. canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
  1591. var ctx = canvas.getContext('2d');
  1592. // Configures the canvas
  1593. ctx.scale(scale, scale);
  1594. ctx.translate(-x0, -y0);
  1595. // Paint white background instead of transparent
  1596. var bg = graph.background;
  1597. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1598. {
  1599. bg = '#ffffff';
  1600. }
  1601. // Paints background
  1602. ctx.save();
  1603. ctx.fillStyle = bg;
  1604. ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
  1605. ctx.restore();
  1606. var htmlCanvas = new mxJsCanvas(canvas);
  1607. // NOTE: htmlCanvas passed into async canvas is only used for image
  1608. // and canvas caching (canvas caching not used in this case as we do
  1609. // not render text). To reuse that cache via the thumbImageCache we
  1610. // pass that into the async canvas and override the image cache in
  1611. // the newly created html canvas with that of the thumbImageCache.
  1612. // LATER: Is clear thumbImageCache needed if file changes?
  1613. var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
  1614. htmlCanvas.images = this.thumbImageCache.images;
  1615. // Render graph
  1616. var imgExport = new mxImageExport();
  1617. imgExport.drawShape = function(state, canvas)
  1618. {
  1619. if (state.shape instanceof mxShape && state.shape.checkBounds())
  1620. {
  1621. canvas.save();
  1622. canvas.translate(0.5, 0.5);
  1623. state.shape.paint(canvas);
  1624. canvas.translate(-0.5, -0.5);
  1625. canvas.restore();
  1626. }
  1627. };
  1628. imgExport.drawText = function(state, canvas)
  1629. {
  1630. // No text output for thumbnails
  1631. };
  1632. imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
  1633. asynCanvas.finish(mxUtils.bind(this, function()
  1634. {
  1635. try
  1636. {
  1637. imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
  1638. // Removes temporary graph from DOM
  1639. if (graph != this.editor.graph && graph.container.parentNode != null)
  1640. {
  1641. graph.container.parentNode.removeChild(graph.container);
  1642. }
  1643. }
  1644. catch (e)
  1645. {
  1646. canvas = null;
  1647. }
  1648. success(canvas);
  1649. }));
  1650. result = true;
  1651. }
  1652. }
  1653. catch (e)
  1654. {
  1655. // ignore and use placeholder
  1656. // Removes temporary graph from DOM
  1657. if (graph != this.editor.graph && graph.container.parentNode != null)
  1658. {
  1659. graph.container.parentNode.removeChild(graph.container);
  1660. }
  1661. }
  1662. return result;
  1663. };
  1664. /**
  1665. * Translates this point by the given vector.
  1666. *
  1667. * @param {number} dx X-coordinate of the translation.
  1668. * @param {number} dy Y-coordinate of the translation.
  1669. */
  1670. App.prototype.createBackground = function()
  1671. {
  1672. var bg = this.createDiv('background');
  1673. bg.style.position = 'absolute';
  1674. bg.style.background = 'white';
  1675. bg.style.left = '0px';
  1676. bg.style.top = '0px';
  1677. bg.style.bottom = '0px';
  1678. bg.style.right = '0px';
  1679. mxUtils.setOpacity(bg, 100);
  1680. if (mxClient.IS_QUIRKS)
  1681. {
  1682. new mxDivResizer(bg);
  1683. }
  1684. return bg;
  1685. };
  1686. /**
  1687. * Translates this point by the given vector.
  1688. *
  1689. * @param {number} dx X-coordinate of the translation.
  1690. * @param {number} dy Y-coordinate of the translation.
  1691. */
  1692. (function()
  1693. {
  1694. var editorUiSetMode = EditorUi.prototype.setMode;
  1695. App.prototype.setMode = function(mode, remember)
  1696. {
  1697. editorUiSetMode.apply(this, arguments);
  1698. // Note: UseLocalStorage affects the file dialogs
  1699. // and should not be modified if mode is undefined
  1700. if (this.mode != null)
  1701. {
  1702. Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
  1703. }
  1704. if (this.appIcon != null)
  1705. {
  1706. var file = this.getCurrentFile();
  1707. mode = (file != null) ? file.getMode() : mode;
  1708. if (mode == App.MODE_GOOGLE)
  1709. {
  1710. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
  1711. this.appIcon.style.cursor = 'pointer';
  1712. }
  1713. else if (mode == App.MODE_DROPBOX)
  1714. {
  1715. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
  1716. this.appIcon.style.cursor = 'pointer';
  1717. }
  1718. else if (mode == App.MODE_ONEDRIVE)
  1719. {
  1720. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
  1721. this.appIcon.style.cursor = 'pointer';
  1722. }
  1723. else
  1724. {
  1725. this.appIcon.removeAttribute('title');
  1726. this.appIcon.style.cursor = 'default';
  1727. }
  1728. }
  1729. if (remember)
  1730. {
  1731. try
  1732. {
  1733. if (isLocalStorage)
  1734. {
  1735. localStorage.setItem('.mode', mode);
  1736. }
  1737. else if (typeof(Storage) != 'undefined')
  1738. {
  1739. var expiry = new Date();
  1740. expiry.setYear(expiry.getFullYear() + 1);
  1741. document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
  1742. }
  1743. }
  1744. catch (e)
  1745. {
  1746. // ignore possible access denied
  1747. }
  1748. }
  1749. };
  1750. })();
  1751. /**
  1752. * Function: authorize
  1753. *
  1754. * Authorizes the client, gets the userId and calls <open>.
  1755. */
  1756. App.prototype.appIconClicked = function(evt)
  1757. {
  1758. if (mxEvent.isAltDown(evt))
  1759. {
  1760. this.showSplash(true);
  1761. }
  1762. else
  1763. {
  1764. var file = this.getCurrentFile();
  1765. var mode = (file != null) ? file.getMode() : null;
  1766. if (mode == App.MODE_GOOGLE)
  1767. {
  1768. if (file != null && file.desc != null && file.desc.parents != null &&
  1769. file.desc.parents.length > 0 && !mxEvent.isShiftDown(evt))
  1770. {
  1771. // Opens containing folder
  1772. this.openLink('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
  1773. }
  1774. else if (file != null && file.getId() != null)
  1775. {
  1776. this.openLink('https://drive.google.com/open?id=' + file.getId());
  1777. }
  1778. else
  1779. {
  1780. this.openLink('https://drive.google.com/?authuser=0');
  1781. }
  1782. }
  1783. else if (mode == App.MODE_DROPBOX)
  1784. {
  1785. this.openLink('https://www.dropbox.com/');
  1786. }
  1787. else if (mode == App.MODE_ONEDRIVE)
  1788. {
  1789. this.openLink('https://onedrive.live.com/');
  1790. }
  1791. else if (mode == App.MODE_TRELLO)
  1792. {
  1793. this.openLink('https://trello.com/');
  1794. }
  1795. else if (mode == App.MODE_GITHUB)
  1796. {
  1797. if (file != null && file.constructor == GitHubFile)
  1798. {
  1799. this.openLink(file.meta.html_url);
  1800. }
  1801. else
  1802. {
  1803. this.openLink('https://github.com/');
  1804. }
  1805. }
  1806. }
  1807. mxEvent.consume(evt);
  1808. };
  1809. /**
  1810. * Function: authorize
  1811. *
  1812. * Authorizes the client, gets the userId and calls <open>.
  1813. */
  1814. App.prototype.clearMode = function()
  1815. {
  1816. if (isLocalStorage)
  1817. {
  1818. localStorage.removeItem('.mode');
  1819. }
  1820. else if (typeof(Storage) != 'undefined')
  1821. {
  1822. var expiry = new Date();
  1823. expiry.setYear(expiry.getFullYear() - 1);
  1824. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  1825. }
  1826. };
  1827. /**
  1828. * Translates this point by the given vector.
  1829. *
  1830. * @param {number} dx X-coordinate of the translation.
  1831. * @param {number} dy Y-coordinate of the translation.
  1832. */
  1833. App.prototype.getDiagramId = function()
  1834. {
  1835. var id = window.location.hash;
  1836. // Strips the hash sign
  1837. if (id != null && id.length > 0)
  1838. {
  1839. id = id.substring(1);
  1840. }
  1841. // Workaround for Trello client appending data after hash
  1842. if (id != null && id.length > 1 && id.charAt(0) == 'T')
  1843. {
  1844. var idx = id.indexOf('#');
  1845. if (idx > 0)
  1846. {
  1847. id = id.substring(0, idx);
  1848. }
  1849. }
  1850. return id;
  1851. };
  1852. /**
  1853. * Opens any file specified in the URL parameters.
  1854. */
  1855. App.prototype.open = function()
  1856. {
  1857. // Cross-domain window access is not allowed in FF, so if we
  1858. // were opened from another domain then this will fail.
  1859. try
  1860. {
  1861. // If the create URL param is used in embed mode then
  1862. // we try to open the XML from window.opener[value].
  1863. // Use this for embedding via tab to bypass the timing
  1864. // issues when passing messages without onload event.
  1865. if (window.opener != null)
  1866. {
  1867. var value = urlParams['create'];
  1868. if (value != null)
  1869. {
  1870. value = decodeURIComponent(value);
  1871. }
  1872. if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
  1873. value.substring(0, 8) != 'https://')
  1874. {
  1875. var doc = mxUtils.parseXml(window.opener[value]);
  1876. this.editor.setGraphXml(doc.documentElement);
  1877. }
  1878. else if (window.opener.openFile != null)
  1879. {
  1880. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename, temp)
  1881. {
  1882. this.spinner.stop();
  1883. if (filename == null)
  1884. {
  1885. var title = urlParams['title'];
  1886. temp = true;
  1887. if (title != null)
  1888. {
  1889. filename = decodeURIComponent(title);
  1890. }
  1891. else
  1892. {
  1893. filename = this.defaultFilename;
  1894. }
  1895. }
  1896. // Replaces PNG with XML extension
  1897. var dot = (!this.useCanvasForExport) ? filename.substring(filename.length - 4) == '.png' : -1;
  1898. if (dot > 0)
  1899. {
  1900. filename = filename.substring(0, filename.length - 4) + '.drawio';
  1901. }
  1902. this.fileLoaded((mxClient.IS_IOS) ?
  1903. new StorageFile(this, xml, filename) :
  1904. new LocalFile(this, xml, filename, temp));
  1905. }));
  1906. }
  1907. }
  1908. }
  1909. catch(e)
  1910. {
  1911. // ignore
  1912. }
  1913. };
  1914. App.prototype.loadGapi = function(then)
  1915. {
  1916. if (typeof gapi !== 'undefined')
  1917. {
  1918. gapi.load(((urlParams['picker'] != '0') ? 'picker,': '') + 'auth:' + App.GOOGLE_APIS, mxUtils.bind(this, function(resp)
  1919. {
  1920. // Starts the app without the Google Option if the API fails to load
  1921. if (gapi.client == null)
  1922. {
  1923. this.drive = null;
  1924. this.mode = null;
  1925. then();
  1926. }
  1927. else
  1928. {
  1929. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1930. {
  1931. // Needed to avoid popup blocking for non-immediate authentication
  1932. gapi.auth.init(mxUtils.bind(this, function()
  1933. {
  1934. if (gapi.client.drive == null)
  1935. {
  1936. this.drive = null;
  1937. this.mode = null;
  1938. }
  1939. then();
  1940. }));
  1941. }));
  1942. }
  1943. }));
  1944. }
  1945. };
  1946. /**
  1947. * Main function. Program starts here.
  1948. *
  1949. * @param {number} dx X-coordinate of the translation.
  1950. * @param {number} dy Y-coordinate of the translation.
  1951. */
  1952. App.prototype.load = function()
  1953. {
  1954. // Checks if we're running in embedded mode
  1955. if (urlParams['embed'] != '1')
  1956. {
  1957. if (this.spinner.spin(document.body, mxResources.get('starting')))
  1958. {
  1959. try
  1960. {
  1961. this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
  1962. }
  1963. catch (e)
  1964. {
  1965. // ignores invalid state args
  1966. }
  1967. this.editor.graph.setEnabled(this.getCurrentFile() != null);
  1968. // Passes the userId from the state parameter to the client
  1969. if ((window.location.hash == null || window.location.hash.length == 0) &&
  1970. this.drive != null && this.stateArg != null && this.stateArg.userId != null)
  1971. {
  1972. this.drive.setUserId(this.stateArg.userId);
  1973. }
  1974. // Legacy support for fileId parameter which is moved to the hash tag
  1975. if (urlParams['fileId'] != null)
  1976. {
  1977. window.location.hash = 'G' + urlParams['fileId'];
  1978. window.location.search = this.getSearch(['fileId']);
  1979. }
  1980. else
  1981. {
  1982. // Asynchronous or disabled loading of client
  1983. if (this.drive == null)
  1984. {
  1985. if (this.mode == App.MODE_GOOGLE)
  1986. {
  1987. this.mode = null;
  1988. }
  1989. this.start();
  1990. }
  1991. else
  1992. {
  1993. this.loadGapi(mxUtils.bind(this, function()
  1994. {
  1995. if (urlParams['convert-realtime'] == '1')
  1996. {
  1997. this.spinner.stop();
  1998. this.drive.convertRealtimeFiles();
  1999. }
  2000. else
  2001. {
  2002. this.start();
  2003. }
  2004. }));
  2005. }
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. this.restoreLibraries();
  2012. if (urlParams['gapi'] == '1')
  2013. {
  2014. this.loadGapi(function() {});
  2015. }
  2016. }
  2017. };
  2018. /**
  2019. * Adds the listener for automatically saving the diagram for local changes.
  2020. */
  2021. App.prototype.showRefreshDialog = function(title, message)
  2022. {
  2023. if (!this.showingRefreshDialog)
  2024. {
  2025. this.showingRefreshDialog = true;
  2026. this.showError(title || mxResources.get('externalChanges'),
  2027. message || mxResources.get('redirectToNewApp'),
  2028. mxResources.get('refresh'), mxUtils.bind(this, function()
  2029. {
  2030. var file = this.getCurrentFile();
  2031. if (file != null)
  2032. {
  2033. file.setModified(false);
  2034. }
  2035. this.spinner.spin(document.body, mxResources.get('connecting'));
  2036. this.editor.graph.setEnabled(false);
  2037. window.location.reload();
  2038. }), null, null, null, null, null, 340, 180);
  2039. // Adds important notice to dialog
  2040. if (this.dialog != null && this.dialog.container != null)
  2041. {
  2042. var alert = this.createRealtimeNotice();
  2043. alert.style.left = '0';
  2044. alert.style.right = '0';
  2045. alert.style.borderRadius = '0';
  2046. alert.style.borderLeftStyle = 'none';
  2047. alert.style.borderRightStyle = 'none';
  2048. alert.style.marginBottom = '26px';
  2049. alert.style.padding = '8px 0 8px 0';
  2050. this.dialog.container.appendChild(alert);
  2051. }
  2052. }
  2053. };
  2054. /**
  2055. * Called in start after the spinner stops.
  2056. */
  2057. App.prototype.showAlert = function(message)
  2058. {
  2059. if (message != null && message.length > 0)
  2060. {
  2061. var div = document.createElement('div');
  2062. div.className = 'geAlert';
  2063. div.style.zIndex = 2e9;
  2064. div.style.left = '50%';
  2065. div.style.top = '-100%';
  2066. mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
  2067. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
  2068. div.innerHTML = message;
  2069. var close = document.createElement('a');
  2070. close.className = 'geAlertLink';
  2071. close.style.textAlign = 'right';
  2072. close.style.marginTop = '20px';
  2073. close.style.display = 'block';
  2074. close.setAttribute('title', mxResources.get('close'));
  2075. close.innerHTML = mxResources.get('close');
  2076. div.appendChild(close);
  2077. mxEvent.addListener(close, 'click', function(evt)
  2078. {
  2079. if (div.parentNode != null)
  2080. {
  2081. div.parentNode.removeChild(div);
  2082. mxEvent.consume(evt);
  2083. }
  2084. });
  2085. document.body.appendChild(div);
  2086. // Delayed to get smoother animation after DOM rendering
  2087. window.setTimeout(function()
  2088. {
  2089. div.style.top = '30px';
  2090. }, 10);
  2091. // Fades out the alert after 15 secs
  2092. window.setTimeout(function()
  2093. {
  2094. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
  2095. div.style.opacity = '0';
  2096. window.setTimeout(function()
  2097. {
  2098. if (div.parentNode != null)
  2099. {
  2100. div.parentNode.removeChild(div);
  2101. }
  2102. }, 2000);
  2103. }, 15000);
  2104. }
  2105. };
  2106. /**
  2107. * Translates this point by the given vector.
  2108. *
  2109. * @param {number} dx X-coordinate of the translation.
  2110. * @param {number} dy Y-coordinate of the translation.
  2111. */
  2112. App.prototype.start = function()
  2113. {
  2114. this.bg.parentNode.removeChild(this.bg);
  2115. this.restoreLibraries();
  2116. this.spinner.stop();
  2117. try
  2118. {
  2119. // Listens to changes of the hash if not in embed or client mode
  2120. if (urlParams['client'] != '1' && urlParams['embed'] != '1')
  2121. {
  2122. // KNOWN: Does not work in quirks mode
  2123. mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
  2124. {
  2125. try
  2126. {
  2127. this.hideDialog();
  2128. var id = this.getDiagramId();
  2129. var file = this.getCurrentFile();
  2130. if (file == null || file.getHash() != id)
  2131. {
  2132. this.loadFile(id, true);
  2133. }
  2134. }
  2135. catch (e)
  2136. {
  2137. // Workaround for possible scrollWidth of null in Dialog ctor
  2138. if (document.body != null)
  2139. {
  2140. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2141. {
  2142. var file = this.getCurrentFile();
  2143. window.location.hash = (file != null) ? file.getHash() : '';
  2144. }));
  2145. }
  2146. }
  2147. }));
  2148. }
  2149. // Redirects old url URL parameter to new #U format
  2150. if ((window.location.hash == null || window.location.hash.length <= 1) && urlParams['url'] != null)
  2151. {
  2152. this.loadFile('U' + urlParams['url'], true);
  2153. }
  2154. else if (this.getCurrentFile() == null)
  2155. {
  2156. var done = mxUtils.bind(this, function()
  2157. {
  2158. // Starts in client mode and waits for data
  2159. if (urlParams['client'] == '1' && (window.location.hash == null ||
  2160. window.location.hash.length == 0 || window.location.hash.substring(0, 2) == '#P'))
  2161. {
  2162. var doLoadFile = mxUtils.bind(this, function(xml)
  2163. {
  2164. // Extracts graph model from PNG
  2165. if (xml.substring(0, 22) == 'data:image/png;base64,')
  2166. {
  2167. xml = this.extractGraphModelFromPng(xml);
  2168. }
  2169. var title = urlParams['title'];
  2170. if (title != null)
  2171. {
  2172. title = decodeURIComponent(title);
  2173. }
  2174. else
  2175. {
  2176. title = this.defaultFilename;
  2177. }
  2178. var file = new LocalFile(this, xml, title, true);
  2179. if (window.location.hash != null && window.location.hash.substring(0, 2) == '#P')
  2180. {
  2181. file.getHash = function()
  2182. {
  2183. return window.location.hash.substring(1);
  2184. };
  2185. }
  2186. this.fileLoaded(file);
  2187. this.getCurrentFile().setModified(!this.editor.chromeless);
  2188. });
  2189. var parent = window.opener || window.parent;
  2190. if (parent != window)
  2191. {
  2192. var value = urlParams['create'];
  2193. if (value != null)
  2194. {
  2195. doLoadFile(parent[decodeURIComponent(value)]);
  2196. }
  2197. else
  2198. {
  2199. value = urlParams['data'];
  2200. if (value != null)
  2201. {
  2202. doLoadFile(decodeURIComponent(value));
  2203. }
  2204. else
  2205. {
  2206. this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
  2207. {
  2208. // Ignores messages from other windows
  2209. if (evt.source == parent)
  2210. {
  2211. doLoadFile(xml);
  2212. }
  2213. }));
  2214. }
  2215. }
  2216. }
  2217. }
  2218. // Checks if no earlier loading errors are showing
  2219. else if (this.dialog == null)
  2220. {
  2221. if (urlParams['demo'] == '1')
  2222. {
  2223. var prev = Editor.useLocalStorage;
  2224. this.createFile(this.defaultFilename, null, null, null, null, null, null, true);
  2225. Editor.useLocalStorage = prev;
  2226. }
  2227. else
  2228. {
  2229. var waiting = false;
  2230. // Checks if we're waiting for some asynchronous file to be loaded
  2231. // Cross-domain window access is not allowed in FF, so if we
  2232. // were opened from another domain then this will fail.
  2233. try
  2234. {
  2235. waiting = window.opener != null && window.opener.openFile != null;
  2236. }
  2237. catch(e)
  2238. {
  2239. // ignore
  2240. }
  2241. if (waiting)
  2242. {
  2243. // Spinner is stopped in App.open
  2244. this.spinner.spin(document.body, mxResources.get('loading'))
  2245. }
  2246. else
  2247. {
  2248. var id = this.getDiagramId();
  2249. if (urlParams['splash'] == '0' && (id == null || id.length == 0))
  2250. {
  2251. if (!mxClient.IS_CHROMEAPP)
  2252. {
  2253. var draft = this.getDraft();
  2254. var fileData = (draft != null) ? draft.data : this.getFileData();
  2255. var prev = Editor.useLocalStorage;
  2256. this.createFile(this.defaultFilename, fileData, null, null, null, null, null, true);
  2257. Editor.useLocalStorage = prev;
  2258. // Draft was used so the user should save the file
  2259. if (draft != null)
  2260. {
  2261. var file = this.getCurrentFile();
  2262. if (file != null)
  2263. {
  2264. file.addUnsavedStatus();
  2265. }
  2266. }
  2267. }
  2268. }
  2269. else
  2270. {
  2271. this.loadFile(id);
  2272. }
  2273. }
  2274. }
  2275. }
  2276. });
  2277. var value = decodeURIComponent(urlParams['create'] || '');
  2278. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2279. value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
  2280. {
  2281. var reconnect = mxUtils.bind(this, function()
  2282. {
  2283. // Removes URL parameter and reloads the page
  2284. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  2285. {
  2286. window.location.search = this.getSearch(['create', 'title']);
  2287. };
  2288. });
  2289. var showCreateDialog = mxUtils.bind(this, function(xml)
  2290. {
  2291. this.spinner.stop();
  2292. // Resets mode for dialog - local file is only for preview
  2293. if (urlParams['splash'] != '0')
  2294. {
  2295. this.fileLoaded(new LocalFile(this, xml, null));
  2296. this.editor.graph.setEnabled(false);
  2297. this.mode = urlParams['mode'];
  2298. var title = urlParams['title'];
  2299. if (title != null)
  2300. {
  2301. title = decodeURIComponent(title);
  2302. }
  2303. else
  2304. {
  2305. title = this.defaultFilename;
  2306. }
  2307. var serviceCount = this.getServiceCount(true);
  2308. var rowLimit = (serviceCount <= 4) ? 4 : 3;
  2309. var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
  2310. {
  2311. if (mode == null)
  2312. {
  2313. this.hideDialog();
  2314. var prev = Editor.useLocalStorage;
  2315. this.createFile((filename.length > 0) ? filename : this.defaultFilename,
  2316. this.getFileData(), null, null, null, true, null, true);
  2317. Editor.useLocalStorage = prev;
  2318. }
  2319. else
  2320. {
  2321. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2322. {
  2323. this.createFile(filename, this.getFileData(true),
  2324. null, mode, null, true, folderId);
  2325. }));
  2326. }
  2327. }), null, null, null, null, urlParams['browser'] == '1', null, null, true, rowLimit,
  2328. null, null, null, this.editor.fileExtensions);
  2329. this.showDialog(dlg.container, 400, (serviceCount > rowLimit) ? 390 : 270,
  2330. true, false, mxUtils.bind(this, function(cancel)
  2331. {
  2332. if (cancel && this.getCurrentFile() == null)
  2333. {
  2334. this.showSplash();
  2335. }
  2336. }));
  2337. dlg.init();
  2338. }
  2339. });
  2340. value = decodeURIComponent(value);
  2341. if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
  2342. {
  2343. // Cross-domain window access is not allowed in FF, so if we
  2344. // were opened from another domain then this will fail.
  2345. try
  2346. {
  2347. if (window.opener != null && window.opener[value] != null)
  2348. {
  2349. showCreateDialog(window.opener[value]);
  2350. }
  2351. else
  2352. {
  2353. this.handleError(null, mxResources.get('errorLoadingFile'));
  2354. }
  2355. }
  2356. catch (e)
  2357. {
  2358. this.handleError(e, mxResources.get('errorLoadingFile'));
  2359. }
  2360. }
  2361. else
  2362. {
  2363. this.loadTemplate(value, function(text)
  2364. {
  2365. showCreateDialog(text);
  2366. }, mxUtils.bind(this, function()
  2367. {
  2368. this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
  2369. }));
  2370. }
  2371. }
  2372. else
  2373. {
  2374. // Passes the fileId from the state parameter to the hash tag and reloads
  2375. // the page without the state parameter
  2376. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2377. urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
  2378. {
  2379. if (this.stateArg.ids != null)
  2380. {
  2381. window.location.hash = 'G' + this.stateArg.ids[0];
  2382. }
  2383. }
  2384. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2385. this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
  2386. {
  2387. this.setMode(App.MODE_GOOGLE);
  2388. this.actions.get('new').funct();
  2389. }
  2390. else
  2391. {
  2392. done();
  2393. }
  2394. }
  2395. }
  2396. }
  2397. catch (e)
  2398. {
  2399. this.handleError(e);
  2400. }
  2401. };
  2402. /**
  2403. * Translates this point by the given vector.
  2404. *
  2405. * @param {number} dx X-coordinate of the translation.
  2406. * @param {number} dy Y-coordinate of the translation.
  2407. */
  2408. App.prototype.showSplash = function(force)
  2409. {
  2410. var serviceCount = this.getServiceCount(true, true);
  2411. var showSecondDialog = mxUtils.bind(this, function()
  2412. {
  2413. var dlg = new SplashDialog(this);
  2414. this.showDialog(dlg.container, 340, (serviceCount < 2 ||
  2415. mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) ? 200 : 260, true, true,
  2416. mxUtils.bind(this, function(cancel)
  2417. {
  2418. // Creates a blank diagram if the dialog is closed
  2419. if (cancel && !mxClient.IS_CHROMEAPP)
  2420. {
  2421. var prev = Editor.useLocalStorage;
  2422. this.createFile(this.defaultFilename, null, null, null, null, null, null,
  2423. urlParams['local'] != '1');
  2424. Editor.useLocalStorage = prev;
  2425. }
  2426. }), true);
  2427. });
  2428. if (this.editor.isChromelessView())
  2429. {
  2430. this.handleError({message: mxResources.get('noFileSelected')},
  2431. mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2432. {
  2433. this.showSplash();
  2434. }));
  2435. }
  2436. else if (!mxClient.IS_CHROMEAPP && (this.mode == null || force))
  2437. {
  2438. var rowLimit = (serviceCount == 4) ? 2 : 3;
  2439. var dlg = new StorageDialog(this, mxUtils.bind(this, function()
  2440. {
  2441. this.hideDialog();
  2442. showSecondDialog();
  2443. }), rowLimit);
  2444. this.showDialog(dlg.container, (rowLimit < 3) ? 260 : 300,
  2445. (serviceCount >= 4) ? 420 : 300, true, false);
  2446. dlg.init();
  2447. }
  2448. else if (urlParams['create'] == null)
  2449. {
  2450. showSecondDialog();
  2451. }
  2452. };
  2453. /**
  2454. * Translates this point by the given vector.
  2455. *
  2456. * @param {number} dx X-coordinate of the translation.
  2457. * @param {number} dy Y-coordinate of the translation.
  2458. */
  2459. App.prototype.addLanguageMenu = function(elt, addLabel)
  2460. {
  2461. var img = null;
  2462. if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
  2463. {
  2464. var langMenu = this.menus.get('language');
  2465. if (langMenu != null)
  2466. {
  2467. img = document.createElement('div');
  2468. img.setAttribute('title', mxResources.get('language'));
  2469. img.className = 'geIcon geSprite geSprite-globe';
  2470. img.style.position = 'absolute';
  2471. img.style.cursor = 'pointer';
  2472. img.style.bottom = '20px';
  2473. img.style.right = '20px';
  2474. if (addLabel)
  2475. {
  2476. img.style.direction = 'rtl';
  2477. img.style.textAlign = 'right';
  2478. img.style.right = '24px';
  2479. var label = document.createElement('span');
  2480. label.style.display = 'inline-block';
  2481. label.style.fontSize = '12px';
  2482. label.style.margin = '5px 24px 0 0';
  2483. label.style.color = 'gray';
  2484. mxUtils.write(label, mxResources.get('language'));
  2485. img.appendChild(label);
  2486. }
  2487. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  2488. {
  2489. this.editor.graph.popupMenuHandler.hideMenu();
  2490. var menu = new mxPopupMenu(this.menus.get('language').funct);
  2491. menu.div.className += ' geMenubarMenu';
  2492. menu.smartSeparators = true;
  2493. menu.showDisabled = true;
  2494. menu.autoExpand = true;
  2495. // Disables autoexpand and destroys menu when hidden
  2496. menu.hideMenu = mxUtils.bind(this, function()
  2497. {
  2498. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  2499. menu.destroy();
  2500. });
  2501. var offset = mxUtils.getOffset(img);
  2502. menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
  2503. // Allows hiding by clicking on document
  2504. this.setCurrentMenu(menu);
  2505. }));
  2506. elt.appendChild(img);
  2507. }
  2508. }
  2509. return img;
  2510. };
  2511. /**
  2512. * Translates this point by the given vector.
  2513. *
  2514. * @param {number} dx X-coordinate of the translation.
  2515. * @param {number} dy Y-coordinate of the translation.
  2516. */
  2517. App.prototype.pickFile = function(mode)
  2518. {
  2519. try
  2520. {
  2521. mode = (mode != null) ? mode : this.mode;
  2522. if (mode == App.MODE_GOOGLE)
  2523. {
  2524. if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2525. {
  2526. this.drive.pickFile();
  2527. }
  2528. else
  2529. {
  2530. this.openLink('https://drive.google.com');
  2531. }
  2532. }
  2533. else
  2534. {
  2535. var peer = this.getPeerForMode(mode);
  2536. if (peer != null)
  2537. {
  2538. peer.pickFile();
  2539. }
  2540. // input.click does not work in IE on Windows 7
  2541. else if (mode == App.MODE_DEVICE && Graph.fileSupport && ((!mxClient.IS_IE && !mxClient.IS_IE11) ||
  2542. navigator.appVersion.indexOf('Windows NT 6.1') < 0))
  2543. {
  2544. var input = document.createElement('input');
  2545. input.setAttribute('type', 'file');
  2546. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2547. {
  2548. if (input.files != null)
  2549. {
  2550. this.openFiles(input.files);
  2551. }
  2552. }));
  2553. input.click();
  2554. }
  2555. else
  2556. {
  2557. this.hideDialog();
  2558. window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
  2559. window.baseUrl = this.getUrl();
  2560. window.openKey = 'open';
  2561. var prevValue = Editor.useLocalStorage;
  2562. Editor.useLocalStorage = (mode == App.MODE_BROWSER);
  2563. this.openFile();
  2564. // Installs local handler for opened files in same window
  2565. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2566. {
  2567. // Replaces PNG with XML extension
  2568. var dot = !this.useCanvasForExport && filename.substring(filename.length - 4) == '.png';
  2569. if (dot)
  2570. {
  2571. filename = filename.substring(0, filename.length - 4) + '.drawio';
  2572. }
  2573. this.fileLoaded((mode == App.MODE_BROWSER) ?
  2574. new StorageFile(this, xml, filename) :
  2575. new LocalFile(this, xml, filename));
  2576. }));
  2577. // Extends dialog close to show splash screen
  2578. var dlg = this.dialog;
  2579. var dlgClose = dlg.close;
  2580. this.dialog.close = mxUtils.bind(this, function(cancel)
  2581. {
  2582. Editor.useLocalStorage = prevValue;
  2583. dlgClose.apply(dlg, arguments);
  2584. if (this.getCurrentFile() == null)
  2585. {
  2586. this.showSplash();
  2587. }
  2588. });
  2589. }
  2590. }
  2591. }
  2592. catch (e)
  2593. {
  2594. this.handleError(e);
  2595. }
  2596. };
  2597. /**
  2598. * Translates this point by the given vector.
  2599. *
  2600. * @param {number} dx X-coordinate of the translation.
  2601. * @param {number} dy Y-coordinate of the translation.
  2602. */
  2603. App.prototype.pickLibrary = function(mode)
  2604. {
  2605. mode = (mode != null) ? mode : this.mode;
  2606. if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE || mode == App.MODE_GITHUB || mode == App.MODE_TRELLO)
  2607. {
  2608. var peer = (mode == App.MODE_GOOGLE) ? this.drive :
  2609. ((mode == App.MODE_ONEDRIVE) ? this.oneDrive :
  2610. ((mode == App.MODE_GITHUB) ? this.gitHub :
  2611. ((mode == App.MODE_TRELLO) ? this.trello :
  2612. this.dropbox)));
  2613. if (peer != null)
  2614. {
  2615. peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
  2616. {
  2617. if (optionalFile != null)
  2618. {
  2619. try
  2620. {
  2621. this.loadLibrary(optionalFile);
  2622. }
  2623. catch (e)
  2624. {
  2625. this.handleError(e, mxResources.get('errorLoadingFile'));
  2626. }
  2627. }
  2628. else
  2629. {
  2630. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2631. {
  2632. peer.getLibrary(id, mxUtils.bind(this, function(file)
  2633. {
  2634. this.spinner.stop();
  2635. try
  2636. {
  2637. this.loadLibrary(file);
  2638. }
  2639. catch (e)
  2640. {
  2641. this.handleError(e, mxResources.get('errorLoadingFile'));
  2642. }
  2643. }), mxUtils.bind(this, function(resp)
  2644. {
  2645. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2646. }));
  2647. }
  2648. }
  2649. }));
  2650. }
  2651. }
  2652. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2653. {
  2654. var input = document.createElement('input');
  2655. input.setAttribute('type', 'file');
  2656. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2657. {
  2658. if (input.files != null)
  2659. {
  2660. for (var i = 0; i < input.files.length; i++)
  2661. {
  2662. (mxUtils.bind(this, function(file)
  2663. {
  2664. var reader = new FileReader();
  2665. reader.onload = mxUtils.bind(this, function(e)
  2666. {
  2667. try
  2668. {
  2669. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  2670. }
  2671. catch (e)
  2672. {
  2673. this.handleError(e, mxResources.get('errorLoadingFile'));
  2674. }
  2675. });
  2676. reader.readAsText(file);
  2677. }))(input.files[i]);
  2678. }
  2679. }
  2680. }));
  2681. input.click();
  2682. }
  2683. else
  2684. {
  2685. window.openNew = false;
  2686. window.openKey = 'open';
  2687. var prevValue = Editor.useLocalStorage;
  2688. Editor.useLocalStorage = mode == App.MODE_BROWSER;
  2689. // Closes dialog after open
  2690. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2691. {
  2692. this.hideDialog(cancel);
  2693. }));
  2694. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2695. {
  2696. try
  2697. {
  2698. this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
  2699. new LocalLibrary(this, xml, filename));
  2700. }
  2701. catch (e)
  2702. {
  2703. this.handleError(e, mxResources.get('errorLoadingFile'));
  2704. }
  2705. }));
  2706. // Removes openFile if dialog is closed
  2707. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
  2708. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2709. {
  2710. Editor.useLocalStorage = prevValue;
  2711. window.openFile = null;
  2712. });
  2713. }
  2714. };
  2715. /**
  2716. * Translates this point by the given vector.
  2717. *
  2718. * @param {number} dx X-coordinate of the translation.
  2719. * @param {number} dy Y-coordinate of the translation.
  2720. */
  2721. App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  2722. {
  2723. try
  2724. {
  2725. mode = (mode != null) ? mode : this.mode;
  2726. noSpin = (noSpin != null) ? noSpin : false;
  2727. noReload = (noReload != null) ? noReload : false;
  2728. var xml = this.createLibraryDataFromImages(images);
  2729. var error = mxUtils.bind(this, function(resp)
  2730. {
  2731. this.spinner.stop();
  2732. if (fn != null)
  2733. {
  2734. fn();
  2735. }
  2736. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  2737. });
  2738. // Handles special case for local libraries
  2739. if (file == null && mode == App.MODE_DEVICE)
  2740. {
  2741. file = new LocalLibrary(this, xml, name);
  2742. }
  2743. if (file == null)
  2744. {
  2745. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2746. {
  2747. if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2748. {
  2749. this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
  2750. {
  2751. this.spinner.stop();
  2752. this.hideDialog(true);
  2753. this.libraryLoaded(newFile, images);
  2754. }), error, this.drive.libraryMimeType);
  2755. }
  2756. else if (mode == App.MODE_GITHUB && this.gitHub != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2757. {
  2758. this.gitHub.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2759. {
  2760. this.spinner.stop();
  2761. this.hideDialog(true);
  2762. this.libraryLoaded(newFile, images);
  2763. }), error, folderId);
  2764. }
  2765. else if (mode == App.MODE_TRELLO && this.trello != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2766. {
  2767. this.trello.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2768. {
  2769. this.spinner.stop();
  2770. this.hideDialog(true);
  2771. this.libraryLoaded(newFile, images);
  2772. }), error, folderId);
  2773. }
  2774. else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2775. {
  2776. this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2777. {
  2778. this.spinner.stop();
  2779. this.hideDialog(true);
  2780. this.libraryLoaded(newFile, images);
  2781. }), error, folderId);
  2782. }
  2783. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2784. {
  2785. this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2786. {
  2787. this.spinner.stop();
  2788. this.hideDialog(true);
  2789. this.libraryLoaded(newFile, images);
  2790. }), error, folderId);
  2791. }
  2792. else if (mode == App.MODE_BROWSER)
  2793. {
  2794. var fn = mxUtils.bind(this, function()
  2795. {
  2796. var file = new StorageLibrary(this, xml, name);
  2797. // Inserts data into local storage
  2798. file.saveFile(name, false, mxUtils.bind(this, function()
  2799. {
  2800. this.hideDialog(true);
  2801. this.libraryLoaded(file, images);
  2802. }), error);
  2803. });
  2804. if (localStorage.getItem(name) == null)
  2805. {
  2806. fn();
  2807. }
  2808. else
  2809. {
  2810. this.confirm(mxResources.get('replaceIt', [name]), fn);
  2811. }
  2812. }
  2813. else
  2814. {
  2815. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  2816. }
  2817. }));
  2818. }
  2819. else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
  2820. {
  2821. file.setData(xml);
  2822. var doSave = mxUtils.bind(this, function()
  2823. {
  2824. file.save(true, mxUtils.bind(this, function(resp)
  2825. {
  2826. this.spinner.stop();
  2827. this.hideDialog(true);
  2828. if (!noReload)
  2829. {
  2830. this.libraryLoaded(file, images);
  2831. }
  2832. if (fn != null)
  2833. {
  2834. fn();
  2835. }
  2836. }), error);
  2837. });
  2838. if (name != file.getTitle())
  2839. {
  2840. var oldHash = file.getHash();
  2841. file.rename(name, mxUtils.bind(this, function(resp)
  2842. {
  2843. // Change hash in stored settings
  2844. if (file.constructor != LocalLibrary && oldHash != file.getHash())
  2845. {
  2846. mxSettings.removeCustomLibrary(oldHash);
  2847. mxSettings.addCustomLibrary(file.getHash());
  2848. }
  2849. // Workaround for library files changing hash so
  2850. // the old library cannot be removed from the
  2851. // sidebar using the updated file in libraryLoaded
  2852. this.removeLibrarySidebar(oldHash);
  2853. doSave();
  2854. }), error)
  2855. }
  2856. else
  2857. {
  2858. doSave();
  2859. }
  2860. }
  2861. }
  2862. catch (e)
  2863. {
  2864. this.handleError(e);
  2865. }
  2866. };
  2867. /**
  2868. * Adds the label menu items to the given menu and parent.
  2869. */
  2870. App.prototype.saveFile = function(forceDialog, success)
  2871. {
  2872. var file = this.getCurrentFile();
  2873. if (file != null)
  2874. {
  2875. // FIXME: Invoke for local files
  2876. var done = mxUtils.bind(this, function()
  2877. {
  2878. this.removeDraft();
  2879. if (this.getCurrentFile() != file && !file.isModified())
  2880. {
  2881. // Workaround for possible status update while save as dialog is showing
  2882. // is to show no saved status for device files
  2883. if (file.getMode() != App.MODE_DEVICE)
  2884. {
  2885. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
  2886. }
  2887. else
  2888. {
  2889. this.editor.setStatus('');
  2890. }
  2891. }
  2892. if (success != null)
  2893. {
  2894. success();
  2895. }
  2896. });
  2897. if (!forceDialog && file.getTitle() != null && this.mode != null)
  2898. {
  2899. this.save(file.getTitle(), done);
  2900. }
  2901. else
  2902. {
  2903. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  2904. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2905. var prev = this.mode;
  2906. var serviceCount = this.getServiceCount(true);
  2907. if (isLocalStorage)
  2908. {
  2909. serviceCount++;
  2910. }
  2911. var rowLimit = (serviceCount <= 4) ? 2 : (serviceCount > 6 ? 4 : 3);
  2912. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
  2913. {
  2914. if (name != null && name.length > 0)
  2915. {
  2916. if (prev == null && mode == App.MODE_DEVICE)
  2917. {
  2918. this.setMode(App.MODE_DEVICE);
  2919. this.save(name, done);
  2920. }
  2921. else if (mode == 'download')
  2922. {
  2923. var tmp = new LocalFile(this, null, name);
  2924. tmp.save();
  2925. }
  2926. else if (mode == '_blank')
  2927. {
  2928. window.openFile = new OpenFile(function()
  2929. {
  2930. window.openFile = null;
  2931. });
  2932. // Do not use a filename to use undefined mode
  2933. window.openFile.setData(this.getFileData(true));
  2934. this.openLink(this.getUrl(window.location.pathname), null, true);
  2935. }
  2936. else if (prev != mode)
  2937. {
  2938. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2939. {
  2940. this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
  2941. name.indexOf('.') < 0 || /(\.drawio)$/i.test(name),
  2942. /(\.svg)$/i.test(name), /(\.html)$/i.test(name)),
  2943. null, mode, done, this.mode == null, folderId);
  2944. }));
  2945. }
  2946. else if (mode != null)
  2947. {
  2948. this.save(name, done);
  2949. }
  2950. }
  2951. }), mxUtils.bind(this, function()
  2952. {
  2953. this.hideDialog();
  2954. }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
  2955. (this.isOffline()) ? null :
  2956. 'https://desk.draw.io/support/solutions/articles/16000042485',
  2957. true, rowLimit, null, null, null, this.editor.fileExtensions);
  2958. this.showDialog(dlg.container, 460, (serviceCount > rowLimit) ? 390 : 270, true, true);
  2959. dlg.init();
  2960. }
  2961. }
  2962. };
  2963. /**
  2964. * Translates this point by the given vector.
  2965. *
  2966. * @param {number} dx X-coordinate of the translation.
  2967. * @param {number} dy Y-coordinate of the translation.
  2968. */
  2969. App.prototype.loadTemplate = function(url, onload, onerror, templateFilename)
  2970. {
  2971. var base64 = false;
  2972. var realUrl = url;
  2973. if (!this.editor.isCorsEnabledForUrl(realUrl))
  2974. {
  2975. // Always uses base64 response to check magic numbers for file type
  2976. var nocache = 't=' + new Date().getTime();
  2977. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url) + '&base64=1&' + nocache;
  2978. base64 = true;
  2979. }
  2980. var filterFn = (templateFilename != null) ? templateFilename : url;
  2981. this.loadUrl(realUrl, mxUtils.bind(this, function(responseData)
  2982. {
  2983. try
  2984. {
  2985. var data = (!base64) ? responseData : ((window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ?
  2986. atob(responseData) : Base64.decode(responseData));
  2987. if (/(\.v(dx|sdx?))($|\?)/i.test(filterFn) || this.isVisioData(data))
  2988. {
  2989. this.importVisio(this.base64ToBlob(responseData.substring(responseData.indexOf(',') + 1)), function(xml)
  2990. {
  2991. onload(xml);
  2992. }, onerror, filterFn);
  2993. }
  2994. else if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, filterFn))
  2995. {
  2996. // Asynchronous parsing via server
  2997. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  2998. {
  2999. if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status <= 299 &&
  3000. xhr.responseText.substring(0, 13) == '<mxGraphModel')
  3001. {
  3002. onload(xhr.responseText);
  3003. }
  3004. }), url);
  3005. }
  3006. else if (this.isLucidChartData(data))
  3007. {
  3008. this.convertLucidChart(data, mxUtils.bind(this, function(xml)
  3009. {
  3010. onload(xml);
  3011. }), mxUtils.bind(this, function(e)
  3012. {
  3013. onerror(e);
  3014. }));
  3015. }
  3016. else
  3017. {
  3018. if (/(\.png)($|\?)/i.test(filterFn) || this.isPngData(data))
  3019. {
  3020. data = this.extractGraphModelFromPng(responseData);
  3021. }
  3022. onload(data);
  3023. }
  3024. }
  3025. catch (e)
  3026. {
  3027. onerror(e);
  3028. }
  3029. }), onerror, /(\.png)($|\?)/i.test(filterFn) || /(\.v(dx|sdx?))($|\?)/i.test(filterFn), null, null, base64);
  3030. };
  3031. /**
  3032. * Translates this point by the given vector.
  3033. *
  3034. * @param {number} dx X-coordinate of the translation.
  3035. * @param {number} dy Y-coordinate of the translation.
  3036. */
  3037. App.prototype.getPeerForMode = function(mode)
  3038. {
  3039. if (mode == App.MODE_GOOGLE)
  3040. {
  3041. return this.drive;
  3042. }
  3043. else if (mode == App.MODE_GITHUB)
  3044. {
  3045. return this.gitHub;
  3046. }
  3047. else if (mode == App.MODE_DROPBOX)
  3048. {
  3049. return this.dropbox;
  3050. }
  3051. else if (mode == App.MODE_ONEDRIVE)
  3052. {
  3053. return this.oneDrive;
  3054. }
  3055. else if (mode == App.MODE_TRELLO)
  3056. {
  3057. return this.trello;
  3058. }
  3059. else
  3060. {
  3061. return null;
  3062. }
  3063. };
  3064. /**
  3065. * Translates this point by the given vector.
  3066. *
  3067. * @param {number} dx X-coordinate of the translation.
  3068. * @param {number} dy Y-coordinate of the translation.
  3069. */
  3070. App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId, tempFile)
  3071. {
  3072. mode = (tempFile) ? null : ((mode != null) ? mode : this.mode);
  3073. if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  3074. {
  3075. data = (data != null) ? data : this.emptyDiagramXml;
  3076. var complete = mxUtils.bind(this, function()
  3077. {
  3078. this.spinner.stop();
  3079. });
  3080. var error = mxUtils.bind(this, function(resp)
  3081. {
  3082. complete();
  3083. if (resp == null && this.getCurrentFile() == null && this.dialog == null)
  3084. {
  3085. this.showSplash();
  3086. }
  3087. else if (resp != null)
  3088. {
  3089. this.handleError(resp);
  3090. }
  3091. });
  3092. try
  3093. {
  3094. if (mode == App.MODE_GOOGLE && this.drive != null)
  3095. {
  3096. if (folderId == null && this.stateArg != null && this.stateArg.folderId != null)
  3097. {
  3098. folderId = this.stateArg.folderId;
  3099. }
  3100. this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
  3101. {
  3102. complete();
  3103. this.fileCreated(file, libs, replace, done);
  3104. }), error);
  3105. }
  3106. else if (mode == App.MODE_GITHUB && this.gitHub != null)
  3107. {
  3108. this.gitHub.insertFile(title, data, mxUtils.bind(this, function(file)
  3109. {
  3110. complete();
  3111. this.fileCreated(file, libs, replace, done);
  3112. }), error, false, folderId);
  3113. }
  3114. else if (mode == App.MODE_TRELLO && this.trello != null)
  3115. {
  3116. this.trello.insertFile(title, data, mxUtils.bind(this, function(file)
  3117. {
  3118. complete();
  3119. this.fileCreated(file, libs, replace, done);
  3120. }), error, false, folderId);
  3121. }
  3122. else if (mode == App.MODE_DROPBOX && this.dropbox != null)
  3123. {
  3124. this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
  3125. {
  3126. complete();
  3127. this.fileCreated(file, libs, replace, done);
  3128. }), error);
  3129. }
  3130. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  3131. {
  3132. this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
  3133. {
  3134. complete();
  3135. this.fileCreated(file, libs, replace, done);
  3136. }), error, false, folderId);
  3137. }
  3138. else if (mode == App.MODE_BROWSER)
  3139. {
  3140. complete();
  3141. var fn = mxUtils.bind(this, function()
  3142. {
  3143. var file = new StorageFile(this, data, title);
  3144. // Inserts data into local storage
  3145. file.saveFile(title, false, mxUtils.bind(this, function()
  3146. {
  3147. this.fileCreated(file, libs, replace, done);
  3148. }), error);
  3149. });
  3150. if (localStorage.getItem(title) == null)
  3151. {
  3152. fn();
  3153. }
  3154. else
  3155. {
  3156. this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
  3157. {
  3158. if (this.getCurrentFile() == null && this.dialog == null)
  3159. {
  3160. this.showSplash();
  3161. }
  3162. }));
  3163. }
  3164. }
  3165. else
  3166. {
  3167. complete();
  3168. this.fileCreated(new LocalFile(this, data, title, mode == null), libs, replace, done);
  3169. }
  3170. }
  3171. catch (e)
  3172. {
  3173. complete();
  3174. this.handleError(e);
  3175. }
  3176. }
  3177. };
  3178. /**
  3179. * Translates this point by the given vector.
  3180. *
  3181. * @param {number} dx X-coordinate of the translation.
  3182. * @param {number} dy Y-coordinate of the translation.
  3183. */
  3184. App.prototype.fileCreated = function(file, libs, replace, done)
  3185. {
  3186. var url = window.location.pathname;
  3187. if (libs != null && libs.length > 0)
  3188. {
  3189. url += '?libs=' + libs;
  3190. }
  3191. url = this.getUrl(url);
  3192. // Always opens a new tab for local files to avoid losing changes
  3193. if (file.getMode() != App.MODE_DEVICE)
  3194. {
  3195. url += '#' + file.getHash();
  3196. }
  3197. // Makes sure to produce consistent output with finalized files via createFileData this needs
  3198. // to save the file again since it needs the newly created file ID for redirecting in HTML
  3199. if (this.spinner.spin(document.body, mxResources.get('inserting')))
  3200. {
  3201. var data = file.getData();
  3202. var dataNode = (data.length > 0) ? this.editor.extractGraphModel(
  3203. mxUtils.parseXml(data).documentElement, true) : null;
  3204. var redirect = window.location.protocol + '//' + window.location.hostname + url;
  3205. var node = dataNode;
  3206. var graph = null;
  3207. // Handles special case where SVG files need a rendered graph to be saved
  3208. if (dataNode != null && /\.svg$/i.test(file.getTitle()))
  3209. {
  3210. graph = this.createTemporaryGraph(this.editor.graph.getStylesheet());
  3211. document.body.appendChild(graph.container);
  3212. node = this.decodeNodeIntoGraph(node, graph);
  3213. }
  3214. file.setData(this.createFileData(dataNode, graph, file, redirect));
  3215. if (graph != null)
  3216. {
  3217. graph.container.parentNode.removeChild(graph.container);
  3218. }
  3219. var complete = mxUtils.bind(this, function()
  3220. {
  3221. this.spinner.stop();
  3222. });
  3223. var fn = mxUtils.bind(this, function()
  3224. {
  3225. complete();
  3226. var currentFile = this.getCurrentFile();
  3227. if (replace == null && currentFile != null)
  3228. {
  3229. replace = !currentFile.isModified() && currentFile.getMode() == null;
  3230. }
  3231. var fn3 = mxUtils.bind(this, function()
  3232. {
  3233. window.openFile = null;
  3234. this.fileLoaded(file);
  3235. if (replace)
  3236. {
  3237. file.addAllSavedStatus();
  3238. }
  3239. if (libs != null)
  3240. {
  3241. this.sidebar.showEntries(libs);
  3242. }
  3243. });
  3244. var fn2 = mxUtils.bind(this, function()
  3245. {
  3246. if (replace || currentFile == null || !currentFile.isModified())
  3247. {
  3248. fn3();
  3249. }
  3250. else
  3251. {
  3252. this.confirm(mxResources.get('allChangesLost'), null, fn3,
  3253. mxResources.get('cancel'), mxResources.get('discardChanges'));
  3254. }
  3255. });
  3256. if (done != null)
  3257. {
  3258. done();
  3259. }
  3260. // Opens the file in a new window
  3261. if (replace != null && !replace)
  3262. {
  3263. // Opens local file in a new window
  3264. if (file.constructor == LocalFile)
  3265. {
  3266. window.openFile = new OpenFile(function()
  3267. {
  3268. window.openFile = null;
  3269. });
  3270. window.openFile.setData(file.getData(), file.getTitle(), file.getMode() == null);
  3271. }
  3272. if (done != null)
  3273. {
  3274. done();
  3275. }
  3276. window.openWindow(url, null, fn2);
  3277. }
  3278. else
  3279. {
  3280. fn2();
  3281. }
  3282. });
  3283. // Updates data in memory for local files
  3284. if (file.constructor == LocalFile)
  3285. {
  3286. fn();
  3287. }
  3288. else
  3289. {
  3290. file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
  3291. {
  3292. fn();
  3293. }), mxUtils.bind(this, function(resp)
  3294. {
  3295. complete();
  3296. this.handleError(resp);
  3297. }));
  3298. }
  3299. }
  3300. };
  3301. /**
  3302. * Translates this point by the given vector.
  3303. *
  3304. * @param {number} dx X-coordinate of the translation.
  3305. * @param {number} dy Y-coordinate of the translation.
  3306. */
  3307. App.prototype.loadFile = function(id, sameWindow, file, success, force)
  3308. {
  3309. this.hideDialog();
  3310. var fn2 = mxUtils.bind(this, function()
  3311. {
  3312. if (id == null || id.length == 0)
  3313. {
  3314. this.editor.setStatus('');
  3315. this.fileLoaded(null);
  3316. }
  3317. else if (this.spinner.spin(document.body, mxResources.get('loading')))
  3318. {
  3319. // Handles files from localStorage
  3320. if (id.charAt(0) == 'L')
  3321. {
  3322. this.spinner.stop();
  3323. if (!isLocalStorage)
  3324. {
  3325. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3326. {
  3327. var tempFile = this.getCurrentFile();
  3328. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3329. }));
  3330. }
  3331. else
  3332. {
  3333. try
  3334. {
  3335. id = decodeURIComponent(id.substring(1));
  3336. var data = localStorage.getItem(id);
  3337. if (data != null)
  3338. {
  3339. this.fileLoaded(new StorageFile(this, data, id));
  3340. if (success != null)
  3341. {
  3342. success();
  3343. }
  3344. }
  3345. else
  3346. {
  3347. throw {message: mxResources.get('fileNotFound')};
  3348. }
  3349. }
  3350. catch (e)
  3351. {
  3352. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3353. {
  3354. var tempFile = this.getCurrentFile();
  3355. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3356. }));
  3357. }
  3358. }
  3359. }
  3360. else if (file != null)
  3361. {
  3362. // File already loaded
  3363. this.spinner.stop();
  3364. this.fileLoaded(file);
  3365. if (success != null)
  3366. {
  3367. success();
  3368. }
  3369. }
  3370. else if (id.charAt(0) == 'S')
  3371. {
  3372. this.spinner.stop();
  3373. try
  3374. {
  3375. this.loadDescriptor(JSON.parse(Graph.decompress(id.substring(1))),
  3376. success, mxUtils.bind(this, function(e)
  3377. {
  3378. this.handleError(e, mxResources.get('errorLoadingFile'));
  3379. }));
  3380. }
  3381. catch (e)
  3382. {
  3383. this.handleError(e, mxResources.get('errorLoadingFile'));
  3384. }
  3385. }
  3386. else if (id.charAt(0) == 'R')
  3387. {
  3388. // Raw file encoded into URL
  3389. this.spinner.stop();
  3390. var data = decodeURIComponent(id.substring(1));
  3391. if (data.charAt(0) != '<')
  3392. {
  3393. data = Graph.decompress(data);
  3394. }
  3395. var tempFile = new LocalFile(this, data, (urlParams['title'] != null) ?
  3396. decodeURIComponent(urlParams['title']) : this.defaultFilename, true);
  3397. tempFile.getHash = function()
  3398. {
  3399. return id;
  3400. };
  3401. this.fileLoaded(tempFile);
  3402. if (success != null)
  3403. {
  3404. success();
  3405. }
  3406. }
  3407. else if (id.charAt(0) == 'U')
  3408. {
  3409. var url = decodeURIComponent(id.substring(1));
  3410. var doFallback = mxUtils.bind(this, function()
  3411. {
  3412. // Fallback for non-public Google Drive files
  3413. if (url.substring(0, 31) == 'https://drive.google.com/uc?id=' &&
  3414. (this.drive != null || typeof window.DriveClient === 'function'))
  3415. {
  3416. this.hideDialog();
  3417. var fallback = mxUtils.bind(this, function()
  3418. {
  3419. this.spinner.stop();
  3420. if (this.drive != null)
  3421. {
  3422. var tempId = url.substring(31, url.lastIndexOf('&ex'));
  3423. this.loadFile('G' + tempId, sameWindow, null, mxUtils.bind(this, function()
  3424. {
  3425. var currentFile = this.getCurrentFile();
  3426. if (currentFile != null && this.editor.chromeless && !this.editor.editable)
  3427. {
  3428. currentFile.getHash = function()
  3429. {
  3430. return 'G' + tempId;
  3431. };
  3432. window.location.hash = '#' + currentFile.getHash();
  3433. }
  3434. if (success != null)
  3435. {
  3436. success();
  3437. }
  3438. }));
  3439. return true;
  3440. }
  3441. else
  3442. {
  3443. return false;
  3444. }
  3445. });
  3446. if (!fallback() && this.spinner.spin(document.body, mxResources.get('loading')))
  3447. {
  3448. this.addListener('clientLoaded', fallback);
  3449. }
  3450. return true;
  3451. }
  3452. else
  3453. {
  3454. return false;
  3455. }
  3456. });
  3457. this.loadTemplate(url, mxUtils.bind(this, function(text)
  3458. {
  3459. this.spinner.stop();
  3460. if (text != null && text.length > 0)
  3461. {
  3462. var filename = this.defaultFilename;
  3463. // Tries to find name from URL with valid extensions
  3464. if (urlParams['title'] == null && urlParams['notitle'] != '1')
  3465. {
  3466. var tmp = url;
  3467. var dot = url.lastIndexOf('.');
  3468. var slash = tmp.lastIndexOf('/');
  3469. if (dot > slash && slash > 0)
  3470. {
  3471. tmp = tmp.substring(slash + 1, dot);
  3472. var ext = url.substring(dot);
  3473. if (!this.useCanvasForExport && ext == '.png')
  3474. {
  3475. ext = '.drawio';
  3476. }
  3477. if (ext === '.svg' || ext === '.xml' ||
  3478. ext === '.html' || ext === '.png' ||
  3479. ext === '.drawio')
  3480. {
  3481. filename = tmp + ext;
  3482. }
  3483. }
  3484. }
  3485. var tempFile = new LocalFile(this, text, (urlParams['title'] != null) ?
  3486. decodeURIComponent(urlParams['title']) : filename, true);
  3487. tempFile.getHash = function()
  3488. {
  3489. return id;
  3490. };
  3491. if (!this.fileLoaded(tempFile, true) && !doFallback())
  3492. {
  3493. this.handleError({message: mxResources.get('fileNotFound')},
  3494. mxResources.get('errorLoadingFile'));
  3495. }
  3496. }
  3497. else if (!doFallback())
  3498. {
  3499. this.handleError({message: mxResources.get('fileNotFound')},
  3500. mxResources.get('errorLoadingFile'));
  3501. }
  3502. }), mxUtils.bind(this, function()
  3503. {
  3504. if (!doFallback())
  3505. {
  3506. this.spinner.stop();
  3507. this.handleError({message: mxResources.get('fileNotFound')},
  3508. mxResources.get('errorLoadingFile'));
  3509. }
  3510. }), (urlParams['template-filename'] != null) ?
  3511. decodeURIComponent(urlParams['template-filename']) : null);
  3512. }
  3513. else
  3514. {
  3515. // Google Drive files are handled as default file types
  3516. var peer = null;
  3517. if (id.charAt(0) == 'G')
  3518. {
  3519. peer = this.drive;
  3520. }
  3521. else if (id.charAt(0) == 'D')
  3522. {
  3523. peer = this.dropbox;
  3524. }
  3525. else if (id.charAt(0) == 'W')
  3526. {
  3527. peer = this.oneDrive;
  3528. }
  3529. else if (id.charAt(0) == 'H')
  3530. {
  3531. peer = this.gitHub;
  3532. }
  3533. else if (id.charAt(0) == 'T')
  3534. {
  3535. peer = this.trello;
  3536. }
  3537. if (peer == null)
  3538. {
  3539. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3540. {
  3541. var currentFile = this.getCurrentFile();
  3542. window.location.hash = (currentFile != null) ? currentFile.getHash() : '';
  3543. }));
  3544. }
  3545. else
  3546. {
  3547. var peerChar = id.charAt(0);
  3548. id = decodeURIComponent(id.substring(1));
  3549. peer.getFile(id, mxUtils.bind(this, function(file)
  3550. {
  3551. this.spinner.stop();
  3552. this.fileLoaded(file);
  3553. var currentFile = this.getCurrentFile();
  3554. // Keeps ID event for converted files in chromeless mode for refresh to work
  3555. if (currentFile == null)
  3556. {
  3557. window.location.hash = '';
  3558. this.showSplash();
  3559. }
  3560. else if (this.editor.chromeless && !this.editor.editable)
  3561. {
  3562. currentFile.getHash = function()
  3563. {
  3564. return peerChar + id;
  3565. };
  3566. window.location.hash = '#' + currentFile.getHash();
  3567. }
  3568. else
  3569. {
  3570. window.location.hash = currentFile.getHash();
  3571. }
  3572. if (success != null)
  3573. {
  3574. success();
  3575. }
  3576. }), mxUtils.bind(this, function(resp)
  3577. {
  3578. // Makes sure the file does not save the invalid UI model and overwrites anything important
  3579. if (window.console != null && resp != null)
  3580. {
  3581. console.log('error in loadFile:', id, resp);
  3582. }
  3583. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
  3584. {
  3585. var currentFile = this.getCurrentFile();
  3586. if (currentFile == null)
  3587. {
  3588. window.location.hash = '';
  3589. this.showSplash();
  3590. }
  3591. else
  3592. {
  3593. window.location.hash = '#' + currentFile.getHash();
  3594. }
  3595. }));
  3596. }));
  3597. }
  3598. }
  3599. }
  3600. });
  3601. var currentFile = this.getCurrentFile();
  3602. var fn = mxUtils.bind(this, function()
  3603. {
  3604. if (force || currentFile == null || !currentFile.isModified())
  3605. {
  3606. fn2();
  3607. }
  3608. else
  3609. {
  3610. this.confirm(mxResources.get('allChangesLost'), mxUtils.bind(this, function()
  3611. {
  3612. if (currentFile != null)
  3613. {
  3614. window.location.hash = currentFile.getHash();
  3615. }
  3616. }), fn2, mxResources.get('cancel'), mxResources.get('discardChanges'));
  3617. }
  3618. });
  3619. if (id == null || id.length == 0)
  3620. {
  3621. fn();
  3622. }
  3623. else if (currentFile != null && currentFile.isModified() && !sameWindow)
  3624. {
  3625. window.openWindow(this.getUrl() + '#' + id, null, fn);
  3626. }
  3627. else
  3628. {
  3629. fn();
  3630. }
  3631. };
  3632. /**
  3633. * Translates this point by the given vector.
  3634. *
  3635. * @param {number} dx X-coordinate of the translation.
  3636. * @param {number} dy Y-coordinate of the translation.
  3637. */
  3638. App.prototype.getLibraryStorageHint = function(file)
  3639. {
  3640. var tip = file.getTitle();
  3641. if (file.constructor != LocalLibrary)
  3642. {
  3643. tip += '\n' + file.getHash();
  3644. }
  3645. if (file.constructor == DriveLibrary)
  3646. {
  3647. tip += ' (' + mxResources.get('googleDrive') + ')';
  3648. }
  3649. else if (file.constructor == GitHubLibrary)
  3650. {
  3651. tip += ' (' + mxResources.get('github') + ')';
  3652. }
  3653. else if (file.constructor == TrelloLibrary)
  3654. {
  3655. tip += ' (' + mxResources.get('trello') + ')';
  3656. }
  3657. else if (file.constructor == DropboxLibrary)
  3658. {
  3659. tip += ' (' + mxResources.get('dropbox') + ')';
  3660. }
  3661. else if (file.constructor == OneDriveLibrary)
  3662. {
  3663. tip += ' (' + mxResources.get('oneDrive') + ')';
  3664. }
  3665. else if (file.constructor == StorageLibrary)
  3666. {
  3667. tip += ' (' + mxResources.get('browser') + ')';
  3668. }
  3669. else if (file.constructor == LocalLibrary)
  3670. {
  3671. tip += ' (' + mxResources.get('device') + ')';
  3672. }
  3673. return tip;
  3674. };
  3675. /**
  3676. * Updates action states depending on the selection.
  3677. */
  3678. App.prototype.restoreLibraries = function()
  3679. {
  3680. if (this.sidebar != null)
  3681. {
  3682. if (this.pendingLibraries == null)
  3683. {
  3684. this.pendingLibraries = new Object();
  3685. }
  3686. // Ignores this library next time
  3687. var ignore = mxUtils.bind(this, function(id, keep)
  3688. {
  3689. if (!keep)
  3690. {
  3691. mxSettings.removeCustomLibrary(id);
  3692. }
  3693. delete this.pendingLibraries[id];
  3694. });
  3695. var load = mxUtils.bind(this, function(libs, done)
  3696. {
  3697. var waiting = 0;
  3698. var files = [];
  3699. // Loads in order of libs array
  3700. var checkDone = mxUtils.bind(this, function()
  3701. {
  3702. if (waiting == 0)
  3703. {
  3704. if (libs != null)
  3705. {
  3706. for (var i = libs.length - 1; i >= 0; i--)
  3707. {
  3708. if (files[i] != null)
  3709. {
  3710. this.loadLibrary(files[i]);
  3711. }
  3712. }
  3713. }
  3714. if (done != null)
  3715. {
  3716. done();
  3717. }
  3718. }
  3719. });
  3720. if (libs != null)
  3721. {
  3722. for (var i = 0; i < libs.length; i++)
  3723. {
  3724. var name = encodeURIComponent(decodeURIComponent(libs[i]));
  3725. (mxUtils.bind(this, function(id, index)
  3726. {
  3727. if (id != null && id.length > 0 && this.pendingLibraries[id] == null &&
  3728. this.sidebar.palettes[id] == null)
  3729. {
  3730. // Waits for all libraries to load
  3731. waiting++;
  3732. var onload = mxUtils.bind(this, function(file)
  3733. {
  3734. delete this.pendingLibraries[id];
  3735. files[index] = file;
  3736. waiting--;
  3737. checkDone();
  3738. });
  3739. var onerror = mxUtils.bind(this, function(keep)
  3740. {
  3741. ignore(id, keep);
  3742. waiting--;
  3743. checkDone();
  3744. });
  3745. this.pendingLibraries[id] = true;
  3746. var service = id.substring(0, 1);
  3747. if (service == 'L')
  3748. {
  3749. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3750. {
  3751. // Make asynchronous for barrier to work
  3752. window.setTimeout(mxUtils.bind(this, function()
  3753. {
  3754. try
  3755. {
  3756. var name = decodeURIComponent(id.substring(1));
  3757. var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
  3758. {
  3759. if (name == '.scratchpad' && xml == null)
  3760. {
  3761. xml = this.emptyLibraryXml;
  3762. }
  3763. if (xml != null)
  3764. {
  3765. onload(new StorageLibrary(this, xml, name));
  3766. }
  3767. else
  3768. {
  3769. onerror();
  3770. }
  3771. }));
  3772. }
  3773. catch (e)
  3774. {
  3775. onerror();
  3776. }
  3777. }), 0);
  3778. }
  3779. }
  3780. else if (service == 'U')
  3781. {
  3782. var url = decodeURIComponent(id.substring(1));
  3783. if (!this.isOffline())
  3784. {
  3785. var realUrl = url;
  3786. if (!this.editor.isCorsEnabledForUrl(realUrl))
  3787. {
  3788. var nocache = 't=' + new Date().getTime();
  3789. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url) + '&' + nocache;
  3790. }
  3791. try
  3792. {
  3793. // Uses proxy to avoid CORS issues
  3794. mxUtils.get(realUrl, mxUtils.bind(this, function(req)
  3795. {
  3796. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3797. {
  3798. try
  3799. {
  3800. onload(new UrlLibrary(this, req.getText(), url));
  3801. }
  3802. catch (e)
  3803. {
  3804. onerror();
  3805. }
  3806. }
  3807. else
  3808. {
  3809. onerror();
  3810. }
  3811. }), function()
  3812. {
  3813. onerror();
  3814. });
  3815. }
  3816. catch (e)
  3817. {
  3818. onerror();
  3819. }
  3820. }
  3821. }
  3822. else if (service == 'R')
  3823. {
  3824. var libDesc = decodeURIComponent(id.substring(1));
  3825. if (!this.isOffline())
  3826. {
  3827. try
  3828. {
  3829. libDesc = JSON.parse(libDesc);
  3830. var libObj = {
  3831. id: libDesc[0],
  3832. title: libDesc[1],
  3833. downloadUrl: libDesc[2]
  3834. }
  3835. this.remoteInvoke('getFileContent', [libObj.downloadUrl], null, mxUtils.bind(this, function(libContent)
  3836. {
  3837. try
  3838. {
  3839. onload(new RemoteLibrary(this, libContent, libObj));
  3840. }
  3841. catch (e)
  3842. {
  3843. onerror();
  3844. }
  3845. }), function()
  3846. {
  3847. onerror();
  3848. });
  3849. }
  3850. catch (e)
  3851. {
  3852. onerror();
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. var peer = null;
  3859. if (service == 'G')
  3860. {
  3861. if (this.drive != null && this.drive.user != null)
  3862. {
  3863. peer = this.drive;
  3864. }
  3865. }
  3866. else if (service == 'H')
  3867. {
  3868. if (this.gitHub != null && this.gitHub.getUser() != null)
  3869. {
  3870. peer = this.gitHub;
  3871. }
  3872. }
  3873. else if (service == 'T')
  3874. {
  3875. if (this.trello != null && this.trello.isAuthorized())
  3876. {
  3877. peer = this.trello;
  3878. }
  3879. }
  3880. else if (service == 'D')
  3881. {
  3882. if (this.dropbox != null && this.dropbox.getUser() != null)
  3883. {
  3884. peer = this.dropbox;
  3885. }
  3886. }
  3887. else if (service == 'W')
  3888. {
  3889. if (this.oneDrive != null && this.oneDrive.getUser() != null)
  3890. {
  3891. peer = this.oneDrive;
  3892. }
  3893. }
  3894. if (peer != null)
  3895. {
  3896. peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
  3897. {
  3898. try
  3899. {
  3900. onload(file);
  3901. }
  3902. catch (e)
  3903. {
  3904. onerror();
  3905. }
  3906. }), function(resp)
  3907. {
  3908. onerror();
  3909. });
  3910. }
  3911. else
  3912. {
  3913. onerror(true);
  3914. }
  3915. }
  3916. }
  3917. }))(name, i);
  3918. }
  3919. checkDone();
  3920. }
  3921. else
  3922. {
  3923. checkDone();
  3924. }
  3925. });
  3926. load(mxSettings.getCustomLibraries(), function()
  3927. {
  3928. load((urlParams['clibs'] || '').split(';'));
  3929. });
  3930. }
  3931. };
  3932. /**
  3933. * Translates this point by the given vector.
  3934. *
  3935. * @param {number} dx X-coordinate of the translation.
  3936. * @param {number} dy Y-coordinate of the translation.
  3937. */
  3938. App.prototype.updateButtonContainer = function()
  3939. {
  3940. if (this.buttonContainer != null)
  3941. {
  3942. var file = this.getCurrentFile();
  3943. // Comments
  3944. if (this.commentsSupported())
  3945. {
  3946. if (this.commentButton == null)
  3947. {
  3948. this.commentButton = document.createElement('a');
  3949. this.commentButton.setAttribute('title', mxResources.get('comments'));
  3950. this.commentButton.className = 'geToolbarButton';
  3951. this.commentButton.style.cssText = 'display:inline-block;position:relative;box-sizing:border-box;' +
  3952. 'margin-right:4px;float:left;cursor:pointer;width:24px;height:24px;background-size:24px 24px;' +
  3953. 'background-position:center center;background-repeat:no-repeat;background-image:' +
  3954. 'url(' + Editor.commentImage + ');';
  3955. if (uiTheme == 'atlas')
  3956. {
  3957. this.commentButton.style.marginRight = '10px';
  3958. this.commentButton.style.marginTop = '-3px';
  3959. }
  3960. mxEvent.addListener(this.commentButton, 'click', mxUtils.bind(this, function()
  3961. {
  3962. this.actions.get('comments').funct();
  3963. }));
  3964. this.buttonContainer.appendChild(this.commentButton);
  3965. if (uiTheme == 'dark' || uiTheme == 'atlas')
  3966. {
  3967. this.commentButton.style.filter = 'invert(100%)';
  3968. }
  3969. }
  3970. }
  3971. else if (this.commentButton != null)
  3972. {
  3973. this.commentButton.parentNode.removeChild(this.commentButton);
  3974. this.commentButton = null;
  3975. }
  3976. // Share
  3977. if (file != null && file.constructor == DriveFile)
  3978. {
  3979. if (this.shareButton == null)
  3980. {
  3981. this.shareButton = document.createElement('div');
  3982. this.shareButton.className = 'geBtn gePrimaryBtn';
  3983. this.shareButton.style.display = 'inline-block';
  3984. this.shareButton.style.padding = '0 10px 0 10px';
  3985. this.shareButton.style.marginTop = '-4px';
  3986. this.shareButton.style.height = '28px';
  3987. this.shareButton.style.lineHeight = '28px';
  3988. this.shareButton.style.minWidth = '0px';
  3989. this.shareButton.style.cssFloat = 'right';
  3990. this.shareButton.setAttribute('title', mxResources.get('share'));
  3991. var icon = document.createElement('img');
  3992. icon.setAttribute('src', this.shareImage);
  3993. icon.setAttribute('align', 'absmiddle');
  3994. icon.style.marginRight = '4px';
  3995. icon.style.marginTop = '-3px';
  3996. this.shareButton.appendChild(icon);
  3997. mxUtils.write(this.shareButton, mxResources.get('share'));
  3998. mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
  3999. {
  4000. this.actions.get('share').funct();
  4001. }));
  4002. this.buttonContainer.appendChild(this.shareButton);
  4003. }
  4004. }
  4005. else if (this.shareButton != null)
  4006. {
  4007. this.shareButton.parentNode.removeChild(this.shareButton);
  4008. this.shareButton = null;
  4009. }
  4010. }
  4011. };
  4012. /**
  4013. * Translates this point by the given vector.
  4014. *
  4015. * @param {number} dx X-coordinate of the translation.
  4016. * @param {number} dy Y-coordinate of the translation.
  4017. */
  4018. App.prototype.save = function(name, done)
  4019. {
  4020. var file = this.getCurrentFile();
  4021. var msg = mxResources.get('saving');
  4022. if (file != null && this.spinner.spin(document.body, msg))
  4023. {
  4024. this.editor.setStatus('');
  4025. if (this.editor.graph.isEditing())
  4026. {
  4027. this.editor.graph.stopEditing();
  4028. }
  4029. var success = mxUtils.bind(this, function()
  4030. {
  4031. file.handleFileSuccess(true);
  4032. if (done != null)
  4033. {
  4034. done();
  4035. }
  4036. });
  4037. var error = mxUtils.bind(this, function(err)
  4038. {
  4039. file.handleFileError(err, true);
  4040. });
  4041. try
  4042. {
  4043. if (name == file.getTitle())
  4044. {
  4045. file.save(true, success, error);
  4046. }
  4047. else
  4048. {
  4049. file.saveAs(name, success, error)
  4050. }
  4051. }
  4052. catch (err)
  4053. {
  4054. file.handleFileError(err, true);
  4055. }
  4056. }
  4057. };
  4058. /**
  4059. * Invokes callback with null if mode does not support folder or not null
  4060. * if a valid folder was chosen for a mode that supports it. No callback
  4061. * is made if no folder was chosen for a mode that supports it.
  4062. */
  4063. App.prototype.pickFolder = function(mode, fn, enabled, direct, force)
  4064. {
  4065. enabled = (enabled != null) ? enabled : true;
  4066. var resume = this.spinner.pause();
  4067. if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
  4068. {
  4069. // Shows a save dialog
  4070. this.drive.pickFolder(mxUtils.bind(this, function(evt)
  4071. {
  4072. resume();
  4073. if (evt.action == google.picker.Action.PICKED)
  4074. {
  4075. var folderId = null;
  4076. if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
  4077. {
  4078. folderId = evt.docs[0].id;
  4079. }
  4080. fn(folderId);
  4081. }
  4082. }), force);
  4083. }
  4084. else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  4085. {
  4086. this.oneDrive.pickFolder(mxUtils.bind(this, function(files)
  4087. {
  4088. var folderId = null;
  4089. resume();
  4090. if (files != null && files.value != null && files.value.length > 0)
  4091. {
  4092. folderId = OneDriveFile.prototype.getIdOf(files.value[0]);
  4093. fn(folderId);
  4094. }
  4095. }), direct);
  4096. }
  4097. else if (enabled && mode == App.MODE_GITHUB && this.gitHub != null)
  4098. {
  4099. this.gitHub.pickFolder(mxUtils.bind(this, function(folderPath)
  4100. {
  4101. resume();
  4102. fn(folderPath);
  4103. }));
  4104. }
  4105. else if (enabled && mode == App.MODE_TRELLO && this.trello != null)
  4106. {
  4107. this.trello.pickFolder(mxUtils.bind(this, function(cardId)
  4108. {
  4109. resume();
  4110. fn(cardId);
  4111. }));
  4112. }
  4113. else
  4114. {
  4115. EditorUi.prototype.pickFolder.apply(this, arguments);
  4116. }
  4117. };
  4118. /**
  4119. *
  4120. */
  4121. App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  4122. {
  4123. if (mode == App.MODE_DROPBOX)
  4124. {
  4125. if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4126. {
  4127. // LATER: Add folder picker
  4128. this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4129. data, mxUtils.bind(this, function()
  4130. {
  4131. this.spinner.stop();
  4132. }), mxUtils.bind(this, function(resp)
  4133. {
  4134. this.spinner.stop();
  4135. this.handleError(resp);
  4136. }));
  4137. }
  4138. }
  4139. else if (mode == App.MODE_GOOGLE)
  4140. {
  4141. if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4142. {
  4143. this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
  4144. {
  4145. // TODO: Add callback with url param for clickable status message
  4146. // "File exported. Click here to open folder."
  4147. // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
  4148. // mxResources.get('saved') + '</div>');
  4149. //
  4150. // // Installs click handler for opening
  4151. // if (this.statusContainer != null)
  4152. // {
  4153. // var links = this.statusContainer.getElementsByTagName('div');
  4154. //
  4155. // if (links.length > 0)
  4156. // {
  4157. // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
  4158. // {
  4159. // if (resp != null && resp.id != null)
  4160. // {
  4161. // window.open('https://drive.google.com/open?id=' + resp.id);
  4162. // }
  4163. // }));
  4164. // }
  4165. // }
  4166. this.spinner.stop();
  4167. }), mxUtils.bind(this, function(resp)
  4168. {
  4169. this.spinner.stop();
  4170. this.handleError(resp);
  4171. }), mimeType, base64Encoded);
  4172. }
  4173. }
  4174. else if (mode == App.MODE_ONEDRIVE)
  4175. {
  4176. if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4177. {
  4178. // KNOWN: OneDrive does not show .svg extension
  4179. this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4180. data, mxUtils.bind(this, function()
  4181. {
  4182. this.spinner.stop();
  4183. }), mxUtils.bind(this, function(resp)
  4184. {
  4185. this.spinner.stop();
  4186. this.handleError(resp);
  4187. }), false, folderId);
  4188. }
  4189. }
  4190. else if (mode == App.MODE_GITHUB)
  4191. {
  4192. if (this.gitHub != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4193. {
  4194. // Must insert file as library to force the file to be written
  4195. this.gitHub.insertFile(filename, data, mxUtils.bind(this, function()
  4196. {
  4197. this.spinner.stop();
  4198. }), mxUtils.bind(this, function(resp)
  4199. {
  4200. this.spinner.stop();
  4201. this.handleError(resp);
  4202. }), true, folderId, base64Encoded);
  4203. }
  4204. }
  4205. else if (mode == App.MODE_TRELLO)
  4206. {
  4207. if (this.trello != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4208. {
  4209. this.trello.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4210. data, mxUtils.bind(this, function()
  4211. {
  4212. this.spinner.stop();
  4213. }), mxUtils.bind(this, function(resp)
  4214. {
  4215. this.spinner.stop();
  4216. this.handleError(resp);
  4217. }), false, folderId);
  4218. }
  4219. }
  4220. else if (mode == App.MODE_BROWSER)
  4221. {
  4222. var fn = mxUtils.bind(this, function()
  4223. {
  4224. localStorage.setItem(filename, data);
  4225. });
  4226. if (localStorage.getItem(filename) == null)
  4227. {
  4228. fn();
  4229. }
  4230. else
  4231. {
  4232. this.confirm(mxResources.get('replaceIt', [filename]), fn);
  4233. }
  4234. }
  4235. };
  4236. /**
  4237. * Translates this point by the given vector.
  4238. *
  4239. * @param {number} dx X-coordinate of the translation.
  4240. * @param {number} dy Y-coordinate of the translation.
  4241. */
  4242. App.prototype.descriptorChanged = function()
  4243. {
  4244. var file = this.getCurrentFile();
  4245. if (file != null)
  4246. {
  4247. if (this.fname != null)
  4248. {
  4249. this.fnameWrapper.style.display = 'block';
  4250. this.fname.innerHTML = '';
  4251. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4252. mxUtils.write(this.fname, filename);
  4253. this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
  4254. }
  4255. var graph = this.editor.graph;
  4256. var editable = file.isEditable() && !file.invalidChecksum;
  4257. if (graph.isEnabled() && !editable)
  4258. {
  4259. graph.reset();
  4260. }
  4261. graph.setEnabled(editable);
  4262. // Ignores title and hash for revisions
  4263. if (urlParams['rev'] == null)
  4264. {
  4265. this.updateDocumentTitle();
  4266. var newHash = file.getHash();
  4267. if (newHash.length > 0)
  4268. {
  4269. window.location.hash = newHash;
  4270. }
  4271. else if (window.location.hash.length > 0)
  4272. {
  4273. window.location.hash = '';
  4274. }
  4275. }
  4276. }
  4277. this.updateUi();
  4278. if (this.format != null && this.editor.graph.isSelectionEmpty())
  4279. {
  4280. this.format.refresh();
  4281. }
  4282. };
  4283. /**
  4284. * Adds the listener for automatically saving the diagram for local changes.
  4285. */
  4286. App.prototype.showAuthDialog = function(peer, showRememberOption, fn, closeFn)
  4287. {
  4288. var resume = this.spinner.pause();
  4289. this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
  4290. {
  4291. try
  4292. {
  4293. if (fn != null)
  4294. {
  4295. fn(remember, mxUtils.bind(this, function()
  4296. {
  4297. this.hideDialog();
  4298. resume();
  4299. }));
  4300. }
  4301. }
  4302. catch (e)
  4303. {
  4304. this.editor.setStatus(mxUtils.htmlEntities(e.message));
  4305. }
  4306. })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
  4307. {
  4308. if (closeFn != null)
  4309. {
  4310. closeFn();
  4311. }
  4312. if (cancel && this.getCurrentFile() == null && this.dialog == null)
  4313. {
  4314. this.showSplash();
  4315. }
  4316. }));
  4317. };
  4318. /**
  4319. * Checks if the client is authorized and calls the next step. The optional
  4320. * readXml argument is used for import. Default is false. The optional
  4321. * readLibrary argument is used for reading libraries. Default is false.
  4322. */
  4323. App.prototype.convertFile = function(url, filename, mimeType, extension, success, error)
  4324. {
  4325. var name = filename;
  4326. // SVG file extensions are valid and needed for image import
  4327. if (!/\.svg$/i.test(name))
  4328. {
  4329. name = name.substring(0, filename.lastIndexOf('.')) + extension;
  4330. }
  4331. var gitHubUrl = false;
  4332. if (this.gitHub != null && url.substring(0, this.gitHub.baseUrl.length) == this.gitHub.baseUrl)
  4333. {
  4334. gitHubUrl = true;
  4335. }
  4336. // Workaround for wrong binary response with VSD(X) & VDX files
  4337. if (/\.v(dx|sdx?)$/i.test(filename) && Graph.fileSupport && new XMLHttpRequest().upload &&
  4338. typeof new XMLHttpRequest().responseType === 'string')
  4339. {
  4340. var req = new XMLHttpRequest();
  4341. req.open('GET', url, true);
  4342. if (!gitHubUrl)
  4343. {
  4344. req.responseType = 'blob';
  4345. }
  4346. req.onload = mxUtils.bind(this, function()
  4347. {
  4348. if (req.status >= 200 && req.status <= 299)
  4349. {
  4350. var blob = null;
  4351. if (gitHubUrl)
  4352. {
  4353. var file = JSON.parse(req.responseText);
  4354. blob = this.base64ToBlob(file.content, 'application/octet-stream');
  4355. }
  4356. else
  4357. {
  4358. blob = new Blob([req.response], {type: 'application/octet-stream'});
  4359. }
  4360. this.importVisio(blob, mxUtils.bind(this, function(xml)
  4361. {
  4362. success(new LocalFile(this, xml, name, true));
  4363. }), error, filename)
  4364. }
  4365. else if (error != null)
  4366. {
  4367. error({message: mxResources.get('errorLoadingFile')});
  4368. }
  4369. });
  4370. req.onerror = error;
  4371. req.send();
  4372. }
  4373. else
  4374. {
  4375. var handleData = mxUtils.bind(this, function(data)
  4376. {
  4377. try
  4378. {
  4379. if (/\.png$/i.test(filename))
  4380. {
  4381. temp = this.extractGraphModelFromPng(data);
  4382. if (temp != null)
  4383. {
  4384. success(new LocalFile(this, temp, name, true));
  4385. }
  4386. else
  4387. {
  4388. success(new LocalFile(this, data, filename, true));
  4389. }
  4390. }
  4391. else if (Graph.fileSupport && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  4392. {
  4393. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  4394. {
  4395. if (xhr.readyState == 4)
  4396. {
  4397. if (xhr.status >= 200 && xhr.status <= 299)
  4398. {
  4399. success(new LocalFile(this, xhr.responseText, name, true));
  4400. }
  4401. else if (error != null)
  4402. {
  4403. error({message: mxResources.get('errorLoadingFile')});
  4404. }
  4405. }
  4406. }), filename);
  4407. }
  4408. else
  4409. {
  4410. success(new LocalFile(this, data, name, true));
  4411. }
  4412. }
  4413. catch (e)
  4414. {
  4415. if (error != null)
  4416. {
  4417. error(e);
  4418. }
  4419. }
  4420. });
  4421. var binary = /\.png$/i.test(filename) || /\.jpe?g$/i.test(filename) || (mimeType != null &&
  4422. mimeType.substring(0, 6) == 'image/');
  4423. // NOTE: Cannot force non-binary request via loadUrl so needs separate
  4424. // code as decoding twice on content with binary data did not work
  4425. if (gitHubUrl)
  4426. {
  4427. mxUtils.get(url, mxUtils.bind(this, function(req)
  4428. {
  4429. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  4430. {
  4431. if (success != null)
  4432. {
  4433. var file = JSON.parse(req.getText());
  4434. var data = file.content;
  4435. if (file.encoding === 'base64')
  4436. {
  4437. if (/\.png$/i.test(filename))
  4438. {
  4439. data = 'data:image/png;base64,' + data;
  4440. }
  4441. else
  4442. {
  4443. // Workaround for character encoding issues in IE10/11
  4444. data = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ? atob(data) : Base64.decode(data);
  4445. }
  4446. }
  4447. handleData(data);
  4448. }
  4449. }
  4450. else if (error != null)
  4451. {
  4452. error({code: App.ERROR_UNKNOWN});
  4453. }
  4454. }), function()
  4455. {
  4456. if (error != null)
  4457. {
  4458. error({code: App.ERROR_UNKNOWN});
  4459. }
  4460. }, false, this.timeout, function()
  4461. {
  4462. if (error != null)
  4463. {
  4464. error({code: App.ERROR_TIMEOUT, retry: fn});
  4465. }
  4466. });
  4467. }
  4468. else
  4469. {
  4470. this.loadUrl(url, handleData, error, binary);
  4471. }
  4472. }
  4473. };
  4474. /**
  4475. * Adds the listener for automatically saving the diagram for local changes.
  4476. */
  4477. App.prototype.updateHeader = function()
  4478. {
  4479. if (this.menubar != null)
  4480. {
  4481. this.appIcon = document.createElement('a');
  4482. this.appIcon.style.display = 'block';
  4483. this.appIcon.style.position = 'absolute';
  4484. this.appIcon.style.width = '40px';
  4485. this.appIcon.style.height = (this.menubarHeight - 16) + 'px';
  4486. this.appIcon.style.margin = '8px 0px 8px 8px';
  4487. this.appIcon.style.borderRadius = '4px';
  4488. if (uiTheme != 'dark')
  4489. {
  4490. this.appIcon.style.backgroundColor = '#f08705';
  4491. }
  4492. mxEvent.disableContextMenu(this.appIcon);
  4493. mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
  4494. {
  4495. this.appIconClicked(evt);
  4496. }));
  4497. // LATER: Use Alpha image loader in IE6
  4498. // NOTE: This uses the diagram bit of the old logo as it looks better in this case
  4499. //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
  4500. var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
  4501. 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
  4502. this.appIcon.style.backgroundImage = logo;
  4503. this.appIcon.style.backgroundPosition = 'center center';
  4504. this.appIcon.style.backgroundRepeat = 'no-repeat';
  4505. mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
  4506. mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
  4507. {
  4508. var file = this.getCurrentFile();
  4509. if (file != null)
  4510. {
  4511. var mode = file.getMode();
  4512. if (mode == App.MODE_GOOGLE)
  4513. {
  4514. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
  4515. }
  4516. else if (mode == App.MODE_DROPBOX)
  4517. {
  4518. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
  4519. }
  4520. else if (mode == App.MODE_ONEDRIVE)
  4521. {
  4522. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
  4523. }
  4524. else if (mode == App.MODE_GITHUB)
  4525. {
  4526. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/github-logo-white.svg)';
  4527. }
  4528. else if (mode == App.MODE_TRELLO)
  4529. {
  4530. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/trello-logo-white-orange.svg)';
  4531. }
  4532. }
  4533. }));
  4534. mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
  4535. {
  4536. this.appIcon.style.backgroundImage = logo;
  4537. }));
  4538. if (urlParams['embed'] != '1')
  4539. {
  4540. this.menubarContainer.appendChild(this.appIcon);
  4541. }
  4542. this.fnameWrapper = document.createElement('div');
  4543. this.fnameWrapper.style.position = 'absolute';
  4544. this.fnameWrapper.style.right = '120px';
  4545. this.fnameWrapper.style.left = '50px';
  4546. this.fnameWrapper.style.top = '6px';
  4547. this.fnameWrapper.style.height = '26px';
  4548. this.fnameWrapper.style.display = 'none';
  4549. this.fnameWrapper.style.overflow = 'hidden';
  4550. this.fnameWrapper.style.textOverflow = 'ellipsis';
  4551. this.fname = document.createElement('a');
  4552. this.fname.setAttribute('title', mxResources.get('rename'));
  4553. this.fname.className = 'geItem';
  4554. this.fname.style.padding = '2px 8px 2px 8px';
  4555. this.fname.style.display = 'inline';
  4556. this.fname.style.fontSize = '18px';
  4557. this.fname.style.whiteSpace = 'nowrap';
  4558. // Prevents focus
  4559. mxEvent.addListener(this.fname, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4560. mxUtils.bind(this, function(evt)
  4561. {
  4562. evt.preventDefault();
  4563. }));
  4564. mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
  4565. {
  4566. var file = this.getCurrentFile();
  4567. if (file != null && file.isRenamable())
  4568. {
  4569. if (this.editor.graph.isEditing())
  4570. {
  4571. this.editor.graph.stopEditing();
  4572. }
  4573. this.actions.get('rename').funct();
  4574. }
  4575. mxEvent.consume(evt);
  4576. }));
  4577. this.fnameWrapper.appendChild(this.fname);
  4578. if (urlParams['embed'] != '1')
  4579. {
  4580. this.menubarContainer.appendChild(this.fnameWrapper);
  4581. this.menubar.container.style.position = 'absolute';
  4582. this.menubar.container.style.paddingLeft = '52px';
  4583. this.menubar.container.style.boxSizing = 'border-box';
  4584. this.menubar.container.style.top = '29px';
  4585. }
  4586. /**
  4587. * Adds format panel toggle.
  4588. */
  4589. this.toggleFormatElement = document.createElement('a');
  4590. this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (' + Editor.ctrlKey + '+Shift+P)');
  4591. this.toggleFormatElement.style.position = 'absolute';
  4592. this.toggleFormatElement.style.display = 'inline-block';
  4593. this.toggleFormatElement.style.top = '8px';
  4594. this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '30px' : '10px';
  4595. this.toggleFormatElement.style.padding = '2px';
  4596. this.toggleFormatElement.style.fontSize = '14px';
  4597. this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4598. this.toggleFormatElement.style.width = '16px';
  4599. this.toggleFormatElement.style.height = '16px';
  4600. this.toggleFormatElement.style.backgroundPosition = '50% 50%';
  4601. this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
  4602. this.toolbarContainer.appendChild(this.toggleFormatElement);
  4603. if (uiTheme == 'dark')
  4604. {
  4605. this.toggleFormatElement.style.filter = 'invert(100%)';
  4606. }
  4607. // Prevents focus
  4608. mxEvent.addListener(this.toggleFormatElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4609. mxUtils.bind(this, function(evt)
  4610. {
  4611. evt.preventDefault();
  4612. }));
  4613. mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
  4614. {
  4615. this.actions.get('formatPanel').funct();
  4616. mxEvent.consume(evt);
  4617. }));
  4618. var toggleFormatPanel = mxUtils.bind(this, function()
  4619. {
  4620. if (this.formatWidth > 0)
  4621. {
  4622. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
  4623. }
  4624. else
  4625. {
  4626. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
  4627. }
  4628. });
  4629. this.addListener('formatWidthChanged', toggleFormatPanel);
  4630. toggleFormatPanel();
  4631. this.fullscreenElement = document.createElement('a');
  4632. this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
  4633. this.fullscreenElement.style.position = 'absolute';
  4634. this.fullscreenElement.style.display = 'inline-block';
  4635. this.fullscreenElement.style.top = '8px';
  4636. this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '50px' : '30px';
  4637. this.fullscreenElement.style.padding = '2px';
  4638. this.fullscreenElement.style.fontSize = '14px';
  4639. this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4640. this.fullscreenElement.style.width = '16px';
  4641. this.fullscreenElement.style.height = '16px';
  4642. this.fullscreenElement.style.backgroundPosition = '50% 50%';
  4643. this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
  4644. this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
  4645. this.toolbarContainer.appendChild(this.fullscreenElement);
  4646. // Prevents focus
  4647. mxEvent.addListener(this.fullscreenElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4648. mxUtils.bind(this, function(evt)
  4649. {
  4650. evt.preventDefault();
  4651. }));
  4652. // Some style changes in Atlas theme
  4653. if (uiTheme == 'atlas')
  4654. {
  4655. mxUtils.setOpacity(this.toggleFormatElement, 70);
  4656. mxUtils.setOpacity(this.fullscreenElement, 70);
  4657. }
  4658. var initialPosition = this.hsplitPosition;
  4659. var collapsed = false;
  4660. if (uiTheme == 'dark')
  4661. {
  4662. this.fullscreenElement.style.filter = 'invert(100%)';
  4663. }
  4664. mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
  4665. {
  4666. if (uiTheme != 'atlas' && urlParams['embed'] != '1')
  4667. {
  4668. this.toggleCompactMode(!collapsed);
  4669. }
  4670. this.toggleFormatPanel(!collapsed);
  4671. this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
  4672. this.hideFooter();
  4673. collapsed = !collapsed;
  4674. mxEvent.consume(evt);
  4675. }));
  4676. /**
  4677. * Adds compact UI toggle.
  4678. */
  4679. if (urlParams['embed'] != '1')
  4680. {
  4681. this.toggleElement = document.createElement('a');
  4682. this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
  4683. this.toggleElement.className = 'geButton';
  4684. this.toggleElement.style.position = 'absolute';
  4685. this.toggleElement.style.display = 'inline-block';
  4686. this.toggleElement.style.width = '16px';
  4687. this.toggleElement.style.height = '16px';
  4688. this.toggleElement.style.color = '#666';
  4689. this.toggleElement.style.top = '8px';
  4690. this.toggleElement.style.right = '10px';
  4691. this.toggleElement.style.padding = '2px';
  4692. this.toggleElement.style.fontSize = '14px';
  4693. this.toggleElement.style.textDecoration = 'none';
  4694. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4695. this.toggleElement.style.backgroundPosition = '50% 50%';
  4696. this.toggleElement.style.backgroundRepeat = 'no-repeat';
  4697. if (uiTheme == 'dark')
  4698. {
  4699. this.toggleElement.style.filter = 'invert(100%)';
  4700. }
  4701. // Prevents focus
  4702. mxEvent.addListener(this.toggleElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4703. mxUtils.bind(this, function(evt)
  4704. {
  4705. evt.preventDefault();
  4706. }));
  4707. // Toggles compact mode
  4708. mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
  4709. {
  4710. this.toggleCompactMode();
  4711. mxEvent.consume(evt);
  4712. }));
  4713. if (uiTheme != 'atlas')
  4714. {
  4715. this.toolbarContainer.appendChild(this.toggleElement);
  4716. }
  4717. // Enable compact mode for small screens
  4718. if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
  4719. {
  4720. window.setTimeout(mxUtils.bind(this, function()
  4721. {
  4722. this.toggleElement.click();
  4723. }), 0);
  4724. }
  4725. }
  4726. }
  4727. };
  4728. /**
  4729. * Adds the listener for automatically saving the diagram for local changes.
  4730. */
  4731. App.prototype.toggleCompactMode = function(forceHide)
  4732. {
  4733. if (!forceHide && this.appIcon.style.display == 'none')
  4734. {
  4735. this.menubar.container.style.position = 'absolute';
  4736. this.menubar.container.style.paddingLeft = '52px';
  4737. this.menubar.container.style.paddingTop = '';
  4738. this.menubar.container.style.paddingBottom = '';
  4739. this.menubar.container.style.top = '29px';
  4740. this.buttonContainer.style.visibility = 'visible';
  4741. this.appIcon.style.display = 'block';
  4742. this.fnameWrapper.style.display = 'block';
  4743. this.fnameWrapper.style.visibility = 'visible';
  4744. this.menubarHeight = App.prototype.menubarHeight;
  4745. this.refresh();
  4746. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4747. }
  4748. else
  4749. {
  4750. this.menubar.container.style.position = 'relative';
  4751. this.menubar.container.style.paddingLeft = '4px';
  4752. this.menubar.container.style.paddingTop = '0px';
  4753. this.menubar.container.style.paddingBottom = '0px';
  4754. this.menubar.container.style.top = '0px';
  4755. this.buttonContainer.style.visibility = 'hidden';
  4756. this.appIcon.style.display = 'none';
  4757. this.fnameWrapper.style.display = 'none';
  4758. this.fnameWrapper.style.visibility = 'hidden';
  4759. this.menubarHeight = EditorUi.prototype.menubarHeight;
  4760. this.refresh();
  4761. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
  4762. }
  4763. };
  4764. /**
  4765. * Adds the listener for automatically saving the diagram for local changes.
  4766. */
  4767. App.prototype.updateUserElement = function()
  4768. {
  4769. if ((this.drive == null || this.drive.getUser() == null) &&
  4770. (this.oneDrive == null || this.oneDrive.getUser() == null) &&
  4771. (this.dropbox == null || this.dropbox.getUser() == null) &&
  4772. (this.gitHub == null || this.gitHub.getUser() == null) &&
  4773. (this.trello == null || !this.trello.isAuthorized())) //TODO Trello no user issue
  4774. {
  4775. if (this.userElement != null)
  4776. {
  4777. this.userElement.parentNode.removeChild(this.userElement);
  4778. this.userElement = null;
  4779. }
  4780. }
  4781. else
  4782. {
  4783. if (this.userElement == null)
  4784. {
  4785. this.userElement = document.createElement('a');
  4786. this.userElement.className = 'geItem';
  4787. this.userElement.style.position = 'absolute';
  4788. this.userElement.style.fontSize = '8pt';
  4789. this.userElement.style.top = (uiTheme == 'atlas') ? '8px' : '2px';
  4790. this.userElement.style.right = '30px';
  4791. this.userElement.style.margin = '4px';
  4792. this.userElement.style.padding = '2px';
  4793. this.userElement.style.paddingRight = '16px';
  4794. this.userElement.style.verticalAlign = 'middle';
  4795. this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  4796. this.userElement.style.backgroundPosition = '100% 60%';
  4797. this.userElement.style.backgroundRepeat = 'no-repeat';
  4798. this.menubarContainer.appendChild(this.userElement);
  4799. // Prevents focus
  4800. mxEvent.addListener(this.userElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4801. mxUtils.bind(this, function(evt)
  4802. {
  4803. evt.preventDefault();
  4804. }));
  4805. mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
  4806. {
  4807. if (this.userPanel == null)
  4808. {
  4809. var div = document.createElement('div');
  4810. div.className = 'geDialog';
  4811. div.style.position = 'absolute';
  4812. div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
  4813. div.style.right = '36px';
  4814. div.style.padding = '0px';
  4815. div.style.cursor = 'default';
  4816. this.userPanel = div;
  4817. }
  4818. if (this.userPanel.parentNode != null)
  4819. {
  4820. this.userPanel.parentNode.removeChild(this.userPanel);
  4821. }
  4822. else
  4823. {
  4824. var connected = false;
  4825. this.userPanel.innerHTML = '';
  4826. var img = document.createElement('img');
  4827. img.setAttribute('src', Dialog.prototype.closeImage);
  4828. img.setAttribute('title', mxResources.get('close'));
  4829. img.className = 'geDialogClose';
  4830. img.style.top = '8px';
  4831. img.style.right = '8px';
  4832. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  4833. {
  4834. if (this.userPanel.parentNode != null)
  4835. {
  4836. this.userPanel.parentNode.removeChild(this.userPanel);
  4837. }
  4838. }));
  4839. this.userPanel.appendChild(img);
  4840. if (this.drive != null)
  4841. {
  4842. var driveUser = this.drive.getUser();
  4843. if (driveUser != null)
  4844. {
  4845. connected = true;
  4846. this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
  4847. '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
  4848. '<tr><td valign="top">' +
  4849. ((driveUser.pictureUrl != null) ?
  4850. '<img width="80" height="80" style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
  4851. '<img width="80" height="80" style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
  4852. '</td><td valign="top" style="white-space:nowrap;' +
  4853. ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
  4854. '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
  4855. '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small><br><br>' +
  4856. '<small>' + mxResources.get('googleDrive') + '</small></tr></table>';
  4857. var div = document.createElement('div');
  4858. div.style.textAlign = 'center';
  4859. div.style.paddingBottom = '12px';
  4860. div.style.whiteSpace = 'nowrap';
  4861. // LATER: Cannot change user while file is open since close will not work with new
  4862. // credentials and closing the file using fileLoaded(null) will show splash dialog.
  4863. div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
  4864. {
  4865. var file = this.getCurrentFile();
  4866. if (file != null && file.constructor == DriveFile)
  4867. {
  4868. this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
  4869. {
  4870. this.spinner.spin(document.body, mxResources.get('signOut'));
  4871. this.diagramContainer.style.display = 'none';
  4872. this.formatContainer.style.display = 'none';
  4873. this.hsplit.style.display = 'none';
  4874. this.sidebarContainer.style.display = 'none';
  4875. this.sidebarFooterContainer.style.display = 'none';
  4876. if (this.tabContainer != null)
  4877. {
  4878. this.tabContainer.style.display = 'none';
  4879. }
  4880. file.close();
  4881. // LATER: Use callback to wait for thumbnail update
  4882. window.setTimeout(mxUtils.bind(this, function()
  4883. {
  4884. // Workaround to disable the splash screen before reload
  4885. this.showDialog = function() {};
  4886. window.location.hash = '';
  4887. this.drive.clearUserId();
  4888. gapi.auth.signOut();
  4889. // Reload page to reset client auth
  4890. window.location.reload();
  4891. }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
  4892. }));
  4893. }
  4894. else
  4895. {
  4896. this.drive.clearUserId();
  4897. this.drive.setUser(null);
  4898. gapi.auth.signOut();
  4899. }
  4900. })));
  4901. this.userPanel.appendChild(div);
  4902. }
  4903. }
  4904. var addUser = mxUtils.bind(this, function(user, logo, logout, label)
  4905. {
  4906. if (user != null)
  4907. {
  4908. if (connected)
  4909. {
  4910. this.userPanel.appendChild(document.createElement('hr'));
  4911. }
  4912. connected = true;
  4913. this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
  4914. ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
  4915. '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
  4916. ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font>' : '') +
  4917. ((label != null) ? '<br><br><small>' + mxUtils.htmlEntities(label) + '</small>' : '') +
  4918. '</td></tr></table>';
  4919. var div = document.createElement('div');
  4920. div.style.textAlign = 'center';
  4921. div.style.paddingBottom = '12px';
  4922. div.style.whiteSpace = 'nowrap';
  4923. if (logout != null)
  4924. {
  4925. div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
  4926. }
  4927. this.userPanel.appendChild(div);
  4928. }
  4929. });
  4930. if (this.dropbox != null)
  4931. {
  4932. addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
  4933. {
  4934. var file = this.getCurrentFile();
  4935. if (file != null && file.constructor == DropboxFile)
  4936. {
  4937. var doLogout = mxUtils.bind(this, function()
  4938. {
  4939. this.dropbox.logout();
  4940. window.location.hash = '';
  4941. });
  4942. if (!file.isModified())
  4943. {
  4944. doLogout();
  4945. }
  4946. else
  4947. {
  4948. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4949. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4950. }
  4951. }
  4952. else
  4953. {
  4954. this.dropbox.logout();
  4955. }
  4956. }), mxResources.get('dropbox'));
  4957. }
  4958. if (this.oneDrive != null)
  4959. {
  4960. addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
  4961. {
  4962. var file = this.getCurrentFile();
  4963. if (file != null && file.constructor == OneDriveFile)
  4964. {
  4965. var doLogout = mxUtils.bind(this, function()
  4966. {
  4967. this.oneDrive.logout();
  4968. window.location.hash = '';
  4969. });
  4970. if (!file.isModified())
  4971. {
  4972. doLogout();
  4973. }
  4974. else
  4975. {
  4976. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4977. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4978. }
  4979. }
  4980. else
  4981. {
  4982. this.oneDrive.logout();
  4983. }
  4984. }), mxResources.get('oneDrive'));
  4985. }
  4986. if (this.gitHub != null)
  4987. {
  4988. addUser(this.gitHub.getUser(), IMAGE_PATH + '/github-logo.svg', mxUtils.bind(this, function()
  4989. {
  4990. var file = this.getCurrentFile();
  4991. if (file != null && file.constructor == GitHubFile)
  4992. {
  4993. var doLogout = mxUtils.bind(this, function()
  4994. {
  4995. this.gitHub.logout();
  4996. window.location.hash = '';
  4997. });
  4998. if (!file.isModified())
  4999. {
  5000. doLogout();
  5001. }
  5002. else
  5003. {
  5004. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  5005. mxResources.get('cancel'), mxResources.get('discardChanges'));
  5006. }
  5007. }
  5008. else
  5009. {
  5010. this.gitHub.logout();
  5011. }
  5012. }), mxResources.get('github'));
  5013. }
  5014. //TODO We have no user info from Trello, how we can create a user?
  5015. if (this.trello != null)
  5016. {
  5017. addUser(this.trello.getUser(), IMAGE_PATH + '/trello-logo.svg', mxUtils.bind(this, function()
  5018. {
  5019. var file = this.getCurrentFile();
  5020. if (file != null && file.constructor == TrelloFile)
  5021. {
  5022. var doLogout = mxUtils.bind(this, function()
  5023. {
  5024. this.trello.logout();
  5025. window.location.hash = '';
  5026. });
  5027. if (!file.isModified())
  5028. {
  5029. doLogout();
  5030. }
  5031. else
  5032. {
  5033. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  5034. mxResources.get('cancel'), mxResources.get('discardChanges'));
  5035. }
  5036. }
  5037. else
  5038. {
  5039. this.trello.logout();
  5040. }
  5041. }), mxResources.get('trello'));
  5042. }
  5043. if (!connected)
  5044. {
  5045. var div = document.createElement('div');
  5046. div.style.textAlign = 'center';
  5047. div.style.padding = '20px 20px 10px 10px';
  5048. div.innerHTML = mxResources.get('notConnected');
  5049. this.userPanel.appendChild(div);
  5050. }
  5051. var div = document.createElement('div');
  5052. div.style.textAlign = 'center';
  5053. div.style.padding = '12px';
  5054. div.style.background = 'whiteSmoke';
  5055. div.style.borderTop = '1px solid #e0e0e0';
  5056. div.style.whiteSpace = 'nowrap';
  5057. var btn = mxUtils.button(mxResources.get('close'), mxUtils.bind(this, function()
  5058. {
  5059. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5060. {
  5061. this.userPanel.parentNode.removeChild(this.userPanel);
  5062. }
  5063. }));
  5064. div.appendChild(btn);
  5065. this.userPanel.appendChild(div);
  5066. document.body.appendChild(this.userPanel);
  5067. }
  5068. mxEvent.consume(evt);
  5069. }));
  5070. mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
  5071. {
  5072. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5073. {
  5074. this.userPanel.parentNode.removeChild(this.userPanel);
  5075. }
  5076. }));
  5077. }
  5078. var user = null;
  5079. if (this.drive != null && this.drive.getUser() != null)
  5080. {
  5081. user = this.drive.getUser();
  5082. }
  5083. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5084. {
  5085. user = this.oneDrive.getUser();
  5086. }
  5087. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5088. {
  5089. user = this.dropbox.getUser();
  5090. }
  5091. else if (this.gitHub != null && this.gitHub.getUser() != null)
  5092. {
  5093. user = this.gitHub.getUser();
  5094. }
  5095. //TODO Trello no user issue
  5096. if (user != null)
  5097. {
  5098. this.userElement.innerHTML = '';
  5099. if (screen.width > 560)
  5100. {
  5101. mxUtils.write(this.userElement, user.displayName);
  5102. this.userElement.style.display = 'block';
  5103. }
  5104. }
  5105. else
  5106. {
  5107. this.userElement.style.display = 'none';
  5108. }
  5109. }
  5110. };
  5111. //TODO Use this function to get the currently logged in user
  5112. App.prototype.getCurrentUser = function()
  5113. {
  5114. var user = null;
  5115. if (this.drive != null && this.drive.getUser() != null)
  5116. {
  5117. user = this.drive.getUser();
  5118. }
  5119. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5120. {
  5121. user = this.oneDrive.getUser();
  5122. }
  5123. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5124. {
  5125. user = this.dropbox.getUser();
  5126. }
  5127. else if (this.gitHub != null && this.gitHub.getUser() != null)
  5128. {
  5129. user = this.gitHub.getUser();
  5130. }
  5131. //TODO Trello no user issue
  5132. return user;
  5133. }
  5134. /**
  5135. * Override depends on mxSettings which is not defined in the minified viewer.
  5136. */
  5137. var editorResetGraph = Editor.prototype.resetGraph;
  5138. Editor.prototype.resetGraph = function()
  5139. {
  5140. editorResetGraph.apply(this, arguments);
  5141. // Overrides default with persisted value
  5142. this.graph.pageFormat = mxSettings.getPageFormat();
  5143. };