| 1 |
(function($){ |
| 2 |
|
| 3 |
/*---------------------------------------------------------------------- |
| 4 |
* |
| 5 |
* vars |
| 6 |
* |
| 7 |
*---------------------------------------------------------------------*/ |
| 8 |
var shift_is_down = false; |
| 9 |
var data = { |
| 10 |
action : 'get_input_metabox_ids', |
| 11 |
post_id : false, |
| 12 |
page_template : false, |
| 13 |
page_parent : false, |
| 14 |
page_type : false, |
| 15 |
page : false, |
| 16 |
post : false, |
| 17 |
post_category : false, |
| 18 |
post_format : false, |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
/*---------------------------------------------------------------------- |
| 23 |
* |
| 24 |
* Exists |
| 25 |
* |
| 26 |
*---------------------------------------------------------------------*/ |
| 27 |
|
| 28 |
$.fn.exists = function() |
| 29 |
{ |
| 30 |
return $(this).length>0; |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
/*---------------------------------------------------------------------- |
| 35 |
* |
| 36 |
* Document Ready |
| 37 |
* |
| 38 |
*---------------------------------------------------------------------*/ |
| 39 |
|
| 40 |
$(document).ready(function(){ |
| 41 |
|
| 42 |
// vars |
| 43 |
var post_id = $('input#post_ID').val(); |
| 44 |
|
| 45 |
// show metaboxes for this post |
| 46 |
data = { |
| 47 |
action : 'get_input_metabox_ids', |
| 48 |
post_id : post_id, |
| 49 |
page_template : false, |
| 50 |
page_parent : false, |
| 51 |
page_type : false, |
| 52 |
page : post_id, |
| 53 |
post : post_id, |
| 54 |
post_category : false, |
| 55 |
post_format : false, |
| 56 |
taxonomy : false |
| 57 |
}; |
| 58 |
|
| 59 |
// update fields from ajax response |
| 60 |
function update_fields() |
| 61 |
{ |
| 62 |
$.ajax({ |
| 63 |
url: ajaxurl, |
| 64 |
data: data, |
| 65 |
type: 'post', |
| 66 |
dataType: 'json', |
| 67 |
success: function(result){ |
| 68 |
|
| 69 |
// hide all metaboxes |
| 70 |
$('#poststuff .acf_postbox').hide(); |
| 71 |
$('#adv-settings .acf_hide_label').hide(); |
| 72 |
|
| 73 |
// show the new postboxes |
| 74 |
$.each(result, function(k, v) { |
| 75 |
$('#poststuff #acf_' + v).show(); |
| 76 |
$('#adv-settings .acf_hide_label[for="acf_' + v + '-hide"]').show(); |
| 77 |
}); |
| 78 |
|
| 79 |
// load style |
| 80 |
$.ajax({ |
| 81 |
url: ajaxurl, |
| 82 |
data: { |
| 83 |
action : 'get_input_style', |
| 84 |
acf_id : result[0] |
| 85 |
}, |
| 86 |
type: 'post', |
| 87 |
dataType: 'html', |
| 88 |
success: function(result){ |
| 89 |
|
| 90 |
$('#acf_style').html(result); |
| 91 |
|
| 92 |
} |
| 93 |
}); |
| 94 |
|
| 95 |
} |
| 96 |
}); |
| 97 |
} |
| 98 |
//update_fields(); |
| 99 |
|
| 100 |
// hide acf stuff |
| 101 |
/*$('#poststuff .acf_postbox').hide(); |
| 102 |
$('#adv-settings .acf_hide_label').hide(); |
| 103 |
|
| 104 |
// show acf? |
| 105 |
$('#poststuff .acf_postbox').each(function(){ |
| 106 |
|
| 107 |
// vars |
| 108 |
var show = $(this).children('.inside').children('.options').attr('data-show'); |
| 109 |
var id = $(this).attr('id').replace('acf_', ''); |
| 110 |
|
| 111 |
if(show == 'true') |
| 112 |
{ |
| 113 |
$(this).show(); |
| 114 |
$('#adv-settings .acf_hide_label[for="acf_' + id + '-hide"]').show(); |
| 115 |
} |
| 116 |
|
| 117 |
});*/ |
| 118 |
|
| 119 |
|
| 120 |
// on save, delete all unused metaboxes |
| 121 |
$('input#publish').click(function(){ |
| 122 |
|
| 123 |
// do validation? |
| 124 |
$('#post-body .acf_postbox:hidden').remove(); |
| 125 |
|
| 126 |
return true; |
| 127 |
}); |
| 128 |
|
| 129 |
/*-------------------------------------------------------------------------------------- |
| 130 |
* |
| 131 |
* Change |
| 132 |
* |
| 133 |
*-------------------------------------------------------------------------------------*/ |
| 134 |
|
| 135 |
$('#page_template').change(function(){ |
| 136 |
|
| 137 |
data.page_template = $(this).val(); |
| 138 |
update_fields(); |
| 139 |
|
| 140 |
}); |
| 141 |
|
| 142 |
$('#parent_id').change(function(){ |
| 143 |
|
| 144 |
var page_parent = $(this).val(); |
| 145 |
|
| 146 |
if($(this).val() != "") |
| 147 |
{ |
| 148 |
data.page_type = 'child'; |
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
data.page_type = 'parent'; |
| 153 |
} |
| 154 |
|
| 155 |
update_fields(); |
| 156 |
|
| 157 |
}); |
| 158 |
|
| 159 |
$('#categorychecklist input[type="checkbox"]').change(function(){ |
| 160 |
|
| 161 |
data.post_category = ['0']; |
| 162 |
|
| 163 |
$('#categorychecklist :checked').each(function(){ |
| 164 |
data.post_category.push($(this).val()) |
| 165 |
}); |
| 166 |
|
| 167 |
//console.log(data.post_category); |
| 168 |
|
| 169 |
update_fields(); |
| 170 |
|
| 171 |
}); |
| 172 |
|
| 173 |
|
| 174 |
$('#post-formats-select input[type="radio"]').change(function(){ |
| 175 |
|
| 176 |
data.post_format = $(this).val(); |
| 177 |
update_fields(); |
| 178 |
|
| 179 |
}); |
| 180 |
|
| 181 |
// taxonomy |
| 182 |
$('div[id*="taxonomy-"] input[type="checkbox"]').change(function(){ |
| 183 |
|
| 184 |
data.taxonomy = ['0']; |
| 185 |
|
| 186 |
$(this).closest('ul').find('input[type="checkbox"]:checked').each(function(){ |
| 187 |
data.taxonomy.push($(this).val()) |
| 188 |
}); |
| 189 |
|
| 190 |
update_fields(); |
| 191 |
|
| 192 |
}); |
| 193 |
|
| 194 |
}); |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
})(jQuery); |