Skip to content

Commit

Permalink
Update unique_url_slug.html
Browse files Browse the repository at this point in the history
  • Loading branch information
hzik authored Oct 26, 2021
1 parent 2751aa8 commit 7d190d3
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions unique_url_slug.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</style>
</head>
<body>
<div class="text-field text-field--has-button" style="border-bottom:1px solid #e0e0e0">
<div class="text-field text-field--has-button" id="element">
<div class="text-field__input u-transparent-border u-no-left-padding">
<div id="unique" class="notranslate public-DraftEditor-content" contenteditable="true" placeholder="Enter slug here..." role="textbox" spellcheck="false" style="outline: none; user-select: text; overflow-wrap: break-word;"></div>
</div>
Expand All @@ -69,7 +69,7 @@
var generates_from = '';
var autogenerate = '[autogenerated]';
var force_uniqueness = "false";
var allowed_chars = '[^a-zA-Z0-9]';
var restricted_chars = '[^a-zA-Z0-9]';

function updateDisabled(disabled) {
if (disabled) {
Expand Down Expand Up @@ -112,17 +112,26 @@
if (element.config.repeater) {
repeater = element.config.repeater;
}
else {
showError("Missing 'Repeater' URL for proxying requests from this element to Preview API");
}
if (element.config.codename) {
codename = element.config.codename;
}
else {
showError("Missing codename of 'Custom URL Slug' element");
}
if (element.config.generates_from) {
generates_from = element.config.generates_from;
}
else {
showError("Missing source 'Text' element codename");
}
if (element.config.force_uniqueness) {
force_uniqueness = element.config.force_uniqueness;
}
if (element.config.allowed_chars) {
allowed_chars = element.config.allowed_chars;
if (element.config.restricted_chars) {
restricted_chars = element.config.restricted_chars;
}
}
if (element.value) {
Expand Down Expand Up @@ -161,7 +170,7 @@
}

function setValue(value) {
var re = new RegExp(allowed_chars,"g");
var re = new RegExp(restricted_chars,"g");
value = value.replace(re,'-');
$('#unique').text(value);
isUnique(value);
Expand Down Expand Up @@ -229,8 +238,16 @@
}
return result;
}

function showError(message) {
$('#element').hide();
$('#unique-status').css("color","#ef5350");
$('#unique-status').addClass("item-status--failed");
$('#unique-status').text(message);
throw new Error(message);
}

</script>

</body>
</html>
</html>

0 comments on commit 7d190d3

Please sign in to comment.