Commit 00ef3788 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #275 from hypothesis/rename-onlogin

Rename the onLogin callback to onLoginRequest
parents 7a9b6ba3 2be48134
...@@ -96,20 +96,20 @@ with the following keys: ...@@ -96,20 +96,20 @@ with the following keys:
* `icon` _String|null_. The URL to an image for the annotation service. This image will appear to the left of the name of the currently selected group. The image should be suitable for display at 16x16px and the recommended format is SVG. * `icon` _String|null_. The URL to an image for the annotation service. This image will appear to the left of the name of the currently selected group. The image should be suitable for display at 16x16px and the recommended format is SVG.
* `onLogin` _function_. A JavaScript function that the Hypothesis client will * `onLoginRequest` _function_. A JavaScript function that the Hypothesis client
call in order to login (for example, when the user clicks a login button in will call in order to login (for example, when the user clicks a login button
the Hypothesis client's sidebar). in the Hypothesis client's sidebar).
This setting can only be [set using window.hypothesisConfig](#configuring-the-client-using-javascript). This setting can only be [set using window.hypothesisConfig](#configuring-the-client-using-javascript).
If the hosting page provides an `onLogin` function then the Hypothesis client If the hosting page provides an `onLoginRequest` function then the Hypothesis
will call this function instead of doing its usual procedure for logging in client will call this function instead of doing its usual procedure for
to the public service at [hypothes.is](https://hypothes.is/). logging in to the public service at [hypothes.is](https://hypothes.is/).
No arguments are passed to the `onLogin` function. No arguments are passed to the `onLoginRequest` function.
The `onLogin` function should cause a login procedure for the hosting page The `onLoginRequest` function should cause a login procedure for the hosting
to be performed - for example by redirecting to a login page, or by opening page to be performed - for example by redirecting to a login page, or by
a popup login window. After a successful login the hosting page should opening a popup login window. After a successful login the hosting page
reload the original page with a non-null `grantToken` for the logged-in user should reload the original page with a non-null `grantToken` for the
in the `services` configuration setting. logged-in user in the `services` configuration setting.
...@@ -37,7 +37,7 @@ module.exports = class Sidebar extends Host ...@@ -37,7 +37,7 @@ module.exports = class Sidebar extends Host
this._setupGestures() this._setupGestures()
# The partner-provided login callback function (if any). # The partner-provided login callback function (if any).
@onLogin = options.services?[0]?.onLogin @onLoginRequest = options.services?[0]?.onLoginRequest
this._setupSidebarEvents() this._setupSidebarEvents()
...@@ -55,8 +55,8 @@ module.exports = class Sidebar extends Host ...@@ -55,8 +55,8 @@ module.exports = class Sidebar extends Host
@crossframe.on('show', this.show.bind(this)) @crossframe.on('show', this.show.bind(this))
@crossframe.on('hide', this.hide.bind(this)) @crossframe.on('hide', this.hide.bind(this))
@crossframe.on(events.DO_LOGIN, => @crossframe.on(events.DO_LOGIN, =>
if @onLogin if @onLoginRequest
@onLogin() @onLoginRequest()
); );
# Return this for chaining # Return this for chaining
......
...@@ -48,17 +48,17 @@ describe 'Sidebar', -> ...@@ -48,17 +48,17 @@ describe 'Sidebar', ->
assert.called(target) assert.called(target)
describe 'on DO_LOGIN event', -> describe 'on DO_LOGIN event', ->
it 'calls the onLogin callback function if one was provided', -> it 'calls the onLoginRequest callback function if one was provided', ->
onLogin = sandbox.stub() onLoginRequest = sandbox.stub()
sidebar = createSidebar(options={services: [{onLogin: onLogin}]}) sidebar = createSidebar(options={services: [{onLoginRequest: onLoginRequest}]})
emitEvent(events.DO_LOGIN) emitEvent(events.DO_LOGIN)
assert.called(onLogin) assert.called(onLoginRequest)
it 'only calls the onLogin callback of the first service', -> it 'only calls the onLoginRequest callback of the first service', ->
# Even though options.services is an array it only calls the onLogin # Even though options.services is an array it only calls the onLoginRequest
# callback function of the first service. The onLogins of any other # callback function of the first service. The onLoginRequests of any other
# services are ignored. # services are ignored.
firstOnLogin = sandbox.stub() firstOnLogin = sandbox.stub()
secondOnLogin = sandbox.stub() secondOnLogin = sandbox.stub()
...@@ -66,9 +66,9 @@ describe 'Sidebar', -> ...@@ -66,9 +66,9 @@ describe 'Sidebar', ->
sidebar = createSidebar( sidebar = createSidebar(
options={ options={
services: [ services: [
{onLogin: firstOnLogin}, {onLoginRequest: firstOnLogin},
{onLogin: secondOnLogin}, {onLoginRequest: secondOnLogin},
{onLogin: thirdOnLogin}, {onLoginRequest: thirdOnLogin},
] ]
} }
) )
...@@ -79,17 +79,17 @@ describe 'Sidebar', -> ...@@ -79,17 +79,17 @@ describe 'Sidebar', ->
assert.notCalled(secondOnLogin) assert.notCalled(secondOnLogin)
assert.notCalled(thirdOnLogin) assert.notCalled(thirdOnLogin)
it 'never calls the onLogin callbacks of further services', -> it 'never calls the onLoginRequest callbacks of further services', ->
# Even if the first service doesn't have an onLogin, it still doesn't # Even if the first service doesn't have an onLoginRequest, it still doesn't
# call the onLogins of further services. # call the onLoginRequests of further services.
secondOnLogin = sandbox.stub() secondOnLogin = sandbox.stub()
thirdOnLogin = sandbox.stub() thirdOnLogin = sandbox.stub()
sidebar = createSidebar( sidebar = createSidebar(
options={ options={
services: [ services: [
{}, {},
{onLogin: secondOnLogin}, {onLoginRequest: secondOnLogin},
{onLogin: thirdOnLogin}, {onLoginRequest: thirdOnLogin},
] ]
} }
) )
...@@ -107,7 +107,7 @@ describe 'Sidebar', -> ...@@ -107,7 +107,7 @@ describe 'Sidebar', ->
sidebar = createSidebar(options={services: []}) sidebar = createSidebar(options={services: []})
emitEvent(events.DO_LOGIN) emitEvent(events.DO_LOGIN)
it 'does not crash if the first service has no onLogin', -> it 'does not crash if the first service has no onLoginRequest', ->
sidebar = createSidebar(options={services: [{}]}) sidebar = createSidebar(options={services: [{}]})
emitEvent(events.DO_LOGIN) emitEvent(events.DO_LOGIN)
......
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