-
Notifications
You must be signed in to change notification settings - Fork 0
/
default-media-uploader-view.js
74 lines (56 loc) · 1.78 KB
/
default-media-uploader-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
( function( $, _ ) {
var media = wp.media;
if ( media ) {
media.view.MediaFrame.Select.prototype.initialize = function() {
media.view.MediaFrame.prototype.initialize.apply( this, arguments );
// Fix for WooCommerce Product Gallery
this.states.forEach(function( state ) {
var library = state.get( 'library' );
if ( library ) {
library.props.set( 'uploadedTo', media.view.settings.post.id );
library.props.set( 'orderby', 'menuOrder' );
library.props.set( 'order', 'ASC' );
}
});
_.defaults( this.options, {
selection: [],
library: {
uploadedTo: media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
},
multiple: false,
state: 'library'
});
this.createSelection();
this.createStates();
this.bindHandlers();
};
media.controller.FeaturedImage.prototype.initialize = function() {
var library, comparator;
if ( ! this.get( 'library' ) ) {
this.set( 'library', media.query( {
type: 'image',
uploadedTo: media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
} ) );
}
media.controller.Library.prototype.initialize.apply( this, arguments );
library = this.get( 'library' );
comparator = library.comparator;
library.comparator = function( a, b ) {
var aInQuery = !! this.mirroring.get( a.cid ),
bInQuery = !! this.mirroring.get( b.cid );
if ( ! aInQuery && bInQuery ) {
return -1;
} else if ( aInQuery && ! bInQuery ) {
return 1;
} else {
return comparator.apply( this, arguments );
}
};
library.observe( this.get( 'selection' ) );
};
}
}(jQuery, _));