upload.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var upload_pic = [];
  2. var upload_file = [];
  3. var upload = [];
  4. function loadUpload(i,e,key,upload,assets)
  5. {
  6. var value = e.attr('v');
  7. if(typeof(upload[value]) != "undefined")
  8. {
  9. return;
  10. }
  11. upload[value] = true;
  12. e.uploadify({
  13. 'formData' : {'key' : key},
  14. 'swf' : assets + 'uploadify.swf',
  15. 'buttonText' : '选择文件',
  16. 'fileObjName' : 'file',
  17. 'uploader' : upload,
  18. 'cancelImg' : assets + 'upload/img/fyuploadify-cancel.png',
  19. 'onUploadSuccess':function(file,data,response)
  20. {
  21. //console.info(data);
  22. var data = eval('('+data+')');
  23. if(data.status)
  24. {
  25. var mul = e.attr('mul');
  26. if(mul == 'yes')
  27. {
  28. if(e.attr('t') == 'file')
  29. {
  30. if(upload_file.length <= 0 && $("#" + value).val())
  31. {
  32. upload_file = $("#" + value).val().split(',');
  33. }
  34. var m = $('.' +value+'_mul');
  35. var i = m.find('li').eq(upload_file.length);
  36. if(i.length)
  37. {
  38. i.find('a').eq(0).html(data.name);
  39. }
  40. else
  41. {
  42. m.append('<li><a href="'+data.url+'" target="_blank" title="点此下载" >'+data.name+'</a>&nbsp;&nbsp;<a href="javascript:;" title="点此删除" style="color:red;" onclick="fileDel($(this), \''+value+'\')">[删除]</a></li>');
  43. }
  44. upload_file.push(data.url);
  45. $("#" + value).val(upload_file.join(','));
  46. }
  47. else
  48. {
  49. if(upload_pic.length <= 0 && $("#" + value).val())
  50. {
  51. upload_pic = $("#" + value).val().split(',');
  52. }
  53. var m = $('.' +value+'_mul');
  54. var i = m.find('img').eq(upload_pic.length);
  55. if(i.length)
  56. {
  57. i.attr('src', data.url);
  58. }
  59. else
  60. {
  61. m.append('<a href="javascript:;" title="点此删除" onclick="picDel($(this), \''+value+'\')"><img src="'+data.url+'" width="150" style="margin-left:5px;" alt="点此删除"/></a>');
  62. }
  63. upload_pic.push(data.url);
  64. $("#" + value).val(upload_pic.join(','));
  65. }
  66. }
  67. else
  68. {
  69. if(e.attr('t') == 'file')
  70. {
  71. }
  72. else
  73. {
  74. $('#show_'+value).attr('src',data.url).show();
  75. }
  76. $("#"+file.id).find('.data').html('上传完毕');
  77. $('#'+value).val(data.url);
  78. }
  79. }
  80. else
  81. {
  82. $("#"+file.id).find('.data').html("<font color='red'>"+data.message+"</font>");
  83. return false;
  84. }
  85. }
  86. });
  87. }
  88. /*
  89. if(jQuery.browser.msie){
  90. SWFUpload.prototype.getFlashHTML = function () {
  91. return ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
  92. '<param name="wmode" value="', this.settings.button_window_mode , '" />',
  93. '<param name="movie" value="', this.settings.flash_url, '" />',
  94. '<param name="quality" value="high" />',
  95. '<param name="menu" value="false" />',
  96. '<param name="allowScriptAccess" value="always" />',
  97. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  98. '</object>'].join("");
  99. }
  100. }
  101. */
  102. function picDel(e,v)
  103. {
  104. if(confirm('确定要删除图片吗?'))
  105. {
  106. if(upload_pic.length <= 0 && $("#" + v).val())
  107. {
  108. upload_pic = $("#" + v).val().split(',');
  109. }
  110. var p = e.find('img').attr('src');
  111. e.remove();
  112. upload_pic.remove(p);
  113. //console.info(pic);
  114. $("#" + v).val(upload_pic.join(','));
  115. }
  116. }
  117. function fileDel(e,v)
  118. {
  119. if(confirm('确定要删除文件吗?'))
  120. {
  121. if(upload_file.length <= 0 && $("#" + v).val())
  122. {
  123. upload_file = $("#" + v).val().split(',');
  124. }
  125. var parent = e.parent();
  126. var p = parent.find('a').eq(0).attr('href');
  127. parent.remove();
  128. upload_file.remove(p);
  129. //console.info(pic);
  130. $("#" + v).val(upload_file.join(','));
  131. }
  132. }