Skip to content

Commit

Permalink
upgrade ha lite and caption js
Browse files Browse the repository at this point in the history
  • Loading branch information
maboa committed Nov 2, 2023
1 parent cf8debd commit 8a5e758
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
14 changes: 7 additions & 7 deletions wp-hyperaudio/hyperaudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Hyperaudio Interactive Transcript
* Plugin URI: https://hyper.audio
* Description: Hyperaudio Interactive Transcript Maker and Player – maximise your audio and video content's accessibility to humans and search engines.
* Version: 1.0.16
* Version: 1.0.14
* Author: Mark Boas
* Author URI: https://maboa.it
**/
Expand Down Expand Up @@ -226,12 +226,12 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)
function hyperaudio_init()
{
if (!is_admin()) {
wp_enqueue_script('velocity', plugins_url('/js/velocity.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('hyperaudio-lite', plugins_url('/js/hyperaudio-lite.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('caption', plugins_url('/js/caption.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('share-this', plugins_url('/js/share-this.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('share-this-twitter', plugins_url('/js/share-this-twitter.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('share-this-clipboard', plugins_url('/js/share-this-clipboard.js', __FILE__), array(), '1.0.0', false);
wp_enqueue_script('velocity', plugins_url('/js/velocity.js', __FILE__), false, '1.0.0', false);
wp_enqueue_script('hyperaudio-lite', plugins_url('/js/hyperaudio-lite.js', __FILE__), false, '1.0.0', false);
wp_enqueue_script('caption', plugins_url('/js/caption.js', __FILE__), false, '1.0.0', false);
wp_enqueue_script('share-this', plugins_url('/js/share-this.js', __FILE__), false, '1.0.0', false);
wp_enqueue_script('share-this-twitter', plugins_url('/js/share-this-twitter.js', __FILE__), false, '1.0.0', false);
wp_enqueue_script('share-this-clipboard', plugins_url('/js/share-this-clipboard.js', __FILE__), false, '1.0.0', false);
}
}

Expand Down
32 changes: 23 additions & 9 deletions wp-hyperaudio/js/caption.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.1.1 (patch) */
/*! Version 2.1.3 patch 2*/
'use strict';

var caption = function () {
Expand All @@ -20,7 +20,7 @@ var caption = function () {
return timecode.substring(0,8) + "," + timecode.substring(9,12);
}

cap.init = function (transcriptId, playerId, maxLength, minLength) {
cap.init = function (transcriptId, playerId, maxLength, minLength, label, srclang) {
var transcript = document.getElementById(transcriptId);
var words = transcript.querySelectorAll('[data-m]');
var data = {};
Expand Down Expand Up @@ -303,20 +303,33 @@ var caption = function () {
var video = document.getElementById(playerId);

if (video !== null) {
video.addEventListener("loadedmetadata", function() {
video.addEventListener("loadedmetadata", function listener() {
//var track = document.createElement("track");
var track = document.getElementById(playerId+'-vtt');
track.kind = "captions";
track.label = "English";
track.srclang = "en";

if (label !== undefined) {
console.log("setting label as "+label);
track.label = label;
}

if (srclang !== undefined) {
console.log("setting srclang as "+srclang);
track.srclang = srclang;
}
//track.label = "English";
//track.srclang = "en";
track.src = "data:text/vtt,"+encodeURIComponent(captionsVtt);
video.textTracks[0].mode = "showing";
});
video.removeEventListener("loadedmetadata", listener, true);
}, true);

video.textTracks[0].mode = "showing";
if (video.textTracks[0] !== undefined) {
video.textTracks[0].mode = "showing";
}
}

function captionsObj(vtt, srt) {
function captionsObj(vtt, srt, data) {
// clean up – remove any double blank lines
// and blank line at the start of srt

Expand All @@ -326,9 +339,10 @@ var caption = function () {

this.vtt = vtt.replaceAll("\n\n\n","\n\n");
this.srt = srt.replaceAll("\n\n\n","\n\n");
this.data = captions;
}

return new captionsObj(captionsVtt, captionsSrt);
return new captionsObj(captionsVtt, captionsSrt, captions);
};

return cap;
Expand Down
8 changes: 6 additions & 2 deletions wp-hyperaudio/js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.1.3 */
/*! Version 2.1.4 */

'use strict';

Expand Down Expand Up @@ -177,7 +177,11 @@ const hyperaudioPlayerOptions = {
}

function hyperaudioPlayer(playerType, instance) {
return new playerType(instance);
if (playerType !== null && playerType !== undefined) {
return new playerType(instance);
} else {
alert("data-player-type attribute must be set on player if not native, eg SoundCloud, YouTube, Vimeo, VideoJS")
}
}

class HyperaudioLite {
Expand Down
2 changes: 1 addition & 1 deletion wp-hyperaudio/readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== Hyperaudio ===
Contributors: Maboas
Contributors: Maboa
Donate link: https://patreon.com/hyperaudio
Tags: Podcasts, Captions, Transcripts, Interactive Transcripts, Accessibility, Media, Audio, Video, Subtitles
Requires at least: 3.1
Expand Down

0 comments on commit 8a5e758

Please sign in to comment.