|
28 | 28 | * - Jump from any page to a specific step (via uri hash tag test.html#steps-uid-1-3) |
29 | 29 | * - Add Swipe gesture for devices that support touch |
30 | 30 | * - Allow clicking on the next step even if it is disabled (so that people can decide whether they use prev button or the step button next to the current step) |
| 31 | + * - Property to set the step orientation (horizontal/vertical) [stepOrientation: "horizontal" v 0] |
31 | 32 | * |
32 | 33 | */ |
33 | 34 |
|
34 | 35 | /** |
35 | 36 | * @module jQuery.steps |
36 | 37 | * @requires jQuery (always required), jQuery.cookie (only required if saveState is `true`) |
37 | 38 | */ |
38 | | -(function ($) |
| 39 | +;(function ($, undefined) |
39 | 40 | { |
| 41 | + "use strict"; |
| 42 | + |
40 | 43 | /** |
41 | 44 | * A global unique id count. |
42 | 45 | * |
|
487 | 490 | **/ |
488 | 491 | current: "current step:", |
489 | 492 |
|
| 493 | + /** |
| 494 | + * This label is important for accessability reasons and describes the kind of navigation. |
| 495 | + * |
| 496 | + * @property pagination |
| 497 | + * @type String |
| 498 | + * @default "Pagination" |
| 499 | + * @for defaults |
| 500 | + * @since 0.9.7 |
| 501 | + **/ |
| 502 | + pagination: "Pagination", |
| 503 | + |
490 | 504 | /** |
491 | 505 | * Label for the finish button. |
492 | 506 | * |
|
776 | 790 | **/ |
777 | 791 | function initialize(options) |
778 | 792 | { |
| 793 | + /*jshint -W040 */ |
779 | 794 | var opts = $.extend(true, {}, $.fn.steps.defaults, options); |
780 | 795 |
|
781 | 796 | return this.each(function (i) |
|
964 | 979 | { |
965 | 980 | var options = wizard.data("options"), |
966 | 981 | state = wizard.data("state"), |
| 982 | + uniqueId = getUniqueId(wizard), |
967 | 983 | contentWrapper = $(document.createElement(options.contentContainerTag)).addClass("content"), |
968 | 984 | startIndex = options.startIndex; |
969 | 985 |
|
970 | 986 | contentWrapper.html(wizard.html()); |
971 | | - wizard.addClass(options.cssClass).empty().append(contentWrapper); |
| 987 | + wizard.attr("role", "application").addClass(options.cssClass).empty().append(contentWrapper); |
972 | 988 |
|
973 | 989 | var stepTitles = contentWrapper.children(options.headerTag), |
974 | 990 | stepContents = contentWrapper.children(options.bodyTag).addClass("body").hide(); |
|
987 | 1003 | // Tries to load the saved state (step position) |
988 | 1004 | if (options.saveState && $.cookie) |
989 | 1005 | { |
990 | | - var savedState = $.cookie(_cookiePrefix + getUniqueId(wizard)); |
| 1006 | + var savedState = $.cookie(_cookiePrefix + uniqueId); |
991 | 1007 | // Sets the saved position to the start index if not undefined or out of range |
992 | 1008 | var savedIndex = parseInt(savedState, 0); |
993 | 1009 | if (!isNaN(savedIndex) && savedIndex < state.stepCount) |
|
1025 | 1041 |
|
1026 | 1042 | if (options.enablePagination) |
1027 | 1043 | { |
1028 | | - var actionCollection = $(document.createElement("ul")), |
| 1044 | + var actionCollection = $("<ul role=\"menu\" aria-label=\"" + options.labels.pagination + "\"></ul>"), |
1029 | 1045 | actionWrapper = $(document.createElement(options.actionContainerTag)) |
1030 | 1046 | .addClass("actions").append(actionCollection); |
1031 | 1047 | wizard.append(actionWrapper); |
1032 | 1048 |
|
1033 | 1049 | if (!options.forceMoveForward) |
1034 | 1050 | { |
1035 | | - actionCollection.append($("<li><a href=\"#previous\">" + options.labels.previous + "</a></li>")); |
| 1051 | + actionCollection.append($("<li><a href=\"#previous\" role=\"menuitem\">" + options.labels.previous + "</a></li>")); |
1036 | 1052 | } |
1037 | 1053 |
|
1038 | | - actionCollection.append($("<li><a href=\"#next\">" + options.labels.next + "</a></li>")); |
| 1054 | + actionCollection.append($("<li><a href=\"#next\" role=\"menuitem\">" + options.labels.next + "</a></li>")); |
1039 | 1055 |
|
1040 | 1056 | if (options.enableFinishButton) |
1041 | 1057 | { |
1042 | | - actionCollection.append($("<li><a href=\"#finish\">" + options.labels.finish + "</a></li>")); |
| 1058 | + actionCollection.append($("<li><a href=\"#finish\" role=\"menuitem\">" + options.labels.finish + "</a></li>")); |
1043 | 1059 | } |
1044 | 1060 |
|
1045 | 1061 | refreshActionState(wizard); |
|
1067 | 1083 | index: index + 1, |
1068 | 1084 | title: header.html() |
1069 | 1085 | }), |
1070 | | - stepItem = $("<li></li>").html("<a href=\"#" + header.attr("id") + "\">" + title + "</a>"); |
| 1086 | + stepItem = $("<li><a href=\"#" + header.attr("id") + "\">" + title + "</a></li>"); |
1071 | 1087 |
|
1072 | 1088 | if (index === 0) |
1073 | 1089 | { |
|
1138 | 1154 | */ |
1139 | 1155 | function updateSteps(wizard, index) |
1140 | 1156 | { |
1141 | | - var options = wizard.data("options"); |
| 1157 | + var options = wizard.data("options"), |
| 1158 | + uniqueId = getUniqueId(wizard); |
1142 | 1159 |
|
1143 | 1160 | for (var i = index; i < wizard.data("state").stepCount; i++) |
1144 | 1161 | { |
1145 | | - var title = $(".content > .title:eq(" + i + ")", wizard).attr("id", getUniqueId(wizard) + "-" + i); |
1146 | | - $(".steps > ol > li:eq(" + i + ") > a", wizard).attr("href", "#" + getUniqueId(wizard) + "-" + i) |
| 1162 | + var uniqueStepId = getUniqueId(wizard) + "-" + i, |
| 1163 | + title = $(".content > .title:eq(" + i + ")", wizard).attr("id", uniqueStepId); |
| 1164 | + $(".steps > ol > li:eq(" + i + ") > a", wizard).attr("href", "#" + uniqueStepId) |
1147 | 1165 | .html(renderTemplate(options.titleTemplate, { index: i + 1, title: title.html() })); |
1148 | 1166 | } |
1149 | 1167 | } |
|
1163 | 1181 | var options = wizard.data("options"), |
1164 | 1182 | steps = $(".steps li", wizard), |
1165 | 1183 | currentOrNewStep = steps.eq(index), |
1166 | | - currentInfo = $("<span class=\"current-info\">" + options.labels.current + " </span>"), |
| 1184 | + currentInfo = $("<span class=\"current-info audible\">" + options.labels.current + " </span>"), |
1167 | 1185 | stepTitles = $(".content > .title", wizard); |
1168 | 1186 |
|
1169 | 1187 | if (oldIndex != null) |
|
1179 | 1197 | } |
1180 | 1198 |
|
1181 | 1199 | /** |
1182 | | - * Refreshs the visualization for the complete action navigation. |
| 1200 | + * Refreshs the visualization for the entire pagination. |
1183 | 1201 | * |
1184 | 1202 | * @static |
1185 | 1203 | * @private |
|
1201 | 1219 | var previous = $(".actions a[href$='#previous']", wizard).parent(); |
1202 | 1220 | if (state.currentIndex > 0) |
1203 | 1221 | { |
1204 | | - previous.removeClass("disabled"); |
| 1222 | + previous.removeClass("disabled").attr("aria-disabled", "false"); |
1205 | 1223 | } |
1206 | 1224 | else |
1207 | 1225 | { |
1208 | | - previous.addClass("disabled"); |
| 1226 | + previous.addClass("disabled").attr("aria-disabled", "true"); |
1209 | 1227 | } |
1210 | 1228 | } |
1211 | 1229 |
|
1212 | 1230 | if (options.enableFinishButton && options.showFinishButtonAlways) |
1213 | 1231 | { |
1214 | 1232 | if (state.stepCount === 0) |
1215 | 1233 | { |
1216 | | - finish.addClass("disabled"); |
1217 | | - next.addClass("disabled"); |
| 1234 | + finish.addClass("disabled").attr("aria-disabled", "true"); |
| 1235 | + next.addClass("disabled").attr("aria-disabled", "true"); |
1218 | 1236 | } |
1219 | 1237 | else if (state.stepCount > 1 && state.stepCount > (state.currentIndex + 1)) |
1220 | 1238 | { |
1221 | | - finish.removeClass("disabled"); |
1222 | | - next.removeClass("disabled"); |
| 1239 | + finish.removeClass("disabled").attr("aria-disabled", "false"); |
| 1240 | + next.removeClass("disabled").attr("aria-disabled", "false"); |
1223 | 1241 | } |
1224 | 1242 | else |
1225 | 1243 | { |
1226 | | - finish.removeClass("disabled"); |
1227 | | - next.addClass("disabled"); |
| 1244 | + finish.removeClass("disabled").attr("aria-disabled", "false"); |
| 1245 | + next.addClass("disabled").attr("aria-disabled", "true"); |
1228 | 1246 | } |
1229 | 1247 | } |
1230 | 1248 | else |
1231 | 1249 | { |
1232 | 1250 | if (state.stepCount === 0) |
1233 | 1251 | { |
1234 | | - finish.hide(); |
1235 | | - next.show().addClass("disabled"); |
| 1252 | + finish.hide().attr("aria-hidden", "true"); |
| 1253 | + next.show().attr("aria-hidden", "false").addClass("disabled").attr("aria-disabled", "true"); |
1236 | 1254 | } |
1237 | 1255 | else if (state.stepCount > (state.currentIndex + 1)) |
1238 | 1256 | { |
1239 | | - finish.hide(); |
1240 | | - next.show().removeClass("disabled"); |
| 1257 | + finish.hide().attr("aria-hidden", "true"); |
| 1258 | + next.show().attr("aria-hidden", "false").removeClass("disabled").attr("aria-disabled", "false"); |
1241 | 1259 | } |
1242 | 1260 | else if (!options.enableFinishButton) |
1243 | 1261 | { |
1244 | | - next.addClass("disabled"); |
| 1262 | + next.addClass("disabled").attr("aria-disabled", "true"); |
1245 | 1263 | } |
1246 | 1264 | else |
1247 | 1265 | { |
1248 | | - finish.show(); |
1249 | | - next.hide().addClass("disabled"); |
| 1266 | + finish.show().attr("aria-hidden", "false"); |
| 1267 | + next.hide().attr("aria-hidden", "true"); |
1250 | 1268 | } |
1251 | 1269 | } |
1252 | 1270 | } |
|
1452 | 1470 | } |
1453 | 1471 |
|
1454 | 1472 | /** |
1455 | | - * Handles the keyup DOM event. |
| 1473 | + * Handles the keyup DOM event for pagination. |
1456 | 1474 | * |
1457 | 1475 | * @static |
1458 | 1476 | * @private |
|
0 commit comments