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
const input = $('<input id="inputUrl"/>').attr({
placeholder: 'http://www.example.com/',
placeholder: 'https://www.example.com/',
required: 'true',
autofocus: 'autofocus',
class: 'form-control',
@ -92,9 +92,10 @@ class LinkEditor extends BootstrapDialog {
const me = this;
this.form.unbind('submit').submit((event) => {
event.preventDefault();
if (me.checkURL(input.val())) {
let inputValue = input.val();
inputValue = this.hasProtocol(inputValue) ? inputValue : `https://${inputValue}`;
if (me.checkURL(inputValue)) {
me.cleanError();
const inputValue = input.val();
if (inputValue != null && $.trim(inputValue) !== '') {
model.setValue(inputValue);
}
@ -115,7 +116,16 @@ class LinkEditor extends BootstrapDialog {
* @return {Boolean} true if the url is valid
*/
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));
}

View File

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