Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Pass a response callback function to custom target functions #65

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions jquery.jeditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,21 @@

/* Check if given target is function */
if ($.isFunction(settings.target)) {
var str = settings.target.apply(self, [input.val(), settings]);
$(self).html(str);
self.editing = false;
callback.apply(self, [self.innerHTML, settings]);
/* TODO: this is not dry */
if (!$.trim($(self).html())) {
$(self).html(settings.placeholder);
/* Callback function to handle the target reponse */
var handleresponse = function(value) {
$(self).html(value);
self.editing = false;
callback.apply(self, [self.innerHTML, settings]);
/* TODO: this is not dry */
if (!$.trim($(self).html())) {
$(self).html(settings.placeholder);
}
}
/* Call the user target function */
var user_target = settings.target.apply(self, [input.val(), settings, handleresponse]);
/* Handle the target function return for compatibility */
if (false !== user_target && undefined !== user_target) {
handleresponse(user_target);
}
} else {
/* Add edited content and id of edited element to POST. */
Expand Down