From 231d5161d613c4927312e9fbc9894f540b49db31 Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Thu, 9 May 2019 10:58:22 +0100 Subject: [PATCH] MDL-65539 formats: Section labels not updated during move Before this change when moving a section via drag and drop the aria-label for the section was not being updated neither was the title on the drag handle. The result was the the drop menu on keyboard drag and drop displayed the wrong information after a section was moved. --- course/format/topics/format.js | 12 +++++++----- course/format/weeks/format.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/course/format/topics/format.js b/course/format/topics/format.js index c7e69419c5b..9b4807fd6a1 100644 --- a/course/format/topics/format.js +++ b/course/format/topics/format.js @@ -48,6 +48,7 @@ M.course.format.swap_sections = function(Y, node1, node2) { * Process sections after ajax response * * @param {YUI} Y YUI3 instance + * @param {NodeList} sectionlist of sections * @param {array} response ajax response * @param {string} sectionfrom first affected section * @param {string} sectionto last affected section @@ -76,13 +77,14 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro // Update section title. var content = Y.Node.create('' + response.sectiontitles[i] + ''); sectionlist.item(i).all('.'+CSS.SECTIONNAME).setHTML(content); - // Update move icon. - ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); - str = ele.getAttribute('alt'); + // Update the drag handle. + ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE).ancestor('.section-handle'); + str = ele.getAttribute('title'); stridx = str.lastIndexOf(' '); newstr = str.substr(0, stridx +1) + i; - ele.setAttribute('alt', newstr); - ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed. + ele.setAttribute('title', newstr); + // Update the aria-label for the section. + sectionlist.item(i).setAttribute('aria-label', content.get('innerText').trim()); } } } diff --git a/course/format/weeks/format.js b/course/format/weeks/format.js index 1fb0c8ed7fd..b37f233456f 100644 --- a/course/format/weeks/format.js +++ b/course/format/weeks/format.js @@ -48,6 +48,7 @@ M.course.format.swap_sections = function(Y, node1, node2) { * Process sections after ajax response * * @param {YUI} Y YUI3 instance + * @param {NodeList} sectionlist of sections * @param {array} response ajax response * @param {string} sectionfrom first affected section * @param {string} sectionto last affected section @@ -77,13 +78,14 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro var content = Y.Node.create('' + response.sectiontitles[i] + ''); sectionlist.item(i).all('.'+CSS.SECTIONNAME).setHTML(content); - // Update move icon. - ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE); - str = ele.getAttribute('alt'); + // Update the drag handle. + ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE).ancestor('.section-handle'); + str = ele.getAttribute('title'); stridx = str.lastIndexOf(' '); newstr = str.substr(0, stridx +1) + i; - ele.setAttribute('alt', newstr); - ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed. + ele.setAttribute('title', newstr); + // Update the aria-label for the section. + sectionlist.item(i).setAttribute('aria-label', content.get('innerText').trim()); // Remove the current class as section has been moved. sectionlist.item(i).removeClass('current');