alignbuttons.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @fileoverview
  3. * 에디터의 이미지를 선택시 툴바의 align icon을 변경시키는 module
  4. */
  5. TrexMessage.addMsg({
  6. '@align.image.align.center': "가운데정렬",
  7. '@align.image.align.full': "오른쪽글흐름",
  8. '@align.image.align.left': "왼쪽정렬",
  9. '@align.image.align.right': "왼쪽글흐름",
  10. '@align.text.align.center': "가운데정렬 (Ctrl+.)",
  11. '@align.text.align.full': "양쪽정렬",
  12. '@align.text.align.left': "왼쪽정렬 (Ctrl+,)",
  13. '@align.text.align.right': "오른쪽정렬 (Ctrl+/)"
  14. });
  15. Trex.module("Register an eventhandler in order to change align icons upon toolbar when user click a specific image or not.",
  16. function(editor, toolbar, sidebar, canvas){
  17. var _imageAlignModeClass = "tx-selected-image";
  18. var _alignset = [
  19. toolbar.tools['alignleft'], toolbar.tools['aligncenter'], toolbar.tools['alignright'], toolbar.tools['alignfull']
  20. ];
  21. var _excludes = [
  22. "txc-2image-c", "txc-3image-c", "txc-footnote", "txc-jukebox", "txc-movie", "txc-gallery", "txc-imazing", "txc-map",
  23. "txc-file",'txc-emo',"tx-entry-embed", "txc-bgm", "txc-pie"
  24. ];
  25. var _changeButton = function(kind) {
  26. var _exec = function(tool, kind, title){
  27. if (!tool) {
  28. return;
  29. }
  30. var _elList = _NULL;
  31. var _elIcon = _NULL;
  32. if(!_elList) {
  33. _elList = $tom.find(tool.button.elButton, "li");
  34. }
  35. if(!_elIcon) {
  36. _elIcon = $tx(tool.button.elIcon);
  37. }
  38. _elIcon.title = title;
  39. if(kind == "image") {
  40. if(!$tx.hasClassName(_elList, _imageAlignModeClass)) {
  41. $tx.addClassName(_elList, _imageAlignModeClass);
  42. }
  43. tool.imageAlignMode = _TRUE;
  44. } else {
  45. if($tx.hasClassName(_elList, _imageAlignModeClass)) {
  46. $tx.removeClassName(_elList, _imageAlignModeClass);
  47. }
  48. tool.imageAlignMode = _FALSE;
  49. }
  50. };
  51. _exec(_alignset[0], kind, kind=="image" ? TXMSG("@align.image.align.left") : TXMSG("@align.text.align.left"));
  52. _exec(_alignset[1], kind, kind=="image" ? TXMSG("@align.image.align.center") : TXMSG("@align.text.align.center"));
  53. _exec(_alignset[2], kind, kind=="image" ? TXMSG("@align.image.align.right") : TXMSG("@align.text.align.right"));
  54. _exec(_alignset[3], kind, kind=="image" ? TXMSG("@align.image.align.full") : TXMSG("@align.text.align.full"));
  55. };
  56. canvas.observeElement([
  57. { tag: "body" },
  58. { tag: "table" },
  59. { tag: "hr" }
  60. ], function() {
  61. _changeButton("text");
  62. });
  63. canvas.observeElement({ tag: "img" }, function(element) {
  64. var matched = Trex.Util.getMatchedClassName(element, _excludes);
  65. if(matched) {
  66. _changeButton("text");
  67. } else if($tom.find(element, 'button')) {
  68. _changeButton("text");
  69. } else {
  70. _changeButton("image");
  71. }
  72. });
  73. }
  74. );