Skip to content

Commit 89cad9b

Browse files
committed
Merge branch 'develop'
2 parents 1c94703 + 17f9602 commit 89cad9b

File tree

13 files changed

+122
-79
lines changed

13 files changed

+122
-79
lines changed

README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,42 @@ Because of this, it's often overlooked in favor of styled `<div>` combos.
1313

1414
* Cross browser reset and styling to pull `<progress>` element in line with modern slim-style bars
1515
* CSS helpers that provide classes and attributes to deal with things like positioning, growth style, simulation etc.
16-
* Optional JS helper for better control and interaction with `<progress>` elements.
16+
* Optional JS helper for better control and interaction with `<progress>` elements. For example; being able to hook into network request status and display this to the end user.
1717
* Plays nice wherever the `<progress>` element is supported!
1818

19+
```js
20+
const myEp = new Ep(document.querySelector('progress'));
21+
myEp.simulate();
22+
const xhttp = new XMLHttpRequest();
23+
xhttp.onreadystatechange = function() {
24+
if (this.readyState == 4 && this.status == 200) {
25+
myEp.complete();
26+
}
27+
};
28+
xhttp.open('GET', '/index.html', true);
29+
xhttp.send();
30+
```
31+
32+
## Index
33+
34+
* [Browser support](https://github.com/jh3y/ep#browser-support)
35+
* [Caveats](https://github.com/jh3y/ep#caveats)
36+
* [Usage](https://github.com/jh3y/ep#usage)
37+
* [Install](https://github.com/jh3y/ep#install)
38+
* [Just using the stylesheet](https://github.com/jh3y/ep#just-using-the-stylesheet)
39+
* [Including the optional JS helper](https://github.com/jh3y/ep#including-the-optional-js-helper)
40+
* [Integrating with your own SASS files](https://github.com/jh3y/ep#integrating-with-your-own-sass-files)
41+
* [CSS Helpers Api](https://github.com/jh3y/ep#css-helpers-api)
42+
* [Aesthetic helpers](https://github.com/jh3y/ep#aesthetic-helpers)
43+
* [Behavioural helpers](https://github.com/jh3y/ep#behavioural-helpers)
44+
* [Sass variables](https://github.com/jh3y/ep#sass-variables)
45+
* [Javascript Helper Api](https://github.com/jh3y/ep#javascript-helper-api)
46+
* [Hooking into network requests](https://github.com/jh3y/ep#hooking-into-network-requests)
47+
* [What happened to progrecss?](https://github.com/jh3y/ep#what-happened-to-progrecss)
48+
* [Development](https://github.com/jh3y/ep#development)
49+
* [Contributing](https://github.com/jh3y/ep#contributing)
50+
* [License](https://github.com/jh3y/ep#license)
51+
1952

2053
## Browser support
2154

@@ -160,8 +193,7 @@ As for the methods available(`?` denotes an optional parameter);
160193
* `setSpread(? {bool} spread)` - Set whether `<progress>` element should be spred style. By default will set to false.
161194
* `setIndeterminate(? {bool} indeterminate)` - Set whether `<progress>` element is using `indeterminate` helper class. By default, will remove helper class.
162195
* `togglePause` - Toggles pause attribute for play/pause animation.
163-
* `setPosition({Array string} positions)` - Takes an array of positions that will be applied to the element. For example, `['top', 'fixed']` will set `ep--top ep--fixed` class to the `<progress>` element.
164-
* `resetPosition` - Resets position by removing all classes.
196+
* `setPosition(? {Array string} positions)` - Takes an optional array of positions that will be applied to the element. For example, `['top', 'fixed']` will set `ep--top ep--fixed` class to the `<progress>` element. If no positions are declared, all currently applied will be wiped.
165197
* `increase(? {number} value, ? {function} cb)` - Increase progress value by optional increment with an optional callback. By default, increment is 5.
166198
* `decrease(? {number} value, ? {function} cb)` - Decrease progress value by optional decrement with an optional callback. By default, decrement is 5.
167199
* `reset` - Resets `<progress>` value to 0.
@@ -170,8 +202,24 @@ As for the methods available(`?` denotes an optional parameter);
170202
* `simulate(? {number} step, ? {number} increment, ? {number} max)` - Simulation on the Javascript side is an example where we have more control than we do with CSS. Set a simulation by declaring a step duration in `ms`, an `increment` and a `max` value for the simulation to reach. The default simulation will increment by 5 every second until the `<progress>` element has a value of 99.
171203
* `complete(? {function} cb)` - Complete a progress bar by setting value to 100 and then resetting it. Provide optional callback for when complete.
172204

205+
#### Hooking into network requests
206+
Yep. You can easily integrate `ep` to communicate network request status to the end user. The most basic example being something like the following;
207+
```js
208+
const myEp = new Ep(document.querySelector('progress'));
209+
myEp.reset();
210+
myEp.simulate();
211+
const xhttp = new XMLHttpRequest();
212+
xhttp.onreadystatechange = function() {
213+
if (this.readyState == 4 && this.status == 200) {
214+
myEp.complete();
215+
}
216+
};
217+
xhttp.open('GET', '/index.html', true);
218+
xhttp.send();
219+
```
220+
We start with a simple `progress` element. Reset it to make sure it starts at `0` and start a simulation. When we get the `OK` from our network request, set our element to complete :tada:
173221

174-
## What happened to progre(c)ss?
222+
## What happened to progrecss?
175223
For some time, I'd intended to revisit `progre(c)ss` with some ideas I had. When I finally got round to it, I went back over the issues and something struck me. Someone had pointed out why not use the `<progress>` element?
176224

177225
I'd previously struck this off because I liked being able to add `:pseudo` element progress bars to any element with relative ease where the `:pseudo` elements were available.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ep",
33
"main": "dist/ep.css",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"homepage": "http://jh3y.github.io/ep",
66
"authors": [
77
"jh3y <jh3y@users.noreply.github.com>"

dist/ep.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ progress {
2626
-webkit-appearance: none;
2727
-moz-appearance: none;
2828
appearance: none;
29-
background: #3498db;
3029
border: 0;
3130
display: block !important;
3231
height: 6px;
3332
opacity: 0.6;
3433
position: relative;
3534
-webkit-transition: width 0.25s ease 0s, visibility 0.5s ease 0s;
3635
transition: width 0.25s ease 0s, visibility 0.5s ease 0s;
37-
width: 0; }
36+
width: 0;
37+
background: #3498db; }
3838
progress::-ms-fill {
3939
border: 0; }
4040
progress::-moz-progress-bar {

dist/ep.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
5050

5151
/* Santize values so that value can't be set out of 0-100 range */
5252
var sanitizeValue = function sanitizeValue(val) {
53-
var min = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
54-
var max = arguments.length <= 2 || arguments[2] === undefined ? 100 : arguments[2];
53+
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
54+
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
5555

5656
var sanitized = val;
5757
if (sanitized > max) sanitized = max;
@@ -87,7 +87,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
8787
}, {
8888
key: 'setSpread',
8989
value: function setSpread() {
90-
var spread = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
90+
var spread = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
9191

9292
var cl = this._EL.classList;
9393
spread ? cl.add('ep--spread') : cl.remove('ep--spread');
@@ -107,7 +107,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
107107
}, {
108108
key: 'setIndeterminate',
109109
value: function setIndeterminate() {
110-
var indeterminate = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
110+
var indeterminate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
111111

112112
var cl = this._EL.classList;
113113
var indeterminateCL = 'ep--indeterminate';
@@ -137,24 +137,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
137137
value: function setPosition(posArr) {
138138
var _this2 = this;
139139

140-
if (posArr && posArr.length) posArr.forEach(function (pos) {
141-
return _this2._EL.classList.add('ep--' + pos);
142-
});
143-
}
144-
/**
145-
* Resets <progress> element position by removing all ep positional helpers
146-
* @returns {undefined}
147-
*/
148-
149-
}, {
150-
key: 'resetPosition',
151-
value: function resetPosition() {
152140
var positions = ['top', 'fixed', 'bottom'];
153141
for (var p = 0; p < positions.length; p++) {
154142
for (var cl = 0; cl < this._EL.classList.length; cl++) {
155143
if (this._EL.classList[cl] === 'ep--' + positions[p]) this._EL.classList.remove('ep--' + positions[p]);
156144
}
157-
}
145+
}if (posArr && posArr.length) posArr.forEach(function (pos) {
146+
return _this2._EL.classList.add('ep--' + pos);
147+
});
158148
}
159149
/**
160150
* Helper function to increase <progress> value by a value
@@ -169,7 +159,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
169159
}, {
170160
key: 'increase',
171161
value: function increase() {
172-
var amount = arguments.length <= 0 || arguments[0] === undefined ? 5 : arguments[0];
162+
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
173163
var cb = arguments[1];
174164

175165
this.set(this._VALUE + amount, cb);
@@ -187,7 +177,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
187177
}, {
188178
key: 'decrease',
189179
value: function decrease() {
190-
var amount = arguments.length <= 0 || arguments[0] === undefined ? 5 : arguments[0];
180+
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
191181
var cb = arguments[1];
192182

193183
this.set(this._VALUE - amount, cb);
@@ -231,7 +221,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
231221
}, {
232222
key: 'mock',
233223
value: function mock() {
234-
var duration = arguments.length <= 0 || arguments[0] === undefined ? 4 : arguments[0];
224+
var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
235225

236226
var _this4 = this;
237227

@@ -263,7 +253,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
263253
value: function time() {
264254
var _this5 = this;
265255

266-
var duration = arguments.length <= 0 || arguments[0] === undefined ? 4 : arguments[0];
256+
var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
267257
var cb = arguments[1];
268258

269259
var onTimerEnd = function onTimerEnd() {
@@ -292,12 +282,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
292282
}, {
293283
key: 'simulate',
294284
value: function simulate() {
295-
var step = arguments.length <= 0 || arguments[0] === undefined ? 1000 : arguments[0];
285+
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
296286

297287
var _this6 = this;
298288

299-
var increment = arguments.length <= 1 || arguments[1] === undefined ? 5 : arguments[1];
300-
var max = arguments.length <= 2 || arguments[2] === undefined ? 99 : arguments[2];
289+
var increment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
290+
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 99;
301291

302292
this._SIMULATING = setInterval(function () {
303293
var modMax = max % _this6._VALUE;

0 commit comments

Comments
 (0)