Skip to content

Mhughes2k js core module guides #1386

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
55 changes: 0 additions & 55 deletions docs/guides/javascript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,61 +467,6 @@ Care should be taken in the following scenarios:

## Preferences

## Prefetch

<Since versions={[ 3.9 ]} />

Assets including strings, and templates, can be pre-fetched shortly after the page loads to improve the perceived performance of the page when consuming those components.

```todo
Link to jsdocs here
```

```js title="Example of fetching a string and template"
import Prefetch from 'core/prefetch';

// Prefetch the string 'discussion' from the 'mod_forum' component.
Prefetch.prefetchString('discussion', 'mod_forum');

// Prefetch the strings yes, no, and maybe from the 'core' component.
Prefetch.prefetchStrings('core', ['yes', 'no', 'maybe']);

// Prefetch the templates 'core/toast'.
Prefetch.prefetchTemplate('core/toast');

// Prefetch the templates 'core/toast' and 'core/modal'.
Prefetch.prefetchTemplates(['core/toast', 'core/modal']);
```

## Dropzone

<Since version="4.4" issueNumber="MDL-80850" />

The use of the `core/dropzone` module provides a simplified developer experience for creating drop zones within Moodle.

The module attempts to ensure that accessibility requirements are met, including applying the correct styles and keyboard navigation.

Drop zones will trigger callbacks for common actions that occur within the drop zone for other code to listen to and react accordingly.

```js title="Example of creating a dropzone"
import Dropzone from 'core/dropzone';

// Get the element that will be the dropzone.
const dropZoneContainer = document.querySelector('#dropZoneId');
// Create a new dropzone accepting only images.
const dropZone = new Dropzone(
dropZoneContainer,
'image/*',
function(files) {
window.console.log(files);
}
);
// Set the custom message for the dropzone. Otherwise, it will use the default message.
dropZone.setLabel('Drop images here');
// Initialising the dropzone.
dropZone.init();
```

## Reactive state

<Since versions={[ 4.0 ]} />
Expand Down
29 changes: 29 additions & 0 deletions docs/guides/javascript/modules/dropzone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Dropzone
---
<Since version="4.4" issueNumber="MDL-80850" />

The use of the `core/dropzone` module provides a simplified developer experience for creating drop zones within Moodle.

The module attempts to ensure that accessibility requirements are met, including applying the correct styles and keyboard navigation.

Drop zones will trigger callbacks for common actions that occur within the drop zone for other code to listen to and react accordingly.

```js title="Example of creating a dropzone"
import Dropzone from 'core/dropzone';

// Get the element that will be the dropzone.
const dropZoneContainer = document.querySelector('#dropZoneId');
// Create a new dropzone accepting only images.
const dropZone = new Dropzone(
dropZoneContainer,
'image/*',
function(files) {
window.console.log(files);
}
);
// Set the custom message for the dropzone. Otherwise, it will use the default message.
dropZone.setLabel('Drop images here');
// Initialising the dropzone.
dropZone.init();
```
16 changes: 16 additions & 0 deletions docs/guides/javascript/modules/log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Log
---

It is not recommended to use the vanila `window.console.log()` function to output JavaScript logging information.

The `core/log` module offers different levels of log output that is governed by Moodle's debugging levels.

```js title="Example use of logging"
import Log from 'core/log';

Log.info("Info class log statement");

Log.debug("Debugging information, only appears when DEBUG mode is DEBUG_DEVELOPER");

```
26 changes: 26 additions & 0 deletions docs/guides/javascript/modules/prefetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Prefetch
---
<Since versions={[ 3.9 ]} />

Assets including strings, and templates, can be pre-fetched shortly after the page loads to improve the perceived performance of the page when consuming those components.

```todo
Link to jsdocs here
```

```js title="Example of fetching a string and template"
import Prefetch from 'core/prefetch';

// Prefetch the string 'discussion' from the 'mod_forum' component.
Prefetch.prefetchString('discussion', 'mod_forum');

// Prefetch the strings yes, no, and maybe from the 'core' component.
Prefetch.prefetchStrings('core', ['yes', 'no', 'maybe']);

// Prefetch the templates 'core/toast'.
Prefetch.prefetchTemplate('core/toast');

// Prefetch the templates 'core/toast' and 'core/modal'.
Prefetch.prefetchTemplates(['core/toast', 'core/modal']);
```
Loading