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