-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitAlarm - 副本.html
371 lines (322 loc) · 8.06 KB
/
TitAlarm - 副本.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
a:link,a:visited{color:#f00; text-decoration:underline}
fieldset{margin:20px 10px}
pre{border:1px solid #fc0;background:#ffd;padding:5px}
fieldset{margin:20px;padding:20px;text-align:left}
fieldset legend{padding:5px 10px;font-weight:700;font-size:16px}
table{color:#333;background:#E8F5FE;border-collapse:collapse;width:100%;text-align:left;}
thead{}
thead th{padding:1em 1em .5em;border:1px solid #5C9CC0;font-size:120%;background:#5C9CC0;text-align:left}
thead tr{}
td{padding:.5em 1em;border:1px solid #BBE1F1}
tbody td{background:#EEFAFF;}
tfoot{background-color:#A9C9E2;}
tfoot td{padding-bottom:1.5em;border:1px solid #BBE1F1}
dl{padding:10px 5px}
dl dt{font-weight:700;font-sie:14px;padding:5px 0;}
dl dt span{color:#f60;padding:0 8px}
pre{border:1px solid #ADCD3C;background-color:#F2FDDB;padding:5px;white-space: pre-wrap;
word-wrap: break-word;}
</style>
</head>
<body>
<a href="javascript:;" class="tit">111111</a>
<a href="javascript:;" class="tit">222222</a>
<a href="javascript:;" class="tit">333333</a>
<a href="javascript:;" class="tit">_(:3」∠)_</a>
<fieldset>
<legend>ASDUI.TitAlarm.Class(网页标题信息提示)</legend>
<dl>
<dt>调用方法:</dt>
<dd>
<pre>new ASDUI.TitAlarm(options);</pre>
</dd>
<dt>一个藏袍:</dt>
<dd>
<pre>
var st = new ASDUI.TitAlarm();
</pre>
</dd>
</dl>
<table>
<col id="middle" />
<col />
<col />
<thead>
<tr><th>Option</th>
<th>参数描述</th></tr>
</thead>
<tfoot>
</tfoot>
<tbody>
<tr>
<td>tim</td>
<td>闪动频率,默认值350</td>
</tr>
<tr>
<td>tit</td>
<td>提示的内容</td>
</tr>
<tr>
<td>delay</td>
<td>闪动提示时长,默认值3500</td>
</tr>
<tr>
<td>mess</td>
<td>全局标识,当前闪动的内容</td>
</tr>
<tr>
<td>title</td>
<td>原始标题</td>
</tr>
<tr><td>null</td>
<td>null</td>
</tr>
</tbody>
</table>
<dl>
<dt>外置方法:<span>.start(string);</span>开始提示</dt>
<dd>
<pre>
a = new ASDUI.TitAlarm();
a.start('[系统消息]');
</pre>
</dd>
</dl>
</fieldset>
<script type="text/javascript" src="js/jquery1.91.min.js"></script>
<script type="text/javascript">
var ZUI ={};
(function() {
$.Class = function(classDefinition)
{
classDefinition = classDefinition || {};
// create class structure
var newClass = function()
{
// reset class variables. Clone arrays and objects
reset(this);
// run constructor
return (this.initialize) ? this.initialize.apply(this, arguments) : this;
};
// store class definition
newClass.$definition = classDefinition;
// apply params to class
extend(newClass.prototype, classDefinition);
// parent function
newClass.prototype.parentMethod = function() {
if (arguments.callee.caller === this.$parent) {
throw 'This function has no parent.';
}
return this.$parent.apply(this, arguments);
};
return newClass;
};
var reset = function(object){
for (var key in object){
var value = object[key];
switch ($.type(value)) {
case 'object': object[key] = $.extend(true, {}, value); break;
case 'array': object[key] = $.extend(true, [], value); break;
}
}
return object;
};
var extend = function(target, object) {
var key, value;
for (key in object) {
if (object.hasOwnProperty(key) === false || object[key] === undefined ) {
continue;
}
if (key === 'Extends') {
// class overloading
$.each($.type(object.Extends) === 'array' ? object.Extends : [object.Extends], function() {
extend(target, this.$definition);
});
} else if ($.isFunction(target[key]) && $.isFunction(object[key])) {
// function overloading
target[key] = overload(object[key], target[key]);
} else {
// regular assigning
target[key] = object[key];
}
}
};
var overload = function(overloadFunction, parentFunction) {
return function() {
var oldParent = this.$parent;
this.$parent = parentFunction;
var result = overloadFunction.apply(this, arguments);
this.$parent = oldParent;
return result;
};
};
/**
* @param string
* @returns {XML|string|void}
* @private
*/
var removeOn = function(string){
return string.replace(/^on([A-Z])/, function(full, first){
return first.toLowerCase();
});
};
/**
* Class to send and receive events
*
* @class Events
*/
this.Events = new $.Class({
$events: {},
/**
* Add an event
*
* @param {String} type - the name of the event
* @param {Function} fn - the function to call
* @returns {*}
* @public
*/
on: function(type, fn){
type = removeOn(type);
var events = this.$events[type] || [];
if ($.inArray(events, fn) < 0) {
events.push(fn);
this.$events[type] = events;
}
return this;
},
/**
* Remove an event
* @param {String} type - the name of the event
* @param {Function} [fn] - optional the function to be removed. Otherwise all listeners
* @returns {*}
* @public
*/
off: function(type, fn){
type = removeOn(type);
var events = this.$events[type];
if (events){
if (fn == undefined) {
delete this.$events[type];
} else {
var index = events.indexOf(fn);
if (index != -1) delete events[index];
}
}
return this;
},
/**
* Fire an event
* @param {String} type the event name
* @param {Array} args an array of arguments to send to the event function
* @returns {*}
* @public
*/
trigger: function(type, args){
var events, i;
type = removeOn(type);
events = this.$events[type];
if (!events) return this;
args = $.isArray(args) ? args : [args];
for (i = 0; i < events.length; i++) {
if (events[i]) {
events[i].apply(this, args);
}
}
return this;
}
});
}());
ZUI.TitAlarm = new $.Class({
Extends: [Events],//继承Event
options:{
tim:350, //闪动频率
tit:'_(:3」∠)_', //提示的内容
circle:true,
delay:12, //闪动提示次数
mess:'', //全局标识当前闪动的内容
title:null, //原始标题
auto:false,
start:$.noop
},
initialize:function(options){
this.options = $.extend({},this.options, options);
this.title=this.options.title ? this.options.title : document.title;
this.times;
this.times2;
this.busy = false;
this.tit = this.getCircle(this.options.tit);
this.on('start', this.options.start);
this.options.auto && this.run();
},
getCircle: function(t){
if(this.options.circle){
var arr = t.split('');
var a =[];
for(i=0;i<arr.length;i++){
//console.log(arr.slice());
var newArr =[];
newArr = (1>0) ? arr.slice(i,arr.length).concat(arr.slice(0,i)) : arr.slice(i,arr.length);
a[i]=newArr.join('');
}
}else{
a = t;
}
return a;
},
run:function(){
var step=0,self = this;
$('body').everyTime(this.options.tim+'ms','TA',function(){
step++;
if(self.options.circle){
if(step==self.tit.length) step=0;
document.title = self.tit[step];
}else{
if (step==3) step=1;
if (step==1) document.title = self.title;
if (step==2) document.title = self.options.tit + self.title;
}
},this.options.delay);
this.busy = true;
$.fireEvent(this.options.onStart,[this]);
},
start:function(o){
if(!o)return false;
this.busy && $('body').stopTime ('TA');//防止重复
this.tit=this.getCircle(o);
this.run();
},
test:function(a){
console.log(a);
}
});
a = new ZUI.TitAlarm({start:function(){console.log(1)}});
a.trigger('start');
a.off('start');
//继承示例:
ZUI.Box2 = new $.Class({
Extends: [ZUI.TitAlarm],
options: {
tim:1000,
tit:'oooops!',
},
initialize:function(options){
this.test('ppppp');//调用父类
//this.parentMethod();
//console.log(this);
//this.parent('run');
}
});
new ZUI.Box2();
//a.start('[系统消息]');
$('a.tit').bind('click',function(){
a.start($(this).text())
});
</script>
</body>
</html>