", {
class: "able-search-result-text",
id: resultId,
});
itemText.html('...' + resultsArray[i]["caption"] + '...');
$resultsItem.append(itemStartSpan, itemText);
$resultsList.append($resultsItem);
}
$('#' + this.searchDiv)
.html(searchStringHtml)
.append($resultsSummary, $resultsList);
} else {
var noResults = $('').text( this.translate( 'noResultsFound', 'No results found.' ) );
$('#' + this.searchDiv)
.html(searchStringHtml)
.append(noResults);
}
}
}
};
AblePlayer.prototype.searchFor = function (searchString, ignoreCaps) {
// return chronological array of caption cues that match searchTerms
var captionLang, captions, results, caption, c, i, j;
results = [];
// split searchTerms into an array
var searchTerms = searchString.split(" ");
if (this.captions.length > 0) {
// Get caption track that matches this.searchLang
for (i = 0; i < this.captions.length; i++) {
if (this.captions[i].language === this.searchLang) {
captionLang = this.searchLang;
captions = this.captions[i].cues;
}
}
if (captions.length > 0) {
c = 0;
for (i = 0; i < captions.length; i++) {
if (
$.inArray(captions[i].components.children[0]["type"], [
"string",
"i",
"b",
"u",
"v",
"c",
]) !== -1
) {
caption = this.flattenCueForCaption(captions[i]);
var captionNormalized = ignoreCaps
? caption.toLowerCase()
: caption;
for (j = 0; j < searchTerms.length; j++) {
var searchTermNormalized = ignoreCaps
? searchTerms[j].toLowerCase()
: searchTerms[j];
if (captionNormalized.indexOf(searchTermNormalized) !== -1) {
results[c] = [];
results[c]["start"] = captions[i].start;
results[c]["lang"] = captionLang;
results[c]["caption"] = this.highlightSearchTerm(
searchTerms,
caption
);
c++;
break;
}
}
}
}
}
}
return results;
};
AblePlayer.prototype.highlightSearchTerm = function (
searchTerms,
resultString
) {
// highlight ALL found searchTerms in the current resultString
// Need to step through the remaining terms to see if they're present as well
searchTerms.forEach(function (searchTerm) {
var reg = new RegExp(searchTerm, "gi");
resultString = resultString.replace(
reg,
'$&'
);
});
return resultString;
};
/**
* Convert a number of seconds into readable time information.
*
* @param {int} totalSecondsFloat
*
* @returns {string[]} array 'value' HH:MM:SS and 'title' speakable time.
*/
AblePlayer.prototype.secondsToTime = function (totalSecondsFloat) {
// return an array of totalSeconds converted into two formats
// time['value'] = HH:MM:SS with hours dropped if there are none
// time['title'] = a speakable rendering, so speech rec users can easily speak the link
var totalSeconds = Math.floor(totalSecondsFloat);
var h = parseInt(totalSeconds / 3600, 10) % 24;
var m = parseInt(totalSeconds / 60, 10) % 60;
var s = totalSeconds % 60;
var value = '';
var title = '';
if (h > 0) {
value += String(h).padStart(2, '0') + ':';
title += h > 0 ? h + ' ' + (h === 1 ? this.translate( 'hour', 'hour' ) : this.translate( 'hours', 'hours' ) ) : '';
}
value += String(m).padStart(2, '0') + ':';
title += m > 0 ? m + ' ' + (m === 1 ? this.translate( 'minute', 'minute' ) : this.translate( 'minutes', 'minutes' ) ) : '';
value += String(s).padStart(2, '0');
title += s > 0 ? s + ' ' + (s === 1 ? this.translate( 'second', 'second' ) : this.translate( 'seconds', 'seconds' ) ) : '';
var time = [];
time["value"] = value;
time["title"] = title;
return time;
};
}
export default addSearchFunctions;