config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. var textboxOption = function( data, padding, bgcolor, border ){
  2. return {
  3. data: data,
  4. style: {
  5. padding:padding, backgroundColor:bgcolor, border:border
  6. }
  7. };
  8. };
  9. Trex.__CONFIG_COMMON = {
  10. thumbs: {
  11. options:[
  12. {color:"#FF0000"}, {color:"#FF5E00"}, {color:"#FFBB00"}, {color:"#FFE400"}, {color:"#ABF200"}, {color:"#1FDA11"}, {color:"#00D8FF"}, {color:"#0055FF"}, {color:"#0900FF"}, {color:"#6600FF"}, {color:"#FF00DD"}, {color:"#FF007F"}, {color:"#000000"}, {color:"#FFFFFF"},
  13. {color:"#FFD8D8"}, {color:"#FAE0D4"}, {color:"#FAECC5"}, {color:"#FAF4C0"}, {color:"#E4F7BA"}, {color:"#CEFBC9"}, {color:"#D4F4FA"}, {color:"#D9E5FF"}, {color:"#DAD9FF"}, {color:"#E8D9FF"}, {color:"#FFD9FA"}, {color:"#FFD9EC"}, {color:"#F6F6F6"}, {color:"#EAEAEA"},
  14. {color:"#FFA7A7"}, {color:"#FFC19E"}, {color:"#FFE08C"}, {color:"#FAED7D"}, {color:"#CEF279"}, {color:"#B7F0B1"}, {color:"#B2EBF4"}, {color:"#B2CCFF"}, {color:"#B5B2FF"}, {color:"#D1B2FF"}, {color:"#FFB2F5"}, {color:"#FFB2D9"}, {color:"#D5D5D5"}, {color:"#BDBDBD"},
  15. {color:"#F15F5F"}, {color:"#F29661"}, {color:"#F2CB61"}, {color:"#E5D85C"}, {color:"#BCE55C"}, {color:"#86E57F"}, {color:"#5CD1E5"}, {color:"#6699FF"}, {color:"#6B66FF"}, {color:"#A366FF"}, {color:"#F261DF"}, {color:"#F261AA"}, {color:"#A6A6A6"}, {color:"#8C8C8C"},
  16. {color:"#CC3D3D"}, {color:"#CC723D"}, {color:"#CCA63D"}, {color:"#C4B73B"}, {color:"#9FC93C"}, {color:"#47C83E"}, {color:"#3DB7CC"}, {color:"#4174D9"}, {color:"#4641D9"}, {color:"#7E41D9"}, {color:"#D941C5"}, {color:"#D9418D"}, {color:"#747474"}, {color:"#5D5D5D"},
  17. {color:"#980000"}, {color:"#993800"}, {color:"#997000"}, {color:"#998A00"}, {color:"#6B9900"}, {color:"#2F9D27"}, {color:"#008299"}, {color:"#003399"}, {color:"#050099"}, {color:"#3D0099"}, {color:"#990085"}, {color:"#99004C"}, {color:"#4C4C4C"}, {color:"#353535"},
  18. {color:"#670000"}, {color:"#662500"}, {color:"#664B00"}, {color:"#665C00"}, {color:"#476600"}, {color:"#22741C"}, {color:"#005766"}, {color:"#002266"}, {color:"#030066"}, {color:"#290066"}, {color:"#660058"}, {color:"#660033"}, {color:"#212121"}, {color:"#000000"}
  19. ],
  20. transparent: {
  21. color: "transparent",
  22. border: "#999999",
  23. image: "#iconpath/ic_transparent4.gif?v=2",
  24. thumb: "#iconpath/txt_transparent.gif?v=2",
  25. thumbImage:"#iconpath/color_transparent_prev.gif?v=2"
  26. }
  27. },
  28. textbox: {
  29. options: [
  30. textboxOption('txc-textbox1', '10px', '#ffffff', '1px solid #f7f7f7'),
  31. textboxOption('txc-textbox2', '10px', '#eeeeee', '1px solid #eeeeee'),
  32. textboxOption('txc-textbox3', '10px', '#fefeb8', '1px solid #fefeb8'),
  33. textboxOption('txc-textbox4', '10px', '#fedec7', '1px solid #fedec7'),
  34. textboxOption('txc-textbox5', '10px', '#e7fdb5', '1px solid #e7fdb5'),
  35. textboxOption('txc-textbox6', '10px', '#dbe8fb', '1px solid #dbe8fb'),
  36. textboxOption('txc-textbox7', '10px', '#ffffff', '1px dashed #cbcbcb'),
  37. textboxOption('txc-textbox8', '10px', '#eeeeee', '1px dashed #c1c1c1'),
  38. textboxOption('txc-textbox9', '10px', '#fefeb8', '1px dashed #f3c534'),
  39. textboxOption('txc-textbox10', '10px', '#fedec7', '1px dashed #fe8943'),
  40. textboxOption('txc-textbox11', '10px', '#e7fdb5', '1px dashed #9fd331'),
  41. textboxOption('txc-textbox12', '10px', '#dbe8fb', '1px dashed #79a5e4'),
  42. textboxOption('txc-textbox13', '10px', '#ffffff', '1px solid #cbcbcb'),
  43. textboxOption('txc-textbox14', '10px', '#eeeeee', '1px solid #c1c1c1'),
  44. textboxOption('txc-textbox15', '10px', '#fefeb8', '1px solid #f3c534'),
  45. textboxOption('txc-textbox16', '10px', '#fedec7', '1px solid #fe8943'),
  46. textboxOption('txc-textbox17', '10px', '#e7fdb5', '1px solid #9fd331'),
  47. textboxOption('txc-textbox18', '10px', '#dbe8fb', '1px solid #79a5e4'),
  48. textboxOption('txc-textbox19', '10px', '#ffffff', '3px double #cbcbcb'),
  49. textboxOption('txc-textbox20', '10px', '#eeeeee', '3px double #c1c1c1'),
  50. textboxOption('txc-textbox21', '10px', '#fefeb8', '3px double #f3c534'),
  51. textboxOption('txc-textbox22', '10px', '#fedec7', '3px double #fe8943'),
  52. textboxOption('txc-textbox23', '10px', '#e7fdb5', '3px double #9fd331'),
  53. textboxOption('txc-textbox24', '10px', '#dbe8fb', '3px double #79a5e4')
  54. ]
  55. }
  56. };
  57. /**
  58. * 에디터 전반적인 설정을 관리하는 클래스로 각 함수를 static 하게 접근할 수 있다.
  59. *
  60. * @class
  61. */
  62. var TrexConfig = function() {
  63. //preset < daumx < project < page
  64. var __IS_SETUP = _FALSE;
  65. var __POST_PROCESSOR = [];
  66. var __TREX_PARAM = {};
  67. var __TREX_CONFIGURE = {
  68. cdnHost: "//s1.daumcdn.net/editor",
  69. cmnHost: "http://editor.daum.net",
  70. wrapper: "tx_trex_container",
  71. form: 'tx_editor_form',
  72. txIconPath: "images/icon/editor/",
  73. txDecoPath: "images/deco/contents/",
  74. params: [],
  75. events: {
  76. preventUnload: _TRUE,
  77. useHotKey: _TRUE
  78. },
  79. save: { },
  80. adaptor: { },
  81. toolbar: { },
  82. sidebar: {
  83. attachbox: { },
  84. embeder: { },
  85. attacher: { },
  86. searcher: { }
  87. },
  88. plugin: { }
  89. };
  90. var _createAnchors = function() {
  91. return {
  92. "Tool": __TREX_CONFIGURE.toolbar,
  93. "Sidebar": __TREX_CONFIGURE.sidebar,
  94. "Plugin": __TREX_CONFIGURE.plugin,
  95. "Adaptor": __TREX_CONFIGURE.adaptor,
  96. "Save": __TREX_CONFIGURE.save,
  97. "Attacher": __TREX_CONFIGURE.sidebar.attacher,
  98. "Embeder": __TREX_CONFIGURE.sidebar.embeder,
  99. "Searcher": __TREX_CONFIGURE.sidebar.searcher
  100. };
  101. };
  102. var _addParameter = function(tname, pname) {
  103. if (__IS_SETUP) {
  104. throw new Error("configure is already setup (addParameter)")
  105. }
  106. __TREX_PARAM[tname] = pname;
  107. };
  108. var _trexConfig = /** @lends TrexConfig */{
  109. /**
  110. * url을 에디터 설정값과 주어진 파라미터 값으로 변환하여 넘겨준다.
  111. * @function
  112. * @param {String} url - url
  113. * @param {Object} params - 키,값 쌍으로 이루어진 데이터
  114. * @returns {String} 변환된 url
  115. * @example
  116. * TrexConfig.getUrl("#host#path/pages/trex/image.html?username=#username", {
  117. * 'username': 'daumeditor'
  118. * });
  119. */
  120. getUrl: function(url, params) {
  121. if(typeof url !== 'string') { return url; };
  122. var loader = _WIN['EditorJSLoader'] || opener && opener['EditorJSLoader'] || (PopupUtil && PopupUtil.getOpener()['EditorJSLoader']);
  123. url = url.replace(/#host#path\/pages\//g, loader.getPageBasePath());
  124. url = url.replace(/#host/g, __TREX_CONFIGURE["txHost"]);
  125. url = url.replace(/#path\/?/g, __TREX_CONFIGURE["txPath"]);
  126. url = url.replace(/#cdnhost/g, __TREX_CONFIGURE["cdnHost"]);
  127. url = url.replace(/#cmnhost/g, __TREX_CONFIGURE["cmnHost"]);
  128. for(var _name in __TREX_PARAM) {
  129. url = url.replace(new RegExp("#".concat(_name), "g"), __TREX_CONFIGURE[__TREX_PARAM[_name]]);
  130. }
  131. if(params) {
  132. for(var name in params) {
  133. url = url.replace(new RegExp("#".concat(name), "g"), params[name]);
  134. }
  135. }
  136. return url;
  137. },
  138. /**
  139. * 팝업창을 띄울때 옵션을 문자열로 만들어 넘겨준다.
  140. * @function
  141. * @param {Object} features - 키,값 쌍으로 이루어진 데이터
  142. * @returns {String} 옵션 문자열
  143. * @example
  144. * TrexConfig.getPopFeatures({ left:250, top:65, width:797, height:644 });
  145. */
  146. getPopFeatures: function(features) {
  147. if(features == _NULL) return _NULL;
  148. if(typeof(features) === "string") { //redefine
  149. return features;
  150. }
  151. var popFeatures = [];
  152. ["toolbar", "location", "directories", "menubar"].each(function(name) {
  153. popFeatures.push(name + "=" + (features[name] || "no"));
  154. });
  155. ["scrollbars", "resizable"].each(function(name) {
  156. popFeatures.push(name + "=" + (features[name] || "yes"));
  157. });
  158. ["width", "height"].each(function(name) {
  159. popFeatures.push(name + "=" + (features[name] || "500"));
  160. });
  161. ["left", "top"].each(function(name) {
  162. popFeatures.push(name + "=" + (features[name] || "100"));
  163. });
  164. return popFeatures.join(",");
  165. },
  166. /**
  167. * 컨텐츠 삽입용 이미지의 상위 url을 넘겨준다. <br/>
  168. * txDecoPath 값이 셋팅된 경우는 해당 url을 넘겨준다.
  169. * @function
  170. * @param {String} url - url
  171. * @param {String} subpath - 하위 디렉터리 (optional)
  172. * @returns {String} 변환된 컨텐츠 삽입용 이미지url
  173. */
  174. getDecoPath: function(url) {
  175. return url.replace(/#decopath\/?/, this.getUrl(__TREX_CONFIGURE["txDecoPath"]));
  176. },
  177. /**
  178. * 에디터에서 사용되는 이미지의 상위 url을 넘겨준다. <br/>
  179. * txIconPath 값이 셋팅된 경우는 해당 url을 넘겨준다.
  180. * @function
  181. * @param {String} url - url
  182. * @param {String} subpath - 하위 디렉터리 (optional)
  183. * @returns {String} 에디터에서 사용되는 이미지url
  184. */
  185. getIconPath: function(url) {
  186. return url.replace(/#iconpath\/?/, this.getUrl(__TREX_CONFIGURE["txIconPath"]));
  187. },
  188. /**
  189. * 에디터 로딩이 완료되면 설정값을 셋업시키는 함수로
  190. * postprocessing로 등록된 함수들을 실행하며
  191. * 이후에는 설정값을 추가할 수 없다.
  192. * @private
  193. * @function
  194. * @param {Object} config - new Editor() 할 때 입력한 설정값
  195. * @returns {Object} 셋업된 설정값
  196. */
  197. setup: function(config) {
  198. $tx.deepcopy(__TREX_CONFIGURE, config);
  199. __TREX_CONFIGURE.params.each(function(name) {
  200. _addParameter(name, name);
  201. });
  202. __POST_PROCESSOR.each(function(fn) {
  203. fn(__TREX_CONFIGURE);
  204. });
  205. __IS_SETUP = _TRUE;
  206. this.setupVersion();
  207. return __TREX_CONFIGURE;
  208. },
  209. setupVersion: function() {
  210. // 다른 곳에서 txVersion 을 사용할 수도 있기에 호환을 위해 txVersion 추가
  211. __TREX_CONFIGURE.txVersion = Editor.version;
  212. },
  213. /**
  214. * 파라미터를 추가한다.<br/>
  215. * 파라미터란 getUrl 할 때 기본으로 변환할 키,값들을 정의해놓은 데이터
  216. * @function
  217. * @param {String} tname - url에 포함될 id
  218. * @param {String} pname - 설정값에 존재하는 id
  219. * @example
  220. * TrexConfig.addParameter('host', 'txHost');
  221. */
  222. addParameter: function(tname, pname) {
  223. _addParameter(tname, pname);
  224. },
  225. /**
  226. * 주어진 설정값을 deep copy로 복사한다.
  227. * @function
  228. * @param {Object} config - 주어진 설정값
  229. */
  230. clone: function(config) {
  231. return $tx.deepcopy({}, config);
  232. },
  233. /**
  234. * 주어진 설정값에 새로운 설정값들을 deep copy로 복사한다.
  235. * @function
  236. * @param {Object} config - 첫번째 인자는 주어진 설정값, 그 이후는 새로운 설정값들
  237. * @example
  238. * TrexConfig.merge(config, { 'id': 'tx_happy' }, { 'options': [1,2,3] });
  239. */
  240. merge: function() {
  241. var _config = {};
  242. $A(arguments).each(function(source) {
  243. $tx.deepcopy(_config, source);
  244. });
  245. return _config;
  246. }
  247. };
  248. /**
  249. * 주어진 설정값을 root 설정값에 추가한다.
  250. * @name add
  251. * @memberOf TrexConfig
  252. * @function
  253. * @param {Object} config - 주어진 설정값
  254. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  255. */
  256. _trexConfig["add"] = function(config, postprocessing) {
  257. if (__IS_SETUP) {
  258. throw new Error("configure is already setup (mergeConfig)")
  259. }
  260. $tx.deepcopy(__TREX_CONFIGURE, config);
  261. if(postprocessing) {
  262. __POST_PROCESSOR.push(postprocessing);
  263. }
  264. };
  265. /**
  266. * 주어진 키로 설정값을 리턴한다.
  267. * @name get
  268. * @memberOf TrexConfig
  269. * @function
  270. * @param {String} key - 주어진 키
  271. */
  272. _trexConfig["get"] = function(key) {
  273. return __TREX_CONFIGURE[key];
  274. };
  275. /**
  276. * 주어진 키로 주어진 설정값을 root/toolbar 아래에 추가한다.
  277. * @name addTool
  278. * @memberOf TrexConfig
  279. * @function
  280. * @param {String} key - 주어진 키값
  281. * @param {Object} config - 주어진 설정값
  282. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  283. */
  284. /**
  285. * 주어진 키로 주어진 설정값을 root/sidebar 아래에 추가한다.
  286. * @name addSidebar
  287. * @memberOf TrexConfig
  288. * @function
  289. * @param {String} key - 주어진 키값
  290. * @param {Object} config - 주어진 설정값
  291. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  292. */
  293. /**
  294. * 주어진 키로 주어진 설정값을 root/plugin 아래에 추가한다.
  295. * @name addPlugin
  296. * @memberOf TrexConfig
  297. * @function
  298. * @param {String} key - 주어진 키값
  299. * @param {Object} config - 주어진 설정값
  300. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  301. */
  302. /**
  303. * 주어진 키로 주어진 설정값을 root/adaptor 아래에 추가한다.
  304. * @name addAdaptor
  305. * @memberOf TrexConfig
  306. * @function
  307. * @param {String} key - 주어진 키값
  308. * @param {Object} config - 주어진 설정값
  309. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  310. */
  311. /**
  312. * 주어진 키로 주어진 설정값을 root/save 아래에 추가한다.
  313. * @name addSave
  314. * @memberOf TrexConfig
  315. * @function
  316. * @param {String} key - 주어진 키값
  317. * @param {Object} config - 주어진 설정값
  318. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  319. */
  320. /**
  321. * 주어진 키로 주어진 설정값을 root/sidebar/attacher 아래에 추가한다.
  322. * @name addAttacher
  323. * @memberOf TrexConfig
  324. * @function
  325. * @param {String} key - 주어진 키값
  326. * @param {Object} config - 주어진 설정값
  327. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  328. */
  329. /**
  330. * 주어진 키로 주어진 설정값을 root/sidebar/embeder 아래에 추가한다.
  331. * @name addEmbeder
  332. * @memberOf TrexConfig
  333. * @function
  334. * @param {String} key - 주어진 키값
  335. * @param {Object} config - 주어진 설정값
  336. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  337. */
  338. /**
  339. * 주어진 키로 주어진 설정값을 root/sidebar/searcher 아래에 추가한다.
  340. * @name addSearcher
  341. * @memberOf TrexConfig
  342. * @function
  343. * @param {String} key - 주어진 키값
  344. * @param {Object} config - 주어진 설정값
  345. * @param {Function} postprocessing - 에디터가 로딩된 후 처리할 함수 (optional)
  346. */
  347. var _addConfig = function(key, config, postprocessing) {
  348. if (__IS_SETUP) {
  349. throw new Error("configure is already setup (mergeConfig)")
  350. }
  351. this[key] = this[key] || {};
  352. $tx.deepcopy(this[key], config);
  353. if(postprocessing) {
  354. __POST_PROCESSOR.push(postprocessing);
  355. }
  356. };
  357. /**
  358. * 주어진 키로 root/toolbar[key]의 설정값을 리턴한다.
  359. * @name getTool
  360. * @memberOf TrexConfig
  361. * @function
  362. * @param {String,Object} key - 주어진 키
  363. */
  364. /**
  365. * 주어진 키로 root/sidebar[key]의 설정값을 리턴한다.
  366. * @name getSidebar
  367. * @memberOf TrexConfig
  368. * @function
  369. * @param {String,Object} key - 주어진 키
  370. */
  371. /**
  372. * 주어진 키로 root/adaptor[key]의 설정값을 리턴한다.
  373. * @name getAdaptor
  374. * @memberOf TrexConfig
  375. * @function
  376. * @param {String,Object} key - 주어진 키
  377. */
  378. /**
  379. * 주어진 키로 root/save[key]의 설정값을 리턴한다.
  380. * @name getSave
  381. * @memberOf TrexConfig
  382. * @function
  383. * @param {String,Object} key - 주어진 키
  384. */
  385. /**
  386. * 주어진 키로 root/sidebar/attacher[key]의 설정값을 리턴한다.
  387. * @name getAttacher
  388. * @memberOf TrexConfig
  389. * @function
  390. * @param {String,Object} key - 주어진 키
  391. */
  392. /**
  393. * 주어진 키로 root/sidebar/embeder[key]의 설정값을 리턴한다.
  394. * @name getEmbeder
  395. * @memberOf TrexConfig
  396. * @function
  397. * @param {String,Object} key - 주어진 키
  398. */
  399. /**
  400. * 주어진 키로 root/sidebar/searcher[key]의 설정값을 리턴한다.
  401. * @name getSearcher
  402. * @memberOf TrexConfig
  403. * @function
  404. * @param {String,Object} key - 주어진 키
  405. */
  406. var _getConfig = function(key) {
  407. return this[key];
  408. };
  409. var _anchors = _createAnchors();
  410. for(var _name in _anchors) {
  411. _trexConfig["add" + _name] = _addConfig.bind(_anchors[_name]);
  412. _trexConfig["get" + _name] = _getConfig.bind(_anchors[_name]);
  413. }
  414. return _trexConfig;
  415. }();
  416. _WIN.TrexConfig = TrexConfig;