App.js 131 KB

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