Skip to content

Commit 3b3f81a

Browse files
authored
Merge pull request #1258 from roland04/devdocs-bootstrap5-compatibility-data
[docs] Documentation for MDL-84450
2 parents 78ff7bd + 32466bf commit 3b3f81a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/guides/bs5migration/index.md

+41
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,44 @@ Some of the SCSS helpers and utilities available in the backwards-compatibility
723723

724724
All these backwards-compatible SCSS helpers and utilities will be available until the final deprecation in Moodle 6.0.
725725
More details about the SCSS deprecation process can be found in [SCSS deprecation](/general/development/policies/deprecation/scss-deprecation).
726+
727+
### Bootstrap 4 old data attributes syntax silent replacement
728+
729+
<Since version="5.0" issueNumber="MDL-84450" />
730+
731+
To minimize immediate breaking changes, the backwards-compatibility layer implements a silent replacement mechanism for Bootstrap 4's data attribute syntax.
732+
733+
As per Bootstrap's migration guide "*Data attributes for all JavaScript plugins are now namespaced to help distinguish Bootstrap functionality from third parties and your own code. For example, we use `data-bs-toggle` instead of `data-toggle`.*"
734+
735+
This feature can be used to translate old data attributes to their Bootstrap 5 equivalents, allowing existing markup to function without requiring immediate updates.
736+
737+
```js title="Example of bs4-compat silent replacement in amd module"
738+
import initBootstrap4Compatibility from 'theme_boost/bs4-compat';
739+
740+
[...]
741+
742+
// Init Bootstrap 4 compatibility giving an specific element to look into.
743+
initBootstrap4Compatibility(document.querySelector('[data-region="my-plugin-region"]'));
744+
745+
// Init Bootstrap 4 compatibility in the entire document.
746+
initBootstrap4Compatibility();
747+
```
748+
749+
```mustache title="Example of bs4-compat silent replacement in a template"
750+
[...]
751+
752+
{{#js}}
753+
// Init Bootstrap 4 compatibility in the entire document.
754+
require(['theme_boost/bs4-compat'], function(BS4Compat) {
755+
BS4Compat();
756+
});
757+
{{/js}}
758+
```
759+
760+
This will replace for example `data-toggle="tooltip"` with `data-bs-toggle="tooltip"`, or `data-target="#collapsableContent"` with `data-bs-target="#collapsableContent"`.
761+
762+
:::warning
763+
764+
Dynamic generated content containing old data attributes syntax will not be replaced.
765+
766+
:::

0 commit comments

Comments
 (0)