316 lines
9.5 KiB
JavaScript
316 lines
9.5 KiB
JavaScript
var upload1_count = 0;
|
|
var upload2_count = 0;
|
|
var upload1, upload2;
|
|
window.onload = function() {
|
|
upload1 = new SWFUpload({
|
|
// Backend Settings
|
|
upload_url: "/service/upload",
|
|
post_params: param.image,
|
|
|
|
// File Upload Settings
|
|
file_size_limit : "2048", // 2MB
|
|
file_types : "*.jpg;*.gif;*.png",
|
|
file_types_description : "Image Files",
|
|
file_upload_limit : "5",
|
|
file_queue_limit : "5",
|
|
|
|
// Event Handler Settings (all my handlers are in the Handler.js file)
|
|
file_dialog_start_handler : fileDialogStart,
|
|
file_queued_handler : fileQueued,
|
|
file_queue_error_handler : fileQueueError,
|
|
file_dialog_complete_handler : fileDialogComplete,
|
|
upload_start_handler : uploadStart,
|
|
upload_progress_handler : uploadProgress,
|
|
upload_error_handler : uploadError,
|
|
upload_success_handler : uploadSuccess,
|
|
upload_complete_handler : uploadComplete,
|
|
|
|
// Button Settings
|
|
button_image_url : "/static/img/uploadbtn.gif",
|
|
button_placeholder_id : "spanButtonPlaceholder1",
|
|
button_width: 82,
|
|
button_height: 38,
|
|
|
|
// Flash Settings
|
|
flash_url : "/static/lib/swfupload/swfupload.swf",
|
|
|
|
custom_settings : {
|
|
progressTarget : "fsUploadProgress1",
|
|
cancelButtonId : "btnCancel1"
|
|
},
|
|
|
|
// Debug Settings
|
|
debug: false
|
|
});
|
|
|
|
upload2 = new SWFUpload({
|
|
// Backend Settings
|
|
upload_url: "/service/upload",
|
|
post_params: param.voice,
|
|
|
|
// File Upload Settings
|
|
file_size_limit : "20480", // 20mb
|
|
file_types : "*.mp3",
|
|
file_types_description : "MP3 Files",
|
|
file_upload_limit : "1",
|
|
file_queue_limit : "1",
|
|
|
|
// Event Handler Settings (all my handlers are in the Handler.js file)
|
|
file_dialog_start_handler : fileDialogStart,
|
|
file_queued_handler : fileQueued,
|
|
file_queue_error_handler : fileQueueError,
|
|
file_dialog_complete_handler : fileDialogComplete,
|
|
upload_start_handler : uploadStart,
|
|
upload_progress_handler : uploadProgress,
|
|
upload_error_handler : uploadError,
|
|
upload_success_handler : uploadSuccess,
|
|
upload_complete_handler : uploadComplete,
|
|
|
|
// Button Settings
|
|
button_image_url : "/static/img/uploadbtn.gif",
|
|
button_placeholder_id : "spanButtonPlaceholder2",
|
|
button_width: 82,
|
|
button_height: 38,
|
|
|
|
// Flash Settings
|
|
flash_url : "/static/lib/swfupload/swfupload.swf",
|
|
|
|
custom_settings : {
|
|
progressTarget : "fsUploadProgress2",
|
|
cancelButtonId : "btnCancel2"
|
|
},
|
|
|
|
// Debug Settings
|
|
debug: false
|
|
});
|
|
}
|
|
var mp3player = {
|
|
loaded : function(){
|
|
// Local copy of jQuery selectors, for performance.
|
|
var my_jPlayer = $("#jquery_jplayer"),
|
|
my_trackName = $("#jp_container .track-name"),
|
|
my_playState = $("#jp_container .play-state"),
|
|
my_extraPlayInfo = $("#jp_container .extra-play-info");
|
|
|
|
// Some options
|
|
var opt_play_first = false, // If true, will attempt to auto-play the default track on page loads. No effect on mobile devices, like iOS.
|
|
opt_auto_play = false, // If true, when a track is selected, it will auto-play.
|
|
opt_text_playing = "Now playing", // Text when playing
|
|
opt_text_selected = "Track selected"; // Text when not playing
|
|
|
|
// Change the time format
|
|
$.jPlayer.timeFormat.padMin = false;
|
|
$.jPlayer.timeFormat.padSec = false;
|
|
$.jPlayer.timeFormat.sepMin = " min ";
|
|
$.jPlayer.timeFormat.sepSec = " sec";
|
|
|
|
// Initialize the play state text
|
|
my_playState.text(opt_text_selected);
|
|
|
|
// Instance jPlayer
|
|
my_jPlayer.jPlayer({
|
|
ready: function () {
|
|
|
|
},
|
|
timeupdate: function(event) {
|
|
my_extraPlayInfo.text(parseInt(event.jPlayer.status.currentPercentAbsolute, 10) + "%");
|
|
},
|
|
play: function(event) {
|
|
|
|
},
|
|
pause: function(event) {
|
|
},
|
|
ended: function(event) {
|
|
|
|
},
|
|
swfPath: "/static/lib/jplayer",
|
|
cssSelectorAncestor: "#jp_container",
|
|
supplied: "mp3",
|
|
solution:"flash,html"
|
|
});
|
|
|
|
// Create click handlers for the different tracks
|
|
$(".jp-play").click(function(e) {
|
|
my_jPlayer.jPlayer("setMedia", {
|
|
mp3: $(this).attr('rel'),
|
|
errorAlerts : true,
|
|
warningAlerts : false
|
|
});
|
|
my_jPlayer.jPlayer("play");
|
|
$('#player_status').show();
|
|
$(this).blur();
|
|
return false;
|
|
});
|
|
$('.jp-stop').click(function(e){
|
|
$('#player_status').hide();
|
|
});
|
|
$('.voice_del').click(function(e) {
|
|
$(this).deleteatt({
|
|
'id':$(this).attr('rel'),
|
|
'url':'/service/delatt',
|
|
'content':'是否删除'+$(this).next('h4').html(),
|
|
'item_prefix':'thumbItems_',
|
|
'callback': function(){
|
|
upload2.setStats({successful_uploads:0});
|
|
upload2.setFileUploadLimit(1);
|
|
my_jPlayer.jPlayer( "stop" );
|
|
}
|
|
});
|
|
});
|
|
},
|
|
makeHtml : function(data){
|
|
html = '<div class="well well-small" id="thumbItems_'+data.attid+'">'
|
|
+' <button type="button" class="voice_del close glyphicon glyphicon-trash" rel="'+data.attid+'" title="删除"></button>'
|
|
+' <h4>'+data.realname+'</h4>'
|
|
+' <div id="jp_container" class="demo-container">'
|
|
+' <div class="btn-group">'
|
|
+' <button type="button" class="btn btn-default jp-play" rel="/uploads/'+data.file_url+'"><span class="glyphicon glyphicon-play"></span></button>'
|
|
+' <button type="button" class="btn btn-default jp-pause"><span class="glyphicon glyphicon-pause"></span></button>'
|
|
+' <button type="button" class="btn btn-default jp-stop"><span class="glyphicon glyphicon-stop"></span></button>'
|
|
+' <button type="button" class="btn btn-default jp-mute"><span class="glyphicon glyphicon-volume-down"></span></button>'
|
|
+' <button type="button" class="btn btn-default jp-volume-max"><span class="glyphicon glyphicon-volume-up"></span></button>'
|
|
+' </div>'
|
|
+' <span id="player_status" style="display:none;">'
|
|
+' 音量:<a class="jp-volume-bar" href="#">|<---------->|</a>'
|
|
+' <span class="extra-play-info"></span> of <span class="jp-duration"></span>, which is <span class="jp-current-time"></span>'
|
|
+' </span>'
|
|
+'<input type="hidden" name="voice" value="'+data.file_url+'" />'
|
|
+' </div>'
|
|
+'</div>';
|
|
|
|
return html;
|
|
}
|
|
}
|
|
|
|
var thumbfunc = {
|
|
binddelbtn : function(id){
|
|
this.dom = $('#thumbItems_'+id).children('.media-body').children('.thumb_del');
|
|
this.dom.bind('click',function(e) {
|
|
$(this).deleteatt({
|
|
'id':$(this).attr('rel'),
|
|
'url':'/service/delatt',
|
|
'content':'是否删除'+$(this).next('h4').html(),
|
|
'item_prefix':'thumbItems_',
|
|
'callback': thumbfunc.queueset()
|
|
});
|
|
});
|
|
},
|
|
loaded : function(){
|
|
$('#thumbs').children('div').each(function(index, element) {
|
|
this.delbtn = $(this).children('.media-body').children('.thumb_del');
|
|
$(this).hover(
|
|
function(){
|
|
$(this).addClass('hovered');
|
|
},
|
|
function(){
|
|
$(this).removeClass('hovered');
|
|
}
|
|
)
|
|
|
|
this.delbtn.bind('click',function(e) {
|
|
$(this).deleteatt({
|
|
'id':$(this).attr('rel'),
|
|
'url':'/service/delatt',
|
|
'content':'是否删除'+$(this).next('h4').html(),
|
|
'item_prefix':'thumbItems_',
|
|
'callback': thumbfunc.queueset()
|
|
});
|
|
});
|
|
});
|
|
},
|
|
queueset : function(){
|
|
this.chilrenslen = $('#thumbs').children('div').length;
|
|
upload1.setStats({successful_uploads:this.chilrenslen});
|
|
upload1.setFileUploadLimit(5- this.chilrenslen);
|
|
upload1.setFileQueueLimit(5- this.chilrenslen);
|
|
},
|
|
filetype : function(mime){
|
|
|
|
this.patrn=/image/;
|
|
if (this.patrn.test(mime))
|
|
{
|
|
return "image";
|
|
}
|
|
|
|
this.patrn=/audio/
|
|
if(this.patrn.test(mime))
|
|
{
|
|
return "audio";
|
|
}
|
|
|
|
return null;
|
|
},
|
|
makeHtml : function(data){
|
|
|
|
html = '<div class="media well well-small" id="thumbItems_'+data.attid+'">'
|
|
+'<a class="pull-left" href="javascript:void(0);">'
|
|
+'<img class="media-object img-thumbnail" src="/uploads/'+data.thumb[400].url+'">'
|
|
+'</a>'
|
|
+'<div class="media-body">'
|
|
+'<button type="button" class="thumb_del close glyphicon glyphicon-trash" rel="'+data.attid+'" title="删除"></button>'
|
|
+'<h4 class="media-heading">'+data.realname+'</h4>'
|
|
+'<textarea name="thumb['+data.attid+'][description]" class="form-control" rows="2"></textarea>'
|
|
+'<input type="hidden" name="thumb['+data.attid+'][id]" value="'+data.attid+'" />'
|
|
+'</div>'
|
|
+'</div>';
|
|
return html;
|
|
}
|
|
};
|
|
thumbfunc.loaded();
|
|
|
|
|
|
function voicesubmited(data){
|
|
if (typeof(data)=='object')
|
|
{
|
|
if(typeof(data.error)!='undefined')
|
|
{
|
|
$("#alert-info").attr('class','alert alert-danger');
|
|
$("#alert-info").html(data.error);
|
|
return false;
|
|
}
|
|
if(typeof(data.success)!='undefined')
|
|
{
|
|
$("#alert-info").attr('class','alert alert-success');
|
|
$("#alert-info").html("投稿成功!通过评审后会自动发布(页面将自动跳转,<a href=\"/member\" class=\"alert-link\">如果没有跳转请点击这里</a>)");
|
|
setTimeout("window.location.href ='/member'",3000);
|
|
return false;
|
|
}
|
|
}
|
|
else{
|
|
$("#alert-info").attr('class','alert alert-danger');
|
|
$("#alert-info").html('服务器掉链子了,<a href="/service/reporterror/?content=voice_submit_error">通知管理员揍它</a>');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
$(document).ready(function(e) {
|
|
$('#tags').tagsInput({width:'auto'});//taginput
|
|
|
|
$('#submit_btn').click(function(e) {//submit
|
|
editor.sync();
|
|
$.ajax({
|
|
'type':"POST",
|
|
'url':"/voice/submit",
|
|
'data':$("#voice_submit").serialize(),
|
|
'success':voicesubmited,
|
|
'timeout': 30000,
|
|
'error': function(){
|
|
$("#alert-info").attr('class','alert alert-danger');
|
|
$("#alert-info").html("出现错误,请稍后重试");
|
|
$('#submit-loading').hide();
|
|
return false;
|
|
},
|
|
'beforeSend': function(){
|
|
$("#submit_btn").addClass('disabled');
|
|
$("#submit_btn").attr('disabled','disabled');
|
|
$('#submit-loading').show();
|
|
},
|
|
complete: function(){
|
|
$("#submit_btn").removeClass('disabled');
|
|
$("#submit_btn").removeAttr('disabled');
|
|
$('#submit-loading').hide();
|
|
}
|
|
});
|
|
});
|
|
}); |