File: instance.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 (212 lines) | stat: -rw-r--r-- 5,611 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
/* bender-tags: editor,jquery */
/* bender-ckeditor-adapters: jquery */
/* bender-ckeditor-plugins: wysiwygarea */
/* global $ */

bender.test( {
	assertEditor: function( nameOrObject, name ) {
		if ( typeof nameOrObject == 'string' ) {
			name = nameOrObject;
			nameOrObject = CKEDITOR.instances[ nameOrObject ];
		}

		assert.isObject( nameOrObject, name + ' should exist.' );
		assert.areSame( name, nameOrObject.name, name + ' name should match.' );
		assert.areSame( $( '#' + name ).get( 0 ), nameOrObject.element.$, 'Instance element should match.' );
	},

	assertEditorMode: function( editorName, mode ) {
		assert.areSame( mode, CKEDITOR.instances[ editorName ].elementMode, editorName + ' should be created by replace.' );
	},

	assertEditorInstances: function( expected ) {
		arrayAssert.itemsAreEqual( expected, CKEDITOR.tools.object.keys( CKEDITOR.instances ), 'Editors instances list should match with expected.' );
	},

	destroyAll: function() {
		var instances = CKEDITOR.instances;

		for ( var i in instances )
			instances[ i ].destroy();
	},

	'test creator: replace': function() {
		$( '#editor1' ).ckeditor( function() {
			resume( function() {
				this.assertEditor( 'editor1' );
				this.assertEditorMode( 'editor1', CKEDITOR.ELEMENT_MODE_REPLACE );
				this.assertEditorInstances( [ 'editor1' ] );
			} );
		} );

		wait();
	},

	'test creator: replace all': function() {
		this.destroyAll();

		$( '.myclass' ).ckeditor();

		this.assertEditorMode( 'editor2', CKEDITOR.ELEMENT_MODE_REPLACE );
		this.assertEditor( 'editor2' );

		this.assertEditorMode( 'editor3', CKEDITOR.ELEMENT_MODE_REPLACE );
		this.assertEditor( 'editor3' );

		this.assertEditorInstances( [ 'editor2', 'editor3' ] );
	},

	'test creator: inline': function() {
		$( '#inline' ).ckeditor();

		this.assertEditorMode( 'inline', CKEDITOR.ELEMENT_MODE_INLINE );
		this.assertEditor( 'inline' );
	},

	'test empty collection returns this': function() {
		assert.areSame( 0, $( 'doesntExist' ).ckeditor().length, 'Adapter should return \'this\' when element does not exist.' );
	},

	'test wrong type of element': function() {
		var failed;

		try {
			$( 'a#link1' ).ckeditor();
		} catch ( e ) {
			failed = true;
		}

		assert.isTrue( failed, 'Error object must be thrown because this element is invalid.' );
	},

	'test respect env.isCompatible': function() {
		var failed;

		CKEDITOR.env.isCompatible = false;

		try {
			$( '#editor4' ).ckeditor().get( 0 );
		} catch ( e ) {
			failed = true;
		}

		assert.isTrue( failed, 'Error should be thrown.' );
		assert.isUndefined( CKEDITOR.instances.editor4, 'editor4 is undefined.' );

		CKEDITOR.env.isCompatible = true;
	},

	'test ckeditorGet (deprec API)': function() {
		$( '#editor6' ).ckeditor();
		this.assertEditor( $( '#editor6' ).ckeditorGet(), 'editor6' );
	},

	'test callback function': function() {
		var that = this;

		assert.isUndefined( CKEDITOR.instances.editor5, 'editor5 should be undefined.' );

		$( '#editor5' ).ckeditor( function() {
			resume( function() {
				that.assertEditor( 'editor5' );
			} );
		} );

		wait();
	},

	'test config': function() {
		$( '#editor7' ).ckeditor( { uiColor: '#9AB8F3' } );

		$( '#editor7' ).ckeditor().editor.on( 'instanceReady', function() {
			resume( function() {
				assert.areSame( '#9AB8F3', $( '#editor7' ).ckeditor().editor.config.uiColor, 'Configuration should be set.' );
			} );
		} );

		wait();
	},

	'test config + callback': function() {
		$( '#editor8' ).ckeditor( { uiColor: '#9AB8F3' }, function() {
			resume( function() {
				assert.areSame( '#9AB8F3', $( '#editor8' ).ckeditor().editor.config.uiColor, 'Configuration should be set.' );
			} );
		} );

		wait();
	},

	'test callback + config': function() {
		$( '#editor9' ).ckeditor( function() {
			resume( function() {
				assert.areSame( '#9AB8F3', $( '#editor9' ).ckeditor().editor.config.uiColor, 'Configuration should be set.' );
			} );
		}, { uiColor: '#9AB8F3' } );

		wait();
	},

	'test chaining#1': function() {
		var callbackCalled;

		$( '#editor10' ).ckeditor( function() {
			callbackCalled = true;
		} ).ckeditor( function() {
			resume( function() {
				assert.isTrue( callbackCalled, 'First callback should be called.' );
			} );
		} );

		wait();
	},

	'test chaining#2': function() {
		$( 'body' ).find( '#editor11' ).ckeditor().end().find( 'a#link2' ).addClass( 'mylink' ).end();

		this.assertEditor( 'editor11' );
		assert.isTrue( $( 'a#link2' ).hasClass( 'mylink' ) );
	},

	'test ckeditor().editor': function() {
		$( '#editor12' ).ckeditor();

		assert.isUndefined( $( '#editor12' ).editor, '$( selector ).editor should be undefined' );
		this.assertEditor( $( '#editor12' ).ckeditor().editor, 'editor12' );
	},

	'test ckeditor().editor (collection)': function() {
		$( '.editors13' ).ckeditor();

		assert.isUndefined( $( '.editors13' ).editor, '$( selector ).editor should be undefined' );
		this.assertEditor( $( '.editors13' ).ckeditor().editor, 'editor13a' );
	},

	'test promise': function() {
		var ready = [];

		$( '#editor14' ).ckeditor( function() {
			ready.push( this.name );
		} ).promise.done( function() {
			resume( function() {
				arrayAssert.itemsAreSame( [ 'editor14' ], ready, 'Editor14 should be ready.' );
			} );
		} );

		wait();
	},

	'test promise (collection)': function() {
		var ready = [];

		$( '.editors15' ).ckeditor( function() {
			ready.push( this.name );
		} ).promise.done( function() {
			resume( function() {
				arrayAssert.itemsAreSame( [ 'editor15a', 'editor15b' ], ready.sort(), 'Editor15a and Editor15b should be ready.' );
			} );
		} );

		wait();
	}
} );