$(document).ready(function(){
//图片上传
$("#article_image_upload").fileupload({
dataType: 'json',
url: "index.php?act=publish&op=article_image_upload",
add: function(e,data) {
$.each(data.files, function (index, file) {
var image_content = '
';
image_content += '';
image_content += '';
image_content += '正在上传:' + file.name + '';
image_content += '
';
image_content += '';
$("#article_image_list").append(image_content);
});
data.submit();
},
done: function (e,data) {
result = data.result;
var $image_box = $('#' + result.origin_file_name.replace(/\./g, '_'));
if(result.status == "success") {
$image_box.find('img').attr('src', result.file_url);
var $image_handle = $image_box.find('.handle');
var image_handle = '插入';
image_handle += '封面';
image_handle += '删除';
$image_handle.html(image_handle);
var image_hidden = '';
$image_handle.after(image_hidden);
$image_box.attr('id', '');
} else {
$image_box.remove();
showError(result.error);
}
}
});
//图片列表上移
$("#btn_image_list_up").click(function(){
var position = $("#article_image_list").position();
var list_height = $("#article_image_list").height();
if((list_height + position.top) > 447) {
var newtop = position.top - 121;
$("#article_image_list").css("top", newtop);
}
});
//图片列表下移
$("#btn_image_list_down").click(function(){
var position = $("#article_image_list").position();
if(position.top < 0) {
var newtop = position.top + 103;
$("#article_image_list").css("top", newtop);
}
});
//设封面图
$("[nctype='btn_set_article_image']").live("click",function(){
var article_image = $("").append($(this).parent().parent().find("img").clone()).html();
$("#div_article_image").html(article_image);
$("#article_image").val($(this).attr("image_name"));
});
//插入编辑器
$("[nctype='btn_insert_article_image']").live("click",function(){
var html = KE.html();
html += ""+$("
").append($(this).parent().parent().find("img").clone()).html()+"";
KE.html(html);
});
//图片删除
$("[nctype='btn_drop_article_image']").live("click",function(){
var image_object = $(this).parent().parent();
var image_name = $(this).attr("image_name");
$.getJSON("index.php?act=publish&op=article_image_drop", { image_name: image_name }, function(result){
if(result.status == "success") {
image_object.remove();
} else {
showError(result.error);
}
});
});
//标签操作
$("[nctype='cms_tag']").live("click",function(){
var current_css = $(this).attr("class");
if(current_css == "btn-cms-tag") {
$(this).attr("class","btn-cms-tag-selected");
} else {
$(this).attr("class","btn-cms-tag");
}
var cms_tag_selected = '';
$(".btn-cms-tag-selected").each(function(){
cms_tag_selected += $(this).attr("tag_id") + ",";
});
$("#article_tag").val(cms_tag_selected.substring(0, cms_tag_selected.length-1));
});
//添加商品按钮文字
$("[name='goods_search_type']").click(function(){
var search_type = $("[name='goods_search_type']:checked").val();
if(search_type == 'goods_url') {
$("#btn_goods_search").val("添加");
} else {
$("#btn_goods_search").val("搜索");
}
});
//商品搜索
$("#btn_goods_search").click(function(){
if($("#article_goods_list li").length < 3) {
var search_type = $("[name='goods_search_type']:checked").val();
var search_keyword = $("#goods_search_keyword").val();
$("#goods_search_keyword").val("");
if(search_keyword != "") {
if(search_type == "goods_url") {
var url = encodeURIComponent(search_keyword);
$.getJSON("index.php?act=api&op=goods_info_by_url", { url: url}, function(data){
if(data.result == "true") {
var temp = '';
temp += '- '+data.title+'
';
temp += '
';
temp += '- 价格:'+data.price+'
';
temp += '
选择删除相关商品';
temp += '';
temp += '';
temp += '';
temp += '';
temp += '';
temp += '';
$("#article_goods_list").append(temp);
} else {
alert(data.message);
}
});
} else {
$("#div_goods_select").load("index.php?act=api&op=goods_list&search_type="+search_type+"&search_keyword="+search_keyword);
}
}
}
});
//商品选择翻页
$("#div_goods_select .demo").live('click',function(e){
$("#div_goods_select").load($(this).attr('href'));
return false;
});
//商品添加
$("#goods_search_list [nctype='btn_goods_select']").live("click",function(){
if($("#article_goods_list li").length < 3) {
var temp = ''+$(this).html();
temp += '';
temp += '';
temp += '';
temp += '';
temp += '';
temp += '';
$("#article_goods_list").append(temp);
}
});
//商品删除
$("#article_goods_list [nctype='btn_goods_select']").live("click",function(){
$(this).remove();
});
//文章搜索
$("#btn_article_search").click(function(){
var search_type = $("[name='article_search_type']:checked").val();
var search_keyword = $("#article_search_keyword").val();
if(search_keyword != "") {
$("#div_article_select").load("index.php?act=api&op=article_list&search_type="+search_type+"&search_keyword="+search_keyword);
}
});
//文章选择翻页
$("#div_article_select .demo").live('click',function(e){
$("#div_article_select").load($(this).attr('href'));
return false;
});
//文章添加
$("#article_search_list [nctype='btn_article_select']").live("click",function(){
var temp = $("").append($(this).clone()).html();
$("#article_link_list").append(temp);
$("#article_link_list").last("li").find("i").text("选择删除相关文章");
refresh_article_link();
});
//文章删除
$("#article_link_list [nctype='btn_article_select']").live("click",function(){
$(this).remove();
refresh_article_link();
});
function refresh_article_link() {
var cms_article_selected = '';
$("#article_link_list [nctype='btn_article_select']").each(function(){
cms_article_selected += $(this).attr("article_id") + ",";
});
$("#article_link").val(cms_article_selected.substring(0, cms_article_selected.length-1));
}
});