htmx 拡張機能の構築

拡張機能を定義するには、関数htmx.defineExtension() をコールします

<script>
  htmx.defineExtension('my-ext', {
    onEvent : function(name, evt) {
        console.log("Fired event: " + name, evt);
    }
  })
</script>

通常は、インライン script タグに埋め込むのではなく、スタンドアロンの JavaScript ファイルで実行します。

拡張機能には、ダッシュで区切り、多少短く、また記述的な名前を付けるべきです。

拡張機能は、以下の既定の拡張ポイントをオーバーライドして、機能を追加または変更できます

{
    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;}
}