Dev: Add destroy

This commit is contained in:
surunzi
2016-04-06 13:58:47 +08:00
parent 5bd69c5742
commit 6ca0916f39
8 changed files with 35 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "eruda",
"version": "0.0.6",
"version": "0.0.7",
"description": "Console for mobile JavaScript",
"main": "index.js",
"scripts": {

View File

@@ -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'}))
}
}

View File

@@ -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>

View File

@@ -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;

View File

@@ -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;

View File

@@ -16,4 +16,8 @@ export default class Tool
return this;
}
destroy()
{
this._$el.remove();
}
}

View File

@@ -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
};

View File

@@ -18,11 +18,5 @@
document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
})();
</script>
<script>
(function () {
if (!eruda) return;
eruda.remove('console');
})();
</script>
</body>
</html>