Skip to content

Display the toolbar on touchscreens #185

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

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: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pen - What You See Is What You Get (WYSIWYG)</title>
<style type="text/css">
<style>
*{padding:0;margin:0;}
html{border-top:10px #1abf89 solid;}
body{width:800px;margin:0 auto;padding:5% 20px 20px;font-family:Palatino, Optima, Georgia, serif;}
@media all and (max-width:1024px){ body, pre a{width:60%;} }
body{max-width:800px;margin:0 auto;padding:5% 20px 20px;font-family:Palatino, Optima, Georgia, serif;}
@media all and (max-width:1024px){ body, pre a{max-width:60%;} }
small{color:#999;}
pre{white-space:pre-wrap;}

Expand Down
19 changes: 17 additions & 2 deletions src/pen.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,29 @@
addListener(ctx, editor, 'mousedown', function() {
selecting = true;
});
addListener(ctx, editor, 'touchstart', function() {
selecting = true;
});
addListener(ctx, editor, 'mouseleave', function() {
if (selecting) updateStatus(800);
selecting = false;
});
addListener(ctx, editor, 'touchleave', function() {
if (selecting) updateStatus(800);
selecting = false;
});
addListener(ctx, editor, 'mouseup', function() {
if (selecting) updateStatus(100);
selecting = false;
});
addListener(ctx, editor, 'touchend', function() {
if (selecting) updateStatus(100);
selecting = false;
});
addListener(ctx, editor, 'touchcancel', function() {
if (selecting) updateStatus(100);
selecting = false;
});
// Hide menu when focusing outside of editor
outsideClick = function(e) {
if (ctx._menu && !containsNode(editor, e.target) && !containsNode(ctx._menu, e.target)) {
Expand Down Expand Up @@ -725,7 +740,7 @@
if (!this._inputBar || !this._inputActive) return this;
}
var offset = this._range.getBoundingClientRect()
, menuPadding = 10
, menuPadding = 'ontouchstart' in window ? 20 : 10
, top = offset.top - menuPadding
, left = offset.left + (offset.width / 2)
, menu = this._menu
Expand Down Expand Up @@ -760,7 +775,7 @@
} else {
stylesheet.insertRule('.pen-menu:after {left: 50%; }', 0);
}
if (menuOffset.y < 0) {
if (menuOffset.y < 0 || 'ontouchstart' in window) {
menu.classList.add('pen-menu-below');
menuOffset.y = offset.top + offset.height + menuPadding;
} else {
Expand Down