forked from nswish/jQuery.AutoComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
173 lines (151 loc) · 5.98 KB
/
test.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
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
var alltest = {};
alltest.testWidth = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'width': 300
});
};
alltest.testItemHeight = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'itemHeight': 50
});
};
alltest.testArrayAsData = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve']
});
};
alltest.testFunctionAsData = function(input){
$(input).AutoComplete({
'data': function(){
return ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'];
}
});
};
alltest.testAjaxJsonAsData = function(input){
$(input).AutoComplete({
'data': "../test/data.json",
'ajaxDataType': 'json',
'onerror': function(msg){alert(msg);}
});
};
alltest.testAjaxXmlAsData = function(input){
$(input).AutoComplete({
'data': "../test/data.xml",
'ajaxDataType': 'xml',
'onerror': function(msg){alert(msg);}
});
};
alltest.testMaxHeight = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'maxHeight': 100
});
}
alltest.testMaxItems = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'maxItems': 3
});
}
alltest.testUpDirection = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'listDirection': 'up'
});
}
alltest.testDownDirection = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'listDirection': 'down'
});
}
alltest.testListStyleNormal = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'listStyle': 'normal'
});
}
alltest.testIconList = function(input){
var world = ['Cambodia', 'Cameroon', 'Canada', 'Cape-Verde', 'Cayman-Islands', 'Central-African-Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Commonwealth', 'Comoros', 'Costa-Rica', "Cote-d'Ivoire", 'Croatia', 'Cuba', 'Cyprus', 'Czech-Republic'],
result = [];
$.each(world, function(index, name){
new Image().src = '../demo/image/worldFlag/' + name + '.png'; // 预加载图片
result.push({
'value': name,
'label': name,
'image': '../demo/image/worldFlag/' + name + '.png'
});
});
$(input).AutoComplete({
'data': result,
'listStyle': 'iconList',
'itemHeight': 24,
'width': 280,
'onerror': function(msg){alert(msg);}
});
}
alltest.testIconListUp = function(input){
var world = ['Cambodia', 'Cameroon', 'Canada', 'Cape-Verde', 'Cayman-Islands', 'Central-African-Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Commonwealth', 'Comoros', 'Costa-Rica', "Cote-d'Ivoire", 'Croatia', 'Cuba', 'Cyprus', 'Czech-Republic'],
result = [];
$.each(world, function(index, name){
new Image().src = '../demo/image/worldFlag/' + name + '.png'; // 预加载图片
result.push({
'value': name,
'label': name,
'image': '../demo/image/worldFlag/' + name + '.png'
});
});
$(input).AutoComplete({
'data': result,
'listStyle': 'iconList',
'listDirection': 'up',
'emphasis': false,
'itemHeight': 24,
'maxHeight': 240,
'onerror': function(msg){alert(msg);}
});
}
alltest.testListStyleCustom = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'listStyle': 'custom',
'emphasis': false,
'createItemHandler': function(index, data){
return "<span style='color:green;'>--"+data.label+"--</span>"; // 文本显示为绿色,并在前后使用'--'包裹
},
'onerror': function(msg){alert(msg);}
});
}
alltest.testOtherHandlersExistAfterDestroy = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve']
}).bind('keyup', function(){
$(this).after('exist');
}).AutoComplete('destroy');
};
alltest.testMatchHandler = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'matchHandler': function(keyword, data){
return data.value.indexOf(keyword) == 0; // 匹配规则: 以输入框中的值开头且大小写敏感
}
});
};
alltest.testEmphasisHandler = function(input){
$(input).AutoComplete({
'data': ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'],
'emphasisHandler': function(keyword, data){
var regex = RegExp("("+keyword.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1")+")", 'ig');
data.label = data.label.replace(regex, "<span style='font-weight:bold;color:blue;'>$1</span>");
}
});
}
alltest.testAsyncTrue = function(input){
$(input).AutoComplete({
'data': "../test/data.json",
'async': true,
'onerror': function(msg){alert(msg);}
});
}