-
Notifications
You must be signed in to change notification settings - Fork 54
/
twinput1.0.0.js
61 lines (61 loc) · 1.46 KB
/
twinput1.0.0.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
(function($){
var isIE;
$.fn.tw_input_placeholder = function(option){
isIE = (navigator.appName == 'Microsoft Internet Explorer');
var opt = $.extend({
speed: 100,
delay: 1000,
keywords: ['keywords'],
}, (option||{}));
if(typeof opt.keywords=='string'){
opt.keywords = [opt.keywords];
}
return this.each(function(){
var input = $(this);
var input_element = input.get(0);
var keywordsx, inputx, keywords;
//var input = input;
function st(){
keywordsx = inputx = 0;
keywords = opt.keywords[keywordsx];
input.show();
tw();
}
input.focus(function(){
if(!isIE){
$(input).attr("placeholder",'');
}else{
input.val("")
}
var ti = $.data(input_element, 'tw_input');
if(ti){
clearTimeout(ti);
$.data(input_element, 'tw_input', false);
}else{
$(this).select();
}
});
input.blur(function(){
if(input.val()==''){st();}
});
function tw(){
if(!isIE){
$(input).attr("placeholder",keywords.substring(0, inputx++)+'|');
}else{
input.val(keywords.substring(0, inputx++)+'|');
}
if(inputx > keywords.length){
$.data(input_element, 'tw_input', setTimeout(function(){
if(++keywordsx >= opt.keywords.length){keywordsx=0;}
keywords = opt.keywords[keywordsx];
inputx = 0;
tw();
}, opt.delay));
}else{
$.data(input_element, 'tw_input', setTimeout(tw, opt.speed));
}
}
if(!input.val()){st();}
});
}
})(jQuery);