mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 06:32:11 +00:00
fixed search and filters
This commit is contained in:
@@ -8,6 +8,8 @@ $(document).ready(function() {
|
||||
$('.datepicker').datepicker('setDate', new Date());
|
||||
//$('.datepicker').datepicker("hide");
|
||||
|
||||
//jsut everything work better
|
||||
$.ajax({async:false});
|
||||
|
||||
jQuery.extend({
|
||||
getValues: function(url) {
|
||||
@@ -114,29 +116,68 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
|
||||
$("ul#exercises").sortable({
|
||||
items: "> li",
|
||||
cancel: ':input, button' ,
|
||||
placeholder: "ui-state-highlight",
|
||||
revert: true,
|
||||
start: function(e, ui){
|
||||
ui.placeholder.height(ui.item.height());
|
||||
},
|
||||
stop: function(event, ui) {
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//$('#newworkout').trigger('sortupdate');
|
||||
$("#Leftpane").delegate("button.recent-link", "click",function () {
|
||||
var id = $(this).attr('value');
|
||||
$('div#Rightpane').empty().load("/workouts/"+ id + "/recent/", function(){
|
||||
$("button").button();
|
||||
});
|
||||
$('div#Leftpane').empty().load("/users/"+ id + "/sidebar", function(){
|
||||
$("button").button();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$("#Leftpane").delegate("button.newex-link", "click",function () {
|
||||
var id = $(this).attr('value');
|
||||
$('div#Rightpane').empty().load(id);
|
||||
$('div#Leftpane').empty().load("/workouts/filters", function(){
|
||||
PopulateExerciseList(originalExerciselist);
|
||||
$("ul#exercises").sortable({
|
||||
items: "> li",
|
||||
cancel: ':input, button' ,
|
||||
placeholder: "ui-state-highlight",
|
||||
revert: true,
|
||||
start: function(e, ui){
|
||||
ui.placeholder.height(ui.item.height());
|
||||
},
|
||||
stop: function(event, ui) {
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
$("button").button();
|
||||
});
|
||||
|
||||
$("#top").delegate("button.home-link", "click",function() {
|
||||
//$("#top").delegate("button.home-link", "click",function () {
|
||||
// window.location = this.id;
|
||||
|
||||
$("button.map-link").click(function () {
|
||||
console.log('mapclick');
|
||||
var id = $(this).attr('value');
|
||||
console.log(id);
|
||||
$('div#Rightpane').empty().load(id, function(){
|
||||
PopulateExerciseList(originalExerciselist);
|
||||
$('div#Rightpane').empty().load("/workouts/"+ id + "/recent/", function(){
|
||||
$("button").button();
|
||||
});
|
||||
$('div#Leftpane').empty().load("/users/"+ id + "/sidebar", function(){
|
||||
$("button").button();
|
||||
});
|
||||
});
|
||||
|
||||
$("#Rightpane").delegate("a", "click",function() {
|
||||
console.log("yup yup" + $(this).attr('href'));
|
||||
var id = $(this).attr('href');
|
||||
$('div#Rightpane').empty().load(id , function(){
|
||||
$("button").button();
|
||||
});
|
||||
// Stop regular handling of "click" in IE (and some others)
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#Leftpane").delegate("button.map-link", "click",function () {
|
||||
var id = $(this).attr('value');
|
||||
$('div#Rightpane').empty().load(id);
|
||||
$("button").button();
|
||||
});
|
||||
|
||||
$(document).on('click', '.addthisExercise',(function() {
|
||||
@@ -157,9 +198,28 @@ $(document).ready(function() {
|
||||
//filteredExerciseArray = filterarray(originalExerciselist);
|
||||
//PopulateExerciseList(arr);
|
||||
|
||||
$(document).on('click', '.filter',(function (){
|
||||
var keyREGEX= "";
|
||||
if ($(".filter:checked").length > 0)
|
||||
$(document).on('click', '.filter', function(){
|
||||
filterarray();
|
||||
});
|
||||
|
||||
$(document).on('keyup', '#searchbox', function(){
|
||||
filterarray();
|
||||
});
|
||||
|
||||
|
||||
|
||||
function filterarray(){
|
||||
console.time('Filter');
|
||||
|
||||
var searchstring = $("#searchbox").val();
|
||||
var keyREGEX= "";
|
||||
|
||||
if(jQuery.trim(searchstring).length > 0)
|
||||
{
|
||||
keyREGEX += '('+ searchstring +')';
|
||||
}
|
||||
|
||||
if ($(".filter:checked").length > 0)
|
||||
{
|
||||
// any one is checked
|
||||
var len = $('.filter').length;
|
||||
@@ -172,31 +232,43 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
//keyREGEX += "'";
|
||||
keyREGEX = keyREGEX.replace(")(", ")|(");
|
||||
} else {
|
||||
// none is checked
|
||||
keyREGEX = '(none is checked)';
|
||||
keyREGEX = keyREGEX.replace(/\)\(/g, ")|(");
|
||||
}
|
||||
|
||||
console.log("Regex= " + keyREGEX);
|
||||
filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
||||
PopulateExerciseList(filteredExerciseArray);
|
||||
//filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
||||
//PopulateExerciseList(filteredExerciseArray);
|
||||
|
||||
$("#exerciselist li").each(function(){
|
||||
//var keywordarray = $(this).data('keywords');
|
||||
var keyworddata = $(this).data('keywords').toString();
|
||||
if(jQuery.trim(searchstring).length > 0) {
|
||||
if ( ($(this).text().search(new RegExp(keyREGEX,'i')) > -1) && (keyworddata.search(new RegExp(keyREGEX,'ig')) > -1) ) {
|
||||
console.log("search" + $(this).text() + " " + keyREGEX);
|
||||
$(this).show();
|
||||
console.log('thisshow1 ' + $(this).text() + ' ' + keyworddata.search(new RegExp(keyREGEX,'ig')) );
|
||||
} else {
|
||||
console.log('thishide1 ' + $(this).text() + ' ' + keyworddata.search(new RegExp(keyREGEX,'ig')));
|
||||
$(this).hide();
|
||||
}
|
||||
}
|
||||
else if (keyworddata.search(new RegExp(keyREGEX,'ig')) > -1)
|
||||
{
|
||||
console.log('thisshow ' + $(this).text() + ' ' + keyworddata + ' ' + keyworddata.search(new RegExp(keyREGEX,'ig')));
|
||||
$(this).show();
|
||||
}
|
||||
else {
|
||||
console.log('thishide ' + $(this).text() + ' ' + keyworddata + ' ' + keyworddata.search(new RegExp(keyREGEX,'ig')));
|
||||
$(this).hide();
|
||||
}
|
||||
});
|
||||
|
||||
console.timeEnd('Filter');
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function filterarray(input, regex){
|
||||
console.log('passed regex' + regex);
|
||||
var keyRE=new RegExp(regex);
|
||||
var arr = jQuery.grep(input, function(n, i){
|
||||
return keyRE.test(n.keywords);
|
||||
// return $.grep(n.keywords, function (item, i) {
|
||||
// return keyRE.test(item);
|
||||
// });
|
||||
});
|
||||
console.log("arr " + arr.length);
|
||||
return arr;
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// Pseudocode for 1RM calcs
|
||||
@@ -226,10 +298,11 @@ function PopulateExerciseList(exerciselist) {
|
||||
var newExerciselist = $('<div></div>');
|
||||
$.each(exerciselist, function (i, item) {
|
||||
//console.log("Exercisename = " + item.name);
|
||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||
var newElem = $('<li>'+item.name + ' - ' + item.description + '<button type="button" class="addthisExercise">+</li>');
|
||||
$(newElem).data('name', item.name);
|
||||
$(newElem).data('exid', item._id);
|
||||
$(newElem).data('musclearray', item.musclearray);
|
||||
$(newElem).data('keywords', item.keywords);
|
||||
//$(newElem).data('musclearrayMod', item.musclearrayMod);
|
||||
$(newElem).data('datafields', item.datafields);
|
||||
newExerciselist.append(newElem);
|
||||
|
||||
@@ -24,6 +24,12 @@ list-style-type: none;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#userphoto {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
background-color: #99B2FF;
|
||||
}
|
||||
|
||||
#exerciselist {
|
||||
width : 500px;
|
||||
height : 400px;
|
||||
|
||||
Reference in New Issue
Block a user