|
@@ -32,7 +32,7 @@ layout: default
|
|
|
// Toggles whether editable fields are editable or not
|
|
|
// and removes editing tools.
|
|
|
function toggleEditMode() {
|
|
|
- if (editMode === true) {
|
|
|
+ if (editMode === true) { // switch to preview mode
|
|
|
editMode = false;
|
|
|
classDisplayAll("section","block");
|
|
|
classDisplayAll("button","none");
|
|
@@ -65,15 +65,40 @@ layout: default
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // Handle links
|
|
|
+ // TKTK
|
|
|
+ // Handle author link
|
|
|
+ var authorName = document.getElementById("author-text").value;
|
|
|
+ var authorURL = document.getElementById("author-url").value;
|
|
|
+ if (authorName != "") {
|
|
|
+ document.getElementById("authorship-words").style.display = "inline";
|
|
|
+ if (authorURL != "") { // both author and URL present
|
|
|
+ document.getElementById("authorship-result").innerHTML = "<a href='" + authorURL +"'>" + authorName + "</a>";
|
|
|
+ document.getElementById("authorship-result").style.display = "inline";
|
|
|
+ } else { // only authorName present
|
|
|
+ document.getElementById("authorship-result").innerHTML = authorName;
|
|
|
+ document.getElementById("authorship-result").style.display = "inline";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ document.getElementById("authorship").style.display = "none";
|
|
|
+ }
|
|
|
// Finally, change button name
|
|
|
document.getElementById("editToggle").innerHTML = "Customize";
|
|
|
- } else {
|
|
|
+ } else { // Switch to editMode
|
|
|
editMode = true;
|
|
|
classDisplayAll("button","block");
|
|
|
classDisplayAll("question","block");
|
|
|
classDisplayAll("editable","block");
|
|
|
classDisplayAll("header","block");
|
|
|
classDisplayAll("section","none");
|
|
|
+ classDisplayAll("link-text","inline");
|
|
|
+ classDisplayAll("link-url","inline");
|
|
|
+ // link handling TKTK
|
|
|
+ // author handling
|
|
|
+ document.getElementById("authorship-result").style.display = "none";
|
|
|
+ document.getElementById("authorship-words").style.display = "none";
|
|
|
+ document.getElementById("authorship").style.display = "block";
|
|
|
+ // make all editable fields visible
|
|
|
var editableFields = document.getElementsByClassName("editable");
|
|
|
for (var i = 0; i < editableFields.length; i++) {
|
|
|
editableFields[i].style.borderStyle = "none none dashed none";
|
|
@@ -144,6 +169,19 @@ layout: default
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // Add authorship block
|
|
|
+ var authorName = document.getElementById("author-text").value;
|
|
|
+ var authorURL = document.getElementById("author-url").value;
|
|
|
+ var authorshipBlock = "---\n\nCreated by ";
|
|
|
+ if (authorName != "") {
|
|
|
+ if (authorURL != "") { // both author and URL present
|
|
|
+ authorshipBlock += ("[" + authorName + "](" + authorURL + ")");
|
|
|
+ } else { // only authorName present
|
|
|
+ authorshipBlock += authorName;
|
|
|
+ }
|
|
|
+ content += (authorshipBlock + "\n");
|
|
|
+ }
|
|
|
+ // Add attribution block
|
|
|
content += document.getElementById('attributionMD').innerHTML;
|
|
|
// Starting here, see https://stackoverflow.com/a/33542499
|
|
|
var blob = new Blob([content], {type: 'text/plain'});
|
|
@@ -185,7 +223,12 @@ layout: default
|
|
|
var fields = document.getElementsByClassName("editable");
|
|
|
for (var i = 0; i < fields.length; i++) {
|
|
|
var key = fields[i].id;
|
|
|
- var value = fields[i].innerHTML.replace(/(<([^>]+)>)/ig,"");
|
|
|
+ var value = "";
|
|
|
+ if (fields[i].nodeName == "INPUT") { // for <input>
|
|
|
+ value = fields[i].value.replace(/(<([^>]+)>)/ig,"");
|
|
|
+ } else { // for other fields
|
|
|
+ value = fields[i].innerHTML.replace(/(<([^>]+)>)/ig,"");
|
|
|
+ }
|
|
|
rule[0][key] = value;
|
|
|
}
|
|
|
const store = new SteinStore(
|
|
@@ -211,8 +254,11 @@ layout: default
|
|
|
var value = rule[key];
|
|
|
if (typeof value === "undefined") {
|
|
|
value = "";
|
|
|
+ } else if (key.includes("-")) { // links
|
|
|
+ document.getElementById(key).value = value;
|
|
|
+ } else {
|
|
|
+ document.getElementById(key).innerHTML = value;
|
|
|
}
|
|
|
- document.getElementById(key).innerHTML = value;
|
|
|
}
|
|
|
// Publish timestamp to Rule
|
|
|
document.getElementById('dateTime').innerHTML = rule['timestamp'];
|
|
@@ -425,6 +471,17 @@ layout: default
|
|
|
|
|
|
</div><!--hiding section s5-->
|
|
|
|
|
|
+ <div id="authorship" class="linkbox">
|
|
|
+ <span id="authorship-words">Created by</span>
|
|
|
+ <input contenteditable="true" class="editable link-text" id="author-text" placeholder="Created by">
|
|
|
+ <span class="link-divider"><img src="{% link assets/tabler_icons/pencil.svg %}" title="Add link" /></span>
|
|
|
+ <input contenteditable="true" class="editable link-url" id="author-url" placeholder="Creator URL (http://, https://)" type="url" pattern="http://.*|https://.*">
|
|
|
+ <span id="authorship-result"></span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </div><!--#rulebox-->
|
|
|
+
|
|
|
+
|
|
|
<div id="attribution" style="display:none;">
|
|
|
<br />
|
|
|
<p><a href="https://communityrule.info">
|
|
@@ -439,12 +496,9 @@ layout: default
|
|
|
|
|
|
[](https://communityrule.info)
|
|
|
|
|
|
-Created with [CommunityRule](https://communityrule.info)
|
|
|
-
|
|
|
[Creative Commons BY-SA](https://creativecommons.org/licenses/by-sa/4.0/)</div>
|
|
|
|
|
|
- </div><!--#rulebox-->
|
|
|
-
|
|
|
+
|
|
|
<button class="pushButton" id="publishRule" onclick="publishRule()"
|
|
|
title="Add to the public Library">Publish</button>
|
|
|
<button class="pushButton" id="toggleDisplayMode" onclick="toggleDisplayMode()"
|