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('
  1. 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('
  1. Item1

Test

  1. Item2
', 'p', 2); ParagraphBetweenUnorderedLists = createState('

Test

', 'p', 2); ParagraphBetweenMixedLists = createState('
  1. Item1

Test

', 'p', 2); NonEmptyHeading = createState('

Test

', 'h1', 0); TableCellWithoutBrs = createState('
Test 
', 'td', 4); TableCellWithoutBrs2 = createState('
Test 
', 'td', 0); TableCellWithBrsFirstLine = createState('
Test
Line 2
 
', 'td', 1); TableCellWithBrsFirstLine2 = createState('
Test
Line 2
 
', 'td', 0); TableCellWithBrsMiddleLine = createState('
Test
Line 2
Line 3
 
', 'td br:nth-child(1)', 'afterNextCharacter'); TableCellWithBrsLastLine = createState('
Test
Line 2
 
', 'td br:nth-child(1)', 'afterNextCharacter'); TableCellWithAdjacentBrsFirstLine = createState('
Test

Line 2
 
', 'td', 1); HeadingInOrderedList = createState('
  1. Test

', 'h2', '2'); HeadingInUnorderedList = createState('', 'h2', '2'); HeadingInOrderedListBeforeParagraph = createState('
  1. Test

Content
After

', 'h2', '2'); DefinitionListDescription = createState('
Term
Description
', 'dd', 2); DefinitionListTerm = createState('
Term
Description
', 'dt', 2); EndOfParagraphBeforeOL = createState('

Test

  1. Item
', 'p', 4); EndOfParagraphBeforeOLWithListType = createState('

Test

  1. Item
', 'p', 4); EndOfParagraphBeforeUL = createState('

Test

', 'p', 4); StartOfParagraphAfterOL = createState('
  1. Item

Test

', 'p', 1); StartOfParagraphAfterUL = createState('

Test

', 'p', 1); StartOfParagraphAfterOLWithListType = createState('
  1. Item

Test

', 'p', 1); EmptyOrderedListItem = createState('
  1. Before
  2.  
  3. After
', 'li:nth-child(2)', 0); EmptyUnorderedListItem = createState('', 'li:nth-child(2)', 0); NonEmptyOrderedListItem = createState('
  1. Before
  2. Test
  3. After
', 'li:nth-child(2)', 0); NonEmptyUnorderedListItem = createState('', 'li:nth-child(2)', 0); NestedEmptyOrderedListItem = createState('
  1. Before
    1.  
  2. After
', 'li ol li', 0); NestedEmptyUnorderedListItem = createState('', 'li ul li', 0); NestedNonEmptyOrderedListItem = createState('
  1. Before
    1. Test
  2. After
', 'li ol li', 0); NestedNonEmptyUnorderedListItem = createState('', 'li ul li', 0); NestedOrderedListWithMultipleItems = createState('
  1. Before
    1. Item1
    2. Item2
', 'li ol li', 0); NestedUnorderedListWithMultipleItems = createState('', 'li ul li', 0); OrderedLowerAlphaListItem = createState('
  1. Item 1
  2. Item 2
', 'li:nth-child(2)', 0); UnorderedSquareListItem = createState('', 'li:nth-child(2)', 0); OrderedListItemWithNestedChild = createState('
  1. Item1
    1. Nested
', 'li:nth-child(1)', 2); UnorderedListItemWithNestedChild = createState('', 'li:nth-child(1)', 2); OrderedListWithAdjacentNestedLists = createState('
    1. Item 1
  1. Item 2
    1. Item 3
', 'li:nth-child(2)', 4); UnorderedListWithAdjacentNestedLists = createState('', 'li:nth-child(2)', 4); OrderedListItemWithMargin = createState('
  1. Test
', 'li', 0); UnorderedListItemWithMargin = createState('', 'li', 0); OrderedListItemWithNestedAlphaList = createState('
  1. Item
    1. Nested
', 'li', 2); /** Collapsed DIV Tests **/ OrderedListItemInsideDiv = createState('
    \n
  1. Item1
  2. Item2
', 'li:nth-child(1)', 2); UnorderedListItemInsideDiv = createState('
', 'li:nth-child(1)', 2); ParagraphInDiv = createState('

Item

', '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
Item1
Item2
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('
Cell 1
', 'td', 1, 'td', 1); //selection is a single point so it will avoid table selection bugs in ie9. CellWithBrSingleLineSelection = createState('
Cell 1
Line 2
', 'td', 1, 'td', 4); CellWithBrMultipleLineSelection = createState('
Cell 1
Line 2
', 'td', 1, 'td', 4); TableCellWithTextAfterUL = createState('
  • Existing
Line1
Line2
Line3
Line4
', '#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('
  1. Item 1
', 'li', 1, 'li', 4); MultiLiOlSelection = createState('
  1. Item 1
  2. 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('
    1. Item 1
    2. Item 2
', 'li li:nth-child(1)', 1, 'li li:nth-child(2)', 4); IndentedOlInOlCorrectSelection = createState('
  1. Item 1
    1. Indented
', 'li', 1, 'li li', 4); IndentedUlInUlCorrectSelection = createState('', 'li', 1, 'li li', 4); IndentedOlInOlIncorrectSelection = createState('
  1. Item 1
    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('
  1. Item 1
', 'li', 1, 'li li', 4); IndentedOlInUlIncorrectSelection = createState('', 'li', 1, 'ul ol li', 4); IndentedUlInOlIncorrectSelection = createState('
  1. Item 1
', 'li', 1, 'ol ul li', 4); // TODO: Paragraph/heading to list combinations. ParagraphBeforeOlSelection = createState('

Before

  1. Item 1
', 'p', 3, 'li', 4); ParagraphBeforeUlSelection = createState('

Before

', 'p', 3, 'li', 4); ParagraphAfterOlSelection = createState('
  1. Item 1

After

', 'li', 4, 'p', 3); ParagraphAfterUlSelection = createState('

After

', 'li', 4, 'p', 3); ParagraphBeforeAndAfterOlSelection = createState('

Before

  1. 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');