maxGraph/javascript/examples/editors/js/mxApplication.js

80 lines
1.6 KiB
JavaScript

/*
* $Id: mxApplication.js,v 1.2 2013/10/28 08:45:09 gaudenz Exp $
* Copyright (c) 2006-2013, JGraph Ltd
*
* Defines the startup sequence of the application.
*
*/
{
/**
* Constructs a new application (note that this returns an mxEditor
* instance).
*/
function mxApplication(config)
{
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
{
var node = mxUtils.load(config).getDocumentElement();
var editor = new mxEditor(node);
// 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;
}
}