include-vals.js 835 B

123456789101112131415161718192021222324
  1. (function(){
  2. function mergeObjects(obj1, obj2) {
  3. for (var key in obj2) {
  4. if (obj2.hasOwnProperty(key)) {
  5. obj1[key] = obj2[key];
  6. }
  7. }
  8. return obj1;
  9. }
  10. htmx.defineExtension('include-vals', {
  11. onEvent: function (name, evt) {
  12. if (name === "htmx:configRequest") {
  13. var includeValsElt = htmx.closest(evt.detail.elt, "[include-vals],[data-include-vals]");
  14. if (includeValsElt) {
  15. var includeVals = includeValsElt.getAttribute("include-vals") || includeValsElt.getAttribute("data-include-vals");
  16. var valuesToInclude = eval("({" + includeVals + "})");
  17. mergeObjects(evt.detail.parameters, valuesToInclude);
  18. }
  19. }
  20. }
  21. });
  22. })();