PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.1
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.1
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / assets / js / stockpack-no-search.js

stockpack-no-search.js in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 3.7.1, at assets/js/stockpack-no-search.js

69 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const StockpackNoSearch = wp.media.View.extend( /** @lends wp.media.view.Toolbar.prototype */{
2 tagName: 'div',
3 className: 'stockpack-no-search',
4 template: wp.template( 'stockpack-no-search' ),
5
6 defaults: {
7 message: '',
8 inspiration: [],
9 },
10
11 initialize() {
12 this.model = new Backbone.Model( this.defaults );
13 // If any of the `options` have a key from `defaults`, apply its
14 // value to the `model` and remove it from the `options object.
15 _.each( this.defaults, function( def, key ) {
16 const value = this.options[ key ];
17 if ( _.isUndefined( value ) ) {
18 return;
19 }
20
21 this.model.set( key, value );
22 delete this.options[ key ];
23 }, this );
24 this.setInspiration();
25 this.listenTo( this.model, 'change', this.render );
26 },
27
28 setInspiration() {
29 const random = this.getRandomInt( 1, 8 );
30
31 this.model.set( 'unsure', this.model.get( 'inspiration' ).unsure );
32 const inspiration = this.model.get( 'inspiration' ).random[ 'item_' + random ];
33 this.model.set( 'illustration', inspiration.image );
34 this.model.set( 'response', inspiration.message );
35 },
36
37 render() {
38 wp.Backbone.View.prototype.render.apply( this, arguments );
39 return this;
40 },
41
42 getRandomInt( min, max ) {
43 min = Math.ceil( min );
44 max = Math.floor( max );
45 return Math.floor( Math.random() * ( max - min + 1 ) ) + min;
46 },
47
48 dispose() {
49 this.$el.remove();
50 if ( this.timer ) {
51 this.timer.destroy();
52 }
53 },
54
55 prepare() {
56 return this.model.toJSON();
57 },
58
59 show() {
60 this.$el.removeClass( 'hidden' );
61 },
62 hide() {
63 this.$el.addClass( 'hidden' );
64 },
65
66 } );
67
68 export default StockpackNoSearch;
69