-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb-matrix.js
More file actions
94 lines (75 loc) · 2.69 KB
/
b-matrix.js
File metadata and controls
94 lines (75 loc) · 2.69 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(function () {
var app = angular.module('appMatrix', []);
var digMap = {
square : [
[{}, {}, {}, {}],
[{}, {}, {}, {}],
[{}, {}, {}, {}],
[{}, {}, {}, {}]
],
currentRow : 0,
currentCol : 0,
mouseOut : true
}
app.controller('MatrixController', function ($timeout) {
this.digMap = digMap;
this.offsetLeft = 0;
this.offsetTop = 0;
this.timer = 0;
this.addCol = function () {
this.digMap.square.map(function (row) {
return row.push({});
});
}
this.addRow = function () {
this.digMap.square.push(this.digMap.square[0].slice(0));
}
this.delCol = function () {
this.digMap.square.map(function (row) {
return row.splice(digMap.currentCol, 1);
});
if (this.digMap.currentCol === this.digMap.square[0].length) {
tBody = document.getElementsByClassName("b-matrix__table")[0].children[0];
this.overTable({ target: tBody.children[0].children[this.digMap.currentCol - 1] });
}
}
this.delRow = function () {
this.digMap.square.splice(this.digMap.currentRow, 1);
if (this.digMap.currentRow === this.digMap.square.length) {
tBody = document.getElementsByClassName("b-matrix__table")[0].children[0];
this.overTable({ target: tBody.children[this.digMap.currentRow -1].children[0] });
}
}
this.isShowDelCol = function () {
return this.digMap.square[0].length > 1 && !this.digMap.mouseOut;
}
this.isShowDelRow = function () {
return this.digMap.square.length > 1 && !this.digMap.mouseOut;
}
this.overTable = function (event) {
this.digMap.currentRow = event.target.parentElement.rowIndex;
this.digMap.currentCol = event.target.cellIndex;
this.offsetTop = event.target.offsetTop;
this.offsetLeft = event.target.offsetLeft;
this.digMap.mouseOut = false;
}
this.mStyleCol = function () {
return {
left: this.offsetLeft + 'px'
};
}
this.mStyleRow = function () {
return {
top: this.offsetTop + 'px'
};
}
this.leaveDiv = function () {
this.timer = $timeout(function () {
digMap.mouseOut = true;
}, 500);
}
this.overDiv = function () {
$timeout.cancel(this.timer);
}
});
})();