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

feat: add option to open target in a new tab #40

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ Directly from unpkg.com

# Banner Attributes

| Name | Type | Description |
| ---------------------- | --------------- | ------------------------------------------------------------------ |
| width | Number | Banner width |
| height | Number | Banner height |
| id | String | The slot ID for this banner |
| category-id* | Optional String | The category ID of the current page |
| category-ids* | Optional String | Comma (,) separated list of category IDs, the item must match all |
| category-disjunctions* | Optional String | Comma (,) separated list of category IDs, the item must match any |
| search-query | Optional String | The search query of the current page |
| location | Optional String | The location for geotargeting |
| Name | Type | Description |
| ---------------------- | ---------------- | --------------------------------------------------------------------------- |
| width | Number | Banner width |
| height | Number | Banner height |
| id | String | The slot ID for this banner |
| category-id* | Optional String | The category ID of the current page |
| category-ids* | Optional String | Comma (,) separated list of category IDs, the item must match all |
| category-disjunctions* | Optional String | Comma (,) separated list of category IDs, the item must match any |
| search-query | Optional String | The search query of the current page |
| location | Optional String | The location for geotargeting |
| new-tab | Optional Boolean | Opens the link in a new tab (defaults to false) |

\* Only one of `[category-id, category-ids, category-disjunctions]` must be set.
If multiple are set, only the first will be considered, in that order.
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export class TopsortBanner extends LitElement {
@property({ attribute: "location", type: String })
readonly location?: string;

@property({ attribute: "new-tab", type: Boolean })
readonly newTab?: boolean;

private task = new Task(this, {
task: (...args) => this.runAuction(...args),
args: () => [],
Expand Down Expand Up @@ -130,14 +133,16 @@ export class TopsortBanner extends LitElement {
}
`;
const href = this.getLink(banner);
const imgtag = html`<img src="${src}" alt="Topsort banner"></img>`;
const atag = this.newTab
? html`<a href="${href}" target="_blank">${imgtag}</a>`
: html`<a href="${href}">${imgtag}</a>`;
return html`
<div style="${style}"
data-ts-clickable
data-ts-resolved-bid=${banner.resolvedBidId}
class="ts-banner">
<a href="${href}">
<img src="${src}" alt="Topsort banner"></img>
</a>
${atag}
</div>
`;
}
Expand Down