Comments (6)
I think the problem is on line 83
this.$container[method]('mousedown touchstart', this.selector, this.began);
So I changed the listener to 'mousemove' instead of 'musedown'
this.$container[method]('mousemove touchstart', this.selector, this.began);
and in the 'began' method to differentiate when we are really moving a brick I am checking the mouse event buttons
Draggable.prototype.began = function(event) {
var _ref;
if (this.$target) {
return;
}
event.preventDefault();
event.stopPropagation();
if (!(event.buttons == 1 && event.which == 1)) {
return;
}
this.bind('on');
this.$target = $(event.target).closest(this.$container.find(this.selector));
this.$target.addClass('dragging');
this.origin = {
x: this.coordinate(event).pageX - this.$target.position().left,
y: this.coordinate(event).pageY - this.$target.position().top
};
return (_ref = this.callbacks) != null ? typeof _ref.began === "function" ? _ref.began(event) : void 0 : void 0;
};
Maybe is not be the most elegant way to solve the problem, but for now it works.
Also would be nice if the 'reordered' callback will be called only if you have really changed the positions of the bricks, it is only a proposal.
Cheers.
from jquery-gridly.
@bellzebu Sounds like a bug. I'll try to take a look at it when I get a chance.
from jquery-gridly.
Thank you Kevin.
A temporary fix to know when the order is really changed consists in compare the actual $selected array in the callback with another array containing the previous $selected.
Cheers.
from jquery-gridly.
+1
from jquery-gridly.
Easy solution to prevent reorder on mouse click is to add this line to Gridly.prototype.draggingEnd
Gridly.prototype.draggingEnded = function(event) {
if (!this._draggable.dragged) return;
// ...
});
I have also added a check to see which elements actually changed
Gridly.prototype.draggingEnded = function(event) {
// prevent simple mouse click reordered callback
if (!this._draggable.dragged) return;
var $elements, before, ref, ref1, reordered = [];
// remember initial order elements
before = this.$('> *');
$elements = this.$sorted();
this.ordinalize($elements);
setTimeout(this.layout, 0);
// do a check to see if any items actually changed
$elements.each(function(index, el){
var ordered = before[index];
if ($(el).data('position') !== $(ordered).data('position')) {
reordered.push(el);
}
});
// nothing changed
if (!reordered.length) return;
// pass reordered items as second parameter to the callback
return (ref = this.settings) != null ? (ref1 = ref.callbacks) != null ? typeof ref1.reordered === "function" ? ref1.reordered($elements, reordered) : void 0 : void 0 : void 0;
};
Drag handling logic needs some improvement. Also lines like this make the code very hard to read
return (ref = this.settings) != null ? (ref1 = ref.callbacks) != null ? typeof ref1.reordered === "function" ? ref1.reordered($elements, reordered) : void 0 : void 0 : void 0;```
from jquery-gridly.
Maybe this is a bad answer, but finally I decided to use this.
$("#grl_OrdersToList>.StyledCard .cardIndex").each(function (index) {
$(this).text(index+1);
});
from jquery-gridly.
Related Issues (20)
- Vertical grid HOT 2
- Multiple grids misbehaviour
- Jquery version compatibility HOT 8
- who can help to provide a frame explain for source code ? HOT 1
- Delete button's callback not run correctly on mobile. HOT 5
- Reloading the grid
- Brick moving
- Grid Width HOT 1
- Using within a hidden div HOT 1
- How can i get the drag element before the reorder
- Touch compatible? HOT 4
- Is there any way to serialize current state and use it later? HOT 1
- Prepending a tile is not working
- How can i use multiple column HOT 1
- Mobile Browser Touch event clicks are not working HOT 2
- resizing gridly elements
- Library is breaking on IE 11.
- Hi! Is there any way to just make the boxes switch places rather than "shifting" all the preceding bricks
- Items are being clicked when started dragging.
- Tiles flickering when there's more than one row HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-gridly.