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

Allow templating in sortAscending and sortDescending ARIA strings #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/option/language.aria.sortAscending.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<description>
ARIA label that is added to the table headers when the column may be sorted ascending by activating the column (click or return when focused).

Note that the column header text is prefixed to this string.
The variable _HEADER_ is replaced by the column header. If not present, the column header is prefixed to this string.
</description>

<example title="Set ARIA sort ascending string"><![CDATA[
$('#example').dataTable( {
"language": {
"aria": {
"sortAscending": " - click/return to sort ascending"
"sortAscending": "click to sort by _HEADER_ ascending"
}
}
} );
Expand Down
4 changes: 2 additions & 2 deletions docs/option/language.aria.sortDescending.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<description>
ARIA label that is added to the table headers when the column may be sorted descending by activing the column (click or return when focused).

Note that the column header text is prefixed to this string.
The variable _HEADER_ is replaced by the column header. If not present, the column header is prefixed to this string.
</description>

<example title="Set ARIA sort descending string"><![CDATA[
$('#example').dataTable( {
"language": {
"aria": {
"sortDescending": " - click/return to sort descending"
"sortDescending": "click to sort by _HEADER_ descending"
}
}
} );
Expand Down
12 changes: 8 additions & 4 deletions js/core/core.sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ function _fnSortAria ( settings )
nextSort = asSorting[0];
}

label = sTitle + ( nextSort === "asc" ?
oAria.sSortAscending :
oAria.sSortDescending
);
var sSortLabel = nextSort === "asc" ? oAria.sSortAscending : oAria.sSortDescending;

if (sSortLabel.indexOf("_HEADER_") !== -1) {
label = sSortLabel.replace("_HEADER_", sTitle);
}
else {
label = sTitle + sSortLabel;
}
}
else {
label = sTitle;
Expand Down
18 changes: 10 additions & 8 deletions js/model/model.defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,9 +1417,10 @@ DataTable.defaults = {
/**
* ARIA label that is added to the table headers when the column may be
* sorted ascending by activing the column (click or return when focused).
* Note that the column header is prefixed to this string.
* The variable _HEADER_ is replaced by the column header. If not present,
* the column header is prefixed to this string.
* @type string
* @default : activate to sort column ascending
* @default _HEADER_: activate to sort column ascending
*
* @dtopt Language
* @name DataTable.defaults.language.aria.sortAscending
Expand All @@ -1429,20 +1430,21 @@ DataTable.defaults = {
* $('#example').dataTable( {
* "language": {
* "aria": {
* "sortAscending": " - click/return to sort ascending"
* "sortAscending": "click to sort by _HEADER_ ascending"
* }
* }
* } );
* } );
*/
"sSortAscending": ": activate to sort column ascending",
"sSortAscending": "_HEADER_: activate to sort column ascending",

/**
* ARIA label that is added to the table headers when the column may be
* sorted descending by activing the column (click or return when focused).
* Note that the column header is prefixed to this string.
* The variable _HEADER_ is replaced by the column header. If not present,
* the column header is prefixed to this string.
* @type string
* @default : activate to sort column ascending
* @default _HEADER_: activate to sort column ascending
*
* @dtopt Language
* @name DataTable.defaults.language.aria.sortDescending
Expand All @@ -1452,13 +1454,13 @@ DataTable.defaults = {
* $('#example').dataTable( {
* "language": {
* "aria": {
* "sortDescending": " - click/return to sort descending"
* "sortDescending": "click to sort by _HEADER_ descending"
* }
* }
* } );
* } );
*/
"sSortDescending": ": activate to sort column descending"
"sSortDescending": "_HEADER_: activate to sort column descending"
},

/**
Expand Down