Commit 4dfbfa2c authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #141 from hypothesis/fix-prevent-default-override

Fix prevent default override
parents 212ddc11 ffca6a90
...@@ -4,6 +4,11 @@ var classnames = require('classnames'); ...@@ -4,6 +4,11 @@ var classnames = require('classnames');
var template = require('./adder.html'); var template = require('./adder.html');
var ANNOTATE_BTN_CLASS = 'js-annotate-btn';
var ANNOTATE_BTN_SELECTOR = '.js-annotate-btn';
var HIGHLIGHT_BTN_SELECTOR = '.js-highlight-btn';
/** /**
* Show the adder above the selection with an arrow pointing down at the * Show the adder above the selection with an arrow pointing down at the
* selected text. * selected text.
...@@ -95,6 +100,7 @@ function createAdderDOM(container) { ...@@ -95,6 +100,7 @@ function createAdderDOM(container) {
*/ */
function Adder(container, options) { function Adder(container, options) {
var self = this;
var element = createAdderDOM(container); var element = createAdderDOM(container);
Object.assign(container.style, { Object.assign(container.style, {
...@@ -118,22 +124,24 @@ function Adder(container, options) { ...@@ -118,22 +124,24 @@ function Adder(container, options) {
var view = element.ownerDocument.defaultView; var view = element.ownerDocument.defaultView;
var enterTimeout; var enterTimeout;
element.querySelector('.js-annotate-btn') element.querySelector(ANNOTATE_BTN_SELECTOR)
.addEventListener('click', handleCommand.bind(this, 'annotate')); .addEventListener('click', handleCommand);
element.querySelector('.js-highlight-btn') element.querySelector(HIGHLIGHT_BTN_SELECTOR)
.addEventListener('click', handleCommand.bind(this, 'highlight')); .addEventListener('click', handleCommand);
function handleCommand(command, event) { function handleCommand(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
if (command === 'annotate') { var isAnnotateCommand = this.classList.contains(ANNOTATE_BTN_CLASS);
if (isAnnotateCommand) {
options.onAnnotate(); options.onAnnotate();
} else { } else {
options.onHighlight(); options.onHighlight();
} }
this.hide(); self.hide();
} }
function width() { function width() {
...@@ -221,6 +229,14 @@ function Adder(container, options) { ...@@ -221,6 +229,14 @@ function Adder(container, options) {
'annotator-adder--arrow-up': arrowDirection === ARROW_POINTING_UP, 'annotator-adder--arrow-up': arrowDirection === ARROW_POINTING_UP,
}); });
// Some sites make big assumptions about interactive
// elements on the page. Some want to hide interactive elements
// after use. So we need to make sure the button stays displayed
// the way it was originally displayed - without the inline styles
// See: https://github.com/hypothesis/client/issues/137
this.element.querySelector(ANNOTATE_BTN_SELECTOR).style.display = '';
this.element.querySelector(HIGHLIGHT_BTN_SELECTOR).style.display = '';
Object.assign(container.style, { Object.assign(container.style, {
top: toPx(top), top: toPx(top),
left: toPx(left), left: toPx(left),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment