Quellcode durchsuchen

Added static files for clipboard and htmx

sleepytaco vor 3 Jahren
Ursprung
Commit
63ec8af9c6

Datei-Diff unterdrückt, da er zu groß ist
+ 6 - 0
apps/main/static/clipboard.js/clipboard.min.js


+ 84 - 0
apps/main/static/htmx/extensions/class-tools.js

@@ -0,0 +1,84 @@
+(function(){
+
+    function splitOnWhitespace(trigger) {
+        return trigger.split(/\s+/);
+    }
+
+    function parseClassOperation(trimmedValue) {
+        var split = splitOnWhitespace(trimmedValue);
+        if (split.length > 1) {
+            var operation = split[0];
+            var classDef = split[1].trim();
+            var cssClass;
+            var delay;
+            if (classDef.indexOf(":") > 0) {
+                var splitCssClass = classDef.split(':');
+                cssClass = splitCssClass[0];
+                delay = htmx.parseInterval(splitCssClass[1]);
+            } else {
+                cssClass = classDef;
+                delay = 100;
+            }
+            return {
+                operation:operation,
+                cssClass:cssClass,
+                delay:delay
+            }
+        } else {
+            return null;
+        }
+    }
+
+    function processClassList(elt, classList) {
+        var runs = classList.split("&");
+        for (var i = 0; i < runs.length; i++) {
+            var run = runs[i];
+            var currentRunTime = 0;
+            var classOperations = run.split(",");
+            for (var j = 0; j < classOperations.length; j++) {
+                var value = classOperations[j];
+                var trimmedValue = value.trim();
+                var classOperation = parseClassOperation(trimmedValue);
+                if (classOperation) {
+                    if (classOperation.operation === "toggle") {
+                        setTimeout(function () {
+                            setInterval(function () {
+                                elt.classList[classOperation.operation].call(elt.classList, classOperation.cssClass);
+                            }, classOperation.delay);
+                        }, currentRunTime);
+                        currentRunTime = currentRunTime + classOperation.delay;
+                    } else {
+                        currentRunTime = currentRunTime + classOperation.delay;
+                        setTimeout(function () {
+                            elt.classList[classOperation.operation].call(elt.classList, classOperation.cssClass);
+                        }, currentRunTime);
+                    }
+                }
+            }
+        }
+    }
+
+    function maybeProcessClasses(elt) {
+        if (elt.getAttribute) {
+            var classList = elt.getAttribute("classes") || elt.getAttribute("data-classes");
+            if (classList) {
+                processClassList(elt, classList);
+            }
+        }
+    }
+
+    htmx.defineExtension('class-tools', {
+        onEvent: function (name, evt) {
+            if (name === "htmx:afterProcessNode") {
+                var elt = evt.detail.elt;
+                maybeProcessClasses(elt);
+                if (elt.querySelectorAll) {
+                    var children = elt.querySelectorAll("[classes], [data-classes]");
+                    for (var i = 0; i < children.length; i++) {
+                        maybeProcessClasses(children[i]);
+                    }
+                }
+            }
+        }
+    });
+})();

+ 24 - 0
apps/main/static/htmx/extensions/include-vals.js

@@ -0,0 +1,24 @@
+(function(){
+
+    function mergeObjects(obj1, obj2) {
+        for (var key in obj2) {
+            if (obj2.hasOwnProperty(key)) {
+                obj1[key] = obj2[key];
+            }
+        }
+        return obj1;
+    }
+
+    htmx.defineExtension('include-vals', {
+        onEvent: function (name, evt) {
+            if (name === "htmx:configRequest") {
+                var includeValsElt = htmx.closest(evt.detail.elt, "[include-vals],[data-include-vals]");
+                if (includeValsElt) {
+                    var includeVals = includeValsElt.getAttribute("include-vals") || includeValsElt.getAttribute("data-include-vals");
+                    var valuesToInclude = eval("({" + includeVals + "})");
+                    mergeObjects(evt.detail.parameters, valuesToInclude);
+                }
+            }
+        }
+    });
+})();

+ 137 - 0
apps/main/static/htmx/extensions/preload.js

@@ -0,0 +1,137 @@
+// This adds the "preload" extension to htmx.  By default, this will
+// preload the targets of any tags with `href` or `hx-get` attributes
+// if they also have a `preload` attribute as well.  See documentation
+// for more detauls
+htmx.defineExtension("preload", {
+
+	onEvent: function(name, event) {
+
+		// Only take actions on "htmx:afterProcessNode"
+		if (name !== "htmx:afterProcessNode") {
+			return;
+		}
+
+		// SOME HELPER FUNCTIONS WE'LL NEED ALONG THE WAY
+
+		// attr gets the closest non-empty value from the attribute.
+		var attr = function(node, property) {
+			if (node == undefined) {return undefined;}
+			return node.getAttribute(property) || node.getAttribute("data-" + property) || attr(node.parentElement, property)
+		}
+
+		// load handles the actual HTTP fetch, and uses htmx.ajax in cases where we're
+		// preloading an htmx resource (this sends the same HTTP headers as a regular htmx request)
+		var load = function(node) {
+
+			// Called after a successful AJAX request, to mark the
+			// content as loaded (and prevent additional AJAX calls.)
+			var done = function(html) {
+				node.preloadState = "DONE"
+
+				if (attr(node, "preload-images") == "true") {
+					document.createElement("div").innerHTML = html // create and populate a node to load linked resources, too.
+				}
+			}
+
+			return function() {
+
+				// If this value has already been loaded, then do not try again.
+				if (node.preloadState !== "READY") {
+					return;
+				}
+
+				// Special handling for HX-GET - use built-in htmx.ajax function
+				// so that headers match other htmx requests, then set
+				// node.preloadState = TRUE so that requests are not duplicated
+				// in the future
+				var hxGet = node.getAttribute("hx-get") || node.getAttribute("data-hx-get")
+				if (hxGet) {
+					htmx.ajax("GET", hxGet, {handler:function(elt, info) {
+						done(info.xhr.responseText);
+					}});
+					return;
+				}
+
+				// Otherwise, perform a standard xhr request, then set
+				// node.preloadState = TRUE so that requests are not duplicated
+				// in the future.
+				if (node.getAttribute("href")) {
+					var r = new XMLHttpRequest();
+					r.open("GET", node.getAttribute("href"));
+					r.onload = function() {done(r.responseText);};
+					r.send();
+					return;
+				}
+			}
+		}
+
+		// This function processes a specific node and sets up event handlers.
+		// We'll search for nodes and use it below.
+		var init = function(node) {
+
+			// If this node DOES NOT include a "GET" transaction, then there's nothing to do here.
+			if (node.getAttribute("href") + node.getAttribute("hx-get") + node.getAttribute("data-hx-get") == "") {
+				return;
+			}
+
+			// Guarantee that we only initialize each node once.
+			if (node.preloadState !== undefined) {
+				return;
+			}
+
+			// Get event name from config.
+			var on = attr(node, "preload") || "mousedown"
+
+			// FALL THROUGH to here means we need to add an EventListener
+
+			// Apply the listener to the node
+			node.addEventListener(on, function(evt) {
+				if (node.preloadState === "PAUSE") { // Only add one event listener
+					node.preloadState = "READY"; // Requred for the `load` function to trigger
+
+					// Special handling for "mouseover" events.  Wait 100ms before triggering load.
+					if (on === "mouseover") {
+						window.setTimeout(load(node), 100);
+					} else {
+						load(node)() // all other events trigger immediately.
+					}
+				}
+			})
+
+			// Special handling for certain built-in event handlers
+			switch (on) {
+
+				case "mouseover":
+					// Mirror `touchstart` events (fires immediately)
+					node.addEventListener("touchstart", load(node));
+
+					// WHhen the mouse leaves, immediately disable the preload
+					node.addEventListener("mouseout", function(evt) {
+						if ((evt.target === node) && (node.preloadState === "READY")) {
+							node.preloadState = "PAUSE";
+						}
+					})
+					break;
+
+				case "mousedown":
+					 // Mirror `touchstart` events (fires immediately)
+					node.addEventListener("touchstart", load(node));
+					break;
+			}
+
+			// Mark the node as ready to run.
+			node.preloadState = "PAUSE";
+			htmx.trigger(node, "preload:init") // This event can be used to load content immediately.
+		}
+
+		// Search for all child nodes that have a "preload" attribute
+		event.target.querySelectorAll("[preload]").forEach(function(node) {
+
+			// Initialize the node with the "preload" attribute
+			init(node)
+
+			// Initialize all child elements that are anchors or have `hx-get` (use with care)
+			node.querySelectorAll("a,[hx-get],[data-hx-get").forEach(init)
+		})
+	}
+})

+ 27 - 0
apps/main/static/htmx/extensions/remove-me.js

@@ -0,0 +1,27 @@
+(function(){
+    function maybeRemoveMe(elt) {
+        var timing = elt.getAttribute("remove-me") || elt.getAttribute("data-remove-me");
+        if (timing) {
+            setTimeout(function () {
+                elt.parentElement.removeChild(elt);
+            }, htmx.parseInterval(timing));
+        }
+    }
+
+    htmx.defineExtension('remove-me', {
+        onEvent: function (name, evt) {
+            if (name === "htmx:afterProcessNode") {
+                var elt = evt.detail.elt;
+                if (elt.getAttribute) {
+                    maybeRemoveMe(elt);
+                    if (elt.querySelectorAll) {
+                        var children = elt.querySelectorAll("[remove-me], [data-remove-me");
+                        for (var i = 0; i < children.length; i++) {
+                            maybeRemoveMe(children[i]);
+                        }
+                    }
+                }
+            }
+        }
+    });
+})();

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
apps/main/static/htmx/htmx.min.js


+ 15 - 9
templates/base.html

@@ -22,9 +22,14 @@
 
         </style>
 
+          <!--
           <script src="https://unpkg.com/htmx.org@1.4.1"></script>
-        <script src="https://unpkg.com/htmx.org/dist/ext/class-tools.js"></script>
-            <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
+          <script src="https://unpkg.com/htmx.org/dist/ext/class-tools.js"></script>
+          <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
+
+          -->
+
+        <script src="{% static 'clipboard.js/clipboard.min.js' %}"></script>
 
 
         <link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Open+Sans&display=swap" rel="stylesheet">
@@ -312,7 +317,7 @@
           })
 
 
-                var clipboard = new ClipboardJS('.copy-btn');
+            var clipboard = new ClipboardJS('.copy-btn');
 
 
              // Get the input field
@@ -399,14 +404,15 @@
 
         </script>
 
-        <script type="text/javascript" src="{% static 'jquery3.6.0/js/jquery-3.6.0.min.js' %}"></script>
+        <script src="{% static 'htmx/htmx.min.js' %}"></script>
+        <script src="{% static 'htmx/extensions/class-tools.js' %}"></script>
+        <script src="{% static 'jquery3.6.0/js/jquery-3.6.0.min.js' %}"></script>
+        <script src="{% static 'bootstrap5.0.1/js/bootstrap.bundle.js' %}"></script>
+
         <!--
         <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
+        <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
+        <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
         -->
-        <script type="text/javascript" src="{% static 'bootstrap5.0.1/js/bootstrap.bundle.js' %}"></script>
-    <!--
-    <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
-    <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
-    -->
     </body>
 </html>

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.