moodle/lib/templates/block.mustache
Andrew Nicols 31d6adef4d MDL-70990 core_block: Replace legacy BLOCK_CONTENT_UPDATED event
The legacy M.core.event.BLOCK_CONTENT_UPDATED event has been replaced with a
new core_block/events::blockContentUpdated native DOM event.

The new event can be triggered using the `notifyBlockContentUpdated`
event, and by providing the HTMLElement that was updated, for example:

```
import {notifyBlockContentUpdated} from 'core_block/events';

const someHandler = e => {
    // ...
    const updatedBlock = e.target.closest('.block');
    notifyBlockContentUpdated(updatedBlock);
};
```

The new event can be listened to at any point in the DOM using the
following syntax:

```
import {eventTypes} from 'core_block/events';

const handler = e => {
    // The block that was updated.
    e.target;

    // The id of the updated block.
    e.detail.instanceId;
};

document.addEventListener(eventTypes.blockContentUpdated, handler);
```

A backward-compatabibility layer is included to ensure that any legacy
YUI event listener is still called with the same arguments.

This legacy bridges will be removed after Moodle 4.3.
2021-05-26 10:47:17 +08:00

66 lines
1.7 KiB
Plaintext

{{!
@template core/block
Example context (json):
{
"id": "block0",
"class": "block block_html",
"showskiplink": true,
"type": "html",
"ariarole": "complementary",
"title": "Test block",
"blockinstanceid": 1,
"content": "<p>Hello block world!</p>"
}
}}
{{! Block Skip Link }}
{{#showskiplink}}
<a href="#sb-{{skipid}}" class="sr-only sr-only-focusable">{{#str}}skipa, access, {{{title}}}{{/str}}</a>
{{/showskiplink}}
{{! Start Block Container }}
<section id="{{id}}"
class="{{#hidden}}hidden{{/hidden}} {{class}} {{#hascontrols}}block_with_controls{{/hascontrols}} card mb-3"
role="{{ariarole}}"
data-block="{{type}}"
data-instance-id="{{blockinstanceid}}"
{{#arialabel}}
aria-label={{#quote}}{{{arialabel}}}{{/quote}}
{{/arialabel}}
{{^arialabel}}
{{#title}}
aria-labelledby="instance-{{blockinstanceid}}-header"
{{/title}}
{{/arialabel}}>
{{! Block contents }}
<div class="card-body p-3">
{{! Block header }}
{{#title}}
<h5 id="instance-{{blockinstanceid}}-header" class="card-title d-inline">{{{title}}}</h5>
{{/title}}
{{#hascontrols}}
<div class="block-controls float-right header">
{{{controls}}}
</div>
{{/hascontrols}}
<div class="card-text content mt-3">
{{{content}}}
<div class="footer">{{{footer}}}</div>
{{{annotation}}}
</div>
</div>
{{! End Block Container }}
</section>
{{! Block Skip Link Target }}
{{#showskiplink}}
<span id="sb-{{skipid}}"></span>
{{/showskiplink}}