diff --git a/packages/mindplot/src/components/widget/LinkEditor.js b/packages/mindplot/src/components/widget/LinkEditor.js index 681429c1..f4dbcabc 100644 --- a/packages/mindplot/src/components/widget/LinkEditor.js +++ b/packages/mindplot/src/components/widget/LinkEditor.js @@ -60,7 +60,7 @@ class LinkEditor extends BootstrapDialog { // Add Input const input = $('').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)); } diff --git a/packages/mindplot/src/components/widget/LinkIconTooltip.js b/packages/mindplot/src/components/widget/LinkIconTooltip.js index 62e28a9c..a40b56fc 100644 --- a/packages/mindplot/src/components/widget/LinkIconTooltip.js +++ b/packages/mindplot/src/components/widget/LinkIconTooltip.js @@ -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 = $('
').css({ padding: '5px',