Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to display joystick before touch in semi/static mode #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [`options.restJoystick` defaults to true](#optionsrestjoystick-defaults-to-true)
* [`options.restOpacity` defaults to 0.5](#optionsrestopacity-defaults-to-05)
* [`options.catchDistance` defaults to 200](#optionscatchdistance-defaults-to-200)
* [`options.displayBeforeTouch` defaults to true](#optionsdisplaybeforetouch-defaults-to-true)
- [API](#api)
* [NippleJS instance (manager)](#nipplejs-instance-manager)
+ [`manager.on(type, handler)`](#managerontype-handler)
Expand Down Expand Up @@ -142,7 +143,8 @@ var options = {
lockY: Boolean, // only move on the Y axis
catchDistance: Number, // distance to recycle previous joystick in
// 'semi' mode
dynamicPage: Boolean, // Enable if the page has dynamically visible elements
dynamicPage: Boolean, // Enable if the page has dynamically visible elements
displayBeforeTouch: Boolean // Enable joystick display before any touch event
};
```

Expand Down Expand Up @@ -257,6 +259,9 @@ Locks joystick's movement to the y (vertical) axis
### `options.dynamicPage` defaults to true
Enable if the page has dynamically visible elements such as for Vue, React, Angular or simply some CSS hiding or showing some DOM.

### `options.displayBeforeTouch` defaults to true
Enable joystick display before any touch event. In `semi` mode, make sure `position` option has been overridden.

----

## API
Expand Down
7 changes: 5 additions & 2 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function Collection (manager, options) {
restOpacity: 0.5,
lockX: false,
lockY: false,
dynamicPage: false
dynamicPage: false,
displayBeforeTouch: true,
};

self.config(options);
Expand Down Expand Up @@ -101,7 +102,9 @@ Collection.prototype.begin = function () {

// We place our static nipple
// if needed.
if (opts.mode === 'static') {
var isModeReadyForDisplay = opts.mode === 'static' ||
opts.mode === 'semi' && opts.position !== self.defaults.position;
if (opts.displayBeforeTouch === true && isModeReadyForDisplay === true) {
var nipple = self.createNipple(
opts.position,
self.manager.getIdentifier()
Expand Down