-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.html
405 lines (374 loc) · 12.7 KB
/
edit.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Word Total Frequency</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery.tmpl.js"></script>
<script type="text/javascript" src="jplayer/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="./fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="./jquery.tag/jquery.tag.js"></script>
<link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<link rel="stylesheet" href="./jquery.tag/jquery.tag.css" />
<link href="jplayer/skin/jplayer.blue.monday.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<script>
var Playlist = function(instance, playlist, options) {
var self = this;
this.instance = instance; // String: To associate specific HTML with this playlist
this.playlist = playlist; // Array of Objects: The playlist
this.options = options; // Object: The jPlayer constructor options for this playlist
this.current = 0;
this.cssId = {
jPlayer: "jquery_jplayer_",
interface: "jp_interface_",
playlist: "jp_playlist_"
};
this.cssSelector = {};
$.each(this.cssId, function(entity, id) {
self.cssSelector[entity] = "#" + id + self.instance;
});
if(!this.options.cssSelectorAncestor) {
this.options.cssSelectorAncestor = this.cssSelector.interface;
}
$(this.cssSelector.jPlayer).jPlayer(this.options);
$(this.cssSelector.interface + " .jp-previous").click(function() {
self.playlistPrev();
$(this).blur();
return false;
});
$(this.cssSelector.interface + " .jp-next").click(function() {
self.playlistNext();
$(this).blur();
return false;
});
};
Playlist.prototype = {
displayPlaylist: function() {
var self = this;
$(this.cssSelector.playlist + " ul").empty();
for (i=0; i < this.playlist.length; i++) {
var listItem = (i === this.playlist.length-1) ? "<li class='jp-playlist-last' " : "<li ";
listItem += "file='" + this.playlist[i].mp3+"'>";
listItem += "<a href='#' id='" + this.cssId.playlist + this.instance + "_item_" + i +"' tabindex='1'>" + this.playlist[i].name
if (this.playlist.length > 1)
listItem += "<img class='img-delete-sound' src='jplayer/delete.png' title='删除这个发音' onclick='return removeSound(this);'/>"
listItem += "</a>";
// Create links to free media
if(this.playlist[i].free) {
var first = true;
listItem += "<div class='jp-free-media'>(";
$.each(this.playlist[i], function(property,value) {
if($.jPlayer.prototype.format[property]) { // Check property is a media format.
if(first) {
first = false;
} else {
listItem += " | ";
}
listItem += "<a id='" + self.cssId.playlist + self.instance + "_item_" + i + "_" + property + "' href='" + value + "' tabindex='1'>" + property + "</a>";
}
});
listItem += ")</span>";
}
listItem += "</li>";
// Associate playlist items with their media
$(this.cssSelector.playlist + " ul").append(listItem);
$(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() {
var index = $(this).data("index");
if(self.current !== index) {
self.playlistChange(index);
} else {
$(self.cssSelector.jPlayer).jPlayer("play");
}
$(this).blur();
return false;
});
// Disable free media links to force access via right click
if(this.playlist[i].free) {
$.each(this.playlist[i], function(property,value) {
if($.jPlayer.prototype.format[property]) { // Check property is a media format.
$(self.cssSelector.playlist + "_item_" + i + "_" + property).data("index", i).click(function() {
var index = $(this).data("index");
$(self.cssSelector.playlist + "_item_" + index).click();
$(this).blur();
return false;
});
}
});
}
}
},
playlistInit: function(autoplay) {
if(autoplay) {
this.playlistChange(this.current);
} else {
this.playlistConfig(this.current);
}
},
playlistConfig: function(index) {
$(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current");
$(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current");
this.current = index;
$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
},
playlistChange: function(index) {
this.playlistConfig(index);
$(this.cssSelector.jPlayer).jPlayer("play");
},
playlistNext: function() {
var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
this.playlistChange(index);
},
playlistPrev: function() {
var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
this.playlistChange(index);
}
};
function removeSound(elm){
var tr = $(elm).parents('tr');
var ul = $(elm).parents('ul');
var li = $(elm).parents('li');
var b = confirm("你确认要删除发音\"" + li.text() + "\"吗?");
if (b){
li.remove();
var files = [];
$.each(ul.find('li'), function(idx, el){
files.push($(el).attr('file'));
});
$('.soundFile', tr).val(files.join(' '));
}
return false;
}
function gup(name)
{
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null )
return "";
else
return results[1];
}
function batchSave(){
$('tr[dirty] .btn-save').click();
}
$(window).unload(function(){
batchSave();
});
$(document).ready(function(){
// automatic save every 3 secs
setInterval(batchSave, 3000);
var page = gup('page') || 1;
$.getJSON('get.php?page='+page, function(json){
$('#wordTemplate').tmpl(json.rows).appendTo('#wordTable');
$('tr:even', '#wordTable').css('background-color', '#eee')
$('.btn-json').fancybox({scrolling:'no'});
$('.tags').tag();
$.each($('#wordTable tr'), function(idx, tr){
var id = $('.id', tr).val();
var files = $('.soundFile', tr).val().split(' ');
var mp3s = [];
$.each(files, function(idx, file){
var parts = file.split('/');
var name = parts[parts.length-1];
mp3s.push({
name:name,
mp3:file
});
});
var audioPlaylist = new Playlist(id, mp3s, {
ready: function() {
audioPlaylist.displayPlaylist();
audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
},
ended: function() {
//audioPlaylist.playlistNext();
},
play: function() {
$(this).jPlayer("pauseOthers");
},
swfPath: "jplayer",
supplied: "mp3"
});
});
});
$('#previous-page').click(function(){
var page = parseInt(gup('page') || 1);
if (page > 1){
--page;
var url = location.href;
if (url.indexOf('?') > -1)
url = url.substr(0, url.indexOf('?'));
location.href = url + '?page=' + page;
}
});
$('#next-page').click(function(){
var page = parseInt(gup('page') || 1);
if (page){
++page;
var url = location.href;
if (url.indexOf('?') > -1)
url = url.substr(0, url.indexOf('?'));
location.href = url + '?page=' + page;
}
});
/*
$('#wordTable').delegate('.btn-json', 'click', function(){
var tr = $(this).parents('tr');
alert($('.json', tr).val());
});
*/
$('#wordTable').delegate('.btn-save', 'click', function(){
var tr = $(this).parents('tr');
var data = {};
data['action'] = 'update';
data['id'] = $('.id', tr).val();
data['spell'] = $('.spell', tr).val();
data['prototype'] = $('.prototype', tr).val();
data['phonetic'] = $('.phonetic', tr).val();
data['frequency'] = $('.frequency', tr).val();
data['tags'] = $('.tags', tr).val();
data['category'] = $('.category', tr).val();
data['soundFile'] = $('.soundFile', tr).val();
data['translate'] = $('.translate', tr).val();
data['detail'] = $('.detail', tr).html().replace(/<br>/g, '\n');
$.ajax({
type:'POST',
url:'saveword.php',
data: data,
dataType: 'json',
contentType:'application/x-www-form-urlencoded;charset=utf-8',
timeout: 1000,
success: function(msg){
tr.removeAttr('dirty');
console.log('data saved for "' + msg.word + '"');
},
error: function(msg){
console.log('[ERROR]: saving for "' + msg.word + '"');
}
});
});
$('#wordTable').delegate('.btn-delete', 'click', function(){
var tr = $(this).parents('tr');
var b = confirm("你确认要删除单词\"" + $('.spell', tr).val() + "\"吗?");
if (b){
var data = {};
data['action'] = 'delete';
data['id'] = $('.id', tr).val();
$.ajax({
type:'POST',
url:'saveword.php',
data: data,
dataType: 'json',
contentType:'application/x-www-form-urlencoded;charset=utf-8',
timeout: 1000,
success: function(msg){
location.reload();
}
});
}
});
$('#wordTable').delegate('.tags-container > a', 'click', function(){
var tr = $(this).parents('tr');
var tag = $(this).text().toLowerCase().replace('-', '');
var elm = $('.tags', tr);
if (elm.val().indexOf(tag) == -1){
$('.taglist', tr).remove();
elm.val(elm.val()+','+tag);
elm.tag();
$('.tags', tr).change();
}
return false;
});
/*************************
** trigger value change **
*************************/
$('#wordTable').delegate('input', 'change', function(){
var tr = $(this).parents('tr');
tr.attr('dirty', true);
});
$('#wordTable').delegate('.detail', 'keydown', function(){
var tr = $(this).parents('tr');
tr.attr('dirty', true);
});
});
</script>
<style>
</style>
<body>
<script id="wordTemplate" type="text/x-jquery-tmpl">
<tr>
<td valign="top">
<input type="hidden" class="id" value="${id}"/>
<input type="text" class="spell" value="${spell}"/>
<br/><span class="label">原型:</span><input type="text" class="prototype" value="${prototype}"/>
<br/><span class="label">参看:</span><input type="text" class="reference" value="${reference}"/>
<br/><span class="label">音标:</span><input type="text" class="phonetic" value="${phonetic}"/>
<br/><span class="label">出现频率:</span><input type="text" class="frequency" value="${frequency}"/>
<br/><span class="label">单词集(0-4):</span><input type="text" class="category" value="${category}"/>
<br/><input type="hidden" class="soundFile" value="${soundFile}"/>
<div style="display:none">
<textarea id="json-${id}" style="width:800px;height:600px;font-size:12px;">
${json}
</textarea>
</div>
</td>
<td valign="top">
标签:
<span class="tags-container">
<a href="#">CET-4</a>
<a href="#">CET-6</a>
<a href="#">TOEFL</a>
<a href="#">IELTS</a>
<a href="#">GRE</a>
</span>
<br/><input type="text" class="tags" value="${tags}" data-seperator=","/>
<div id="jquery_jplayer_${id}" class="jp-jplayer"></div>
<div class="jp-audio">
<div class="jp-type-playlist">
<div id="jp_interface_${id}" class="jp-interface">
<ul class="jp-controls">
<li><a href="#" class="jp-play" tabindex="1">play</a></li>
<li><a href="#" class="jp-pause" tabindex="1">pause</a></li>
<li><a href="#" class="jp-stop" tabindex="1">stop</a></li>
<li><a href="#" class="jp-mute" tabindex="1">mute</a></li>
<li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li>
<li><a href="#" class="jp-previous" tabindex="1">previous</a></li>
<li><a href="#" class="jp-next" tabindex="1">next</a></li>
</ul>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
</div>
<div id="jp_playlist_${id}" class="jp-playlist">
<ul>
<!-- The method Playlist.displayPlaylist() uses this unordered list -->
<li></li>
</ul>
</div>
</div>
</div>
</td>
<td>
<input type="text" class="translate" value="${translate}"/>
<br/><div class="detail" contenteditable="true">${detail}</div>
</td>
<td valign="top">
<button class="btn-json" href="#json-${id}">JSON</button>
<br/><br/><button class="btn-save">SAVE</button>
<br/><br/><button class="btn-delete">DELETE</button>
</td>
</tr>
</script>
<table id="wordTable"></table>
<div id="navigator">
<button id="previous-page">Previous Page</button>
<br/><br/>
<button id="next-page">Next Page</button>
</div>
</body>
</html>