Skip to content

Commit

Permalink
feat: allow spaces in plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jul 16, 2024
1 parent c818a46 commit 447d363
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions src/DevTools/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ export default class DevTools extends Emitter {
defaults(tool, { init, show, hide, destroy })
}

let name = tool.name
if (!name) return logger.error('You must specify a name for a tool')
name = name.toLowerCase()
if (this._tools[name]) return logger.warn(`Tool ${name} already exists`)
const name = tool.name
if (!name) {
return logger.error('You must specify a name for a tool')
}

this._$tools.prepend(
`<div id="${c(name)}" class="${c(name + ' tool')}"></div>`
)
tool.init(this._$tools.find(`.${c(name)}.${c('tool')}`), this)
if (this._tools[name]) {
return logger.warn(`Tool ${name} already exists`)
}

const id = name.replace(/\s+/g, '-')
this._$tools.prepend(`<div id="${c(id)}" class="${c(id + ' tool')}"></div>`)
tool.init(this._$tools.find(`.${c(id)}.${c('tool')}`), this)
tool.active = false
this._tools[name] = tool

Expand Down Expand Up @@ -155,7 +158,9 @@ export default class DevTools extends Emitter {
if (tool) return tool
}
showTool(name) {
if (this._curTool === name) return this
if (this._curTool === name) {
return this
}
this._curTool = name

const tools = this._tools
Expand Down
2 changes: 1 addition & 1 deletion test/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
var Tool = eruda.Tool
eruda.add(
new (Tool.extend({
name: 'test3',
name: 'test plugin',
init: function ($el) {
this.callSuper(Tool, 'init', arguments)
this._$el.html('This is another new plugin')
Expand Down

0 comments on commit 447d363

Please sign in to comment.