Commit 9c3fb515 authored by Juan Corona's avatar Juan Corona Committed by Juan Corona

Make the loading of the BucketBar and Toolbar plugins selective

- Add logic that removes the plugins conditionally based on the config.
- Move the existing logic for the `theme` config to be grouped with the above.
- The new location for the existing logic is better for testing.
- Add tests for the new and existing logic.
parent d9a12ac4
......@@ -63,10 +63,6 @@ $.noConflict(true)(function() {
window.__hypothesis_frame = true;
}
if(config.theme === 'clean') {
delete pluginClasses.BucketBar;
}
config.pluginClasses = pluginClasses;
var annotator = new Klass(document.body, config);
......
......@@ -25,7 +25,13 @@ module.exports = class Sidebar extends Host
gestureState: null
constructor: (element, config) ->
if config.theme == 'clean' || config.externalContainerSelector
delete config.pluginClasses.BucketBar
if config.externalContainerSelector
delete config.pluginClasses.Toolbar
super
this.hide()
if config.openSidebar || config.annotations || config.query
......@@ -252,9 +258,9 @@ module.exports = class Sidebar extends Host
@frame.css 'margin-left': ''
@frame.addClass 'annotator-collapsed'
@plugins.Toolbar.hideCloseBtn();
if @plugins.Toolbar?
@plugins.Toolbar.hideCloseBtn();
@plugins.Toolbar.showExpandSidebarBtn();
if @options.showHighlights == 'whenSidebarOpen'
......
......@@ -7,6 +7,8 @@ rafStub = (fn) ->
Sidebar = proxyquire('../sidebar', { raf: rafStub })
EXTERNAL_CONTAINER_SELECTOR = 'test-external-container'
describe 'Sidebar', ->
sandbox = sinon.sandbox.create()
CrossFrame = null
......@@ -39,14 +41,22 @@ describe 'Sidebar', ->
fakeToolbar.getWidth = sandbox.stub()
fakeToolbar.destroy = sandbox.stub()
fakeBucketBar = {}
fakeBucketBar.element = {on: sandbox.stub()}
fakeBucketBar.destroy = sandbox.stub()
CrossFrame = sandbox.stub()
CrossFrame.returns(fakeCrossFrame)
Toolbar = sandbox.stub()
Toolbar.returns(fakeToolbar)
BucketBar = sandbox.stub()
BucketBar.returns(fakeBucketBar)
sidebarConfig.pluginClasses['CrossFrame'] = CrossFrame
sidebarConfig.pluginClasses['Toolbar'] = Toolbar
sidebarConfig.pluginClasses['BucketBar'] = BucketBar
afterEach ->
sandbox.restore()
......@@ -358,3 +368,13 @@ describe 'Sidebar', ->
sidebar.gestureState = { initial: -DEFAULT_WIDTH }
sidebar.onPan({type: 'panright', deltaX: 50})
assertLayoutValues layoutChangeHandlerSpy.lastCall.args[0], { width: 300 }
describe 'config', ->
it 'does not have the BucketBar plugin if the clean theme is enabled', ->
sidebar = createSidebar({ theme: 'clean' })
assert.isUndefined(sidebar.plugins.BucketBar)
it 'does not have the BucketBar or Toolbar plugin if an external container is provided', ->
sidebar = createSidebar({ externalContainerSelector: '.' + EXTERNAL_CONTAINER_SELECTOR })
assert.isUndefined(sidebar.plugins.BucketBar)
assert.isUndefined(sidebar.plugins.Toolbar)
\ No newline at end of file
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