Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit cb214ae

Browse files
Merge pull request #87 from readium/fixes/gestures
Take into account more interactive elements when handling EPUB gesture events
2 parents 8b847da + 8f8050b commit cb214ae

File tree

5 files changed

+33
-45
lines changed

5 files changed

+33
-45
lines changed

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
language: swift
22
osx_image: xcode11
3+
xcode_project: r2-navigator-swift.xcodeproj
4+
xcode_scheme: r2-navigator-swift
5+
xcode_destination: platform=iOS Simulator,OS=11.3,name=iPhone X
6+
xcode_sdk: iphonesimulator13.0
37

48
branches:
59
only:
@@ -13,7 +17,8 @@ cache:
1317
before_install:
1418
- brew update
1519
- brew outdated carthage || brew upgrade carthage
16-
- carthage update --verbose --no-use-binaries --platform iOS --cache-builds
20+
- carthage bootstrap --verbose --no-use-binaries --platform iOS --cache-builds
1721

1822
script:
19-
- xcodebuild clean build -project r2-navigator-swift.xcodeproj -scheme r2-navigator-swift -quiet
23+
- xcodebuild clean build -quiet
24+

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "readium/r2-shared-swift" == 1.4.1
1+
github "readium/r2-shared-swift" == 1.4.2

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "readium/r2-shared-swift" "1.4.1"
1+
github "readium/r2-shared-swift" "1.4.2"

R2Navigator.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Pod::Spec.new do |s|
22

33
s.name = "R2Navigator"
4-
s.version = "1.2.2"
4+
s.version = "1.2.3"
55
s.license = "BSD 3-Clause License"
66
s.summary = "R2 Navigator"
77
s.homepage = "http://readium.github.io"
88
s.author = { "Aferdita Muriqi" => "aferdita.muriqi@gmail.com" }
9-
s.source = { :git => "https://github.com/readium/r2-navigator-swift.git", :tag => "1.2.2" }
9+
s.source = { :git => "https://github.com/readium/r2-navigator-swift.git", :tag => "1.2.3" }
1010
s.exclude_files = ["**/Info*.plist"]
1111
s.requires_arc = true
1212
s.resources = ['r2-navigator-swift/Resources/**']

r2-navigator-swift/EPUB/Resources/Scripts/gestures.js

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,41 @@
11
(function() {
2-
var isTapping = false;
3-
var touchStartTime = null;
4-
var startX = 0;
5-
var startY = 0;
6-
7-
document.addEventListener('touchstart', touchstart, false);
8-
document.addEventListener('touchend', touchend, false);
9-
10-
function touchstart(event) {
11-
isTapping = (event.touches.length == 1);
12-
if (isInteractiveElement(event.target) || !isTapping) {
13-
return;
14-
}
15-
16-
var touch = event.changedTouches[0];
17-
startX = touch.pageX;
18-
startY = touch.pageY;
19-
touchStartTime = Date.now();
20-
}
2+
window.addEventListener('DOMContentLoaded', function(event) {
3+
// If we don't set the CSS cursor property to pointer, then the click events are not triggered pre-iOS 13.
4+
document.body.style.cursor = 'pointer';
5+
6+
document.addEventListener('click', onClick, false);
7+
});
218

22-
function touchend(event) {
23-
if (!isTapping || touchStartTime == null || Date.now() - touchStartTime > 500) {
9+
function onClick(event) {
10+
if (event.defaultPrevented || isInteractiveElement(event.target)) {
2411
return;
2512
}
26-
isTapping = false;
27-
28-
var touch = event.changedTouches[0];
2913

30-
function approximatelyEqual(a, b) {
31-
return Math.abs(a - b) < 2;
32-
}
33-
34-
if (!approximatelyEqual(startX, touch.pageX) || !approximatelyEqual(startY, touch.pageY)) {
35-
return;
36-
}
37-
3814
if (!window.getSelection().isCollapsed) {
3915
// There's an on-going selection, the tap will dismiss it so we don't forward it.
4016
return;
4117
}
4218

4319
webkit.messageHandlers.tap.postMessage({
44-
"screenX": touch.screenX,
45-
"screenY": touch.screenY,
46-
"clientX": touch.clientX,
47-
"clientY": touch.clientY,
20+
"screenX": event.screenX,
21+
"screenY": event.screenY,
22+
"clientX": event.clientX,
23+
"clientY": event.clientY,
4824
});
4925

5026
// We don't want to disable the default WebView behavior as it breaks some features without bringing any value.
5127
// event.stopPropagation();
5228
// event.preventDefault();
5329
}
5430

31+
// See. https://github.com/JayPanoz/architecture/tree/touch-handling/misc/touch-handling
5532
function isInteractiveElement(element) {
5633
var interactiveTags = [
5734
'a',
35+
'audio',
5836
'button',
37+
'canvas',
38+
'details',
5939
'input',
6040
'label',
6141
'option',
@@ -64,10 +44,13 @@
6444
'textarea',
6545
'video',
6646
]
67-
68-
// https://stackoverflow.com/questions/4878484/difference-between-tagname-and-nodename
6947
if (interactiveTags.indexOf(element.nodeName.toLowerCase()) != -1) {
70-
return true;
48+
return true;
49+
}
50+
51+
// Checks whether the element is editable by the user.
52+
if (element.hasAttribute('contenteditable') && element.getAttribute('contenteditable').toLowerCase() != 'false') {
53+
return true;
7154
}
7255

7356
// Checks parents recursively because the touch might be for example on an <em> inside a <a>.

0 commit comments

Comments
 (0)