language selector working
This commit is contained in:
parent
1fa6c57221
commit
6622b88dfe
@ -48,6 +48,8 @@ class WhatDidTheySayAdmin {
|
||||
add_filter('the_media_transcript', array(&$this, 'the_media_transcript'));
|
||||
add_filter('the_language_name', array(&$this, 'the_language_name'));
|
||||
|
||||
add_filter('wp_footer', array(&$this, 'wp_footer'));
|
||||
|
||||
if (isset($_REQUEST['wdts'])) {
|
||||
if (isset($_REQUEST['wdts']['_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['wdts']['_nonce'], 'what-did-they-say')) {
|
||||
@ -67,6 +69,24 @@ class WhatDidTheySayAdmin {
|
||||
return '<h3>' . $language . '</h3>';
|
||||
}
|
||||
|
||||
function wp_footer() { ?>
|
||||
<script type="text/javascript">
|
||||
$$('.transcript-bundle').each(function(d) {
|
||||
var select = d.select("select");
|
||||
if (select.length == 1) {
|
||||
select = select[0];
|
||||
var toggle_transcripts = function() {
|
||||
d.select(".transcript-holder").each(function(div) {
|
||||
div.hasClassName($F(select)) ? div.show() : div.hide();
|
||||
});
|
||||
};
|
||||
Event.observe(select, 'change', toggle_transcripts);
|
||||
Event.observe(window, 'load', toggle_transcripts)
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php }
|
||||
|
||||
/**
|
||||
* user_has_cap filter.
|
||||
*/
|
||||
|
@ -63,4 +63,53 @@ function the_language_name($language = null) {
|
||||
echo $name;
|
||||
}
|
||||
|
||||
function the_media_transcript_select_and_display($dropdown_message = null, $single_language_message = null) {
|
||||
global $post, $what_did_they_say;
|
||||
|
||||
if (is_null($dropdown_message)) { $dropdown_message = __('Select a language:', 'what-did-they-say'); }
|
||||
if (is_null($single_language_message)) { $single_language_message = __('%s transcript:', 'what-did-they-say'); }
|
||||
|
||||
$transcripts = array();
|
||||
foreach ($what_did_they_say->get_transcripts($post->ID) as $code => $transcript) {
|
||||
$transcript = trim($transcript);
|
||||
if (!empty($transcript)) {
|
||||
$transcripts[$code] = $transcript;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($transcripts) > 0) {
|
||||
$default_language = $what_did_they_say->get_default_language();
|
||||
|
||||
$output = array();
|
||||
$output[] = '<div class="transcript-bundle">';
|
||||
|
||||
if (count($transcripts) == 1) {
|
||||
list($code, $transcript) = each($transcripts);
|
||||
$output[] = apply_filters('the_language_name', get_the_language_name($code));
|
||||
$output[] = apply_filters('the_media_transcript', $transcript);
|
||||
} else {
|
||||
$output[] = $dropdown_message;
|
||||
$output[] = '<select>';
|
||||
foreach($transcripts as $code => $transcript) {
|
||||
$output[] = '<option value="' . $code . '"' . (($code == $default_language) ? ' selected="selected"' : '') . '>'
|
||||
. get_the_language_name($code)
|
||||
. '</option>';
|
||||
}
|
||||
$output[] = '</select>';
|
||||
foreach ($transcripts as $code => $transcript) {
|
||||
$language_name = apply_filters('the_language_name', get_the_language_name($code));
|
||||
$transcript = apply_filters('the_media_transcript', $transcript);
|
||||
|
||||
$output[] = '<div '
|
||||
. (($code == $default_language) ? 'style="display:none"' : '')
|
||||
. ' class="transcript-holder ' . $code . '">' . $language_name . $transcript . '</div>';
|
||||
}
|
||||
}
|
||||
$output[] = '</div>';
|
||||
|
||||
$output = apply_filters('the_media_transcript_select_and_display', implode("\n", $output));
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user