1
|
|
|
var pollux = { |
2
|
|
|
media: { |
3
|
|
|
featured: {}, |
4
|
|
|
}, |
5
|
|
|
metabox: {}, |
6
|
|
|
}; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @return void |
10
|
|
|
*/ |
11
|
|
|
pollux.media.featured.init = function() |
12
|
|
|
{ |
13
|
|
|
jQuery( '#postimagediv' ) |
14
|
|
|
.on( 'click', '#pollux-set-featured', function( ev ) { |
15
|
|
|
ev.preventDefault(); |
16
|
|
|
wp.media.view.settings.post.featuredImageId = Math.round( jQuery( '#featured' ).val() ); |
|
|
|
|
17
|
|
|
pollux.media.featured.frame = wp.media.featuredImage.frame; |
18
|
|
|
pollux.media.featured.frame().open(); |
19
|
|
|
}) |
20
|
|
|
.on( 'click', '#pollux-remove-featured', function( ev ) { |
21
|
|
|
ev.preventDefault(); |
22
|
|
|
pollux.media.featured.frame = wp.media.featuredImage.frame; |
|
|
|
|
23
|
|
|
pollux.media.featured.set(-1); |
24
|
|
|
}); |
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
pollux.media.featured.select = function() |
31
|
|
|
{ |
32
|
|
|
if( !wp.media.view.settings.post.featuredImageId )return; |
|
|
|
|
33
|
|
|
var selection = this.get( 'selection' ).single(); |
34
|
|
|
pollux.media.featured.set( selection ? selection.id : -1 ); |
35
|
|
|
}; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
pollux.media.featured.set = function( id ) |
41
|
|
|
{ |
42
|
|
|
wp.media.view.settings.post.featuredImageId = Math.round( id ); |
|
|
|
|
43
|
|
|
wp.media.post( 'pollux/archives/featured/html', { |
44
|
|
|
_wpnonce: jQuery( '#_wpnonce' ).val(), |
45
|
|
|
post_type: jQuery( '#archive-type' ).val(), |
46
|
|
|
thumbnail_id: id, |
47
|
|
|
}).done( function( html ) { |
48
|
|
|
jQuery( '.inside', '#postimagediv' ).html( html ); |
49
|
|
|
}); |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
pollux.metabox.hasValue = function( el ) |
56
|
|
|
{ |
57
|
|
|
if( el.type === 'checkbox' ) { |
58
|
|
|
return el.checked === true; |
59
|
|
|
} |
60
|
|
|
return el.value !== ''; |
61
|
|
|
}; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
pollux.metabox.init = function() |
67
|
|
|
{ |
68
|
|
|
var depends = document.querySelectorAll( '.rwmb-input [data-depends]' ); |
69
|
|
|
[].forEach.call( depends, function( el ) { |
70
|
|
|
var dependency = pollux.metabox.setVisibility( el ); |
71
|
|
|
var event = dependency.type === 'checkbox' ? 'change' : 'keyup'; |
72
|
|
|
dependency.addEventListener( event, function() { |
73
|
|
|
pollux.metabox.onChangeValue( el ); |
74
|
|
|
}, false ); |
75
|
|
|
}); |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
pollux.metabox.onChangeValue = function( el ) |
82
|
|
|
{ |
83
|
|
|
pollux.metabox.setVisibility( el ); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return element |
88
|
|
|
*/ |
89
|
|
|
pollux.metabox.setVisibility = function( el ) |
90
|
|
|
{ |
91
|
|
|
var dependency = document.getElementById( el.getAttribute( 'data-depends' )); |
92
|
|
|
var field = el.closest( '.rwmb-field' ); |
93
|
|
|
if( pollux.metabox.hasValue( dependency )) { |
94
|
|
|
field.classList.remove( 'hidden' ); |
95
|
|
|
} |
96
|
|
|
else { |
97
|
|
|
field.classList.add( 'hidden' ); |
98
|
|
|
} |
99
|
|
|
return dependency; |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
jQuery(function() { |
103
|
|
|
pollux.media.featured.init(); |
104
|
|
|
pollux.metabox.init(); |
105
|
|
|
}); |
106
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.