[damned-lies] Rewrite a bit the dynamic branch loading JS code



commit 3543c62d9d2adab84f5fef0a043f402fb291fa36
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Nov 23 13:03:31 2019 +0100

    Rewrite a bit the dynamic branch loading JS code

 templates/module_detail.html | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/templates/module_detail.html b/templates/module_detail.html
index 9268227b..17c2270e 100644
--- a/templates/module_detail.html
+++ b/templates/module_detail.html
@@ -18,10 +18,13 @@ $(document).ready(function() {
             } else {
                 if (branch_div.attr("class") == "empty") {
                     // Load the branch stats dynamically
-                    branch_div.load("/module/{{ module.name }}/branch/"+this.id+"/");
-                    branch_div.attr("class", "loaded");
+                    branch_div.load(branch_div.data('url'), function() {
+                        branch_div.attr("class", "loaded");
+                        branch_div.slideDown();
+                    });
+                } else {
+                    branch_div.slideDown();
                 }
-                branch_div.slideDown();
                 $(this).children('img').attr("src", "{{ STATIC_URL }}img/open.png");
             }
         });
@@ -99,7 +102,7 @@ $(document).ready(function() {
   <!-- Main loop through branches -->
   {% for branch in branches %}
     <hr>
-    <h2><a href="." class="branch" id="{{ branch.name }}">
+    <h2><a href="." class="branch" id="{{ branch.name|slugify }}">
     {% if forloop.counter < 3 %}
       <img src="{{ STATIC_URL }}img/open.png" /></a>
     {% else %}
@@ -115,11 +118,13 @@ $(document).ready(function() {
     {% endif %}
     </h2>
     {% if forloop.counter < 3 %}
-      <div id="div-{{ branch.name }}" class="loaded">
+      <div id="div-{{ branch.name|slugify }}" class="loaded">
         {% include "branch_detail.html" %}
       </div>
     {% else %}
-      <div id="div-{{ branch.name }}" class="empty" style="display:none;"></div>
+      <div id="div-{{ branch.name|slugify }}" class="empty" style="display:none;"
+           data-url="{% url 'module_branch' module.name branch.name %}">
+      </div>
     {% endif %}
   {% endfor %}
 {% endif %}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]