Fragment
Introduction
fragment.js is an Asynchronous Module Definition (AMD) module to allow the inclusion of rendered HTML code and associated JavaScript to be inserted through AJAX onto a page.
History
The issue for this was created to allow Moodle mforms to be changed and submitted via AJAX. Mforms currently do a lot of validation, and include accessibility code and tags. Most of Moodle uses these forms and there seemed no clear way to borrow or create another system that would satisfy all requirements.
fragment.js details
This JavaScript module is located at lib/amd/src/fragment.js
loadFragment is the exposed function to use. It takes four parameters.
- component: The component for the callback that you will also supply. e.g. "mod_assign"
- callback: The callback that you are calling.
- contextid: The context ID for the component.
- params: Parameters for the callback function.
This function returns a promise that is resolved with HTML and JavaScript.