-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-4-highlight.html
143 lines (139 loc) · 4.57 KB
/
example-4-highlight.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!doctype html>
<html>
<style>
.tk_word {
font-family: Verdana;
color: #333;
font-size: 12px;
}
.tk_inline_comment, .tk_block_comment, .tk_comment {
color: #007400
}
.tk_string, .tk_regexp {
color: #c41a16
}
.tk_keywords {
color: #069;
font-weight: bold;
}
.tk_jskeywords {
color: #1951d5;
}
</style>
<script src="myFormat_v1.0.js" ></script>
<textarea id="text" style="width:90%; height:300px; border:1px solid #999" >
if (a && (c < d))
var Hongru = {
get : function (id) {return document.getElementById(id)},
tween : {
linear : function (f, t, d) { return t * d + f; },
ease : function (f, t, d) { return -t * .5 * (Math.cos(Math.PI * d) - 1) + f; }
},
tweens: [],
tweensCnt: 0,
anim : function (obj, params) {
var self = this,
objList = [],
objReturn = [];
var animimg = function () {
var i = -1, o;
while( o = self.tweens[++i] ) {
var cTime = (new Date()).getTime() - o.start;
if (cTime < o.duration) {
for (var k in o.val) {
var m = o.val[k];
o.obj[k] = Math.ceil(o.ease(m.from, m.diff, cTime/o.duration)) + (o.cssMode ? 'px' : 0);
}
} else {
cTime = o.duration;
for (var k in o.val) {
var m = o.val[k];
o.obj[k] = Math.ceil(o.ease(m.from, m.diff, cTime/o.duration)) + (o.cssMode ? 'px' : 0);
}
self.tweens.splice(i, 1);
self.tweensCnt--;
if (o.onFinish) o.onFinish (o.params);
self.stop();
}
if (!o.cssMode) o.obj.onTween();
}
};
if (typeof obj == "string" || !obj.length) objList.push(obj); else objList = obj;
for (var il = 0, l = objList.length; il < l; il++) {
var obj = this.get(objList[il]) || objList[il];
var o = {};
o.val = {};
o.cssMode = true;
o.o = obj;
o.obj = obj.style;
for (var k in params) {
var p = params[k];
if (k === "cssMode") {
if (p === false) {
o.cssMode = false;
o.obj = obj;
}
} else if (k === "onTween") {
o.obj.onTween = p;
} else if (k === "from") {
for (var i in p) o.obj[i] = o.cssMode ? (Math.ceil(p[i]) + 'px') : p[i];
} else if (k === "to") {
for (var i in p) {
var from = o.cssMode ? (parseInt(o.obj[i]) || 0) : (o.obj[i] || 0);
o.val[i] = {
from: from,
diff: p[i] - from
};
}
} else o[k] = params[k];
}
if (!o.ease) o.ease = this.tween.ease;
if (!o.cssMode && params['from']) o.obj.onTween();
o.duration = params.duration ? params.duration : 1000;
o.start = (new Date()).getTime();
this.tweens.push(o);
this.tweensCnt++;
if (!this.running) this.running = window.setInterval(animimg, 10);
objReturn.push(o);
}
return objReturn.length === 1 ? o : objReturn;
},
stop : function () {
if (!this.tweensCnt) {
window.clearInterval(this.running);
this.running = false;
}
},
kill : function (obj) {
if (obj) {
for (var i = 0; i < this.tweensCnt; i++) {
if (this.tweens[i] === obj || this.tweens[i].o === obj || this.tweens[i].o === this.get(obj)) {
this.tweensCnt--;
this.tweens.splice(i, 1);
this.stop();
}
}
}
},
reset : function () {
this.tweensCnt = 0;
this.stop();
while( this.tweens.length ) {
this.tweens.stop();
}
}
}</textarea>
<input type="button" value="format" onclick="myFormat()" />
<pre id="output"></pre>
<script>
function myFormat () {
var v = document.getElementById('text').value;
var ret = new jsFormat(v).toHtml;
var output = document.getElementById('output');
if (output.outerHTML) {
output.outerHTML = '<pre>'+ret+'</pre>';
} else
document.getElementById('output').innerHTML = ret;
}
</script>
</html>