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