Show:
  1. /**
  2. * Extends EditorParaBase with IE support
  3. * @class Plugin.EditorParaIE
  4. * @extends Plugin.EditorParaBase
  5. * @constructor
  6. * @module editor
  7. * @submodule editor-para-ie
  8. */
  9. var EditorParaIE = function() {
  10. EditorParaIE.superclass.constructor.apply(this, arguments);
  11. }, HOST = 'host', NODE_CHANGE = 'nodeChange',
  12. P = 'p';
  13. Y.extend(EditorParaIE, Y.Plugin.EditorParaBase, {
  14. /**
  15. * Resolves the ROOT editor element.
  16. * @method _getRoot
  17. * @private
  18. */
  19. _getRoot: function() {
  20. return this.get(HOST).getInstance().EditorSelection.ROOT;
  21. },
  22. /**
  23. * nodeChange handler to handle fixing an empty document.
  24. * @private
  25. * @method _onNodeChange
  26. */
  27. _onNodeChange: function(e) {
  28. var host = this.get(HOST), inst = host.getInstance(),
  29. btag = inst.EditorSelection.DEFAULT_BLOCK_TAG,
  30. prev, LAST_CHILD = ':last-child', para, b, para2,
  31. lc, lc2, found = false;
  32. switch (e.changedType) {
  33. case 'enter-up':
  34. para = ((this._lastPara) ? this._lastPara : e.changedNode);
  35. b = para.one('br.yui-cursor');
  36. if (this._lastPara) {
  37. delete this._lastPara;
  38. }
  39. if (b) {
  40. if (b.previous() || b.next()) {
  41. if (b.ancestor(P)) {
  42. b.remove();
  43. }
  44. }
  45. }
  46. if (!para.test(btag)) {
  47. para2 = para.ancestor(btag);
  48. if (para2) {
  49. para = para2;
  50. para2 = null;
  51. }
  52. }
  53. if (para.test(btag)) {
  54. prev = para.previous();
  55. if (prev) {
  56. lc = prev.one(LAST_CHILD);
  57. while (!found) {
  58. if (lc) {
  59. lc2 = lc.one(LAST_CHILD);
  60. if (lc2) {
  61. lc = lc2;
  62. } else {
  63. found = true;
  64. }
  65. } else {
  66. found = true;
  67. }
  68. }
  69. if (lc) {
  70. host.copyStyles(lc, para);
  71. }
  72. }
  73. }
  74. break;
  75. case 'enter':
  76. if (e.changedNode.test('br')) {
  77. e.changedNode.remove();
  78. } else if (e.changedNode.test('p, span')) {
  79. b = e.changedNode.one('br.yui-cursor');
  80. if (b) {
  81. b.remove();
  82. }
  83. }
  84. break;
  85. }
  86. },
  87. initializer: function() {
  88. var host = this.get(HOST);
  89. if (host.editorBR) {
  90. Y.error('Can not plug EditorPara and EditorBR at the same time.');
  91. return;
  92. }
  93. host.on(NODE_CHANGE, Y.bind(this._onNodeChange, this));
  94. }
  95. }, {
  96. /**
  97. * editorPara
  98. * @static
  99. * @property NAME
  100. */
  101. NAME: 'editorPara',
  102. /**
  103. * editorPara
  104. * @static
  105. * @property NS
  106. */
  107. NS: 'editorPara',
  108. ATTRS: {
  109. host: {
  110. value: false
  111. }
  112. }
  113. });
  114. Y.namespace('Plugin');
  115. Y.Plugin.EditorPara = EditorParaIE;