Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Draggable: Add "updatePosition" option to control if we want to automatically update the position of the draggable. #718

Closed
wants to merge 1 commit into from

3 participants

@Carpetsmoker

Draggable: Add "updatePosition" option to control if we want to automatically update the position of the draggable.
This is useful for some advanced usage of draggable where you want to update the position yourself in the drag callback.

@Carpetsmoker Carpetsmoker Update ui/jquery.ui.draggable.js
Draggable: Add "updatePosition" option to control if we want to automatically update the position of the draggable.
This is useful for some advanced usage of draggable where you want to update the position yourself in the drag callback.
14ab034
@scottgonzalez

How does this relate to refreshPositions?

@Carpetsmoker

As I understand it, it doesn't.

Here's an example of this option in use:
http://arp242.net/tmp/jqueryui/updatePosition.html

Without this option, the draggable updates the position of the .bar, which means it goes up twice as fast as the .bottom div grows in height since I do the updating in the drag callback.

This is just one usage scenario, there are probably others.

@scottgonzalez

So to clarify, you want to use draggable, but never have it actually drag? That doesn't seem like an option we should add. Have you tried just calling event.preventDefault() in the drag callback?

@mikesherov
Collaborator

Hi @Carpetsmoker, thanks again for contributing this patch. We recently re-enabled the test suite for draggable. In order for us to land this patch, we'd need a few tests added to the test suite proving this doesn't break existing functionality and also that it fixes the bug as described. Can you add some tests here please?

@mikesherov
Collaborator

Hi @Carpetsmoker, thanks again for contributing this pull request! However, we're not going to be adding this option to core. This fiddle shows preventDefault is adequate to cover your use case: http://jsfiddle.net/ZKxMR/1/

In the future, please submit a bug on the bug tracker http://bugs.jqueryui.com first so we can discuss the issue before doing the work to fix it. There are tons of bugs to fix there too if you'd like to contribute further.

@mikesherov mikesherov closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 23, 2012
  1. @Carpetsmoker

    Update ui/jquery.ui.draggable.js

    Carpetsmoker authored
    Draggable: Add "updatePosition" option to control if we want to automatically update the position of the draggable.
    This is useful for some advanced usage of draggable where you want to update the position yourself in the drag callback.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 ui/jquery.ui.draggable.js
View
12 ui/jquery.ui.draggable.js
@@ -42,7 +42,8 @@ $.widget("ui.draggable", $.ui.mouse, {
snapMode: "both",
snapTolerance: 20,
stack: false,
- zIndex: false
+ zIndex: false,
+ updatePosition: true
},
_create: function() {
@@ -181,9 +182,12 @@ $.widget("ui.draggable", $.ui.mouse, {
}
this.position = ui.position;
}
-
- if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
- if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
+ if (this.options.updatePosition) {
+ if (!this.options.axis || this.options.axis != "y")
+ this.helper[0].style.left = this.position.left + 'px';
+ if (!this.options.axis || this.options.axis != "x")
+ this.helper[0].style.top = this.position.top + 'px';
+ }
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
return false;
Something went wrong with that request. Please try again.