totally rewrite how transcripts are displayed

This commit is contained in:
John Bintz 2009-10-04 18:54:22 -04:00
parent 693a01d7e6
commit 4a70567486
4 changed files with 87 additions and 40 deletions

View File

@ -71,7 +71,7 @@ class WhatDidTheySayAdmin {
add_filter('the_media_transcript', array(&$this, 'the_media_transcript'), 10, 2);
add_filter('the_language_name', array(&$this, 'the_language_name'), 10, 2);
add_filter('the_matching_transcript_excerpts', array(&$this, 'the_matching_transcript_excerpts'), 10, 3);
add_filter('the_multiple_transcript_language_name', array(&$this, 'the_multiple_transcript_language_name'), 10, 3);
add_filter('the_transcript_language_name', array(&$this, 'the_transcript_language_name'), 10, 3);
add_filter('the_transcript_format_string', array(&$this, 'the_transcript_format_string'), 10);
add_filter('template_redirect', array(&$this, 'template_redirect'));
@ -109,6 +109,7 @@ class WhatDidTheySayAdmin {
function include_editor_javascript() {
$nonce = wp_create_nonce('what-did-they-say');
$language_options = new WDTSLanguageOptions();
include(dirname(__FILE__) . '/partials/_editor-script.inc');
}
@ -258,27 +259,12 @@ class WhatDidTheySayAdmin {
/**
* Handle showing the header above a bundle of live transcripts.
*/
function the_multiple_transcript_language_name($language_format, $transcripts, $content) {
if (count($transcripts) == 1) {
$content = get_the_language_name(reset(array_keys($transcripts)));
} else {
$dropdown = array();
$dropdown[] = '<select>';
foreach ($transcripts as $code => $transcript) {
$dropdown[] = '<option value="' . $code . '"' . (($code == $default_language) ? ' selected="selected"' : '') . '>'
. get_the_language_name($code)
. '</option>';
}
$dropdown[] = '</select>';
$content = implode("", $dropdown);
}
function the_transcript_language_name($language_format, $code, $content) {
if (is_null($language_format)) { $language_format = apply_filters('the_transcript_format_string', ''); }
return '<h3 class="wdts-transcript-language">' . sprintf($language_format, $content) . '</h3>';
$language_options = new WDTSLanguageOptions();
return array($language_format, $code, '<h3 class="wdts-transcript-language">' . sprintf($language_format, $language_options->get_language_name($code)) . '</h3>');
}
/**

View File

@ -12,8 +12,9 @@
'dialog_name': '<?php _e('Enter the character name:', 'what-did-they-say') ?>',
'dialog_direction': '<?php _e('Enter the direction in which the character is speaking:', 'what-did-they-say') ?>',
'dialog_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>',
'transcripts_updated': '<?php _e('Transcripts updated.', 'what-did-they-say') ?>',
'transcripts_failure': '<?php _e('Transcript update failure!', 'what-did-they-say') ?>'
'transcripts_updated': '<?php _e('Transcripts updated. Reload to see them on page.', 'what-did-they-say') ?>',
'transcripts_failure': '<?php _e('Transcript update failure!', 'what-did-they-say') ?>',
'bundle_header': '<?php echo apply_filters('the_transcript_format_string', '') ?>'
};
WhatDidTheySay.button_labels = {
@ -26,4 +27,14 @@
};
WhatDidTheySay.can_approve = <?php echo current_user_can('approve_transcriptions') ? "true" : "false" ?>;
<?php
$language_output = array();
foreach ($language_options->get_languages() as $code => $info) {
$language_output[] = "${code}: '" . addslashes($info['name']) . "'";
}
?>
WhatDidTheySay.languages = { <?php echo implode(",", $language_output) ?> };
WhatDidTheySay.default_language = '<?php echo $language_options->get_default_language() ?>';
</script>

View File

@ -1,13 +1,65 @@
$$('.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();
});
WhatDidTheySay.get_transcript_language_code = function(transcript) {
for (code in WhatDidTheySay.languages) {
if (WhatDidTheySay.languages.hasOwnProperty(code)) {
if (transcript.hasClassName(code)) {
return code;
}
}
}
return false
};
Event.observe(select, 'change', toggle_transcripts);
Event.observe(window, 'load', toggle_transcripts)
WhatDidTheySay.build_bundle_header = function(bundle) {
bundle.select('h3').each(function(h) { h.parentNode.removeChild(h); });
var new_header = new Element('h3', { 'className': 'wdts-transcript-language' });
var transcript_holders = bundle.select('.transcript-holder');
transcript_holders.invoke('show');
var show_only_this_code = function(code) {
transcript_holders.each(function(t) {
if (t.hasClassName(code)) {
t.show();
} else {
t.hide();
}
});
};
if (transcript_holders.length > 1) {
var select = new Element('select');
show_only_this_code(WhatDidTheySay.default_language);
transcript_holders.each(function(t) {
var code = WhatDidTheySay.get_transcript_language_code(t);
if (code) {
var option = new Element('option', { 'value': code }).update(WhatDidTheySay.languages[code]);
if (code == WhatDidTheySay.default_language) { option.selected = true; }
select.insert(option);
}
});
select.observe('change', function(e) {
var code = select.options[select.selectedIndex].value;
show_only_this_code(code);
});
new_header.update(WhatDidTheySay.messages.bundle_header.replace('%s', '<span />'));
new_header.select('span')[0].insert(select);
} else {
var code = WhatDidTheySay.get_transcript_language_code(transcript_holders[0]);
if (code) {
new_header.update(WhatDidTheySay.messages.bundle_header.replace('%s', WhatDidTheySay.languages[code]));
}
}
bundle.insert({ top: new_header })
}
$$('.transcript-bundle').each(function(d) {
WhatDidTheySay.build_bundle_header(d);
});

View File

@ -148,14 +148,12 @@ function transcripts_display($language_format = null) {
$output[] = '<div class="transcript-bundle">';
$output[] = apply_filters('the_multiple_transcript_language_name', $language_format, $transcripts, '');
foreach ($transcripts as $code => $transcript) {
$transcript = end(apply_filters('the_media_transcript', $transcript));
$output[] = '<div '
. (($code == $default_language) ? 'style="display:none"' : '')
. ' class="transcript-holder ' . $code . '">' . $language_name . $transcript . '</div>';
$output[] = end(apply_filters('the_transcript_language_name', $language_format, $code, ''));
$output[] = '<div class="transcript-holder ' . $code . '">' . $transcript . '</div>';
}
$output[] = '</div>';
}