mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
1ef815cd97
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
11 lines
4.4 KiB
JavaScript
11 lines
4.4 KiB
JavaScript
define("core/templates",["exports","jquery","core/config","core_filters/events","core/yui","./local/templates/renderer","core/utils"],(function(_exports,_jquery,config,filterEvents,Y,_renderer,_utils){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
|
/**
|
|
* Template renderer for Moodle. Load and render Moodle templates with Mustache.
|
|
*
|
|
* @module core/templates
|
|
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
* @since 2.9
|
|
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=_interopRequireDefault(_jquery),config=_interopRequireWildcard(config),filterEvents=_interopRequireWildcard(filterEvents),Y=_interopRequireWildcard(Y),_renderer=_interopRequireDefault(_renderer);const runTemplateJS=source=>{if(""!==source.trim()){const newScript=(0,_jquery.default)("<script>").attr("type","text/javascript").html(source);(0,_jquery.default)("head").append(newScript),newScript.find("script").length&&window.console.error("Template JS contains a script tag. This is not allowed. Only raw JS should be present here.",source)}},domReplace=(element,newHTML,newJS,replaceChildNodes)=>{const replaceNode=(0,_jquery.default)(element);if(!replaceNode.length)return[];const newNodes=(0,_jquery.default)(newHTML);if(replaceChildNodes){new Y.NodeList(replaceNode.children().get()).destroy(!0),replaceNode.empty(),replaceNode.append(newNodes)}else{new Y.NodeList(replaceNode.get()).destroy(!0),replaceNode.replaceWith(newNodes)}return runTemplateJS(newJS),filterEvents.notifyFilterContentUpdated(newNodes),newNodes.get()};var _default={render:function(templateName,context){let themeName=arguments.length>2&&void 0!==arguments[2]?arguments[2]:config.theme;const renderer=new _renderer.default;return _jquery.default.when(new Promise(((resolve,reject)=>{renderer.render(templateName,context,themeName).then(resolve).catch(reject)}))).then((_ref=>{let{html:html,js:js}=_ref;return _jquery.default.Deferred().resolve(html,js)}))},prefetchTemplates:function(templateNames){let themeName=arguments.length>1&&void 0!==arguments[1]?arguments[1]:config.theme;const Loader=_renderer.default.getLoader();return Loader.prefetchTemplates(templateNames,themeName)},renderForPromise:(templateName,context,themeName)=>(new _renderer.default).render(templateName,context,themeName),renderPix:(key,component,title)=>{const renderer=new _renderer.default;return promise=renderer.renderIcon(key,(0,_utils.getNormalisedComponent)(component),title),_jquery.default.when(new Promise(((resolve,reject)=>{promise.then(resolve).catch(reject)})));var promise},runTemplateJS:runTemplateJS,replaceNodeContents:(element,newHTML,newJS)=>domReplace(element,newHTML,newJS,!0),replaceNode:(element,newHTML,newJS)=>domReplace(element,newHTML,newJS,!1),prependNodeContents:(element,html,js)=>((element,html,js)=>{const node=(0,_jquery.default)(element);if(!node.length)return[];const newContent=(0,_jquery.default)(html);return node.prepend(newContent),runTemplateJS(js),filterEvents.notifyFilterContentUpdated(node),newContent.get()})(element,html,js),appendNodeContents:(element,html,js)=>((element,html,js)=>{const node=(0,_jquery.default)(element);if(!node.length)return[];const newContent=(0,_jquery.default)(html);return node.append(newContent),runTemplateJS(js),filterEvents.notifyFilterContentUpdated(node),newContent.get()})(element,html,js)};return _exports.default=_default,_exports.default}));
|
|
|
|
//# sourceMappingURL=templates.min.js.map
|