author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
19 | 1 |
/******/ (function() { // webpackBootstrap |
2 |
/******/ var __webpack_modules__ = ({ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
|
19 | 4 |
/***/ 7727: |
5 |
/***/ (function(module) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
var $ = Backbone.$, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
Attachment; |
5 | 9 |
|
10 |
/** |
|
11 |
* wp.media.model.Attachment |
|
12 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* |
5 | 15 |
* @class |
16 |
* @augments Backbone.Model |
|
17 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
Attachment = Backbone.Model.extend(/** @lends wp.media.model.Attachment.prototype */{ |
5 | 19 |
/** |
20 |
* Triggered when attachment details change |
|
21 |
* Overrides Backbone.Model.sync |
|
22 |
* |
|
23 |
* @param {string} method |
|
24 |
* @param {wp.media.model.Attachment} model |
|
25 |
* @param {Object} [options={}] |
|
26 |
* |
|
16 | 27 |
* @return {Promise} |
5 | 28 |
*/ |
29 |
sync: function( method, model, options ) { |
|
30 |
// If the attachment does not yet have an `id`, return an instantly |
|
31 |
// rejected promise. Otherwise, all of our requests will fail. |
|
32 |
if ( _.isUndefined( this.id ) ) { |
|
33 |
return $.Deferred().rejectWith( this ).promise(); |
|
34 |
} |
|
0 | 35 |
|
5 | 36 |
// Overload the `read` request so Attachment.fetch() functions correctly. |
37 |
if ( 'read' === method ) { |
|
38 |
options = options || {}; |
|
39 |
options.context = this; |
|
40 |
options.data = _.extend( options.data || {}, { |
|
41 |
action: 'get-attachment', |
|
42 |
id: this.id |
|
43 |
}); |
|
44 |
return wp.media.ajax( options ); |
|
0 | 45 |
|
5 | 46 |
// Overload the `update` request so properties can be saved. |
47 |
} else if ( 'update' === method ) { |
|
16 | 48 |
// If we do not have the necessary nonce, fail immediately. |
5 | 49 |
if ( ! this.get('nonces') || ! this.get('nonces').update ) { |
0 | 50 |
return $.Deferred().rejectWith( this ).promise(); |
5 | 51 |
} |
0 | 52 |
|
5 | 53 |
options = options || {}; |
54 |
options.context = this; |
|
55 |
||
56 |
// Set the action and ID. |
|
57 |
options.data = _.extend( options.data || {}, { |
|
58 |
action: 'save-attachment', |
|
0 | 59 |
id: this.id, |
60 |
nonce: this.get('nonces').update, |
|
5 | 61 |
post_id: wp.media.model.settings.post.id |
0 | 62 |
}); |
63 |
||
5 | 64 |
// Record the values of the changed attributes. |
65 |
if ( model.hasChanged() ) { |
|
66 |
options.data.changes = {}; |
|
0 | 67 |
|
5 | 68 |
_.each( model.changed, function( value, key ) { |
69 |
options.data.changes[ key ] = this.get( key ); |
|
70 |
}, this ); |
|
0 | 71 |
} |
72 |
||
5 | 73 |
return wp.media.ajax( options ); |
0 | 74 |
|
5 | 75 |
// Overload the `delete` request so attachments can be removed. |
76 |
// This will permanently delete an attachment. |
|
77 |
} else if ( 'delete' === method ) { |
|
0 | 78 |
options = options || {}; |
79 |
||
5 | 80 |
if ( ! options.wait ) { |
81 |
this.destroyed = true; |
|
82 |
} |
|
83 |
||
84 |
options.context = this; |
|
85 |
options.data = _.extend( options.data || {}, { |
|
86 |
action: 'delete-post', |
|
87 |
id: this.id, |
|
88 |
_wpnonce: this.get('nonces')['delete'] |
|
89 |
}); |
|
90 |
||
91 |
return wp.media.ajax( options ).done( function() { |
|
92 |
this.destroyed = true; |
|
93 |
}).fail( function() { |
|
94 |
this.destroyed = false; |
|
95 |
}); |
|
0 | 96 |
|
5 | 97 |
// Otherwise, fall back to `Backbone.sync()`. |
98 |
} else { |
|
99 |
/** |
|
100 |
* Call `sync` directly on Backbone.Model |
|
101 |
*/ |
|
102 |
return Backbone.Model.prototype.sync.apply( this, arguments ); |
|
103 |
} |
|
104 |
}, |
|
105 |
/** |
|
106 |
* Convert date strings into Date objects. |
|
107 |
* |
|
108 |
* @param {Object} resp The raw response object, typically returned by fetch() |
|
16 | 109 |
* @return {Object} The modified response object, which is the attributes hash |
110 |
* to be set on the model. |
|
5 | 111 |
*/ |
112 |
parse: function( resp ) { |
|
113 |
if ( ! resp ) { |
|
114 |
return resp; |
|
115 |
} |
|
0 | 116 |
|
5 | 117 |
resp.date = new Date( resp.date ); |
118 |
resp.modified = new Date( resp.modified ); |
|
119 |
return resp; |
|
120 |
}, |
|
121 |
/** |
|
122 |
* @param {Object} data The properties to be saved. |
|
123 |
* @param {Object} options Sync options. e.g. patch, wait, success, error. |
|
124 |
* |
|
125 |
* @this Backbone.Model |
|
126 |
* |
|
16 | 127 |
* @return {Promise} |
5 | 128 |
*/ |
129 |
saveCompat: function( data, options ) { |
|
130 |
var model = this; |
|
131 |
||
16 | 132 |
// If we do not have the necessary nonce, fail immediately. |
5 | 133 |
if ( ! this.get('nonces') || ! this.get('nonces').update ) { |
134 |
return $.Deferred().rejectWith( this ).promise(); |
|
135 |
} |
|
0 | 136 |
|
5 | 137 |
return wp.media.post( 'save-attachment-compat', _.defaults({ |
138 |
id: this.id, |
|
139 |
nonce: this.get('nonces').update, |
|
140 |
post_id: wp.media.model.settings.post.id |
|
141 |
}, data ) ).done( function( resp, status, xhr ) { |
|
142 |
model.set( model.parse( resp, xhr ), options ); |
|
143 |
}); |
|
144 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
},/** @lends wp.media.model.Attachment */{ |
5 | 146 |
/** |
147 |
* Create a new model on the static 'all' attachments collection and return it. |
|
148 |
* |
|
149 |
* @static |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* |
5 | 151 |
* @param {Object} attrs |
16 | 152 |
* @return {wp.media.model.Attachment} |
5 | 153 |
*/ |
154 |
create: function( attrs ) { |
|
155 |
var Attachments = wp.media.model.Attachments; |
|
156 |
return Attachments.all.push( attrs ); |
|
157 |
}, |
|
158 |
/** |
|
159 |
* Create a new model on the static 'all' attachments collection and return it. |
|
160 |
* |
|
161 |
* If this function has already been called for the id, |
|
162 |
* it returns the specified attachment. |
|
163 |
* |
|
164 |
* @static |
|
165 |
* @param {string} id A string used to identify a model. |
|
166 |
* @param {Backbone.Model|undefined} attachment |
|
16 | 167 |
* @return {wp.media.model.Attachment} |
5 | 168 |
*/ |
169 |
get: _.memoize( function( id, attachment ) { |
|
170 |
var Attachments = wp.media.model.Attachments; |
|
171 |
return Attachments.all.push( attachment || { id: id } ); |
|
172 |
}) |
|
173 |
}); |
|
174 |
||
175 |
module.exports = Attachment; |
|
176 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
|
19 | 180 |
/***/ 6940: |
181 |
/***/ (function(module) { |
|
0 | 182 |
|
5 | 183 |
/** |
184 |
* wp.media.model.Attachments |
|
185 |
* |
|
186 |
* A collection of attachments. |
|
187 |
* |
|
188 |
* This collection has no persistence with the server without supplying |
|
189 |
* 'options.props.query = true', which will mirror the collection |
|
190 |
* to an Attachments Query collection - @see wp.media.model.Attachments.mirror(). |
|
191 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* |
5 | 194 |
* @class |
195 |
* @augments Backbone.Collection |
|
196 |
* |
|
197 |
* @param {array} [models] Models to initialize with the collection. |
|
198 |
* @param {object} [options] Options hash for the collection. |
|
199 |
* @param {string} [options.props] Options hash for the initial query properties. |
|
200 |
* @param {string} [options.props.order] Initial order (ASC or DESC) for the collection. |
|
201 |
* @param {string} [options.props.orderby] Initial attribute key to order the collection by. |
|
202 |
* @param {string} [options.props.query] Whether the collection is linked to an attachments query. |
|
203 |
* @param {string} [options.observe] |
|
204 |
* @param {string} [options.filters] |
|
205 |
* |
|
206 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachments.prototype */{ |
5 | 208 |
/** |
209 |
* @type {wp.media.model.Attachment} |
|
210 |
*/ |
|
211 |
model: wp.media.model.Attachment, |
|
212 |
/** |
|
213 |
* @param {Array} [models=[]] Array of models used to populate the collection. |
|
214 |
* @param {Object} [options={}] |
|
215 |
*/ |
|
216 |
initialize: function( models, options ) { |
|
217 |
options = options || {}; |
|
218 |
||
219 |
this.props = new Backbone.Model(); |
|
220 |
this.filters = options.filters || {}; |
|
221 |
||
222 |
// Bind default `change` events to the `props` model. |
|
223 |
this.props.on( 'change', this._changeFilteredProps, this ); |
|
224 |
||
225 |
this.props.on( 'change:order', this._changeOrder, this ); |
|
226 |
this.props.on( 'change:orderby', this._changeOrderby, this ); |
|
227 |
this.props.on( 'change:query', this._changeQuery, this ); |
|
228 |
||
229 |
this.props.set( _.defaults( options.props || {} ) ); |
|
0 | 230 |
|
5 | 231 |
if ( options.observe ) { |
232 |
this.observe( options.observe ); |
|
233 |
} |
|
234 |
}, |
|
235 |
/** |
|
236 |
* Sort the collection when the order attribute changes. |
|
237 |
* |
|
238 |
* @access private |
|
239 |
*/ |
|
240 |
_changeOrder: function() { |
|
241 |
if ( this.comparator ) { |
|
242 |
this.sort(); |
|
243 |
} |
|
244 |
}, |
|
245 |
/** |
|
246 |
* Set the default comparator only when the `orderby` property is set. |
|
247 |
* |
|
248 |
* @access private |
|
249 |
* |
|
250 |
* @param {Backbone.Model} model |
|
251 |
* @param {string} orderby |
|
252 |
*/ |
|
253 |
_changeOrderby: function( model, orderby ) { |
|
254 |
// If a different comparator is defined, bail. |
|
255 |
if ( this.comparator && this.comparator !== Attachments.comparator ) { |
|
256 |
return; |
|
257 |
} |
|
0 | 258 |
|
5 | 259 |
if ( orderby && 'post__in' !== orderby ) { |
260 |
this.comparator = Attachments.comparator; |
|
261 |
} else { |
|
262 |
delete this.comparator; |
|
263 |
} |
|
264 |
}, |
|
265 |
/** |
|
266 |
* If the `query` property is set to true, query the server using |
|
267 |
* the `props` values, and sync the results to this collection. |
|
268 |
* |
|
269 |
* @access private |
|
270 |
* |
|
271 |
* @param {Backbone.Model} model |
|
16 | 272 |
* @param {boolean} query |
5 | 273 |
*/ |
274 |
_changeQuery: function( model, query ) { |
|
275 |
if ( query ) { |
|
276 |
this.props.on( 'change', this._requery, this ); |
|
277 |
this._requery(); |
|
278 |
} else { |
|
279 |
this.props.off( 'change', this._requery, this ); |
|
280 |
} |
|
281 |
}, |
|
282 |
/** |
|
283 |
* @access private |
|
284 |
* |
|
285 |
* @param {Backbone.Model} model |
|
286 |
*/ |
|
287 |
_changeFilteredProps: function( model ) { |
|
288 |
// If this is a query, updating the collection will be handled by |
|
289 |
// `this._requery()`. |
|
290 |
if ( this.props.get('query') ) { |
|
291 |
return; |
|
292 |
} |
|
293 |
||
294 |
var changed = _.chain( model.changed ).map( function( t, prop ) { |
|
295 |
var filter = Attachments.filters[ prop ], |
|
296 |
term = model.get( prop ); |
|
297 |
||
298 |
if ( ! filter ) { |
|
299 |
return; |
|
300 |
} |
|
301 |
||
302 |
if ( term && ! this.filters[ prop ] ) { |
|
303 |
this.filters[ prop ] = filter; |
|
304 |
} else if ( ! term && this.filters[ prop ] === filter ) { |
|
305 |
delete this.filters[ prop ]; |
|
0 | 306 |
} else { |
5 | 307 |
return; |
0 | 308 |
} |
309 |
||
5 | 310 |
// Record the change. |
311 |
return true; |
|
312 |
}, this ).any().value(); |
|
313 |
||
314 |
if ( ! changed ) { |
|
315 |
return; |
|
316 |
} |
|
0 | 317 |
|
16 | 318 |
// If no `Attachments` model is provided to source the searches from, |
319 |
// then automatically generate a source from the existing models. |
|
5 | 320 |
if ( ! this._source ) { |
321 |
this._source = new Attachments( this.models ); |
|
322 |
} |
|
0 | 323 |
|
5 | 324 |
this.reset( this._source.filter( this.validator, this ) ); |
325 |
}, |
|
0 | 326 |
|
5 | 327 |
validateDestroyed: false, |
328 |
/** |
|
329 |
* Checks whether an attachment is valid. |
|
330 |
* |
|
331 |
* @param {wp.media.model.Attachment} attachment |
|
16 | 332 |
* @return {boolean} |
5 | 333 |
*/ |
334 |
validator: function( attachment ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
|
5 | 336 |
if ( ! this.validateDestroyed && attachment.destroyed ) { |
337 |
return false; |
|
338 |
} |
|
339 |
return _.all( this.filters, function( filter ) { |
|
340 |
return !! filter.call( this, attachment ); |
|
341 |
}, this ); |
|
342 |
}, |
|
343 |
/** |
|
344 |
* Add or remove an attachment to the collection depending on its validity. |
|
345 |
* |
|
346 |
* @param {wp.media.model.Attachment} attachment |
|
347 |
* @param {Object} options |
|
16 | 348 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 349 |
*/ |
350 |
validate: function( attachment, options ) { |
|
351 |
var valid = this.validator( attachment ), |
|
352 |
hasAttachment = !! this.get( attachment.cid ); |
|
0 | 353 |
|
5 | 354 |
if ( ! valid && hasAttachment ) { |
355 |
this.remove( attachment, options ); |
|
356 |
} else if ( valid && ! hasAttachment ) { |
|
357 |
this.add( attachment, options ); |
|
358 |
} |
|
0 | 359 |
|
5 | 360 |
return this; |
361 |
}, |
|
0 | 362 |
|
5 | 363 |
/** |
364 |
* Add or remove all attachments from another collection depending on each one's validity. |
|
365 |
* |
|
366 |
* @param {wp.media.model.Attachments} attachments |
|
16 | 367 |
* @param {Object} [options={}] |
5 | 368 |
* |
369 |
* @fires wp.media.model.Attachments#reset |
|
370 |
* |
|
16 | 371 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 372 |
*/ |
373 |
validateAll: function( attachments, options ) { |
|
374 |
options = options || {}; |
|
0 | 375 |
|
5 | 376 |
_.each( attachments.models, function( attachment ) { |
377 |
this.validate( attachment, { silent: true }); |
|
378 |
}, this ); |
|
0 | 379 |
|
5 | 380 |
if ( ! options.silent ) { |
381 |
this.trigger( 'reset', this, options ); |
|
382 |
} |
|
383 |
return this; |
|
384 |
}, |
|
385 |
/** |
|
386 |
* Start observing another attachments collection change events |
|
387 |
* and replicate them on this collection. |
|
388 |
* |
|
389 |
* @param {wp.media.model.Attachments} The attachments collection to observe. |
|
16 | 390 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 391 |
*/ |
392 |
observe: function( attachments ) { |
|
393 |
this.observers = this.observers || []; |
|
394 |
this.observers.push( attachments ); |
|
0 | 395 |
|
5 | 396 |
attachments.on( 'add change remove', this._validateHandler, this ); |
18 | 397 |
attachments.on( 'add', this._addToTotalAttachments, this ); |
398 |
attachments.on( 'remove', this._removeFromTotalAttachments, this ); |
|
5 | 399 |
attachments.on( 'reset', this._validateAllHandler, this ); |
400 |
this.validateAll( attachments ); |
|
401 |
return this; |
|
402 |
}, |
|
403 |
/** |
|
404 |
* Stop replicating collection change events from another attachments collection. |
|
405 |
* |
|
406 |
* @param {wp.media.model.Attachments} The attachments collection to stop observing. |
|
16 | 407 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 408 |
*/ |
409 |
unobserve: function( attachments ) { |
|
410 |
if ( attachments ) { |
|
411 |
attachments.off( null, null, this ); |
|
412 |
this.observers = _.without( this.observers, attachments ); |
|
0 | 413 |
|
5 | 414 |
} else { |
415 |
_.each( this.observers, function( attachments ) { |
|
416 |
attachments.off( null, null, this ); |
|
417 |
}, this ); |
|
418 |
delete this.observers; |
|
419 |
} |
|
0 | 420 |
|
5 | 421 |
return this; |
422 |
}, |
|
423 |
/** |
|
18 | 424 |
* Update total attachment count when items are added to a collection. |
425 |
* |
|
426 |
* @access private |
|
427 |
* |
|
428 |
* @since 5.8.0 |
|
429 |
*/ |
|
430 |
_removeFromTotalAttachments: function() { |
|
431 |
if ( this.mirroring ) { |
|
432 |
this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1; |
|
433 |
} |
|
434 |
}, |
|
435 |
/** |
|
436 |
* Update total attachment count when items are added to a collection. |
|
437 |
* |
|
438 |
* @access private |
|
439 |
* |
|
440 |
* @since 5.8.0 |
|
441 |
*/ |
|
442 |
_addToTotalAttachments: function() { |
|
443 |
if ( this.mirroring ) { |
|
444 |
this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1; |
|
445 |
} |
|
446 |
}, |
|
447 |
/** |
|
5 | 448 |
* @access private |
449 |
* |
|
450 |
* @param {wp.media.model.Attachments} attachment |
|
451 |
* @param {wp.media.model.Attachments} attachments |
|
452 |
* @param {Object} options |
|
453 |
* |
|
16 | 454 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 455 |
*/ |
456 |
_validateHandler: function( attachment, attachments, options ) { |
|
457 |
// If we're not mirroring this `attachments` collection, |
|
458 |
// only retain the `silent` option. |
|
459 |
options = attachments === this.mirroring ? options : { |
|
460 |
silent: options && options.silent |
|
461 |
}; |
|
0 | 462 |
|
5 | 463 |
return this.validate( attachment, options ); |
464 |
}, |
|
465 |
/** |
|
466 |
* @access private |
|
467 |
* |
|
468 |
* @param {wp.media.model.Attachments} attachments |
|
469 |
* @param {Object} options |
|
16 | 470 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 471 |
*/ |
472 |
_validateAllHandler: function( attachments, options ) { |
|
473 |
return this.validateAll( attachments, options ); |
|
474 |
}, |
|
475 |
/** |
|
476 |
* Start mirroring another attachments collection, clearing out any models already |
|
477 |
* in the collection. |
|
478 |
* |
|
479 |
* @param {wp.media.model.Attachments} The attachments collection to mirror. |
|
16 | 480 |
* @return {wp.media.model.Attachments} Returns itself to allow chaining. |
5 | 481 |
*/ |
482 |
mirror: function( attachments ) { |
|
483 |
if ( this.mirroring && this.mirroring === attachments ) { |
|
484 |
return this; |
|
485 |
} |
|
0 | 486 |
|
5 | 487 |
this.unmirror(); |
488 |
this.mirroring = attachments; |
|
489 |
||
490 |
// Clear the collection silently. A `reset` event will be fired |
|
491 |
// when `observe()` calls `validateAll()`. |
|
492 |
this.reset( [], { silent: true } ); |
|
493 |
this.observe( attachments ); |
|
0 | 494 |
|
16 | 495 |
// Used for the search results. |
496 |
this.trigger( 'attachments:received', this ); |
|
5 | 497 |
return this; |
498 |
}, |
|
499 |
/** |
|
500 |
* Stop mirroring another attachments collection. |
|
501 |
*/ |
|
502 |
unmirror: function() { |
|
503 |
if ( ! this.mirroring ) { |
|
504 |
return; |
|
505 |
} |
|
0 | 506 |
|
5 | 507 |
this.unobserve( this.mirroring ); |
508 |
delete this.mirroring; |
|
509 |
}, |
|
510 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* Retrieve more attachments from the server for the collection. |
5 | 512 |
* |
513 |
* Only works if the collection is mirroring a Query Attachments collection, |
|
514 |
* and forwards to its `more` method. This collection class doesn't have |
|
515 |
* server persistence by itself. |
|
516 |
* |
|
16 | 517 |
* @param {Object} options |
518 |
* @return {Promise} |
|
5 | 519 |
*/ |
520 |
more: function( options ) { |
|
521 |
var deferred = jQuery.Deferred(), |
|
522 |
mirroring = this.mirroring, |
|
523 |
attachments = this; |
|
0 | 524 |
|
5 | 525 |
if ( ! mirroring || ! mirroring.more ) { |
526 |
return deferred.resolveWith( this ).promise(); |
|
527 |
} |
|
16 | 528 |
/* |
529 |
* If we're mirroring another collection, forward `more` to |
|
530 |
* the mirrored collection. Account for a race condition by |
|
531 |
* checking if we're still mirroring that collection when |
|
532 |
* the request resolves. |
|
533 |
*/ |
|
5 | 534 |
mirroring.more( options ).done( function() { |
535 |
if ( this === attachments.mirroring ) { |
|
536 |
deferred.resolveWith( this ); |
|
537 |
} |
|
16 | 538 |
|
539 |
// Used for the search results. |
|
540 |
attachments.trigger( 'attachments:received', this ); |
|
5 | 541 |
}); |
0 | 542 |
|
5 | 543 |
return deferred.promise(); |
544 |
}, |
|
545 |
/** |
|
546 |
* Whether there are more attachments that haven't been sync'd from the server |
|
547 |
* that match the collection's query. |
|
548 |
* |
|
549 |
* Only works if the collection is mirroring a Query Attachments collection, |
|
550 |
* and forwards to its `hasMore` method. This collection class doesn't have |
|
551 |
* server persistence by itself. |
|
552 |
* |
|
16 | 553 |
* @return {boolean} |
5 | 554 |
*/ |
555 |
hasMore: function() { |
|
556 |
return this.mirroring ? this.mirroring.hasMore() : false; |
|
557 |
}, |
|
558 |
/** |
|
18 | 559 |
* Holds the total number of attachments. |
560 |
* |
|
561 |
* @since 5.8.0 |
|
562 |
*/ |
|
563 |
totalAttachments: 0, |
|
564 |
||
565 |
/** |
|
566 |
* Gets the total number of attachments. |
|
567 |
* |
|
568 |
* @since 5.8.0 |
|
569 |
* |
|
570 |
* @return {number} The total number of attachments. |
|
571 |
*/ |
|
572 |
getTotalAttachments: function() { |
|
573 |
return this.mirroring ? this.mirroring.totalAttachments : 0; |
|
574 |
}, |
|
575 |
||
576 |
/** |
|
16 | 577 |
* A custom Ajax-response parser. |
5 | 578 |
* |
18 | 579 |
* See trac ticket #24753. |
5 | 580 |
* |
18 | 581 |
* Called automatically by Backbone whenever a collection's models are returned |
582 |
* by the server, in fetch. The default implementation is a no-op, simply |
|
583 |
* passing through the JSON response. We override this to add attributes to |
|
584 |
* the collection items. |
|
585 |
* |
|
586 |
* @param {Object|Array} response The raw response Object/Array. |
|
5 | 587 |
* @param {Object} xhr |
16 | 588 |
* @return {Array} The array of model attributes to be added to the collection |
5 | 589 |
*/ |
18 | 590 |
parse: function( response, xhr ) { |
591 |
if ( ! _.isArray( response ) ) { |
|
592 |
response = [response]; |
|
0 | 593 |
} |
18 | 594 |
return _.map( response, function( attrs ) { |
5 | 595 |
var id, attachment, newAttributes; |
0 | 596 |
|
5 | 597 |
if ( attrs instanceof Backbone.Model ) { |
598 |
id = attrs.get( 'id' ); |
|
599 |
attrs = attrs.attributes; |
|
600 |
} else { |
|
601 |
id = attrs.id; |
|
602 |
} |
|
0 | 603 |
|
5 | 604 |
attachment = wp.media.model.Attachment.get( id ); |
605 |
newAttributes = attachment.parse( attrs, xhr ); |
|
606 |
||
607 |
if ( ! _.isEqual( attachment.attributes, newAttributes ) ) { |
|
608 |
attachment.set( newAttributes ); |
|
0 | 609 |
} |
610 |
||
5 | 611 |
return attachment; |
612 |
}); |
|
613 |
}, |
|
18 | 614 |
|
5 | 615 |
/** |
616 |
* If the collection is a query, create and mirror an Attachments Query collection. |
|
617 |
* |
|
618 |
* @access private |
|
18 | 619 |
* @param {Boolean} refresh Deprecated, refresh parameter no longer used. |
5 | 620 |
*/ |
18 | 621 |
_requery: function() { |
5 | 622 |
var props; |
623 |
if ( this.props.get('query') ) { |
|
624 |
props = this.props.toJSON(); |
|
625 |
this.mirror( wp.media.model.Query.get( props ) ); |
|
626 |
} |
|
627 |
}, |
|
628 |
/** |
|
629 |
* If this collection is sorted by `menuOrder`, recalculates and saves |
|
630 |
* the menu order to the database. |
|
631 |
* |
|
16 | 632 |
* @return {undefined|Promise} |
5 | 633 |
*/ |
634 |
saveMenuOrder: function() { |
|
635 |
if ( 'menuOrder' !== this.props.get('orderby') ) { |
|
636 |
return; |
|
637 |
} |
|
0 | 638 |
|
16 | 639 |
/* |
640 |
* Removes any uploading attachments, updates each attachment's |
|
641 |
* menu order, and returns an object with an { id: menuOrder } |
|
642 |
* mapping to pass to the request. |
|
643 |
*/ |
|
5 | 644 |
var attachments = this.chain().filter( function( attachment ) { |
645 |
return ! _.isUndefined( attachment.id ); |
|
646 |
}).map( function( attachment, index ) { |
|
647 |
// Indices start at 1. |
|
648 |
index = index + 1; |
|
649 |
attachment.set( 'menuOrder', index ); |
|
650 |
return [ attachment.id, index ]; |
|
651 |
}).object().value(); |
|
652 |
||
653 |
if ( _.isEmpty( attachments ) ) { |
|
654 |
return; |
|
655 |
} |
|
0 | 656 |
|
5 | 657 |
return wp.media.post( 'save-attachment-order', { |
658 |
nonce: wp.media.model.settings.post.nonce, |
|
659 |
post_id: wp.media.model.settings.post.id, |
|
660 |
attachments: attachments |
|
661 |
}); |
|
662 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
},/** @lends wp.media.model.Attachments */{ |
5 | 664 |
/** |
665 |
* A function to compare two attachment models in an attachments collection. |
|
666 |
* |
|
667 |
* Used as the default comparator for instances of wp.media.model.Attachments |
|
668 |
* and its subclasses. @see wp.media.model.Attachments._changeOrderby(). |
|
669 |
* |
|
670 |
* @param {Backbone.Model} a |
|
671 |
* @param {Backbone.Model} b |
|
672 |
* @param {Object} options |
|
16 | 673 |
* @return {number} -1 if the first model should come before the second, |
674 |
* 0 if they are of the same rank and |
|
675 |
* 1 if the first model should come after. |
|
5 | 676 |
*/ |
677 |
comparator: function( a, b, options ) { |
|
678 |
var key = this.props.get('orderby'), |
|
679 |
order = this.props.get('order') || 'DESC', |
|
680 |
ac = a.cid, |
|
681 |
bc = b.cid; |
|
682 |
||
683 |
a = a.get( key ); |
|
684 |
b = b.get( key ); |
|
685 |
||
686 |
if ( 'date' === key || 'modified' === key ) { |
|
687 |
a = a || new Date(); |
|
688 |
b = b || new Date(); |
|
689 |
} |
|
690 |
||
691 |
// If `options.ties` is set, don't enforce the `cid` tiebreaker. |
|
692 |
if ( options && options.ties ) { |
|
693 |
ac = bc = null; |
|
694 |
} |
|
695 |
||
696 |
return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac ); |
|
697 |
}, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
/** @namespace wp.media.model.Attachments.filters */ |
5 | 699 |
filters: { |
700 |
/** |
|
701 |
* @static |
|
702 |
* Note that this client-side searching is *not* equivalent |
|
703 |
* to our server-side searching. |
|
704 |
* |
|
705 |
* @param {wp.media.model.Attachment} attachment |
|
706 |
* |
|
707 |
* @this wp.media.model.Attachments |
|
708 |
* |
|
16 | 709 |
* @return {Boolean} |
5 | 710 |
*/ |
711 |
search: function( attachment ) { |
|
712 |
if ( ! this.props.get('search') ) { |
|
713 |
return true; |
|
714 |
} |
|
0 | 715 |
|
5 | 716 |
return _.any(['title','filename','description','caption','name'], function( key ) { |
717 |
var value = attachment.get( key ); |
|
718 |
return value && -1 !== value.search( this.props.get('search') ); |
|
719 |
}, this ); |
|
720 |
}, |
|
721 |
/** |
|
722 |
* @static |
|
723 |
* @param {wp.media.model.Attachment} attachment |
|
724 |
* |
|
725 |
* @this wp.media.model.Attachments |
|
726 |
* |
|
16 | 727 |
* @return {boolean} |
5 | 728 |
*/ |
729 |
type: function( attachment ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
var type = this.props.get('type'), atts = attachment.toJSON(), mime, found; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
if ( ! type || ( _.isArray( type ) && ! type.length ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
mime = atts.mime || ( atts.file && atts.file.type ) || ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
if ( _.isArray( type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
found = _.find( type, function (t) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
return -1 !== mime.indexOf( t ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
found = -1 !== mime.indexOf( type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
return found; |
5 | 747 |
}, |
748 |
/** |
|
749 |
* @static |
|
750 |
* @param {wp.media.model.Attachment} attachment |
|
751 |
* |
|
752 |
* @this wp.media.model.Attachments |
|
753 |
* |
|
16 | 754 |
* @return {boolean} |
5 | 755 |
*/ |
756 |
uploadedTo: function( attachment ) { |
|
757 |
var uploadedTo = this.props.get('uploadedTo'); |
|
758 |
if ( _.isUndefined( uploadedTo ) ) { |
|
759 |
return true; |
|
760 |
} |
|
761 |
||
762 |
return uploadedTo === attachment.get('uploadedTo'); |
|
763 |
}, |
|
764 |
/** |
|
765 |
* @static |
|
766 |
* @param {wp.media.model.Attachment} attachment |
|
767 |
* |
|
768 |
* @this wp.media.model.Attachments |
|
769 |
* |
|
16 | 770 |
* @return {boolean} |
5 | 771 |
*/ |
772 |
status: function( attachment ) { |
|
773 |
var status = this.props.get('status'); |
|
774 |
if ( _.isUndefined( status ) ) { |
|
775 |
return true; |
|
776 |
} |
|
777 |
||
778 |
return status === attachment.get('status'); |
|
779 |
} |
|
780 |
} |
|
781 |
}); |
|
782 |
||
783 |
module.exports = Attachments; |
|
784 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
|
19 | 788 |
/***/ 5927: |
789 |
/***/ (function(module) { |
|
18 | 790 |
|
791 |
/** |
|
19 | 792 |
* wp.media.model.PostImage |
793 |
* |
|
794 |
* An instance of an image that's been embedded into a post. |
|
18 | 795 |
* |
19 | 796 |
* Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. |
797 |
* |
|
798 |
* @memberOf wp.media.model |
|
799 |
* |
|
800 |
* @class |
|
801 |
* @augments Backbone.Model |
|
18 | 802 |
* |
19 | 803 |
* @param {int} [attributes] Initial model attributes. |
804 |
* @param {int} [attributes.attachment_id] ID of the attachment. |
|
805 |
**/ |
|
806 |
var PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{ |
|
807 |
||
808 |
initialize: function( attributes ) { |
|
809 |
var Attachment = wp.media.model.Attachment; |
|
810 |
this.attachment = false; |
|
18 | 811 |
|
19 | 812 |
if ( attributes.attachment_id ) { |
813 |
this.attachment = Attachment.get( attributes.attachment_id ); |
|
814 |
if ( this.attachment.get( 'url' ) ) { |
|
815 |
this.dfd = jQuery.Deferred(); |
|
816 |
this.dfd.resolve(); |
|
817 |
} else { |
|
818 |
this.dfd = this.attachment.fetch(); |
|
819 |
} |
|
820 |
this.bindAttachmentListeners(); |
|
821 |
} |
|
822 |
||
823 |
// Keep URL in sync with changes to the type of link. |
|
824 |
this.on( 'change:link', this.updateLinkUrl, this ); |
|
825 |
this.on( 'change:size', this.updateSize, this ); |
|
18 | 826 |
|
19 | 827 |
this.setLinkTypeFromUrl(); |
828 |
this.setAspectRatio(); |
|
829 |
||
830 |
this.set( 'originalUrl', attributes.url ); |
|
831 |
}, |
|
18 | 832 |
|
19 | 833 |
bindAttachmentListeners: function() { |
834 |
this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl ); |
|
835 |
this.listenTo( this.attachment, 'sync', this.setAspectRatio ); |
|
836 |
this.listenTo( this.attachment, 'change', this.updateSize ); |
|
837 |
}, |
|
838 |
||
839 |
changeAttachment: function( attachment, props ) { |
|
840 |
this.stopListening( this.attachment ); |
|
841 |
this.attachment = attachment; |
|
842 |
this.bindAttachmentListeners(); |
|
18 | 843 |
|
19 | 844 |
this.set( 'attachment_id', this.attachment.get( 'id' ) ); |
845 |
this.set( 'caption', this.attachment.get( 'caption' ) ); |
|
846 |
this.set( 'alt', this.attachment.get( 'alt' ) ); |
|
847 |
this.set( 'size', props.get( 'size' ) ); |
|
848 |
this.set( 'align', props.get( 'align' ) ); |
|
849 |
this.set( 'link', props.get( 'link' ) ); |
|
850 |
this.updateLinkUrl(); |
|
851 |
this.updateSize(); |
|
852 |
}, |
|
18 | 853 |
|
19 | 854 |
setLinkTypeFromUrl: function() { |
855 |
var linkUrl = this.get( 'linkUrl' ), |
|
856 |
type; |
|
857 |
||
858 |
if ( ! linkUrl ) { |
|
859 |
this.set( 'link', 'none' ); |
|
860 |
return; |
|
18 | 861 |
} |
862 |
||
19 | 863 |
// Default to custom if there is a linkUrl. |
864 |
type = 'custom'; |
|
865 |
||
866 |
if ( this.attachment ) { |
|
867 |
if ( this.attachment.get( 'url' ) === linkUrl ) { |
|
868 |
type = 'file'; |
|
869 |
} else if ( this.attachment.get( 'link' ) === linkUrl ) { |
|
870 |
type = 'post'; |
|
871 |
} |
|
18 | 872 |
} else { |
19 | 873 |
if ( this.get( 'url' ) === linkUrl ) { |
874 |
type = 'file'; |
|
875 |
} |
|
876 |
} |
|
877 |
||
878 |
this.set( 'link', type ); |
|
879 |
}, |
|
880 |
||
881 |
updateLinkUrl: function() { |
|
882 |
var link = this.get( 'link' ), |
|
883 |
url; |
|
884 |
||
885 |
switch( link ) { |
|
886 |
case 'file': |
|
887 |
if ( this.attachment ) { |
|
888 |
url = this.attachment.get( 'url' ); |
|
889 |
} else { |
|
890 |
url = this.get( 'url' ); |
|
891 |
} |
|
892 |
this.set( 'linkUrl', url ); |
|
893 |
break; |
|
894 |
case 'post': |
|
895 |
this.set( 'linkUrl', this.attachment.get( 'link' ) ); |
|
896 |
break; |
|
897 |
case 'none': |
|
898 |
this.set( 'linkUrl', '' ); |
|
899 |
break; |
|
18 | 900 |
} |
901 |
}, |
|
19 | 902 |
|
903 |
updateSize: function() { |
|
904 |
var size; |
|
18 | 905 |
|
19 | 906 |
if ( ! this.attachment ) { |
907 |
return; |
|
908 |
} |
|
909 |
||
910 |
if ( this.get( 'size' ) === 'custom' ) { |
|
911 |
this.set( 'width', this.get( 'customWidth' ) ); |
|
912 |
this.set( 'height', this.get( 'customHeight' ) ); |
|
913 |
this.set( 'url', this.get( 'originalUrl' ) ); |
|
914 |
return; |
|
18 | 915 |
} |
916 |
||
19 | 917 |
size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ]; |
918 |
||
919 |
if ( ! size ) { |
|
920 |
return; |
|
921 |
} |
|
922 |
||
923 |
this.set( 'url', size.url ); |
|
924 |
this.set( 'width', size.width ); |
|
925 |
this.set( 'height', size.height ); |
|
926 |
}, |
|
927 |
||
928 |
setAspectRatio: function() { |
|
929 |
var full; |
|
930 |
||
931 |
if ( this.attachment && this.attachment.get( 'sizes' ) ) { |
|
932 |
full = this.attachment.get( 'sizes' ).full; |
|
933 |
||
934 |
if ( full ) { |
|
935 |
this.set( 'aspectRatio', full.width / full.height ); |
|
936 |
return; |
|
937 |
} |
|
938 |
} |
|
939 |
||
940 |
this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) ); |
|
18 | 941 |
} |
942 |
}); |
|
943 |
||
19 | 944 |
module.exports = PostImage; |
18 | 945 |
|
946 |
||
947 |
/***/ }), |
|
948 |
||
19 | 949 |
/***/ 4009: |
950 |
/***/ (function(module) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
var Attachments = wp.media.model.Attachments, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
Query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* wp.media.model.Query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
* A collection of attachments that match the supplied query arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
* Note: Do NOT change this.args after the query has been initialized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
* Things will break. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
* @class |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
* @augments wp.media.model.Attachments |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* @augments Backbone.Collection |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
* @param {array} [models] Models to initialize with the collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
* @param {object} [options] Options hash. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
* @param {object} [options.args] Attachments query arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
* @param {object} [options.args.posts_per_page] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
/** |
16 | 976 |
* @param {Array} [models=[]] Array of initial models to populate the collection. |
977 |
* @param {Object} [options={}] |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
initialize: function( models, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
var allowed; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
Attachments.prototype.initialize.apply( this, arguments ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
this.args = options.args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
this._hasMore = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
this.created = new Date(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
this.filters.order = function( attachment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
var orderby = this.props.get('orderby'), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
order = this.props.get('order'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
if ( ! this.comparator ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
|
16 | 997 |
/* |
998 |
* We want any items that can be placed before the last |
|
999 |
* item in the set. If we add any items after the last |
|
1000 |
* item, then we can't guarantee the set is complete. |
|
1001 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
if ( this.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
return 1 !== this.comparator( attachment, this.last(), { ties: true }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
|
16 | 1005 |
/* |
1006 |
* Handle the case where there are no items yet and |
|
1007 |
* we're sorting for recent items. In that case, we want |
|
1008 |
* changes that occurred after we created the query. |
|
1009 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
} else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
return attachment.get( orderby ) >= this.created; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
// If we're sorting by menu order and we have no items, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
// accept any items that have the default menu order (0). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
} else if ( 'ASC' === order && 'menuOrder' === orderby ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
return attachment.get( orderby ) === 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
// Otherwise, we don't want any items yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
|
16 | 1023 |
/* |
1024 |
* Observe the central `wp.Uploader.queue` collection to watch for |
|
1025 |
* new matches for the query. |
|
1026 |
* |
|
1027 |
* Only observe when a limited number of query args are set. There |
|
1028 |
* are no filters for other properties, so observing will result in |
|
1029 |
* false positives in those queries. |
|
1030 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
this.observe( wp.Uploader.queue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
* Whether there are more attachments that haven't been sync'd from the server |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
* that match the collection's query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* |
16 | 1040 |
* @return {boolean} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
hasMore: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
return this._hasMore; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* Fetch more attachments from the server for the collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
* |
16 | 1048 |
* @param {Object} [options={}] |
1049 |
* @return {Promise} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
more: function( options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
var query = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
// If there is already a request pending, return early with the Deferred object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
if ( this._more && 'pending' === this._more.state() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
return this._more; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
if ( ! this.hasMore() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
return jQuery.Deferred().resolveWith( this ).promise(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
options.remove = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
|
18 | 1066 |
return this._more = this.fetch( options ).done( function( response ) { |
1067 |
if ( _.isEmpty( response ) || -1 === query.args.posts_per_page || response.length < query.args.posts_per_page ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
query._hasMore = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
* Overrides Backbone.Collection.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
* Overrides wp.media.model.Attachments.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* |
16 | 1076 |
* @param {string} method |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
* @param {Backbone.Model} model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
* @param {Object} [options={}] |
16 | 1079 |
* @return {Promise} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
sync: function( method, model, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
var args, fallback; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
// Overload the read method so Attachment.fetch() functions correctly. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
if ( 'read' === method ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
options = options || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
options.context = this; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
options.data = _.extend( options.data || {}, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
action: 'query-attachments', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
post_id: wp.media.model.settings.post.id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
// Clone the args so manipulation is non-destructive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
args = _.clone( this.args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
// Determine which page to query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
if ( -1 !== args.posts_per_page ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
args.paged = Math.round( this.length / args.posts_per_page ) + 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
options.data.query = args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
return wp.media.ajax( options ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
|
16 | 1104 |
// Otherwise, fall back to `Backbone.sync()`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
* Call wp.media.model.Attachments.sync or Backbone.sync |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
return fallback.sync.apply( this, arguments ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
}, /** @lends wp.media.model.Query */{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
defaultProps: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
orderby: 'date', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
order: 'DESC' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
defaultArgs: { |
18 | 1125 |
posts_per_page: 80 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
orderby: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* A map of JavaScript orderby values to their WP_Query equivalents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
* @type {Object} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
valuemap: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
'id': 'ID', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
'uploadedTo': 'parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
'menuOrder': 'menu_order ID' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
* A map of JavaScript query properties to their WP_Query equivalents. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
* @readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
propmap: { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
'search': 's', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
'type': 'post_mime_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
'perPage': 'posts_per_page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
'menuOrder': 'menu_order', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
'uploadedTo': 'post_parent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
'status': 'post_status', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
'include': 'post__in', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
'exclude': 'post__not_in', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
'author': 'author' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
* Creates and returns an Attachments Query collection given the properties. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* Caches query objects and reuses where possible. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* @method |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
* @param {object} [props] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
* @param {Object} [props.order] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
* @param {Object} [props.orderby] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
* @param {Object} [props.include] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
* @param {Object} [props.exclude] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* @param {Object} [props.s] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* @param {Object} [props.post_mime_type] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* @param {Object} [props.posts_per_page] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* @param {Object} [props.menu_order] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* @param {Object} [props.post_parent] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* @param {Object} [props.post_status] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* @param {Object} [props.author] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
* @param {Object} [options] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
* |
16 | 1180 |
* @return {wp.media.model.Query} A new Attachments Query collection. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
get: (function(){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
* @type Array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
var queries = []; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
/** |
16 | 1190 |
* @return {Query} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
return function( props, options ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
var args = {}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
orderby = Query.orderby, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
defaults = Query.defaultProps, |
18 | 1196 |
query; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
// Remove the `query` property. This isn't linked to a query, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
// this *is* the query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
delete props.query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
// Fill default args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
_.defaults( props, defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
// Normalize the order. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
props.order = props.order.toUpperCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
if ( 'DESC' !== props.order && 'ASC' !== props.order ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
props.order = defaults.order.toUpperCase(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
// Ensure we have a valid orderby value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
if ( ! _.contains( orderby.allowed, props.orderby ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
props.orderby = defaults.orderby; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
_.each( [ 'include', 'exclude' ], function( prop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
props[ prop ] = [ props[ prop ] ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
// Generate the query `args` object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
// Correct any differing property names. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
_.each( props, function( value, prop ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
if ( _.isNull( value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
args[ Query.propmap[ prop ] || prop ] = value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
// Fill any other default query args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
_.defaults( args, Query.defaultArgs ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
// `props.orderby` does not always map directly to `args.orderby`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
// Substitute exceptions specified in orderby.keymap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
|
18 | 1239 |
queries = []; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
// Otherwise, create a new query and add it to the cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
if ( ! query ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
query = new Query( [], _.extend( options || {}, { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
props: props, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
args: args |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
} ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
queries.push( query ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
return query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
}()) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
module.exports = Query; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
/***/ }), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
|
19 | 1260 |
/***/ 6584: |
1261 |
/***/ (function(module) { |
|
1262 |
||
1263 |
var Attachments = wp.media.model.Attachments, |
|
1264 |
Selection; |
|
0 | 1265 |
|
5 | 1266 |
/** |
19 | 1267 |
* wp.media.model.Selection |
5 | 1268 |
* |
19 | 1269 |
* A selection of attachments. |
5 | 1270 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
* @memberOf wp.media.model |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1272 |
* |
5 | 1273 |
* @class |
19 | 1274 |
* @augments wp.media.model.Attachments |
1275 |
* @augments Backbone.Collection |
|
1276 |
*/ |
|
1277 |
Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{ |
|
1278 |
/** |
|
1279 |
* Refresh the `single` model whenever the selection changes. |
|
1280 |
* Binds `single` instead of using the context argument to ensure |
|
1281 |
* it receives no parameters. |
|
1282 |
* |
|
1283 |
* @param {Array} [models=[]] Array of models used to populate the collection. |
|
1284 |
* @param {Object} [options={}] |
|
1285 |
*/ |
|
1286 |
initialize: function( models, options ) { |
|
1287 |
/** |
|
1288 |
* call 'initialize' directly on the parent class |
|
1289 |
*/ |
|
1290 |
Attachments.prototype.initialize.apply( this, arguments ); |
|
1291 |
this.multiple = options && options.multiple; |
|
5 | 1292 |
|
19 | 1293 |
this.on( 'add remove reset', _.bind( this.single, this, false ) ); |
5 | 1294 |
}, |
0 | 1295 |
|
19 | 1296 |
/** |
1297 |
* If the workflow does not support multi-select, clear out the selection |
|
1298 |
* before adding a new attachment to it. |
|
1299 |
* |
|
1300 |
* @param {Array} models |
|
1301 |
* @param {Object} options |
|
1302 |
* @return {wp.media.model.Attachment[]} |
|
1303 |
*/ |
|
1304 |
add: function( models, options ) { |
|
1305 |
if ( ! this.multiple ) { |
|
1306 |
this.remove( this.models ); |
|
1307 |
} |
|
1308 |
/** |
|
1309 |
* call 'add' directly on the parent class |
|
1310 |
*/ |
|
1311 |
return Attachments.prototype.add.call( this, models, options ); |
|
5 | 1312 |
}, |
0 | 1313 |
|
19 | 1314 |
/** |
1315 |
* Fired when toggling (clicking on) an attachment in the modal. |
|
1316 |
* |
|
1317 |
* @param {undefined|boolean|wp.media.model.Attachment} model |
|
1318 |
* |
|
1319 |
* @fires wp.media.model.Selection#selection:single |
|
1320 |
* @fires wp.media.model.Selection#selection:unsingle |
|
1321 |
* |
|
1322 |
* @return {Backbone.Model} |
|
1323 |
*/ |
|
1324 |
single: function( model ) { |
|
1325 |
var previous = this._single; |
|
5 | 1326 |
|
19 | 1327 |
// If a `model` is provided, use it as the single model. |
1328 |
if ( model ) { |
|
1329 |
this._single = model; |
|
1330 |
} |
|
1331 |
// If the single model isn't in the selection, remove it. |
|
1332 |
if ( this._single && ! this.get( this._single.cid ) ) { |
|
1333 |
delete this._single; |
|
5 | 1334 |
} |
1335 |
||
19 | 1336 |
this._single = this._single || this.last(); |
1337 |
||
1338 |
// If single has changed, fire an event. |
|
1339 |
if ( this._single !== previous ) { |
|
1340 |
if ( previous ) { |
|
1341 |
previous.trigger( 'selection:unsingle', previous, this ); |
|
5 | 1342 |
|
19 | 1343 |
// If the model was already removed, trigger the collection |
1344 |
// event manually. |
|
1345 |
if ( ! this.get( previous.cid ) ) { |
|
1346 |
this.trigger( 'selection:unsingle', previous, this ); |
|
1347 |
} |
|
5 | 1348 |
} |
19 | 1349 |
if ( this._single ) { |
1350 |
this._single.trigger( 'selection:single', this._single, this ); |
|
0 | 1351 |
} |
1352 |
} |
|
5 | 1353 |
|
19 | 1354 |
// Return the single model, or the last model as a fallback. |
1355 |
return this._single; |
|
5 | 1356 |
} |
1357 |
}); |
|
1358 |
||
19 | 1359 |
module.exports = Selection; |
5 | 1360 |
|
1361 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
/***/ }) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
|
19 | 1364 |
/******/ }); |
1365 |
/************************************************************************/ |
|
1366 |
/******/ // The module cache |
|
1367 |
/******/ var __webpack_module_cache__ = {}; |
|
1368 |
/******/ |
|
1369 |
/******/ // The require function |
|
1370 |
/******/ function __webpack_require__(moduleId) { |
|
1371 |
/******/ // Check if module is in cache |
|
1372 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
1373 |
/******/ if (cachedModule !== undefined) { |
|
1374 |
/******/ return cachedModule.exports; |
|
1375 |
/******/ } |
|
1376 |
/******/ // Create a new module (and put it into the cache) |
|
1377 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
|
1378 |
/******/ // no module.id needed |
|
1379 |
/******/ // no module.loaded needed |
|
1380 |
/******/ exports: {} |
|
1381 |
/******/ }; |
|
1382 |
/******/ |
|
1383 |
/******/ // Execute the module function |
|
1384 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
1385 |
/******/ |
|
1386 |
/******/ // Return the exports of the module |
|
1387 |
/******/ return module.exports; |
|
1388 |
/******/ } |
|
1389 |
/******/ |
|
1390 |
/************************************************************************/ |
|
1391 |
var __webpack_exports__ = {}; |
|
1392 |
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
|
1393 |
!function() { |
|
1394 |
/** |
|
1395 |
* @output wp-includes/js/media-models.js |
|
1396 |
*/ |
|
1397 |
||
1398 |
var $ = jQuery, |
|
1399 |
Attachment, Attachments, l10n, media; |
|
1400 |
||
1401 |
/** @namespace wp */ |
|
1402 |
window.wp = window.wp || {}; |
|
1403 |
||
1404 |
/** |
|
1405 |
* Create and return a media frame. |
|
1406 |
* |
|
1407 |
* Handles the default media experience. |
|
1408 |
* |
|
1409 |
* @alias wp.media |
|
1410 |
* @memberOf wp |
|
1411 |
* @namespace |
|
1412 |
* |
|
1413 |
* @param {Object} attributes The properties passed to the main media controller. |
|
1414 |
* @return {wp.media.view.MediaFrame} A media workflow. |
|
1415 |
*/ |
|
1416 |
media = wp.media = function( attributes ) { |
|
1417 |
var MediaFrame = media.view.MediaFrame, |
|
1418 |
frame; |
|
1419 |
||
1420 |
if ( ! MediaFrame ) { |
|
1421 |
return; |
|
1422 |
} |
|
1423 |
||
1424 |
attributes = _.defaults( attributes || {}, { |
|
1425 |
frame: 'select' |
|
1426 |
}); |
|
1427 |
||
1428 |
if ( 'select' === attributes.frame && MediaFrame.Select ) { |
|
1429 |
frame = new MediaFrame.Select( attributes ); |
|
1430 |
} else if ( 'post' === attributes.frame && MediaFrame.Post ) { |
|
1431 |
frame = new MediaFrame.Post( attributes ); |
|
1432 |
} else if ( 'manage' === attributes.frame && MediaFrame.Manage ) { |
|
1433 |
frame = new MediaFrame.Manage( attributes ); |
|
1434 |
} else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) { |
|
1435 |
frame = new MediaFrame.ImageDetails( attributes ); |
|
1436 |
} else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) { |
|
1437 |
frame = new MediaFrame.AudioDetails( attributes ); |
|
1438 |
} else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) { |
|
1439 |
frame = new MediaFrame.VideoDetails( attributes ); |
|
1440 |
} else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) { |
|
1441 |
frame = new MediaFrame.EditAttachments( attributes ); |
|
1442 |
} |
|
1443 |
||
1444 |
delete attributes.frame; |
|
1445 |
||
1446 |
media.frame = frame; |
|
1447 |
||
1448 |
return frame; |
|
1449 |
}; |
|
1450 |
||
1451 |
/** @namespace wp.media.model */ |
|
1452 |
/** @namespace wp.media.view */ |
|
1453 |
/** @namespace wp.media.controller */ |
|
1454 |
/** @namespace wp.media.frames */ |
|
1455 |
_.extend( media, { model: {}, view: {}, controller: {}, frames: {} }); |
|
1456 |
||
1457 |
// Link any localized strings. |
|
1458 |
l10n = media.model.l10n = window._wpMediaModelsL10n || {}; |
|
1459 |
||
1460 |
// Link any settings. |
|
1461 |
media.model.settings = l10n.settings || {}; |
|
1462 |
delete l10n.settings; |
|
1463 |
||
1464 |
Attachment = media.model.Attachment = __webpack_require__( 7727 ); |
|
1465 |
Attachments = media.model.Attachments = __webpack_require__( 6940 ); |
|
1466 |
||
1467 |
media.model.Query = __webpack_require__( 4009 ); |
|
1468 |
media.model.PostImage = __webpack_require__( 5927 ); |
|
1469 |
media.model.Selection = __webpack_require__( 6584 ); |
|
1470 |
||
1471 |
/** |
|
1472 |
* ======================================================================== |
|
1473 |
* UTILITIES |
|
1474 |
* ======================================================================== |
|
1475 |
*/ |
|
1476 |
||
1477 |
/** |
|
1478 |
* A basic equality comparator for Backbone models. |
|
1479 |
* |
|
1480 |
* Used to order models within a collection - @see wp.media.model.Attachments.comparator(). |
|
1481 |
* |
|
1482 |
* @param {mixed} a The primary parameter to compare. |
|
1483 |
* @param {mixed} b The primary parameter to compare. |
|
1484 |
* @param {string} ac The fallback parameter to compare, a's cid. |
|
1485 |
* @param {string} bc The fallback parameter to compare, b's cid. |
|
1486 |
* @return {number} -1: a should come before b. |
|
1487 |
* 0: a and b are of the same rank. |
|
1488 |
* 1: b should come before a. |
|
1489 |
*/ |
|
1490 |
media.compare = function( a, b, ac, bc ) { |
|
1491 |
if ( _.isEqual( a, b ) ) { |
|
1492 |
return ac === bc ? 0 : (ac > bc ? -1 : 1); |
|
1493 |
} else { |
|
1494 |
return a > b ? -1 : 1; |
|
1495 |
} |
|
1496 |
}; |
|
1497 |
||
1498 |
_.extend( media, /** @lends wp.media */{ |
|
1499 |
/** |
|
1500 |
* media.template( id ) |
|
1501 |
* |
|
1502 |
* Fetch a JavaScript template for an id, and return a templating function for it. |
|
1503 |
* |
|
1504 |
* See wp.template() in `wp-includes/js/wp-util.js`. |
|
1505 |
* |
|
1506 |
* @borrows wp.template as template |
|
1507 |
*/ |
|
1508 |
template: wp.template, |
|
1509 |
||
1510 |
/** |
|
1511 |
* media.post( [action], [data] ) |
|
1512 |
* |
|
1513 |
* Sends a POST request to WordPress. |
|
1514 |
* See wp.ajax.post() in `wp-includes/js/wp-util.js`. |
|
1515 |
* |
|
1516 |
* @borrows wp.ajax.post as post |
|
1517 |
*/ |
|
1518 |
post: wp.ajax.post, |
|
1519 |
||
1520 |
/** |
|
1521 |
* media.ajax( [action], [options] ) |
|
1522 |
* |
|
1523 |
* Sends an XHR request to WordPress. |
|
1524 |
* See wp.ajax.send() in `wp-includes/js/wp-util.js`. |
|
1525 |
* |
|
1526 |
* @borrows wp.ajax.send as ajax |
|
1527 |
*/ |
|
1528 |
ajax: wp.ajax.send, |
|
1529 |
||
1530 |
/** |
|
1531 |
* Scales a set of dimensions to fit within bounding dimensions. |
|
1532 |
* |
|
1533 |
* @param {Object} dimensions |
|
1534 |
* @return {Object} |
|
1535 |
*/ |
|
1536 |
fit: function( dimensions ) { |
|
1537 |
var width = dimensions.width, |
|
1538 |
height = dimensions.height, |
|
1539 |
maxWidth = dimensions.maxWidth, |
|
1540 |
maxHeight = dimensions.maxHeight, |
|
1541 |
constraint; |
|
1542 |
||
1543 |
/* |
|
1544 |
* Compare ratios between the two values to determine |
|
1545 |
* which max to constrain by. If a max value doesn't exist, |
|
1546 |
* then the opposite side is the constraint. |
|
1547 |
*/ |
|
1548 |
if ( ! _.isUndefined( maxWidth ) && ! _.isUndefined( maxHeight ) ) { |
|
1549 |
constraint = ( width / height > maxWidth / maxHeight ) ? 'width' : 'height'; |
|
1550 |
} else if ( _.isUndefined( maxHeight ) ) { |
|
1551 |
constraint = 'width'; |
|
1552 |
} else if ( _.isUndefined( maxWidth ) && height > maxHeight ) { |
|
1553 |
constraint = 'height'; |
|
1554 |
} |
|
1555 |
||
1556 |
// If the value of the constrained side is larger than the max, |
|
1557 |
// then scale the values. Otherwise return the originals; they fit. |
|
1558 |
if ( 'width' === constraint && width > maxWidth ) { |
|
1559 |
return { |
|
1560 |
width : maxWidth, |
|
1561 |
height: Math.round( maxWidth * height / width ) |
|
1562 |
}; |
|
1563 |
} else if ( 'height' === constraint && height > maxHeight ) { |
|
1564 |
return { |
|
1565 |
width : Math.round( maxHeight * width / height ), |
|
1566 |
height: maxHeight |
|
1567 |
}; |
|
1568 |
} else { |
|
1569 |
return { |
|
1570 |
width : width, |
|
1571 |
height: height |
|
1572 |
}; |
|
1573 |
} |
|
1574 |
}, |
|
1575 |
/** |
|
1576 |
* Truncates a string by injecting an ellipsis into the middle. |
|
1577 |
* Useful for filenames. |
|
1578 |
* |
|
1579 |
* @param {string} string |
|
1580 |
* @param {number} [length=30] |
|
1581 |
* @param {string} [replacement=…] |
|
1582 |
* @return {string} The string, unless length is greater than string.length. |
|
1583 |
*/ |
|
1584 |
truncate: function( string, length, replacement ) { |
|
1585 |
length = length || 30; |
|
1586 |
replacement = replacement || '…'; |
|
1587 |
||
1588 |
if ( string.length <= length ) { |
|
1589 |
return string; |
|
1590 |
} |
|
1591 |
||
1592 |
return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 ); |
|
1593 |
} |
|
1594 |
}); |
|
1595 |
||
1596 |
/** |
|
1597 |
* ======================================================================== |
|
1598 |
* MODELS |
|
1599 |
* ======================================================================== |
|
1600 |
*/ |
|
1601 |
/** |
|
1602 |
* wp.media.attachment |
|
1603 |
* |
|
1604 |
* @static |
|
1605 |
* @param {string} id A string used to identify a model. |
|
1606 |
* @return {wp.media.model.Attachment} |
|
1607 |
*/ |
|
1608 |
media.attachment = function( id ) { |
|
1609 |
return Attachment.get( id ); |
|
1610 |
}; |
|
1611 |
||
1612 |
/** |
|
1613 |
* A collection of all attachments that have been fetched from the server. |
|
1614 |
* |
|
1615 |
* @static |
|
1616 |
* @member {wp.media.model.Attachments} |
|
1617 |
*/ |
|
1618 |
Attachments.all = new Attachments(); |
|
1619 |
||
1620 |
/** |
|
1621 |
* wp.media.query |
|
1622 |
* |
|
1623 |
* Shorthand for creating a new Attachments Query. |
|
1624 |
* |
|
1625 |
* @param {Object} [props] |
|
1626 |
* @return {wp.media.model.Attachments} |
|
1627 |
*/ |
|
1628 |
media.query = function( props ) { |
|
1629 |
return new Attachments( null, { |
|
1630 |
props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } ) |
|
1631 |
}); |
|
1632 |
}; |
|
1633 |
||
1634 |
// Clean up. Prevents mobile browsers caching. |
|
1635 |
$(window).on('unload', function(){ |
|
1636 |
window.wp = null; |
|
1637 |
}); |
|
1638 |
||
1639 |
}(); |
|
1640 |
/******/ })() |
|
1641 |
; |