cms_article_publish.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. $(document).ready(function(){
  2. //图片上传
  3. $("#article_image_upload").fileupload({
  4. dataType: 'json',
  5. url: "index.php?act=publish&op=article_image_upload",
  6. add: function(e,data) {
  7. $.each(data.files, function (index, file) {
  8. var image_content = '<li id=' + file.name.replace(/\./g, '_') + '>';
  9. image_content += '<div class="picture">';
  10. image_content += '<a href="Javascript:void(0);">';
  11. image_content += '<img src="'+ LOADING_IMAGE +'" alt="" />';
  12. image_content += '</a></div>';
  13. image_content += '<div class="handle">';
  14. image_content += '<span class="upload-state">正在上传:' + file.name + '</span>';
  15. image_content += '</div>';
  16. image_content += '</li>';
  17. $("#article_image_list").append(image_content);
  18. });
  19. data.submit();
  20. },
  21. done: function (e,data) {
  22. result = data.result;
  23. var $image_box = $('#' + result.origin_file_name.replace(/\./g, '_'));
  24. if(result.status == "success") {
  25. $image_box.find('img').attr('src', result.file_url);
  26. var $image_handle = $image_box.find('.handle');
  27. var image_handle = '<a nctype="btn_insert_article_image">插入</a>';
  28. image_handle += '<a nctype="btn_set_article_image" image_name="'+result.file_name+'">封面</a>';
  29. image_handle += '<a nctype="btn_drop_article_image" image_name="'+result.file_name+'">删除</a>';
  30. $image_handle.html(image_handle);
  31. var image_hidden = '<input name="article_image_all[]" type="hidden" value="'+result.file_name + ',' + result.file_path +'" />';
  32. $image_handle.after(image_hidden);
  33. $image_box.attr('id', '');
  34. } else {
  35. $image_box.remove();
  36. showError(result.error);
  37. }
  38. }
  39. });
  40. //图片列表上移
  41. $("#btn_image_list_up").click(function(){
  42. var position = $("#article_image_list").position();
  43. var list_height = $("#article_image_list").height();
  44. if((list_height + position.top) > 447) {
  45. var newtop = position.top - 121;
  46. $("#article_image_list").css("top", newtop);
  47. }
  48. });
  49. //图片列表下移
  50. $("#btn_image_list_down").click(function(){
  51. var position = $("#article_image_list").position();
  52. if(position.top < 0) {
  53. var newtop = position.top + 103;
  54. $("#article_image_list").css("top", newtop);
  55. }
  56. });
  57. //设封面图
  58. $("[nctype='btn_set_article_image']").live("click",function(){
  59. var article_image = $("<div />").append($(this).parent().parent().find("img").clone()).html();
  60. $("#div_article_image").html(article_image);
  61. $("#article_image").val($(this).attr("image_name"));
  62. });
  63. //插入编辑器
  64. $("[nctype='btn_insert_article_image']").live("click",function(){
  65. var html = KE.html();
  66. html += "<p>"+$("<div />").append($(this).parent().parent().find("img").clone()).html()+"</p>";
  67. KE.html(html);
  68. });
  69. //图片删除
  70. $("[nctype='btn_drop_article_image']").live("click",function(){
  71. var image_object = $(this).parent().parent();
  72. var image_name = $(this).attr("image_name");
  73. $.getJSON("index.php?act=publish&op=article_image_drop", { image_name: image_name }, function(result){
  74. if(result.status == "success") {
  75. image_object.remove();
  76. } else {
  77. showError(result.error);
  78. }
  79. });
  80. });
  81. //标签操作
  82. $("[nctype='cms_tag']").live("click",function(){
  83. var current_css = $(this).attr("class");
  84. if(current_css == "btn-cms-tag") {
  85. $(this).attr("class","btn-cms-tag-selected");
  86. } else {
  87. $(this).attr("class","btn-cms-tag");
  88. }
  89. var cms_tag_selected = '';
  90. $(".btn-cms-tag-selected").each(function(){
  91. cms_tag_selected += $(this).attr("tag_id") + ",";
  92. });
  93. $("#article_tag").val(cms_tag_selected.substring(0, cms_tag_selected.length-1));
  94. });
  95. //添加商品按钮文字
  96. $("[name='goods_search_type']").click(function(){
  97. var search_type = $("[name='goods_search_type']:checked").val();
  98. if(search_type == 'goods_url') {
  99. $("#btn_goods_search").val("添加");
  100. } else {
  101. $("#btn_goods_search").val("搜索");
  102. }
  103. });
  104. //商品搜索
  105. $("#btn_goods_search").click(function(){
  106. if($("#article_goods_list li").length < 3) {
  107. var search_type = $("[name='goods_search_type']:checked").val();
  108. var search_keyword = $("#goods_search_keyword").val();
  109. $("#goods_search_keyword").val("");
  110. if(search_keyword != "") {
  111. if(search_type == "goods_url") {
  112. var url = encodeURIComponent(search_keyword);
  113. $.getJSON("index.php?act=api&op=goods_info_by_url", { url: url}, function(data){
  114. if(data.result == "true") {
  115. var temp = '<li nctype="btn_goods_select"><dl>';
  116. temp += '<dt class="name"><a href="'+data.url+'" target="_blank">'+data.title+'</a></dt>';
  117. temp += '<dd class="image"><img title="'+data.title+'" src="'+data.image+'" /></dd>';
  118. temp += '<dd class="price">价格:<em>'+data.price+'</em></dd>';
  119. temp += '</dl><i>选择删除相关商品</i>';
  120. temp += '<input name="article_goods_url[]" value="'+data.url+'" type="hidden" />';
  121. temp += '<input name="article_goods_title[]" value="'+data.title+'" type="hidden" />';
  122. temp += '<input name="article_goods_image[]" value="'+data.image+'" type="hidden" />';
  123. temp += '<input name="article_goods_price[]" value="'+data.price+'" type="hidden" />';
  124. temp += '<input name="article_goods_type[]" value="'+data.type+'" type="hidden" />';
  125. temp += '</li>';
  126. $("#article_goods_list").append(temp);
  127. } else {
  128. alert(data.message);
  129. }
  130. });
  131. } else {
  132. $("#div_goods_select").load("index.php?act=api&op=goods_list&search_type="+search_type+"&search_keyword="+search_keyword);
  133. }
  134. }
  135. }
  136. });
  137. //商品选择翻页
  138. $("#div_goods_select .demo").live('click',function(e){
  139. $("#div_goods_select").load($(this).attr('href'));
  140. return false;
  141. });
  142. //商品添加
  143. $("#goods_search_list [nctype='btn_goods_select']").live("click",function(){
  144. if($("#article_goods_list li").length < 3) {
  145. var temp = '<li nctype="btn_goods_select">'+$(this).html();
  146. temp += '<input name="article_goods_url[]" value="'+$(this).attr("goods_url")+'" type="hidden" />';
  147. temp += '<input name="article_goods_title[]" value="'+$(this).attr("goods_title")+'" type="hidden" />';
  148. temp += '<input name="article_goods_image[]" value="'+$(this).attr("goods_image")+'" type="hidden" />';
  149. temp += '<input name="article_goods_price[]" value="'+$(this).attr("goods_price")+'" type="hidden" />';
  150. temp += '<input name="article_goods_type[]" value="'+$(this).attr("goods_type")+'" type="hidden" />';
  151. temp += '</li>';
  152. $("#article_goods_list").append(temp);
  153. }
  154. });
  155. //商品删除
  156. $("#article_goods_list [nctype='btn_goods_select']").live("click",function(){
  157. $(this).remove();
  158. });
  159. //文章搜索
  160. $("#btn_article_search").click(function(){
  161. var search_type = $("[name='article_search_type']:checked").val();
  162. var search_keyword = $("#article_search_keyword").val();
  163. if(search_keyword != "") {
  164. $("#div_article_select").load("index.php?act=api&op=article_list&search_type="+search_type+"&search_keyword="+search_keyword);
  165. }
  166. });
  167. //文章选择翻页
  168. $("#div_article_select .demo").live('click',function(e){
  169. $("#div_article_select").load($(this).attr('href'));
  170. return false;
  171. });
  172. //文章添加
  173. $("#article_search_list [nctype='btn_article_select']").live("click",function(){
  174. var temp = $("<div />").append($(this).clone()).html();
  175. $("#article_link_list").append(temp);
  176. $("#article_link_list").last("li").find("i").text("选择删除相关文章");
  177. refresh_article_link();
  178. });
  179. //文章删除
  180. $("#article_link_list [nctype='btn_article_select']").live("click",function(){
  181. $(this).remove();
  182. refresh_article_link();
  183. });
  184. function refresh_article_link() {
  185. var cms_article_selected = '';
  186. $("#article_link_list [nctype='btn_article_select']").each(function(){
  187. cms_article_selected += $(this).attr("article_id") + ",";
  188. });
  189. $("#article_link").val(cms_article_selected.substring(0, cms_article_selected.length-1));
  190. }
  191. });