App.js 141 KB

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