File: list.js

package info (click to toggle)
ckeditor 4.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 258,804 kB
  • sloc: javascript: 239,590; sh: 184; makefile: 64; python: 37; php: 15; xml: 5
file content (240 lines) | stat: -rw-r--r-- 10,207 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* bender-tags: editor */
/* bender-ckeditor-plugins: list,justify,bidi,table,forms,toolbar */

// Use two editor instances as there are some issues on Edge 16+ when single instance is used.
bender.editors = {
	editor1: {
		config: {
			enterMode: CKEDITOR.ENTER_P
		},
		allowedForTests: 'li{margin-right}[type]; ul[lang]; ol{font-size}; dl dt dd'
	},
	editor2: {
		config: {
			enterMode: CKEDITOR.ENTER_P
		},
		allowedForTests: 'li{margin-right}[type]; ul[lang]; ol{font-size}; dl dt dd'
	}
};

bender.test( {
	supportForSelectFullList: function( editor ) {
		// With full selection, it will break inline in old IEs.
		return !( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE &&
			CKEDITOR.env.ie && CKEDITOR.env.version < 9 );
	},

	// Test list creation.
	'test apply list': function() {
		var bot = this.editorBots.editor1;

		bot.setHtmlWithSelection( '[<p>foo<br />bar</p><p>baz</p>]' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol><li>foo</li><li>bar</li><li>baz</li></ol>', bot.getData( false, true ) );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul><li>foo</li><li>bar</li><li>baz</li></ul>', bot.getData( false, true ) );
	},

	// https://dev.ckeditor.com/ticket/3940
	'test create list in table': function() {
		var bot = this.editorBots.editor1;
		bender.tools.testInputOut( 'create_list_table', function( input, expected ) {
			bot.setHtmlWithSelection( input );
			bot.execCommand( 'numberedlist' );
			assert.areSame( bender.tools.compatHtml( expected ), bot.getData( false, true ) );
		} );
	},

	'test apply list ( with justify style)': function() {
		var bot = this.editorBots.editor1;

		bot.setHtmlWithSelection( '<p>[foo</p><p style="text-align:center;">bar</p><p style="text-align:right;">baz]</p>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol><li>foo</li><li style="text-align:center;">bar</li><li style="text-align:right;">baz</li></ol>', bot.getData( true ) );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul><li>foo</li><li style="text-align:center;">bar</li><li style="text-align:right;">baz</li></ul>', bot.getData( true ) );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<p>foo</p><p style="text-align:center;">bar</p><p style="text-align:right;">baz</p>', bot.getData( true ) );
	},

	'test apply list (with text direction)': function() {
		// Selection of rtl elements in IE8 is broken. Tested selection can't be achieved.
		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
			assert.ignore();
		}

		var bot = this.editorBots.editor1;

		bot.setHtmlWithSelection( '[<p dir="rtl">foo</p><p dir="rtl">bar</p><p dir="rtl">baz</p>]' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol dir="rtl"><li>foo</li><li>bar</li><li>baz</li></ol>', bot.getData( true ) );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul dir="rtl"><li>foo</li><li>bar</li><li>baz</li></ul>', bot.getData( true ) );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<p dir="rtl">foo</p><p dir="rtl">bar</p><p dir="rtl">baz</p>', bot.getData( true ) );
	},

	// https://dev.ckeditor.com/ticket/7657
	'test apply list (with block styles)': function() {
		// Selection of rtl elements in IE8 is broken. Tested selection can't be achieved.
		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
			assert.ignore();
		}

		var bot = this.editorBots.editor1;

		bot.setHtmlWithSelection( '[<p dir="rtl">Item 1</p><p dir="rtl" style="margin-right: 40px;">Item 2</p><p dir="rtl" style="margin-right: 80px;">Item 3</p>]' );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul dir="rtl"><li>item 1</li><li style="margin-right:40px;">item 2</li><li style="margin-right:80px;">item 3</li></ul>', bot.getData( true ) );
	},

	// Test list removal.
	'test remove list': function() {
		var bot = this.editorBots.editor1;

		bot.setHtmlWithSelection( '<ol><li>^text</li></ol>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<p>text</p>', bot.getData( false, true ) );

		// With full selection, it will break inline in old IEs.
		if ( this.supportForSelectFullList( bot.editor ) ) {
			bot.setHtmlWithSelection( '[<ol><li>text</li></ol>]' );
			bot.execCommand( 'numberedlist' );
			assert.areSame( '<p>text</p>', bot.getData( false, true ) );
		}

		// With nested list.
		bot.setHtmlWithSelection( '<ul><li>a<ol><li>^b<ul><li>c</li></ul></li></ol></li></ul>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ul><li>a</li></ul><p>b</p><ul><li>c</li></ul>', bot.getData( false, true ) );
	},

	// (https://dev.ckeditor.com/ticket/6715)
	'test remove list (inside table)': function() {
		var bot = this.editorBots.editor1;
		bot.setHtmlWithSelection( '<table><tr><td><ol><li>[item 1</li><li>item 2]</li></ol></td></tr></table>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<table><tbody><tr><td><p>item 1</p><p>item 2</p></td></tr></tbody></table>', bot.getData( false, true ) );
	},

	// (https://dev.ckeditor.com/ticket/7645)
	'test remove list (with input)': function() {
		var bot = this.editorBots.editor1;
		bot.setHtmlWithSelection( '<ol><li><input name="name" type="checkbox">[item1</li><li>item2]</li></ol>' );
		bot.execCommand( 'numberedlist' );
		assert.isMatching( /<p><input name="name" type="checkbox" (value="on" )?\/>item1<\/p><p>item2<\/p>/, bot.getData( true ) );
	},

	/**
	 *  Test merge newlist with previous list. (https://dev.ckeditor.com/ticket/3820)
	 */
	'test create list with merge': function() {
		var bot = this.editorBots.editor2;
		bot.setHtmlWithSelection( '<ul><li>bullet line 1</li><li>bullet line 2</li></ul><p>^second line</p>' );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul><li>bullet line 1</li><li>bullet line 2</li><li>second line</li></ul>', bot.getData( 1 ) );
	},

	/**
	 * Test switch list type with custom bullet attributes. (https://dev.ckeditor.com/ticket/4950)
	 */
	'test switch list type (with custom bullet)': function() {
		var bot = this.editorBots.editor2;
		bot.setHtmlWithSelection( '<ol><li type="square">[item1</li><li type="square">item2</li><li type="square">item3]</li></ol> ' );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul><li type="square">item1</li><li type="square">item2</li><li type="square">item3</li></ul>', bot.getData( 1 ) );
	},

	// https://dev.ckeditor.com/ticket/7290
	'test switch list type (inside definition list)': function() {
		var bot = this.editorBots.editor2;
		bender.tools.testInputOut( 'switch_list_dl', function( source, expected ) {
			bot.setHtmlWithSelection( source );
			bot.execCommand( 'numberedlist' );
			assert.areSame( bender.tools.compatHtml( expected ), bot.getData( false, true ) );

		} );
	},

	// https://dev.ckeditor.com/ticket/6059
	'test switch list type keeps text direction': function() {
		var bot = this.editorBots.editor2;
		bot.setHtmlWithSelection( '[<ol dir="rtl" lang="en"><li>line 1</li><li>line 2</li></ol>]' );
		bot.execCommand( 'bulletedlist' );
		assert.areSame( '<ul dir="rtl" lang="en"><li>line 1</li><li>line 2</li></ul>', bot.getData( true ) );
	},

	// https://dev.ckeditor.com/ticket/8997
	'test change list type keep styles on sub list': function() {
		var bot = this.editorBots.editor2;

		if ( !this.supportForSelectFullList( bot.editor ) ) {
			assert.ignore();
		}
		bot.setHtmlWithSelection( '[<ul style="font-size:16px;"><li>foo<ul style="font-size:22px;"><li>bar</li></ul></li></ul>]' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol style="font-size:16px;"><li>foo<ol style="font-size:22px;"><li>bar</li></ol></li></ol>', bot.getData( true ) );
	},

	'test create list with merge below (with direction)': function() {
		var bot = this.editorBots.editor2;

		// LTR
		bot.setHtmlWithSelection( '<p>^ltr</p><ol dir="rtl"><li>rtl</li></ol>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol dir="rtl"><li dir="ltr">ltr</li><li>rtl</li></ol>', bot.getData( false, true ) );

		// RTL
		bot.setHtmlWithSelection( '<p dir="rtl">^rtl</p><ol><li>ltr</li></ol>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol><li dir="rtl">rtl</li><li>ltr</li></ol>', bot.getData( false, true ) );
	},

	'test create list with merge above (with direction)': function() {
		var bot = this.editorBots.editor2;

		bot.setHtmlWithSelection( '<ol dir="rtl"><li>rtl</li></ol><p>^ltr</p>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol dir="rtl"><li>rtl</li><li dir="ltr">ltr</li></ol>', bot.getData( false, true ) );

		// RTL
		bot.setHtmlWithSelection( '<ol><li>ltr</li></ol><p dir="rtl">^rtl</p>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol><li>ltr</li><li dir="rtl">rtl</li></ol>', bot.getData( false, true ) );

		// LTR
		bot.setHtmlWithSelection( '<ol dir="rtl"><li>rtl</li></ol><p dir="ltr">^ltr</p>' );
		bot.execCommand( 'numberedlist' );
		assert.areSame( '<ol dir="rtl"><li>rtl</li><li dir="ltr">ltr</li></ol>', bot.getData( true ) );

	},

	'test single list type active inside of nested list': function() {
		var bot = this.editorBots.editor2, ed = bot.editor;
		bot.setHtmlWithSelection( '<ol><li>item1<ul><li>^item2</li></ul></li></ol>' );
		var nList = ed.getCommand( 'numberedlist' ), bList = ed.getCommand( 'bulletedlist' );
		assert.areSame( CKEDITOR.TRISTATE_OFF, nList.state, 'check numbered list inactive' );
		assert.areSame( CKEDITOR.TRISTATE_ON, bList.state, 'check bulleted list active' );

	},

	'test inactive when list is out of block limit': function() {
		var bot = this.editorBots.editor2, ed = bot.editor;
		bot.setHtmlWithSelection( '<ul><li><table><tr><td>^foo</td></tr></table></li></ul>' );
		var bList = ed.getCommand( 'bulletedlist' );
		assert.areSame( CKEDITOR.TRISTATE_OFF, bList.state, 'check numbered list inactive' );
	},

	// #2721
	'test sublist order after removing higher order sublist': function() {
		var bot = this.editorBots.editor1,
			editor = bot.editor;

		bot.setHtmlWithSelection( '<ol><li>test<ol><li>^<ol><li>a</li><li>b</li><li>c</li></ol></li></ol></li></ol>' );
		editor.fire( 'key', {
			domEvent: new CKEDITOR.dom.event( { keyCode: 8 } )
		} );

		assert.areSame( '<ol><li>test<ol><li>a</li><li>b</li><li>c</li></ol></li></ol>', bender.tools.compatHtml( editor.getData() ) );
	}
} );