Dev: Expose Tool class
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user