This repository was archived by the owner on Dec 5, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdragcheck.js
More file actions
65 lines (56 loc) · 2.82 KB
/
Copy pathdragcheck.js
File metadata and controls
65 lines (56 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function ($) {
$.fn.dragcheck = function (options) {
var opts = $.extend({}, $.fn.dragcheck.defaults, options);
return this.each(function () {
var $this = $(this);
var enabled = false;
var state = false;
var startIndex = null;
// meta data plugin support
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
$(':checkbox', $this)
.mousedown(function () {
var $obj = $(this);
enabled = true;
state = !$obj.is(':checked');
startIndex = (o.container ? $obj.parents(o.container).index() : $obj.index());
$obj.one('mouseout', function () {
if (enabled) {
o.onSelect($(this), state);
}
});
})
.mouseover(function () {
if (enabled) {
var $obj = $(this);
var sourceRow = (o.container ? $obj.parents(o.container) : $obj);
var targetRow = (o.container ? $obj.parents(o.container).parent().children(o.container).eq(startIndex) : $obj.parent().children(':checkbox').eq(startIndex));
var endIndex = sourceRow.index();
if (endIndex > startIndex) {
var prevelements = sourceRow.prevUntil(targetRow, o.container || ':checkbox');
o.onSelect((o.container ? targetRow.find(':checkbox') : targetRow), state);
o.onSelect((o.container ? sourceRow.find(':checkbox') : sourceRow), state);
$.each((o.container ? prevelements.find(':checkbox') : prevelements), function() {
o.onSelect($(this), state);
});
}
else if (endIndex < startIndex) {
var nextelements = sourceRow.nextUntil(targetRow, o.container || ':checkbox');
o.onSelect((o.container ? targetRow.find(':checkbox') : targetRow), state);
o.onSelect((o.container ? sourceRow.find(':checkbox') : sourceRow), state);
$.each((o.container ? nextelements.find(':checkbox') : nextelements), function () {
o.onSelect($(this), state);
});
}
}
});
$('html').mouseup(function () {
enabled = false;
});
});
};
$.fn.dragcheck.defaults = {
container: null,
onSelect: function (obj, state) { }
};
})(jQuery);