horizontalrule.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @fileoverview
  3. * 여러 스타일의 구분선을 삽입할 때 쓰이는 menu를 포함하는 Tool인 '구분선' Icon Source,
  4. * Class Trex.Tool.HorizontalRule과 configuration을 포함
  5. *
  6. */
  7. TrexConfig.addTool(
  8. "horizontalrule",
  9. {
  10. wysiwygonly: _TRUE,
  11. sync: _FALSE,
  12. status: _TRUE,
  13. top: _NULL,
  14. left: _NULL,
  15. options: [{ data: 'tx-hr-border-1',
  16. image: '#iconpath/horizontalrule/line01.gif?v=2',
  17. html: '<hr style="display:block; border: black 0 none; border-top: black 1px solid; height: 1px"/>'
  18. },
  19. { data: 'tx-hr-border-2',
  20. image: '#iconpath/horizontalrule/line02.gif?v=2',
  21. html: '<hr style="display:block; border: black 0 none; border-top: black 1px solid; border-bottom: black 3px solid; height: 7px"/>'
  22. },
  23. { data: 'tx-hr-border-3',
  24. image: '#iconpath/horizontalrule/line04.gif?v=2',
  25. html: '<hr style="display:block; border: black 0 none; border-top: black 1px dotted; height: 1px"/>'
  26. },
  27. { data: 'tx-hr-image-1',
  28. image: '#iconpath/horizontalrule/line03.gif?v=2',
  29. html: '<div style="background: url(#decopath/horizontalrule/line03.gif?v=2) repeat-x scroll left; width: 99%; height: 15px"><hr style="border: black 0 none; left: -9999px; position: relative; top: -9999px"></div>'
  30. },
  31. { data: 'tx-hr-image-2',
  32. image: '#iconpath/horizontalrule/line05.gif?v=2',
  33. html: '<div style="background: url(#decopath/horizontalrule/line05.gif?v=2) repeat-x scroll left; width: 99%; height: 15px"><hr style="border: black 0 none; left: -9999px; position: relative; top: -9999px"></div>'
  34. },
  35. { data: 'tx-hr-image-3',
  36. image: '#iconpath/horizontalrule/line06.gif?v=2',
  37. html: '<div style="background: url(#decopath/horizontalrule/line06.gif?v=2) repeat-x scroll left; width: 99%; height: 15px"><hr style="border: black 0 none; left: -9999px; position: relative; top: -9999px"></div>'
  38. },
  39. { data: 'tx-hr-image-4',
  40. image: '#iconpath/horizontalrule/line07.gif?v=2',
  41. html: '<div style="background: url(#decopath/horizontalrule/line08.gif?v=2) repeat-x scroll left; width: 99%; height: 15px"><hr style="border: black 0 none; left: -9999px; position: relative; top: -9999px"></div>'
  42. }]
  43. },
  44. function(root){
  45. var _config = TrexConfig.getTool("horizontalrule", root);
  46. _config.options.each(function(option) {
  47. option.image = TrexConfig.getIconPath(option.image);
  48. if(option.html) {
  49. option.html = TrexConfig.getDecoPath(option.html);
  50. }
  51. });
  52. }
  53. );
  54. Trex.Tool.HorizontalRule = Trex.Class.create({
  55. $const: {
  56. __Identity: 'horizontalrule'
  57. },
  58. $extend: Trex.Tool,
  59. oninitialized: function(config) {
  60. var _canvas = this.canvas;
  61. var map = {};
  62. config.options.each(function(option) {
  63. map[option.data] = {
  64. html: option.html
  65. };
  66. });
  67. var _toolHandler = function(data) {
  68. if(!map[data]) {
  69. return;
  70. }
  71. var _item = map[data];
  72. if (_canvas.isWYSIWYG()) {
  73. _canvas.execute(function(processor){
  74. // hr 태그는 p 태그 하위에 포함 될 수 없으므로 newline으로 내용을 추가 한 뒤에 래핑된 p태그를 제거한다.
  75. var pastedNode = processor.pasteContent(_item.html, _TRUE);
  76. if ($tom.isTagName(pastedNode.parentNode, 'p')) {
  77. $tom.unwrap(pastedNode.parentNode);
  78. }
  79. });
  80. } else {
  81. _canvas.execute(function(processor) {
  82. processor.insertTag('',_item.html);
  83. });
  84. }
  85. };
  86. /* button & menu weave */
  87. this.weave.bind(this)(
  88. /* button */
  89. new Trex.Button(this.buttonCfg),
  90. /* menu */
  91. new Trex.Menu.List(this.menuCfg),
  92. /* handler */
  93. _toolHandler
  94. );
  95. }
  96. });