maxGraph/javascript/examples/editors/js/app.js

93 lines
1.9 KiB
JavaScript

/*
* Copyright (c) 2006-2013, JGraph Ltd
*
* Defines the startup sequence of the application.
*/
{
/**
* Constructs a new application (returns an mxEditor instance)
*/
function createEditor(config)
{
var editor = null;
var hideSplash = function()
{
// Fades-out the splash screen
var splash = document.getElementById('splash');
if (splash != null)
{
try
{
mxEvent.release(splash);
mxEffects.fadeOut(splash, 100, true);
}
catch (e)
{
splash.parentNode.removeChild(splash);
}
}
};
try
{
if (!mxClient.isBrowserSupported())
{
mxUtils.error('Browser is not supported!', 200, false);
}
else
{
mxObjectCodec.allowEval = true;
var node = mxUtils.load(config).getDocumentElement();
editor = new mxEditor(node);
mxObjectCodec.allowEval = false;
// Adds active border for panning inside the container
editor.graph.createPanningManager = function()
{
var pm = new mxPanningManager(this);
pm.border = 30;
return pm;
};
editor.graph.allowAutoPanning = true;
editor.graph.timerAutoScroll = true;
// Updates the window title after opening new files
var title = document.title;
var funct = function(sender)
{
document.title = title + ' - ' + sender.getTitle();
};
editor.addListener(mxEvent.OPEN, funct);
// Prints the current root in the window title if the
// current root of the graph changes (drilling).
editor.addListener(mxEvent.ROOT, funct);
funct(editor);
// Displays version in statusbar
editor.setStatus('mxGraph '+mxClient.VERSION);
// Shows the application
hideSplash();
}
}
catch (e)
{
hideSplash();
// Shows an error message if the editor cannot start
mxUtils.alert('Cannot start application: ' + e.message);
throw e; // for debugging
}
return editor;
}
}