Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional 'target' attribute for <button> #42

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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