Skip to content

Commit

Permalink
add onClearLog event
Browse files Browse the repository at this point in the history
  • Loading branch information
Maizify committed Dec 13, 2017
1 parent 1977d39 commit 83a2cdc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ English | [简体中文](./CHANGELOG_CN.md)
#### V3.x.x (dev)

- [FEATURE] Add `vConsole.showSwitch()` and `vConsole.hideSwitch()` methods, see [Public Properties & Methods](./doc/public_properties_methods.md).
- [FEATURE] Add `onReady` callback function to `vConsole.option`.
- [FEATURE] Add `onReady` and `onClearLog` callback function to `vConsole.option`.


#### V3.0.0 (2017-09-27)
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#### V3.x.x (dev)

- 【特性】新增 `vConsole.showSwitch()``vConsole.hideSwitch()` 方法,请查阅[公共属性及方法](./doc/public_properties_methods_CN.md)
- 【特性】新增 `onReady` 回调方法,位于 `vConsole.option`
- 【特性】新增 `onReady` `onClearLog` 回调方法,位于 `vConsole.option`


#### V3.0.0 (2017-09-27)
Expand Down
6 changes: 3 additions & 3 deletions dist/vconsole.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions example/demo1.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ <h1 class="page_title">Demo 1</h1>
maxLogNumber: 1000,
onReady: function() {
// console.log('vConsole is ready.');
},
onClearLog: function() {
// console.log('on clearLog');
}
});

Expand Down
13 changes: 11 additions & 2 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,17 @@ class VConsole {
this.showTab(this.tabList[0]);
}

if (tool.isFunction(this.option.onReady)) {
this.option.onReady.call(this);
this.triggerEvent('ready');
}

/**
* trigger a vConsole.option event
* @protect
*/
triggerEvent(eventName, param) {
eventName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
if (tool.isFunction(this.option[eventName])) {
this.option[eventName].apply(this, param);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/log/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class VConsoleLogTab extends VConsolePlugin {

clearLog() {
$.one('.vc-log', this.$tabbox).innerHTML = '';
this.vConsole.triggerEvent('clearLog');
}

/**
Expand Down

0 comments on commit 83a2cdc

Please sign in to comment.