Commit 63e2da2f authored by Eduardo's avatar Eduardo

Revert "Rename methods hide/show to open/close"

This reverts commit 85f6023f.
parent df326eef
......@@ -206,14 +206,14 @@ export default class Guest extends Delegator {
// Hide the sidebar in response to a document click or tap, so it doesn't obscure
// the document content.
const maybeCloseSidebar = event => {
const maybeHideSidebar = event => {
if (!this.closeSidebarOnDocumentClick || this.isEventInAnnotator(event)) {
// Don't hide the sidebar if event occurred inside Hypothesis UI, or
// the user is making a selection, or the behavior was disabled because
// the sidebar doesn't overlap the content.
return;
}
this.crossframe?.call('closeSidebar');
this.crossframe?.call('hideSidebar');
};
addListener('click', event => {
......@@ -222,7 +222,7 @@ export default class Guest extends Delegator {
const toggle = event.metaKey || event.ctrlKey;
this.selectAnnotations(annotations, toggle);
} else {
maybeCloseSidebar(event);
maybeHideSidebar(event);
}
});
......@@ -230,7 +230,7 @@ export default class Guest extends Delegator {
// on touch-input devices, not all elements will generate a "click" event.
addListener('touchstart', event => {
if (!annotationsAt(event.target).length) {
maybeCloseSidebar(event);
maybeHideSidebar(event);
}
});
......@@ -593,7 +593,7 @@ export default class Guest extends Delegator {
targets.then(() => this.anchor(/** @type {AnnotationData} */ (annotation)));
if (!annotation.$highlight) {
this.crossframe?.call('openSidebar');
this.crossframe?.call('showSidebar');
}
return annotation;
}
......@@ -617,7 +617,7 @@ export default class Guest extends Delegator {
showAnnotations(annotations) {
const tags = annotations.map(a => a.$tag);
this.crossframe?.call('showAnnotations', tags);
this.crossframe?.call('openSidebar');
this.crossframe?.call('showSidebar');
}
/**
......
import Delegator from './delegator';
import { createSidebarConfig } from './config/sidebar';
import { createShadowRoot } from './util/shadow-root';
import { render } from 'preact';
/**
* Create the iframe that will load the notebook application.
......@@ -52,13 +51,13 @@ export default class Notebook extends Delegator {
*/
this.container = null;
this.subscribe('openNotebook', groupId => {
this.subscribe('showNotebook', groupId => {
this._groupId = groupId;
this.open();
this.show();
});
this.subscribe('closeNotebook', () => this.close());
this.subscribe('hideNotebook', () => this.hide());
// If the sidebar has opened, get out of the way
this.subscribe('sidebarOpened', () => this.close());
this.subscribe('sidebarOpened', () => this.hide());
}
_update() {
......@@ -77,14 +76,14 @@ export default class Notebook extends Delegator {
}
}
open() {
show() {
const container = this._initContainer();
this._update();
container.classList.add('is-open');
container.style.display = '';
}
close() {
hide() {
if (this.container) {
this.container.classList.remove('is-open');
this.container.style.display = 'none';
......
......@@ -127,14 +127,14 @@ export default class Sidebar extends Guest {
config.query ||
config.group
) {
this.subscribe('panelReady', () => this.open());
this.subscribe('panelReady', () => this.show());
}
// Set up the toolbar on the left edge of the sidebar.
const toolbarContainer = document.createElement('div');
this.toolbar = new ToolbarController(toolbarContainer, {
createAnnotation: () => this.createAnnotation(),
setSidebarOpen: open => (open ? this.open() : this.close()),
setSidebarOpen: open => (open ? this.show() : this.hide()),
setHighlightsVisible: show => this.setAllVisibleHighlights(show),
});
this.toolbar.useMinimalControls = config.theme === 'clean';
......@@ -159,7 +159,7 @@ export default class Sidebar extends Guest {
final: /** @type {number|null} */ (null),
};
this._setupGestures();
this.close();
this.hide();
// Publisher-provided callback functions
const [serviceConfig] = config.services || [];
......@@ -205,21 +205,21 @@ export default class Sidebar extends Guest {
_setupSidebarEvents() {
annotationCounts(document.body, this.crossframe);
sidebarTrigger(document.body, () => this.open());
sidebarTrigger(document.body, () => this.show());
features.init(this.crossframe);
this.crossframe.on('openSidebar', () => this.open());
this.crossframe.on('closeSidebar', () => this.close());
this.crossframe.on('showSidebar', () => this.show());
this.crossframe.on('hideSidebar', () => this.hide());
// Re-publish the crossframe event so that anything extending Delegator
// can subscribe to it (without need for crossframe)
this.crossframe.on('openNotebook', groupId => {
this.close();
this.publish('openNotebook', [groupId]);
this.crossframe.on('showNotebook', groupId => {
this.hide();
this.publish('showNotebook', [groupId]);
});
this.crossframe.on('closeNotebook', () => {
this.open();
this.publish('closeNotebook');
this.crossframe.on('hideNotebook', () => {
this.show();
this.publish('hideNotebook');
});
const eventHandlers = [
......@@ -345,9 +345,9 @@ export default class Sidebar extends Guest {
_onResize() {
if (this.toolbar.sidebarOpen === true) {
if (window.innerWidth < MIN_RESIZE) {
this.close();
this.hide();
} else {
this.open();
this.show();
}
}
}
......@@ -384,9 +384,9 @@ export default class Sidebar extends Guest {
this._gestureState.final === null ||
this._gestureState.final <= -MIN_RESIZE
) {
this.open();
this.show();
} else {
this.close();
this.hide();
}
this._resetGestureState();
break;
......@@ -405,7 +405,7 @@ export default class Sidebar extends Guest {
}
}
open() {
show() {
this.crossframe.call('sidebarOpened');
this.publish('sidebarOpened');
......@@ -424,7 +424,7 @@ export default class Sidebar extends Guest {
this._notifyOfLayoutChange(true);
}
close() {
hide() {
if (this.frame) {
this.frame.style.marginLeft = '';
this.frame.classList.add('annotator-collapsed');
......
......@@ -450,7 +450,7 @@ describe('Guest', () => {
it('hides sidebar when the user taps or clicks in the page', () => {
for (let event of ['click', 'touchstart']) {
rootElement.dispatchEvent(new Event(event));
assert.calledWith(guest.plugins.CrossFrame.call, 'closeSidebar');
assert.calledWith(guest.plugins.CrossFrame.call, 'hideSidebar');
}
});
......@@ -563,7 +563,7 @@ describe('Guest', () => {
FakeAdder.instance.options.onShowAnnotations([{ $tag: 'ann1' }]);
assert.calledWith(fakeCrossFrame.call, 'openSidebar');
assert.calledWith(fakeCrossFrame.call, 'showSidebar');
assert.calledWith(fakeCrossFrame.call, 'showAnnotations', ['ann1']);
}));
......
......@@ -27,20 +27,20 @@ describe('Notebook', () => {
const notebook = createNotebook();
assert.isNull(notebook.container);
notebook.open();
notebook.show();
assert.isNotNull(notebook.container);
});
it('is not created if `hide` is called before notebook is first shown', () => {
const notebook = createNotebook();
notebook.close();
notebook.hide();
assert.isNull(notebook.container);
});
it('displays when opened', () => {
const notebook = createNotebook();
notebook.open();
notebook.show();
assert.equal(notebook.container.style.display, '');
assert.isTrue(notebook.container.classList.contains('is-open'));
......@@ -49,8 +49,8 @@ describe('Notebook', () => {
it('hides when closed', () => {
const notebook = createNotebook();
notebook.open();
notebook.close();
notebook.show();
notebook.hide();
assert.equal(notebook.container.style.display, 'none');
assert.isFalse(notebook.container.classList.contains('is-open'));
......@@ -58,12 +58,12 @@ describe('Notebook', () => {
});
describe('creating the notebook iframe', () => {
it('creates the iframe when the notebook is opened for the first time', () => {
it('creates the iframe when the notebook is shown for the first time', () => {
const notebook = createNotebook();
assert.isNull(notebook.frame);
notebook.open();
notebook.show();
assert.isTrue(notebook.frame instanceof Element);
});
......@@ -73,7 +73,7 @@ describe('Notebook', () => {
notebookAppUrl: 'http://www.example.com/foo/bar',
});
notebook.open();
notebook.show();
// The rest of the config gets added as a hash to the end of the src,
// so split that off and look at the string before it
......@@ -83,16 +83,16 @@ describe('Notebook', () => {
);
});
it('does not create a new iframe if opened again with same group ID', () => {
it('does not create a new iframe if shown again with same group ID', () => {
const notebook = createNotebook();
notebook._groupId = 'mygroup';
// The first opening will create a new iFrame
notebook.publish('openNotebook', ['myGroup']);
// The first showing will create a new iFrame
notebook.publish('showNotebook', ['myGroup']);
const removeSpy = sinon.spy(notebook.frame, 'remove');
// Open it again — the group hasn't changed so the iframe won't be
// Show it again — the group hasn't changed so the iframe won't be
// replaced
notebook.publish('openNotebook', ['myGroup']);
notebook.publish('showNotebook', ['myGroup']);
assert.notCalled(removeSpy);
});
......@@ -101,41 +101,41 @@ describe('Notebook', () => {
const notebook = createNotebook();
notebook._groupId = 'mygroup';
// First open: creates an iframe
notebook.publish('openNotebook', ['myGroup']);
// First show: creates an iframe
notebook.publish('showNotebook', ['myGroup']);
const removeSpy = sinon.spy(notebook.frame, 'remove');
// Open again with another group
notebook.publish('openNotebook', ['anotherGroup']);
// Show again with another group
notebook.publish('showNotebook', ['anotherGroup']);
// Open again, which will remove the first iframe and create a new one
notebook.open();
// Show again, which will remove the first iframe and create a new one
notebook.show();
assert.calledOnce(removeSpy);
});
});
describe('responding to events', () => {
it('opens on `openNotebook`', () => {
it('shows on `showNotebook`', () => {
const notebook = createNotebook();
notebook.publish('openNotebook');
notebook.publish('showNotebook');
assert.equal(notebook.container.style.display, '');
});
it('closes on `closeNotebook`', () => {
it('hides on `hideNotebook`', () => {
const notebook = createNotebook();
notebook.open();
notebook.publish('closeNotebook');
notebook.show();
notebook.publish('hideNotebook');
assert.equal(notebook.container.style.display, 'none');
});
it('closes on "sidebarOpened"', () => {
it('hides on "sidebarOpened"', () => {
const notebook = createNotebook();
notebook.open();
notebook.show();
notebook.publish('sidebarOpened');
assert.equal(notebook.container.style.display, 'none');
......@@ -148,7 +148,7 @@ describe('Notebook', () => {
const hostDocument = notebook.element;
// Make sure the frame is created
notebook.open();
notebook.show();
assert.isNotNull(hostDocument.querySelector('hypothesis-notebook'));
notebook.destroy();
......
......@@ -190,16 +190,16 @@ describe('Sidebar', () => {
});
describe('toolbar buttons', () => {
it('opens and closes sidebar when toolbar button is clicked', () => {
it('shows or hides sidebar when toolbar button is clicked', () => {
const sidebar = createSidebar();
sinon.stub(sidebar, 'open');
sinon.stub(sidebar, 'close');
sinon.stub(sidebar, 'show');
sinon.stub(sidebar, 'hide');
FakeToolbarController.args[0][1].setSidebarOpen(true);
assert.called(sidebar.open);
assert.called(sidebar.show);
FakeToolbarController.args[0][1].setSidebarOpen(false);
assert.called(sidebar.close);
assert.called(sidebar.hide);
});
it('shows or hides highlights when toolbar button is clicked', () => {
......@@ -235,45 +235,45 @@ describe('Sidebar', () => {
return result;
};
describe('on "open" event', () =>
it('opens the frame', () => {
const target = sandbox.stub(Sidebar.prototype, 'open');
describe('on "show" event', () =>
it('shows the frame', () => {
const target = sandbox.stub(Sidebar.prototype, 'show');
createSidebar();
emitEvent('openSidebar');
emitEvent('showSidebar');
assert.called(target);
}));
describe('on "close" event', () =>
it('closes the frame', () => {
const target = sandbox.stub(Sidebar.prototype, 'close');
describe('on "hide" event', () =>
it('hides the frame', () => {
const target = sandbox.stub(Sidebar.prototype, 'hide');
createSidebar();
emitEvent('closeSidebar');
emitEvent('hideSidebar');
assert.called(target);
}));
describe('on "openNotebook" event', () => {
describe('on "showNotebook" event', () => {
it('hides itself and republishes the event', () => {
const sidebar = createSidebar();
sinon.stub(sidebar, 'publish');
sinon.stub(sidebar, 'close');
emitEvent('openNotebook', 'mygroup');
sinon.stub(sidebar, 'hide');
emitEvent('showNotebook', 'mygroup');
assert.calledWith(
sidebar.publish,
'openNotebook',
'showNotebook',
sinon.match(['mygroup'])
);
assert.calledOnce(sidebar.close);
assert.calledOnce(sidebar.hide);
});
});
describe('on "closeNotebook" event', () => {
it('opens itself and republishes the event', () => {
describe('on "hideNotebook" event', () => {
it('shows itself and republishes the event', () => {
const sidebar = createSidebar();
sinon.stub(sidebar, 'publish');
sinon.stub(sidebar, 'open');
emitEvent('closeNotebook');
assert.calledWith(sidebar.publish, 'closeNotebook');
assert.calledOnce(sidebar.open);
sinon.stub(sidebar, 'show');
emitEvent('hideNotebook');
assert.calledWith(sidebar.publish, 'hideNotebook');
assert.calledOnce(sidebar.show);
});
});
......@@ -421,18 +421,18 @@ describe('Sidebar', () => {
assert.equal(sidebar.frame.style.pointerEvents, '');
});
it('calls `open` if the widget is fully visible', () => {
it('calls `show` if the widget is fully visible', () => {
sidebar._gestureState = { final: -500 };
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar._onPan({ type: 'panend' });
assert.calledOnce(open);
assert.calledOnce(show);
});
it('calls `close` if the widget is not fully visible', () => {
it('calls `hide` if the widget is not fully visible', () => {
sidebar._gestureState = { final: -100 };
const close = sandbox.stub(sidebar, 'close');
const hide = sandbox.stub(sidebar, 'hide');
sidebar._onPan({ type: 'panend' });
assert.calledOnce(close);
assert.calledOnce(hide);
});
});
......@@ -453,43 +453,43 @@ describe('Sidebar', () => {
const sidebar = createSidebar({
annotations: 'ann-id',
});
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar.publish('panelReady');
assert.calledOnce(open);
assert.calledOnce(show);
});
it('opens the sidebar when a direct-linked group is present.', () => {
const sidebar = createSidebar({
group: 'group-id',
});
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar.publish('panelReady');
assert.calledOnce(open);
assert.calledOnce(show);
});
it('opens the sidebar when a direct-linked query is present.', () => {
const sidebar = createSidebar({
query: 'tag:foo',
});
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar.publish('panelReady');
assert.calledOnce(open);
assert.calledOnce(show);
});
it('opens the sidebar when openSidebar is set to true.', () => {
const sidebar = createSidebar({
openSidebar: true,
});
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar.publish('panelReady');
assert.calledOnce(open);
assert.calledOnce(show);
});
it('does not open the sidebar if not configured to.', () => {
it('does not show the sidebar if not configured to.', () => {
const sidebar = createSidebar();
const open = sandbox.stub(sidebar, 'open');
const show = sandbox.stub(sidebar, 'show');
sidebar.publish('panelReady');
assert.notCalled(open);
assert.notCalled(show);
});
});
......@@ -513,24 +513,24 @@ describe('Sidebar', () => {
});
});
describe('#open', () => {
describe('#show', () => {
it('shows highlights if "showHighlights" is set to "whenSidebarOpen"', () => {
const sidebar = createSidebar({ showHighlights: 'whenSidebarOpen' });
assert.isFalse(sidebar.visibleHighlights);
sidebar.open();
sidebar.show();
assert.isTrue(sidebar.visibleHighlights);
});
it('does not show highlights otherwise', () => {
const sidebar = createSidebar({ showHighlights: 'never' });
assert.isFalse(sidebar.visibleHighlights);
sidebar.open();
sidebar.show();
assert.isFalse(sidebar.visibleHighlights);
});
it('updates the `sidebarOpen` property of the toolbar', () => {
const sidebar = createSidebar();
sidebar.open();
sidebar.show();
assert.equal(fakeToolbar.sidebarOpen, true);
});
});
......@@ -539,8 +539,8 @@ describe('Sidebar', () => {
it('hides highlights if "showHighlights" is set to "whenSidebarOpen"', () => {
const sidebar = createSidebar({ showHighlights: 'whenSidebarOpen' });
sidebar.open();
sidebar.close();
sidebar.show();
sidebar.hide();
assert.isFalse(sidebar.visibleHighlights);
});
......@@ -548,8 +548,8 @@ describe('Sidebar', () => {
it('updates the `sidebarOpen` property of the toolbar', () => {
const sidebar = createSidebar();
sidebar.open();
sidebar.close();
sidebar.show();
sidebar.hide();
assert.equal(fakeToolbar.sidebarOpen, false);
});
......@@ -582,21 +582,21 @@ describe('Sidebar', () => {
assert.equal(fakeToolbar.sidebarOpen, false);
});
it('invokes the "open" method when window is resized', () => {
// Calling the 'open' methods adjust the marginLeft at different screen sizes
it('invokes the "show" method when window is resized', () => {
// Calling the 'show' methods adjust the marginLeft at different screen sizes
const sidebar = createSidebar({ openSidebar: true });
sidebar.publish('panelReady');
sinon.stub(sidebar, 'open');
sinon.stub(sidebar, 'show');
// Make the window very small
window.innerWidth = MIN_RESIZE;
window.dispatchEvent(new Event('resize'));
assert.calledOnce(sidebar.open);
assert.calledOnce(sidebar.show);
// Make the window very large
window.innerWidth = MIN_RESIZE * 10;
window.dispatchEvent(new Event('resize'));
assert.calledTwice(sidebar.open);
assert.calledTwice(sidebar.show);
});
});
......@@ -674,7 +674,7 @@ describe('Sidebar', () => {
it('notifies when sidebar changes expanded state', () => {
sinon.stub(sidebar, 'publish');
sidebar.open();
sidebar.show();
assert.calledOnce(layoutChangeHandlerSpy);
assert.calledWith(
sidebar.publish,
......@@ -687,7 +687,7 @@ describe('Sidebar', () => {
expanded: true,
});
sidebar.close();
sidebar.hide();
assert.calledTwice(layoutChangeHandlerSpy);
assert.calledThrice(sidebar.publish);
assertLayoutValues(layoutChangeHandlerSpy.lastCall.args[0], {
......@@ -745,14 +745,14 @@ describe('Sidebar', () => {
});
it('notifies when sidebar changes expanded state', () => {
sidebar.open();
sidebar.show();
assert.calledOnce(layoutChangeHandlerSpy);
assertLayoutValues(layoutChangeHandlerSpy.lastCall.args[0], {
expanded: true,
width: DEFAULT_WIDTH,
});
sidebar.close();
sidebar.hide();
assert.calledTwice(layoutChangeHandlerSpy);
assertLayoutValues(layoutChangeHandlerSpy.lastCall.args[0], {
expanded: false,
......
......@@ -54,7 +54,7 @@ function UserMenu({ auth, bridge, onLogout, serviceUrl, settings }) {
!isThirdParty || serviceSupports('onLogoutRequestProvided');
const onSelectNotebook = () => {
bridge.call('openNotebook', store.focusedGroupId());
bridge.call('showNotebook', store.focusedGroupId());
};
const onProfileSelected = () =>
......
......@@ -204,7 +204,7 @@ describe('UserMenu', () => {
const openNotebookItem = findMenuItem(wrapper, 'Open notebook');
openNotebookItem.props().onClick();
assert.calledOnce(fakeBridge.call);
assert.calledWith(fakeBridge.call, 'openNotebook', 'mygroup');
assert.calledWith(fakeBridge.call, 'showNotebook', 'mygroup');
});
});
......
......@@ -114,7 +114,7 @@ export default function FrameSync(annotationsService, bridge, store) {
// and delete the (unsaved) annotation so it gets un-selected in the
// target document
if (!store.isLoggedIn()) {
bridge.call('openSidebar');
bridge.call('showSidebar');
store.openSidebarPanel('loginPrompt');
bridge.call('deleteAnnotation', formatAnnot(annot));
return;
......@@ -167,11 +167,11 @@ export default function FrameSync(annotationsService, bridge, store) {
});
// These invoke the matching methods by name on the Guests
bridge.on('openSidebar', function () {
bridge.call('openSidebar');
bridge.on('showSidebar', function () {
bridge.call('showSidebar');
});
bridge.on('closeSidebar', function () {
bridge.call('closeSidebar');
bridge.on('hideSidebar', function () {
bridge.call('hideSidebar');
});
bridge.on('setVisibleHighlights', function (state) {
bridge.call('setVisibleHighlights', state);
......
......@@ -243,7 +243,7 @@ describe('sidebar/services/frame-sync', function () {
const ann = { target: [] };
fakeBridge.emit('beforeCreateAnnotation', { tag: 't1', msg: ann });
assert.calledWith(fakeBridge.call, 'openSidebar');
assert.calledWith(fakeBridge.call, 'showSidebar');
});
it('should open the login prompt panel', () => {
......@@ -369,16 +369,16 @@ describe('sidebar/services/frame-sync', function () {
});
describe('on a relayed bridge call', function () {
it('calls "openSidebar"', function () {
fakeBridge.emit('openSidebar');
it('calls "showSidebar"', function () {
fakeBridge.emit('showSidebar');
assert.calledWith(fakeBridge.call, 'openSidebar');
assert.calledWith(fakeBridge.call, 'showSidebar');
});
it('calls "closeSidebar"', function () {
fakeBridge.emit('closeSidebar');
it('calls "hideSidebar"', function () {
fakeBridge.emit('hideSidebar');
assert.calledWith(fakeBridge.call, 'closeSidebar');
assert.calledWith(fakeBridge.call, 'hideSidebar');
});
it('calls "setVisibleHighlights"', function () {
......
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