国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

234 строки
7.5KB

  1. /**
  2. *
  3. * @version $Id: handlers.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2022, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. //事件句并
  10. function fileQueueError(file, errorCode, message) {
  11. try {
  12. var imageName = "error.gif";
  13. var errorName = "";
  14. if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
  15. errorName = "您添加的文件超过了限制";
  16. }
  17. if (errorName !== "") {
  18. alert(errorName);
  19. return;
  20. }
  21. switch (errorCode) {
  22. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  23. imageName = "zerobyte.gif";
  24. break;
  25. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  26. imageName = "toobig.gif";
  27. break;
  28. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  29. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  30. default:
  31. alert(message);
  32. break;
  33. }
  34. addImage("images/" + imageName, 0);
  35. } catch (ex) {
  36. this.debug(ex);
  37. }
  38. }
  39. function fileDialogComplete(numFilesSelected, numFilesQueued) {
  40. try {
  41. if (numFilesQueued > 0) {
  42. this.startUpload();
  43. }
  44. } catch (ex) {
  45. this.debug(ex);
  46. }
  47. }
  48. function uploadProgress(file, bytesLoaded) {
  49. try {
  50. var percent = Math.ceil((bytesLoaded / file.size) * 100);
  51. var progress = new FileProgress(file, this.customSettings.upload_target);
  52. progress.setProgress(percent);
  53. if (percent === 100) {
  54. progress.setStatus("创建缩略图...");
  55. progress.toggleCancel(false, this);
  56. } else {
  57. progress.setStatus("上传中...");
  58. progress.toggleCancel(true, this);
  59. }
  60. } catch (ex) {
  61. this.debug(ex);
  62. }
  63. }
  64. function uploadSuccess(file, serverData) {
  65. try {
  66. var progress = new FileProgress(file, this.customSettings.upload_target);
  67. if (serverData.substring(0, 7) === "FILEID:") {
  68. addImage("swfupload.php?dopost=thumbnail&id=" + serverData.substring(7), serverData.substring(7));
  69. progress.setStatus("获取缩略图");
  70. progress.toggleCancel(false);
  71. } else {
  72. addImage("images/error.gif", 0);
  73. progress.setStatus("有错误");
  74. progress.toggleCancel(false);
  75. alert(serverData);
  76. }
  77. } catch (ex) {
  78. this.debug(ex);
  79. }
  80. }
  81. function uploadComplete(file) {
  82. try {
  83. if (this.getStats().files_queued > 0) {
  84. this.startUpload();
  85. } else {
  86. var progress = new FileProgress(file, this.customSettings.upload_target);
  87. progress.setComplete();
  88. progress.setStatus("所有图片上传完成...");
  89. progress.toggleCancel(false);
  90. }
  91. } catch (ex) {
  92. this.debug(ex);
  93. }
  94. }
  95. function uploadError(file, errorCode, message) {
  96. var imageName = "error.gif";
  97. var progress;
  98. try {
  99. switch (errorCode) {
  100. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  101. try {
  102. progress = new FileProgress(file, this.customSettings.upload_target);
  103. progress.setCancelled();
  104. progress.setStatus("Cancelled");
  105. progress.toggleCancel(false);
  106. }
  107. catch (ex1) {
  108. this.debug(ex1);
  109. }
  110. break;
  111. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  112. try {
  113. progress = new FileProgress(file, this.customSettings.upload_target);
  114. progress.setCancelled();
  115. progress.setStatus("Stopped");
  116. progress.toggleCancel(true);
  117. }
  118. catch (ex2) {
  119. this.debug(ex2);
  120. }
  121. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  122. imageName = "uploadlimit.gif";
  123. break;
  124. default:
  125. alert(message);
  126. break;
  127. }
  128. addImage("images/" + imageName, 0);
  129. } catch (ex3) {
  130. this.debug(ex3);
  131. }
  132. }
  133. var albImg = 0;
  134. function addImage(src, pid) {
  135. var newImgDiv = document.createElement("div");
  136. var delstr = '';
  137. var iptwidth = 160;
  138. albImg++;
  139. if (pid != 0) {
  140. albImg = 'ok' + pid;
  141. delstr = '<a class="btn btn-success btn-sm" href="javascript:delAlbPic(' + pid + ')">删除</a>';
  142. } else {
  143. albImg = 'err' + albImg;
  144. }
  145. newImgDiv.className = 'albCt';
  146. newImgDiv.id = 'albCt' + albImg;
  147. document.getElementById("thumbnails").appendChild(newImgDiv);
  148. newImgDiv.innerHTML = '<img src="' + src + '" style="width:160px">' + delstr;
  149. if (typeof arctype != 'undefined' && arctype == 'article') {
  150. iptwidth = 100;
  151. if (pid != 0) {
  152. newImgDiv.innerHTML = '<img src="' + src + '" style="width:160px" onClick="addtoEdit(' + pid + ')">' + delstr;
  153. }
  154. }
  155. newImgDiv.innerHTML += '<div style="margin-top:10px">注释:<input type="text" name="picinfo' + albImg + '" value="" style="width:' + iptwidth + 'px;"></div>';
  156. }
  157. /* ******************************************
  158. * FileProgress Object
  159. * Control object for displaying file info
  160. * ****************************************** */
  161. function FileProgress(file, targetID) {
  162. this.fileProgressID = "divFileProgress";
  163. this.fileProgressWrapper = document.getElementById(this.fileProgressID);
  164. if (!this.fileProgressWrapper) {
  165. this.fileProgressWrapper = document.createElement("div");
  166. this.fileProgressWrapper.className = "progressWrapper";
  167. this.fileProgressWrapper.id = this.fileProgressID;
  168. this.fileProgressElement = document.createElement("div");
  169. this.fileProgressElement.className = "progressContainer";
  170. var progressCancel = document.createElement("a");
  171. progressCancel.className = "progressCancel";
  172. progressCancel.href = "#";
  173. progressCancel.style.visibility = "hidden";
  174. progressCancel.appendChild(document.createTextNode(" "));
  175. var progressText = document.createElement("div");
  176. progressText.className = "progressName";
  177. progressText.appendChild(document.createTextNode(file.name));
  178. var progressBar = document.createElement("div");
  179. progressBar.className = "progressBarInProgress";
  180. var progressStatus = document.createElement("div");
  181. progressStatus.className = "progressBarStatus";
  182. progressStatus.innerHTML = "&nbsp;";
  183. this.fileProgressElement.appendChild(progressCancel);
  184. this.fileProgressElement.appendChild(progressText);
  185. this.fileProgressElement.appendChild(progressStatus);
  186. this.fileProgressElement.appendChild(progressBar);
  187. this.fileProgressWrapper.appendChild(this.fileProgressElement);
  188. document.getElementById(targetID).appendChild(this.fileProgressWrapper);
  189. } else {
  190. this.fileProgressElement = this.fileProgressWrapper.firstChild;
  191. this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
  192. }
  193. this.height = this.fileProgressWrapper.offsetHeight;
  194. }
  195. FileProgress.prototype.setProgress = function (percentage) {
  196. this.fileProgressElement.className = "progressContainer blue";
  197. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  198. this.fileProgressElement.childNodes[3].style.width = percentage + "%";
  199. };
  200. FileProgress.prototype.setComplete = function () {
  201. this.fileProgressElement.className = "progressContainer green";
  202. this.fileProgressElement.childNodes[3].className = "progressBarComplete";
  203. this.fileProgressElement.childNodes[3].style.width = "";
  204. };
  205. FileProgress.prototype.setError = function () {
  206. this.fileProgressElement.className = "progressContainer red";
  207. this.fileProgressElement.childNodes[3].className = "progressBarError";
  208. this.fileProgressElement.childNodes[3].style.width = "";
  209. };
  210. FileProgress.prototype.setCancelled = function () {
  211. this.fileProgressElement.className = "progressContainer";
  212. this.fileProgressElement.childNodes[3].className = "progressBarError";
  213. this.fileProgressElement.childNodes[3].style.width = "";
  214. };
  215. FileProgress.prototype.setStatus = function (status) {
  216. this.fileProgressElement.childNodes[2].innerHTML = status;
  217. };
  218. FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
  219. this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
  220. if (swfuploadInstance) {
  221. var fileID = this.fileProgressID;
  222. this.fileProgressElement.childNodes[0].onclick = function () {
  223. swfuploadInstance.cancelUpload(fileID);
  224. return false;
  225. };
  226. }
  227. };