Skip to content

Commit

Permalink
Merge pull request #169 from thomastweets/master
Browse files Browse the repository at this point in the history
Add config option to open links in new windows.
  • Loading branch information
sofish committed Jun 23, 2016
2 parents 61a46b4 + b9353bb commit 047c542
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var options = {
class: 'pen', // {String} class of the editor,
debug: false, // {Boolean} false by default
textarea: '<textarea name="content"></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);
Expand All @@ -60,7 +61,8 @@ defaults = {
'blockquote', 'h2', 'h3', 'p', 'insertorderedlist', 'insertunorderedlist',
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
],
stay: true
stay: true,
linksInNewWindow: false
}
```

Expand Down
16 changes: 14 additions & 2 deletions src/pen.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
],
titles: {},
cleanAttrs: ['id', 'class', 'style', 'name'],
cleanTags: ['script']
cleanTags: ['script'],
linksInNewWindow: false
};

// user-friendly config
Expand Down Expand Up @@ -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()) + '</a>';
return commandOverall(ctx, 'insertHTML', value);
} else {
return commandOverall(ctx, tag, value);
}
}

function initToolbar(ctx) {
var icons = '', inputStr = '<input class="pen-input" placeholder="http://" />';

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 047c542

Please sign in to comment.