-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
158 lines (142 loc) · 4.51 KB
/
demo.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
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>suggestion组件</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
input{
display: block;
width: 300px;
height: 25px;
line-height: 25px;
margin-left: 10px;
}
#baiduSuggestion{
position: absolute;
background-color: white;
border: 1px solid #999;
max-height: 100px;
overflow: auto;
}
</style>
百度搜索:<input id="baiduSearch" />
本地存储:<input id="localSearch" />
静态文件:<input readonly id="staticSearch" />
<div id="baiduSuggestion"></div>
<div id="localSuggestion"></div>
<div id="staticSuggestion"></div>
<button id="taobaoSearch">淘宝搜索</button>
<button id="fileSearch">本地接口搜索</button>
<script type="text/javascript" src="../../lib/lib.js"></script>
<script type="text/javascript" src="../../lib/jquery.js"></script>
<script type="text/javascript" src="../../lib/underscore.js"></script>
<script type="text/javascript" src="suggestion.js"></script>
<script>
var suggestion = lib.extend.useComponent("Suggestion", {
getData: function(value){
lib.send.jsonp("http://sug.music.baidu.com/info/suggestion?format=json&word="+value,{
callback: function(data){
console.log(data);
suggestion.returnData(data.song);
}
});
},
formatData: function(item){
var template = _.template("<%- songname %>");
var content = template(item);
return content;
},
currentInput: lib.g("baiduSearch"),
render: "baiduSuggestion"
});
suggestion.addListener("selected",function(text){
alert(text)
});
suggestion.addListener("submit",function(value,obj){
console.log(value);
console.log(obj);
console.log(obj[0])
});
lib.on("baiduSearch","click",function(){
suggestion.setCurrentInput(this);
});
lib.on("localSearch","click",function(){
suggestion.setCurrentInput(this);
});
lib.on("taobaoSearch","click",function(){
suggestion.setGetData({
url:"http://suggest.taobao.com/sug?extras=1&code=utf-8",
key:"q",
filter:function(data){
return data.result;
}
});
});
lib.on("fileSearch","click",function(){
suggestion.setGetData(function(value){
setTimeout(function(){
suggestion.returnData([
{name:"我的电脑"},
{name:"回收站"}
]);
},3000);
});
});
/*
var staticSuggestion = lib.extend.useComponent("Suggestion", {
getData: function(value){
this.returnData([{
title: "爱的创可贴",
url: "http://www.baidu.com",
type: "电视剧",
info: "治愈系爱情偶像剧治愈系爱情偶像剧治愈系爱情偶像剧治愈系爱情偶像剧",
img: "http://c.hiphotos.baidu.com/video/pic/item/dc54564e9258d109d5e8a2f1d058ccbf6c814d6d.jpg"
},{
title: "百变大咖秀",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "百变大咖秀",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "仁心解码2",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "神探高伦布",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "喜剧电影",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "动作电影",
url: "http://www.baidu.com",
type: "电视剧"
},{
title: "云上的诱惑",
url: "http://www.baidu.com",
type: "电视剧"
}]);
},
formatData: function(item){
var template = _.template("<%- title %>[<%- type %>]");
var content = template(item);
return content;
},
currentInput: lib.g("staticSearch"),
autocomplete: true
});
staticSuggestion.addListener("selected",function(text){
alert(text)
});
staticSuggestion.render("staticSuggestion");
lib.on("staticSearch","click",function(){
staticSuggestion.isOwner = true;
staticSuggestion.getData();
});
*/
</script>