1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {isNumber} from 'tinper-sparrow/src/util';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const setRowFocus = function (index, quiet, force) {
|
15 | var rowId = null
|
16 | if (index instanceof Row) {
|
17 | index = this.getIndexByRowId(index.rowId)
|
18 | rowId = index.rowId
|
19 | }
|
20 | if (index === -1 || (index === this.focusIndex() && !force)) {
|
21 | return;
|
22 | }
|
23 | this.focusIndex(index)
|
24 | if (quiet) {
|
25 | return;
|
26 | }
|
27 | this.currentRowChange(-this.currentRowChange())
|
28 | if (!rowId) {
|
29 | rowId = this.getRow(index).rowId
|
30 | }
|
31 | this.trigger(DataTable.ON_ROW_FOCUS, {
|
32 | index: index,
|
33 | rowId: rowId
|
34 | })
|
35 | this.updateCurrIndex();
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const setRowUnFocus = function () {
|
43 | this.currentRowChange(-this.currentRowChange())
|
44 | var indx = this.focusIndex(), rowId = null;
|
45 | if (indx !== -1) {
|
46 | rowId = this.getRow(indx).rowId
|
47 | }
|
48 | this.trigger(DataTable.ON_ROW_UNFOCUS, {
|
49 | index: indx,
|
50 | rowId: rowId
|
51 | })
|
52 | this.focusIndex(-1)
|
53 | this.updateCurrIndex();
|
54 | }
|
55 |
|
56 |
|
57 | const updateFocusIndex = function (opIndex, opType, num) {
|
58 | if (!isNumber(num)) {
|
59 | num = 1
|
60 | }
|
61 | if (opIndex <= this.focusIndex() && this.focusIndex() != -1) {
|
62 | if (opType === '+') {
|
63 | this.focusIndex(this.focusIndex() + num)
|
64 | } else if (opType === '-') {
|
65 | if (this.focusIndex() >= opIndex && this.focusIndex() <= opIndex + num - 1) {
|
66 | this.focusIndex(this.focusIndex() - 1)
|
67 | } else if (this.focusIndex() > opIndex + num - 1) {
|
68 | this.focusIndex(this.focusIndex() - num)
|
69 | }
|
70 | }
|
71 | }
|
72 | }
|
73 |
|
74 | export {
|
75 | setRowFocus,
|
76 | setRowUnFocus,
|
77 | updateFocusIndex
|
78 | }
|