mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 14:59:53 +02:00
#Adjustments of init - **could break some integrations!!**
* Configuration are picked up from the mermaid object and is not passed as arguments. Same handling for all diagram types, sequenceDiagrams were handled in a different way before this commit. When init is called with: * 0 arguments - all mermaid divs are processed * 1 argument - this is interpreted as a definition of what nodes to process * 2 arguments - for (some) backwards compatability the second argument is interpreted as the definition of nodes to process. The first argument (prrobably a sequence config is ignored) A definition of nodes to process can be * a css selector for what elements to be processed * a list of nodes as in the result of a command like the one below ``` document.querySelectorAll('.tbProcessed'); ```
This commit is contained in:
48
src/main.js
48
src/main.js
@@ -75,25 +75,34 @@ var parse = function(text){
|
||||
* c-->|No |d(Transform);
|
||||
* ```
|
||||
*/
|
||||
var init = function (sequenceConfig, arr) {
|
||||
arr = arr == null ? document.querySelectorAll('.mermaid')
|
||||
: typeof arr === "string" ? document.querySelectorAll(arr)
|
||||
: arr instanceof Node ? [arr]
|
||||
: arr;
|
||||
|
||||
//arr = document.querySelectorAll('.mermaid');
|
||||
var i;
|
||||
|
||||
if (sequenceConfig !== 'undefined' && (typeof sequenceConfig !== 'undefined')) {
|
||||
if(typeof sequenceConfig === 'object'){
|
||||
seq.setConf(sequenceConfig);
|
||||
} else{
|
||||
seq.setConf(JSON.parse(sequenceConfig));
|
||||
/**
|
||||
* Renders the mermaid diagrams
|
||||
* @* param nodes- a css selector or an array of nodes
|
||||
*/
|
||||
var init = function () {
|
||||
var nodes;
|
||||
if(arguments.length === 2){
|
||||
// sequence config was passed as #1
|
||||
if(typeof arguments[0] !== 'undefined'){
|
||||
mermaid.sequenceConfig = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
var element = arr[i];
|
||||
nodes = arguments[1];
|
||||
}
|
||||
else{
|
||||
nodes = arguments[0];
|
||||
}
|
||||
|
||||
nodes = nodes === undefined ? document.querySelectorAll('.mermaid')
|
||||
: typeof nodes === "string" ? document.querySelectorAll(nodes)
|
||||
: nodes instanceof Node ? [nodes]
|
||||
// Last case - sequence config was passed pick next
|
||||
: nodes;
|
||||
|
||||
var i;
|
||||
for (i = 0; i < nodes.length; i++) {
|
||||
var element = nodes[i];
|
||||
|
||||
// Check if previously processed
|
||||
if(!element.getAttribute("data-processed")) {
|
||||
@@ -102,7 +111,7 @@ var init = function (sequenceConfig, arr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
id = 'mermaidChart' + nextId++;
|
||||
var id = 'mermaidChart' + nextId++;
|
||||
|
||||
var txt = element.innerHTML;
|
||||
txt = txt.replace(/>/g,'>');
|
||||
@@ -133,6 +142,9 @@ var init = function (sequenceConfig, arr) {
|
||||
utils.cloneCssStyles(element.firstChild, classes);
|
||||
break;
|
||||
case 'sequenceDiagram':
|
||||
if(typeof mermaid.sequenceConfig === 'object'){
|
||||
seq.setConf(mermaid.sequenceConfig);
|
||||
}
|
||||
seq.draw(txt,id);
|
||||
utils.cloneCssStyles(element.firstChild, []);
|
||||
break;
|
||||
@@ -229,5 +241,3 @@ if(typeof document !== 'undefined'){
|
||||
exports.contentLoaded();
|
||||
}, false);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user