-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cc1226
commit 197af06
Showing
8 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import * as Handlebars from 'handlebars'; | ||
import * as url from 'url'; | ||
|
||
function isActive(currentUrl: string, linkUrl: string): boolean { | ||
let current = url.parse(currentUrl, true); | ||
let href = url.parse(linkUrl, true); | ||
if (current.pathname !== href.pathname) { | ||
return false; | ||
} | ||
for (let k in href.query) { | ||
if (href.query[k] === undefined || href.query[k] !== current.query[k]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export default function linkTo(this: any, opts?: Handlebars.HelperOptions) { | ||
if (!opts) { | ||
throw new Error('No options were passed to {{link-to}}'); | ||
} | ||
let { hash } = opts; | ||
let { disabled, classNames, href } = hash; | ||
classNames = classNames.split(' '); | ||
classNames = (classNames || '').split(' '); | ||
if (disabled) { | ||
classNames.push('disabled'); | ||
} | ||
let active = isActive(opts.data.root.request.url, href); | ||
|
||
if (active) { | ||
classNames.push('active'); | ||
} | ||
return new Handlebars.SafeString(`<a class='${classNames.join(' ')}' href='${href}'>${opts.fn(this)}</a>`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<span class="table-col-sort mui--pull-right"> | ||
{{#link-to classNames='sort-button' href=(merge-qps request.url sort=by order='asc') }}⬆{{/link-to}} {{#link-to classNames='sort-button' | ||
href=(merge-qps request.url sort=by order='desc') }}⬇{{/link-to}} | ||
</span> |