diff --git a/doc/Tool_Api.md b/doc/Tool_Api.md index 8d3e41e..eff8b02 100644 --- a/doc/Tool_Api.md +++ b/doc/Tool_Api.md @@ -74,6 +74,40 @@ console.html('Red'); ## Info +Display special information, could be used for displaying user info to track +user logs. + +By default, page url and browser user agent is shown. + +### clear + +Clear infos. + +### add + +Add infos. + +|Name |Type |Desc | +|-------|------|------------| +|name |string|Info name | +|content|string|Info content| + +```javascript +info.add('title', 'content'); +``` + +### remove + +Remove specified info. + +|Name|Type |Desc | +|----|------|---------| +|name|string|Info name| + +```javascript +info.remove('title'); +``` + ## Snippets Allow you to register small function that can be triggered multiple times. diff --git a/src/Info/Info.es6 b/src/Info/Info.es6 index 2a7db7a..6827e56 100644 --- a/src/Info/Info.es6 +++ b/src/Info/Info.es6 @@ -28,6 +28,27 @@ export default class Info extends Tool return this; } + remove(name) + { + let msgs = this._msgs; + + for (let i = 0, len = msgs.length; i < len; i++) + { + if (msgs[i].name === name) msgs.splice(i, 1); + } + + this._render(); + + return this; + } + clear() + { + this._msgs = []; + + this._render(); + + return this; + } _addDefInfo() { util.each(defInfo, info => this.add(info.name, info.val)); diff --git a/src/Info/defInfo.es6 b/src/Info/defInfo.es6 index c09a54b..33de883 100644 --- a/src/Info/defInfo.es6 +++ b/src/Info/defInfo.es6 @@ -6,9 +6,5 @@ export default [ { name: 'User Agent', val: navigator.userAgent - }, - { - name: 'Help', - val: 'Use eruda.get("info").add("name", "value") to add your own custom info.' } ]; \ No newline at end of file diff --git a/test/info.js b/test/info.js index e69de29..c3c7254 100644 --- a/test/info.js +++ b/test/info.js @@ -0,0 +1,37 @@ +var tool = eruda.get('info'), + $tool = $('.eruda-info'); + +describe('default', function () +{ + it('location', function () + { + expect($tool.find('.eruda-content').eq(0)).toContainText(location.href); + }); + + it('user agent', function () + { + expect($tool.find('.eruda-content').eq(1)).toContainText(navigator.userAgent); + }); +}); + +describe('basic', function () +{ + it('clear', function () + { + tool.clear(); + expect($tool.find('li')).toHaveLength(0); + }); + + it('add', function () + { + tool.add('test', 'eruda'); + expect($tool.find('.eruda-title')).toContainText('test'); + expect($tool.find('.eruda-content')).toContainText('eruda'); + }); + + it('remove', function () + { + tool.remove('test'); + expect($tool.find('li')).toHaveLength(0); + }); +}); \ No newline at end of file