artabro/wire/modules/Inputfield/InputfieldPageName/InputfieldPageName.min.js

1 line
1.9 KiB
JavaScript
Raw Permalink Normal View History

2024-08-27 11:35:37 +02:00
var InputfieldPageName={sanitize:function(name){name=name.toLowerCase().trim();var srch;for(srch in ProcessWire.config.InputfieldPageName.replacements){var repl=ProcessWire.config.InputfieldPageName.replacements[srch];if(name.indexOf(srch)>-1){if(srch==".")srch="\\.";var re=new RegExp(srch,"g");name=name.replace(re,repl)}}name=name.replace(/['"\u0022\u0027\u00AB\u00BB\u2018\u2019\u201A\u201B\u201C\u201D\u201E\u201F\u2039\u203A\u300C\u300D\u300E\u300F\u301D\u301E\u301F\uFE41\uFE42\uFE43\uFE44\uFF02\uFF07\uFF62\uFF63]/g,"");if(ProcessWire.config.InputfieldPageName.charset=="UTF8"){var whitelist=ProcessWire.config.InputfieldPageName.whitelist;if(whitelist.length){var newName="";for(var n=0;n<name.length;n++){var c=name.substring(n,n+1);if(whitelist.indexOf(c)==-1)c="-";newName+=c}name=newName}else{}}else{name=name.replace(/[^-_.a-z0-9 ]/g,"-")}name=name.replace(/\s+/g,"-");name=name.replace(/\.\.+/g,".");name=name.replace(/(\.-|-\.)/g,"-");name=name.replace(/(^[-_.]+|[-_.]+$)/g,"");name=name.replace(/--+/g,"-");if(name.length>128){name=name.trim();name=name.substring(0,128).split("-").slice(0,-1).join(" ")}return name},updatePreview:function($t,value){var $previewPath=$("#"+$t.attr("id")+"_path");var slash=parseInt($previewPath.attr("data-slashUrls"))>0?"/":"";$previewPath.find("strong").text(value.length>0?value+slash:"")}};jQuery(document).ready(function($){$(document).on("keyup",".InputfieldPageName input[type=text]",function(){var value=InputfieldPageName.sanitize($(this).val());InputfieldPageName.updatePreview($(this),value)}).on("blur",".InputfieldPageName input[type=text]",function(){var value=InputfieldPageName.sanitize($(this).val());$(this).val(value);InputfieldPageName.updatePreview($(this),value)});$(document).on("reloaded",".InputfieldPageName",function(){$(this).find("input[type=text]").trigger("keyup")});$(".InputfieldPageName").find("input[type=text]").trigger("keyup")});