Skip to content

Commit d0316ce

Browse files
author
Anthony Du Pont
committed
✨ Release v1.1.0
1 parent b06f628 commit d0316ce

File tree

23 files changed

+219
-45
lines changed

23 files changed

+219
-45
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,29 @@ H.on('NAVIGATE_ERROR', () => {
253253

254254
Check out the [**Basic Menu Active**](https://github.com/Dogstudio/highway/tree/master/examples/basic-menu-active) example for more details about events handling in **Highway**.
255255

256+
## Modes
257+
258+
**Highway** gives you the opportunity to choose between three transitions modes. These modes are available to let you run your transitions the way you need to create beautiful and creative navigations.
259+
260+
- `out-in`: Will run the `out` transition **then** the `in` transition (*default*).
261+
- `in-out`: Will run the `in` transition **then** the `out` transition.
262+
- `both`: Will run the `in` and `out` transition at **the same time**.
263+
264+
In order to tell **Highway** which mode you want to use, just tell it in its options.
265+
266+
```javascript
267+
// [...]
268+
const H = new Highway.Core({
269+
mode: 'both',
270+
renderers: {
271+
home: Home
272+
},
273+
transitions: {
274+
default: Transition
275+
}
276+
});
277+
```
278+
256279
## Examples
257280

258281
- [**Basic Setup**](https://github.com/Dogstudio/highway/tree/master/examples/basic-setup)
@@ -268,6 +291,10 @@ Check out the [**Basic Menu Active**](https://github.com/Dogstudio/highway/tree/
268291
- [ ] More Examples
269292

270293
## History
294+
#### 1.1.0 (2018-03-17)
295+
296+
- Introduce [**modes**](https://github.com/Dogstudio/highway/tree/master/examples/modes)
297+
271298
#### 1.0.1 (2018-03-17)
272299

273300
- Create `Highway.Transition` to use Promises instead of callbacks for transitions

dist/highway.js

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var PARAM_REGEX = /\?([\w_\-.=&]+)/;
9595
var ANCHOR_REGEX = /(#.*)$/;
9696
var ORIGIN_REGEX = /(https?:\/\/[\w\-.]+)/;
9797
var PATHNAME_REGEX = /https?:\/\/.*?(\/[\w_\-./]+)/;
98+
var CAMELCASE_REGEX = /[-_](\w)/g;
9899

99100
/**
100101
* Get origin of an URL
@@ -262,6 +263,18 @@ function getTransition(page, transitions) {
262263
return transitions[slug];
263264
}
264265

266+
/**
267+
* Converts string to camelCase
268+
*
269+
* @arg {String} string - String to parse
270+
* @return {String} Parsed string
271+
*/
272+
function camelize(string) {
273+
return string.replace(CAMELCASE_REGEX, function (_, c) {
274+
return c ? c.toUpperCase() : '';
275+
});
276+
}
277+
265278
/**
266279
* Export all helpers
267280
*/
@@ -276,7 +289,8 @@ module.exports = {
276289
getAnchor: getAnchor,
277290
getPathname: getPathname,
278291
getRenderer: getRenderer,
279-
getTransition: getTransition
292+
getTransition: getTransition,
293+
camelize: camelize
280294
};
281295

282296
/***/ }),
@@ -639,6 +653,7 @@ var HighwayCore = function (_Emitter) {
639653
_this.transitions = opts.transitions;
640654

641655
// Some usefull stuffs for later
656+
_this.mode = opts.mode || 'out-in';
642657
_this.state = {};
643658
_this.cache = {};
644659
_this.navigating = false;
@@ -857,11 +872,13 @@ var HighwayCore = function (_Emitter) {
857872

858873
this.emit('NAVIGATE_START', from, to, title, this.state);
859874

860-
// We hide the page we come `from` and since the `hide` method returns a
861-
// Promise because come transition might occur we need to wait for the
862-
// Promise resolution before calling the `show` method of the page we go `to`.
863-
this.from.hide().then(function () {
864-
_this5.to.show().then(function () {
875+
// We select the right method based on the mode provided in the options.
876+
// If no mode is provided then the `out-in` method is chosen.
877+
var method = _helpers2.default.camelize(this.mode);
878+
879+
if (typeof this[method] === 'function') {
880+
// Now we call the pipeline!
881+
this[method]().then(function () {
865882
_this5.navigating = false;
866883

867884
// We prepare the next navigation by replacing the `from` renderer by
@@ -879,7 +896,61 @@ var HighwayCore = function (_Emitter) {
879896
// Same as the `NAVIGATE_START` event
880897
_this5.emit('NAVIGATE_END', from, to, title, _this5.state);
881898
});
899+
}
900+
}
901+
902+
/**
903+
* Run `out` transition then `in` transition
904+
*
905+
* @return {Promise} `out-in` Promise
906+
*/
907+
908+
}, {
909+
key: 'outIn',
910+
value: function outIn() {
911+
var _this6 = this;
882912

913+
// Call `out` transition
914+
return this.from.hide().then(function () {
915+
// Reset scroll position
916+
window.scrollTo(0, 0);
917+
}).then(function () {
918+
// Call `in` transition
919+
_this6.to.show();
920+
});
921+
}
922+
923+
/**
924+
* Run `in` transition then `out` transition
925+
*
926+
* @return {Promise} `in-out` Promise
927+
*/
928+
929+
}, {
930+
key: 'inOut',
931+
value: function inOut() {
932+
var _this7 = this;
933+
934+
// Call the `in` transition
935+
return this.to.show().then(function () {
936+
// Reset scroll position
937+
window.scrollTo(0, 0);
938+
}).then(function () {
939+
// Call the `out` transition
940+
_this7.from.hide();
941+
});
942+
}
943+
944+
/**
945+
* Run both `in` and `out` transition at the same time.
946+
*
947+
* @return {Promise} `both` Promise
948+
*/
949+
950+
}, {
951+
key: 'both',
952+
value: function both() {
953+
return Promise.all([this.to.show(), this.from.hide()]).then(function () {
883954
// Reset scroll position
884955
window.scrollTo(0, 0);
885956
});

dist/highway.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/highway.min.js.gz

136 Bytes
Binary file not shown.

examples/basic-css-transition/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic-css-transition/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dogstudio/highway",
33
"license": "MIT",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "webpack",
@@ -16,6 +16,6 @@
1616
"webpack-cli": "^2.0.12"
1717
},
1818
"dependencies": {
19-
"@dogstudio/highway": "^1.0.1"
19+
"@dogstudio/highway": "^1.1.0"
2020
}
2121
}

examples/basic-css-transition/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# yarn lockfile v1
33

44

5-
"@dogstudio/highway@^1.0.1":
6-
version "1.0.1"
7-
resolved "https://registry.yarnpkg.com/@dogstudio/highway/-/highway-1.0.1.tgz#1d38da001396363b2502b3c38a61ba2c13921131"
5+
"@dogstudio/highway@^1.1.0":
6+
version "1.1.0"
7+
resolved "https://registry.yarnpkg.com/@dogstudio/highway/-/highway-1.1.0.tgz#f6282309ec9e9a8529b03b72e2a8d308e8dce44d"
88

99
"@sindresorhus/is@^0.7.0":
1010
version "0.7.0"

examples/basic-google-analytics/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic-google-analytics/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dogstudio/highway",
33
"license": "MIT",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "webpack",
@@ -16,6 +16,6 @@
1616
"webpack-cli": "^2.0.12"
1717
},
1818
"dependencies": {
19-
"@dogstudio/highway": "^1.0.1"
19+
"@dogstudio/highway": "^1.1.0"
2020
}
2121
}

examples/basic-google-analytics/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# yarn lockfile v1
33

44

5-
"@dogstudio/highway@^1.0.1":
6-
version "1.0.1"
7-
resolved "https://registry.yarnpkg.com/@dogstudio/highway/-/highway-1.0.1.tgz#1d38da001396363b2502b3c38a61ba2c13921131"
5+
"@dogstudio/highway@^1.1.0":
6+
version "1.1.0"
7+
resolved "https://registry.yarnpkg.com/@dogstudio/highway/-/highway-1.1.0.tgz#f6282309ec9e9a8529b03b72e2a8d308e8dce44d"
88

99
"@sindresorhus/is@^0.7.0":
1010
version "0.7.0"

0 commit comments

Comments
 (0)