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

Commit

Permalink
pass a response callback function to custom target functions. by @bsh…
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasCARPi committed Feb 20, 2018
1 parent 923415f commit 9bbf74c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ <h4 class='trigger'><i class='fas fa-eye'></i> Show source code</h4>
onedit : function() { console.log('If I return false edition will be canceled'); return true;},
before : function() { console.log('Triggered before form appears');},
callback : function(result, settings, submitdata) {
console.log('Triggered after submit');
console.log('Callback function: triggered after submit');
console.log('Result: ' + result);
console.log('Settings.width: ' + settings.width);
console.log('Submitdata: ' + submitdata.pwet);
Expand Down
21 changes: 15 additions & 6 deletions src/jquery.jeditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,22 @@

/* Check if given target is function */
if ($.isFunction(settings.target)) {
var str = settings.target.apply(self, [input.val(), settings, self]);
$(self).html(str);
self.editing = false;
callback.apply(self, [self.innerHTML, settings]);
if (!$.trim($(self).html())) {
$(self).html(settings.placeholder);
/* Callback function to handle the target reponse */
var responseHandler = function(value) {
$(self).html(value);
self.editing = false;
callback.apply(self, [self.innerHTML, settings]);
if (!$.trim($(self).html())) {
$(self).html(settings.placeholder);
}
};
/* Call the user target function */
var userTarget = settings.target.apply(self, [input.val(), settings, responseHandler]);
/* Handle the target function return for compatibility */
if (false !== userTarget && undefined !== userTarget) {
responseHandler(userTarget);
}

} else {
/* Add edited content and id of edited element to POST. */
var submitdata = {};
Expand Down

0 comments on commit 9bbf74c

Please sign in to comment.