-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble Tabbing
More file actions
69 lines (67 loc) · 2.94 KB
/
Copy pathBubble Tabbing
File metadata and controls
69 lines (67 loc) · 2.94 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
66
67
68
69
// Activate the bubble editor on click of a table cell
$('#example').on( 'click', 'tbody td', function (e) {
editor.bubble(this, { submitOnBlur: true });
} );
editor.on("open", function (ev,type) {
var current = $($("#example").DataTable().rows(editor.ids()).cell(editor.modifier()).node());
if (type === "bubble" || type=== "inline") {
$(document).on('keydown.editor', function (e) {
var kc = e.keyCode;
console.log(kc)
if (kc === 9 || kc === 37 || kc === 38 || kc === 39 || kc === 40) {
e.preventDefault();
current.removeClass("focus");
}
// for tabbing and shift tabbing.
if (kc === 9) {
if (e.shiftKey && current.prevAll("td.editable").length) {
// One cell to the left (skipping the first column)
current.prevAll("td.editable").first().focus().click().addClass("focus");
console.log("prev cell");
}
else if (e.shiftKey) {
// Up to the previous row
current.parent().prev().children(".editable").last(0).focus().click().addClass("focus");
console.log("prev row")
}
else if (current.nextAll("td.editable").length) {
current.nextAll("td.editable").first().focus().click().addClass("focus");
console.log("next cell")
}
else if (current.parent().next().length) {
current.parent().next().children(".editable").first(0).focus().click().addClass("focus");
}
}
//left arrow
else if (kc === 37) {
if (current.prevAll("td.editable").length) {
current.prevAll("td.editable").first().focus().click().addClass("focus");
}
else {
current.parent().prev().children("td.editable").last(0).focus().click().addClass("focus");
}
}
// Up Arrow
else if (kc === 38) {
var ci = current.index();
current.parent().prev().children().eq(ci).focus().click().addClass("focus");
}
// right arrow
else if (kc === 39) {
if (current.nextAll("td.editable").length) {
current.nextAll("td.editable").first().focus().click().addClass("focus");
}
else {
current.parent().next().children("td.editable").eq(0).focus().click().addClass("focus");
}
}
// down arrow
else if (kc === 40) {
var ci = current.index();
current.parent().next().children().eq(ci).focus().click().addClass("focus");
}
});
}
}).on('close', function () {
$(document).off('keydown.editor');
});