Skip to content

Commit

Permalink
Merge pull request foundation#42 from ClementParis016/feature/button-…
Browse files Browse the repository at this point in the history
…target

Add optional 'target' attribute for <button>
  • Loading branch information
rafibomb committed May 18, 2016
2 parents 41e9e58 + 89fc9bb commit 848e773
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/componentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ module.exports = function(element) {
case this.components.button:
var expander = '';

// Prepare optional target attribute for the <a> element
var target = '';
if (element.attr('target')) {
target = ' target=' + element.attr('target');
}

// If we have the href attribute we can create an anchor for the inner of the button;
if (element.attr('href')) {
inner = format('<a href="%s">%s</a>', element.attr('href'), inner);
inner = format('<a href="%s"%s>%s</a>', element.attr('href'), target, inner);
}

// If the button is expanded, it needs a <center> tag around the content
Expand Down
23 changes: 21 additions & 2 deletions test/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ describe('Button', () => {
compare(input, expected);
});

it('creates a button with target="_blank"', () => {
var input = '<button href="http://zurb.com" target="_blank">Button</button>';
var expected = `
<table class="button">
<tr>
<td>
<table>
<tr>
<td><a href="http://zurb.com" target="_blank">Button</a></td>
</tr>
</table>
</td>
</tr>
</table>
`;

compare(input, expected);
});

it('creates a button with classes', () => {
var input = `
<button class="small alert" href="http://zurb.com">Button</button>
Expand Down Expand Up @@ -229,7 +248,7 @@ describe('Callout', () => {
compare(input, expected);
});
});

describe('Spacer', () => {
it('creates a spacer element with correct size', () => {
var input = '<spacer size="10"></spacer>';
Expand All @@ -245,7 +264,7 @@ describe('Spacer', () => {

compare(input, expected);
});

it('copies classes to the final spacer HTML', () => {
var input = '<spacer size="10" class="bgcolor"></spacer>';
var expected = `
Expand Down

0 comments on commit 848e773

Please sign in to comment.