file.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * @fileoverview
  3. * File 업로드 관련 Source
  4. * Trex.Tool.File - UI,
  5. * Trex.Attacher.File,
  6. * Trex.Attachment.File,
  7. * default configuration를 포함하고 있다.
  8. */
  9. TrexConfig.addTool(
  10. "file",
  11. {
  12. disabledonmobile: _TRUE,
  13. wysiwygonly: _TRUE,
  14. sync: _FALSE,
  15. status: _FALSE
  16. }
  17. );
  18. TrexMessage.addMsg({
  19. '@file.title': "파일"
  20. });
  21. /**
  22. * Trex.Tool.File
  23. * @class
  24. * @extends Trex.Tool
  25. */
  26. Trex.Tool.File = Trex.Class.create({
  27. /** ignore */
  28. $const: {
  29. __Identity: 'file'
  30. },
  31. /** ignore */
  32. $extend: Trex.Tool,
  33. oninitialized: function() {
  34. var _editor = this.editor;
  35. this.weave.bind(this)(
  36. new Trex.Button(this.buttonCfg),
  37. _NULL,
  38. function() {
  39. _editor.getSidebar().getAttacher("file").execute();
  40. }
  41. );
  42. }
  43. });
  44. TrexConfig.addAttacher(
  45. "file",
  46. {
  47. multiple: _TRUE,
  48. multipleuse: _FALSE,
  49. checksize: _TRUE,
  50. boxonly: _FALSE,
  51. wysiwygonly: _FALSE,
  52. features: { left:250, top:65, width:450, height:404 },
  53. popPageUrl: "#host#path/pages/trex/file.html"
  54. },
  55. function(root){
  56. var _config = TrexConfig.getAttacher("file", root);
  57. _config.popPageUrl = TrexConfig.getUrl(_config.popPageUrl);
  58. _config.features = TrexConfig.getPopFeatures(_config.features);
  59. }
  60. );
  61. /**
  62. * Trex.Attacher.File
  63. * @class
  64. * @extends Trex.Attacher
  65. */
  66. Trex.Attacher.File = Trex.Class.create({
  67. /** @ignore */
  68. $const: {
  69. __Identity: 'file'
  70. },
  71. /** @ignore */
  72. $extend: Trex.Attacher,
  73. name: 'file',
  74. title: TXMSG("@file.title"),
  75. canModified: _TRUE,
  76. canResized: _FALSE,
  77. oninitialized: function() {
  78. },
  79. getKey: function(data) {
  80. return data.key || data.attachurl;
  81. },
  82. /**
  83. * data를 editor에 맞게 parsing할때 불리는 methond
  84. * @memberOf Trex.Attacher.File.prototype
  85. * @param {Object} data
  86. */
  87. getDataForEntry: function(data) {
  88. if(!data.dispElId) {
  89. data.dispElId = Trex.Util.getDispElId();
  90. }
  91. var _seq = ((data.tmpSeq)? this.entryBox.syncSeq(data.tmpSeq): this.entryBox.newSeq());
  92. var _ext = data.filename.split(".").pop().toLowerCase();
  93. var _thumburl;
  94. switch(_ext){
  95. case "jpg":
  96. case "gif":
  97. case "png":
  98. case "bmp":
  99. _thumburl = data.attachurl.replace("/attach/", "/thumbnail/");
  100. break;
  101. default :
  102. _thumburl = Trex.Util.thumburl(_ext);
  103. }
  104. var _data = Object.extend({
  105. dataSeq: _seq,
  106. thumburl: _thumburl,
  107. prevurl: Trex.Util.prevurl(data.filename.split(".").pop().toLowerCase())
  108. }, data); //NOTE: Cuz IE
  109. return _data;
  110. }
  111. });
  112. /**
  113. * Trex.Attachment.File
  114. *
  115. * @example
  116. * data = {
  117. * attachurl: "string",
  118. * filename: "string",
  119. * filesize: number,
  120. * filemime: "string"
  121. * }
  122. * @class
  123. * @extends Trex.Attachment
  124. */
  125. Trex.Attachment.File = Trex.Class.create({
  126. /** @ignore */
  127. $const: {
  128. __Identity: 'file'
  129. },
  130. /** @ignore */
  131. $extend: Trex.Attachment,
  132. getFieldAttr: function(data) {
  133. return {
  134. name: 'tx_attach_file',
  135. value: [data.attachurl, data.filesize, data.filename].join('|')
  136. };
  137. },
  138. getBoxAttr: function(data) {
  139. var _nameMaxLength = 56;
  140. var _filename = data.filename;
  141. if(_filename.getRealLength() > _nameMaxLength) {
  142. if (/\./.test(_filename)) {
  143. var _nameArr = _filename.split(".");
  144. var _ext = _nameArr.pop().cutRealLength(_nameMaxLength - 4);
  145. var _name = _nameArr.join(".").cutRealLength(_nameMaxLength - 1 - _ext.length);
  146. _filename = _name + "." + _ext;
  147. } else {
  148. _filename = _filename.cutRealLength(_nameMaxLength);
  149. }
  150. }
  151. return {
  152. name: _filename + " (" + data.filesize.toByteUnit() + ")",
  153. image: data.thumburl
  154. };
  155. },
  156. /**
  157. * object의 style 값을 가져온다.
  158. * @function
  159. */
  160. getObjectStyle: function(data) {
  161. var _objstyle = {};
  162. if(this.actor.config.objstyle) {
  163. _objstyle = Object.extend(_objstyle, this.actor.config.objstyle);
  164. }
  165. if(data.imagealign) {
  166. var _objectStyle = {
  167. "L": Trex.Tool.AlignLeft,
  168. "C": Trex.Tool.AlignCenter,
  169. "FL": Trex.Tool.AlignRight,
  170. "FR": Trex.Tool.AlignFull
  171. }[data.imagealign];
  172. if (_objectStyle && _objectStyle.__TextModeProps && _objectStyle.__TextModeProps['image']) {
  173. _objstyle = Object.extend(_objstyle, _objectStyle.__TextModeProps['button']['style']);
  174. }
  175. }
  176. return _objstyle;
  177. },
  178. /**
  179. * object를 감싸고 있는 paragraph tag 의 style 값을 가져온다.
  180. * @function
  181. */
  182. getParaStyle: function(data) {
  183. var _parastyle = Object.extend({}, this.actor.config.parastyle || this.actor.config.defaultstyle);
  184. if(data.imagealign) {
  185. var _objectStyle = {
  186. "L": Trex.Tool.AlignLeft,
  187. "C": Trex.Tool.AlignCenter,
  188. "FL": Trex.Tool.AlignFull,
  189. "FR": Trex.Tool.AlignRight
  190. }[data.imagealign];
  191. if (_objectStyle && _objectStyle.__TextModeProps && _objectStyle.__TextModeProps['paragraph']) {
  192. _parastyle = Object.extend(_parastyle, _objectStyle.__TextModeProps['paragraph']['style']);
  193. }
  194. }
  195. return _parastyle;
  196. },
  197. getSaveHtml: function(data) {
  198. return "<a href=\"" + data.attachurl + "\"><img src=\"" + data.prevurl + "\"/> " + data.filename + "</a>";
  199. },
  200. getDispHtml: function(data) {
  201. return "<button id=\"" + data.dispElId + "\" class=\"txc-file\"><img class=\"tx-unresizable\" src=\"" + data.prevurl + "\" ld=\"" + data.attachurl + "\"/> " + data.filename + "</button>";
  202. },
  203. getDispText: function(data) {
  204. return "[" + TXMSG("@file.title") + ":" + data.dataSeq + "]";
  205. },
  206. getRegLoad: function(data) {
  207. return new RegExp("<(?:a|A)\\s*href=\"?" + data.attachurl.getRegExp() + "[^\"]*\"?[^>]*><(?:img|IMG)[^>]*\/?>[\\S\\s]*?<\/(?:a|A)>", "gm");
  208. },
  209. getRegHtml: function(data) {
  210. return new RegExp("<(?:button|BUTTON)[^>]*id=\"?" + data.dispElId + "\"?[^>]*>[\\S\\s]*?" + data.attachurl.getRegExp() + "[\\S\\s]*?<\/(?:button|BUTTON)>", "gm");
  211. },
  212. getRegText: function(data) {
  213. return new RegExp("\\[" + TXMSG("@file.title") + ":" + data.dataSeq + "\\]", "gm");
  214. }
  215. });