Skip to content

Commit

Permalink
Fix touch support. #169 for jquery-sortable
Browse files Browse the repository at this point in the history
Fix touch support. #169 for jquery-sortable

Fix touch support. In case we are dragging something clickable,
preventDefault on drag, not on mousedown/touchstart by collinstocks.

johnny/jquery-sortable#169

This is support for FirefoxOS
  • Loading branch information
ycatch committed Jan 9, 2016
1 parent fb2dfc7 commit 4aa0be8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
26 changes: 14 additions & 12 deletions js/mameblock.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@
}());

/* ===================================================
* jquery-sortable.js v0.9.13
* jquery-sortable.js v0.9.12
* http://johnny.github.com/jquery-sortable/
* ===================================================
* Copyright (c) 2012 Jonas von Andrian
Expand Down Expand Up @@ -1964,9 +1964,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ========================================================== */


!function ( $, window, pluginName, undefined){
var containerDefaults = {
var eventNames,
containerDefaults = {
// If true, items can be dragged from this container
drag: true,
// If true, items can be droped onto this container
Expand Down Expand Up @@ -2023,21 +2023,22 @@
// The Placeholder has not been moved yet.
onDrag: function ($item, position, _super, event) {
$item.css(position)
event.preventDefault()
},
// Called after the drag has been started,
// that is the mouse button is being held down and
// that is the mouse button is beeing held down and
// the mouse is moving.
// The container is the closest initialized container.
// Therefore it might not be the container, that actually contains the item.
onDragStart: function ($item, container, _super, event) {
$item.css({
height: $item.outerHeight(),
width: $item.outerWidth()
height: $item.height(),
width: $item.width()
})
$item.addClass(container.group.options.draggedClass)
$("body").addClass(container.group.options.bodyClass)
},
// Called when the mouse button is being released
// Called when the mouse button is beeing released
onDrop: function ($item, container, _super, event) {
$item.removeClass(container.group.options.draggedClass).removeAttr("style")
$("body").removeClass(container.group.options.bodyClass)
Expand All @@ -2046,7 +2047,7 @@
// Ignore if element clicked is input, select or textarea
onMousedown: function ($item, _super, event) {
if (!event.target.nodeName.match(/^(input|select|textarea)$/i)) {
event.preventDefault()
if (event.type.match(/^mouse/)) event.preventDefault()
return true
}
},
Expand Down Expand Up @@ -2191,7 +2192,7 @@
this.item = closestItem;
this.itemContainer = itemContainer;
if (this.item.is(this.options.exclude) || !this.options.onMousedown(this.item, groupDefaults.onMousedown, e)) {
return;
return;
}
this.setPointer(e);
this.toggleListeners('on');
Expand Down Expand Up @@ -2338,10 +2339,11 @@
) >= this.options.distance)
},
getPointer: function(e) {
var o = e.originalEvent || e.originalEvent.touches && e.originalEvent.touches[0]
var o = e.originalEvent,
t = (e.originalEvent.touches && e.originalEvent.touches[0]) || {};
return {
left: e.pageX || o.pageX,
top: e.pageY || o.pageY
left: e.pageX || o.pageX || t.pageX,
top: e.pageY || o.pageY || t.pageY
}
},
setupDelayTimer: function () {
Expand Down
26 changes: 14 additions & 12 deletions js/src/jquery-sortable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ===================================================
* jquery-sortable.js v0.9.13
* jquery-sortable.js v0.9.12
* http://johnny.github.com/jquery-sortable/
* ===================================================
* Copyright (c) 2012 Jonas von Andrian
Expand Down Expand Up @@ -27,9 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ========================================================== */


!function ( $, window, pluginName, undefined){
var containerDefaults = {
var eventNames,
containerDefaults = {
// If true, items can be dragged from this container
drag: true,
// If true, items can be droped onto this container
Expand Down Expand Up @@ -86,21 +86,22 @@
// The Placeholder has not been moved yet.
onDrag: function ($item, position, _super, event) {
$item.css(position)
event.preventDefault()
},
// Called after the drag has been started,
// that is the mouse button is being held down and
// that is the mouse button is beeing held down and
// the mouse is moving.
// The container is the closest initialized container.
// Therefore it might not be the container, that actually contains the item.
onDragStart: function ($item, container, _super, event) {
$item.css({
height: $item.outerHeight(),
width: $item.outerWidth()
height: $item.height(),
width: $item.width()
})
$item.addClass(container.group.options.draggedClass)
$("body").addClass(container.group.options.bodyClass)
},
// Called when the mouse button is being released
// Called when the mouse button is beeing released
onDrop: function ($item, container, _super, event) {
$item.removeClass(container.group.options.draggedClass).removeAttr("style")
$("body").removeClass(container.group.options.bodyClass)
Expand All @@ -109,7 +110,7 @@
// Ignore if element clicked is input, select or textarea
onMousedown: function ($item, _super, event) {
if (!event.target.nodeName.match(/^(input|select|textarea)$/i)) {
event.preventDefault()
if (event.type.match(/^mouse/)) event.preventDefault()
return true
}
},
Expand Down Expand Up @@ -254,7 +255,7 @@
this.item = closestItem;
this.itemContainer = itemContainer;
if (this.item.is(this.options.exclude) || !this.options.onMousedown(this.item, groupDefaults.onMousedown, e)) {
return;
return;
}
this.setPointer(e);
this.toggleListeners('on');
Expand Down Expand Up @@ -401,10 +402,11 @@
) >= this.options.distance)
},
getPointer: function(e) {
var o = e.originalEvent || e.originalEvent.touches && e.originalEvent.touches[0]
var o = e.originalEvent,
t = (e.originalEvent.touches && e.originalEvent.touches[0]) || {};
return {
left: e.pageX || o.pageX,
top: e.pageY || o.pageY
left: e.pageX || o.pageX || t.pageX,
top: e.pageY || o.pageY || t.pageY
}
},
setupDelayTimer: function () {
Expand Down

0 comments on commit 4aa0be8

Please sign in to comment.