-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.js
81 lines (78 loc) · 2.17 KB
/
tools.js
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
let tools = {}
tools.formatNumber = function(n){
n += "";
var re = /(\d{1,3})(?=(\d{3})+$)/g;
return n.replace(re,"$1,");
}
tools.inputKeyup = function(){
for(let i=0;i<document.getElementsByClassName('dream-total').length;i++){
document.getElementsByClassName('dream-total')[i].addEventListener('keyup',function(e){
let theValue = e.target.value
document.getElementsByClassName('dream-total')[i].value = tools.formatNumber(theValue)
})
}
}
tools.delComma = function(data){
if(data) {
data = data.replace(/[,]/g, '');
return data;
}
}
tools.setAttributes = function(obj,attributes){
for(let name in attributes){
obj[name]=attributes[name];
}
return obj;
}
tools.setStyles = function(obj,styles){
for(let name in styles){
obj.style[name]=styles[name];
}
return obj;
}
tools.createElement = function(tagName,settings,parentElement){
let obj=document.createElement(tagName);
if(settings.atrs){tools.setAttributes(obj,settings.atrs);}
if(settings.stys){tools.setStyles(obj,settings.stys);}
//if(parentElement instanceof Element){parentElement.appendChild(obj);} => Element 無法被測試辨認
parentElement.appendChild(obj)
return obj;
}
tools.getPosition = function(element){
let elementBox = element.getBoundingClientRect()
let elementPosition = {}
let elementLeft = elementBox.left
let elementTop = elementBox.top
let scrollDistance = document.documentElement.scrollTop || document.body.scrollTop;
let topBorder = elementTop+scrollDistance
elementPosition.x=elementLeft
elementPosition.y=topBorder
return elementPosition
}
let observeRobot
let spaceTalk
let step0
let step1
let step1_1
let step1_2
let step2_0
let step3_0
let step3_1
let step3_2
let step3_3
let step3_4
let oneWordByOneWord
tools.clearTimeOuts = function(){
clearTimeout(oneWordByOneWord)
clearTimeout(step0)
clearTimeout(step1)
clearTimeout(step1_1)
clearTimeout(step1_2)
clearTimeout(step2_0)
clearTimeout(step3_0)
clearTimeout(step3_1)
clearTimeout(step3_2)
clearTimeout(step3_3)
clearTimeout(observeRobot)
clearTimeout(spaceTalk)
}