quote.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @fileoverview
  3. * Tool '인용구' Source,
  4. * Class Trex.Tool.Quote 와 configuration을 포함
  5. *
  6. */
  7. TrexConfig.addTool(
  8. "quote",
  9. {
  10. sync: _FALSE,
  11. status: _TRUE,
  12. rows: 2,
  13. cols: 3,
  14. options: [
  15. { type: 'image', data: 'tx-quote1', image: '#iconpath/quote/citation01.gif?v=2' },
  16. { type: 'image', data: 'tx-quote2', image: '#iconpath/quote/citation02.gif?v=2' },
  17. { type: 'image', data: 'tx-quote3', image: '#iconpath/quote/citation03.gif?v=2' },
  18. { type: 'image', data: 'tx-quote4', image: '#iconpath/quote/citation04.gif?v=2' },
  19. { type: 'image', data: 'tx-quote5', image: '#iconpath/quote/citation05.gif?v=2' },
  20. { type: 'cancel', data: 'tx-quote6', image: '#iconpath/quote/citation06.gif?v=2' }
  21. ]
  22. },
  23. function(root){
  24. var _config = TrexConfig.getTool("quote", root);
  25. _config.options.each(function(option) {
  26. option.image = TrexConfig.getIconPath(option.image, 'quote');
  27. });
  28. }
  29. );
  30. Trex.Tool.Quote = Trex.Class.create({
  31. $const: {
  32. __Identity: 'quote'
  33. },
  34. $extend: Trex.Tool,
  35. oninitialized: function(config) {
  36. var _tool = this;
  37. var _canvas = this.canvas;
  38. var _map = {};
  39. config.options.each(function(option) {
  40. _map[option.data] = {
  41. type: option.type
  42. };
  43. });
  44. var _toolHandler = function(data) {
  45. if(!_map[data]) {
  46. return;
  47. }
  48. var _type = _map[data].type;
  49. var _tag = "blockquote";
  50. var _attributes = { "className": data };
  51. if(_canvas.isWYSIWYG()) {
  52. _canvas.execute(function(processor) {
  53. var _bNode = processor.findNode(_tag);
  54. if (_bNode) {
  55. if(_type == "cancel") {
  56. processor.unwrap(_bNode);
  57. } else {
  58. processor.apply(_bNode, _attributes);
  59. }
  60. } else {
  61. if(_type != "cancel") {
  62. var _nodes = processor.blocks(function() {
  63. return '%wrapper,%paragraph';
  64. });
  65. _nodes = _nodes.findAll(function(node) {
  66. if($tom.kindOf(node, "%innergroup")) {
  67. processor.wrap($tom.children(node), _tag, _attributes);
  68. return _FALSE;
  69. } else {
  70. return _TRUE;
  71. }
  72. });
  73. processor.wrap(_nodes, _tag, _attributes);
  74. }
  75. }
  76. });
  77. } else {
  78. _canvas.execute(function(processor) {
  79. processor.insertTag('<blockquote>','</blockquote>');
  80. });
  81. }
  82. };
  83. /* button & menu weave */
  84. this.weave.bind(this)(
  85. /* button */
  86. new Trex.Button(this.buttonCfg),
  87. /* menu */
  88. new Trex.Menu.List(this.menuCfg),
  89. /* handler */
  90. _toolHandler
  91. );
  92. var _popdownHandler = function(ev) {
  93. _tool.button.onMouseDown(ev);
  94. };
  95. this.bindKeyboard({ // ctrl + q
  96. ctrlKey: _TRUE,
  97. keyCode: 81
  98. }, _popdownHandler);
  99. }
  100. });