2

It is nowhere documented, see http://api.jqueryui.com/draggable/#option-revert


It shows that you can supply a function for the revert option, but it doesn't show which arguments this function will receive.

demongolem
  • 9,474
  • 36
  • 90
  • 105
user3280015
  • 279
  • 2
  • 10
  • Not documented ...? `Multiple types supported: Boolean:... String:... Function:...` – Rory McCrossan Jul 10 '14 at 08:26
  • The question is which **arguments** the **revert function** accepts or receives, if you supply one.. – user3280015 Jul 10 '14 at 08:39
  • That's what I answered, and what the ***API is showing you***. I don't understand your confusion. – Rory McCrossan Jul 10 '14 at 08:41
  • No it doesn't. It shows that you can supply a function for the revert option, but it doesn't show which arguments this function will receive – user3280015 Jul 10 '14 at 08:42
  • Right, that's the information which should be in the question. – Rory McCrossan Jul 10 '14 at 08:43
  • It is, if you read it carefully ;) the API only documents the revert option, not the revert function. (Agreed I could have worded it more precisely) – user3280015 Jul 10 '14 at 08:44
  • Does this help? -> http://stackoverflow.com/questions/14571919/adding-a-function-to-jquery-draggable-revert-event – PulseLab Jul 10 '14 at 14:24
  • Your updated title doesn't help the downvote issue you appear to be having. – Kevin B Jul 10 '14 at 14:26
  • also, the documentation that you linked to has the answer, under `Multiple types supported:` – Kevin B Jul 10 '14 at 14:27
  • Thanks PulseLab, but actually it doesn't. It isn't an official source and there are several different function signatures in the question and the answers. 'is_valid_drop' doesn't correspond with what I'm getting, also it seems to set at least two – user3280015 Jul 10 '14 at 14:27

1 Answers1

6

You should learn to read source code when the documentation is not complete/satisfactory. The following invocation:

this.options.revert.call(this.element, dropped)

is on line 6055 in the non-minified jquery-ui.js (and is the first result when you grep for options.revert)

This means that if revert is a function, it is invoked on the the widget element jquery object1; and it is passed dropped as the only argument.

dropped is a boolean value, which indicates whether the current draggable was dropped on a valid droppable element; as can be seen a couple of lines above it.

As the comments say: when the droppable is valid and accepts the dragged element, dropped holds a reference to the droppable jQuery DOM element (and thus converts to true when evaluated as a boolean)


  1. The object a function is invoked on (in this case - the jQuery element that underlies the draggable widget -- is not passed as an argument; it is merely the context within which the function is invoked and is accessible within the function with the this reference.

The only argument the function receives is the dropped boolean.

Lee
  • 922
  • 2
  • 11
  • 19
blgt
  • 8,135
  • 1
  • 25
  • 28
  • 1
    Thanks man. This is the first directly useful answer and apparently you're the first person who got the question. – user3280015 Jul 10 '14 at 14:35
  • 'this.element' seems to refer to the draggable itself unless I didn't understand the code, not the droppable, then I saw examples where it was used as the droppable, and examples where it was used as a boolean dropped. Or 'is_valid_drop' even. I would need to access the droppable. I don't think you should have to read code to get this info though. – user3280015 Jul 10 '14 at 14:36
  • Actually I didn't. The comments were more helpful, I suggest editing them into the question, so it would also be useful to others :) About your comment: `this.element` refers to the object (the draggable) the `revert` function is invoked on, it is NOT an argument. It can be accessed within the function with `this`. – blgt Jul 10 '14 at 14:36
  • What's not clear about "EDIT It shows that you can supply a function for the revert option, but it doesn't show which **arguments** this function will receive" ? – user3280015 Jul 10 '14 at 14:38
  • What do you mean "it is NOT an argument"? Oh I get it, because of the .call() semantics? SEE this is why I expect documentation for that. Can't expect a standard user of a jquery function to read and understand its intricate code ;) – user3280015 Jul 10 '14 at 14:41
  • @user3280015 Edited in post now. – blgt Jul 10 '14 at 14:43
  • 2
    Just for the records, the returned `dropped` is **not** a boolean. It is false if the current draggable was dropped on a valid droppable element, and otherwise it is the droppable object it was dropped on itself. So much for documentation by code ;-) – user3280015 Jul 11 '14 at 11:34