-
Notifications
You must be signed in to change notification settings - Fork 2
/
metabox.js
80 lines (66 loc) · 2.29 KB
/
metabox.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
75
76
77
78
79
80
;(function ( $, window, document, undefined ) {
$(document).ready( function() {
var $typeSelect, basicFields, productFields, galleryFields, summaryFields, playerFields, hideFields, hideStuff, showEverything, postType;
postType = twitterCardOptions.postType;
$typeSelect = $('#' + postType + '_twitter_card_twitter_card_type');
summaryFields = [ $('#' + postType + '-twitter-card-large-image') ];
basicFields = [
$('#' + postType + '_twitter_card_twitter_card_title').parent(),
$('#' + postType + '_twitter_card_twitter_card_description').parent()
];
playerFields = [
$('#' + postType + '_twitter_card_twitter_card_video_url').parent(),
$('#' + postType + '_twitter_card_twitter_card_player_url').parent(),
$('#' + postType + '_twitter_card_twitter_card_player_width').parent(),
$('#' + postType + '_twitter_card_twitter_card_player_height').parent(),
$('#' + postType + '_twitter_card_twitter_card_player_image').parent()
];
productFields = [ $('#' + postType + '-twitter-card-product-image') ];
for ( var i = 1; i <= 2; i++ ) {
productFields.push( $('#' + postType + '_twitter_card_twitter_card_label'+i).parent() );
productFields.push( $('#' + postType + '_twitter_card_twitter_card_data'+i).parent() );
}
galleryFields = [];
for ( var i = 1; i <= 4; i++ ) {
galleryFields.push( $('#' + postType + '-twitter-card-gallery-image-'+i) );
}
hideFields = function( fields ) {
$.each( fields, function( i, $v ) {
$v.hide();
} );
}
showFields = function( fields ) {
$.each( fields, function( i, $v ) {
$v.show();
} );
}
hideEverything = function() {
hideFields(galleryFields);
hideFields(summaryFields);
hideFields(basicFields);
hideFields(productFields);
hideFields(playerFields);
}
showByType = function () {
hideEverything();
var cardType = $typeSelect.val();
if ( cardType != '' ) {
showFields(basicFields);
}
if ( cardType === 'gallery' ) {
showFields(galleryFields);
}
if ( cardType === 'summary_large_image' ) {
showFields(summaryFields);
}
if ( cardType === 'product' ) {
showFields(productFields);
}
if ( cardType === 'player' ) {
showFields(playerFields);
}
}
showByType();
$typeSelect.on( 'change', showByType );
} );
})( jQuery, window, document );