Skip to content

Commit

Permalink
Add option for custom replace content method
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbochmann committed May 23, 2024
1 parent 6afe646 commit dbbccc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Documentation/Utilities/AjaxContentRenderer/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,20 @@ ausgelöst wird. Das bedeutet z.B. dass Checkboxen nicht den checked Status erha
z.B. ein anderes Element lädt und selbst gar nicht aktualisiert wird, dann bekommt eine Checkbox
keinen checked Status. Wenn das betrffende Element die CSS Klasse "ajax-dont-prevent-default" bekommt,
wird das verhindert.

Eigene Methode zum ersetzen des Inhalts
---------------------------------------

Wenn ein Element, welches den Ajax Request startet, das data-Attribut
**data-ajax-custom-replace-method** hat, dann wird diese Method zum ersetzen
des Inhalts aufgerufen. Die Method muss in der DMK.Objects.AjaxContent Klasse
ergänzt werden. z.B. so:

~~~~ {.sourceCode .js}
DMK.Objects.AjaxContent.prototype.replaceContentForSomethingElse = function(contentId, html, from, to) {
appendContent(contentId, html)
};
~~~~

Ansonsten wird der komplette Inhalt des Elements 1:1 ersetzt.
6 changes: 5 additions & 1 deletion Resources/Public/JavaScript/AjaxContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@
else if (parameters.page === "prev") {
from = 1;
}
_self.replaceContent(parameters.contentid, data, from, to);
if ($el.data("ajaxCustomReplaceMethod")) {
_self[$el.data("ajaxCustomReplaceMethod")](parameters.contentid, data, from, to);
} else {
_self.replaceContent(parameters.contentid, data, from, to);
}
};

if ($el.hasClass("notcachable")) {
Expand Down

0 comments on commit dbbccc5

Please sign in to comment.