-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (111 loc) · 3.46 KB
/
index.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
<html>
<head>
<title>aniyo search</title>
<script type="text/javascript" src="http://s.hatena.ne.jp/js/HatenaStar.js"></script>
<script type="text/javascript">
if ( typeof(AniyoSearch) == 'undefined' ) { AniyoSearch = {}; }
AniyoSearch.IncrementSearcher = new Ten.Class({
initialize: function(opt) {
this.jsonURL = opt.jsonURL;
this.allSongs = [];
this.currentSongs = [];
this.changing = false;
this.showAllTimer = undefined;
this.elems = {
keyword: new Ten.Selector.getElementsBySelector('#keyword')[0],
songsList: new Ten.Selector.getElementsBySelector('#songs_list')[0]
};
this.loadSongs();
this.startUpdation();
this.startListeningKeys();
}
}, {
loadSongs: function() {
new Ten.JSONP(this.jsonURL, this, 'onCompleteLoadingSongs');
},
onCompleteLoadingSongs: function(data) {
this.allSongs = this.currentSongs = data.songs;
this.updateSongsList();
},
startUpdation: function() {
// 定期的に表示を更新する
var self = this;
setInterval(function (){
if (!self.changing) { return; }
self.updateSongsList({limit: 15}); // とりあえず10件だけ表示する
// しばらく(1秒)入力がなければ
self.showAllTimer = setTimeout( function() {
self.updateSongsList(); //全件表示
}, 600);
self.changing = false;
}, 300);
},
updateSongsList: function(opt) {
var limit;
if ( opt == undefined || opt.limit == undefined || opt.limit > this.currentSongs.length) {
limit = this.currentSongs.length;
}
else {
limit = opt.limit;
}
// 表示を更新する
Ten.DOM.removeAllChildren(this.elems.songsList);
if (this.currentSongs.length == 0) {
this.currentSongs = this.allSongs;
}
for ( var i = 0; i < limit; i++) {
var song = this.currentSongs[i];
this.elems.songsList.appendChild(new Ten.Element('li', {
innerHTML: song
}));
}
},
startListeningKeys: function() {
new Ten.Observer(this.elems.keyword, 'onkeyup', this, 'onInputFormKeyUp' );
},
onInputFormKeyUp: function() {
if (this.showAllTimer != undefined) { // 全件表示をキャンセル
clearTimeout(this.showAllTimer);
}
if (this.changing) { return; } // 表示の更新中なら何もしない
// マッチするエントリをとりだす
var newSongs = [];
for ( var i = 0; i < this.allSongs.length; i++) {
var song = this.allSongs[i];
if (song.match(this.elems.keyword.value, 'i')) {
newSongs.push(song);
}
}
this.currentSongs = newSongs;
this.changing = true;
}
});
Ten.DOM.addEventListener('DOMContentLoaded', function () {
new AniyoSearch.IncrementSearcher({
jsonURL: '/aniyosearch/songs.json'
});
});
</script>
<style type="text/css">
h1 {
font-size: 1.5em;
color: #666;
}
#search {
background-color: #aaf;
padding: 0.5em;
}
#songs_list li {
list-style: none;
}
</style>
</head>
<body>
<h1>アニソン歌う子検索 (for Hyperjoy)</h1>
<form id="search">
<label for"keyword"></label><input type="text" name="keyword" id="keyword" />
</form>
<ul id="songs_list">
</ul>
</body>
</html>