1
0
mirror of synced 2025-12-13 10:18:40 +08:00

Dev: Expose Tool class

This commit is contained in:
surunzi
2017-11-19 16:02:16 +08:00
parent 53af31ced6
commit 3b6f7b8e0e
5 changed files with 24 additions and 16 deletions

View File

@@ -53,9 +53,12 @@ export default class DevTools extends util.Emitter
return this._isShow ? this.hide() : this.show();
}
add(tool)
{
if (!(tool instanceof Tool))
{
let {init, show, hide, destroy} = new Tool();
util.defaults(tool, {init, show, hide, destroy});
}
let name = tool.name;
if (!name) return logger.error('You must specify a name for a tool');

View File

@@ -1,23 +1,24 @@
export default class Tool
{
import util from '../lib/util';
export default util.Class({
init($el)
{
this._$el = $el;
}
},
show()
{
this._$el.show();
return this;
}
},
hide()
{
this._$el.hide();
return this;
}
},
destroy()
{
this._$el.remove();
}
}
});

View File

@@ -1,5 +1,6 @@
import EntryBtn from './EntryBtn/EntryBtn';
import DevTools from './DevTools/DevTools';
import Tool from './DevTools/Tool';
import Console from './Console/Console';
import Network from './Network/Network';
import Elements from './Elements/Elements';
@@ -34,7 +35,7 @@ module.exports = {
_isInit: false,
version: VERSION,
config, util,
Console, Elements, Network, Sources, Resources, Info, Snippets, Features,
Tool, Console, Elements, Network, Sources, Resources, Info, Snippets, Features,
get(name)
{
if (!this._checkInit()) return;

View File

@@ -1,15 +1,10 @@
import highlight from './highlight';
import beautify from 'js-beautify';
import config from './config';
export default function (util)
{
Object.assign(util, {
highlight,
beautify,
createCfg(name)
{
return config.create('eruda-' + name);
}
beautify
});
}

View File

@@ -58,7 +58,6 @@
eruda.add({name: 'test'});
eruda.add(function (eruda)
{
console.log(eruda);
return {
name: 'test2',
init: function ($el)
@@ -68,6 +67,15 @@
}
};
});
var Tool = eruda.Tool;
eruda.add(new (Tool.extend({
name: 'test3',
init: function ($el)
{
this.callSuper(Tool, 'init', arguments);
this._$el.html('This is another new plugin');
}
})));
});
addClickEvent('issue29', function ()
{