From 0362a8d2153571787fe5821c95edcef946b833ed Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Sat, 25 Jul 2026 16:24:39 +0000
Subject: [PATCH] update theme module
---
/dev/null | 440 -------------------------------
.gitignore | 8
exampleSite/go.mod | 2
exampleSite/netlify.toml | 5
static/fonts/LICENSE.txt | 30 ++
exampleSite/.env.example | 6
THIRD-PARTY-LICENSES.md | 257 ++++++++++++++++++
layouts/_shortcodes/chart.html | 6
exampleSite/go.sum | 2
static/js/table.js | 58 ++++
exampleSite/package.json | 1
11 files changed, 364 insertions(+), 451 deletions(-)
diff --git a/.gitignore b/.gitignore
index cd351d3..f8c537b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,10 @@
__generated__
.hugo_build.lock
.claude/
-CLAUDE.md
\ No newline at end of file
+CLAUDE.md
+
+# Secrets — never commit real credentials (.env.example is tracked)
+.env
+
+# Internal audit notes (not for distribution)
+AUDIT-port-and-commercialization.md
\ No newline at end of file
diff --git a/THIRD-PARTY-LICENSES.md b/THIRD-PARTY-LICENSES.md
new file mode 100644
index 0000000..95144c2
--- /dev/null
+++ b/THIRD-PARTY-LICENSES.md
@@ -0,0 +1,257 @@
+# Third-Party Licenses
+
+This product bundles the third-party components listed below. Their copyright
+and license notices are retained here as required by their respective licenses.
+The Compose theme itself is licensed separately (see `LICENSE`).
+
+| Component | Version | License | Copyright | Bundled at |
+|-----------|---------|---------|-----------|------------|
+| Chart.js | 2.9.4 | MIT | © 2014–2020 Chart.js Contributors | `static/js/chart.min.js` |
+| Fuse.js | 6.4.6 | Apache-2.0 | © 2017 Kiro Risk | `assets/js/search/fuse.js` |
+| algoliasearch (lite) | 4.14.3 | MIT | © 2014–2021 Algolia | `assets/js/search/algolia.js` |
+| lite-youtube-embed | — | Apache-2.0 | © Google LLC / Paul Irish | `static/js/lite-yt-embed.js` |
+| Mermaid | 10.x | MIT | © 2014–present Knut Sveidqvist | loaded via CDN in `layouts/_partials/scripts/mermaid.html` |
+| Metropolis (font) | — | The Unlicense (public domain) | Chris Simpson | `static/fonts/Metropolis-*` |
+
+---
+
+## MIT License
+
+Applies to **Chart.js** (© 2014–2020 Chart.js Contributors), **algoliasearch**
+(© 2014–2021 Algolia), and **Mermaid** (© 2014–present Knut Sveidqvist).
+
+```
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+```
+
+---
+
+## Apache License 2.0
+
+Applies to **Fuse.js** (© 2017 Kiro Risk) and **lite-youtube-embed**
+(© Google LLC / Paul Irish).
+
+```
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+```
+
+---
+
+## The Unlicense
+
+Applies to the **Metropolis** typeface by Chris Simpson (`static/fonts/`).
+
+```
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute
+this software, either in source code form or as a compiled binary, for any
+purpose, commercial or non-commercial, and by any means.
+
+In jurisdictions that recognize copyright laws, the author or authors of this
+software dedicate any and all copyright interest in the software to the public
+domain. We make this dedication for the benefit of the public at large and to
+the detriment of our heirs and successors. We intend this dedication to be an
+overt act of relinquishment in perpetuity of all present and future rights to
+this software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
+```
diff --git a/dist/.gitkeep b/dist/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/dist/.gitkeep
+++ /dev/null
diff --git a/exampleSite/.env.example b/exampleSite/.env.example
new file mode 100644
index 0000000..27270bd
--- /dev/null
+++ b/exampleSite/.env.example
@@ -0,0 +1,6 @@
+# TinaCMS credentials — retrieved from your project at https://app.tina.io
+# Copy this file to `.env` and fill in your own values. Never commit `.env`.
+TINA_CLIENT_ID=your-tina-client-id
+TINA_TOKEN=your-tina-read-only-token
+TINA_BRANCH=master
+TINA_SEARCH_TOKEN=your-tina-search-token
diff --git a/exampleSite/go.mod b/exampleSite/go.mod
index 02fd692..8939038 100644
--- a/exampleSite/go.mod
+++ b/exampleSite/go.mod
@@ -2,4 +2,4 @@
go 1.26
-require github.com/onweru/compose v0.0.0-20260311151102-9c9d20205634 // indirect
+require github.com/onweru/compose v0.0.0-20260725154251-88f8de089f26 // indirect
diff --git a/exampleSite/go.sum b/exampleSite/go.sum
index 9b06d69..f8b6f89 100644
--- a/exampleSite/go.sum
+++ b/exampleSite/go.sum
@@ -46,3 +46,5 @@
github.com/onweru/compose v0.0.0-20251102155514-af9906211aee/go.mod h1:2eSBLsKzvKf3r4/vHiKdakIBqDtWACDAqAD7tRdt00o=
github.com/onweru/compose v0.0.0-20260311151102-9c9d20205634 h1:hrpglPpwt6jZA8ep+e3QR91b4QSg6Tr24OkNm/CJcl8=
github.com/onweru/compose v0.0.0-20260311151102-9c9d20205634/go.mod h1:2eSBLsKzvKf3r4/vHiKdakIBqDtWACDAqAD7tRdt00o=
+github.com/onweru/compose v0.0.0-20260725154251-88f8de089f26 h1:b2gt6zpOgGbYhH01EtMxdPqnaVaOvK0soZ/3MQqzqGY=
+github.com/onweru/compose v0.0.0-20260725154251-88f8de089f26/go.mod h1:2eSBLsKzvKf3r4/vHiKdakIBqDtWACDAqAD7tRdt00o=
diff --git a/exampleSite/netlify.toml b/exampleSite/netlify.toml
index 767b379..a20090b 100644
--- a/exampleSite/netlify.toml
+++ b/exampleSite/netlify.toml
@@ -1,5 +1,4 @@
[build.environment]
-DART_SASS_VERSION = "1.102.0"
GO_VERSION = "1.26.5"
HUGO_VERSION = "0.164.0"
NODE_VERSION = "22.23.1"
@@ -10,10 +9,6 @@
publish = "public"
command = """\
tinacms build &&
- curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
- tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
- rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \
- export PATH="${HOME}/.local/dart-sass:${PATH}" && \
git config core.quotepath false && \
hugo --gc --minify --baseURL "${URL}"
"""
diff --git a/exampleSite/package.json b/exampleSite/package.json
index c7e97b1..601f28e 100644
--- a/exampleSite/package.json
+++ b/exampleSite/package.json
@@ -24,7 +24,6 @@
"@tinacms/auth": "^1.1.3",
"@tinacms/cli": "^2.5.6",
"@types/node": "^24.9.2",
- "next-tinacms-cloudinary": "^27.0.2",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"tinacms": "^3.11.0"
diff --git a/layouts/_shortcodes/chart.html b/layouts/_shortcodes/chart.html
index 780e9e8..03ff6a7 100644
--- a/layouts/_shortcodes/chart.html
+++ b/layouts/_shortcodes/chart.html
@@ -25,18 +25,18 @@
{{- end }}
{{- if in $charts "table" }}
-<script src='{{ absURL "js/w3.js" }}'></script>
+<script src='{{ absURL "js/table.js" }}'></script>
<div class="table_wrap">
{{- if not (in $charts "noFilter") }}
<p>
- <input oninput="w3.filterHTML('#chartTable', '.row', this.value)" class="form_search search_field forminput"
+ <input oninput="composeTable.filter('#chartTable', '.row', this.value)" class="form_search search_field forminput"
placeholder="Filter Table Values">
</p>
{{- end }}
<table id="chartTable">
<thead>
{{- range $index, $title := $data.columnTitles }}
- <th onclick="w3.sortHTML('#chartTable', '.row', 'td:nth-child({{ add $index 1 }})')">{{ $title }} {{ partial
+ <th onclick="composeTable.sort('#chartTable', '.row', 'td:nth-child({{ add $index 1 }})')">{{ $title }} {{ partial
"sprite" (dict "icon" "sort") . }}</th>
{{- end }}
</thead>
diff --git a/static/fonts/LICENSE.txt b/static/fonts/LICENSE.txt
new file mode 100644
index 0000000..c6e2285
--- /dev/null
+++ b/static/fonts/LICENSE.txt
@@ -0,0 +1,30 @@
+Metropolis Typeface
+Designed by Chris Simpson
+Released into the public domain under The Unlicense.
+Source: https://github.com/dephiny/metropolis (original: https://fontsarena.com/metropolis-by-chris-simpson/)
+
+Commercial use, redistribution, and modification are explicitly permitted.
+
+---
+
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute
+this software, either in source code form or as a compiled binary, for any
+purpose, commercial or non-commercial, and by any means.
+
+In jurisdictions that recognize copyright laws, the author or authors of this
+software dedicate any and all copyright interest in the software to the public
+domain. We make this dedication for the benefit of the public at large and to
+the detriment of our heirs and successors. We intend this dedication to be an
+overt act of relinquishment in perpetuity of all present and future rights to
+this software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
diff --git a/static/js/table.js b/static/js/table.js
new file mode 100644
index 0000000..9b7e5d6
--- /dev/null
+++ b/static/js/table.js
@@ -0,0 +1,58 @@
+/*!
+ * Compose theme — chart-table filter/sort.
+ * Self-authored replacement for the two W3Schools w3.js functions
+ * (filterHTML / sortHTML) previously used by the `chart` shortcode.
+ * MIT — part of the Compose theme; no third-party code.
+ *
+ * Behaviour is a faithful port of the originals:
+ * - filter: case-insensitive substring match on each row's innerHTML.
+ * - sort: lexicographic (lowercased) sort by a cell selector, toggling
+ * ascending -> descending when the column is already ascending.
+ */
+(function () {
+ "use strict";
+
+ function filter(tableSel, rowSel, term) {
+ var needle = (term || "").toUpperCase();
+ var rows = document.querySelectorAll(rowSel);
+ for (var i = 0; i < rows.length; i++) {
+ var match = rows[i].innerHTML.toUpperCase().indexOf(needle) > -1;
+ rows[i].style.display = match ? "" : "none";
+ }
+ }
+
+ function sort(tableSel, rowSel, cellSel) {
+ var table = document.querySelector(tableSel);
+ if (!table) {
+ return;
+ }
+ var rows = Array.prototype.slice.call(table.querySelectorAll(rowSel));
+ if (rows.length < 2) {
+ return;
+ }
+ function value(row) {
+ var cell = cellSel ? row.querySelector(cellSel) : row;
+ return cell ? cell.innerHTML.toLowerCase() : "";
+ }
+ var ascending = rows.slice().sort(function (a, b) {
+ var x = value(a), y = value(b);
+ return x < y ? -1 : x > y ? 1 : 0;
+ });
+ // Match w3.sortHTML: if the column is already ascending, sort descending.
+ var alreadyAscending = rows.every(function (row, i) {
+ return row === ascending[i];
+ });
+ var ordered = alreadyAscending
+ ? rows.slice().sort(function (a, b) {
+ var x = value(a), y = value(b);
+ return x < y ? 1 : x > y ? -1 : 0;
+ })
+ : ascending;
+ var parent = rows[0].parentNode;
+ ordered.forEach(function (row) {
+ parent.appendChild(row);
+ });
+ }
+
+ window.composeTable = { filter: filter, sort: sort };
+})();
diff --git a/static/js/w3.js b/static/js/w3.js
deleted file mode 100644
index f638315..0000000
--- a/static/js/w3.js
+++ /dev/null
@@ -1,440 +0,0 @@
-/* W3.JS 1.03 December 2017 by w3schools.com */
-"use strict";
-var w3 = {};
-w3.hide = function (sel) {
- w3.hideElements(w3.getElements(sel));
-};
-w3.hideElements = function (elements) {
- var i, l = elements.length;
- for (i = 0; i < l; i++) {
- w3.hideElement(elements[i]);
- }
-};
-w3.hideElement = function (element) {
- w3.styleElement(element, "display", "none");
-};
-w3.show = function (sel, a) {
- var elements = w3.getElements(sel);
- if (a) {w3.hideElements(elements);}
- w3.showElements(elements);
-};
-w3.showElements = function (elements) {
- var i, l = elements.length;
- for (i = 0; i < l; i++) {
- w3.showElement(elements[i]);
- }
-};
-w3.showElement = function (element) {
- w3.styleElement(element, "display", "block");
-};
-w3.addStyle = function (sel, prop, val) {
- w3.styleElements(w3.getElements(sel), prop, val);
-};
-w3.styleElements = function (elements, prop, val) {
- var i, l = elements.length;
- for (i = 0; i < l; i++) {
- w3.styleElement(elements[i], prop, val);
- }
-};
-w3.styleElement = function (element, prop, val) {
- element.style.setProperty(prop, val);
-};
-w3.toggleShow = function (sel) {
- var i, x = w3.getElements(sel), l = x.length;
- for (i = 0; i < l; i++) {
- if (x[i].style.display == "none") {
- w3.styleElement(x[i], "display", "block");
- } else {
- w3.styleElement(x[i], "display", "none");
- }
- }
-};
-w3.addClass = function (sel, name) {
- w3.addClassElements(w3.getElements(sel), name);
-};
-w3.addClassElements = function (elements, name) {
- var i, l = elements.length;
- for (i = 0; i < l; i++) {
- w3.addClassElement(elements[i], name);
- }
-};
-w3.addClassElement = function (element, name) {
- var i, arr1, arr2;
- arr1 = element.className.split(" ");
- arr2 = name.split(" ");
- for (i = 0; i < arr2.length; i++) {
- if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
- }
-};
-w3.removeClass = function (sel, name) {
- w3.removeClassElements(w3.getElements(sel), name);
-};
-w3.removeClassElements = function (elements, name) {
- var i, l = elements.length, arr1, arr2, j;
- for (i = 0; i < l; i++) {
- w3.removeClassElement(elements[i], name);
- }
-};
-w3.removeClassElement = function (element, name) {
- var i, arr1, arr2;
- arr1 = element.className.split(" ");
- arr2 = name.split(" ");
- for (i = 0; i < arr2.length; i++) {
- while (arr1.indexOf(arr2[i]) > -1) {
- arr1.splice(arr1.indexOf(arr2[i]), 1);
- }
- }
- element.className = arr1.join(" ");
-};
-w3.toggleClass = function (sel, c1, c2) {
- w3.toggleClassElements(w3.getElements(sel), c1, c2);
-};
-w3.toggleClassElements = function (elements, c1, c2) {
- var i, l = elements.length;
- for (i = 0; i < l; i++) {
- w3.toggleClassElement(elements[i], c1, c2);
- }
-};
-w3.toggleClassElement = function (element, c1, c2) {
- var t1, t2, t1Arr, t2Arr, j, arr, allPresent;
- t1 = (c1 || "");
- t2 = (c2 || "");
- t1Arr = t1.split(" ");
- t2Arr = t2.split(" ");
- arr = element.className.split(" ");
- if (t2Arr.length == 0) {
- allPresent = true;
- for (j = 0; j < t1Arr.length; j++) {
- if (arr.indexOf(t1Arr[j]) == -1) {allPresent = false;}
- }
- if (allPresent) {
- w3.removeClassElement(element, t1);
- } else {
- w3.addClassElement(element, t1);
- }
- } else {
- allPresent = true;
- for (j = 0; j < t1Arr.length; j++) {
- if (arr.indexOf(t1Arr[j]) == -1) {allPresent = false;}
- }
- if (allPresent) {
- w3.removeClassElement(element, t1);
- w3.addClassElement(element, t2);
- } else {
- w3.removeClassElement(element, t2);
- w3.addClassElement(element, t1);
- }
- }
-};
-w3.getElements = function (id) {
- if (typeof id == "object") {
- return [id];
- } else {
- return document.querySelectorAll(id);
- }
-};
-w3.filterHTML = function(id, sel, filter) {
- var a, b, c, i, ii, iii, hit;
- a = w3.getElements(id);
- for (i = 0; i < a.length; i++) {
- b = w3.getElements(sel);
- for (ii = 0; ii < b.length; ii++) {
- hit = 0;
- if (b[ii].innerHTML.toUpperCase().indexOf(filter.toUpperCase()) > -1) {
- hit = 1;
- }
- c = b[ii].getElementsByTagName("*");
- for (iii = 0; iii < c.length; iii++) {
- if (c[iii].innerHTML.toUpperCase().indexOf(filter.toUpperCase()) > -1) {
- hit = 1;
- }
- }
- if (hit == 1) {
- b[ii].style.display = "";
- } else {
- b[ii].style.display = "none";
- }
- }
- }
-};
-w3.sortHTML = function(id, sel, sortvalue) {
- var a, b, i, ii, y, bytt, v1, v2, cc, j;
- a = w3.getElements(id);
- for (i = 0; i < a.length; i++) {
- for (j = 0; j < 2; j++) {
- cc = 0;
- y = 1;
- while (y == 1) {
- y = 0;
- b = a[i].querySelectorAll(sel);
- for (ii = 0; ii < (b.length - 1); ii++) {
- bytt = 0;
- if (sortvalue) {
- v1 = b[ii].querySelector(sortvalue).innerHTML.toLowerCase();
- v2 = b[ii + 1].querySelector(sortvalue).innerHTML.toLowerCase();
- } else {
- v1 = b[ii].innerHTML.toLowerCase();
- v2 = b[ii + 1].innerHTML.toLowerCase();
- }
- if ((j == 0 && (v1 > v2)) || (j == 1 && (v1 < v2))) {
- bytt = 1;
- break;
- }
- }
- if (bytt == 1) {
- b[ii].parentNode.insertBefore(b[ii + 1], b[ii]);
- y = 1;
- cc++;
- }
- }
- if (cc > 0) {break;}
- }
- }
-};
-w3.sortHTMLbyNumber = function(id, sel, sortvalue) {
- var a, b, i, ii, y, bytt, v1, v2, cc, j;
- a = w3.getElements(id);
- for (i = 0; i < a.length; i++) {
- for (j = 0; j < 2; j++) {
- cc = 0;
- y = 1;
- while (y == 1) {
- y = 0;
- b = a[i].querySelectorAll(sel);
- for (ii = 0; ii < (b.length - 1); ii++) {
- bytt = 0;
- if (sortvalue) {
- v1 = b[ii].querySelector(sortvalue).innerHTML.toLowerCase();
- v2 = b[ii + 1].querySelector(sortvalue).innerHTML.toLowerCase();
- } else {
- v1 = b[ii].innerHTML.toLowerCase();
- v2 = b[ii + 1].innerHTML.toLowerCase();
- }
- var i1 = parseInt(v1, 10);
- var i2 = parseInt(v2, 10);
- if(Number.isNaN(i1)) {
- i1 = -1;
- }
- if(Number.isNaN(i2)) {
- i2 = -1;
- }
- if ((j == 0 && (i1 > i2)) || (j == 1 && (i1 < i2))) {
- bytt = 1;
- break;
- }
- }
- if (bytt == 1) {
- b[ii].parentNode.insertBefore(b[ii + 1], b[ii]);
- y = 1;
- cc++;
- }
- }
- if (cc > 0) {break;}
- }
- }
-};
-w3.slideshow = function (sel, ms, func) {
- var i, ss, x = w3.getElements(sel), l = x.length;
- ss = {};
- ss.current = 1;
- ss.x = x;
- ss.ondisplaychange = func;
- if (!isNaN(ms) || ms == 0) {
- ss.milliseconds = ms;
- } else {
- ss.milliseconds = 1000;
- }
- ss.start = function() {
- ss.display(ss.current)
- if (ss.ondisplaychange) {ss.ondisplaychange();}
- if (ss.milliseconds > 0) {
- window.clearTimeout(ss.timeout);
- ss.timeout = window.setTimeout(ss.next, ss.milliseconds);
- }
- };
- ss.next = function() {
- ss.current += 1;
- if (ss.current > ss.x.length) {ss.current = 1;}
- ss.start();
- };
- ss.previous = function() {
- ss.current -= 1;
- if (ss.current < 1) {ss.current = ss.x.length;}
- ss.start();
- };
- ss.display = function (n) {
- w3.styleElements(ss.x, "display", "none");
- w3.styleElement(ss.x[n - 1], "display", "block");
- }
- ss.start();
- return ss;
-};
-w3.includeHTML = function(cb) {
- var z, i, elmnt, file, xhttp;
- z = document.getElementsByTagName("*");
- for (i = 0; i < z.length; i++) {
- elmnt = z[i];
- file = elmnt.getAttribute("w3-include-html");
- if (file) {
- xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4) {
- if (this.status == 200) {elmnt.innerHTML = this.responseText;}
- if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
- elmnt.removeAttribute("w3-include-html");
- w3.includeHTML(cb);
- }
- }
- xhttp.open("GET", file, true);
- xhttp.send();
- return;
- }
- }
- if (cb) cb();
-};
-w3.getHttpData = function (file, func) {
- w3.http(file, function () {
- if (this.readyState == 4 && this.status == 200) {
- func(this.responseText);
- }
- });
-};
-w3.getHttpObject = function (file, func) {
- w3.http(file, function () {
- if (this.readyState == 4 && this.status == 200) {
- func(JSON.parse(this.responseText));
- }
- });
-};
-w3.displayHttp = function (id, file) {
- w3.http(file, function () {
- if (this.readyState == 4 && this.status == 200) {
- w3.displayObject(id, JSON.parse(this.responseText));
- }
- });
-};
-w3.http = function (target, readyfunc, xml, method) {
- var httpObj;
- if (!method) {method = "GET"; }
- if (window.XMLHttpRequest) {
- httpObj = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- httpObj = new ActiveXObject("Microsoft.XMLHTTP");
- }
- if (httpObj) {
- if (readyfunc) {httpObj.onreadystatechange = readyfunc;}
- httpObj.open(method, target, true);
- httpObj.send(xml);
- }
-};
-w3.getElementsByAttribute = function (x, att) {
- var arr = [], arrCount = -1, i, l, y = x.getElementsByTagName("*"), z = att.toUpperCase();
- l = y.length;
- for (i = -1; i < l; i += 1) {
- if (i == -1) {y[i] = x;}
- if (y[i].getAttribute(z) !== null) {arrCount += 1; arr[arrCount] = y[i];}
- }
- return arr;
-};
-w3.dataObject = {},
-w3.displayObject = function (id, data) {
- var htmlObj, htmlTemplate, html, arr = [], a, l, rowClone, x, j, i, ii, cc, repeat, repeatObj, repeatX = "";
- htmlObj = document.getElementById(id);
- htmlTemplate = init_template(id, htmlObj);
- html = htmlTemplate.cloneNode(true);
- arr = w3.getElementsByAttribute(html, "w3-repeat");
- l = arr.length;
- for (j = (l - 1); j >= 0; j -= 1) {
- cc = arr[j].getAttribute("w3-repeat").split(" ");
- if (cc.length == 1) {
- repeat = cc[0];
- } else {
- repeatX = cc[0];
- repeat = cc[2];
- }
- arr[j].removeAttribute("w3-repeat");
- repeatObj = data[repeat];
- if (repeatObj && typeof repeatObj == "object" && repeatObj.length != "undefined") {
- i = 0;
- for (x in repeatObj) {
- i += 1;
- rowClone = arr[j];
- rowClone = w3_replace_curly(rowClone, "element", repeatX, repeatObj[x]);
- a = rowClone.attributes;
- for (ii = 0; ii < a.length; ii += 1) {
- a[ii].value = w3_replace_curly(a[ii], "attribute", repeatX, repeatObj[x]).value;
- }
- (i === repeatObj.length) ? arr[j].parentNode.replaceChild(rowClone, arr[j]) : arr[j].parentNode.insertBefore(rowClone, arr[j]);
- }
- } else {
- console.log("w3-repeat must be an array. " + repeat + " is not an array.");
- continue;
- }
- }
- html = w3_replace_curly(html, "element");
- htmlObj.parentNode.replaceChild(html, htmlObj);
- function init_template(id, obj) {
- var template;
- template = obj.cloneNode(true);
- if (w3.dataObject.hasOwnProperty(id)) {return w3.dataObject[id];}
- w3.dataObject[id] = template;
- return template;
- }
- function w3_replace_curly(elmnt, typ, repeatX, x) {
- var value, rowClone, pos1, pos2, originalHTML, lookFor, lookForARR = [], i, cc, r;
- rowClone = elmnt.cloneNode(true);
- pos1 = 0;
- while (pos1 > -1) {
- originalHTML = (typ == "attribute") ? rowClone.value : rowClone.innerHTML;
- pos1 = originalHTML.indexOf("{{", pos1);
- if (pos1 === -1) {break;}
- pos2 = originalHTML.indexOf("}}", pos1 + 1);
- lookFor = originalHTML.substring(pos1 + 2, pos2);
- lookForARR = lookFor.split("||");
- value = undefined;
- for (i = 0; i < lookForARR.length; i += 1) {
- lookForARR[i] = lookForARR[i].replace(/^\s+|\s+$/gm, ''); //trim
- if (x) {value = x[lookForARR[i]];}
- if (value == undefined && data) {value = data[lookForARR[i]];}
- if (value == undefined) {
- cc = lookForARR[i].split(".");
- if (cc[0] == repeatX) {value = x[cc[1]]; }
- }
- if (value == undefined) {
- if (lookForARR[i] == repeatX) {value = x;}
- }
- if (value == undefined) {
- if (lookForARR[i].substr(0, 1) == '"') {
- value = lookForARR[i].replace(/"/g, "");
- } else if (lookForARR[i].substr(0,1) == "'") {
- value = lookForARR[i].replace(/'/g, "");
- }
- }
- if (value != undefined) {break;}
- }
- if (value != undefined) {
- r = "{{" + lookFor + "}}";
- if (typ == "attribute") {
- rowClone.value = rowClone.value.replace(r, value);
- } else {
- w3_replace_html(rowClone, r, value);
- }
- }
- pos1 = pos1 + 1;
- }
- return rowClone;
- }
- function w3_replace_html(a, r, result) {
- var b, l, i, a, x, j;
- if (a.hasAttributes()) {
- b = a.attributes;
- l = b.length;
- for (i = 0; i < l; i += 1) {
- if (b[i].value.indexOf(r) > -1) {b[i].value = b[i].value.replace(r, result);}
- }
- }
- x = a.getElementsByTagName("*");
- l = x.length;
- a.innerHTML = a.innerHTML.replace(r, result);
- }
-};
\ No newline at end of file
--
Gitblit v1.10.0