(()=> {
var __webpack_modules__=({
3343
(module){
var $=Backbone.$,
Attachment;
Attachment=Backbone.Model.extend({
sync: function(method, model, options){
if(_.isUndefined(this.id)){
return $.Deferred().rejectWith(this).promise();
}
if('read'===method){
options=options||{};
options.context=this;
options.data=_.extend(options.data||{}, {
action: 'get-attachment',
id: this.id
});
return wp.media.ajax(options);
}else if('update'===method){
if(! this.get('nonces')||! this.get('nonces').update){
return $.Deferred().rejectWith(this).promise();
}
options=options||{};
options.context=this;
options.data=_.extend(options.data||{}, {
action:  'save-attachment',
id:      this.id,
nonce:   this.get('nonces').update,
post_id: wp.media.model.settings.post.id
});
if(model.hasChanged()){
options.data.changes={};
_.each(model.changed, function(value, key){
options.data.changes[ key ]=this.get(key);
}, this);
}
return wp.media.ajax(options);
}else if('delete'===method){
options=options||{};
if(! options.wait){
this.destroyed=true;
}
options.context=this;
options.data=_.extend(options.data||{}, {
action:   'delete-post',
id:       this.id,
_wpnonce: this.get('nonces')['delete']
});
return wp.media.ajax(options).done(function(){
this.destroyed=true;
}).fail(function(){
this.destroyed=false;
});
}else{
return Backbone.Model.prototype.sync.apply(this, arguments);
}},
parse: function(resp){
if(! resp){
return resp;
}
resp.date=new Date(resp.date);
resp.modified=new Date(resp.modified);
return resp;
},
saveCompat: function(data, options){
var model=this;
if(! this.get('nonces')||! this.get('nonces').update){
return $.Deferred().rejectWith(this).promise();
}
return wp.media.post('save-attachment-compat', _.defaults({
id:      this.id,
nonce:   this.get('nonces').update,
post_id: wp.media.model.settings.post.id
}, data)).done(function(resp, status, xhr){
model.set(model.parse(resp, xhr), options);
});
}},{
create: function(attrs){
var Attachments=wp.media.model.Attachments;
return Attachments.all.push(attrs);
},
get: _.memoize(function(id, attachment){
var Attachments=wp.media.model.Attachments;
return Attachments.all.push(attachment||{ id: id });
})
});
module.exports=Attachment;
},
8266
(module){
var Attachments=Backbone.Collection.extend({
model: wp.media.model.Attachment,
initialize: function(models, options){
options=options||{};
this.props=new Backbone.Model();
this.filters=options.filters||{};
this.props.on('change', this._changeFilteredProps, this);
this.props.on('change:order',   this._changeOrder,   this);
this.props.on('change:orderby', this._changeOrderby, this);
this.props.on('change:query',   this._changeQuery,   this);
this.props.set(_.defaults(options.props||{}));
if(options.observe){
this.observe(options.observe);
}},
_changeOrder: function(){
if(this.comparator){
this.sort();
}},
_changeOrderby: function(model, orderby){
if(this.comparator&&this.comparator!==Attachments.comparator){
return;
}
if(orderby&&'post__in'!==orderby){
this.comparator=Attachments.comparator;
}else{
delete this.comparator;
}},
_changeQuery: function(model, query){
if(query){
this.props.on('change', this._requery, this);
this._requery();
}else{
this.props.off('change', this._requery, this);
}},
_changeFilteredProps: function(model){
if(this.props.get('query')){
return;
}
var changed=_.chain(model.changed).map(function(t, prop){
var filter=Attachments.filters[ prop ],
term=model.get(prop);
if(! filter){
return;
}
if(term&&! this.filters[ prop ]){
this.filters[ prop ]=filter;
}else if(! term&&this.filters[ prop ]===filter){
delete this.filters[ prop ];
}else{
return;
}
return true;
}, this).any().value();
if(! changed){
return;
}
if(! this._source){
this._source=new Attachments(this.models);
}
this.reset(this._source.filter(this.validator, this));
},
validateDestroyed: false,
validator: function(attachment){
if(! this.validateDestroyed&&attachment.destroyed){
return false;
}
return _.all(this.filters, function(filter){
return !! filter.call(this, attachment);
}, this);
},
validate: function(attachment, options){
var valid=this.validator(attachment),
hasAttachment = !! this.get(attachment.cid);
if(! valid&&hasAttachment){
this.remove(attachment, options);
}else if(valid&&! hasAttachment){
this.add(attachment, options);
}
return this;
},
validateAll: function(attachments, options){
options=options||{};
_.each(attachments.models, function(attachment){
this.validate(attachment, { silent: true });
}, this);
if(! options.silent){
this.trigger('reset', this, options);
}
return this;
},
observe: function(attachments){
this.observers=this.observers||[];
this.observers.push(attachments);
attachments.on('add change remove', this._validateHandler, this);
attachments.on('add', this._addToTotalAttachments, this);
attachments.on('remove', this._removeFromTotalAttachments, this);
attachments.on('reset', this._validateAllHandler, this);
this.validateAll(attachments);
return this;
},
unobserve: function(attachments){
if(attachments){
attachments.off(null, null, this);
this.observers=_.without(this.observers, attachments);
}else{
_.each(this.observers, function(attachments){
attachments.off(null, null, this);
}, this);
delete this.observers;
}
return this;
},
_removeFromTotalAttachments: function(){
if(this.mirroring){
this.mirroring.totalAttachments=this.mirroring.totalAttachments - 1;
}},
_addToTotalAttachments: function(){
if(this.mirroring){
this.mirroring.totalAttachments=this.mirroring.totalAttachments + 1;
}},
_validateHandler: function(attachment, attachments, options){
options=attachments===this.mirroring ? options:{
silent: options&&options.silent
};
return this.validate(attachment, options);
},
_validateAllHandler: function(attachments, options){
return this.validateAll(attachments, options);
},
mirror: function(attachments){
if(this.mirroring&&this.mirroring===attachments){
return this;
}
this.unmirror();
this.mirroring=attachments;
this.reset([], { silent: true });
this.observe(attachments);
this.trigger('attachments:received', this);
return this;
},
unmirror: function(){
if(! this.mirroring){
return;
}
this.unobserve(this.mirroring);
delete this.mirroring;
},
more: function(options){
var deferred=jQuery.Deferred(),
mirroring=this.mirroring,
attachments=this;
if(! mirroring||! mirroring.more){
return deferred.resolveWith(this).promise();
}
mirroring.more(options).done(function(){
if(this===attachments.mirroring){
deferred.resolveWith(this);
}
attachments.trigger('attachments:received', this);
});
return deferred.promise();
},
hasMore: function(){
return this.mirroring ? this.mirroring.hasMore():false;
},
totalAttachments: 0,
getTotalAttachments: function(){
return this.mirroring ? this.mirroring.totalAttachments:0;
},
parse: function(response, xhr){
if(! _.isArray(response)){
response=[response];
}
return _.map(response, function(attrs){
var id, attachment, newAttributes;
if(attrs instanceof Backbone.Model){
id=attrs.get('id');
attrs=attrs.attributes;
}else{
id=attrs.id;
}
attachment=wp.media.model.Attachment.get(id);
newAttributes=attachment.parse(attrs, xhr);
if(! _.isEqual(attachment.attributes, newAttributes)){
attachment.set(newAttributes);
}
return attachment;
});
},
_requery: function(){
var props;
if(this.props.get('query')){
props=this.props.toJSON();
this.mirror(wp.media.model.Query.get(props));
}},
saveMenuOrder: function(){
if('menuOrder'!==this.props.get('orderby')){
return;
}
var attachments=this.chain().filter(function(attachment){
return ! _.isUndefined(attachment.id);
}).map(function(attachment, index){
index=index + 1;
attachment.set('menuOrder', index);
return [ attachment.id, index ];
}).object().value();
if(_.isEmpty(attachments)){
return;
}
return wp.media.post('save-attachment-order', {
nonce:       wp.media.model.settings.post.nonce,
post_id:     wp.media.model.settings.post.id,
attachments: attachments
});
}},{
comparator: function(a, b, options){
var key=this.props.get('orderby'),
order=this.props.get('order')||'DESC',
ac=a.cid,
bc=b.cid;
a=a.get(key);
b=b.get(key);
if('date'===key||'modified'===key){
a=a||new Date();
b=b||new Date();
}
if(options&&options.ties){
ac=bc=null;
}
return('DESC'===order) ? wp.media.compare(a, b, ac, bc):wp.media.compare(b, a, bc, ac);
},
filters: {
search: function(attachment){
if(! this.props.get('search')){
return true;
}
return _.any(['title','filename','description','caption','name'], function(key){
var value=attachment.get(key);
return value&&-1!==value.search(this.props.get('search'));
}, this);
},
type: function(attachment){
var type=this.props.get('type'), atts=attachment.toJSON(), mime, found;
if(! type||(_.isArray(type)&&! type.length)){
return true;
}
mime=atts.mime||(atts.file&&atts.file.type)||'';
if(_.isArray(type)){
found=_.find(type, function (t){
return -1!==mime.indexOf(t);
});
}else{
found=-1!==mime.indexOf(type);
}
return found;
},
uploadedTo: function(attachment){
var uploadedTo=this.props.get('uploadedTo');
if(_.isUndefined(uploadedTo)){
return true;
}
return uploadedTo===attachment.get('uploadedTo');
},
status: function(attachment){
var status=this.props.get('status');
if(_.isUndefined(status)){
return true;
}
return status===attachment.get('status');
}}
});
module.exports=Attachments;
},
9104
(module){
var PostImage=Backbone.Model.extend({
initialize: function(attributes){
var Attachment=wp.media.model.Attachment;
this.attachment=false;
if(attributes.attachment_id){
this.attachment=Attachment.get(attributes.attachment_id);
if(this.attachment.get('url')){
this.dfd=jQuery.Deferred();
this.dfd.resolve();
}else{
this.dfd=this.attachment.fetch();
}
this.bindAttachmentListeners();
}
this.on('change:link', this.updateLinkUrl, this);
this.on('change:size', this.updateSize, this);
this.setLinkTypeFromUrl();
this.setAspectRatio();
this.set('originalUrl', attributes.url);
},
bindAttachmentListeners: function(){
this.listenTo(this.attachment, 'sync', this.setLinkTypeFromUrl);
this.listenTo(this.attachment, 'sync', this.setAspectRatio);
this.listenTo(this.attachment, 'change', this.updateSize);
},
changeAttachment: function(attachment, props){
this.stopListening(this.attachment);
this.attachment=attachment;
this.bindAttachmentListeners();
this.set('attachment_id', this.attachment.get('id'));
this.set('caption', this.attachment.get('caption'));
this.set('alt', this.attachment.get('alt'));
this.set('size', props.get('size'));
this.set('align', props.get('align'));
this.set('link', props.get('link'));
this.updateLinkUrl();
this.updateSize();
},
setLinkTypeFromUrl: function(){
var linkUrl=this.get('linkUrl'),
type;
if(! linkUrl){
this.set('link', 'none');
return;
}
type='custom';
if(this.attachment){
if(this.attachment.get('url')===linkUrl){
type='file';
}else if(this.attachment.get('link')===linkUrl){
type='post';
}}else{
if(this.get('url')===linkUrl){
type='file';
}}
this.set('link', type);
},
updateLinkUrl: function(){
var link=this.get('link'),
url;
switch(link){
case 'file':
if(this.attachment){
url=this.attachment.get('url');
}else{
url=this.get('url');
}
this.set('linkUrl', url);
break;
case 'post':
this.set('linkUrl', this.attachment.get('link'));
break;
case 'none':
this.set('linkUrl', '');
break;
}},
updateSize: function(){
var size;
if(! this.attachment){
return;
}
if(this.get('size')==='custom'){
this.set('width', this.get('customWidth'));
this.set('height', this.get('customHeight'));
this.set('url', this.get('originalUrl'));
return;
}
size=this.attachment.get('sizes')[ this.get('size') ];
if(! size){
return;
}
this.set('url', size.url);
this.set('width', size.width);
this.set('height', size.height);
},
setAspectRatio: function(){
var full;
if(this.attachment&&this.attachment.get('sizes')){
full=this.attachment.get('sizes').full;
if(full){
this.set('aspectRatio', full.width / full.height);
return;
}}
this.set('aspectRatio', this.get('customWidth') / this.get('customHeight'));
}});
module.exports=PostImage;
},
1288
(module){
var Attachments=wp.media.model.Attachments,
Query;
Query=Attachments.extend({
initialize: function(models, options){
var allowed;
options=options||{};
Attachments.prototype.initialize.apply(this, arguments);
this.args=options.args;
this._hasMore=true;
this.created=new Date();
this.filters.order=function(attachment){
var orderby=this.props.get('orderby'),
order=this.props.get('order');
if(! this.comparator){
return true;
}
if(this.length){
return 1!==this.comparator(attachment, this.last(), { ties: true });
}else if('DESC'===order&&('date'===orderby||'modified'===orderby)){
return attachment.get(orderby) >=this.created;
}else if('ASC'===order&&'menuOrder'===orderby){
return attachment.get(orderby)===0;
}
return false;
};
allowed=[ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
if(wp.Uploader&&_(this.args).chain().keys().difference(allowed).isEmpty().value()){
this.observe(wp.Uploader.queue);
}},
hasMore: function(){
return this._hasMore;
},
more: function(options){
var query=this;
if(this._more&&'pending'===this._more.state()){
return this._more;
}
if(! this.hasMore()){
return jQuery.Deferred().resolveWith(this).promise();
}
options=options||{};
options.remove=false;
return this._more=this.fetch(options).done(function(response){
if(_.isEmpty(response)||-1===query.args.posts_per_page||response.length < query.args.posts_per_page){
query._hasMore=false;
}});
},
sync: function(method, model, options){
var args, fallback;
if('read'===method){
options=options||{};
options.context=this;
options.data=_.extend(options.data||{}, {
action:  'query-attachments',
post_id: wp.media.model.settings.post.id
});
args=_.clone(this.args);
if(-1!==args.posts_per_page){
args.paged=Math.round(this.length / args.posts_per_page) + 1;
}
options.data.query=args;
return wp.media.ajax(options);
}else{
fallback=Attachments.prototype.sync ? Attachments.prototype:Backbone;
return fallback.sync.apply(this, arguments);
}}
}, {
defaultProps: {
orderby: 'date',
order:   'DESC'
},
defaultArgs: {
posts_per_page: 80
},
orderby: {
allowed:  [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],
valuemap: {
'id':         'ID',
'uploadedTo': 'parent',
'menuOrder':  'menu_order ID'
}},
propmap: {
'search':		's',
'type':			'post_mime_type',
'perPage':		'posts_per_page',
'menuOrder':	'menu_order',
'uploadedTo':	'post_parent',
'status':		'post_status',
'include':		'post__in',
'exclude':		'post__not_in',
'author':		'author'
},
get: (function(){
var queries=[];
return function(props, options){
var args={},
orderby=Query.orderby,
defaults=Query.defaultProps,
query;
delete props.query;
_.defaults(props, defaults);
props.order=props.order.toUpperCase();
if('DESC'!==props.order&&'ASC'!==props.order){
props.order=defaults.order.toUpperCase();
}
if(! _.contains(orderby.allowed, props.orderby)){
props.orderby=defaults.orderby;
}
_.each([ 'include', 'exclude' ], function(prop){
if(props[ prop ]&&! _.isArray(props[ prop ])){
props[ prop ]=[ props[ prop ] ];
}});
_.each(props, function(value, prop){
if(_.isNull(value)){
return;
}
args[ Query.propmap[ prop ]||prop ]=value;
});
_.defaults(args, Query.defaultArgs);
args.orderby=orderby.valuemap[ props.orderby ]||props.orderby;
queries=[];
if(! query){
query=new Query([], _.extend(options||{}, {
props: props,
args:  args
}));
queries.push(query);
}
return query;
};}())
});
module.exports=Query;
},
4134
(module){
var Attachments=wp.media.model.Attachments,
Selection;
Selection=Attachments.extend({
initialize: function(models, options){
Attachments.prototype.initialize.apply(this, arguments);
this.multiple=options&&options.multiple;
this.on('add remove reset', _.bind(this.single, this, false));
},
add: function(models, options){
if(! this.multiple){
this.remove(this.models);
}
return Attachments.prototype.add.call(this, models, options);
},
single: function(model){
var previous=this._single;
if(model){
this._single=model;
}
if(this._single&&! this.get(this._single.cid)){
delete this._single;
}
this._single=this._single||this.last();
if(this._single!==previous){
if(previous){
previous.trigger('selection:unsingle', previous, this);
if(! this.get(previous.cid)){
this.trigger('selection:unsingle', previous, this);
}}
if(this._single){
this._single.trigger('selection:single', this._single, this);
}}
return this._single;
}});
module.exports=Selection;
}
});
var __webpack_module_cache__={};
function __webpack_require__(moduleId){
var cachedModule=__webpack_module_cache__[moduleId];
if(cachedModule!==undefined){
return cachedModule.exports;
}
var module=__webpack_module_cache__[moduleId]={
exports: {}
};
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
return module.exports;
}
var Attachment, Attachments, l10n, media;
window.wp=window.wp||{};
media=wp.media=function(attributes){
var MediaFrame=media.view.MediaFrame,
frame;
if(! MediaFrame){
return;
}
attributes=_.defaults(attributes||{}, {
frame: 'select'
});
if('select'===attributes.frame&&MediaFrame.Select){
frame=new MediaFrame.Select(attributes);
}else if('post'===attributes.frame&&MediaFrame.Post){
frame=new MediaFrame.Post(attributes);
}else if('manage'===attributes.frame&&MediaFrame.Manage){
frame=new MediaFrame.Manage(attributes);
}else if('image'===attributes.frame&&MediaFrame.ImageDetails){
frame=new MediaFrame.ImageDetails(attributes);
}else if('audio'===attributes.frame&&MediaFrame.AudioDetails){
frame=new MediaFrame.AudioDetails(attributes);
}else if('video'===attributes.frame&&MediaFrame.VideoDetails){
frame=new MediaFrame.VideoDetails(attributes);
}else if('edit-attachments'===attributes.frame&&MediaFrame.EditAttachments){
frame=new MediaFrame.EditAttachments(attributes);
}
delete attributes.frame;
media.frame=frame;
return frame;
};
_.extend(media, { model: {}, view: {}, controller: {}, frames: {}});
l10n=media.model.l10n=window._wpMediaModelsL10n||{};
media.model.settings=l10n.settings||{};
delete l10n.settings;
Attachment=media.model.Attachment=__webpack_require__(3343);
Attachments=media.model.Attachments=__webpack_require__(8266);
media.model.Query=__webpack_require__(1288);
media.model.PostImage=__webpack_require__(9104);
media.model.Selection=__webpack_require__(4134);
media.compare=function(a, b, ac, bc){
if(_.isEqual(a, b)){
return ac===bc ? 0:(ac > bc ? -1:1);
}else{
return a > b ? -1:1;
}};
_.extend(media, {
template: wp.template,
post: wp.ajax.post,
ajax: wp.ajax.send,
fit: function(dimensions){
var width=dimensions.width,
height=dimensions.height,
maxWidth=dimensions.maxWidth,
maxHeight=dimensions.maxHeight,
constraint;
if(! _.isUndefined(maxWidth)&&! _.isUndefined(maxHeight)){
constraint=(width / height > maxWidth / maxHeight) ? 'width':'height';
}else if(_.isUndefined(maxHeight)){
constraint='width';
}else if(_.isUndefined(maxWidth)&&height > maxHeight){
constraint='height';
}
if('width'===constraint&&width > maxWidth){
return {
width:maxWidth,
height: Math.round(maxWidth * height / width)
};}else if('height'===constraint&&height > maxHeight){
return {
width:Math.round(maxHeight * width / height),
height: maxHeight
};}else{
return {
width:width,
height: height
};}},
truncate: function(string, length, replacement){
length=length||30;
replacement=replacement||'&hellip;';
if(string.length <=length){
return string;
}
return string.substr(0, length / 2) + replacement + string.substr(-1 * length / 2);
}});
media.attachment=function(id){
return Attachment.get(id);
};
Attachments.all=new Attachments();
media.query=function(props){
return new Attachments(null, {
props: _.extend(_.defaults(props||{}, { orderby: 'date' }), { query: true })
});
};
})()
;