diff --git a/doc/TOOL_API.md b/doc/TOOL_API.md index 59bd4dd..2a82f16 100644 --- a/doc/TOOL_API.md +++ b/doc/TOOL_API.md @@ -143,13 +143,14 @@ Clear infos. Add info. -|Name |Type |Desc | -|-------|------|------------| -|name |string|Info name | -|content|string|Info content| +|Name |Type |Desc | +|-------|---------------|------------| +|name |string |Info name | +|content|string function|Info content| ```javascript info.add('title', 'content'); +info.add('location', () => location.href); ``` ### remove diff --git a/src/Info/Info.js b/src/Info/Info.js index 660b309..d907be6 100644 --- a/src/Info/Info.js +++ b/src/Info/Info.js @@ -1,6 +1,6 @@ import Tool from '../DevTools/Tool'; import defInfo from './defInfo'; -import {evalCss, each} from '../lib/util'; +import {evalCss, each, isFn} from '../lib/util'; export default class Info extends Tool { @@ -20,6 +20,12 @@ export default class Info extends Tool this._addDefInfo(); } + show() + { + this._render(); + + super.show(); + } destroy() { super.destroy(); @@ -61,7 +67,16 @@ export default class Info extends Tool } _render() { - this._renderHtml(this._tpl({messages: this._msgs})); + let messages = []; + + each(this._msgs, ({name, val}) => + { + if (isFn(val)) val = val(); + + messages.push({name, val}); + }); + + this._renderHtml(this._tpl({messages})); } _renderHtml(html) { diff --git a/src/Info/defInfo.js b/src/Info/defInfo.js index 633b473..ef859eb 100644 --- a/src/Info/defInfo.js +++ b/src/Info/defInfo.js @@ -5,7 +5,10 @@ let browser = detectBrowser(); export default [ { name: 'Location', - val: location.href + val() + { + return location.href; + } }, { name: 'User Agent',