// besci.org site fixes — // original credit for this snippet: https://github.com/brettpthomas // This creates an all-lowercase, hypenated slug with no special characters for each string, and creates a link around each substring in the string separated by a comma function getLinkFromTagText(tagText) { var slug = tagText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "" + tagText + ""; } function getLinkFromPaperText(paperText) { var slug = paperText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "
"+paperText+"
" ; } function getLinkFromProductText(productText) { var slug = productText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "" + productText + ""; } function getLinkFromTacticText(tacticText) { var slug = tacticText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "
"+tacticText+"
" ; } function getLinkFromBehaviorText(behaviorText) { var slug = behaviorText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "
"+behaviorText+"
" ; } function besci1(besciText) { var slug = besciText.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return "" + besciText + ""; } // This separates the new link items into separate array items and rejoins them together, separating with a space function getLinksHtmlFromTagsString(tagsString) { var linksList = tagsString.split(',').map(getLinkFromTagText); return linksList.join(' '); } function getLinksHtmlFromPapersString(papersString) { var linksList = papersString.split(',').map(getLinkFromPaperText); return linksList.join(' '); } function getLinksHtmlFromProductsString(productsString) { var linksList = productsString.split(',').map(getLinkFromProductText); return linksList.join(' '); } function getLinksHtmlFromTacticsString(tacticsString) { var linksList = tacticsString.split(',').map(getLinkFromTacticText); return linksList.join(' '); } function getLinksHtmlFromBehaviorsString(behaviorsString) { var linksList = behaviorsString.split(',').map(getLinkFromBehaviorText); return linksList.join(' '); } function besci2(besciString) { var besciList = besciString.split(',').map(besci1); return besciList.join(' '); } // This wraps the link HTML around each item function addLinksToTagsStringElement() { var tagsString = $(this).html(); $(this).html(getLinksHtmlFromTagsString(tagsString)); } function addLinksToPapersStringElement() { var papersString = $(this).html(); $(this).html(getLinksHtmlFromPapersString(papersString)); } function addLinksToProductsStringElement() { var productsString = $(this).html(); $(this).html(getLinksHtmlFromProductsString(productsString)); } function addLinksToTacticsStringElement() { var tacticsString = $(this).html(); $(this).html(getLinksHtmlFromTacticsString(tacticsString)); } function addLinksToBehaviorsStringElement() { var behaviorsString = $(this).html(); $(this).html(getLinksHtmlFromBehaviorsString(behaviorsString)); } function besci3() { var besciString = $(this).html(); $(this).html(besci2(besciString)); } // This does all the stuff above to any strings within divs with the classes specified in quotes $(".tag-array").each(addLinksToTagsStringElement); $(".paper-array").each(addLinksToPapersStringElement); $(".product-array").each(addLinksToProductsStringElement); $(".tactic-array").each(addLinksToTacticsStringElement); $(".behavior-array").each(addLinksToBehaviorsStringElement); $(".besci-array").each(besci3); // This does some other cleaning up of ugly strings $(".comma-space").text(function(i, val) { return val.replace(/,/g, ", "); }); $(".comma-split").text(function(i, val) { return val.split(/,/g).join(" "); }); $(".comma-amp").text(function(i, val) { return val.replace(/,/g, " & "); }); // ↓ enter the string hack functions function step1(txt1) { var slug = txt1.replace(/[!\"#$%&'\(\)\*\+\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') .replace(/ /g, "-") .toLowerCase(); return ""+ txt1 +""; } // This separates the new link items into separate array items and rejoins them together, separating with a space function step2(txt2) { var txt3 = txt2.split(',').map(step1); return txt3.join(', '); } // This wraps the link HTML around each item function step3() { var txt4 = $(this).html(); $(this).html(step2(txt4)); } $(".splitter").each(step3);