12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024 |
- /**
- * Copyright (c) 2006-2017, JGraph Ltd
- * Copyright (c) 2006-2017, Gaudenz Alder
- */
- /**
- * Constructs a new point for the optional x and y coordinates. If no
- * coordinates are given, then the default values for <x> and <y> are used.
- * @constructor
- * @class Implements a basic 2D point. Known subclassers = {@link mxRectangle}.
- * @param {number} x X-coordinate of the point.
- * @param {number} y Y-coordinate of the point.
- */
- App = function(editor, container, lightbox)
- {
- EditorUi.call(this, editor, container, (lightbox != null) ? lightbox : urlParams['lightbox'] == '1');
- // Pre-fetches images
- if (mxClient.IS_SVG)
- {
- 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=';
- }
- else
- {
- var img = new Image();
- img.src = mxGraph.prototype.warningImage.src;
- }
-
- // Global helper method to deal with popup blockers
- window.openWindow = mxUtils.bind(this, function(url, pre, fallback)
- {
- var wnd = null;
-
- try
- {
- wnd = window.open(url);
- }
- catch (e)
- {
- // ignore
- }
-
- if (wnd == null || wnd === undefined)
- {
- this.showDialog(new PopupDialog(this, url, pre, fallback).container, 320, 140, true, true);
- }
- else if (pre != null)
- {
- pre();
- }
- });
-
- // Initial state for toolbar items is disabled
- this.updateDocumentTitle();
- this.updateUi();
-
- // Checks if canvas is supported
- var cnv = document.createElement('canvas');
- this.canvasSupported = !!(cnv.getContext && cnv.getContext('2d'));
-
- // Global helper method to display error messages
- window.showOpenAlert = mxUtils.bind(this, function(message)
- {
- // Cancel must be called before showing error message
- if (window.openFile != null)
- {
- window.openFile.cancel(true);
- }
-
- this.handleError(message);
- });
-
- // Sets help link for placeholders
- if (!this.isOffline())
- {
- EditDataDialog.placeholderHelpLink = 'https://desk.draw.io/support/solutions/articles/16000051979';
- }
- // Handles opening files via drag and drop
- this.addFileDropHandler([document]);
-
- // Process the queue for waiting plugins
- if (App.DrawPlugins != null)
- {
- for (var i = 0; i < App.DrawPlugins.length; i++)
- {
- try
- {
- App.DrawPlugins[i](this);
- }
- catch (e)
- {
- if (window.console != null)
- {
- console.log('Plugin Error:', e, App.DrawPlugins[i]);
- }
- }
- }
-
- // Installs global callback for plugins
- window.Draw.loadPlugin = mxUtils.bind(this, function(callback)
- {
- callback(this);
- });
- }
- this.load();
- };
- /**
- * Executes the first step for connecting to Google Drive.
- */
- App.ERROR_TIMEOUT = 'timeout';
- /**
- * Executes the first step for connecting to Google Drive.
- */
- App.ERROR_BUSY = 'busy';
- /**
- * Executes the first step for connecting to Google Drive.
- */
- App.ERROR_UNKNOWN = 'unknown';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_GOOGLE = 'google';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_DROPBOX = 'dropbox';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_ONEDRIVE = 'onedrive';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_GITHUB = 'github';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_DEVICE = 'device';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.MODE_BROWSER = 'browser';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.DROPBOX_APPKEY = 'libwls2fa9szdji';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.DROPBOX_URL = 'https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.DROPINS_URL = 'https://www.dropbox.com/static/api/2/dropins.js';
- /**
- * Sets the delay for autosave in milliseconds. Default is 2000.
- */
- App.ONEDRIVE_URL = 'https://js.live.net/v7.2/OneDrive.js';
- /**
- * Defines plugin IDs for loading via p URL parameter. Update the table at
- * https://desk.draw.io/solution/articles/16000042546
- */
- App.pluginRegistry = {'4xAKTrabTpTzahoLthkwPNUn': '/plugins/explore.js',
- 'ex': '/plugins/explore.js', 'p1': '/plugins/p1.js', 'ac': '/plugins/connect.js',
- 'acj': '/plugins/connectJira.js', 'voice': '/plugins/voice.js',
- 'tips': '/plugins/tooltips.js', 'svgdata': '/plugins/svgdata.js',
- 'doors': '/plugins/doors.js', 'electron': 'plugins/electron.js',
- 'number': '/plugins/number.js', 'sql': '/plugins/sql.js',
- 'props': '/plugins/props.js', 'text': '/plugins/text.js',
- 'anim': '/plugins/animation.js', 'update': '/plugins/update.js',
- 'trees': '/plugins/trees/trees.js', 'import': '/plugins/import.js',
- 'replay': '/plugins/replay.js', 'anon': '/plugins/anonymize.js'};
- /**
- * Function: authorize
- *
- * Authorizes the client, gets the userId and calls <open>.
- */
- App.getStoredMode = function()
- {
- var mode = null;
-
- if (mode == null && isLocalStorage)
- {
- mode = localStorage.getItem('.mode');
- }
-
- if (mode == null && typeof(Storage) != 'undefined')
- {
- var cookies = document.cookie.split(";");
-
- for (var i = 0; i < cookies.length; i++)
- {
- // Removes spaces around cookie
- var cookie = mxUtils.trim(cookies[i]);
-
- if (cookie.substring(0, 5) == 'MODE=')
- {
- mode = cookie.substring(5);
- break;
- }
- }
-
- if (mode != null && isLocalStorage)
- {
- // Moves to local storage
- var expiry = new Date();
- expiry.setYear(expiry.getFullYear() - 1);
- document.cookie = 'MODE=; expires=' + expiry.toUTCString();
- localStorage.setItem('.mode', mode);
- }
- }
-
- return mode;
- };
- /**
- * Static Application initializer executed at load-time.
- */
- (function()
- {
- if (!mxClient.IS_CHROMEAPP)
- {
- if (urlParams['offline'] != '1')
- {
- // Switches to dropbox mode for db.draw.io
- if (window.location.hostname == 'db.draw.io' && urlParams['mode'] == null)
- {
- urlParams['mode'] = 'dropbox';
- }
-
- App.mode = urlParams['mode'];
-
- if (App.mode == null)
- {
- // Stored mode overrides preferred mode
- App.mode = App.getStoredMode();
- }
- }
- /**
- * Lazy loading backends.
- */
- if (window.mxscript != null)
- {
- // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
- if (urlParams['embed'] != '1')
- {
- if (typeof window.DriveClient === 'function')
- {
- if (urlParams['gapi'] != '0' && isSvgBrowser &&
- (document.documentMode == null || document.documentMode >= 10))
- {
- // Immediately loads client
- if (App.mode == App.MODE_GOOGLE || (urlParams['state'] != null &&
- window.location.hash == '') || (window.location.hash != null &&
- window.location.hash.substring(0, 2) == '#G'))
- {
- mxscript('https://apis.google.com/js/api.js');
- }
- // Keeps lazy loading for fallback to authenticated Google file if not public in loadFile
- else if (urlParams['chrome'] == '0' && (window.location.hash == null ||
- window.location.hash.substring(0, 45) !== '#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D'))
- {
- // Disables loading of client
- window.DriveClient = null;
- }
- }
- else
- {
- // Disables loading of client
- window.DriveClient = null;
- }
- }
-
- // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
- // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
- if (typeof window.DropboxClient === 'function')
- {
- if (urlParams['db'] != '0' && isSvgBrowser &&
- (document.documentMode == null || document.documentMode > 9))
- {
- // Immediately loads client
- if (App.mode == App.MODE_DROPBOX || (window.location.hash != null &&
- window.location.hash.substring(0, 2) == '#D'))
- {
- mxscript(App.DROPBOX_URL);
-
- // Must load this after the dropbox SDK since they use the same namespace
- mxscript(App.DROPINS_URL, null, 'dropboxjs', App.DROPBOX_APPKEY);
- }
- else if (urlParams['chrome'] == '0')
- {
- window.DropboxClient = null;
- }
- }
- else
- {
- // Disables loading of client
- window.DropboxClient = null;
- }
- }
-
- // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
- if (typeof window.OneDriveClient === 'function')
- {
- if (urlParams['od'] != '0' && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))
- {
- // Immediately loads client
- if (App.mode == App.MODE_ONEDRIVE || (window.location.hash != null &&
- window.location.hash.substring(0, 2) == '#W'))
- {
- mxscript(App.ONEDRIVE_URL);
- }
- else if (urlParams['chrome'] == '0')
- {
- window.OneDriveClient = null;
- }
- }
- else
- {
- // Disables loading of client
- window.OneDriveClient = null;
- }
- }
- }
-
- // Loads JSON for older browsers
- if (typeof(JSON) == 'undefined')
- {
- mxscript('js/json/json2.min.js');
- }
- }
- }
- })();
- /**
- * Program flow starts here.
- *
- * Optional callback is called with the app instance.
- */
- App.main = function(callback)
- {
- var lastErrorMessage = null;
-
- // Changes top level error handling
- if (EditorUi.enableLogging)
- {
- window.onerror = function(message, url, linenumber, colno, err)
- {
- try
- {
- if (message == lastErrorMessage || (message != null && url != null &&
- ((message.indexOf('Script error') != -1) || (message.indexOf('extension') != -1))))
- {
- // TODO log external domain script failure "Script error." is
- // reported when the error occurs in a script that is hosted
- // on a domain other than the domain of the current page
- }
- // DocumentClosedError seems to be an FF bug an can be ignored for now
- else if (message != null && message.indexOf('DocumentClosedError') < 0)
- {
- lastErrorMessage = message;
- var img = new Image();
- var severity = (message.indexOf('NetworkError') >= 0 || message.indexOf('SecurityError') >= 0 ||
- message.indexOf('NS_ERROR_FAILURE') >= 0 || message.indexOf('out of memory') >= 0) ?
- 'CONFIG' : 'SEVERE';
- var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
- img.src = logDomain + '/log?severity=' + severity + '&v=' + encodeURIComponent(EditorUi.VERSION) +
- '&msg=clientError:' + encodeURIComponent(message) + ':url:' + encodeURIComponent(window.location.href) +
- ':lnum:' + encodeURIComponent(linenumber) +
- ((colno != null) ? ':colno:' + encodeURIComponent(colno) : '') +
- ((err != null && err.stack != null) ? '&stack=' + encodeURIComponent(err.stack) : '');
- }
- }
- catch (err)
- {
- // do nothing
- }
- };
- }
- /**
- * Lazy loading of additional CSS for atlas theme.
- */
- if (uiTheme == 'atlas')
- {
- mxClient.link('stylesheet', 'styles/atlas.css');
- }
-
- if (window.mxscript != null)
- {
- /**
- * Color dialog - Do not add to app.min.js due to path issues!
- */
- if (urlParams['chrome'] != '0')
- {
- mxscript('js/jscolor/jscolor.js');
- }
-
- /**
- * Injects offline dependencies
- */
- if (urlParams['offline'] == '1')
- {
- mxscript('js/shapes.min.js');
-
- var frame = document.createElement('iframe');
- frame.setAttribute('width', '0');
- frame.setAttribute('height', '0');
- frame.setAttribute('src', 'offline.html');
- document.body.appendChild(frame);
-
- // Precaching for stencils. Alternatively we could generate
- // a cache manifest with all stencil and shape files but this
- // simplifies the cache file, streamlines the shape loading
- // to a single loading point (here) vs dynamic loading in the
- // online version. It does slow down the startup time though.
- mxStencilRegistry.stencilSet = {};
-
- // Overrides dynamic loading (everything loaded at startup)
- mxStencilRegistry.getStencil = function(name)
- {
- return mxStencilRegistry.stencils[name];
- };
-
- // Takes stencil data from cache for populating sidebar
- mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force)
- {
- var name = stencilFile.substring(stencilFile.indexOf('/') + 1);
- name = 'mxgraph.' + name.substring(0, name.length - 4).replace(/\//g, '.');
- var node = mxStencilRegistry.stencilSet[name];
-
- if (node != null)
- {
- mxStencilRegistry.parseStencilSet(node, postStencilLoad, false);
- }
- };
-
- // Preload all stencils from merged XML file
- var req2 = mxUtils.load('stencils.xml');
- var root = req2.getXml().documentElement;
- var node = root.firstChild;
-
- while (node != null)
- {
- if (node.nodeName == 'shapes' && node.getAttribute('name') != null)
- {
- mxStencilRegistry.stencilSet[node.getAttribute('name').toLowerCase()] = node;
- mxStencilRegistry.parseStencilSet(node);
- }
-
- node = node.nextSibling;
- }
- }
-
- /**
- * Loads Google Image Picker API (not allowed inside iframes)
- */
- if (urlParams['picker'] != '0' && !mxClient.IS_QUIRKS && document.documentMode != 8)
- {
- 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');
- }
- /**
- * Loading plugins.
- */
- if (urlParams['plugins'] != '0' && urlParams['offline'] != '1')
- {
- var plugins = mxSettings.getPlugins();
- var temp = urlParams['p'];
-
- if ((temp != null) || (plugins != null && plugins.length > 0))
- {
- App.initPluginCallback();
- }
-
- if (temp != null)
- {
- // Used to request draw.io sources in dev mode
- var drawDevUrl = '';
- if (urlParams['drawdev'] == '1')
- {
- drawDevUrl = document.location.protocol + '//drawhost.jgraph.com/';
- }
-
- // Mapping from key to URL in App.plugins
- var t = temp.split(';');
-
- for (var i = 0; i < t.length; i++)
- {
- var url = App.pluginRegistry[t[i]];
-
- if (url != null)
- {
- mxscript(drawDevUrl + url);
- }
- else if (window.console != null)
- {
- console.log('Unknown plugin:', t[i]);
- }
- }
- }
-
- if (plugins != null && plugins.length > 0 && urlParams['plugins'] != '0')
- {
- // Loading plugins inside the asynchronous block below stops the page from loading so a
- // hardcoded message for the warning dialog is used since the resources are loadd below
- 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';
- var tmp = window.location.protocol + '//' + window.location.host;
- var local = true;
-
- for (var i = 0; i < plugins.length && local; i++)
- {
- if (plugins[i].charAt(0) != '/' && plugins[i].substring(0, tmp.length) != tmp)
- {
- local = false;
- }
- }
-
- if (local || mxUtils.confirm(mxResources.replacePlaceholders(warning, [plugins.join('\n')]).replace(/\\n/g, '\n')))
- {
- for (var i = 0; i < plugins.length; i++)
- {
- try
- {
- mxscript(plugins[i]);
- }
- catch (e)
- {
- // ignore
- }
- }
- }
- }
- }
-
- // Loads gapi for all browsers but IE8 and below if not disabled or if enabled and in embed mode
- // Special case: Cannot load in asynchronous code below
- if (typeof window.DriveClient === 'function' &&
- (typeof gapi === 'undefined' && (((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
- (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && isSvgBrowser &&
- isLocalStorage && (document.documentMode == null || document.documentMode >= 10))))
- {
- mxscript('https://apis.google.com/js/api.js?onload=DrawGapiClientCallback');
- }
- // Disables client
- else if (typeof window.gapi === 'undefined')
- {
- window.DriveClient = null;
- }
- }
-
- /**
- * Asynchronous MathJax extension.
- */
- if (urlParams['math'] != '0')
- {
- Editor.initMath();
- }
- // Adds required resources (disables loading of fallback properties, this can only
- // be used if we know that all keys are defined in the language specific file)
- mxResources.loadDefaultBundle = false;
- var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
- mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);
- // Prefetches asynchronous requests so that below code runs synchronous
- // Loading the correct bundle (one file) via the fallback system in mxResources. The stylesheet
- // is compiled into JS in the build process and is only needed for local development.
- mxUtils.getAll((urlParams['dev'] != '1') ? [bundle] : [bundle, STYLE_PATH + '/default.xml'], function(xhr)
- {
- // Adds bundle text to resources
- mxResources.parse(xhr[0].getText());
-
- // Prepares themes with mapping from old default-style to old XML file
- if (xhr.length > 1)
- {
- Graph.prototype.defaultThemes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();
- }
- // Main
- var ui = new App(new Editor(urlParams['chrome'] == '0'));
-
- if (window.mxscript != null)
- {
- // Loads dropbox for all browsers but IE8 and below (no CORS) if not disabled or if enabled and in embed mode
- // KNOWN: Picker does not work in IE11 (https://dropbox.zendesk.com/requests/1650781)
- if (typeof window.DropboxClient === 'function' &&
- (window.Dropbox == null && window.DrawDropboxClientCallback != null &&
- (((urlParams['embed'] != '1' && urlParams['db'] != '0') ||
- (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
- isSvgBrowser && (document.documentMode == null || document.documentMode > 9))))
- {
- mxscript(App.DROPBOX_URL, function()
- {
- // Must load this after the dropbox SDK since they use the same namespace
- mxscript(App.DROPINS_URL, function()
- {
- DrawDropboxClientCallback();
- }, 'dropboxjs', App.DROPBOX_APPKEY);
- });
- }
- // Disables client
- else if (typeof window.Dropbox === 'undefined' || typeof window.Dropbox.choose === 'undefined')
- {
- window.DropboxClient = null;
- }
-
- // Loads OneDrive for all browsers but IE6/IOS if not disabled or if enabled and in embed mode
- if (typeof window.OneDriveClient === 'function' &&
- (typeof OneDrive === 'undefined' && window.DrawOneDriveClientCallback != null &&
- (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
- urlParams['od'] == '1')) && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10))))
- {
- mxscript(App.ONEDRIVE_URL, window.DrawOneDriveClientCallback);
- }
- // Disables client
- else if (typeof window.OneDrive === 'undefined')
- {
- window.OneDriveClient = null;
- }
- }
-
- if (callback != null)
- {
- callback(ui);
- }
-
- /**
- * For developers only
- */
- if (urlParams['chrome'] != '0' && urlParams['test'] == '1')
- {
- mxLog.show();
- mxLog.debug('Started in ' + (new Date().getTime() - t0.getTime()) + 'ms');
- mxLog.debug('Export:', EXPORT_URL);
- mxLog.debug('Development mode:', (urlParams['dev'] == '1') ? 'active' : 'inactive');
- mxLog.debug('Test mode:', (urlParams['test'] == '1') ? 'active' : 'inactive');
- }
- }, function()
- {
- document.getElementById('geStatus').innerHTML = 'Error loading page. <a href="javascript:void(0);" onclick="location.reload();">Please try refreshing.</a>';
- });
- };
- //Extends EditorUi
- mxUtils.extend(App, EditorUi);
- /**
- * Executes the first step for connecting to Google Drive.
- */
- App.prototype.defaultUserPicture = 'https://lh3.googleusercontent.com/-HIzvXUy6QUY/AAAAAAAAAAI/AAAAAAAAAAA/giuR7PQyjEk/photo.jpg?sz=30';
- /**
- *
- */
- 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==';
- /**
- *
- */
- App.prototype.chevronUpImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/chevron-up.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDg2NEE3NUY1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDg2NEE3NjA1MUVBMTFFM0I3MUVEMTc0N0YyOUI4QzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0ODY0QTc1RDUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0ODY0QTc1RTUxRUExMUUzQjcxRUQxNzQ3RjI5QjhDMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pg+qUokAAAAMUExURQAAANnZ2b+/v////5bgre4AAAAEdFJOU////wBAKqn0AAAAL0lEQVR42mJgRgMMRAswMKAKMDDARBjg8lARBoR6KImkH0wTbygT6YaS4DmAAAMAYPkClOEDDD0AAAAASUVORK5CYII=';
- /**
- *
- */
- 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';
- /**
- *
- */
- App.prototype.formatShowImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-show.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REY1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5RTA1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlERDU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlERTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlnMQ/8AAAAJUExURQAAAP///3FxcTfTiAsAAAACdFJOU/8A5bcwSgAAACFJREFUeNpiYEQDDEQJMMABTAAixcQ00ALoDiPRcwABBgB6DADly9Yx8wAAAABJRU5ErkJggg==';
- /**
- *
- */
- App.prototype.formatHideImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/format-hide.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODdCREY5REI1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODdCREY5REM1NkQ3MTFFNTkyNjNEMTA5NjgwODUyRTgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4N0JERjlEOTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4N0JERjlEQTU2RDcxMUU1OTI2M0QxMDk2ODA4NTJFOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqjT9SMAAAAGUExURQAAAP///6XZn90AAAACdFJOU/8A5bcwSgAAAB9JREFUeNpiYEQDDEQJMMABTAAmNdAC6A4j0XMAAQYAcbwA1Xvj1CgAAAAASUVORK5CYII=';
- /**
- *
- */
- App.prototype.fullscreenImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/fullscreen.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAAAAAClZ7nPAAAAAXRSTlMAQObYZgAAABpJREFUCNdjgAAbGxAy4AEh5gNwBBGByoIBAIueBd12TUjqAAAAAElFTkSuQmCC';
- /**
- * Executes the first step for connecting to Google Drive.
- */
- App.prototype.timeout = 25000;
- /**
- * Overriden UI settings depending on mode.
- */
- if (urlParams['embed'] != '1')
- {
- App.prototype.menubarHeight = 60;
- }
- /**
- * Queue for loading plugins and wait for UI instance
- */
- App.initPluginCallback = function()
- {
- if (App.DrawPlugins == null)
- {
- // Workaround for need to load plugins now but wait for UI instance
- App.DrawPlugins = [];
-
- // Global entry point for plugins is Draw.loadPlugin. This is the only
- // long-term supported solution for access to the EditorUi instance.
- window.Draw = new Object();
- window.Draw.loadPlugin = function(callback)
- {
- App.DrawPlugins.push(callback);
- };
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.init = function()
- {
- EditorUi.prototype.init.apply(this, arguments);
- /**
- * Specifies the default filename.
- */
- this.defaultLibraryName = mxResources.get('untitledLibrary');
- /**
- * Holds the listener for description changes.
- */
- this.descriptorChangedListener = mxUtils.bind(this, this.descriptorChanged);
- /**
- * Basic adds for all backends.
- */
- this.basicAds = ['<a title="' + mxResources.get('loveIt', ['draw.io']) +
- '" target="_blank" href="https://twitter.com/intent/tweet?text=' +
- 'I%20%E2%9D%A4%EF%B8%8F%20www.draw.io' +
- '" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' +
- 'left=\'+((screen.width-640)/2)+\',top=\'+((screen.height-280)/3)+\',height=280,width=640\');return false;"\'>' +
- '<img border="0" align="absmiddle" width="18" height="18" style="margin-top:-2px;padding-right:12px;" src="' +
- Editor.tweetImage + '"/>I <img width="18" height="18" src="' + Editor.heartImage +
- '" border="0" align="absmiddle"> draw.io</a>',
- '<a title="Share on Facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=' +
- encodeURIComponent('https://www.draw.io') +
- '" onclick="javascript:window.open(this.href, \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' +
- 'left=\'+((screen.width-640)/2)+\',top=\'+((screen.height-520)/3)+\',height=520,width=640\');return false;"\'>' +
- '<img border="0" align="absmiddle" width="18" height="18" style="margin-top:-2px;padding-right:8px;" src="' +
- Editor.facebookImage + '"/>Share on Facebook</a>',
- '<a title="draw.io Offline App" href="https://www.draw.io/app" target="_blank">' +
- '<img border="0" align="absmiddle" style="margin-top:-1px;padding-right:8px;" src="images/download.png"/>' +
- 'draw.io Offline App</a>'];
- /**
- * Creates github client.
- */
- this.gitHub = (!mxClient.IS_IE || document.documentMode == 10 ||
- mxClient.IS_IE11 || mxClient.IS_EDGE) &&
- (urlParams['gh'] != '0' && (urlParams['embed'] != '1' ||
- urlParams['gh'] == '1')) ? new GitHubClient(this) : null;
-
- if (this.gitHub != null)
- {
- this.gitHub.addListener('userChanged', mxUtils.bind(this, function()
- {
- this.updateUserElement();
- this.restoreLibraries();
- }))
- }
- /**
- * Lazy-loading for individual backends
- */
- if (urlParams['embed'] != '1' || urlParams['od'] == '1')
- {
- /**
- * Creates onedrive client if all required libraries are available.
- */
- var initOneDriveClient = mxUtils.bind(this, function()
- {
- if (typeof OneDrive !== 'undefined')
- {
- /**
- * Holds the x-coordinate of the point.
- */
- this.oneDrive = new OneDriveClient(this);
-
- this.oneDrive.addListener('userChanged', mxUtils.bind(this, function()
- {
- this.updateUserElement();
- this.restoreLibraries();
- }))
-
- // Notifies listeners of new client
- this.fireEvent(new mxEventObject('clientLoaded', 'client', this.oneDrive));
- }
- else if (window.DrawOneDriveClientCallback == null)
- {
- window.DrawOneDriveClientCallback = initOneDriveClient;
- }
- });
- initOneDriveClient();
- }
- /**
- * Creates drive client with all required libraries are available.
- */
- if (urlParams['embed'] != '1' || urlParams['gapi'] == '1')
- {
- var initDriveClient = mxUtils.bind(this, function()
- {
- /**
- * Creates google drive client if all required libraries are available.
- */
- if (typeof gapi !== 'undefined')
- {
- var doInit = mxUtils.bind(this, function()
- {
- /**
- * Holds the x-coordinate of the point.
- */
- this.drive = new DriveClient(this);
-
- /**
- * Adds important notice for new app if drive file is loaded in old app.
- */
- if (this.drive.appId == '420247213240')
- {
- this.editor.addListener('fileLoaded', mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
-
- if (file != null && file.constructor == DriveFile)
- {
- var td = document.getElementById('geFooterItem2');
-
- if (td != null)
- {
- td.innerHTML = '<a href="https://support.draw.io/display/DO/2014/11/27/Switching+application+in+Google+Drive" ' +
- 'target="_blank" title="IMPORTANT NOTICE" >IMPORTANT NOTICE</a>';
- }
- }
- }));
- }
-
- this.drive.addListener('userChanged', mxUtils.bind(this, function()
- {
- // Changes the footer ads for Google Accounts
- if (this.updateAd != null)
- {
- this.adsHtml = this.basicAds.concat([
- '<a title="Google Docs Add-on" href="https://chrome.google.com/webstore/detail/drawio-diagrams/clpbjldiohnnmfmkngmaohehlnfkmoea" target="_blank">' +
- '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/> Google Docs Add-on</a>',
- '<a title="Google Chrome App" href="https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla" target="_blank">' +
- '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/download.png"/> Google Chrome App</a>',
- '<a title="Please help us to 5 stars" href="https://chrome.google.com/webstore/detail/drawio-pro/onlkggianjhjenigcpigpjehhpplldkc/reviews" target="_blank">' +
- '<img border="0" align="absmiddle" style="margin-top:-4px;" src="images/glyphicons_star.png"/> Please help us to 5 stars</a>']);
- }
-
- this.updateUserElement();
- this.restoreLibraries();
- this.checkLicense();
- }))
-
- // Notifies listeners of new client
- this.fireEvent(new mxEventObject('clientLoaded', 'client', this.drive));
- });
-
- if (window.DrawGapiClientCallback != null)
- {
- gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
- {
- // Starts the app without the Google Option if the API fails to load
- if (gapi.drive != null && gapi.drive.realtime != null)
- {
- gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
- {
- this.defineCustomObjects();
-
- // Needed to avoid popup blocking for non-immediate authentication
- gapi.auth.init(mxUtils.bind(this, function()
- {
- if (gapi.client.drive != null)
- {
- doInit();
- }
- }));
- }));
- }
- }));
-
- /**
- * Clears any callbacks.
- */
- window.DrawGapiClientCallback = null;
- }
- else
- {
- doInit();
- }
- }
- else if (window.DrawGapiClientCallback == null)
- {
- window.DrawGapiClientCallback = initDriveClient;
- }
- });
-
- initDriveClient();
- }
- if (urlParams['embed'] != '1' || urlParams['db'] == '1')
- {
- /**
- * Creates dropbox client if all required libraries are available.
- */
- var initDropboxClient = mxUtils.bind(this, function()
- {
- if (typeof Dropbox === 'function' && typeof Dropbox.choose !== 'undefined')
- {
- /**
- * Clears dropbox client callback.
- */
- window.DrawDropboxClientCallback = null;
-
- /**
- * Holds the x-coordinate of the point.
- */
- this.dropbox = new DropboxClient(this);
-
- this.dropbox.addListener('userChanged', mxUtils.bind(this, function()
- {
- this.updateUserElement();
- this.restoreLibraries();
- }));
-
- // Notifies listeners of new client
- this.fireEvent(new mxEventObject('clientLoaded', 'client', this.dropbox));
- }
- else if (window.DrawDropboxClientCallback == null)
- {
- window.DrawDropboxClientCallback = initDropboxClient;
- }
- });
- initDropboxClient();
- }
- if (urlParams['embed'] != '1')
- {
- /**
- * Holds the background element.
- */
- this.bg = this.createBackground();
- document.body.appendChild(this.bg);
- this.diagramContainer.style.visibility = 'hidden';
- this.formatContainer.style.visibility = 'hidden';
- this.hsplit.style.display = 'none';
- this.sidebarContainer.style.display = 'none';
- this.sidebarFooterContainer.style.display = 'none';
- // Sets the initial mode
- if (urlParams['local'] == '1')
- {
- this.setMode(App.MODE_DEVICE);
- }
- else
- {
- this.mode = App.mode;
- }
- }
- else if (this.menubar != null)
- {
- this.menubar.container.style.paddingTop = '0px';
- }
- this.updateHeader();
-
- // Changes footer from time to time
- var td = document.getElementById('geFooterItem2');
-
- if (td != null)
- {
- this.basicAds.push(td.innerHTML);
- this.adsHtml = this.basicAds;
- var lastAd = this.adsHtml.length - 1;
- var thread2 = null;
- var thread = null;
-
- this.updateAd = function(index, delay)
- {
- delay = (delay != null) ? delay : 1000;
- mxUtils.setPrefixedStyle(td.style, 'transition', 'all ' + (delay / 1000) + 's ease');
- if (thread2 != null)
- {
- window.clearTimeout(thread2);
- thread2 = null;
- }
-
- if (this.adsHtml.length == 1)
- {
- window.clearInterval(thread);
- }
-
- if (this.adsHtml.length == 0)
- {
- td.style.visibility = 'hidden';
- td.innerHTML = '';
- }
- else
- {
- td.style.visibility = 'visible';
-
- if (index == lastAd)
- {
- index++;
- }
- mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(0)');
- td.style.opacity = '0';
-
- window.setTimeout(mxUtils.bind(this, function()
- {
- td.innerHTML = this.adsHtml[index];
- mxUtils.setPrefixedStyle(td.style, 'transform', 'scale(1)');
- td.style.opacity = '1';
- lastAd = index;
- }), delay);
- }
- };
-
- thread = window.setInterval(mxUtils.bind(this, function()
- {
- this.updateAd(Math.round(Math.random() * (this.adsHtml.length - 2)));
- }), 180000);
-
- mxEvent.addListener(td, 'click', mxUtils.bind(this, function()
- {
- this.adsHtml.splice(lastAd, 1);
- lastAd = null;
- this.updateAd(0);
- }));
- if (mxSettings.getOpenCounter() > 10 && urlParams['embed'] != '1')
- {
- thread2 = window.setTimeout(mxUtils.bind(this, function()
- {
- this.updateAd(0);
- }), 15000);
- }
- }
-
- if (this.menubar != null)
- {
- this.buttonContainer = document.createElement('div');
- this.buttonContainer.style.display = 'inline-block';
- this.buttonContainer.style.paddingRight = '48px';
- this.buttonContainer.style.position = 'absolute';
- this.buttonContainer.style.right = '0px';
-
- this.menubar.container.appendChild(this.buttonContainer);
- }
- if (uiTheme == 'atlas' && this.menubar != null)
- {
- if (this.toggleElement != null)
- {
- this.toggleElement.click();
- this.toggleElement.style.display = 'none';
- }
-
- this.icon = document.createElement('img');
- this.icon.setAttribute('src', IMAGE_PATH + '/logo-flat-small.png');
- this.icon.setAttribute('title', mxResources.get('draw.io'));
- this.icon.style.paddingTop = '11px';
- this.icon.style.marginLeft = '4px';
- this.icon.style.marginRight = '6px';
-
- if (mxClient.IS_QUIRKS)
- {
- this.icon.style.marginTop = '12px';
- }
-
- this.menubar.container.insertBefore(this.icon, this.menubar.container.firstChild);
- }
- };
- /**
- * Returns true if the current domain is for the new drive app.
- */
- App.prototype.isDriveDomain = function()
- {
- return urlParams['drive'] != '0' &&
- (window.location.hostname == 'test.draw.io' ||
- window.location.hostname == 'cdn.draw.io' ||
- window.location.hostname == 'www.draw.io' ||
- window.location.hostname == 'drive.draw.io' ||
- window.location.hostname == 'jgraph.github.io');
- };
- /**
- * Returns true if the current domain is for the old drive app.
- */
- App.prototype.isLegacyDriveDomain = function()
- {
- return urlParams['drive'] == 0 || window.location.hostname == 'legacy.draw.io';
- };
- /**
- *
- */
- App.prototype.checkLicense = function()
- {
- var driveUser = this.drive.getUser();
- var email = ((urlParams['dev'] == '1') ? urlParams['lic'] : null) ||
- ((driveUser != null) ? driveUser.email : null);
-
- if (!this.isOffline() && !this.editor.chromeless && email != null)
- {
- // Anonymises the local part of the email address
- var at = email.lastIndexOf('@');
- var domain = email;
-
- if (at >= 0)
- {
- domain = email.substring(at + 1);
- //email = this.crc32(email.substring(0, at)) + '@' + domain;
- }
-
- // Timestamp is workaround for cached response in certain environments
- mxUtils.post('/license', 'domain=' + encodeURIComponent(domain) + '&email=' + encodeURIComponent(email) +
- '&ds=' + encodeURIComponent(driveUser.displayName) + '&lc=' + encodeURIComponent(driveUser.locale) +
- '&ts=' + new Date().getTime(),
- mxUtils.bind(this, function(req)
- {
- var registered = false;
- var exp = null;
-
- try
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- var value = req.getText();
- registered = true;
-
- if (value.length > 0)
- {
- var lic = JSON.parse(value);
-
- if (lic != null)
- {
- exp = this.handleLicense(lic, domain);
- }
- }
- }
- }
- catch (e)
- {
- // ignore
- }
- }));
- }
- };
- /**
- * Returns true if the current domain is for the new drive app.
- */
- App.prototype.handleLicense = function(lic, domain)
- {
- var footer = document.getElementById('geFooter');
- var expiry = null;
- if (footer != null && lic != null)
- {
- expiry = lic.expiry;
-
- if (lic.footer != null)
- {
- footer.innerHTML = decodeURIComponent(lic.footer);
- }
- else
- {
- this.hideFooter();
-
- if (expiry != null && expiry != 'never')
- {
- var exp = new Date(Date.parse(expiry));
- var diff = Math.round((exp - Date.now()) / (1000 * 60 * 60 * 24));
-
- if (diff < 90)
- {
- var link = 'https://support.draw.io/display/DKB/draw.io+footer+state+that+license+is+expiring+on+Google+For+Work+account?domain=' + encodeURIComponent(domain);
- footer.style.height = '100%';
- footer.style.margin = '0px';
- footer.style.display = '';
-
- if (diff < 0)
- {
- this.footerHeight = 80;
- footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert geBlink">' +
- '<a href="' + link + '" style="padding-top:16px;" target="_blank">' +
- '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
- mxResources.get('licenseHasExpired', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
- }
- else
- {
- this.footerHeight = 46;
- footer.innerHTML = '<table height="100%"><tr><td valign="middle" align="center" class="geStatusAlert">' +
- '<a href="' + link + '" target="_blank">' +
- '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="top" style="margin-right:6px">' +
- mxResources.get('licenseWillExpire', [domain, exp.toLocaleDateString()]) + '</a></td></tr></table>';
- }
-
- this.refresh();
- }
- }
- }
- }
-
- return expiry;
- };
- /**
- *
- */
- App.prototype.getEditBlankXml = function()
- {
- var file = this.getCurrentFile();
-
- if (file != null && this.editor.chromeless && this.editor.graph.lightbox && file.realtime == null)
- {
- return file.getData();
- }
- else
- {
- return this.getFileData(true);
- }
- };
- /**
- * Updates action states depending on the selection.
- */
- App.prototype.updateActionStates = function()
- {
- EditorUi.prototype.updateActionStates.apply(this, arguments);
- var file = this.getCurrentFile();
- this.actions.get('revisionHistory').setEnabled(file != null && ((file.constructor == DriveFile &&
- file.isEditable()) || file.constructor == DropboxFile));
- };
- /**
- * Updates draft in local storage
- */
- App.prototype.updateDraft = function()
- {
- if (isLocalStorage && localStorage != null)
- {
- localStorage.setItem('.draft', JSON.stringify({modified: new Date().getTime(), data: this.getFileData()}));
- }
- };
- /**
- * Returns the draft in local storage
- */
- App.prototype.getDraft = function()
- {
- // FIXME: Handle multiple tabs
- // if (isLocalStorage && localStorage != null)
- // {
- // try
- // {
- // var draft = localStorage.getItem('.draft');
- //
- // if (draft != null)
- // {
- // return JSON.parse(draft);
- // }
- // }
- // catch (e)
- // {
- // // ignore quota etc
- // }
- // }
- return null;
- };
- /**
- * Adds the specified entry to the recent file list in local storage
- */
- App.prototype.addRecent = function(entry)
- {
- if (isLocalStorage && localStorage != null)
- {
- var recent = this.getRecent();
-
- if (recent == null)
- {
- recent = [];
- }
- else
- {
- for (var i = 0; i < recent.length; i++)
- {
- if (recent[i].id == entry.id)
- {
- recent.splice(i, 1);
- }
- }
- }
-
- if (recent != null)
- {
- recent.unshift(entry);
- recent = recent.slice(0, 5);
- localStorage.setItem('.recent', JSON.stringify(recent));
- }
- }
- };
- /**
- * Returns the recent file list from local storage
- */
- App.prototype.getRecent = function()
- {
- if (isLocalStorage && localStorage != null)
- {
- try
- {
- var recent = localStorage.getItem('.recent');
-
- if (recent != null)
- {
- return JSON.parse(recent);
- }
- }
- catch (e)
- {
- // ignore
- }
-
- return null;
- }
- };
- /**
- * Clears the recent file list in local storage
- */
- App.prototype.resetRecent = function(entry)
- {
- if (isLocalStorage && localStorage != null)
- {
- try
- {
- localStorage.removeItem('.recent');
- }
- catch (e)
- {
- // ignore
- }
- }
- };
- /**
- * Clears the draft save in local storage
- */
- App.prototype.removeDraft = function()
- {
- if (isLocalStorage && localStorage != null && urlParams['splash'] == '0')
- {
- try
- {
- localStorage.removeItem('.draft');
- }
- catch (e)
- {
- // ignore quota etc
- }
- }
- };
- /**
- * Sets the onbeforeunload for the application
- */
- App.prototype.onBeforeUnload = function()
- {
- if (urlParams['embed'] == '1' && this.editor.modified)
- {
- return mxResources.get('allChangesLost');
- }
- else
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- // KNOWN: Message is ignored by most browsers
- if (file.constructor == LocalFile && file.getHash() == '' && !file.isModified() &&
- urlParams['nowarn'] != '1' && !this.isDiagramEmpty() && urlParams['url'] == null &&
- !this.editor.chromeless)
- {
- return mxResources.get('ensureDataSaved');
- }
- else if (file.constructor != DriveFile && file.isModified())
- {
- return mxResources.get('allChangesLost');
- }
- else
- {
- file.close(true);
- }
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.updateDocumentTitle = function()
- {
- if (!this.editor.graph.lightbox)
- {
- var title = this.editor.appName;
- var file = this.getCurrentFile();
-
- if (this.isOfflineApp())
- {
- title += ' app';
- }
-
- if (file != null)
- {
- var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
- title = filename + ' - ' + title;
- }
-
- document.title = title;
- }
- };
- /**
- * Authorizes the client, gets the userId and calls <open>.
- */
- App.prototype.createCrcTable = function()
- {
- var crcTable = [];
- var c;
- for (var n = 0; n < 256; n++)
- {
- c = n;
-
- for (var k = 0; k < 8; k++)
- {
- c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
- }
-
- crcTable[n] = c;
- }
-
- return crcTable;
- };
- /**
- * Authorizes the client, gets the userId and calls <open>.
- */
- App.prototype.crc32 = function(str)
- {
- this.crcTable = this.crcTable || this.createCrcTable();
- var crc = 0 ^ (-1);
- for (var i = 0; i < str.length; i++ )
- {
- crc = (crc >>> 8) ^ this.crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
- }
- return (crc ^ (-1)) >>> 0;
- };
- /**
- * Returns a thumbnail of the current file.
- */
- App.prototype.getThumbnail = function(width, success)
- {
- var result = false;
-
- try
- {
- if (this.thumbImageCache == null)
- {
- this.thumbImageCache = new Object();
- }
-
- var graph = this.editor.graph;
-
- // Exports PNG for first page while other page is visible by creating a graph
- // LATER: Add caching for the graph or SVG while not on first page
- if (this.pages != null && this.currentPage != this.pages[0])
- {
- graph = this.createTemporaryGraph(graph.getStylesheet());
- var graphGetGlobalVariable = graph.getGlobalVariable;
- var page = this.pages[0];
-
- graph.getGlobalVariable = function(name)
- {
- if (name == 'page')
- {
- return page.getName();
- }
- else if (name == 'pagenumber')
- {
- return 1;
- }
-
- return graphGetGlobalVariable.apply(this, arguments);
- };
-
- document.body.appendChild(graph.container);
- graph.model.setRoot(page.root);
- }
-
- // Uses client-side canvas export
- if (mxClient.IS_CHROMEAPP || (!graph.mathEnabled && this.useCanvasForExport))
- {
- this.exportToCanvas(mxUtils.bind(this, function(canvas)
- {
- // Removes temporary graph from DOM
- if (graph != this.editor.graph)
- {
- graph.container.parentNode.removeChild(graph.container);
- }
-
- success(canvas);
- }), width, this.thumbImageCache, '#ffffff', function()
- {
- // Continues with null in error case
- success();
- }, null, null, null, null, null, null, graph);
-
- result = true;
- }
- else if (this.canvasSupported && this.getCurrentFile() != null)
- {
- var canvas = document.createElement('canvas');
- var bounds = graph.getGraphBounds();
- var scale = width / bounds.width;
-
- // Limits scale to 1 or 2 * width / height
- scale = Math.min(1, Math.min((width * 3) / (bounds.height * 4), scale));
-
- var x0 = Math.floor(bounds.x);
- var y0 = Math.floor(bounds.y);
-
- canvas.setAttribute('width', Math.ceil(scale * (bounds.width + 4)));
- canvas.setAttribute('height', Math.ceil(scale * (bounds.height + 4)));
-
- var ctx = canvas.getContext('2d');
-
- // Configures the canvas
- ctx.scale(scale, scale);
- ctx.translate(-x0, -y0);
-
- // Paint white background instead of transparent
- var bg = graph.background;
-
- if (bg == null || bg == '' || bg == mxConstants.NONE)
- {
- bg = '#ffffff';
- }
-
- // Paints background
- ctx.save();
- ctx.fillStyle = bg;
- ctx.fillRect(x0, y0, Math.ceil(bounds.width + 4), Math.ceil(bounds.height + 4));
- ctx.restore();
-
- var htmlCanvas = new mxJsCanvas(canvas);
-
- // NOTE: htmlCanvas passed into async canvas is only used for image
- // and canvas caching (canvas caching not used in this case as we do
- // not render text). To reuse that cache via the thumbImageCache we
- // pass that into the async canvas and override the image cache in
- // the newly created html canvas with that of the thumbImageCache.
- // LATER: Is clear thumbImageCache needed if file changes?
- var asynCanvas = new mxAsyncCanvas(this.thumbImageCache);
- htmlCanvas.images = this.thumbImageCache.images;
-
- // Render graph
- var imgExport = new mxImageExport();
-
- imgExport.drawShape = function(state, canvas)
- {
- if (state.shape instanceof mxShape && state.shape.checkBounds())
- {
- canvas.save();
- canvas.translate(0.5, 0.5);
- state.shape.paint(canvas);
- canvas.translate(-0.5, -0.5);
- canvas.restore();
- }
- };
-
- imgExport.drawText = function(state, canvas)
- {
- // No text output for thumbnails
- };
-
- imgExport.drawState(graph.getView().getState(graph.model.root), asynCanvas);
-
- asynCanvas.finish(mxUtils.bind(this, function()
- {
- imgExport.drawState(graph.getView().getState(graph.model.root), htmlCanvas);
-
- // Removes temporary graph from DOM
- if (graph != this.editor.graph)
- {
- graph.container.parentNode.removeChild(graph.container);
- }
-
- success(canvas);
- }));
-
- result = true;
- }
- }
- catch (e)
- {
- // ignore and use placeholder
- // Removes temporary graph from DOM
- if (graph != this.editor.graph)
- {
- graph.container.parentNode.removeChild(graph.container);
- }
- }
-
- return result;
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.createBackground = function()
- {
- var bg = this.createDiv('background');
- bg.style.position = 'absolute';
- bg.style.background = 'white';
- bg.style.left = '0px';
- bg.style.top = '0px';
- bg.style.bottom = '0px';
- bg.style.right = '0px';
-
- mxUtils.setOpacity(bg, 100);
-
- if (mxClient.IS_QUIRKS)
- {
- new mxDivResizer(bg);
- }
- return bg;
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- (function()
- {
- var editorUiSetMode = EditorUi.prototype.setMode;
-
- App.prototype.setMode = function(mode, remember)
- {
- editorUiSetMode.apply(this, arguments);
-
- // Note: UseLocalStorage affects the file dialogs
- // and should not be modified if mode is undefined
- if (this.mode != null)
- {
- Editor.useLocalStorage = this.mode == App.MODE_BROWSER;
- }
-
- if (remember)
- {
- if (isLocalStorage)
- {
- localStorage.setItem('.mode', mode);
- }
- else if (typeof(Storage) != 'undefined')
- {
- var expiry = new Date();
- expiry.setYear(expiry.getFullYear() + 1);
- document.cookie = 'MODE=' + mode + '; expires=' + expiry.toUTCString();
- }
- }
-
- if (this.appIcon != null)
- {
- var file = this.getCurrentFile();
- var mode = (file != null) ? file.getMode() : null;
-
- if (mode == App.MODE_GOOGLE)
- {
- this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('googleDrive')]));
- this.appIcon.style.cursor = 'pointer';
- }
- else if (mode == App.MODE_DROPBOX)
- {
- this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('dropbox')]));
- this.appIcon.style.cursor = 'pointer';
- }
- else if (mode == App.MODE_ONEDRIVE)
- {
- this.appIcon.setAttribute('title', mxResources.get('openIt', [mxResources.get('oneDrive')]));
- this.appIcon.style.cursor = 'pointer';
- }
- else
- {
- this.appIcon.removeAttribute('title');
- this.appIcon.style.cursor = 'default';
- }
- }
- };
- })();
- /**
- * Function: authorize
- *
- * Authorizes the client, gets the userId and calls <open>.
- */
- App.prototype.appIconClicked = function(evt)
- {
- if (mxEvent.isAltDown(evt))
- {
- this.showSplash(true);
- }
- else
- {
- var file = this.getCurrentFile();
- var mode = (file != null) ? file.getMode() : null;
-
- if (mode == App.MODE_GOOGLE)
- {
- if (file.desc.parents.length > 0)
- {
- window.open('https://drive.google.com/drive/folders/' + file.desc.parents[0].id);
- }
- else
- {
- window.open('https://drive.google.com/?authuser=0');
- }
- }
- else if (mode == App.MODE_DROPBOX)
- {
- window.open('https://www.dropbox.com/');
- }
- else if (mode == App.MODE_ONEDRIVE)
- {
- window.open('https://onedrive.live.com/');
- }
- else if (mode == App.MODE_GITHUB)
- {
- if (file != null && file.constructor == GitHubFile)
- {
- window.open(file.meta.html_url);
- }
- else
- {
- window.open('https://github.com/');
- }
- }
- }
-
- mxEvent.consume(evt);
- };
- /**
- * Function: authorize
- *
- * Authorizes the client, gets the userId and calls <open>.
- */
- App.prototype.clearMode = function()
- {
- if (isLocalStorage)
- {
- localStorage.removeItem('.mode');
- }
- else if (typeof(Storage) != 'undefined')
- {
- var expiry = new Date();
- expiry.setYear(expiry.getFullYear() - 1);
- document.cookie = 'MODE=; expires=' + expiry.toUTCString();
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.getDiagramId = function()
- {
- var id = window.location.hash;
-
- // Strips the hash sign
- if (id != null && id.length > 0)
- {
- id = id.substring(1);
- }
-
- return id;
- };
- /**
- * Opens any file specified in the URL parameters.
- */
- App.prototype.open = function()
- {
- // Cross-domain window access is not allowed in FF, so if we
- // were opened from another domain then this will fail.
- try
- {
- // If the create URL param is used in embed mode then
- // we try to open the XML from window.opener[value].
- // Use this for embedding via tab to bypass the timing
- // issues when passing messages without onload event.
- if (window.opener != null)
- {
- var value = urlParams['create'];
-
- if (value != null)
- {
- value = decodeURIComponent(value);
- }
-
- if (value != null && value.length > 0 && value.substring(0, 7) != 'http://' &&
- value.substring(0, 8) != 'https://')
- {
- var doc = mxUtils.parseXml(window.opener[value]);
- this.editor.setGraphXml(doc.documentElement);
- }
- else if (window.opener.openFile != null)
- {
- window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename, temp)
- {
- this.spinner.stop();
-
- if (filename == null)
- {
- var title = urlParams['title'];
- temp = true;
-
- if (title != null)
- {
- filename = decodeURIComponent(title);
- }
- else
- {
- filename = this.defaultFilename;
- }
- }
-
- // Replaces PNG with XML extension
- var dot = filename.substring(filename.length - 4) == '.png';
-
- if (dot > 0)
- {
- filename = filename.substring(0, filename.length - 4) + '.xml';
- }
-
- this.fileLoaded((mxClient.IS_IOS) ?
- new StorageFile(this, xml, filename) :
- new LocalFile(this, xml, filename, temp));
- }));
- }
- }
- }
- catch(e)
- {
- // ignore
- }
- };
- /**
- * Main function. Program starts here.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.load = function()
- {
- // Checks if we're running in embedded mode
- if (urlParams['embed'] != '1')
- {
- if (this.spinner.spin(document.body, mxResources.get('starting')))
- {
- try
- {
- this.stateArg = (urlParams['state'] != null && this.drive != null) ? JSON.parse(decodeURIComponent(urlParams['state'])) : null;
- }
- catch (e)
- {
- // ignores invalid state args
- }
-
- this.editor.graph.setEnabled(this.getCurrentFile() != null);
-
- // Passes the userId from the state parameter to the client
- if ((window.location.hash == null || window.location.hash.length == 0) &&
- this.drive != null && this.stateArg != null && this.stateArg.userId != null)
- {
- this.drive.setUserId(this.stateArg.userId);
- }
- // Legacy support for fileId parameter which is moved to the hash tag
- if (urlParams['fileId'] != null)
- {
- window.location.hash = 'G' + urlParams['fileId'];
- window.location.search = this.getSearch(['fileId']);
- }
- else
- {
- // Asynchronous or disabled loading of client
- if (this.drive == null)
- {
- if (this.mode == App.MODE_GOOGLE)
- {
- this.mode = null;
- }
-
- this.start();
- }
- else
- {
- gapi.load('auth:client,drive-realtime,drive-share', mxUtils.bind(this, function(resp)
- {
- // Starts the app without the Google Option if the API fails to load
- if (gapi.drive == null || gapi.drive.realtime == null)
- {
- this.mode = null;
- this.drive = null;
- this.start();
- }
- else
- {
- gapi.client.load('drive', 'v2', mxUtils.bind(this, function()
- {
- // Needed to avoid popup blocking for non-immediate authentication
- gapi.auth.init(mxUtils.bind(this, function()
- {
- if (gapi.client.drive == null)
- {
- this.mode = null;
- this.drive = null;
- }
-
- this.start();
- }));
- }));
- }
- }));
- }
- }
- }
- }
- else
- {
- this.restoreLibraries();
- }
- };
- /**
- * Called in start after the spinner stops.
- */
- App.prototype.showAlert = function(message)
- {
- if (message != null && message.length > 0)
- {
- var div = document.createElement('div');
- div.className = 'geAlert';
- div.style.zIndex = 2e9;
- div.style.left = '50%';
- div.style.top = '-100%';
- mxUtils.setPrefixedStyle(div.style, 'transform', 'translate(-50%,0%)');
- mxUtils.setPrefixedStyle(div.style, 'transition', 'all 1s ease');
-
- div.innerHTML = message;
-
- var close = document.createElement('a');
- close.className = 'geAlertLink';
- close.style.textAlign = 'right';
- close.style.marginTop = '20px';
- close.style.display = 'block';
- close.setAttribute('href', 'javascript:void(0);');
- close.setAttribute('title', mxResources.get('close'));
- close.innerHTML = mxResources.get('close');
- div.appendChild(close);
-
- mxEvent.addListener(close, 'click', function(evt)
- {
- if (div.parentNode != null)
- {
- div.parentNode.removeChild(div);
- mxEvent.consume(evt);
- }
- });
-
- document.body.appendChild(div);
-
- // Delayed to get smoother animation after DOM rendering
- window.setTimeout(function()
- {
- div.style.top = '30px';
- }, 10);
-
- // Fades out the alert after 15 secs
- window.setTimeout(function()
- {
- mxUtils.setPrefixedStyle(div.style, 'transition', 'all 2s ease');
- div.style.opacity = '0';
-
- window.setTimeout(function()
- {
- if (div.parentNode != null)
- {
- div.parentNode.removeChild(div);
- }
- }, 2000);
- }, 15000);
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.start = function()
- {
- this.bg.parentNode.removeChild(this.bg);
- this.restoreLibraries();
- this.spinner.stop();
-
- try
- {
- // Listens to changes of the hash if not in embed or client mode
- if (urlParams['client'] != '1' && urlParams['embed'] != '1')
- {
- // KNOWN: Does not work in quirks mode
- mxEvent.addListener(window, 'hashchange', mxUtils.bind(this, function(evt)
- {
- try
- {
- var id = this.getDiagramId();
- var file = this.getCurrentFile();
-
- if (file == null || file.getHash() != id)
- {
- this.loadFile(id, true);
- }
- }
- catch (e)
- {
- // Workaround for possible scrollWidth of null in Dialog ctor
- if (document.body != null)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- window.location.hash = (file != null) ? file.getHash() : '';
- }));
- }
- }
- }));
- }
-
- // Redirects old url URL parameter to new #U format
- if ((window.location.hash == null || window.location.hash.length <= 1) && urlParams['url'] != null)
- {
- this.loadFile('U' + urlParams['url'], true);
- }
- else if (this.getCurrentFile() == null)
- {
- var done = mxUtils.bind(this, function()
- {
- // Starts in client mode and waits for data
- if (urlParams['client'] == '1' && (window.location.hash == null ||
- window.location.hash.length == 0))
- {
- var parent = window.opener || window.parent;
-
- if (parent != window)
- {
- this.installMessageHandler(mxUtils.bind(this, function(xml, evt)
- {
- // Ignores messages from other windows
- if (evt.source == parent)
- {
- // Extracts graph model from PNG
- if (xml.substring(0, 22) == 'data:image/png;base64,')
- {
- xml = this.extractGraphModelFromPng(xml);
- }
-
- var title = urlParams['title'];
-
- if (title != null)
- {
- title = decodeURIComponent(title);
- }
- else
- {
- title = this.defaultFilename;
- }
-
- this.fileLoaded(new LocalFile(this, xml, title, true));
- this.getCurrentFile().setModified(!this.editor.chromeless);
- }
- }));
- }
- }
- // Checks if no earlier loading errors are showing
- else if (this.dialog == null)
- {
- if (urlParams['demo'] == '1')
- {
- var prev = Editor.useLocalStorage;
- this.createFile(this.defaultFilename, null, null, null, null, null, null, true);
- Editor.useLocalStorage = prev;
- }
- else
- {
- var waiting = false;
-
- // Checks if we're waiting for some asynchronous file to be loaded
- // Cross-domain window access is not allowed in FF, so if we
- // were opened from another domain then this will fail.
- try
- {
- waiting = window.opener != null && window.opener.openFile != null;
- }
- catch(e)
- {
- // ignore
- }
-
- if (waiting)
- {
- // Spinner is stopped in App.open
- this.spinner.spin(document.body, mxResources.get('loading'))
- }
- else
- {
- var id = this.getDiagramId();
-
- if (urlParams['splash'] == '0' && (id == null || id.length == 0))
- {
- var draft = this.getDraft();
- var fileData = (draft != null) ? draft.data : this.getFileData();
- var prev = Editor.useLocalStorage;
- this.createFile(this.defaultFilename, fileData, null, null, null, null, null, true);
- Editor.useLocalStorage = prev;
-
- // Draft was used so the user should save the file
- if (draft != null)
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- file.addUnsavedStatus();
- }
- }
- }
- else
- {
- this.loadFile(this.getDiagramId());
- }
- }
- }
- }
- });
-
- // Defines custom classes for realtime in Google Drive
- if (this.drive != null)
- {
- this.defineCustomObjects();
- }
-
- var value = decodeURIComponent(urlParams['create'] || '');
-
- if ((window.location.hash == null || window.location.hash.length <= 1) &&
- value != null && value.length > 0 && this.spinner.spin(document.body, mxResources.get('loading')))
- {
- var reconnect = mxUtils.bind(this, function()
- {
- // Removes URL parameter and reloads the page
- if (this.spinner.spin(document.body, mxResources.get('reconnecting')))
- {
- window.location.search = this.getSearch(['create', 'title']);
- };
- });
-
- var showCreateDialog = mxUtils.bind(this, function(xml)
- {
- this.spinner.stop();
-
- // Resets mode for dialog - local file is only for preview
- if (urlParams['splash'] != '0')
- {
- this.fileLoaded(new LocalFile(this, xml, null));
-
- this.editor.graph.setEnabled(false);
- this.mode = urlParams['mode'];
- var title = urlParams['title'];
-
- if (title != null)
- {
- title = decodeURIComponent(title);
- }
- else
- {
- title = this.defaultFilename;
- }
-
- var serviceCount = this.getServiceCount(true);
- var rowLimit = (serviceCount <= 4) ? 4 : 3;
-
- var dlg = new CreateDialog(this, title, mxUtils.bind(this, function(filename, mode)
- {
- if (mode == null)
- {
- this.hideDialog();
- var prev = Editor.useLocalStorage;
- this.createFile((filename.length > 0) ? filename : this.defaultFilename,
- this.getFileData(), null, null, null, null, null, true);
- Editor.useLocalStorage = prev;
- }
- else
- {
- this.createFile(filename, this.getFileData(true), null, mode);
- }
- }), null, null, null, null, urlParams['browser'] == '1', null, null, true, rowLimit);
- this.showDialog(dlg.container, 380, (serviceCount > rowLimit) ? 390 : 270,
- true, false, mxUtils.bind(this, function(cancel)
- {
- if (cancel && this.getCurrentFile() == null)
- {
- this.showSplash();
- }
- }));
- dlg.init();
- }
- });
-
- value = decodeURIComponent(value);
-
- if (value.substring(0, 7) != 'http://' && value.substring(0, 8) != 'https://')
- {
- // Cross-domain window access is not allowed in FF, so if we
- // were opened from another domain then this will fail.
- try
- {
- if (window.opener != null && window.opener[value] != null)
- {
- showCreateDialog(window.opener[value]);
- }
- else
- {
- this.handleError(null, mxResources.get('errorLoadingFile'));
- }
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'));
- }
- }
- else
- {
- this.loadTemplate(value, function(text)
- {
- showCreateDialog(text);
- }, mxUtils.bind(this, function()
- {
- this.handleError(null, mxResources.get('errorLoadingFile'), reconnect);
- }));
- }
- }
- else
- {
- // Passes the fileId from the state parameter to the hash tag and reloads
- // the page without the state parameter
- if ((window.location.hash == null || window.location.hash.length <= 1) &&
- urlParams['state'] != null && this.stateArg != null && this.stateArg.action == 'open')
- {
- if (this.stateArg.ids != null)
- {
- window.location.hash = 'G' + this.stateArg.ids[0];
- }
- }
-
- if ((window.location.hash == null || window.location.hash.length <= 1) &&
- this.drive != null && this.stateArg != null && this.stateArg.action == 'create')
- {
- this.setMode(App.MODE_GOOGLE);
- this.actions.get('new').funct();
- }
- else
- {
- done();
- }
- }
- }
- }
- catch (e)
- {
- this.handleError(e);
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.showSplash = function(force)
- {
- var serviceCount = this.getServiceCount(false) + 1;
-
- var showSecondDialog = mxUtils.bind(this, function()
- {
- var dlg = new SplashDialog(this);
-
- this.showDialog(dlg.container, 340, (serviceCount < 2 ||
- mxClient.IS_CHROMEAPP || EditorUi.isElectronApp) ? 200 : 260, true, true,
- mxUtils.bind(this, function(cancel)
- {
- // Creates a blank diagram if the dialog is closed
- if (cancel && !mxClient.IS_CHROMEAPP)
- {
- var prev = Editor.useLocalStorage;
- this.createFile(this.defaultFilename, null, null, null, null, null, null,
- urlParams['local'] != '1');
- Editor.useLocalStorage = prev;
- }
- }));
- });
-
- if (this.editor.chromeless)
- {
- this.handleError({message: mxResources.get('noFileSelected')},
- mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
- {
- this.showSplash();
- }));
- }
- else if (this.mode == null || force)
- {
- var rowLimit = (serviceCount <= 4) ? 2 : 3;
-
- var dlg = new StorageDialog(this, mxUtils.bind(this, function()
- {
- this.hideDialog();
- showSecondDialog();
- }), rowLimit);
-
- this.showDialog(dlg.container, (rowLimit < 3) ? 260 : 300, (serviceCount > rowLimit) ? 420 : 300, true, false);
- dlg.init();
- }
- else if (urlParams['create'] == null)
- {
- showSecondDialog();
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.addLanguageMenu = function(elt)
- {
- var img = null;
-
- if (!this.isOfflineApp() || mxClient.IS_CHROMEAPP)
- {
- var langMenu = this.menus.get('language');
-
- if (langMenu != null)
- {
- img = document.createElement('div');
- img.setAttribute('title', mxResources.get('language'));
- img.className = 'geIcon geSprite geSprite-globe';
- img.style.position = 'absolute';
- img.style.cursor = 'pointer';
- img.style.bottom = '20px';
- img.style.right = '20px';
-
- mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
- {
- this.editor.graph.popupMenuHandler.hideMenu();
- var menu = new mxPopupMenu(this.menus.get('language').funct);
- menu.div.className += ' geMenubarMenu';
- menu.smartSeparators = true;
- menu.showDisabled = true;
- menu.autoExpand = true;
-
- // Disables autoexpand and destroys menu when hidden
- menu.hideMenu = mxUtils.bind(this, function()
- {
- mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
- menu.destroy();
- });
-
- var offset = mxUtils.getOffset(img);
- menu.popup(offset.x, offset.y + img.offsetHeight, null, evt);
-
- // Allows hiding by clicking on document
- this.setCurrentMenu(menu);
- }));
-
- elt.appendChild(img);
- }
- }
-
- return img;
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.defineCustomObjects = function()
- {
- if (gapi.drive.realtime != null && gapi.drive.realtime.custom != null)
- {
- gapi.drive.realtime.custom.registerType(mxRtCell, 'Cell');
-
- mxRtCell.prototype.cellId = gapi.drive.realtime.custom.collaborativeField('cellId');
- mxRtCell.prototype.type = gapi.drive.realtime.custom.collaborativeField('type');
- mxRtCell.prototype.value = gapi.drive.realtime.custom.collaborativeField('value');
- mxRtCell.prototype.xmlValue = gapi.drive.realtime.custom.collaborativeField('xmlValue');
- mxRtCell.prototype.style = gapi.drive.realtime.custom.collaborativeField('style');
- mxRtCell.prototype.geometry = gapi.drive.realtime.custom.collaborativeField('geometry');
- mxRtCell.prototype.visible = gapi.drive.realtime.custom.collaborativeField('visible');
- mxRtCell.prototype.collapsed = gapi.drive.realtime.custom.collaborativeField('collapsed');
- mxRtCell.prototype.connectable = gapi.drive.realtime.custom.collaborativeField('connectable');
- mxRtCell.prototype.parent = gapi.drive.realtime.custom.collaborativeField('parent');
- mxRtCell.prototype.children = gapi.drive.realtime.custom.collaborativeField('children');
- mxRtCell.prototype.source = gapi.drive.realtime.custom.collaborativeField('source');
- mxRtCell.prototype.target = gapi.drive.realtime.custom.collaborativeField('target');
- }
- };
- mxRtCell = function() {};
- // Ignores rtCell property in codec and cloning
- mxCodecRegistry.getCodec(mxCell).exclude.push('rtCell');
- mxCell.prototype.mxTransient.push('rtCell');
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.pickFile = function(mode)
- {
- mode = (mode != null) ? mode : this.mode;
-
- if (mode == App.MODE_GOOGLE)
- {
- if (this.drive != null && typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- this.drive.pickFile();
- }
- else
- {
- window.open('https://drive.google.com');
- }
- }
- else
- {
- var peer = this.getPeerForMode(mode);
-
- if (peer != null)
- {
- peer.pickFile();
- }
- else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
- {
- var input = document.createElement('input');
- input.setAttribute('type', 'file');
-
- mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
- {
- if (input.files != null)
- {
- this.openFiles(input.files);
- }
- }));
-
- input.click();
- }
- else
- {
- this.hideDialog();
- window.openNew = this.getCurrentFile() != null && !this.isDiagramEmpty();
- window.baseUrl = this.getUrl();
- window.openKey = 'open';
- var prevValue = Editor.useLocalStorage;
- Editor.useLocalStorage = (mode == App.MODE_BROWSER);
- this.openFile();
-
- // Installs local handler for opened files in same window
- window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
- {
- // Replaces PNG with XML extension
- var dot = filename.substring(filename.length - 4) == '.png';
-
- if (dot > 0)
- {
- filename = filename.substring(0, filename.length - 4) + '.xml';
- }
-
- this.fileLoaded((mode == App.MODE_BROWSER) ?
- new StorageFile(this, xml, filename) :
- new LocalFile(this, xml, filename));
- }));
-
- // Extends dialog close to show splash screen
- var dlg = this.dialog;
- var dlgClose = dlg.close;
-
- this.dialog.close = mxUtils.bind(this, function(cancel)
- {
- Editor.useLocalStorage = prevValue;
- dlgClose.apply(dlg, arguments);
-
- if (this.getCurrentFile() == null)
- {
- this.showSplash();
- }
- });
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.pickLibrary = function(mode)
- {
- mode = (mode != null) ? mode : this.mode;
-
- if (mode == App.MODE_GOOGLE || mode == App.MODE_DROPBOX || mode == App.MODE_ONEDRIVE || mode == App.MODE_GITHUB)
- {
- var peer = (mode == App.MODE_GOOGLE) ? this.drive :
- ((mode == App.MODE_ONEDRIVE) ? this.oneDrive :
- ((mode == App.MODE_GITHUB) ? this.gitHub :
- this.dropbox));
-
- if (peer != null)
- {
- peer.pickLibrary(mxUtils.bind(this, function(id, optionalFile)
- {
- if (optionalFile != null)
- {
- try
- {
- this.loadLibrary(optionalFile);
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'));
- }
- }
- else
- {
- if (this.spinner.spin(document.body, mxResources.get('loading')))
- {
- peer.getLibrary(id, mxUtils.bind(this, function(file)
- {
- this.spinner.stop();
-
- try
- {
- this.loadLibrary(file);
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'));
- }
- }), mxUtils.bind(this, function(resp)
- {
- this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
- }));
- }
- }
- }));
- }
- }
- else if (mode == App.MODE_DEVICE && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
- {
- var input = document.createElement('input');
- input.setAttribute('type', 'file');
-
- mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
- {
- if (input.files != null)
- {
- for (var i = 0; i < input.files.length; i++)
- {
- (mxUtils.bind(this, function(file)
- {
- var reader = new FileReader();
-
- reader.onload = mxUtils.bind(this, function(e)
- {
- try
- {
- this.loadLibrary(new LocalLibrary(this, e.target.result, file.name));
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'));
- }
- });
- reader.readAsText(file);
- }))(input.files[i]);
- }
- }
- }));
- input.click();
- }
- else
- {
- window.openNew = false;
- window.openKey = 'open';
-
- var prevValue = Editor.useLocalStorage;
- Editor.useLocalStorage = mode == App.MODE_BROWSER;
-
- // Closes dialog after open
- window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
- {
- this.hideDialog(cancel);
- }));
-
- window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
- {
- try
- {
- this.loadLibrary((mode == App.MODE_BROWSER) ? new StorageLibrary(this, xml, filename) :
- new LocalLibrary(this, xml, filename));
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'));
- }
- }));
- // Removes openFile if dialog is closed
- this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 360,
- (Editor.useLocalStorage) ? 480 : 220, true, true, function()
- {
- Editor.useLocalStorage = prevValue;
- window.openFile = null;
- });
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.saveLibrary = function(name, images, file, mode, noSpin, noReload, fn)
- {
- mode = (mode != null) ? mode : this.mode;
- noSpin = (noSpin != null) ? noSpin : false;
- noReload = (noReload != null) ? noReload : false;
- var xml = this.createLibraryDataFromImages(images);
-
- var error = mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
-
- if (fn != null)
- {
- fn();
- }
-
- this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
- });
- // Handles special case for local libraries
- if (file == null && mode == App.MODE_DEVICE)
- {
- file = new LocalLibrary(this, xml, name);
- }
-
- if (file == null)
- {
- this.pickFolder(mode, mxUtils.bind(this, function(folderId)
- {
- if (mode == App.MODE_GOOGLE && this.drive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- this.drive.insertFile(name, xml, folderId, mxUtils.bind(this, function(newFile)
- {
- this.spinner.stop();
- this.hideDialog(true);
- this.libraryLoaded(newFile, images);
- }), error, this.drive.libraryMimeType);
- }
- else if (mode == App.MODE_GITHUB && this.gitHub != null && this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- this.gitHub.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
- {
- this.spinner.stop();
- this.hideDialog(true);
- this.libraryLoaded(newFile, images);
- }), error, folderId);
- }
- else if (mode == App.MODE_DROPBOX && this.dropbox != null && this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- this.dropbox.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
- {
- this.spinner.stop();
- this.hideDialog(true);
- this.libraryLoaded(newFile, images);
- }), error, folderId);
- }
- else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- this.oneDrive.insertLibrary(name, xml, mxUtils.bind(this, function(newFile)
- {
- this.spinner.stop();
- this.hideDialog(true);
- this.libraryLoaded(newFile, images);
- }), error, folderId);
- }
- else if (mode == App.MODE_BROWSER)
- {
- var fn = mxUtils.bind(this, function()
- {
- var file = new StorageLibrary(this, xml, name);
-
- // Inserts data into local storage
- file.saveFile(name, false, mxUtils.bind(this, function()
- {
- this.hideDialog(true);
- this.libraryLoaded(file, images);
- }), error);
- });
-
- if (localStorage.getItem(name) == null)
- {
- fn();
- }
- else
- {
- this.confirm(mxResources.get('replaceIt', [name]), fn);
- }
- }
- else
- {
- this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
- }
- }));
- }
- else if (noSpin || this.spinner.spin(document.body, mxResources.get('saving')))
- {
- file.setData(xml);
-
- var doSave = mxUtils.bind(this, function()
- {
- file.save(true, mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
- this.hideDialog(true);
-
- if (!noReload)
- {
- this.libraryLoaded(file, images);
- }
-
- if (fn != null)
- {
- fn();
- }
- }), error);
- });
-
- if (name != file.getTitle())
- {
- var oldHash = file.getHash();
-
- file.rename(name, mxUtils.bind(this, function(resp)
- {
- // Change hash in stored settings
- if (file.constructor != LocalLibrary && oldHash != file.getHash())
- {
- mxSettings.removeCustomLibrary(oldHash);
- mxSettings.addCustomLibrary(file.getHash());
- }
- // Workaround for library files changing hash so
- // the old library cannot be removed from the
- // sidebar using the updated file in libraryLoaded
- this.removeLibrarySidebar(oldHash);
- doSave();
- }), error)
- }
- else
- {
- doSave();
- }
- }
- };
- /**
- * Adds the label menu items to the given menu and parent.
- */
- App.prototype.saveFile = function(forceDialog)
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- // FIXME: Invoke for local files
- var done = mxUtils.bind(this, function()
- {
- this.removeDraft();
-
- // Workaround for possible status update while save as dialog is showing
- // is to show no saved status for device files
- if (file.getMode() != App.MODE_DEVICE)
- {
- this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
- }
- else
- {
- this.editor.setStatus('');
- }
- });
-
- if (!forceDialog && file.getTitle() != null && this.mode != null)
- {
- this.save(file.getTitle(), done);
- }
- else
- {
- var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
- var allowTab = !mxClient.IS_IOS || !navigator.standalone;
- var prev = this.mode;
- var serviceCount = this.getServiceCount(true);
-
- if (isLocalStorage)
- {
- serviceCount++;
- }
-
- var rowLimit = (serviceCount <= 4) ? 2 : 3;
-
- var dlg = new CreateDialog(this, filename, mxUtils.bind(this, function(name, mode)
- {
- if (name != null && name.length > 0)
- {
- if (prev == null && mode == App.MODE_DEVICE)
- {
- this.setMode(App.MODE_DEVICE);
- this.save(name, done);
- }
- else if (mode == 'download')
- {
- var tmp = new LocalFile(this, null, name);
- tmp.save();
- }
- else if (mode == '_blank')
- {
- window.openFile = new OpenFile(function()
- {
- window.openFile = null;
- });
-
- // Do not use a filename to use undefined mode
- window.openFile.setData(this.getFileData(true));
- window.open(this.getUrl(window.location.pathname));
- }
- else if (prev != mode)
- {
- this.pickFolder(mode, mxUtils.bind(this, function(folderId)
- {
- this.createFile(name, this.getFileData(/(\.xml)$/i.test(name) ||
- name.indexOf('.') < 0, /(\.svg)$/i.test(name),
- /(\.html)$/i.test(name)), null, mode, done,
- this.mode == null, folderId);
- }), mode !== App.MODE_GITHUB);
- }
- else if (mode != null)
- {
- this.save(name, done);
- }
- }
- }), mxUtils.bind(this, function()
- {
- this.hideDialog();
- }), mxResources.get('saveAs'), mxResources.get('download'), null, null, allowTab,
- (this.isOffline()) ? null :
- 'https://desk.draw.io/support/solutions/articles/16000042485',
- true, rowLimit);
- this.showDialog(dlg.container, 460, (serviceCount > rowLimit) ? 390 : 270, true, true);
- dlg.init();
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- EditorUi.prototype.loadTemplate = function(url, onload, onerror)
- {
- var realUrl = url;
-
- if (!this.isCorsEnabledForUrl(realUrl))
- {
- realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
- }
-
- this.loadUrl(realUrl, mxUtils.bind(this, function(data)
- {
- if (!this.isOffline() && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
- {
- // Asynchronous parsing via server
- this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
- {
- if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status <= 299 &&
- xhr.responseText.substring(0, 13) == '<mxGraphModel')
- {
- onload(xhr.responseText);
- }
- }), url);
- }
- else
- {
- if (/(\.png)($|\?)/i.test(url))
- {
- data = this.extractGraphModelFromPng(data);
- }
-
- onload(data);
- }
- }), onerror, /(\.png)($|\?)/i.test(url));
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.getPeerForMode = function(mode)
- {
- if (mode == App.MODE_GOOGLE)
- {
- return this.drive;
- }
- else if (mode == App.MODE_GITHUB)
- {
- return this.gitHub;
- }
- else if (mode == App.MODE_DROPBOX)
- {
- return this.dropbox;
- }
- else if (mode == App.MODE_ONEDRIVE)
- {
- return this.oneDrive;
- }
- else
- {
- return null;
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.createFile = function(title, data, libs, mode, done, replace, folderId, tempFile)
- {
- mode = (tempFile) ? null : ((mode != null) ? mode : this.mode);
- if (title != null && this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- data = (data != null) ? data : this.emptyDiagramXml;
-
- var complete = mxUtils.bind(this, function()
- {
- this.spinner.stop();
- });
-
- var error = mxUtils.bind(this, function(resp)
- {
- complete();
-
- if (resp == null && this.getCurrentFile() == null && this.dialog == null)
- {
- this.showSplash();
- }
- else if (resp != null)
- {
- this.handleError(resp);
- }
- });
-
- if (mode == App.MODE_GOOGLE && this.drive != null)
- {
- folderId = (this.stateArg != null) ? this.stateArg.folderId : folderId;
- this.drive.insertFile(title, data, folderId, mxUtils.bind(this, function(file)
- {
- complete();
- this.fileCreated(file, libs, replace, done);
- }), error);
- }
- else if (mode == App.MODE_GITHUB && this.gitHub != null)
- {
- this.pickFolder(mode, mxUtils.bind(this, function(folderId)
- {
- this.gitHub.insertFile(title, data, mxUtils.bind(this, function(file)
- {
- complete();
- this.fileCreated(file, libs, replace, done);
- }), error, false, folderId);
- }));
- }
- else if (mode == App.MODE_DROPBOX && this.dropbox != null)
- {
- this.dropbox.insertFile(title, data, mxUtils.bind(this, function(file)
- {
- complete();
- this.fileCreated(file, libs, replace, done);
- }), error);
- }
- else if (mode == App.MODE_ONEDRIVE && this.oneDrive != null)
- {
- this.oneDrive.insertFile(title, data, mxUtils.bind(this, function(file)
- {
- complete();
- this.fileCreated(file, libs, replace, done);
- }), error, false, folderId);
- }
- else if (mode == App.MODE_BROWSER)
- {
- complete();
-
- var fn = mxUtils.bind(this, function()
- {
- var file = new StorageFile(this, data, title);
-
- // Inserts data into local storage
- file.saveFile(title, false, mxUtils.bind(this, function()
- {
- this.fileCreated(file, libs, replace, done);
- }), error);
- });
-
- if (localStorage.getItem(title) == null)
- {
- fn();
- }
- else
- {
- this.confirm(mxResources.get('replaceIt', [title]), fn, mxUtils.bind(this, function()
- {
- if (this.getCurrentFile() == null && this.dialog == null)
- {
- this.showSplash();
- }
- }));
- }
- }
- else
- {
- complete();
- this.fileCreated(new LocalFile(this, data, title, mode == null), libs, replace, done);
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.fileCreated = function(file, libs, replace, done)
- {
- var url = window.location.pathname;
-
- if (libs != null && libs.length > 0)
- {
- url += '?libs=' + libs;
- }
-
- url = this.getUrl(url);
- // Always opens a new tab for local files to avoid losing changes
- if (file.getMode() != App.MODE_DEVICE)
- {
- url += '#' + file.getHash();
- }
-
- // Makes sure to produce consistent output with finalized files via createFileData this needs
- // to save the file again since it needs the newly created file ID for redirecting in HTML
- if (this.spinner.spin(document.body, mxResources.get('inserting')))
- {
- var data = file.getData();
- var dataNode = (data.length > 0) ? this.editor.extractGraphModel(
- mxUtils.parseXml(data).documentElement, true) : null;
- var redirect = window.location.protocol + '//' + window.location.hostname + url;
- var graph = null;
-
- // Handles special case where SVG files need a rendered graph to be saved
- if (dataNode != null && /\.svg$/i.test(file.getTitle()))
- {
- graph = this.createTemporaryGraph(this.editor.graph.getStylesheet());
- document.body.appendChild(graph.container);
- node = dataNode;
-
- if (node != null)
- {
- var diagramNode = null;
-
- if (node.nodeName == 'diagram')
- {
- diagramNode = node;
- }
- else if (node.nodeName == 'mxfile')
- {
- var diagrams = node.getElementsByTagName('diagram');
- if (diagrams.length > 0)
- {
- diagramNode = diagrams[0];
- var graphGetGlobalVariable = graph.getGlobalVariable;
-
- graph.getGlobalVariable = function(name)
- {
- if (name == 'page')
- {
- return diagramNode.getAttribute('name') || mxResources.get('pageWithNumber', [1])
- }
- else if (name == 'pagenumber')
- {
- return 1;
- }
-
- return graphGetGlobalVariable.apply(this, arguments);
- };
- }
- }
-
- if (diagramNode != null)
- {
- var tmp = graph.decompress(mxUtils.getTextContent(diagramNode));
-
- if (tmp != null && tmp.length > 0)
- {
- node = mxUtils.parseXml(tmp).documentElement;
- }
- }
- }
-
- // Hack to decode XML into temp graph via editor
- var prev = this.editor.graph;
-
- try
- {
- this.editor.graph = graph;
- this.editor.setGraphXml(node);
- }
- catch (e)
- {
- // ignore
- }
- finally
- {
- this.editor.graph = prev;
- }
- }
-
- file.setData(this.createFileData(dataNode, graph, file, redirect));
- if (graph != null)
- {
- graph.container.parentNode.removeChild(graph.container);
- }
- var complete = mxUtils.bind(this, function()
- {
- this.spinner.stop();
- });
-
- var fn = mxUtils.bind(this, function()
- {
- complete();
-
- var currentFile = this.getCurrentFile();
-
- if (replace == null && currentFile != null)
- {
- replace = !currentFile.isModified() && currentFile.getMode() == null;
- }
-
- var fn3 = mxUtils.bind(this, function()
- {
- window.openFile = null;
- this.fileLoaded(file);
-
- if (replace)
- {
- this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
- }
-
- if (libs != null)
- {
- this.sidebar.showEntries(libs);
- }
- });
- var fn2 = mxUtils.bind(this, function()
- {
- if (replace || currentFile == null || !currentFile.isModified())
- {
- fn3();
- }
- else
- {
- this.confirm(mxResources.get('allChangesLost'), null, fn3,
- mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- });
- if (done != null)
- {
- done();
- }
-
- // Opens the file in a new window
- if (replace != null && !replace)
- {
- // Opens local file in a new window
- if (file.constructor == LocalFile)
- {
- window.openFile = new OpenFile(function()
- {
- window.openFile = null;
- });
-
- window.openFile.setData(file.getData(), file.getTitle(), file.getMode() == null);
- }
- if (done != null)
- {
- done();
- }
-
- window.openWindow(url, null, fn2);
- }
- else
- {
- fn2();
- }
- });
-
- // Updates data in memory for local files and save is implicit
- // via start of realtime for DriveFiles
- if (file.constructor == LocalFile || file.constructor == DriveFile)
- {
- fn();
- }
- else
- {
- file.saveFile(file.getTitle(), false, mxUtils.bind(this, function()
- {
- fn();
- }), mxUtils.bind(this, function(resp)
- {
- complete();
- this.handleError(resp);
- }));
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.loadFile = function(id, sameWindow, file)
- {
- this.hideDialog();
-
- var fn2 = mxUtils.bind(this, function()
- {
- if (id == null || id.length == 0)
- {
- this.editor.setStatus('');
- this.fileLoaded(null);
- }
- else if (this.spinner.spin(document.body, mxResources.get('loading')))
- {
- // Handles files from localStorage
- if (id.charAt(0) == 'L')
- {
- this.spinner.stop();
- if (!isLocalStorage)
- {
- this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
- {
- var tempFile = this.getCurrentFile();
- window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
- }));
- }
- else
- {
- try
- {
- id = decodeURIComponent(id.substring(1));
- var data = localStorage.getItem(id);
-
- if (data != null)
- {
- this.fileLoaded(new StorageFile(this, data, id));
- }
- else
- {
- throw {message: mxResources.get('fileNotFound')};
- }
- }
- catch (e)
- {
- this.handleError(e, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
- {
- var tempFile = this.getCurrentFile();
- window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
- }));
- }
- }
- }
- else if (file != null)
- {
- // File already loaded
- this.spinner.stop();
- this.fileLoaded(file);
- }
- else if (id.charAt(0) == 'R')
- {
- // Raw file encoded into URL
- this.spinner.stop();
- var data = decodeURIComponent(id.substring(1));
-
- if (data.charAt(0) != '<')
- {
- data = this.editor.graph.decompress(data);
- }
-
- var tempFile = new LocalFile(this, data, (urlParams['title'] != null) ?
- decodeURIComponent(urlParams['title']) : this.defaultFilename, true);
- tempFile.getHash = function()
- {
- return id;
- };
- this.fileLoaded(tempFile);
- }
- else if (id.charAt(0) == 'U')
- {
- var url = decodeURIComponent(id.substring(1));
-
- this.loadTemplate(url, mxUtils.bind(this, function(text)
- {
- this.spinner.stop();
-
- if (text != null && text.length > 0)
- {
- var filename = this.defaultFilename;
-
- // Tries to find name from URL with valid extensions
- if (urlParams['title'] == null && urlParams['notitle'] != '1')
- {
- var tmp = url;
- var dot = url.lastIndexOf('.');
- var slash = tmp.lastIndexOf('/');
-
- if (dot > slash && slash > 0)
- {
- tmp = tmp.substring(slash + 1, dot);
- var ext = url.substring(dot);
-
- if (ext == '.png')
- {
- ext = '.xml';
- }
- if (ext === '.svg' || ext === '.xml' || ext === '.html')
- {
- filename = tmp + ext;
- }
- }
- }
-
- var tempFile = new LocalFile(this, text, (urlParams['title'] != null) ?
- decodeURIComponent(urlParams['title']) : filename, true);
- tempFile.getHash = function()
- {
- return id;
- };
-
- if (!this.fileLoaded(tempFile))
- {
- // Fallback for non-public Google Drive diagrams
- if (url.substring(0, 31) == 'https://drive.google.com/uc?id=' &&
- (this.drive != null || typeof window.DriveClient === 'function'))
- {
- this.hideDialog();
-
- var fallback = mxUtils.bind(this, function()
- {
- if (this.drive != null)
- {
- this.spinner.stop();
- this.loadFile('G' + url.substring(31, url.lastIndexOf('&')), sameWindow);
-
- return true;
- }
- else
- {
- return false;
- }
- });
-
- if (!fallback() && this.spinner.spin(document.body, mxResources.get('loading')))
- {
- this.addListener('clientLoaded', fallback);
- }
- }
- }
- }
- }), mxUtils.bind(this, function()
- {
- this.spinner.stop();
- this.handleError({message: mxResources.get('fileNotFound')}, mxResources.get('errorLoadingFile'));
- }));
- }
- else
- {
- // Google Drive files are handled as default file types
- var peer = null;
-
- if (id.charAt(0) == 'G')
- {
- peer = this.drive;
- }
- else if (id.charAt(0) == 'D')
- {
- peer = this.dropbox;
- }
- else if (id.charAt(0) == 'W')
- {
- peer = this.oneDrive;
- }
- else if (id.charAt(0) == 'H')
- {
- peer = this.gitHub;
- }
-
- if (peer == null)
- {
- this.handleError({message: mxResources.get('serviceUnavailableOrBlocked')}, mxResources.get('errorLoadingFile'), mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- window.location.hash = (file != null) ? file.getHash() : '';
- }));
- }
- else
- {
- id = decodeURIComponent(id.substring(1));
-
- peer.getFile(id, mxUtils.bind(this, function(file)
- {
- this.spinner.stop();
- this.fileLoaded(file);
- }), mxUtils.bind(this, function(resp)
- {
- // Makes sure the file does not save the invalid UI model and overwrites anything important
- if (window.console != null && resp != null)
- {
- console.log('error in loadFile:', id, resp);
- }
-
- this.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null, mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
-
- if (file == null)
- {
- window.location.hash = '';
- this.showSplash();
- }
- else
- {
- window.location.hash = file.getHash();
- }
- }));
- }));
- }
- }
- }
- });
-
- var currentFile = this.getCurrentFile();
-
- var fn = mxUtils.bind(this, function()
- {
- if (currentFile == null || !currentFile.isModified())
- {
- fn2();
- }
- else
- {
- this.confirm(mxResources.get('allChangesLost'), mxUtils.bind(this, function()
- {
- if (currentFile != null)
- {
- window.location.hash = currentFile.getHash();
- }
- }), fn2, mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- });
-
- if (id == null || id.length == 0)
- {
- fn();
- }
- else if (currentFile != null && currentFile.isModified() && !sameWindow)
- {
- window.openWindow(this.getUrl() + '#' + id, null, fn);
- }
- else
- {
- fn();
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.getLibraryStorageHint = function(file)
- {
- var tip = file.getTitle();
-
- if (file.constructor != LocalLibrary)
- {
- tip += '\n' + file.getHash();
- }
-
- if (file.constructor == DriveLibrary)
- {
- tip += ' (' + mxResources.get('googleDrive') + ')';
- }
- else if (file.constructor == GitHubLibrary)
- {
- tip += ' (' + mxResources.get('github') + ')';
- }
- else if (file.constructor == DropboxLibrary)
- {
- tip += ' (' + mxResources.get('dropbox') + ')';
- }
- else if (file.constructor == OneDriveLibrary)
- {
- tip += ' (' + mxResources.get('oneDrive') + ')';
- }
- else if (file.constructor == StorageLibrary)
- {
- tip += ' (' + mxResources.get('browser') + ')';
- }
- else if (file.constructor == LocalLibrary)
- {
- tip += ' (' + mxResources.get('device') + ')';
- }
- return tip;
- };
- /**
- * Updates action states depending on the selection.
- */
- App.prototype.restoreLibraries = function()
- {
- if (this.sidebar != null)
- {
- if (this.pendingLibraries == null)
- {
- this.pendingLibraries = new Object();
- }
-
- // Ignores this library next time
- var ignore = mxUtils.bind(this, function(id)
- {
- mxSettings.removeCustomLibrary(id);
- delete this.pendingLibraries[id];
- });
-
- var load = mxUtils.bind(this, function(libs)
- {
- if (libs != null)
- {
- for (var i = 0; i < libs.length; i++)
- {
- var name = encodeURIComponent(decodeURIComponent(libs[i]));
-
- (mxUtils.bind(this, function(id)
- {
- if (id != null && id.length > 0 && this.pendingLibraries[id] == null &&
- this.sidebar.palettes[id] == null)
- {
- this.pendingLibraries[id] = true;
- var service = id.substring(0, 1);
-
- if (service == 'L')
- {
- if (isLocalStorage || mxClient.IS_CHROMEAPP)
- {
- try
- {
- var name = decodeURIComponent(id.substring(1));
- var xml = this.getLocalData(name, mxUtils.bind(this, function(xml)
- {
- if (name == '.scratchpad' && xml == null)
- {
- xml = this.emptyLibraryXml;
- }
-
- if (xml != null)
- {
- this.loadLibrary(new StorageLibrary(this, xml, name));
- }
- else
- {
- ignore(id);
- }
- }));
- }
- catch (e)
- {
- ignore(id);
- }
- }
- }
- else if (service == 'U')
- {
- var url = decodeURIComponent(id.substring(1));
-
- if (!this.isOffline())
- {
- var realUrl = url;
-
- if (!this.isCorsEnabledForUrl(realUrl))
- {
- realUrl = PROXY_URL + '?url=' + encodeURIComponent(url);
- }
-
- // Uses proxy to avoid CORS issues
- mxUtils.get(realUrl, mxUtils.bind(this, function(req)
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- try
- {
- this.loadLibrary(new UrlLibrary(this, req.getText(), url));
- delete this.pendingLibraries[id];
- }
- catch (e)
- {
- ignore(id);
- }
- }
- else
- {
- ignore(id);
- }
- }), function()
- {
- ignore(id);
- });
- }
- }
- else
- {
- var peer = null;
-
- if (service == 'G')
- {
- if (this.drive != null && this.drive.user != null)
- {
- peer = this.drive;
- }
- }
- else if (service == 'H')
- {
- if (this.gitHub != null && this.gitHub.getUser() != null)
- {
- peer = this.gitHub;
- }
- }
- else if (service == 'D')
- {
- if (this.dropbox != null && this.dropbox.getUser() != null)
- {
- peer = this.dropbox;
- }
- }
- else if (service == 'W')
- {
- if (this.oneDrive != null && this.oneDrive.getUser() != null)
- {
- peer = this.oneDrive;
- }
- }
-
- if (peer != null)
- {
- peer.getLibrary(decodeURIComponent(id.substring(1)), mxUtils.bind(this, function(file)
- {
- try
- {
- this.loadLibrary(file);
- delete this.pendingLibraries[id];
- }
- catch (e)
- {
- ignore(id);
- }
- }), function(resp)
- {
- ignore(id);
- });
- }
- else
- {
- delete this.pendingLibraries[id];
- }
- }
- }
- }))(name);
- }
- }
- });
-
- load(mxSettings.getCustomLibraries());
- load((urlParams['clibs'] || '').split(';'));
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.updateButtonContainer = function()
- {
- if (this.buttonContainer != null)
- {
- var file = this.getCurrentFile();
-
- if (file != null && file.constructor == DriveFile)
- {
- // Adds Share button
- if (this.shareButton == null)
- {
- this.shareButton = document.createElement('div');
- this.shareButton.className = 'geBtn gePrimaryBtn';
- this.shareButton.style.display = 'inline-block';
- this.shareButton.style.padding = '0 10px 0 10px';
- this.shareButton.style.marginTop = '-4px';
- this.shareButton.style.height = '28px';
- this.shareButton.style.lineHeight = '28px';
- this.shareButton.style.minWidth = '0px';
- this.shareButton.style.cssFloat = 'right';
-
- var icon = document.createElement('img');
- icon.setAttribute('src', this.shareImage);
- icon.setAttribute('align', 'absmiddle');
- icon.style.marginRight = '4px';
- icon.style.marginTop = '-3px';
- this.shareButton.appendChild(icon);
-
- mxUtils.write(this.shareButton, mxResources.get('share'));
-
- mxEvent.addListener(this.shareButton, 'click', mxUtils.bind(this, function()
- {
- this.actions.get('share').funct();
- }));
-
- this.buttonContainer.appendChild(this.shareButton);
- }
- }
- else if (this.shareButton != null)
- {
- this.shareButton.parentNode.removeChild(this.shareButton);
- this.shareButton = null;
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.save = function(name, done)
- {
- var file = this.getCurrentFile();
- var msg = mxResources.get('saving');
-
- if (file != null && file.constructor == DriveFile)
- {
- msg = mxResources.get('createRevision');
- }
-
- if (file != null && this.spinner.spin(document.body, msg))
- {
- this.editor.setStatus('');
-
- if (this.editor.graph.isEditing())
- {
- this.editor.graph.stopEditing();
- }
-
- var success = mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
-
- if (this.getCurrentFile() == file)
- {
- if (file.isModified())
- {
- if (!file.isAutosave())
- {
- file.addUnsavedStatus();
- }
- }
- else
- {
- this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('allChangesSaved')));
- }
- }
-
- if (done != null)
- {
- done();
- }
- });
-
- var error = mxUtils.bind(this, function(resp)
- {
- // Spinner is paused and resumed in handleError
- this.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
- });
-
- if (name == file.getTitle())
- {
- file.save(true, success, error);
- }
- else
- {
- file.saveAs(name, success, error)
- }
- }
- };
- /**
- * Invokes callback with null if mode does not support folder or not null
- * if a valid folder was chosen for a mode that supports it. No callback
- * is made if no folder was chosen for a mode that supports it.
- */
- App.prototype.pickFolder = function(mode, fn, enabled)
- {
- enabled = (enabled != null) ? enabled : true;
- var resume = this.spinner.pause();
-
- if (enabled && mode == App.MODE_GOOGLE && this.drive != null)
- {
- // Shows a save dialog
- this.drive.pickFolder(mxUtils.bind(this, function(evt)
- {
- resume();
-
- if (evt.action == google.picker.Action.PICKED)
- {
- var folderId = null;
-
- if (evt.docs != null && evt.docs.length > 0 && evt.docs[0].type == 'folder')
- {
- folderId = evt.docs[0].id;
- }
-
- fn(folderId);
- }
- }));
- }
- else if (enabled && mode == App.MODE_ONEDRIVE && this.oneDrive != null)
- {
- this.oneDrive.pickFolder(mxUtils.bind(this, function(files)
- {
- var folderId = null;
- resume();
-
- if (files != null && files.value != null && files.value.length > 0)
- {
- folderId = files.value[0].id;
- fn(folderId);
- }
- }));
- }
- else if (enabled && mode == App.MODE_GITHUB && this.gitHub != null)
- {
- this.gitHub.pickFolder(mxUtils.bind(this, function(folderPath)
- {
- resume();
- fn(folderPath);
- }));
- }
- else
- {
- EditorUi.prototype.pickFolder.apply(this, arguments);
- }
- };
- /**
- *
- */
- App.prototype.exportFile = function(data, filename, mimeType, base64Encoded, mode, folderId)
- {
- if (mode == App.MODE_DROPBOX)
- {
- if (this.dropbox != null && this.spinner.spin(document.body, mxResources.get('saving')))
- {
- // LATER: Add folder picker
- this.dropbox.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
- data, mxUtils.bind(this, function()
- {
- this.spinner.stop();
- }), mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
- this.handleError(resp);
- }));
- }
- }
- else if (mode == App.MODE_GOOGLE)
- {
- if (this.drive != null && this.spinner.spin(document.body, mxResources.get('saving')))
- {
- this.drive.insertFile(filename, data, folderId, mxUtils.bind(this, function(resp)
- {
- // TODO: Add callback with url param for clickable status message
- // "File exported. Click here to open folder."
- // this.editor.setStatus('<div class="geStatusMessage" style="cursor:pointer;">' +
- // mxResources.get('saved') + '</div>');
- //
- // // Installs click handler for opening
- // if (this.statusContainer != null)
- // {
- // var links = this.statusContainer.getElementsByTagName('div');
- //
- // if (links.length > 0)
- // {
- // mxEvent.addListener(links[0], 'click', mxUtils.bind(this, function()
- // {
- // if (resp != null && resp.parents != null && resp.parents.length > 0)
- // {
- // var id = resp.parents[0].id;
- //
- // if (id != null)
- // {
- // window.open('https://drive.google.com/drive/folders/' + id);
- // }
- // }
- // }));
- // }
- // }
-
- this.spinner.stop();
- }), mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
- this.handleError(resp);
- }), mimeType, base64Encoded, false);
- }
- }
- else if (mode == App.MODE_ONEDRIVE)
- {
- if (this.oneDrive != null && this.spinner.spin(document.body, mxResources.get('saving')))
- {
- // KNOWN: OneDrive does not show .svg extension
- this.oneDrive.insertFile(filename, (base64Encoded) ? this.base64ToBlob(data, mimeType) :
- data, mxUtils.bind(this, function()
- {
- this.spinner.stop();
- }), mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
- this.handleError(resp);
- }), false, folderId);
- }
- }
- else if (mode == App.MODE_GITHUB)
- {
- if (this.gitHub != null && this.spinner.spin(document.body, mxResources.get('saving')))
- {
- // Must insert file as library to force the file to be written
- this.gitHub.insertFile(filename, data, mxUtils.bind(this, function()
- {
- this.spinner.stop();
- }), mxUtils.bind(this, function(resp)
- {
- this.spinner.stop();
- this.handleError(resp);
- }), true, folderId, base64Encoded);
- }
- }
- else if (mode == App.MODE_BROWSER)
- {
- var fn = mxUtils.bind(this, function()
- {
- localStorage.setItem(filename, data);
- });
-
- if (localStorage.getItem(filename) == null)
- {
- fn();
- }
- else
- {
- this.confirm(mxResources.get('replaceIt', [filename]), fn);
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.descriptorChanged = function()
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- if (this.fname != null)
- {
- this.fnameWrapper.style.display = 'block';
- this.fname.innerHTML = '';
- var filename = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
- mxUtils.write(this.fname, filename);
- this.fname.setAttribute('title', filename + ' - ' + mxResources.get('rename'));
- }
-
- this.editor.graph.setEnabled(file.isEditable());
-
- // Ignores title and hash for revisions
- if (urlParams['rev'] == null)
- {
- this.updateDocumentTitle();
-
- var newHash = file.getHash();
-
- if (newHash.length > 0)
- {
- window.location.hash = newHash;
- }
- else if (window.location.hash.length > 0)
- {
- window.location.hash = '';
- }
- }
- }
- };
- /**
- * Translates this point by the given vector.
- *
- * @param {number} dx X-coordinate of the translation.
- * @param {number} dy Y-coordinate of the translation.
- */
- App.prototype.toggleChat = function()
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- if (file.chatWindow == null)
- {
- var cwLeft = document.body.offsetWidth - 300;
- file.chatWindow = new ChatWindow(this, mxResources.get('chatWindowTitle'), document.getElementById('geChat'), cwLeft , 80, 250, 350, file.realtime);
- file.chatWindow.window.setVisible(false);
- }
-
- file.chatWindow.window.setVisible(!file.chatWindow.window.isVisible());
- }
- };
- /**
- * Adds the listener for automatically saving the diagram for local changes.
- */
- App.prototype.showAuthDialog = function(peer, showRememberOption, fn, closeFn)
- {
- var resume = this.spinner.pause();
-
- this.showDialog(new AuthDialog(this, peer, showRememberOption, mxUtils.bind(this, function(remember)
- {
- try
- {
- if (fn != null)
- {
- fn(remember, mxUtils.bind(this, function()
- {
- this.hideDialog();
- resume();
- }));
- }
- }
- catch (e)
- {
- this.editor.setStatus(mxUtils.htmlEntities(e.message));
- }
- })).container, 300, (showRememberOption) ? 180 : 140, true, true, mxUtils.bind(this, function(cancel)
- {
- if (closeFn != null)
- {
- closeFn();
- }
-
- if (cancel && this.getCurrentFile() == null && this.dialog == null)
- {
- this.showSplash();
- }
- }));
- };
- /**
- * Checks if the client is authorized and calls the next step. The optional
- * readXml argument is used for import. Default is false. The optional
- * readLibrary argument is used for reading libraries. Default is false.
- */
- App.prototype.convertFile = function(url, filename, mimeType, extension, success, error)
- {
- var name = filename;
-
- // SVG file extensions are valid and needed for image import
- if (!/\.svg$/i.test(name))
- {
- name = name.substring(0, filename.lastIndexOf('.')) + extension;
- }
-
- var gitHubUrl = false;
-
- if (this.gitHub != null && url.substring(0, this.gitHub.baseUrl.length) == this.gitHub.baseUrl)
- {
- gitHubUrl = true;
- }
-
- // Workaround for wrong binary response with VSDX files
- if (/\.vsdx$/i.test(filename) && Graph.fileSupport && new XMLHttpRequest().upload &&
- typeof new XMLHttpRequest().responseType === 'string')
- {
- var req = new XMLHttpRequest();
- req.open('GET', url, true);
-
- if (!gitHubUrl)
- {
- req.responseType = 'blob';
- }
- req.onload = mxUtils.bind(this, function()
- {
- var blob = null;
-
- if (gitHubUrl)
- {
- var file = JSON.parse(req.responseText);
- blob = this.base64ToBlob(file.content, 'application/octet-stream');
- }
- else
- {
- blob = new Blob([req.response], {type: 'application/octet-stream'});
- }
- this.parseFile(blob, mxUtils.bind(this, function(xhr)
- {
- if (xhr.readyState == 4)
- {
- if (xhr.status >= 200 && xhr.status <= 299)
- {
- success(new LocalFile(this, xhr.responseText, name, true));
- }
- else if (error != null)
- {
- error({message: mxResources.get('errorLoadingFile')});
- }
- }
- }), filename);
- });
- req.send();
- }
- else
- {
- var handleData = mxUtils.bind(this, function(data)
- {
- try
- {
- if (/\.png$/i.test(filename))
- {
- temp = this.extractGraphModelFromPng(data);
-
- if (temp != null)
- {
- success(new LocalFile(this, temp, name, true));
- }
- else
- {
- success(new LocalFile(this, data, filename, true));
- }
- }
- else if (Graph.fileSupport && new XMLHttpRequest().upload && this.isRemoteFileFormat(data, url))
- {
- this.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
- {
- if (xhr.readyState == 4)
- {
- if (xhr.status >= 200 && xhr.status <= 299)
- {
- success(new LocalFile(this, xhr.responseText, name, true));
- }
- else if (error != null)
- {
- error({message: mxResources.get('errorLoadingFile')});
- }
- }
- }), filename);
- }
- else
- {
- success(new LocalFile(this, data, name, true));
- }
- }
- catch (e)
- {
- if (error != null)
- {
- error(e);
- }
- }
- });
- var binary = /\.png$/i.test(filename) || /\.jpe?g$/i.test(filename) || (mimeType != null &&
- mimeType.substring(0, 6) == 'image/');
-
- // NOTE: Cannot force non-binary request via loadUrl so needs separate
- // code as decoding twice on content with binary data did not work
- if (gitHubUrl)
- {
- mxUtils.get(url, mxUtils.bind(this, function(req)
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- if (success != null)
- {
- var file = JSON.parse(req.getText());
- var data = file.content;
-
- if (file.encoding === 'base64')
- {
- if (/\.png$/i.test(filename))
- {
- data = 'data:image/png;base64,' + data;
- }
- else
- {
- // Workaround for character encoding issues in IE10/11
- data = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ? atob(data) : Base64.decode(data);
- }
- }
-
- handleData(data);
- }
- }
- else if (error != null)
- {
- error({code: App.ERROR_UNKNOWN});
- }
- }), function()
- {
- if (error != null)
- {
- error({code: App.ERROR_UNKNOWN});
- }
- }, false, this.timeout, function()
- {
- if (error != null)
- {
- error({code: App.ERROR_TIMEOUT, retry: fn});
- }
- });
- }
- else
- {
- this.loadUrl(url, handleData, error, binary);
- }
- }
- };
- /**
- * Adds the listener for automatically saving the diagram for local changes.
- */
- App.prototype.updateHeader = function()
- {
- if (this.menubar != null)
- {
- this.appIcon = document.createElement('a');
- this.appIcon.style.display = 'block';
- this.appIcon.style.position = 'absolute';
- this.appIcon.style.width = '40px';
- this.appIcon.style.backgroundColor = '#f18808';
- this.appIcon.style.height = this.menubarHeight + 'px';
-
- mxEvent.disableContextMenu(this.appIcon);
-
- mxEvent.addListener(this.appIcon, 'click', mxUtils.bind(this, function(evt)
- {
- this.appIconClicked(evt);
- }));
-
- // LATER: Use Alpha image loader in IE6
- // NOTE: This uses the diagram bit of the old logo as it looks better in this case
- //this.appIcon.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + IMAGE_PATH + '/logo-white.png,sizingMethod=\'scale\')';
- var logo = (!mxClient.IS_SVG) ? 'url(\'' + IMAGE_PATH + '/logo-white.png\')' :
- 'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIKICAgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzA2LjE4NSAxMjAuMjk2IgogICB2aWV3Qm94PSIyNCAyNiA2OCA2OCIKICAgeT0iMHB4IgogICB4PSIwcHgiCiAgIHZlcnNpb249IjEuMSI+CiAgIAkgPGc+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNDEuMDYxIgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjkiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTUyOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGxpbmUKICAgICAgIHkyPSI3Mi4zOTQiCiAgICAgICB4Mj0iNzUuMDc2IgogICAgICAgeTE9IjQzLjM4NCIKICAgICAgIHgxPSI1OC4wNjgiCiAgICAgICBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiCiAgICAgICBzdHJva2Utd2lkdGg9IjMuNTAwOCIKICAgICAgIHN0cm9rZT0iI0ZGRkZGRiIKICAgICAgIGZpbGw9Im5vbmUiIC8+PGc+PHBhdGgKICAgICAgICAgZD0iTTUyLjc3Myw3Ny4wODRjMCwxLjk1NC0xLjU5OSwzLjU1My0zLjU1MywzLjU1M0gzNi45OTljLTEuOTU0LDAtMy41NTMtMS41OTktMy41NTMtMy41NTN2LTkuMzc5ICAgIGMwLTEuOTU0LDEuNTk5LTMuNTUzLDMuNTUzLTMuNTUzaDEyLjIyMmMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjc3LjA4NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnCiAgICAgICBpZD0iZzM0MTkiPjxwYXRoCiAgICAgICAgIGQ9Ik02Ny43NjIsNDguMDc0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINTEuOTg4Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M0g2NC4yMWMxLjk1NCwwLDMuNTUzLDEuNTk5LDMuNTUzLDMuNTUzVjQ4LjA3NHoiCiAgICAgICAgIGZpbGw9IiNGRkZGRkYiIC8+PC9nPjxnPjxwYXRoCiAgICAgICAgIGQ9Ik04Mi43NTIsNzcuMDg0YzAsMS45NTQtMS41OTksMy41NTMtMy41NTMsMy41NTNINjYuOTc3Yy0xLjk1NCwwLTMuNTUzLTEuNTk5LTMuNTUzLTMuNTUzdi05LjM3OSAgICBjMC0xLjk1NCwxLjU5OS0zLjU1MywzLjU1My0zLjU1M2gxMi4yMjJjMS45NTQsMCwzLjU1MywxLjU5OSwzLjU1MywzLjU1M1Y3Ny4wODR6IgogICAgICAgICBmaWxsPSIjRkZGRkZGIiAvPjwvZz48L2c+PC9zdmc+)';
- this.appIcon.style.backgroundImage = logo;
- this.appIcon.style.backgroundPosition = 'center center';
- this.appIcon.style.backgroundRepeat = 'no-repeat';
-
- mxUtils.setPrefixedStyle(this.appIcon.style, 'transition', 'all 125ms linear');
-
- mxEvent.addListener(this.appIcon, 'mouseover', mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
-
- if (file != null)
- {
- var mode = file.getMode();
-
- if (mode == App.MODE_GOOGLE)
- {
- this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/google-drive-logo-white.svg)';
- }
- else if (mode == App.MODE_DROPBOX)
- {
- this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/dropbox-logo-white.svg)';
- }
- else if (mode == App.MODE_ONEDRIVE)
- {
- this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/onedrive-logo-white.svg)';
- }
- else if (mode == App.MODE_GITHUB)
- {
- this.appIcon.style.backgroundImage = 'url(' + IMAGE_PATH + '/github-logo-white.svg)';
- }
- }
- }));
-
- mxEvent.addListener(this.appIcon, 'mouseout', mxUtils.bind(this, function()
- {
- this.appIcon.style.backgroundImage = logo;
- }));
-
- if (urlParams['embed'] != '1')
- {
- this.menubarContainer.appendChild(this.appIcon);
- }
-
- this.fnameWrapper = document.createElement('div');
- this.fnameWrapper.style.position = 'absolute';
- this.fnameWrapper.style.right = '120px';
- this.fnameWrapper.style.left = '50px';
- this.fnameWrapper.style.top = '6px';
- this.fnameWrapper.style.height = '26px';
- this.fnameWrapper.style.display = 'none';
- this.fnameWrapper.style.overflow = 'hidden';
- this.fnameWrapper.style.textOverflow = 'ellipsis';
-
- this.fname = document.createElement('a');
- this.fname.setAttribute('href', 'javascript:void(0);');
- this.fname.setAttribute('title', mxResources.get('rename'));
- this.fname.className = 'geItem';
- this.fname.style.padding = '2px 8px 2px 8px';
- this.fname.style.display = 'inline';
- this.fname.style.fontSize = '18px';
- this.fname.style.whiteSpace = 'nowrap';
-
- mxEvent.addListener(this.fname, 'click', mxUtils.bind(this, function(evt)
- {
- var file = this.getCurrentFile();
-
- if (file != null && file.isRenamable())
- {
- this.actions.get('rename').funct();
- }
-
- mxEvent.consume(evt);
- }));
-
- this.fnameWrapper.appendChild(this.fname);
-
- if (urlParams['embed'] != '1')
- {
- this.menubarContainer.appendChild(this.fnameWrapper);
-
- this.menubar.container.style.position = 'absolute';
- this.menubar.container.style.paddingLeft = '52px';
- this.menubar.container.style.boxSizing = 'border-box';
- this.menubar.container.style.top = '29px';
-
- this.toolbar.container.style.paddingLeft = '56px';
- }
-
- /**
- * Adds format panel toggle.
- */
- this.toggleFormatElement = document.createElement('a');
- this.toggleFormatElement.setAttribute('href', 'javascript:void(0);');
- this.toggleFormatElement.setAttribute('title', mxResources.get('formatPanel') + ' (Ctrl+Shift+P)');
- this.toggleFormatElement.style.position = 'absolute';
- this.toggleFormatElement.style.display = 'inline-block';
- this.toggleFormatElement.style.top = '5px';
- this.toggleFormatElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '26px' : '10px';
- this.toggleFormatElement.style.padding = '2px';
- this.toggleFormatElement.style.fontSize = '14px';
- this.toggleFormatElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
- this.toggleFormatElement.style.width = '16px';
- this.toggleFormatElement.style.height = '16px';
- this.toggleFormatElement.style.backgroundPosition = '50% 50%';
- this.toggleFormatElement.style.backgroundRepeat = 'no-repeat';
- this.toolbarContainer.appendChild(this.toggleFormatElement);
- mxEvent.addListener(this.toggleFormatElement, 'click', mxUtils.bind(this, function(evt)
- {
- this.actions.get('formatPanel').funct();
- mxEvent.consume(evt);
- }));
- var toggleFormatPanel = mxUtils.bind(this, function()
- {
- if (this.formatWidth > 0)
- {
- this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatShowImage + '\')';
- }
- else
- {
- this.toggleFormatElement.style.backgroundImage = 'url(\'' + this.formatHideImage + '\')';
- }
- });
-
- this.addListener('formatWidthChanged', toggleFormatPanel);
- toggleFormatPanel();
- this.fullscreenElement = document.createElement('a');
- this.fullscreenElement.setAttribute('href', 'javascript:void(0);');
- this.fullscreenElement.setAttribute('title', mxResources.get('fullscreen'));
- this.fullscreenElement.style.position = 'absolute';
- this.fullscreenElement.style.display = 'inline-block';
- this.fullscreenElement.style.top = '5px';
- this.fullscreenElement.style.right = (uiTheme != 'atlas' && urlParams['embed'] != '1') ? '42px' : '26px';
- this.fullscreenElement.style.padding = '2px';
- this.fullscreenElement.style.fontSize = '14px';
- this.fullscreenElement.className = (uiTheme != 'atlas') ? 'geButton' : '';
- this.fullscreenElement.style.width = '16px';
- this.fullscreenElement.style.height = '16px';
- this.fullscreenElement.style.backgroundPosition = '50% 50%';
- this.fullscreenElement.style.backgroundRepeat = 'no-repeat';
- this.fullscreenElement.style.backgroundImage = 'url(\'' + this.fullscreenImage + '\')';
- this.toolbarContainer.appendChild(this.fullscreenElement);
-
- var initialPosition = this.hsplitPosition;
- var collapsed = false;
- mxEvent.addListener(this.fullscreenElement, 'click', mxUtils.bind(this, function(evt)
- {
- if (uiTheme != 'atlas' && urlParams['embed'] != '1')
- {
- this.toggleCompactMode(!collapsed);
- }
- this.toggleFormatPanel(!collapsed);
- this.hsplitPosition = (!collapsed) ? 0 : initialPosition;
- this.hideFooter();
- collapsed = !collapsed;
- mxEvent.consume(evt);
- }));
-
- // Some style changes in Atlas theme
- if (uiTheme == 'atlas')
- {
- mxUtils.setOpacity(this.toggleFormatElement, 70);
- mxUtils.setOpacity(this.fullscreenElement, 70);
- this.toggleFormatElement.style.right = '6px';
- this.fullscreenElement.style.right = '22px';
- this.toggleFormatElement.style.top = '8px';
- this.fullscreenElement.style.top = '8px';
- }
-
- /**
- * Adds compact UI toggle.
- */
- if (urlParams['embed'] != '1')
- {
- this.toggleElement = document.createElement('a');
- this.toggleElement.setAttribute('href', 'javascript:void(0);');
- this.toggleElement.setAttribute('title', mxResources.get('collapseExpand'));
- this.toggleElement.className = 'geButton';
- this.toggleElement.style.position = 'absolute';
- this.toggleElement.style.display = 'inline-block';
- this.toggleElement.style.width = '16px';
- this.toggleElement.style.height = '16px';
- this.toggleElement.style.color = '#666';
- this.toggleElement.style.top = '5px';
- this.toggleElement.style.right = '10px';
- this.toggleElement.style.padding = '2px';
- this.toggleElement.style.fontSize = '14px';
- this.toggleElement.style.textDecoration = 'none';
- this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
-
- this.toggleElement.style.backgroundPosition = '50% 50%';
- this.toggleElement.style.backgroundRepeat = 'no-repeat';
-
- // Toggles compact mode
- mxEvent.addListener(this.toggleElement, 'click', mxUtils.bind(this, function(evt)
- {
- this.toggleCompactMode();
- mxEvent.consume(evt);
- }));
-
- if (uiTheme != 'atlas')
- {
- this.toolbarContainer.appendChild(this.toggleElement);
- }
-
- // Enable compact mode for small screens
- if (screen.height <= 740 && typeof this.toggleElement.click !== 'undefined')
- {
- window.setTimeout(mxUtils.bind(this, function()
- {
- this.toggleElement.click();
- }), 0);
- }
- }
- }
- };
- /**
- * Adds the listener for automatically saving the diagram for local changes.
- */
- App.prototype.toggleCompactMode = function(forceHide)
- {
- if (!forceHide && this.appIcon.style.display == 'none')
- {
- this.menubar.container.style.position = 'absolute';
- this.menubar.container.style.paddingLeft = '52px';
- this.menubar.container.style.paddingTop = '';
- this.menubar.container.style.paddingBottom = '';
- this.menubar.container.style.top = '29px';
- this.toolbar.container.style.paddingLeft = '56px';
- this.buttonContainer.style.visibility = 'visible';
- this.appIcon.style.display = 'block';
- this.fnameWrapper.style.display = 'block';
- this.fnameWrapper.style.visibility = 'visible';
- this.menubarHeight = App.prototype.menubarHeight;
- this.refresh();
- this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronUpImage + '\')';
- }
- else
- {
- this.menubar.container.style.position = 'relative';
- this.menubar.container.style.paddingLeft = '4px';
- this.menubar.container.style.paddingTop = '0px';
- this.menubar.container.style.paddingBottom = '0px';
- this.menubar.container.style.top = '0px';
- this.toolbar.container.style.paddingLeft = '4px';
- this.buttonContainer.style.visibility = 'hidden';
- this.appIcon.style.display = 'none';
- this.fnameWrapper.style.display = 'none';
- this.fnameWrapper.style.visibility = 'hidden';
- this.menubarHeight = EditorUi.prototype.menubarHeight;
- this.refresh();
- this.toggleElement.style.backgroundImage = 'url(\'' + this.chevronDownImage + '\')';
- }
- };
- /**
- * Adds the listener for automatically saving the diagram for local changes.
- */
- App.prototype.updateUserElement = function()
- {
- if ((this.drive == null || this.drive.getUser() == null) &&
- (this.oneDrive == null || this.oneDrive.getUser() == null) &&
- (this.dropbox == null || this.dropbox.getUser() == null) &&
- (this.gitHub == null || this.gitHub.getUser() == null))
- {
- if (this.userElement != null)
- {
- this.userElement.parentNode.removeChild(this.userElement);
- this.userElement = null;
- }
- }
- else
- {
- if (this.userElement == null)
- {
- this.userElement = document.createElement('a');
- this.userElement.setAttribute('href', 'javascript:void(0);');
- this.userElement.className = 'geItem';
- this.userElement.style.position = 'absolute';
- this.userElement.style.fontSize = '8pt';
- this.userElement.style.top = '4px';
- this.userElement.style.right = '30px';
- this.userElement.style.color = '#666';
- this.userElement.style.margin = '4px';
- this.userElement.style.padding = '2px';
- this.userElement.style.paddingRight = '16px';
- this.userElement.style.verticalAlign = 'middle';
- this.userElement.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
- this.userElement.style.backgroundPosition = '100% 60%';
- this.userElement.style.backgroundRepeat = 'no-repeat';
-
- this.menubarContainer.appendChild(this.userElement);
- mxEvent.addListener(this.userElement, 'click', mxUtils.bind(this, function(evt)
- {
- if (this.userPanel == null)
- {
- var div = document.createElement('div');
- div.className = 'geDialog';
- div.style.position = 'absolute';
- div.style.top = (this.userElement.clientTop + this.userElement.clientHeight + 6) + 'px';
- div.style.right = '36px';
- div.style.padding = '0px';
- this.userPanel = div;
- }
-
- if (this.userPanel.parentNode != null)
- {
- this.userPanel.parentNode.removeChild(this.userPanel);
- }
- else
- {
- var connected = false;
- this.userPanel.innerHTML = '';
-
- var img = document.createElement('img');
- img.setAttribute('src', Dialog.prototype.closeImage);
- img.setAttribute('title', mxResources.get('close'));
- img.className = 'geDialogClose';
- img.style.top = '8px';
- img.style.right = '8px';
-
- mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
- {
- if (this.userPanel.parentNode != null)
- {
- this.userPanel.parentNode.removeChild(this.userPanel);
- }
- }));
-
- this.userPanel.appendChild(img);
-
- if (this.drive != null)
- {
- var driveUser = this.drive.getUser();
-
- if (driveUser != null)
- {
- connected = true;
- this.userPanel.innerHTML += '<table title="User ID: ' + driveUser.id +
- '" style="font-size:10pt;padding:20px 20px 10px 10px;">' +
- '<tr><td valign="top">' +
- ((driveUser.pictureUrl != null) ?
- '<img style="margin-right:10px;border-radius:50%;" src="' + driveUser.pictureUrl + '"/>' :
- '<img style="margin-right:4px;margin-top:2px;" src="' + this.defaultUserPicture + '"/>') +
- '</td><td valign="top" style="white-space:nowrap;' +
- ((driveUser.pictureUrl != null) ? 'padding-top:14px;' : '') +
- '"><b>' + mxUtils.htmlEntities(driveUser.displayName) + '</b><br>' +
- '<small>' + mxUtils.htmlEntities(driveUser.email) + '</small></tr></table>';
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.padding = '12px';
- div.style.background = 'whiteSmoke';
- div.style.borderTop = '1px solid #e0e0e0';
- div.style.whiteSpace = 'nowrap';
- // LATER: Cannot change user while file is open since close will not work with new
- // credentials and closing the file using fileLoaded(null) will show splash dialog.
- div.appendChild(mxUtils.button(mxResources.get('signOut'), mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- if (file != null && file.constructor == DriveFile)
- {
- this.confirm(mxResources.get('areYouSure'), mxUtils.bind(this, function()
- {
- this.spinner.spin(document.body, mxResources.get('signOut'));
-
- this.diagramContainer.style.display = 'none';
- this.formatContainer.style.display = 'none';
- this.hsplit.style.display = 'none';
- this.sidebarContainer.style.display = 'none';
- this.sidebarFooterContainer.style.display = 'none';
-
- if (this.tabContainer != null)
- {
- this.tabContainer.style.display = 'none';
- }
-
- file.close();
-
- // LATER: Use callback to wait for thumbnail update
- window.setTimeout(mxUtils.bind(this, function()
- {
- // Workaround to disable the splash screen before reload
- this.showDialog = function() {};
- window.location.hash = '';
- this.drive.clearUserId();
- gapi.auth.signOut();
-
- // Reload page to reset client auth
- window.location.reload();
- }), (file != null && file.constructor == DriveFile) ? 2000 : 0);
- }));
- }
- else
- {
- this.drive.clearUserId();
- this.drive.setUser(null);
- gapi.auth.signOut();
- }
- })));
-
- this.userPanel.appendChild(div);
- }
- }
-
- var addUser = mxUtils.bind(this, function(user, logo, logout)
- {
- if (user != null)
- {
- if (connected)
- {
- this.userPanel.appendChild(document.createElement('hr'));
- }
-
- connected = true;
- this.userPanel.innerHTML += '<table style="font-size:10pt;padding:20px 20px 10px 10px;"><tr><td valign="top">' +
- ((logo != null) ? '<img style="margin-right:10px;" src="' + logo + '" width="40" height="40"/></td>' : '') +
- '<td valign="middle" style="white-space:nowrap;"><b>' + mxUtils.htmlEntities(user.displayName) + '</b>' +
- ((user.email != null) ? '<br><font color="gray">' + mxUtils.htmlEntities(user.email) + '</font></td>' : '') +
- '</tr></table>';
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.padding = '12px';
- div.style.background = 'whiteSmoke';
- div.style.borderTop = '1px solid #e0e0e0';
- div.style.whiteSpace = 'nowrap';
-
- if (logout != null)
- {
- div.appendChild(mxUtils.button(mxResources.get('signOut'), logout));
- }
-
- this.userPanel.appendChild(div);
- }
- });
-
- if (this.dropbox != null)
- {
- addUser(this.dropbox.getUser(), IMAGE_PATH + '/dropbox-logo.svg', mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- if (file != null && file.constructor == DropboxFile)
- {
- var doLogout = mxUtils.bind(this, function()
- {
- this.dropbox.logout();
- window.location.hash = '';
- });
-
- if (!file.isModified())
- {
- doLogout();
- }
- else
- {
- this.confirm(mxResources.get('allChangesLost'), null, doLogout,
- mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- }
- else
- {
- this.dropbox.logout();
- }
- }));
- }
- if (this.oneDrive != null)
- {
- addUser(this.oneDrive.getUser(), IMAGE_PATH + '/onedrive-logo.svg', mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- if (file != null && file.constructor == OneDriveFile)
- {
- var doLogout = mxUtils.bind(this, function()
- {
- this.oneDrive.logout();
- window.location.hash = '';
- });
-
- if (!file.isModified())
- {
- doLogout();
- }
- else
- {
- this.confirm(mxResources.get('allChangesLost'), null, doLogout,
- mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- }
- else
- {
- this.oneDrive.logout();
- }
- }));
- }
- if (this.gitHub != null)
- {
- addUser(this.gitHub.getUser(), IMAGE_PATH + '/github-logo.svg', mxUtils.bind(this, function()
- {
- var file = this.getCurrentFile();
- if (file != null && file.constructor == GitHubFile)
- {
- var doLogout = mxUtils.bind(this, function()
- {
- this.gitHub.logout();
- window.location.hash = '';
- });
-
- if (!file.isModified())
- {
- doLogout();
- }
- else
- {
- this.confirm(mxResources.get('allChangesLost'), null, doLogout,
- mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- }
- else
- {
- this.gitHub.logout();
- }
- }));
- }
-
- if (!connected)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.padding = '20px 20px 10px 10px';
- div.innerHTML = mxResources.get('notConnected');
-
- this.userPanel.appendChild(div);
- }
- document.body.appendChild(this.userPanel);
- }
-
- mxEvent.consume(evt);
- }));
-
- mxEvent.addListener(document.body, 'click', mxUtils.bind(this, function(evt)
- {
- if (!mxEvent.isConsumed(evt) && this.userPanel != null && this.userPanel.parentNode != null)
- {
- this.userPanel.parentNode.removeChild(this.userPanel);
- }
- }));
- }
-
- var user = null;
-
- if (this.drive != null && this.drive.getUser() != null)
- {
- user = this.drive.getUser();
- }
- else if (this.oneDrive != null && this.oneDrive.getUser() != null)
- {
- user = this.oneDrive.getUser();
- }
- else if (this.dropbox != null && this.dropbox.getUser() != null)
- {
- user = this.dropbox.getUser();
- }
- else if (this.gitHub != null && this.gitHub.getUser() != null)
- {
- user = this.gitHub.getUser();
- }
-
- if (user != null)
- {
- this.userElement.innerHTML = '';
-
- if (screen.width > 560)
- {
- mxUtils.write(this.userElement, user.displayName);
- this.userElement.style.display = 'block';
- }
- }
- else
- {
- this.userElement.style.display = 'none';
- }
- }
- };
- /**
- * Override depends on mxSettings which is not defined in the minified viewer.
- */
- var editorResetGraph = Editor.prototype.resetGraph;
- Editor.prototype.resetGraph = function()
- {
- editorResetGraph.apply(this, arguments);
-
- // Overrides default with persisted value
- this.graph.pageFormat = mxSettings.getPageFormat();
- };
|