mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-09 18:39:41 +02:00
No global mermaid
This commit is contained in:
@@ -37,7 +37,7 @@ var init = function () {
|
|||||||
if (arguments.length >= 2) {
|
if (arguments.length >= 2) {
|
||||||
/*! sequence config was passed as #1 */
|
/*! sequence config was passed as #1 */
|
||||||
if (typeof arguments[0] !== 'undefined') {
|
if (typeof arguments[0] !== 'undefined') {
|
||||||
global.mermaid.sequenceConfig = arguments[0]
|
mermaid.sequenceConfig = arguments[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes = arguments[1]
|
nodes = arguments[1]
|
||||||
@@ -68,14 +68,14 @@ var init = function () {
|
|||||||
if (typeof global.mermaid_config !== 'undefined') {
|
if (typeof global.mermaid_config !== 'undefined') {
|
||||||
mermaidAPI.initialize(global.mermaid_config)
|
mermaidAPI.initialize(global.mermaid_config)
|
||||||
}
|
}
|
||||||
log.debug('Start On Load before: ' + global.mermaid.startOnLoad)
|
log.debug('Start On Load before: ' + mermaid.startOnLoad)
|
||||||
if (typeof global.mermaid.startOnLoad !== 'undefined') {
|
if (typeof mermaid.startOnLoad !== 'undefined') {
|
||||||
log.debug('Start On Load inner: ' + global.mermaid.startOnLoad)
|
log.debug('Start On Load inner: ' + mermaid.startOnLoad)
|
||||||
mermaidAPI.initialize({ startOnLoad: global.mermaid.startOnLoad })
|
mermaidAPI.initialize({ startOnLoad: mermaid.startOnLoad })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof global.mermaid.ganttConfig !== 'undefined') {
|
if (typeof mermaid.ganttConfig !== 'undefined') {
|
||||||
mermaidAPI.initialize({ gantt: global.mermaid.ganttConfig })
|
mermaidAPI.initialize({ gantt: mermaid.ganttConfig })
|
||||||
}
|
}
|
||||||
|
|
||||||
var txt
|
var txt
|
||||||
@@ -117,10 +117,10 @@ const initialize = function (config) {
|
|||||||
log.debug('Initializing mermaid')
|
log.debug('Initializing mermaid')
|
||||||
if (typeof config.mermaid !== 'undefined') {
|
if (typeof config.mermaid !== 'undefined') {
|
||||||
if (typeof config.mermaid.startOnLoad !== 'undefined') {
|
if (typeof config.mermaid.startOnLoad !== 'undefined') {
|
||||||
global.mermaid.startOnLoad = config.mermaid.startOnLoad
|
mermaid.startOnLoad = config.mermaid.startOnLoad
|
||||||
}
|
}
|
||||||
if (typeof config.mermaid.htmlLabels !== 'undefined') {
|
if (typeof config.mermaid.htmlLabels !== 'undefined') {
|
||||||
global.mermaid.htmlLabels = config.mermaid.htmlLabels
|
mermaid.htmlLabels = config.mermaid.htmlLabels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mermaidAPI.initialize(config)
|
mermaidAPI.initialize(config)
|
||||||
@@ -136,30 +136,30 @@ const contentLoaded = function () {
|
|||||||
// Check state of start config mermaid namespace
|
// Check state of start config mermaid namespace
|
||||||
if (typeof global.mermaid_config !== 'undefined') {
|
if (typeof global.mermaid_config !== 'undefined') {
|
||||||
if (global.mermaid_config.htmlLabels === false) {
|
if (global.mermaid_config.htmlLabels === false) {
|
||||||
global.mermaid.htmlLabels = false
|
mermaid.htmlLabels = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.mermaid.startOnLoad) {
|
if (mermaid.startOnLoad) {
|
||||||
// For backwards compatability reasons also check mermaid_config variable
|
// For backwards compatability reasons also check mermaid_config variable
|
||||||
if (typeof global.mermaid_config !== 'undefined') {
|
if (typeof global.mermaid_config !== 'undefined') {
|
||||||
// Check if property startOnLoad is set
|
// Check if property startOnLoad is set
|
||||||
if (global.mermaid_config.startOnLoad === true) {
|
if (global.mermaid_config.startOnLoad === true) {
|
||||||
global.mermaid.init()
|
mermaid.init()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No config found, do check API config
|
// No config found, do check API config
|
||||||
config = mermaidAPI.getConfig()
|
config = mermaidAPI.getConfig()
|
||||||
if (config.startOnLoad) {
|
if (config.startOnLoad) {
|
||||||
global.mermaid.init()
|
mermaid.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (typeof global.mermaid.startOnLoad === 'undefined') {
|
if (typeof mermaid.startOnLoad === 'undefined') {
|
||||||
log.debug('In start, no config')
|
log.debug('In start, no config')
|
||||||
config = mermaidAPI.getConfig()
|
config = mermaidAPI.getConfig()
|
||||||
if (config.startOnLoad) {
|
if (config.startOnLoad) {
|
||||||
global.mermaid.init()
|
mermaid.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,51 +7,49 @@
|
|||||||
*/
|
*/
|
||||||
import mermaid from './mermaid'
|
import mermaid from './mermaid'
|
||||||
|
|
||||||
global.mermaid = mermaid
|
|
||||||
|
|
||||||
describe('when using mermaid and ', function () {
|
describe('when using mermaid and ', function () {
|
||||||
describe('when detecting chart type ', function () {
|
describe('when detecting chart type ', function () {
|
||||||
it('should not start rendering with mermaid_config.startOnLoad set to false', function () {
|
it('should not start rendering with mermaid_config.startOnLoad set to false', function () {
|
||||||
global.mermaid_config = { startOnLoad: false }
|
global.mermaid_config = { startOnLoad: false }
|
||||||
|
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).not.toHaveBeenCalled()
|
expect(mermaid.init).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not start rendering with mermaid.startOnLoad set to false', function () {
|
it('should not start rendering with mermaid.startOnLoad set to false', function () {
|
||||||
global.mermaid.startOnLoad = false
|
mermaid.startOnLoad = false
|
||||||
global.mermaid_config = { startOnLoad: true }
|
global.mermaid_config = { startOnLoad: true }
|
||||||
|
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).not.toHaveBeenCalled()
|
expect(mermaid.init).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering with both startOnLoad set', function () {
|
it('should start rendering with both startOnLoad set', function () {
|
||||||
global.mermaid.startOnLoad = true
|
mermaid.startOnLoad = true
|
||||||
global.mermaid_config = { startOnLoad: true }
|
global.mermaid_config = { startOnLoad: true }
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).toHaveBeenCalled()
|
expect(mermaid.init).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering with mermaid.startOnLoad set and no mermaid_config defined', function () {
|
it('should start rendering with mermaid.startOnLoad set and no mermaid_config defined', function () {
|
||||||
global.mermaid.startOnLoad = true
|
mermaid.startOnLoad = true
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).toHaveBeenCalled()
|
expect(mermaid.init).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should start rendering as a default with no changes performed', function () {
|
it('should start rendering as a default with no changes performed', function () {
|
||||||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>'
|
||||||
spyOn(global.mermaid, 'init')
|
spyOn(mermaid, 'init')
|
||||||
mermaid.contentLoaded()
|
mermaid.contentLoaded()
|
||||||
expect(global.mermaid.init).toHaveBeenCalled()
|
expect(mermaid.init).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user