Skip to content
This repository was archived by the owner on Oct 2, 2018. It is now read-only.

Commit 6f024de

Browse files
author
Joshua Smith
committed
Add swipe gesture to menu
1 parent a92dd01 commit 6f024de

7 files changed

Lines changed: 58 additions & 31 deletions

File tree

index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<script type="text/javascript" src="scripts/lib/lang-css.js"></script>
4040
<script type="text/javascript" src="scripts/lib/lang-wiki.js"></script>
4141
<script type="text/javascript" src="scripts/lib/stringview.js"></script>
42-
<script type="text/javascript" src="scripts/lib/bugsense.js"></script>
42+
<!--<script type="text/javascript" src="scripts/lib/bugsense.js"></script>-->
4343

4444
<!-- Parsers -->
4545
<script type="text/javascript" src="scripts/parsers/base64.js"></script>
@@ -76,7 +76,7 @@
7676
<body role="application">
7777
<div class="spinner center" id="loadSpinner" style="z-index: 1000;"><div></div></div>
7878

79-
<section data-type="sidebar" id="sidebar_welcome">
79+
<section data-type="sidebar" id="sidebar_welcome" data-swipe-left="sidebar" data-swipe-left-id="welcome">
8080
<header>
8181
<h1>Menu</h1>
8282
</header>
@@ -106,9 +106,11 @@ <h2>Other</h2>
106106
</nav>
107107
</section>
108108

109-
<section role="region" id="welcome">
109+
<section role="region" id="welcome"
110+
data-swipe-right="sidebar" data-swipe-right-id="welcome" data-swipe-right-state="open"
111+
data-swipe-left="sidebar" data-swipe-left-id="welcome" data-swipe-left-state="close">
110112
<header>
111-
<button data-click="sidebar" data-click-id="welcome"><span class="icon icon-menu"></span></button>
113+
<button data-click="sidebar" data-click-id="welcome" class="drawerEnabled"><span class="icon icon-menu"></span></button>
112114
<menu type="toolbar">
113115
<button data-click="nav" data-click-location="add"><span class="icon icon-create"></span></button>
114116
</menu>
@@ -201,7 +203,7 @@ <h2>Documents on Dropbox</h2>
201203
</section>
202204
<div class="background"></div>
203205

204-
<section data-type="sidebar" id="sidebar_main" data-position="right">
206+
<section data-type="sidebar" id="sidebar_main" data-position="right" data-swipe-right="sidebar" data-swipe-right-id="main">
205207
<header>
206208
<h1>Menu</h1>
207209
</header>
@@ -233,13 +235,15 @@ <h2>Other</h2>
233235
</nav>
234236
</section>
235237

236-
<section role="region" id="edit">
238+
<section role="region" id="edit"
239+
data-swipe-left="sidebar" data-swipe-left-id="main" data-swipe-left-state="open"
240+
data-swipe-right="sidebar" data-swipe-right-id="main" data-swipe-right-state="close">
237241
<header>
238242
<button data-click="closeFile"><span class="icon icon-close"></span></button>
239243
<menu type="toolbar">
240244
<button data-click="saveFromEditor" id="editorSaveButton"><span class="icon icon-save"></span></button>
241245
<button data-click="fullscreen"><span class="icon icon-fs"></span></button>
242-
<button data-click="sidebar" data-click-id="main"><span class="icon icon-menu"></span></button>
246+
<button data-click="sidebar" data-click-id="main" class="drawerEnabled"><span class="icon icon-menu"></span></button>
243247
</menu>
244248
<h1><span id="currentFileLocation" style="display:none;"></span><span id="currentFileDirectory" style="display:none;"></span><span id="currentFileName"></span><span id="currentFileType"></span></h1>
245249
</header>

scripts/firetext.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ window.addEventListener('DOMContentLoaded', function () { firetext.init(); });
4747

4848
firetext.init = function () {
4949
// Initialize Bugsense
50-
bugsenseInit();
50+
//bugsenseInit();
5151

5252
// Find device type
5353
checkDevice();
54+
55+
// Initialize gestures
56+
initGestures();
5457

5558
/* Select important elements for later */
5659
// Misc
@@ -215,14 +218,14 @@ function updateAddDialog() {
215218

216219

217220
/* Bugsense
218-
------------------------*/
221+
------------------------
219222
function bugsenseInit() {
220223
if (firetext.settings.get('stats.enabled') != 'false') {
221224
bugsense = new Bugsense({ appversion: '0.3.1', apiKey: '' });
222225
} else {
223226
bugsense = null;
224227
}
225-
}
228+
}*/
226229

227230

228231
/* Doc lists
@@ -909,6 +912,13 @@ document.addEventListener('blur', function(event) {
909912
processActions('data-blur', event.target);
910913
});
911914

915+
function initGestures () {
916+
new GestureDetector(document.body).startDetecting();
917+
document.body.addEventListener('swipe', function (event) {
918+
processActions(('data-swipe-'+event.detail.direction), event.target);
919+
});
920+
}
921+
912922
function processActions(eventAttribute, target) {
913923
if (target && target.getAttribute) {
914924
if (target.hasAttribute(eventAttribute) != true) {
@@ -931,7 +941,7 @@ function processActions(eventAttribute, target) {
931941
} else if (calledFunction == 'navBack') {
932942
regions.navBack();
933943
} else if (calledFunction == 'sidebar') {
934-
regions.sidebar(target.getAttribute(eventAttribute + '-id'));
944+
regions.sidebar(target.getAttribute(eventAttribute + '-id'), target.getAttribute(eventAttribute + '-state'));
935945
} else if (calledFunction == 'saveFromEditor') {
936946
saveFromEditor(true, true);
937947
} else if (calledFunction == 'closeFile') {

scripts/lib/gesture_detector.js

100755100644
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
* also pass an optional object as the second constructor argument. If you're
3535
* interested in holdstart/holdmove/holdend events, pass {holdEvents:true} as
3636
* this second argument. Otherwise they will not be generated.
37+
* If you want to customize the pan threshold, pass
38+
* {panThreshold:X, mousePanThreshold:Y} (X and Y in pixels) in the options
39+
* argument.
3740
*
3841
* Implementation note: event processing is done with a simple finite-state
3942
* machine. This means that in general, the various kinds of gestures are
@@ -58,6 +61,9 @@ var GestureDetector = (function() {
5861
function GD(e, options) {
5962
this.element = e;
6063
this.options = options || {};
64+
this.options.panThreshold = this.options.panThreshold || GD.PAN_THRESHOLD;
65+
this.options.mousePanThreshold =
66+
this.options.mousePanThreshold || GD.MOUSE_PAN_THRESHOLD;
6167
this.state = initialState;
6268
this.timers = {};
6369
this.listeningForMouseEvents = true;
@@ -159,7 +165,7 @@ var GestureDetector = (function() {
159165
var event = this.element.ownerDocument.createEvent('CustomEvent');
160166
event.initCustomEvent(type, true, true, detail);
161167
this.target.dispatchEvent(event);
162-
}
168+
};
163169

164170
//
165171
// Tuneable parameters
@@ -363,8 +369,8 @@ var GestureDetector = (function() {
363369
if (t.identifier !== d.touch1)
364370
return;
365371

366-
if (abs(t.screenX - d.start.screenX) > GD.PAN_THRESHOLD ||
367-
abs(t.screenY - d.start.screenY) > GD.PAN_THRESHOLD) {
372+
if (abs(t.screenX - d.start.screenX) > d.options.panThreshold ||
373+
abs(t.screenY - d.start.screenY) > d.options.panThreshold) {
368374
d.clearTimer('holdtimeout');
369375
d.switchTo(panStartedState, e, t);
370376
}
@@ -711,8 +717,8 @@ var GestureDetector = (function() {
711717
// then switch to the mouse panning state. Otherwise remain
712718
// in this state
713719

714-
if (abs(e.screenX - d.start.screenX) > GD.MOUSE_PAN_THRESHOLD ||
715-
abs(e.screenY - d.start.screenY) > GD.MOUSE_PAN_THRESHOLD) {
720+
if (abs(e.screenX - d.start.screenX) > d.options.mousePanThreshold ||
721+
abs(e.screenY - d.start.screenY) > d.options.mousePanThreshold) {
716722
d.clearTimer('holdtimeout');
717723
d.switchTo(mousePannedState, e);
718724
}

scripts/regions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ regions.navBack = function () {
9999
regions.nav(regions.history.pop());
100100
}
101101

102-
regions.sidebar = function (name) {
102+
regions.sidebar = function (name, state) {
103103
if (document.getElementById('sidebar_' + name) && document.querySelector('.current')) {
104-
if (document.querySelector('.current').getAttribute('data-state') == 'drawer') {
104+
if ((state && (state != 'open' || state == 'close')) ||
105+
(!state && document.querySelector('.current').getAttribute('data-state') == 'drawer')) {
105106
document.getElementById('sidebar_' + name).classList.remove('active');
106107
document.querySelector('.current').setAttribute('data-state', 'none');
107108
} else {

style/bb/action_menu.css

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ section[role="object"] {
1616
right: 0;
1717
bottom: 0;
1818
padding: 0 0 7rem;
19-
transform: scale(2, 2);
20-
-moz-transform: scale(2, 2);
21-
-webkit-transform: scale(2, 2);
22-
-o-transform: scale(2, 2);
23-
-ms-transform: scale(2, 2);
24-
opacity: 0;
19+
-moz-transform: translateY(100%);
20+
-webkit-transform: translateY(100%);
21+
-o-transform: translateY(100%);
22+
-ms-transform: translateY(100%);
23+
transform: translateY(100%);
24+
-moz-transition: all .4s ease;
25+
-webkit-transition: all .4s ease;
26+
-o-transition: all .4s ease;
27+
transition: all .4s ease;
2528
pointer-events: none;
26-
transition: all .4s;
27-
-moz-transition: all .4s;
28-
-webkit-transition: all .4s;
29-
-o-transition: all .4s;
3029
/**
3130
* Using "font-size: 0" to avoid the unwanted visual space (about 3px) created
3231
* by white spaces and line breaks in the code between inline-block elements.
@@ -40,11 +39,11 @@ section[role="object"].current,
4039
section[role="action"].parent,
4140
section[role="object"].parent {
4241
opacity: 1;
43-
transform: none;
4442
-moz-transform: none;
4543
-webkit-transform: none;
4644
-o-transform: none;
4745
-ms-transform: none;
46+
transform: none;
4847
pointer-events: auto;
4948
}
5049

style/bb/status.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* ---------------------------------- */
44
section[role="status"] {
55
background: #dfdfdf;
6-
background-size: auto auto, 100% 100%;
76
overflow: hidden;
87
position: absolute;
98
z-index: 100;
@@ -25,7 +24,7 @@ section[role="status"] p {
2524
font-size: 1.6rem;
2625
line-height: 1.4em;
2726
max-width: 75%;
28-
margin: 1rem 0;
27+
margin: 0;
2928
text-align: left;
3029
}
3130

style/regions.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ section[role="dialog"].current {
9696
transform: translateX(80%) !important;
9797
}
9898

99+
[data-state="drawer"].current > *:not(.drawerEnabled) {
100+
pointer-events: none;
101+
}
102+
103+
[data-state="drawer"].current .drawerEnabled {
104+
pointer-events: all;
105+
}
106+
99107
[data-state="drawer"][data-position="right"].current {
100108
-moz-transform: translateX(-80%) !important;
101109
-webkit-transform: translateX(-80%) !important;

0 commit comments

Comments
 (0)