mirror of
https://github.com/liriliri/eruda.git
synced 2026-04-05 10:28:34 +08:00
Dev: Add destroy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eruda",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"description": "Console for mobile JavaScript",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -50,6 +50,7 @@ export default class Console extends Tool
|
||||
{
|
||||
var log = this._log;
|
||||
|
||||
this._origOnerror = window.onerror;
|
||||
window.onerror = (errMsg, url, lineNum, column, errObj) =>
|
||||
{
|
||||
if (errObj) return log.error(errObj);
|
||||
@@ -58,6 +59,12 @@ export default class Console extends Tool
|
||||
|
||||
return this;
|
||||
}
|
||||
destroy()
|
||||
{
|
||||
super.destroy();
|
||||
|
||||
window.onerror = this._origOnerror;
|
||||
}
|
||||
_appendTpl()
|
||||
{
|
||||
var $el = this._$el;
|
||||
@@ -89,8 +96,10 @@ export default class Console extends Tool
|
||||
log.input(jsInput);
|
||||
|
||||
$jsInput.val('');
|
||||
$jsInput.get(0).blur();
|
||||
}
|
||||
});
|
||||
}).on('focusin', () => $jsInput.css({height: '100%'}))
|
||||
.on('focusout', () => $jsInput.css({height: '40px'}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<div class="eruda-logs"></div>
|
||||
<input class="eruda-js-input" type="text" placeholder="Type JavaScript here"/>
|
||||
<textarea class="eruda-js-input" type="text" placeholder="Type JavaScript here"></textarea>
|
||||
|
||||
@@ -61,11 +61,11 @@ export default class DevTools
|
||||
remove(name)
|
||||
{
|
||||
var tool = this._tools[name];
|
||||
delete this._tools[name];
|
||||
this._$tools.find('.eruda-' + name);
|
||||
|
||||
delete this._tools[name];
|
||||
this._navBar.remove(name);
|
||||
|
||||
tool.destroy();
|
||||
if (tool.active)
|
||||
{
|
||||
var keys = util.keys(this._tools);
|
||||
@@ -80,6 +80,12 @@ export default class DevTools
|
||||
|
||||
if (tool) return tool;
|
||||
}
|
||||
destroy()
|
||||
{
|
||||
util.each(this._tools, (tool, key) => this.remove(key));
|
||||
this._navBar.destroy();
|
||||
this._$el.remove();
|
||||
}
|
||||
showTool(name)
|
||||
{
|
||||
var tools = this._tools;
|
||||
|
||||
@@ -24,6 +24,10 @@ export default class NavBar extends util.Emitter
|
||||
this._$el.find('li.' + name).remove();
|
||||
this._$el.css({width: this._len * 69});
|
||||
}
|
||||
destroy()
|
||||
{
|
||||
this._$el.remove();
|
||||
}
|
||||
activeTool(name)
|
||||
{
|
||||
var $el = this._$el;
|
||||
|
||||
@@ -16,4 +16,8 @@ export default class Tool
|
||||
|
||||
return this;
|
||||
}
|
||||
destroy()
|
||||
{
|
||||
this._$el.remove();
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ settings.separator()
|
||||
|
||||
function appendContainer()
|
||||
{
|
||||
util.$('#eruda').remove();
|
||||
if (eruda) eruda.destroy();
|
||||
util.$('body').append('<div id="eruda"></div>');
|
||||
$container = util.$('#eruda');
|
||||
}
|
||||
@@ -79,6 +79,12 @@ module.exports = {
|
||||
|
||||
return this;
|
||||
},
|
||||
destroy()
|
||||
{
|
||||
devTools.destroy();
|
||||
$container.remove();
|
||||
window.eruda = undefined;
|
||||
},
|
||||
util
|
||||
};
|
||||
|
||||
|
||||
@@ -18,11 +18,5 @@
|
||||
document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
|
||||
})();
|
||||
</script>
|
||||
<script>
|
||||
(function () {
|
||||
if (!eruda) return;
|
||||
eruda.remove('console');
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user