processor_webkit.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Trex.I.Processor.Webkit = {
  2. /**
  3. * Paragraph 를 채운다.
  4. * @private
  5. * @param {Node} node - paragraph 노드
  6. */
  7. stuffNode: function(node) {
  8. return $tom.stuff(node, this.newNode('br'));
  9. },
  10. /**
  11. * @private
  12. * @memberOf Trex.Canvas.ProcessorP
  13. * Webkit에서 newlinepolicy가 p일 경우 Enter Key 이벤트가 발생하면 실행한다.
  14. */
  15. controlEnterByParagraph: function() {
  16. throw $propagate;
  17. },
  18. findParagraph: function(node) {
  19. var matched = function(node) {
  20. return $tom.kindOf(node, "div,p,blockquote");
  21. };
  22. var mustStop = function(node) {
  23. return $tom.kindOf(node, "body,li,%tablegroup");
  24. };
  25. return $tom.findAncestor(node, matched, mustStop);
  26. },
  27. findAncestorListItem: function(node) {
  28. var matched = function(node) {
  29. return $tom.kindOf(node, "li");
  30. };
  31. var mustStop = function(node) {
  32. return $tom.kindOf(node, "body,%tablegroup");
  33. };
  34. return $tom.findAncestor(node, matched, mustStop);
  35. },
  36. divideListItem: function(li) {
  37. var newLi, self = this;
  38. self.execWithMarker(function(marker) {
  39. newLi = $tom.divideTree(li, marker.endMarker);
  40. });
  41. if (!$tom.hasUsefulChildren(li, _TRUE)) {
  42. li.innerHTML = "";
  43. }
  44. if (!$tom.hasUsefulChildren(newLi, _TRUE)) {
  45. newLi.innerHTML = "";
  46. }
  47. self.stuffNode(li);
  48. self.stuffNode(newLi);
  49. self.moveCaretTo(newLi);
  50. },
  51. /**
  52. * 선택된 영역의 native queryCommandState 값을 얻어온다.
  53. * @param {String} command - 커맨드 명
  54. * @returns {Boolean} - 해당 영역이 커맨드 상태인지 여부
  55. * @example
  56. * processor.queryCommandState('bold');
  57. * @description
  58. * webkit 계열의 브라우저(크롬,사파리)에서 img 에 대한 queryCommandState 가 부정확하여 수정.
  59. */
  60. queryCommandState: function(command) {
  61. var range = this.getRange();
  62. if (this.hasControl() && range.collapsed === _FALSE && range.endOffset - range.startOffset === 1) {
  63. if (command === "bold" || command === "underline" || command === "italic" || command === "strikethrough") {
  64. var elem = this.getControl();
  65. if (elem.tagName === "IMG" || elem.tagName === "BUTTON") {
  66. return _FALSE;
  67. }
  68. }
  69. }//<-여기까지 webkit 계열의 브라우저 queryCommandState 에러 처리.
  70. //위 코드와 관련된 티켓: #FTDUEDTR-1107
  71. try {
  72. return this.doc.queryCommandState(command);
  73. } catch(e) { return _FALSE; }
  74. },
  75. /**
  76. * for safari bug. 빈노드에 글자크기, 글자폰트 기억 못시킴.
  77. */
  78. addDummyNbsp: function (nodes) {
  79. var _node;
  80. if (nodes.length === 1) {
  81. _node = nodes[0];
  82. if (_node.tagName.toLowerCase() === "span"
  83. && _node.childNodes.length === 1
  84. && _node.firstChild.nodeType === 3
  85. && _node.firstChild.data === "") {
  86. _node.firstChild.data = "\u00A0";
  87. }
  88. }
  89. }
  90. };