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