Skip to content

Commit

Permalink
target blank option working, looks horrid
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayjo committed Aug 19, 2014
1 parent 070fc75 commit 3d1abe6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions demo/custom-toolbar.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h2>Custom Labels </h2>
var editor = new MediumEditor('.editable', {
buttons: ['bold', 'italic', 'underline', 'quote', 'anchor', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent'],
buttonLabels: 'fontawesome',
anchorTarget: true,
});
var editor2 = new MediumEditor('.secondEditable', {
buttons: ['bold', 'italic', 'underline', 'anchor'],
Expand Down
33 changes: 22 additions & 11 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ if (typeof module === 'object') {
this.toolbar = this.createToolbar();
this.keepToolbarAlive = false;
this.anchorForm = this.toolbar.querySelector('.medium-editor-toolbar-form-anchor');
this.anchorInput = this.anchorForm.querySelector('input');
this.anchorInput = this.anchorForm.querySelector('input[type="text"]');
this.anchorTarget = this.anchorForm.querySelector('input[type="checkbox"]');
this.toolbarActions = this.toolbar.querySelector('.medium-editor-toolbar-actions');
this.anchorPreview = this.createAnchorPreview();

Expand Down Expand Up @@ -489,17 +490,18 @@ if (typeof module === 'object') {


target.setAttribute('type', 'checkbox');

target_label.innerHTML = "Open in New Window?";
target_label.appendChild(target);



anchor.className = 'medium-editor-toolbar-form-anchor';
anchor.id = 'medium-editor-toolbar-form-anchor';
anchor.appendChild(input);
anchor.appendChild(close);
anchor.appendChild(target_label);

if ( this.options.anchorTarget ) {
anchor.appendChild(target_label);
}

return anchor;
},
Expand Down Expand Up @@ -556,10 +558,8 @@ if (typeof module === 'object') {

clickingIntoArchorForm: function (e) {
var self = this;
console.log('here');

if (e.type && e.type.toLowerCase() === 'blur' && e.relatedTarget && e.relatedTarget === self.anchorInput) {
console.log('here2');
return true;
}

Expand Down Expand Up @@ -878,12 +878,23 @@ if (typeof module === 'object') {
e.stopPropagation();
self.keepToolbarAlive = true;
});

this.anchorInput.addEventListener('keyup', function (e) {
var target;

if (e.keyCode === 13) {
e.preventDefault();
self.createLink(this);
if ( self.options.anchorTarget && self.anchorTarget.checked ) {
target = "_blank";
}
else {
target = "_self";
}

self.createLink(this, target);
}
});

this.anchorInput.addEventListener('click', function (e) {
// make sure not to hide form when cliking into the input
e.stopPropagation();
Expand All @@ -892,13 +903,13 @@ if (typeof module === 'object') {

// Hide the anchor form when focusing outside of it.
document.body.addEventListener('click', function (e) {
if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) ) {
if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) && !isDescendant(self.toolbarActions, e.target) ) {
self.keepToolbarAlive = false;
self.checkSelection();
}
}, true);
document.body.addEventListener('focus', function (e) {
if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) ) {
if (e.target !== self.anchorForm && !isDescendant(self.anchorForm, e.target) && !isDescendant(self.toolbarActions, e.target) ) {
self.keepToolbarAlive = false;
self.checkSelection();
}
Expand Down Expand Up @@ -1108,7 +1119,7 @@ if (typeof module === 'object') {
}
},

createLink: function (input) {
createLink: function (input, target) {
if (input.value.trim().length === 0) {
this.hideToolbarActions();
return;
Expand All @@ -1122,7 +1133,7 @@ if (typeof module === 'object') {

document.execCommand('createLink', false, input.value);

if (this.options.targetBlank) {
if (this.options.targetBlank || target === "_blank" ) {
this.setTargetBlank();
}

Expand Down
Loading

0 comments on commit 3d1abe6

Please sign in to comment.