要定义扩展,请调用 htmx.defineExtension()
函数:
¥To define an extension you call the htmx.defineExtension()
function:
<script>
htmx.defineExtension('my-ext', {
onEvent : function(name, evt) {
console.log("Fired event: " + name, evt);
}
})
</script>
通常,这是在独立的 javascript 文件中完成的,而不是在内联 script
标记中完成的。
¥Typically, this is done in a stand-alone javascript file, rather than in an inline script
tag.
扩展的名称应以破折号分隔,并且应简短且具有描述性。
¥Extensions should have names that are dash separated and that are reasonably short and descriptive.
扩展可以覆盖以下默认扩展点来添加或更改功能:
¥Extensions can override the following default extension points to add or change functionality:
{
init: function(api) {return null;},
getSelectors: function() {return null;},
onEvent : function(name, evt) {return true;},
transformResponse : function(text, xhr, elt) {return text;},
isInlineSwap : function(swapStyle) {return false;},
handleSwap : function(swapStyle, target, fragment, settleInfo) {return false;},
encodeParameters : function(xhr, parameters, elt) {return null;}
}