File: plugin.js

package info (click to toggle)
ckeditor 4.4.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,632 kB
  • ctags: 2,419
  • sloc: sh: 190; python: 37; makefile: 29; php: 15; xml: 5
file content (168 lines) | stat: -rw-r--r-- 3,940 bytes parent folder | download
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
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: dialog */

CKEDITOR.on( 'instanceLoaded', function() {
	CKEDITOR.dialog.add( 'testDialog1', function() {
		return {
			title: 'Test Dialog 1',
			contents: [
				{
					id: 'info',
					label: 'Test',
					elements: [
						{
							type: 'text',
							id: 'foo',
							label: 'bar'
						}
					]
				}
			]
		};
	} );
	CKEDITOR.dialog.add( 'testDialog2', '%TEST_DIR%_assets/testdialog.js' );
} );

bender.editor = {};

bender.test(
{
	'test open dialog from local' : function() {
		var ed = this.editor, tc = this;
		ed.openDialog( 'testDialog1', function( dialog ) {
			tc.resume( function() {
				assert.isNotNull( dialog );

				wait( function() {
					dialog.getButton( 'cancel' ).click();
				}, 100 );
			} );
		} );
		tc.wait();
	},

	'test open dialog from url' : function() {
		var ed = this.editor, tc = this;
		ed.openDialog( 'testDialog2', function( dialog ) {
			tc.resume( function() {
				assert.isNotNull( dialog );

				wait( function() {
					dialog.getButton( 'cancel' ).click();
				}, 100 );
			} );
		} );
		tc.wait();
	},

	'test dialog\'s field are disabled when not allowed': function() {
		var ed = this.editor,
			tc = this;

		CKEDITOR.dialog.add( 'testDialog3', function() {
			return {
				title: 'Test Dialog 3',
				contents: [
					{
						id: 'tab1',
						label: 'Test 1',
						elements: [
							{
								type: 'text',
								id: 'foo',
								label: 'foo',
								requiredContent: 'p'
							},
							{
								type: 'text',
								id: 'bar',
								label: 'bar',
								requiredContent: 'x'
							}
						]
					},
					{
						id: 'tab2',
						label: 'Test 2',
						elements: [
							// vbox shouldn't be count as visible uielement,
							// so entire tab2 should be hidden.
							{
								type: 'vbox',
								children: [
									{
										type: 'text',
										id: 'bom',
										label: 'bom',
										requiredContent: 'y'
									}
								]
							}
						]
					},
					{
						id: 'tab3',
						label: 'Test 3',
						elements: [
							{
								type: 'text',
								id: 'bim',
								label: 'bim'
							}
						]
					}
				]
			};
		} );

		ed.openDialog( 'testDialog3', function( dialog ) {
			setTimeout( function() {
				resume( function() {
					// Tab 2 has no visible elements, so it should be hidden.
					assert.areSame( 2, dialog.getPageCount() );
					assert.isTrue( dialog.parts.tabs.getChild( 0 ).isVisible() );
					assert.isFalse( dialog.parts.tabs.getChild( 1 ).isVisible() );
					assert.isTrue( dialog.parts.tabs.getChild( 2 ).isVisible() );

					assert.isTrue( dialog.getContentElement( 'tab1', 'foo' ).getInputElement().isVisible() );
					assert.isFalse( dialog.getContentElement( 'tab1', 'bar' ).getInputElement().isVisible() );
					assert.isFalse( dialog.getContentElement( 'tab2', 'bom' ).getInputElement().isVisible() );

					// Element tab2:bom should be still invisible after switching to second tab.
					dialog.selectPage( 'tab2' );
					assert.isFalse( dialog.getContentElement( 'tab2', 'bom' ).getInputElement().isVisible() );

					dialog.selectPage( 'tab3' );
					assert.isTrue( dialog.getContentElement( 'tab3', 'bim' ).getInputElement().isVisible() );

					dialog.getButton( 'ok' ).click();
				} );
			}, 200 );
		} );
		wait();
	},

	'test dialog is triggered on doubleclick': function() {
		var editor = this.editor,
			openedDialog = null,
			revert = bender.tools.replaceMethod( editor, 'openDialog', function( name ) {
				openedDialog = name;
			} );

		editor.fire( 'doubleclick', { element: editor.editable() } );

		assert.isNull( openedDialog, 'dialog was not opened' );

		editor.once( 'doubleclick', function( evt ) {
			evt.data.dialog = 'testdoubleclick';
		} );

		editor.fire( 'doubleclick', { element: editor.editable() } );

		assert.areSame( 'testdoubleclick', openedDialog, 'dialog was opened on doubleclick' );

		revert();
	}
} );

//]]>