Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/mybp1/js/tinymce/tests/
Upload File :
Current File : /var/www/html/mmishra/mybp1/js/tinymce/tests/formatting_apply.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unit tests for apply formatting</title>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript" src="qunit/runner.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script>
var editor;

QUnit.config.autostart = false;
module("Apply formatting", {
	autostart: false
});

function getContent() {
	return editor.getContent().toLowerCase().replace(/[\r\n]+/g, '');
};

test('Formatter - apply (inline)', function() {
	var rng, format;

	expect(37);

	// Inline element on selected text
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p>', 'Inline element on selected text');

	// Inline element on partially selected text
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 1);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 3);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p>1<b>23</b>4</p>', 'Inline element on partially selected text');

	// Inline element on partially selected text in start/end elements
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p><p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 1);
	rng.setEnd(editor.dom.select('p')[1].firstChild, 3);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p>1<b>234</b></p><p><b>123</b>4</p>', 'Inline element on partially selected text in start/end elements');

	// Inline element on selected element
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p>', 'Inline element on selected element');

	// Inline element on multiple selected elements
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p><p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p><p><b>1234</b></p>', 'Inline element on multiple selected elements');

	// Inline element on multiple selected elements with various childnodes
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><em>1234</em>5678<span>9</span></p><p><em>1234</em>5678<span>9</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b><em>1234</em>5678<span>9</span></b></p><p><b><em>1234</em>5678<span>9</span></b></p>', 'Inline element on multiple selected elements with various childnodes');

	// Inline element with attributes
	editor.formatter.register('format', {inline : 'b', attributes : {title : 'value1', id : 'value2'}});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b id="value2" title="value1">1234</b></p>', 'Inline element with attributes');

	// Inline element with styles
	editor.formatter.register('format', {inline : 'b', styles : {color : '#ff0000', fontSize : '10px'}});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b style=\"color: #ff0000; font-size: 10px;\">1234</b></p>', 'Inline element with styles');

	// Inline element with attributes and styles
	editor.formatter.register('format', {inline : 'b', attributes : {title : 'value1', id : 'value2'}, styles : {color : '#ff0000', fontSize : '10px'}});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b id="value2" style="color: #ff0000; font-size: 10px;" title="value1">1234</b></p>', 'Inline element with attributes and styles');

	// Inline element with wrapable parents
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>x<em><span>1234</span></em>y</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('span')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('span')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p>x<b><em><span>1234</span></em></b>y</p>', 'Inline element with wrapable parents');

	// Inline element with redundant child
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><b>1234</b></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0], 0);
	rng.setEnd(editor.dom.select('p')[0], 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p>', 'Inline element with redundant child');

	// Inline element with redundant parent
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><b>a<em>1234</em>b</b></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('em')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('em')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>a<em>1234</em>b</b></p>', 'Inline element with redundant parent');

	// Inline element with redundant child of similar type 1
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'strong'}
	]);
	editor.getBody().innerHTML = '<p>a<strong>1234</strong>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0], 0);
	rng.setEnd(editor.dom.select('p')[0], 3);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>a1234b</b></p>', 'Inline element with redundant child of similar type 1');

	// Inline element with redundant child of similar type 2
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'span', styles : {fontWeight : 'bold'}}
	]);
	editor.getBody().innerHTML = '<p><span style="font-weight:bold">1234</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0], 0);
	rng.setEnd(editor.dom.select('p')[0], 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p>', 'Inline element with redundant child of similar type 2');

	// Inline element with redundant children of similar types
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'strong'},
		{inline : 'span', styles : {fontWeight : 'bold'}}
	]);
	editor.getBody().innerHTML = '<p><span style="font-weight:bold">a<strong>1234</strong><b>5678</b>b</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0], 0);
	rng.setEnd(editor.dom.select('p')[0], 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>a12345678b</b></p>', 'Inline element with redundant children of similar types');

	// Inline element with redundant parent 1
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'strong'}
	]);
	editor.getBody().innerHTML = '<p><strong>a<em>1234</em>b</strong></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('em')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('em')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><strong>a<em>1234</em>b</strong></p>', 'Inline element with redundant parent 1');

	// Inline element with redundant parent 2
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'span', styles : {fontWeight : 'bold'}}
	]);
	editor.getBody().innerHTML = '<p><span style="font-weight:bold">a<em>1234</em>b</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('em')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('em')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="font-weight: bold;">a<em>1234</em>b</span></p>', 'Inline element with redundant parent 2');

	// Inline element with redundant parents of similar types
	editor.formatter.register('format', [
		{inline : 'b'},
		{inline : 'strong'},
		{inline : 'span', styles : {fontWeight : 'bold'}}
	]);
	editor.getBody().innerHTML = '<p><span style="font-weight:bold"><strong><b>a<em>1234</em>b</b></strong></span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('em')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('em')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="font-weight: bold;"><strong><b>a<em>1234</em>b</b></strong></span></p>', 'Inline element with redundant parents of similar types');

	// Inline element merged with parent and child
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>a<b>12<b>34</b>56</b>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('b')[0].firstChild, 1);
	rng.setEnd(editor.dom.select('b')[0].lastChild, 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p>a<b>123456</b>b</p>', 'Inline element merged with parent and child');

	// Inline element merged with child 1
	editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}});
	editor.getBody().innerHTML = '<p>a<span style="font-weight:bold">1234</span>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="font-weight: bold;">a1234b</span></p>', 'Inline element merged with child 1');

	// Inline element merged with child 2
	editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}});
	editor.getBody().innerHTML = '<p>a<span style="font-weight:bold; color:#ff0000">1234</span>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style=\"font-weight: bold;\">a<span style=\"color: #ff0000;\">1234</span>b</span></p>', 'Inline element merged with child 2');

	// Inline element merged with child 3
	editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}});
	editor.getBody().innerHTML = '<p>a<span id="id" style="font-weight:bold">1234</span>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style=\"font-weight: bold;\">a<span id=\"id\">1234</span>b</span></p>', 'Inline element merged with child 3');

	// Inline element merged with child 3
	editor.formatter.register('format', {inline : 'span', styles : {fontWeight : 'bold'}, merge : true});
	editor.getBody().innerHTML = '<p><span style="color:#ff0000">1234</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="color: #ff0000; font-weight: bold;">1234</span></p>', 'Inline element merged with child 3');

	// Inline element merged with child 4
	editor.formatter.register('format', {inline : 'span', styles : {color : '#00ff00'}});
	editor.getBody().innerHTML = '<p><span style="color:#ff0000">1234</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="color: #00ff00;">1234</span></p>', 'Inline element merged with child 4');

	// Inline element with attributes merged with child 1
	editor.formatter.register('format', {inline : 'font', attributes : {face : 'arial'}, merge : true});
	editor.getBody().innerHTML = '<p><font size="7">1234</font></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><font face="arial" size="7">1234</font></p>', 'Inline element with attributes merged with child 1');

	// Inline element with attributes merged with child 2
	editor.formatter.register('format', {inline : 'font', attributes : {size : '7'}});
	editor.getBody().innerHTML = '<p>a<font size="7">1234</font>b</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><font size="7">a1234b</font></p>', 'Inline element with attributes merged with child 2');

	// Inline element merged with left sibling
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><b>1234</b>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].lastChild, 0);
	rng.setEnd(editor.dom.select('p')[0].lastChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>12345678</b></p>', 'Inline element merged with left sibling');

	// Inline element merged with right sibling
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234<b>5678</b></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>12345678</b></p>', 'Inline element merged with right sibling');

	// Inline element merged with left and right siblings
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><b>12</b>34<b>56</b></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].childNodes[1], 0);
	rng.setEnd(editor.dom.select('p')[0].childNodes[1], 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>123456</b></p>', 'Inline element merged with left and right siblings');

	// Inline element not merged in exact mode
	editor.formatter.register('format', {inline : 'span', styles : {color : '#00ff00'}, exact : true});
	editor.getBody().innerHTML = '<p><span style="color:#ff0000">1234</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="color: #00ff00;"><span style="color: #ff0000;">1234</span></span></p>', 'Inline element not merged in exact mode');

	// Inline element merged in exact mode
	editor.formatter.register('format', {inline : 'span', styles : {color : '#ff0000'}, exact : true});
	editor.getBody().innerHTML = '<p><span style="color:#ff0000">1234</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style="color: #ff0000;">1234</span></p>', 'Inline element merged in exact mode');

	// Deep left branch
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p><em><i><ins>1234</ins></i></em><em>text1</em><em>text2</em></p><p><em>5678</em></p><p>9012</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('ins')[0].firstChild, 1);
	rng.setEnd(editor.dom.select('p')[2].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><em><i><ins>1<b>234</b></ins></i></em><b><em>text1</em><em>text2</em></b></p><p><b><em>5678</em></b></p><p><b>9012</b></p>', 'Deep left branch');

	// Deep right branch
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>9012</p><p><em>5678</em></p><p><em><i><ins>1234</ins></i></em><em>text1</em><em>text2</em></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('em')[3].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>9012</b></p><p><b><em>5678</em></b></p><p><b><em><i><ins>1234</ins></i></em><em>text1</em></b><em><b>text</b>2</em></p>', 'Deep right branch');

	// Full element text selection on two elements with a table in the middle
	editor.formatter.register('format', {inline : 'b'});
	editor.getBody().innerHTML = '<p>1234</p><table><tbody><tr><td>123</td></tr></tbody></table><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[1].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><b>1234</b></p><table><tbody><tr><td><b>123</b></td></tr></tbody></table><p><b>5678</b></p>', 'Full element text selection on two elements with a table in the middle');

	// Inline element on selected text with variables
	editor.formatter.register('format', {inline : 'b', styles : {color : '%color'}, attributes : {title : '%title'}}, {color : '#ff0000', title : 'title'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format', {color : '#ff0000', title : 'title'});
	equals(getContent(), '<p><b style="color: #ff0000;" title="title">1234</b></p>', 'Inline element on selected text');

	// Remove redundant children
	editor.formatter.register('format', {inline : 'span', styles : {fontFamily : 'arial'}});
	editor.getBody().innerHTML = '<p><span style="font-family: sans-serif;"><span style="font-family: palatino;">1</span>2<span style="font-family: verdana;">3</span>4</span></p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0], 0);
	rng.setEnd(editor.dom.select('p')[0], 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p><span style=\"font-family: ' + fontFace('arial') + ';\">1234</span></p>', 'Remove redundant children');

	// Inline element on selected text with function values
	editor.formatter.register('format', {
		inline : 'b',
		styles : {
			color : function(vars) {
				return vars.color + '00ff';
			}
		},
		attributes : {
			title : function(vars) {
				return vars.title + '2';
			}
		}
	});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format', {
		color : '#ff',
		title : 'title'
	});
	equals(getContent(), '<p><b style="color: #ff00ff;" title="title2">1234</b></p>', 'Inline element on selected text with function values');
});

test('Formatter - apply (block)', function() {
	var rng;

	expect(9);

	// Block element on selected text
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div>', 'Block element on selected text');

	// Block element on partially selected text
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 1);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 3);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div>', 'Block element on partially selected text');

	// Block element on selected element
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 1);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div>', 'Block element on selected element');

	// Block element on selected elements
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '<p>1234</p><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div><div>5678</div>', 'Block element on selected elements');

	// Block element on selected elements with attributes
	editor.formatter.register('format', {block : 'div', attributes : {'title' : 'test'}});
	editor.getBody().innerHTML = '<p>1234</p><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div title="test">1234</div><div title="test">5678</div>', 'Block element on selected elements with attributes');

	// Block element on nested element
	editor.formatter.register('format', {block : 'p'});
	editor.getBody().innerHTML = '<div><h1>1234</h1></div>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('h1')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('h1')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div><p>1234</p></div>', 'Block element on nested element');

	// Block element on selected non wrapped text 1
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '1234';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody().firstChild, 0);
	rng.setEnd(editor.getBody().firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div>', 'Block element on selected non wrapped text 1');

	// Block element on selected non wrapped text 2
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '1234<br />4567<br />8910';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody().firstChild, 0);
	rng.setEnd(editor.getBody().lastChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div><div>4567</div><div>8910</div>', 'Block element on selected non wrapped text 2');

	// Block element on selected non wrapped text 3
	editor.formatter.register('format', {block : 'div'});
	editor.getBody().innerHTML = '<br />1234<br /><br />4567<br />8910<br />';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 7);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div>1234</div><div>4567</div><div>8910</div>', 'Block element on selected non wrapped text 3');
});

test('Formatter - apply (block wrapper)', function() {
	var rng;

	expect(3);

	// Block element wrapper 1
	editor.formatter.register('format', {block : 'blockquote', wrapper : 1});
	editor.getBody().innerHTML = '<h1>1234</h1><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('h1')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<blockquote><h1>1234</h1><p>5678</p></blockquote>', 'Block element wrapper 1');

	// Block element wrapper 2
	editor.formatter.register('format', {block : 'blockquote', wrapper : 1});
	editor.getBody().innerHTML = '<h1>1234</h1>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('h1')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('h1')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<blockquote><h1>1234</h1></blockquote>', 'Block element wrapper 2');

	// Block element wrapper 3
	editor.formatter.register('format', {block : 'blockquote', wrapper : 1});
	editor.getBody().innerHTML = '<br /><h1>1234</h1><br />';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 3);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<blockquote><h1>1234</h1></blockquote>', 'Block element wrapper 3');
});

test('Formatter - apply (selector)', function() {
	var rng;

	expect(4);

	// Apply format on single element that matches a selector
	editor.formatter.register('format', {selector : 'p', attributes : {title : 'test'}, styles : {'color' : '#ff0000'}, classes : 'a b c'});
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p class="a b c" style="color: #ff0000;" title="test">1234</p>', 'Apply format on single element that matches a selector');

	// Apply format on multiple elements that matches a selector
	editor.formatter.register('format', {selector : 'p', attributes : {title : 'test'}, styles : {'color' : '#ff0000'}, classes : 'a b c'});
	editor.getBody().innerHTML = '<p>1234</p><div>test</div><p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[1].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p class="a b c" style="color: #ff0000;" title="test">1234</p><div>test</div><p class="a b c" style="color: #ff0000;" title="test">1234</p>', 'Apply format on multiple elements that matches a selector');

	// Apply format on single element parent that matches a selector
	editor.formatter.register('format', {selector : 'div', attributes : {title : 'test'}, styles : {'color' : '#ff0000'}, classes : 'a b c'});
	editor.getBody().innerHTML = '<div><p>1234</p><p>test</p><p>1234</p></div>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('div')[0], 1);
	rng.setEnd(editor.dom.select('div')[0], 2);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<div class="a b c" style="color: #ff0000;" title="test"><p>1234</p><p>test</p><p>1234</p></div>', 'Apply format on single element parent that matches a selector');

	// Apply format on top of existing selector element
	editor.formatter.register('format', {selector : 'p', attributes : {title : 'test2'}, styles : {'color' : '#00ff00'}, classes : 'a b c'});
	editor.getBody().innerHTML = '<p class=\"c d\" title=\"test\">1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply('format');
	equals(getContent(), '<p class="c d a b" style="color: #00ff00;" title="test2">1234</p>', 'Apply format on top of existing selector element');
});

/*
test('Formatter - apply (list block)', function() {
	var rng;

	// Ordered list on selected paragraph text
	editor.getBody().innerHTML = '<p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li></ol>', 'Ordered list on paragraph text');

	// Ordered list on the text of two selected paragraphs
	editor.getBody().innerHTML = '<p>1234</p><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[1].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li><li>5678</li></ol>', 'Ordered list on the text of two selected paragraphs');

	// Ordered list on two selected paragraph elements
	editor.getBody().innerHTML = '<p>1234</p><p>5678</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.getBody(), 0);
	rng.setEnd(editor.getBody(), 2);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li><li>5678</li></ol>', 'Ordered list on two selected paragraph elements');

	// Ordered list on selected paragraph text before similar list
	editor.getBody().innerHTML = '<p>1234</p><ol><li>abc</li></ol>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li><li>abc</li></ol>', 'Ordered list on selected paragraph text before similar list');

	// Ordered list on selected paragraph text after similar list
	editor.getBody().innerHTML = '<ol><li>abc</li></ol><p>1234</p>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>abc</li><li>1234</li></ol>', 'Ordered list on selected paragraph text after similar list');

	// Ordered list on selected paragraph text between similar list
	editor.getBody().innerHTML = '<ol><li>1234</li></ol><p>5678</p><ol><li>9123</li></ol>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('p')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('p')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li><li>5678</li><li>9123</li></ol>', 'Ordered list on selected paragraph text between similar list');

	// Ordered list on selected unordered list item text
	editor.getBody().innerHTML = '<ul><li>1234</li></ul>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('li')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('li')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234</li></ol>', 'Ordered list on selected unordered list item text');

	// Ordered list on selected unordered list with sublists
	editor.getBody().innerHTML = '<ul><li>1234<ul><li>1234</li></ul></li></ul>';
	rng = editor.dom.createRng();
	rng.setStart(editor.dom.select('li')[0].firstChild, 0);
	rng.setEnd(editor.dom.select('li')[0].firstChild, 4);
	editor.selection.setRng(rng);
	editor.formatter.apply({list_block : 'ol', replace : 'ul', list_item : 'li'});
	equals(getContent(), '<ol><li>1234<ol><li>1234</li></ol></li></ol>', 'Ordered list on selected unordered list with sublists');
});
*/

tinyMCE.init({
	mode : "exact",
	elements : "elm1",
	theme : "advanced",
	add_unload_trigger : false,
	theme_advanced_styles : 'test1=test1;test2=test2',
	valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong,b,em,i,strike,u,#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big',
	apply_source_formatting : 0,
	fix_list_elements : 0,
	fix_table_elements : 0,
	forced_root_block : '',
	convert_fonts_to_spans : false,
	entities : 'raw',
	valid_styles : {
		'*' : 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,float,margin,margin-top,margin-right,margin-bottom,margin-left,display'
	},
	init_instance_callback : function(ed) {
		editor = ed;

		ed.onNodeChange.addToTop(function() {
			return false;
		});

		QUnit.start();
	}
});
</script>
</head>
<body>
	<h1 id="qunit-header">Unit tests for text formatting</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<textarea id="elm1" name="elm1"></textarea>
	<div>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
	</div>
</body>
</html>