(function ($) { AblePlayer.prototype.showSearchResults = function() { // search VTT file for all instances of searchTerms // Currently just supports search terms separated with one or more spaces // TODO: Add support for more robust search syntax: // Search terms wrapped in quotation marks ("") must occur exactly as they appear in the quotes // Search terms with an attached minus sign (e.g., -term) are to be excluded from results // Boolean AND/OR operators // ALSO: Add localization support var thisObj = this; if (this.searchDiv && this.searchString) { if ($('#' + this.SearchDiv)) { var resultsArray = this.searchFor(this.searchString); if (resultsArray.length > 0) { var resultsSummary = $('
',{ 'class': 'able-search-results-summary' }); var resultsSummaryText = 'Found ' + resultsArray.length + ' matching items. '; resultsSummaryText += 'Click the time associated with any item '; resultsSummaryText += 'to play the video from that point.'; resultsSummary.html(resultsSummaryText); var resultsList = $('
').text('No results found.');
$('#' + this.searchDiv).append(noResults);
}
}
}
};
AblePlayer.prototype.searchFor = function(searchString) {
// return chronological array of caption cues that match searchTerms
var captionLang, captions, results, caption, c, i, j;
// split searchTerms into an array
var searchTerms = searchString.split(' ');
if (this.captions.length > 0) {
captionLang = this.captions[0].language; // in case it's needed later
captions = this.captions[0].cues;
if (captions.length > 0) {
var results = [];
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]);
for (j = 0; j < searchTerms.length; j++) {
if (caption.indexOf(searchTerms[j]) !== -1) {
results[c] = [];
results[c]['start'] = captions[i].start;
results[c]['caption'] = this.highlightSearchTerm(searchTerms,j,caption);
c++;
break;
}
}
}
}
}
}
return results;
};
AblePlayer.prototype.highlightSearchTerm = function(searchTerms, index, resultString) {
// highlight ALL found searchTerms in the current resultString
// index is the first index in the searchTerm array where a match has already been found
// Need to step through the remaining terms to see if they're present as well
var i, searchTerm, termIndex, termLength, str1, str2, str3;
for (i=index; i