PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.2
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
← All changes | assets/js/stockpack.js +136 -130 2.0 → 3.7.2 View file →
@@ -2,159 +2,165 @@
2 2 import StockpackImages from './models/stockpack-images-model';
3 3 import StockpackSelection from './models/stockpack-selection-model';
4 4 import './stockpack-helpers';
5 5
6 -const oldMediaFrame = wp.media.view.MediaFrame.Post;
7 -const oldMediaFrameSelect = wp.media.view.MediaFrame.Select;
6 +const Stockpack = {
7 + init: () => {
8 + const oldMediaFrame = wp.media.view.MediaFrame.Post;
8 9
9 -window.StockpackQueue = new StockpackImages( [], { query: false } );
10 -window.StockpackQueueErrors = new Backbone.Collection();
10 + const oldMediaFrameSelect = wp.media.view.MediaFrame.Select;
11 + window.StockpackQueue = new StockpackImages( [], { query: false } );
12 + window.StockpackQueueErrors = new Backbone.Collection();
11 13
12 -// Extending the current media library frame to add a new tab
13 -wp.media.view.MediaFrame.Post = oldMediaFrame.extend( {
14 14
15 - /**
16 - * overwrite router to
17 - *
18 - * @param {wp.media.view.Router} routerView
19 - */
20 - browseRouter( routerView ) {
21 - oldMediaFrame.prototype.browseRouter.apply( this, arguments );
22 - routerView.set( {
23 - stockpack: {
24 - text: wp.media.view.l10n.stockpack.title,
25 - priority: 60,
15 + // Extending the current media library frame to add a new tab
16 + wp.media.view.MediaFrame.Post = oldMediaFrame.extend( {
17 +
18 + /**
19 + * overwrite router to
20 + *
21 + * @param {wp.media.view.Router} routerView
22 + */
23 + browseRouter( routerView ) {
24 + oldMediaFrame.prototype.browseRouter.apply( this, arguments );
25 + routerView.set( {
26 + stockpack: {
27 + text: wp.media.view.l10n.stockpack.title,
28 + priority: 60,
29 + },
30 + } );
26 31 },
27 - } );
28 - },
29 32
30 - /**
31 - * Bind region mode event callbacks.
32 - *
33 - * @see media.controller.Region.render
34 - */
35 - bindHandlers() {
36 - oldMediaFrame.prototype.bindHandlers.apply( this, arguments );
37 - this.on( 'content:create:stockpack', this.stockpackContent, this );
38 - },
33 + /**
34 + * Bind region mode event callbacks.
35 + *
36 + * @see media.controller.Region.render
37 + */
38 + bindHandlers() {
39 + oldMediaFrame.prototype.bindHandlers.apply( this, arguments );
40 + this.on( 'content:create:stockpack', this.stockpackContent, this );
41 + },
39 42
40 - /**
41 - * Render callback for the content region in the `browse` mode.
42 - *
43 - * @param {wp.media.controller.Region} contentRegion
44 - */
45 - stockpackContent( contentRegion ) {
46 - const state = this.state();
47 - if ( ! state.get( 'stockpack-images' ) ) {
48 - state.set( 'stockpack-images', window.getStockpackQuery() );
49 - // Watch for downloaded images.
50 - state.get( 'library' ).observe( window.StockpackQueue );
51 - }
43 + /**
44 + * Render callback for the content region in the `browse` mode.
45 + *
46 + * @param {wp.media.controller.Region} contentRegion
47 + */
48 + stockpackContent( contentRegion ) {
49 + const state = this.state();
50 + if ( ! state.get( 'stockpack-images' ) ) {
51 + state.set( 'stockpack-images', window.getStockpackQuery() );
52 + // Watch for downloaded images.
53 + state.get( 'library' ).observe( window.StockpackQueue );
54 + }
52 55
53 - if ( ! state.get( 'stockpack-selection' ) ) {
54 - let props;
55 - props = state.get( 'stockpack-images' ).props.toJSON();
56 - props = _.omit( props, 'orderby', 'query' );
56 + if ( ! state.get( 'stockpack-selection' ) ) {
57 + let props;
58 + props = state.get( 'stockpack-images' ).props.toJSON();
59 + props = _.omit( props, 'orderby', 'query' );
57 60
58 - state.set( 'stockpack-selection', new StockpackSelection( null, {
59 - multiple: false,
60 - props,
61 - } ) );
62 - }
61 + state.set( 'stockpack-selection', new StockpackSelection( null, {
62 + multiple: false,
63 + props,
64 + } ) );
65 + }
63 66
64 - this.$el.removeClass( 'hide-toolbar' );
67 + this.$el.removeClass( 'hide-toolbar' );
65 68
66 - // Browse our library of attachments.
67 - contentRegion.view = new StockpackBrowser( {
68 - collection: state.get( 'stockpack-images' ),
69 - selection: state.get( 'stockpack-selection' ),
70 - controller: this,
71 - model: state,
72 - idealColumnWidth: state.get( 'idealColumnWidth' ),
73 - suggestedWidth: state.get( 'suggestedWidth' ),
74 - suggestedHeight: state.get( 'suggestedHeight' ),
75 - } );
76 - },
69 + // Browse our library of attachments.
70 + contentRegion.view = new StockpackBrowser( {
71 + collection: state.get( 'stockpack-images' ),
72 + selection: state.get( 'stockpack-selection' ),
73 + controller: this,
74 + model: state,
75 + idealColumnWidth: state.get( 'idealColumnWidth' ),
76 + suggestedWidth: state.get( 'suggestedWidth' ),
77 + suggestedHeight: state.get( 'suggestedHeight' ),
78 + } );
79 + },
77 80
78 - getFrame( id ) {
79 - return this.states.findWhere( { id } );
80 - },
81 + getFrame( id ) {
82 + return this.states.findWhere( { id } );
83 + },
81 84
82 -} );
85 + } );
83 86
84 -// Order is important, post is based on the old select
85 -wp.media.view.MediaFrame.Select = oldMediaFrameSelect.extend( {
87 + // Order is important, post is based on the old select
88 + wp.media.view.MediaFrame.Select = oldMediaFrameSelect.extend( {
86 89
87 - /**
88 - * overwrite router to
89 - *
90 - * @param {wp.media.view.Router} routerView
91 - */
92 - browseRouter( routerView ) {
93 - oldMediaFrameSelect.prototype.browseRouter.apply( this, arguments );
94 - routerView.set( {
95 - stockpack: {
96 - text: wp.media.view.l10n.stockpack.title,
97 - priority: 60,
90 + /**
91 + * overwrite router to
92 + *
93 + * @param {wp.media.view.Router} routerView
94 + */
95 + browseRouter( routerView ) {
96 + oldMediaFrameSelect.prototype.browseRouter.apply( this, arguments );
97 + routerView.set( {
98 + stockpack: {
99 + text: wp.media.view.l10n.stockpack.title,
100 + priority: 60,
101 + },
102 + } );
98 103 },
99 - } );
100 - },
101 104
102 - /**
103 - * Bind region mode event callbacks.
104 - *
105 - * @see media.controller.Region.render
106 - */
107 - bindHandlers() {
108 - oldMediaFrameSelect.prototype.bindHandlers.apply( this, arguments );
109 - this.on( 'content:create:stockpack', this.stockpackContent, this );
110 - },
105 + /**
106 + * Bind region mode event callbacks.
107 + *
108 + * @see media.controller.Region.render
109 + */
110 + bindHandlers() {
111 + oldMediaFrameSelect.prototype.bindHandlers.apply( this, arguments );
112 + this.on( 'content:create:stockpack', this.stockpackContent, this );
113 + },
111 114
112 - /**
113 - * Render callback for the content region in the `browse` mode.
114 - *
115 - * @param {wp.media.controller.Region} contentRegion
116 - */
117 - stockpackContent( contentRegion ) {
118 - const state = this.state();
119 - if ( ! state.get( 'stockpack-images' ) ) {
120 - state.set( 'stockpack-images', window.getStockpackQuery() );
121 - // Watch for downloaded images.
122 - state.get( 'library' ).observe( window.StockpackQueue );
123 - }
115 + /**
116 + * Render callback for the content region in the `browse` mode.
117 + *
118 + * @param {wp.media.controller.Region} contentRegion
119 + */
120 + stockpackContent( contentRegion ) {
121 + const state = this.state();
122 + if ( ! state.get( 'stockpack-images' ) ) {
123 + state.set( 'stockpack-images', window.getStockpackQuery() );
124 + // Watch for downloaded images.
125 + state.get( 'library' ).observe( window.StockpackQueue );
126 + }
124 127
125 - if ( ! state.get( 'stockpack-selection' ) ) {
126 - let props;
127 - props = state.get( 'stockpack-images' ).props.toJSON();
128 - props = _.omit( props, 'orderby', 'query' );
128 + if ( ! state.get( 'stockpack-selection' ) ) {
129 + let props;
130 + props = state.get( 'stockpack-images' ).props.toJSON();
131 + props = _.omit( props, 'orderby', 'query' );
129 132
130 - state.set( 'stockpack-selection', new StockpackSelection( null, {
131 - multiple: false,
132 - props,
133 - } ) );
134 - }
133 + state.set( 'stockpack-selection', new StockpackSelection( null, {
134 + multiple: false,
135 + props,
136 + } ) );
137 + }
135 138
136 - if ( ! state.get( 'provider' ) ) {
137 - state.set( 'provider', '' );
138 - }
139 + if ( ! state.get( 'provider' ) ) {
140 + state.set( 'provider', '' );
141 + }
139 142
140 - this.$el.removeClass( 'hide-toolbar' );
143 + this.$el.removeClass( 'hide-toolbar' );
141 144
142 - // Browse our library of attachments.
143 - contentRegion.view = new StockpackBrowser( {
144 - collection: state.get( 'stockpack-images' ),
145 - selection: state.get( 'stockpack-selection' ),
146 - controller: this,
147 - model: state,
148 - idealColumnWidth: state.get( 'idealColumnWidth' ),
149 - suggestedWidth: state.get( 'suggestedWidth' ),
150 - suggestedHeight: state.get( 'suggestedHeight' ),
151 - provider: state.get( 'provider' ),
152 - } );
153 - },
145 + // Browse our library of attachments.
146 + contentRegion.view = new StockpackBrowser( {
147 + collection: state.get( 'stockpack-images' ),
148 + selection: state.get( 'stockpack-selection' ),
149 + controller: this,
150 + model: state,
151 + idealColumnWidth: state.get( 'idealColumnWidth' ),
152 + suggestedWidth: state.get( 'suggestedWidth' ),
153 + suggestedHeight: state.get( 'suggestedHeight' ),
154 + provider: state.get( 'provider' ),
155 + } );
156 + },
154 157
155 - getFrame( id ) {
156 - return this.states.findWhere( { id } );
157 - },
158 + getFrame( id ) {
159 + return this.states.findWhere( { id } );
160 + },
158 161
159 -} );
162 + } );
163 + }
164 +}
160 165
166 +export default Stockpack;