Improve link url dialog

This commit is contained in:
Paulo Gustavo Veiga 2022-03-25 16:50:25 -03:00
parent 602e58f58e
commit ed8fe3a455
2 changed files with 16 additions and 6 deletions

View File

@ -60,7 +60,7 @@ class LinkEditor extends BootstrapDialog {
// Add Input // Add Input
const input = $('<input id="inputUrl"/>').attr({ const input = $('<input id="inputUrl"/>').attr({
placeholder: 'http://www.example.com/', placeholder: 'https://www.example.com/',
required: 'true', required: 'true',
autofocus: 'autofocus', autofocus: 'autofocus',
class: 'form-control', class: 'form-control',
@ -92,9 +92,10 @@ class LinkEditor extends BootstrapDialog {
const me = this; const me = this;
this.form.unbind('submit').submit((event) => { this.form.unbind('submit').submit((event) => {
event.preventDefault(); event.preventDefault();
if (me.checkURL(input.val())) { let inputValue = input.val();
inputValue = this.hasProtocol(inputValue) ? inputValue : `https://${inputValue}`;
if (me.checkURL(inputValue)) {
me.cleanError(); me.cleanError();
const inputValue = input.val();
if (inputValue != null && $.trim(inputValue) !== '') { if (inputValue != null && $.trim(inputValue) !== '') {
model.setValue(inputValue); model.setValue(inputValue);
} }
@ -115,7 +116,16 @@ class LinkEditor extends BootstrapDialog {
* @return {Boolean} true if the url is valid * @return {Boolean} true if the url is valid
*/ */
checkURL(url) { checkURL(url) {
const regex = /^(http|https|ftp):\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i; const regex = /^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i;
return (regex.test(url));
}
/**
* checks whether the input is a valid url
* @return {Boolean} true if the url is valid
*/
hasProtocol(url) {
const regex = /^(http|https):\/\//i;
return (regex.test(url)); return (regex.test(url));
} }

View File

@ -40,8 +40,8 @@ class LinkIconTooltip extends FloatingTip {
static _buildContent(linkIcon) { static _buildContent(linkIcon) {
const url = linkIcon.getModel().getUrl(); const url = linkIcon.getModel().getUrl();
const linkText = `URL: ${url}`; const linkText = `${url}`;
const linkPreview = `http://free.pagepeeker.com/v2/thumbs.php?size=m&url=${url}`; const linkPreview = `https://free.pagepeeker.com/v2/thumbs.php?size=m&url=${url}`;
const result = $('<div></div>').css({ const result = $('<div></div>').css({
padding: '5px', padding: '5px',