padmaAPI/static/js/padmaSearch.js
2010-07-15 05:32:35 +05:30

110 lines
2.7 KiB
JavaScript

$(document).ready(function() {
$('#searchForm').submit(function(e) {
e.preventDefault();
$('.searchResults').html('');
var val = $.trim($('#search').val());
if (val == '') {
return;
}
doSearch(val);
});
});
/*
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);
var noOfResults = matchingLayers.length;
$('#resultStats').html(noOfResults + " layers found");
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);
*/
}
}
}
/*
* @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;
if (val.toLowerCase().indexOf(word.toLowerCase()) != -1) {
var matchedLayer = padmaVideos[v].layers[l];
// var matchedLayer = new padmaLayer(layers[l], v)
matchedLayers.push(matchedLayer);
}
}
}
}
}
return matchedLayers;
}
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;
}
}
return false;
};