Skip to content

Commit 1b9e71b

Browse files
authored
Merge pull request #134 from NGO-Algorithm-Audit/feature/structural_edits
Feature/structural edits
2 parents fad9bda + 43bb0ca commit 1b9e71b

File tree

377 files changed

+127348
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

377 files changed

+127348
-496
lines changed

content/english/technical-tools/documentation/classification-quick-scan.md

Lines changed: 144 additions & 215 deletions
Large diffs are not rendered by default.

content/nederlands/technical-tools/documentation/classification-quick-scan.md

Lines changed: 156 additions & 275 deletions
Large diffs are not rendered by default.

layouts/shortcodes/dynamic_form_engine.html

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ <h3>{{.title}}</h3>
2828
{{ $visibilityCondition := "" }}
2929
{{ range .visible_when_or }}
3030
{{ range .visible_when_and }}
31+
{{ $compareSign := "==" }}
32+
{{ if .compareSign }}
33+
{{ $compareSign = .compareSign }}
34+
{{ end }}
3135
{{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" .value | printf "%s" }}
32-
{{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" "=" | printf "%s" }}
36+
{{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" $compareSign | printf "%s" }}
3337
{{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" .identifier | printf "%s" }}
3438
{{ $visibilityCondition = printf "%s" $visibilityCondition | printf "%s%s" "&&" | printf "%s" }}
3539
{{ end }}
@@ -166,8 +170,12 @@ <h6 class="d-inline ml-1" >{{.title}}</h6>
166170
<script>
167171
document.addEventListener("DOMContentLoaded", function (event) {
168172

173+
var valuesAreEqual = function (inputValue, value) {
174+
return inputValue === value || (value === '*' && inputValue);
175+
}
176+
169177
var calculateVisibleFields = function () {
170-
// this is what the data attribute looks like: data-show-when="||&&data1=medium&&data2=medium||&&data1=low"
178+
// this is what the data attribute looks like: data-show-when=="||&&data1==medium&&data2=medium||&&data1==low"
171179
// This field should be hidden when no input is selected, and shown if either data 1 and data 2 are medium or data 1 is low.
172180
$('.score-card__question').each(function () {
173181
const showWhen = $(this).attr('data-show-when');
@@ -183,14 +191,26 @@ <h6 class="d-inline ml-1" >{{.title}}</h6>
183191
if (andCondition.indexOf('=') === -1) {
184192
return;
185193
}
186-
const [name, value] = andCondition.split('=');
194+
// And condition can be either a==b or a!=b
195+
const andCondSplitted = andCondition.split('=');
196+
let name = andCondSplitted[0];
197+
let value = andCondSplitted[andCondSplitted.length - 1];
198+
const checkForEquals = andCondSplitted.length > 2;
199+
const checkForUnequal = !checkForEquals;
200+
if (!checkForEquals) {
201+
// clean up name when name is a!
202+
name = name.substring(0, name.length - 1);
203+
}
204+
187205
// Check for radio button
188206
let input = document.querySelector(`.score-card__question:not(.d-none) input[name=${name}]:checked`);
189207
// Check for checkbox
190208
if (!input) {
191209
input = document.querySelector(`.score-card__question:not(.d-none) input[id=${name}]:checked`);
192210
}
193-
if (!input || input.value !== value) {
211+
if (!input
212+
|| (checkForEquals && !valuesAreEqual(input.value, value))
213+
|| (checkForUnequal && valuesAreEqual(input.value, value))) {
194214
andShow = false;
195215
}
196216
});

layouts/shortcodes/embed_pdf.html

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
{{- if not ($.Page.Scratch.Get "embed-pdf-count") -}}
2+
3+
<script type="text/javascript" src= '/js/pdf-js/build/pdf.js'></script>
4+
5+
<style>
6+
#embed-pdf-container {
7+
position: relative;
8+
width: 100%;
9+
height: auto;
10+
min-height: 20vh;
11+
/* overflow-y:scroll; */
12+
}
13+
14+
.pdf-canvas {
15+
border: 1px solid black;
16+
direction: ltr;
17+
width: 100%;
18+
height: auto;
19+
display: none;
20+
}
21+
22+
#the-canvas {
23+
border: 1px solid black;
24+
direction: ltr;
25+
width: 100%;
26+
height: auto;
27+
display: none;
28+
}
29+
30+
31+
.pdf-loadingWrapper {
32+
display: none;
33+
justify-content: center;
34+
align-items: center;
35+
width: 100%;
36+
height: 350px;
37+
}
38+
39+
.pdf-loading {
40+
display: inline-block;
41+
width: 50px;
42+
height: 50px;
43+
border: 3px solid #d2d0d0;;
44+
border-radius: 50%;
45+
border-top-color: #383838;
46+
animation: spin 1s ease-in-out infinite;
47+
-webkit-animation: spin 1s ease-in-out infinite;
48+
}
49+
50+
{{/* Download link */}}
51+
52+
53+
54+
#overlayText {
55+
word-wrap: break-word;
56+
display: grid;
57+
justify-content: end;
58+
}
59+
60+
#overlayText a {
61+
position: relative;
62+
top: 10px;
63+
right: 4px;
64+
color: #000;
65+
margin: auto;
66+
background-color: #eeeeee;
67+
padding: 0.3em 1em;
68+
border: solid 2px;
69+
border-radius: 12px;
70+
border-color: #00000030;
71+
text-decoration: none;
72+
}
73+
74+
#overlayText svg {
75+
height: clamp(1em, 2vw, 1.4em);
76+
width: clamp(1em, 2vw, 1.4em);
77+
}
78+
79+
80+
81+
@keyframes spin {
82+
to { -webkit-transform: rotate(360deg); }
83+
}
84+
@-webkit-keyframes spin {
85+
to { -webkit-transform: rotate(360deg); }
86+
}
87+
</style>
88+
{{- end -}}
89+
90+
{{- $.Page.Scratch.Add "embed-pdf-count" 1 -}}
91+
<div class="embed-pdf-container mt-5" id="embed-pdf-container-{{ substr (.Get "url" | md5) 0 8 }}">
92+
<div class="pdf-loadingWrapper" id="pdf-loadingWrapper-{{ substr (.Get "url" | md5) 0 8 }}">
93+
<div class="pdf-loading" id="pdf-loading-{{ substr (.Get "url" | md5) 0 8 }}"></div>
94+
</div>
95+
<canvas class="pdf-canvas" id="pdf-canvas-{{ substr (.Get "url" | md5) 0 8 }}"></canvas>
96+
</div>
97+
98+
<div class="pdf-paginator mt-1 mb-5" id="pdf-paginator-{{ substr (.Get "url" | md5) 0 8 }}">
99+
<button class="btn py-1" id="pdf-prev-{{ substr (.Get "url" | md5) 0 8 }}">Previous</button>
100+
<button class="btn py-1" id="pdf-next-{{ substr (.Get "url" | md5) 0 8 }}">Next</button> &nbsp; &nbsp;
101+
<span>
102+
<span class="pdf-pagenum" id="pdf-pagenum-{{ substr (.Get "url" | md5) 0 8 }}"></span> / <span class="pdf-pagecount" id="pdf-pagecount-{{ substr (.Get "url" | md5) 0 8 }}"></span>
103+
</span>
104+
<a class="pdf-source" id="pdf-source-{{ substr (.Get "url" | md5) 0 8 }}" href="{{ .Get "url" }}">[pdf]</a>
105+
</div>
106+
107+
<noscript>
108+
View the PDF file <a class="pdf-source" id="pdf-source-noscript-{{ substr (.Get "url" | md5) 0 8 }}" href="{{ .Get "url" }}">here</a>.
109+
</noscript>
110+
111+
<script type="text/javascript">
112+
(function(){
113+
var url = '{{ .Get "url" }}';
114+
115+
var hidePaginator = "{{ .Get "hidePaginator" }}" === "true";
116+
var hideLoader = "{{ .Get "hideLoader" }}" === "true";
117+
var selectedPageNum = parseInt("{{ .Get "renderPageNum" }}") || 1;
118+
119+
// Loaded via <script> tag, create shortcut to access PDF.js exports.
120+
var pdfjsLib = window['pdfjs-dist/build/pdf'];
121+
122+
// The workerSrc property shall be specified.
123+
if (pdfjsLib.GlobalWorkerOptions.workerSrc == '')
124+
pdfjsLib.GlobalWorkerOptions.workerSrc = "{{.Site.BaseURL}}" + 'js/pdf-js/build/pdf.worker.js';
125+
126+
// Change the Scale value for lower or higher resolution.
127+
var pdfDoc = null,
128+
pageNum = selectedPageNum,
129+
pageRendering = false,
130+
pageNumPending = null,
131+
scale = 3,
132+
canvas = document.getElementById('pdf-canvas-{{ substr (.Get "url" | md5) 0 8 }}'),
133+
ctx = canvas.getContext('2d'),
134+
paginator = document.getElementById("pdf-paginator-{{ substr (.Get "url" | md5) 0 8 }}"),
135+
loadingWrapper = document.getElementById('pdf-loadingWrapper-{{ substr (.Get "url" | md5) 0 8 }}');
136+
137+
138+
// Attempt to show paginator and loader if enabled
139+
showPaginator();
140+
showLoader();
141+
142+
/**
143+
* Get page info from document, resize canvas accordingly, and render page.
144+
* @param num Page number.
145+
*/
146+
function renderPage(num) {
147+
pageRendering = true;
148+
// Using promise to fetch the page
149+
pdfDoc.getPage(num).then(function(page) {
150+
var viewport = page.getViewport({scale: scale});
151+
canvas.height = viewport.height;
152+
canvas.width = viewport.width;
153+
154+
// Render PDF page into canvas context
155+
var renderContext = {
156+
canvasContext: ctx,
157+
viewport: viewport
158+
};
159+
var renderTask = page.render(renderContext);
160+
161+
// Wait for rendering to finish
162+
renderTask.promise.then(function() {
163+
pageRendering = false;
164+
showContent();
165+
166+
if (pageNumPending !== null) {
167+
// New page rendering is pending
168+
renderPage(pageNumPending);
169+
pageNumPending = null;
170+
}
171+
});
172+
});
173+
174+
// Update page counters
175+
document.getElementById('pdf-pagenum-{{ substr (.Get "url" | md5) 0 8 }}').textContent = num;
176+
}
177+
178+
/**
179+
* Hides loader and shows canvas
180+
*/
181+
function showContent() {
182+
loadingWrapper.style.display = 'none';
183+
canvas.style.display = 'block';
184+
}
185+
186+
/**
187+
* If we haven't disabled the loader, show loader and hide canvas
188+
*/
189+
function showLoader() {
190+
if(hideLoader) return
191+
loadingWrapper.style.display = 'flex';
192+
canvas.style.display = 'none';
193+
}
194+
195+
/**
196+
* If we haven't disabled the paginator, show paginator
197+
*/
198+
function showPaginator() {
199+
if(hidePaginator) return
200+
paginator.style.display = 'block';
201+
}
202+
203+
/**
204+
* If another page rendering in progress, waits until the rendering is
205+
* finished. Otherwise, executes rendering immediately.
206+
*/
207+
function queueRenderPage(num) {
208+
if (pageRendering) {
209+
pageNumPending = num;
210+
} else {
211+
renderPage(num);
212+
}
213+
}
214+
215+
/**
216+
* Displays previous page.
217+
*/
218+
function onPrevPage() {
219+
if (pageNum <= 1) {
220+
return;
221+
}
222+
pageNum--;
223+
queueRenderPage(pageNum);
224+
}
225+
document.getElementById('pdf-prev-{{ substr (.Get "url" | md5) 0 8 }}').addEventListener('click', onPrevPage);
226+
227+
/**
228+
* Displays next page.
229+
*/
230+
function onNextPage() {
231+
if (pageNum >= pdfDoc.numPages) {
232+
return;
233+
}
234+
pageNum++;
235+
queueRenderPage(pageNum);
236+
}
237+
document.getElementById('pdf-next-{{ substr (.Get "url" | md5) 0 8 }}').addEventListener('click', onNextPage);
238+
239+
/**
240+
* Asynchronously downloads PDF.
241+
*/
242+
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
243+
pdfDoc = pdfDoc_;
244+
var numPages = pdfDoc.numPages;
245+
document.getElementById('pdf-pagecount-{{ substr (.Get "url" | md5) 0 8 }}').textContent = numPages;
246+
247+
// If the user passed in a number that is out of range, render the last page.
248+
if(pageNum > numPages) {
249+
pageNum = numPages
250+
}
251+
252+
// Initial/first page rendering
253+
renderPage(pageNum);
254+
});
255+
})();
256+
</script>

0 commit comments

Comments
 (0)