1 /** |
1 /** |
2 * $Id: editor_plugin_src.js 953 2008-11-04 10:16:50Z spocke $ |
2 * $Id: editor_plugin_src.js 1209 2009-08-20 12:35:10Z spocke $ |
3 * |
3 * |
4 * @author Moxiecode |
4 * @author Moxiecode |
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. |
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. |
6 */ |
6 */ |
7 |
7 |
8 (function() { |
8 (function() { |
9 var each = tinymce.each; |
9 var each = tinymce.each; |
|
10 |
|
11 // Checks if the selection/caret is at the start of the specified block element |
|
12 function isAtStart(rng, par) { |
|
13 var doc = par.ownerDocument, rng2 = doc.createRange(), elm; |
|
14 |
|
15 rng2.setStartBefore(par); |
|
16 rng2.setEnd(rng.endContainer, rng.endOffset); |
|
17 |
|
18 elm = doc.createElement('body'); |
|
19 elm.appendChild(rng2.cloneContents()); |
|
20 |
|
21 // Check for text characters of other elements that should be treated as content |
|
22 return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0; |
|
23 }; |
10 |
24 |
11 tinymce.create('tinymce.plugins.TablePlugin', { |
25 tinymce.create('tinymce.plugins.TablePlugin', { |
12 init : function(ed, url) { |
26 init : function(ed, url) { |
13 var t = this; |
27 var t = this; |
14 |
28 |
53 }); |
67 }); |
54 }); |
68 }); |
55 } |
69 } |
56 |
70 |
57 ed.onInit.add(function() { |
71 ed.onInit.add(function() { |
|
72 // Fixes an issue on Gecko where it's impossible to place the caret behind a table |
|
73 // This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled |
|
74 if (!tinymce.isIE && ed.getParam('forced_root_block')) { |
|
75 function fixTableCaretPos() { |
|
76 var last = ed.getBody().lastChild; |
|
77 |
|
78 if (last && last.nodeName == 'TABLE') |
|
79 ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />'); |
|
80 }; |
|
81 |
|
82 // Fixes an bug where it's impossible to place the caret before a table in Gecko |
|
83 // this fix solves it by detecting when the caret is at the beginning of such a table |
|
84 // and then manually moves the caret infront of the table |
|
85 if (tinymce.isGecko) { |
|
86 ed.onKeyDown.add(function(ed, e) { |
|
87 var rng, table, dom = ed.dom; |
|
88 |
|
89 // On gecko it's not possible to place the caret before a table |
|
90 if (e.keyCode == 37 || e.keyCode == 38) { |
|
91 rng = ed.selection.getRng(); |
|
92 table = dom.getParent(rng.startContainer, 'table'); |
|
93 |
|
94 if (table && ed.getBody().firstChild == table) { |
|
95 if (isAtStart(rng, table)) { |
|
96 rng = dom.createRng(); |
|
97 |
|
98 rng.setStartBefore(table); |
|
99 rng.setEndBefore(table); |
|
100 |
|
101 ed.selection.setRng(rng); |
|
102 |
|
103 e.preventDefault(); |
|
104 } |
|
105 } |
|
106 } |
|
107 }); |
|
108 } |
|
109 |
|
110 ed.onKeyUp.add(fixTableCaretPos); |
|
111 ed.onSetContent.add(fixTableCaretPos); |
|
112 ed.onVisualAid.add(fixTableCaretPos); |
|
113 |
|
114 ed.onPreProcess.add(function(ed, o) { |
|
115 var last = o.node.lastChild; |
|
116 |
|
117 if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR') |
|
118 ed.dom.remove(last); |
|
119 }); |
|
120 |
|
121 fixTableCaretPos(); |
|
122 } |
|
123 |
58 if (ed && ed.plugins.contextmenu) { |
124 if (ed && ed.plugins.contextmenu) { |
59 ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) { |
125 ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) { |
60 var sm, se = ed.selection, el = se.getNode() || ed.getBody(); |
126 var sm, se = ed.selection, el = se.getNode() || ed.getBody(); |
61 |
127 |
62 if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) { |
128 if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) { |