66 Commits

Author SHA1 Message Date
Andrew Nicols
1ef815cd97
MDL-78266 core: Break apart core/templates
This commit breaks apart the responsibilities of the core/templates
module to separate out the different constituent parts. Broadly speaking
these are:
- core/local/templates/loader - responsible for fetching, and caching,
  of templates
- core/local/templates/renderer - A Moodle wrapper around the Mustache
  engine
2023-05-25 13:42:00 +08:00
Andrew Nicols
16dee82ce5
MDL-78266 core: Migrate core/templates to esm 2023-05-25 12:09:46 +08:00
Paul Holden
ea0515758a MDL-77003 javascript: improve string helper JSON detection.
Changes in fbc2732d made the JS template string helper method
too strict in regards to what it considers a valid JSON object.

Co-authored-by: Mike Churchward <mike@brickfieldlabs.ie>
2023-01-24 22:14:12 +00:00
Meirza
fbc2732d9f MDL-76508 templates: Handling non-JSON string
When the param string contains a left curly bracket as the first character,
the system will assume the string is a JSON string and will be parsed and returned as an object.
But in some cases, the string is not JSON and will return an error if the system parses it.
For example, a user might have used the course name with a left curly bracket as the first character.
Adding a double quote after the left curly bracket to differentiate between string and JSON string,
so it can be safe to parse the string, and also added try..catch to ensure that the parsing creates an object type.
2022-12-23 09:57:36 +07:00
Lars Bonczek
e875c6118c MDL-75516 core: Perform proper JSON encoding in mustache quote helper 2022-12-02 13:39:58 +01:00
Andrew Nicols
e1b9d5f3cd MDL-73915 js: Drop support for IE and android
Moodle announced that support for IE would be dropped back in August
2020 with Moodle 3.9 but not active steps were taken at that time. That
decision was made in MDLSITE-6109 and this particular step was meant to
be taken in Moodle 3.10.

This is the first step taken to actively drop support for IE.

This commit also bumps the browser support pattern from 0.25% to 0.3%.
The percentage here includes any browser where at least this percentage
of users worldwide may be using a browser. In this case it causes
support for Android 4.3-4.4 to be dropped, which relate to Android
KitKat (released 2013).

This combination of changes means that all of the supported browsers in
our compatibility list support modern features including async,
for...of, classes, native Promises, and more which has a huge impact on
the ease of debugging code, and drastically reduces the minified file
size because a number of native Polyfills included by Babel are no
longer included.
2022-02-23 08:55:20 +08:00
Andrew Nicols
0a4047ab31 MDL-73915 js: Switch amd minification to terser
Unfortunately the babel minify-mangle plugin seems to be abandoned and
in certain circumstances can be very buggy. The only safe options are to
disable it, or to switch to a different minification library.

Not minifying our javascript is not ideal, so this commit updates the
javascript tasks to use a rollup, combined with babel, and terser.

Babel still converts code from ES/UMD/AMD to AMD modules with the
relevant browser support, whilst terser minifies the code.

The rollup bundler handles tracking and creation of sourcemaps, and
supports better parallelisation of the tasks.

Since the upgrade to Node LTS/Gallium requires an upgrade to @babel/core
and eslint, which change the built files anyway, this seems like the
ideal time to make this change.
2022-02-23 08:55:09 +08:00
Shamim Rezaie
4f96d7ac92 MDL-70721 core: a new mustache helper to clean string after get_string 2021-11-15 22:14:03 +11:00
Andrew Nicols
d4c6ac20c7 MDL-70990 core_filter: Add new native filterContentUpdated event
The legacy M.core.event.FILTER_CONTENT_UPDATED event has been replaced with a
new core_filter/events::filterContentUpdated native DOM event.

The new event can be triggered using the `notifyFilterContentUpdated`
function, and by providing with an Array containing the HTMLElements
that were updated, for example:

```
import {notifyFilterContentUpdated} from 'core_filter/events';

const someHandler = e => {
    // ...
    const nodeList = Array.from(document.querySelectorAll('div'));
    notifyFilterContentUpdated(nodeList);
};
```

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

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

const handler = e => {
    // The list of HTMLElements in an Array.
    e.detail.nodes;
};

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

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

This legacy bridges will be removed after Moodle 4.3.
2021-05-26 10:47:15 +08:00
Dongsheng Cai
ee58790e46 MDL-65203 template: tab should be quoted to produce valid json 2021-05-18 20:40:32 +10:00
Andrew Nicols
1b7ce2dd0d MDL-70802 javascript: Normalise component consistently in templates 2021-03-24 11:18:33 +08:00
Andrew Nicols
f456195599 MDL-67917 core: Return newly added nodes from template helpers
Part of MDL-67743
2020-05-27 10:49:43 +08:00
Andrew Nicols
bc9426c879 MDL-68528 js: Normalise core component for template strings 2020-05-19 11:40:44 +08:00
Andrew Nicols
b9dec51ab4 MDL-68677 core: Correct usage of templaterev for caching templates
The M.cfg.templaterev variable should only be used to present persistent
caching, not caching of content within the same page load.

Preventing caching of same-page content makes it difficult to develop
for real user experiences as content is slow to load and does not give a
realistic and consistent loading experience.

This change affects the loading of partials specifically which notably
includes the loading spinner. Without this patch the loading icon is
often not seen at all because it does not load in a timely fashion and
the content being loaded is loaded first.
2020-05-14 14:10:55 +08:00
Andrew Nicols
f879cc518e MDL-66109 js: Build changes for NodeJS upgrade
This change includes a build to fix all minified file changes in Moodle
as a result of upgrades to our build process.
2020-05-11 10:55:54 +08:00
Andrew Nicols
983baf4e34 MDL-68524 js: Add prefetch module 2020-05-05 10:16:10 +08:00
Andrew Nicols
373d43aef1 MDL-66074 core: Add a renderForPromise function
Promises only take a single argument so this makes it easier to chain
promises and use them with await.
2019-10-28 13:55:12 +08:00
Tim Schroeder
f8f04b773d
MDL-66542 lib: Fix quote escaping in JS quote helper 2019-09-30 10:09:07 +02:00
Jake Dallimore
2796356278 Merge branch 'MDL-66367_master' of git://github.com/markn86/moodle 2019-09-05 09:26:28 +08:00
Mark Nelson
af8a70756f MDL-66367 core: don't cache templates if templaterev is invalid 2019-09-04 12:54:02 +02:00
Mark Nelson
9e5edc7f68 MDL-66367 core: use templaterev as the cache key when getting templates 2019-09-04 12:54:02 +02:00
Ryan Wyllie
3fb0cbd4bb MDL-62284 javascript: prevent nested JS mustache handler calls
Prevent the JS mustache helper from being executed from within
the render call of another mustache helper because it can allow
users to inject JS into the page.
2019-09-04 11:22:51 +08:00
Andrew Nicols
0261d1effa MDL-50346 core: Allow sub-directories in template names 2019-08-07 11:44:49 +08:00
Ryan Wyllie
195ea4480b MDL-62497 javascript: build AMD modules with new transpiler 2019-07-19 14:12:49 +08:00
Mark Nelson
3f7360f07d MDL-65794 core: use themerev as the cache key when getting templates 2019-07-16 14:23:34 +08:00
Kristian Ringer
6c97045e5e MDL-65183 block_timeline: escape newline characters 2019-06-07 09:37:34 +10:00
Simey Lameze
545e2abb91 MDL-63244 core: make mustache retrieve language 2019-03-19 15:03:51 +08:00
Ryan Wyllie
c77ba4890a MDL-64348 javascript: change template loading to a buffer
Changed the template loading to buffer the requests for templates
so that they can be sent in batches to the server to save large
volumes of network requests.
2019-01-07 09:03:06 +08:00
Ryan Wyllie
2b92891a88 MDL-64348 javascript: change template loading to also load dependencies
Changed the getTemplate function in templates.js to use the
core_output_load_template_with_dependencies function to load the
requested template and all of the dependencies required to render it.

The dependencies are added to the relevant caches so that when the
template is rendered they aren't re-requested from the server.
2019-01-07 09:03:06 +08:00
Andrew Nicols
23e347bb32 MDL-64181 core: Ensure that self is included in parentage 2018-11-27 14:42:40 +08:00
Damyon Wiese
a2cb00b655 MDL-64181 javascript: Recursive template fix
This change prevents template rendering from waiting for itself, but does
allow it to wait for another async call to render.
2018-11-27 08:44:36 +08:00
Andrew Nicols
eb514bb3e5 MDL-63714 javascript: Add new core/pending module 2018-10-24 12:49:09 +08:00
Andrew Nicols
4b7ad8845c MDL-63714 core: Wrap doRender in pendingjs 2018-10-24 08:12:10 +08:00
Andrew Nicols
61e0f58ca3 MDL-63667 amd: Check for parent template recursion 2018-10-18 12:04:19 +08:00
Damyon Wiese
b51c5b929f MDL-63667 output: Fix for recursive templates
A template can include itself - e.g. by looping over the context children and rendering a tree.

Ensure this promise still resolves.

Example: admin/tool/lp/templates/competencies_tree.mustache.
2018-10-18 10:48:01 +08:00
Ryan Wyllie
0015f5b8f1 MDL-63667 javascript: fix failed to pre-fetch the template error 2018-10-17 13:49:25 +08:00
Dan Poltawski
50c277a5d8 MDL-57139 js: built 2017-06-01 14:54:40 +01:00
David Mudrák
74e238f4b7 MDL-58760 templates: Make {{#pix}} helper work with escaped icon key
There is a difference between how our PHP mustache engine and JS
mustache engine escaping works. If the icon key is not hard-coded in the
template but defined as a context variable, the JS mustache engine
escapes the forward slashes.
2017-04-28 23:04:04 +02:00
Ryan Wyllie
e03d5d4790 MDL-57445 core: allow context variables in pix helper
Allow the user of context variables in the id and component section of
the pix helper.

Part of MDL-55611 epic.
2017-04-03 11:35:37 +08:00
Dan Poltawski
dca0ea03b1 Merge branch 'MDL-58317-master' of git://github.com/damyon/moodle 2017-03-21 08:03:42 +00:00
Damyon Wiese
f4e623b3e7 MDL-58317 templates: Fix async template render
There is an edge case where we do not wait for all promises before
rendering a template. This can generate "failed to pre-fetch the template" JS errors.
2017-03-20 13:29:09 +08:00
Damyon Wiese
e330b1c214 MDL-40759 icons: Refactor to allow theme icon systems 2017-03-17 15:52:18 +08:00
Damyon Wiese
95b06c13c6 MDL-40759 icons: Refactor icon system to be extensible. 2017-03-17 15:51:29 +08:00
Andrew Nicols
e2310e4361 Merge branch 'MDL-57975-master' of git://github.com/ryanwyllie/moodle 2017-03-10 18:04:42 +00:00
Ryan Wyllie
0e5b3e282f MDL-57975 javascript: add userdate mustache js helper
Part of MDL-55611
2017-03-08 03:33:24 +00:00
Ryan Wyllie
75378ded5f MDL-57972 mustache: add shortentext template helper
Part of MDL-55611
2017-03-07 06:33:56 +00:00
Damyon Wiese
f3cd5c5b7b MDL-57009 javascript: Always use when.apply
Or it does not really wait for the promises.
2017-02-07 15:03:43 +08:00
Damyon Wiese
b302369d17 MDL-57009 javascript: cibot nagging 2017-02-02 15:54:19 +08:00
Damyon Wiese
39bf2a985b MDL-57009 javascript: Dont rely on async ajax
Recursively pre-scan mustache templates to extract the list of blocks and partials. Then
we can pre-fetch them all and don't have to rely on jquery async ajax (which is deprecated).

This is part of a refactoring of the promises code in the templates module to prevent duplicate requests.
2017-02-02 15:54:19 +08:00
Damyon Wiese
f20a336b43 MDL-57009 js: Do not fetch the same template twice
Also clean up promises use of done vs then.
2017-02-02 15:54:19 +08:00