Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

define("tool_componentlibrary/mustache",["exports","tool_componentlibrary/selectors","core/ajax","core/config","core/templates","core/log","core/notification"],(function(_exports,_selectors,_ajax,_config,_templates,_log,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
   * Render mustache template examples within the component library.
   *
   * @module     tool_componentlibrary/mustache
   * @copyright  2021 Bas Brands <bas@moodle.com>
   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
   */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.mustache=void 0,_selectors=_interopRequireDefault(_selectors),_ajax=_interopRequireDefault(_ajax),_config=_interopRequireDefault(_config),_templates=_interopRequireDefault(_templates),_log=_interopRequireDefault(_log),_notification=_interopRequireDefault(_notification);const loadTemplate=container=>{const sourcecontainer=container.querySelector(_selectors.default.mustachesource),contextcontainer=container.querySelector(_selectors.default.mustachecontext),templateName=container.dataset.template;let context=container.querySelector(_selectors.default.mustacherawcontext).textContent;const parts=templateName.split("/"),request={methodname:"core_output_load_template",args:{component:parts.shift(),template:parts.join("/"),themename:_config.default.theme,includecomments:!0}};_ajax.default.call([request])[0].done((source=>{if(sourcecontainer.textContent=source,!context){const example=source.match(/Example context \(json\):([\s\S]+?)(}})/);context=example[1];const precontainer=document.createElement("pre");precontainer.innerHTML=JSON.stringify(JSON.parse(context),null,4),contextcontainer.parentNode.appendChild(precontainer),contextcontainer.classList.add("d-none")}(async(container,templateName,context)=>{try{context=JSON.parse(context)}catch(e){_log.default.debug("Could not parse json example context for template."),_log.default.debug(e)}const{html:html,js:js}=await _templates.default.renderForPromise(templateName,context),rendercontainer=container.querySelector(_selectors.default.mustacherendered);await _templates.default.replaceNodeContents(rendercontainer,html,js)})(container,templateName,context)})).fail(_notification.default.exception)};_exports.mustache=()=>{document.querySelectorAll(_selectors.default.mustachecode).forEach((container=>{loadTemplate(container)}))}}));

//# sourceMappingURL=mustache.min.js.map