cms_special.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. $(document).ready(function(){
  2. var d;
  3. var image_object;
  4. $('a[nctype="nyroModal"]').nyroModal();
  5. //文件上传
  6. var textButton1="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />";
  7. $(textButton1).insertBefore("#special_image");
  8. $("#special_image").change(function(){
  9. $("#textfield1").val($("#special_image").val());
  10. });
  11. var textButton2="<input type='text' name='textfield' id='textfield2' class='type-file-text' /><input type='button' name='button' id='button2' value='' class='type-file-button' />";
  12. $(textButton2).insertBefore("#special_background");
  13. $("#special_background").change(function(){
  14. $("#textfield2").val($("#special_background").val());
  15. });
  16. $("input[nctype='cms_image']").live("change", function(){
  17. var src = getFullPath($(this)[0]);
  18. $(this).parent().prev().find('.low_source').attr('src',src);
  19. $(this).parent().find('input[class="type-file-text"]').val($(this).val());
  20. });
  21. //图片上传
  22. $("#picture_image_upload").fileupload({
  23. dataType: 'json',
  24. url: "index.php?act=cms_special&op=special_image_upload",
  25. add: function(e,data) {
  26. $.each(data.files, function(index, file) {
  27. var image_content = '<li id=' + file.name.replace('.', '_') + ' class="picture">';
  28. image_content += '<div class="size-64x64"><span class="thumb size-64x64"><i></i><img src="' + LOADING_IMAGE + '" alt="" /></span></div>';
  29. image_content += '<p class="handle">';
  30. image_content += '</p>';
  31. $("#special_image_list").append(image_content);
  32. });
  33. data.submit();
  34. },
  35. done: function (e,data) {
  36. result = data.result;
  37. var $image_box = $('#' + result.origin_file_name.replace('.', '_'));
  38. if(result.status == "success") {
  39. $image_box.find('img').attr('src', result.file_url);
  40. var $image_handle = $image_box.find('.handle');
  41. var image_handle = '<a nctype="btn_show_image_insert_link" image_url="'+result.file_url+'" class="insert-link tooltip" title="以图片链接模式插入专题页">&nbsp;</a>';
  42. image_handle += '<a nctype="btn_show_image_insert_hot_point" image_name="'+result.file_name+'" image_url="'+result.file_url+'" class="insert-hotpoint tooltip " title="以热点链接模式插入专题页">&nbsp;</a>';
  43. image_handle += '<a nctype="btn_drop_special_image" image_name="'+result.file_name+'" class="delete tooltip " title="删除该图片">&nbsp;</a>';
  44. $image_handle.html(image_handle);
  45. var image_hidden = '<input name="special_image_all[]" type="hidden" value="'+result.file_name+'" />';
  46. $image_handle.after(image_hidden);
  47. $image_box.attr('id', '');
  48. } else {
  49. $image_box.remove();
  50. alert(result.error);
  51. }
  52. }
  53. });
  54. //图片删除
  55. $("[nctype='btn_drop_special_image']").live("click",function(){
  56. var image_object = $(this).parents("li");
  57. var image_name = $(this).attr("image_name");
  58. $.getJSON("index.php?act=cms_special&op=special_image_drop", { image_name: image_name }, function(result){
  59. if(result.status == "success") {
  60. image_object.remove();
  61. } else {
  62. showError(result.error);
  63. }
  64. });
  65. });
  66. //插入图片链接对话框
  67. $("[nctype='btn_show_image_insert_link']").live('click', function(){
  68. $("#_dialog_image_insert_link").find("img").attr("src", $(this).attr("image_url"));
  69. html_form('dialog_image_insert_link', '图片链接', $("#_dialog_image_insert_link").html(), 640);
  70. });
  71. //插入图片链接
  72. $("[nctype='btn_image_insert_link']").live('click', function(){
  73. var html = $("#special_content").val();
  74. var item = $(this).parents("table");
  75. var link = item.find("[nctype='_image_insert_link']").val();
  76. html += "<div class='special-content-link'>";
  77. if(link != "") {
  78. html += "<a href=" + link +" target='_blank'>";
  79. }
  80. html += $("<div />").append(item.find("img").clone()).html();
  81. if(link != "") {
  82. html += "</a>";
  83. }
  84. html += "</div>";
  85. $("#special_content").val(html);
  86. special_view_update();
  87. DialogManager.close("dialog_image_insert_link");
  88. });
  89. //插入热点图
  90. $("[nctype='btn_show_image_insert_hot_point']").live('click', function(){
  91. $("#_dialog_image_insert_hot_point").find("img").attr("src", $(this).attr("image_url"));
  92. d = html_form('dialog_image_insert_hot_point', '图片热点', $("#_dialog_image_insert_hot_point").html(), 1040);
  93. var count = 0;
  94. var dialog_object = $("#fwin_dialog_image_insert_hot_point");
  95. var filename = $(this).attr("image_name").replace(".","");
  96. image_object = dialog_object.find("[nctype='img_hot_point']");
  97. var x1 = dialog_object.find("[nctype='x1']");
  98. var y1 = dialog_object.find("[nctype='y1']");
  99. var x2 = dialog_object.find("[nctype='x2']");
  100. var y2 = dialog_object.find("[nctype='y2']");
  101. var w = dialog_object.find("[nctype='w']");
  102. var h = dialog_object.find("[nctype='h']");
  103. var url = dialog_object.find("[nctype='url']");
  104. image_object.imgAreaSelect({
  105. handles: true,
  106. fadeSpeed: 200,
  107. onSelectChange: preview
  108. });
  109. image_object.attr("usemap","#"+filename);
  110. image_object.after('<map id="'+filename+'" name="'+filename+'"></map>');
  111. $("[nctype='delete_hot_point']").live("click",function(){
  112. var key = $(this).attr("name");
  113. $("#"+key).remove();
  114. $("."+key).remove();
  115. });
  116. $("[nctype='select_hot_point']").live("click",function(){
  117. var xy = $(this).attr("name");
  118. var xyarray = xy.split(",");
  119. var ias = image_object.imgAreaSelect({ instance: true });
  120. ias.setSelection(xyarray[0],xyarray[1],xyarray[2],xyarray[3],true);
  121. ias.setOptions({ show: true });
  122. ias.update();
  123. });
  124. dialog_object.find("[nctype='btn_hot_point_commit']").click(function(){
  125. count++;
  126. var key = filename + count;
  127. var xy = x1.val()+','+y1.val()+','+x2.val()+','+y2.val()+',';
  128. image_object.parent().find("map").append('<area id='+key+' shape="rect" coords="'+xy+'" href="'+url.val()+'" target="_blank" />');
  129. dialog_object.find("[nctype='list']").append('<li class="'+key+'"><i></i>热点区域'+count+'<span>('+url.val()+')</span><a nctype="select_hot_point" name="'+xy+'" href="###" class="btn-select-hot-point">选中</a><a nctype="delete_hot_point" class="btn-delete-hot-point" name="'+key+'" href="###">删除</a></li>');
  130. image_object.after('<div class='+key+' style="width:'+w.val()+'px;height:'+h.val()+'px;position:absolute;left:'+x1.val()+'px;top:'+y1.val()+'px;border:1px solid #cccccc;">'+count+'</div>');
  131. url.val('');
  132. var ias = image_object.imgAreaSelect({ instance: true });
  133. ias.cancelSelection();
  134. });
  135. $(".dialog_close_button").unbind().bind("click", function() {
  136. var ias = image_object.imgAreaSelect({ instance: true });
  137. ias.cancelSelection();
  138. DialogManager.close("dialog_image_insert_hot_point");
  139. });
  140. });
  141. //插入图片链接
  142. $("[nctype='btn_image_insert_hot_point']").live('click', function(){
  143. var html = $("#special_content").val();
  144. var hot_point = $(this).parents("table").find(".special-hot-point").clone();
  145. hot_point.find("div").remove();
  146. hot_point = $("<div />").append(hot_point).html();
  147. html += hot_point;
  148. $("#special_content").val(html);
  149. special_view_update();
  150. var ias = image_object.imgAreaSelect({ instance: true });
  151. ias.cancelSelection();
  152. DialogManager.close("dialog_image_insert_hot_point");
  153. });
  154. //图片删除
  155. $("[nctype='btn_drop_special_image']").click(function() {
  156. $(this).parents(".picture").remove();
  157. });
  158. //插入商品对话框
  159. $("#btn_show_special_insert_goods").click(function(){
  160. html_form('dialog_special_insert_goods', '插入商品', $("#_dialog_special_insert_goods").html(), 640);
  161. });
  162. //选择商品
  163. $("[nctype='btn_special_goods']").live('click', function(){
  164. var goods_list = $(this).parents("table").find("[nctype='_special_goods_list']");
  165. var link_item = $(this).parents("table").find("[nctype='_input_goods_link']");
  166. var link = link_item.val();
  167. link_item.val('');
  168. if(link != '') {
  169. var url = encodeURIComponent(link);
  170. $.getJSON("index.php?act=cms_special&op=goods_info_by_url", { url: url}, function(data){
  171. if(data.result == "true") {
  172. var temp = '<li nctype="btn_goods_select"><dl>';
  173. temp += '<dt class="name"><a href="'+data.url+'" target="_blank">'+data.title+'</a></dt>';
  174. temp += '<dd class="image"><a href="'+data.url+'" target="_blank"><img title="'+data.title+'" src="'+data.image+'" /></a></dd>';
  175. temp += '<dd class="price">价格:<em>'+data.price+'</em></dd>';
  176. temp += '<dd class="taobao-item-delete" nctype="btn_special_goods_delete" title="删除添加的商品">&nbsp;</dd>';
  177. temp += '</dl></li>';
  178. $(goods_list).append(temp);
  179. } else {
  180. alert(data.message);
  181. }
  182. });
  183. }
  184. });
  185. //删除商品
  186. $("[nctype='btn_special_goods_delete']").live('click', function(){
  187. $(this).parent().parent().remove();
  188. });
  189. //插入商品列表
  190. $("[nctype='btn_special_insert_goods']").live('click', function(){
  191. var html = $("#special_content").val();
  192. html += "<div class='special-content-goods-list'>";
  193. var goods_list = $("<div />").append($(this).parents("table").find("[nctype='_special_goods_list']").clone());
  194. goods_list.find("i").remove();
  195. goods_list.find("[nctype='btn_special_goods_delete']").remove();
  196. html += goods_list.html();
  197. html += "</div>";
  198. $("#special_content").val(html);
  199. special_view_update();
  200. DialogManager.close("dialog_special_insert_goods");
  201. });
  202. //编辑模式
  203. $("#btn_content_edit").click(function(){
  204. $(this).attr("class", "tab-btn actived");
  205. $("#btn_content_view").attr("class", "tab-btn");
  206. $("#div_content_edit").show();
  207. $("#div_content_view").hide();
  208. });
  209. //预览模式
  210. $("#btn_content_view").click(function(){
  211. $(this).attr("class", "tab-btn actived");
  212. $("#btn_content_edit").attr("class", "tab-btn");
  213. $("#div_content_edit").hide();
  214. $("#div_content_view").show();
  215. });
  216. //更新预览窗口
  217. $("#special_content").change(function(){
  218. special_view_update();
  219. });
  220. function special_view_update() {
  221. $("#div_content_view").html($("#special_content").val());
  222. }
  223. special_view_update();
  224. });
  225. //选取相关
  226. function preview(img, selection) {
  227. if (!selection.width || !selection.height)
  228. return;
  229. var scaleX = 100 / selection.width;
  230. var scaleY = 100 / selection.height;
  231. $('#preview img').css({
  232. width: Math.round(scaleX * 300),
  233. height: Math.round(scaleY * 300),
  234. marginLeft: -Math.round(scaleX * selection.x1),
  235. marginTop: -Math.round(scaleY * selection.y1)
  236. });
  237. var dialog_object = $("#fwin_dialog_image_insert_hot_point");
  238. dialog_object.find("[nctype='x1']").val(selection.x1);
  239. dialog_object.find("[nctype='y1']").val(selection.y1);
  240. dialog_object.find("[nctype='x2']").val(selection.x2);
  241. dialog_object.find("[nctype='y2']").val(selection.y2);
  242. dialog_object.find("[nctype='w']").val(selection.width);
  243. dialog_object.find("[nctype='h']").val(selection.height);
  244. }