$(document).ready(function(){ var d; var image_object; $('a[nctype="nyroModal"]').nyroModal(); //文件上传 var textButton1=""; $(textButton1).insertBefore("#special_image"); $("#special_image").change(function(){ $("#textfield1").val($("#special_image").val()); }); var textButton2=""; $(textButton2).insertBefore("#special_background"); $("#special_background").change(function(){ $("#textfield2").val($("#special_background").val()); }); $("input[nctype='cms_image']").live("change", function(){ var src = getFullPath($(this)[0]); $(this).parent().prev().find('.low_source').attr('src',src); $(this).parent().find('input[class="type-file-text"]').val($(this).val()); }); //图片上传 $("#picture_image_upload").fileupload({ dataType: 'json', url: "index.php?act=cms_special&op=special_image_upload", add: function(e,data) { $.each(data.files, function(index, file) { var image_content = '
  • '; image_content += '
    '; image_content += '

    '; image_content += '

    '; $("#special_image_list").append(image_content); }); data.submit(); }, done: function (e,data) { result = data.result; var $image_box = $('#' + result.origin_file_name.replace('.', '_')); 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(); alert(result.error); } } }); //图片删除 $("[nctype='btn_drop_special_image']").live("click",function(){ var image_object = $(this).parents("li"); var image_name = $(this).attr("image_name"); $.getJSON("index.php?act=cms_special&op=special_image_drop", { image_name: image_name }, function(result){ if(result.status == "success") { image_object.remove(); } else { showError(result.error); } }); }); //插入图片链接对话框 $("[nctype='btn_show_image_insert_link']").live('click', function(){ $("#_dialog_image_insert_link").find("img").attr("src", $(this).attr("image_url")); html_form('dialog_image_insert_link', '图片链接', $("#_dialog_image_insert_link").html(), 640); }); //插入图片链接 $("[nctype='btn_image_insert_link']").live('click', function(){ var html = $("#special_content").val(); var item = $(this).parents("table"); var link = item.find("[nctype='_image_insert_link']").val(); html += "
  • 热点区域'+count+'('+url.val()+')选中删除
  • '); image_object.after('
    '+count+'
    '); url.val(''); var ias = image_object.imgAreaSelect({ instance: true }); ias.cancelSelection(); }); $(".dialog_close_button").unbind().bind("click", function() { var ias = image_object.imgAreaSelect({ instance: true }); ias.cancelSelection(); DialogManager.close("dialog_image_insert_hot_point"); }); }); //插入图片链接 $("[nctype='btn_image_insert_hot_point']").live('click', function(){ var html = $("#special_content").val(); var hot_point = $(this).parents("table").find(".special-hot-point").clone(); hot_point.find("div").remove(); hot_point = $("
    ").append(hot_point).html(); html += hot_point; $("#special_content").val(html); special_view_update(); var ias = image_object.imgAreaSelect({ instance: true }); ias.cancelSelection(); DialogManager.close("dialog_image_insert_hot_point"); }); //图片删除 $("[nctype='btn_drop_special_image']").click(function() { $(this).parents(".picture").remove(); }); //插入商品对话框 $("#btn_show_special_insert_goods").click(function(){ html_form('dialog_special_insert_goods', '插入商品', $("#_dialog_special_insert_goods").html(), 640); }); //选择商品 $("[nctype='btn_special_goods']").live('click', function(){ var goods_list = $(this).parents("table").find("[nctype='_special_goods_list']"); var link_item = $(this).parents("table").find("[nctype='_input_goods_link']"); var link = link_item.val(); link_item.val(''); if(link != '') { var url = encodeURIComponent(link); $.getJSON("index.php?act=cms_special&op=goods_info_by_url", { url: url}, function(data){ if(data.result == "true") { var temp = '
  • '; temp += '
    '+data.title+'
    '; temp += '
    '; temp += '
    价格:'+data.price+'
    '; temp += '
     
    '; temp += '
  • '; $(goods_list).append(temp); } else { alert(data.message); } }); } }); //删除商品 $("[nctype='btn_special_goods_delete']").live('click', function(){ $(this).parent().parent().remove(); }); //插入商品列表 $("[nctype='btn_special_insert_goods']").live('click', function(){ var html = $("#special_content").val(); html += "
    "; var goods_list = $("
    ").append($(this).parents("table").find("[nctype='_special_goods_list']").clone()); goods_list.find("i").remove(); goods_list.find("[nctype='btn_special_goods_delete']").remove(); html += goods_list.html(); html += "
    "; $("#special_content").val(html); special_view_update(); DialogManager.close("dialog_special_insert_goods"); }); //编辑模式 $("#btn_content_edit").click(function(){ $(this).attr("class", "tab-btn actived"); $("#btn_content_view").attr("class", "tab-btn"); $("#div_content_edit").show(); $("#div_content_view").hide(); }); //预览模式 $("#btn_content_view").click(function(){ $(this).attr("class", "tab-btn actived"); $("#btn_content_edit").attr("class", "tab-btn"); $("#div_content_edit").hide(); $("#div_content_view").show(); }); //更新预览窗口 $("#special_content").change(function(){ special_view_update(); }); function special_view_update() { $("#div_content_view").html($("#special_content").val()); } special_view_update(); }); //选取相关 function preview(img, selection) { if (!selection.width || !selection.height) return; var scaleX = 100 / selection.width; var scaleY = 100 / selection.height; $('#preview img').css({ width: Math.round(scaleX * 300), height: Math.round(scaleY * 300), marginLeft: -Math.round(scaleX * selection.x1), marginTop: -Math.round(scaleY * selection.y1) }); var dialog_object = $("#fwin_dialog_image_insert_hot_point"); dialog_object.find("[nctype='x1']").val(selection.x1); dialog_object.find("[nctype='y1']").val(selection.y1); dialog_object.find("[nctype='x2']").val(selection.x2); dialog_object.find("[nctype='y2']").val(selection.y2); dialog_object.find("[nctype='w']").val(selection.width); dialog_object.find("[nctype='h']").val(selection.height); }