image.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * @imageoverview
  3. * Image 업로드 관련 Source
  4. * Trex.Tool.Image - UI,
  5. * Trex.Attacher.Image,
  6. * Trex.Attachment.Image,
  7. * default configuration를 포함하고 있다.
  8. */
  9. TrexConfig.addTool(
  10. "image",
  11. {
  12. disabledonmobile: _TRUE,
  13. wysiwygonly: _TRUE,
  14. sync: _FALSE,
  15. status: _FALSE
  16. }
  17. );
  18. TrexMessage.addMsg({
  19. '@image.title': "사진"
  20. });
  21. Trex.Tool.Image = Trex.Class.create({
  22. $const: {
  23. __Identity: 'image'
  24. },
  25. $extend: Trex.Tool,
  26. oninitialized: function() {
  27. var _editor = this.editor;
  28. this.weave.bind(this)(
  29. new Trex.Button(this.buttonCfg),
  30. _NULL,
  31. function() {
  32. _editor.getSidebar().getAttacher("image").execute();
  33. }
  34. );
  35. }
  36. });
  37. TrexConfig.addAttacher(
  38. "image",
  39. {
  40. multiple: _TRUE,
  41. multipleuse: _FALSE,
  42. checksize: _TRUE,
  43. boxonly: _FALSE,
  44. wysiwygonly: _TRUE,
  45. objattr: {},
  46. features: { left:250, top:65, width:450, height:180 },
  47. popPageUrl: "#host#path/pages/trex/image.html"
  48. },
  49. function(root){
  50. var _config = TrexConfig.getAttacher("image", root);
  51. _config.popPageUrl = TrexConfig.getUrl(_config.popPageUrl);
  52. _config.features = TrexConfig.getPopFeatures(_config.features);
  53. }
  54. );
  55. /**
  56. * Trex.Attacher.Image
  57. * @class
  58. * @extends Trex.Attacher
  59. */
  60. Trex.Attacher.Image = Trex.Class.create({
  61. $const: {
  62. __Identity: 'image'
  63. },
  64. $extend: Trex.Attacher,
  65. name: 'image',
  66. title: TXMSG("@image.title"),
  67. canModified: _FALSE,
  68. canResized: _TRUE,
  69. matchRegexStartTag: /<(\w+)/,// 첨부시에 dispHtml을 기준으로 속성 및 스타일을 적용 할 태그를 찾을 때 사용
  70. oninitialized: function() {
  71. },
  72. getKey: function(data) {
  73. return data.imageurl;
  74. },
  75. getDataForEntry: function(data) {
  76. data.imageurl = this.encodeSpaceInUrl(data.imageurl);
  77. data.originalurl = this.encodeSpaceInUrl(data.originalurl);
  78. data.attachurl = this.encodeSpaceInUrl(data.attachurl);
  79. data.thumburl = data.thumburl || data.imageurl.replace(/\/image\//gm, '/P150x100/');
  80. if(!data.dispElId) {
  81. data.dispElId = Trex.Util.getDispElId();
  82. }
  83. var _seq = ((data.tmpSeq)? this.entryBox.syncSeq(data.tmpSeq): this.entryBox.newSeq());
  84. var _data = Object.extend({
  85. dataSeq: _seq
  86. }, data); //NOTE: Cuz IE
  87. return _data;
  88. },
  89. createEntry: function(data, type) {
  90. return this.createAttachment(data, type);
  91. },
  92. encodeSpaceInUrl: function(url){
  93. if ( !url ) {
  94. return ;
  95. }
  96. return url.replace(/ /g, "%20");
  97. },
  98. execAttach: function(data, type) {
  99. var _entry = this.createEntry(this.getDataForEntry(data), type);
  100. _entry.execRegister();
  101. },
  102. execReload: function(data, content, type) {
  103. var _entry = this.createEntry(this.getDataForEntry(data, content), type);
  104. _entry.execReload();
  105. }
  106. });
  107. /**
  108. * Trex.Attachment.Image
  109. *
  110. * @example
  111. * data = {
  112. * thumburl: "string",
  113. * imageurl: "string",
  114. * filename: "string",
  115. * filesize: number
  116. * }
  117. * @class
  118. * @extends Trex.Attachment
  119. */
  120. Trex.Attachment.Image = Trex.Class.create({
  121. $const: {
  122. __Identity: 'image'
  123. },
  124. $extend: Trex.Attachment,
  125. getFieldAttr: function(data) {
  126. return {
  127. name: 'tx_attach_image',
  128. value: [data.thumburl, data.imageurl, data.originalurl, data.exifurl, data.filename, data.filesize].join('|')
  129. };
  130. },
  131. getBoxAttr: function(data) {
  132. var _rectangle = data.width ? data.width + "x" + data.height + " / " : "";
  133. return {
  134. name: data.filename + " (" + _rectangle + data.filesize.toByteUnit() + ")",
  135. image: data.thumburl
  136. };
  137. },
  138. getObjectAttr: function(data) {
  139. var _objattr = Object.extend({}, this.actor.config.objattr);
  140. if(data.width) {
  141. if(!_objattr.width || _objattr.width > data.width) {
  142. _objattr.width = data.width;
  143. }
  144. } else {
  145. _objattr.width = _NULL;
  146. }
  147. if(data.height) {
  148. if(!_objattr.height || _objattr.height > data.height) {
  149. _objattr.height = data.height;
  150. }
  151. } else {
  152. _objattr.height = _NULL;
  153. }
  154. return _objattr;
  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.__ImageModeProps && _objectStyle.__ImageModeProps['image']) {
  173. _objstyle = Object.extend(_objstyle, _objectStyle.__ImageModeProps['image']['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.AlignRight,
  189. "FR": Trex.Tool.AlignFull
  190. }[data.imagealign];
  191. if (_objectStyle && _objectStyle.__ImageModeProps && _objectStyle.__ImageModeProps['paragraph']) {
  192. _parastyle = Object.extend(_parastyle, _objectStyle.__ImageModeProps['paragraph']['style']);
  193. }
  194. }
  195. return _parastyle;
  196. },
  197. getSaveHtml: function(data) {
  198. return "<img src=\"" + data.imageurl + "\" class=\"txc-image\"/>";
  199. },
  200. getDispHtml: function(data) {
  201. return "<img id=\"" + data.dispElId + "\" src=\"" + data.imageurl + "\" class=\"txc-image\"/>";
  202. },
  203. getDispText: function(data) {
  204. return "<img src=\"" + data.imageurl + "\" class=\"txc-image\"/>";
  205. },
  206. getRegLoad: function(data) {
  207. return new RegExp("<(?:img|IMG)[^>]*src=\"?" + data.imageurl.getRegExp() + "\"?[^>]*\/?>", "gim");
  208. },
  209. getRegHtml: function(data) {
  210. return new RegExp("<(?:img|IMG)[^>]*src=\"?" + data.imageurl.getRegExp() + "\"?[^>]*\/?>", "gim");
  211. },
  212. getRegText: function(data) {
  213. return new RegExp("<(?:img|IMG)[^>]*src=\"?" + data.imageurl.getRegExp() + "\"?[^>]*\/?>", "gim");
  214. }
  215. });