/*
* $Id: Dialogs.js,v 1.103 2014/02/11 14:08:15 gaudenz Exp $
* Copyright (c) 2006-2010, JGraph Ltd
*/
var StorageDialog = function(editorUi, fn)
{
var div = document.createElement('div');
div.style.textAlign = 'center';
div.style.whiteSpace = 'nowrap';
var elt = editorUi.addLanguageMenu(div);
var bottom = '28px';
if (elt != null)
{
elt.style.bottom = bottom;
}
if (!editorUi.isOffline() && editorUi.getServiceCount() > 1)
{
var help = document.createElement('a');
help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
help.setAttribute('title', mxResources.get('help'));
help.setAttribute('target', '_blank');
help.style.position = 'absolute';
help.style.textDecoration = 'none';
help.style.cursor = 'pointer';
help.style.fontSize = '12px';
help.style.bottom = bottom;
help.style.left = '26px';
help.style.color = 'gray';
mxUtils.write(help, mxResources.get('help'));
div.appendChild(help);
}
var demo = document.createElement('div');
demo.style.position = 'absolute';
demo.style.cursor = 'pointer';
demo.style.fontSize = '12px';
demo.style.bottom = bottom;
demo.style.color = 'gray';
mxUtils.write(demo, mxResources.get('decideLater'));
if (editorUi.isOfflineApp())
{
demo.style.right = '20px';
}
else
{
mxUtils.setPrefixedStyle(demo.style, 'transform', 'translate(-50%,0)');
demo.style.left = '50%';
}
this.init = function()
{
if (mxClient.IS_QUIRKS || document.documentMode == 8)
{
demo.style.marginLeft = -Math.round(demo.clientWidth / 2) + 'px';
}
};
div.appendChild(demo);
mxEvent.addListener(demo, 'click', function()
{
editorUi.hideDialog();
var prev = Editor.useLocalStorage;
editorUi.createFile(editorUi.defaultFilename, null, null, App.MODE_DEVICE);
editorUi.setMode(null);
Editor.useLocalStorage = prev;
});
var buttons = document.createElement('div');
if (mxClient.IS_QUIRKS)
{
buttons.style.whiteSpace = 'nowrap';
buttons.style.cssFloat = 'left';
}
buttons.style.border = '1px solid #d3d3d3';
buttons.style.borderWidth = '1px 0px 1px 0px';
buttons.style.padding = '26px 0px 12px 0px';
var cb = document.createElement('input');
cb.setAttribute('type', 'checkbox');
cb.setAttribute('checked', 'checked');
cb.defaultChecked = true;
function addLogo(img, title, mode, clientName)
{
var button = document.createElement('a');
button.style.overflow = 'hidden';
var logo = document.createElement('img');
logo.setAttribute('src', img);
logo.setAttribute('border', '0');
logo.setAttribute('align', 'absmiddle');
logo.style.width = '60px';
logo.style.height = '60px';
logo.style.paddingBottom = '6px';
button.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
button.className = 'geBaseButton';
button.style.position = 'relative';
button.style.margin = '4px';
button.style.padding = '8px 10px 12px 10px';
button.style.whiteSpace = 'nowrap';
// Workaround for quirks is a vertical list (limited to max 2 items)
if (mxClient.IS_QUIRKS)
{
button.style.cssFloat = 'left';
button.style.zoom = '1';
}
button.appendChild(logo);
var label = document.createElement('div');
button.appendChild(label);
mxUtils.write(label, title);
function initButton()
{
mxEvent.addListener(button, 'click', function()
{
// Special case: Redirect all drive users to draw.io pro
if (mode == App.MODE_GOOGLE && !editorUi.isDriveDomain())
{
window.location.hostname = DriveClient.prototype.newAppHostname;
}
else if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
{
// Tries immediate authentication
editorUi.drive.checkToken(mxUtils.bind(this, function()
{
editorUi.spinner.stop();
editorUi.setMode(mode, cb.checked);
fn();
}));
}
else
{
editorUi.setMode(mode, cb.checked);
fn();
}
});
};
// Supports lazy loading
if (clientName != null && editorUi[clientName] == null)
{
logo.style.visibility = 'hidden';
mxUtils.setOpacity(label, 10);
var size = 12;
var spinner = new Spinner({
lines: 12, // The number of lines to draw
length: size, // The length of each line
width: 5, // The line thickness
radius: 10, // The radius of the inner circle
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1.5, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
top: '40%',
zIndex: 2e9 // The z-index (defaults to 2000000000)
});
spinner.spin(button);
// Timeout after 30 secs
var timeout = window.setTimeout(function()
{
if (editorUi[clientName] == null)
{
spinner.stop();
button.style.display = 'none';
}
}, 30000);
editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
{
if (editorUi[clientName] != null)
{
window.clearTimeout(timeout);
mxUtils.setOpacity(label, 100);
logo.style.visibility = '';
spinner.stop();
initButton();
}
}));
}
else
{
initButton();
}
buttons.appendChild(button);
};
var hd = document.createElement('p');
hd.style.fontSize = '16pt';
hd.style.padding = '0px';
hd.style.paddingTop = '4px';
hd.style.paddingBottom = '20px';
hd.style.margin = '0px';
hd.style.color = 'gray';
mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
div.appendChild(hd);
if (typeof window.DriveClient === 'function')
{
addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
}
if (typeof window.DropboxClient === 'function')
{
addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
}
if (typeof window.OneDriveClient === 'function')
{
addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
}
if (!mxClient.IS_IOS || urlParams['storage'] == 'device')
{
addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
}
if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
{
addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
}
div.appendChild(buttons);
var p2 = document.createElement('p');
p2.style.paddingTop = '10px';
p2.appendChild(cb);
var span = document.createElement('span');
span.style.color = 'gray';
span.style.fontSize = '12px';
mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
p2.appendChild(span);
buttons.appendChild(p2);
mxEvent.addListener(span, 'click', function(evt)
{
cb.checked = !cb.checked;
mxEvent.consume(evt);
});
// Checks if Google Drive is missing after a 5 sec delay
if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
(document.documentMode == null || document.documentMode >= 10))
{
window.setTimeout(function()
{
if (editorUi.drive == null)
{
// To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
// chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
var p3 = document.createElement('p');
p3.style.padding = '8px';
p3.style.fontSize = '9pt';
p3.style.marginTop = '-14px';
p3.innerHTML = '' +
' ' +
mxResources.get('googleDriveMissingClickHere') + '';
div.appendChild(p3);
}
}, 5000);
}
this.container = div;
};
/**
* Constructs a dialog for creating new files from templates.
*/
var SplashDialog = function(editorUi)
{
var div = document.createElement('div');
div.style.textAlign = 'center';
editorUi.addLanguageMenu(div);
var help = null;
var serviceCount = editorUi.getServiceCount();
if (!editorUi.isOffline() && serviceCount > 1)
{
help = document.createElement('a');
help.setAttribute('href', 'https://support.draw.io/display/DO/Selecting+Storage');
help.setAttribute('title', mxResources.get('help'));
help.setAttribute('target', '_blank');
help.style.position = 'absolute';
help.style.fontSize = '12px';
help.style.textDecoration = 'none';
help.style.cursor = 'pointer';
help.style.bottom = '22px';
help.style.left = '26px';
help.style.color = 'gray';
mxUtils.write(help, mxResources.get('help'));
div.appendChild(help);
}
var hd = document.createElement('p');
hd.style.fontSize = '16pt';
hd.style.padding = '0px';
hd.style.paddingTop = '2px';
hd.style.margin = '0px';
hd.style.color = 'gray';
var logo = document.createElement('img');
logo.setAttribute('border', '0');
logo.setAttribute('align', 'absmiddle');
logo.style.width = '40px';
logo.style.height = '40px';
logo.style.marginRight = '12px';
logo.style.paddingBottom = '4px';
var service = '';
if (editorUi.mode == App.MODE_GOOGLE)
{
logo.src = IMAGE_PATH + '/google-drive-logo.svg';
service = mxResources.get('googleDrive');
if (help != null)
{
help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Google+Drive');
}
}
else if (editorUi.mode == App.MODE_DROPBOX)
{
logo.src = IMAGE_PATH + '/dropbox-logo.svg';
service = mxResources.get('dropbox');
if (help != null)
{
help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+Dropbox');
}
}
else if (editorUi.mode == App.MODE_ONEDRIVE)
{
logo.src = IMAGE_PATH + '/onedrive-logo.svg';
service = mxResources.get('oneDrive');
if (help != null)
{
help.setAttribute('href', 'https://support.draw.io/display/DO/Using+draw.io+with+OneDrive');
}
}
else if (editorUi.mode == App.MODE_BROWSER)
{
logo.src = IMAGE_PATH + '/osa_database.png';
service = mxResources.get('browser');
}
else
{
logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
service = mxResources.get('device');
}
hd.appendChild(logo);
mxUtils.write(hd, service);
div.appendChild(hd);
var buttons = document.createElement('div');
if (mxClient.IS_QUIRKS)
{
buttons.style.whiteSpace = 'nowrap';
buttons.style.cssFloat = 'left';
}
buttons.style.border = '1px solid #d3d3d3';
buttons.style.borderWidth = '1px 0px 1px 0px';
buttons.style.padding = '18px 0px 24px 0px';
buttons.style.margin = '4px 0px 0px 0px';
var btn = document.createElement('button');
btn.className = 'geBigButton';
btn.style.marginBottom = '8px';
btn.style.overflow = 'hidden';
btn.style.width = '340px';
if (mxClient.IS_QUIRKS)
{
btn.style.width = '340px';
}
mxUtils.write(btn, mxResources.get('createNewDiagram'));
mxEvent.addListener(btn, 'click', function()
{
editorUi.hideDialog();
editorUi.actions.get('new').funct();
});
buttons.appendChild(btn);
mxUtils.br(buttons);
var btn = document.createElement('button');
btn.className = 'geBigButton';
btn.style.marginBottom = '22px';
btn.style.overflow = 'hidden';
btn.style.width = '340px';
if (mxClient.IS_QUIRKS)
{
btn.style.width = '340px';
}
mxUtils.write(btn, mxResources.get('openExistingDiagram'));
mxEvent.addListener(btn, 'click', function()
{
editorUi.actions.get('open').funct();
});
buttons.appendChild(btn);
var storage = 'undefined';
if (editorUi.mode == App.MODE_GOOGLE)
{
storage = mxResources.get('googleDrive');
}
else if (editorUi.mode == App.MODE_DROPBOX)
{
storage = mxResources.get('dropbox');
}
else if (editorUi.mode == App.MODE_ONEDRIVE)
{
storage = mxResources.get('oneDrive');
}
else if (editorUi.mode == App.MODE_DEVICE)
{
storage = mxResources.get('device');
}
else if (editorUi.mode == App.MODE_BROWSER)
{
storage = mxResources.get('browser');
}
if (serviceCount > 1)
{
var link = document.createElement('a');
link.setAttribute('href', 'javascript:void(0)');
link.style.display = 'block';
link.style.marginTop = '6px';
mxUtils.write(link, mxResources.get('notUsingService', [storage]));
mxEvent.addListener(link, 'click', function()
{
editorUi.hideDialog(false);
editorUi.clearMode();
editorUi.showSplash(true);
});
buttons.appendChild(link);
var driveUser = (editorUi.drive != null) ? editorUi.drive.getUser() : null;
if (editorUi.mode == App.MODE_GOOGLE && driveUser != null)
{
btn.style.marginBottom = '24px';
var link = document.createElement('a');
link.setAttribute('href', 'javascript:void(0)');
link.style.display = 'block';
link.style.marginTop = '2px';
mxUtils.write(link, mxResources.get('changeUser') + ' (' + driveUser.displayName + ')');
// Makes room after last big buttons
btn.style.marginBottom = '16px';
buttons.style.paddingBottom = '18px';
mxEvent.addListener(link, 'click', function()
{
editorUi.hideDialog();
editorUi.drive.clearUserId();
editorUi.drive.setUser(null);
gapi.auth.signOut();
// Restores current dialog after clearing user
editorUi.setMode(App.MODE_GOOGLE);
editorUi.hideDialog();
editorUi.showSplash();
// FIXME: Does not force showing the auth dialog if only one user is logged in
editorUi.drive.authorize(false, mxUtils.bind(this, mxUtils.bind(this, function()
{
editorUi.hideDialog();
editorUi.showSplash();
})), mxUtils.bind(this, function(resp)
{
editorUi.handleError(resp, null, function()
{
editorUi.hideDialog();
editorUi.showSplash();
});
}));
});
buttons.appendChild(link);
}
}
div.appendChild(buttons);
// Changes Chrome App dialog
if (serviceCount < 2)
{
hd.style.paddingTop = '12px';
hd.innerHTML = '';
mxUtils.write(hd, mxResources.get('chooseAnOption') + ':');
buttons.style.border = 'none';
buttons.style.padding = '16px 0px 0px 0px';
btn.style.marginBottom = '0px';
}
this.init = function()
{
if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
{
var fn = function()
{
var oneDriveUser = editorUi.oneDrive.getUser();
if (oneDriveUser != null)
{
btn.style.marginBottom = '24px';
var link = document.createElement('a');
link.setAttribute('href', 'javascript:void(0)');
link.style.display = 'block';
link.style.marginTop = '2px';
mxUtils.write(link, mxResources.get('changeUser') + ' (' + oneDriveUser.displayName + ')');
// Makes room after last big buttons
btn.style.marginBottom = '16px';
buttons.style.paddingBottom = '18px';
mxEvent.addListener(link, 'click', function()
{
editorUi.oneDrive.logout();
link.parentNode.removeChild(link);
// NOTE: Could use userEvent=true here but it seems the logout
// call is asynchronous and the client isn't fully logged out
// when called immediately so we show the auth dialog to get
// a delay (sometimes event that is not enough so should use
// async callback on logout but that seems to be broken)
editorUi.oneDrive.execute(fn);
});
buttons.appendChild(link);
}
};
editorUi.oneDrive.execute(fn);
}
};
this.container = div;
};
/**
*
*/
var ConfirmDialog = function(editorUi, message, okFn, cancelFn, okLabel, cancelLabel)
{
var div = document.createElement('div');
div.style.textAlign = 'center';
var p2 = document.createElement('div');
p2.style.padding = '6px';
p2.style.overflow = 'auto';
p2.style.maxHeight = '40px';
if (mxClient.IS_QUIRKS)
{
p2.style.height = '60px';
}
mxUtils.write(p2, message);
div.appendChild(p2);
var btns = document.createElement('div');
btns.style.marginTop = '16px';
btns.style.textAlign = 'center';
var cancelBtn = mxUtils.button(cancelLabel || mxResources.get('cancel'), function()
{
editorUi.hideDialog();
if (cancelFn != null)
{
cancelFn();
}
});
cancelBtn.className = 'geBtn';
if (editorUi.editor.cancelFirst)
{
btns.appendChild(cancelBtn);
}
var okBtn = mxUtils.button(okLabel || mxResources.get('ok'), function()
{
editorUi.hideDialog();
if (okFn != null)
{
okFn();
}
});
btns.appendChild(okBtn);
okBtn.className = 'geBtn gePrimaryBtn';
if (!editorUi.editor.cancelFirst)
{
btns.appendChild(cancelBtn);
}
div.appendChild(btns);
this.container = div;
};
/**
*
*/
var ErrorDialog = function(editorUi, title, message, buttonText, fn, retry, buttonText2, fn2, hide)
{
hide = (hide != null) ? hide : true;
var div = document.createElement('div');
div.style.textAlign = 'center';
if (title != null)
{
var hd = document.createElement('div');
hd.style.padding = '0px';
hd.style.margin = '0px';
hd.style.fontSize = '18px';
hd.style.paddingBottom = '16px';
hd.style.marginBottom = '16px';
hd.style.borderBottom = '1px solid #c0c0c0';
hd.style.color = 'gray';
mxUtils.write(hd, title);
div.appendChild(hd);
}
var p2 = document.createElement('div');
p2.style.padding = '6px';
p2.innerHTML = message;
div.appendChild(p2);
var btns = document.createElement('div');
btns.style.marginTop = '16px';
btns.style.textAlign = 'right';
if (retry != null)
{
var retryBtn = mxUtils.button(mxResources.get('tryAgain'), function()
{
editorUi.hideDialog();
retry();
});
retryBtn.className = 'geBtn';
btns.appendChild(retryBtn);
btns.style.textAlign = 'center';
}
var btn = mxUtils.button(buttonText, function()
{
if (hide)
{
editorUi.hideDialog();
}
if (fn != null)
{
fn();
}
});
btn.className = 'geBtn';
btns.appendChild(btn);
if (buttonText2 != null)
{
var mainBtn = mxUtils.button(buttonText2, function()
{
if (hide)
{
editorUi.hideDialog();
}
if (fn2 != null)
{
fn2();
}
});
mainBtn.className = 'geBtn gePrimaryBtn';
btns.appendChild(mainBtn);
}
this.init = function()
{
btn.focus();
};
div.appendChild(btns);
this.container = div;
};
/**
* Constructs a new embed dialog
*/
var EmbedHtmlDialog = function(editorUi)
{
var file = editorUi.getCurrentFile();
var div = document.createElement('div');
var graph = editorUi.editor.graph;
var bounds = graph.getGraphBounds();
var scale = graph.view.scale;
var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
mxUtils.br(div);
var textarea = document.createElement('textarea');
textarea.style.marginTop = '6px';
textarea.style.width = '550px';
textarea.style.height = '160px';
textarea.style.marginBottom = '10px';
textarea.style.resize = 'none';
div.appendChild(textarea);
mxUtils.br(div);
mxUtils.write(div, mxResources.get('embedNotice') + ': ');
mxUtils.br(div);
var textarea2 = document.createElement('textarea');
textarea2.style.marginTop = '6px';
textarea2.style.width = '550px';
textarea2.style.height = '20px';
textarea2.style.resize = 'none';
textarea2.style.marginBottom = '10px';
div.appendChild(textarea2);
mxUtils.br(div);
mxUtils.write(div, mxResources.get('publicDiagramUrl') + ': ');
var urlInput = document.createElement('input');
urlInput.setAttribute('type', 'text');
urlInput.setAttribute('size', '28');
urlInput.style.width = '340px';
urlInput.style.marginBottom = '8px';
div.appendChild(urlInput);
mxUtils.br(div);
var options = document.createElement('div');
options.style.paddingTop = '10px';
options.style.textAlign = 'center';
var fitCheckBox = document.createElement('input');
fitCheckBox.setAttribute('type', 'checkbox');
fitCheckBox.setAttribute('checked', 'checked');
fitCheckBox.defaultChecked = true;
options.appendChild(fitCheckBox);
mxUtils.write(options, mxResources.get('fit'));
var label = document.createElement('span');
label.style.marginLeft = '10px';
mxUtils.write(label, mxResources.get('zoom') + ': ');
options.appendChild(label);
var zoomInput = document.createElement('input');
zoomInput.setAttribute('type', 'text');
zoomInput.setAttribute('size', '4');
zoomInput.style.width = '40px';
zoomInput.value = '100%';
options.appendChild(zoomInput);
var label = document.createElement('span');
label.style.marginLeft = '10px';
mxUtils.write(label, mxResources.get('link') + ': ');
options.appendChild(label);
var borderColorInput = document.createElement('input');
borderColorInput.setAttribute('type', 'text');
borderColorInput.setAttribute('size', '8');
borderColorInput.style.width = '50px';
borderColorInput.value = '#0000ff';
options.appendChild(borderColorInput);
mxUtils.br(options);
var lightboxCheckBox = document.createElement('input');
lightboxCheckBox.setAttribute('type', 'checkbox');
lightboxCheckBox.setAttribute('checked', 'checked');
lightboxCheckBox.defaultChecked = true;
lightboxCheckBox.style.marginTop = '14px';
options.appendChild(lightboxCheckBox);
mxUtils.write(options, mxResources.get('lightbox'));
var editCheckBox = document.createElement('input');
editCheckBox.setAttribute('type', 'checkbox');
editCheckBox.setAttribute('checked', 'checked');
editCheckBox.defaultChecked = true;
editCheckBox.style.marginLeft = '10px';
options.appendChild(editCheckBox);
mxUtils.write(options, mxResources.get('edit'));
var layersCheckBox = document.createElement('input');
layersCheckBox.setAttribute('type', 'checkbox');
layersCheckBox.style.marginLeft = '10px';
var model = editorUi.editor.graph.getModel();
if (editorUi.pages == null || editorUi.pages.length == 0 &&
(model.getChildCount(model.getRoot()) <= 1))
{
layersCheckBox.setAttribute('disabled', 'disabled');
}
else
{
layersCheckBox.setAttribute('checked', 'checked');
layersCheckBox.defaultChecked = true;
}
options.appendChild(layersCheckBox);
mxUtils.write(options, mxResources.get('layers'));
var zoomCheckBox = document.createElement('input');
zoomCheckBox.setAttribute('type', 'checkbox');
zoomCheckBox.style.marginLeft = '10px';
options.appendChild(zoomCheckBox);
mxUtils.write(options, mxResources.get('zoom'));
zoomCheckBox.setAttribute('checked', 'checked');
zoomCheckBox.defaultChecked = true;
var pagesCheckBox = document.createElement('input');
pagesCheckBox.setAttribute('type', 'checkbox');
pagesCheckBox.style.marginLeft = '10px';
if (editorUi.pages != null && editorUi.pages.length > 1)
{
pagesCheckBox.setAttribute('checked', 'checked');
pagesCheckBox.defaultChecked = true;
options.appendChild(pagesCheckBox);
}
mxUtils.write(options, mxResources.get('allPages'));
div.appendChild(options);
function update(force)
{
var s = editorUi.getBasenames();
var data = {};
if (borderColorInput.value != '' && borderColorInput.value != mxConstants.NONE)
{
data.highlight = borderColorInput.value;
}
if (!lightboxCheckBox.checked)
{
data.lightbox = false;
}
data.nav = graph.foldingEnabled;
var zoom = parseInt(zoomInput.value);
if (!isNaN(zoom) && zoom != 100)
{
data.zoom = zoom / 100;
}
var tb = [];
if (pagesCheckBox.checked)
{
tb.push('pages');
data.resize = true;
if (editorUi.pages != null && editorUi.currentPage != null)
{
data.page = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
}
}
if (zoomCheckBox.checked)
{
tb.push('zoom');
data.resize = true;
}
if (layersCheckBox.checked)
{
tb.push('layers');
}
if (tb.length > 0)
{
if (lightboxCheckBox)
{
tb.push('lightbox');
}
data.toolbar = tb.join(' ');
}
if (editCheckBox.checked)
{
if (urlInput.value != '')
{
data.edit = urlInput.value;
}
else
{
data.edit = '_blank';
}
}
if (urlInput.value != '')
{
data.url = urlInput.value;
}
else
{
data.xml = editorUi.getFileData(true, null, null, null, null, !pagesCheckBox.checked);
}
textarea.value = '
';
var s2 = (s.length > 0) ? (((urlParams['dev'] == '1') ?
'https://test.draw.io/embed2.js?dev=1&s=' :
'https://www.draw.io/embed2.js?s=') + s.join(';')) :
(((urlParams['dev'] == '1') ?
'https://test.draw.io/js/viewer.min.js' :
'https://www.draw.io/js/viewer.min.js'));
textarea2.value = '';
textarea.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
textarea.select();
}
else
{
document.execCommand('selectAll', false, null);
}
};
this.init = function()
{
update();
};
mxEvent.addListener(urlInput, 'change', update);
mxEvent.addListener(borderColorInput, 'change', update);
mxEvent.addListener(zoomInput, 'change', update);
mxEvent.addListener(layersCheckBox, 'change', update);
mxEvent.addListener(editCheckBox, 'change', update);
mxEvent.addListener(fitCheckBox, 'change', update);
mxEvent.addListener(lightboxCheckBox, 'change', update);
mxEvent.addListener(zoomCheckBox, 'change', update);
mxEvent.addListener(pagesCheckBox, 'change', update);
var buttons = document.createElement('div');
buttons.style.paddingTop = '20px';
buttons.style.textAlign = 'right';
if (!editorUi.isOffline())
{
var helpBtn = mxUtils.button(mxResources.get('help'), function()
{
window.open('https://desk.draw.io/solution/articles/16000042542-how-to-embed-html-');
});
helpBtn.className = 'geBtn';
buttons.appendChild(helpBtn);
}
// Loads forever in IE9
if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
(document.documentMode == null || document.documentMode > 9))
{
var previewBtn = mxUtils.button(mxResources.get('preview'), function()
{
var wnd = window.open();
var doc = wnd.document;
if (document.compatMode === 'CSS1Compat')
{
doc.writeln('');
}
doc.writeln('');
doc.writeln('' + encodeURIComponent(mxResources.get('preview')) +
'');
doc.writeln('');
doc.writeln(textarea.value);
var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
if (direct)
{
doc.writeln(textarea2.value);
}
doc.writeln('');
doc.writeln('');
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 = /= 5 || mxClient.IS_QUIRKS)
{
textarea.select();
}
else
{
document.execCommand('selectAll', false, null);
}
document.execCommand('copy');
editorUi.alert(mxResources.get('copiedToClipboard'));
});
buttons.appendChild(closeBtn);
// Does not work in Safari and shows annoying dialog for IE11-
if (!mxClient.IS_SF && document.documentMode == null)
{
buttons.appendChild(copyBtn);
copyBtn.className = 'geBtn gePrimaryBtn';
closeBtn.className = 'geBtn';
}
else
{
closeBtn.className = 'geBtn gePrimaryBtn';
}
div.appendChild(buttons);
this.container = div;
};
/**
* Constructs a new embed dialog
*/
var EmbedSvgDialog = function(editorUi, isImage)
{
var file = editorUi.getCurrentFile();
var div = document.createElement('div');
var graph = editorUi.editor.graph;
var bounds = graph.getGraphBounds();
var scale = graph.view.scale;
var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
mxUtils.write(div, mxResources.get('mainEmbedNotice') + ': ');
mxUtils.br(div);
var textarea = document.createElement('textarea');
textarea.style.marginTop = '6px';
textarea.style.width = '550px';
textarea.style.height = '280px';
textarea.style.resize = 'none';
div.appendChild(textarea);
mxUtils.br(div);
var options = document.createElement('div');
options.style.paddingTop = '16px';
options.style.textAlign = 'center';
var fitCheckBox = document.createElement('input');
fitCheckBox.setAttribute('type', 'checkbox');
fitCheckBox.setAttribute('checked', 'checked');
fitCheckBox.defaultChecked = true;
options.appendChild(fitCheckBox);
mxUtils.write(options, mxResources.get('fit'));
var shadowCheckBox = document.createElement('input');
shadowCheckBox.setAttribute('type', 'checkbox');
shadowCheckBox.style.marginLeft = '10px';
if (graph.shadowVisible)
{
shadowCheckBox.setAttribute('checked', 'checked');
shadowCheckBox.defaultChecked = true;
}
if (!isImage || editorUi.isExportToCanvas())
{
options.appendChild(shadowCheckBox);
mxUtils.write(options, mxResources.get('shadow'));
}
var imageCheckBox = document.createElement('input');
imageCheckBox.setAttribute('type', 'checkbox');
imageCheckBox.style.marginLeft = '10px';
if (!isImage)
{
options.appendChild(imageCheckBox);
mxUtils.write(options, mxResources.get('image'));
}
var retinaCheckBox = document.createElement('input');
retinaCheckBox.setAttribute('type', 'checkbox');
retinaCheckBox.style.marginLeft = '10px';
if (isImage)
{
options.appendChild(retinaCheckBox);
mxUtils.write(options, mxResources.get('retina'));
}
var lightboxCheckBox = document.createElement('input');
lightboxCheckBox.setAttribute('type', 'checkbox');
lightboxCheckBox.setAttribute('checked', 'checked');
lightboxCheckBox.defaultChecked = true;
lightboxCheckBox.style.marginLeft = '10px';
options.appendChild(lightboxCheckBox);
mxUtils.write(options, mxResources.get('lightbox'));
var editCheckBox = document.createElement('input');
editCheckBox.setAttribute('type', 'checkbox');
editCheckBox.setAttribute('checked', 'checked');
editCheckBox.defaultChecked = true;
editCheckBox.style.marginLeft = '10px';
options.appendChild(editCheckBox);
mxUtils.write(options, mxResources.get('edit'));
var layersCheckBox = document.createElement('input');
layersCheckBox.setAttribute('type', 'checkbox');
layersCheckBox.style.marginLeft = '10px';
var model = editorUi.editor.graph.getModel();
if (model.getChildCount(model.getRoot()) > 1)
{
layersCheckBox.setAttribute('checked', 'checked');
layersCheckBox.defaultChecked = true;
}
else
{
layersCheckBox.setAttribute('disabled', 'disabled');
}
options.appendChild(layersCheckBox);
mxUtils.write(options, mxResources.get('layers'));
div.appendChild(options);
function update(force)
{
if (isImage)
{
var bounds = editorUi.editor.graph.getGraphBounds();
function doUpdate(dataUri)
{
var onclick = ' ';
var css = '';
// Adds double click handling
if (lightboxCheckBox.checked)
{
// KNOWN: Message passing does not seem to work in IE11
onclick = " onclick=\"(function(img){if(img.wnd!=null&&!img.wnd.closed){img.wnd.focus();}else{var r=function(evt){if(evt.data=='ready'&&evt.source==img.wnd){img.wnd.postMessage(decodeURIComponent(" +
"img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0" +
((editCheckBox.checked) ? "&edit=_blank" : "") +
((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
css += 'cursor:pointer;';
}
if (fitCheckBox.checked)
{
css += 'max-width:100%;';
}
var atts = '';
if (retinaCheckBox.checked)
{
atts = ' width="' + Math.round(bounds.width) + '" height="' + Math.round(bounds.height) + '"';
}
textarea.value = '';
textarea.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
textarea.select();
}
else
{
document.execCommand('selectAll', false, null);
}
};
if (editorUi.isExportToCanvas())
{
var scale = 1;
var ignoreSelection = true;
textarea.value = mxResources.get('updatingDocument');
editorUi.exportToCanvas(mxUtils.bind(this, function(canvas)
{
var xml = (lightboxCheckBox.checked) ? editorUi.getFileData(true) : null;
var data = editorUi.createPngDataUri(canvas, xml);
doUpdate(data);
}), null, null, null, mxUtils.bind(this, function(e)
{
textarea.value = '';
editorUi.handleError({message: mxResources.get('unknownError')});
}), null, true, (retinaCheckBox.checked) ? 2 : 1, null, shadowCheckBox.checked);
}
else
{
var data = editorUi.getFileData(true);
if (bounds.width * bounds.height <= MAX_AREA && data.length <= MAX_REQUEST_SIZE)
{
textarea.value = mxResources.get('updatingDocument');
var size = '';
if (retinaCheckBox.checked)
{
size = '&w=' + Math.round(2 * bounds.width) +
'&h=' + Math.round(2 * bounds.height);
}
var embed = (lightboxCheckBox.checked) ? '1' : '0';
var req = new mxXmlRequest(EXPORT_URL, 'format=png' +
'&base64=1&embedXml=' + embed + size + '&xml=' +
encodeURIComponent(data));
// LATER: Updates on each change, add a delay
req.send(mxUtils.bind(this, function()
{
if (req.getStatus() == 200)
{
// Fixes possible "incorrect function" for select() on
// DOM node which is no longer in document with IE11
if (document.body.contains(div))
{
doUpdate('data:image/png;base64,' + req.getText());
}
}
else
{
textarea.value = '';
editorUi.handleError({message: mxResources.get('unknownError')});
}
}));
}
else
{
textarea.value = '';
editorUi.handleError({message: mxResources.get('drawingTooLarge')}, mxResources.get('error'));
}
}
}
else
{
var svgRoot = editorUi.editor.graph.getSvg();
// Keeps hashtag links on same page
var links = svgRoot.getElementsByTagName('a');
if (links != null)
{
for (var i = 0; i < links.length; i++)
{
var href = links[i].getAttribute('href');
if (href != null && href.charAt(0) == '#' &&
links[i].getAttribute('target') == '_blank')
{
links[i].removeAttribute('target');
}
}
}
if (lightboxCheckBox.checked)
{
svgRoot.setAttribute('content', editorUi.getFileData(true));
}
// Adds shadow filter
if (shadowCheckBox.checked)
{
editorUi.editor.addSvgShadow(svgRoot);
}
// SVG inside image tag
if (imageCheckBox.checked)
{
var onclick = ' ';
var css = '';
// Adds double click handling
if (lightboxCheckBox.checked)
{
// KNOWN: Message passing does not seem to work in IE11
onclick = "onclick=\"(function(img){if(img.wnd!=null&&!img.wnd.closed){img.wnd.focus();}else{var r=function(evt){if(evt.data=='ready'&&evt.source==img.wnd){img.wnd.postMessage(decodeURIComponent(" +
"img.getAttribute('src')),'*');window.removeEventListener('message',r);}};window.addEventListener('message',r);img.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0" +
((editCheckBox.checked) ? "&edit=_blank" : "") +
((layersCheckBox.checked) ? '&layers=1' : '') + "');}})(this);\"";
css += 'cursor:pointer;';
}
if (fitCheckBox.checked)
{
css += 'max-width:100%;';
}
// Images inside IMG don't seem to work so embed them all
editorUi.convertImages(svgRoot, function(svgRoot)
{
textarea.value = '';
});
}
else
{
var css = '';
// Adds double click handling
if (lightboxCheckBox.checked)
{
// KNOWN: Message passing does not seem to work in IE11
var js = "(function(svg){var src=window.event.target||window.event.srcElement;" +
// Ignores link events
"while (src!=null&&src.nodeName.toLowerCase()!='a'){src=src.parentNode;}if(src==null)" +
// Focus existing lightbox
"{if(svg.wnd!=null&&!svg.wnd.closed){svg.wnd.focus();}else{var r=function(evt){" +
// Message handling
"if(evt.data=='ready'&&evt.source==svg.wnd){svg.wnd.postMessage(decodeURIComponent(" +
"svg.getAttribute('content')),'*');window.removeEventListener('message',r);}};" +
"window.addEventListener('message',r);" +
// Opens lightbox window
"svg.wnd=window.open('https://www.draw.io/?client=1&lightbox=1&chrome=0" +
((editCheckBox.checked) ? "&edit=_blank" : "") +
((layersCheckBox.checked) ? '&layers=1' : '') + "');}}})(this);";
svgRoot.setAttribute('onclick', js);
css += 'cursor:pointer;';
}
// Adds responsive size
if (fitCheckBox.checked)
{
var w = parseInt(svgRoot.getAttribute('width'));
var h = parseInt(svgRoot.getAttribute('height'));
svgRoot.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
css += 'max-width:100%;max-height:' + h + 'px;';
svgRoot.removeAttribute('height');
}
if (css != '')
{
svgRoot.setAttribute('style', css);
}
textarea.value = mxUtils.getXml(svgRoot);
}
textarea.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
textarea.select();
}
else
{
document.execCommand('selectAll', false, null);
}
}
};
this.init = function()
{
update();
};
mxEvent.addListener(imageCheckBox, 'change', update);
mxEvent.addListener(retinaCheckBox, 'change', update);
mxEvent.addListener(shadowCheckBox, 'change', update);
mxEvent.addListener(fitCheckBox, 'change', update);
mxEvent.addListener(lightboxCheckBox, 'change', update);
mxEvent.addListener(editCheckBox, 'change', update);
mxEvent.addListener(layersCheckBox, 'change', update);
var buttons = document.createElement('div');
buttons.style.paddingTop = '18px';
buttons.style.textAlign = 'right';
if (!editorUi.isOffline() && !isImage)
{
var helpBtn = mxUtils.button(mxResources.get('help'), function()
{
window.open('https://desk.draw.io/solution/articles/16000042548-how-to-embed-svg-');
});
helpBtn.className = 'geBtn';
buttons.appendChild(helpBtn);
}
// Loads forever in IE9
if (!mxClient.IS_CHROMEAPP && !navigator.standalone && mxClient.IS_SVG &&
(document.documentMode == null || document.documentMode > 9))
{
var previewBtn = mxUtils.button(mxResources.get('preview'), function()
{
var wnd = window.open();
var doc = wnd.document;
doc.writeln('' + encodeURIComponent(mxResources.get('preview')) +
'' +
'' + textarea.value + '');
doc.close();
});
previewBtn.className = 'geBtn';
buttons.appendChild(previewBtn);
}
var closeBtn = mxUtils.button(mxResources.get('close'), function()
{
editorUi.hideDialog();
});
var copyBtn = mxUtils.button(mxResources.get('copy'), function()
{
textarea.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
textarea.select();
}
else
{
document.execCommand('selectAll', false, null);
}
document.execCommand('copy');
editorUi.alert(mxResources.get('copiedToClipboard'));
});
buttons.appendChild(closeBtn);
// Does not work in Safari and shows annoying dialog for IE11-
if (!mxClient.IS_SF && document.documentMode == null)
{
buttons.appendChild(copyBtn);
copyBtn.className = 'geBtn gePrimaryBtn';
closeBtn.className = 'geBtn';
}
else
{
closeBtn.className = 'geBtn gePrimaryBtn';
}
div.appendChild(buttons);
this.container = div;
};
/**
* Constructs a dialog for embedding the diagram in Google Sites.
*/
var GoogleSitesDialog = function(editorUi)
{
var div = document.createElement('div');
var graph = editorUi.editor.graph;
var bounds = graph.getGraphBounds();
var scale = graph.view.scale;
var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
mxUtils.write(div, mxResources.get('googleGadget') + ':');
mxUtils.br(div);
var gadgetInput = document.createElement('input');
gadgetInput.setAttribute('type', 'text');
gadgetInput.style.marginBottom = '8px';
gadgetInput.style.marginTop = '2px';
gadgetInput.style.width = '410px';
div.appendChild(gadgetInput);
mxUtils.br(div);
this.init = function()
{
gadgetInput.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
gadgetInput.select();
}
else
{
document.execCommand('selectAll', false, null);
}
};
mxUtils.write(div, mxResources.get('top') + ':');
var topInput = document.createElement('input');
topInput.setAttribute('type', 'text');
topInput.setAttribute('size', '4');
topInput.style.marginRight = '16px';
topInput.style.marginLeft = '4px';
topInput.value = x0;
div.appendChild(topInput);
mxUtils.write(div, mxResources.get('height') + ':');
var heightInput = document.createElement('input');
heightInput.setAttribute('type', 'text');
heightInput.setAttribute('size', '4');
heightInput.style.marginLeft = '4px';
heightInput.value = Math.ceil(bounds.height / scale);
div.appendChild(heightInput);
mxUtils.br(div);
var hr = document.createElement('hr');
hr.setAttribute('size', '1');
hr.style.marginBottom = '16px';
hr.style.marginTop = '16px';
div.appendChild(hr);
mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
mxUtils.br(div);
var urlInput = document.createElement('input');
urlInput.setAttribute('type', 'text');
urlInput.setAttribute('size', '28');
urlInput.style.marginBottom = '8px';
urlInput.style.marginTop = '2px';
urlInput.style.width = '410px';
div.appendChild(urlInput);
mxUtils.br(div);
mxUtils.write(div, mxResources.get('borderWidth') + ':');
var borderInput = document.createElement('input');
borderInput.setAttribute('type', 'text');
borderInput.setAttribute('size', '3');
borderInput.style.marginBottom = '8px';
borderInput.style.marginLeft = '4px';
borderInput.value = '0';
div.appendChild(borderInput);
mxUtils.br(div);
var panCheckBox = document.createElement('input');
panCheckBox.setAttribute('type', 'checkbox');
panCheckBox.setAttribute('checked', 'checked');
panCheckBox.defaultChecked = true;
panCheckBox.style.marginLeft = '16px';
div.appendChild(panCheckBox);
mxUtils.write(div, mxResources.get('pan') + ' ');
var zoomCheckBox = document.createElement('input');
zoomCheckBox.setAttribute('type', 'checkbox');
zoomCheckBox.setAttribute('checked', 'checked');
zoomCheckBox.defaultChecked = true;
zoomCheckBox.style.marginLeft = '8px';
div.appendChild(zoomCheckBox);
mxUtils.write(div, mxResources.get('zoom') + ' ');
var editCheckBox = document.createElement('input');
editCheckBox.setAttribute('type', 'checkbox');
editCheckBox.style.marginLeft = '8px';
editCheckBox.setAttribute('title', window.location.href);
div.appendChild(editCheckBox);
mxUtils.write(div, mxResources.get('edit') + ' ');
var editBlankCheckBox = document.createElement('input');
editBlankCheckBox.setAttribute('type', 'checkbox');
editBlankCheckBox.style.marginLeft = '8px';
div.appendChild(editBlankCheckBox);
mxUtils.write(div, mxResources.get('asNew') + ' ');
mxUtils.br(div);
var resizeCheckBox = document.createElement('input');
resizeCheckBox.setAttribute('type', 'checkbox');
resizeCheckBox.setAttribute('checked', 'checked');
resizeCheckBox.defaultChecked = true;
resizeCheckBox.style.marginLeft = '16px';
div.appendChild(resizeCheckBox);
mxUtils.write(div, mxResources.get('resize') + ' ');
var fitCheckBox = document.createElement('input');
fitCheckBox.setAttribute('type', 'checkbox');
fitCheckBox.style.marginLeft = '8px';
div.appendChild(fitCheckBox);
mxUtils.write(div, mxResources.get('fit') + ' ');
var embedCheckBox = document.createElement('input');
embedCheckBox.setAttribute('type', 'checkbox');
embedCheckBox.style.marginLeft = '8px';
div.appendChild(embedCheckBox);
mxUtils.write(div, mxResources.get('embed') + ' ');
var node = null;
var s = editorUi.getBasenames().join(';');
var file = editorUi.getCurrentFile();
function update()
{
var title = (file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
if (embedCheckBox.checked && urlInput.value != '')
{
var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
if (title != null)
{
gurl += '&title=' + encodeURIComponent(title);
}
if (s.length > 0)
{
gurl += '&s=' + s;
}
if (borderInput.value != '' && borderInput.value != '0')
{
gurl += '&border=' + borderInput.value;
}
if (heightInput.value != '')
{
gurl += '&height=' + heightInput.value;
}
gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
gurl += '&x0=' + Number(topInput.value);
gurl += '&y0=' + y0;
if (graph.mathEnabled)
{
gurl += '&math=1';
}
if (editBlankCheckBox.checked)
{
gurl += '&edit=_blank';
}
else if (editCheckBox.checked)
{
gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
}
gadgetInput.value = gurl;
}
else if (file.constructor == DriveFile || file.constructor == DropboxFile)
{
var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
if (urlInput.value != '')
{
gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
}
else
{
gurl += file.getHash().substring(1);
if (file.constructor == DropboxFile)
{
gurl += '&type=2';
}
else
{
gurl += '&type=1';
}
}
if (title != null)
{
gurl += '&title=' + encodeURIComponent(title);
}
if (heightInput.value != '')
{
var h = parseInt(heightInput.value) + parseInt(topInput.value);
gurl += '&height=' + h;
}
gadgetInput.value = gurl;
}
else
{
gadgetInput.value = '';
}
};
// Tries to generate public image URL (only for Drive files)
update();
urlInput.setAttribute('placeholder', mxResources.get('loading') + '...');
editorUi.getPublicUrl(file, function(url)
{
urlInput.setAttribute('placeholder', '');
urlInput.value = (url != null) ? url : '';
update();
});
mxEvent.addListener(panCheckBox, 'change', update);
mxEvent.addListener(zoomCheckBox, 'change', update);
mxEvent.addListener(resizeCheckBox, 'change', update);
mxEvent.addListener(fitCheckBox, 'change', update);
mxEvent.addListener(editCheckBox, 'change', update);
mxEvent.addListener(editBlankCheckBox, 'change', update);
mxEvent.addListener(embedCheckBox, 'change', update);
mxEvent.addListener(heightInput, 'change', update);
mxEvent.addListener(topInput, 'change', update);
mxEvent.addListener(borderInput, 'change', update);
mxEvent.addListener(urlInput, 'change', update);
mxEvent.addListener(gadgetInput, 'click', function()
{
gadgetInput.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
gadgetInput.select();
}
else
{
document.execCommand('selectAll', false, null);
}
});
var buttons = document.createElement('div');
buttons.style.paddingTop = '12px';
buttons.style.textAlign = 'right';
var closeBtn = mxUtils.button(mxResources.get('close'), function()
{
editorUi.hideDialog();
});
closeBtn.className = 'geBtn gePrimaryBtn';
buttons.appendChild(closeBtn);
div.appendChild(buttons);
this.container = div;
};
/**
* Constructs a dialog for embedding the diagram in Google Sites.
*/
var IframeDialog = function(editorUi, image, link)
{
var div = document.createElement('div');
var graph = editorUi.editor.graph;
var bounds = graph.getGraphBounds();
var scale = graph.view.scale;
var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
mxUtils.write(div, mxResources.get((link) ? 'link' : 'mainEmbedNotice') + ': ');
mxUtils.br(div);
var iframeInput = document.createElement('input');
iframeInput.setAttribute('type', 'text');
iframeInput.style.marginBottom = '8px';
iframeInput.style.marginTop = '2px';
iframeInput.style.width = '410px';
div.appendChild(iframeInput);
mxUtils.br(div);
this.init = function()
{
if (iframeInput.getAttribute('disabled') != 'disabled')
{
iframeInput.focus();
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
iframeInput.select();
}
else
{
document.execCommand('selectAll', false, null);
}
}
};
var widthInput = document.createElement('input');
widthInput.setAttribute('type', 'text');
widthInput.style.marginRight = '16px';
widthInput.style.width = '60px';
widthInput.style.marginBottom = '8px';
widthInput.style.marginLeft = '4px';
widthInput.value = '100%';
if (!image && !link)
{
mxUtils.write(div, mxResources.get('width') + ':');
div.appendChild(widthInput);
}
var heightInput = document.createElement('input');
heightInput.setAttribute('type', 'text');
heightInput.style.width = '60px';
heightInput.style.marginLeft = '4px';
heightInput.value = (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / scale) + 2) + 'px';
var lightboxCheckBox = document.createElement('input');
lightboxCheckBox.setAttribute('type', 'checkbox');
var editCheckBox = document.createElement('input');
editCheckBox.setAttribute('type', 'checkbox');
var layersCheckBox = document.createElement('input');
layersCheckBox.setAttribute('type', 'checkbox');
if (!image)
{
if (!link)
{
mxUtils.write(div, mxResources.get('height') + ':');
div.appendChild(heightInput);
mxUtils.br(div);
}
lightboxCheckBox.setAttribute('checked', 'checked');
lightboxCheckBox.defaultChecked = true;
div.appendChild(lightboxCheckBox);
mxUtils.write(div, mxResources.get('lightbox'));
layersCheckBox.style.marginLeft = '16px';
var model = editorUi.editor.graph.getModel();
if (model.getChildCount(model.getRoot()) > 1)
{
layersCheckBox.setAttribute('checked', 'checked');
layersCheckBox.defaultChecked = true;
}
else
{
layersCheckBox.setAttribute('disabled', 'disabled');
}
div.appendChild(layersCheckBox);
mxUtils.write(div, mxResources.get('layers'));
editCheckBox.style.marginLeft = '16px';
editCheckBox.setAttribute('checked', 'checked');
editCheckBox.defaultChecked = true;
div.appendChild(editCheckBox);
mxUtils.write(div, mxResources.get('edit'));
mxUtils.br(div);
}
var hr = document.createElement('hr');
hr.setAttribute('size', '1');
hr.style.marginBottom = '16px';
hr.style.marginTop = '16px';
div.appendChild(hr);
mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
mxUtils.br(div);
var urlInput = document.createElement('input');
urlInput.setAttribute('type', 'text');
urlInput.setAttribute('size', '28');
urlInput.style.marginBottom = '8px';
urlInput.style.marginTop = '2px';
urlInput.style.width = '410px';
div.appendChild(urlInput);
mxUtils.br(div);
var node = null;
var previewBtn = mxUtils.button(mxResources.get('preview'), function()
{
if (image || link)
{
window.open(iframeInput.value);
}
else
{
var wnd = window.open();
var doc = wnd.document;
if (document.compatMode === 'CSS1Compat')
{
doc.writeln('');
}
doc.writeln('' + encodeURIComponent(mxResources.get('preview')) +
'');
doc.writeln('');
doc.writeln(iframeInput.value);
doc.writeln('');
doc.writeln('