Skip to content

Commit

Permalink
Always call LMSFinish on close (#16)
Browse files Browse the repository at this point in the history
* don't need .bowerrc any more
* switch to the proper Notify API
* always call LMSFinish on close confirm
* correct typo
* check that we're actually connected to an LMS before attempting to call LMSFinish
* bump version, update README
* add link to spoor
* README improvements (#17)
Co-authored-by: tomgreenfield <tomgreenfield@users.noreply.github.com>
  • Loading branch information
Matt Leathes authored Mar 2, 2021
1 parent c8bf4f7 commit 44062fc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 123 deletions.
167 changes: 59 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,71 @@

An extension to add a close button and/or prompts.

## Installation
As of v2.1.0 this extension will now call `LMSFinish` on close if the [Spoor extension](https://github.com/adaptlearning/adapt-contrib-spoor) is installed, enabled and connected to an LMS. This can be used as a workaround for those Learning Management Systems that are affected by the [disallow sync XHR in page dismissal](https://www.chromestatus.com/feature/4664843055398912) change to Chromium-based browsers (such as Chrome, Edge and Opera) and which have yet to be updated to avoid being affected by this change.

## Installation
* Add the [example JSON](example.json) to `course.json`.
* With [Adapt CLI](https://github.com/adaptlearning/adapt-cli) installed, run `adapt install close`. Alternatively, download the ZIP and extract into the src > extensions directory.
* With [Adapt CLI](https://github.com/adaptlearning/adapt-cli) installed, run `adapt install close`. Alternatively, [download the ZIP](https://github.com/cgkineo/adapt-close/archive/master.zip) and extract into the src > extensions directory.
* Run an appropriate Grunt task.

## Usage

* A close button can be added to the navigation bar.
* Prompts using notify can be triggered on this button.
* In addition, browser dialogs can be displayed if you close the window in a normal fashion.
* When the learner clicks the close button, a [Notify](https://github.com/adaptlearning/adapt_framework/wiki/Core-modules#notify) prompt can be shown that asks the learner to confirm they want to exit (or return to the course)
* A browser dialog can be displayed if the learner closes the window/tab in a normal fashion i.e. using the browser window/tab close button/equivalent keyboard shortcut

## Attributes
### `_isEnabled` (boolean):
Enables/disables this extension. The default value is `false`. Set this to `true` to enable this extension.

### `browserPromptIfIncomplete` (string):
Populate with text to display a browser dialog if the learner attempts to close the course window/tab when the course hasn't yet been completed

### `browserPromptIfComplete` (string):
Populate with text to display a browser dialog if the learner attempts to close the course window/tab when the course has been completed

**Note:** Firefox, Chrome and Edge do not allow custom text to be included in the browser dialog. Additionally, most 'evergreen' browsers now seem to ignore any attempt to display a dialog in response to the `beforeunload` event if the user hasn't interacted with the page.

### `_button` (object):
Contains the following settings:

* `_isEnabled` (boolean):
Controls whether a close button should be added to the top navigation bar or not. Set this to `false` if you just want to have the browser dialog (see above) show on exit. The default value is `false`.

* `_closeViaLMSFinish` (boolean):
Set to `true` to let the SCORM `LMSFinish` routine handle closing the course. This can be useful when the course hasn't been opened in a new window or where the course window can't be closed via JavaScript. This setting should only be enabled if the course will be launched from a SCORM-conformant Learning Management System that supports this functionality. The default value is `false`.

* `_notifyPromptIfIncomplete` (object):
Contains the following settings:

* `_isEnabled` (boolean):
Controls whether a prompt should be displayed if the learner clicks the close button when the course hasn't yet been completed. The default value is `false`.

* `title` (string):
Title of the prompt e.g. "Confirm close"

* `body` (string):
Body text of the prompt e.g. "Are you sure you want to exit the course? You have not yet completed all the content."

* `confirm` (string):
Confirm button text e.g. "Exit course".

* `cancel` (string):
Cancel button text e.g. "Cancel".

* `_notifyPromptIfComplete` (object):
Contains the following settings:

* `_isEnabled` (boolean):
Controls whether a prompt should be displayed if the learner clicks the close button when the course has been completed. The default value is `false`.

* `title` (string):
Title of the prompt e.g. "Confirm close"

* `body` (string):
Body text of the prompt e.g. "Are you sure you want to exit the course?"

* `confirm` (string):
Confirm button text e.g. "Exit course".

<table>
<tr>
<th colspan="3">Attribute<br></th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td colspan="3"><code>_isEnabled</code></td>
<td>Boolean</td>
<td>Set to <code>false</code> to completely disable the extension</td>
<td><code>false</code></td>
</tr>
<tr>
<td rowspan="12"><code>_button</code></td>
<td colspan="2"><code>_isEnabled</code></td>
<td>Boolean</td>
<td>Adds a close button to the navigation bar</td>
<td><code>false</code></td>
</tr>
<tr>
<td colspan="2"><code>_closeViaLMSFinish</code></td>
<td>Boolean</td>
<td>Set to <code>true</code> to have the button directly call the SCORM 'finish' function to close the course. This can be useful when the course hasn't been opened in a new window or where the course window can't be closed via JavaScript.</td>
<td><code>false</code></td>
</tr>
<tr>
<td rowspan="5"><code>_notifyPromptIfIncomplete</code></td>
<td><code>_isEnabled</code></td>
<td>Boolean</td>
<td>Displays a notify prompt if the close button is selected while the course is incomplete</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>title</code></td>
<td>String</td>
<td>Prompt title</td>
<td><code>"Confirm close"</code></td>
</tr>
<tr>
<td><code>body</code></td>
<td>String</td>
<td>Prompt message<br></td>
<td><code>"Are you sure you want to close the window?"</code></td>
</tr>
<tr>
<td><code>confirm</code></td>
<td>String</td>
<td>Confirm button text</td>
<td><code>"Close window"</code></td>
</tr>
<tr>
<td><code>cancel</code></td>
<td>String</td>
<td>Cancel button text<br></td>
<td><code>"Cancel"</code></td>
</tr>
<tr>
<td rowspan="5"><code>_notifyPromptIfComplete</code></td>
<td><code>_isEnabled</code></td>
<td>Boolean</td>
<td>Displays a notify prompt if the close button is selected after the course has been completed</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>title</code></td>
<td>String</td>
<td>Prompt title</td>
<td><code>"Confirm close"</code></td>
</tr>
<tr>
<td><code>body</code></td>
<td>String</td>
<td>Prompt message</td>
<td><code>"Are you sure you want to close the window?"</code></td>
</tr>
<tr>
<td><code>confirm</code></td>
<td>String</td>
<td>Confirm button text</td>
<td><code>"Close window"</code></td>
</tr>
<tr>
<td><code>cancel</code></td>
<td>String</td>
<td>Cancel button text</td>
<td><code>"Cancel"</code></td>
</tr>
<tr>
<td colspan="3"><code>browserPromptIfIncomplete</code></td>
<td>String</td>
<td>Populate with text to display a browser dialog if the window is closed while the course is incomplete</td>
<td><code>""</code></td>
</tr>
<tr>
<td colspan="3"><code>browserPromptIfComplete</code></td>
<td>String<br></td>
<td>Populate with text to display a browser dialog if the window is closed after the course has been completed</td>
<td><code>""</code></td>
</tr>
</table>

* Note: Firefox doesn’t support custom messages in its dialogs. UPDATE July 2020 Neither Chrome nor Edge (the new version that's based on Chromium) allow custom messages any more. Additionally, most 'evergreen' browsers now seem to ignore any attempt to display a dialog in response to the `beforeunload` event if the user hasn't interacted with the page.
* `cancel` (string):
Cancel button text e.g. "Cancel".
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapt-close",
"version": "2.0.0",
"version": "2.1.0",
"framework": ">=5",
"extension": "close",
"displayName": "Close",
Expand Down
8 changes: 4 additions & 4 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"_notifyPromptIfIncomplete": {
"_isEnabled": false,
"title": "Confirm close",
"body": "Are you sure you want to close the window?",
"confirm": "Close window",
"body": "Are you sure you want to exit the course?",
"confirm": "Exit course",
"cancel": "Cancel"
},
"_notifyPromptIfComplete": {
"_isEnabled": false,
"title": "Confirm close",
"body": "Are you sure you want to close the window?",
"confirm": "Close window",
"body": "Are you sure you want to exit the course?",
"confirm": "Exit window",
"cancel": "Cancel"
}
},
Expand Down
17 changes: 11 additions & 6 deletions js/adapt-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define([

if (!prompt || !prompt._isEnabled) return Adapt.trigger('close:confirm');

Adapt.trigger('notify:prompt', {
Adapt.notify.prompt({
title: prompt.title,
body: prompt.body,
_prompts: [
Expand All @@ -48,12 +48,17 @@ define([
var config = Adapt.course.get('_close');
config.browserPromptIfIncomplete = config.browserPromptIfComplete = false;

if (config._button._closeViaLMSFinish) {
var scorm = require('extensions/adapt-contrib-spoor/js/scorm/wrapper');
if (scorm) scorm.getInstance().finish();
} else {
top.window.close();
var scormWrapper = require('extensions/adapt-contrib-spoor/js/scorm/wrapper');
if (scormWrapper) {
var scormWrapperInstance = scormWrapper.getInstance();
if (scormWrapperInstance.lmsConnected && !scormWrapperInstance.finishCalled) {
scormWrapperInstance.finish();
}
}

if (config._button._closeViaLMSFinish) return;

top.window.close();
}

});
Expand Down
8 changes: 4 additions & 4 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
},
"body": {
"type": "string",
"default": "Are you sure you want to close the window?",
"default": "Are you sure you want to exit the course?",
"inputType": "TextArea",
"help": "Enter the prompt message",
"translatable": true
},
"confirm": {
"type": "string",
"default": "Close window",
"default": "Exit course",
"inputType": "Text",
"help": "Enter the confirm button text",
"translatable": true
Expand Down Expand Up @@ -109,14 +109,14 @@
},
"body": {
"type": "string",
"default": "Are you sure you want to close the window?",
"default": "Are you sure you want to exit the course?",
"inputType": "TextArea",
"help": "Enter the prompt message",
"translatable": true
},
"confirm": {
"type": "string",
"default": "Close window",
"default": "Exit course",
"inputType": "Text",
"help": "Enter the confirm button text",
"translatable": true
Expand Down

0 comments on commit 44062fc

Please sign in to comment.