Self hosted FLOSS fitness/workout, nutrition and weight tracker
Duplicate jQuery selector
Peter van der Does769e64924208
diff --git a/wger/exercises/templates/muscles/overview.html b/wger/exercises/templates/muscles/overview.htmlindex 8fd32881d..ba73057d8 100644--- a/wger/exercises/templates/muscles/overview.html+++ b/wger/exercises/templates/muscles/overview.html@@ -20,10 +20,11 @@ $(document).ready(function() {// Hightlight the first element- wgerHighlightMuscle($('.muscle').first());+ var $muscle = $('.muscle');+ wgerHighlightMuscle($muscle.first());// Highlight on hover- $('.muscle').hover(function(e) {+ $muscle.hover(function(e) {e.preventDefault();wgerHighlightMuscle(this);});diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.htmlindex 7480f3e40..c5d70971c 100644--- a/wger/manager/templates/mobile/workout/view.html+++ b/wger/manager/templates/mobile/workout/view.html@@ -32,16 +32,16 @@ function wgerCustomModalInit()$(document).ready(function() {- /*- * Show/Hide the comments to the exercises- */- {% if user.userprofile.show_comments %}- $(".exercise-comments").show();- {% else %}- $(".exercise-comments").hide();- {% endif %}- wgerToggleComments();-+ var $exercisecomments = $(".exercise-comments");+ /*+ * Show/Hide the comments to the exercises+ */+ {% if user.userprofile.show_comments %}+ $exercisecomments.show();+ {% else %}+ $exercisecomments.hide();+ {% endif %}+ wgerToggleComments();});</script>{% endblock %}diff --git a/wger/manager/templates/workout/timer.html b/wger/manager/templates/workout/timer.htmlindex 15f06c61f..5b8a06626 100644--- a/wger/manager/templates/workout/timer.html+++ b/wger/manager/templates/workout/timer.html@@ -18,234 +18,234 @@* http://bookofzeus.com/articles/build-a-fancy-countdown-with-html5*/-var div_height = $( window ).height() * 0.80;-var div_width = $( window ).width() * 0.85;+var div_height = $(window).height() * 0.80;+var div_width = $(window).width() * 0.85;var start = new Date();var counter = {- // counters (in seconds, except the milliseconds one)- start: 0,- end: 60,- seconds: 0,- milliseconds: 0,-- // other- fps: 40,- step_id: '',- interval: 0,-- // Canvas info- ctx: '',- canvas_size: [0, 0],- radius: 75,- center: 75,-- draw_step: function(){- /*- * Step function, called every 1000/fps ms- */-- // Perform exit cleanup if we finish the countdown- if (this.milliseconds >= this.end * 1000)- {- clearInterval(this.interval);- $('#counter-' + this.step_id).html('0');-- var step = $('li[data-step="' + this.step_id + '"]');- paginate_to(step.data('number') + 1);- return;- }-- // Update the HTML element with the current remaining time once per second- if (this.seconds != Math.ceil(this.milliseconds/1000))- {- $('#counter-' + this.step_id).html(this.end - this.seconds);- }-- // Draw the arc in the canvas element- var step = this.milliseconds / (this.end * 1000) ;- this.ctx.clearRect(0, 0, this.canvas_size[0], this.canvas_size[1]);- this.ctx.beginPath();- this.ctx.moveTo(this.center[0], this.center[1]);- this.ctx.arc(- this.center[0],- this.center[1],- this.radius,- Math.PI * -0.5,- Math.PI * (-0.5 + step*2),- true // anti clockwise- );- this.ctx.lineTo(this.center[0], this.center[1]); // line back to the center- this.ctx.closePath();- this.ctx.fillStyle = 'rgb(40, 40, 40)'; // color- this.ctx.fill();-- // Update counters- this.seconds = Math.ceil(this.milliseconds/1000);- this.milliseconds = this.milliseconds + 1000/this.fps;- },+ // counters (in seconds, except the milliseconds one)+ start: 0,+ end: 60,+ seconds: 0,+ milliseconds: 0,++ // other+ fps: 40,+ step_id: '',+ interval: 0,++ // Canvas info+ ctx: '',+ canvas_size: [0, 0],+ radius: 75,+ center: 75,++ draw_step: function () {+ /*+ * Step function, called every 1000/fps ms+ */++ // Perform exit cleanup if we finish the countdown+ if (this.milliseconds >= this.end * 1000) {+ clearInterval(this.interval);+ $('#counter-' + this.step_id).html('0');++ var step = $('li[data-step="' + this.step_id + '"]');+ paginate_to(step.data('number') + 1);+ return;+ }- init_canvas: function(step_id, seconds){- /*- * Initialise the canvas- */- var canvas = document.getElementById('canvas-div-' + step_id);- this.ctx = canvas.getContext('2d');- this.canvas_size = [canvas.width, canvas.height];- this.radius = Math.min(this.canvas_size[0], this.canvas_size[1]) / 2;- this.center = [this.canvas_size[0]/2, this.canvas_size[1]/2];+ // Update the HTML element with the current remaining time once per second+ if (this.seconds != Math.ceil(this.milliseconds / 1000)) {+ $('#counter-' + this.step_id).html(this.end - this.seconds);}-};+ // Draw the arc in the canvas element+ var step = this.milliseconds / (this.end * 1000);+ this.ctx.clearRect(0, 0, this.canvas_size[0], this.canvas_size[1]);+ this.ctx.beginPath();+ this.ctx.moveTo(this.center[0], this.center[1]);+ this.ctx.arc(+ this.center[0],+ this.center[1],+ this.radius,+ Math.PI * -0.5,+ Math.PI * (-0.5 + step * 2),+ true // anti clockwise+ );+ this.ctx.lineTo(this.center[0], this.center[1]); // line back to the center+ this.ctx.closePath();+ this.ctx.fillStyle = 'rgb(40, 40, 40)'; // color+ this.ctx.fill();++ // Update counters+ this.seconds = Math.ceil(this.milliseconds / 1000);+ this.milliseconds = this.milliseconds + 1000 / this.fps;+ },++ init_canvas: function (step_id, seconds) {+ /*+ * Initialise the canvas+ */+ var canvas = document.getElementById('canvas-div-' + step_id);+ this.ctx = canvas.getContext('2d');+ this.canvas_size = [canvas.width, canvas.height];+ this.radius = Math.min(this.canvas_size[0], this.canvas_size[1]) / 2;+ this.center = [this.canvas_size[0] / 2, this.canvas_size[1] / 2];+ }+};-function start_countdown(step_id, seconds)-{+function start_countdown(step_id, seconds) {/** Initialise the counter objects and start the interval*/- counter.start = 0;- counter.end = seconds;- counter.milliseconds = 0;- counter.seconds = 0;- counter.step_id = step_id;-- counter.init_canvas(step_id, seconds);- counter.interval = setInterval(- function() { counter.draw_step(step_id, seconds); },- 1000/counter.fps- );+ counter.start = 0;+ counter.end = seconds;+ counter.milliseconds = 0;+ counter.seconds = 0;+ counter.step_id = step_id;++ counter.init_canvas(step_id, seconds);+ counter.interval = setInterval(+ function () {+ counter.draw_step(step_id, seconds);+ },+ 1000 / counter.fps+ );}-function paginate_to(index){+function paginate_to(index) {/** Paginate to the step page with the given index*/- $('ul#workout-timer').animate({- "margin-left": (-index * div_width)- }, 600)+ $('ul#workout-timer').animate({+ "margin-left": (-index * div_width)+ }, 600)}+$(document).ready(function () {+ var $timerstep = $('.timer-step');+ var $timercontainer = $('#timer-container');+ var $sessionform = $('#session-form');+ var $savebuttonform = $('#save_button_form');++ $('#page-title').remove();++ $timerstep.width(div_width);+ $timerstep.height(div_height);++ //wrap into mother div+ $timercontainer.find('ul').wrap('<div id="mother" />');++ //assign height width and overflow hidden to mother+ $('#mother').css({+ width: function () {+ return div_width;+ },+ height: function () {+ return div_height;+ },+ position: 'relative',+ overflow: 'hidden'+ });++ //get total of image sizes and set as width for ul+ var totalWidth = $timerstep.length * div_width;+ $timercontainer.find('ul').css({+ width: function () {+ return totalWidth;+ }+ });++ // Bind the buttons that create new logs+ $('.save_log').bind("click", function (e) {+ e.preventDefault();+ var step_id = $(this).parents('li').data('step');+ var form = $('#form-' + step_id);++ $.post(form.attr('action'), form.serialize(), function (data) {+ //response+ }+ );+ });++ // Bind the timer +/- buttons+ //timer-minus+ $('.timer-minus').bind("click", function (e) {+ e.preventDefault();+ counter.end = counter.end - 10;+ });+ $('.timer-plus').bind("click", function (e) {+ e.preventDefault();+ counter.end = counter.end + 10;+ });++ // Bind the pagination buttons+ $timercontainer.find('ul li.timer-step a.next').bind("click", function (e) {+ e.preventDefault();+ var step_id = $(this).parents('li').data('step');+ var step_time = $(this).parents('li').data('time');+ var step_nr = $(this).parents('li').data('number');++ //Cancel any previously running countdowns+ clearInterval(counter.interval);++ // Paginate to next step+ paginate_to(step_nr + 1);++ // Start the countdown for the next step slightly after the previous+ // pagination animation is finished+ var next_step = $(this).parents('li.timer-step').next();+ if (next_step.is('.pause-step')) {+ setTimeout(function () {+ start_countdown(next_step.data('step'), next_step.data('time'));+ }, 700);+ }++ // If we have reached the last page, compute total workout time+ if (next_step.is('#workout-complete')) {+ var end = new Date();+ var milliseconds = (end.getTime() - start.getTime());++ var hours = (milliseconds / 1000) / 3600;+ var minutes = (milliseconds / 1000) / 60 - Math.floor(hours) * 60;+ var seconds = milliseconds / 1000 - Math.floor(minutes) * 60 - Math.floor(hours) * 3600;++ hours = (hours < 10) ? '0' + hours : hours;+ minutes = (minutes < 10) ? '0' + minutes : minutes;+ seconds = (seconds < 10) ? '0' + seconds : seconds;++ //a.toLocaleTimeString()+ $('#total_time').html(Math.floor(hours) + ':' + Math.floor(minutes) + ':' + Math.floor(seconds));++ $('#id_time_start').val(start.getHours() + ':' + start.getMinutes());+ $('#id_time_end').val(end.getHours() + ':' + end.getMinutes());+ $('#id_date').val(end.getFullYear() + '-' + end.getMonth() + '-' + end.getDay());+ $('#id_user').val('1');+ }-$(document).ready(function() {-- $('#page-title').remove();-- $('.timer-step').width(div_width);- $('.timer-step').height(div_height);-- //wrap into mother div- $('#timer-container').find('ul').wrap('<div id="mother" />');-- //assign height width and overflow hidden to mother- $('#mother').css({- width: function() {- return div_width;- },- height: function() {- return div_height;- },- position: 'relative',- overflow: 'hidden'- });-- //get total of image sizes and set as width for ul- var totalWidth = $('.timer-step').length * div_width;- $('#timer-container').find('ul').css({- width: function() {- return totalWidth;- }- });-- // Bind the buttons that create new logs- $('.save_log').bind("click", function(e) {- e.preventDefault();- var step_id = $(this).parents('li').data('step');- var form = $('#form-' + step_id);-- $.post( form.attr('action'), form.serialize(), function(data) {- //response- }- );- });-- // Bind the timer +/- buttons- //timer-minus- $('.timer-minus').bind("click", function(e) {- e.preventDefault();- counter.end = counter.end - 10;- });- $('.timer-plus').bind("click", function(e) {- e.preventDefault();- counter.end = counter.end + 10;- });-- // Bind the pagination buttons- $('#timer-container').find('ul li.timer-step a.next').bind("click", function(e) {- e.preventDefault();- var step_id = $(this).parents('li').data('step');- var step_time = $(this).parents('li').data('time');- var step_nr = $(this).parents('li').data('number');-- //Cancel any previously running countdowns- clearInterval(counter.interval);-- // Paginate to next step- paginate_to(step_nr + 1);-- // Start the countdown for the next step slightly after the previous- // pagination animation is finished- var next_step = $(this).parents('li.timer-step').next();- if (next_step.is('.pause-step'))- {- setTimeout(function() {- start_countdown(next_step.data('step'), next_step.data('time'));- }, 700);- }-- // If we have reached the last page, compute total workout time- if (next_step.is('#workout-complete'))- {- var end = new Date();- var milliseconds = (end.getTime() - start.getTime());-- var hours = (milliseconds/1000) / 3600;- var minutes = (milliseconds/1000) / 60 - Math.floor(hours)*60;- var seconds = milliseconds/1000 - Math.floor(minutes)*60 - Math.floor(hours)*3600;-- hours = (hours < 10) ? '0' + hours : hours;- minutes = (minutes < 10) ? '0' + minutes : minutes;- seconds = (seconds < 10) ? '0' + seconds : seconds;-- //a.toLocaleTimeString()- $('#total_time').html(Math.floor(hours) + ':' + Math.floor(minutes) + ':' + Math.floor(seconds));-- $('#id_time_start').val(start.getHours() + ':' + start.getMinutes());- $('#id_time_end').val(end.getHours() + ':' + end.getMinutes());- $('#id_date').val(end.getFullYear() + '-' + end.getMonth() + '-' + end.getDay());- $('#id_user').val('1');- }-- });-- // Bind the button to save the workout session form- $('#save_button_form').bind("click", function(e) {- e.preventDefault();- $.post( $('#session-form').attr('action'),- $('#session-form').serialize(),-- // After clicking on the save button once, disable it- function( data ) {- var today = new Date();- var date = '/' + today.getFullYear() + '/' + (today.getMonth() + 1) + '/' + today.getDate();- window.location = '/' + getCurrentLanguage() + '/workout/calendar/' + wgerGetUsername() + date;- $('#save_button_form').unbind("click");- $('#save_button_form').addClass('disabled');- $('#save_button_form').bind("click", function(e) {- e.preventDefault();- });- });+ });++ // Bind the button to save the workout session form+ $savebuttonform.bind("click", function (e) {+ e.preventDefault();+ $.post($sessionform.attr('action'),+ $sessionform.serialize(),++ // After clicking on the save button once, disable it+ function (data) {+ var today = new Date();+ var date = '/' + today.getFullYear() + '/' + (today.getMonth() + 1) + '/' + today.getDate();+ window.location =+ '/' + getCurrentLanguage() + '/workout/calendar/' + wgerGetUsername() + date;+ $savebuttonform.unbind("click");+ $savebuttonform.addClass('disabled');+ $savebuttonform.bind("click", function (e) {+ e.preventDefault();});+ });+ });});</script>{% endblock %}diff --git a/wger/manager/templates/workout/view.html b/wger/manager/templates/workout/view.htmlindex 9e14ae836..8ecc022ec 100644--- a/wger/manager/templates/workout/view.html+++ b/wger/manager/templates/workout/view.html@@ -24,24 +24,24 @@{# #}{% block header %}<script>-function wgerCustomModalInit()-{- // Set up the edit set functions on modal dialogs- wgerInitEditSet();+function wgerCustomModalInit() {+ // Set up the edit set functions on modal dialogs+ wgerInitEditSet();}-$(document).ready(function() {- // Allow the sets to be sortable- wgerSetupSortable();+$(document).ready(function () {+ var $exercisecomments = $(".exercise-comments");+ // Allow the sets to be sortable+ wgerSetupSortable();- // Show/Hide the comments to the exercises- {% if user.userprofile.show_comments %}- $(".exercise-comments").show();- {% else %}- $(".exercise-comments").hide();- {% endif %}- wgerToggleComments();- });+ // Show/Hide the comments to the exercises+ {% if user.userprofile.show_comments %}+ $exercisecomments.show();+ {% else %}+ $exercisecomments.hide();+ {% endif %}+ wgerToggleComments();+});</script>{% endblock %}