function createState(content, startSelector, startOffset, endSelector, endOffset) {
return function() {
editor.setContent(content);
setSelection(startSelector, startOffset, endSelector, endOffset);
};
}
/** Collapsed Selection States **/
function EmptyParagraph() {
var body = editor.getBody();
while (body.firstChild) {
editor.dom.remove(body.firstChild);
}
var p = body.ownerDocument.createElement('p');
p.appendChild(body.ownerDocument.createTextNode(''));
body.appendChild(p, body);
setSelection(p.firstChild, 0);
}
function EmptyHeading() {
EmptyParagraph();
editor.dom.rename(editor.getBody().firstChild, 'h1');
setSelection(editor.getBody().firstChild.firstChild, 0);
}
function TextAfterUL() {
editor.setContent('
Test');
setSelection(editor.dom.getRoot().lastChild, 2);
}
function TextAfterOL() {
editor.setContent('- Item
Test');
setSelection(editor.dom.getRoot().lastChild, 2);
}
EmptyContent = createState('', 'body', 0);
PlainText = createState('Test', 'body', 0);
NonEmptyParagraph = createState('Test
', 'p', 0);
ParagraphWithMarginLeft = createState('Test
', 'p', 0);
ParagraphWithPaddingLeft = createState('Test
', 'p', 0);
ParagraphWithMarginAndPaddingLeft = createState('Test
', 'p', 0);
CenteredListItem = createState('', 'li:nth-child(1)', 2);
ItemInCenteredList = createState('', 'li:nth-child(1)', 2);
RightAlignedListItem = createState('', 'li:nth-child(1)', 2);
ItemInRightAlignedList = createState('', 'li:nth-child(1)', 2);
ParagraphBetweenOrderedLists = createState('- Item1
Test
- Item2
', 'p', 2);
ParagraphBetweenUnorderedLists = createState('Test
', 'p', 2);
ParagraphBetweenMixedLists = createState('- Item1
Test
', 'p', 2);
NonEmptyHeading = createState('Test
', 'h1', 0);
TableCellWithoutBrs = createState('', 'td', 4);
TableCellWithoutBrs2 = createState('', 'td', 0);
TableCellWithBrsFirstLine = createState('', 'td', 1);
TableCellWithBrsFirstLine2 = createState('', 'td', 0);
TableCellWithBrsMiddleLine = createState('', 'td br:nth-child(1)', 'afterNextCharacter');
TableCellWithBrsLastLine = createState('', 'td br:nth-child(1)', 'afterNextCharacter');
TableCellWithAdjacentBrsFirstLine = createState('', 'td', 1);
HeadingInOrderedList = createState('Test
', 'h2', '2');
HeadingInUnorderedList = createState('', 'h2', '2');
HeadingInOrderedListBeforeParagraph = createState('Test
Content
After
', 'h2', '2');
DefinitionListDescription = createState('- Term
- Description
', 'dd', 2);
DefinitionListTerm = createState('- Term
- Description
', 'dt', 2);
EndOfParagraphBeforeOL = createState('Test
- Item
', 'p', 4);
EndOfParagraphBeforeOLWithListType = createState('Test
- Item
', 'p', 4);
EndOfParagraphBeforeUL = createState('Test
', 'p', 4);
StartOfParagraphAfterOL = createState('- Item
Test
', 'p', 1);
StartOfParagraphAfterUL = createState('Test
', 'p', 1);
StartOfParagraphAfterOLWithListType = createState('- Item
Test
', 'p', 1);
EmptyOrderedListItem = createState('- Before
-
- After
', 'li:nth-child(2)', 0);
EmptyUnorderedListItem = createState('', 'li:nth-child(2)', 0);
NonEmptyOrderedListItem = createState('- Before
- Test
- After
', 'li:nth-child(2)', 0);
NonEmptyUnorderedListItem = createState('', 'li:nth-child(2)', 0);
NestedEmptyOrderedListItem = createState('- Before
-
- After
', 'li ol li', 0);
NestedEmptyUnorderedListItem = createState('', 'li ul li', 0);
NestedNonEmptyOrderedListItem = createState('- Before
- Test
- After
', 'li ol li', 0);
NestedNonEmptyUnorderedListItem = createState('', 'li ul li', 0);
NestedOrderedListWithMultipleItems = createState('- Before
- Item1
- Item2
', 'li ol li', 0);
NestedUnorderedListWithMultipleItems = createState('', 'li ul li', 0);
OrderedLowerAlphaListItem = createState('- Item 1
- Item 2
', 'li:nth-child(2)', 0);
UnorderedSquareListItem = createState('', 'li:nth-child(2)', 0);
OrderedListItemWithNestedChild = createState('- Item1
- Nested
', 'li:nth-child(1)', 2);
UnorderedListItemWithNestedChild = createState('', 'li:nth-child(1)', 2);
OrderedListWithAdjacentNestedLists = createState('- Item 1
- Item 2
- Item 3
', 'li:nth-child(2)', 4);
UnorderedListWithAdjacentNestedLists = createState('', 'li:nth-child(2)', 4);
OrderedListItemWithMargin = createState('- Test
', 'li', 0);
UnorderedListItemWithMargin = createState('', 'li', 0);
OrderedListItemWithNestedAlphaList = createState('- Item
- Nested
', 'li', 2);
/** Collapsed DIV Tests **/
OrderedListItemInsideDiv = createState('', 'li:nth-child(1)', 2);
UnorderedListItemInsideDiv = createState('', 'li:nth-child(1)', 2);
ParagraphInDiv = createState('', 'p', 2);
TextInDiv = createState('Item
', 'div', 2);
TextWithBrsInDivFirstLine = createState('Item1
Item2
', 'div', 2);
TextWithBrsInDivMiddleLine = createState('Item1
Item2
Item3
', 'br:nth-child(1)', 'afterNextCharacter');
TextWithBrsInDivLastLine = createState('Item1
Item2
', 'br:nth-child(1)', 'afterNextCharacter');
TextWithBrsInFormattingInDiv = function() {
var rng;
editor.setContent('Before
Item1
Item2
Item3
');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('div')[0].childNodes[1], 0);
rng.setEnd(editor.dom.select('div')[0], 6);
editor.selection.setRng(rng);
};
TextWithBrInsideFormatting = function() {
var rng;
editor.setContent('Before
Item1Item2
Item3
');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('span')[0].childNodes[0], 2);
rng.setEnd(editor.dom.select('div')[0], 4);
editor.selection.setRng(rng);
};
/** Expanded Selection States **/
SingleParagraphSelection = createState('This is a test
', 'p', 5, 'p', 7);
MultipleParagraphSelection = createState('This is a test
Second paragraph
', 'p:nth-child(1)', 5, 'p:nth-child(2)', 6);
SingleHeadingSelection = createState('This is a test
', 'h1', 5, 'h1', 7);
MultipleHeadingSelection = createState('This is a test
Second paragraph
', 'h1:nth-child(1)', 5, 'h1:nth-child(2)', 6);
SingleBlockSelection = createState('This is a test
', 'div', 5, 'div', 7);
MultipleBlockSelection = createState('This is a test
Second paragraph
', 'div:nth-child(1)', 5, 'div:nth-child(2)', 6);
SingleBlockWithBrSelection = createState('Item1
Item2
', 'div', 3, 'br', 'afterNextCharacter');
MultipleBlockWithBrSelection = createState('Item1
Item2
Item3
', 'div:nth-child(1)', 2, 'div:nth-child(2)', 3);
MultipleBlockWithBrPartialSelection = createState('Item1
Item2
Item3
Item4
', 'div:nth-child(1)', 2, 'div:nth-child(2)', 3);
MultipleBlockWithBrPartialSelectionAtEnd = createState('Item1
Item2
Item3
Item4
', 'div:nth-child(1) br', 'afterNextCharacter', 'div:nth-child(2) br', 'afterNextCharacter');
MultipleBlockWithEmptyDivsAllSelected = createState('
a
b
', '#start', 0, '#end', 0);
CellWithoutBrSelection = createState('', 'td', 1, 'td', 1); //selection is a single point so it will avoid table selection bugs in ie9.
CellWithBrSingleLineSelection = createState('', 'td', 1, 'td', 4);
CellWithBrMultipleLineSelection = createState('', 'td', 1, 'td', 4);
TableCellWithTextAfterUL = createState('', '#start', 1, '#end', 'afterNextCharacter');
ParagraphToHeadingSelection = createState('This is a test
Second paragraph
', 'p', 5, 'h1', 6);
ParagraphToBlockSelection = createState('This is a test
Second paragraph
', 'p', 5, 'div', 6);
HeadingToParagraphSelection = createState('This is a test
Second paragraph
', 'h1', 5, 'p', 6);
BlockToParagraphSelection = createState('This is a test
Second paragraph
', 'div', 5, 'p', 6);
MultipleParagraphAndHeadingSelection = createState('This is a test
Second paragraph
Third paragraph
', 'p', 5, 'div', 5);
ThreeBoldDivsWithBrSelection = createState('One
Two
Three
', 'div:nth-child(1) strong', 2, 'div:nth-child(3) strong', 2);
SingleLiOlSelection = createState('- Item 1
', 'li', 1, 'li', 4);
MultiLiOlSelection = createState('- Item 1
- Item 2
', 'li:nth-child(1)', 1, 'li:nth-child(2)', 4);
SingleLiUlSelection = createState('', 'li', 1, 'li', 4);
MultiLiUlSelection = createState('', 'li:nth-child(1)', 1, 'li:nth-child(2)', 4);
MultiNestedLiUlSelection = createState('', 'li li:nth-child(1)', 1, 'li li:nth-child(2)', 4);
MultiNestedLiOlSelection = createState('- Item 1
- Item 2
', 'li li:nth-child(1)', 1, 'li li:nth-child(2)', 4);
IndentedOlInOlCorrectSelection = createState('- Item 1
- Indented
', 'li', 1, 'li li', 4);
IndentedUlInUlCorrectSelection = createState('', 'li', 1, 'li li', 4);
IndentedOlInOlIncorrectSelection = createState('- Item 1
- Indented
', 'li', 1, 'ol ol li', 4);
IndentedUlInUlIncorrectSelection = createState('', 'li', 1, 'ul ul li', 4);
IndentedOlInUlCorrectSelection = createState('', 'li', 1, 'li li', 4);
IndentedUlInOlCorrectSelection = createState('- Item 1
', 'li', 1, 'li li', 4);
IndentedOlInUlIncorrectSelection = createState('', 'li', 1, 'ul ol li', 4);
IndentedUlInOlIncorrectSelection = createState('- Item 1
', 'li', 1, 'ol ul li', 4);
// TODO: Paragraph/heading to list combinations.
ParagraphBeforeOlSelection = createState('Before
- Item 1
', 'p', 3, 'li', 4);
ParagraphBeforeUlSelection = createState('Before
', 'p', 3, 'li', 4);
ParagraphAfterOlSelection = createState('- Item 1
After
', 'li', 4, 'p', 3);
ParagraphAfterUlSelection = createState('After
', 'li', 4, 'p', 3);
ParagraphBeforeAndAfterOlSelection = createState('Before
- Item 1
After
', 'p', 4, '#after', 3);
ParagraphBeforeAndAfterUlSelection = createState('Before
After
', 'p', 4, '#after', 3);
SelectionEndingAtBr = createState('Item
After
', 'p', 2, 'br', 'after');
SelectionStartingAtBr = createState('Before
Item
', 'p', 'after', 'br', 'afterNextCharacter');