App.js 155 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777
  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. this.actions.get('revisionHistory').setEnabled(this.isRevisionHistoryEnabled());
  1321. };
  1322. /**
  1323. * Updates draft in local storage
  1324. */
  1325. App.prototype.updateDraft = function()
  1326. {
  1327. if (isLocalStorage && localStorage != null)
  1328. {
  1329. localStorage.setItem('.draft', JSON.stringify({modified:
  1330. new Date().getTime(), data: this.getFileData()}));
  1331. }
  1332. };
  1333. /**
  1334. * Returns the draft in local storage
  1335. */
  1336. App.prototype.getDraft = function()
  1337. {
  1338. // FIXME: Handle multiple tabs
  1339. // if (isLocalStorage && localStorage != null)
  1340. // {
  1341. // try
  1342. // {
  1343. // var draft = localStorage.getItem('.draft');
  1344. //
  1345. // if (draft != null)
  1346. // {
  1347. // return JSON.parse(draft);
  1348. // }
  1349. // }
  1350. // catch (e)
  1351. // {
  1352. // // ignore quota etc
  1353. // }
  1354. // }
  1355. return null;
  1356. };
  1357. /**
  1358. * Adds the specified entry to the recent file list in local storage
  1359. */
  1360. App.prototype.addRecent = function(entry)
  1361. {
  1362. if (isLocalStorage && localStorage != null)
  1363. {
  1364. var recent = this.getRecent();
  1365. if (recent == null)
  1366. {
  1367. recent = [];
  1368. }
  1369. else
  1370. {
  1371. for (var i = 0; i < recent.length; i++)
  1372. {
  1373. if (recent[i].id == entry.id)
  1374. {
  1375. recent.splice(i, 1);
  1376. }
  1377. }
  1378. }
  1379. if (recent != null)
  1380. {
  1381. recent.unshift(entry);
  1382. recent = recent.slice(0, 10);
  1383. localStorage.setItem('.recent', JSON.stringify(recent));
  1384. }
  1385. }
  1386. };
  1387. /**
  1388. * Returns the recent file list from local storage
  1389. */
  1390. App.prototype.getRecent = function()
  1391. {
  1392. if (isLocalStorage && localStorage != null)
  1393. {
  1394. try
  1395. {
  1396. var recent = localStorage.getItem('.recent');
  1397. if (recent != null)
  1398. {
  1399. return JSON.parse(recent);
  1400. }
  1401. }
  1402. catch (e)
  1403. {
  1404. // ignore
  1405. }
  1406. return null;
  1407. }
  1408. };
  1409. /**
  1410. * Clears the recent file list in local storage
  1411. */
  1412. App.prototype.resetRecent = function(entry)
  1413. {
  1414. if (isLocalStorage && localStorage != null)
  1415. {
  1416. try
  1417. {
  1418. localStorage.removeItem('.recent');
  1419. }
  1420. catch (e)
  1421. {
  1422. // ignore
  1423. }
  1424. }
  1425. };
  1426. /**
  1427. * Clears the draft save in local storage
  1428. */
  1429. App.prototype.removeDraft = function()
  1430. {
  1431. if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
  1432. {
  1433. try
  1434. {
  1435. localStorage.removeItem('.draft');
  1436. }
  1437. catch (e)
  1438. {
  1439. // ignore quota etc
  1440. }
  1441. }
  1442. };
  1443. /**
  1444. * Sets the onbeforeunload for the application
  1445. */
  1446. App.prototype.onBeforeUnload = function()
  1447. {
  1448. if (urlParams['embed'] == '1' && this.editor.modified)
  1449. {
  1450. return mxResources.get('allChangesLost');
  1451. }
  1452. else
  1453. {
  1454. var file = this.getCurrentFile();
  1455. if (file != null)
  1456. {
  1457. // KNOWN: Message is ignored by most browsers
  1458. if (file.constructor == LocalFile && file.getHash() == '' && !file.isModified() &&
  1459. urlParams['nowarn'] != '1' && !this.isDiagramEmpty() && urlParams['url'] == null &&
  1460. !this.editor.isChromelessView())
  1461. {
  1462. return mxResources.get('ensureDataSaved');
  1463. }
  1464. else if (file.isModified())
  1465. {
  1466. return mxResources.get('allChangesLost');
  1467. }
  1468. else
  1469. {
  1470. file.close(true);
  1471. }
  1472. }
  1473. }
  1474. };
  1475. /**
  1476. * Translates this point by the given vector.
  1477. *
  1478. * @param {number} dx X-coordinate of the translation.
  1479. * @param {number} dy Y-coordinate of the translation.
  1480. */
  1481. App.prototype.updateDocumentTitle = function()
  1482. {
  1483. if (!this.editor.graph.isLightboxView())
  1484. {
  1485. var title = this.editor.appName;
  1486. var file = this.getCurrentFile();
  1487. if (this.isOfflineApp())
  1488. {
  1489. title += ' app';
  1490. }
  1491. if (file != null)
  1492. {
  1493. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  1494. title = filename + ' - ' + title;
  1495. }
  1496. document.title = title;
  1497. }
  1498. };
  1499. /**
  1500. * Authorizes the client, gets the userId and calls <open>.
  1501. */
  1502. App.prototype.createCrcTable = function()
  1503. {
  1504. var crcTable = [];
  1505. var c;
  1506. for (var n = 0; n < 256; n++)
  1507. {
  1508. c = n;
  1509. for (var k = 0; k < 8; k++)
  1510. {
  1511. c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  1512. }
  1513. crcTable[n] = c;
  1514. }
  1515. return crcTable;
  1516. };
  1517. /**
  1518. * Returns a thumbnail of the current file.
  1519. */
  1520. App.prototype.getThumbnail = function(width, success)
  1521. {
  1522. var result = false;
  1523. try
  1524. {
  1525. if (this.thumbImageCache == null)
  1526. {
  1527. this.thumbImageCache = new Object();
  1528. }
  1529. var graph = this.editor.graph;
  1530. // Exports PNG for first page while other page is visible by creating a graph
  1531. // LATER: Add caching for the graph or SVG while not on first page
  1532. if (this.pages != null && this.currentPage != this.pages[0])
  1533. {
  1534. graph = this.createTemporaryGraph(graph.getStylesheet());
  1535. var graphGetGlobalVariable = graph.getGlobalVariable;
  1536. var page = this.pages[0];
  1537. graph.getGlobalVariable = function(name)
  1538. {
  1539. if (name == 'page')
  1540. {
  1541. return page.getName();
  1542. }
  1543. else if (name == 'pagenumber')
  1544. {
  1545. return 1;
  1546. }
  1547. return graphGetGlobalVariable.apply(this, arguments);
  1548. };
  1549. document.body.appendChild(graph.container);
  1550. graph.model.setRoot(page.root);
  1551. }
  1552. // Uses client-side canvas export
  1553. if (mxClient.IS_CHROMEAPP || (!graph.mathEnabled && this.useCanvasForExport))
  1554. {
  1555. this.exportToCanvas(mxUtils.bind(this, function(canvas)
  1556. {
  1557. try
  1558. {
  1559. // Removes temporary graph from DOM
  1560. if (graph != this.editor.graph && graph.container.parentNode != null)
  1561. {
  1562. graph.container.parentNode.removeChild(graph.container);
  1563. }
  1564. }
  1565. catch (e)
  1566. {
  1567. canvas = null;
  1568. }
  1569. success(canvas);
  1570. }), width, this.thumbImageCache, '#ffffff', function()
  1571. {
  1572. // Continues with null in error case
  1573. success();
  1574. }, null, null, null, null, null, null, graph);
  1575. result = true;
  1576. }
  1577. else if (this.canvasSupported && this.getCurrentFile() != null)
  1578. {
  1579. var canvas = document.createElement('canvas');
  1580. var bounds = graph.getGraphBounds();
  1581. var scale = width / bounds.width;
  1582. // Limits scale to 1 or 2 * width / height
  1583. scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
  1584. var x0 = Math.floor(bounds.x);
  1585. var y0 = Math.floor(bounds.y);
  1586. canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
  1587. canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
  1588. var ctx = canvas.getContext('2d');
  1589. // Configures the canvas
  1590. ctx.scale(scale, scale);
  1591. ctx.translate(-x0, -y0);
  1592. // Paint white background instead of transparent
  1593. var bg = graph.background;
  1594. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1595. {
  1596. bg = '#ffffff';
  1597. }
  1598. // Paints background
  1599. ctx.save();
  1600. ctx.fillStyle = bg;
  1601. ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
  1602. ctx.restore();
  1603. var htmlCanvas = new mxJsCanvas(canvas);
  1604. // NOTE: htmlCanvas passed into async canvas is only used for image
  1605. // and canvas caching (canvas caching not used in this case as we do
  1606. // not render text). To reuse that cache via the thumbImageCache we
  1607. // pass that into the async canvas and override the image cache in
  1608. // the newly created html canvas with that of the thumbImageCache.
  1609. // LATER: Is clear thumbImageCache needed if file changes?
  1610. var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
  1611. htmlCanvas.images = this.thumbImageCache.images;
  1612. // Render graph
  1613. var imgExport = new mxImageExport();
  1614. imgExport.drawShape = function(state, canvas)
  1615. {
  1616. if (state.shape instanceof mxShape && state.shape.checkBounds())
  1617. {
  1618. canvas.save();
  1619. canvas.translate(0.5, 0.5);
  1620. state.shape.paint(canvas);
  1621. canvas.translate(-0.5, -0.5);
  1622. canvas.restore();
  1623. }
  1624. };
  1625. imgExport.drawText = function(state, canvas)
  1626. {
  1627. // No text output for thumbnails
  1628. };
  1629. imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
  1630. asynCanvas.finish(mxUtils.bind(this, function()
  1631. {
  1632. try
  1633. {
  1634. imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
  1635. // Removes temporary graph from DOM
  1636. if (graph != this.editor.graph && graph.container.parentNode != null)
  1637. {
  1638. graph.container.parentNode.removeChild(graph.container);
  1639. }
  1640. }
  1641. catch (e)
  1642. {
  1643. canvas = null;
  1644. }
  1645. success(canvas);
  1646. }));
  1647. result = true;
  1648. }
  1649. }
  1650. catch (e)
  1651. {
  1652. // ignore and use placeholder
  1653. // Removes temporary graph from DOM
  1654. if (graph != this.editor.graph && graph.container.parentNode != null)
  1655. {
  1656. graph.container.parentNode.removeChild(graph.container);
  1657. }
  1658. }
  1659. return result;
  1660. };
  1661. /**
  1662. * Translates this point by the given vector.
  1663. *
  1664. * @param {number} dx X-coordinate of the translation.
  1665. * @param {number} dy Y-coordinate of the translation.
  1666. */
  1667. App.prototype.createBackground = function()
  1668. {
  1669. var bg = this.createDiv('background');
  1670. bg.style.position = 'absolute';
  1671. bg.style.background = 'white';
  1672. bg.style.left = '0px';
  1673. bg.style.top = '0px';
  1674. bg.style.bottom = '0px';
  1675. bg.style.right = '0px';
  1676. mxUtils.setOpacity(bg, 100);
  1677. if (mxClient.IS_QUIRKS)
  1678. {
  1679. new mxDivResizer(bg);
  1680. }
  1681. return bg;
  1682. };
  1683. /**
  1684. * Translates this point by the given vector.
  1685. *
  1686. * @param {number} dx X-coordinate of the translation.
  1687. * @param {number} dy Y-coordinate of the translation.
  1688. */
  1689. (function()
  1690. {
  1691. var editorUiSetMode = EditorUi.prototype.setMode;
  1692. App.prototype.setMode = function(mode, remember)
  1693. {
  1694. editorUiSetMode.apply(this, arguments);
  1695. // Note: UseLocalStorage affects the file dialogs
  1696. // and should not be modified if mode is undefined
  1697. if (this.mode != null)
  1698. {
  1699. Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
  1700. }
  1701. if (this.appIcon != null)
  1702. {
  1703. var file = this.getCurrentFile();
  1704. mode = (file != null) ? file.getMode() : mode;
  1705. if (mode == App.MODE_GOOGLE)
  1706. {
  1707. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
  1708. this.appIcon.style.cursor = 'pointer';
  1709. }
  1710. else if (mode == App.MODE_DROPBOX)
  1711. {
  1712. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
  1713. this.appIcon.style.cursor = 'pointer';
  1714. }
  1715. else if (mode == App.MODE_ONEDRIVE)
  1716. {
  1717. this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
  1718. this.appIcon.style.cursor = 'pointer';
  1719. }
  1720. else
  1721. {
  1722. this.appIcon.removeAttribute('title');
  1723. this.appIcon.style.cursor = 'default';
  1724. }
  1725. }
  1726. if (remember)
  1727. {
  1728. try
  1729. {
  1730. if (isLocalStorage)
  1731. {
  1732. localStorage.setItem('.mode', mode);
  1733. }
  1734. else if (typeof(Storage) != 'undefined')
  1735. {
  1736. var expiry = new Date();
  1737. expiry.setYear(expiry.getFullYear() + 1);
  1738. document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
  1739. }
  1740. }
  1741. catch (e)
  1742. {
  1743. // ignore possible access denied
  1744. }
  1745. }
  1746. };
  1747. })();
  1748. /**
  1749. * Function: authorize
  1750. *
  1751. * Authorizes the client, gets the userId and calls <open>.
  1752. */
  1753. App.prototype.appIconClicked = function(evt)
  1754. {
  1755. if (mxEvent.isAltDown(evt))
  1756. {
  1757. this.showSplash(true);
  1758. }
  1759. else
  1760. {
  1761. var file = this.getCurrentFile();
  1762. var mode = (file != null) ? file.getMode() : null;
  1763. if (mode == App.MODE_GOOGLE)
  1764. {
  1765. if (file != null && file.desc != null && file.desc.parents != null &&
  1766. file.desc.parents.length > 0 && !mxEvent.isShiftDown(evt))
  1767. {
  1768. // Opens containing folder
  1769. this.openLink('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
  1770. }
  1771. else if (file != null && file.getId() != null)
  1772. {
  1773. this.openLink('https://drive.google.com/open?id=' + file.getId());
  1774. }
  1775. else
  1776. {
  1777. this.openLink('https://drive.google.com/?authuser=0');
  1778. }
  1779. }
  1780. else if (mode == App.MODE_DROPBOX)
  1781. {
  1782. this.openLink('https://www.dropbox.com/');
  1783. }
  1784. else if (mode == App.MODE_ONEDRIVE)
  1785. {
  1786. this.openLink('https://onedrive.live.com/');
  1787. }
  1788. else if (mode == App.MODE_TRELLO)
  1789. {
  1790. this.openLink('https://trello.com/');
  1791. }
  1792. else if (mode == App.MODE_GITHUB)
  1793. {
  1794. if (file != null && file.constructor == GitHubFile)
  1795. {
  1796. this.openLink(file.meta.html_url);
  1797. }
  1798. else
  1799. {
  1800. this.openLink('https://github.com/');
  1801. }
  1802. }
  1803. }
  1804. mxEvent.consume(evt);
  1805. };
  1806. /**
  1807. * Function: authorize
  1808. *
  1809. * Authorizes the client, gets the userId and calls <open>.
  1810. */
  1811. App.prototype.clearMode = function()
  1812. {
  1813. if (isLocalStorage)
  1814. {
  1815. localStorage.removeItem('.mode');
  1816. }
  1817. else if (typeof(Storage) != 'undefined')
  1818. {
  1819. var expiry = new Date();
  1820. expiry.setYear(expiry.getFullYear() - 1);
  1821. document.cookie = 'MODE=; expires=' + expiry.toUTCString();
  1822. }
  1823. };
  1824. /**
  1825. * Translates this point by the given vector.
  1826. *
  1827. * @param {number} dx X-coordinate of the translation.
  1828. * @param {number} dy Y-coordinate of the translation.
  1829. */
  1830. App.prototype.getDiagramId = function()
  1831. {
  1832. var id = window.location.hash;
  1833. // Strips the hash sign
  1834. if (id != null && id.length > 0)
  1835. {
  1836. id = id.substring(1);
  1837. }
  1838. // Workaround for Trello client appending data after hash
  1839. if (id != null && id.length > 1 && id.charAt(0) == 'T')
  1840. {
  1841. var idx = id.indexOf('#');
  1842. if (idx > 0)
  1843. {
  1844. id = id.substring(0, idx);
  1845. }
  1846. }
  1847. return id;
  1848. };
  1849. /**
  1850. * Opens any file specified in the URL parameters.
  1851. */
  1852. App.prototype.open = function()
  1853. {
  1854. // Cross-domain window access is not allowed in FF, so if we
  1855. // were opened from another domain then this will fail.
  1856. try
  1857. {
  1858. // If the create URL param is used in embed mode then
  1859. // we try to open the XML from window.opener[value].
  1860. // Use this for embedding via tab to bypass the timing
  1861. // issues when passing messages without onload event.
  1862. if (window.opener != null)
  1863. {
  1864. var value = urlParams['create'];
  1865. if (value != null)
  1866. {
  1867. value = decodeURIComponent(value);
  1868. }
  1869. if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
  1870. value.substring(0, 8) != 'https://')
  1871. {
  1872. var doc = mxUtils.parseXml(window.opener[value]);
  1873. this.editor.setGraphXml(doc.documentElement);
  1874. }
  1875. else if (window.opener.openFile != null)
  1876. {
  1877. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename, temp)
  1878. {
  1879. this.spinner.stop();
  1880. if (filename == null)
  1881. {
  1882. var title = urlParams['title'];
  1883. temp = true;
  1884. if (title != null)
  1885. {
  1886. filename = decodeURIComponent(title);
  1887. }
  1888. else
  1889. {
  1890. filename = this.defaultFilename;
  1891. }
  1892. }
  1893. // Replaces PNG with XML extension
  1894. var dot = (!this.useCanvasForExport) ? filename.substring(filename.length - 4) == '.png' : -1;
  1895. if (dot > 0)
  1896. {
  1897. filename = filename.substring(0, filename.length - 4) + '.drawio';
  1898. }
  1899. this.fileLoaded((mxClient.IS_IOS) ?
  1900. new StorageFile(this, xml, filename) :
  1901. new LocalFile(this, xml, filename, temp));
  1902. }));
  1903. }
  1904. }
  1905. }
  1906. catch(e)
  1907. {
  1908. // ignore
  1909. }
  1910. };
  1911. App.prototype.loadGapi = function(then)
  1912. {
  1913. if (typeof gapi !== 'undefined')
  1914. {
  1915. gapi.load(((urlParams['picker'] != '0') ? 'picker,': '') + 'auth:' + App.GOOGLE_APIS, mxUtils.bind(this, function(resp)
  1916. {
  1917. // Starts the app without the Google Option if the API fails to load
  1918. if (gapi.client == null)
  1919. {
  1920. this.drive = null;
  1921. this.mode = null;
  1922. then();
  1923. }
  1924. else
  1925. {
  1926. gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
  1927. {
  1928. // Needed to avoid popup blocking for non-immediate authentication
  1929. gapi.auth.init(mxUtils.bind(this, function()
  1930. {
  1931. if (gapi.client.drive == null)
  1932. {
  1933. this.drive = null;
  1934. this.mode = null;
  1935. }
  1936. then();
  1937. }));
  1938. }));
  1939. }
  1940. }));
  1941. }
  1942. };
  1943. /**
  1944. * Main function. Program starts here.
  1945. *
  1946. * @param {number} dx X-coordinate of the translation.
  1947. * @param {number} dy Y-coordinate of the translation.
  1948. */
  1949. App.prototype.load = function()
  1950. {
  1951. // Checks if we're running in embedded mode
  1952. if (urlParams['embed'] != '1')
  1953. {
  1954. if (this.spinner.spin(document.body, mxResources.get('starting')))
  1955. {
  1956. try
  1957. {
  1958. this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
  1959. }
  1960. catch (e)
  1961. {
  1962. // ignores invalid state args
  1963. }
  1964. this.editor.graph.setEnabled(this.getCurrentFile() != null);
  1965. // Passes the userId from the state parameter to the client
  1966. if ((window.location.hash == null || window.location.hash.length == 0) &&
  1967. this.drive != null && this.stateArg != null && this.stateArg.userId != null)
  1968. {
  1969. this.drive.setUserId(this.stateArg.userId);
  1970. }
  1971. // Legacy support for fileId parameter which is moved to the hash tag
  1972. if (urlParams['fileId'] != null)
  1973. {
  1974. window.location.hash = 'G' + urlParams['fileId'];
  1975. window.location.search = this.getSearch(['fileId']);
  1976. }
  1977. else
  1978. {
  1979. // Asynchronous or disabled loading of client
  1980. if (this.drive == null)
  1981. {
  1982. if (this.mode == App.MODE_GOOGLE)
  1983. {
  1984. this.mode = null;
  1985. }
  1986. this.start();
  1987. }
  1988. else
  1989. {
  1990. this.loadGapi(mxUtils.bind(this, function()
  1991. {
  1992. if (urlParams['convert-realtime'] == '1')
  1993. {
  1994. this.spinner.stop();
  1995. this.drive.convertRealtimeFiles();
  1996. }
  1997. else
  1998. {
  1999. this.start();
  2000. }
  2001. }));
  2002. }
  2003. }
  2004. }
  2005. }
  2006. else
  2007. {
  2008. this.restoreLibraries();
  2009. if (urlParams['gapi'] == '1')
  2010. {
  2011. this.loadGapi(function() {});
  2012. }
  2013. }
  2014. };
  2015. /**
  2016. * Adds the listener for automatically saving the diagram for local changes.
  2017. */
  2018. App.prototype.showRefreshDialog = function(title, message)
  2019. {
  2020. if (!this.showingRefreshDialog)
  2021. {
  2022. this.showingRefreshDialog = true;
  2023. this.showError(title || mxResources.get('externalChanges'),
  2024. message || mxResources.get('redirectToNewApp'),
  2025. mxResources.get('refresh'), mxUtils.bind(this, function()
  2026. {
  2027. var file = this.getCurrentFile();
  2028. if (file != null)
  2029. {
  2030. file.setModified(false);
  2031. }
  2032. this.spinner.spin(document.body, mxResources.get('connecting'));
  2033. this.editor.graph.setEnabled(false);
  2034. window.location.reload();
  2035. }), null, null, null, null, null, 340, 180);
  2036. // Adds important notice to dialog
  2037. if (this.dialog != null && this.dialog.container != null)
  2038. {
  2039. var alert = this.createRealtimeNotice();
  2040. alert.style.left = '0';
  2041. alert.style.right = '0';
  2042. alert.style.borderRadius = '0';
  2043. alert.style.borderLeftStyle = 'none';
  2044. alert.style.borderRightStyle = 'none';
  2045. alert.style.marginBottom = '26px';
  2046. alert.style.padding = '8px 0 8px 0';
  2047. this.dialog.container.appendChild(alert);
  2048. }
  2049. }
  2050. };
  2051. /**
  2052. * Called in start after the spinner stops.
  2053. */
  2054. App.prototype.showAlert = function(message)
  2055. {
  2056. if (message != null && message.length > 0)
  2057. {
  2058. var div = document.createElement('div');
  2059. div.className = 'geAlert';
  2060. div.style.zIndex = 2e9;
  2061. div.style.left = '50%';
  2062. div.style.top = '-100%';
  2063. mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
  2064. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
  2065. div.innerHTML = message;
  2066. var close = document.createElement('a');
  2067. close.className = 'geAlertLink';
  2068. close.style.textAlign = 'right';
  2069. close.style.marginTop = '20px';
  2070. close.style.display = 'block';
  2071. close.setAttribute('title', mxResources.get('close'));
  2072. close.innerHTML = mxResources.get('close');
  2073. div.appendChild(close);
  2074. mxEvent.addListener(close, 'click', function(evt)
  2075. {
  2076. if (div.parentNode != null)
  2077. {
  2078. div.parentNode.removeChild(div);
  2079. mxEvent.consume(evt);
  2080. }
  2081. });
  2082. document.body.appendChild(div);
  2083. // Delayed to get smoother animation after DOM rendering
  2084. window.setTimeout(function()
  2085. {
  2086. div.style.top = '30px';
  2087. }, 10);
  2088. // Fades out the alert after 15 secs
  2089. window.setTimeout(function()
  2090. {
  2091. mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
  2092. div.style.opacity = '0';
  2093. window.setTimeout(function()
  2094. {
  2095. if (div.parentNode != null)
  2096. {
  2097. div.parentNode.removeChild(div);
  2098. }
  2099. }, 2000);
  2100. }, 15000);
  2101. }
  2102. };
  2103. /**
  2104. * Translates this point by the given vector.
  2105. *
  2106. * @param {number} dx X-coordinate of the translation.
  2107. * @param {number} dy Y-coordinate of the translation.
  2108. */
  2109. App.prototype.start = function()
  2110. {
  2111. this.bg.parentNode.removeChild(this.bg);
  2112. this.restoreLibraries();
  2113. this.spinner.stop();
  2114. try
  2115. {
  2116. // Listens to changes of the hash if not in embed or client mode
  2117. if (urlParams['client'] != '1' && urlParams['embed'] != '1')
  2118. {
  2119. // KNOWN: Does not work in quirks mode
  2120. mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
  2121. {
  2122. try
  2123. {
  2124. this.hideDialog();
  2125. var id = this.getDiagramId();
  2126. var file = this.getCurrentFile();
  2127. if (file == null || file.getHash() != id)
  2128. {
  2129. this.loadFile(id, true);
  2130. }
  2131. }
  2132. catch (e)
  2133. {
  2134. // Workaround for possible scrollWidth of null in Dialog ctor
  2135. if (document.body != null)
  2136. {
  2137. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2138. {
  2139. var file = this.getCurrentFile();
  2140. window.location.hash = (file != null) ? file.getHash() : '';
  2141. }));
  2142. }
  2143. }
  2144. }));
  2145. }
  2146. // Redirects old url URL parameter to new #U format
  2147. if ((window.location.hash == null || window.location.hash.length <= 1) && urlParams['url'] != null)
  2148. {
  2149. this.loadFile('U' + urlParams['url'], true);
  2150. }
  2151. else if (this.getCurrentFile() == null)
  2152. {
  2153. var done = mxUtils.bind(this, function()
  2154. {
  2155. // Starts in client mode and waits for data
  2156. if (urlParams['client'] == '1' && (window.location.hash == null ||
  2157. window.location.hash.length == 0 || window.location.hash.substring(0, 2) == '#P'))
  2158. {
  2159. var doLoadFile = mxUtils.bind(this, function(xml)
  2160. {
  2161. // Extracts graph model from PNG
  2162. if (xml.substring(0, 22) == 'data:image/png;base64,')
  2163. {
  2164. xml = this.extractGraphModelFromPng(xml);
  2165. }
  2166. var title = urlParams['title'];
  2167. if (title != null)
  2168. {
  2169. title = decodeURIComponent(title);
  2170. }
  2171. else
  2172. {
  2173. title = this.defaultFilename;
  2174. }
  2175. var file = new LocalFile(this, xml, title, true);
  2176. if (window.location.hash != null && window.location.hash.substring(0, 2) == '#P')
  2177. {
  2178. file.getHash = function()
  2179. {
  2180. return window.location.hash.substring(1);
  2181. };
  2182. }
  2183. this.fileLoaded(file);
  2184. this.getCurrentFile().setModified(!this.editor.chromeless);
  2185. });
  2186. var parent = window.opener || window.parent;
  2187. if (parent != window)
  2188. {
  2189. var value = urlParams['create'];
  2190. if (value != null)
  2191. {
  2192. doLoadFile(parent[decodeURIComponent(value)]);
  2193. }
  2194. else
  2195. {
  2196. value = urlParams['data'];
  2197. if (value != null)
  2198. {
  2199. doLoadFile(decodeURIComponent(value));
  2200. }
  2201. else
  2202. {
  2203. this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
  2204. {
  2205. // Ignores messages from other windows
  2206. if (evt.source == parent)
  2207. {
  2208. doLoadFile(xml);
  2209. }
  2210. }));
  2211. }
  2212. }
  2213. }
  2214. }
  2215. // Checks if no earlier loading errors are showing
  2216. else if (this.dialog == null)
  2217. {
  2218. if (urlParams['demo'] == '1')
  2219. {
  2220. var prev = Editor.useLocalStorage;
  2221. this.createFile(this.defaultFilename, null, null, null, null, null, null, true);
  2222. Editor.useLocalStorage = prev;
  2223. }
  2224. else
  2225. {
  2226. var waiting = false;
  2227. // Checks if we're waiting for some asynchronous file to be loaded
  2228. // Cross-domain window access is not allowed in FF, so if we
  2229. // were opened from another domain then this will fail.
  2230. try
  2231. {
  2232. waiting = window.opener != null && window.opener.openFile != null;
  2233. }
  2234. catch(e)
  2235. {
  2236. // ignore
  2237. }
  2238. if (waiting)
  2239. {
  2240. // Spinner is stopped in App.open
  2241. this.spinner.spin(document.body, mxResources.get('loading'))
  2242. }
  2243. else
  2244. {
  2245. var id = this.getDiagramId();
  2246. if (urlParams['splash'] == '0' && (id == null || id.length == 0))
  2247. {
  2248. if (!mxClient.IS_CHROMEAPP)
  2249. {
  2250. var draft = this.getDraft();
  2251. var fileData = (draft != null) ? draft.data : this.getFileData();
  2252. var prev = Editor.useLocalStorage;
  2253. this.createFile(this.defaultFilename, fileData, null, null, null, null, null, true);
  2254. Editor.useLocalStorage = prev;
  2255. // Draft was used so the user should save the file
  2256. if (draft != null)
  2257. {
  2258. var file = this.getCurrentFile();
  2259. if (file != null)
  2260. {
  2261. file.addUnsavedStatus();
  2262. }
  2263. }
  2264. }
  2265. }
  2266. else
  2267. {
  2268. this.loadFile(id);
  2269. }
  2270. }
  2271. }
  2272. }
  2273. });
  2274. var value = decodeURIComponent(urlParams['create'] || '');
  2275. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2276. value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
  2277. {
  2278. var reconnect = mxUtils.bind(this, function()
  2279. {
  2280. // Removes URL parameter and reloads the page
  2281. if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
  2282. {
  2283. window.location.search = this.getSearch(['create', 'title']);
  2284. };
  2285. });
  2286. var showCreateDialog = mxUtils.bind(this, function(xml)
  2287. {
  2288. this.spinner.stop();
  2289. // Resets mode for dialog - local file is only for preview
  2290. if (urlParams['splash'] != '0')
  2291. {
  2292. this.fileLoaded(new LocalFile(this, xml, null));
  2293. this.editor.graph.setEnabled(false);
  2294. this.mode = urlParams['mode'];
  2295. var title = urlParams['title'];
  2296. if (title != null)
  2297. {
  2298. title = decodeURIComponent(title);
  2299. }
  2300. else
  2301. {
  2302. title = this.defaultFilename;
  2303. }
  2304. var serviceCount = this.getServiceCount(true);
  2305. var rowLimit = (serviceCount <= 4) ? 4 : 3;
  2306. var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
  2307. {
  2308. if (mode == null)
  2309. {
  2310. this.hideDialog();
  2311. var prev = Editor.useLocalStorage;
  2312. this.createFile((filename.length > 0) ? filename : this.defaultFilename,
  2313. this.getFileData(), null, null, null, true, null, true);
  2314. Editor.useLocalStorage = prev;
  2315. }
  2316. else
  2317. {
  2318. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2319. {
  2320. this.createFile(filename, this.getFileData(true),
  2321. null, mode, null, true, folderId);
  2322. }));
  2323. }
  2324. }), null, null, null, null, urlParams['browser'] == '1', null, null, true, rowLimit,
  2325. null, null, null, this.editor.fileExtensions);
  2326. this.showDialog(dlg.container, 400, (serviceCount > rowLimit) ? 390 : 270,
  2327. true, false, mxUtils.bind(this, function(cancel)
  2328. {
  2329. if (cancel && this.getCurrentFile() == null)
  2330. {
  2331. this.showSplash();
  2332. }
  2333. }));
  2334. dlg.init();
  2335. }
  2336. });
  2337. value = decodeURIComponent(value);
  2338. if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
  2339. {
  2340. // Cross-domain window access is not allowed in FF, so if we
  2341. // were opened from another domain then this will fail.
  2342. try
  2343. {
  2344. if (window.opener != null && window.opener[value] != null)
  2345. {
  2346. showCreateDialog(window.opener[value]);
  2347. }
  2348. else
  2349. {
  2350. this.handleError(null, mxResources.get('errorLoadingFile'));
  2351. }
  2352. }
  2353. catch (e)
  2354. {
  2355. this.handleError(e, mxResources.get('errorLoadingFile'));
  2356. }
  2357. }
  2358. else
  2359. {
  2360. this.loadTemplate(value, function(text)
  2361. {
  2362. showCreateDialog(text);
  2363. }, mxUtils.bind(this, function()
  2364. {
  2365. this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
  2366. }));
  2367. }
  2368. }
  2369. else
  2370. {
  2371. // Passes the fileId from the state parameter to the hash tag and reloads
  2372. // the page without the state parameter
  2373. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2374. urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
  2375. {
  2376. if (this.stateArg.ids != null)
  2377. {
  2378. window.location.hash = 'G' + this.stateArg.ids[0];
  2379. }
  2380. }
  2381. if ((window.location.hash == null || window.location.hash.length <= 1) &&
  2382. this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
  2383. {
  2384. this.setMode(App.MODE_GOOGLE);
  2385. this.actions.get('new').funct();
  2386. }
  2387. else
  2388. {
  2389. done();
  2390. }
  2391. }
  2392. }
  2393. }
  2394. catch (e)
  2395. {
  2396. this.handleError(e);
  2397. }
  2398. };
  2399. /**
  2400. * Translates this point by the given vector.
  2401. *
  2402. * @param {number} dx X-coordinate of the translation.
  2403. * @param {number} dy Y-coordinate of the translation.
  2404. */
  2405. App.prototype.showSplash = function(force)
  2406. {
  2407. var serviceCount = this.getServiceCount(true, true);
  2408. var showSecondDialog = mxUtils.bind(this, function()
  2409. {
  2410. var dlg = new SplashDialog(this);
  2411. this.showDialog(dlg.container, 340, (serviceCount < 2 ||
  2412. mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) ? 200 : 260, true, true,
  2413. mxUtils.bind(this, function(cancel)
  2414. {
  2415. // Creates a blank diagram if the dialog is closed
  2416. if (cancel && !mxClient.IS_CHROMEAPP)
  2417. {
  2418. var prev = Editor.useLocalStorage;
  2419. this.createFile(this.defaultFilename, null, null, null, null, null, null,
  2420. urlParams['local'] != '1');
  2421. Editor.useLocalStorage = prev;
  2422. }
  2423. }), true);
  2424. });
  2425. if (this.editor.isChromelessView())
  2426. {
  2427. this.handleError({message: mxResources.get('noFileSelected')},
  2428. mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  2429. {
  2430. this.showSplash();
  2431. }));
  2432. }
  2433. else if (!mxClient.IS_CHROMEAPP && (this.mode == null || force))
  2434. {
  2435. var rowLimit = (serviceCount == 4) ? 2 : 3;
  2436. var dlg = new StorageDialog(this, mxUtils.bind(this, function()
  2437. {
  2438. this.hideDialog();
  2439. showSecondDialog();
  2440. }), rowLimit);
  2441. this.showDialog(dlg.container, (rowLimit < 3) ? 260 : 300,
  2442. (serviceCount >= 4) ? 420 : 300, true, false);
  2443. dlg.init();
  2444. }
  2445. else if (urlParams['create'] == null)
  2446. {
  2447. showSecondDialog();
  2448. }
  2449. };
  2450. /**
  2451. * Translates this point by the given vector.
  2452. *
  2453. * @param {number} dx X-coordinate of the translation.
  2454. * @param {number} dy Y-coordinate of the translation.
  2455. */
  2456. App.prototype.addLanguageMenu = function(elt, addLabel)
  2457. {
  2458. var img = null;
  2459. if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
  2460. {
  2461. var langMenu = this.menus.get('language');
  2462. if (langMenu != null)
  2463. {
  2464. img = document.createElement('div');
  2465. img.setAttribute('title', mxResources.get('language'));
  2466. img.className = 'geIcon geSprite geSprite-globe';
  2467. img.style.position = 'absolute';
  2468. img.style.cursor = 'pointer';
  2469. img.style.bottom = '20px';
  2470. img.style.right = '20px';
  2471. if (addLabel)
  2472. {
  2473. img.style.direction = 'rtl';
  2474. img.style.textAlign = 'right';
  2475. img.style.right = '24px';
  2476. var label = document.createElement('span');
  2477. label.style.display = 'inline-block';
  2478. label.style.fontSize = '12px';
  2479. label.style.margin = '5px 24px 0 0';
  2480. label.style.color = 'gray';
  2481. mxUtils.write(label, mxResources.get('language'));
  2482. img.appendChild(label);
  2483. }
  2484. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  2485. {
  2486. this.editor.graph.popupMenuHandler.hideMenu();
  2487. var menu = new mxPopupMenu(this.menus.get('language').funct);
  2488. menu.div.className += ' geMenubarMenu';
  2489. menu.smartSeparators = true;
  2490. menu.showDisabled = true;
  2491. menu.autoExpand = true;
  2492. // Disables autoexpand and destroys menu when hidden
  2493. menu.hideMenu = mxUtils.bind(this, function()
  2494. {
  2495. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  2496. menu.destroy();
  2497. });
  2498. var offset = mxUtils.getOffset(img);
  2499. menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
  2500. // Allows hiding by clicking on document
  2501. this.setCurrentMenu(menu);
  2502. }));
  2503. elt.appendChild(img);
  2504. }
  2505. }
  2506. return img;
  2507. };
  2508. /**
  2509. * Translates this point by the given vector.
  2510. *
  2511. * @param {number} dx X-coordinate of the translation.
  2512. * @param {number} dy Y-coordinate of the translation.
  2513. */
  2514. App.prototype.pickFile = function(mode)
  2515. {
  2516. try
  2517. {
  2518. mode = (mode != null) ? mode : this.mode;
  2519. if (mode == App.MODE_GOOGLE)
  2520. {
  2521. if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2522. {
  2523. this.drive.pickFile();
  2524. }
  2525. else
  2526. {
  2527. this.openLink('https://drive.google.com');
  2528. }
  2529. }
  2530. else
  2531. {
  2532. var peer = this.getPeerForMode(mode);
  2533. if (peer != null)
  2534. {
  2535. peer.pickFile();
  2536. }
  2537. // input.click does not work in IE on Windows 7
  2538. else if (mode == App.MODE_DEVICE && Graph.fileSupport && ((!mxClient.IS_IE && !mxClient.IS_IE11) ||
  2539. navigator.appVersion.indexOf('Windows NT 6.1') < 0))
  2540. {
  2541. if (this.openFileInputElt == null)
  2542. {
  2543. var input = document.createElement('input');
  2544. input.setAttribute('type', 'file');
  2545. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2546. {
  2547. if (input.files != null)
  2548. {
  2549. this.openFiles(input.files);
  2550. }
  2551. input.value = '';
  2552. }));
  2553. input.style.display = 'none';
  2554. document.body.appendChild(input);
  2555. this.openFileInputElt = input;
  2556. }
  2557. this.openFileInputElt.click();
  2558. }
  2559. else
  2560. {
  2561. this.hideDialog();
  2562. window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
  2563. window.baseUrl = this.getUrl();
  2564. window.openKey = 'open';
  2565. var prevValue = Editor.useLocalStorage;
  2566. Editor.useLocalStorage = (mode == App.MODE_BROWSER);
  2567. this.openFile();
  2568. // Installs local handler for opened files in same window
  2569. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2570. {
  2571. // Replaces PNG with XML extension
  2572. var dot = !this.useCanvasForExport && filename.substring(filename.length - 4) == '.png';
  2573. if (dot)
  2574. {
  2575. filename = filename.substring(0, filename.length - 4) + '.drawio';
  2576. }
  2577. this.fileLoaded((mode == App.MODE_BROWSER) ?
  2578. new StorageFile(this, xml, filename) :
  2579. new LocalFile(this, xml, filename));
  2580. }));
  2581. // Extends dialog close to show splash screen
  2582. var dlg = this.dialog;
  2583. var dlgClose = dlg.close;
  2584. this.dialog.close = mxUtils.bind(this, function(cancel)
  2585. {
  2586. Editor.useLocalStorage = prevValue;
  2587. dlgClose.apply(dlg, arguments);
  2588. if (this.getCurrentFile() == null)
  2589. {
  2590. this.showSplash();
  2591. }
  2592. });
  2593. }
  2594. }
  2595. }
  2596. catch (e)
  2597. {
  2598. this.handleError(e);
  2599. }
  2600. };
  2601. /**
  2602. * Translates this point by the given vector.
  2603. *
  2604. * @param {number} dx X-coordinate of the translation.
  2605. * @param {number} dy Y-coordinate of the translation.
  2606. */
  2607. App.prototype.pickLibrary = function(mode)
  2608. {
  2609. mode = (mode != null) ? mode : this.mode;
  2610. if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE || mode == App.MODE_GITHUB || mode == App.MODE_TRELLO)
  2611. {
  2612. var peer = (mode == App.MODE_GOOGLE) ? this.drive :
  2613. ((mode == App.MODE_ONEDRIVE) ? this.oneDrive :
  2614. ((mode == App.MODE_GITHUB) ? this.gitHub :
  2615. ((mode == App.MODE_TRELLO) ? this.trello :
  2616. this.dropbox)));
  2617. if (peer != null)
  2618. {
  2619. peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
  2620. {
  2621. if (optionalFile != null)
  2622. {
  2623. try
  2624. {
  2625. this.loadLibrary(optionalFile);
  2626. }
  2627. catch (e)
  2628. {
  2629. this.handleError(e, mxResources.get('errorLoadingFile'));
  2630. }
  2631. }
  2632. else
  2633. {
  2634. if (this.spinner.spin(document.body, mxResources.get('loading')))
  2635. {
  2636. peer.getLibrary(id, mxUtils.bind(this, function(file)
  2637. {
  2638. this.spinner.stop();
  2639. try
  2640. {
  2641. this.loadLibrary(file);
  2642. }
  2643. catch (e)
  2644. {
  2645. this.handleError(e, mxResources.get('errorLoadingFile'));
  2646. }
  2647. }), mxUtils.bind(this, function(resp)
  2648. {
  2649. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2650. }));
  2651. }
  2652. }
  2653. }));
  2654. }
  2655. }
  2656. else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  2657. {
  2658. if (this.libFileInputElt == null)
  2659. {
  2660. var input = document.createElement('input');
  2661. input.setAttribute('type', 'file');
  2662. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  2663. {
  2664. if (input.files != null)
  2665. {
  2666. for (var i = 0; i < input.files.length; i++)
  2667. {
  2668. (mxUtils.bind(this, function(file)
  2669. {
  2670. var reader = new FileReader();
  2671. reader.onload = mxUtils.bind(this, function(e)
  2672. {
  2673. try
  2674. {
  2675. this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
  2676. }
  2677. catch (e)
  2678. {
  2679. this.handleError(e, mxResources.get('errorLoadingFile'));
  2680. }
  2681. });
  2682. reader.readAsText(file);
  2683. }))(input.files[i]);
  2684. }
  2685. }
  2686. input.value = '';
  2687. }));
  2688. input.style.display = 'none';
  2689. document.body.appendChild(input);
  2690. this.libFileInputElt = input;
  2691. }
  2692. this.libFileInputElt.click();
  2693. }
  2694. else
  2695. {
  2696. window.openNew = false;
  2697. window.openKey = 'open';
  2698. var prevValue = Editor.useLocalStorage;
  2699. Editor.useLocalStorage = mode == App.MODE_BROWSER;
  2700. // Closes dialog after open
  2701. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2702. {
  2703. this.hideDialog(cancel);
  2704. }));
  2705. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  2706. {
  2707. try
  2708. {
  2709. this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
  2710. new LocalLibrary(this, xml, filename));
  2711. }
  2712. catch (e)
  2713. {
  2714. this.handleError(e, mxResources.get('errorLoadingFile'));
  2715. }
  2716. }));
  2717. // Removes openFile if dialog is closed
  2718. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
  2719. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2720. {
  2721. Editor.useLocalStorage = prevValue;
  2722. window.openFile = null;
  2723. });
  2724. }
  2725. };
  2726. /**
  2727. * Translates this point by the given vector.
  2728. *
  2729. * @param {number} dx X-coordinate of the translation.
  2730. * @param {number} dy Y-coordinate of the translation.
  2731. */
  2732. App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
  2733. {
  2734. try
  2735. {
  2736. mode = (mode != null) ? mode : this.mode;
  2737. noSpin = (noSpin != null) ? noSpin : false;
  2738. noReload = (noReload != null) ? noReload : false;
  2739. var xml = this.createLibraryDataFromImages(images);
  2740. var error = mxUtils.bind(this, function(resp)
  2741. {
  2742. this.spinner.stop();
  2743. if (fn != null)
  2744. {
  2745. fn();
  2746. }
  2747. this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  2748. });
  2749. // Handles special case for local libraries
  2750. if (file == null && mode == App.MODE_DEVICE)
  2751. {
  2752. file = new LocalLibrary(this, xml, name);
  2753. }
  2754. if (file == null)
  2755. {
  2756. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2757. {
  2758. if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2759. {
  2760. this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
  2761. {
  2762. this.spinner.stop();
  2763. this.hideDialog(true);
  2764. this.libraryLoaded(newFile, images);
  2765. }), error, this.drive.libraryMimeType);
  2766. }
  2767. else if (mode == App.MODE_GITHUB && this.gitHub != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2768. {
  2769. this.gitHub.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2770. {
  2771. this.spinner.stop();
  2772. this.hideDialog(true);
  2773. this.libraryLoaded(newFile, images);
  2774. }), error, folderId);
  2775. }
  2776. else if (mode == App.MODE_TRELLO && this.trello != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2777. {
  2778. this.trello.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2779. {
  2780. this.spinner.stop();
  2781. this.hideDialog(true);
  2782. this.libraryLoaded(newFile, images);
  2783. }), error, folderId);
  2784. }
  2785. else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2786. {
  2787. this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2788. {
  2789. this.spinner.stop();
  2790. this.hideDialog(true);
  2791. this.libraryLoaded(newFile, images);
  2792. }), error, folderId);
  2793. }
  2794. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  2795. {
  2796. this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
  2797. {
  2798. this.spinner.stop();
  2799. this.hideDialog(true);
  2800. this.libraryLoaded(newFile, images);
  2801. }), error, folderId);
  2802. }
  2803. else if (mode == App.MODE_BROWSER)
  2804. {
  2805. var fn = mxUtils.bind(this, function()
  2806. {
  2807. var file = new StorageLibrary(this, xml, name);
  2808. // Inserts data into local storage
  2809. file.saveFile(name, false, mxUtils.bind(this, function()
  2810. {
  2811. this.hideDialog(true);
  2812. this.libraryLoaded(file, images);
  2813. }), error);
  2814. });
  2815. if (localStorage.getItem(name) == null)
  2816. {
  2817. fn();
  2818. }
  2819. else
  2820. {
  2821. this.confirm(mxResources.get('replaceIt', [name]), fn);
  2822. }
  2823. }
  2824. else
  2825. {
  2826. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  2827. }
  2828. }));
  2829. }
  2830. else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
  2831. {
  2832. file.setData(xml);
  2833. var doSave = mxUtils.bind(this, function()
  2834. {
  2835. file.save(true, mxUtils.bind(this, function(resp)
  2836. {
  2837. this.spinner.stop();
  2838. this.hideDialog(true);
  2839. if (!noReload)
  2840. {
  2841. this.libraryLoaded(file, images);
  2842. }
  2843. if (fn != null)
  2844. {
  2845. fn();
  2846. }
  2847. }), error);
  2848. });
  2849. if (name != file.getTitle())
  2850. {
  2851. var oldHash = file.getHash();
  2852. file.rename(name, mxUtils.bind(this, function(resp)
  2853. {
  2854. // Change hash in stored settings
  2855. if (file.constructor != LocalLibrary && oldHash != file.getHash())
  2856. {
  2857. mxSettings.removeCustomLibrary(oldHash);
  2858. mxSettings.addCustomLibrary(file.getHash());
  2859. }
  2860. // Workaround for library files changing hash so
  2861. // the old library cannot be removed from the
  2862. // sidebar using the updated file in libraryLoaded
  2863. this.removeLibrarySidebar(oldHash);
  2864. doSave();
  2865. }), error)
  2866. }
  2867. else
  2868. {
  2869. doSave();
  2870. }
  2871. }
  2872. }
  2873. catch (e)
  2874. {
  2875. this.handleError(e);
  2876. }
  2877. };
  2878. /**
  2879. * Adds the label menu items to the given menu and parent.
  2880. */
  2881. App.prototype.saveFile = function(forceDialog, success)
  2882. {
  2883. var file = this.getCurrentFile();
  2884. if (file != null)
  2885. {
  2886. // FIXME: Invoke for local files
  2887. var done = mxUtils.bind(this, function()
  2888. {
  2889. this.removeDraft();
  2890. if (this.getCurrentFile() != file && !file.isModified())
  2891. {
  2892. // Workaround for possible status update while save as dialog is showing
  2893. // is to show no saved status for device files
  2894. if (file.getMode() != App.MODE_DEVICE)
  2895. {
  2896. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
  2897. }
  2898. else
  2899. {
  2900. this.editor.setStatus('');
  2901. }
  2902. }
  2903. if (success != null)
  2904. {
  2905. success();
  2906. }
  2907. });
  2908. if (!forceDialog && file.getTitle() != null && this.mode != null)
  2909. {
  2910. this.save(file.getTitle(), done);
  2911. }
  2912. else
  2913. {
  2914. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  2915. var allowTab = !mxClient.IS_IOS || !navigator.standalone;
  2916. var prev = this.mode;
  2917. var serviceCount = this.getServiceCount(true);
  2918. if (isLocalStorage)
  2919. {
  2920. serviceCount++;
  2921. }
  2922. var rowLimit = (serviceCount <= 4) ? 2 : (serviceCount > 6 ? 4 : 3);
  2923. var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
  2924. {
  2925. if (name != null && name.length > 0)
  2926. {
  2927. if (prev == null && mode == App.MODE_DEVICE)
  2928. {
  2929. this.setMode(App.MODE_DEVICE);
  2930. this.save(name, done);
  2931. }
  2932. else if (mode == 'download')
  2933. {
  2934. var tmp = new LocalFile(this, null, name);
  2935. tmp.save();
  2936. }
  2937. else if (mode == '_blank')
  2938. {
  2939. window.openFile = new OpenFile(function()
  2940. {
  2941. window.openFile = null;
  2942. });
  2943. // Do not use a filename to use undefined mode
  2944. window.openFile.setData(this.getFileData(true));
  2945. this.openLink(this.getUrl(window.location.pathname), null, true);
  2946. }
  2947. else if (prev != mode)
  2948. {
  2949. this.pickFolder(mode, mxUtils.bind(this, function(folderId)
  2950. {
  2951. this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
  2952. name.indexOf('.') < 0 || /(\.drawio)$/i.test(name),
  2953. /(\.svg)$/i.test(name), /(\.html)$/i.test(name)),
  2954. null, mode, done, this.mode == null, folderId);
  2955. }));
  2956. }
  2957. else if (mode != null)
  2958. {
  2959. this.save(name, done);
  2960. }
  2961. }
  2962. }), mxUtils.bind(this, function()
  2963. {
  2964. this.hideDialog();
  2965. }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
  2966. (this.isOffline()) ? null :
  2967. 'https://desk.draw.io/support/solutions/articles/16000042485',
  2968. true, rowLimit, null, null, null, this.editor.fileExtensions);
  2969. this.showDialog(dlg.container, 460, (serviceCount > rowLimit) ? 390 : 270, true, true);
  2970. dlg.init();
  2971. }
  2972. }
  2973. };
  2974. /**
  2975. * Translates this point by the given vector.
  2976. *
  2977. * @param {number} dx X-coordinate of the translation.
  2978. * @param {number} dy Y-coordinate of the translation.
  2979. */
  2980. App.prototype.loadTemplate = function(url, onload, onerror, templateFilename)
  2981. {
  2982. var base64 = false;
  2983. var realUrl = url;
  2984. if (!this.editor.isCorsEnabledForUrl(realUrl))
  2985. {
  2986. // Always uses base64 response to check magic numbers for file type
  2987. var nocache = 't=' + new Date().getTime();
  2988. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url) + '&base64=1&' + nocache;
  2989. base64 = true;
  2990. }
  2991. var filterFn = (templateFilename != null) ? templateFilename : url;
  2992. this.loadUrl(realUrl, mxUtils.bind(this, function(responseData)
  2993. {
  2994. try
  2995. {
  2996. var data = (!base64) ? responseData : ((window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ?
  2997. atob(responseData) : Base64.decode(responseData));
  2998. if (/(\.v(dx|sdx?))($|\?)/i.test(filterFn) || this.isVisioData(data))
  2999. {
  3000. this.importVisio(this.base64ToBlob(responseData.substring(responseData.indexOf(',') + 1)), function(xml)
  3001. {
  3002. onload(xml);
  3003. }, onerror, filterFn);
  3004. }
  3005. else if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, filterFn))
  3006. {
  3007. // Asynchronous parsing via server
  3008. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  3009. {
  3010. if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status <= 299 &&
  3011. xhr.responseText.substring(0, 13) == '<mxGraphModel')
  3012. {
  3013. onload(xhr.responseText);
  3014. }
  3015. }), url);
  3016. }
  3017. else if (this.isLucidChartData(data))
  3018. {
  3019. this.convertLucidChart(data, mxUtils.bind(this, function(xml)
  3020. {
  3021. onload(xml);
  3022. }), mxUtils.bind(this, function(e)
  3023. {
  3024. onerror(e);
  3025. }));
  3026. }
  3027. else
  3028. {
  3029. if (/(\.png)($|\?)/i.test(filterFn) || this.isPngData(data))
  3030. {
  3031. data = this.extractGraphModelFromPng(responseData);
  3032. }
  3033. onload(data);
  3034. }
  3035. }
  3036. catch (e)
  3037. {
  3038. onerror(e);
  3039. }
  3040. }), onerror, /(\.png)($|\?)/i.test(filterFn) || /(\.v(dx|sdx?))($|\?)/i.test(filterFn), null, null, base64);
  3041. };
  3042. /**
  3043. * Translates this point by the given vector.
  3044. *
  3045. * @param {number} dx X-coordinate of the translation.
  3046. * @param {number} dy Y-coordinate of the translation.
  3047. */
  3048. App.prototype.getPeerForMode = function(mode)
  3049. {
  3050. if (mode == App.MODE_GOOGLE)
  3051. {
  3052. return this.drive;
  3053. }
  3054. else if (mode == App.MODE_GITHUB)
  3055. {
  3056. return this.gitHub;
  3057. }
  3058. else if (mode == App.MODE_DROPBOX)
  3059. {
  3060. return this.dropbox;
  3061. }
  3062. else if (mode == App.MODE_ONEDRIVE)
  3063. {
  3064. return this.oneDrive;
  3065. }
  3066. else if (mode == App.MODE_TRELLO)
  3067. {
  3068. return this.trello;
  3069. }
  3070. else
  3071. {
  3072. return null;
  3073. }
  3074. };
  3075. /**
  3076. * Translates this point by the given vector.
  3077. *
  3078. * @param {number} dx X-coordinate of the translation.
  3079. * @param {number} dy Y-coordinate of the translation.
  3080. */
  3081. App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId, tempFile)
  3082. {
  3083. mode = (tempFile) ? null : ((mode != null) ? mode : this.mode);
  3084. if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
  3085. {
  3086. data = (data != null) ? data : this.emptyDiagramXml;
  3087. var complete = mxUtils.bind(this, function()
  3088. {
  3089. this.spinner.stop();
  3090. });
  3091. var error = mxUtils.bind(this, function(resp)
  3092. {
  3093. complete();
  3094. if (resp == null && this.getCurrentFile() == null && this.dialog == null)
  3095. {
  3096. this.showSplash();
  3097. }
  3098. else if (resp != null)
  3099. {
  3100. this.handleError(resp);
  3101. }
  3102. });
  3103. try
  3104. {
  3105. if (mode == App.MODE_GOOGLE && this.drive != null)
  3106. {
  3107. if (folderId == null && this.stateArg != null && this.stateArg.folderId != null)
  3108. {
  3109. folderId = this.stateArg.folderId;
  3110. }
  3111. this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
  3112. {
  3113. complete();
  3114. this.fileCreated(file, libs, replace, done);
  3115. }), error);
  3116. }
  3117. else if (mode == App.MODE_GITHUB && this.gitHub != null)
  3118. {
  3119. this.gitHub.insertFile(title, data, mxUtils.bind(this, function(file)
  3120. {
  3121. complete();
  3122. this.fileCreated(file, libs, replace, done);
  3123. }), error, false, folderId);
  3124. }
  3125. else if (mode == App.MODE_TRELLO && this.trello != null)
  3126. {
  3127. this.trello.insertFile(title, data, mxUtils.bind(this, function(file)
  3128. {
  3129. complete();
  3130. this.fileCreated(file, libs, replace, done);
  3131. }), error, false, folderId);
  3132. }
  3133. else if (mode == App.MODE_DROPBOX && this.dropbox != null)
  3134. {
  3135. this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
  3136. {
  3137. complete();
  3138. this.fileCreated(file, libs, replace, done);
  3139. }), error);
  3140. }
  3141. else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  3142. {
  3143. this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
  3144. {
  3145. complete();
  3146. this.fileCreated(file, libs, replace, done);
  3147. }), error, false, folderId);
  3148. }
  3149. else if (mode == App.MODE_BROWSER)
  3150. {
  3151. complete();
  3152. var fn = mxUtils.bind(this, function()
  3153. {
  3154. var file = new StorageFile(this, data, title);
  3155. // Inserts data into local storage
  3156. file.saveFile(title, false, mxUtils.bind(this, function()
  3157. {
  3158. this.fileCreated(file, libs, replace, done);
  3159. }), error);
  3160. });
  3161. if (localStorage.getItem(title) == null)
  3162. {
  3163. fn();
  3164. }
  3165. else
  3166. {
  3167. this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
  3168. {
  3169. if (this.getCurrentFile() == null && this.dialog == null)
  3170. {
  3171. this.showSplash();
  3172. }
  3173. }));
  3174. }
  3175. }
  3176. else
  3177. {
  3178. complete();
  3179. this.fileCreated(new LocalFile(this, data, title, mode == null), libs, replace, done);
  3180. }
  3181. }
  3182. catch (e)
  3183. {
  3184. complete();
  3185. this.handleError(e);
  3186. }
  3187. }
  3188. };
  3189. /**
  3190. * Translates this point by the given vector.
  3191. *
  3192. * @param {number} dx X-coordinate of the translation.
  3193. * @param {number} dy Y-coordinate of the translation.
  3194. */
  3195. App.prototype.fileCreated = function(file, libs, replace, done)
  3196. {
  3197. var url = window.location.pathname;
  3198. if (libs != null && libs.length > 0)
  3199. {
  3200. url += '?libs=' + libs;
  3201. }
  3202. url = this.getUrl(url);
  3203. // Always opens a new tab for local files to avoid losing changes
  3204. if (file.getMode() != App.MODE_DEVICE)
  3205. {
  3206. url += '#' + file.getHash();
  3207. }
  3208. // Makes sure to produce consistent output with finalized files via createFileData this needs
  3209. // to save the file again since it needs the newly created file ID for redirecting in HTML
  3210. if (this.spinner.spin(document.body, mxResources.get('inserting')))
  3211. {
  3212. var data = file.getData();
  3213. var dataNode = (data.length > 0) ? this.editor.extractGraphModel(
  3214. mxUtils.parseXml(data).documentElement, true) : null;
  3215. var redirect = window.location.protocol + '//' + window.location.hostname + url;
  3216. var node = dataNode;
  3217. var graph = null;
  3218. // Handles special case where SVG files need a rendered graph to be saved
  3219. if (dataNode != null && /\.svg$/i.test(file.getTitle()))
  3220. {
  3221. graph = this.createTemporaryGraph(this.editor.graph.getStylesheet());
  3222. document.body.appendChild(graph.container);
  3223. node = this.decodeNodeIntoGraph(node, graph);
  3224. }
  3225. file.setData(this.createFileData(dataNode, graph, file, redirect));
  3226. if (graph != null)
  3227. {
  3228. graph.container.parentNode.removeChild(graph.container);
  3229. }
  3230. var complete = mxUtils.bind(this, function()
  3231. {
  3232. this.spinner.stop();
  3233. });
  3234. var fn = mxUtils.bind(this, function()
  3235. {
  3236. complete();
  3237. var currentFile = this.getCurrentFile();
  3238. if (replace == null && currentFile != null)
  3239. {
  3240. replace = !currentFile.isModified() && currentFile.getMode() == null;
  3241. }
  3242. var fn3 = mxUtils.bind(this, function()
  3243. {
  3244. window.openFile = null;
  3245. this.fileLoaded(file);
  3246. if (replace)
  3247. {
  3248. file.addAllSavedStatus();
  3249. }
  3250. if (libs != null)
  3251. {
  3252. this.sidebar.showEntries(libs);
  3253. }
  3254. });
  3255. var fn2 = mxUtils.bind(this, function()
  3256. {
  3257. if (replace || currentFile == null || !currentFile.isModified())
  3258. {
  3259. fn3();
  3260. }
  3261. else
  3262. {
  3263. this.confirm(mxResources.get('allChangesLost'), null, fn3,
  3264. mxResources.get('cancel'), mxResources.get('discardChanges'));
  3265. }
  3266. });
  3267. if (done != null)
  3268. {
  3269. done();
  3270. }
  3271. // Opens the file in a new window
  3272. if (replace != null && !replace)
  3273. {
  3274. // Opens local file in a new window
  3275. if (file.constructor == LocalFile)
  3276. {
  3277. window.openFile = new OpenFile(function()
  3278. {
  3279. window.openFile = null;
  3280. });
  3281. window.openFile.setData(file.getData(), file.getTitle(), file.getMode() == null);
  3282. }
  3283. if (done != null)
  3284. {
  3285. done();
  3286. }
  3287. window.openWindow(url, null, fn2);
  3288. }
  3289. else
  3290. {
  3291. fn2();
  3292. }
  3293. });
  3294. // Updates data in memory for local files
  3295. if (file.constructor == LocalFile)
  3296. {
  3297. fn();
  3298. }
  3299. else
  3300. {
  3301. file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
  3302. {
  3303. fn();
  3304. }), mxUtils.bind(this, function(resp)
  3305. {
  3306. complete();
  3307. this.handleError(resp);
  3308. }));
  3309. }
  3310. }
  3311. };
  3312. /**
  3313. * Translates this point by the given vector.
  3314. *
  3315. * @param {number} dx X-coordinate of the translation.
  3316. * @param {number} dy Y-coordinate of the translation.
  3317. */
  3318. App.prototype.loadFile = function(id, sameWindow, file, success, force)
  3319. {
  3320. this.hideDialog();
  3321. var fn2 = mxUtils.bind(this, function()
  3322. {
  3323. if (id == null || id.length == 0)
  3324. {
  3325. this.editor.setStatus('');
  3326. this.fileLoaded(null);
  3327. }
  3328. else if (this.spinner.spin(document.body, mxResources.get('loading')))
  3329. {
  3330. // Handles files from localStorage
  3331. if (id.charAt(0) == 'L')
  3332. {
  3333. this.spinner.stop();
  3334. if (!isLocalStorage)
  3335. {
  3336. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3337. {
  3338. var tempFile = this.getCurrentFile();
  3339. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3340. }));
  3341. }
  3342. else
  3343. {
  3344. try
  3345. {
  3346. id = decodeURIComponent(id.substring(1));
  3347. var data = localStorage.getItem(id);
  3348. if (data != null)
  3349. {
  3350. this.fileLoaded(new StorageFile(this, data, id));
  3351. if (success != null)
  3352. {
  3353. success();
  3354. }
  3355. }
  3356. else
  3357. {
  3358. throw {message: mxResources.get('fileNotFound')};
  3359. }
  3360. }
  3361. catch (e)
  3362. {
  3363. this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3364. {
  3365. var tempFile = this.getCurrentFile();
  3366. window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
  3367. }));
  3368. }
  3369. }
  3370. }
  3371. else if (file != null)
  3372. {
  3373. // File already loaded
  3374. this.spinner.stop();
  3375. this.fileLoaded(file);
  3376. if (success != null)
  3377. {
  3378. success();
  3379. }
  3380. }
  3381. else if (id.charAt(0) == 'S')
  3382. {
  3383. this.spinner.stop();
  3384. try
  3385. {
  3386. this.loadDescriptor(JSON.parse(Graph.decompress(id.substring(1))),
  3387. success, mxUtils.bind(this, function(e)
  3388. {
  3389. this.handleError(e, mxResources.get('errorLoadingFile'));
  3390. }));
  3391. }
  3392. catch (e)
  3393. {
  3394. this.handleError(e, mxResources.get('errorLoadingFile'));
  3395. }
  3396. }
  3397. else if (id.charAt(0) == 'R')
  3398. {
  3399. // Raw file encoded into URL
  3400. this.spinner.stop();
  3401. var data = decodeURIComponent(id.substring(1));
  3402. if (data.charAt(0) != '<')
  3403. {
  3404. data = Graph.decompress(data);
  3405. }
  3406. var tempFile = new LocalFile(this, data, (urlParams['title'] != null) ?
  3407. decodeURIComponent(urlParams['title']) : this.defaultFilename, true);
  3408. tempFile.getHash = function()
  3409. {
  3410. return id;
  3411. };
  3412. this.fileLoaded(tempFile);
  3413. if (success != null)
  3414. {
  3415. success();
  3416. }
  3417. }
  3418. else if (id.charAt(0) == 'U')
  3419. {
  3420. var url = decodeURIComponent(id.substring(1));
  3421. var doFallback = mxUtils.bind(this, function()
  3422. {
  3423. // Fallback for non-public Google Drive files
  3424. if (url.substring(0, 31) == 'https://drive.google.com/uc?id=' &&
  3425. (this.drive != null || typeof window.DriveClient === 'function'))
  3426. {
  3427. this.hideDialog();
  3428. var fallback = mxUtils.bind(this, function()
  3429. {
  3430. this.spinner.stop();
  3431. if (this.drive != null)
  3432. {
  3433. var tempId = url.substring(31, url.lastIndexOf('&ex'));
  3434. this.loadFile('G' + tempId, sameWindow, null, mxUtils.bind(this, function()
  3435. {
  3436. var currentFile = this.getCurrentFile();
  3437. if (currentFile != null && this.editor.chromeless && !this.editor.editable)
  3438. {
  3439. currentFile.getHash = function()
  3440. {
  3441. return 'G' + tempId;
  3442. };
  3443. window.location.hash = '#' + currentFile.getHash();
  3444. }
  3445. if (success != null)
  3446. {
  3447. success();
  3448. }
  3449. }));
  3450. return true;
  3451. }
  3452. else
  3453. {
  3454. return false;
  3455. }
  3456. });
  3457. if (!fallback() && this.spinner.spin(document.body, mxResources.get('loading')))
  3458. {
  3459. this.addListener('clientLoaded', fallback);
  3460. }
  3461. return true;
  3462. }
  3463. else
  3464. {
  3465. return false;
  3466. }
  3467. });
  3468. this.loadTemplate(url, mxUtils.bind(this, function(text)
  3469. {
  3470. this.spinner.stop();
  3471. if (text != null && text.length > 0)
  3472. {
  3473. var filename = this.defaultFilename;
  3474. // Tries to find name from URL with valid extensions
  3475. if (urlParams['title'] == null && urlParams['notitle'] != '1')
  3476. {
  3477. var tmp = url;
  3478. var dot = url.lastIndexOf('.');
  3479. var slash = tmp.lastIndexOf('/');
  3480. if (dot > slash && slash > 0)
  3481. {
  3482. tmp = tmp.substring(slash + 1, dot);
  3483. var ext = url.substring(dot);
  3484. if (!this.useCanvasForExport && ext == '.png')
  3485. {
  3486. ext = '.drawio';
  3487. }
  3488. if (ext === '.svg' || ext === '.xml' ||
  3489. ext === '.html' || ext === '.png' ||
  3490. ext === '.drawio')
  3491. {
  3492. filename = tmp + ext;
  3493. }
  3494. }
  3495. }
  3496. var tempFile = new LocalFile(this, text, (urlParams['title'] != null) ?
  3497. decodeURIComponent(urlParams['title']) : filename, true);
  3498. tempFile.getHash = function()
  3499. {
  3500. return id;
  3501. };
  3502. if (!this.fileLoaded(tempFile, true) && !doFallback())
  3503. {
  3504. this.handleError({message: mxResources.get('fileNotFound')},
  3505. mxResources.get('errorLoadingFile'));
  3506. }
  3507. }
  3508. else if (!doFallback())
  3509. {
  3510. this.handleError({message: mxResources.get('fileNotFound')},
  3511. mxResources.get('errorLoadingFile'));
  3512. }
  3513. }), mxUtils.bind(this, function()
  3514. {
  3515. if (!doFallback())
  3516. {
  3517. this.spinner.stop();
  3518. this.handleError({message: mxResources.get('fileNotFound')},
  3519. mxResources.get('errorLoadingFile'));
  3520. }
  3521. }), (urlParams['template-filename'] != null) ?
  3522. decodeURIComponent(urlParams['template-filename']) : null);
  3523. }
  3524. else
  3525. {
  3526. // Google Drive files are handled as default file types
  3527. var peer = null;
  3528. if (id.charAt(0) == 'G')
  3529. {
  3530. peer = this.drive;
  3531. }
  3532. else if (id.charAt(0) == 'D')
  3533. {
  3534. peer = this.dropbox;
  3535. }
  3536. else if (id.charAt(0) == 'W')
  3537. {
  3538. peer = this.oneDrive;
  3539. }
  3540. else if (id.charAt(0) == 'H')
  3541. {
  3542. peer = this.gitHub;
  3543. }
  3544. else if (id.charAt(0) == 'T')
  3545. {
  3546. peer = this.trello;
  3547. }
  3548. if (peer == null)
  3549. {
  3550. this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
  3551. {
  3552. var currentFile = this.getCurrentFile();
  3553. window.location.hash = (currentFile != null) ? currentFile.getHash() : '';
  3554. }));
  3555. }
  3556. else
  3557. {
  3558. var peerChar = id.charAt(0);
  3559. id = decodeURIComponent(id.substring(1));
  3560. peer.getFile(id, mxUtils.bind(this, function(file)
  3561. {
  3562. this.spinner.stop();
  3563. this.fileLoaded(file);
  3564. var currentFile = this.getCurrentFile();
  3565. // Keeps ID event for converted files in chromeless mode for refresh to work
  3566. if (currentFile == null)
  3567. {
  3568. window.location.hash = '';
  3569. this.showSplash();
  3570. }
  3571. else if (this.editor.chromeless && !this.editor.editable)
  3572. {
  3573. currentFile.getHash = function()
  3574. {
  3575. return peerChar + id;
  3576. };
  3577. window.location.hash = '#' + currentFile.getHash();
  3578. }
  3579. else
  3580. {
  3581. window.location.hash = currentFile.getHash();
  3582. }
  3583. if (success != null)
  3584. {
  3585. success();
  3586. }
  3587. }), mxUtils.bind(this, function(resp)
  3588. {
  3589. // Makes sure the file does not save the invalid UI model and overwrites anything important
  3590. if (window.console != null && resp != null)
  3591. {
  3592. console.log('error in loadFile:', id, resp);
  3593. }
  3594. this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
  3595. {
  3596. var currentFile = this.getCurrentFile();
  3597. if (currentFile == null)
  3598. {
  3599. window.location.hash = '';
  3600. this.showSplash();
  3601. }
  3602. else
  3603. {
  3604. window.location.hash = '#' + currentFile.getHash();
  3605. }
  3606. }));
  3607. }));
  3608. }
  3609. }
  3610. }
  3611. });
  3612. var currentFile = this.getCurrentFile();
  3613. var fn = mxUtils.bind(this, function()
  3614. {
  3615. if (force || currentFile == null || !currentFile.isModified())
  3616. {
  3617. fn2();
  3618. }
  3619. else
  3620. {
  3621. this.confirm(mxResources.get('allChangesLost'), mxUtils.bind(this, function()
  3622. {
  3623. if (currentFile != null)
  3624. {
  3625. window.location.hash = currentFile.getHash();
  3626. }
  3627. }), fn2, mxResources.get('cancel'), mxResources.get('discardChanges'));
  3628. }
  3629. });
  3630. if (id == null || id.length == 0)
  3631. {
  3632. fn();
  3633. }
  3634. else if (currentFile != null && currentFile.isModified() && !sameWindow)
  3635. {
  3636. window.openWindow(this.getUrl() + '#' + id, null, fn);
  3637. }
  3638. else
  3639. {
  3640. fn();
  3641. }
  3642. };
  3643. /**
  3644. * Translates this point by the given vector.
  3645. *
  3646. * @param {number} dx X-coordinate of the translation.
  3647. * @param {number} dy Y-coordinate of the translation.
  3648. */
  3649. App.prototype.getLibraryStorageHint = function(file)
  3650. {
  3651. var tip = file.getTitle();
  3652. if (file.constructor != LocalLibrary)
  3653. {
  3654. tip += '\n' + file.getHash();
  3655. }
  3656. if (file.constructor == DriveLibrary)
  3657. {
  3658. tip += ' (' + mxResources.get('googleDrive') + ')';
  3659. }
  3660. else if (file.constructor == GitHubLibrary)
  3661. {
  3662. tip += ' (' + mxResources.get('github') + ')';
  3663. }
  3664. else if (file.constructor == TrelloLibrary)
  3665. {
  3666. tip += ' (' + mxResources.get('trello') + ')';
  3667. }
  3668. else if (file.constructor == DropboxLibrary)
  3669. {
  3670. tip += ' (' + mxResources.get('dropbox') + ')';
  3671. }
  3672. else if (file.constructor == OneDriveLibrary)
  3673. {
  3674. tip += ' (' + mxResources.get('oneDrive') + ')';
  3675. }
  3676. else if (file.constructor == StorageLibrary)
  3677. {
  3678. tip += ' (' + mxResources.get('browser') + ')';
  3679. }
  3680. else if (file.constructor == LocalLibrary)
  3681. {
  3682. tip += ' (' + mxResources.get('device') + ')';
  3683. }
  3684. return tip;
  3685. };
  3686. /**
  3687. * Updates action states depending on the selection.
  3688. */
  3689. App.prototype.restoreLibraries = function()
  3690. {
  3691. if (this.sidebar != null)
  3692. {
  3693. if (this.pendingLibraries == null)
  3694. {
  3695. this.pendingLibraries = new Object();
  3696. }
  3697. // Ignores this library next time
  3698. var ignore = mxUtils.bind(this, function(id, keep)
  3699. {
  3700. if (!keep)
  3701. {
  3702. mxSettings.removeCustomLibrary(id);
  3703. }
  3704. delete this.pendingLibraries[id];
  3705. });
  3706. var load = mxUtils.bind(this, function(libs, done)
  3707. {
  3708. var waiting = 0;
  3709. var files = [];
  3710. // Loads in order of libs array
  3711. var checkDone = mxUtils.bind(this, function()
  3712. {
  3713. if (waiting == 0)
  3714. {
  3715. if (libs != null)
  3716. {
  3717. for (var i = libs.length - 1; i >= 0; i--)
  3718. {
  3719. if (files[i] != null)
  3720. {
  3721. this.loadLibrary(files[i]);
  3722. }
  3723. }
  3724. }
  3725. if (done != null)
  3726. {
  3727. done();
  3728. }
  3729. }
  3730. });
  3731. if (libs != null)
  3732. {
  3733. for (var i = 0; i < libs.length; i++)
  3734. {
  3735. var name = encodeURIComponent(decodeURIComponent(libs[i]));
  3736. (mxUtils.bind(this, function(id, index)
  3737. {
  3738. if (id != null && id.length > 0 && this.pendingLibraries[id] == null &&
  3739. this.sidebar.palettes[id] == null)
  3740. {
  3741. // Waits for all libraries to load
  3742. waiting++;
  3743. var onload = mxUtils.bind(this, function(file)
  3744. {
  3745. delete this.pendingLibraries[id];
  3746. files[index] = file;
  3747. waiting--;
  3748. checkDone();
  3749. });
  3750. var onerror = mxUtils.bind(this, function(keep)
  3751. {
  3752. ignore(id, keep);
  3753. waiting--;
  3754. checkDone();
  3755. });
  3756. this.pendingLibraries[id] = true;
  3757. var service = id.substring(0, 1);
  3758. if (service == 'L')
  3759. {
  3760. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3761. {
  3762. // Make asynchronous for barrier to work
  3763. window.setTimeout(mxUtils.bind(this, function()
  3764. {
  3765. try
  3766. {
  3767. var name = decodeURIComponent(id.substring(1));
  3768. var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
  3769. {
  3770. if (name == '.scratchpad' && xml == null)
  3771. {
  3772. xml = this.emptyLibraryXml;
  3773. }
  3774. if (xml != null)
  3775. {
  3776. onload(new StorageLibrary(this, xml, name));
  3777. }
  3778. else
  3779. {
  3780. onerror();
  3781. }
  3782. }));
  3783. }
  3784. catch (e)
  3785. {
  3786. onerror();
  3787. }
  3788. }), 0);
  3789. }
  3790. }
  3791. else if (service == 'U')
  3792. {
  3793. var url = decodeURIComponent(id.substring(1));
  3794. if (!this.isOffline())
  3795. {
  3796. var realUrl = url;
  3797. if (!this.editor.isCorsEnabledForUrl(realUrl))
  3798. {
  3799. var nocache = 't=' + new Date().getTime();
  3800. realUrl = PROXY_URL + '?url=' + encodeURIComponent(url) + '&' + nocache;
  3801. }
  3802. try
  3803. {
  3804. // Uses proxy to avoid CORS issues
  3805. mxUtils.get(realUrl, mxUtils.bind(this, function(req)
  3806. {
  3807. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3808. {
  3809. try
  3810. {
  3811. onload(new UrlLibrary(this, req.getText(), url));
  3812. }
  3813. catch (e)
  3814. {
  3815. onerror();
  3816. }
  3817. }
  3818. else
  3819. {
  3820. onerror();
  3821. }
  3822. }), function()
  3823. {
  3824. onerror();
  3825. });
  3826. }
  3827. catch (e)
  3828. {
  3829. onerror();
  3830. }
  3831. }
  3832. }
  3833. else if (service == 'R')
  3834. {
  3835. var libDesc = decodeURIComponent(id.substring(1));
  3836. if (!this.isOffline())
  3837. {
  3838. try
  3839. {
  3840. libDesc = JSON.parse(libDesc);
  3841. var libObj = {
  3842. id: libDesc[0],
  3843. title: libDesc[1],
  3844. downloadUrl: libDesc[2]
  3845. }
  3846. this.remoteInvoke('getFileContent', [libObj.downloadUrl], null, mxUtils.bind(this, function(libContent)
  3847. {
  3848. try
  3849. {
  3850. onload(new RemoteLibrary(this, libContent, libObj));
  3851. }
  3852. catch (e)
  3853. {
  3854. onerror();
  3855. }
  3856. }), function()
  3857. {
  3858. onerror();
  3859. });
  3860. }
  3861. catch (e)
  3862. {
  3863. onerror();
  3864. }
  3865. }
  3866. }
  3867. else
  3868. {
  3869. var peer = null;
  3870. if (service == 'G')
  3871. {
  3872. if (this.drive != null && this.drive.user != null)
  3873. {
  3874. peer = this.drive;
  3875. }
  3876. }
  3877. else if (service == 'H')
  3878. {
  3879. if (this.gitHub != null && this.gitHub.getUser() != null)
  3880. {
  3881. peer = this.gitHub;
  3882. }
  3883. }
  3884. else if (service == 'T')
  3885. {
  3886. if (this.trello != null && this.trello.isAuthorized())
  3887. {
  3888. peer = this.trello;
  3889. }
  3890. }
  3891. else if (service == 'D')
  3892. {
  3893. if (this.dropbox != null && this.dropbox.getUser() != null)
  3894. {
  3895. peer = this.dropbox;
  3896. }
  3897. }
  3898. else if (service == 'W')
  3899. {
  3900. if (this.oneDrive != null && this.oneDrive.getUser() != null)
  3901. {
  3902. peer = this.oneDrive;
  3903. }
  3904. }
  3905. if (peer != null)
  3906. {
  3907. peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
  3908. {
  3909. try
  3910. {
  3911. onload(file);
  3912. }
  3913. catch (e)
  3914. {
  3915. onerror();
  3916. }
  3917. }), function(resp)
  3918. {
  3919. onerror();
  3920. });
  3921. }
  3922. else
  3923. {
  3924. onerror(true);
  3925. }
  3926. }
  3927. }
  3928. }))(name, i);
  3929. }
  3930. checkDone();
  3931. }
  3932. else
  3933. {
  3934. checkDone();
  3935. }
  3936. });
  3937. load(mxSettings.getCustomLibraries(), function()
  3938. {
  3939. load((urlParams['clibs'] || '').split(';'));
  3940. });
  3941. }
  3942. };
  3943. /**
  3944. * Translates this point by the given vector.
  3945. *
  3946. * @param {number} dx X-coordinate of the translation.
  3947. * @param {number} dy Y-coordinate of the translation.
  3948. */
  3949. App.prototype.updateButtonContainer = function()
  3950. {
  3951. if (this.buttonContainer != null)
  3952. {
  3953. var file = this.getCurrentFile();
  3954. // Comments
  3955. if (this.commentsSupported())
  3956. {
  3957. if (this.commentButton == null)
  3958. {
  3959. this.commentButton = document.createElement('a');
  3960. this.commentButton.setAttribute('title', mxResources.get('comments'));
  3961. this.commentButton.className = 'geToolbarButton';
  3962. this.commentButton.style.cssText = 'display:inline-block;position:relative;box-sizing:border-box;' +
  3963. 'margin-right:4px;float:left;cursor:pointer;width:24px;height:24px;background-size:24px 24px;' +
  3964. 'background-position:center center;background-repeat:no-repeat;background-image:' +
  3965. 'url(' + Editor.commentImage + ');';
  3966. if (uiTheme == 'atlas')
  3967. {
  3968. this.commentButton.style.marginRight = '10px';
  3969. this.commentButton.style.marginTop = '-3px';
  3970. }
  3971. mxEvent.addListener(this.commentButton, 'click', mxUtils.bind(this, function()
  3972. {
  3973. this.actions.get('comments').funct();
  3974. }));
  3975. this.buttonContainer.appendChild(this.commentButton);
  3976. if (uiTheme == 'dark' || uiTheme == 'atlas')
  3977. {
  3978. this.commentButton.style.filter = 'invert(100%)';
  3979. }
  3980. }
  3981. }
  3982. else if (this.commentButton != null)
  3983. {
  3984. this.commentButton.parentNode.removeChild(this.commentButton);
  3985. this.commentButton = null;
  3986. }
  3987. // Share
  3988. if (file != null && file.constructor == DriveFile)
  3989. {
  3990. if (this.shareButton == null)
  3991. {
  3992. this.shareButton = document.createElement('div');
  3993. this.shareButton.className = 'geBtn gePrimaryBtn';
  3994. this.shareButton.style.display = 'inline-block';
  3995. this.shareButton.style.padding = '0 10px 0 10px';
  3996. this.shareButton.style.marginTop = '-4px';
  3997. this.shareButton.style.height = '28px';
  3998. this.shareButton.style.lineHeight = '28px';
  3999. this.shareButton.style.minWidth = '0px';
  4000. this.shareButton.style.cssFloat = 'right';
  4001. this.shareButton.setAttribute('title', mxResources.get('share'));
  4002. var icon = document.createElement('img');
  4003. icon.setAttribute('src', this.shareImage);
  4004. icon.setAttribute('align', 'absmiddle');
  4005. icon.style.marginRight = '4px';
  4006. icon.style.marginTop = '-3px';
  4007. this.shareButton.appendChild(icon);
  4008. mxUtils.write(this.shareButton, mxResources.get('share'));
  4009. mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
  4010. {
  4011. this.actions.get('share').funct();
  4012. }));
  4013. this.buttonContainer.appendChild(this.shareButton);
  4014. }
  4015. }
  4016. else if (this.shareButton != null)
  4017. {
  4018. this.shareButton.parentNode.removeChild(this.shareButton);
  4019. this.shareButton = null;
  4020. }
  4021. }
  4022. };
  4023. /**
  4024. * Translates this point by the given vector.
  4025. *
  4026. * @param {number} dx X-coordinate of the translation.
  4027. * @param {number} dy Y-coordinate of the translation.
  4028. */
  4029. App.prototype.save = function(name, done)
  4030. {
  4031. var file = this.getCurrentFile();
  4032. var msg = mxResources.get('saving');
  4033. if (file != null && this.spinner.spin(document.body, msg))
  4034. {
  4035. this.editor.setStatus('');
  4036. if (this.editor.graph.isEditing())
  4037. {
  4038. this.editor.graph.stopEditing();
  4039. }
  4040. var success = mxUtils.bind(this, function()
  4041. {
  4042. file.handleFileSuccess(true);
  4043. if (done != null)
  4044. {
  4045. done();
  4046. }
  4047. });
  4048. var error = mxUtils.bind(this, function(err)
  4049. {
  4050. file.handleFileError(err, true);
  4051. });
  4052. try
  4053. {
  4054. if (name == file.getTitle())
  4055. {
  4056. file.save(true, success, error);
  4057. }
  4058. else
  4059. {
  4060. file.saveAs(name, success, error)
  4061. }
  4062. }
  4063. catch (err)
  4064. {
  4065. file.handleFileError(err, true);
  4066. }
  4067. }
  4068. };
  4069. /**
  4070. * Invokes callback with null if mode does not support folder or not null
  4071. * if a valid folder was chosen for a mode that supports it. No callback
  4072. * is made if no folder was chosen for a mode that supports it.
  4073. */
  4074. App.prototype.pickFolder = function(mode, fn, enabled, direct, force)
  4075. {
  4076. enabled = (enabled != null) ? enabled : true;
  4077. var resume = this.spinner.pause();
  4078. if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
  4079. {
  4080. // Shows a save dialog
  4081. this.drive.pickFolder(mxUtils.bind(this, function(evt)
  4082. {
  4083. resume();
  4084. if (evt.action == google.picker.Action.PICKED)
  4085. {
  4086. var folderId = null;
  4087. if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
  4088. {
  4089. folderId = evt.docs[0].id;
  4090. }
  4091. fn(folderId);
  4092. }
  4093. }), force);
  4094. }
  4095. else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
  4096. {
  4097. this.oneDrive.pickFolder(mxUtils.bind(this, function(files)
  4098. {
  4099. var folderId = null;
  4100. resume();
  4101. if (files != null && files.value != null && files.value.length > 0)
  4102. {
  4103. folderId = OneDriveFile.prototype.getIdOf(files.value[0]);
  4104. fn(folderId);
  4105. }
  4106. }), direct);
  4107. }
  4108. else if (enabled && mode == App.MODE_GITHUB && this.gitHub != null)
  4109. {
  4110. this.gitHub.pickFolder(mxUtils.bind(this, function(folderPath)
  4111. {
  4112. resume();
  4113. fn(folderPath);
  4114. }));
  4115. }
  4116. else if (enabled && mode == App.MODE_TRELLO && this.trello != null)
  4117. {
  4118. this.trello.pickFolder(mxUtils.bind(this, function(cardId)
  4119. {
  4120. resume();
  4121. fn(cardId);
  4122. }));
  4123. }
  4124. else
  4125. {
  4126. EditorUi.prototype.pickFolder.apply(this, arguments);
  4127. }
  4128. };
  4129. /**
  4130. *
  4131. */
  4132. App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
  4133. {
  4134. if (mode == App.MODE_DROPBOX)
  4135. {
  4136. if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4137. {
  4138. // LATER: Add folder picker
  4139. this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4140. data, mxUtils.bind(this, function()
  4141. {
  4142. this.spinner.stop();
  4143. }), mxUtils.bind(this, function(resp)
  4144. {
  4145. this.spinner.stop();
  4146. this.handleError(resp);
  4147. }));
  4148. }
  4149. }
  4150. else if (mode == App.MODE_GOOGLE)
  4151. {
  4152. if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4153. {
  4154. this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
  4155. {
  4156. // TODO: Add callback with url param for clickable status message
  4157. // "File exported. Click here to open folder."
  4158. // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
  4159. // mxResources.get('saved') + '</div>');
  4160. //
  4161. // // Installs click handler for opening
  4162. // if (this.statusContainer != null)
  4163. // {
  4164. // var links = this.statusContainer.getElementsByTagName('div');
  4165. //
  4166. // if (links.length > 0)
  4167. // {
  4168. // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
  4169. // {
  4170. // if (resp != null && resp.id != null)
  4171. // {
  4172. // window.open('https://drive.google.com/open?id=' + resp.id);
  4173. // }
  4174. // }));
  4175. // }
  4176. // }
  4177. this.spinner.stop();
  4178. }), mxUtils.bind(this, function(resp)
  4179. {
  4180. this.spinner.stop();
  4181. this.handleError(resp);
  4182. }), mimeType, base64Encoded);
  4183. }
  4184. }
  4185. else if (mode == App.MODE_ONEDRIVE)
  4186. {
  4187. if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4188. {
  4189. // KNOWN: OneDrive does not show .svg extension
  4190. this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4191. data, mxUtils.bind(this, function()
  4192. {
  4193. this.spinner.stop();
  4194. }), mxUtils.bind(this, function(resp)
  4195. {
  4196. this.spinner.stop();
  4197. this.handleError(resp);
  4198. }), false, folderId);
  4199. }
  4200. }
  4201. else if (mode == App.MODE_GITHUB)
  4202. {
  4203. if (this.gitHub != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4204. {
  4205. // Must insert file as library to force the file to be written
  4206. this.gitHub.insertFile(filename, data, mxUtils.bind(this, function()
  4207. {
  4208. this.spinner.stop();
  4209. }), mxUtils.bind(this, function(resp)
  4210. {
  4211. this.spinner.stop();
  4212. this.handleError(resp);
  4213. }), true, folderId, base64Encoded);
  4214. }
  4215. }
  4216. else if (mode == App.MODE_TRELLO)
  4217. {
  4218. if (this.trello != null && this.spinner.spin(document.body, mxResources.get('saving')))
  4219. {
  4220. this.trello.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
  4221. data, mxUtils.bind(this, function()
  4222. {
  4223. this.spinner.stop();
  4224. }), mxUtils.bind(this, function(resp)
  4225. {
  4226. this.spinner.stop();
  4227. this.handleError(resp);
  4228. }), false, folderId);
  4229. }
  4230. }
  4231. else if (mode == App.MODE_BROWSER)
  4232. {
  4233. var fn = mxUtils.bind(this, function()
  4234. {
  4235. localStorage.setItem(filename, data);
  4236. });
  4237. if (localStorage.getItem(filename) == null)
  4238. {
  4239. fn();
  4240. }
  4241. else
  4242. {
  4243. this.confirm(mxResources.get('replaceIt', [filename]), fn);
  4244. }
  4245. }
  4246. };
  4247. /**
  4248. * Translates this point by the given vector.
  4249. *
  4250. * @param {number} dx X-coordinate of the translation.
  4251. * @param {number} dy Y-coordinate of the translation.
  4252. */
  4253. App.prototype.descriptorChanged = function()
  4254. {
  4255. var file = this.getCurrentFile();
  4256. if (file != null)
  4257. {
  4258. if (this.fname != null)
  4259. {
  4260. this.fnameWrapper.style.display = 'block';
  4261. this.fname.innerHTML = '';
  4262. var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  4263. mxUtils.write(this.fname, filename);
  4264. this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
  4265. }
  4266. var graph = this.editor.graph;
  4267. var editable = file.isEditable() && !file.invalidChecksum;
  4268. if (graph.isEnabled() && !editable)
  4269. {
  4270. graph.reset();
  4271. }
  4272. graph.setEnabled(editable);
  4273. // Ignores title and hash for revisions
  4274. if (urlParams['rev'] == null)
  4275. {
  4276. this.updateDocumentTitle();
  4277. var newHash = file.getHash();
  4278. if (newHash.length > 0)
  4279. {
  4280. window.location.hash = newHash;
  4281. }
  4282. else if (window.location.hash.length > 0)
  4283. {
  4284. window.location.hash = '';
  4285. }
  4286. }
  4287. }
  4288. this.updateUi();
  4289. if (this.format != null && this.editor.graph.isSelectionEmpty())
  4290. {
  4291. this.format.refresh();
  4292. }
  4293. };
  4294. /**
  4295. * Adds the listener for automatically saving the diagram for local changes.
  4296. */
  4297. App.prototype.showAuthDialog = function(peer, showRememberOption, fn, closeFn)
  4298. {
  4299. var resume = this.spinner.pause();
  4300. this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
  4301. {
  4302. try
  4303. {
  4304. if (fn != null)
  4305. {
  4306. fn(remember, mxUtils.bind(this, function()
  4307. {
  4308. this.hideDialog();
  4309. resume();
  4310. }));
  4311. }
  4312. }
  4313. catch (e)
  4314. {
  4315. this.editor.setStatus(mxUtils.htmlEntities(e.message));
  4316. }
  4317. })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
  4318. {
  4319. if (closeFn != null)
  4320. {
  4321. closeFn();
  4322. }
  4323. if (cancel && this.getCurrentFile() == null && this.dialog == null)
  4324. {
  4325. this.showSplash();
  4326. }
  4327. }));
  4328. };
  4329. /**
  4330. * Checks if the client is authorized and calls the next step. The optional
  4331. * readXml argument is used for import. Default is false. The optional
  4332. * readLibrary argument is used for reading libraries. Default is false.
  4333. */
  4334. App.prototype.convertFile = function(url, filename, mimeType, extension, success, error)
  4335. {
  4336. var name = filename;
  4337. // SVG file extensions are valid and needed for image import
  4338. if (!/\.svg$/i.test(name))
  4339. {
  4340. name = name.substring(0, filename.lastIndexOf('.')) + extension;
  4341. }
  4342. var gitHubUrl = false;
  4343. if (this.gitHub != null && url.substring(0, this.gitHub.baseUrl.length) == this.gitHub.baseUrl)
  4344. {
  4345. gitHubUrl = true;
  4346. }
  4347. // Workaround for wrong binary response with VSD(X) & VDX files
  4348. if (/\.v(dx|sdx?)$/i.test(filename) && Graph.fileSupport && new XMLHttpRequest().upload &&
  4349. typeof new XMLHttpRequest().responseType === 'string')
  4350. {
  4351. var req = new XMLHttpRequest();
  4352. req.open('GET', url, true);
  4353. if (!gitHubUrl)
  4354. {
  4355. req.responseType = 'blob';
  4356. }
  4357. req.onload = mxUtils.bind(this, function()
  4358. {
  4359. if (req.status >= 200 && req.status <= 299)
  4360. {
  4361. var blob = null;
  4362. if (gitHubUrl)
  4363. {
  4364. var file = JSON.parse(req.responseText);
  4365. blob = this.base64ToBlob(file.content, 'application/octet-stream');
  4366. }
  4367. else
  4368. {
  4369. blob = new Blob([req.response], {type: 'application/octet-stream'});
  4370. }
  4371. this.importVisio(blob, mxUtils.bind(this, function(xml)
  4372. {
  4373. success(new LocalFile(this, xml, name, true));
  4374. }), error, filename)
  4375. }
  4376. else if (error != null)
  4377. {
  4378. error({message: mxResources.get('errorLoadingFile')});
  4379. }
  4380. });
  4381. req.onerror = error;
  4382. req.send();
  4383. }
  4384. else
  4385. {
  4386. var handleData = mxUtils.bind(this, function(data)
  4387. {
  4388. try
  4389. {
  4390. if (/\.png$/i.test(filename))
  4391. {
  4392. temp = this.extractGraphModelFromPng(data);
  4393. if (temp != null)
  4394. {
  4395. success(new LocalFile(this, temp, name, true));
  4396. }
  4397. else
  4398. {
  4399. success(new LocalFile(this, data, filename, true));
  4400. }
  4401. }
  4402. else if (Graph.fileSupport && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
  4403. {
  4404. this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
  4405. {
  4406. if (xhr.readyState == 4)
  4407. {
  4408. if (xhr.status >= 200 && xhr.status <= 299)
  4409. {
  4410. success(new LocalFile(this, xhr.responseText, name, true));
  4411. }
  4412. else if (error != null)
  4413. {
  4414. error({message: mxResources.get('errorLoadingFile')});
  4415. }
  4416. }
  4417. }), filename);
  4418. }
  4419. else
  4420. {
  4421. success(new LocalFile(this, data, name, true));
  4422. }
  4423. }
  4424. catch (e)
  4425. {
  4426. if (error != null)
  4427. {
  4428. error(e);
  4429. }
  4430. }
  4431. });
  4432. var binary = /\.png$/i.test(filename) || /\.jpe?g$/i.test(filename) || (mimeType != null &&
  4433. mimeType.substring(0, 6) == 'image/');
  4434. // NOTE: Cannot force non-binary request via loadUrl so needs separate
  4435. // code as decoding twice on content with binary data did not work
  4436. if (gitHubUrl)
  4437. {
  4438. mxUtils.get(url, mxUtils.bind(this, function(req)
  4439. {
  4440. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  4441. {
  4442. if (success != null)
  4443. {
  4444. var file = JSON.parse(req.getText());
  4445. var data = file.content;
  4446. if (file.encoding === 'base64')
  4447. {
  4448. if (/\.png$/i.test(filename))
  4449. {
  4450. data = 'data:image/png;base64,' + data;
  4451. }
  4452. else
  4453. {
  4454. // Workaround for character encoding issues in IE10/11
  4455. data = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ? atob(data) : Base64.decode(data);
  4456. }
  4457. }
  4458. handleData(data);
  4459. }
  4460. }
  4461. else if (error != null)
  4462. {
  4463. error({code: App.ERROR_UNKNOWN});
  4464. }
  4465. }), function()
  4466. {
  4467. if (error != null)
  4468. {
  4469. error({code: App.ERROR_UNKNOWN});
  4470. }
  4471. }, false, this.timeout, function()
  4472. {
  4473. if (error != null)
  4474. {
  4475. error({code: App.ERROR_TIMEOUT, retry: fn});
  4476. }
  4477. });
  4478. }
  4479. else
  4480. {
  4481. this.loadUrl(url, handleData, error, binary);
  4482. }
  4483. }
  4484. };
  4485. /**
  4486. * Adds the listener for automatically saving the diagram for local changes.
  4487. */
  4488. App.prototype.updateHeader = function()
  4489. {
  4490. if (this.menubar != null)
  4491. {
  4492. this.appIcon = document.createElement('a');
  4493. this.appIcon.style.display = 'block';
  4494. this.appIcon.style.position = 'absolute';
  4495. this.appIcon.style.width = '40px';
  4496. this.appIcon.style.height = (this.menubarHeight - 16) + 'px';
  4497. this.appIcon.style.margin = '8px 0px 8px 8px';
  4498. this.appIcon.style.borderRadius = '4px';
  4499. if (uiTheme != 'dark')
  4500. {
  4501. this.appIcon.style.backgroundColor = '#f08705';
  4502. }
  4503. mxEvent.disableContextMenu(this.appIcon);
  4504. mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
  4505. {
  4506. this.appIconClicked(evt);
  4507. }));
  4508. // LATER: Use Alpha image loader in IE6
  4509. // NOTE: This uses the diagram bit of the old logo as it looks better in this case
  4510. //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
  4511. var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
  4512. 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
  4513. this.appIcon.style.backgroundImage = logo;
  4514. this.appIcon.style.backgroundPosition = 'center center';
  4515. this.appIcon.style.backgroundRepeat = 'no-repeat';
  4516. mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
  4517. mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
  4518. {
  4519. var file = this.getCurrentFile();
  4520. if (file != null)
  4521. {
  4522. var mode = file.getMode();
  4523. if (mode == App.MODE_GOOGLE)
  4524. {
  4525. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
  4526. }
  4527. else if (mode == App.MODE_DROPBOX)
  4528. {
  4529. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
  4530. }
  4531. else if (mode == App.MODE_ONEDRIVE)
  4532. {
  4533. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
  4534. }
  4535. else if (mode == App.MODE_GITHUB)
  4536. {
  4537. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/github-logo-white.svg)';
  4538. }
  4539. else if (mode == App.MODE_TRELLO)
  4540. {
  4541. this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/trello-logo-white-orange.svg)';
  4542. }
  4543. }
  4544. }));
  4545. mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
  4546. {
  4547. this.appIcon.style.backgroundImage = logo;
  4548. }));
  4549. if (urlParams['embed'] != '1')
  4550. {
  4551. this.menubarContainer.appendChild(this.appIcon);
  4552. }
  4553. this.fnameWrapper = document.createElement('div');
  4554. this.fnameWrapper.style.position = 'absolute';
  4555. this.fnameWrapper.style.right = '120px';
  4556. this.fnameWrapper.style.left = '50px';
  4557. this.fnameWrapper.style.top = '6px';
  4558. this.fnameWrapper.style.height = '26px';
  4559. this.fnameWrapper.style.display = 'none';
  4560. this.fnameWrapper.style.overflow = 'hidden';
  4561. this.fnameWrapper.style.textOverflow = 'ellipsis';
  4562. this.fname = document.createElement('a');
  4563. this.fname.setAttribute('title', mxResources.get('rename'));
  4564. this.fname.className = 'geItem';
  4565. this.fname.style.padding = '2px 8px 2px 8px';
  4566. this.fname.style.display = 'inline';
  4567. this.fname.style.fontSize = '18px';
  4568. this.fname.style.whiteSpace = 'nowrap';
  4569. // Prevents focus
  4570. mxEvent.addListener(this.fname, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4571. mxUtils.bind(this, function(evt)
  4572. {
  4573. evt.preventDefault();
  4574. }));
  4575. mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
  4576. {
  4577. var file = this.getCurrentFile();
  4578. if (file != null && file.isRenamable())
  4579. {
  4580. if (this.editor.graph.isEditing())
  4581. {
  4582. this.editor.graph.stopEditing();
  4583. }
  4584. this.actions.get('rename').funct();
  4585. }
  4586. mxEvent.consume(evt);
  4587. }));
  4588. this.fnameWrapper.appendChild(this.fname);
  4589. if (urlParams['embed'] != '1')
  4590. {
  4591. this.menubarContainer.appendChild(this.fnameWrapper);
  4592. this.menubar.container.style.position = 'absolute';
  4593. this.menubar.container.style.paddingLeft = '52px';
  4594. this.menubar.container.style.boxSizing = 'border-box';
  4595. this.menubar.container.style.top = '29px';
  4596. }
  4597. /**
  4598. * Adds format panel toggle.
  4599. */
  4600. this.toggleFormatElement = document.createElement('a');
  4601. this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (' + Editor.ctrlKey + '+Shift+P)');
  4602. this.toggleFormatElement.style.position = 'absolute';
  4603. this.toggleFormatElement.style.display = 'inline-block';
  4604. this.toggleFormatElement.style.top = '8px';
  4605. this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '30px' : '10px';
  4606. this.toggleFormatElement.style.padding = '2px';
  4607. this.toggleFormatElement.style.fontSize = '14px';
  4608. this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4609. this.toggleFormatElement.style.width = '16px';
  4610. this.toggleFormatElement.style.height = '16px';
  4611. this.toggleFormatElement.style.backgroundPosition = '50% 50%';
  4612. this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
  4613. this.toolbarContainer.appendChild(this.toggleFormatElement);
  4614. if (uiTheme == 'dark')
  4615. {
  4616. this.toggleFormatElement.style.filter = 'invert(100%)';
  4617. }
  4618. // Prevents focus
  4619. mxEvent.addListener(this.toggleFormatElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4620. mxUtils.bind(this, function(evt)
  4621. {
  4622. evt.preventDefault();
  4623. }));
  4624. mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
  4625. {
  4626. this.actions.get('formatPanel').funct();
  4627. mxEvent.consume(evt);
  4628. }));
  4629. var toggleFormatPanel = mxUtils.bind(this, function()
  4630. {
  4631. if (this.formatWidth > 0)
  4632. {
  4633. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
  4634. }
  4635. else
  4636. {
  4637. this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
  4638. }
  4639. });
  4640. this.addListener('formatWidthChanged', toggleFormatPanel);
  4641. toggleFormatPanel();
  4642. this.fullscreenElement = document.createElement('a');
  4643. this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
  4644. this.fullscreenElement.style.position = 'absolute';
  4645. this.fullscreenElement.style.display = 'inline-block';
  4646. this.fullscreenElement.style.top = '8px';
  4647. this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '50px' : '30px';
  4648. this.fullscreenElement.style.padding = '2px';
  4649. this.fullscreenElement.style.fontSize = '14px';
  4650. this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
  4651. this.fullscreenElement.style.width = '16px';
  4652. this.fullscreenElement.style.height = '16px';
  4653. this.fullscreenElement.style.backgroundPosition = '50% 50%';
  4654. this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
  4655. this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
  4656. this.toolbarContainer.appendChild(this.fullscreenElement);
  4657. // Prevents focus
  4658. mxEvent.addListener(this.fullscreenElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4659. mxUtils.bind(this, function(evt)
  4660. {
  4661. evt.preventDefault();
  4662. }));
  4663. // Some style changes in Atlas theme
  4664. if (uiTheme == 'atlas')
  4665. {
  4666. mxUtils.setOpacity(this.toggleFormatElement, 70);
  4667. mxUtils.setOpacity(this.fullscreenElement, 70);
  4668. }
  4669. var initialPosition = this.hsplitPosition;
  4670. var collapsed = false;
  4671. if (uiTheme == 'dark')
  4672. {
  4673. this.fullscreenElement.style.filter = 'invert(100%)';
  4674. }
  4675. mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
  4676. {
  4677. if (uiTheme != 'atlas' && urlParams['embed'] != '1')
  4678. {
  4679. this.toggleCompactMode(!collapsed);
  4680. }
  4681. this.toggleFormatPanel(!collapsed);
  4682. this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
  4683. this.hideFooter();
  4684. collapsed = !collapsed;
  4685. mxEvent.consume(evt);
  4686. }));
  4687. /**
  4688. * Adds compact UI toggle.
  4689. */
  4690. if (urlParams['embed'] != '1')
  4691. {
  4692. this.toggleElement = document.createElement('a');
  4693. this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
  4694. this.toggleElement.className = 'geButton';
  4695. this.toggleElement.style.position = 'absolute';
  4696. this.toggleElement.style.display = 'inline-block';
  4697. this.toggleElement.style.width = '16px';
  4698. this.toggleElement.style.height = '16px';
  4699. this.toggleElement.style.color = '#666';
  4700. this.toggleElement.style.top = '8px';
  4701. this.toggleElement.style.right = '10px';
  4702. this.toggleElement.style.padding = '2px';
  4703. this.toggleElement.style.fontSize = '14px';
  4704. this.toggleElement.style.textDecoration = 'none';
  4705. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4706. this.toggleElement.style.backgroundPosition = '50% 50%';
  4707. this.toggleElement.style.backgroundRepeat = 'no-repeat';
  4708. if (uiTheme == 'dark')
  4709. {
  4710. this.toggleElement.style.filter = 'invert(100%)';
  4711. }
  4712. // Prevents focus
  4713. mxEvent.addListener(this.toggleElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4714. mxUtils.bind(this, function(evt)
  4715. {
  4716. evt.preventDefault();
  4717. }));
  4718. // Toggles compact mode
  4719. mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
  4720. {
  4721. this.toggleCompactMode();
  4722. mxEvent.consume(evt);
  4723. }));
  4724. if (uiTheme != 'atlas')
  4725. {
  4726. this.toolbarContainer.appendChild(this.toggleElement);
  4727. }
  4728. // Enable compact mode for small screens
  4729. if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
  4730. {
  4731. window.setTimeout(mxUtils.bind(this, function()
  4732. {
  4733. this.toggleElement.click();
  4734. }), 0);
  4735. }
  4736. }
  4737. }
  4738. };
  4739. /**
  4740. * Adds the listener for automatically saving the diagram for local changes.
  4741. */
  4742. App.prototype.toggleCompactMode = function(forceHide)
  4743. {
  4744. if (!forceHide && this.appIcon.style.display == 'none')
  4745. {
  4746. this.menubar.container.style.position = 'absolute';
  4747. this.menubar.container.style.paddingLeft = '52px';
  4748. this.menubar.container.style.paddingTop = '';
  4749. this.menubar.container.style.paddingBottom = '';
  4750. this.menubar.container.style.top = '29px';
  4751. this.buttonContainer.style.visibility = 'visible';
  4752. this.appIcon.style.display = 'block';
  4753. this.fnameWrapper.style.display = 'block';
  4754. this.fnameWrapper.style.visibility = 'visible';
  4755. this.menubarHeight = App.prototype.menubarHeight;
  4756. this.refresh();
  4757. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
  4758. }
  4759. else
  4760. {
  4761. this.menubar.container.style.position = 'relative';
  4762. this.menubar.container.style.paddingLeft = '4px';
  4763. this.menubar.container.style.paddingTop = '0px';
  4764. this.menubar.container.style.paddingBottom = '0px';
  4765. this.menubar.container.style.top = '0px';
  4766. this.buttonContainer.style.visibility = 'hidden';
  4767. this.appIcon.style.display = 'none';
  4768. this.fnameWrapper.style.display = 'none';
  4769. this.fnameWrapper.style.visibility = 'hidden';
  4770. this.menubarHeight = EditorUi.prototype.menubarHeight;
  4771. this.refresh();
  4772. this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
  4773. }
  4774. };
  4775. /**
  4776. * Adds the listener for automatically saving the diagram for local changes.
  4777. */
  4778. App.prototype.updateUserElement = function()
  4779. {
  4780. if ((this.drive == null || this.drive.getUser() == null) &&
  4781. (this.oneDrive == null || this.oneDrive.getUser() == null) &&
  4782. (this.dropbox == null || this.dropbox.getUser() == null) &&
  4783. (this.gitHub == null || this.gitHub.getUser() == null) &&
  4784. (this.trello == null || !this.trello.isAuthorized())) //TODO Trello no user issue
  4785. {
  4786. if (this.userElement != null)
  4787. {
  4788. this.userElement.parentNode.removeChild(this.userElement);
  4789. this.userElement = null;
  4790. }
  4791. }
  4792. else
  4793. {
  4794. if (this.userElement == null)
  4795. {
  4796. this.userElement = document.createElement('a');
  4797. this.userElement.className = 'geItem';
  4798. this.userElement.style.position = 'absolute';
  4799. this.userElement.style.fontSize = '8pt';
  4800. this.userElement.style.top = (uiTheme == 'atlas') ? '8px' : '2px';
  4801. this.userElement.style.right = '30px';
  4802. this.userElement.style.margin = '4px';
  4803. this.userElement.style.padding = '2px';
  4804. this.userElement.style.paddingRight = '16px';
  4805. this.userElement.style.verticalAlign = 'middle';
  4806. this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  4807. this.userElement.style.backgroundPosition = '100% 60%';
  4808. this.userElement.style.backgroundRepeat = 'no-repeat';
  4809. this.menubarContainer.appendChild(this.userElement);
  4810. // Prevents focus
  4811. mxEvent.addListener(this.userElement, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  4812. mxUtils.bind(this, function(evt)
  4813. {
  4814. evt.preventDefault();
  4815. }));
  4816. mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
  4817. {
  4818. if (this.userPanel == null)
  4819. {
  4820. var div = document.createElement('div');
  4821. div.className = 'geDialog';
  4822. div.style.position = 'absolute';
  4823. div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
  4824. div.style.right = '36px';
  4825. div.style.padding = '0px';
  4826. div.style.cursor = 'default';
  4827. this.userPanel = div;
  4828. }
  4829. if (this.userPanel.parentNode != null)
  4830. {
  4831. this.userPanel.parentNode.removeChild(this.userPanel);
  4832. }
  4833. else
  4834. {
  4835. var connected = false;
  4836. this.userPanel.innerHTML = '';
  4837. var img = document.createElement('img');
  4838. img.setAttribute('src', Dialog.prototype.closeImage);
  4839. img.setAttribute('title', mxResources.get('close'));
  4840. img.className = 'geDialogClose';
  4841. img.style.top = '8px';
  4842. img.style.right = '8px';
  4843. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  4844. {
  4845. if (this.userPanel.parentNode != null)
  4846. {
  4847. this.userPanel.parentNode.removeChild(this.userPanel);
  4848. }
  4849. }));
  4850. this.userPanel.appendChild(img);
  4851. if (this.drive != null)
  4852. {
  4853. var driveUser = this.drive.getUser();
  4854. if (driveUser != null)
  4855. {
  4856. connected = true;
  4857. this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
  4858. '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
  4859. '<tr><td valign="top">' +
  4860. ((driveUser.pictureUrl != null) ?
  4861. '<img width="80" height="80" style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
  4862. '<img width="80" height="80" style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
  4863. '</td><td valign="top" style="white-space:nowrap;' +
  4864. ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
  4865. '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
  4866. '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small><br><br>' +
  4867. '<small>' + mxResources.get('googleDrive') + '</small></tr></table>';
  4868. var div = document.createElement('div');
  4869. div.style.textAlign = 'center';
  4870. div.style.paddingBottom = '12px';
  4871. div.style.whiteSpace = 'nowrap';
  4872. // LATER: Cannot change user while file is open since close will not work with new
  4873. // credentials and closing the file using fileLoaded(null) will show splash dialog.
  4874. div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
  4875. {
  4876. var file = this.getCurrentFile();
  4877. if (file != null && file.constructor == DriveFile)
  4878. {
  4879. this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
  4880. {
  4881. this.spinner.spin(document.body, mxResources.get('signOut'));
  4882. this.diagramContainer.style.display = 'none';
  4883. this.formatContainer.style.display = 'none';
  4884. this.hsplit.style.display = 'none';
  4885. this.sidebarContainer.style.display = 'none';
  4886. this.sidebarFooterContainer.style.display = 'none';
  4887. if (this.tabContainer != null)
  4888. {
  4889. this.tabContainer.style.display = 'none';
  4890. }
  4891. file.close();
  4892. // LATER: Use callback to wait for thumbnail update
  4893. window.setTimeout(mxUtils.bind(this, function()
  4894. {
  4895. // Workaround to disable the splash screen before reload
  4896. this.showDialog = function() {};
  4897. window.location.hash = '';
  4898. this.drive.clearUserId();
  4899. gapi.auth.signOut();
  4900. // Reload page to reset client auth
  4901. window.location.reload();
  4902. }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
  4903. }));
  4904. }
  4905. else
  4906. {
  4907. this.drive.clearUserId();
  4908. this.drive.setUser(null);
  4909. gapi.auth.signOut();
  4910. }
  4911. })));
  4912. this.userPanel.appendChild(div);
  4913. }
  4914. }
  4915. var addUser = mxUtils.bind(this, function(user, logo, logout, label)
  4916. {
  4917. if (user != null)
  4918. {
  4919. if (connected)
  4920. {
  4921. this.userPanel.appendChild(document.createElement('hr'));
  4922. }
  4923. connected = true;
  4924. this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
  4925. ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
  4926. '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
  4927. ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font>' : '') +
  4928. ((label != null) ? '<br><br><small>' + mxUtils.htmlEntities(label) + '</small>' : '') +
  4929. '</td></tr></table>';
  4930. var div = document.createElement('div');
  4931. div.style.textAlign = 'center';
  4932. div.style.paddingBottom = '12px';
  4933. div.style.whiteSpace = 'nowrap';
  4934. if (logout != null)
  4935. {
  4936. div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
  4937. }
  4938. this.userPanel.appendChild(div);
  4939. }
  4940. });
  4941. if (this.dropbox != null)
  4942. {
  4943. addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
  4944. {
  4945. var file = this.getCurrentFile();
  4946. if (file != null && file.constructor == DropboxFile)
  4947. {
  4948. var doLogout = mxUtils.bind(this, function()
  4949. {
  4950. this.dropbox.logout();
  4951. window.location.hash = '';
  4952. });
  4953. if (!file.isModified())
  4954. {
  4955. doLogout();
  4956. }
  4957. else
  4958. {
  4959. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4960. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4961. }
  4962. }
  4963. else
  4964. {
  4965. this.dropbox.logout();
  4966. }
  4967. }), mxResources.get('dropbox'));
  4968. }
  4969. if (this.oneDrive != null)
  4970. {
  4971. addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
  4972. {
  4973. var file = this.getCurrentFile();
  4974. if (file != null && file.constructor == OneDriveFile)
  4975. {
  4976. var doLogout = mxUtils.bind(this, function()
  4977. {
  4978. this.oneDrive.logout();
  4979. window.location.hash = '';
  4980. });
  4981. if (!file.isModified())
  4982. {
  4983. doLogout();
  4984. }
  4985. else
  4986. {
  4987. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  4988. mxResources.get('cancel'), mxResources.get('discardChanges'));
  4989. }
  4990. }
  4991. else
  4992. {
  4993. this.oneDrive.logout();
  4994. }
  4995. }), mxResources.get('oneDrive'));
  4996. }
  4997. if (this.gitHub != null)
  4998. {
  4999. addUser(this.gitHub.getUser(), IMAGE_PATH + '/github-logo.svg', mxUtils.bind(this, function()
  5000. {
  5001. var file = this.getCurrentFile();
  5002. if (file != null && file.constructor == GitHubFile)
  5003. {
  5004. var doLogout = mxUtils.bind(this, function()
  5005. {
  5006. this.gitHub.logout();
  5007. window.location.hash = '';
  5008. });
  5009. if (!file.isModified())
  5010. {
  5011. doLogout();
  5012. }
  5013. else
  5014. {
  5015. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  5016. mxResources.get('cancel'), mxResources.get('discardChanges'));
  5017. }
  5018. }
  5019. else
  5020. {
  5021. this.gitHub.logout();
  5022. }
  5023. }), mxResources.get('github'));
  5024. }
  5025. //TODO We have no user info from Trello, how we can create a user?
  5026. if (this.trello != null)
  5027. {
  5028. addUser(this.trello.getUser(), IMAGE_PATH + '/trello-logo.svg', mxUtils.bind(this, function()
  5029. {
  5030. var file = this.getCurrentFile();
  5031. if (file != null && file.constructor == TrelloFile)
  5032. {
  5033. var doLogout = mxUtils.bind(this, function()
  5034. {
  5035. this.trello.logout();
  5036. window.location.hash = '';
  5037. });
  5038. if (!file.isModified())
  5039. {
  5040. doLogout();
  5041. }
  5042. else
  5043. {
  5044. this.confirm(mxResources.get('allChangesLost'), null, doLogout,
  5045. mxResources.get('cancel'), mxResources.get('discardChanges'));
  5046. }
  5047. }
  5048. else
  5049. {
  5050. this.trello.logout();
  5051. }
  5052. }), mxResources.get('trello'));
  5053. }
  5054. if (!connected)
  5055. {
  5056. var div = document.createElement('div');
  5057. div.style.textAlign = 'center';
  5058. div.style.padding = '20px 20px 10px 10px';
  5059. div.innerHTML = mxResources.get('notConnected');
  5060. this.userPanel.appendChild(div);
  5061. }
  5062. var div = document.createElement('div');
  5063. div.style.textAlign = 'center';
  5064. div.style.padding = '12px';
  5065. div.style.background = 'whiteSmoke';
  5066. div.style.borderTop = '1px solid #e0e0e0';
  5067. div.style.whiteSpace = 'nowrap';
  5068. var btn = mxUtils.button(mxResources.get('close'), mxUtils.bind(this, function()
  5069. {
  5070. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5071. {
  5072. this.userPanel.parentNode.removeChild(this.userPanel);
  5073. }
  5074. }));
  5075. div.appendChild(btn);
  5076. this.userPanel.appendChild(div);
  5077. document.body.appendChild(this.userPanel);
  5078. }
  5079. mxEvent.consume(evt);
  5080. }));
  5081. mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
  5082. {
  5083. if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
  5084. {
  5085. this.userPanel.parentNode.removeChild(this.userPanel);
  5086. }
  5087. }));
  5088. }
  5089. var user = null;
  5090. if (this.drive != null && this.drive.getUser() != null)
  5091. {
  5092. user = this.drive.getUser();
  5093. }
  5094. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5095. {
  5096. user = this.oneDrive.getUser();
  5097. }
  5098. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5099. {
  5100. user = this.dropbox.getUser();
  5101. }
  5102. else if (this.gitHub != null && this.gitHub.getUser() != null)
  5103. {
  5104. user = this.gitHub.getUser();
  5105. }
  5106. //TODO Trello no user issue
  5107. if (user != null)
  5108. {
  5109. this.userElement.innerHTML = '';
  5110. if (screen.width > 560)
  5111. {
  5112. mxUtils.write(this.userElement, user.displayName);
  5113. this.userElement.style.display = 'block';
  5114. }
  5115. }
  5116. else
  5117. {
  5118. this.userElement.style.display = 'none';
  5119. }
  5120. }
  5121. };
  5122. //TODO Use this function to get the currently logged in user
  5123. App.prototype.getCurrentUser = function()
  5124. {
  5125. var user = null;
  5126. if (this.drive != null && this.drive.getUser() != null)
  5127. {
  5128. user = this.drive.getUser();
  5129. }
  5130. else if (this.oneDrive != null && this.oneDrive.getUser() != null)
  5131. {
  5132. user = this.oneDrive.getUser();
  5133. }
  5134. else if (this.dropbox != null && this.dropbox.getUser() != null)
  5135. {
  5136. user = this.dropbox.getUser();
  5137. }
  5138. else if (this.gitHub != null && this.gitHub.getUser() != null)
  5139. {
  5140. user = this.gitHub.getUser();
  5141. }
  5142. //TODO Trello no user issue
  5143. return user;
  5144. }
  5145. /**
  5146. * Override depends on mxSettings which is not defined in the minified viewer.
  5147. */
  5148. var editorResetGraph = Editor.prototype.resetGraph;
  5149. Editor.prototype.resetGraph = function()
  5150. {
  5151. editorResetGraph.apply(this, arguments);
  5152. // Overrides default with persisted value
  5153. this.graph.pageFormat = mxSettings.getPageFormat();
  5154. };