App.js 140 KB

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