Skip to content

Commit e053d2d

Browse files
committed
refactor Pinch: move bind to a file
1 parent b8a5e8b commit e053d2d

2 files changed

Lines changed: 53 additions & 52 deletions

File tree

lib/interaction/Pinch/bind.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = function () {
2+
// @tapspace.interaction.Pinch:bind()
3+
//
4+
// Bind gesture event listeners.
5+
//
6+
if (this.bound) {
7+
return
8+
}
9+
this.bound = true
10+
11+
// Pass 'this' for handlers.
12+
const self = this
13+
14+
this.ongesturestart = (ev) => {
15+
// Mark as active. TODO allow custom class name
16+
self.target.element.classList.add('active-pinch')
17+
self.source.emit('pinchstart', ev)
18+
}
19+
this.ongesturemove = (ev) => {
20+
// DEBUG
21+
// console.log('pivot', ev.center.point)
22+
// console.log('freedom', self.capturer.getFreedom())
23+
// console.log('ev.delta', ev.delta.helm)
24+
self.applyTransform(ev)
25+
self.source.emit('pinchmove', ev)
26+
self.source.emit('pinch', ev)
27+
}
28+
this.ongestureend = (ev) => {
29+
// Deactivate styling, for example grabbing cursor
30+
self.target.element.classList.remove('active-pinch')
31+
self.source.emit('pinchend', ev)
32+
}
33+
this.ongesturecancel = (ev) => {
34+
// TODO Return the target to the original position
35+
// TODO by using the total transform.
36+
self.target.element.classList.remove('active-pinch')
37+
self.source.emit('pinchcancel', ev)
38+
}
39+
40+
// Capturer options determine the gesture freedom.
41+
const capturerOptions = {}
42+
if (this.options.freedom) {
43+
capturerOptions.freedom = this.options.freedom
44+
}
45+
// Bind listeners to the component capturer.
46+
this.capturer = this.source.capturer('gesture', capturerOptions)
47+
this.capturer.on('gesturestart', this.ongesturestart)
48+
this.capturer.on('gesturemove', this.ongesturemove)
49+
this.capturer.on('gestureend', this.ongestureend)
50+
this.capturer.on('gesturecancel', this.ongesturecancel)
51+
}

lib/interaction/Pinch/index.js

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,60 +78,10 @@ const PinchGesture = function (source, target, options) {
7878

7979
module.exports = PinchGesture
8080
const proto = PinchGesture.prototype
81-
82-
proto.bind = function () {
83-
// @tapspace.interaction.Pinch:bind()
84-
//
85-
// Bind gesture event listeners.
86-
//
87-
if (this.bound) {
88-
return
89-
}
90-
this.bound = true
91-
92-
// Pass 'this' for handlers.
93-
const self = this
94-
95-
this.ongesturestart = (ev) => {
96-
// Mark as active. TODO allow custom class name
97-
self.target.element.classList.add('active-pinch')
98-
self.source.emit('pinchstart', ev)
99-
}
100-
this.ongesturemove = (ev) => {
101-
// DEBUG
102-
// console.log('pivot', ev.center.point)
103-
// console.log('freedom', self.capturer.getFreedom())
104-
// console.log('ev.delta', ev.delta.helm)
105-
self.applyTransform(ev)
106-
self.source.emit('pinchmove', ev)
107-
self.source.emit('pinch', ev)
108-
}
109-
this.ongestureend = (ev) => {
110-
// Deactivate styling, for example grabbing cursor
111-
self.target.element.classList.remove('active-pinch')
112-
self.source.emit('pinchend', ev)
113-
}
114-
this.ongesturecancel = (ev) => {
115-
// TODO Return the target to the original position
116-
// TODO by using the total transform.
117-
self.target.element.classList.remove('active-pinch')
118-
self.source.emit('pinchcancel', ev)
119-
}
120-
121-
// Capturer options determine the gesture freedom.
122-
const capturerOptions = {}
123-
if (this.options.freedom) {
124-
capturerOptions.freedom = this.options.freedom
125-
}
126-
// Bind listeners to the component capturer.
127-
this.capturer = this.source.capturer('gesture', capturerOptions)
128-
this.capturer.on('gesturestart', this.ongesturestart)
129-
this.capturer.on('gesturemove', this.ongesturemove)
130-
this.capturer.on('gestureend', this.ongestureend)
131-
this.capturer.on('gesturecancel', this.ongesturecancel)
132-
}
81+
proto.isPinch = true
13382

13483
proto.applyTransform = require('./applyTransform')
84+
proto.bind = require('./bind')
13585
proto.disableDilation = require('./disableDilation')
13686
proto.disableRotation = require('./disableRotation')
13787
proto.disableTranslation = require('./disableTranslation')

0 commit comments

Comments
 (0)