Skip to content
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

Replace "firstRun" config option with "openSidebar" and "openLoginForm" #63

Merged
merged 2 commits into from
Aug 3, 2016
Merged
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
30 changes: 30 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Configuring the sidebar
=======================

The Hypothesis sidebar can be configured by providing a settings object in the
body of the hosting page:

```html
<script type="application/json" class="js-hypothesis-config">
{
"openSidebar": true
}
</script>
<script async src="https://hypothes.is/embed.js"></script>
```

**N.B.** The body of the `.js-hypothesis-config` tag must be [valid
JSON](http://jsonlint.com/) -- invalid JSON will cause the entire config object
to be ignored.

Config keys
-----------

### `openLoginForm`

_Boolean_. Controls whether the login panel is automatically opened on startup,
as if the user had clicked "Log in" themselves.

### `openSidebar`

_Boolean_. Controls whether the sidebar opens automatically on startup.
2 changes: 1 addition & 1 deletion h/static/scripts/annotator/sidebar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = class Sidebar extends Host
super
this.hide()

if options.firstRun || options.annotations
if options.openSidebar || options.annotations
this.on 'panelReady', => this.show()

if @plugins.BucketBar?
Expand Down
4 changes: 2 additions & 2 deletions h/static/scripts/annotator/test/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('annotator configuration', function () {
it('merges the config from hypothesisConfig()', function () {
var fakeWindow = Object.assign({}, fakeWindowBase, {
hypothesisConfig: function () {
return {firstRun: true};
return {foo: true};
},
});
assert.deepEqual(config(fakeWindow), {
app: 'app.html',
firstRun: true,
foo: true,
});
});

Expand Down
6 changes: 5 additions & 1 deletion h/static/scripts/app-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ module.exports = function AppController(
// update the auth info in the top bar and show the login form
// after first install of the extension.
$scope.auth = authStateFromUserID(state.userid);
if (!state.userid && settings.firstRun) {

// FIXME: Fix this horrendous !== 'false' conditional. Unfortunately, we
// currently pass settings from the hosting page into the sidebar via the
// URL query string, so type information is lost. Ugh.
if (!state.userid && settings.openLoginForm && settings.openLoginForm !== 'false') {
$scope.login();
}
});
Expand Down
1 change: 0 additions & 1 deletion h/static/scripts/test/app-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ describe('AppController', function () {
};

fakeSettings = {
firstRun: false,
serviceUrl: 'http://fake.service.com/',
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/gulp/live-reload-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function LiveReloadServer(port, appServer) {
liveReloadServer: 'ws://' + appHost + ':${port}',

// Open the sidebar when the page loads
firstRun: true,
openSidebar: true,
};
};

Expand Down