From 7b1dddf26d2b52a08e55a812f5ebfba9dd853c1d Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Thu, 20 Sep 2018 15:57:28 +0800 Subject: [PATCH] fix #8 closes a notification. --- README.md | 11 ++++++++++- src/main.js | 4 ++++ website/App.js | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43241fb..bdcbc0f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ const notify = new Notify({ effect: 'flash', // flash | scroll, Flashing or scrolling openurl:'https://github.com/jaywcjlove/iNotify', // Click on the pop-up window to open the connection address onclick: () => { // Click on the pop-up window trip event + // Programmatically closes a notification. + notify.close(); console.log('---') }, // Optional playback sound @@ -168,7 +170,6 @@ iNotify.setTitle('New title') // Flashing new title iNotify.setTitle() // Clear Blinking Show original title ``` - ### setInterval Set time interval. @@ -177,6 +178,14 @@ Set time interval. iNotify.setInterval(2000) ``` +### close + +Programmatically closes a notification. + +```js +iNotify.close(); +``` + ### addTimer Add counter diff --git a/src/main.js b/src/main.js index cb2d7e0..badcb4c 100644 --- a/src/main.js +++ b/src/main.js @@ -203,6 +203,7 @@ Notify.prototype = { n.onerror = () => { (json.onerror && typeof json.onerror === 'function') && json.onerror(n); }; + this.Notifiy = n; } return this; }, @@ -270,6 +271,9 @@ Notify.prototype = { } return this; }, + close() { + if (this.Notifiy) this.Notifiy.close(); + }, // 清除Icon faviconClear() { const newicon = document.getElementById(`new${this.updateFavicon.id}`); diff --git a/website/App.js b/website/App.js index 6c223e2..83ec75e 100644 --- a/website/App.js +++ b/website/App.js @@ -71,6 +71,23 @@ export default class App extends Component { this.iN.faviconClear(); }, }, + { + label: 'Open website.', + onClick: () => { + this.iN.notify({ + title: 'Welcome to iNotify!', + body: 'You are opening the iNotify website!', + openurl: 'https://github.com/jaywcjlove/iNotify', + onclick: () => { + console.log('on click'); + this.iN.close(); + }, + onshow: () => { + console.log('on show'); + }, + }); + }, + }, { label: 'Favicon Font color', onClick: () => { @@ -100,11 +117,16 @@ export default class App extends Component { title: '通知!', body: '您来了一条新消息', }, + onclick: () => { + console.log('on click'); + this.iN.close(); + }, }); this.iN.setTitle('New news, welcome to iNotify!') .notify({ title: 'Welcome to iNotify!', body: 'You are opening the iNotify website!', + openurl: 'https://github.com/jaywcjlove/iNotify', }) .player(); }