Best JavaScript code snippet using storybook-root
lists.js
Source: lists.js
...59 editor.getBody().innerHTML = trimBrs(60 '<p>a</βp>'61 );62 editor.focus();63 Utils.setSelection('p', 0);64 execCommand('InsertUnorderedList');65 equal(editor.getContent(), '<ul><li>a</βli></βul>');66 equal(editor.selection.getNode().nodeName, 'LI');67});68test('Apply UL list to single empty P', function() {69 editor.getBody().innerHTML = trimBrs(70 '<p><br></βp>'71 );72 editor.focus();73 Utils.setSelection('p', 0);74 execCommand('InsertUnorderedList');75 equal(trimBrs(editor.getContent({format: 'raw'})), '<ul><li></βli></βul>');76 equal(editor.selection.getNode().nodeName, 'LI');77});78test('Apply UL list to multiple Ps', function() {79 editor.getBody().innerHTML = trimBrs(80 '<p>a</βp>' +81 '<p>b</βp>' +82 '<p>c</βp>'83 );84 editor.focus();85 Utils.setSelection('p', 0, 'p:last', 0);86 execCommand('InsertUnorderedList');87 equal(editor.getContent(),88 '<ul>' +89 '<li>a</βli>' +90 '<li>b</βli>' +91 '<li>c</βli>' +92 '</βul>'93 );94 equal(editor.selection.getStart().nodeName, 'LI');95});96test('Apply OL list to single P', function() {97 editor.getBody().innerHTML = trimBrs(98 '<p>a</βp>'99 );100 editor.focus();101 Utils.setSelection('p', 0);102 execCommand('InsertOrderedList');103 equal(editor.getContent(), '<ol><li>a</βli></βol>');104 equal(editor.selection.getNode().nodeName, 'LI');105});106test('Apply OL list to single empty P', function() {107 editor.getBody().innerHTML = trimBrs(108 '<p><br></βp>'109 );110 editor.focus();111 Utils.setSelection('p', 0);112 execCommand('InsertOrderedList');113 equal(trimBrs(editor.getContent({format: 'raw'})), '<ol><li></βli></βol>');114 equal(editor.selection.getNode().nodeName, 'LI');115});116test('Apply OL list to multiple Ps', function() {117 editor.getBody().innerHTML = trimBrs(118 '<p>a</βp>' +119 '<p>b</βp>' +120 '<p>c</βp>'121 );122 editor.focus();123 Utils.setSelection('p', 0, 'p:last', 0);124 execCommand('InsertOrderedList');125 equal(editor.getContent(),126 '<ol>' +127 '<li>a</βli>' +128 '<li>b</βli>' +129 '<li>c</βli>' +130 '</βol>'131 );132 equal(editor.selection.getStart().nodeName, 'LI');133});134test('Apply OL to UL list', function() {135 editor.getBody().innerHTML = trimBrs(136 '<ul>' +137 '<li>a</βli>' +138 '<li>b</βli>' +139 '<li>c</βli>' +140 '</βul>'141 );142 editor.focus();143 Utils.setSelection('li', 0, 'li:last', 0);144 execCommand('InsertOrderedList');145 equal(editor.getContent(),146 '<ol>' +147 '<li>a</βli>' +148 '<li>b</βli>' +149 '<li>c</βli>' +150 '</βol>'151 );152 equal(editor.selection.getStart().nodeName, 'LI');153});154test('Apply OL to UL list with collapsed selection', function() {155 editor.getBody().innerHTML = trimBrs(156 '<ul>' +157 '<li>a</βli>' +158 '<li>b</βli>' +159 '<li>c</βli>' +160 '</βul>'161 );162 editor.focus();163 Utils.setSelection('li:nth-child(2)');164 execCommand('InsertOrderedList');165 equal(editor.getContent(),166 '<ol>' +167 '<li>a</βli>' +168 '<li>b</βli>' +169 '<li>c</βli>' +170 '</βol>'171 );172 equal(editor.selection.getStart().nodeName, 'LI');173});174test('Apply UL to OL list', function() {175 editor.getBody().innerHTML = trimBrs(176 '<ol>' +177 '<li>a</βli>' +178 '<li>b</βli>' +179 '<li>c</βli>' +180 '</βol>'181 );182 editor.focus();183 Utils.setSelection('li', 0, 'li:last', 0);184 execCommand('InsertUnorderedList');185 equal(editor.getContent(),186 '<ul>' +187 '<li>a</βli>' +188 '<li>b</βli>' +189 '<li>c</βli>' +190 '</βul>'191 );192 equal(editor.selection.getStart().nodeName, 'LI');193});194test('Apply UL to OL list collapsed selection', function() {195 editor.getBody().innerHTML = trimBrs(196 '<ol>' +197 '<li>a</βli>' +198 '<li>b</βli>' +199 '<li>c</βli>' +200 '</βol>'201 );202 editor.focus();203 Utils.setSelection('li:nth-child(2)');204 execCommand('InsertUnorderedList');205 equal(editor.getContent(),206 '<ul>' +207 '<li>a</βli>' +208 '<li>b</βli>' +209 '<li>c</βli>' +210 '</βul>'211 );212 equal(editor.selection.getStart().nodeName, 'LI');213});214test('Apply UL to P and merge with adjacent lists', function() {215 editor.getBody().innerHTML = trimBrs(216 '<ul>' +217 '<li>a</βli>' +218 '</βul>' +219 '<p>b</βp>' +220 '<ul>' +221 '<li>c</βli>' +222 '</βul>'223 );224 editor.focus();225 Utils.setSelection('p', 1);226 execCommand('InsertUnorderedList');227 equal(editor.getContent(),228 '<ul>' +229 '<li>a</βli>' +230 '<li>b</βli>' +231 '<li>c</βli>' +232 '</βul>'233 );234 equal(editor.selection.getStart().nodeName, 'LI');235});236test('Apply UL to OL and merge with adjacent lists', function() {237 editor.getBody().innerHTML = trimBrs(238 '<ul>' +239 '<li>a</βli>' +240 '</βul>' +241 '<ol><li>b</βli></βol>' +242 '<ul>' +243 '<li>c</βli>' +244 '</βul>'245 );246 editor.focus();247 Utils.setSelection('ol li', 1);248 execCommand('InsertUnorderedList');249 equal(editor.getContent(),250 '<ul>' +251 '<li>a</βli>' +252 '<li>b</βli>' +253 '<li>c</βli>' +254 '</βul>'255 );256 equal(editor.selection.getStart().nodeName, 'LI');257});258test('Apply OL to P and merge with adjacent lists', function() {259 editor.getBody().innerHTML = trimBrs(260 '<ol>' +261 '<li>a</βli>' +262 '</βol>' +263 '<p>b</βp>' +264 '<ol>' +265 '<li>c</βli>' +266 '</βol>'267 );268 editor.focus();269 Utils.setSelection('p', 1);270 execCommand('InsertOrderedList');271 equal(editor.getContent(),272 '<ol>' +273 '<li>a</βli>' +274 '<li>b</βli>' +275 '<li>c</βli>' +276 '</βol>'277 );278 equal(editor.selection.getStart().nodeName, 'LI');279});280test('Apply OL to UL and merge with adjacent lists', function() {281 editor.getBody().innerHTML = trimBrs(282 '<ol>' +283 '<li>a</βli>' +284 '</βol>' +285 '<ul><li>b</βli></βul>' +286 '<ol>' +287 '<li>c</βli>' +288 '</βol>'289 );290 editor.focus();291 Utils.setSelection('ul li', 1);292 execCommand('InsertOrderedList');293 equal(editor.getContent(),294 '<ol>' +295 '<li>a</βli>' +296 '<li>b</βli>' +297 '<li>c</βli>' +298 '</βol>'299 );300 equal(editor.selection.getStart().nodeName, 'LI');301});302test('Apply UL list to single text line', function() {303 editor.settings.forced_root_block = false;304 editor.getBody().innerHTML = (305 'a'306 );307 editor.focus();308 Utils.setSelection('body', 0);309 execCommand('InsertUnorderedList');310 equal(editor.getContent(), '<ul><li>a</βli></βul>');311 equal(editor.selection.getNode().nodeName, 'LI');312});313test('Apply UL list to single text line with BR', function() {314 editor.settings.forced_root_block = false;315 editor.getBody().innerHTML = (316 'a<br>'317 );318 editor.focus();319 Utils.setSelection('body', 0);320 execCommand('InsertUnorderedList');321 equal(editor.getContent(), '<ul><li>a</βli></βul>');322 equal(editor.selection.getNode().nodeName, 'LI');323});324test('Apply UL list to multiple lines separated by BR', function() {325 editor.settings.forced_root_block = false;326 editor.getBody().innerHTML = (327 'a<br>' +328 'b<br>' +329 'c'330 );331 editor.focus();332 editor.execCommand('SelectAll');333 execCommand('InsertUnorderedList');334 equal(editor.getContent(),335 '<ul>' +336 '<li>a</βli>' +337 '<li>b</βli>' +338 '<li>c</βli>' +339 '</βul>'340 );341 equal(editor.selection.getStart().nodeName, 'LI');342});343test('Apply UL list to multiple lines separated by BR and with trailing BR', function() {344 editor.settings.forced_root_block = false;345 editor.getBody().innerHTML = (346 'a<br>' +347 'b<br>' +348 'c<br>'349 );350 editor.focus();351 editor.execCommand('SelectAll');352 execCommand('InsertUnorderedList');353 equal(editor.getContent(),354 '<ul>' +355 '<li>a</βli>' +356 '<li>b</βli>' +357 '<li>c</βli>' +358 '</βul>'359 );360 equal(editor.selection.getStart().nodeName, 'LI');361});362test('Apply UL list to multiple formatted lines separated by BR', function() {363 editor.settings.forced_root_block = false;364 editor.getBody().innerHTML = (365 '<strong>a</βstrong><br>' +366 '<span>b</βspan><br>' +367 '<em>c</βem>'368 );369 editor.focus();370 Utils.setSelection('strong', 0, 'em', 0);371 execCommand('InsertUnorderedList');372 equal(editor.getContent(),373 '<ul>' +374 '<li><strong>a</βstrong></βli>' +375 '<li><span>b</βspan></βli>' +376 '<li><em>c</βem></βli>' +377 '</βul>'378 );379 equal(editor.selection.getStart().nodeName, 'STRONG');380 equal(editor.selection.getEnd().nodeName, tinymce.Env.ie && tinymce.Env.ie < 9 ? 'LI' : 'EM'); /β/β Old IE will return the end LI not a big deal381});382/β/β Ignore on IE 7, 8 this is a known bug not worth fixing383if (!tinymce.Env.ie || tinymce.Env.ie > 8) {384 test('Apply UL list to br line and text block line', function() {385 editor.settings.forced_root_block = false;386 editor.setContent(387 'a' +388 '<p>b</βp>'389 );390 var rng = editor.dom.createRng();391 rng.setStart(editor.getBody().firstChild, 0);392 rng.setEnd(editor.getBody().lastChild.firstChild, 1);393 editor.selection.setRng(rng);394 execCommand('InsertUnorderedList');395 equal(editor.getContent(),396 '<ul>' +397 '<li>a</βli>' +398 '<li>b</βli>' +399 '</βul>'400 );401 equal(editor.selection.getStart().nodeName, 'LI');402 equal(editor.selection.getEnd().nodeName, 'LI');403 });404}405test('Apply UL list to text block line and br line', function() {406 editor.settings.forced_root_block = false;407 editor.getBody().innerHTML = (408 '<p>a</βp>' +409 'b'410 );411 editor.focus();412 var rng = editor.dom.createRng();413 rng.setStart(editor.getBody().firstChild.firstChild, 0);414 rng.setEnd(editor.getBody().lastChild, 1);415 editor.selection.setRng(rng);416 execCommand('InsertUnorderedList');417 equal(editor.getContent(),418 '<ul>' +419 '<li>a</βli>' +420 '<li>b</βli>' +421 '</βul>'422 );423 equal(editor.selection.getStart().nodeName, 'LI');424 equal(editor.selection.getEnd().nodeName, 'LI');425});426test('Apply UL list to all BR lines (SelectAll)', function() {427 editor.settings.forced_root_block = false;428 editor.getBody().innerHTML = (429 'a<br>' +430 'b<br>' +431 'c<br>'432 );433 editor.focus();434 editor.execCommand('SelectAll');435 execCommand('InsertUnorderedList');436 equal(editor.getContent(),437 '<ul>' +438 '<li>a</βli>' +439 '<li>b</βli>' +440 '<li>c</βli>' +441 '</βul>'442 );443});444test('Apply UL list to all P lines (SelectAll)', function() {445 editor.getBody().innerHTML = (446 '<p>a</βp>' +447 '<p>b</βp>' +448 '<p>c</βp>'449 );450 editor.focus();451 editor.execCommand('SelectAll');452 execCommand('InsertUnorderedList');453 equal(editor.getContent(),454 '<ul>' +455 '<li>a</βli>' +456 '<li>b</βli>' +457 '<li>c</βli>' +458 '</βul>'459 );460});461/β/β Remove462test('Remove UL at single LI', function() {463 editor.getBody().innerHTML = trimBrs(464 '<ul>' +465 '<li>a</βli>' +466 '</βul>'467 );468 editor.focus();469 Utils.setSelection('li');470 execCommand('InsertUnorderedList');471 equal(editor.getContent(),472 '<p>a</βp>'473 );474 equal(editor.selection.getStart().nodeName, 'P');475});476test('Remove UL at start LI', function() {477 editor.getBody().innerHTML = trimBrs(478 '<ul>' +479 '<li>a</βli>' +480 '<li>b</βli>' +481 '<li>c</βli>' +482 '</βul>'483 );484 editor.focus();485 Utils.setSelection('li');486 execCommand('InsertUnorderedList');487 equal(editor.getContent(),488 '<p>a</βp>' +489 '<ul>' +490 '<li>b</βli>' +491 '<li>c</βli>' +492 '</βul>'493 );494 equal(editor.selection.getStart().nodeName, 'P');495});496test('Remove UL at start empty LI', function() {497 editor.getBody().innerHTML = trimBrs(498 '<ul>' +499 '<li><br></βli>' +500 '<li>b</βli>' +501 '<li>c</βli>' +502 '</βul>'503 );504 editor.focus();505 Utils.setSelection('li');506 execCommand('InsertUnorderedList');507 equal(editor.getContent(),508 '<p>\u00a0</βp>' +509 '<ul>' +510 '<li>b</βli>' +511 '<li>c</βli>' +512 '</βul>'513 );514 equal(editor.selection.getNode().nodeName, 'P');515});516test('Remove UL at middle LI', function() {517 editor.getBody().innerHTML = trimBrs(518 '<ul>' +519 '<li>a</βli>' +520 '<li>b</βli>' +521 '<li>c</βli>' +522 '</βul>'523 );524 editor.focus();525 Utils.setSelection('li:nth-child(2)', 1);526 execCommand('InsertUnorderedList');527 equal(editor.getContent(),528 '<ul>' +529 '<li>a</βli>' +530 '</βul>' +531 '<p>b</βp>' +532 '<ul>' +533 '<li>c</βli>' +534 '</βul>'535 );536 equal(editor.selection.getStart().nodeName, 'P');537});538test('Remove UL at middle empty LI', function() {539 editor.getBody().innerHTML = trimBrs(540 '<ul>' +541 '<li>a</βli>' +542 '<li><br></βli>' +543 '<li>c</βli>' +544 '</βul>'545 );546 editor.focus();547 Utils.setSelection('li:nth-child(2)', 0);548 execCommand('InsertUnorderedList');549 equal(editor.getContent(),550 '<ul>' +551 '<li>a</βli>' +552 '</βul>' +553 '<p>\u00a0</βp>' +554 '<ul>' +555 '<li>c</βli>' +556 '</βul>'557 );558 equal(editor.selection.getNode().nodeName, 'P');559});560test('Remove UL at end LI', function() {561 editor.getBody().innerHTML = trimBrs(562 '<ul>' +563 '<li>a</βli>' +564 '<li>b</βli>' +565 '<li>c</βli>' +566 '</βul>'567 );568 editor.focus();569 Utils.setSelection('li:last', 1);570 execCommand('InsertUnorderedList');571 equal(editor.getContent(),572 '<ul>' +573 '<li>a</βli>' +574 '<li>b</βli>' +575 '</βul>' +576 '<p>c</βp>'577 );578 equal(editor.selection.getStart().nodeName, 'P');579});580test('Remove UL at end empty LI', function() {581 editor.getBody().innerHTML = trimBrs(582 '<ul>' +583 '<li>a</βli>' +584 '<li>b</βli>' +585 '<li><br></βli>' +586 '</βul>'587 );588 editor.focus();589 Utils.setSelection('li:last', 0);590 execCommand('InsertUnorderedList');591 equal(editor.getContent(),592 '<ul>' +593 '<li>a</βli>' +594 '<li>b</βli>' +595 '</βul>' +596 '<p>\u00a0</βp>'597 );598 equal(editor.selection.getNode().nodeName, 'P');599});600test('Remove UL at middle LI inside parent OL', function() {601 editor.getBody().innerHTML = trimBrs(602 '<ol>' +603 '<li>a</βli>' +604 '<ul>' +605 '<li>b</βli>' +606 '<li>c</βli>' +607 '<li>d</βli>' +608 '</βul>' +609 '<li>e</βli>' +610 '</βol>'611 );612 editor.focus();613 Utils.setSelection('ul li:nth-child(2)', 1);614 execCommand('InsertUnorderedList');615 equal(editor.getContent(),616 '<ol>' +617 '<li>a</βli>' +618 '<ul>' +619 '<li>b</βli>' +620 '</βul>' +621 '</βol>' +622 '<p>c</βp>' +623 '<ol>' +624 '<ul>' +625 '<li>d</βli>' +626 '</βul>' +627 '<li>e</βli>' +628 '</βol>'629 );630 equal(editor.selection.getStart().nodeName, 'P');631});632test('Remove UL at middle LI inside parent OL (html5)', function() {633 editor.getBody().innerHTML = trimBrs(634 '<ol>' +635 '<li>a' +636 '<ul>' +637 '<li>b</βli>' +638 '<li>c</βli>' +639 '<li>d</βli>' +640 '</βul>' +641 '</βli>' +642 '<li>e</βli>' +643 '</βol>'644 );645 editor.focus();646 Utils.setSelection('ul li:nth-child(2)', 1);647 execCommand('InsertUnorderedList');648 equal(editor.getContent(),649 '<ol>' +650 '<li>a' +651 '<ul>' +652 '<li>b</βli>' +653 '</βul>' +654 '</βli>' +655 '</βol>' +656 '<p>c</βp>' +657 '<ol>' +658 '<li>' +659 '<ul>' +660 '<li>d</βli>' +661 '</βul>' +662 '</βli>' +663 '<li>e</βli>' +664 '</βol>'665 );666 equal(editor.selection.getStart().nodeName, 'P');667});668test('Remove UL with single LI in BR mode', function() {669 editor.settings.forced_root_block = false;670 editor.getBody().innerHTML = trimBrs(671 '<ul>' +672 '<li>a</βli>' +673 '</βul>'674 );675 editor.focus();676 Utils.setSelection('li', 1);677 execCommand('InsertUnorderedList');678 equal(editor.getContent(),679 'a'680 );681 equal(editor.selection.getStart().nodeName, 'BODY');682});683test('Remove UL with multiple LI in BR mode', function() {684 editor.settings.forced_root_block = false;685 editor.getBody().innerHTML = trimBrs(686 '<ul>' +687 '<li>a</βli>' +688 '<li>b</βli>' +689 '</βul>'690 );691 editor.focus();692 Utils.setSelection('li:first', 1, 'li:last', 1);693 execCommand('InsertUnorderedList');694 equal(editor.getContent(),695 'a<br /β>' +696 'b'697 );698 equal(editor.selection.getStart().nodeName, 'BODY');699});700test('Remove empty UL between two textblocks', function() {701 editor.getBody().innerHTML = trimBrs(702 '<div>a</βdiv>' +703 '<ul>' +704 '<li></βli>' +705 '</βul>' +706 '<div>b</βdiv>'707 );708 editor.focus();709 Utils.setSelection('li:first', 0);710 execCommand('InsertUnorderedList');711 equal(editor.getContent(),712 '<div>a</βdiv>' +713 '<p>\u00a0</βp>' +714 '<div>b</βdiv>'715 );716 equal(editor.selection.getNode().nodeName, 'P');717});718test('Remove indented list with single item', function() {719 editor.getBody().innerHTML = trimBrs(720 '<ul>' +721 '<li>a' +722 '<ul>' +723 '<li>b</βli>' +724 '</βul>' +725 '</βli>' +726 '<li>c</βli>' +727 '</βul>'728 );729 editor.focus();730 Utils.setSelection('li li', 0, 'li li', 1);731 execCommand('InsertUnorderedList');732 equal(editor.getContent(),733 '<ul>' +734 '<li>a</βli>' +735 '</βul>' +736 '<p>b</βp>' +737 '<ul>' +738 '<li>c</βli>' +739 '</βul>'740 );741 equal(editor.selection.getNode().nodeName, 'P');742});743test('Remove indented list with multiple items', function() {744 editor.getBody().innerHTML = trimBrs(745 '<ul>' +746 '<li>a' +747 '<ul>' +748 '<li>b</βli>' +749 '<li>c</βli>' +750 '</βul>' +751 '</βli>' +752 '<li>d</βli>' +753 '</βul>'754 );755 editor.focus();756 Utils.setSelection('li li:first', 0, 'li li:last', 1);757 execCommand('InsertUnorderedList');758 equal(editor.getContent(),759 '<ul>' +760 '<li>a</βli>' +761 '</βul>' +762 '<p>b</βp>' +763 '<p>c</βp>' +764 '<ul>' +765 '<li>d</βli>' +766 '</βul>'767 );768 equal(editor.selection.getStart().firstChild.data, 'b');769 equal(editor.selection.getEnd().firstChild.data, 'c');770});771/β/β Ignore on IE 7, 8 this is a known bug not worth fixing772if (!tinymce.Env.ie || tinymce.Env.ie > 8) {773 test('Remove empty UL between two textblocks in BR mode', function() {774 editor.settings.forced_root_block = false;775 editor.getBody().innerHTML = trimBrs(776 '<div>a</βdiv>' +777 '<ul>' +778 '<li></βli>' +779 '</βul>' +780 '<div>b</βdiv>'781 );782 editor.focus();783 Utils.setSelection('li:first', 0);784 execCommand('InsertUnorderedList');785 equal(editor.getContent(),786 '<div>a</βdiv>' +787 '<br /β>' +788 '<div>b</βdiv>'789 );790 equal(editor.selection.getStart().nodeName, 'BR');791 });792}793/β/β Outdent794test('Outdent inside LI in beginning of OL in LI', function() {795 editor.getBody().innerHTML = trimBrs(796 '<ol>' +797 '<li>a' +798 '<ol>' +799 '<li>b</βli>' +800 '<li>c</βli>' +801 '</βol>' +802 '</βli>' +803 '</βol>'804 );805 editor.focus();806 Utils.setSelection('li li', 1);807 execCommand('Outdent');808 equal(editor.getContent(),809 '<ol>' +810 '<li>a</βli>' +811 '<li>b' +812 '<ol>' +813 '<li>c</βli>' +814 '</βol>' +815 '</βli>' +816 '</βol>'817 );818 equal(editor.selection.getNode().nodeName, 'LI');819});820test('Outdent inside LI in middle of OL in LI', function() {821 editor.getBody().innerHTML = trimBrs(822 '<ol>' +823 '<li>a' +824 '<ol>' +825 '<li>b</βli>' +826 '<li>c</βli>' +827 '<li>d</βli>' +828 '</βol>' +829 '</βli>' +830 '</βol>'831 );832 editor.focus();833 Utils.setSelection('li li:nth-child(2)', 1);834 execCommand('Outdent');835 equal(editor.getContent(),836 '<ol>' +837 '<li>a' +838 '<ol>' +839 '<li>b</βli>' +840 '</βol>' +841 '</βli>' +842 '<li>c' +843 '<ol>' +844 '<li>d</βli>' +845 '</βol>' +846 '</βli>' +847 '</βol>'848 );849 equal(editor.selection.getNode().nodeName, 'LI');850});851test('Outdent inside LI in end of OL in LI', function() {852 editor.getBody().innerHTML = trimBrs(853 '<ol>' +854 '<li>a' +855 '<ol>' +856 '<li>b</βli>' +857 '<li>c</βli>' +858 '</βol>' +859 '</βli>' +860 '</βol>'861 );862 editor.focus();863 Utils.setSelection('li li:last', 1);864 execCommand('Outdent');865 equal(editor.getContent(),866 '<ol>' +867 '<li>a' +868 '<ol>' +869 '<li>b</βli>' +870 '</βol>' +871 '</βli>' +872 '<li>c</βli>' +873 '</βol>'874 );875 equal(editor.selection.getNode().nodeName, 'LI');876});877/β/β Nested lists in OL elements878test('Outdent inside LI in beginning of OL in OL', function() {879 editor.getBody().innerHTML = trimBrs(880 '<ol>' +881 '<li>a</βli>' +882 '<ol>' +883 '<li>b</βli>' +884 '<li>c</βli>' +885 '</βol>' +886 '</βol>'887 );888 editor.focus();889 Utils.setSelection('ol ol li', 1);890 execCommand('Outdent');891 equal(editor.getContent(),892 '<ol>' +893 '<li>a</βli>' +894 '<li>b</βli>' +895 '<ol>' +896 '<li>c</βli>' +897 '</βol>' +898 '</βol>'899 );900 equal(editor.selection.getNode().nodeName, 'LI');901});902test('Outdent inside LI in middle of OL in OL', function() {903 editor.getBody().innerHTML = trimBrs(904 '<ol>' +905 '<li>a</βli>' +906 '<ol>' +907 '<li>b</βli>' +908 '<li>c</βli>' +909 '<li>d</βli>' +910 '</βol>' +911 '</βol>'912 );913 editor.focus();914 Utils.setSelection('ol ol li:nth-child(2)', 1);915 execCommand('Outdent');916 equal(editor.getContent(),917 '<ol>' +918 '<li>a</βli>' +919 '<ol>' +920 '<li>b</βli>' +921 '</βol>' +922 '<li>c</βli>' +923 '<ol>' +924 '<li>d</βli>' +925 '</βol>' +926 '</βol>'927 );928 equal(editor.selection.getNode().nodeName, 'LI');929});930test('Outdent inside first/βlast LI in inner OL', function() {931 editor.getBody().innerHTML = trimBrs(932 '<ol>' +933 '<li>1' +934 '<ol>' +935 '<li>2</βli>' +936 '<li>3</βli>' +937 '</βol>' +938 '</βli>' +939 '<li>4</βli>' +940 '</βol>'941 );942 editor.focus();943 Utils.setSelection('ol ol li:nth-child(1)', 0, 'ol ol li:nth-child(2)', 1);944 execCommand('Outdent');945 equal(editor.getContent(),946 '<ol>' +947 '<li>1</βli>' +948 '<li>2</βli>' +949 '<li>3</βli>' +950 '<li>4</βli>' +951 '</βol>'952 );953 equal(editor.selection.getRng(true).startContainer.nodeValue, '2');954 equal(editor.selection.getRng(true).endContainer.nodeValue, '3');955});956test('Outdent inside first LI in inner OL where OL is single child of parent LI', function() {957 editor.getBody().innerHTML = trimBrs(958 '<ol>' +959 '<li>a</βli>' +960 '<li>' +961 '<ol>' +962 '<li>b</βli>' +963 '<li>c</βli>' +964 '</βol>' +965 '</βli>' +966 '</βol>'967 );968 editor.focus();969 Utils.setSelection('ol ol li:first', 0);970 execCommand('Outdent');971 equal(editor.getContent(),972 '<ol>' +973 '<li>a</βli>' +974 '<li>b' +975 '<ol>' +976 '<li>c</βli>' +977 '</βol>' +978 '</βli>' +979 '</βol>'980 );981 equal(editor.selection.getNode().nodeName, 'LI');982});983test('Outdent inside LI in end of OL in OL', function() {984 editor.getBody().innerHTML = trimBrs(985 '<ol>' +986 '<li>a</βli>' +987 '<ol>' +988 '<li>b</βli>' +989 '<li>c</βli>' +990 '</βol>' +991 '</βol>'992 );993 editor.focus();994 Utils.setSelection('ol ol li:last', 1);995 execCommand('Outdent');996 equal(editor.getContent(),997 '<ol>' +998 '<li>a</βli>' +999 '<ol>' +1000 '<li>b</βli>' +1001 '</βol>' +1002 '<li>c</βli>' +1003 '</βol>'1004 );1005 equal(editor.selection.getNode().nodeName, 'LI');1006});1007test('Outdent inside only child LI in OL in OL', function() {1008 editor.getBody().innerHTML = trimBrs(1009 '<ol>' +1010 '<li>a' +1011 '<ol>' +1012 '<li>b</βli>' +1013 '</βol>' +1014 '</βli>' +1015 '</βol>'1016 );1017 editor.focus();1018 Utils.setSelection('ol ol li', 0);1019 execCommand('Outdent');1020 equal(editor.getContent(),1021 '<ol>' +1022 '<li>a</βli>' +1023 '<li>b</βli>' +1024 '</βol>'1025 );1026 equal(editor.selection.getNode().nodeName, 'LI');1027});1028test('Outdent multiple LI in OL and nested OL', function() {1029 editor.getBody().innerHTML = trimBrs(1030 '<ol>' +1031 '<li>a' +1032 '<ol>' +1033 '<li>b</βli>' +1034 '</βol>' +1035 '</βli>' +1036 '</βol>'1037 );1038 editor.focus();1039 Utils.setSelection('li', 0, 'li li', 1);1040 execCommand('Outdent');1041 equal(editor.getContent(),1042 '<p>a</βp>' +1043 '<ol>' +1044 '<li>b</βli>' +1045 '</βol>'1046 );1047});1048/β/β Indent1049test('Indent single LI in OL', function() {1050 editor.getBody().innerHTML = trimBrs(1051 '<ol>' +1052 '<li>a</βli>' +1053 '</βol>'1054 );1055 editor.focus();1056 Utils.setSelection('li', 0);1057 execCommand('Indent');1058 equal(editor.getContent(),1059 '<ol>' +1060 '<li>a</βli>' +1061 '</βol>'1062 );1063 equal(editor.selection.getNode().nodeName, 'LI');1064});1065test('Indent middle LI in OL', function() {1066 editor.getBody().innerHTML = trimBrs(1067 '<ol>' +1068 '<li>a</βli>' +1069 '<li>b</βli>' +1070 '<li>c</βli>' +1071 '</βol>'1072 );1073 editor.focus();1074 Utils.setSelection('li:nth-child(2)', 0);1075 execCommand('Indent');1076 equal(editor.getContent(),1077 '<ol>' +1078 '<li>a' +1079 '<ol>' +1080 '<li>b</βli>' +1081 '</βol>' +1082 '</βli>' +1083 '<li>c</βli>' +1084 '</βol>'1085 );1086 equal(editor.selection.getNode().nodeName, 'LI');1087});1088test('Indent last LI in OL', function() {1089 editor.getBody().innerHTML = trimBrs(1090 '<ol>' +1091 '<li>a</βli>' +1092 '<li>b</βli>' +1093 '</βol>'1094 );1095 editor.focus();1096 Utils.setSelection('li:last', 0);1097 execCommand('Indent');1098 equal(editor.getContent(),1099 '<ol>' +1100 '<li>a' +1101 '<ol>' +1102 '<li>b</βli>' +1103 '</βol>' +1104 '</βli>' +1105 '</βol>'1106 );1107 equal(editor.selection.getNode().nodeName, 'LI');1108});1109test('Indent last LI to same level as middle LI', function() {1110 editor.getBody().innerHTML = trimBrs(1111 '<ol>' +1112 '<li>a' +1113 '<ol>' +1114 '<li>b</βli>' +1115 '</βol>' +1116 '</βli>' +1117 '<li>c</βli>' +1118 '</βol>'1119 );1120 editor.focus();1121 Utils.setSelection('li:last', 1);1122 execCommand('Indent');1123 equal(editor.getContent(),1124 '<ol>' +1125 '<li>a' +1126 '<ol>' +1127 '<li>b</βli>' +1128 '<li>c</βli>' +1129 '</βol>' +1130 '</βli>' +1131 '</βol>'1132 );1133 equal(editor.selection.getNode().nodeName, 'LI');1134});1135test('Indent first LI and nested LI OL', function() {1136 editor.getBody().innerHTML = trimBrs(1137 '<ol>' +1138 '<li>a' +1139 '<ol>' +1140 '<li>b</βli>' +1141 '</βol>' +1142 '</βli>' +1143 '</βol>'1144 );1145 editor.focus();1146 Utils.setSelection('li', 0, 'li li', 0);1147 execCommand('Indent');1148 equal(editor.getContent(),1149 '<ol>' +1150 '<li>a' +1151 '<ol>' +1152 '<li>b</βli>' +1153 '</βol>' +1154 '</βli>' +1155 '</βol>'1156 );1157 equal(editor.selection.getNode().nodeName, 'LI');1158});1159test('Indent second LI to same level as nested LI', function() {1160 editor.getBody().innerHTML = trimBrs(1161 '<ul>' +1162 '<li>a</βli>' +1163 '<li>b' +1164 '<ul>' +1165 '<li>c</βli>' +1166 '</βul>' +1167 '</βli>' +1168 '</βul>'1169 );1170 editor.focus();1171 Utils.setSelection('li:nth-child(2)', 0);1172 execCommand('Indent');1173 equal(editor.getContent(),1174 '<ul>' +1175 '<li>a' +1176 '<ul>' +1177 '<li>b</βli>' +1178 '<li>c</βli>' +1179 '</βul>' +1180 '</βli>' +1181 '</βul>'1182 );1183 equal(editor.selection.getNode().nodeName, 'LI');1184});1185test('Indent second LI to same level as nested LI 2', function() {1186 editor.getBody().innerHTML = trimBrs(1187 '<ul>' +1188 '<li>a' +1189 '<ul>' +1190 '<li>b</βli>' +1191 '</βul>' +1192 '</βli>' +1193 '<li>cd' +1194 '<ul>' +1195 '<li>e</βli>' +1196 '</βul>' +1197 '</βli>' +1198 '</βul>'1199 );1200 editor.focus();1201 Utils.setSelection('li:nth-child(2)', 1);1202 execCommand('Indent');1203 equal(editor.getContent(),1204 '<ul>' +1205 '<li>a' +1206 '<ul>' +1207 '<li>b</βli>' +1208 '<li>cd</βli>' +1209 '<li>e</βli>' +1210 '</βul>' +1211 '</βli>' +1212 '</βul>'1213 );1214 equal(editor.selection.getNode().nodeName, 'LI');1215});1216test('Indent second and third LI', function() {1217 editor.getBody().innerHTML = trimBrs(1218 '<ul>' +1219 '<li>a</βli>' +1220 '<li>b</βli>' +1221 '<li>c</βli>' +1222 '</βul>'1223 );1224 editor.focus();1225 Utils.setSelection('li:nth-child(2)', 0, 'li:last', 0);1226 execCommand('Indent');1227 equal(editor.getContent(),1228 '<ul>' +1229 '<li>a' +1230 '<ul>' +1231 '<li>b</βli>' +1232 '<li>c</βli>' +1233 '</βul>' +1234 '</βli>' +1235 '</βul>'1236 );1237});1238/β/β Backspace1239test('Backspace at beginning of single LI in UL', function() {1240 editor.getBody().innerHTML = trimBrs(1241 '<ul>' +1242 '<li>a</βli>' +1243 '</βul>'1244 );1245 editor.focus();1246 Utils.setSelection('li', 0);1247 editor.plugins.lists.backspaceDelete();1248 equal(editor.getContent(),1249 '<p>a</βp>'1250 );1251 equal(editor.selection.getNode().nodeName, 'P');1252});1253test('Backspace at beginning of first LI in UL', function() {1254 editor.getBody().innerHTML = trimBrs(1255 '<ul>' +1256 '<li>a</βli>' +1257 '<li>b</βli>' +1258 '</βul>'1259 );1260 editor.focus();1261 Utils.setSelection('li', 0);1262 editor.plugins.lists.backspaceDelete();1263 equal(editor.getContent(),1264 '<p>a</βp>' +1265 '<ul>' +1266 '<li>b</βli>' +1267 '</βul>'1268 );1269 equal(editor.selection.getNode().nodeName, 'P');1270});1271test('Backspace at beginning of middle LI in UL', function() {1272 editor.getBody().innerHTML = trimBrs(1273 '<ul>' +1274 '<li>a</βli>' +1275 '<li>b</βli>' +1276 '<li>c</βli>' +1277 '</βul>'1278 );1279 editor.focus();1280 Utils.setSelection('li:nth-child(2)', 0);1281 editor.plugins.lists.backspaceDelete();1282 equal(editor.getContent(),1283 '<ul>' +1284 '<li>ab</βli>' +1285 '<li>c</βli>' +1286 '</βul>'1287 );1288 equal(editor.selection.getNode().nodeName, 'LI');1289});1290test('Backspace at beginning of start LI in UL inside UL', function() {1291 editor.getBody().innerHTML = trimBrs(1292 '<ul>' +1293 '<li>a' +1294 '<ul>' +1295 '<li>b</βli>' +1296 '<li>c</βli>' +1297 '</βul>' +1298 '</βli>' +1299 '</βul>'1300 );1301 editor.focus();1302 Utils.setSelection('li li', 0);1303 editor.plugins.lists.backspaceDelete();1304 equal(editor.getContent(),1305 '<ul>' +1306 '<li>ab' +1307 '<ul>' +1308 '<li>c</βli>' +1309 '</βul>' +1310 '</βli>' +1311 '</βul>'1312 );1313 equal(editor.selection.getNode().nodeName, 'LI');1314});1315test('Backspace at beginning of middle LI in UL inside UL', function() {1316 editor.getBody().innerHTML = trimBrs(1317 '<ul>' +1318 '<li>a' +1319 '<ul>' +1320 '<li>b</βli>' +1321 '<li>c</βli>' +1322 '<li>d</βli>' +1323 '</βul>' +1324 '</βli>' +1325 '</βul>'1326 );1327 editor.focus();1328 Utils.setSelection('li li:nth-child(2)', 0);1329 editor.plugins.lists.backspaceDelete();1330 equal(editor.getContent(),1331 '<ul>' +1332 '<li>a' +1333 '<ul>' +1334 '<li>bc</βli>' +1335 '<li>d</βli>' +1336 '</βul>' +1337 '</βli>' +1338 '</βul>'1339 );1340 equal(editor.selection.getNode().nodeName, 'LI');1341});1342test('Backspace at beginning of single LI in UL', function() {1343 editor.getBody().innerHTML = trimBrs(1344 '<ul>' +1345 '<li>a</βli>' +1346 '</βul>'1347 );1348 editor.focus();1349 Utils.setSelection('li', 0);1350 editor.plugins.lists.backspaceDelete();1351 equal(editor.getContent(),1352 '<p>a</βp>'1353 );1354 equal(editor.selection.getNode().nodeName, 'P');1355});1356test('Backspace at beginning of first LI in UL', function() {1357 editor.getBody().innerHTML = trimBrs(1358 '<ul>' +1359 '<li>a</βli>' +1360 '<li>b</βli>' +1361 '</βul>'1362 );1363 editor.focus();1364 Utils.setSelection('li', 0);1365 editor.plugins.lists.backspaceDelete();1366 equal(editor.getContent(),1367 '<p>a</βp>' +1368 '<ul>' +1369 '<li>b</βli>' +1370 '</βul>'1371 );1372 equal(editor.selection.getNode().nodeName, 'P');1373});1374test('Backspace at beginning of middle LI in UL', function() {1375 editor.getBody().innerHTML = trimBrs(1376 '<ul>' +1377 '<li>a</βli>' +1378 '<li>b</βli>' +1379 '<li>c</βli>' +1380 '</βul>'1381 );1382 editor.focus();1383 Utils.setSelection('li:nth-child(2)', 0);1384 editor.plugins.lists.backspaceDelete();1385 equal(editor.getContent(),1386 '<ul>' +1387 '<li>ab</βli>' +1388 '<li>c</βli>' +1389 '</βul>'1390 );1391 equal(editor.selection.getNode().nodeName, 'LI');1392});1393test('Backspace at beginning of start LI in UL inside UL', function() {1394 editor.getBody().innerHTML = trimBrs(1395 '<ul>' +1396 '<li>a' +1397 '<ul>' +1398 '<li>b</βli>' +1399 '<li>c</βli>' +1400 '</βul>' +1401 '</βli>' +1402 '</βul>'1403 );1404 editor.focus();1405 Utils.setSelection('li li', 0);1406 editor.plugins.lists.backspaceDelete();1407 equal(editor.getContent(),1408 '<ul>' +1409 '<li>ab' +1410 '<ul>' +1411 '<li>c</βli>' +1412 '</βul>' +1413 '</βli>' +1414 '</βul>'1415 );1416 equal(editor.selection.getNode().nodeName, 'LI');1417});1418test('Backspace at beginning of middle LI in UL inside UL', function() {1419 editor.getBody().innerHTML = trimBrs(1420 '<ul>' +1421 '<li>a' +1422 '<ul>' +1423 '<li>b</βli>' +1424 '<li>c</βli>' +1425 '<li>d</βli>' +1426 '</βul>' +1427 '</βli>' +1428 '</βul>'1429 );1430 editor.focus();1431 Utils.setSelection('li li:nth-child(2)', 0);1432 editor.plugins.lists.backspaceDelete();1433 equal(editor.getContent(),1434 '<ul>' +1435 '<li>a' +1436 '<ul>' +1437 '<li>bc</βli>' +1438 '<li>d</βli>' +1439 '</βul>' +1440 '</βli>' +1441 '</βul>'1442 );1443 equal(editor.selection.getNode().nodeName, 'LI');1444});1445test('Backspace at beginning of LI with empty LI above in UL', function() {1446 editor.getBody().innerHTML = trimBrs(1447 '<ul>' +1448 '<li>a</βli>' +1449 '<li></βli>' +1450 '<li>b</βli>' +1451 '</βul>'1452 );1453 editor.focus();1454 Utils.setSelection('li:nth-child(3)', 0);1455 editor.plugins.lists.backspaceDelete();1456 equal(editor.getContent(),1457 '<ul>' +1458 '<li>a</βli>' +1459 '<li>b</βli>' +1460 '</βul>'1461 );1462 equal(editor.selection.getNode().innerHTML, 'b');1463});1464test('Backspace at beginning of LI with BR padded empty LI above in UL', function() {1465 editor.getBody().innerHTML = (1466 '<ul>' +1467 '<li>a</βli>' +1468 '<li><br></βli>' +1469 '<li>b</βli>' +1470 '</βul>'1471 );1472 editor.focus();1473 Utils.setSelection('li:nth-child(3)', 0);1474 editor.plugins.lists.backspaceDelete();1475 equal(editor.getContent(),1476 '<ul>' +1477 '<li>a</βli>' +1478 '<li>b</βli>' +1479 '</βul>'1480 );1481 equal(editor.selection.getNode().innerHTML, 'b');1482});1483test('Backspace at empty LI (IE)', function() {1484 editor.getBody().innerHTML = (1485 '<ul>' +1486 '<li>a</βli>' +1487 '<li></βli>' +1488 '<li>b</βli>' +1489 '</βul>'1490 );1491 editor.focus();1492 Utils.setSelection('li:nth-child(2)', 0);1493 editor.plugins.lists.backspaceDelete();1494 equal(editor.getContent(),1495 '<ul>' +1496 '<li>a</βli>' +1497 '<li>b</βli>' +1498 '</βul>'1499 );1500 equal(editor.selection.getNode().innerHTML, 'a');1501});1502test('Backspace at beginning of LI with empty LI with STRING and BR above in UL', function() {1503 editor.getBody().innerHTML = (1504 '<ul>' +1505 '<li>a</βli>' +1506 '<li><strong><br></βstrong></βli>' +1507 '<li>b</βli>' +1508 '</βul>'1509 );1510 editor.focus();1511 Utils.setSelection('li:nth-child(3)', 0);1512 editor.plugins.lists.backspaceDelete();1513 equal(editor.getContent(),1514 '<ul>' +1515 '<li>a</βli>' +1516 '<li>b</βli>' +1517 '</βul>'1518 );1519 equal(editor.selection.getNode().innerHTML, 'b');1520});1521/β/β Delete1522test('Delete at end of single LI in UL', function() {1523 editor.getBody().innerHTML = trimBrs(1524 '<ul>' +1525 '<li>a</βli>' +1526 '</βul>'1527 );1528 editor.focus();1529 Utils.setSelection('li', 1);1530 editor.plugins.lists.backspaceDelete(true);1531 equal(editor.getContent(),1532 '<ul>' +1533 '<li>a</βli>' +1534 '</βul>'1535 );1536 equal(editor.selection.getNode().nodeName, 'LI');1537});1538test('Delete at end of first LI in UL', function() {1539 editor.getBody().innerHTML = trimBrs(1540 '<ul>' +1541 '<li>a</βli>' +1542 '<li>b</βli>' +1543 '</βul>'1544 );1545 editor.focus();1546 Utils.setSelection('li', 1);1547 editor.plugins.lists.backspaceDelete(true);1548 equal(editor.getContent(),1549 '<ul>' +1550 '<li>ab</βli>' +1551 '</βul>'1552 );1553 equal(editor.selection.getNode().nodeName, 'LI');1554});1555test('Delete at end of middle LI in UL', function() {1556 editor.getBody().innerHTML = trimBrs(1557 '<ul>' +1558 '<li>a</βli>' +1559 '<li>b</βli>' +1560 '<li>c</βli>' +1561 '</βul>'1562 );1563 editor.focus();1564 Utils.setSelection('li:nth-child(2)', 1);1565 editor.plugins.lists.backspaceDelete(true);1566 equal(editor.getContent(),1567 '<ul>' +1568 '<li>a</βli>' +1569 '<li>bc</βli>' +1570 '</βul>'1571 );1572 equal(editor.selection.getNode().nodeName, 'LI');1573});1574test('Delete at end of start LI in UL inside UL', function() {1575 editor.getBody().innerHTML = trimBrs(1576 '<ul>' +1577 '<li>a' +1578 '<ul>' +1579 '<li>b</βli>' +1580 '<li>c</βli>' +1581 '</βul>' +1582 '</βli>' +1583 '</βul>'1584 );1585 editor.focus();1586 Utils.setSelection('li li', 1);1587 editor.plugins.lists.backspaceDelete(true);1588 equal(editor.getContent(),1589 '<ul>' +1590 '<li>a' +1591 '<ul>' +1592 '<li>bc</βli>' +1593 '</βul>' +1594 '</βli>' +1595 '</βul>'1596 );1597 equal(editor.selection.getNode().nodeName, 'LI');1598});1599test('Delete at end of middle LI in UL inside UL', function() {1600 editor.getBody().innerHTML = trimBrs(1601 '<ul>' +1602 '<li>a' +1603 '<ul>' +1604 '<li>b</βli>' +1605 '<li>c</βli>' +1606 '<li>d</βli>' +1607 '</βul>' +1608 '</βli>' +1609 '</βul>'1610 );1611 editor.focus();1612 Utils.setSelection('li li:nth-child(2)', 1);1613 editor.plugins.lists.backspaceDelete(true);1614 equal(editor.getContent(),1615 '<ul>' +1616 '<li>a' +1617 '<ul>' +1618 '<li>b</βli>' +1619 '<li>cd</βli>' +1620 '</βul>' +1621 '</βli>' +1622 '</βul>'1623 );1624 equal(editor.selection.getNode().nodeName, 'LI');1625});1626test('Delete at end of LI before empty LI', function() {1627 editor.getBody().innerHTML = (1628 '<ul>' +1629 '<li>a</βli>' +1630 '<li></βli>' +1631 '<li>b</βli>' +1632 '</βul>'1633 );1634 editor.focus();1635 Utils.setSelection('li', 1);1636 editor.plugins.lists.backspaceDelete(true);1637 equal(editor.getContent(),1638 '<ul>' +1639 '<li>a</βli>' +1640 '<li>b</βli>' +1641 '</βul>'1642 );1643 equal(editor.selection.getNode().innerHTML, 'a');1644});1645test('Delete at end of LI before BR padded empty LI', function() {1646 editor.getBody().innerHTML = (1647 '<ul>' +1648 '<li>a</βli>' +1649 '<li><br></βli>' +1650 '<li>b</βli>' +1651 '</βul>'1652 );1653 editor.focus();1654 Utils.setSelection('li', 1);1655 editor.plugins.lists.backspaceDelete(true);1656 equal(editor.getContent(),1657 '<ul>' +1658 '<li>a</βli>' +1659 '<li>b</βli>' +1660 '</βul>'1661 );1662 equal(editor.selection.getNode().innerHTML, 'a');1663});1664test('Delete at end of LI before empty LI with STRONG', function() {1665 editor.getBody().innerHTML = (1666 '<ul>' +1667 '<li>a</βli>' +1668 '<li><strong><br></βstrong></βli>' +1669 '<li>b</βli>' +1670 '</βul>'1671 );1672 editor.focus();1673 Utils.setSelection('li', 1);1674 editor.plugins.lists.backspaceDelete(true);1675 equal(editor.getContent(),1676 '<ul>' +1677 '<li>a</βli>' +1678 '<li>b</βli>' +1679 '</βul>'1680 );1681 equal(editor.selection.getNode().innerHTML, 'a');1682});1683test('Remove UL in inline body element contained in LI', function() {1684 inlineEditor.setContent('<ul><li>a</βli></βul>');1685 inlineEditor.selection.setCursorLocation();1686 inlineEditor.execCommand('InsertUnorderedList');1687 equal(inlineEditor.getContent(), '<p>a</βp>');1688});1689test('Backspace in LI in UL in inline body element contained within LI', function() {1690 inlineEditor.setContent('<ul><li>a</βli></βul>');1691 inlineEditor.focus();1692 inlineEditor.selection.select(inlineEditor.getBody(), true);1693 inlineEditor.selection.collapse(true);1694 inlineEditor.plugins.lists.backspaceDelete();1695 equal(inlineEditor.getContent(), '<p>a</βp>');1696});1697test('Apply DL list to multiple Ps', function() {1698 editor.getBody().innerHTML = trimBrs(1699 '<p>a</βp>' +1700 '<p>b</βp>' +1701 '<p>c</βp>'1702 );1703 editor.focus();1704 Utils.setSelection('p', 0, 'p:last', 0);1705 execCommand('InsertDefinitionList');1706 equal(editor.getContent(),1707 '<dl>' +1708 '<dt>a</βdt>' +1709 '<dt>b</βdt>' +1710 '<dt>c</βdt>' +1711 '</βdl>'1712 );1713 equal(editor.selection.getStart().nodeName, 'DT');1714});1715test('Apply OL list to single P', function() {1716 editor.getBody().innerHTML = trimBrs(1717 '<p>a</βp>'1718 );1719 editor.focus();1720 Utils.setSelection('p', 0);1721 execCommand('InsertDefinitionList');1722 equal(editor.getContent(), '<dl><dt>a</βdt></βdl>');1723 equal(editor.selection.getNode().nodeName, 'DT');1724});1725test('Apply DL to P and merge with adjacent lists', function() {1726 editor.getBody().innerHTML = trimBrs(1727 '<dl>' +1728 '<dt>a</βdt>' +1729 '</βdl>' +1730 '<p>b</βp>' +1731 '<dl>' +1732 '<dt>c</βdt>' +1733 '</βdl>'1734 );1735 editor.focus();1736 Utils.setSelection('p', 1);1737 execCommand('InsertDefinitionList');1738 equal(editor.getContent(),1739 '<dl>' +1740 '<dt>a</βdt>' +1741 '<dt>b</βdt>' +1742 '<dt>c</βdt>' +1743 '</βdl>'1744 );1745 equal(editor.selection.getStart().nodeName, 'DT');1746});1747test('Indent single DT in DL', function() {1748 editor.getBody().innerHTML = trimBrs(1749 '<dl>' +1750 '<dt>a</βdt>' +1751 '</βdl>'1752 );1753 editor.focus();1754 Utils.setSelection('dt', 0);1755 execCommand('Indent');1756 equal(editor.getContent(),1757 '<dl>' +1758 '<dd>a</βdd>' +1759 '</βdl>'1760 );1761 equal(editor.selection.getNode().nodeName, 'DD');1762});1763test('Outdent single DD in DL', function() {1764 editor.getBody().innerHTML = trimBrs(1765 '<dl>' +1766 '<dd>a</βdd>' +1767 '</βdl>'1768 );1769 editor.focus();1770 Utils.setSelection('dd', 1);1771 execCommand('Outdent');1772 equal(editor.getContent(),1773 '<dl>' +1774 '<dt>a</βdt>' +1775 '</βdl>'1776 );1777 equal(editor.selection.getNode().nodeName, 'DT');...
EnterKey.js
Source: EnterKey.js
...29 }30});31test('Enter at end of H1', function() {32 editor.setContent('<h1>abc</βh1>');33 Utils.setSelection('h1', 3);34 Utils.pressEnter();35 equal(editor.getContent(),'<h1>abc</βh1><p>\u00a0</βp>');36 equal(editor.selection.getRng(true).startContainer.nodeName, 'P');37});38test('Enter in midde of H1', function() {39 editor.setContent('<h1>abcd</βh1>');40 Utils.setSelection('h1', 2);41 Utils.pressEnter();42 equal(editor.getContent(),'<h1>ab</βh1><h1>cd</βh1>');43 equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'H1');44});45test('Enter before text after EM', function() {46 editor.setContent('<p><em>a</βem>b</βp>');47 editor.selection.setCursorLocation(editor.getBody().firstChild, 1);48 Utils.pressEnter();49 equal(editor.getContent(),'<p><em>a</βem></βp><p>b</βp>');50 var rng = editor.selection.getRng(true);51 equal(rng.startContainer.nodeValue, 'b');52});53test('Enter before first IMG in P', function() {54 editor.setContent('<p><img alt="" src="about:blank" /β></βp>');55 editor.selection.setCursorLocation(editor.getBody().firstChild, 0);56 Utils.pressEnter();57 equal(editor.getContent(),'<p>\u00a0</βp><p><img src="about:blank" alt="" /β></βp>');58});59test('Enter before last IMG in P with text', function() {60 editor.setContent('<p>abc<img alt="" src="about:blank" /β></βp>');61 editor.selection.setCursorLocation(editor.getBody().firstChild, 1);62 Utils.pressEnter();63 equal(editor.getContent(),'<p>abc</βp><p><img src="about:blank" alt="" /β></βp>');64 var rng = editor.selection.getRng(true);65 equal(rng.startContainer.nodeName, 'P');66 equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'IMG');67});68test('Enter before last IMG in P with IMG sibling', function() {69 editor.setContent('<p><img src="about:blank" alt="" /β><img src="about:blank" alt="" /β></βp>');70 editor.selection.setCursorLocation(editor.getBody().firstChild, 1);71 Utils.pressEnter();72 equal(editor.getContent(),'<p><img src="about:blank" alt="" /β></βp><p><img src="about:blank" alt="" /β></βp>');73 var rng = editor.selection.getRng(true);74 equal(rng.startContainer.nodeName, 'P');75 equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'IMG');76});77test('Enter after last IMG in P', function() {78 editor.setContent('<p>abc<img alt="" src="about:blank" /β></βp>');79 editor.selection.setCursorLocation(editor.getBody().firstChild, 2);80 Utils.pressEnter();81 equal(editor.getContent(),'<p>abc<img src="about:blank" alt="" /β></βp><p>\u00a0</βp>');82});83test('Enter before last INPUT in P with text', function() {84 editor.setContent('<p>abc<input type="text" /β></βp>');85 editor.selection.setCursorLocation(editor.getBody().firstChild, 1);86 Utils.pressEnter();87 equal(editor.getContent(),'<p>abc</βp><p><input type="text" /β></βp>');88 var rng = editor.selection.getRng(true);89 equal(rng.startContainer.nodeName, 'P');90 equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT');91});92test('Enter before last INPUT in P with IMG sibling', function() {93 editor.setContent('<p><input type="text" /β><input type="text" /β></βp>');94 editor.selection.setCursorLocation(editor.getBody().firstChild, 1);95 Utils.pressEnter();96 equal(editor.getContent(),'<p><input type="text" /β></βp><p><input type="text" /β></βp>');97 var rng = editor.selection.getRng(true);98 equal(rng.startContainer.nodeName, 'P');99 equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT');100});101test('Enter after last INPUT in P', function() {102 editor.setContent('<p>abc<input type="text" /β></βp>');103 editor.selection.setCursorLocation(editor.getBody().firstChild, 2);104 Utils.pressEnter();105 equal(editor.getContent(),'<p>abc<input type="text" /β></βp><p>\u00a0</βp>');106});107test('Enter at end of P', function() {108 editor.setContent('<p>abc</βp>');109 Utils.setSelection('p', 3);110 Utils.pressEnter();111 equal(editor.getContent(),'<p>abc</βp><p>\u00a0</βp>');112 equal(editor.selection.getRng(true).startContainer.nodeName, 'P');113});114test('Enter at end of EM inside P', function() {115 editor.setContent('<p><em>abc</βem></βp>');116 Utils.setSelection('em', 3);117 Utils.pressEnter();118 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/β<br([^>]+|)>| /βg, ''), '<p><em>abc</βem></βp><p><em></βem></βp>');119 equal(editor.selection.getRng(true).startContainer.nodeName, 'EM');120});121test('Enter at middle of EM inside P', function() {122 editor.setContent('<p><em>abcd</βem></βp>');123 Utils.setSelection('em', 2);124 Utils.pressEnter();125 equal(editor.getContent(),'<p><em>ab</βem></βp><p><em>cd</βem></βp>');126 equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM');127});128test('Enter at beginning EM inside P', function() {129 editor.setContent('<p><em>abc</βem></βp>');130 Utils.setSelection('em', 0);131 Utils.pressEnter();132 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/β<br([^>]+|)>| /βg, ''), '<p><em></βem></βp><p><em>abc</βem></βp>');133 equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc');134});135test('Enter at end of STRONG in EM inside P', function() {136 editor.setContent('<p><em><strong>abc</βstrong></βem></βp>');137 Utils.setSelection('strong', 3);138 Utils.pressEnter();139 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/β<br([^>]+|)>| /βg, ''), '<p><em><strong>abc</βstrong></βem></βp><p><em><strong></βstrong></βem></βp>');140 equal(editor.selection.getRng(true).startContainer.nodeName, 'STRONG');141});142test('Enter at middle of STRONG in EM inside P', function() {143 editor.setContent('<p><em><strong>abcd</βstrong></βem></βp>');144 Utils.setSelection('strong', 2);145 Utils.pressEnter();146 equal(editor.getContent(),'<p><em><strong>ab</βstrong></βem></βp><p><em><strong>cd</βstrong></βem></βp>');147 equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG');148});149test('Enter at beginning STRONG in EM inside P', function() {150 editor.setContent('<p><em><strong>abc</βstrong></βem></βp>');151 Utils.setSelection('strong', 0);152 Utils.pressEnter();153 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/β<br([^>]+|)>| /βg, ''), '<p><em><strong></βstrong></βem></βp><p><em><strong>abc</βstrong></βem></βp>');154 equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc');155});156test('Enter at beginning of P', function() {157 editor.setContent('<p>abc</βp>');158 Utils.setSelection('p', 0);159 Utils.pressEnter();160 equal(editor.getContent(),'<p>\u00a0</βp><p>abc</βp>');161 equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc');162});163test('Enter at middle of P with style, id and class attributes', function() {164 editor.setContent('<p id="a" class="b" style="color:#000">abcd</βp>');165 Utils.setSelection('p', 2);166 Utils.pressEnter();167 equal(editor.getContent(),'<p id="a" class="b" style="color: #000;">ab</βp><p class="b" style="color: #000;">cd</βp>');168 equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');169});170test('Enter at a range between H1 and P', function() {171 editor.setContent('<h1>abcd</βh1><p>efgh</βp>');172 Utils.setSelection('h1', 2, 'p', 2);173 Utils.pressEnter();174 equal(editor.getContent(),'<h1>abgh</βh1>');175 equal(editor.selection.getNode().nodeName, 'H1');176});177test('Enter at end of H1 in HGROUP', function() {178 editor.setContent('<hgroup><h1>abc</βh1></βhgroup>');179 Utils.setSelection('h1', 3);180 Utils.pressEnter();181 equal(editor.getContent(),'<hgroup><h1>abc</βh1><h1>\u00a0</βh1></βhgroup>');182 equal(editor.selection.getRng(true).startContainer.nodeName, 'H1');183});184test('Enter inside empty TD', function() {185 editor.getBody().innerHTML = '<table><tr><td></βtd></βtr></βtable>';186 Utils.setSelection('td', 0);187 Utils.pressEnter();188 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace(/β<br([^>]+|)>| /βg, ''), '<table><tbody><tr><td><p></βp><p></βp></βtd></βtr></βtbody></βtable>');189 equal(editor.selection.getNode().nodeName, 'P');190});191test('Shift+Enter inside STRONG inside TD with BR', function() {192 editor.getBody().innerHTML = '<table><tr><td>d <strong>e</βstrong><br></βtd></βtr></βtable>';193 Utils.setSelection('strong', 1);194 Utils.pressEnter({shiftKey: true});195 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<table><tbody><tr><td>d <strong>e<br></βstrong><br></βtd></βtr></βtbody></βtable>');196 equal(editor.selection.getNode().nodeName, 'STRONG');197});198test('Enter inside middle of text node in body', function() {199 editor.getBody().innerHTML = 'abcd';200 Utils.setSelection('body', 2);201 Utils.pressEnter();202 equal(editor.getContent(),'<p>ab</βp><p>cd</βp>');203 equal(editor.selection.getNode().nodeName, 'P');204});205test('Enter inside at beginning of text node in body', function() {206 editor.getBody().innerHTML = 'abcd';207 Utils.setSelection('body', 0);208 Utils.pressEnter();209 equal(editor.getContent(),'<p>\u00a0</βp><p>abcd</βp>');210 equal(editor.selection.getNode().nodeName, 'P');211});212test('Enter inside at end of text node in body', function() {213 editor.getBody().innerHTML = 'abcd';214 Utils.setSelection('body', 4);215 Utils.pressEnter();216 equal(editor.getContent(),'<p>abcd</βp><p>\u00a0</βp>');217 equal(editor.selection.getNode().nodeName, 'P');218});219test('Enter inside empty body', function() {220 editor.getBody().innerHTML = '';221 Utils.setSelection('body', 0);222 Utils.pressEnter();223 equal(editor.getContent(),'<p>\u00a0</βp><p>\u00a0</βp>');224 equal(editor.selection.getNode().nodeName, 'P');225});226test('Enter inside empty li in beginning of ol', function() {227 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li></βli><li>a</βli></βol>': '<ol><li><br></βli><li>a</βli></βol>';228 Utils.setSelection('li', 0);229 Utils.pressEnter();230 equal(editor.getContent(),'<p>\u00a0</βp><ol><li>a</βli></βol>');231 equal(editor.selection.getNode().nodeName, 'P');232});233test('Enter inside empty li at the end of ol', function() {234 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli></βol>': '<ol><li>a</βli><li><br></βli></βol>';235 Utils.setSelection('li:last', 0);236 Utils.pressEnter();237 equal(editor.getContent(),'<ol><li>a</βli></βol><p>\u00a0</βp>');238 equal(editor.selection.getNode().nodeName, 'P');239});240test('Shift+Enter inside empty li in the middle of ol', function() {241 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli><li>b</βli></βol>': '<ol><li>a</βli><li><br></βli><li>b</βli></βol>';242 Utils.setSelection('li:nth-child(2)', 0);243 Utils.pressEnter({shiftKey: true});244 equal(editor.getContent(),'<ol><li>a</βli></βol><p>\u00a0</βp><ol><li>b</βli></βol>');245 equal(editor.selection.getNode().nodeName, 'P');246});247test('Shift+Enter inside empty li in beginning of ol', function() {248 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li></βli><li>a</βli></βol>': '<ol><li><br></βli><li>a</βli></βol>';249 Utils.setSelection('li', 0);250 Utils.pressEnter({shiftKey: true});251 equal(editor.getContent(),'<p>\u00a0</βp><ol><li>a</βli></βol>');252 equal(editor.selection.getNode().nodeName, 'P');253});254test('Shift+Enter inside empty li at the end of ol', function() {255 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli></βol>': '<ol><li>a</βli><li><br></βli></βol>';256 Utils.setSelection('li:last', 0);257 Utils.pressEnter({shiftKey: true});258 equal(editor.getContent(),'<ol><li>a</βli></βol><p>\u00a0</βp>');259 equal(editor.selection.getNode().nodeName, 'P');260});261test('Enter inside empty li in the middle of ol with forced_root_block: false', function() {262 editor.settings.forced_root_block = false;263 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli><li>b</βli></βol>': '<ol><li>a</βli><li><br></βli><li>b</βli></βol>';264 Utils.setSelection('li:nth-child(2)', 0);265 Utils.pressEnter();266 equal(editor.getContent(),'<ol><li>a</βli></βol><br /β><ol><li>b</βli></βol>');267 equal(editor.selection.getNode().nodeName, 'BODY');268});269test('Enter inside empty li in beginning of ol with forced_root_block: false', function() {270 editor.settings.forced_root_block = false;271 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li></βli><li>a</βli></βol>': '<ol><li><br></βli><li>a</βli></βol>';272 Utils.setSelection('li', 0);273 Utils.pressEnter();274 equal(editor.getContent(),'<br /β><ol><li>a</βli></βol>');275 equal(editor.selection.getNode().nodeName, 'BODY');276});277test('Enter inside empty li at the end of ol with forced_root_block: false', function() {278 editor.settings.forced_root_block = false;279 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli></βol>': '<ol><li>a</βli><li><br></βli></βol>';280 Utils.setSelection('li:last', 0);281 Utils.pressEnter();282 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<ol><li>a</βli></βol><br>');283 equal(editor.selection.getNode().nodeName, 'BODY');284});285test('Enter inside empty li in the middle of ol', function() {286 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li>a</βli><li></βli><li>b</βli></βol>': '<ol><li>a</βli><li><br></βli><li>b</βli></βol>';287 Utils.setSelection('li:nth-child(2)', 0);288 Utils.pressEnter();289 equal(editor.getContent(),'<ol><li>a</βli></βol><p>\u00a0</βp><ol><li>b</βli></βol>');290 equal(editor.selection.getNode().nodeName, 'P');291});292/β/β Nested lists in LI elements293test('Enter inside empty LI in beginning of OL in LI', function() {294 editor.getBody().innerHTML = Utils.trimBrsOnIE(295 '<ol>' +296 '<li>a' +297 '<ol>' +298 '<li><br></βli>' +299 '<li>a</βli>' +300 '</βol>' +301 '</βli>' +302 '</βol>'303 );304 Utils.setSelection('li li', 0);305 editor.focus();306 Utils.pressEnter();307 equal(editor.getContent(),308 '<ol>' +309 '<li>a</βli>' +310 '<li>' +311 '<ol>' +312 '<li>a</βli>' +313 '</βol>' +314 '</βli>' +315 '</βol>'316 );317 equal(editor.selection.getNode().nodeName, 'LI');318});319test('Enter inside empty LI in middle of OL in LI', function() {320 editor.getBody().innerHTML = Utils.trimBrsOnIE(321 '<ol>' +322 '<li>a' +323 '<ol>' +324 '<li>a</βli>' +325 '<li><br></βli>' +326 '<li>b</βli>' +327 '</βol>' +328 '</βli>' +329 '</βol>'330 );331 Utils.setSelection('li li:nth-child(2)', 0);332 editor.focus();333 Utils.pressEnter();334 equal(editor.getContent(),335 '<ol>' +336 '<li>a' +337 '<ol>' +338 '<li>a</βli>' +339 '</βol>' +340 '</βli>' +341 '<li>\u00a0' +342 '<ol>' +343 '<li>b</βli>' +344 '</βol>' +345 '</βli>' +346 '</βol>'347 );348 /β/β Ignore on IE 7, 8 this is a known bug not worth fixing349 if (!tinymce.Env.ie || tinymce.Env.ie > 8) {350 equal(editor.selection.getNode().nodeName, 'LI');351 }352});353test('Enter inside empty LI in end of OL in LI', function() {354 editor.getBody().innerHTML = Utils.trimBrsOnIE(355 '<ol>' +356 '<li>a' +357 '<ol>' +358 '<li>a</βli>' +359 '<li><br></βli>' +360 '</βol>' +361 '</βli>' +362 '</βol>'363 );364 Utils.setSelection('li li:last', 0);365 editor.focus();366 Utils.pressEnter();367 equal(editor.getContent(),368 '<ol>' +369 '<li>a' +370 '<ol>' +371 '<li>a</βli>' +372 '</βol>' +373 '</βli>' +374 '<li></βli>' +375 '</βol>'376 );377 equal(editor.selection.getNode().nodeName, 'LI');378});379/β/β Nested lists in OL elements380/β/β Ignore on IE 7, 8 this is a known bug not worth fixing381if (!tinymce.Env.ie || tinymce.Env.ie > 8) {382 test('Enter before nested list', function() {383 editor.getBody().innerHTML = Utils.trimBrsOnIE(384 '<ol>' +385 '<li>a' +386 '<ul>' +387 '<li>b</βli>' +388 '<li>c</βli>' +389 '</βul>' +390 '</βli>' +391 '</βol>'392 );393 Utils.setSelection('ol > li', 1);394 editor.focus();395 Utils.pressEnter();396 equal(editor.getContent(),397 '<ol>' +398 '<li>a</βli>' +399 '<li>\u00a0' +400 '<ul>' +401 '<li>b</βli>' +402 '<li>c</βli>' +403 '</βul>' +404 '</βli>' +405 '</βol>'406 );407 equal(editor.selection.getNode().nodeName, 'LI');408 });409}410test('Enter inside empty LI in beginning of OL in OL', function() {411 editor.getBody().innerHTML = Utils.trimBrsOnIE(412 '<ol>' +413 '<li>a</βli>' +414 '<ol>' +415 '<li><br></βli>' +416 '<li>a</βli>' +417 '</βol>' +418 '</βol>'419 );420 Utils.setSelection('ol ol li', 0);421 editor.focus();422 Utils.pressEnter();423 equal(editor.getContent(),424 '<ol>' +425 '<li>a</βli>' +426 '<li></βli>' +427 '<ol>' +428 '<li>a</βli>' +429 '</βol>' +430 '</βol>'431 );432 equal(editor.selection.getNode().nodeName, 'LI');433});434test('Enter inside empty LI in middle of OL in OL', function() {435 editor.getBody().innerHTML = Utils.trimBrsOnIE(436 '<ol>' +437 '<li>a</βli>' +438 '<ol>' +439 '<li>a</βli>' +440 '<li><br></βli>' +441 '<li>b</βli>' +442 '</βol>' +443 '</βol>'444 );445 Utils.setSelection('ol ol li:nth-child(2)', 0);446 editor.focus();447 Utils.pressEnter();448 equal(editor.getContent(),449 '<ol>' +450 '<li>a</βli>' +451 '<ol>' +452 '<li>a</βli>' +453 '</βol>' +454 '<li></βli>' +455 '<ol>' +456 '<li>b</βli>' +457 '</βol>' +458 '</βol>'459 );460 equal(editor.selection.getNode().nodeName, 'LI');461});462test('Enter inside empty LI in end of OL in OL', function() {463 editor.getBody().innerHTML = Utils.trimBrsOnIE(464 '<ol>' +465 '<li>a</βli>' +466 '<ol>' +467 '<li>a</βli>' +468 '<li><br></βli>' +469 '</βol>' +470 '</βol>'471 );472 Utils.setSelection('ol ol li:last', 0);473 editor.focus();474 Utils.pressEnter();475 equal(editor.getContent(),476 '<ol>' +477 '<li>a</βli>' +478 '<ol>' +479 '<li>a</βli>' +480 '</βol>' +481 '<li></βli>' +482 '</βol>'483 );484 equal(editor.selection.getNode().nodeName, 'LI');485});486test('Enter at beginning of first DT inside DL', function() {487 editor.getBody().innerHTML = '<dl><dt>a</βdt></βdl>';488 Utils.setSelection('dt', 0);489 Utils.pressEnter();490 equal(editor.getContent(),'<dl><dt>\u00a0</βdt><dt>a</βdt></βdl>');491 equal(editor.selection.getNode().nodeName, 'DT');492});493test('Enter at beginning of first DD inside DL', function() {494 editor.getBody().innerHTML = '<dl><dd>a</βdd></βdl>';495 Utils.setSelection('dd', 0);496 Utils.pressEnter();497 equal(editor.getContent(),'<dl><dd>\u00a0</βdd><dd>a</βdd></βdl>');498 equal(editor.selection.getNode().nodeName, 'DD');499});500test('Enter at beginning of middle DT inside DL', function() {501 editor.getBody().innerHTML = '<dl><dt>a</βdt><dt>b</βdt><dt>c</βdt></βdl>';502 Utils.setSelection('dt:nth-child(2)', 0);503 Utils.pressEnter();504 equal(editor.getContent(),'<dl><dt>a</βdt><dt>\u00a0</βdt><dt>b</βdt><dt>c</βdt></βdl>');505 equal(editor.selection.getNode().nodeName, 'DT');506});507test('Enter at beginning of middle DD inside DL', function() {508 editor.getBody().innerHTML = '<dl><dd>a</βdd><dd>b</βdd><dd>c</βdd></βdl>';509 Utils.setSelection('dd:nth-child(2)', 0);510 Utils.pressEnter();511 equal(editor.getContent(),'<dl><dd>a</βdd><dd>\u00a0</βdd><dd>b</βdd><dd>c</βdd></βdl>');512 equal(editor.selection.getNode().nodeName, 'DD');513});514test('Enter at end of last DT inside DL', function() {515 editor.getBody().innerHTML = '<dl><dt>a</βdt></βdl>';516 Utils.setSelection('dt', 1);517 Utils.pressEnter();518 equal(editor.getContent(),'<dl><dt>a</βdt><dt>\u00a0</βdt></βdl>');519 equal(editor.selection.getNode().nodeName, 'DT');520});521test('Enter at end of last DD inside DL', function() {522 editor.getBody().innerHTML = '<dl><dd>a</βdd></βdl>';523 Utils.setSelection('dd', 1);524 Utils.pressEnter();525 equal(editor.getContent(),'<dl><dd>a</βdd><dd>\u00a0</βdd></βdl>');526 equal(editor.selection.getNode().nodeName, 'DD');527});528test('Enter at end of last empty DT inside DL', function() {529 editor.getBody().innerHTML = '<dl><dt>a</βdt><dt></βdt></βdl>';530 Utils.setSelection('dt:nth-child(2)', 0);531 Utils.pressEnter();532 equal(editor.getContent(),'<dl><dt>a</βdt></βdl><p>\u00a0</βp>');533 equal(editor.selection.getNode().nodeName, 'P');534});535test('Enter at end of last empty DD inside DL', function() {536 editor.getBody().innerHTML = '<dl><dd>a</βdd><dd></βdd></βdl>';537 Utils.setSelection('dd:nth-child(2)', 0);538 Utils.pressEnter();539 equal(editor.getContent(),'<dl><dd>a</βdd></βdl><p>\u00a0</βp>');540 equal(editor.selection.getNode().nodeName, 'P');541});542test('Enter at beginning of P inside LI', function() {543 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';544 Utils.setSelection('p', 0);545 Utils.pressEnter();546 equal(editor.getContent(),'<ol><li></βli><li><p>abcd</βp></βli></βol>');547 equal(editor.selection.getNode().nodeName, 'P');548});549test('Enter inside middle of P inside LI', function() {550 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';551 Utils.setSelection('p', 2);552 Utils.pressEnter();553 equal(editor.getContent(),'<ol><li><p>ab</βp></βli><li><p>cd</βp></βli></βol>');554 /β/β Ignore on IE 7, 8 this is a known bug not worth fixing555 if (!tinymce.Env.ie || tinymce.Env.ie > 8) {556 equal(editor.selection.getNode().nodeName, 'P');557 }558});559test('Enter at end of P inside LI', function() {560 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';561 Utils.setSelection('p', 4);562 Utils.pressEnter();563 equal(editor.getContent(),'<ol><li><p>abcd</βp></βli><li></βli></βol>');564 equal(editor.selection.getNode().nodeName, 'LI');565});566test('Shift+Enter at beginning of P inside LI', function() {567 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';568 Utils.setSelection('p', 0);569 Utils.pressEnter({shiftKey: true});570 equal(editor.getContent(),'<ol><li><p><br /β>abcd</βp></βli></βol>');571 equal(editor.selection.getNode().nodeName, 'P');572});573test('Shift+Enter inside middle of P inside LI', function() {574 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';575 Utils.setSelection('p', 2);576 Utils.pressEnter({shiftKey: true});577 equal(editor.getContent(),'<ol><li><p>ab<br /β>cd</βp></βli></βol>');578 equal(editor.selection.getNode().nodeName, 'P');579});580test('Shift+Enter at end of P inside LI', function() {581 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';582 Utils.setSelection('p', 4);583 Utils.pressEnter({shiftKey: true});584 equal(editor.getContent(),(tinymce.isIE && tinymce.Env.ie < 11) ? '<ol><li><p>abcd</βp></βli></βol>': '<ol><li><p>abcd<br /β><br /β></βp></βli></βol>');585 equal(editor.selection.getNode().nodeName, 'P');586});587test('Ctrl+Enter at beginning of P inside LI', function() {588 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';589 Utils.setSelection('p', 0);590 Utils.pressEnter({ctrlKey: true});591 equal(editor.getContent(),'<ol><li><p>\u00a0</βp><p>abcd</βp></βli></βol>');592 equal(editor.selection.getNode().nodeName, 'P');593});594test('Ctrl+Enter inside middle of P inside LI', function() {595 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';596 Utils.setSelection('p', 2);597 Utils.pressEnter({ctrlKey: true});598 equal(editor.getContent(),'<ol><li><p>ab</βp><p>cd</βp></βli></βol>');599 equal(editor.selection.getNode().nodeName, 'P');600});601test('Ctrl+Enter at end of P inside LI', function() {602 editor.getBody().innerHTML = '<ol><li><p>abcd</βp></βli></βol>';603 Utils.setSelection('p', 4);604 Utils.pressEnter({ctrlKey: true});605 equal(editor.getContent(),'<ol><li><p>abcd</βp><p>\u00a0</βp></βli></βol>');606 equal(editor.selection.getNode().nodeName, 'P');607});608test('Enter in the middle of text in P with forced_root_block set to false', function() {609 editor.settings.forced_root_block = false;610 editor.getBody().innerHTML = '<p>abc</βp>';611 Utils.setSelection('p', 2);612 Utils.pressEnter();613 equal(editor.getContent(),'<p>ab<br /β>c</βp>');614});615test('Enter at the end of text in P with forced_root_block set to false', function() {616 editor.settings.forced_root_block = false;617 editor.getBody().innerHTML = '<p>abc</βp>';618 Utils.setSelection('p', 3);619 Utils.pressEnter();620 equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? '<p>abc<br></βp>': '<p>abc<br><br></βp>');621});622test('Enter at the middle of text in BODY with forced_root_block set to false', function() {623 editor.settings.forced_root_block = false;624 editor.getBody().innerHTML = 'abcd';625 Utils.setSelection('body', 2);626 editor.focus();627 Utils.pressEnter();628 equal(Utils.cleanHtml(editor.getBody().innerHTML), 'ab<br>cd');629});630test('Enter at the beginning of text in BODY with forced_root_block set to false', function() {631 editor.settings.forced_root_block = false;632 editor.getBody().innerHTML = 'abcd';633 Utils.setSelection('body', 0);634 editor.focus();635 Utils.pressEnter();636 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<br>abcd');637});638test('Enter at the end of text in BODY with forced_root_block set to false', function() {639 editor.settings.forced_root_block = false;640 editor.getBody().innerHTML = 'abcd';641 Utils.setSelection('body', 4);642 editor.focus();643 Utils.pressEnter();644 equal(Utils.cleanHtml(editor.getBody().innerHTML), (tinymce.isIE && tinymce.Env.ie < 11) ? 'abcd<br>': 'abcd<br><br>');645});646test('Enter in empty P at the end of a blockquote and end_container_on_empty_block: true', function() {647 editor.settings.end_container_on_empty_block = true;648 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<blockquote><p>abc</βp><p></βp></βblockquote>': '<blockquote><p>abc</βp><p><br></βp></βblockquote>';649 Utils.setSelection('p:last', 0);650 Utils.pressEnter();651 equal(editor.getContent(),'<blockquote><p>abc</βp></βblockquote><p>\u00a0</βp>');652});653test('Enter in empty P at the beginning of a blockquote and end_container_on_empty_block: true', function() {654 editor.settings.end_container_on_empty_block = true;655 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<blockquote><p></βp><p>abc</βp></βblockquote>': '<blockquote><p><br></βp><p>abc</βp></βblockquote>';656 Utils.setSelection('p', 0);657 Utils.pressEnter();658 equal(editor.getContent(),'<p>\u00a0</βp><blockquote><p>abc</βp></βblockquote>');659});660test('Enter in empty P at in the middle of a blockquote and end_container_on_empty_block: true', function() {661 editor.settings.end_container_on_empty_block = true;662 editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '<blockquote><p>abc</βp><p></βp><p>123</βp></βblockquote>': '<blockquote><p>abc</βp><p><br></βp><p>123</βp></βblockquote>';663 Utils.setSelection('p:nth-child(2)', 0);664 Utils.pressEnter();665 equal(editor.getContent(),'<blockquote><p>abc</βp></βblockquote><p>\u00a0</βp><blockquote><p>123</βp></βblockquote>');666});667test('Enter inside empty P with empty P siblings', function() {668 /β/β Tests that a workaround for an IE bug is working correctly669 editor.getBody().innerHTML = '<p></βp><p></βp><p>X</βp>';670 Utils.setSelection('p', 0);671 Utils.pressEnter();672 equal(editor.getContent(),'<p>\u00a0</βp><p>\u00a0</βp><p>\u00a0</βp><p>X</βp>');673});674test('Enter at end of H1 with forced_root_block_attrs', function() {675 editor.settings.forced_root_block_attrs = {"class": "class1"};676 editor.getBody().innerHTML = '<h1>a</βh1>';677 Utils.setSelection('h1', 1);678 Utils.pressEnter();679 equal(editor.getContent(),'<h1>a</βh1><p class="class1">\u00a0</βp>');680});681test('Shift+Enter at beginning of P', function() {682 editor.getBody().innerHTML = '<p>abc</βp>';683 Utils.setSelection('p', 0);684 Utils.pressEnter({shiftKey: true});685 equal(editor.getContent(),'<p><br /β>abc</βp>');686});687test('Shift+Enter in the middle of P', function() {688 editor.getBody().innerHTML = '<p>abcd</βp>';689 Utils.setSelection('p', 2);690 Utils.pressEnter({shiftKey: true});691 equal(editor.getContent(),'<p>ab<br /β>cd</βp>');692});693test('Shift+Enter at the end of P', function() {694 editor.getBody().innerHTML = '<p>abcd</βp>';695 Utils.setSelection('p', 4);696 Utils.pressEnter({shiftKey: true});697 equal(editor.getContent(),(tinymce.isIE && tinymce.Env.ie < 11) ? '<p>abcd</βp>': '<p>abcd<br /β><br /β></βp>');698});699test('Shift+Enter in the middle of B with a BR after it', function() {700 editor.getBody().innerHTML = '<p><b>abcd</βb><br></βp>';701 Utils.setSelection('b', 2);702 Utils.pressEnter({shiftKey: true});703 equal(editor.getContent(),'<p><b>ab<br /β>cd</βb></βp>');704});705test('Shift+Enter at the end of B with a BR after it', function() {706 editor.getBody().innerHTML = '<p><b>abcd</βb><br></βp>';707 Utils.setSelection('b', 4);708 Utils.pressEnter({shiftKey: true});709 equal(editor.getContent(),'<p><b>abcd<br /β></βb></βp>');710});711test('Enter in beginning of PRE', function() {712 editor.getBody().innerHTML = '<pre>abc</βpre>';713 Utils.setSelection('pre', 0);714 Utils.pressEnter();715 equal(editor.getContent(),'<pre><br /β>abc</βpre>');716});717test('Enter in the middle of PRE', function() {718 editor.getBody().innerHTML = '<pre>abcd</βpre>';719 Utils.setSelection('pre', 2);720 Utils.pressEnter();721 equal(editor.getContent(),'<pre>ab<br /β>cd</βpre>');722});723test('Enter at the end of PRE', function() {724 editor.getBody().innerHTML = '<pre>abcd</βpre>';725 Utils.setSelection('pre', 4);726 Utils.pressEnter();727 equal(editor.getContent(),(tinymce.isIE && tinymce.Env.ie < 11) ? '<pre>abcd</βpre>': '<pre>abcd<br /β><br /β></βpre>');728});729test('Enter in beginning of PRE and br_in_pre: false', function() {730 editor.settings.br_in_pre = false;731 editor.getBody().innerHTML = '<pre>abc</βpre>';732 Utils.setSelection('pre', 0);733 Utils.pressEnter();734 equal(editor.getContent(),'<pre>\u00a0</βpre><pre>abc</βpre>');735});736test('Enter in the middle of PRE and br_in_pre: false', function() {737 editor.settings.br_in_pre = false;738 editor.getBody().innerHTML = '<pre>abcd</βpre>';739 Utils.setSelection('pre', 2);740 Utils.pressEnter();741 equal(editor.getContent(),'<pre>ab</βpre><pre>cd</βpre>');742});743test('Enter at the end of PRE and br_in_pre: false', function() {744 editor.settings.br_in_pre = false;745 editor.getBody().innerHTML = '<pre>abcd</βpre>';746 Utils.setSelection('pre', 4);747 Utils.pressEnter();748 equal(editor.getContent(),'<pre>abcd</βpre><p>\u00a0</βp>');749});750test('Shift+Enter in beginning of PRE', function() {751 editor.getBody().innerHTML = '<pre>abc</βpre>';752 Utils.setSelection('pre', 0);753 Utils.pressEnter({shiftKey: true});754 equal(editor.getContent(),'<pre>\u00a0</βpre><pre>abc</βpre>');755});756test('Shift+Enter in the middle of PRE', function() {757 editor.getBody().innerHTML = '<pre>abcd</βpre>';758 Utils.setSelection('pre', 2);759 Utils.pressEnter({shiftKey: true});760 equal(editor.getContent(),'<pre>ab</βpre><pre>cd</βpre>');761});762test('Shift+Enter at the end of PRE', function() {763 editor.getBody().innerHTML = '<pre>abcd</βpre>';764 Utils.setSelection('pre', 4);765 Utils.pressEnter({shiftKey: true});766 equal(editor.getContent(),'<pre>abcd</βpre><p>\u00a0</βp>');767});768test('Shift+Enter in beginning of P with forced_root_block set to false', function() {769 editor.settings.forced_root_block = false;770 editor.getBody().innerHTML = '<p>abc</βp>';771 Utils.setSelection('p', 0);772 Utils.pressEnter({shiftKey: true});773 equal(editor.getContent(),'<p>\u00a0</βp><p>abc</βp>');774});775test('Shift+Enter in middle of P with forced_root_block set to false', function() {776 editor.settings.forced_root_block = false;777 editor.getBody().innerHTML = '<p>abcd</βp>';778 Utils.setSelection('p', 2);779 Utils.pressEnter({shiftKey: true});780 equal(editor.getContent(),'<p>ab</βp><p>cd</βp>');781});782test('Shift+Enter at the end of P with forced_root_block set to false', function() {783 editor.settings.forced_root_block = false;784 editor.getBody().innerHTML = '<p>abc</βp>';785 Utils.setSelection('p', 3);786 Utils.pressEnter({shiftKey: true});787 equal(editor.getContent(),'<p>abc</βp><p>\u00a0</βp>');788});789test('Shift+Enter in body with forced_root_block set to false', function() {790 editor.settings.forced_root_block = false;791 editor.getBody().innerHTML = 'abcd';792 var rng = editor.dom.createRng();793 rng.setStart(editor.getBody().firstChild, 2);794 rng.setEnd(editor.getBody().firstChild, 2);795 editor.selection.setRng(rng);796 Utils.pressEnter({shiftKey: true});797 equal(editor.getContent(),'<p>ab</βp><p>cd</βp>');798});799test('Enter at the end of DIV layer', function() {800 editor.settings.br_in_pre = false;801 editor.setContent('<div style="position: absolute; top: 1px; left: 2px;">abcd</βdiv>');802 Utils.setSelection('div', 4);803 Utils.pressEnter();804 equal(editor.getContent(),'<div style="position: absolute; top: 1px; left: 2px;"><p>abcd</βp><p>\u00a0</βp></βdiv>');805});806test('Enter in div inside contentEditable:false div', function() {807 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><div>abcd</βdiv></βdiv>';808 Utils.setSelection('div div', 2);809 Utils.pressEnter();810 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><div>abcd</βdiv></βdiv>');811});812test('Enter in div with contentEditable:true inside contentEditable:false div', function() {813 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><div data-mce-contenteditable="true">abcd</βdiv></βdiv>';814 Utils.setSelection('div div', 2);815 Utils.pressEnter();816 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><div data-mce-contenteditable="true"><p>ab</βp><p>cd</βp></βdiv></βdiv>');817});818test('Enter in span with contentEditable:true inside contentEditable:false div', function() {819 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">abcd</βspan></βdiv>';820 Utils.setSelection('span', 2);821 Utils.pressEnter();822 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">abcd</βspan></βdiv>');823});824test('Shift+Enter in span with contentEditable:true inside contentEditable:false div', function() {825 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">abcd</βspan></βdiv>';826 Utils.setSelection('span', 2);827 Utils.pressEnter({shiftKey: true});828 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">ab<br>cd</βspan></βdiv>');829});830test('Enter in span with contentEditable:true inside contentEditable:false div and forced_root_block: false', function() {831 editor.settings.forced_root_block = false;832 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">abcd</βspan></βdiv>';833 Utils.setSelection('span', 2);834 Utils.pressEnter();835 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><span data-mce-contenteditable="true">ab<br>cd</βspan></βdiv>');836});837test('Enter in em within contentEditable:true div inside contentEditable:false div', function() {838 editor.getBody().innerHTML = '<div data-mce-contenteditable="false"><div data-mce-contenteditable="true"><em>abcd</βem></βdiv></βdiv>';839 Utils.setSelection('em', 2);840 Utils.pressEnter();841 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<div data-mce-contenteditable="false"><div data-mce-contenteditable="true"><p><em>ab</βem></βp><p><em>cd</βem></βp></βdiv></βdiv>');842});843test('Enter at end of text in a span inside a P and keep_styles: false', function() {844 editor.settings.keep_styles = false;845 editor.getBody().innerHTML = '<p><em><span style="font-size: 13px;">X</βspan></βem></βp>';846 Utils.setSelection('span', 1);847 Utils.pressEnter();848 equal(editor.getContent(),'<p><em><span style="font-size: 13px;">X</βspan></βem></βp><p>\u00a0</βp>');849});850test('Shift+enter in LI when forced_root_block: false', function() {851 editor.settings.forced_root_block = false;852 editor.getBody().innerHTML = '<ul><li>text</βli></βul>';853 Utils.setSelection('li', 2);854 Utils.pressEnter({shiftKey: true});855 equal(editor.getContent(),'<ul><li>te<br /β>xt</βli></βul>');856});857test('Enter when forced_root_block: false and force_p_newlines: true', function() {858 editor.settings.forced_root_block = false;859 editor.settings.force_p_newlines = true;860 editor.getBody().innerHTML = 'text';861 Utils.setSelection('body', 2);862 Utils.pressEnter();863 equal(editor.getContent(),'<p>te</βp><p>xt</βp>');864});865test('Enter at end of br line', function() {866 editor.settings.forced_root_block = false;867 editor.settings.force_p_newlines = true;868 editor.getBody().innerHTML = '<p>a<br>b</βp>';869 Utils.setSelection('p', 1);870 Utils.pressEnter();871 equal(editor.getContent(), '<p>a</βp><p><br /β>b</βp>');872 var rng = editor.selection.getRng(true);873 equal(rng.startContainer.nodeName, 'P');874 equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'BR');875});876/β/β Ignore on IE 7, 8 this is a known bug not worth fixing877if (!tinymce.Env.ie || tinymce.Env.ie > 8) {878 test('Enter before BR between DIVs', function() {879 editor.getBody().innerHTML = '<div>a<span>b</βspan>c</βdiv><br /β><div>d</βdiv>';880 var rng = editor.dom.createRng();881 rng.setStartBefore(editor.dom.select('br')[0]);882 rng.setEndBefore(editor.dom.select('br')[0]);883 editor.selection.setRng(rng);...
setSelection.js
Source: setSelection.js
1/β**2 * Created by romain & hen (hendrik.strobelt.com)3 */β4function plotSetOverview() {5 var initialize = false;6 var animate = false;7 if (arguments[0]) {8 console.log(arguments[0]);9 initialize = arguments[0].initialize || false;10 if (initialize) {11 ctx.setSelection.mode = "none"12 ctx.setSelection.modeChange = false;13 ctx.setSelection.multiSelIn = d3.set();14 ctx.setSelection.multiSelOut = d3.set();15 }16/β/β animate = arguments[0].animate || false;17/β/β mode = arguments[0].mode || "none";18 }19 console.log("plotSetOverview");20 var majorPadding = 5;21 var minorPadding = 2;22 var cellDistance = 20;23 var cellSize = cellDistance;/β/β - minorPadding;24 var setCellDistance = 12;25 var setCellSize = 10;26 var differenceForMultiSel = 7;27 var textHeight = 62 - differenceForMultiSel;28 var truncateAfter = 7;29 var distanceUsedMenu = 15;30 var paddingForPaginationRight = 115;31 var paddingForPaginationRightExtra = (ctx.setSelection.mode === "none") ? 0 : 100;32 const paginationLinespace = 14;33 var headerSVG = d3.select('#headerVis').select('svg');34 /β/β calculate widths35 var svgWidth = headerSVG.attr("width");36 var menuOffset = usedSets.length * cellSize + distanceUsedMenu;37 var maxWidthUnused = svgWidth - menuOffset - paddingForPaginationRight - paddingForPaginationRightExtra - distanceUsedMenu - cellDistance;38 var unusedSets = sets.filter(function (n) {39 return usedSets.indexOf(n) == -140 });41 /β/β --- INIT the SVG structure (d3 version)42 var setSelectionGroup = headerSVG.selectAll(".setSelection").data([1]);43 setSelectionGroup.enter().append("g").attr({44 class: "setSelection",45 "transform": "translate(" + 0 + "," + 0 + ")"46 })47 /β/β scale for the size of the subSets, also used for the sets48 var setSizeScale = d3.scale.linear().domain([0, d3.max(sets, function (d) {49 return d.setSize;50 })]).nice().range([0, textHeight]);51 function updateUsedSets() {52 /β/β ----------------------------53 /β/β/β-- Render the used Sets54 /β/β ----------------------------55 var usedSetsVis = setSelectionGroup.selectAll(".usedSets").data([1]);56 usedSetsVis.enter().append("g").attr("class", "usedSets");57 usedSetsVis.attr({58 "transform": "translate(" + 0 + "," + differenceForMultiSel + ")"59 })60 var usedSetsLabels = usedSetsVis61 .selectAll('.setLabel')62 .data(usedSets, function (d) {63 return d.elementName;64 })65 usedSetsLabels.exit().remove();66 var usedSetsLabelsEnter = usedSetsLabels.enter().append("g").attr("class", "setLabel").attr({67 transform: function (d, i) {68 return 'translate(' + (cellDistance * (i)) + ', 0)'69 },70 opacity: .171 });72 usedSetsLabelsEnter73 .append('rect')74 .attr({75 class: 'setSizeBackground',76 height: (textHeight + 1),77 width: cellSize,/β/βsetRowScale.rangeBand()78 title: function (d) {79 return d.setSize80 }81 })82 .on('click', setClicked)83 .on('mouseover', function (d, i) {84 mouseoverColumn(d, i);85 })86 .on('mouseout', function (d, i) {87 mouseoutColumn(d, i);88 })89 .append("svg:title")90 .text(function (d) {91 return d.elementName + " (" + d.setSize + ")";92 });93 /β/β background bar94 usedSetsLabelsEnter95 .append('rect')96 .attr({97 class: 'setSizeRect setSize',98 x: 1,99 width: cellSize - 2/β/βsetRowScale.rangeBand()100 })101 /β/β .attr("transform", "skewX(45)")102 .on('mouseover', mouseoverColumn)103 .on('mouseout', mouseoutColumn)104 .on('click', setClicked)105 .append("svg:title")106 .text(function (d) {107 return d.elementName + " (" + d.setSize + ")";108 });109 /β/β *** update sizes (might happen when changing datasets)110 d3.selectAll(".usedSets .setSize").transition().duration(1000).attr({111 y: function (d) {112 return (textHeight - (setSizeScale(d.setSize)));113 },114 height: function (d) {115 return setSizeScale(d.setSize);116 }117 });118 usedSetsLabelsEnter.transition().duration(400).delay(400).attr({119 opacity: 1120 })121 /β/β *** update group position122/β/β usedSetsLabels123/β/β .attr({124/β/β transform: function (d, i) {125/β/β return 'translate(' + (cellDistance * i) + ', 0)'126/β/β }127/β/β })128 usedSetsLabels.attr({129 transform: function (d, i) {130 if (ctx.setSelection.mode === "multiSel") {131 if (ctx.setSelection.multiSelOut.has(d.elementName)) {132 return 'translate(' + (cellDistance * i) + ', -' + differenceForMultiSel + ')'133 } else {134 return 'translate(' + (cellDistance * i) + ', 0)'135 }136 } else {137 return 'translate(' + (cellDistance * i) + ', 0)'138 }139 }140 })141 usedSetsLabels.selectAll(".setSizeRect")142 .attr({143 "class": function (d) {144 if (ctx.setSelection.multiSelOut.has(d.elementName)) {145 return 'setSizeRect unusedSetSize'146 } else {147 return 'setSizeRect setSize'148 }149 }150 })151 }152 updateUsedSets();153 function updateUnusedSets() {154 /β/β ----------------------------155 /β/β/β-- Render the unused Sets156 /β/β ----------------------------157 var sortSize = function (a, b) {158 return b.setSize - a.setSize;159 };160 var sortName = function (a, b) {161 return d3.ascending(a.elementName, b.elementName);162 };163 var sortFn;164 if (ctx.setSelection.setOrder === "name") {165 sortFn = sortName;166 } else {167 sortFn = sortSize;168 }169 var unuseedSetsOffset = menuOffset + paddingForPaginationRight + paddingForPaginationRightExtra + distanceUsedMenu;170 unusedSets.sort(sortFn);171 var unusedSetsGroup = setSelectionGroup.selectAll(".unusedSets").data([1])172 unusedSetsGroup.enter().append("g").attr("class", "unusedSets")173 unusedSetsGroup.attr({174 "transform": function (d) {175 if (ctx.setSelection.mode === "multiSel") {176 return 'translate(' + unuseedSetsOffset + ', 0)'177 } else {178 return 'translate(' + unuseedSetsOffset + ', ' + differenceForMultiSel + ')'179 }180 }181 })182 if (maxWidthUnused < cellDistance) {183 unusedSetsGroup.selectAll('.unusedSetLabel').remove();184 } else {185 /β*186 * add only if there is enough space !!!187 * */β188 console.log(maxWidthUnused, cellDistance);189 var paginationDistance = Math.floor(maxWidthUnused /β cellDistance);190 console.log(maxWidthUnused, cellDistance, paginationDistance);191 if (initialize) {192 ctx.setSelection.paginationStart = +0;193 }194 ctx.setSelection.paginationEnd = +ctx.setSelection.paginationStart + paginationDistance;195 var unusedSetsFiltered = unusedSets.filter(196 function (d, i) {197 return ((ctx.setSelection.paginationStart <= i) && (i <= ctx.setSelection.paginationEnd));198 }199 )200 /β*201 * create buttons for pagination202 * */β203 updatePaginationDecoration();204 var unusedSetsLabels = unusedSetsGroup205 .selectAll('.unusedSetLabel')206 .data(unusedSetsFiltered, function (d) {207 return d.elementName;208 })209 unusedSetsLabels.exit().remove();210 var unusedSetsLabelsEnter = unusedSetsLabels.enter().append("g").attr("class", "unusedSetLabel").attr({211 transform: function (d, i) {212 return 'translate(' + (cellDistance * (i)) + ', -10)'213 },214 opacity: .1215 });216 unusedSetsLabelsEnter217 .append('rect')218 .attr({219 class: 'unusedSetSizeBackground',220/β/β transform: function (d, i) {221/β/β return 'translate(' + (cellDistance * (i )) + ', 20)'222/β/β },223 height: textHeight - 2,224 width: cellSize225 })226 .on('click', setClicked)227 unusedSetsLabelsEnter228 .append('rect')229 .attr({230 class: 'setSizeRect unusedSetSize',231 transform: function (d, i) {232 return 'translate(1, ' + (textHeight - setSizeScale(d.setSize)) + ')'233 }, /β/β ' + (textHeight - 5) + ')'234 height: function (d) {235 return setSizeScale(d.setSize);236 },237 width: cellSize - 2,238 })239 .on('click', setClicked)240 /β/β .append('title').text(function (d) {return d});241 /β/β .append('title').text("what");242/β/β .append("svg:title")243/β/β .text(function(d, i) { return d.elementName + " (" +d.setSize+ ")"; });;244 unusedSetsLabelsEnter245 .append('text').text(function (d) {246 if (d.elementName.length > (truncateAfter + 3)) {247 var str = d.elementName.substring(0, truncateAfter)248 if (str.length < d.elementName.length)249 str = str.trim() + "...";250 } else {251 str = d.elementName.trim();252 }253 return str;254 })255 .attr({256 class: 'setLabel',257 transform: function (d, i) {258 return 'translate(' + (cellDistance + 5) + ', 0) rotate(90)'259 },260 y: cellSize - 3,261 x: 3,262 height: textHeight - 4,263 'text-anchor': 'start'264 })265 .on('click', setClicked)266 .append("svg:title")267 .text(function (d, i) {268 return d.elementName + " (" + d.setSize + ")";269 });270/β/β console.log("animate:", animate);271/β/β var updateUnusedPos =unusedSetsLabelsEnter;272/β/β if (animate){273/β/β updateUnusedPos= unusedSetsLabelsEnter274/β/β .transition().duration(400).delay(400)275/β/β }276/β/β updateUnusedPos.attr({277/β/β opacity:1,278/β/β transform: function (d, i) {279/β/β return 'translate(' + (cellDistance * (i ) + unusedLabelOffset) + ', 0)'280/β/β }281/β/β })282 unusedSetsLabels.attr({283 transform: function (d, i) {284 if (ctx.setSelection.mode === "multiSel") {285 if (ctx.setSelection.multiSelIn.has(d.elementName)) {286 return 'translate(' + (cellDistance * (i)) + ', ' + differenceForMultiSel + ')'287 } else {288 return 'translate(' + (cellDistance * (i)) + ', 0)'289 }290 } else {291 return 'translate(' + (cellDistance * (i)) + ', 0)'292 }293 },294 opacity: 1295 })296 unusedSetsLabels.selectAll(".setSizeRect")297 .attr({298 "class": function (d) {299 if (ctx.setSelection.multiSelIn.has(d.elementName)) {300 return 'setSizeRect setSize'301 } else {302 return 'setSizeRect unusedSetSize'303 }304 }305 })306 }307 }308 updateUnusedSets();309 function updatePaginationDecoration() {310 var internalLeftPadding = 0 /β/β only local311 var setsRight = unusedSets.length - ctx.setSelection.paginationEnd;312 var setsLeft = ctx.setSelection.paginationStart;313 var middlePos = ((paddingForPaginationRight - internalLeftPadding) /β 2 + internalLeftPadding);314 var paginationDistance = Math.floor(maxWidthUnused /β cellDistance);315 var pagi = headerSVG.selectAll(".pagination")316 .data([{countRight: setsRight, countLeft: setsLeft, distance: paginationDistance}])317 var pagiGroup = pagi.enter().append("g").attr({318 "class": "pagination"319 })320/β/β var finalPos = svgWidth-paddingForPaginationRight;321 var finalPos = menuOffset;322/β/β console.log("finalpos", finalPos);323 if (ctx.setSelection.mode !== "none") {324 finalPos += paddingForPaginationRightExtra;325 }326 if (ctx.setSelection.modeChange) {327 pagi.transition().attr({328 "transform": "translate(" + (finalPos) + ",0)"329 })330 } else {331 pagi.attr({332 "transform": "translate(" + (finalPos) + ",0)"333 })334 }335 pagiGroup.append("text")336 .style({337 "text-anchor": "middle",338 "cursor": "default",339 "font-weight": "bold"340 }).attr({341 "transform": function () {342 return "translate(" + (middlePos) + "," + (.8 * paginationLinespace) + ")";343 }344 }).text("Set Selection")345 pagiGroup.append("rect")346 .attr({347 "class": "selectionRect setSelectionArea",348 x: -5,349 width: paddingForPaginationRight - internalLeftPadding + 5,350 height: paginationLinespace * .9,351 opacity: 0352 })353 pagiGroup.append("text").attr({354 "class": "right setSelectionLabelAwesome"355 }).style({356 "text-anchor": "end"357 }).attr({358 "transform": function () {359 return "translate(" + (paddingForPaginationRight - 2) + "," + (2 * paginationLinespace) + ")";360 }361 })362 pagiGroup.append("text").attr({363 "class": "left setSelectionLabelAwesome"364 }).style({365 "text-anchor": "start"366 }).attr({367 "transform": function () {368 return "translate(" + (internalLeftPadding + 2) + "," + (2 * paginationLinespace) + ")";369 }370 })371 pagiGroup.append("text").attr({372 "class": "info_distance"373 }).style({374 "text-anchor": "middle",375 "cursor": "default"376 }).attr({377 "transform": function (d) {378 return "translate(" + (middlePos) + ","379 + (2 * paginationLinespace) + ")";380 }381 })382 pagiGroup.append("rect").attr({383 "class": "multiSelect setSelectionButton"384 }).attr({385 "transform": "translate(" + (internalLeftPadding + 2) + "," + (2.3 * paginationLinespace) + ")",386 width: paddingForPaginationRight - internalLeftPadding - 4,387 height: .9 * paginationLinespace,388 rx: 5,389 ry: 5390 })391 .on({392 "click": function () {393 if (ctx.setSelection.mode == "none") {394 ctx.setSelection.mode = "multiSel";395 ctx.setSelection.modeChange = true;396 plotSetOverview();397 } else if (ctx.setSelection.mode === "multiSel") {398 ctx.setSelection.multiSelIn = d3.set();399 ctx.setSelection.multiSelOut = d3.set();400 ctx.setSelection.mode = "none";401 ctx.setSelection.modeChange = true;402 plotSetOverview();403 }404 }405 })406 pagiGroup.append("text").attr({407 "class": "multiSelect setSelectionButtonText"408 }).style({409 "text-anchor": "middle",410 "cursor": "pointer",411 "pointer-events": "none"412 }).attr({413 "transform": "translate(" + (middlePos) + "," + (3.0 * paginationLinespace) + ")"414 }).text("Batch Add Sets")415 pagiGroup.append("rect").attr({416 "class": "sortFilter setSelectionButton"417 }).attr({418 "transform": "translate(" + (internalLeftPadding + 2) + "," + (3.3 * paginationLinespace) + ")",419 width: paddingForPaginationRight - internalLeftPadding - 4,420 height: .9 * paginationLinespace,421 rx: 5,422 ry: 5423 })424 .on({425 "click": function () {426 if (ctx.setSelection.mode == "none") {427 ctx.setSelection.mode = "sortFilter";428 ctx.setSelection.modeChange = true;429 plotSetOverview();430 } else if (ctx.setSelection.mode === "sortFilter") {431 ctx.setSelection.mode = "none";432 ctx.setSelection.modeChange = true;433 plotSetOverview();434 }435 }436 })437 pagiGroup.append("text").attr({438 "class": "sortFilter setSelectionButtonText"439 }).style({440 "text-anchor": "middle",441 "cursor": "pointer",442 "pointer-events": "none"443 }).attr({444 "transform": "translate(" + (middlePos) + "," + (4 * paginationLinespace) + ")"445 }).text("Sort Sets")446 /β/β --- UPDATES447 pagi.select(".right").text(function (d) {448/β/β if (d.countRight < 1) return '-|'449/β/β else return '>>';450 if (d.countRight < 1) return ''451 else return '\uf0a9';452 }).on({453 "click": function (d) {454 if (d.countRight > 0) {455 ctx.setSelection.paginationStart = ctx.setSelection.paginationStart + d.distance;456 plotSetOverview({animate: false});457 } else {458 return;459 }460 }461 })462 pagi.select(".left")463 .text(function (d) {464/β/β if (d.countLeft < 1) return '|-'465/β/β else return '<<'; })466 if (d.countLeft < 1) return ''467 else return '\uf0a8';468 })469 /β/β&#f053470 .on({471 "click": function (d) {472 if (d.countLeft > 0) {473 ctx.setSelection.paginationStart = Math.max(ctx.setSelection.paginationStart - d.distance, 0);474 plotSetOverview({animate: false});475 } else {476 return;477 }478 }479 })480 pagi.select(".info_distance").text(function (d) {481 return ctx.setSelection.paginationStart + " - " +482 Math.min(ctx.setSelection.paginationEnd, unusedSets.length)483 })484/β/β pagi.select(".multiSelect").style({485/β/β "font-weight": function () {486/β/β/β/β if (ctx.setSelection.mode === "multiSel"){487/β/β/β/β return "bold"488/β/β/β/β }else{489/β/β return "normal"490/β/β/β/β }491/β/β }492/β/β })493 var selRectPos = 0;494 var selRectOpa = 0;495 if (ctx.setSelection.mode === "multiSel") {496 selRectPos = 2.3 * paginationLinespace;497 selRectOpa = 1;498 } else if (ctx.setSelection.mode === "sortFilter") {499 selRectPos = 3.3 * paginationLinespace;500 selRectOpa = 1;501 }502 if (ctx.setSelection.modeChange) {503 pagi.select(".selectionRect").transition().duration(200)504 .attr({505 y: selRectPos,506 opacity: selRectOpa507 })508 } else {509 pagi.select(".selectionRect").attr({510 y: selRectPos,511 opacity: selRectOpa512 })513 }514 updateSecondMenu();515 /β/β only one pass of mode change rendering516 ctx.setSelection.modeChange = false;517 }518 function updateSecondMenu() {519 var menuContent = []520 if (ctx.setSelection.mode === "multiSel") {521 menuContent =522 [[523 {524 name: "Add All Sets", func: function () {525 unusedSets.forEach(function (d) {526 ctx.setSelection.multiSelIn.add(d.elementName);527 });528 ctx.setSelection.multiSelOut = d3.set();529 plotSetOverview();530 }531 },532 {533 name: "Clear All Sets", func: function () {534 ctx.setSelection.multiSelIn = d3.set();535 usedSets.forEach(function (d) {536 ctx.setSelection.multiSelOut.add(d.elementName);537 });538 plotSetOverview()539 }540 },541 {542 name: "Cancel", func: function () {543 ctx.setSelection.multiSelIn = d3.set();544 ctx.setSelection.multiSelOut = d3.set();545 /β/βclose multiselect panel546 ctx.setSelection.mode = "none"547 ctx.setSelection.modeChange = true548 plotSetOverview();549 }, fontawe: "\uf00d"550 },551 {name: "Confirm", func: bulkChange, fontawe: "\uf00c"}552 ]]553 } else if (ctx.setSelection.mode === "sortFilter") {554 menuContent =555 [[556 {557 name: "by Size", func: function () {558 ctx.setSelection.setOrder = "size"559 ctx.setSelection.mode = "none"560 ctx.setSelection.modeChange = true561 plotSetOverview();562 }563 },564 {565 name: "by Name", func: function () {566 ctx.setSelection.setOrder = "name"567 ctx.setSelection.mode = "none"568 ctx.setSelection.modeChange = true569 plotSetOverview()570 }571 }572 ]]573 }574 var menuExtra = headerSVG.selectAll(".setMenuExtra").data(menuContent);575 menuExtra.exit().remove();576 var menuExtraGroup = menuExtra.enter().append("g").attr("class", "setMenuExtra").attr({577 opacity: .1578 })579 menuExtraGroup.append("rect").attr({580 "class": "setSelectionArea",581 x: 5,582 width: paddingForPaginationRightExtra - 10,583 height: textHeight + 5584 })585 if (ctx.setSelection.modeChange) {586 menuExtra.transition().duration(500)587 .attr({588 opacity: 1589 });590 }591 menuExtra592 .attr({593 "transform": "translate(" + (menuOffset) + "," + 0 + ")"594 });595 var menuExtraGroupEntries = menuExtraGroup.selectAll(".menuExtraEntry").data(function (d) {596 return d;597 })598 menuExtraGroupEntries.enter().append("text")599 .attr({600 "class": function (d) {601 if ('fontawe' in d) {602 return "menuExtraEntry setMenuExtraAwesome"603 } else {604 return "menuExtraEntry"605 }606 },607 "transform": function (d, i) {608 return "translate(" + (paddingForPaginationRightExtra /β 2) + "," + ((1 + (i * 1.0)) * paginationLinespace) + ")";609 }610 })611 .style({612 "cursor": "pointer",613 "text-anchor": "middle"614 })615 .text(function (d) {616 if ('fontawe' in d) {617 return d.fontawe + " " + d.name;618 } else {619 return d.name;620 }621 })622 .on("click", function (d) {623 d.func();624 })625 }626/β/β /β/β -- update position !!!627/β/β var unusedSetsLabels = overview.append("foreignObject")628/β/β .attr("width", 710)629/β/β .attr("height", textHeight+20)630/β/β .attr("x", usedSets.length*cellSize)631/β/β .attr("y", 40)632/β/β .append("xhtml:div")633/β/β .style("overflow-x", "auto")634/β/β .append("svg")635/β/β .attr({636/β/β height: textHeight+20,637/β/β width: unusedSets.length*cellSize638/β/β })639/β/β .append("g")640/β/β /β/β.attr("transform", "translate(-50)")641/β/β .attr("class", "unusedSets")642/β/β .selectAll('.unusedSetsLabels')643/β/β .data(unusedSets)644/β/β .enter();645/β/β646/β/β unusedSetsLabels647/β/β .append('rect')648/β/β .sort(sortFn)649/β/β .attr({650/β/β class: 'unusedSetSizeBackground',651/β/β transform: function (d, i) {652/β/β return 'translate(' + (cellDistance * (i )) + ', 20)'653/β/β },654/β/β height: textHeight-2,655/β/β width: cellSize656/β/β })657/β/β .on('click', setClicked)658/β/β659/β/β660/β/β /β/β background bar661/β/β unusedSetsLabels662/β/β .append('rect')663/β/β .sort(sortFn)664/β/β .attr({665/β/β class: 'unusedSetSize',666/β/β transform: function (d, i) {667/β/β return 'translate(' + (cellDistance * i) + ', ' + ( textHeight - minorPadding - setSizeScale(d.setSize) + 21) + ')'668/β/β }, /β/β ' + (textHeight - 5) + ')'669/β/β height: function (d) {670/β/β return setSizeScale(d.setSize);671/β/β },672/β/β width: cellSize673/β/β })674/β/β /β/β .on('mouseover', mouseoverColumn)675/β/β /β/β .on('mouseout', mouseoutColumn)676/β/β .on('click', setClicked)677/β/β678/β/β unusedSetsLabels679/β/β .append('text').text(function (d) {680/β/β681/β/β /β/βvar tmpText = d3.select("svg").append("text").attr("id", "tmpText").text(d.elementName.substring(0, truncateAfter))682/β/β /β/βvar str = Utilities.truncate(tmpText, 70)683/β/β /β/βtmpText.remove();684/β/β var str = d.elementName.substring(0, truncateAfter)685/β/β if(str.length<d.elementName.length)686/β/β str = str.trim() + "...";687/β/β688/β/β return str;689/β/β })690/β/β .sort(sortFn)691/β/β .attr({692/β/β class: 'setLabel',693/β/β /β/β Not sure we need this..694/β/β /β/β id: function (d) {695/β/β /β/β return d.elementName.substring(0, truncateAfter);696/β/β /β/β },697/β/β transform: function (d, i) {698/β/β return 'translate(' + (cellDistance * (i + 1) + 5) + ', 20) rotate(90)'699/β/β },700/β/β y: cellSize - 3,701/β/β x: 3,702/β/β height: textHeight-4,703/β/β 'text-anchor': 'start'704/β/β705/β/β/β/β transform: function (d, i) {706/β/β/β/β return 'translate(' + (cellDistance * (i ) + cellDistance /β 2) + ',' + (setMatrixHeight + textHeight - textSpacing) + ')rotate(270)';707/β/β/β/β }708/β/β })709/β/β .on('click', setClicked)710/β/β .append("svg:title")711/β/β .text(function(d, i) { return d.elementName + " (" +d.setSize+ ")"; });712 function setClicked(d, i) {713 if (ctx.setSelection.mode === "multiSel") {714 if (d.isSelected) {715 /β/β for usedSets:716 if (ctx.setSelection.multiSelOut.has(d.elementName)) {717 ctx.setSelection.multiSelOut.remove(d.elementName);718 } else {719 ctx.setSelection.multiSelOut.add(d.elementName);720 }721 } else {722 /β/β for UNusedSets:723 if (ctx.setSelection.multiSelIn.has(d.elementName)) {724 ctx.setSelection.multiSelIn.remove(d.elementName);725 } else {726 ctx.setSelection.multiSelIn.add(d.elementName);727 }728 }729 plotSetOverview();730 } else {731 updateSetContainment(d, true);732 }733/β/β d3.selectAll(".bulkCheck").transition().remove();734 }735 function bulkChange() {736 var list_update =737 sets.filter(function (d) {738 return ctx.setSelection.multiSelIn.has(d.elementName) ||739 ctx.setSelection.multiSelOut.has(d.elementName)740 })741 ctx.setSelection.multiSelIn = d3.set();742 ctx.setSelection.multiSelOut = d3.set();743 /β/βclose multiselect panel744 ctx.setSelection.mode = "none"745 ctx.setSelection.modeChange = true746 if (list_update.length > 0) {747 /β/β updateSetCon will call plot again748 list_update.map(function (d, i) {749 updateSetContainment(d, i == list_update.length - 1);750 });751 } else {752 plotSetOverview()753 }754 }755}756/β/β overview.on('mouseover', function(d, i) {757/β/β758/β/β /β/β Remove current transitions759/β/β d3.selectAll(".bulkCheck").transition();760/β/β761/β/β var sortFn;762/β/β763/β/β if (ctx.setOrder === "name") {764/β/β sortFn = sortName;765/β/β } else {766/β/β sortFn = sortSize;767/β/β }768/β/β769/β/β if(d3.selectAll(".bulkCheck")[0].length>5)770/β/β return;771/β/β772/β/β usedSets.filter(function(d, ii) {773/β/β774/β/β d3.select(".usedSets")775/β/β .append("foreignObject")776/β/β .datum([d])777/β/β .attr("width", 100)778/β/β .attr("height", 100)779/β/β .attr("class", "bulkCheck")780/β/β .attr("y", 40)781/β/β .attr("x", function(d, i) {782/β/β return cellDistance * (ii);783/β/β })784/β/β .html("<form><input type=checkbox value=setcheck id=setcheck_"+ii+" checked/β></βform>")785/β/β786/β/β })787/β/β788/β/β var unusedSetsCheck = unusedSets.sort(sortFn).filter(function(d, ii) {789/β/β790/β/β d3.select(".unusedSets")791/β/β .append("foreignObject")792/β/β .datum([d])793/β/β .attr("width", 100)794/β/β .attr("height", 100)795/β/β .attr("class", "bulkCheck unusedSets")796/β/β .attr("y", 0)797/β/β .attr("x", function(d, i) {798/β/β return cellDistance * (ii);799/β/β })800/β/β .html("<form><input type=checkbox value=setcheck id="+ii+" /β></βform>")801/β/β802/β/β })803/β/β804/β/β d3.select("#headerVis").select("svg")805/β/β .append("foreignObject")806/β/β .attr("width", 100)807/β/β .attr("height", 100)808/β/β .attr("class", "bulkCheck")809/β/β .attr("y", 20)810/β/β .attr("x", function(d, i) {811/β/β return 0;/β/βctx.w- usedSets.length*cellDistance-100;812/β/β })813/β/β .html("<form><input type=button value=update /β></βform>")814/β/β .on("click", setClickedByBulk);815/β/β816/β/β d3.select("#headerVis").select("svg")817/β/β .append("foreignObject")818/β/β .attr("width", 100)819/β/β .attr("height", 100)820/β/β .attr("class", "bulkCheck")821/β/β .attr("y", 20)822/β/β .attr("x", function(d, i) {823/β/β return 60;/β/βctx.w- usedSets.length*cellDistance-100;824/β/β })825/β/β .html("<form><input type=button value='all' /β></βform>")826/β/β .on("click", function() {827/β/β d3.selectAll("input[value=setcheck]").property("checked", true);828/β/β });829/β/β830/β/β d3.select("#headerVis").select("svg")831/β/β .append("foreignObject")832/β/β .attr("width", 100)833/β/β .attr("height", 100)834/β/β .attr("class", "bulkCheck")835/β/β .attr("y", 20)836/β/β .attr("x", function(d, i) {837/β/β return 95;/β/βctx.w- usedSets.length*cellDistance-100;838/β/β })839/β/β .html("<form><input type=button value='none' /β></βform>")840/β/β .on("click", function() {841/β/β d3.selectAll("input[value=setcheck]").property("checked", false);842/β/β });843/β/β844/β/β d3.select("#headerVis").select("svg")845/β/β .append("foreignObject")846/β/β .attr("width", 200)847/β/β .attr("height", 100)848/β/β .attr("class", "bulkCheck")849/β/β .attr("y", 20)850/β/β .attr("x", function(d, i) {851/β/β return 145;/β/βctx.w- usedSets.length*cellDistance-100;852/β/β })853/β/β .html("<form style='font-size:12px'>Order by: <input type=radio name='order' value='size' "+ (ctx.setOrder == 'size' ? 'checked' : '') +"/β> Size <input type=radio name='order' value='name' "+ (ctx.setOrder == 'name' ? 'checked' : '') +"/β> Name</βform>")854/β/β .on("click", function() {855/β/β d3.select(this).selectAll("input").each(orderChange);856/β/β });857/β/β858/β/β d3.selectAll(".bulkCheck").on("mouseenter", function() {859/β/β /β/β Remove current transitions860/β/β d3.selectAll(".bulkCheck").transition();861/β/β })862/β/β863/β/β })864/β/β .on('mouseout', function(d, i) {865/β/β mouseoutColumn(d, i);866/β/β d3.selectAll(".bulkCheck").transition().duration(1500).remove();867/β/β })868/β/βfunction orderChange() {869/β/β if(!this.checked)870/β/β return;871/β/β872/β/β var sortFn;873/β/β874/β/β if (this.value === "name") {875/β/β sortFn = sortName;876/β/β ctx.setOrder = "name";877/β/β } else {878/β/β sortFn = sortSize;879/β/β ctx.setOrder = "size";880/β/β }881/β/β882/β/β d3.selectAll(".unusedSets .unusedSetSizeBackground")883/β/β .sort(sortFn)884/β/β .transition().duration(500).delay(function(d, i) {885/β/β return i * 500 /β unusedSets.length;886/β/β })887/β/β .attr("transform", function (d, i) {888/β/β return 'translate(' + (cellDistance * (i )) + ', 20)'889/β/β })890/β/β d3.selectAll(".unusedSets .unusedSetSize")891/β/β .sort(sortFn)892/β/β .transition().duration(500).delay(function(d, i) {893/β/β return i * 500 /β unusedSets.length;894/β/β })895/β/β .attr("transform", function (d, i) {896/β/β return 'translate(' + (cellDistance * i) + ', ' + ( textHeight - minorPadding - setSizeScale(d.setSize) + 20) + ')'897/β/β })898/β/β899/β/β d3.selectAll(".unusedSets .setLabel")900/β/β .sort(sortFn)901/β/β .transition().duration(500).delay(function(d, i) {902/β/β return i * 500 /β unusedSets.length;903/β/β })904/β/β .attr("transform", function (d, i) {905/β/β return 'translate(' + (cellDistance * (i + 1) + 5) + ', 20) rotate(90)'906/β/β })907/β/β908/β/β d3.selectAll(".unusedSets .bulkCheck").remove();909/β/β910/β/β unusedSets.sort(sortFn).filter(function(d, ii) {911/β/β912/β/β d3.select(".unusedSets")913/β/β .append("foreignObject")914/β/β .datum([d])915/β/β .attr("width", 100)916/β/β .attr("height", 100)917/β/β .attr("class", "bulkCheck")918/β/β .attr("y", 0)919/β/β .attr("x", function(d, i) {920/β/β return cellDistance * (ii);921/β/β })922/β/β .html("<form><input type=checkbox value=setcheck id="+ii+" /β></βform>")923/β/β924/β/β })925/β/β...
restrictededitingmodeediting-commands.js
...39 editor.commands.add( 'undo', buildFakeCommand( editor ) );40 } );41 it( 'should be enabled outside exception marker', () => {42 model.change( writer => {43 writer.setSelection( firstParagraph, 1 );44 } );45 expect( editor.commands.get( 'undo' ).isEnabled ).to.be.true;46 } );47 it( 'should be enabled inside exception marker', () => {48 model.change( writer => {49 writer.setSelection( firstParagraph, 5 );50 } );51 expect( editor.commands.get( 'undo' ).isEnabled ).to.be.true;52 } );53 } );54 describe( 'redo', () => {55 beforeEach( () => {56 editor.commands.add( 'redo', buildFakeCommand( editor ) );57 } );58 it( 'should be enabled outside exception marker', () => {59 model.change( writer => {60 writer.setSelection( firstParagraph, 1 );61 } );62 expect( editor.commands.get( 'redo' ).isEnabled ).to.be.true;63 } );64 it( 'should be enabled inside exception marker', () => {65 model.change( writer => {66 writer.setSelection( firstParagraph, 5 );67 } );68 expect( editor.commands.get( 'redo' ).isEnabled ).to.be.true;69 } );70 } );71 } );72 describe( 'commands enabled in exception marker', () => {73 describe( 'input', () => {74 beforeEach( () => {75 editor.commands.add( 'input', buildFakeCommand( editor ) );76 model.change( writer => {77 writer.setSelection( firstParagraph, 'end' );78 } );79 } );80 it( 'should be disabled when caret is outside exception marker', () => {81 model.change( writer => {82 writer.setSelection( firstParagraph, 1 );83 } );84 expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;85 } );86 it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {87 model.change( writer => {88 writer.setSelection( firstParagraph, 5 );89 } );90 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;91 } );92 it( 'should be disabled when caret is inside other marker', () => {93 model.change( writer => {94 writer.addMarker( 'foo-bar:1', {95 range: writer.createRange(96 writer.createPositionAt( firstParagraph, 0 ),97 writer.createPositionAt( firstParagraph, 3 ) ),98 usingOperation: true,99 affectsData: true100 } );101 writer.setSelection( firstParagraph, 1 );102 } );103 expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;104 } );105 it( 'should be enabled when caret is inside exception marker (start boundary)', () => {106 model.change( writer => {107 writer.setSelection( firstParagraph, 4 );108 } );109 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;110 } );111 it( 'should be enabled when caret is inside exception marker (end boundary)', () => {112 model.change( writer => {113 writer.setSelection( firstParagraph, 7 );114 } );115 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;116 } );117 it( 'should be disabled for multi-range selection (collapsed ranges)', () => {118 model.change( writer => {119 writer.setSelection( [120 writer.createRange(121 writer.createPositionAt( firstParagraph, 5 )122 ),123 writer.createRange(124 writer.createPositionAt( firstParagraph, 9 )125 )126 ] );127 } );128 expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;129 } );130 it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {131 model.change( writer => {132 writer.setSelection( writer.createRange(133 writer.createPositionAt( firstParagraph, 0 ),134 writer.createPositionAt( firstParagraph, 5 )135 ) );136 } );137 expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;138 } );139 it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {140 model.change( writer => {141 writer.setSelection( writer.createRange(142 writer.createPositionAt( firstParagraph, 5 ),143 writer.createPositionAt( firstParagraph, 6 )144 ) );145 } );146 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;147 } );148 it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {149 model.change( writer => {150 writer.setSelection( writer.createRange(151 writer.createPositionAt( firstParagraph, 4 ),152 writer.createPositionAt( firstParagraph, 6 )153 ) );154 } );155 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;156 } );157 it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {158 model.change( writer => {159 writer.setSelection( writer.createRange(160 writer.createPositionAt( firstParagraph, 5 ),161 writer.createPositionAt( firstParagraph, 7 )162 ) );163 } );164 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;165 } );166 it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {167 model.change( writer => {168 writer.setSelection( writer.createRange(169 writer.createPositionAt( firstParagraph, 4 ),170 writer.createPositionAt( firstParagraph, 7 )171 ) );172 } );173 expect( editor.commands.get( 'input' ).isEnabled ).to.be.true;174 } );175 it( 'should be disabled for non-collapsed selection with more then one range', () => {176 model.change( writer => {177 writer.setSelection( [178 writer.createRange(179 writer.createPositionAt( firstParagraph, 5 ),180 writer.createPositionAt( firstParagraph, 6 )181 ),182 writer.createRange(183 writer.createPositionAt( firstParagraph, 8 ),184 writer.createPositionAt( firstParagraph, 9 )185 )186 ] );187 } );188 expect( editor.commands.get( 'input' ).isEnabled ).to.be.false;189 } );190 } );191 describe( 'delete', () => {192 beforeEach( () => {193 editor.commands.add( 'delete', buildFakeCommand( editor ) );194 model.change( writer => {195 writer.setSelection( firstParagraph, 'end' );196 } );197 } );198 it( 'should be disabled when caret is outside exception marker', () => {199 model.change( writer => {200 writer.setSelection( firstParagraph, 1 );201 } );202 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;203 } );204 it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {205 model.change( writer => {206 writer.setSelection( firstParagraph, 5 );207 } );208 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;209 } );210 it( 'should be disabled when caret is inside exception marker (start boundary)', () => {211 model.change( writer => {212 writer.setSelection( firstParagraph, 4 );213 } );214 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;215 } );216 it( 'should be disabled when caret moves to start boundary and it was enabled previously', () => {217 model.change( writer => {218 writer.setSelection( firstParagraph, 5 );219 } );220 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;221 model.change( writer => {222 writer.setSelection( firstParagraph, 4 );223 } );224 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;225 } );226 it( 'should be enabled when caret is inside exception marker (end boundary)', () => {227 model.change( writer => {228 writer.setSelection( firstParagraph, 7 );229 } );230 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;231 } );232 it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {233 model.change( writer => {234 writer.setSelection( writer.createRange(235 writer.createPositionAt( firstParagraph, 0 ),236 writer.createPositionAt( firstParagraph, 5 )237 ) );238 } );239 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;240 } );241 it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {242 model.change( writer => {243 writer.setSelection( writer.createRange(244 writer.createPositionAt( firstParagraph, 5 ),245 writer.createPositionAt( firstParagraph, 6 )246 ) );247 } );248 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;249 } );250 it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {251 model.change( writer => {252 writer.setSelection( writer.createRange(253 writer.createPositionAt( firstParagraph, 4 ),254 writer.createPositionAt( firstParagraph, 6 )255 ) );256 } );257 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;258 } );259 it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {260 model.change( writer => {261 writer.setSelection( writer.createRange(262 writer.createPositionAt( firstParagraph, 5 ),263 writer.createPositionAt( firstParagraph, 7 )264 ) );265 } );266 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;267 } );268 it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {269 model.change( writer => {270 writer.setSelection( writer.createRange(271 writer.createPositionAt( firstParagraph, 4 ),272 writer.createPositionAt( firstParagraph, 7 )273 ) );274 } );275 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;276 } );277 } );278 describe( 'forwardDelete', () => {279 beforeEach( () => {280 editor.commands.add( 'forwardDelete', buildFakeCommand( editor ) );281 model.change( writer => {282 writer.setSelection( firstParagraph, 'end' );283 } );284 } );285 it( 'should be disabled when caret is outside exception marker', () => {286 model.change( writer => {287 writer.setSelection( firstParagraph, 1 );288 } );289 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;290 } );291 it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {292 model.change( writer => {293 writer.setSelection( firstParagraph, 5 );294 } );295 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;296 } );297 it( 'should be enabled when caret is inside exception marker (start boundary)', () => {298 model.change( writer => {299 writer.setSelection( firstParagraph, 4 );300 } );301 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;302 } );303 it( 'should be disabled when caret is inside exception marker (end boundary)', () => {304 model.change( writer => {305 writer.setSelection( firstParagraph, 7 );306 } );307 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;308 } );309 it( 'should be disabled when caret moves to end boundary and it was enabled previously', () => {310 model.change( writer => {311 writer.setSelection( firstParagraph, 5 );312 } );313 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;314 model.change( writer => {315 writer.setSelection( firstParagraph, 7 );316 } );317 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;318 } );319 it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {320 model.change( writer => {321 writer.setSelection( writer.createRange(322 writer.createPositionAt( firstParagraph, 0 ),323 writer.createPositionAt( firstParagraph, 5 )324 ) );325 } );326 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;327 } );328 it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {329 model.change( writer => {330 writer.setSelection( writer.createRange(331 writer.createPositionAt( firstParagraph, 5 ),332 writer.createPositionAt( firstParagraph, 6 )333 ) );334 } );335 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;336 } );337 it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {338 model.change( writer => {339 writer.setSelection( writer.createRange(340 writer.createPositionAt( firstParagraph, 4 ),341 writer.createPositionAt( firstParagraph, 6 )342 ) );343 } );344 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;345 } );346 it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {347 model.change( writer => {348 writer.setSelection( writer.createRange(349 writer.createPositionAt( firstParagraph, 5 ),350 writer.createPositionAt( firstParagraph, 7 )351 ) );352 } );353 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;354 } );355 it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {356 model.change( writer => {357 writer.setSelection( writer.createRange(358 writer.createPositionAt( firstParagraph, 4 ),359 writer.createPositionAt( firstParagraph, 7 )360 ) );361 } );362 expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;363 } );364 } );365 } );366 describe( 'non-enabled commands', () => {367 beforeEach( () => {368 editor.commands.add( 'other', buildFakeCommand( editor ) );369 model.change( writer => {370 writer.setSelection( firstParagraph, 'end' );371 } );372 } );373 it( 'should be disabled outside exception marker', () => {374 model.change( writer => {375 writer.setSelection( firstParagraph, 1 );376 } );377 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;378 } );379 it( 'should be disabled inside exception marker', () => {380 model.change( writer => {381 writer.setSelection( firstParagraph, 1 );382 } );383 model.change( writer => {384 writer.setSelection( firstParagraph, 5 );385 } );386 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;387 } );388 it( 'should be disabled when caret is inside exception marker (not touching boundaries)', () => {389 model.change( writer => {390 writer.setSelection( firstParagraph, 5 );391 } );392 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;393 } );394 it( 'should be disabled when caret is inside exception marker (start boundary)', () => {395 model.change( writer => {396 writer.setSelection( firstParagraph, 4 );397 } );398 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;399 } );400 it( 'should be disabled when caret is inside exception marker (end boundary)', () => {401 model.change( writer => {402 writer.setSelection( firstParagraph, 7 );403 } );404 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;405 } );406 it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {407 model.change( writer => {408 writer.setSelection( writer.createRange(409 writer.createPositionAt( firstParagraph, 0 ),410 writer.createPositionAt( firstParagraph, 5 )411 ) );412 } );413 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;414 } );415 it( 'should be disabled for non-collapsed selection that is fully contained inside exception marker', () => {416 model.change( writer => {417 writer.setSelection( writer.createRange(418 writer.createPositionAt( firstParagraph, 5 ),419 writer.createPositionAt( firstParagraph, 6 )420 ) );421 } );422 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;423 } );424 it( 'should be disabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {425 model.change( writer => {426 writer.setSelection( writer.createRange(427 writer.createPositionAt( firstParagraph, 4 ),428 writer.createPositionAt( firstParagraph, 6 )429 ) );430 } );431 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;432 } );433 it( 'should be disabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {434 model.change( writer => {435 writer.setSelection( writer.createRange(436 writer.createPositionAt( firstParagraph, 5 ),437 writer.createPositionAt( firstParagraph, 7 )438 ) );439 } );440 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;441 } );442 it( 'should be disabled for non-collapsed selection is equal to exception marker', () => {443 model.change( writer => {444 writer.setSelection( writer.createRange(445 writer.createPositionAt( firstParagraph, 4 ),446 writer.createPositionAt( firstParagraph, 7 )447 ) );448 } );449 expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;450 } );451 } );452 } );453 describe( 'commands enabled in exception marker by configuration', () => {454 let model, firstParagraph;455 beforeEach( async () => {456 editor = await VirtualTestEditor.create( {457 plugins: [ Paragraph, Typing, RestrictedEditingModeEditing ],458 restrictedEditing: {459 allowedCommands: [ 'allowed' ]460 }461 } );462 model = editor.model;463 editor.commands.add( 'allowed', buildFakeCommand( editor ) );464 setModelData( model, '<paragraph>[]foo bar baz</βparagraph>' );465 firstParagraph = model.document.getRoot().getChild( 0 );466 model.change( writer => {467 writer.addMarker( 'restrictedEditingException:1', {468 range: writer.createRange(469 writer.createPositionAt( firstParagraph, 4 ),470 writer.createPositionAt( firstParagraph, 7 ) ),471 usingOperation: true,472 affectsData: true473 } );474 writer.setSelection( firstParagraph, 'end' );475 } );476 } );477 afterEach( async () => {478 await editor.destroy();479 } );480 it( 'should be disabled when caret is outside exception marker', () => {481 model.change( writer => {482 writer.setSelection( firstParagraph, 1 );483 } );484 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.false;485 } );486 it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {487 model.change( writer => {488 writer.setSelection( firstParagraph, 5 );489 } );490 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;491 } );492 it( 'should be disabled when caret is inside other marker', () => {493 model.change( writer => {494 writer.addMarker( 'foo-bar:1', {495 range: writer.createRange(496 writer.createPositionAt( firstParagraph, 0 ),497 writer.createPositionAt( firstParagraph, 3 ) ),498 usingOperation: true,499 affectsData: true500 } );501 writer.setSelection( firstParagraph, 1 );502 } );503 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.false;504 } );505 it( 'should be enabled when caret is inside exception marker (start boundary)', () => {506 model.change( writer => {507 writer.setSelection( firstParagraph, 4 );508 } );509 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;510 } );511 it( 'should be enabled when caret is inside exception marker (end boundary)', () => {512 model.change( writer => {513 writer.setSelection( firstParagraph, 7 );514 } );515 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;516 } );517 it( 'should be disabled for multi-range selection (collapsed ranges)', () => {518 model.change( writer => {519 writer.setSelection( [520 writer.createRange(521 writer.createPositionAt( firstParagraph, 5 )522 ),523 writer.createRange(524 writer.createPositionAt( firstParagraph, 9 )525 )526 ] );527 } );528 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.false;529 } );530 it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {531 model.change( writer => {532 writer.setSelection( writer.createRange(533 writer.createPositionAt( firstParagraph, 0 ),534 writer.createPositionAt( firstParagraph, 5 )535 ) );536 } );537 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.false;538 } );539 it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {540 model.change( writer => {541 writer.setSelection( writer.createRange(542 writer.createPositionAt( firstParagraph, 5 ),543 writer.createPositionAt( firstParagraph, 6 )544 ) );545 } );546 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;547 } );548 it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {549 model.change( writer => {550 writer.setSelection( writer.createRange(551 writer.createPositionAt( firstParagraph, 4 ),552 writer.createPositionAt( firstParagraph, 6 )553 ) );554 } );555 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;556 } );557 it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {558 model.change( writer => {559 writer.setSelection( writer.createRange(560 writer.createPositionAt( firstParagraph, 5 ),561 writer.createPositionAt( firstParagraph, 7 )562 ) );563 } );564 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;565 } );566 it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {567 model.change( writer => {568 writer.setSelection( writer.createRange(569 writer.createPositionAt( firstParagraph, 4 ),570 writer.createPositionAt( firstParagraph, 7 )571 ) );572 } );573 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.true;574 } );575 it( 'should be disabled for non-collapsed selection with more then one range', () => {576 model.change( writer => {577 writer.setSelection( [578 writer.createRange(579 writer.createPositionAt( firstParagraph, 5 ),580 writer.createPositionAt( firstParagraph, 6 )581 ),582 writer.createRange(583 writer.createPositionAt( firstParagraph, 8 ),584 writer.createPositionAt( firstParagraph, 9 )585 )586 ] );587 } );588 expect( editor.commands.get( 'allowed' ).isEnabled ).to.be.false;589 } );590 } );591 describe( 'integration', () => {592 let model, firstParagraph;593 beforeEach( async () => {594 editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, UndoEditing, RestrictedEditingModeEditing ] } );595 model = editor.model;596 setModelData( model, '<paragraph>[]foo bar baz</βparagraph>' );597 firstParagraph = model.document.getRoot().getChild( 0 );598 model.change( writer => {599 writer.addMarker( 'restrictedEditingException:1', {600 range: writer.createRange(601 writer.createPositionAt( firstParagraph, 4 ),602 writer.createPositionAt( firstParagraph, 7 ) ),603 usingOperation: true,604 affectsData: true605 } );606 } );607 } );608 afterEach( async () => {609 await editor.destroy();610 } );611 describe( 'delete + undo', () => {612 it( 'should be enabled after data change (no selection change event on undo)', () => {613 model.change( writer => {614 writer.setSelection( firstParagraph, 7 );615 } );616 editor.execute( 'delete' );617 editor.execute( 'undo' );618 expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;619 } );620 } );621 } );622 class FakeCommand extends Command {623 refresh() {624 this.isEnabled = true;625 }626 }627 function buildFakeCommand( editor ) {628 return new FakeCommand( editor );...
undo.js
Source: undo.js
...17 } );18 it( 'split, remove', () => {19 john.setData( '<paragraph>Foo[]Bar</βparagraph>' );20 john.split();21 john.setSelection( [ 1 ], [ 2 ] );22 john.remove();23 john.undo();24 john.undo();25 expectClients( '<paragraph>FooBar</βparagraph>' );26 } );27 it( 'move, merge', () => {28 john.setData( '[<paragraph>Foo</βparagraph>]<paragraph>Bar</βparagraph>' );29 john.move( [ 2 ] );30 john.setSelection( [ 1 ] );31 john.merge();32 john.undo();33 john.undo();34 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );35 } );36 it.skip( 'move multiple, merge', () => {37 john.setData( '[<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>]<paragraph>Xyz</βparagraph>' );38 john.move( [ 3 ] );39 expectClients( '<paragraph>Xyz</βparagraph><paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );40 john.setSelection( [ 1 ] );41 john.merge();42 expectClients( '<paragraph>XyzFoo</βparagraph><paragraph>Bar</βparagraph>' );43 john.undo();44 expectClients( '<paragraph>Xyz</βparagraph><paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );45 john.undo();46 /β/β Wrong move is done.47 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph><paragraph>Xyz</βparagraph>' );48 } );49 it( 'move inside unwrapped content', () => {50 john.setData( '<blockQuote>[<paragraph>Foo</βparagraph>]<paragraph>Bar</βparagraph></βblockQuote>' );51 john.move( [ 0, 2 ] );52 john.setSelection( [ 0, 0 ] );53 john.unwrap();54 john.undo();55 john.undo();56 expectClients(57 '<blockQuote>' +58 '<paragraph>Foo</βparagraph>' +59 '<paragraph>Bar</βparagraph>' +60 '</βblockQuote>'61 );62 } );63 it( 'remove node, merge', () => {64 john.setData( '<paragraph>Foo</βparagraph><paragraph>[Bar]</βparagraph>' );65 john.remove();66 john.setSelection( [ 1 ] );67 john.merge();68 john.undo();69 john.undo();70 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );71 } );72 it( 'merge, merge #1', () => {73 john.setData(74 '<blockQuote>' +75 '<paragraph>Foo</βparagraph>' +76 '<paragraph>Bar</βparagraph>' +77 '</βblockQuote>' +78 '[]' +79 '<blockQuote>' +80 '<paragraph>Xyz</βparagraph>' +81 '</βblockQuote>'82 );83 john.merge();84 john.setSelection( [ 0, 2 ] );85 john.merge();86 expectClients(87 '<blockQuote>' +88 '<paragraph>Foo</βparagraph>' +89 '<paragraph>BarXyz</βparagraph>' +90 '</βblockQuote>'91 );92 john.undo();93 john.undo();94 expectClients(95 '<blockQuote>' +96 '<paragraph>Foo</βparagraph>' +97 '<paragraph>Bar</βparagraph>' +98 '</βblockQuote>' +99 '<blockQuote>' +100 '<paragraph>Xyz</βparagraph>' +101 '</βblockQuote>'102 );103 } );104 it( 'merge, merge #2', () => {105 john.setData(106 '<blockQuote>' +107 '<paragraph>Foo</βparagraph>' +108 '</βblockQuote>' +109 '[]' +110 '<blockQuote>' +111 '<paragraph>Bar</βparagraph>' +112 '<paragraph>Xyz</βparagraph>' +113 '</βblockQuote>'114 );115 john.merge();116 john.setSelection( [ 0, 1 ] );117 john.merge();118 expectClients(119 '<blockQuote>' +120 '<paragraph>FooBar</βparagraph>' +121 '<paragraph>Xyz</βparagraph>' +122 '</βblockQuote>'123 );124 john.undo();125 john.undo();126 expectClients(127 '<blockQuote>' +128 '<paragraph>Foo</βparagraph>' +129 '</βblockQuote>' +130 '<blockQuote>' +131 '<paragraph>Bar</βparagraph>' +132 '<paragraph>Xyz</βparagraph>' +133 '</βblockQuote>'134 );135 } );136 it( 'merge, unwrap', () => {137 john.setData( '<paragraph></βparagraph>[]<paragraph>Foo</βparagraph>' );138 john.merge();139 john.setSelection( [ 0, 0 ] );140 john.unwrap();141 john.undo();142 john.undo();143 expectClients( '<paragraph></βparagraph><paragraph>Foo</βparagraph>' );144 } );145 it( 'remove node at the split position #1', () => {146 john.setData( '<paragraph>Ab</βparagraph>[]<paragraph>Xy</βparagraph>' );147 john.merge();148 john.setSelection( [ 0, 1 ], [ 0, 2 ] );149 john.remove();150 john.undo();151 john.undo();152 expectClients( '<paragraph>Ab</βparagraph><paragraph>Xy</βparagraph>' );153 } );154 it( 'remove node at the split position #2', () => {155 john.setData( '<paragraph>Ab</βparagraph>[]<paragraph>Xy</βparagraph>' );156 john.merge();157 john.setSelection( [ 0, 2 ], [ 0, 3 ] );158 john.remove();159 john.undo();160 john.undo();161 expectClients( '<paragraph>Ab</βparagraph><paragraph>Xy</βparagraph>' );162 } );163 it( 'undoing split after the element created by split has been removed', () => {164 /β/β This example is ported here from ckeditor5-undo to keep 100% CC in ckeditor5-engine alone.165 john.setData( '<paragraph>Foo[]bar</βparagraph>' );166 john.split();167 john.setSelection( [ 0, 3 ], [ 1, 3 ] );168 john.delete();169 expectClients( '<paragraph>Foo</βparagraph>' );170 john.undo();171 expectClients( '<paragraph>Foo</βparagraph><paragraph>bar</βparagraph>' );172 john.undo();173 expectClients( '<paragraph>Foobar</βparagraph>' );174 } );175 it( 'remove text from paragraph and merge it', () => {176 john.setData( '<paragraph>Foo</βparagraph><paragraph>[Bar]</βparagraph>' );177 john.remove();178 john.setSelection( [ 1 ] );179 john.merge();180 expectClients( '<paragraph>Foo</βparagraph>' );181 john.undo();182 expectClients( '<paragraph>Foo</βparagraph><paragraph></βparagraph>' );183 john.undo();184 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );185 } );186 it( 'delete split paragraphs', () => {187 john.setData( '<paragraph>Foo</βparagraph><paragraph>B[]ar</βparagraph>' );188 john.split();189 john.setSelection( [ 2, 1 ] );190 john.split();191 john.setSelection( [ 1, 0 ], [ 3, 1 ] );192 john.delete();193 john.setSelection( [ 1 ] );194 john.merge();195 expectClients( '<paragraph>Foo</βparagraph>' );196 john.undo();197 expectClients( '<paragraph>Foo</βparagraph><paragraph></βparagraph>' );198 john.undo();199 expectClients( '<paragraph>Foo</βparagraph><paragraph>B</βparagraph><paragraph>a</βparagraph><paragraph>r</βparagraph>' );200 john.undo();201 expectClients( '<paragraph>Foo</βparagraph><paragraph>B</βparagraph><paragraph>ar</βparagraph>' );202 john.undo();203 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );204 john.redo();205 expectClients( '<paragraph>Foo</βparagraph><paragraph>B</βparagraph><paragraph>ar</βparagraph>' );206 john.redo();207 expectClients( '<paragraph>Foo</βparagraph><paragraph>B</βparagraph><paragraph>a</βparagraph><paragraph>r</βparagraph>' );208 john.redo();209 expectClients( '<paragraph>Foo</βparagraph><paragraph></βparagraph>' );210 john.redo();211 expectClients( '<paragraph>Foo</βparagraph>' );212 } );213 it( 'pasting on collapsed selection undo and redo', () => {214 john.setData( '<paragraph>Foo[]Bar</βparagraph>' );215 /β/β Below simulates pasting.216 john.editor.model.change( () => {217 john.split();218 john.setSelection( [ 1 ] );219 john.insert( '<paragraph>1</βparagraph>' );220 john.setSelection( [ 1 ] );221 john.merge();222 john.setSelection( [ 1 ] );223 john.insert( '<paragraph>2</βparagraph>' );224 john.setSelection( [ 2 ] );225 john.merge();226 } );227 expectClients( '<paragraph>Foo1</βparagraph><paragraph>2Bar</βparagraph>' );228 john.undo();229 expectClients( '<paragraph>FooBar</βparagraph>' );230 john.redo();231 expectClients( '<paragraph>Foo1</βparagraph><paragraph>2Bar</βparagraph>' );232 john.undo();233 expectClients( '<paragraph>FooBar</βparagraph>' );234 john.redo();235 expectClients( '<paragraph>Foo1</βparagraph><paragraph>2Bar</βparagraph>' );236 } );237 it( 'selection attribute setting: split, bold, merge, undo, undo, undo', () => {238 /β/β This test is ported from undo to keep 100% CC in engine.239 john.setData( '<paragraph>Foo[]</βparagraph><paragraph>Bar</βparagraph>' );240 john.split();241 john.setSelection( [ 1, 0 ] );242 john._processExecute( 'bold' );243 john._processExecute( 'forwardDelete' );244 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );245 john.undo();246 expectClients( '<paragraph>Foo</βparagraph><paragraph selection:bold="true"></βparagraph><paragraph>Bar</βparagraph>' );247 john.undo();248 expectClients( '<paragraph>Foo</βparagraph><paragraph></βparagraph><paragraph>Bar</βparagraph>' );249 john.undo();250 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );251 } );252 /β/β https:/β/βgithub.com/βckeditor/βckeditor5/βissues/β1288253 it( 'remove two groups of blocks then undo, undo', () => {254 john.setData(255 '<paragraph>X</βparagraph><paragraph>A</βparagraph><paragraph>B[</βparagraph><paragraph>C</βparagraph><paragraph>D]</βparagraph>'256 );257 john.delete();258 john.setSelection( [ 0, 1 ], [ 2, 1 ] );259 john.delete();260 expectClients( '<paragraph>X</βparagraph>' );261 john.undo();262 expectClients( '<paragraph>X</βparagraph><paragraph>A</βparagraph><paragraph>B</βparagraph>' );263 john.undo();264 expectClients(265 '<paragraph>X</βparagraph><paragraph>A</βparagraph><paragraph>B</βparagraph><paragraph>C</βparagraph><paragraph>D</βparagraph>'266 );267 } );268 /β/β https:/β/βgithub.com/βckeditor/βckeditor5/βissues/β1287 TC1269 it( 'pasting on non-collapsed selection undo and redo', () => {270 john.setData( '<paragraph>Fo[o</βparagraph><paragraph>B]ar</βparagraph>' );271 /β/β Below simulates pasting.272 john.editor.model.change( () => {273 john.editor.model.deleteContent( john.document.selection );274 john.setSelection( [ 0, 2 ] );275 john.split();276 john.setSelection( [ 1 ] );277 john.insert( '<paragraph>1</βparagraph>' );278 john.setSelection( [ 1 ] );279 john.merge();280 john.setSelection( [ 1 ] );281 john.insert( '<paragraph>2</βparagraph>' );282 john.setSelection( [ 2 ] );283 john.merge();284 } );285 expectClients( '<paragraph>Fo1</βparagraph><paragraph>2ar</βparagraph>' );286 john.undo();287 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );288 john.redo();289 expectClients( '<paragraph>Fo1</βparagraph><paragraph>2ar</βparagraph>' );290 john.undo();291 expectClients( '<paragraph>Foo</βparagraph><paragraph>Bar</βparagraph>' );292 } );293 it( 'collapsed marker at the beginning of merged element then undo', () => {294 john.setData( '<paragraph>Foo</βparagraph><paragraph>[]Bar</βparagraph>' );295 john.setMarker( 'm1' );296 john.setSelection( [ 1 ] );297 john.merge();298 expectClients( '<paragraph>Foo<m1:start></βm1:start>Bar</βparagraph>' );299 john.undo();300 expectClients( '<paragraph>Foo</βparagraph><paragraph><m1:start></βm1:start>Bar</βparagraph>' );301 } );302 it( 'collapsed marker at the end of merge-target element then undo', () => {303 john.setData( '<paragraph>Foo[]</βparagraph><paragraph>Bar</βparagraph>' );304 john.setMarker( 'm1' );305 john.setSelection( [ 1 ] );306 john.merge();307 expectClients( '<paragraph>Foo<m1:start></βm1:start>Bar</βparagraph>' );308 john.undo();309 expectClients( '<paragraph>Foo<m1:start></βm1:start></βparagraph><paragraph>Bar</βparagraph>' );310 } );311 it( 'empty marker between merged elements then undo', () => {312 john.setData( '<paragraph>Foo[</βparagraph><paragraph>]Bar</βparagraph>' );313 john.setMarker( 'm1' );314 john.setSelection( [ 1 ] );315 john.merge();316 expectClients( '<paragraph>Foo<m1:start></βm1:start>Bar</βparagraph>' );317 john.undo();318 expectClients( '<paragraph>Foo<m1:start></βm1:start></βparagraph><paragraph><m1:end></βm1:end>Bar</βparagraph>' );319 } );320 it( 'left side of marker moved then undo', () => {321 john.setData( '<paragraph>Foo[bar]</βparagraph><paragraph></βparagraph>' );322 john.setMarker( 'm1' );323 john.setSelection( [ 0, 2 ], [ 0, 4 ] );324 john.move( [ 1, 0 ] );325 expectClients( '<paragraph>Fo<m1:start></βm1:start>ar<m1:end></βm1:end></βparagraph><paragraph>ob</βparagraph>' );326 john.undo();327 expectClients( '<paragraph>Foo<m1:start></βm1:start>bar<m1:end></βm1:end></βparagraph><paragraph></βparagraph>' );328 } );329 it( 'right side of marker moved then undo', () => {330 john.setData( '<paragraph>[Foo]bar</βparagraph><paragraph></βparagraph>' );331 john.setMarker( 'm1' );332 john.setSelection( [ 0, 2 ], [ 0, 4 ] );333 john.move( [ 1, 0 ] );334 expectClients( '<paragraph><m1:start></βm1:start>Fo<m1:end></βm1:end>ar</βparagraph><paragraph>ob</βparagraph>' );335 john.undo();336 expectClients( '<paragraph><m1:start></βm1:start>Foo<m1:end></βm1:end>bar</βparagraph><paragraph></βparagraph>' );337 } );338 it( 'marker on closing and opening tag - remove multiple elements #1', () => {339 john.setData(340 '<paragraph>Abc</βparagraph>' +341 '<paragraph>Foo[</βparagraph>' +342 '<paragraph>]Bar</βparagraph>'343 );344 john.setMarker( 'm1' );345 john.setSelection( [ 0, 1 ], [ 2, 2 ] );346 john._processExecute( 'delete' );347 expectClients( '<paragraph>A<m1:start></βm1:start>r</βparagraph>' );348 john.undo();349 expectClients(350 '<paragraph>Abc</βparagraph>' +351 '<paragraph>Foo<m1:start></βm1:start></βparagraph>' +352 '<paragraph><m1:end></βm1:end>Bar</βparagraph>'353 );354 } );355 it( 'marker on closing and opening tag - remove multiple elements #2', () => {356 john.setData(357 '<paragraph>Foo[</βparagraph>' +358 '<paragraph>]Bar</βparagraph>' +359 '<paragraph>Xyz</βparagraph>'360 );361 john.setMarker( 'm1' );362 john.setSelection( [ 0, 1 ], [ 2, 2 ] );363 john._processExecute( 'delete' );364 expectClients( '<paragraph>F<m1:start></βm1:start>z</βparagraph>' );365 john.undo();366 expectClients(367 '<paragraph>Foo<m1:start></βm1:start></βparagraph>' +368 '<paragraph><m1:end></βm1:end>Bar</βparagraph>' +369 '<paragraph>Xyz</βparagraph>'370 );371 } );372 it( 'marker on closing and opening tag + some text - merge elements + remove text', () => {373 john.setData(374 '<paragraph>Foo[</βparagraph>' +375 '<paragraph>B]ar</βparagraph>'376 );377 john.setMarker( 'm1' );378 john.setSelection( [ 0, 1 ], [ 1, 2 ] );379 john._processExecute( 'delete' );380 expectClients( '<paragraph>F<m1:start></βm1:start>r</βparagraph>' );381 john.undo();382 expectClients(383 '<paragraph>Foo<m1:start></βm1:start></βparagraph>' +384 '<paragraph>B<m1:end></βm1:end>ar</βparagraph>'385 );386 } );387 /β/β https:/β/βgithub.com/βckeditor/βckeditor5-engine/βissues/β1668388 it( 'marker and moves with undo-redo-undo', () => {389 john.setData( '<paragraph>X[]Y</βparagraph>' );390 const inputBufferBatch = john.editor.commands.get( 'input' ).buffer.batch;391 john.editor.model.enqueueChange( inputBufferBatch, () => {392 john.type( 'a' );393 john.type( 'b' );394 john.type( 'c' );395 john.setSelection( [ 0, 1 ], [ 0, 4 ] );396 john.setMarker( 'm1' );397 } );398 expectClients( '<paragraph>X<m1:start></βm1:start>abc<m1:end></βm1:end>Y</βparagraph>' );399 john.setSelection( [ 0, 0 ], [ 0, 5 ] );400 john._processExecute( 'delete' );401 expectClients( '<paragraph></βparagraph>' );402 john.undo();403 expectClients( '<paragraph>X<m1:start></βm1:start>abc<m1:end></βm1:end>Y</βparagraph>' );404 john.undo();405 expectClients( '<paragraph>XY</βparagraph>' );406 john.redo();407 expectClients( '<paragraph>X<m1:start></βm1:start>abc<m1:end></βm1:end>Y</βparagraph>' );408 john.redo();409 expectClients( '<paragraph></βparagraph>' );410 john.undo();411 expectClients( '<paragraph>X<m1:start></βm1:start>abc<m1:end></βm1:end>Y</βparagraph>' );412 john.undo();413 expectClients( '<paragraph>XY</βparagraph>' );414 } );415 /β/β https:/β/βgithub.com/βckeditor/βckeditor5/βissues/β1385416 it( 'paste inside paste + undo, undo + redo, redo', () => {417 const model = john.editor.model;418 john.setData( '<paragraph>[]</βparagraph>' );419 model.insertContent( getPastedContent() );420 john.setSelection( [ 0, 3 ] );421 model.insertContent( getPastedContent() );422 expectClients( '<heading1>FooFoobarbar</βheading1>' );423 john.undo();424 expectClients( '<heading1>Foobar</βheading1>' );425 john.undo();426 expectClients( '<paragraph></βparagraph>' );427 john.redo();428 expectClients( '<heading1>Foobar</βheading1>' );429 john.redo();430 expectClients( '<heading1>FooFoobarbar</βheading1>' );431 function getPastedContent() {432 return new Element( 'heading1', null, new Text( 'Foobar' ) );433 }434 } );435 /β/β https:/β/βgithub.com/βckeditor/βckeditor5/βissues/β1540436 it( 'paste, select all, paste, undo, undo, redo, redo, redo', () => {437 john.setData( '<paragraph>[]</βparagraph>' );438 pasteContent();439 john.setSelection( [ 0, 0 ], [ 1, 3 ] );440 pasteContent();441 expectClients( '<heading1>Foo</βheading1><paragraph>Bar</βparagraph>' );442 john.undo();443 expectClients( '<heading1>Foo</βheading1><paragraph>Bar</βparagraph>' );444 john.undo();445 expectClients( '<paragraph></βparagraph>' );446 john.redo();447 expectClients( '<heading1>Foo</βheading1><paragraph>Bar</βparagraph>' );448 john.redo();449 expectClients( '<heading1>Foo</βheading1><paragraph>Bar</βparagraph>' );450 function pasteContent() {451 john.editor.model.insertContent(452 new DocumentFragment( [453 new Element( 'heading1', null, new Text( 'Foo' ) ),454 new Element( 'paragraph', null, new Text( 'Bar' ) )455 ] )456 );457 }458 } );459 /β/β Happens in track changes. Emulated here.460 /β/β https:/β/βgithub.com/βckeditor/βckeditor5-engine/βissues/β1701461 it( 'paste, remove, undo, undo, redo, redo', () => {462 john.setData( '<paragraph>Ab[]cd</βparagraph><paragraph>Wxyz</βparagraph>' );463 john.editor.model.insertContent(464 new DocumentFragment( [465 new Element( 'paragraph', null, new Text( 'Foo' ) ),466 new Element( 'paragraph', null, new Text( 'Bar' ) )467 ] )468 );469 john.setSelection( [ 1, 3 ], [ 2, 2 ] );470 john._processExecute( 'delete' );471 expectClients( '<paragraph>AbFoo</βparagraph><paragraph>Baryz</βparagraph>' );472 john.undo();473 expectClients( '<paragraph>AbFoo</βparagraph><paragraph>Barcd</βparagraph><paragraph>Wxyz</βparagraph>' );474 john.undo();475 expectClients( '<paragraph>Abcd</βparagraph><paragraph>Wxyz</βparagraph>' );476 john.redo();477 expectClients( '<paragraph>AbFoo</βparagraph><paragraph>Barcd</βparagraph><paragraph>Wxyz</βparagraph>' );478 john.redo();479 expectClients( '<paragraph>AbFoo</βparagraph><paragraph>Baryz</βparagraph>' );480 } );...
Settings.js
Source: Settings.js
...21 <div className="account-tour">22 <Row>23 <Col>24 <Navbar color="light" light expand="md" className="settings-nav-tour">25 <NavbarBrand onClick={() => setSelection('index')}>Settings</βNavbarBrand>26 <NavbarToggler onClick={toggle} /β>27 <Collapse isOpen={isOpen} navbar>28 <Nav className="mr-auto" navbar>29 <UncontrolledDropdown nav inNavbar>30 <DropdownToggle nav caret>31 Doors32 </βDropdownToggle>33 <DropdownMenu right >34 <DropdownItem onClick={() => setSelection('cope_door')} >35 Cope and Stick36 </βDropdownItem>37 <DropdownItem onClick={() => setSelection('mt_door')}>38 MT Door39 </βDropdownItem>40 <DropdownItem onClick={() => setSelection('miter_door')}>41 Miter Door42 </βDropdownItem>43 {/β* <DropdownItem onClick={() => setSelection('one_piece_door')}>44 One Piece Door45 </βDropdownItem> */β}46 47 </βDropdownMenu>48 </βUncontrolledDropdown>49 <UncontrolledDropdown nav inNavbar>50 <DropdownToggle nav caret>51 Drawer Fronts52 </βDropdownToggle>53 <DropdownMenu right>54 <DropdownItem onClick={() => setSelection('cope_df')}>55 Cope and Stick56 </βDropdownItem>57 <DropdownItem onClick={() => setSelection('mt_df')}>58 MT Design59 </βDropdownItem>60 <DropdownItem onClick={() => setSelection('miter_df')}>61 Miter Design62 </βDropdownItem>63 <DropdownItem onClick={() => setSelection('slab_type_door')}>64 Slab Type DF65 </βDropdownItem>66 </βDropdownMenu>67 </βUncontrolledDropdown>68 <UncontrolledDropdown nav inNavbar>69 <DropdownToggle nav caret>70 Drawer Boxes71 </βDropdownToggle>72 <DropdownMenu right>73 <DropdownItem onClick={() => setSelection('drawer_box')}>74 Dovetail Drawer Box75 </βDropdownItem>76 </βDropdownMenu>77 </βUncontrolledDropdown>78 <UncontrolledDropdown nav inNavbar>79 <DropdownToggle nav caret>80 Face Frames81 </βDropdownToggle>82 <DropdownMenu right>83 <DropdownItem onClick={() => setSelection('face_frames')}>84 Face Frames85 </βDropdownItem>86 </βDropdownMenu>87 </βUncontrolledDropdown>88 <UncontrolledDropdown nav inNavbar>89 <DropdownToggle nav caret>90 Mouldings91 </βDropdownToggle>92 <DropdownMenu right>93 <DropdownItem onClick={() => setSelection('base_cap')}>94 Base Caps95 </βDropdownItem>96 <DropdownItem onClick={() => setSelection('baseboards')}>97 Baseboards98 </βDropdownItem>99 <DropdownItem onClick={() => setSelection('casings')}>100 Casings101 </βDropdownItem>102 <DropdownItem onClick={() => setSelection('chair_rails')}>103 Chair Rails104 </βDropdownItem>105 <DropdownItem onClick={() => setSelection('crown_mouldings')}>106 Crown Mouldings107 </βDropdownItem>108 <DropdownItem onClick={() => setSelection('solid_crowns')}>109 Solid Crowns110 </βDropdownItem>111 <DropdownItem onClick={() => setSelection('wainscot')}>112 Wainscot113 </βDropdownItem>114 <DropdownItem onClick={() => setSelection('plynths')}>115 Plynths and Others116 </βDropdownItem>117 <DropdownItem onClick={() => setSelection('flat_stock')}>118 Flat Stock119 </βDropdownItem>120 </βDropdownMenu>121 </βUncontrolledDropdown>122 <UncontrolledDropdown nav inNavbar>123 <DropdownToggle nav caret>124 Misc. Items125 </βDropdownToggle>126 <DropdownMenu right>127 <DropdownItem onClick={() => setSelection('misc_items')}>128 Misc Items.129 </βDropdownItem>130 </βDropdownMenu>131 </βUncontrolledDropdown>132 <UncontrolledDropdown nav inNavbar>133 <DropdownToggle nav caret>134 Pricing135 </βDropdownToggle>136 <DropdownMenu right>137 <DropdownItem onClick={() => setSelection('door_pricing')}>138 Doors139 </βDropdownItem>140 <DropdownItem onClick={() => setSelection('drawer_pricing')} >141 Drawer Boxes142 </βDropdownItem>143 </βDropdownMenu>144 </βUncontrolledDropdown>145 </βNav>146 147 </βCollapse>148 </βNavbar>149 </βCol>150 </βRow>151 <Row>152 <Col>153 <Selection selection={selection} /β>154 </βCol>...
LegacyOutputPluginTest.js
Source: LegacyOutputPluginTest.js
...14 Plugin();15 Theme();16 suite.test("Font color", function (editor) {17 editor.setContent('<p>text</βp>');18 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);19 editor.execCommand('forecolor', false, '#FF0000');20 LegacyUnit.equal(editor.getContent().toLowerCase(), '<p><font color="#ff0000">text</βfont></βp>');21 });22 suite.test("Font size", function (editor) {23 editor.setContent('<p>text</βp>');24 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);25 editor.execCommand('fontsize', false, 7);26 LegacyUnit.equal(editor.getContent(), '<p><font size="7">text</βfont></βp>');27 });28 suite.test("Font face", function (editor) {29 editor.setContent('<p>text</βp>');30 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);31 editor.execCommand('fontname', false, "times");32 LegacyUnit.equal(editor.getContent(), '<p><font face="times">text</βfont></βp>');33 });34 suite.test("Bold", function (editor) {35 editor.setContent('<p>text</βp>');36 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);37 editor.execCommand('bold');38 LegacyUnit.equal(editor.getContent(), '<p><b>text</βb></βp>');39 });40 suite.test("Italic", function (editor) {41 editor.setContent('<p>text</βp>');42 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);43 editor.execCommand('italic');44 LegacyUnit.equal(editor.getContent(), '<p><i>text</βi></βp>');45 });46 suite.test("Underline", function (editor) {47 editor.setContent('<p>text</βp>');48 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);49 editor.execCommand('underline');50 LegacyUnit.equal(editor.getContent(), '<p><u>text</βu></βp>');51 });52 suite.test("Strikethrough", function (editor) {53 editor.setContent('<p>text</βp>');54 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);55 editor.execCommand('strikethrough');56 LegacyUnit.equal(editor.getContent(), '<p><strike>text</βstrike></βp>');57 });58 suite.test("Justifyleft", function (editor) {59 editor.setContent('<p>text</βp>');60 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);61 editor.execCommand('justifyleft');62 LegacyUnit.equal(editor.getContent(), '<p align="left">text</βp>');63 });64 suite.test("Justifycenter", function (editor) {65 editor.setContent('<p>text</βp>');66 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);67 editor.execCommand('justifycenter');68 LegacyUnit.equal(editor.getContent(), '<p align="center">text</βp>');69 });70 suite.test("Justifyright", function (editor) {71 editor.setContent('<p>text</βp>');72 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);73 editor.execCommand('justifyright');74 LegacyUnit.equal(editor.getContent(), '<p align="right">text</βp>');75 });76 suite.test("Justifyfull", function (editor) {77 editor.setContent('<p>text</βp>');78 LegacyUnit.setSelection(editor, 'p', 0, 'p', 4);79 editor.execCommand('justifyfull');80 LegacyUnit.equal(editor.getContent(), '<p align="justify">text</βp>');81 });82 TinyLoader.setup(function (editor, onSuccess, onFailure) {83 Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure);84 }, {85 plugins: 'legacyoutput',86 indent: false,87 skin_url: '/βproject/βsrc/βskins/βlightgray/βdist/βlightgray'88 }, success, failure);89 }...
legacyoutput.js
Source: legacyoutput.js
...14 }15});16test("Font color", function() {17 editor.setContent('<p>text</βp>');18 Utils.setSelection('p', 0, 'p', 4);19 editor.execCommand('forecolor', false, '#FF0000');20 equal(editor.getContent().toLowerCase(), '<p><font color="#ff0000">text</βfont></βp>');21});22test("Font size", function() {23 editor.setContent('<p>text</βp>');24 Utils.setSelection('p', 0, 'p', 4);25 editor.execCommand('fontsize', false, 7);26 equal(editor.getContent(), '<p><font size="7">text</βfont></βp>');27});28test("Font face", function() {29 editor.setContent('<p>text</βp>');30 Utils.setSelection('p', 0, 'p', 4);31 editor.execCommand('fontname', false, "times");32 equal(editor.getContent(), '<p><font face="times">text</βfont></βp>');33});34test("Bold", function() {35 editor.setContent('<p>text</βp>');36 Utils.setSelection('p', 0, 'p', 4);37 editor.execCommand('bold');38 equal(editor.getContent(), '<p><b>text</βb></βp>');39});40test("Italic", function() {41 editor.setContent('<p>text</βp>');42 Utils.setSelection('p', 0, 'p', 4);43 editor.execCommand('italic');44 equal(editor.getContent(), '<p><i>text</βi></βp>');45});46test("Underline", function() {47 editor.setContent('<p>text</βp>');48 Utils.setSelection('p', 0, 'p', 4);49 editor.execCommand('underline');50 equal(editor.getContent(), '<p><u>text</βu></βp>');51});52test("Strikethrough", function() {53 editor.setContent('<p>text</βp>');54 Utils.setSelection('p', 0, 'p', 4);55 editor.execCommand('strikethrough');56 equal(editor.getContent(), '<p><strike>text</βstrike></βp>');57});58test("Justifyleft", function() {59 editor.setContent('<p>text</βp>');60 Utils.setSelection('p', 0, 'p', 4);61 editor.execCommand('justifyleft');62 equal(editor.getContent(), '<p align="left">text</βp>');63});64test("Justifycenter", function() {65 editor.setContent('<p>text</βp>');66 Utils.setSelection('p', 0, 'p', 4);67 editor.execCommand('justifycenter');68 equal(editor.getContent(), '<p align="center">text</βp>');69});70test("Justifyright", function() {71 editor.setContent('<p>text</βp>');72 Utils.setSelection('p', 0, 'p', 4);73 editor.execCommand('justifyright');74 equal(editor.getContent(), '<p align="right">text</βp>');75});76test("Justifyfull", function() {77 editor.setContent('<p>text</βp>');78 Utils.setSelection('p', 0, 'p', 4);79 editor.execCommand('justifyfull');80 equal(editor.getContent(), '<p align="justify">text</βp>');...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/βreact';3import { action } from '@storybook/βaddon-actions';4import { linkTo } from '@storybook/βaddon-links';5import { Button, Welcome } from '@storybook/βreact/βdemo';6storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} /β>);7storiesOf('Button', module)8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</βButton>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>π π π π―</βButton>12 ));13import React from 'react';14import { storiesOf } from '@storybook/βreact';15import { action } from '@storybook/βaddon-actions';16import { linkTo } from '@storybook/βaddon-links';17import { Button, Welcome } from '@storybook/βreact/βdemo';18storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} /β>);19storiesOf('Button', module)20 .add('with text', () => (21 <Button onClick={action('clicked')}>Hello Button</βButton>22 .add('with some emoji', () => (23 <Button onClick={action('clicked')}>π π π π―</βButton>24 ));25import React from 'react';26import { storiesOf } from '@storybook/βreact';27import { action } from '@storybook/βaddon-actions';28import { linkTo } from '@storybook/βaddon-links';29import { Button, Welcome } from '@storybook/βreact/βdemo';30storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} /β>);31storiesOf('Button', module)32 .add('with text', () => (33 <Button onClick={action('clicked')}>Hello Button</βButton>34 .add('with some emoji', () => (35 <Button onClick={action('clicked')}>π π π π―</βButton>36 ));37import React from 'react';38import
Using AI Code Generation
1setSelection = (selection) => {2 this.setState({ selection });3 }4render() {5 const { selection } = this.state;6 return (7 selection={selection}8 );9 }10render() {11 const { selection } = this.props;12 return (13 {selection}14 );15 }16export default connect(17)(Storybook);18const mapStateToProps = (state) => ({19});20const mapDispatchToProps = (dispatch) => ({21 setSelection: (selection) => dispatch(setSelection(selection))22});23export default connect(24)(StorybookRoot);25const mapStateToProps = (state) => ({26});27const mapDispatchToProps = (dispatch) => ({28 setSelection: (selection) => dispatch(setSelection(selection))29});30export default connect(31)(StorybookRoot);32const mapStateToProps = (state) => ({33});34const mapDispatchToProps = (dispatch) => ({35 setSelection: (selection) => dispatch(setSelection(selection))36});37export default connect(38)(StorybookRoot);39const mapStateToProps = (state) => ({40});41const mapDispatchToProps = (dispatch) => ({42 setSelection: (selection) => dispatch(setSelection(selection))43});44export default connect(45)(StorybookRoot);46const mapStateToProps = (state) => ({47});48const mapDispatchToProps = (dispatch) => ({49 setSelection: (selection) => dispatch(setSelection(selection))50});51export default connect(
Using AI Code Generation
1import { storiesOf } from '@storybook/βhtml';2import { withKnobs } from '@storybook/βaddon-knobs';3import { withActions } from '@storybook/βaddon-actions';4import { html } from 'lit-html';5storiesOf('My component', module)6 .addDecorator(withKnobs)7 .addDecorator(withActions)8 .add('default', () => html`<my-component></βmy-component>`)9 .add('with some emoji', () => html`<my-component>π π π π―</βmy-component>`)10 .add('with some actions', () => html`<my-component @click=${e => e.target.dispatchEvent(new CustomEvent('my-event', { detail: 'some detail'}))}></βmy-component>`);11import { storiesOf } from '@storybook/βhtml';12import { withKnobs } from '@storybook/βaddon-knobs';13import { withActions } from '@storybook/βaddon-actions';14import { html } from 'lit-html';15storiesOf('My component', module)16 .addDecorator(withKnobs)17 .addDecorator(withActions)18 .add('default', () => html`<my-component></βmy-component>`)19 .add('with some emoji', () => html`<my-component>π π π π―</βmy-component>`)20 .add('with some actions', () => html`<my-component @click=${e => e.target.dispatchEvent(new CustomEvent('my-event', { detail: 'some detail'}))}></βmy-component>`);21import { storiesOf } from '@storybook/βhtml';22import { withKnobs } from '@storybook/βaddon-knobs';23import { withActions } from '@storybook/βaddon-actions';24import { html } from 'lit-html';25storiesOf('My component', module)26 .addDecorator(withKnobs)27 .addDecorator(withActions)28 .add('default', () => html`<my-component></βmy-component>`)29 .add('with some emoji', () => html`<my-component>π π π π―</βmy-component>`)30 .add('with some actions',
Using AI Code Generation
1import { setSelection } from 'storybook-root';2export const setSelection = (selection) => {3 console.log(selection);4};5import { setSelection } from 'storybook-root';6export const setSelection = (selection) => {7 console.log(selection);8};9import { setSelection } from 'storybook-root';10export const setSelection = (selection) => {11 console.log(selection);12};13import { setSelection } from 'storybook-root';14export const setSelection = (selection) => {15 console.log(selection);16};17import { setSelection } from 'storybook-root';18export const setSelection = (selection) => {19 console.log(selection);20};21import { setSelection } from 'storybook-root';22export const setSelection = (selection) => {23 console.log(selection);24};25import { setSelection } from 'storybook-root';26export const setSelection = (selection) => {27 console.log(selection);28};29import { setSelection } from 'storybook-root';30export const setSelection = (selection) => {31 console.log(selection);32};33import { setSelection } from 'storybook-root';34export const setSelection = (selection) => {35 console.log(selection);36};37import { setSelection } from 'storybook-root';38export const setSelection = (selection) => {
Using AI Code Generation
1import { setSelection } from "storybook-root";2setSelection(0, 0, 0, 0);3import { EditorState } from "prosemirror-state";4import { EditorView } from "prosemirror-view";5import { getRootView } from "./βget-root-view";6export const setSelection = (from, to, head = from, anchor = from) => {7 const rootView = getRootView();8 if (rootView instanceof EditorView) {9 const tr = rootView.state.tr.setSelection(10 EditorState.create({11 }).selection.constructor.create(12 );13 rootView.dispatch(tr);14 }15};16import { isEditorView } from "prosemirror-view";17export const getRootView = () => {18 const rootView = document.querySelector(".ProseMirror");19 if (rootView instanceof HTMLElement) {20 return rootView.pmView;21 } else {22 throw new Error("Root view not found");23 }24};
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
In todayβs world, an organizationβs most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today donβt have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesnβt make life easier for users, theyβll leave for a better solution.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the applicationβs state when running tests.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!