12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516 |
- /**
- * Copyright (c) 2006-2017, JGraph Ltd
- * Copyright (c) 2006-2017, Gaudenz Alder
- */
- (function()
- {
- // Adds scrollbars for menus that exceed the page height
- var mxPopupMenuShowMenu = mxPopupMenu.prototype.showMenu;
- mxPopupMenu.prototype.showMenu = function()
- {
- mxPopupMenuShowMenu.apply(this, arguments);
-
- this.div.style.overflowY = 'auto';
- this.div.style.overflowX = 'hidden';
- var h0 = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
- this.div.style.maxHeight = (h0 - 10) + 'px';
- };
-
- Menus.prototype.addLinkToItem = function(item, href)
- {
- if (item != null)
- {
- var link = document.createElement('span');
- link.setAttribute('title', mxResources.get('help'));
- link.style.cssText = 'color:blue;text-decoration:underline;margin-left:12px;cursor:help;';
-
- var icon = document.createElement('img');
- icon.setAttribute('border', '0');
- icon.setAttribute('valign', 'bottom');
- icon.setAttribute('src', Editor.helpImage);
- link.appendChild(icon);
-
- mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
- {
- this.editorUi.menubar.hideMenu();
- window.open(href);
- mxEvent.consume(evt);
- }));
-
- item.firstChild.nextSibling.appendChild(link);
- }
- };
- var menusInit = Menus.prototype.init;
- Menus.prototype.init = function()
- {
- menusInit.apply(this, arguments);
- var editorUi = this.editorUi;
- var graph = editorUi.editor.graph;
- var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled);
- var googleEnabled = ((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
- (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && mxClient.IS_SVG &&
- isLocalStorage && (document.documentMode == null || document.documentMode >= 10);
- var dropboxEnabled = ((urlParams['embed'] != '1' && urlParams['db'] != '0') || (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
- mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
- var oneDriveEnabled = (window.location.hostname == 'www.draw.io' || window.location.hostname == 'test.draw.io' ||
- window.location.hostname == 'drive.draw.io' || window.location.hostname == 'legacy.draw.io') &&
- (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
- urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
- (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10));
- if (!editorUi.isOffline())
- {
- var img = new Image();
- img.src = IMAGE_PATH + '/help.png';
- }
-
- editorUi.actions.addAction('new...', function()
- {
- var compact = editorUi.isOffline();
- var dlg = new NewDialog(editorUi, compact);
- editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
- {
- if (cancel && editorUi.getCurrentFile() == null)
- {
- editorUi.showSplash();
- }
- });
-
- dlg.init();
- });
-
- // Export PDF action for chrome OS (same as print with different dialog title)
- editorUi.actions.addAction('exportPdf', function()
- {
- editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
- (editorUi.pages != null && editorUi.pages.length > 1) ?
- 420 : 360, true, true);
- });
-
- editorUi.actions.addAction('open...', function()
- {
- editorUi.pickFile();
- });
-
- editorUi.actions.addAction('close', function()
- {
- editorUi.fileLoaded(null);
- });
-
- editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
- {
- var cells = graph.getSelectionCells();
-
- if (graph.getSelectionCount() == 1)
- {
- var cell = graph.getSelectionCell();
- var state = graph.view.getState(cell);
-
- if (state != null && state.shape != null && state.shape.stencil != null)
- {
- var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
- editorUi.showDialog(dlg.container, 640, 480, true, false);
- dlg.init();
- }
- }
- }));
-
- editorUi.actions.addAction('revisionHistory...', function()
- {
- var file = editorUi.getCurrentFile();
-
- if (file == null || (file.constructor != DriveFile && file.constructor != DropboxFile) ||
- (editorUi.drive == null && file.constructor == DriveFile) ||
- (editorUi.dropbox == null && file.constructor == DropboxFile))
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
- }
- else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- if (file.constructor == DropboxFile)
- {
- // Limit is maximum number of entries to return
- var promise = editorUi.dropbox.client.filesListRevisions({path: file.stat.path_lower, limit: 100});
- promise.then(mxUtils.bind(this, function(response)
- {
- editorUi.spinner.stop();
-
- try
- {
- var revs = [];
-
- for (var i = response.entries.length - 1; i >= 0; i--)
- {
- (function(stat)
- {
- revs.push({modifiedDate: stat.client_modified, fileSize: stat.size, getXml: function(success, error)
- {
- editorUi.dropbox.readFile({path: file.stat.path_lower, rev: stat.rev}, success, error);
- }, getUrl: function()
- {
- return editorUi.getUrl(window.location.pathname + '?rev=' + stat.rev + '&chrome=0&edit=_blank') + window.location.hash;
- }});
- })(response.entries[i]);
- }
-
- var dlg = new RevisionDialog(editorUi, revs);
- editorUi.showDialog(dlg.container, 640, 480, true, true);
- dlg.init();
- }
- catch (e)
- {
- editorUi.handleError(e);
- }
- }));
- // Workaround for IE8/9 support with catch function
- promise['catch'](function(err)
- {
- editorUi.spinner.stop();
- editorUi.handleError(err);
- });
- }
- // Google Drive File
- else
- {
- editorUi.drive.executeRequest(gapi.client.drive.revisions.list({'fileId': file.getId()}), function(resp)
- {
- editorUi.spinner.stop();
-
- for (var i = 0; i < resp.items.length; i++)
- {
- (function(item)
- {
- item.getXml = function(success, error)
- {
- // Workaround for vanished head revision is to use current head revision from descriptor
- editorUi.drive.executeRequest(gapi.client.drive.revisions.get({'fileId': file.getId(),
- 'revisionId': (resp.items[resp.items.length - 1] === item) ?
- file.desc.headRevisionId : item.id}), function(resp)
- {
- editorUi.drive.getXmlFile(resp, null, function(file2)
- {
- success(file2.getData());
- }, function(resp)
- {
- error(resp);
- });
- }, function(resp)
- {
- error(resp);
- });
- };
-
- item.getUrl = function()
- {
- return editorUi.getUrl(window.location.pathname + '?rev=' + item.id + '&chrome=0&edit=_blank') + window.location.hash;
- };
- })(resp.items[i]);
- }
-
- var dlg = new RevisionDialog(editorUi, resp.items);
- editorUi.showDialog(dlg.container, 640, 480, true, true);
- dlg.init();
- }, function(resp)
- {
- editorUi.spinner.stop();
- editorUi.handleError(resp);
- });
- }
- }
- });
-
- editorUi.actions.addAction('createRevision', function()
- {
- editorUi.actions.get('save').funct();
- }, null, null, 'Ctrl+S');
- editorUi.actions.addAction('upload...', function()
- {
- var file = editorUi.getCurrentFile();
-
- if (file != null)
- {
- // Data is pulled from global variable after tab loads
- // LATER: Change to use message passing to deal with potential cross-domain
- window.drawdata = editorUi.getFileData();
- var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
- window.open(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
- ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
- 'title=' + encodeURIComponent(filename));
- }
- });
- if (typeof(MathJax) !== 'undefined')
- {
- var action = editorUi.actions.addAction('mathematicalTypesetting', function()
- {
- editorUi.setMathEnabled(!editorUi.isMathEnabled());
- });
-
- action.setToggleAction(true);
- action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
- action.isEnabled = isGraphEnabled;
- }
-
- if (isLocalStorage)
- {
- var action = editorUi.actions.addAction('showStartScreen', function()
- {
- mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
- mxSettings.save();
- });
-
- action.setToggleAction(true);
- action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
- }
- var autosaveAction = editorUi.actions.addAction('autosave', function()
- {
- editorUi.editor.setAutosave(!editorUi.editor.autosave);
- });
-
- autosaveAction.setToggleAction(true);
- autosaveAction.setSelectedCallback(function()
- {
- return autosaveAction.isEnabled() && editorUi.editor.autosave;
- });
- editorUi.actions.addAction('editGeometry...', function()
- {
- var cells = graph.getSelectionCells();
- var vertices = [];
-
- for (var i = 0; i < cells.length; i++)
- {
- if (graph.getModel().isVertex(cells[i]))
- {
- vertices.push(cells[i]);
- }
- }
-
- if (vertices.length > 0)
- {
- var dlg = new EditGeometryDialog(editorUi, vertices);
- editorUi.showDialog(dlg.container, 180, 180, true, true);
- dlg.init();
- }
- }, null, null, 'Ctrl+Shift+M');
- var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle',
- 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
- 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
- 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
- 'endSize', 'startStill', 'startArrow', 'startSize', 'arcSize'];
-
- editorUi.actions.addAction('copyStyle', function()
- {
- var state = graph.view.getState(graph.getSelectionCell());
-
- if (graph.isEnabled() && state != null)
- {
- editorUi.copiedStyle = mxUtils.clone(state.style);
-
- // Handles special case for value "none"
- var cellStyle = graph.getModel().getStyle(state.cell);
- var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
-
- for (var j = 0; j < tokens.length; j++)
- {
- var tmp = tokens[j];
- var pos = tmp.indexOf('=');
-
- if (pos >= 0)
- {
- var key = tmp.substring(0, pos);
- var value = tmp.substring(pos + 1);
-
- if (editorUi.copiedStyle[key] == null && value == 'none')
- {
- editorUi.copiedStyle[key] = 'none';
- }
- }
- }
- }
- }, null, null, 'Ctrl+Shift+C');
- editorUi.actions.addAction('pasteStyle', function()
- {
- if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
- {
- graph.getModel().beginUpdate();
-
- try
- {
- var cells = graph.getSelectionCells();
-
- for (var i = 0; i < cells.length; i++)
- {
- var state = graph.view.getState(cells[i]);
-
- for (var j = 0; j < copiedStyles.length; j++)
- {
- var key = copiedStyles[j];
- var value = editorUi.copiedStyle[key];
-
- if (state.style[key] != value)
- {
- graph.setCellStyles(key, value, [cells[i]]);
- }
- }
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
- }
- }, null, null, 'Ctrl+Shift+V');
-
- editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
- {
- if (!editorUi.isOffline())
- {
- var apply = function(image)
- {
- editorUi.setBackgroundImage(image);
- };
-
- var dlg = new BackgroundImageDialog(editorUi, apply);
- editorUi.showDialog(dlg.container, 320, 170, true, true);
- dlg.init();
- }
- }));
-
- action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
- {
- graph.setShadowVisible(!graph.shadowVisible);
- }));
- action.setToggleAction(true);
- action.setSelectedCallback(function() { return graph.shadowVisible; });
- editorUi.actions.put('about', new Action(mxResources.get('aboutDrawio') + '...', function()
- {
- editorUi.showDialog(new AboutDialog(editorUi).container, 220, 300, true, true);
- }, null, null, 'F1'));
-
- editorUi.actions.addAction('userManual...', function()
- {
- window.open('https://support.draw.io/display/DO/Draw.io+Online+User+Manual');
- });
- editorUi.actions.addAction('support...', function()
- {
- window.open('https://support.draw.io/display/DO/draw.io+Online+Support');
- });
- editorUi.actions.addAction('exportOptionsDisabled...', function()
- {
- editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
- mxResources.get('exportOptionsDisabled'));
- });
- editorUi.actions.addAction('keyboardShortcuts...', function()
- {
- if (mxClient.IS_CHROMEAPP)
- {
- window.open('https://www.draw.io/shortcuts.svg');
- }
- else if (mxClient.IS_SVG)
- {
- window.open('shortcuts.svg');
- }
- else
- {
- window.open('https://www.draw.io/?lightbox=1#Uhttps%3A%2F%2Fwww.draw.io%2Fshortcuts.svg');
- }
- });
- editorUi.actions.addAction('feedback...', function()
- {
- var dlg = new FeedbackDialog(editorUi);
- editorUi.showDialog(dlg.container, 610, 360, true, true);
- dlg.init();
- });
- editorUi.actions.addAction('quickStart...', function()
- {
- window.open('https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1');
- });
-
- action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
- {
- if (this.tagsWindow == null)
- {
- this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 280, 120);
- this.tagsWindow.window.addListener('show', function()
- {
- editorUi.fireEvent(new mxEventObject('tags'));
- });
- this.tagsWindow.window.addListener('hide', function()
- {
- editorUi.fireEvent(new mxEventObject('tags'));
- });
- this.tagsWindow.window.setVisible(true);
- editorUi.fireEvent(new mxEventObject('tags'));
- }
- else
- {
- this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
- }
- }));
- action.setToggleAction(true);
- action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
-
- action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
- {
- if (this.findWindow == null)
- {
- this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 204, 140);
- this.findWindow.window.addListener('show', function()
- {
- editorUi.fireEvent(new mxEventObject('find'));
- });
- this.findWindow.window.addListener('hide', function()
- {
- editorUi.fireEvent(new mxEventObject('find'));
- });
- this.findWindow.window.setVisible(true);
- editorUi.fireEvent(new mxEventObject('find'));
- }
- else
- {
- this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
- }
- }));
- action.setToggleAction(true);
- action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
- // Adds language menu to options only if localStorage is available for
- // storing the choice. We do not want to use cookies for older browsers.
- // Note that the URL param lang=XX is available for setting the language
- // in older browsers. URL param has precedence over the saved setting.
- if (mxClient.IS_CHROMEAPP || (isLocalStorage && urlParams['offline'] != '1'))
- {
- this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- var addLangItem = mxUtils.bind(this, function (id)
- {
- var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
- var item = null;
-
- if (lang != '')
- {
- item = menu.addItem(lang, null, mxUtils.bind(this, function()
- {
- mxSettings.setLanguage(id);
- mxSettings.save();
-
- // Shows dialog in new language
- mxClient.language = id;
- mxResources.loadDefaultBundle = false;
- mxResources.add(RESOURCE_BASE);
-
- editorUi.alert(mxResources.get('restartForChangeRequired'));
- }), parent);
-
- if (id == mxLanguage || (id == '' && mxLanguage == null))
- {
- menu.addCheckmark(item, Editor.checkmarkImage);
- }
- }
-
- return item;
- });
-
- var item = addLangItem('');
- menu.addSeparator(parent);
- // LATER: Sort menu by language name
- for(var langId in mxLanguageMap)
- {
- addLangItem(langId);
- }
- })));
- // Extends the menubar with the language menu
- if (uiTheme != 'atlas')
- {
- var menusCreateMenuBar = Menus.prototype.createMenubar;
- Menus.prototype.createMenubar = function(container)
- {
- var menubar = menusCreateMenuBar.apply(this, arguments);
-
- if (menubar != null)
- {
- var langMenu = this.get('language');
-
- if (langMenu != null)
- {
- var elt = menubar.addMenu('', langMenu.funct);
- elt.setAttribute('title', mxResources.get('language'));
- elt.style.width = '16px';
- elt.style.paddingTop = '2px';
- elt.style.paddingLeft = '4px';
- elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
- elt.style.zIndex = '1';
- elt.style.position = 'absolute';
- elt.style.top = '2px';
- elt.style.right = '17px';
- elt.style.display = 'block';
-
- if (!mxClient.IS_VML)
- {
- mxUtils.setOpacity(elt, 60);
- }
-
- document.body.appendChild(elt);
- }
- }
-
- return menubar;
- };
- }
- }
-
- this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
- {
- this.addMenuItems(menu, ['about']);
- }
- else
- {
- // No translation for menu item since help is english only
- var item = menu.addItem('Search', null, null, parent, null, null, false);
-
- var form = document.createElement('div');
- form.style.display = 'inline';
- form.innerHTML = ':<form style="display:inline;margin-left:8px;"' +
- 'target="_blank" method="get" action="https://desk.draw.io/support/search/solutions">' +
- '<input type="text" name="term" size="25"></form>';
- item.firstChild.nextSibling.appendChild(form);
- item.style.backgroundColor = 'whiteSmoke';
- item.style.cursor = 'default';
-
- var realForm = form.getElementsByTagName('form')[0]
- var input = form.getElementsByTagName('input')[0];
-
- if (input != null && realForm != null)
- {
- mxEvent.addListener(realForm, 'submit', function()
- {
- // Logs search terms for improving search results
- if (EditorUi.enableLogging)
- {
- try
- {
- var img = new Image();
- var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
- img.src = logDomain + '/log?severity=CONFIG&msg=helpsearch:' + encodeURIComponent(input.value) + '&v=' + encodeURIComponent(EditorUi.VERSION);
- }
- catch (e)
- {
- // ignore
- }
- }
-
- // Workaround for blocked submit on iOS/IE11
- window.setTimeout(function()
- {
- editorUi.menubar.hideMenu();
- }, 0);
- });
-
- mxEvent.addGestureListeners(item, function(evt)
- {
- if (document.activeElement != input)
- {
- input.focus();
- }
-
- mxEvent.consume(evt);
- }, function(evt)
- {
- mxEvent.consume(evt);
- }, function(evt)
- {
- mxEvent.consume(evt);
- });
- // Sets initial focus on input element
- window.setTimeout(function()
- {
- input.focus();
- }, 0);
- }
- this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-']);
-
- if (!mxClient.IS_CHROMEAPP)
- {
- this.addMenuItems(menu, ['feedback']);
- }
- this.addMenuItems(menu, ['support', '-', 'about']);
- }
- if (urlParams['test'] == '1')
- {
- // For showing the bounding box
- mxResources.parse('showBoundingBox=Show bounding box');
-
- this.editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
- {
- var b = graph.getGraphBounds();
- var tr = graph.view.translate;
- var s = graph.view.scale;
- graph.insertVertex(parent, null, '', b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s, 'fillColor=none;strokeColor=red;');
- }));
- this.addMenuItems(menu, ['-', 'showBoundingBox'], parent);
- // For testing local XML export
- mxResources.parse('testXmlImageExport=XML Image Export');
-
- this.editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
- {
- var bg = '#ffffff';
- var scale = 1;
- var b = 1;
-
- var imgExport = new mxImageExport();
- var bounds = graph.getGraphBounds();
- var vs = graph.view.scale;
-
- // New image export
- var xmlDoc = mxUtils.createXmlDocument();
- var root = xmlDoc.createElement('output');
- xmlDoc.appendChild(root);
-
- // Renders graph. Offset will be multiplied with state's scale when painting state.
- var xmlCanvas = new mxXmlCanvas2D(root);
- xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
- xmlCanvas.scale(scale / vs);
-
- var stateCounter = 0;
-
- var canvasSave = xmlCanvas.save;
- xmlCanvas.save = function()
- {
- stateCounter++;
- canvasSave.apply(this, arguments);
- };
-
- var canvasRestore = xmlCanvas.restore;
- xmlCanvas.restore = function()
- {
- stateCounter--;
- canvasRestore.apply(this, arguments);
- };
-
- var exportDrawShape = imgExport.drawShape;
- imgExport.drawShape = function(state)
- {
- mxLog.debug('entering shape', state, stateCounter);
- exportDrawShape.apply(this, arguments);
- mxLog.debug('leaving shape', state, stateCounter);
- };
-
- imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
-
- // Puts request data together
- var w = Math.ceil(bounds.width * scale / vs + 2 * b);
- var h = Math.ceil(bounds.height * scale / vs + 2 * b);
-
- mxLog.show();
- mxLog.debug(mxUtils.getXml(root));
- mxLog.debug('stateCounter', stateCounter);
- }));
-
- this.addMenuItems(menu, ['testXmlImageExport'], parent);
- mxResources.parse('testShowRtModel=Show RT model');
- mxResources.parse('testDebugRtModel=Debug RT model');
- mxResources.parse('testDownloadRtModel=Download RT model');
-
- this.editorUi.actions.addAction('testShowRtModel', mxUtils.bind(this, function()
- {
- if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
- {
- console.log('bytesUsed', this.editorUi.getCurrentFile().realtime.rtModel.bytesUsed);
- console.log('root', this.editorUi.getCurrentFile().realtime.dumpRoot());
- this.editorUi.getCurrentFile().realtime.check();
- }
- }));
-
- this.editorUi.actions.addAction('testDebugRtModel', mxUtils.bind(this, function()
- {
- gapi.drive.realtime.debug();
- }));
-
- this.editorUi.actions.addAction('testDownloadRtModel', mxUtils.bind(this, function()
- {
- var file = this.editorUi.getCurrentFile();
-
- if (file != null && file.realtime != null &&
- editorUi.spinner.spin(document.body, mxResources.get('export')))
- {
- // LATER: Download full model dump with history
- var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
- file.getHash().substring(1) + '/realtime', null, 'GET');
- // Adds auth token
- req.setRequestHeaders = function(request)
- {
- mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
- var token = gapi.auth.getToken().access_token;
- request.setRequestHeader('authorization', 'Bearer ' + token);
- };
-
- req.send(function(req)
- {
- editorUi.spinner.stop();
-
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- editorUi.saveLocalFile(req.getText(), 'realtime.txt', 'text/plain');
- }
- });
- }
- }));
- if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
- {
- this.addMenuItems(menu, ['-', 'testShowRtModel', 'testDebugRtModel', 'testDownloadRtModel'], parent);
- }
-
- mxResources.parse('testShowConsole=Show Console');
- this.editorUi.actions.addAction('testShowConsole', function()
- {
- if (!mxLog.isVisible())
- {
- mxLog.show();
- }
- else
- {
- mxLog.window.fit();
- }
-
- mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
- });
- this.addMenuItems(menu, ['-', 'testShowConsole']);
- }
- })));
- editorUi.actions.addAction('shapes...', function()
- {
- if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
- {
- editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
- ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
- }
- else
- {
- editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
- ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
- }
- });
- editorUi.actions.addAction('createShape...', function()
- {
- var file = editorUi.getCurrentFile();
-
- if (urlParams['embed'] == '1' || (file != null && file.isEditable()))
- {
- var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
- cell.vertex = true;
-
- var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
- editorUi.showDialog(dlg.container, 640, 480, true, false);
- dlg.init();
- }
- });
-
- editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
-
- editorUi.showHtmlDialog(mxResources.get('create'), 'https://desk.draw.io/support/solutions/articles/16000042542',
- url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, edit)
- {
- editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
- fit, allPages, layers, lightbox, edit, mxUtils.bind(this, function(html, scriptTag)
- {
- var dlg = new EmbedDialog(editorUi, html + '\n' + scriptTag, null, null, function()
- {
- var wnd = window.open();
- var doc = wnd.document;
-
- if (document.compatMode === 'CSS1Compat')
- {
- doc.writeln('<!DOCTYPE html>');
- }
-
- doc.writeln('<html>');
- doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
- '</title><meta charset="utf-8"></head>');
- doc.writeln('<body>');
- doc.writeln(html);
-
- var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
-
- if (direct)
- {
- doc.writeln(scriptTag);
- }
-
- doc.writeln('</body>');
- doc.writeln('</html>');
- doc.close();
-
- // Adds script tag after closing page and delay to fix timing issues
- if (!direct)
- {
- var info = wnd.document.createElement('div');
- info.marginLeft = '26px';
- info.marginTop = '26px';
- mxUtils.write(info, mxResources.get('updatingDocument'));
- var img = wnd.document.createElement('img');
- img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
- '/' + IMAGE_PATH + '/spin.gif');
- img.style.marginLeft = '6px';
- info.appendChild(img);
-
- wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
-
- window.setTimeout(function()
- {
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
- doc.body.appendChild(script);
-
- info.parentNode.removeChild(info);
- }, 20);
- }
- });
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- }));
- });
- });
- }
- }));
-
- editorUi.actions.put('liveImage', new Action('Live image...', function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
-
- if (url != null)
- {
- var encUrl = encodeURIComponent(url);
- var dlg = new EmbedDialog(editorUi, EXPORT_URL + '?format=png&url=' + encUrl, 0);
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- }
- else
- {
- editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
- }
- });
- }
- }));
-
- editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
- {
- editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, edit, layers)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.createEmbedImage(fit, shadow, retina, lightbox, edit, layers, function(result)
- {
- editorUi.spinner.stop();
- var dlg = new EmbedDialog(editorUi, result);
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- }, function(err)
- {
- editorUi.spinner.stop();
- editorUi.handleError(err);
- });
- }
- }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
- }));
- editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
- {
- editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, edit, layers)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.createEmbedSvg(fit, shadow, image, lightbox, edit, layers, function(result)
- {
- editorUi.spinner.stop();
-
- var dlg = new EmbedDialog(editorUi, result);
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- }, function(err)
- {
- editorUi.spinner.stop();
- editorUi.handleError(err);
- });
- }
- }, mxResources.get('formatSvg'), mxResources.get('image'),
- true, 'https://desk.draw.io/support/solutions/articles/16000042548');
- }));
-
- editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
- {
- var bounds = graph.getGraphBounds();
-
- editorUi.showPublishLinkDialog(mxResources.get('iframe'), null, '100%',
- (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / graph.view.scale) + 2),
- function(linkTarget, linkColor, allPages, lightbox, edit, layers, width, height)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
-
- var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
- ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
- allPages, lightbox, edit, layers, url) + '"></iframe>');
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- });
- }
- }, true);
- }));
-
- editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
- {
- editorUi.showPublishLinkDialog(null, null, null, null,
- function(linkTarget, linkColor, allPages, lightbox, edit, layers)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
- var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
- linkColor, allPages, lightbox, edit, layers, url));
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- });
- }
- });
- }));
- editorUi.actions.addAction('googleDocs...', function()
- {
- window.open('http://docsaddon.draw.io');
- });
- editorUi.actions.addAction('googleSites...', function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
- var dlg = new GoogleSitesDialog(editorUi, url);
- editorUi.showDialog(dlg.container, 420, 256, true, true);
- dlg.init();
- });
- }
- });
- // Adds plugins menu item in file menu only if localStorage is available for
- // storing the plugins.
- if (isLocalStorage || mxClient.IS_CHROMEAPP)
- {
- var action = editorUi.actions.addAction('scratchpad', function()
- {
- editorUi.toggleScratchpad();
- });
-
- action.setToggleAction(true);
- action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
- editorUi.actions.addAction('plugins...', function()
- {
- editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
- });
- }
-
- var action = editorUi.actions.addAction('search', function()
- {
- var visible = editorUi.sidebar.isEntryVisible('search');
- editorUi.sidebar.showPalette('search', !visible);
-
- if (isLocalStorage)
- {
- mxSettings.settings.search = !visible;
- mxSettings.save();
- }
- });
-
- action.setToggleAction(true);
- action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
-
- if (urlParams['embed'] == '1')
- {
- editorUi.actions.get('save').funct = function(exit)
- {
- if (graph.isEditing())
- {
- graph.stopEditing();
- }
-
- var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
- editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
-
- if (urlParams['proto'] == 'json')
- {
- var msg = editorUi.createLoadMessage('save');
- msg.xml = data;
-
- if (exit)
- {
- msg.exit = true;
- }
-
- data = JSON.stringify(msg);
- }
-
- var parent = window.opener || window.parent;
- parent.postMessage(data, '*');
-
- if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
- {
- editorUi.editor.modified = false;
- editorUi.editor.setStatus('');
- }
- };
-
- editorUi.actions.addAction('saveAndExit', function()
- {
- editorUi.actions.get('save').funct(true);
- });
-
- editorUi.actions.addAction('exit', function()
- {
- var fn = function()
- {
- var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
- modified: editorUi.editor.modified}) : '';
- var parent = window.opener || window.parent;
- parent.postMessage(msg, '*');
- }
-
- if (!editorUi.editor.modified)
- {
- fn();
- }
- else
- {
- editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
- mxResources.get('cancel'), mxResources.get('discardChanges'));
- }
- });
- }
-
- this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- if (editorUi.isExportToCanvas())
- {
- menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
- {
- // TODO: Enable include option if CRC is fixed
- editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
- 'https://support.draw.io/display/DO/Exporting+Files',
- mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
- addShadow, editable, embedImages, border, cropImage, currentPage)
- {
- var val = parseInt(scale);
-
- if (!isNaN(val) && val > 0)
- {
- this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection,
- addShadow, editable, border, !cropImage, currentPage);
- }
- }), true, false);
- }), parent);
-
- if (editorUi.jpgSupported)
- {
- menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
- {
- editorUi.showExportJpgDialog('https://support.draw.io/display/DO/Exporting+Files',
- mxUtils.bind(this, function(scale, ignoreSelection, addShadow, border, cropImage)
- {
- var val = parseInt(scale);
-
- if (!isNaN(val) && val > 0)
- {
- this.editorUi.exportImage(val / 100, false, ignoreSelection,
- addShadow, false, border, !cropImage, false, 'jpeg');
- }
- }), true);
- }), parent);
- }
- }
-
- // Disabled for standalone mode in iOS because new tab cannot be closed
- else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
- {
- menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
- {
- editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
- {
- this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
- }));
- }), parent);
-
- menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
- {
- editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
- {
- this.editorUi.downloadFile('jpeg', null, null, ignoreSelection);
- }), true);
- }), parent);
- }
-
- menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
- {
- editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
- 'https://support.draw.io/display/DO/Exporting+Files',
- mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
- addShadow, editable, embedImages, border, cropImage, currentPage)
- {
- var val = parseInt(scale);
-
- if (!isNaN(val) && val > 0)
- {
- this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection,
- addShadow, editable, embedImages, border, !cropImage, currentPage);
- }
- }), true);
- }), parent);
- menu.addSeparator(parent);
- // Redirects export to PDF to print in Chrome App
- if (editorUi.isOffline() || editorUi.printPdfExport)
- {
- menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('exportPdf').funct, parent);
- }
- // Disabled for standalone mode in iOS because new tab cannot be closed
- else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
- {
- menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
- {
- var div = document.createElement('div');
- div.style.whiteSpace = 'nowrap';
-
- var hd = document.createElement('h3');
- mxUtils.write(hd, mxResources.get('formatPdf'));
- hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
- div.appendChild(hd);
-
- var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
- false, graph.isSelectionEmpty());
- var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
- !graph.pageVisible || !editorUi.pdfPageExport,
- !editorUi.pdfPageExport);
- crop.style.marginBottom = '16px';
-
- // Crop is only enabled if selection only is selected
- if (!editorUi.pdfPageExport)
- {
- mxEvent.addListener(selection, 'change', function()
- {
- if (selection.checked)
- {
- crop.removeAttribute('disabled');
- }
- else
- {
- crop.setAttribute('disabled', 'disabled');
- }
- });
- }
-
- var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
- {
- this.editorUi.downloadFile('pdf', null, null, !selection.checked, null, !crop.checked);
- }), null, mxResources.get('export'));
- this.editorUi.showDialog(dlg.container, 300, 146, true, true);
- }), parent);
- }
- menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
- {
- editorUi.spinner.stop();
-
- editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
- initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, edit)
- {
- editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
- fit, allPages, layers, lightbox, edit, mxUtils.bind(this, function(html, scriptTag)
- {
- var basename = editorUi.getBaseFilename();
- var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
- '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
- '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
- editorUi.saveData(basename + '.html', 'html', result, 'text/html');
- }));
- });
- });
- }
-
- //this.editorUi.downloadFile('html');
- }), parent);
- if (!editorUi.isOfflineApp() && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
- {
- menu.addItem(mxResources.get('formatVsdx') + '...', null, mxUtils.bind(this, function()
- {
- var delayed = mxUtils.bind(this, function()
- {
- // Checks for signature method
- if (typeof(VsdxExport) !== 'undefined')
- {
- try
- {
- new VsdxExport(editorUi).exportCurrentDiagrams();
- }
- catch (e)
- {
- // ignore
- }
- }
- });
-
- if (typeof(VsdxExport) === 'undefined' && !this.loadingVsdx && !editorUi.isOffline())
- {
- this.loadingVsdx = true;
- // Dependencies included in Devel.js
- mxscript('/js/vsdx.min.js', delayed);
- }
- else
- {
- // Must be async for cell selection
- window.setTimeout(delayed, 0);
- }
- }), parent);
- }
- menu.addSeparator(parent);
- menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
- {
- var div = document.createElement('div');
- div.style.whiteSpace = 'nowrap';
- var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
-
- var hd = document.createElement('h3');
- mxUtils.write(hd, mxResources.get('formatXml'));
- hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
- div.appendChild(hd);
-
- var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
- false, graph.isSelectionEmpty());
- var pages = editorUi.addCheckbox(div, mxResources.get((noPages) ? 'compressed' : 'allPages'), true);
- pages.style.marginBottom = '16px';
-
- mxEvent.addListener(selection, 'change', function()
- {
- if (selection.checked)
- {
- pages.setAttribute('disabled', 'disabled');
- }
- else
- {
- pages.removeAttribute('disabled');
- }
- });
-
- var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
- {
- editorUi.downloadFile('xml', (noPages) ? !pages.checked : null, null,
- !selection.checked, (!noPages) ? !pages.checked : null);
- }), null, mxResources.get('export'));
- this.editorUi.showDialog(dlg.container, 300, 146, true, true);
- }), parent);
- // Disables menu item for all external hosted integrations
- if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp ||/.*\.draw\.io$/.test(window.location.hostname))
- {
- menu.addItem(mxResources.get('url') + '...', null, mxUtils.bind(this, function()
- {
- editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
- function(linkTarget, linkColor, allPages, lightbox, edit, layers)
- {
- var dlg = new EmbedDialog(editorUi, editorUi.createLink(
- linkTarget, linkColor, allPages, lightbox, edit, layers, null, true));
- editorUi.showDialog(dlg.container, 440, 240, true, true);
- dlg.init();
- });
- }), parent);
- }
-
- if (!editorUi.isOffline())
- {
- menu.addSeparator(parent);
- this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
- }
- })));
- this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
-
- this.put('importFrom', new Menu(function(menu, parent)
- {
- function importFile(device)
- {
- if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
- {
- var input = document.createElement('input');
- input.setAttribute('type', 'file');
-
- mxEvent.addListener(input, 'change', function()
- {
- if (input.files != null)
- {
- // Using null for position will disable crop of input file
- editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
- }
- });
- input.click();
- }
- else
- {
- window.openNew = false;
- window.openKey = 'import';
-
- var prevValue = Editor.useLocalStorage;
- Editor.useLocalStorage = !device;
-
- // Closes dialog after open
- window.openFile = new OpenFile(function(cancel)
- {
- editorUi.hideDialog(cancel);
- });
-
- window.openFile.setConsumer(function(xml, filename)
- {
- graph.setSelectionCells(editorUi.importXml(xml));
- });
-
- // Removes openFile if dialog is closed
- editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
- {
- window.openFile = null;
- });
-
- // Extends dialog close to show splash screen
- var dlg = editorUi.dialog;
- var dlgClose = dlg.close;
-
- editorUi.dialog.close = function(cancel)
- {
- Editor.useLocalStorage = prevValue;
- dlgClose.apply(dlg, arguments);
-
- if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
- {
- editorUi.showSplash();
- }
- };
- }
- };
-
- var doImportFile = mxUtils.bind(this, function(data, mime, filename)
- {
- // Gets insert location
- var view = graph.view;
- var bds = graph.getGraphBounds();
- var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
- var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
- if (data.substring(0, 11) == 'data:image/')
- {
- editorUi.loadImage(data, mxUtils.bind(this, function(img)
- {
- editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
- {
- var s = Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2));
- editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
- {
- editorUi.spinner.stop();
- graph.setSelectionCells(cells);
- graph.scrollCellToVisible(graph.getSelectionCell());
- });
- }), true);
- }), mxUtils.bind(this, function()
- {
- editorUi.handleError({message: mxResources.get('cannotOpenFile')});
- }));
- }
- else
- {
- editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
- {
- editorUi.spinner.stop();
- graph.setSelectionCells(cells);
- graph.scrollCellToVisible(graph.getSelectionCell());
- });
- }
- });
-
- var getMimeType = mxUtils.bind(this, function(filename)
- {
- var mime = 'text/xml';
-
- if (/\.png$/i.test(filename))
- {
- mime = 'image/png';
- }
- else if (/\.jpe?g$/i.test(filename))
- {
- mime = 'image/jpg';
- }
- else if (/\.gif$/i.test(filename))
- {
- mime = 'image/gif';
- }
-
- return mime;
- });
-
- function pickFileFromService(service)
- {
- // Drive requires special arguments for libraries and bypassing realtime
- service.pickFile(function(id)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- // NOTE The third argument in getFile says denyConvert to match
- // the existing signature in the original DriveClient which has
- // as slightly different semantic, but works the same way.
- service.getFile(id, function(file)
- {
- var mime = getMimeType(file.getTitle());
-
- // Imports SVG as images
- if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
- {
- file.setData(editorUi.createSvgDataUri(file.getData()));
- mime = 'image/svg+xml';
- }
-
- doImportFile(file.getData(), mime, file.getTitle());
- },
- function(resp)
- {
- editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
- }, service == editorUi.drive);
- }
- }, true);
- };
-
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- if (editorUi.drive != null)
- {
- // Requires special arguments for libraries and realtime
- menu.addItem(mxResources.get('googleDrive') + '...', null, function()
- {
- pickFileFromService(editorUi.drive);
- }, parent);
- }
- else if (googleEnabled)
- {
- menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
- }
-
- if (editorUi.gitHub != null)
- {
- menu.addItem(mxResources.get('github') + '...', null, function()
- {
- pickFileFromService(editorUi.gitHub);
- }, parent);
- }
- if (editorUi.dropbox != null)
- {
- menu.addItem(mxResources.get('dropbox') + '...', null, function()
- {
- pickFileFromService(editorUi.dropbox);
- }, parent);
- }
- else if (dropboxEnabled)
- {
- menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- if (editorUi.oneDrive != null)
- {
- menu.addItem(mxResources.get('oneDrive') + '...', null, function()
- {
- pickFileFromService(editorUi.oneDrive);
- }, parent);
- }
- else if (oneDriveEnabled)
- {
- menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- menu.addSeparator(parent);
- if (isLocalStorage && urlParams['browser'] != '0')
- {
- menu.addItem(mxResources.get('browser') + '...', null, function()
- {
- importFile(false);
- }, parent);
- }
- if (!mxClient.IS_IOS)
- {
- menu.addItem(mxResources.get('device') + '...', null, function()
- {
- importFile(true);
- }, parent);
- }
- if (!editorUi.isOffline())
- {
- menu.addSeparator(parent);
-
- menu.addItem(mxResources.get('url') + '...', null, function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
- {
- if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
-
- // Uses proxy to avoid CORS issues
- editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
- {
- doImportFile(data, mime, fileUrl);
- },
- function ()
- {
- editorUi.spinner.stop();
- editorUi.handleError(null, mxResources.get('errorLoadingFile'));
- }, mime == 'image/png');
- }
- }, mxResources.get('url'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- }, parent);
- }
-
- menu.addItem(mxResources.get('csv') + '...', null, function()
- {
- editorUi.showImportCsvDialog();
- }, parent);
- })).isEnabled = isGraphEnabled;
- this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- var item = menu.addItem(mxResources.get('kennedy'), null, function()
- {
- mxSettings.setUi('');
- mxSettings.save();
- editorUi.alert(mxResources.get('restartForChangeRequired'));
- }, parent);
- if (uiTheme != 'atlas')
- {
- menu.addCheckmark(item, Editor.checkmarkImage);
- }
-
- item = menu.addItem(mxResources.get('atlas'), null, function()
- {
- mxSettings.setUi('atlas');
- mxSettings.save();
- editorUi.alert(mxResources.get('restartForChangeRequired'));
- }, parent);
-
- if (uiTheme == 'atlas')
- {
- menu.addCheckmark(item, Editor.checkmarkImage);
- }
- })));
- this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
- {
- var file = this.editorUi.getCurrentFile();
-
- if (file != null)
- {
- var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
-
- var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
- {
- if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
- {
- // Delete old file, save new file in dropbox if autosize is enabled
- file.rename(title, mxUtils.bind(this, function(resp)
- {
- this.editorUi.spinner.stop();
- }),
- mxUtils.bind(this, function(resp)
- {
- this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
- }));
- }
- }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
- mxResources.get('diagramName') : null, function(name)
- {
- if (name != null && name.length > 0)
- {
- return true;
- }
-
- editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
-
- return false;
- });
- this.editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- }
- })).isEnabled = isGraphEnabled;
-
- editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
- {
- var file = editorUi.getCurrentFile();
-
- if (file != null)
- {
- var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
-
- // Handles extension
- var extension = '';
- var dot = title.lastIndexOf('.');
-
- if (dot >= 0)
- {
- extension = title.substring(dot);
- title = title.substring(0, dot);
- }
-
- title = mxResources.get('copyOf', [title]) + extension;
-
- if (file.constructor == DriveFile)
- {
- var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
- {
- // Mode is "download" if Create button is pressed, means use Google Drive
- if (mode == 'download')
- {
- mode = App.MODE_GOOGLE;
- }
-
- if (newTitle != null && newTitle.length > 0)
- {
- if (mode == App.MODE_GOOGLE)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
- {
- // Makes sure the latest XML is in the file
- file.save(false, mxUtils.bind(this, function()
- {
- // Saveas does not update the file descriptor in Google Drive
- file.saveAs(newTitle, mxUtils.bind(this, function(resp)
- {
- editorUi.spinner.stop();
- var url = editorUi.getUrl();
- window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
- {
- window.location.hash = 'G' + resp.id;
- }));
- }), mxUtils.bind(this, function(resp)
- {
- editorUi.handleError(resp);
- }));
- }), mxUtils.bind(this, function(resp)
- {
- editorUi.handleError(resp);
- }));
- }
- }
- else
- {
- this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
- }
- }
- }), mxUtils.bind(this, function()
- {
- editorUi.hideDialog();
- }), mxResources.get('makeCopy'), mxResources.get('create'), null,
- null, null, null, true);
- editorUi.showDialog(dlg.container, 420, 380, true, true);
- dlg.init();
- }
- else
- {
- // Creates a copy with no predefined storage
- editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
- }
- }
- }));
-
- editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
- {
- var file = editorUi.getCurrentFile();
-
- if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
- {
- editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
- {
- file.move(folderId, mxUtils.bind(this, function(resp)
- {
- editorUi.spinner.stop();
- }), mxUtils.bind(this, function(resp)
- {
- editorUi.handleError(resp);
- }));
- }
- }));
- }
- }));
-
- this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- this.addMenuItems(menu, ['publishLink'], parent);
- })));
- editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
- {
- window.open('http://www.draw.io/app')
- }));
-
- editorUi.actions.put('chromeApp', new Action(mxResources.get('chromeApp') + '...', function()
- {
- window.open('https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla')
- }));
- this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
- {
- var file = this.editorUi.getCurrentFile();
-
- if (file != null)
- {
- this.editorUi.drive.showPermissions(file.getId());
- }
- }));
- this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- if (urlParams['test'] == '1')
- {
- this.addMenuItems(menu, ['liveImage', '-'], parent);
- }
-
- this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
-
- if (!navigator.standalone && !editorUi.isOffline())
- {
- this.addMenuItems(menu, ['embedIframe'], parent);
- }
- if (!editorUi.isOffline())
- {
- this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
- }
- })));
- var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
- var addInsertItem = function(menu, parent, title, method)
- {
- menu.addItem(title, null, mxUtils.bind(this, function()
- {
- if (method == 'fromText')
- {
- var dlg = new ParseDialog(editorUi, title);
- editorUi.showDialog(dlg.container, 620, 420, true, false);
- editorUi.dialog.container.style.overflow = 'auto';
- dlg.init();
- }
- else
- {
- var dlg = new CreateGraphDialog(editorUi, title, method);
- editorUi.showDialog(dlg.container, 620, 420, true, false);
- // Executed after dialog is added to dom
- dlg.init();
- }
- }), parent);
- };
-
- editorUi.actions.addAction('insertText', function()
- {
- if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
- {
- var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
- var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
- 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
- cell.vertex = true;
- graph.startEditingAtCell(graph.addCell(cell));
- }
- }, null, null, 'Ctrl+Shift+X').isEnabled = isGraphEnabled;
-
- editorUi.actions.addAction('insertRectangle', function()
- {
- if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
- {
- var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
- var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
- cell.vertex = true;
- graph.setSelectionCell(graph.addCell(cell));
- graph.scrollCellToVisible(graph.getSelectionCell());
- }
- }, null, null, 'Ctrl+K').isEnabled = isGraphEnabled;
-
- editorUi.actions.addAction('insertEllipse', function()
- {
- if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
- {
- var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
- var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
- cell.vertex = true;
- graph.setSelectionCell(graph.addCell(cell));
- graph.scrollCellToVisible(graph.getSelectionCell());
- }
- }, null, null, 'Ctrl+Shift+K').isEnabled = isGraphEnabled;
-
- this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
- menu.addSeparator(parent);
-
- for (var i = 0; i < methods.length; i++)
- {
- if (methods[i] == '-')
- {
- menu.addSeparator(parent);
- }
- else
- {
- addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
- }
- }
- })));
- this.put('openRecent', new Menu(function(menu, parent)
- {
- var recent = editorUi.getRecent();
- if (recent != null)
- {
- for (var i = 0; i < recent.length; i++)
- {
- (function(entry)
- {
- var modeKey = entry.mode;
-
- // Google and oneDrive use different keys
- if (modeKey == App.MODE_GOOGLE)
- {
- modeKey = 'googleDrive';
- }
- else if (modeKey == App.MODE_ONEDRIVE)
- {
- modeKey = 'oneDrive';
- }
-
- menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
- {
- editorUi.loadFile(entry.id);
- }, parent);
- })(recent[i]);
- }
- menu.addSeparator(parent);
- }
- menu.addItem(mxResources.get('reset'), null, function()
- {
- editorUi.resetRecent();
- }, parent);
- }));
-
- this.put('openFrom', new Menu(function(menu, parent)
- {
- if (editorUi.drive != null)
- {
- menu.addItem(mxResources.get('googleDrive') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_GOOGLE);
- }, parent);
- }
- else if (googleEnabled)
- {
- menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
- if (editorUi.gitHub != null)
- {
- menu.addItem(mxResources.get('github') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_GITHUB);
- }, parent);
- }
-
- if (editorUi.dropbox != null)
- {
- menu.addItem(mxResources.get('dropbox') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_DROPBOX);
- }, parent);
- }
- else if (dropboxEnabled)
- {
- menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- if (editorUi.oneDrive != null)
- {
- menu.addItem(mxResources.get('oneDrive') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_ONEDRIVE);
- }, parent);
- }
- else if (oneDriveEnabled)
- {
- menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- menu.addSeparator(parent);
- if (isLocalStorage && urlParams['browser'] != '0')
- {
- menu.addItem(mxResources.get('browser') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_BROWSER);
- }, parent);
- }
-
- if (!mxClient.IS_IOS)
- {
- menu.addItem(mxResources.get('device') + '...', null, function()
- {
- editorUi.pickFile(App.MODE_DEVICE);
- }, parent);
- }
- if (!editorUi.isOffline())
- {
- menu.addSeparator(parent);
-
- menu.addItem(mxResources.get('url') + '...', null, function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
- {
- if (fileUrl != null && fileUrl.length > 0)
- {
- if (editorUi.getCurrentFile() == null)
- {
- window.location.hash = '#U' + encodeURIComponent(fileUrl);
- }
- else
- {
- window.openWindow(((mxClient.IS_CHROMEAPP) ?
- 'https://www.draw.io/' : 'https://' + location.host + '/') +
- window.location.search + '#U' + encodeURIComponent(fileUrl));
- }
- }
- }, mxResources.get('url'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- }, parent);
- }
- }));
-
- this.put('newLibrary', new Menu(function(menu, parent)
- {
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- if (editorUi.drive != null)
- {
- menu.addItem(mxResources.get('googleDrive') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
- }, parent);
- }
- else if (googleEnabled)
- {
- menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
- }
-
- if (editorUi.gitHub != null)
- {
- menu.addItem(mxResources.get('github') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
- }, parent);
- }
-
- if (editorUi.dropbox != null)
- {
- menu.addItem(mxResources.get('dropbox') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
- }, parent);
- }
- else if (dropboxEnabled)
- {
- menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- if (editorUi.oneDrive != null)
- {
- menu.addItem(mxResources.get('oneDrive') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
- }, parent);
- }
- else if (oneDriveEnabled)
- {
- menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- menu.addSeparator(parent);
- if (isLocalStorage && urlParams['browser'] != '0')
- {
- menu.addItem(mxResources.get('browser') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
- }, parent);
- }
-
- if (!mxClient.IS_IOS)
- {
- menu.addItem(mxResources.get('device') + '...', null, function()
- {
- editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
- }, parent);
- }
- }));
-
- this.put('openLibraryFrom', new Menu(function(menu, parent)
- {
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
- {
- if (editorUi.drive != null)
- {
- menu.addItem(mxResources.get('googleDrive') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_GOOGLE);
- }, parent);
- }
- else if (googleEnabled)
- {
- menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
- }
-
- if (editorUi.gitHub != null)
- {
- menu.addItem(mxResources.get('github') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_GITHUB);
- }, parent);
- }
-
- if (editorUi.dropbox != null)
- {
- menu.addItem(mxResources.get('dropbox') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_DROPBOX);
- }, parent);
- }
- else if (dropboxEnabled)
- {
- menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- if (editorUi.oneDrive != null)
- {
- menu.addItem(mxResources.get('oneDrive') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_ONEDRIVE);
- }, parent);
- }
- else if (oneDriveEnabled)
- {
- menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
- {
- // do nothing
- }, parent, null, false);
- }
-
- menu.addSeparator(parent);
- if (isLocalStorage && urlParams['browser'] != '0')
- {
- menu.addItem(mxResources.get('browser') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_BROWSER);
- }, parent);
- }
-
- if (!mxClient.IS_IOS)
- {
- menu.addItem(mxResources.get('device') + '...', null, function()
- {
- editorUi.pickLibrary(App.MODE_DEVICE);
- }, parent);
- }
- if (!editorUi.isOffline())
- {
- menu.addSeparator(parent);
-
- menu.addItem(mxResources.get('url') + '...', null, function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
- {
- if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- var realUrl = fileUrl;
-
- if (!editorUi.isCorsEnabledForUrl(fileUrl))
- {
- realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
- }
-
- // Uses proxy to avoid CORS issues
- mxUtils.get(realUrl, function(req)
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- editorUi.spinner.stop();
-
- try
- {
- editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
- }
- catch (e)
- {
- editorUi.handleError(e, mxResources.get('errorLoadingFile'));
- }
- }
- else
- {
- editorUi.spinner.stop();
- editorUi.handleError(null, mxResources.get('errorLoadingFile'));
- }
- }, function()
- {
- editorUi.spinner.stop();
- editorUi.handleError(null, mxResources.get('errorLoadingFile'));
- });
- }
- }, mxResources.get('url'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- }, parent);
- }
- }));
-
- // Overrides edit menu to add find
- this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
- 'find', '-',
- 'editData', 'editTooltip', 'editStyle', '-', 'edit', '-', 'editLink', 'openLink', '-',
- 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
- })));
-
- // Overrides view menu to add search and scratchpad
- this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
- concat(['outline', 'layers', '-']));
- this.addMenuItems(menu, ['-', 'search'], parent);
-
- if (isLocalStorage || mxClient.IS_CHROMEAPP)
- {
- var item = this.addMenuItem(menu, 'scratchpad', parent);
-
- if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
- {
- this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
- }
- }
-
- this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
- 'scrollbars', 'tooltips', '-',
- 'grid', 'guides'], parent);
-
- if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
- {
- this.addMenuItem(menu, 'shadowVisible', parent);
- }
-
- this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
- 'resetView', 'zoomIn', 'zoomOut'], parent);
- })));
-
- this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- if (urlParams['embed'] != '1')
- {
- this.addSubmenu('theme', menu, parent);
- menu.addSeparator(parent);
- }
-
- this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
- if (typeof(MathJax) !== 'undefined')
- {
- var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
- this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
- }
- this.addMenuItems(menu, ['autosave', '-', 'createShape', 'editDiagram'], parent);
- menu.addSeparator(parent);
-
- if (urlParams['embed'] != '1' && isLocalStorage)
- {
- this.addMenuItems(menu, ['showStartScreen'], parent);
- }
- if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
- {
- this.addMenuItems(menu, ['plugins', '-'], parent);
-
- var item = this.addMenuItem(menu, 'tags', parent);
-
- if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
- {
- this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000046966');
- }
-
- this.addMenuItems(menu, ['-', 'offline'], parent);
- }
- else
- {
- menu.addSeparator(parent);
- this.addMenuItem(menu, 'tags', parent);
- menu.addSeparator(parent);
- }
-
- if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
- {
- this.addMenuItems(menu, ['chromeApp'], parent);
- }
- })));
- this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
- {
- if (urlParams['embed'] == '1')
- {
- this.addSubmenu('importFrom', menu, parent);
- this.addSubmenu('exportAs', menu, parent);
- this.addSubmenu('embed', menu, parent);
- if (urlParams['libraries'] == '1')
- {
- this.addMenuItems(menu, ['-'], parent);
- this.addSubmenu('newLibrary', menu, parent);
- this.addSubmenu('openLibraryFrom', menu, parent);
- }
-
- this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
-
- if (urlParams['saveAndExit'] == '1')
- {
- this.addMenuItems(menu, ['saveAndExit'], parent);
- }
-
- this.addMenuItems(menu, ['exit'], parent);
- }
- else
- {
- var file = this.editorUi.getCurrentFile();
-
- if (file != null && file.constructor == DriveFile)
- {
- if (file.isRestricted())
- {
- this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
- }
-
- if (file.realtime == null)
- {
- this.addMenuItems(menu, ['save', 'share', '-'], parent);
- }
- else
- {
- if (!file.isAutosave())
- {
- this.addMenuItems(menu, ['save'], parent);
- }
-
- this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
- }
- }
- else
- {
- this.addMenuItems(menu, ['new'], parent);
- }
-
- this.addSubmenu('openFrom', menu, parent);
- if (isLocalStorage)
- {
- this.addSubmenu('openRecent', menu, parent);
- }
-
- if (file != null && file.constructor == DriveFile)
- {
- this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
- }
- else
- {
- this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
-
- if (editorUi.isOfflineApp())
- {
- if (!editorUi.isOffline())
- {
- this.addMenuItems(menu, ['upload'], parent);
- }
- }
- else
- {
- this.addMenuItems(menu, ['makeCopy'], parent);
-
- if (file != null && file.constructor == OneDriveFile)
- {
- this.addMenuItems(menu, ['moveToFolder'], parent);
- }
- }
- }
-
- menu.addSeparator(parent);
- this.addSubmenu('importFrom', menu, parent);
- this.addSubmenu('exportAs', menu, parent);
- menu.addSeparator(parent);
- this.addSubmenu('embed', menu, parent);
- this.addSubmenu('publish', menu, parent);
- menu.addSeparator(parent);
- this.addSubmenu('newLibrary', menu, parent);
- this.addSubmenu('openLibraryFrom', menu, parent);
-
- if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
- {
- this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
- }
-
- if (file != null && file.constructor == DriveFile)
- {
- this.addMenuItems(menu, ['createRevision'], parent);
- }
- this.addMenuItems(menu, ['-', 'pageSetup'], parent);
-
- // Cannot use print in standalone mode on iOS as we cannot open new windows
- if (!mxClient.IS_IOS || !navigator.standalone)
- {
- this.addMenuItems(menu, ['print'], parent);
- }
-
- this.addMenuItems(menu, ['-', 'close']);
- }
- })));
- };
- /**
- * Replaces help menu label with icon on small screen
- */
- var menuCreated = Menus.prototype.menuCreated;
-
- Menus.prototype.menuCreated = function(menu, elt)
- {
- if (screen.width <= 480 && menu == this.get('help'))
- {
- elt.style.paddingRight = '0px';
- elt.style.paddingLeft = '0px';
- elt.innerHTML = '';
-
- var icon = document.createElement('img');
- icon.setAttribute('border', '0');
- icon.setAttribute('valign', 'bottom');
- icon.setAttribute('src', Editor.helpImage);
- elt.appendChild(icon);
- }
-
- menuCreated.apply(this, arguments);
- };
- })();
|