Skip to content

Commit

Permalink
Merge pull request #63 from hypothesis/remove-firstrun-config-option
Browse files Browse the repository at this point in the history
Replace "firstRun" config option with "openSidebar" and "openLoginForm"
  • Loading branch information
robertknight authored Aug 3, 2016
2 parents cbfa2ac + 56fd70c commit 632846d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
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

0 comments on commit 632846d

Please sign in to comment.