diff --git a/readme.md b/readme.md
index 951646a..bd0eac9 100755
--- a/readme.md
+++ b/readme.md
@@ -41,7 +41,8 @@ var options = {
class: 'pen', // {String} class of the editor,
debug: false, // {Boolean} false by default
textarea: '', // fallback for old browsers
- list: ['bold', 'italic', 'underline'] // editor menu list
+ list: ['bold', 'italic', 'underline'], // editor menu list
+ linksInNewWindow: true // open hyperlinks in a new windows/tab
}
var editor = new Pen(options);
@@ -60,7 +61,8 @@ defaults = {
'blockquote', 'h2', 'h3', 'p', 'insertorderedlist', 'insertunorderedlist',
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
],
- stay: true
+ stay: true,
+ linksInNewWindow: false
}
```
diff --git a/src/pen.js b/src/pen.js
index 3819be2..35cd36e 100755
--- a/src/pen.js
+++ b/src/pen.js
@@ -90,7 +90,8 @@
],
titles: {},
cleanAttrs: ['id', 'class', 'style', 'name'],
- cleanTags: ['script']
+ cleanTags: ['script'],
+ linksInNewWindow: false
};
// user-friendly config
@@ -141,6 +142,15 @@
return commandOverall(ctx, 'insertHTML', value);
}
+ function commandLink(ctx, tag, value) {
+ if (this.config.linksInNewWindow) {
+ value = '< a href="' + value + '" target="_blank">' + (selection.toString()) + '';
+ return commandOverall(ctx, 'insertHTML', value);
+ } else {
+ return commandOverall(ctx, tag, value);
+ }
+ }
+
function initToolbar(ctx) {
var icons = '', inputStr = '';
@@ -593,8 +603,10 @@
if (commandsReg.block.test(name)) {
commandBlock(this, name);
- } else if (commandsReg.inline.test(name) || commandsReg.source.test(name)) {
+ } else if (commandsReg.inline.test(name)) {
commandOverall(this, name, value);
+ } else if (commandsReg.source.test(name)) {
+ commandLink(this, name, value);
} else if (commandsReg.insert.test(name)) {
commandInsert(this, name, value);
} else if (commandsReg.wrap.test(name)) {