rule.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. ---
  2. layout: default
  3. # This is where most of the code for CommunityRule lives
  4. # Follow comments below in various sections for further explanation
  5. ---
  6. <!-- Enables dragging on mobile
  7. https://github.com/Bernardo-Castilho/dragdroptouch -->
  8. <script src="/assets/DragDropTouch.js"></script>
  9. <script>
  10. // Enter JavaScript-land!
  11. // First, some functions, followed by initialization commands
  12. // Begin BUILDER functions
  13. // source: https://www.codecanal.com/html5-drag-and-copy/
  14. function allowDrop(ev) {
  15. ev.preventDefault();
  16. }
  17. function drag(ev) {
  18. ev.dataTransfer.setData("text", ev.target.id);
  19. }
  20. function drop(ev) {
  21. ev.preventDefault();
  22. var target = ev.target;
  23. // First, confirm target location is valid
  24. function targetCheck () {
  25. if (!editMode) {
  26. return false;
  27. } else if (target.id == "module-input") {
  28. return true;
  29. } else if (!document.getElementById("module-input").contains(target)) {
  30. // Ignore destinations not in the correct area
  31. return false;
  32. } else if (target.id == "drag-directions") {
  33. // Prevents dropping into dummy text field
  34. target = target.parentElement;
  35. return true;
  36. } else if (target.classList[0] == "module") {
  37. return true;
  38. } else {
  39. // be sure we're adding to module, not its children
  40. target = target.parentElement;
  41. return targetCheck();
  42. }
  43. }
  44. if (!targetCheck()) { return; }
  45. // Set up transfer
  46. var data = ev.dataTransfer.getData("text");
  47. // Iff module is from the menu clone it
  48. var module = document.getElementById(data);
  49. if ((module.parentElement.id == "module-menu") ||
  50. (module.parentElement.parentElement.id == "module-menu")) {
  51. // ^ because a subgroup might be parent
  52. module = module.cloneNode(true);
  53. var name = null;
  54. if (module.id == "module-custom") {
  55. // For custom modules: replace the <input> with text
  56. name = module.getElementsByTagName("input")[0].value;
  57. module.getElementsByTagName("input")[0].remove();
  58. var customText = document.createElement("span");
  59. customText.id = "module-name";
  60. customText.append(name);
  61. module.prepend(customText);
  62. }
  63. // append id with unique timestamp
  64. var nowModule = new Date();
  65. module.id += "-" + nowModule.getTime();
  66. }
  67. // display the deletion button
  68. module.children[2].style.display = "inline";
  69. // pop it in!
  70. target.appendChild(module);
  71. // add module-field button (using HTML so it saves to Library)
  72. module.outerHTML = module.outerHTML.replace("id=\"module-name\"",
  73. "id=\"module-name\" onclick=\"moduleEditField(this.parentNode.id)\"");
  74. // create the module-field
  75. moduleEditField(module.id);
  76. // be sure the dummy text is gone
  77. if (document.contains(document.getElementById("drag-directions"))) {
  78. document.getElementById("drag-directions").remove();
  79. }
  80. }
  81. // Edits the title field of a given module based on #custom-field
  82. function moduleTitleEdit(moduleID) {
  83. var module = document.getElementById(moduleID).children[0];
  84. var content =
  85. stripHTML(document.getElementById("custom-field").innerHTML);
  86. module.title = content;
  87. }
  88. // Sets up a field for displaying and editing module details
  89. function moduleEditField(moduleID) {
  90. var module = document.getElementById(moduleID);
  91. var moduleName = module.children[0].innerHTML;
  92. var moduleTitle = module.children[0].title;
  93. if (editMode) {
  94. var query = "Explain how the <strong>" + moduleName
  95. + "</strong> module works.";
  96. var destination = document.getElementById("builder-field");
  97. if (moduleName == null) { moduleName = ""; }
  98. var output = '\n<div id="custom-field-container">';
  99. output += '<span class="prompt">' + query + '</span>';
  100. output += '<div class="field-controls"><a onclick="this.parentNode.parentNode.remove()"><img src="{% link assets/tabler_icons/x.svg %}" class="delete-module" /></a></div>';
  101. output += '<p contenteditable="true" class="editable" id="custom-field" oninput="moduleTitleEdit(\'' + moduleID + '\')">' + moduleTitle + '</p>';
  102. output += '</div>\n';
  103. destination.innerHTML = output;
  104. } else {
  105. var output = '\n<div id="custom-field-container">';
  106. output += '<div class="field-controls"><a onclick="this.parentNode.parentNode.remove()"><img src="{% link assets/tabler_icons/x.svg %}" class="delete-module" /></a></div>';
  107. output += '<p class="editable" id="custom-field">'
  108. + moduleTitle + '</p>';
  109. }
  110. }
  111. // Tests if the RuleBuilder is empty
  112. function builderEmpty() {
  113. var builder = document.getElementById("module-input");
  114. var childs = builder.children;
  115. if (builder.getElementsByClassName("module").length > 0) {
  116. return false;
  117. } else {
  118. return true;
  119. }
  120. }
  121. // Turns RuleBuilder contents into an output-ready nested array
  122. // Returns empty array if no modules
  123. function builderArray() {
  124. var modules = document.getElementById("module-input").children;
  125. // takes an array of children
  126. // returns an array with all modules in the array, recursively nested
  127. function iterateArray (childs) {
  128. var moduleArray = [];
  129. if (childs.length > 0) {
  130. for (var i = 0; i < childs.length; i++) {
  131. module = childs[i];
  132. if (module.classList[0] == "module") {
  133. var moduleName = module.children.item("module-name");
  134. var moduleData = moduleName.title;
  135. var moduleChilds = module.children;
  136. moduleArray.push(
  137. [stripHTML(moduleName.innerHTML),
  138. stripHTML(moduleData),
  139. iterateArray(moduleChilds)]);
  140. }
  141. }
  142. }
  143. return moduleArray;
  144. } // end function
  145. return iterateArray(modules);
  146. }
  147. // returns HTML version of Builder content
  148. function displayBuilderHTML() {
  149. var output = "";
  150. var mainArray = builderArray();
  151. function arrayHTML(thisArray) {
  152. var thisOutput = "";
  153. if (thisArray.length > 0) {
  154. thisOutput += '<ul>\n';
  155. for (var i = 0; i < thisArray.length; i++) {
  156. var item = thisArray[i];
  157. thisOutput += '<li><strong>' + item[0] + '</strong> ';
  158. thisOutput += item[1] + '</li>\n';
  159. if (item[2].length > 0) {
  160. thisOutput += arrayHTML(item[2]);
  161. }
  162. }
  163. thisOutput += '</ul>\n';
  164. }
  165. return thisOutput
  166. }
  167. if (mainArray.length > 0) {
  168. output += '<div class="builder-list">\n';
  169. output += arrayHTML(mainArray) + '\n</div>\n';
  170. }
  171. return output;
  172. }
  173. // returns Markdown version of Builder content
  174. function displayBuilderMD() {
  175. var mainArray = builderArray();
  176. var indentLevel = 0;
  177. function arrayMD(thisArray) {
  178. var thisOutput = "";
  179. if (thisArray.length > 0) {
  180. for (var i = 0; i < thisArray.length; i++) {
  181. var item = thisArray[i];
  182. for (var x = 0; x < indentLevel; x++) {
  183. thisOutput += " ";
  184. }
  185. thisOutput += "* **" + item[0] + "** ";
  186. thisOutput += item[1] + "\n";
  187. if (item[2].length > 0) {
  188. indentLevel++;
  189. thisOutput += arrayMD(item[2]);
  190. indentLevel--;
  191. }
  192. }
  193. }
  194. return thisOutput;
  195. }
  196. return arrayMD(mainArray);
  197. }
  198. // end RuleBuilder functions
  199. // Removes all HTML content, replacing line break tags with newlines
  200. function stripHTML(input) {
  201. input = input.replace(/<br ?\/?>/ig, "\n").replace(/(<([^>]+)>)/ig,'');
  202. return input;
  203. }
  204. // Intercepts the paste event for editable fields and
  205. // converts the pasted content to plain text,
  206. // stripping styles and unwanted markup added by programs like Word.
  207. function handleEditablePaste(event) {
  208. try {
  209. var pastedText = event.clipboardData
  210. ? event.clipboardData.getData("text/plain")
  211. : window.clipboardData.getData("Text"); // support IE
  212. var cleanedText = cleanPastedText(pastedText);
  213. // Pastes the cleaned up text.
  214. if (document.queryCommandSupported('insertText')) {
  215. document.execCommand('insertText', false, cleanedText);
  216. } else { // support IE
  217. document.execCommand('paste', false, cleanedText);
  218. }
  219. event.stopPropagation();
  220. event.preventDefault();
  221. return false;
  222. } catch (err) {
  223. // If anything goes wrong with browser compatibility,
  224. // pass the event through without modification.
  225. return true;
  226. }
  227. }
  228. // Removes junk that comes with pasting from text editors like Word.
  229. // taken from https://stackoverflow.com/questions/2875027/clean-microsoft-word-pasted-text-using-javascript
  230. function cleanPastedText(text) {
  231. return text.replace(/.*<!--.*-->/g, "");
  232. }
  233. // toggleVisible(id)
  234. // Toggles the visibility of a given element by given ID
  235. function toggleVisible(id) {
  236. var x = document.getElementById(id);
  237. if (x.style.display === "none") {
  238. x.style.display = "block";
  239. } else {
  240. x.style.display = "none";
  241. }
  242. }
  243. // classDisplayAll(className, value)
  244. // Assigns given display value to all elements with a given className
  245. function classDisplayAll(className, value) {
  246. var elements = document.getElementsByClassName(className);
  247. for (var i = 0; i < elements.length; i++) {
  248. elements[i].style.display = value;
  249. }
  250. }
  251. // toggleEditMode()
  252. // Toggles whether editable fields are editable or not
  253. // and removes editing tools.
  254. function toggleEditMode() {
  255. if (editMode === true) { // switch to preview mode
  256. editMode = false;
  257. classDisplayAll("button","none");
  258. classDisplayAll("prompt","none");
  259. classDisplayAll("delete-module","none");
  260. var editableFields = document.getElementsByClassName("editable");
  261. // de-editable-ize the editable fields
  262. for (var i = 0; i < editableFields.length; i++) {
  263. editableFields[i].contentEditable = "false";
  264. editableFields[i].style.borderStyle = "none";
  265. // Remove empty fields entirely
  266. var content = editableFields[i].innerHTML;
  267. content = stripHTML(content);
  268. if (content === "") {
  269. editableFields[i].style.display = "none";
  270. }
  271. }
  272. // RuleBuilder sections
  273. if (builderEmpty()) {
  274. document.getElementById("rule-builder").style.display = "none";
  275. } else {
  276. document.getElementById("builder-field").innerHTML = displayBuilderHTML();
  277. document.getElementById("module-input").style.border = "none";
  278. }
  279. if (document.contains(document.getElementById("custom-field-container"))) {
  280. document.getElementById("custom-field-container").remove();
  281. }
  282. document.getElementById("module-menu").style.display = "none";
  283. // Handle author link
  284. var authorName = document.getElementById("author-text").value;
  285. var authorURL = document.getElementById("author-url").value;
  286. if (authorName != "") {
  287. document.getElementById("authorship-words").style.display = "inline";
  288. if (authorURL != "") { // both author and URL present
  289. document.getElementById("authorship-result").innerHTML = "<a href='" + authorURL +"'>" + authorName + "</a>";
  290. document.getElementById("authorship-result").style.display = "inline";
  291. } else { // only authorName present
  292. document.getElementById("authorship-result").innerHTML = authorName;
  293. document.getElementById("authorship-result").style.display = "inline";
  294. }
  295. } else {
  296. document.getElementById("authorship").style.display = "none";
  297. }
  298. // Finally, change button name
  299. document.getElementById("editToggle").innerHTML = "Customize";
  300. } else { // Switch to editMode
  301. editMode = true;
  302. classDisplayAll("button","block");
  303. classDisplayAll("prompt","block");
  304. classDisplayAll("editable","block");
  305. // RuleBuilder handling
  306. classDisplayAll("delete-module","inline");
  307. document.getElementById("rule-builder").style.display = "block";
  308. document.getElementById("module-menu").style.display = "block";
  309. document.getElementById("module-input").style.border = "";
  310. document.getElementById("builder-field").innerHTML = "";
  311. // link handling
  312. classDisplayAll("link-text","inline");
  313. classDisplayAll("link-url","inline");
  314. document.getElementById("authorship-result").style.display = "none";
  315. document.getElementById("authorship-words").style.display = "none";
  316. document.getElementById("authorship").style.display = "block";
  317. // make all editable fields visible
  318. var editableFields = document.getElementsByClassName("editable");
  319. for (var i = 0; i < editableFields.length; i++) {
  320. editableFields[i].style.borderStyle = "none none dashed none";
  321. editableFields[i].contentEditable = "true";
  322. }
  323. // Change button name
  324. document.getElementById("editToggle").innerHTML = "Preview";
  325. }
  326. }
  327. // toggleDisplayMode()
  328. // toggles full displayMode, the Rule-only display for a published Rule
  329. // first, initialize variable:
  330. var displayMode = false;
  331. function toggleDisplayMode() {
  332. if (displayMode == false) {
  333. editMode = true;
  334. toggleEditMode(); // turns off editMode
  335. classDisplayAll("site-nav","none");
  336. classDisplayAll("post-header","none");
  337. classDisplayAll("site-footer","none");
  338. document.getElementById("attribution").style.display = "block";
  339. document.getElementById("toggleDisplayMode").style.display = "inline-block";
  340. document.getElementById("publishRule").style.display = "none";
  341. document.getElementById("trash").style.display = "inline-block";
  342. displayMode = true;
  343. } else {
  344. toggleEditMode() // turns on editMode
  345. classDisplayAll("site-nav","block");
  346. classDisplayAll("post-header","block");
  347. classDisplayAll("site-footer","block");
  348. document.getElementById("attribution").style.display = "none";
  349. document.getElementById("toggleDisplayMode").style.display = "none";
  350. document.getElementById("publishRule").style.display = "inline-block";
  351. document.getElementById("trash").style.display = "none";
  352. displayMode = false;
  353. }
  354. if (document.getElementById("lineage-list").innerHTML != "") {
  355. document.getElementById("lineage").style.display = "block";
  356. }
  357. }
  358. // textOutput()
  359. // Produces Markdown rendition of Rule from Export button
  360. function textOutput() {
  361. var filename = 'GOVERNANCE.md';
  362. // First, add title, whether there is one or not
  363. var content = '# '+ document.getElementById('communityname').innerHTML + '\n\n';
  364. content = stripHTML(content);
  365. // Next, add structure field
  366. var structure = document.getElementById('structure').innerHTML;
  367. if (structure != "") {
  368. content += stripHTML(structure) + '\n\n';
  369. }
  370. // Add Builder content
  371. if (!builderEmpty()) {
  372. content += displayBuilderMD() + "\n\n";
  373. }
  374. // Now, begin adding Writer elements
  375. var elements = document.getElementsByClassName('output');
  376. for (var i = 2; i < elements.length; i++) { // start after structure
  377. var thisBit = elements[i].innerHTML;
  378. thisBit = stripHTML(thisBit);
  379. if (thisBit != "") {
  380. if (elements[i].classList.contains("subhead")) {
  381. // Before printing subhead, make sure it's not empty
  382. var i2 = i + 1;
  383. while ((i2 < elements.length) &&
  384. (!(elements[i2].classList.contains("subhead")))) {
  385. if (elements[i2].innerHTML != "") {
  386. // in this case, it's not empty, so print and move on
  387. content += '## ';
  388. content += thisBit + '\n\n';
  389. break;
  390. } else { i2++; }
  391. } // won't print anything if a subhead has only empty children
  392. } else {
  393. // Non-subhead elements can just go ahead and print
  394. content += thisBit + '\n\n';
  395. }
  396. }
  397. }
  398. // Add authorship block
  399. var authorName = document.getElementById("author-text").value;
  400. var authorURL = document.getElementById("author-url").value;
  401. var authorshipBlock = "---\n\nCreated by ";
  402. if (authorName != "") {
  403. if (authorURL != "") { // both author and URL present
  404. authorshipBlock += ("[" + authorName + "](" + authorURL + ")");
  405. } else { // only authorName present
  406. authorshipBlock += authorName;
  407. }
  408. content += (authorshipBlock + "\n");
  409. }
  410. // Add attribution block
  411. content += document.getElementById('attributionMD').innerHTML;
  412. // Starting here, see https://stackoverflow.com/a/33542499
  413. var blob = new Blob([content], {type: 'text/plain'});
  414. if(window.navigator.msSaveOrOpenBlob) {
  415. window.navigator.msSaveBlob(blob, filename);
  416. }
  417. else{
  418. var elem = window.document.createElement('a');
  419. elem.href = window.URL.createObjectURL(blob);
  420. elem.download = filename;
  421. document.body.appendChild(elem);
  422. elem.click();
  423. document.body.removeChild(elem);
  424. URL.revokeObjectURL(); // This needs an arg but I can't figure out what
  425. }
  426. var myFile = new Blob([fileContent], {type: 'text/plain'});
  427. window.URL = window.URL || window.webkitURL; document.getElementById('download').setAttribute('href',window.URL.createObjectURL(myFile));
  428. document.getElementById('download').setAttribute('download', fileName);
  429. }
  430. // BEGIN Publish tools, via SteinHQ.com
  431. // publishRule()
  432. // Publishes existing fields to new page, /builder/?rule=[ruleID]
  433. // Opens new page in Display mode
  434. function publishRule() {
  435. // Confirm user knows what they're getting into
  436. var r = confirm("Publish to the public Library?");
  437. if (r == false) { return; }
  438. // Proceed with publication
  439. var now = new Date();
  440. // Numerical ID for published Rule
  441. var timeID = now.getTime();
  442. // Readable UTC timestamp
  443. var dateTime = now.getUTCFullYear()+'.'+(now.getUTCMonth()+1)+'.'+now.getUTCDate()
  444. +' '+now.getUTCHours()+":"+ now.getUTCMinutes()+":"+now.getUTCSeconds()
  445. + ' UTC';
  446. // Check if ruleID exists; while yes, replace and repeat
  447. var rule = [{
  448. ruleID: timeID,
  449. timestamp: dateTime,
  450. }];
  451. // begin adding data
  452. // first, RuleBuilder data
  453. document.getElementById("builder-field").innerHTML = ""; // so it doesn't publish
  454. if (!builderEmpty()) {
  455. rule[0]["modules"] = document.getElementById("module-input").innerHTML;
  456. }
  457. // next, RuleWriter data
  458. var fields = document.getElementsByClassName("editable");
  459. for (var i = 0; i < fields.length; i++) {
  460. var key = fields[i].id;
  461. var value = "";
  462. // including input fields
  463. if (fields[i].nodeName == "INPUT") { // for <input>
  464. value = fields[i].value.replace(/(<([^>]+)>)/ig,"");
  465. } else { // for other fields
  466. value = fields[i].innerHTML.replace(/(<([^>]+)>)/ig,"");
  467. }
  468. rule[0][key] = value;
  469. }
  470. // add to lineage (if it is a fork)
  471. if (rID) {
  472. rule[0]["lineage"] = document.getElementById("lineage-list").innerHTML;
  473. }
  474. // add to database
  475. const store = new SteinStore(
  476. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  477. );
  478. store.append("library", rule).then(data => {
  479. window.open("/create/?r=" + timeID, "_self", false);
  480. });
  481. }
  482. // addLineage
  483. // Adds the current page to the lineage
  484. function addLineage() {
  485. var communityname = document.getElementById("communityname").innerHTML;
  486. var newLineage = " < " + '<a href="/create/?r=' + rID + '">'
  487. + communityname + '</a>';
  488. var oldLineage = document.getElementById("lineage-list").innerHTML;
  489. document.getElementById("lineage-list").innerHTML = newLineage + oldLineage;
  490. }
  491. // fork()
  492. // Forks the current Rule and updates the derivation lineage
  493. function fork() {
  494. document.getElementById("lineage").style.display = "block";
  495. addLineage();
  496. toggleDisplayMode();
  497. }
  498. // displayRule(ID)
  499. // Displays content based on ID
  500. function displayRule(ID) {
  501. const store = new SteinStore(
  502. "https://api.steinhq.com/v1/storages/5e8b937ab88d3d04ae0816a5"
  503. );
  504. (async () => {
  505. var sheets = ["library","templates"];
  506. // create empty set of rules (should only get one member)
  507. var ruleArray = [];
  508. // read values from all sheets
  509. for (var i = 0; i < sheets.length; i++) {
  510. await store.read(sheets[i], { search: { ruleID: ID } }).then(data => {
  511. // test if there's anything in data
  512. if (data.length > 0) {
  513. ruleArray = data;
  514. }
  515. });
  516. }
  517. // Only runs the rest if the array has something
  518. if (ruleArray.length > 0) {
  519. var rule = ruleArray[0];
  520. var fields = document.getElementsByClassName("editable");
  521. for (var i = 0; i < fields.length; i++) {
  522. var key = fields[i].id;
  523. var value = rule[key];
  524. if (typeof value === "undefined") {
  525. value = "";
  526. } else if (key.includes("-")) { // links
  527. document.getElementById(key).value = value;
  528. } else {
  529. document.getElementById(key).innerHTML = value;
  530. }
  531. }
  532. // Add Builder content
  533. document.getElementById("module-input").innerHTML = rule["modules"];
  534. // Add lineage
  535. var lineage = rule["lineage"];
  536. if (typeof lineage === "undefined") {
  537. document.getElementById("lineage-list").innerHTML = "";
  538. } else {
  539. document.getElementById("lineage-list").innerHTML = lineage;
  540. document.getElementById("lineage").display = "block";
  541. }
  542. // Publish timestamp to Rule
  543. document.getElementById('dateTime').innerHTML = rule['timestamp'];
  544. // Finish
  545. displayMode = false;
  546. toggleDisplayMode();
  547. document.title = rule['communityname'] + " / CommunityRule";
  548. }
  549. })();
  550. }
  551. // deleteRule()
  552. // A temporary placeholder that sends an email requesting rule deletion
  553. function deleteRule() {
  554. var urlParamz = new URLSearchParams(window.location.search);
  555. var rID = urlParamz.get('r');
  556. window.open("mailto:medlab@colorado.edu?subject=Delete Rule request ("
  557. + rID + ")&body=Please explain your rationale:\n");
  558. }
  559. // END Publish tools
  560. // FINALLY, Page loading
  561. // First, grab the current URL
  562. var urlParams = new URLSearchParams(window.location.search);
  563. // Determine if it is a published Rule
  564. if (urlParams.has('r')) {
  565. // If so, grab the Rule from database and enter displayMode
  566. var rID = urlParams.get('r');
  567. displayRule(rID);
  568. } else {
  569. // Otherwise, open in editMode as default
  570. var editMode = true;
  571. }
  572. // eqip editable fields to remove formatting from pasted content
  573. window.onload = function() {
  574. var editableElements = document.getElementsByClassName("editable");
  575. for (var i = 0; i < editableElements.length; i++ ) {
  576. editableElements[i].addEventListener("paste", handleEditablePaste);
  577. }
  578. }
  579. </script>
  580. <article class="post">
  581. <header class="post-header">
  582. <h1 class="post-title" id="title">
  583. {{ page.title }}
  584. </h1>
  585. <button class="pushButton" id="editToggle" onclick="toggleEditMode()">
  586. Preview</button>
  587. <div class="post-content">
  588. {{ content }}
  589. </div>
  590. </header>
  591. <div id="rulebox">
  592. <span class="prompt">What is the community’s name?</span>
  593. <h1 contenteditable="true" class="editable output" id="communityname">{{ page.community-name }}</h1>
  594. <span class="prompt">Summarize its structure:</span>
  595. <p contenteditable="true" class="editable output" id="structure">{{ page.structure }}</p>
  596. <!-- RuleBuilder -->
  597. <div id="rule-builder">
  598. <button id="module-toggle" onclick="toggleVisible('module-menu')"
  599. class="button" title="Show/hide">
  600. <img src="{% link assets/tabler_icons/tool.svg %}" title="Modules" />
  601. </button>
  602. <div id="module-input"
  603. ondrop="drop(event)" ondragover="allowDrop(event)">
  604. <span class="prompt" id="drag-directions">Browse modules from below and drag them here.</span>
  605. </div>
  606. <div id="builder-field">
  607. </div>
  608. <div id="module-menu">
  609. <!-- Customizable module -->
  610. <span class="module" id="module-custom"
  611. draggable="true" ondragstart="drag(event)">
  612. <input contenteditable="true" draggable="false" placeholder="Custom..."/>
  613. <img src="{% link assets/tabler_icons/bulb.svg %}" class="module-logo"
  614. draggable="false" />
  615. <a onclick="this.parentNode.remove()" class="delete-module"
  616. style="display:none">
  617. <img src="{% link assets/tabler_icons/x.svg %}" /></a>
  618. </span>
  619. <!-- Load preset modules from _modules/ -->
  620. {% assign modules_array = site.modules | sort: "type" %}
  621. {% assign last_type = "" %}
  622. {% for module in modules_array %}
  623. {% if module.layout == "module" %}
  624. {% if module.type != last_type %}
  625. {% if last_type != "" %}</div>{% endif %}
  626. <div class="module-type-header">
  627. <img src="{{ site.baseurl }}/{{ site.data.module_types[module.type].icon }}" />
  628. {{ module.type }}
  629. <button onclick="toggleVisible('module-type-{{ module.type }}')" class="button chevrons"><img src="{% link assets/tabler_icons/chevrons-down.svg %}" title="Show/hide" /></button>
  630. </div>
  631. <div class="module-questions">{{ site.data.module_types[module.type].question }}</div>
  632. <div id="module-type-{{ module.type }}">
  633. {% endif %}
  634. {% assign last_type = module.type %}
  635. <span class="module" id="module-{{ module.title | slugify }}"
  636. draggable="true" ondragstart="drag(event)">
  637. <span id="module-name" title="{{ module.summary }}">{{ module.title }}</span>
  638. <a target="_blank" href="{{ module.url }}">
  639. <img title="More info" draggable="false" class="module-logo"
  640. src="{% link assets/tabler_icons/info-circle.svg %}" />
  641. </a>
  642. <a onclick="this.parentNode.remove()" class="delete-module"
  643. style="display:none">
  644. <img src="{% link assets/tabler_icons/x.svg %}" /></a>
  645. </span>
  646. {% endif %}
  647. {% endfor %}
  648. </div>
  649. </div>
  650. </div>
  651. <!-- END RuleBuilder -->
  652. <div id="rulewriter-box">
  653. <span class="prompt"></span>
  654. <p id="rulewriter" contenteditable="true" class="editable output"></p>
  655. </div>
  656. <div id="authorship" class="linkbox">
  657. <span id="authorship-words">Created by</span>
  658. <input contenteditable="true" class="editable link-text" id="author-text" placeholder="Created by" />
  659. <span class="link-divider"><img src="{% link assets/tabler_icons/pencil.svg %}" title="Add link" /></span>
  660. <input contenteditable="true" class="editable link-url" id="author-url" placeholder="Creator URL (http://, https://)" type="url" pattern="http://.*|https://.*" />
  661. <span id="authorship-result"></span>
  662. </div>
  663. </div><!--#rulebox-->
  664. <div id="lineage">
  665. <img src="{% link assets/tabler_icons/file.svg %}" title="Derivation lineage" />
  666. <span id="lineage-list"></span>
  667. </div>
  668. <button class="pushButton" id="publishRule" onclick="publishRule()"
  669. title="Add to the public Library">Publish</button>
  670. <button class="pushButton" id="toggleDisplayMode" onclick="fork()"
  671. title="Edit this Rule into a new one">Fork</button>
  672. <button class="pushButton" onclick="textOutput()"
  673. title="Download this Rule as a Markdown text file">Export</button>
  674. <button class="pushButton" id="trash" onclick="deleteRule()">
  675. <img src="{% link assets/tabler_icons/trash.svg %}" title="Rule deletion request" />
  676. </button>
  677. <button class="pushButton"
  678. onclick="javascript:location.href='https://www.colorado.edu/lab/medlab/content/communityrule-user-feedback'">
  679. Feedback
  680. </button>
  681. <div id="attribution" style="display:none;">
  682. <br />
  683. <p><a href="https://communityrule.info">
  684. <img src="https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %}" alt="CommunityRule derived"></a></p>
  685. <p id="dateTime"></p>
  686. <p>Created with <a href="https://communityrule.info">CommunityRule</a>,
  687. <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons BY-SA</a></p>
  688. <p><strong>The Publish feature is experimental. Rules may be removed without notice</strong></p>
  689. </div>
  690. <div id="attributionMD" style="display:none;">---
  691. [![CommunityRule derived](https://communityrule.info{% link assets/CommunityRule-derived-000000.svg %})](https://communityrule.info)
  692. [Creative Commons BY-SA](https://creativecommons.org/licenses/by-sa/4.0/)</div>
  693. </article>