Skip to content

Commit

Permalink
add an option for url types so that it can be opened in current tab
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaligand committed Jul 29, 2017
1 parent e1950ab commit 65fb49d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/ui/public/stringify/__tests__/_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Url Format', function () {
Url = fieldFormats.getType('url');
});

it('ouputs a simple <a> tab by default', function () {
it('outputs a simple <a> tab by default', function () {
const url = new Url();

const $a = unwrap($(url.convert('http://elastic.co', 'html')));
Expand All @@ -34,6 +34,14 @@ describe('Url Format', function () {
expect($a.children().size()).to.be(0);
});

it('outputs a <a> link with target=_self if "open link in current tab" is checked', function () {
const url = new Url({ openLinkInCurrentTab: true });

const $a = unwrap($(url.convert('http://elastic.co', 'html')));
expect($a.is('a')).to.be(true);
expect($a.attr('target')).to.be('_self');
});

it('outputs an <image> if type === "img"', function () {
const url = new Url({ type: 'img' });

Expand Down
8 changes: 8 additions & 0 deletions src/ui/public/stringify/editors/url.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
</select>
</div>

<div class="checkbox" ng-if="editor.formatParams.type == 'a'">
<label>
<input ng-model="editor.formatParams.openLinkInCurrentTab" class="ng-pristine ng-valid ng-touched" type="checkbox">
Open link in current tab
</label>
</div>

<div class="form-group">
<span class="pull-right text-info hintbox-label" ng-click="editor.showUrlTmplHelp = !editor.showUrlTmplHelp">
<i class="fa fa-info"></i> Url Template Help
Expand Down Expand Up @@ -119,6 +126,7 @@ <h4 class="hintbox-heading">
</div>

<input ng-model="editor.formatParams.labelTemplate" class="form-control">

</div>

<field-format-editor-samples inputs="url.samples[editor.formatParams.type]"></field-format-editor-samples>
4 changes: 3 additions & 1 deletion src/ui/public/stringify/types/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export function stringifyUrl(Private) {
linkLabel = label;
}

return `<a href="${url}" target="_blank">${linkLabel}</a>`;
let linkTarget = this.param('openLinkInCurrentTab') ? '_self' : '_blank';

return `<a href="${url}" target="${linkTarget}">${linkLabel}</a>`;
}
}
};
Expand Down

0 comments on commit 65fb49d

Please sign in to comment.