Skip to content

Commit ba1bd2b

Browse files
committed
save commit
1 parent 3d6de20 commit ba1bd2b

File tree

8 files changed

+116
-125
lines changed

8 files changed

+116
-125
lines changed

.postcssrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ plugins:
33
postcss-cssnext: {}
44
postcss-nesting: {}
55
postcss-nested: {}
6-
postcss-nested-ancestors: {}
6+
postcss-nested-ancestors: {}
7+
postcss-clean: {}

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,68 @@
11
# JavaScript Notifier
2+
23
Lightweight notification module for websites
34

45
## Instalation
56

67
### Install via npm
8+
79
Install package
10+
811
```
912
npm install codex-notifier --save
1013
```
1114

1215
#### Connect with Webpack
16+
1317
Require module in your application
18+
1419
```javascript
1520
var notifier = require('exports-loader?notifier!codex-notifier');
1621
```
1722

1823
Import styles
24+
1925
```css
2026
@import url('~codex-notifier/notifier.css');
2127
```
2228

2329
You will need [exports-loader](https://www.npmjs.com/package/exports-loader) and [css-loader]('https://www.npmjs.com/package/css-loader').
2430

25-
2631
### Install directly
32+
2733
1. Download `notifier.js` and `notifier.css` files
2834
2. Add them to your page
2935

3036
### Add from CDN
37+
3138
Add script and stylesheets files from GitHub
39+
3240
```html
3341
<script src="https://cdn.rawgit.com/codex-team/js-notifier/master/notifier.js"></script>
3442
<link rel="stylesheet" href="https://cdn.rawgit.com/codex-team/js-notifier/master/notifier.css">
3543
```
3644

3745
## Usage
46+
3847
Module has only one public method — `show`.
3948
You should pass there object with notification properties
4049

4150
#### General properties
51+
4252
- `message` — notification message (can contains HTML)
4353
- `type` — type of notification: `alert`, `confirm` or `prompt`. `Alert` by default
4454
- `style` — just add `'cdx-notify--' + style` class. We have some default styles: `success` and `error`
4555
- `time` — notification expire time in ms. Only for `alert` notifies expires (8s by default)
4656

4757
#### Confirm notifications properties
58+
4859
- `okText` — text for confirmation button (*Confirm* by default)
4960
- `cancelText` — text for cancel button (*Cancel* by default)
5061
- `okHandler` — fires when *Confirm* button was pressed
5162
- `cancelHandler` — fires when *Cancel* button was pressed or notification was closed
5263

5364
#### Prompt notifications properties
65+
5466
- `okText` — text for submit button (*Ok* by default)
5567
- `okHandler` — fires when submit button was pressed. Gets input's value as a parameter
5668
- `cancelHandler` — fires when notification was closed
@@ -59,27 +71,34 @@ You should pass there object with notification properties
5971
- `inputType` — type of input (text by default)
6072

6173
## Examples
74+
6275
```javascript
6376
notifier.show({
6477
message: 'Refresh the page'
6578
})
6679
```
80+
6781
![Notify](https://github.com/codex-team/js-notifier/raw/master/docs/examples/notify.png)
82+
6883
```javascript
6984
notifier.show({
7085
message: 'Message was sent',
7186
style: 'success',
7287
time: 5000
7388
})
7489
```
90+
7591
![Success](https://github.com/codex-team/js-notifier/raw/master/docs/examples/success.png)
92+
7693
```javascript
7794
notifier.show({
7895
message: 'Sorry, server is busy now',
7996
style: 'error'
8097
})
8198
```
99+
82100
![Error](https://github.com/codex-team/js-notifier/raw/master/docs/examples/error.png)
101+
83102
```javascript
84103
notifier.show({
85104
message: 'Delete account?',
@@ -89,7 +108,9 @@ notifier.show({
89108
okHandler: account.delete
90109
})
91110
```
111+
92112
![Confirm](https://github.com/codex-team/js-notifier/raw/master/docs/examples/confirm.png)
113+
93114
```javascript
94115
notifier.show({
95116
message: 'Enter your email',
@@ -100,7 +121,9 @@ notifier.show({
100121
placeholder: '[email protected]'
101122
})
102123
```
124+
103125
![Prompt](https://github.com/codex-team/js-notifier/raw/master/docs/examples/prompt.png)
104126

105127
## Custom styles
128+
106129
You can easily customize notifications appearance. Read more about it [here](https://github.com/codex-team/js-notifier/blob/master/docs/styles.md)

dist/bundle.js

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
{
22
"name": "codex-notifier",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Simple notifications for your website",
5-
"main": "./notifier.js",
5+
"main": "./dist/bundle.js",
66
"scripts": {
7-
"build": "webpack"
7+
"build": "webpack --config ./webpack.config.js --mode production --watch"
8+
},
9+
"license": "MIT",
10+
"author": {
11+
"name": "CodeX Team",
12+
"email": "[email protected]"
813
},
914
"repository": {
1015
"type": "git",
1116
"url": "git+https://github.com/codex-team/js-notifier.git"
1217
},
13-
"author": "Codex-Team",
14-
"license": "MIT",
1518
"bugs": {
1619
"url": "https://github.com/codex-team/js-notifier/issues"
1720
},
1821
"homepage": "https://github.com/codex-team/js-notifier#readme",
1922
"devDependencies": {
20-
"babel-core": "^6.25.0",
21-
"babel-loader": "^7.0.0",
22-
"babel-preset-es2015": "^6.24.1",
23-
"webpack": "^2.6.1",
24-
"css-loader": "^0.28.4",
25-
"extract-text-webpack-plugin": "^2.1.2",
23+
"babel-core": "^6.26.3",
24+
"babel-loader": "^7.1.5",
25+
"babel-preset-env": "^1.7.0",
26+
"css-loader": "^1.0.0",
27+
"postcss-clean": "^1.1.0",
2628
"postcss-cssnext": "^2.11.0",
2729
"postcss-loader": "^2.0.6",
28-
"postcss-smart-import": "^0.7.4",
2930
"postcss-nested": "^2.0.2",
3031
"postcss-nested-ancestors": "^1.0.0",
31-
"postcss-nesting": "^4.0.1"
32+
"postcss-nesting": "^4.0.1",
33+
"postcss-smart-import": "^0.7.4",
34+
"style-loader": "^0.21.0",
35+
"webpack": "^4.16.3",
36+
"webpack-cli": "^3.1.0"
37+
},
38+
"babel": {
39+
"presets": [
40+
"env"
41+
]
3242
}
3343
}

src/css/base.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@
137137

138138
}
139139

140-
}
140+
}

src/draw.js

+22-37
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ module.exports = function () {
1111
btnsWrapper: 'cdx-notify__btns-wrapper'
1212
};
1313

14-
let alert = function (options) {
15-
16-
let notify = document.createElement('DIV'),
17-
cross = document.createElement('DIV'),
14+
const alert = function alert(options) {
15+
let notify = document.createElement('DIV'),
16+
cross = document.createElement('DIV'),
1817
message = options.message,
19-
style = options.style;
18+
style = options.style;
2019

2120
notify.classList.add(CSS_.notification);
22-
if (style) {
2321

22+
if (style) {
2423
notify.classList.add(CSS_.notification + '--' + style);
25-
2624
}
25+
2726
notify.innerHTML = message;
2827

2928
cross.classList.add(CSS_.crossBtn);
@@ -32,10 +31,9 @@ module.exports = function () {
3231
notify.appendChild(cross);
3332

3433
return notify;
34+
};
3535

36-
}
37-
38-
let confirm = function (options) {
36+
const confirm = function confirm(options) {
3937

4038
let notify = alert(options);
4139

@@ -57,16 +55,12 @@ module.exports = function () {
5755
cancelBtn.classList.add(CSS_.cancelBtn);
5856

5957
if (cancelHandler && typeof cancelHandler === 'function') {
60-
61-
cancelBtn.addEventListener('click', cancelHandler)
62-
crossBtn.addEventListener('click', cancelHandler)
63-
58+
cancelBtn.addEventListener('click', cancelHandler);
59+
crossBtn.addEventListener('click', cancelHandler);
6460
}
6561

6662
if (okHandler && typeof okHandler === 'function') {
67-
6863
okBtn.addEventListener('click', okHandler);
69-
7064
}
7165

7266
okBtn.addEventListener('click', notify.remove.bind(notify));
@@ -78,10 +72,9 @@ module.exports = function () {
7872
notify.appendChild(btnsWrapper);
7973

8074
return notify;
75+
};
8176

82-
}
83-
84-
let prompt = function (options) {
77+
const prompt = function prompt(options) {
8578

8679
let notify = alert(options);
8780

@@ -101,25 +94,19 @@ module.exports = function () {
10194
input.classList.add(CSS_.input);
10295

10396
if (options.placeholder) {
104-
10597
input.setAttribute('placeholder', options.placeholder);
106-
10798
}
108-
if (options.default) {
10999

100+
if (options.default) {
110101
input.value = options.default;
111-
112102
}
113-
if (options.inputType) {
114103

104+
if (options.inputType) {
115105
input.type = options.inputType;
116-
117106
}
118107

119108
if (cancelHandler && typeof cancelHandler === 'function') {
120-
121109
crossBtn.addEventListener('click', cancelHandler)
122-
123110
}
124111

125112
if (okHandler && typeof okHandler === 'function') {
@@ -140,25 +127,23 @@ module.exports = function () {
140127
notify.appendChild(btnsWrapper);
141128

142129
return notify;
130+
};
143131

144-
145-
}
146-
147-
let wrapper = function () {
132+
const getWrapper = function getWrapper() {
148133

149134
let wrapper = document.createElement('DIV');
150135

151136
wrapper.classList.add(CSS_.wrapper);
152137

153138
return wrapper;
154139

155-
}
140+
};
156141

157142
return {
158-
alert: alert,
159-
confirm: confirm,
160-
prompt: prompt,
161-
wrapper: wrapper
143+
alert,
144+
confirm,
145+
prompt,
146+
getWrapper
162147
}
163148

164-
}()
149+
}();

0 commit comments

Comments
 (0)