2016-01-12 07:47:25 +00:00
|
|
|
/**
|
|
|
|
* The code in the <project-logo></project-logo> area
|
|
|
|
* must not be changed.
|
|
|
|
*
|
|
|
|
* @see http://bpmn.io/license for more information.
|
|
|
|
*/
|
2014-06-11 12:41:55 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var assign = require('lodash/object/assign'),
|
2015-02-05 08:24:27 +00:00
|
|
|
omit = require('lodash/object/omit'),
|
2016-02-25 13:07:23 +00:00
|
|
|
isNumber = require('lodash/lang/isNumber');
|
2015-02-05 08:24:27 +00:00
|
|
|
|
|
|
|
var domify = require('min-dom/lib/domify'),
|
|
|
|
domQuery = require('min-dom/lib/query'),
|
|
|
|
domRemove = require('min-dom/lib/remove');
|
2015-02-02 13:46:21 +00:00
|
|
|
|
2016-09-14 06:18:56 +00:00
|
|
|
var innerSVG = require('tiny-svg/lib/innerSVG');
|
|
|
|
|
2014-04-09 08:50:20 +00:00
|
|
|
var Diagram = require('diagram-js'),
|
2015-02-05 08:24:27 +00:00
|
|
|
BpmnModdle = require('bpmn-moddle');
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-04-09 08:50:20 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
var inherits = require('inherits');
|
2014-04-09 08:50:20 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
var Importer = require('./import/Importer');
|
2014-03-26 16:45:04 +00:00
|
|
|
|
|
|
|
|
2014-06-30 17:04:40 +00:00
|
|
|
function checkValidationError(err) {
|
|
|
|
|
|
|
|
// check if we can help the user by indicating wrong BPMN 2.0 xml
|
|
|
|
// (in case he or the exporting tool did not get that right)
|
|
|
|
|
|
|
|
var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
|
|
|
var match = pattern.exec(err.message);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
err.message =
|
|
|
|
'unparsable content <' + match[1] + '> detected; ' +
|
|
|
|
'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
var DEFAULT_OPTIONS = {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2017-01-27 09:09:34 +00:00
|
|
|
position: 'relative'
|
2014-12-18 08:45:45 +00:00
|
|
|
};
|
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure the passed argument is a proper unit (defaulting to px)
|
|
|
|
*/
|
|
|
|
function ensureUnit(val) {
|
|
|
|
return val + (isNumber(val) ? 'px' : '');
|
|
|
|
}
|
|
|
|
|
2014-04-08 13:23:52 +00:00
|
|
|
/**
|
2015-01-10 11:04:26 +00:00
|
|
|
* A viewer for BPMN 2.0 diagrams.
|
2014-04-25 14:14:36 +00:00
|
|
|
*
|
2015-01-10 11:04:26 +00:00
|
|
|
* Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
|
|
|
|
* additional features.
|
2014-08-01 05:55:47 +00:00
|
|
|
*
|
2015-05-04 12:49:48 +00:00
|
|
|
*
|
|
|
|
* ## Extending the Viewer
|
|
|
|
*
|
|
|
|
* In order to extend the viewer pass extension modules to bootstrap via the
|
|
|
|
* `additionalModules` option. An extension module is an object that exposes
|
|
|
|
* named services.
|
|
|
|
*
|
|
|
|
* The following example depicts the integration of a simple
|
|
|
|
* logging component that integrates with interaction events:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
*
|
|
|
|
* // logging component
|
|
|
|
* function InteractionLogger(eventBus) {
|
|
|
|
* eventBus.on('element.hover', function(event) {
|
|
|
|
* console.log()
|
|
|
|
* })
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* InteractionLogger.$inject = [ 'eventBus' ]; // minification save
|
|
|
|
*
|
|
|
|
* // extension module
|
|
|
|
* var extensionModule = {
|
|
|
|
* __init__: [ 'interactionLogger' ],
|
|
|
|
* interactionLogger: [ 'type', InteractionLogger ]
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* // extend the viewer
|
|
|
|
* var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
|
|
|
|
* bpmnViewer.importXML(...);
|
|
|
|
* ```
|
|
|
|
*
|
2014-04-08 13:23:52 +00:00
|
|
|
* @param {Object} [options] configuration options to pass to the viewer
|
|
|
|
* @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
|
|
|
|
* @param {String|Number} [options.width] the width of the viewer
|
|
|
|
* @param {String|Number} [options.height] the height of the viewer
|
2015-02-12 14:50:23 +00:00
|
|
|
* @param {Object} [options.moddleExtensions] extension packages to provide
|
2014-08-01 05:55:47 +00:00
|
|
|
* @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
|
|
|
|
* @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
|
2014-04-08 13:23:52 +00:00
|
|
|
*/
|
2014-04-04 16:48:37 +00:00
|
|
|
function Viewer(options) {
|
2014-12-18 08:45:45 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
options = assign({}, DEFAULT_OPTIONS, options);
|
2014-04-08 13:23:52 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
this.moddle = this._createModdle(options);
|
2016-03-16 16:11:38 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
this.container = this._createContainer(options);
|
2014-04-08 13:23:52 +00:00
|
|
|
|
2016-01-12 07:47:25 +00:00
|
|
|
/* <project-logo> */
|
2014-04-04 16:48:37 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
addProjectLogo(this.container);
|
2014-05-06 12:32:54 +00:00
|
|
|
|
|
|
|
/* </project-logo> */
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
this._init(this.container, this.moddle, options);
|
2014-03-18 16:01:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
inherits(Viewer, Diagram);
|
|
|
|
|
2016-01-12 07:47:25 +00:00
|
|
|
module.exports = Viewer;
|
|
|
|
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
2016-03-17 08:39:43 +00:00
|
|
|
* Parse and render a BPMN 2.0 diagram.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* Once finished the viewer reports back the result to the
|
|
|
|
* provided callback function with (err, warnings).
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-03-17 08:39:43 +00:00
|
|
|
* ## Life-Cycle Events
|
|
|
|
*
|
|
|
|
* During import the viewer will fire life-cycle events:
|
|
|
|
*
|
|
|
|
* * import.parse.start (about to read model from xml)
|
|
|
|
* * import.parse.complete (model read; may have worked or not)
|
|
|
|
* * import.render.start (graphical import start)
|
|
|
|
* * import.render.complete (graphical import finished)
|
|
|
|
* * import.done (everything done)
|
|
|
|
*
|
|
|
|
* You can use these events to hook into the life-cycle.
|
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {String} xml the BPMN 2.0 xml
|
2016-03-17 09:42:14 +00:00
|
|
|
* @param {Function} [done] invoked with (err, warnings=[])
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-03-21 20:10:01 +00:00
|
|
|
Viewer.prototype.importXML = function(xml, done) {
|
|
|
|
|
2016-03-17 09:42:14 +00:00
|
|
|
// done is optional
|
|
|
|
done = done || function() {};
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
var self = this;
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// hook in pre-parse listeners +
|
|
|
|
// allow xml manipulation
|
|
|
|
xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// hook in post parse listeners +
|
|
|
|
// allow definitions manipulation
|
|
|
|
definitions = self._emit('import.parse.complete', {
|
|
|
|
error: err,
|
|
|
|
definitions: definitions,
|
|
|
|
context: context
|
|
|
|
}) || definitions;
|
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
var parseWarnings = context.warnings;
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
if (err) {
|
2014-06-30 17:04:40 +00:00
|
|
|
err = checkValidationError(err);
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
self._emit('import.done', { error: err, warnings: parseWarnings });
|
2016-03-17 08:39:43 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
return done(err, parseWarnings);
|
2016-03-16 16:11:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
self.importDefinitions(definitions, function(err, importWarnings) {
|
2016-03-17 08:39:43 +00:00
|
|
|
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
|
|
|
|
|
|
|
self._emit('import.done', { error: err, warnings: allWarnings });
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
done(err, allWarnings);
|
2015-02-17 09:55:28 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Export the currently displayed BPMN 2.0 diagram as
|
|
|
|
* a BPMN 2.0 XML document.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Object} [options] export options
|
|
|
|
* @param {Boolean} [options.format=false] output formated XML
|
|
|
|
* @param {Boolean} [options.preamble=true] output preamble
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Function} done invoked with (err, xml)
|
|
|
|
*/
|
2014-03-24 10:02:58 +00:00
|
|
|
Viewer.prototype.saveXML = function(options, done) {
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
done = options;
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var definitions = this.definitions;
|
|
|
|
|
|
|
|
if (!definitions) {
|
|
|
|
return done(new Error('no definitions loaded'));
|
|
|
|
}
|
|
|
|
|
2014-09-04 11:27:36 +00:00
|
|
|
this.moddle.toXML(definitions, options, done);
|
2014-03-24 10:02:58 +00:00
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Export the currently displayed BPMN 2.0 diagram as
|
|
|
|
* an SVG image.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {Function} done invoked with (err, svgStr)
|
|
|
|
*/
|
2014-03-24 10:02:58 +00:00
|
|
|
Viewer.prototype.saveSVG = function(options, done) {
|
2014-08-17 17:08:52 +00:00
|
|
|
|
2014-03-24 10:02:58 +00:00
|
|
|
if (!done) {
|
|
|
|
done = options;
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
2014-08-17 17:08:52 +00:00
|
|
|
var canvas = this.get('canvas');
|
|
|
|
|
2014-11-26 10:31:23 +00:00
|
|
|
var contentNode = canvas.getDefaultLayer(),
|
2016-09-14 06:18:56 +00:00
|
|
|
defsNode = domQuery('defs', canvas._svg);
|
2014-08-17 17:08:52 +00:00
|
|
|
|
2016-09-14 06:18:56 +00:00
|
|
|
var contents = innerSVG(contentNode),
|
2017-09-26 13:22:15 +00:00
|
|
|
defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
|
2014-03-24 10:02:58 +00:00
|
|
|
|
2014-08-17 17:08:52 +00:00
|
|
|
var bbox = contentNode.getBBox();
|
2014-03-24 10:02:58 +00:00
|
|
|
|
2014-08-17 17:08:52 +00:00
|
|
|
var svg =
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?>\n' +
|
|
|
|
'<!-- created with bpmn-js / http://bpmn.io -->\n' +
|
|
|
|
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
|
|
|
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
|
|
|
'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
|
|
|
'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
|
|
|
defs + contents +
|
|
|
|
'</svg>';
|
2014-03-24 10:02:58 +00:00
|
|
|
|
|
|
|
done(null, svg);
|
|
|
|
};
|
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Get a named diagram service.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @example
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
* var startEventShape = elementRegistry.get('StartEvent_1');
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {String} name
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @return {Object} diagram service instance
|
2016-03-16 22:11:05 +00:00
|
|
|
*
|
|
|
|
* @method Viewer#get
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-04-04 16:48:37 +00:00
|
|
|
|
2016-02-11 16:20:41 +00:00
|
|
|
/**
|
|
|
|
* Invoke a function in the context of this viewer.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @example
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* viewer.invoke(function(elementRegistry) {
|
|
|
|
* var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
* });
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @param {Function} fn to be invoked
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2016-02-11 16:20:41 +00:00
|
|
|
* @return {Object} the functions return value
|
2016-03-16 22:11:05 +00:00
|
|
|
*
|
|
|
|
* @method Viewer#invoke
|
2016-02-11 16:20:41 +00:00
|
|
|
*/
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
/**
|
|
|
|
* Remove all drawn elements from the viewer.
|
|
|
|
*
|
|
|
|
* After calling this method the viewer can still
|
|
|
|
* be reused for opening another diagram.
|
|
|
|
*
|
|
|
|
* @method Viewer#clear
|
|
|
|
*/
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2014-08-01 05:47:36 +00:00
|
|
|
Viewer.prototype.importDefinitions = function(definitions, done) {
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-08-01 05:47:36 +00:00
|
|
|
// use try/catch to not swallow synchronous exceptions
|
|
|
|
// that may be raised during model parsing
|
|
|
|
try {
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
if (this.definitions) {
|
|
|
|
// clear existing rendered diagram
|
2014-08-01 05:47:36 +00:00
|
|
|
this.clear();
|
|
|
|
}
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
// update definitions
|
2014-08-01 05:47:36 +00:00
|
|
|
this.definitions = definitions;
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
// perform graphical import
|
|
|
|
Importer.importBpmnDiagram(this, definitions, done);
|
2014-08-01 05:47:36 +00:00
|
|
|
} catch (e) {
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
// handle synchronous errors
|
2014-08-01 05:47:36 +00:00
|
|
|
done(e);
|
|
|
|
}
|
|
|
|
};
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
Viewer.prototype.getModules = function() {
|
|
|
|
return this._modules;
|
|
|
|
};
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* Destroy the viewer instance and remove all its
|
|
|
|
* remainders from the document tree.
|
2014-12-18 08:45:45 +00:00
|
|
|
*/
|
|
|
|
Viewer.prototype.destroy = function() {
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
// diagram destroy
|
|
|
|
Diagram.prototype.destroy.call(this);
|
|
|
|
|
|
|
|
// dom detach
|
2015-02-05 08:24:27 +00:00
|
|
|
domRemove(this.container);
|
2014-12-18 08:45:45 +00:00
|
|
|
};
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* Register an event listener
|
2014-06-24 13:50:51 +00:00
|
|
|
*
|
2016-02-16 09:31:12 +00:00
|
|
|
* Remove a previously added listener via {@link #off(event, callback)}.
|
2016-02-18 00:16:10 +00:00
|
|
|
*
|
2014-06-24 13:50:51 +00:00
|
|
|
* @param {String} event
|
2016-02-16 09:31:12 +00:00
|
|
|
* @param {Number} [priority]
|
|
|
|
* @param {Function} callback
|
|
|
|
* @param {Object} [that]
|
2014-06-24 13:50:51 +00:00
|
|
|
*/
|
2016-03-16 22:11:05 +00:00
|
|
|
Viewer.prototype.on = function(event, priority, callback, target) {
|
|
|
|
return this.get('eventBus').on(event, priority, callback, target);
|
2016-02-16 09:31:12 +00:00
|
|
|
};
|
2014-04-25 14:14:36 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
/**
|
2016-03-16 22:11:05 +00:00
|
|
|
* De-register an event listener
|
2016-02-16 09:31:12 +00:00
|
|
|
*
|
|
|
|
* @param {String} event
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
Viewer.prototype.off = function(event, callback) {
|
2016-03-16 22:11:05 +00:00
|
|
|
this.get('eventBus').off(event, callback);
|
|
|
|
};
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
Viewer.prototype.attachTo = function(parentNode) {
|
|
|
|
|
|
|
|
if (!parentNode) {
|
|
|
|
throw new Error('parentNode required');
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we detach from the
|
|
|
|
// previous, old parent
|
|
|
|
this.detach();
|
|
|
|
|
|
|
|
// unwrap jQuery if provided
|
2017-02-17 17:44:01 +00:00
|
|
|
if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
2017-01-27 09:09:34 +00:00
|
|
|
parentNode = parentNode.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof parentNode === 'string') {
|
|
|
|
parentNode = domQuery(parentNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
var container = this._container;
|
|
|
|
|
|
|
|
parentNode.appendChild(container);
|
|
|
|
|
|
|
|
this._emit('attach', {});
|
|
|
|
};
|
|
|
|
|
|
|
|
Viewer.prototype.detach = function() {
|
|
|
|
|
|
|
|
var container = this._container,
|
|
|
|
parentNode = container.parentNode;
|
|
|
|
|
|
|
|
if (!parentNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._emit('detach', {});
|
|
|
|
|
|
|
|
parentNode.removeChild(container);
|
|
|
|
};
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
Viewer.prototype._init = function(container, moddle, options) {
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
this._container = container;
|
2016-03-16 22:11:05 +00:00
|
|
|
var baseModules = options.modules || this.getModules(),
|
|
|
|
additionalModules = options.additionalModules || [],
|
|
|
|
staticModules = [
|
|
|
|
{
|
|
|
|
bpmnjs: [ 'value', this ],
|
|
|
|
moddle: [ 'value', moddle ]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
|
|
|
|
|
|
|
var diagramOptions = assign(omit(options, 'additionalModules'), {
|
|
|
|
canvas: assign({}, options.canvas, { container: container }),
|
|
|
|
modules: diagramModules
|
|
|
|
});
|
|
|
|
|
|
|
|
// invoke diagram constructor
|
|
|
|
Diagram.call(this, diagramOptions);
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
if (options && options.container) {
|
|
|
|
this.attachTo(options.container);
|
|
|
|
}
|
2016-03-16 22:11:05 +00:00
|
|
|
};
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
/**
|
|
|
|
* Emit an event on the underlying {@link EventBus}
|
|
|
|
*
|
|
|
|
* @param {String} type
|
|
|
|
* @param {Object} event
|
|
|
|
*
|
|
|
|
* @return {Object} event processing result (if any)
|
|
|
|
*/
|
|
|
|
Viewer.prototype._emit = function(type, event) {
|
|
|
|
return this.get('eventBus').fire(type, event);
|
|
|
|
};
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
Viewer.prototype._createContainer = function(options) {
|
2016-02-18 00:16:10 +00:00
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
var container = domify('<div class="bjs-container"></div>');
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
assign(container.style, {
|
|
|
|
width: ensureUnit(options.width),
|
|
|
|
height: ensureUnit(options.height),
|
|
|
|
position: options.position
|
|
|
|
});
|
|
|
|
|
|
|
|
return container;
|
|
|
|
};
|
|
|
|
|
|
|
|
Viewer.prototype._createModdle = function(options) {
|
|
|
|
var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
|
|
|
|
|
|
|
return new BpmnModdle(moddleOptions);
|
2014-03-26 16:45:04 +00:00
|
|
|
};
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
// modules the viewer is composed of
|
2014-06-17 09:19:31 +00:00
|
|
|
Viewer.prototype._modules = [
|
2014-06-19 07:49:26 +00:00
|
|
|
require('./core'),
|
2016-02-25 16:40:56 +00:00
|
|
|
require('diagram-js/lib/i18n/translate'),
|
2014-08-01 09:40:18 +00:00
|
|
|
require('diagram-js/lib/features/selection'),
|
|
|
|
require('diagram-js/lib/features/overlays')
|
2014-06-11 12:41:55 +00:00
|
|
|
];
|
|
|
|
|
2016-02-18 00:16:10 +00:00
|
|
|
// default moddle extensions the viewer is composed of
|
|
|
|
Viewer.prototype._moddleExtensions = {};
|
2016-01-12 07:47:25 +00:00
|
|
|
|
|
|
|
/* <project-logo> */
|
|
|
|
|
|
|
|
var PoweredBy = require('./util/PoweredByUtil'),
|
|
|
|
domEvent = require('min-dom/lib/event');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the project logo to the diagram container as
|
|
|
|
* required by the bpmn.io license.
|
|
|
|
*
|
|
|
|
* @see http://bpmn.io/license
|
|
|
|
*
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
|
|
|
function addProjectLogo(container) {
|
|
|
|
var logoData = PoweredBy.BPMNIO_LOGO;
|
|
|
|
|
|
|
|
var linkMarkup =
|
|
|
|
'<a href="http://bpmn.io" ' +
|
|
|
|
'target="_blank" ' +
|
|
|
|
'class="bjs-powered-by" ' +
|
|
|
|
'title="Powered by bpmn.io" ' +
|
|
|
|
'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
|
|
|
|
'<img src="data:image/png;base64,' + logoData + '">' +
|
|
|
|
'</a>';
|
|
|
|
|
|
|
|
var linkElement = domify(linkMarkup);
|
|
|
|
|
|
|
|
container.appendChild(linkElement);
|
|
|
|
|
|
|
|
domEvent.bind(linkElement, 'click', function(event) {
|
|
|
|
PoweredBy.open();
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-14 06:18:56 +00:00
|
|
|
/* </project-logo> */
|