Skip to content

Commit

Permalink
Add default target
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Mar 15, 2018
1 parent e7aca11 commit 9b64fd3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ module.exports = panzoom;


function panzoom (target, cb) {
if (!target || !(cb instanceof Function)) return false;

if (target instanceof Function) {
cb = target
target = document.body || document.documentElement
}

//enable panning
let pos = position({
Expand All @@ -30,6 +32,8 @@ function panzoom (target, cb) {
impetus = new Impetus({
source: target,
update: (x, y) => {
if (impetusStoppedAt) return

let e = {
type: 'mouse',
dx: x-lastX, dy: y-lastY, dz: 0,
Expand All @@ -38,7 +42,6 @@ function panzoom (target, cb) {

lastX = x;
lastY = y;

cb(e);
},
multiplier: 1,
Expand All @@ -60,16 +63,21 @@ function panzoom (target, cb) {
let pinch = touchPinch(target);
let mult = 2;
let initialCoords;
let impetusStoppedAt;

pinch.on('start', (curr) => {
impetus && impetus.pause()

let [f1, f2] = pinch.fingers;

initialCoords = [f2.position[0]*.5 + f1.position[0]*.5, f2.position[1]*.5 + f1.position[1]*.5];

impetus && impetus.pause()
});
pinch.on('end', () => {
if (!initialCoords) return;

initialCoords = null;
impetusStoppedAt = null;

impetus && impetus.resume()
});
pinch.on('change', (curr, prev) => {
Expand Down
21 changes: 21 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Dmitry Ivanov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ See [demo](https://dfcreative.github.io/plot-grid).
```js
const panzoom = require('pan-zoom');

panzoom(target, e => {
// define interaction listener on a target
panzoom(document.body, e => {
//e contains all the params related to the interaction

//pan deltas
Expand Down
Empty file added test.js
Empty file.

0 comments on commit 9b64fd3

Please sign in to comment.