Skip to content

Commit

Permalink
Make handles draggable to allow selection in firefox
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
Sebastian Plagemann committed Nov 20, 2014
1 parent 5ea6fdf commit f7e1b14
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 48 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Expand Up @@ -19,4 +19,5 @@ RWOverdijk (https://github.com/RWOverdijk)
ssafejava (http://github.com/ssafejava)
TV productions (https://github.com/TV-productions)
Steve Farthing (https://github.com/sfarthin)
Adam Nowotny (https://github.com/AdamNowotny)
Adam Nowotny (https://github.com/AdamNowotny)
Sebastian Plagemann (https://github.com/splagemann)
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "html.sortable",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "https://github.com/voidberg/html5sortable",
"authors": [
"Alexandru Badiu <andu@ctrlz.ro>"
Expand Down
37 changes: 15 additions & 22 deletions dist/html.sortable.js
Expand Up @@ -23,6 +23,9 @@
}, options);

return this.each(function () {

var index, items = $(this).children(options.items), handles = options.handle ? items.find(options.handle) : items;

if (method === 'reload') {
$(this).children(options.items).off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s');
}
Expand All @@ -32,7 +35,8 @@
$(this).off('sortupdate');
$(this).removeData('opts');
citems.add(this).removeData('connectWith items')
.off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s').off('sortupdate');
.off('dragstart.h5s dragend.h5s dragover.h5s dragenter.h5s drop.h5s').off('sortupdate');
handles.off('selectstart.h5s');
}
return;
}
Expand All @@ -46,15 +50,9 @@
options = soptions;
}

var isHandle, index, items = $(this).children(options.items);
var startParent, newParent;
var placeholder = ( options.placeholder === null ) ? $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder"/>') : $(options.placeholder).addClass('sortable-placeholder');

items.find(options.handle).mousedown(function () {
isHandle = true;
}).mouseup(function () {
isHandle = false;
});
$(this).data('items', options.items);
placeholders = placeholders.add(placeholder);
if (options.connectWith) {
Expand All @@ -64,12 +62,16 @@
items.attr('role', 'option');
items.attr('aria-grabbed', 'false');

items.attr('draggable', 'true').on('dragstart.h5s',function (e) {
e.stopImmediatePropagation();
if (options.handle && !isHandle) {
return false;
// Setup drag handles
handles.attr('draggable', 'true').not('a[href], img').on('selectstart.h5s', function() {
if (this.dragDrop) {
this.dragDrop();
}
isHandle = false;
return false;
}).end();

// Handle drag events on draggable items
items.on('dragstart.h5s', function(e) {
var dt = e.originalEvent.dataTransfer;
dt.effectAllowed = 'move';
dt.setData('text', '');
Expand All @@ -93,16 +95,7 @@
}
dragging = null;
draggingHeight = null;
}).not('a[href], img').on('selectstart.h5s',function () {
if (options.handle && !isHandle) {
return true;
}

if (this.dragDrop) {
this.dragDrop();
}
return false;
}).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function (e) {

This comment has been minimized.

Copy link
@lukasoppermann

lukasoppermann Dec 24, 2014

Owner

@voidberg you know why we need to add placeholder?

}).add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) {
if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/html.sortable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/html.sortable.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 15 additions & 22 deletions src/html.sortable.js
Expand Up @@ -23,6 +23,9 @@
}, options);

return this.each(function () {

var index, items = $(this).children(options.items), handles = options.handle ? items.find(options.handle) : items;

if (method === 'reload') {
$(this).children(options.items).off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s');
}
Expand All @@ -32,7 +35,8 @@
$(this).off('sortupdate');
$(this).removeData('opts');
citems.add(this).removeData('connectWith items')
.off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s').off('sortupdate');
.off('dragstart.h5s dragend.h5s dragover.h5s dragenter.h5s drop.h5s').off('sortupdate');
handles.off('selectstart.h5s');
}
return;
}
Expand All @@ -46,15 +50,9 @@
options = soptions;
}

var isHandle, index, items = $(this).children(options.items);
var startParent, newParent;
var placeholder = ( options.placeholder === null ) ? $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder"/>') : $(options.placeholder).addClass('sortable-placeholder');

items.find(options.handle).mousedown(function () {
isHandle = true;
}).mouseup(function () {
isHandle = false;
});
$(this).data('items', options.items);
placeholders = placeholders.add(placeholder);
if (options.connectWith) {
Expand All @@ -64,12 +62,16 @@
items.attr('role', 'option');
items.attr('aria-grabbed', 'false');

items.attr('draggable', 'true').on('dragstart.h5s',function (e) {
e.stopImmediatePropagation();
if (options.handle && !isHandle) {
return false;
// Setup drag handles
handles.attr('draggable', 'true').not('a[href], img').on('selectstart.h5s', function() {
if (this.dragDrop) {
this.dragDrop();
}
isHandle = false;
return false;
}).end();

// Handle drag events on draggable items
items.on('dragstart.h5s', function(e) {
var dt = e.originalEvent.dataTransfer;
dt.effectAllowed = 'move';
dt.setData('text', '');
Expand All @@ -93,16 +95,7 @@
}
dragging = null;
draggingHeight = null;
}).not('a[href], img').on('selectstart.h5s',function () {
if (options.handle && !isHandle) {
return true;
}

if (this.dragDrop) {
this.dragDrop();
}
return false;
}).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function (e) {
}).add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) {
if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) {
return true;
}
Expand Down

0 comments on commit f7e1b14

Please sign in to comment.