Änderungen von Dokument Sandbox
Zuletzt geändert von Holger Engels am 2024/01/26 15:58
Von Version 21.3
bearbeitet von Holger Engels
am 2023/11/15 12:00
am 2023/11/15 12:00
Änderungskommentar:
Es gibt keinen Kommentar für diese Version
Auf Version 9.1
bearbeitet von Holger Engels
am 2023/11/08 06:52
am 2023/11/08 06:52
Änderungskommentar:
Es gibt keinen Kommentar für diese Version
Zusammenfassung
-
Seiteneigenschaften (1 geändert, 0 hinzugefügt, 0 gelöscht)
Details
- Seiteneigenschaften
-
- Inhalt
-
... ... @@ -99,8 +99,45 @@ 99 99 100 100 [[image:XWikiLogo.png]] 101 101 102 -= =Orphaned Pages ==102 += Makros = 103 103 104 +Makros bieten die Möglichkeit, das Aussehen von Wiki-Seiten zu verbessern und stellen zusätzliche Funktionalitäten in der Seite zur Verfügung. Hier sind zwei Beispiele, wie Makros die Inhalte verbessern können: 105 + 106 +{{html clean="false"}} 107 +<script> 108 + customElements.define("star-rating", class extends HTMLElement { 109 + set rating(rate) { 110 + if (!String(rate).includes("%")) rate = Number(rate) / this.stars * 100 + "%"; 111 + this.querySelector(":nth-child(2)").setAttribute("width", rate); //2nd rect 112 + } 113 + set value(v) { 114 + this.setAttribute("rating", v); 115 + } 116 + connectedCallback() { 117 + let {bgcolor,stars,nocolor,color,rating} = this.attributes; 118 + let repeat = (count, func) => Array(count).fill().map(func); 119 + this.stars = ~~stars.value || 5; 120 + this.innerHTML = `<svg viewBox="0 0 ${this.stars*100} 100" style=cursor:pointer>` + 121 + `<rect height=100 fill=${nocolor.value} width=100% />` + 122 + `<rect height=100 fill=${color.value} />` + 123 + repeat(this.stars , (i, n) => `<path fill=${bgcolor.value} d="m${ n*100 } 0h102v100h-102v-100m91 42a6 6 90 00-4-10l-22-1a1 1 90 01-1 0l-8-21a6 6 90 00-11 0l-8 21a1 1 90 01-1 1l-22 1a6 6 90 00-4 10l18 14a1 1 90 010 1l-6 22a6 6 90 008 6l19-13a1 1 90 011 0l19 13a6 6 90 006 0a6 6 90 002-6l-6-22a1 1 90 010-1z"/>`) + 124 + repeat(this.stars * 2, (i, n) => `<rect x=${ n*50 } n=${n} opacity=0 width=50 height=100 ` + 125 + ` onclick="this.closest('star-rating').value=${(n+1)/2}; this.closest('star-rating').dispatchEvent(new Event('click'))" ` + 126 + ` onmouseover="this.closest('star-rating').rating=${(n+1)/2}"/>`) + 127 + "</svg>"; 128 + this.rating = rating.value; 129 + this.addEventListener('mouseleave', (e) => { 130 + if (e.target.tagName === 'STAR-RATING') { 131 + e.target.rating = e.target.getAttribute("rating") 132 + } 133 + }) 134 + } 135 + }); 136 +</script> 137 +{{/html}} 138 + 139 + 140 + 104 104 {{velocity filter="none"}} 105 105 {{html clean="false" wiki="true"}} 106 106 #set ($query = "where (doc.parent is null or doc.parent='') and doc.fullName != 'Main.WebHome' order by doc.name asc") ... ... @@ -117,42 +117,35 @@ 117 117 {{/velocity}} 118 118 119 119 120 -== Rating Tests == 121 - 122 -{{velocity}} 123 -#set($ref = $doc.space + "^" + "test") 124 -#set($average = $services.ratings.aufgaben.getAverageRating($ref)) 125 -#set($myv = $services.ratings.aufgaben.getRating($ref)) 126 -$ref = $average.get().averageVote 127 -$myv.get().totalVote 128 -{{html clean="false" wiki="true"}} 129 -<style> 130 -star-rating { display: inline-block; width: 120px } 131 -</style> 132 -<star-rating stars=5 rating="$average.get().averageVote" rid="test" bgcolor="white" nocolor="lightgrey" color="gold" onclick="rated.call(this)"></star-rating> 133 -{{/html}} 134 -{{/velocity}} 135 - 136 136 {{html clean="false"}} 137 137 <script> 138 - function rated() { 139 - console.log(XWiki.currentDocument.space + ".WebHome") 140 - console.log(this.getAttribute("rating")); 141 - sendRate(this.getAttribute("rid"), parseInt(this.getAttribute("rating"))); 142 - } 143 - var sendRate = function (rid, vote) { 144 - fetch(new XWiki.Document('WebHome', 'Macros.Aufgabenbewertung').getURL('get') + "?outputSyntax=plain", { 145 - method: "POST", 146 - headers: { "Content-Type": "application/json"}, 147 - body: JSON.stringify({ 148 - vote: vote, 149 - doc: XWiki.currentDocument.space + ".WebHome", 150 - id: rid, 151 - form_token: document.documentElement.getAttribute("data-xwiki-form-token") 152 - }) 153 - }).then(data => { 154 - console.log(data.json()) 159 + customElements.define("star-rating", class extends HTMLElement { 160 + set rating(rate) { 161 + if (!String(rate).includes("%")) rate = Number(rate) / this.stars * 100 + "%"; 162 + this.querySelector(":nth-child(2)").setAttribute("width", rate); //2nd rect 163 + } 164 + set value(v) { 165 + this.setAttribute("rating", v); 166 + } 167 + connectedCallback() { 168 + let {bgcolor,stars,nocolor,color,rating} = this.attributes; 169 + let repeat = (count, func) => Array(count).fill().map(func); 170 + this.stars = ~~stars.value || 5; 171 + this.innerHTML = `<svg viewBox="0 0 ${this.stars*100} 100" style=cursor:pointer>` + 172 + `<rect height=100 fill=${nocolor.value} width=100% />` + 173 + `<rect height=100 fill=${color.value} />` + 174 + repeat(this.stars , (i, n) => `<path fill=${bgcolor.value} d="m${ n*100 } 0h102v100h-102v-100m91 42a6 6 90 00-4-10l-22-1a1 1 90 01-1 0l-8-21a6 6 90 00-11 0l-8 21a1 1 90 01-1 1l-22 1a6 6 90 00-4 10l18 14a1 1 90 010 1l-6 22a6 6 90 008 6l19-13a1 1 90 011 0l19 13a6 6 90 006 0a6 6 90 002-6l-6-22a1 1 90 010-1z"/>`) + 175 + repeat(this.stars * 2, (i, n) => `<rect x=${ n*50 } n=${n} opacity=0 width=50 height=100 ` + 176 + ` onclick="this.closest('star-rating').value=${(n+1)/2}; this.closest('star-rating').dispatchEvent(new Event('click'))" ` + 177 + ` onmouseover="this.closest('star-rating').rating=${(n+1)/2}"/>`) + 178 + "</svg>"; 179 + this.rating = rating.value; 180 + this.addEventListener('mouseleave', (e) => { 181 + if (e.target.tagName === 'STAR-RATING') { 182 + e.target.rating = e.target.getAttribute("rating") 183 + } 184 + }) 185 + } 155 155 }); 156 - } 157 157 </script> 158 158 {{/html}}