You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1299 lines
67 KiB

2 years ago
  1. /*!
  2. * jQuery.filer
  3. * Copyright (c) 2015 CreativeDream
  4. * Website: https://github.com/CreativeDream/jquery.filer
  5. * Version: 1.0.4 (03-Nov-2015)
  6. * Requires: jQuery v1.7.1 or later
  7. */
  8. (function ($) {
  9. "use strict";
  10. $.fn.filer = function (q) {
  11. return this.each(function (t, r) {
  12. var s = $(r),
  13. b = '.jFiler',
  14. p = $(),
  15. o = $(),
  16. l = $(),
  17. sl = [],
  18. n = $.extend(true, {}, $.fn.filer.defaults, q),
  19. f = {
  20. init: function () {
  21. s.wrap('<div class="jFiler"></div>');
  22. s.prop("jFiler").boxEl = p = s.closest(b);
  23. f._changeInput();
  24. },
  25. _bindInput: function () {
  26. if (n.changeInput && o.size() > 0) {
  27. o.bind("click", f._clickHandler);
  28. }
  29. s.on({
  30. "focus": function () {
  31. o.addClass('focused');
  32. },
  33. "blur": function () {
  34. o.removeClass('focused');
  35. },
  36. "change": function () {
  37. f._onChange();
  38. }
  39. });
  40. if (n.dragDrop) {
  41. (o.length > 0 ? o : s)
  42. .bind("drop", f._dragDrop.drop)
  43. .bind("dragover", f._dragDrop.dragEnter)
  44. .bind("dragleave", f._dragDrop.dragLeave);
  45. }
  46. if (n.uploadFile && n.clipBoardPaste) {
  47. $(window)
  48. .on("paste", f._clipboardPaste);
  49. }
  50. },
  51. _unbindInput: function () {
  52. if (n.changeInput && o.size() > 0) {
  53. o.unbind("click", f._clickHandler);
  54. }
  55. },
  56. _clickHandler: function () {
  57. s.click();
  58. },
  59. _applyAttrSettings: function () {
  60. var d = ["name", "limit", "maxSize", "extensions", "changeInput", "showThumbs", "appendTo", "theme", "addMore", "excludeName", "files", "options"];
  61. for (var k in d) {
  62. var j = "data-jfiler-" + d[k];
  63. if (f._assets.hasAttr(j)) {
  64. switch (d[k]) {
  65. case "changeInput":
  66. case "showThumbs":
  67. case "addMore":
  68. n[d[k]] = ["true", "false"].indexOf(s.attr(j)) > -1 ? s.attr(j) === "true" : s.attr(j);
  69. break;
  70. case "extensions":
  71. n[d[k]] = s.attr(j)
  72. .replace(/ /g, '')
  73. .split(",");
  74. break;
  75. case "files":
  76. case "options":
  77. n[d[k]] = JSON.parse(s.attr(j));
  78. break;
  79. default:
  80. n[d[k]] = s.attr(j);
  81. }
  82. s.removeAttr(j);
  83. }
  84. }
  85. },
  86. _changeInput: function () {
  87. f._applyAttrSettings();
  88. n.beforeRender !== null && typeof n.beforeRender === "function" ? n.beforeRender(p, s) : null;
  89. if (n.theme) {
  90. p.addClass('jFiler-theme-' + n.theme);
  91. }
  92. if (s.get(0)
  93. .tagName.toLowerCase() !== "input" && s.get(0)
  94. .type !== "file") {
  95. o = s;
  96. s = $("<input type=\"file\" name=\"" + n.name + "\" />");
  97. s.css({
  98. position: "absolute",
  99. left: "-9999px",
  100. top: "-9999px",
  101. "z-index": "-9999"
  102. });
  103. p.prepend(s);
  104. f._isGn = s;
  105. } else {
  106. if (n.changeInput) {
  107. switch (typeof n.changeInput) {
  108. case "boolean"://╠common.ChooseFiles⇒請選擇文件╣╠common.ChooseFilesToUpload⇒選擇要上傳的文件╣
  109. o = $('<div class="jFiler-input"><div class="jFiler-input-caption"><span data-i18n="common.ChooseFilesToUpload">' + n.captions.feedback + '</span></div><div class="jFiler-input-button" data-i18n="common.ChooseFiles">' + n.captions.button + '</div></div>"');
  110. break;
  111. case "string":
  112. case "object":
  113. o = $(n.changeInput);
  114. break;
  115. case "function":
  116. o = $(n.changeInput(p, s, n));
  117. break;
  118. }
  119. s.after(o);
  120. s.css({
  121. position: "absolute",
  122. left: "-9999px",
  123. top: "-9999px",
  124. "z-index": "-9999"
  125. });
  126. }
  127. }
  128. s.prop("jFiler").newInputEl = o;
  129. if (!n.limit || (n.limit && n.limit >= 2)) {
  130. s.attr("multiple", "multiple");
  131. s.attr("name")
  132. .slice(-2) !== "[]" ? s.attr("name", s.attr("name") + "[]") : null;
  133. }
  134. f._bindInput();
  135. if (n.files) {
  136. f._append(false, {
  137. files: n.files
  138. });
  139. }
  140. n.afterRender !== null && typeof n.afterRender === "function" ? n.afterRender(l, p, o, s) : null;
  141. },
  142. _clear: function () {
  143. f.files = null;
  144. s.prop("jFiler")
  145. .files = null;
  146. if (!n.uploadFile && !n.addMore) {
  147. f._reset();
  148. }
  149. f._set('feedback', (f._itFl && f._itFl.length > 0 ? f._itFl.length + ' ' + n.captions.feedback2 : n.captions.feedback));
  150. n.onEmpty !== null && typeof n.onEmpty === "function" ? n.onEmpty(p, o, s) : null;
  151. },
  152. _reset: function (a) {
  153. if (!a) {
  154. if (!n.uploadFile && n.addMore) {
  155. for (var i = 0; i < sl.length; i++) {
  156. sl[i].remove();
  157. }
  158. sl = [];
  159. f._unbindInput();
  160. if (f._isGn) {
  161. s = f._isGn;
  162. } else {
  163. s = $(r);
  164. }
  165. f._bindInput();
  166. }
  167. f._set('input', '');
  168. }
  169. f._itFl = [];
  170. f._itFc = null;
  171. f._ajFc = 0;
  172. s.prop("jFiler")
  173. .files_list = f._itFl;
  174. s.prop("jFiler")
  175. .current_file = f._itFc;
  176. if (!f._prEr) {
  177. f._itFr = [];
  178. p.find("input[name^='jfiler-items-exclude-']:hidden")
  179. .remove();
  180. }
  181. l.fadeOut("fast", function () {
  182. $(this)
  183. .remove();
  184. });
  185. s.prop("jFiler").listEl = l = $();
  186. },
  187. _set: function (element, value) {
  188. switch (element) {
  189. case 'input':
  190. s.val("");
  191. break;
  192. case 'feedback':
  193. if (o.length > 0) {
  194. o.find('.jFiler-input-caption span')
  195. .html(value);
  196. }
  197. break;
  198. }
  199. },
  200. _filesCheck: function () {
  201. var s = 0;
  202. if (n.limit && f.files.length + f._itFl.length > n.limit) {
  203. layer.alert(f._assets.textParse(n.captions.errors.filesLimit));
  204. return false;
  205. }
  206. for (var t = 0; t < f.files.length; t++) {
  207. var x = f.files[t].name.split(".")
  208. .pop()
  209. .toLowerCase(),
  210. file = f.files[t],
  211. m = {
  212. name: file.name,
  213. size: file.size,
  214. description: file.description || '',
  215. fileid: file.fileid || '',
  216. size2: f._assets.bytesToSize(file.size),
  217. type: file.type,
  218. ext: x
  219. };
  220. if (n.extensions !== null && $.inArray(x, n.extensions) === -1) {
  221. layer.alert(f._assets.textParse(n.captions.errors.filesType, m));
  222. break;
  223. }
  224. if (n.maxSize !== null && f.files[t].size > n.maxSize * 1048576) {
  225. layer.alert(f._assets.textParse(n.captions.errors.filesSize, m));
  226. return false;
  227. //break;
  228. }
  229. if (file.size === 4096 && file.type.length === 0) {
  230. break;
  231. }
  232. s += f.files[t].size;
  233. }
  234. if (n.maxSize !== null && s >= Math.round(n.maxSize * 1048576)) {
  235. layer.alert(f._assets.textParse(n.captions.errors.filesSizeAll));
  236. return false;
  237. }
  238. if (n.addMore || n.uploadFile) {
  239. var _m = f._itFl.filter(function (a, b) {
  240. if (a.file.name === file.name && a.file.size === file.size && a.file.type === file.type && (file.lastModified ? a.file.lastModified === file.lastModified : true)) {
  241. return true;
  242. }
  243. });
  244. if (_m.length > 0) {
  245. return false;
  246. }
  247. }
  248. return true;
  249. },
  250. _thumbCreator: {
  251. create: function (i) {
  252. var file = f.files[i],
  253. id = f._itFc ? f._itFc.id : i,
  254. name = file.name,
  255. description = file.description || '',
  256. fileid = file.fileid || '',
  257. size = file.size,
  258. type = file.type.split("/", 1)
  259. .toString()
  260. .toLowerCase(),
  261. ext = name.indexOf(".") !== -1 ? name.split(".")
  262. .pop()
  263. .toLowerCase() : "",
  264. progressBar = n.uploadFile ? '<div class="jFiler-jProgressBar">' + n.templates.progressBar + '</div>' : '',
  265. opts = {
  266. id: id,
  267. name: name,
  268. size: size,
  269. description: description,
  270. fileid: fileid,
  271. size2: f._assets.bytesToSize(size),
  272. type: type,
  273. extension: ext,
  274. icon: f._assets.getIcon(ext, type),
  275. icon2: f._thumbCreator.generateIcon({
  276. type: type,
  277. extension: ext
  278. }),
  279. image: '<div class="jFiler-item-thumb-image fi-loading"></div>',
  280. progressBar: progressBar,
  281. _appended: file._appended
  282. },
  283. html = "";
  284. if (file.opts) {
  285. opts = $.extend({}, file.opts, opts);
  286. }
  287. html = $(f._thumbCreator.renderContent(opts))
  288. .attr("data-jfiler-index", id);
  289. html.get(0)
  290. .jfiler_id = id;
  291. f._thumbCreator.renderFile(file, html, opts);
  292. if (file.forList) {
  293. return html;
  294. }
  295. f._itFc.html = html;
  296. html.hide()[n.templates.itemAppendToEnd ? "appendTo" : "prependTo"](l.find(n.templates._selectors.list))
  297. .show();
  298. if (!file._appended) {
  299. f._onSelect(i);
  300. }
  301. },
  302. renderContent: function (opts) {
  303. return f._assets.textParse((opts._appended ? n.templates.itemAppend : n.templates.item), opts);
  304. },
  305. renderFile: function (file, html, opts) {
  306. if (html.find('.jFiler-item-thumb-image')
  307. .size() === 0) {
  308. return false;
  309. }
  310. if (file.file && opts.type === "image") {
  311. var g = '<img src="' + file.file + '" draggable="false" />',
  312. m = html.find('.jFiler-item-thumb-image.fi-loading');
  313. $(g)
  314. .error(function () {
  315. g = f._thumbCreator.generateIcon(opts);
  316. html.addClass('jFiler-no-thumbnail');
  317. m.removeClass('fi-loading')
  318. .html(g);
  319. })
  320. .load(function () {
  321. m.removeClass('fi-loading')
  322. .html(g);
  323. });
  324. return true;
  325. }
  326. if (window.File && window.FileList && window.FileReader && opts.type === "image" && opts.size < 6e+6) {
  327. var y = new FileReader;
  328. y.onload = function (e) {
  329. var g = '<img src="' + e.target.result + '" draggable="false" />',
  330. m = html.find('.jFiler-item-thumb-image.fi-loading');
  331. $(g)
  332. .error(function () {
  333. g = f._thumbCreator.generateIcon(opts);
  334. html.addClass('jFiler-no-thumbnail');
  335. m.removeClass('fi-loading')
  336. .html(g);
  337. })
  338. .load(function () {
  339. m.removeClass('fi-loading')
  340. .html(g);
  341. });
  342. };
  343. y.readAsDataURL(file);
  344. } else {
  345. var _g = f._thumbCreator.generateIcon(opts),
  346. _m = html.find('.jFiler-item-thumb-image.fi-loading');
  347. html.addClass('jFiler-no-thumbnail');
  348. _m.removeClass('fi-loading')
  349. .html(_g);
  350. }
  351. },
  352. generateIcon: function (obj) {
  353. var m = new Array(3);
  354. if (obj && obj.type && obj.extension) {
  355. switch (obj.type) {
  356. case "image":
  357. m[0] = "f-image";
  358. m[1] = "<i class=\"icon-jfi-file-image\"></i>"
  359. break;
  360. case "video":
  361. m[0] = "f-video";
  362. m[1] = "<i class=\"icon-jfi-file-video\"></i>"
  363. break;
  364. case "audio":
  365. m[0] = "f-audio";
  366. m[1] = "<i class=\"icon-jfi-file-audio\"></i>"
  367. break;
  368. default:
  369. m[0] = "f-file f-file-ext-" + obj.extension;
  370. m[1] = obj.extension.length > 0 ? "." + obj.extension : "";
  371. m[2] = 1;
  372. }
  373. } else {
  374. m[0] = "f-file";
  375. m[1] = obj.extension && obj.extension.length > 0 ? "." + obj.extension : "";
  376. m[2] = 1;
  377. }
  378. var el = '<span class="jFiler-icon-file ' + m[0] + '">' + m[1] + '</span>';
  379. if (m[2] === 1) {
  380. var c = f._assets.text2Color(obj.extension);
  381. if (c) {
  382. var j = $(el)
  383. .appendTo("body"),
  384. h = j.css("box-shadow");
  385. h = c + h.substring(h.replace(/^.*(rgba?\([^)]+\)).*$/, '$1')
  386. .length, h.length);
  387. j.css({
  388. '-webkit-box-shadow': h,
  389. '-moz-box-shadow': h,
  390. 'box-shadow': h
  391. })
  392. .attr('style', '-webkit-box-shadow: ' + h + '; -moz-box-shadow: ' + h + '; box-shadow: ' + h + ';');
  393. el = j.prop('outerHTML');
  394. j.remove();
  395. }
  396. }
  397. return el;
  398. },
  399. _box: function (params) {
  400. if (n.beforeShow !== null && typeof n.beforeShow === "function" ? !n.beforeShow(f.files, l, p, o, s) : false) {
  401. return false;
  402. }
  403. if (l.length < 1) {
  404. var appendTo;
  405. if (n.appendTo) {
  406. appendTo = $(n.appendTo);
  407. } else {
  408. appendTo = p;
  409. }
  410. appendTo.find('.jFiler-items')
  411. .remove();
  412. l = $('<div class="jFiler-items jFiler-row"></div>');
  413. s.prop("jFiler").listEl = l;
  414. l.append(f._assets.textParse(n.templates.box))
  415. .appendTo(appendTo);
  416. l.on('click', n.templates._selectors.remove, function (e) {
  417. e.preventDefault();
  418. var that = this;
  419. if ($(that).hasClass('icon-jfi-trash')) {
  420. layer.confirm(i18next.t(n.captions.removeConfirmation), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  421. f._remove(params ? params.remove.event : e, params ? params.remove.el : $(that).closest(n.templates._selectors.item));
  422. layer.close(index);
  423. });
  424. }
  425. else if ($(that).hasClass('icon-jfi-download-o')) {
  426. f._download(params ? params.remove.el : $(that).closest(n.templates._selectors.item));
  427. }
  428. else if ($(that).hasClass('icon-jfi-pencil')) {
  429. f._edit(params ? params.remove.el : $(that).closest(n.templates._selectors.item));
  430. }
  431. });
  432. }
  433. for (var i = 0; i < f.files.length; i++) {
  434. if (!f.files[i]._appended) f.files[i]._choosed = true;
  435. f._addToMemory(i);
  436. f._thumbCreator.create(i);
  437. }
  438. }
  439. },
  440. _upload: function (i) {
  441. var el = f._itFc.html,
  442. formData = new FormData();
  443. formData.append(s.attr('name'), f._itFc.file, (f._itFc.file.name ? f._itFc.file.name : false));
  444. if (n.uploadFile.data !== null && $.isPlainObject(n.uploadFile.data)) {
  445. for (var k in n.uploadFile.data) {
  446. formData.append(k, n.uploadFile.data[k]);
  447. }
  448. }
  449. f._ajax.send(el, formData, f._itFc);
  450. },
  451. _ajax: {
  452. send: function (el, formData, c) {
  453. c.ajax = $.ajax({
  454. url: n.uploadFile.url,
  455. data: formData,
  456. type: n.uploadFile.type,
  457. enctype: n.uploadFile.enctype,
  458. xhr: function () {
  459. var myXhr = $.ajaxSettings.xhr();
  460. if (myXhr.upload) {
  461. myXhr.upload.addEventListener("progress", function (e) {
  462. f._ajax.progressHandling(e, el);
  463. }, false);
  464. }
  465. return myXhr;
  466. },
  467. complete: function (jqXHR, textStatus) {
  468. c.ajax = false;
  469. f._ajFc++;
  470. if (f._ajFc >= f.files.length) {
  471. f._ajFc = 0;
  472. n.uploadFile.onComplete !== null && typeof n.uploadFile.onComplete === "function" ? n.uploadFile.onComplete(l, p, o, s, jqXHR, textStatus) : null;
  473. }
  474. },
  475. beforeSend: function (jqXHR, settings) {
  476. return n.uploadFile.beforeSend !== null && typeof n.uploadFile.beforeSend === "function" ? n.uploadFile.beforeSend(el, l, p, o, s, c.id, jqXHR, settings) : true;
  477. },
  478. success: function (data, textStatus, jqXHR) {
  479. c.uploaded = true;
  480. n.uploadFile.success !== null && typeof n.uploadFile.success === "function" ? n.uploadFile.success(data, el, l, p, o, s, c.id, textStatus, jqXHR) : null;
  481. },
  482. error: function (jqXHR, textStatus, errorThrown) {
  483. c.uploaded = false;
  484. n.uploadFile.error !== null && typeof n.uploadFile.error === "function" ? n.uploadFile.error(el, l, p, o, s, c.id, jqXHR, textStatus, errorThrown) : null;
  485. },
  486. statusCode: n.uploadFile.statusCode,
  487. cache: false,
  488. contentType: false,
  489. processData: false
  490. });
  491. return c.ajax;
  492. },
  493. progressHandling: function (e, el) {
  494. if (e.lengthComputable) {
  495. var t = Math.round(e.loaded * 100 / e.total)
  496. .toString();
  497. n.uploadFile.onProgress !== null && typeof n.uploadFile.onProgress === "function" ? n.uploadFile.onProgress(t, el, l, p, o, s) : null;
  498. el.find('.jFiler-jProgressBar')
  499. .find(n.templates._selectors.progressBar)
  500. .css("width", t + "%");
  501. }
  502. }
  503. },
  504. _dragDrop: {
  505. dragEnter: function (e) {
  506. e.preventDefault();
  507. e.stopPropagation();
  508. p.addClass('dragged');
  509. f._set('feedback', n.captions.drop);
  510. n.dragDrop.dragEnter !== null && typeof n.dragDrop.dragEnter === "function" ? n.dragDrop.dragEnter(e, o, s, p) : null;
  511. },
  512. dragLeave: function (e) {
  513. e.preventDefault();
  514. e.stopPropagation();
  515. if (!f._dragDrop._dragLeaveCheck(e)) {
  516. return false;
  517. }
  518. p.removeClass('dragged');
  519. f._set('feedback', n.captions.feedback);
  520. n.dragDrop.dragLeave !== null && typeof n.dragDrop.dragLeave === "function" ? n.dragDrop.dragLeave(e, o, s, p) : null;
  521. },
  522. drop: function (e) {
  523. e.preventDefault();
  524. p.removeClass('dragged');
  525. if (!e.originalEvent.dataTransfer.files || e.originalEvent.dataTransfer.files.length <= 0) {
  526. return;
  527. }
  528. f._set('feedback', n.captions.feedback);
  529. f._onChange(e, e.originalEvent.dataTransfer.files);
  530. n.dragDrop.drop !== null && typeof n.dragDrop.drop === "function" ? n.dragDrop.drop(e.originalEvent.dataTransfer.files, e, o, s, p) : null;
  531. },
  532. _dragLeaveCheck: function (e) {
  533. var related = e.relatedTarget,
  534. inside = false;
  535. if (related !== o) {
  536. if (related) {
  537. inside = $.contains(o, related);
  538. }
  539. if (inside) {
  540. return false;
  541. }
  542. }
  543. return true;
  544. }
  545. },
  546. _clipboardPaste: function (e, fromDrop) {
  547. if (!fromDrop && (!e.originalEvent.clipboardData && !e.originalEvent.clipboardData.items)) {
  548. return;
  549. }
  550. if (fromDrop && (!e.originalEvent.dataTransfer && !e.originalEvent.dataTransfer.items)) {
  551. return;
  552. }
  553. if (f._clPsePre) {
  554. return;
  555. }
  556. var items = (fromDrop ? e.originalEvent.dataTransfer.items : e.originalEvent.clipboardData.items),
  557. b64toBlob = function (b64Data, contentType, sliceSize) {
  558. contentType = contentType || '';
  559. sliceSize = sliceSize || 512;
  560. var byteCharacters = atob(b64Data);
  561. var byteArrays = [];
  562. for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  563. var slice = byteCharacters.slice(offset, offset + sliceSize);
  564. var byteNumbers = new Array(slice.length);
  565. for (var i = 0; i < slice.length; i++) {
  566. byteNumbers[i] = slice.charCodeAt(i);
  567. }
  568. var byteArray = new Uint8Array(byteNumbers);
  569. byteArrays.push(byteArray);
  570. }
  571. var blob = new Blob(byteArrays, {
  572. type: contentType
  573. });
  574. return blob;
  575. };
  576. if (items) {
  577. for (var i = 0; i < items.length; i++) {
  578. if (items[i].type.indexOf("image") !== -1 || items[i].type.indexOf("text/uri-list") !== -1) {
  579. if (fromDrop) {
  580. try {
  581. window.atob(e.originalEvent.dataTransfer.getData("text/uri-list")
  582. .toString()
  583. .split(',')[1]);
  584. } catch (e) {
  585. return;
  586. }
  587. }
  588. var blob = fromDrop ? b64toBlob(e.originalEvent.dataTransfer.getData("text/uri-list")
  589. .toString()
  590. .split(',')[1], "image/png") : items[i].getAsFile();
  591. try {
  592. blob.name = Math.random()
  593. .toString(36)
  594. .substring(5);
  595. blob.name += blob.type.indexOf("/") !== -1 ? "." + blob.type.split("/")[1].toString()
  596. .toLowerCase() : ".png";
  597. f._onChange(e, [blob]);
  598. f._clPsePre = setTimeout(function () {
  599. delete f._clPsePre;
  600. }, 1000);
  601. } catch (e) { }
  602. }
  603. }
  604. }
  605. },
  606. _onSelect: function (i) {
  607. if (n.uploadFile && !$.isEmptyObject(n.uploadFile)) {
  608. f._upload(i);
  609. }
  610. n.onSelect !== null && typeof n.onSelect === "function" ? n.onSelect(f.files[i], f._itFc.html, l, p, o, s) : null;
  611. if (i + 1 >= f.files.length) {
  612. n.afterShow !== null && typeof n.afterShow === "function" ? n.afterShow(l, p, o, s) : null;
  613. }
  614. },
  615. _onChange: function (e, d) {
  616. if (!d) {
  617. if (!s.get(0)
  618. .files || typeof s.get(0)
  619. .files === "undefined" || s.get(0)
  620. .files.length === 0) {
  621. if (!n.uploadFile && !n.addMore) {
  622. f._set('input', '');
  623. f._clear();
  624. }
  625. return false;
  626. }
  627. f.files = s.get(0).files;
  628. } else {
  629. if (!d || d.length === 0) {
  630. f._set('input', '');
  631. f._clear();
  632. return false;
  633. }
  634. f.files = d;
  635. }
  636. if (!n.uploadFile && !n.addMore) {
  637. f._reset(true);
  638. }
  639. s.prop("jFiler").files = f.files;
  640. if (!f._filesCheck() || (n.beforeSelect !== null && typeof n.beforeSelect === "function" ? !n.beforeSelect(f.files, l, p, o, s) : false)) {
  641. f._set('input', '');
  642. f._clear();
  643. return false;
  644. }
  645. f._set('feedback', f.files.length + f._itFl.length + ' ' + n.captions.feedback2);
  646. if (n.showThumbs) {
  647. f._thumbCreator._box();
  648. } else {
  649. for (var i = 0; i < f.files.length; i++) {
  650. f.files[i]._choosed = true;
  651. f._addToMemory(i);
  652. f._onSelect(i);
  653. }
  654. }
  655. if (!n.uploadFile && n.addMore) {
  656. var elem = $('<input type="file" />');
  657. var attributes = s.prop("attributes");
  658. $.each(attributes, function () {
  659. elem.attr(this.name, this.value);
  660. });
  661. s.after(elem);
  662. f._unbindInput();
  663. sl.push(elem);
  664. s = elem;
  665. f._bindInput();
  666. }
  667. },
  668. _append: function (e, data) {
  669. var files = (!data ? false : data.files);
  670. if (!files || files.length <= 0) {
  671. return;
  672. }
  673. f.files = files;
  674. s.prop("jFiler")
  675. .files = f.files;
  676. if (n.showThumbs) {
  677. for (var i = 0; i < f.files.length; i++) {
  678. f.files[i]._appended = true;
  679. }
  680. f._thumbCreator._box();
  681. }
  682. },
  683. _getList: function (e, data) {
  684. var files = (!data ? false : data.files);
  685. if (!files || files.length <= 0) {
  686. return;
  687. }
  688. f.files = files;
  689. s.prop("jFiler")
  690. .files = f.files;
  691. if (n.showThumbs) {
  692. var returnData = [];
  693. for (var i = 0; i < f.files.length; i++) {
  694. f.files[i].forList = true;
  695. returnData.push(f._thumbCreator.create(i));
  696. }
  697. if (data.callback) {
  698. data.callback(returnData, l, p, o, s);
  699. }
  700. }
  701. },
  702. _retryUpload: function (e, data) {
  703. var id = parseInt(typeof data === "object" ? data.attr("data-jfiler-index") : data),
  704. obj = f._itFl.filter(function (value, key) {
  705. return value.id === id;
  706. });
  707. if (obj.length > 0) {
  708. if (n.uploadFile && !$.isEmptyObject(n.uploadFile) && !obj[0].uploaded) {
  709. f._itFc = obj[0];
  710. s.prop("jFiler")
  711. .current_file = f._itFc;
  712. f._upload(id);
  713. return true;
  714. }
  715. } else {
  716. return false;
  717. }
  718. },
  719. _remove: function (e, el) {
  720. if (el.binded) {
  721. if (typeof el.data.id !== "undefined") {
  722. el = l.find(n.templates._selectors.item + "[data-jfiler-index='" + el.data.id + "']");
  723. if (el.size() === 0) {
  724. return false;
  725. }
  726. }
  727. if (el.data.el) {
  728. el = el.data.el;
  729. }
  730. }
  731. var attrId = el.get(0)
  732. .jfiler_id || el.attr('data-jfiler-index'),
  733. id = null,
  734. excl_input = function (id) {
  735. var input = p.find("input[name^='jfiler-items-exclude-']:hidden")
  736. .first(),
  737. item = f._itFl[id],
  738. val = [];
  739. if (input.size() === 0) {
  740. input = $('<input type="hidden" name="jfiler-items-exclude-' + (n.excludeName ? n.excludeName : (s.attr("name")
  741. .slice(-2) !== "[]" ? s.attr("name") : s.attr("name")
  742. .substring(0, s.attr("name")
  743. .length - 2)) + "-" + t) + '">');
  744. input.appendTo(p);
  745. }
  746. if (item.file._choosed || item.file._appended || item.uploaded) {
  747. f._prEr = true;
  748. f._itFr.push(item);
  749. if (n.addMore) {
  750. var current_input = item.input,
  751. count_same_input = 0;
  752. f._itFl.filter(function (val, index) {
  753. if (val.file._choosed && val.input.get(0) === current_input.get(0)) count_same_input++;
  754. });
  755. if (count_same_input === 1) {
  756. f._itFr = f._itFr.filter(function (val, index) {
  757. return val.file._choosed ? val.input.get(0) !== current_input.get(0) : true;
  758. });
  759. current_input.val("");
  760. f._prEr = false;
  761. }
  762. }
  763. for (var i = 0; i < f._itFr.length; i++) {
  764. val.push(f._itFr[i].file.name);
  765. }
  766. val = JSON.stringify(val);
  767. input.val(val);
  768. }
  769. },
  770. callback = function (el, id) {
  771. excl_input(id);
  772. f._itFl.splice(id, 1);
  773. if (f._itFl.length < 1) {
  774. f._reset();
  775. f._clear();
  776. } else {
  777. f._set('feedback', f._itFl.length + ' ' + n.captions.feedback2);
  778. }
  779. el.fadeOut("fast", function () {
  780. $(this).remove();
  781. });
  782. };
  783. $.each(f._itFl, function (idx,val) {
  784. if (val.id == attrId) {
  785. id = idx;
  786. }
  787. })
  788. //for (var key in f._itFl) {
  789. // if (key === 'length' || !f._itFl.hasOwnProperty(key)) continue;
  790. // id = attrId;
  791. // //if (f._itFl[key].id.toString() === attrId) {
  792. // // id = attrId;
  793. // //}
  794. //}
  795. if (!f._itFl.hasOwnProperty(id)) {
  796. return false;
  797. }
  798. if (f._itFl[id].ajax) {
  799. f._itFl[id].ajax.abort();
  800. callback(el, id);
  801. return;
  802. }
  803. n.onRemove !== null && typeof n.onRemove === "function" ? n.onRemove(el, f._itFl[id].file, id, l, p, o, s) : null;
  804. callback(el, id);
  805. },
  806. _addToMemory: function (i) {
  807. f._itFl.push({
  808. id: f._itFl.length,
  809. file: f.files[i],
  810. html: $(),
  811. ajax: false,
  812. uploaded: false
  813. });
  814. if (n.addMore && !f.files[i]._appended) f._itFl[f._itFl.length - 1].input = s;
  815. f._itFc = f._itFl[f._itFl.length - 1];
  816. s.prop("jFiler")
  817. .files_list = f._itFl;
  818. s.prop("jFiler")
  819. .current_file = f._itFc;
  820. },
  821. _assets: {
  822. bytesToSize: function (bytes) {
  823. if (bytes === 0) return '0 Byte';
  824. var k = 1000;
  825. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  826. var i = Math.floor(Math.log(bytes) / Math.log(k));
  827. return (bytes / Math.pow(k, i))
  828. .toPrecision(3) + ' ' + sizes[i];
  829. },
  830. hasAttr: function (attr, el) {
  831. var _el = !el ? s : el,
  832. a = _el.attr(attr);
  833. if (!a || typeof a === "undefined") {
  834. return false;
  835. } else {
  836. return true;
  837. }
  838. },
  839. getIcon: function (ext, type) {
  840. var types = ["audio", "image", "text", "video"];
  841. if ($.inArray(type, types) > -1) {
  842. return '<i class="icon-jfi-file-' + type + ' jfi-file-ext-' + ext + '"></i>';
  843. }
  844. return '<i class="icon-jfi-file-o jfi-file-type-' + type + ' jfi-file-ext-' + ext + '"></i>';
  845. },
  846. textParse: function (text, opts) {
  847. opts = $.extend({}, {
  848. limit: n.limit,
  849. maxSize: n.maxSize,
  850. extensions: n.extensions ? n.extensions.join(',') : null
  851. }, opts && $.isPlainObject(opts) ? opts : {}, n.options);
  852. switch (typeof text) {
  853. case "string":
  854. return text.replace(/\{\{fi-(.*?)\}\}/g, function (match, a) {
  855. a = a.replace(/ /g, '');
  856. if (a.match(/(.*?)\|limitTo\:(\d+)/)) {
  857. return a.replace(/(.*?)\|limitTo\:(\d+)/, function (match, a, b) {
  858. var _a = opts[a] ? opts[a] : "",
  859. str = a.substring(0, b);
  860. str = _a.length > str.length ? str.substring(0, str.length - 3) + "..." : str;
  861. return str;
  862. });
  863. } else {
  864. return opts[a] ? opts[a] : "";
  865. }
  866. });
  867. case "function":
  868. return text(opts);
  869. default:
  870. return text;
  871. }
  872. },
  873. text2Color: function (str) {
  874. str = str === 'xls' ? 'xlsx' : str;
  875. if (!str || str.length === 0) {
  876. return false;
  877. }
  878. var i, hash, colour;
  879. for (i = 0, hash = 0; i < str.length; hash = str.charCodeAt(i++) + ((hash << 5) - hash));
  880. for (i = 0, colour = "#"; i < 3; colour += ("00" + ((hash >> i++ * 2) & 0xFF)
  881. .toString(16))
  882. .slice(-2));
  883. return colour;
  884. }
  885. },
  886. _download: function (el) {
  887. var attrId = el.get(0)
  888. .jfiler_id || el.attr('data-jfiler-index'),
  889. id = null;
  890. for (var key in f._itFl) {
  891. if (key === 'length' || !f._itFl.hasOwnProperty(key)) continue;
  892. if (f._itFl[key].id.toString() === attrId) {
  893. id = key;
  894. }
  895. }
  896. n.onDownload(f._itFl[attrId].file);
  897. },
  898. _edit: function (el) {
  899. var attrId = el.get(0)
  900. .jfiler_id || el.attr('data-jfiler-index'),
  901. id = null;
  902. for (var key in f._itFl) {
  903. if (key === 'length' || !f._itFl.hasOwnProperty(key)) continue;
  904. if (f._itFl[key].id.toString() === attrId) {
  905. id = key;
  906. }
  907. }
  908. if (n.onEdit) {
  909. n.onEdit(f._itFl[id].file, el);
  910. }
  911. },
  912. files: null,
  913. _itFl: [],
  914. _itFc: null,
  915. _itFr: [],
  916. _ajFc: 0,
  917. _prEr: false
  918. };
  919. s.prop("jFiler", {
  920. options: n,
  921. listEl: l,
  922. boxEl: p,
  923. newInputEl: o,
  924. inputEl: s,
  925. files: f.files,
  926. files_list: f._itFl,
  927. current_file: f._itFc,
  928. append: function (data) {
  929. return f._append(false, {
  930. files: [data]
  931. });
  932. },
  933. remove: function (id) {
  934. f._remove(null, {
  935. binded: true,
  936. data: {
  937. id: id
  938. }
  939. });
  940. return true;
  941. },
  942. reset: function () {
  943. f._reset();
  944. f._clear();
  945. return true;
  946. },
  947. retry: function (data) {
  948. return f._retryUpload(data);
  949. }
  950. }).on("filer.append", function (e, data) {
  951. f._append(e, data)
  952. }).on("filer.remove", function (e, data) {
  953. data.binded = true;
  954. f._remove(e, data);
  955. }).on("filer.reset", function (e) {
  956. f._reset();
  957. f._clear();
  958. return true;
  959. }).on("filer.generateList", function (e, data) {
  960. return f._getList(e, data)
  961. }).on("filer.retry", function (e, data) {
  962. return f._retryUpload(e, data)
  963. });
  964. f.init();
  965. return this;
  966. });
  967. };
  968. $.fn.filer.defaults = {
  969. limit: null,
  970. maxSize: null,
  971. extensions: null,
  972. changeInput: true,
  973. edit: true,
  974. showThumbs: false,
  975. appendTo: null,
  976. theme: 'default',
  977. templates: {
  978. box: '<ul class="jFiler-items-list jFiler-items-default"></ul>',
  979. item: '<li class="jFiler-item"><div class="jFiler-item-container"><div class="jFiler-item-inner"><div class="jFiler-item-icon pull-left">{{fi-icon}}</div><div class="jFiler-item-info pull-left"><div class="jFiler-item-title" title="{{fi-name}}">{{fi-name | limitTo:30}}</div><div class="jFiler-item-others"><span>size: {{fi-size2}}</span><span>type: {{fi-extension}}</span><span class="jFiler-item-status">{{fi-progressBar}}</span></div><div class="jFiler-item-assets"><ul class="list-inline"><li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li></ul></div></div></div></div></li>',
  980. itemAppend: '<li class="jFiler-item"><div class="jFiler-item-container"><div class="jFiler-item-inner"><div class="jFiler-item-icon pull-left">{{fi-icon}}</div><div class="jFiler-item-info pull-left"><div class="jFiler-item-title">{{fi-name | limitTo:35}}</div><div class="jFiler-item-others"><span>size: {{fi-size2}}</span><span>type: {{fi-extension}}</span><span class="jFiler-item-status"></span></div><div class="jFiler-item-assets"><ul class="list-inline"><li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li></ul></div></div></div></div></li>',
  981. progressBar: '<div class="bar"></div>',
  982. itemAppendToEnd: false,
  983. removeConfirmation: true,
  984. _selectors: {
  985. list: '.jFiler-items-list',
  986. item: '.jFiler-item',
  987. progressBar: '.bar',
  988. remove: '.jFiler-item-trash-action'
  989. }
  990. },
  991. files: null,
  992. uploadFile: null,
  993. dragDrop: null,
  994. addMore: false,
  995. clipBoardPaste: true,
  996. excludeName: null,
  997. beforeRender: null,
  998. afterRender: null,
  999. beforeShow: null,
  1000. beforeSelect: null,
  1001. onSelect: null,
  1002. afterShow: null,
  1003. onRemove: null,
  1004. onEmpty: null,
  1005. options: null,
  1006. captions: {
  1007. button: "Choose Files",
  1008. feedback: "Choose files To Upload",
  1009. feedback2: "<span data-i18n='common.filesWereChosen'>files were chosen</span>",//╠common.filesWereChosen⇒個文件選中╣
  1010. drop: "Drop file here to Upload",
  1011. removeConfirmation: 'common.IsRemoveFile',// ╠common.IsRemoveFile⇒确实要删除此文件吗?╣
  1012. errors: {
  1013. filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
  1014. filesType: "Only Images are allowed to be uploaded.",
  1015. filesSize: "{{fi-name}} 檔案大小超過 {{fi-maxSize}} MB.",
  1016. //filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
  1017. filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
  1018. }
  1019. }
  1020. }
  1021. })(jQuery);
  1022. $(function () {
  1023. /**
  1024. * 註冊上傳附件
  1025. * @param {Object} option 必要的參數
  1026. */
  1027. window.fnUploadRegister = function (option) {
  1028. option.edit = option.edit !== false ? true : false;
  1029. var defultoption = {
  1030. limit: 1000,
  1031. //extensions: ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'png'],
  1032. changeInput: '<div class="jFiler-input-dragDrop">+</div>',
  1033. showThumbs: true,
  1034. templates: {
  1035. box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
  1036. item: '<li class="jFiler-item" data-id="{{fi-fileid}}">\
  1037. <div class="jFiler-item-container">\
  1038. <div class="jFiler-item-inner">\
  1039. <div class="jFiler-item-thumb">\
  1040. <div class="jFiler-item-status"></div>\
  1041. <div class="jFiler-item-info">\
  1042. <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
  1043. <span class="jFiler-item-others">{{fi-size2}}</span>\
  1044. </div>\
  1045. {{fi-image}}\
  1046. </div>\
  1047. <div class="jFiler-item-assets jFiler-row">\
  1048. <ul class="list-inline pull-left">\
  1049. <li>{{fi-progressBar}}</li>\
  1050. </ul>\
  1051. <ul class="list-inline pull-right">\
  1052. <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
  1053. </ul>\
  1054. </div>\
  1055. </div>\
  1056. </div>\
  1057. </li>',
  1058. itemAppend: '<li class="jFiler-item" data-id="{{fi-fileid}}">\
  1059. <div class="jFiler-item-container">\
  1060. <div class="jFiler-item-inner">\
  1061. <div class="jFiler-item-thumb">\
  1062. <div class="jFiler-item-status"></div>\
  1063. <div class="jFiler-item-info">\
  1064. <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
  1065. <span class="jFiler-item-others">{{fi-size2}}</span>\
  1066. </div>\
  1067. {{fi-image}}\
  1068. </div>\
  1069. <div class="jFiler-item-assets jFiler-row">\
  1070. <ul class="list-inline pull-left">\
  1071. <li><span class="jFiler-item-others">{{fi-icon}}</span></li>\
  1072. </ul>\
  1073. <ul class="list-inline pull-right">'
  1074. + (option.edit ? '<li><a class="icon-jfi-pencil jFiler-item-trash-action"></a></li>' : '') +
  1075. '<li><a class="icon-jfi-download-o jFiler-item-trash-action"></a></li>\
  1076. <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
  1077. </ul>\
  1078. </div>\
  1079. </div>\
  1080. </div>\
  1081. </li>',
  1082. progressBar: '<div class="bar"></div>',
  1083. itemAppendToEnd: true,
  1084. removeConfirmation: true,
  1085. _selectors: {
  1086. list: '.jFiler-items-list',
  1087. item: '.jFiler-item',
  1088. progressBar: '.bar',
  1089. remove: '.jFiler-item-trash-action'
  1090. }
  1091. },
  1092. dragDrop: {
  1093. dragEnter: null,
  1094. dragLeave: null,
  1095. drop: null,
  1096. },
  1097. uploadFile: {
  1098. url: '/Controller.ashx?action=upload&source=' + (option.folder || 'Common') + '&userid=' + parent.UserID + '&orgid=' + parent.OrgID + '&parentid=' + option.parentid,
  1099. data: null,
  1100. type: 'POST',
  1101. enctype: 'multipart/form-data',
  1102. beforeSend: function () { },
  1103. success: function (data, el) {
  1104. if (option.type && option.type === 'one') {
  1105. $('.jFiler-theme-' + lastoption.theme).find('.jFiler-input-dragDrop').hide();
  1106. }
  1107. var oData = $.parseJSON(data)[0],
  1108. parent = el.attr('data-id', oData.FileID).find(".jFiler-jProgressBar").parent();
  1109. el.find(".jFiler-jProgressBar").fadeOut("slow", function () {
  1110. $("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success</div>").hide().appendTo(parent).fadeIn("slow");
  1111. });
  1112. },
  1113. error: function (el) {
  1114. var parent = el.find(".jFiler-jProgressBar").parent();
  1115. el.find(".jFiler-jProgressBar").fadeOut("slow", function () {
  1116. $("<div class=\"jFiler-item-others text-error\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");
  1117. });
  1118. },
  1119. statusCode: null,
  1120. onProgress: null,
  1121. // Callback fired after all files were uploaded
  1122. onComplete: function (listEl, parentEl, newInputEl, inputEl, jqXHR, textStatus) {
  1123. // callback will go here
  1124. }
  1125. },
  1126. onRemove: function (itemEl, file) {
  1127. var sFileId = file.fileid || itemEl.attr('data-id');
  1128. if (sFileId) {
  1129. DelFile(sFileId).done(function () {
  1130. if (option.type && option.type === 'one') {
  1131. $('.jFiler-theme-' + lastoption.theme).find('.jFiler-input-dragDrop').show();
  1132. }
  1133. });
  1134. }
  1135. },
  1136. onDownload: function (file) {
  1137. DownLoadFile(file.path, file.filename);
  1138. }
  1139. };
  1140. if (option.input) {
  1141. var lastoption = $.extend(true, {}, defultoption, option);
  1142. if (option.type === 'list') {
  1143. lastoption.templates = {
  1144. box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
  1145. item: '<li class="jFiler-item" data-id="{{fi-fileid}}">\
  1146. <div class="jFiler-item-container">\
  1147. <div class="jFiler-item-inner">\
  1148. <div class="jFiler-item-thumb cus-thumb">\
  1149. <div class="jFiler-item-status"></div>\
  1150. <div class="jFiler-item-info">\
  1151. <span class="jFiler-item-others">{{fi-size2}}</span>\
  1152. </div>\
  1153. {{fi-image}}\
  1154. </div>\
  1155. <div class="jFiler-item-assets jFiler-row">\
  1156. <ul class="list-inline pull-left">\
  1157. <li>{{fi-progressBar}}</li>\
  1158. </ul>\
  1159. <ul class="list-inline pull-left">\
  1160. <li>{{fi-name}}</li>\
  1161. </ul>\
  1162. <ul class="list-inline pull-right">\
  1163. <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
  1164. </ul>\
  1165. </div>\
  1166. </div>\
  1167. </div>\
  1168. </li>',
  1169. itemAppend: '<li class="jFiler-item" data-id="{{fi-fileid}}">\
  1170. <div class="jFiler-item-container">\
  1171. <div class="jFiler-item-inner">\
  1172. <div class="jFiler-item-thumb cus-thumb">\
  1173. <div class="jFiler-item-status"></div>\
  1174. <div class="jFiler-item-info">\
  1175. <span class="jFiler-item-others">{{fi-size2}}</span>\
  1176. </div>\
  1177. {{fi-image}}\
  1178. </div>\
  1179. <div class="jFiler-item-assets jFiler-row">\
  1180. <ul class="list-inline pull-left">\
  1181. <li><span class="jFiler-item-others">{{fi-icon}}</span></li>\
  1182. </ul>\
  1183. <ul class="list-inline pull-left file-name">\
  1184. <li>{{fi-name}}</li>\
  1185. <li class="jFiler-item-description">\
  1186. <span class="jFiler-item-title">{{fi-description}}</span>\
  1187. </li>\
  1188. </ul>\
  1189. <ul class="list-inline pull-right">\
  1190. <li><a class="icon-jfi-pencil jFiler-item-trash-action"></a></li>\
  1191. <li><a class="icon-jfi-download-o jFiler-item-trash-action"></a></li>\
  1192. <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
  1193. </ul>\
  1194. </div>\
  1195. </div>\
  1196. </div>\
  1197. </li>',
  1198. progressBar: '<div class="bar"></div>',
  1199. itemAppendToEnd: true,
  1200. removeConfirmation: true,
  1201. _selectors: {
  1202. list: '.jFiler-items-list',
  1203. item: '.jFiler-item',
  1204. progressBar: '.bar',
  1205. remove: '.jFiler-item-trash-action'
  1206. }
  1207. };
  1208. }
  1209. if (option.edit) {
  1210. lastoption.onEdit = function (file, el) {
  1211. EditFile(file, el);
  1212. };
  1213. }
  1214. option.input.filer(lastoption);
  1215. if (option.type && option.type === 'one' && lastoption.files && lastoption.files.length > 0) {
  1216. $('.jFiler-theme-' + lastoption.theme).find('.jFiler-input-dragDrop').hide();
  1217. }
  1218. if (option.type !== 'one') {
  1219. $('.jFiler-theme-' + lastoption.theme).find(".jFiler-items-grid").dragsort({
  1220. dragEnd: function () {
  1221. updFilesOrder(this);
  1222. }
  1223. });
  1224. }
  1225. }
  1226. };
  1227. /**
  1228. * 抓去上傳的附件
  1229. * @param {String} parentid 父層ID
  1230. * @param {Function} callback}文件list
  1231. * @param {Number} flag 標記
  1232. * @return {Object} ajax
  1233. */
  1234. window.fnGetUploadFiles = function (parentid, callback, flag) {
  1235. return g_api.ConnectLite(Service.com, 'GetUploadFiles', {
  1236. ParentID: parentid
  1237. }, function (res) {
  1238. if (res.RESULT) {
  1239. var saFiles = res.DATA.rel,
  1240. files = [];
  1241. $.each(saFiles, function (idx, file) {
  1242. if (file.FileID) {
  1243. var f = {
  1244. fileid: file.FileID,
  1245. name: file.FileName,
  1246. filename: file.FileName.split('.')[0],
  1247. subname: file.SubFileName,
  1248. description: file.Description,
  1249. link: file.Link,
  1250. size: file.FileSize,
  1251. type: file.FileType,
  1252. file: gServerUrl + '/' + file.FilePath,
  1253. path: file.FilePath
  1254. }
  1255. files.push(f);
  1256. }
  1257. });
  1258. if (typeof callback === 'function') {
  1259. callback(files, parentid, flag);
  1260. }
  1261. }
  1262. });
  1263. };
  1264. /**
  1265. * 上傳文件排序
  1266. * @param {Element} dom 當前文件標籤
  1267. */
  1268. window.updFilesOrder = function (dom) {
  1269. var saLis = $(dom).parent('ul').find('li.jFiler-item'),
  1270. saOrders = [],
  1271. oUpdPm = {};
  1272. saLis.each(function (idx, el) {
  1273. $(el).attr('data-jfiler-index', idx);
  1274. var sFileId = $(el).attr('data-id');
  1275. saOrders.push({
  1276. values: { OrderByValue: idx },
  1277. keys: {
  1278. FileID: sFileId
  1279. }
  1280. });
  1281. });
  1282. oUpdPm = {
  1283. files: saOrders
  1284. };
  1285. CallAjax(ComFn.W_Com, ComFn.GetUpd, { Params: oUpdPm });
  1286. };
  1287. });