Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Preload images on the muscle overview page

Roland Geiderdf2990740662
diff --git a/exercises/templates/muscle_overview.html b/exercises/templates/muscle_overview.html
index 611ab6dab..2f138c39a 100644
--- a/exercises/templates/muscle_overview.html
+++ b/exercises/templates/muscle_overview.html
@@ -11,6 +11,13 @@
{% block header %}
<script>
$(document).ready(function() {
+ //Prefetch the background images
+ {% for muscle in muscle_list|first %}
+ prefetch_images(['/static/images/muscles/main/muscle-' + {{muscle.id}} + '.svg']);
+ {% endfor %}
+ prefetch_images(['/static/images/muscles/muscular_system_back.svg']);
+
+
$('.muscle').hover(function(e) {
e.preventDefault();
var div_id = $(this).data('target');
@@ -44,7 +51,6 @@ $(document).ready(function() {
Main Content
-->
{% block content %}
-
<h2>{% trans "Muscle overview" %} </h2>
@@ -60,7 +66,7 @@ $(document).ready(function() {
</div>
<div class="ym-g33 ym-gl">
<div class="ym-gbox-left">
- {% comment %}Why do we need to use |first?{% endcomment %}
+ {# Why do we need to use |first? #}
{% regroup muscle_list|first by is_front as muscle_group %}
{% for group in muscle_group %}
{% if group.grouper %}
diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.js
index ead8de754..5a9dfe061 100644
--- a/manager/static/js/workout-manager.js
+++ b/manager/static/js/workout-manager.js
@@ -791,3 +791,15 @@ function load_maincontent()
});
});
}
+
+/*
+ * Helper function to prefetch images on a page
+ */
+function prefetch_images(imageArray)
+{
+ $(imageArray).each(function(){
+ (new Image()).src = this;
+ //console.log('Preloading image' + this);
+ });
+}
+