-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathprompt.js
58 lines (49 loc) · 1.33 KB
/
prompt.js
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
/* eslint object-shorthand: 0 */
import GeneratedImagesContainer from './generated-images-container';
/**
* View to render the tab content.
*
* This contains the prompt input (and related functionality) as
* well as basic HTML for the other containers (errors, images).
*/
const Prompt = wp.media.View.extend( {
template: wp.template( 'dalle-prompt' ),
events: {
'click .button-generate': 'promptRequest',
'keyup .prompt': 'promptRequest',
},
/**
* Render the view.
*/
render: function () {
this.$el.html( this.template() );
return this;
},
/**
* Event tied to the prompt input and button.
*
* When a prompt is submitted, trigger off a
* request.
*
* @param {Object} event
*/
promptRequest: function ( event ) {
let prompt = '';
let quality = '';
let size = '';
let style = '';
const parent = event.target.parentElement;
if ( event.which === 13 ) {
prompt = event.target.value.trim();
} else if ( event.target.nodeName === 'BUTTON' ) {
prompt = parent.querySelector( '.prompt' ).value.trim();
quality = parent.querySelector( '.quality' ).value.trim();
size = parent.querySelector( '.size' ).value.trim();
style = parent.querySelector( '.style' ).value.trim();
}
if ( prompt ) {
new GeneratedImagesContainer( { prompt, quality, size, style } );
}
},
} );
export default Prompt;