Ticket #3175: draggable-revert.patch
| File draggable-revert.patch, 2.3 KB (added by kevingessner, 2 years ago) |
|---|
|
Patch for ui.draggable adding callback capability to revert: (with test) |
-
tests/draggable-revert.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 4 <head> 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 6 <title>jQuery UI Draggable Revert-Function Test</title> 7 8 <script type="text/javascript" src="../jquery-1.2.6.js"></script> 9 <script type="text/javascript" src="../ui/ui.core.js"></script> 10 <script type="text/javascript" src="../ui/ui.draggable.js"></script> 11 <script type="text/javascript" src="draggable-revert.js"></script> 12 13 <style type="text/css"> 14 15 #draggable { 16 width: 150px; 17 height: 150px; 18 background-color: #ccc; 19 padding: 10px; 20 border: solid 1px black; 21 } 22 23 </style> 24 </head> 25 <body> 26 <h1>jQuery UI Draggable Revert-Function Test</h1> 27 <p><input id="revert" type="checkbox"> <label for="revert">Revert?</label></p> 28 <div id="draggable">Drag me!</div> 29 </body> 30 </html> 31 No newline at end of file -
tests/draggable-revert.js
1 $(function () { 2 $('#draggable').draggable({ 3 revert: function () { 4 return !!($('#revert').val()); 5 } 6 }); 7 }); 8 No newline at end of file -
ui/ui.draggable.js
229 229 if ($.ui.ddmanager && !this.options.dropBehaviour) 230 230 var dropped = $.ui.ddmanager.drop(this, e); 231 231 232 if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true ) {232 if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || (typeof(this.options.revert) == 'function' && this.options.revert())) { 233 233 var self = this; 234 234 $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10) || 500, function() { 235 235 self.propagate("stop", e);
![(please configure the [header_logo] section in trac.ini)](/chrome/site/nologo.gif)