padmaAPI/static/js/padmaSearch.js

110 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2010-07-12 19:09:53 +00:00
$(document).ready(function() {
$('#searchForm').submit(function(e) {
e.preventDefault();
2010-07-15 00:02:35 +00:00
$('.searchResults').html('');
2010-07-12 19:09:53 +00:00
var val = $.trim($('#search').val());
if (val == '') {
return;
}
doSearch(val);
2010-07-13 12:08:50 +00:00
});
});
2010-07-12 19:09:53 +00:00
/*
var words = val.split(" ");
for (var i = 0; i < words.length; i++) {
var thisWord = words[i];
if (!prevSearchTerms.inArray(thisWord) && thisWord.length > 3) {
doSearch(thisWord);
prevSearchTerms.push(thisWord);
}
}
*/
function getVideoById(id) {
for (var i=0; i < padmaVideos.length; i++) {
var thisVideo = padmaVideos[i];
if (thisVideo.id == id) {
return thisVideo;
}
}
return false;
}
$('.addToClipBin').live("click", function(e) {
e.preventDefault();
/*
var layerId = $(this).parents(".layerResult").attr("data-id");
var videoId = $(this).parents(".videoWrapper").attr("id");
var video = getVideoById(videoId);
var layer = video.getLayerById(layerId);
*/
var parent = $(this).parents('.layerResult');
var layer = parent.data("layer");
parent.slideUp();
layer.addToClipBin();
});
function doSearch(word) {
var matchingLayers = findMatchingLayers(word);
2010-07-15 00:02:35 +00:00
var noOfResults = matchingLayers.length;
$('#resultStats').html(noOfResults + " layers found");
2010-07-12 19:09:53 +00:00
for (var l=0; l < matchingLayers.length; l++) {
if (matchingLayers[l]) {
var layer = matchingLayers[l];
layer.showResult(word);
/*
var imgPath = layer.firstFrame128;
// console.log(layer.getVideoElem());
// var html = '';
// console.log(imgPath);
var html = layer.getVideoElem();
// console.log(html);
// var html = layer.getThumbElem();
// var imgHtml = "<img src='" + imgPath + "' />";
$('#results').append(html);
*/
}
}
2010-07-13 12:08:50 +00:00
}
2010-07-12 19:09:53 +00:00
/*
* @param {String} word Word to search for in layers
* @returns {Array} Array of padmaLayer objects
*/
function findMatchingLayers(word) {
var matchedLayers = [];
for (var v=0; v < padmaVideos.length; v++) {
if (padmaVideos[v].layers) {
var layers = padmaVideos[v].layers;
for (var l=0; l < layers.length; l++) {
if (layers[l].value) {
var val = layers[l].value;
2010-07-15 00:02:35 +00:00
if (val.toLowerCase().indexOf(word.toLowerCase()) != -1) {
2010-07-12 19:09:53 +00:00
var matchedLayer = padmaVideos[v].layers[l];
// var matchedLayer = new padmaLayer(layers[l], v)
matchedLayers.push(matchedLayer);
2010-07-13 12:08:50 +00:00
}
}
2010-07-12 19:09:53 +00:00
}
}
}
2010-07-13 12:08:50 +00:00
return matchedLayers;
}
2010-07-12 19:09:53 +00:00
Array.prototype.inArray = function(value) {
// Returns true if the passed value is found in the
// array. Returns false if it is not.
var i;
for (i=0; i < this.length; i++) {
if (this[i] == value) {
return true;
}
2010-07-13 12:08:50 +00:00
}
2010-07-12 19:09:53 +00:00
return false;
2010-07-13 12:08:50 +00:00
};
2010-07-12 19:09:53 +00:00