Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function linky(e) {
if (!e.keyCode || e.keyCode === 13) {
e.preventDefault();
toolbar._class.remove('ed-link-input-active');
me.caret.restore();
var url = input.value;
var node = me.caret.parent();
if (url) {
if (!/https?:\/\//.test(url)) {
url = 'http://' + url;
}
if (node.tagName.toLowerCase() === 'a') {
node.href = url;
} else {
format.a(url);
}
} else {
format.unlink();
}
}
}
events.bind(input, 'blur', linky);
function linky(e) {
if (!e.keyCode || e.keyCode === 13) {
e.preventDefault();
toolbar._class.remove('ed-link-input-active');
me.caret.restore();
var url = input.value;
var node = me.caret.parent();
if (url) {
if (!/https?:\/\//.test(url)) {
url = 'http://' + url;
}
if (node.tagName.toLowerCase() === 'a') {
node.href = url;
} else {
format.a(url);
}
} else {
format.unlink();
}
}
}
events.bind(input, 'blur', linky);
createButton('a', 'Insert a link', function() {
if (!toolbar._class.has('ed-link-input-active')) {
toolbar._class.add('ed-link-input-active');
var node = me.caret.parent();
if (node.tagName.toLowerCase() === 'a') {
input.value = node.href;
} else {
input.value = '';
format.a('/');
}
me.caret.save();
input.focus();
}
});
toolbar.appendChild(input);
createButton('a', 'Insert a link', function() {
if (!toolbar._class.has('ed-link-input-active')) {
toolbar._class.add('ed-link-input-active');
var node = me.caret.parent();
if (node.tagName.toLowerCase() === 'a') {
input.value = node.href;
} else {
input.value = '';
format.a('/');
}
me.caret.save();
input.focus();
}
});
toolbar.appendChild(input);