Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ebdec7e

Browse files
authoredOct 29, 2018
Merge pull request #45 from ckeditor/t/35
Feature: Implemented a tip in the form that helps users discover the auto embedding. Closes #35.
2 parents a1b1b8d + 0240af5 commit ebdec7e

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed
 

‎lang/contexts.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"media widget": "Label for the media widget.",
33
"Media URL": "Label for the URL input in the Media Embed URL editing balloon.",
4+
"Paste the URL into the content to embed faster.": "The tip displayed next to the media URL input informing about an easier way of embedding.",
45
"The URL must not be empty.": "An error message that informs about an empty value in the URL input.",
56
"This media URL is not supported.": "An error message that informs about unsupported media URL.",
67
"Insert media": "Toolbar button tooltip for the Media Embed feature."

‎src/mediaembedui.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class MediaEmbedUI extends Plugin {
8181
}
8282
} );
8383

84-
dropdown.on( 'change:isOpen', () => form.resetErrors() );
84+
dropdown.on( 'change:isOpen', () => form.resetFormStatus() );
8585
dropdown.on( 'cancel', () => closeUI() );
8686

8787
function closeUI() {

‎src/ui/mediaformview.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export default class MediaFormView extends View {
218218
* @returns {Boolean}
219219
*/
220220
isValid() {
221-
this.resetErrors();
221+
this.resetFormStatus();
222222

223223
for ( const validator of this._validators ) {
224224
const errorText = validator( this );
@@ -236,10 +236,14 @@ export default class MediaFormView extends View {
236236
}
237237

238238
/**
239-
* Cleans up the errors in all form fields. See {@link #isValid}.
239+
* Cleans up the supplementary error and information text of the {@link #urlInputView}
240+
* bringing them back to the state when the form has been displayed for the first time.
241+
*
242+
* See {@link #isValid}.
240243
*/
241-
resetErrors() {
242-
this.urlInputView.errorText = false;
244+
resetFormStatus() {
245+
this.urlInputView.errorText = null;
246+
this.urlInputView.infoText = null;
243247
}
244248

245249
/**
@@ -252,9 +256,17 @@ export default class MediaFormView extends View {
252256
const t = this.locale.t;
253257

254258
const labeledInput = new LabeledInputView( this.locale, InputTextView );
259+
const inputView = labeledInput.inputView;
255260

256261
labeledInput.label = t( 'Media URL' );
257-
labeledInput.inputView.placeholder = 'https://example.com';
262+
inputView.placeholder = 'https://example.com';
263+
264+
inputView.on( 'input', () => {
265+
// Display the #infoText only when there's some value to hide it when the input
266+
// is empty, e.g. user used backspace to clean it up.
267+
labeledInput.infoText = inputView.element.value ?
268+
t( 'Paste the URL into the content to embed faster.' ) : null;
269+
} );
258270

259271
return labeledInput;
260272
}

‎tests/mediaembedui.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ describe( 'MediaEmbedUI', () => {
151151
} );
152152

153153
describe( '#change:isOpen event', () => {
154-
it( 'resets form errors', () => {
155-
const spy = sinon.spy( form, 'resetErrors' );
154+
it( 'resets form status', () => {
155+
const spy = sinon.spy( form, 'resetFormStatus' );
156156

157157
dropdown.fire( 'change:isOpen' );
158158

‎tests/ui/mediaformview.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ describe( 'MediaFormView', () => {
8181
it( 'has placeholder', () => {
8282
expect( view.urlInputView.inputView.placeholder ).to.equal( 'https://example.com' );
8383
} );
84+
85+
it( 'displays the info text when upon #input when the field has a value', () => {
86+
view.urlInputView.inputView.element.value = 'foo';
87+
view.urlInputView.inputView.fire( 'input' );
88+
89+
expect( view.urlInputView.infoText ).to.match( /^Paste the URL/ );
90+
91+
view.urlInputView.inputView.element.value = '';
92+
view.urlInputView.inputView.fire( 'input' );
93+
94+
expect( view.urlInputView.infoText ).to.be.null;
95+
} );
8496
} );
8597

8698
describe( 'template', () => {
@@ -244,8 +256,8 @@ describe( 'MediaFormView', () => {
244256
} );
245257

246258
describe( 'isValid()', () => {
247-
it( 'calls resetErrors()', () => {
248-
const spy = sinon.spy( view, 'resetErrors' );
259+
it( 'calls resetFormStatus()', () => {
260+
const spy = sinon.spy( view, 'resetFormStatus' );
249261

250262
view.isValid();
251263

@@ -277,17 +289,25 @@ describe( 'MediaFormView', () => {
277289
sinon.assert.calledOnce( val1 );
278290
sinon.assert.calledOnce( val2 );
279291

280-
expect( view.urlInputView.errorText ).to.be.false;
292+
expect( view.urlInputView.errorText ).to.be.null;
281293
} );
282294
} );
283295

284-
describe( 'resetErrors()', () => {
296+
describe( 'resetFormStatus()', () => {
285297
it( 'resets urlInputView#errorText', () => {
286298
view.urlInputView.errorText = 'foo';
287299

288-
view.resetErrors();
300+
view.resetFormStatus();
301+
302+
expect( view.urlInputView.errorText ).to.be.null;
303+
} );
304+
305+
it( 'resets urlInputView#infoText', () => {
306+
view.urlInputView.infoText = 'foo';
307+
308+
view.resetFormStatus();
289309

290-
expect( view.urlInputView.errorText ).to.be.false;
310+
expect( view.urlInputView.infoText ).to.be.null;
291311
} );
292312
} );
293313
} );

0 commit comments

Comments
 (0)
This repository has been archived.