mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-14 09:44:51 +01:00
Code refactoring: Pushing functions is now to the funs list is now available in a separate function. Also, setLink no longer using the .link attribute and instead calls links directly via window.open
This commit is contained in:
@@ -294,8 +294,6 @@ export const addTask = function (descr, data) {
|
|||||||
data: data
|
data: data
|
||||||
},
|
},
|
||||||
task: descr,
|
task: descr,
|
||||||
/* The link the rectangle will href to */
|
|
||||||
link: undefined,
|
|
||||||
classes: []
|
classes: []
|
||||||
}
|
}
|
||||||
const taskInfo = parseData(lastTaskID, data)
|
const taskInfo = parseData(lastTaskID, data)
|
||||||
@@ -325,8 +323,6 @@ export const addTaskOrg = function (descr, data) {
|
|||||||
type: currentSection,
|
type: currentSection,
|
||||||
description: descr,
|
description: descr,
|
||||||
task: descr,
|
task: descr,
|
||||||
/* The link the rectangle will href to */
|
|
||||||
link: undefined,
|
|
||||||
classes: []
|
classes: []
|
||||||
}
|
}
|
||||||
const taskInfo = compileData(lastTask, data)
|
const taskInfo = compileData(lastTask, data)
|
||||||
@@ -385,7 +381,7 @@ export const setLink = function (ids, linkStr) {
|
|||||||
ids.split(',').forEach(function (id) {
|
ids.split(',').forEach(function (id) {
|
||||||
let rawTask = findTaskById(id)
|
let rawTask = findTaskById(id)
|
||||||
if (typeof rawTask !== 'undefined') {
|
if (typeof rawTask !== 'undefined') {
|
||||||
rawTask.link = linkStr
|
pushFun(id, ()=>{window.open(linkStr, "_self")})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
setClass(ids, 'clickable')
|
setClass(ids, 'clickable')
|
||||||
@@ -412,11 +408,21 @@ const setClickFun = function (id, functionName, functionArgs) {
|
|||||||
}
|
}
|
||||||
let rawTask = findTaskById(id)
|
let rawTask = findTaskById(id)
|
||||||
if (typeof rawTask !== 'undefined') {
|
if (typeof rawTask !== 'undefined') {
|
||||||
|
pushFun(id, () => {window[functionName](id, ...functionArgs)})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callbackFunction is executed in a click event bound to the task with the specified id or the task's assigned text
|
||||||
|
* @param id The task's id
|
||||||
|
* @param callbackFunction A function to be executed when clicked on the task or the task's text
|
||||||
|
*/
|
||||||
|
const pushFun = function (id, callbackFunction){
|
||||||
funs.push(function (element) {
|
funs.push(function (element) {
|
||||||
const elem = d3.select(element).select(`[id="${id}"]`)
|
const elem = d3.select(element).select(`[id="${id}"]`)
|
||||||
if (elem !== null) {
|
if (elem !== null) {
|
||||||
elem.on('click', function () {
|
elem.on('click', function () {
|
||||||
window[functionName](id, ...functionArgs)
|
callbackFunction()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -424,13 +430,11 @@ const setClickFun = function (id, functionName, functionArgs) {
|
|||||||
const elem = d3.select(element).select(`[id="${id}-text"]`)
|
const elem = d3.select(element).select(`[id="${id}-text"]`)
|
||||||
if (elem !== null) {
|
if (elem !== null) {
|
||||||
elem.on('click', function () {
|
elem.on('click', function () {
|
||||||
console.log('test')
|
callbackFunction()
|
||||||
window[functionName](id, ...functionArgs)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by parser when a click definition is found. Registers an event handler.
|
* Called by parser when a click definition is found. Registers an event handler.
|
||||||
|
|||||||
Reference in New Issue
Block a user