[kupu-checkins] r32820 - in kupu/trunk/kupu: common doc tests
duncan at codespeak.net
duncan at codespeak.net
Mon Oct 2 15:17:36 CEST 2006
Author: duncan
Date: Mon Oct 2 15:17:32 2006
New Revision: 32820
Modified:
kupu/trunk/kupu/common/kupubasetools.js
kupu/trunk/kupu/doc/CHANGES.txt
kupu/trunk/kupu/tests/test_kupubasetools.js
Log:
New '(remove style)' option on the style pulldown. Removes the innermost styled span, p, div, h1, ... If it finds a TD/TR/... with a class it removes the class but leaves the tag alone.
Modified: kupu/trunk/kupu/common/kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/common/kupubasetools.js (original)
+++ kupu/trunk/kupu/common/kupubasetools.js Mon Oct 2 15:17:32 2006
@@ -339,8 +339,8 @@
var normal = ['Normal', 'p|'];
var td = ['Plain Cell', 'td|'];
- var nochar = ['No char style', 'span|'];
-
+ var nostyle = ['(remove style)', ''];
+
var opts = [];
while (options.length) {
opt = options[0];
@@ -357,8 +357,8 @@
td = optarray;
} else if (v=='p|') {
normal = optarray;
- } else if (v=='span|') {
- nochar = optarray;
+ } else if (v=='') {
+ nostyle = optarray;
} else {
opts.push([opt.text,v]);
}
@@ -367,7 +367,7 @@
tablestyles[td[1]] = 0;
paraoptions.push(normal);
parastyles[normal[1]] = 0;
- styleoptions.push(nochar);
+ styleoptions.push(nostyle);
for (i = 0; i < opts.length; i++) {
optarray = opts[i];
@@ -383,7 +383,7 @@
paraoptions.push(optarray);
};
};
- if (styleoptions.length > 1) {
+ if (styleoptions.length) {
for (var i = 0; i < styleoptions.length; i++) {
optarray = styleoptions[i];
parastyles[optarray[1]] = paraoptions.length;
@@ -672,6 +672,38 @@
el.removeAttribute("className");
}
}
+ this._removeStyle = function() {
+ function needbreak(e) {
+ if (isblock && e) {
+ if (blocktagre.test(e.nodeName) || e.nodeName=='BR') return;
+ parent.insertBefore(ed.newElement('br'), n);
+ }
+ }
+ var n = this.editor.getSelectedNode(true);
+ var ed = this.editor;
+ while(n) {
+ var tag = n.nodeName.toLowerCase();
+ var isblock = blocktagre.test(tag);
+ if (tblre.test(tag) && n.className) {
+ n.removeAttribute("class");
+ n.removeAttribute("className");
+ return;
+ }
+ if (isblock || tag == 'span') {
+ var parent = n.parentNode;
+ var el;
+ needbreak(n.previousSibling);
+ while ((el = n.firstChild)) {
+ parent.insertBefore(el, n);
+ }
+ needbreak(n.nextSibling);
+ parent.removeChild(n);
+ return;
+ }
+ n = n.parentNode;
+ };
+ };
+
this.setTextStyle = function(style, noupdate) {
/* parse the argument into a type and classname part
generate a block element accordingly
@@ -690,7 +722,9 @@
if (this.editor.getBrowserName() == 'IE') {
command = '<' + eltype + '>';
};
- if (tblre.test(eltype)) {
+ if (!style) {
+ this._removeStyle();
+ } else if (tblre.test(eltype)) {
this._cleanCell(eltype, classname);
} else if (eltype=='SPAN') {
doc.execCommand('removeformat', null);
Modified: kupu/trunk/kupu/doc/CHANGES.txt
==============================================================================
--- kupu/trunk/kupu/doc/CHANGES.txt (original)
+++ kupu/trunk/kupu/doc/CHANGES.txt Mon Oct 2 15:17:32 2006
@@ -2,6 +2,14 @@
Kupu changes
============
+- 1.4 Beta 2
+
+ - Paragraph styling now permitted inside a table again.
+
+ - New style option '(remove style)' always present and removes the
+ closest style round the selection (i.e. a span or block tag, or
+ removes the className if it hits a table tag with a class).
+
- 1.4 Beta 1
- Fixed some problems with handling of multi-valued form fields in the
Modified: kupu/trunk/kupu/tests/test_kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/tests/test_kupubasetools.js (original)
+++ kupu/trunk/kupu/tests/test_kupubasetools.js Mon Oct 2 15:17:32 2006
@@ -140,17 +140,35 @@
this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
};
-// This test doesn't work yet: the intention is that setting text style
-// to '' will remove a block style round the current selection.
-// this.test_removeTextStyle_ParaStyle_SingleTableCell = function() {
-// //Remove a paragraph style inside a table cell
-// var data = '<table><tbody><tr><td><h1 class="te st">bar</h1></td></tr></tbody></table>';
-// var expected = '<table><tbody><tr><td>bar</td></tr></tbody></table>';
-// this.body.innerHTML = data;
-// this._setSelection(0, null, 3, null, 'bar', 1);
-// this.ui.setTextStyle('');
-// this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
-// };
+ this.test_removeTextStyle_ParaStyle_SingleTableCell = function() {
+ //Remove a paragraph style inside a table cell
+ var data = '<table><tbody><tr><td>foo<h1 class="te st">bar</h1>baz</td></tr></tbody></table>';
+ var expected = '<table><tbody><tr><td>foo<br>bar<br>baz</td></tr></tbody></table>';
+ this.body.innerHTML = data;
+ this._setSelection(4, null, 6, null, 'ar', 2);
+ this.ui.setTextStyle('');
+ this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
+ };
+
+ this.test_removeTextStyle_SpanStyle_SingleTableCell = function() {
+ //Remove a paragraph style inside a table cell
+ var data = '<table><tbody><tr><td>foo<span class="te st">bar</span>baz</td></tr></tbody></table>';
+ var expected = '<table><tbody><tr><td>foobarbaz</td></tr></tbody></table>';
+ this.body.innerHTML = data;
+ this._setSelection(3, null, 6, null, 'bar', 1);
+ this.ui.setTextStyle('');
+ this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
+ };
+
+ this.test_removeTextStyle_NoStyle = function() {
+ //Remove a paragraph style when there isn't one
+ var data = 'hello world';
+ var expected = 'hello world';
+ this.body.innerHTML = data;
+ this._setSelection(3, null, 6, null, 'lo ', 0);
+ this.ui.setTextStyle('');
+ this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
+ };
this.test_setTextStyle_TableRow = function() {
//Apply a table row style inside a table cell
More information about the kupu-checkins
mailing list