mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +01:00
Improve link url dialog
This commit is contained in:
parent
602e58f58e
commit
ed8fe3a455
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user