$(document).ready(function() { //makes buttons buttons $("button").button(); //just everything works better when synchro $.ajax({async:false}); // $.widget( "ui.timespinner", $.ui.spinner, { // options: { // // seconds // step: 60 * 1000, // // hours // page: 60, // culture: "en-US", // spin : function(event, ui) { // console.log("SPINN!"); // return false; // }, // change: function( event, ui ) { // console.log("change!"); // return false; // } // } // _parse: function( value ) { // if ( typeof value === "string" ) { // // already a timestamp // if ( Number( value ) == value ) { // return Number( value ); // } // return +Globalize.parseDate( value ); // } // return value; // }, // _format: function( value ) { // return Globalize.format( new Date(value), "t" ); // } // }); // $( "#culture" ).change(function() { // var current = $( "#spinner" ).timespinner( "value" ); // Globalize.culture( $(this).val() ); // $( "#spinner" ).timespinner( "value", current ); // }); // }); jQuery.extend({ getValues: function(url) { var result = null; $.ajax({ url: url, type: 'get', dataType: 'json', async: false, success: function(data) { result = data; } }); return result; } }); originalExerciselist = $.getValues("/api/exerciselist"); var musclesearcharray = []; var muscleSVGmap = ['Triceps','Forearms','Biceps','Deltoids','Back','Lats','Glutes','Hamstrings','Calves','Traps','Abs','Quads','Shins','Pectorals']; function LoadBodyHistory() { $('span.SVGBODY').empty().load("/images/BlankBody.svg", function(){ workoutmusclesum = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]; var currentsvg = $(this).first('svg#Layer_1'); $(this).siblings('.workoutentry').each(function(){ $(this).children('p.workoutelement').each(function(){ exercisemusculearray = $(this).data("musclearray"); jQuery.each(exercisemusculearray, function(index, element) { //console.log('marray'+index +'=' + element); workoutmusclesum[index] = workoutmusclesum[index] + element; }); }); //console.log('Tarray= '+workoutmusclesum); jQuery.each(workoutmusclesum, function(index, element) { console.log('color='+ muscleSVGmap[index] +'=' + (element/5)); $(currentsvg).find('g#' + muscleSVGmap[index]).children().css("opacity",(element/5)); $(currentsvg).find('g#' + muscleSVGmap[index]).children().css("fill",'#0AADE3'); }); }); }); } LoadBodyHistory(); var colors = "0f0 0ff f60 f0f 00f f00".split(' '), i=0; $(document).on('click', '.SVGBODYFilter g',(function() { if ($(this).data('Clicked') === 'True') { $(this).data('Clicked', 'False'); $(this).children('path').css("fill",'#0AADE3'); musclesearcharray.splice(musclesearcharray.indexOf(this.id),1); filterarray(); } else { $(this).data('Clicked', 'True'); $(this).children('path').css("fill",'#00ff00'); musclesearcharray.push(this.id); filterarray(); } }) ); $("button#addExercise").click(function() { var newElem = $('
  • '); $(newElem).appendTo('ul#exercises'); $("button").button(); $( "ul#exercises" ).sortable( "refresh" ); $('#newworkout').trigger('sortupdate'); }); $(document).on('click', '.addSet',(function() { var newElem = $('
  • '); $(this).siblings('ul.sets').append(newElem); $("button").button(); $("ul.sets").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'); } }); $( "#exercises" ).sortable( "refresh" ); $( ".sets" ).sortable( "refresh" ); $('#newworkout').trigger('sortupdate'); })); $(document).on('click', '.delete',function() { $(this).closest('li').remove(); $('#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(); //$('span.SVGBODY').empty().load("/images/BlankBody.svg", function(){ //$("button").button(); //}); LoadBodyHistory(); }); $('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, function(){ //$( "#timespinner" ).timespinner(); //makes datepickers $( ".datepicker" ).datepicker(); $('.datepicker').datepicker('setDate', new Date()); $("#newworkout").bind('sortupdate', function(event, ui) { console.log('sortupdate called'); $('#exercises > li').each(function(){ var itemindex= $(this).index(); $(this).find('input, select').each(function() { var newname = $(this).attr('name').replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']'); $(this).attr('name', newname); }); $(this).find('ul li').each(function(){ var itemindex2= $(this).index(); $(this).children('input').each(function(){ var newname2 = $(this).attr('name').replace(/\[splits\]\[[0-9]*\]/,'[splits][' + itemindex2 + ']'); newname2 = newname2.replace(/elements\[[0-9]*\]/,'elements[' + itemindex + ']'); $(this).attr('name', newname2); }); // $(this).children('label').each(function(){ // var newname2 = 'Set '+ (itemindex2 + 1 ) + ''; // $(this).html(newname2); // }); //Only show delete if more than 1 set if ( $(this).siblings('.set').length > 0 ) { $(this).children('.delete').show(); } else { $(this).children('.delete').hide(); } }); }); }); }); $('div#Leftpane').empty().load("/workouts/filters", function(){ $('span.SVGBODYFilter').empty().load("/images/BlankBody.svg", function(){ //$("button").button(); }); 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() { var id = $(this).attr('value'); $('div#Rightpane').empty().load("/workouts/"+ id + "/recent/", function(){ $("button").button(); $('span.SVGBODY').empty().load("/images/BlankBody.svg", function(){ }); LoadBodyHistory(); }); $('div#Leftpane').empty().load("/users/"+ id + "/sidebar", function(){ $("button").button(); }); }); $("#Rightpane").delegate("a", "click",function() { var id = $(this).attr('href'); $('div#Rightpane').empty().load(id , function(){ $("button").button(); LoadBodyHistory(); }); return false; }); $("#Leftpane").delegate("button.map-link", "click",function () { var id = $(this).attr('value'); $('div#Rightpane').empty().load(id , function(){ $("button").button(); $( ".buttonset" ).buttonset(); }); }); $(document).on('click', '.addthisExercise',(function() { var newElem = $('
  • '); $(newElem).data('musclearray', $(this).closest('li').data('musclearray')); $(newElem).data('musclearrayMod', $(this).closest('li').data('musclearrayMod')); $(newElem).appendTo('ul#exercises'); $( ".hiddenelement" ).hide(); $("button").button(); $( "ul#exercises" ).sortable( "refresh" ); $( "ul#sets" ).sortable( "refresh" ); $('#newworkout').trigger('sortupdate'); }) ); $(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) { var len = $('.filter').length; $(".filter").each(function(index, element) { if ($(this).is (':checked')){ keyREGEX += '('+ $(this).val() +')'; } }); } if (musclesearcharray.length > 0 ){ jQuery.each(musclesearcharray, function(index, element) { keyREGEX += '('+ this +')'; }); } keyREGEX = keyREGEX.replace(/\)\(/g, ")|("); console.log("Regex= " + keyREGEX); $("#exerciselist li").each(function(){ 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) ) { $(this).show(); } else { $(this).hide(); } } else if (keyworddata.search(new RegExp(keyREGEX,'ig')) > -1) { $(this).show(); } else { $(this).hide(); } }); console.timeEnd('Filter'); } // function filterarrayMuscles(){ // console.time('FilterMuscles'); // var keyREGEX= ""; // if (musclesearcharray.length > 0 ){ // jQuery.each(musclesearcharray, function(index, element) { // keyREGEX += '('+ this +')'; // }); // } // keyREGEX = keyREGEX.replace(/\)\(/g, ")|("); // console.log("Regex= " + keyREGEX); // $("#exerciselist li").each(function(){ // 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) ) { // $(this).show(); // } else { // $(this).hide(); // } // } // else if (keyworddata.search(new RegExp(keyREGEX,'ig')) > -1) // { // $(this).show(); // } // else { // $(this).hide(); // } // }); // console.timeEnd('Filter'); // } ///////////////////////////////// // Pseudocode for 1RM calcs // for each exercise in workout // get H1RM for exercise // C1RMsum = 0 // for each set in exercise // calculate C1RM and store in array // find highest C1RM in array // if C1RM > H1RM then // H1RM = C1RM // set comment to "yay" // for each value in array // set[index] = value/H1RM // C1RMsum += value/H1RM // Done // assume sum sumarray * each in musclearray ////// Make below standalone funtion "updateExerciselistDIV" function PopulateExerciseList(exerciselist) { console.time('PopulateExList'); var newExerciselist = $('
    '); $.each(exerciselist, function (i, item) { var newElem = $('
  • '+item.name + ' - ' + item.description + '
  • '); $(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); }); $('#exerciselist').empty(); $(newExerciselist).appendTo('#exerciselist'); $("button").button(); console.timeEnd('PopulateExList'); } });