|
739 | 739 |
|
740 | 740 | var contentContainer = wizard.children(".content"),
|
741 | 741 | header = $(document.createElement(options.headerTag)).html(step.title),
|
742 |
| - body = $(document.createElement(options.bodyTag)).addClass("body").hide(); |
| 742 | + body = $(document.createElement(options.bodyTag)); |
743 | 743 |
|
744 | 744 | if (step.contentMode == null || step.contentMode === $.fn.steps.contentMode.html)
|
745 | 745 | {
|
|
763 | 763 | }
|
764 | 764 | state.stepCount++;
|
765 | 765 |
|
| 766 | + transformBody(wizard, body, index); |
766 | 767 | transformTitle(wizard, header, index);
|
767 | 768 |
|
768 | 769 | state.currentStep = getStepProperties(wizard, state.currentIndex);
|
|
849 | 850 | parent = anchor.parent(),
|
850 | 851 | isDisabled = parent.hasClass("disabled");
|
851 | 852 | // Remove the class to make the anchor clickable!
|
852 |
| - parent.removeClass("disabled"); |
| 853 | + parent.removeClass("disabled").attr("aria-disabled", "false"); |
853 | 854 | anchor.click();
|
854 | 855 |
|
855 | 856 | // An error occured
|
856 | 857 | if (oldIndex === state.currentIndex && isDisabled)
|
857 | 858 | {
|
858 | 859 | // Add the class again to disable the anchor; avoid click action.
|
859 |
| - parent.addClass("disabled"); |
| 860 | + parent.addClass("disabled").attr("aria-disabled", "true"); |
860 | 861 | return false;
|
861 | 862 | }
|
862 | 863 |
|
|
912 | 913 | state.transitionShowElement = stepContents.eq(index);
|
913 | 914 | stepContents.eq(oldIndex).fadeOut(options.transitionEffectSpeed, function ()
|
914 | 915 | {
|
915 |
| - var wizard = $(this).parents(":has(.steps)"); |
| 916 | + var wizard = $(this).attr("aria-hidden", "true").parents(":has(.steps)"); |
916 | 917 | var state = wizard.data("state");
|
917 | 918 |
|
918 | 919 | if (state.transitionShowElement)
|
919 | 920 | {
|
920 |
| - state.transitionShowElement.fadeIn(options.transitionEffectSpeed); |
| 921 | + state.transitionShowElement.fadeIn(options.transitionEffectSpeed, |
| 922 | + function () { $(this).attr("aria-hidden", "false"); }); |
921 | 923 | state.transitionShowElement = null;
|
922 | 924 | }
|
923 | 925 | }).promise();
|
|
927 | 929 | state.transitionShowElement = stepContents.eq(index);
|
928 | 930 | stepContents.eq(oldIndex).slideUp(options.transitionEffectSpeed, function ()
|
929 | 931 | {
|
930 |
| - var wizard = $(this).parents(":has(.steps)"); |
| 932 | + var wizard = $(this).attr("aria-hidden", "true").parents(":has(.steps)"); |
931 | 933 | var state = wizard.data("state");
|
932 | 934 |
|
933 | 935 | if (state.transitionShowElement)
|
934 | 936 | {
|
935 |
| - state.transitionShowElement.slideDown(options.transitionEffectSpeed); |
| 937 | + state.transitionShowElement.slideDown(options.transitionEffectSpeed, |
| 938 | + function () { $(this).attr("aria-hidden", "false"); }); |
936 | 939 | state.transitionShowElement = null;
|
937 | 940 | }
|
938 | 941 | }).promise();
|
|
946 | 949 | posFadeIn = (index > oldIndex) ? outerWidth : -(outerWidth);
|
947 | 950 |
|
948 | 951 | currentStep.animate({ left: posFadeOut }, options.transitionEffectSpeed,
|
949 |
| - function () { $(this).hide(); }).promise(); |
950 |
| - newStep.css("left", posFadeIn + "px").show(); |
| 952 | + function () { $(this).hide().attr("aria-hidden", "true"); }).promise(); |
| 953 | + newStep.css("left", posFadeIn + "px").show().attr("aria-hidden", "false"); |
951 | 954 | newStep.animate({ left: 0 }, options.transitionEffectSpeed).promise();
|
952 | 955 | break;
|
953 | 956 |
|
954 | 957 | default:
|
955 |
| - stepContents.eq(oldIndex).hide(); |
956 |
| - stepContents.eq(index).show(); |
| 958 | + stepContents.eq(oldIndex).hide().attr("aria-hidden", "true"); |
| 959 | + stepContents.eq(index).show().attr("aria-hidden", "false"); |
957 | 960 | break;
|
958 | 961 | }
|
959 | 962 |
|
|
987 | 990 | wizard.attr("role", "application").addClass(options.cssClass).empty().append(contentWrapper);
|
988 | 991 |
|
989 | 992 | var stepTitles = contentWrapper.children(options.headerTag),
|
990 |
| - stepContents = contentWrapper.children(options.bodyTag).addClass("body").hide(); |
| 993 | + stepContents = contentWrapper.children(options.bodyTag); |
991 | 994 |
|
992 | 995 | if (stepTitles.length > stepContents.length)
|
993 | 996 | {
|
|
1012 | 1015 | }
|
1013 | 1016 | }
|
1014 | 1017 |
|
| 1018 | + // Add WIA-ARIA support |
| 1019 | + stepContents.each(function (index) |
| 1020 | + { |
| 1021 | + transformBody(wizard, $(this), index); |
| 1022 | + }); |
| 1023 | + |
1015 | 1024 | // Make the start step visible
|
1016 |
| - stepContents.eq(startIndex).show(); |
| 1025 | + stepContents.eq(startIndex).show().attr("aria-hidden", "false"); |
1017 | 1026 |
|
1018 | 1027 | var stepsWrapper = $(document.createElement(options.stepsContainerTag))
|
1019 |
| - .addClass("steps").append($(document.createElement("ol"))); |
| 1028 | + .addClass("steps").append($("<ol role=\"tablist\"></ol>")); |
1020 | 1029 | wizard.prepend(stepsWrapper);
|
1021 | 1030 |
|
1022 | 1031 | stepTitles.each(function (index)
|
|
1030 | 1039 |
|
1031 | 1040 | if (index > startIndex && !options.enableAllSteps)
|
1032 | 1041 | {
|
1033 |
| - $(".steps > ol > li:eq(" + index + ")", wizard).addClass("disabled"); |
| 1042 | + $(".steps > ol > li:eq(" + index + ")", wizard).addClass("disabled") |
| 1043 | + .attr("aria-disabled", "true"); |
1034 | 1044 | }
|
1035 | 1045 | });
|
1036 | 1046 |
|
|
1063 | 1073 | }
|
1064 | 1074 | }
|
1065 | 1075 |
|
| 1076 | + /** |
| 1077 | + * Transforms the body to a proper tabpanel. |
| 1078 | + * |
| 1079 | + * @static |
| 1080 | + * @private |
| 1081 | + * @param wizard {Object} A jQuery wizard object |
| 1082 | + * @param body {Object} A jQuery body object |
| 1083 | + * @param index {Integer} The position of the body |
| 1084 | + * @since 0.9.7 |
| 1085 | + */ |
| 1086 | + function transformBody(wizard, body, index) |
| 1087 | + { |
| 1088 | + var uniqueId = getUniqueId(wizard), |
| 1089 | + uniqueBodyId = uniqueId + "-tabpanel-" + index, |
| 1090 | + uniqueHeaderId = uniqueId + "-header-" + index; |
| 1091 | + body.attr("id", uniqueBodyId).attr("role", "tabpanel").attr("aria-labelledby", uniqueHeaderId) |
| 1092 | + .addClass("body").hide().attr("aria-hidden", "true"); |
| 1093 | + } |
| 1094 | + |
1066 | 1095 | /**
|
1067 | 1096 | * Transforms the title to a step item button.
|
1068 | 1097 | *
|
|
1074 | 1103 | */
|
1075 | 1104 | function transformTitle(wizard, header, index)
|
1076 | 1105 | {
|
1077 |
| - header.attr("id", getUniqueId(wizard) + "-" + index).attr("tabindex", "-1").addClass("title"); |
1078 |
| - |
1079 |
| - var options = wizard.data("options"), |
| 1106 | + var uniqueId = getUniqueId(wizard), |
| 1107 | + uniqueStepId = uniqueId + "-tab-" + index, |
| 1108 | + uniqueBodyId = uniqueId + "-tabpanel-" + index, |
| 1109 | + uniqueHeaderId = uniqueId + "-header-" + index, |
| 1110 | + options = wizard.data("options"), |
1080 | 1111 | state = wizard.data("state"),
|
1081 | 1112 | stepCollection = $(".steps > ol", wizard),
|
1082 | 1113 | title = renderTemplate(options.titleTemplate, {
|
1083 | 1114 | index: index + 1,
|
1084 | 1115 | title: header.html()
|
1085 | 1116 | }),
|
1086 |
| - stepItem = $("<li><a href=\"#" + header.attr("id") + "\">" + title + "</a></li>"); |
| 1117 | + stepItem = $("<li role=\"tab\"><a id=\"" + uniqueStepId + "\" href=\"#" + uniqueHeaderId + |
| 1118 | + "\" aria-controls=\"" + uniqueBodyId + "\">" + title + "</a></li>"); |
| 1119 | + |
| 1120 | + header.attr("id", uniqueHeaderId).attr("tabindex", "-1").addClass("title"); |
1087 | 1121 |
|
1088 | 1122 | if (index === 0)
|
1089 | 1123 | {
|
|
1159 | 1193 |
|
1160 | 1194 | for (var i = index; i < wizard.data("state").stepCount; i++)
|
1161 | 1195 | {
|
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) |
| 1196 | + var uniqueStepId = uniqueId + "-tab-" + i, |
| 1197 | + uniqueBodyId = uniqueId + "-tabpanel-" + i, |
| 1198 | + uniqueHeaderId = uniqueId + "-header-" + i, |
| 1199 | + title = $(".content > .title:eq(" + i + ")", wizard).attr("id", uniqueHeaderId); |
| 1200 | + $(".steps > ol > li:eq(" + i + ") > a", wizard).attr("id", uniqueStepId) |
| 1201 | + .attr("aria-controls", uniqueBodyId).attr("href", "#" + uniqueHeaderId) |
1165 | 1202 | .html(renderTemplate(options.titleTemplate, { index: i + 1, title: title.html() }));
|
| 1203 | + $(".content > .body:eq(" + i + ")", wizard).attr("id", uniqueBodyId) |
| 1204 | + .attr("aria-labelledby", uniqueHeaderId); |
1166 | 1205 | }
|
1167 | 1206 | }
|
1168 | 1207 |
|
|
1192 | 1231 | currentOrNewStep.children("a").focus();
|
1193 | 1232 | }
|
1194 | 1233 |
|
1195 |
| - currentOrNewStep.addClass("current").removeClass("disabled done").children("a").prepend(currentInfo); |
| 1234 | + currentOrNewStep.addClass("current").removeClass("disabled done") |
| 1235 | + .attr("aria-disabled", "false").children("a").prepend(currentInfo); |
1196 | 1236 | stepTitles.eq(index).addClass("current").next(".body").addClass("current");
|
1197 | 1237 | }
|
1198 | 1238 |
|
|
0 commit comments