forked from CollectionBuilder/collectionbuilder-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: trigger warning added (CollectionBuilder#48)
* feat: trigger warning added * fix: add trigger warnings for browse * fix: more consitent layout
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% comment %} | ||
Adds Bootstrap styled trigger warning to page. | ||
By default the trigger warning is: "This item contains sensitive content." | ||
The trigger warning can be customized in the site.data.theme file. | ||
{% endcomment %} | ||
|
||
{% if site.data.theme.trigger-warning %} | ||
{% assign trigger_field = site.data.theme.trigger-field | default: "subject" %} | ||
{% assign trigger_terms = site.data.theme.trigger-terms | split: "," %} | ||
{% assign terms = page[trigger_field] | split: ";" %} | ||
|
||
<div class="alert alert-danger" role="alert" id="trigger-warning" style="display: none;"> | ||
{{ site.data.theme.trigger-warning-text-item | default: "This item may contain sensitive content." }} | ||
</div> | ||
|
||
<script> | ||
var triggerTerms = {{ trigger_terms | jsonify }}; | ||
var terms = {{ terms | jsonify }}; | ||
// strip whitespace from terms | ||
terms = terms.map(function(x) { return x.trim(); }); | ||
|
||
function doTwoArraysShareElement(arr1, arr2) { | ||
return arr1.some(item => arr2.includes(item)); | ||
} | ||
|
||
// Check if the arrays share an element and show the warning if they do | ||
if (doTwoArraysShareElement(terms, triggerTerms)) { | ||
document.getElementById("trigger-warning").style.display = "block"; | ||
} | ||
</script> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters