From 5673cb0bffc4ec9a07c500107ea42ccb870e126e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"J.=20Rene=CC=81e=20Beach"?= <splendidnoise@gmail.com>
Date: Wed, 13 Mar 2013 13:18:19 -0400
Subject: [PATCH] Issue #1272990 by mgifford, Everett Zufelt, jessebeach: Make
 tabledrag warning message show when row weights are
 enabled, and add WAI-ARIA live region
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: J. Renée Beach <splendidnoise@gmail.com>
---
 core/misc/drupal.js         |   41 +++++++++++++++++++++++++----------------
 core/misc/tabledrag.js      |    9 ++++++---
 core/modules/block/block.js |   19 ++++++++++++-------
 3 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/core/misc/drupal.js b/core/misc/drupal.js
index d7a4e40..b057268 100644
--- a/core/misc/drupal.js
+++ b/core/misc/drupal.js
@@ -271,12 +271,14 @@ Drupal.t = function (str, args, options) {
    */
   Drupal.behaviors.drupalAnnounce = {
     attach: function (settings, context) {
-      liveElement = document.createElement('div');
-      liveElement.id = 'drupal-live-announce';
-      liveElement.className = 'element-invisible';
-      liveElement.setAttribute('aria-live', 'polite');
-      liveElement.setAttribute('aria-busy', 'false');
-      document.body.appendChild(liveElement);
+      if (!parent.window.document.getElementById('drupal-live-announce')) {
+        liveElement = document.createElement('div');
+        liveElement.id = 'drupal-live-announce';
+        liveElement.className = 'element-invisible';
+        liveElement.setAttribute('aria-live', 'polite');
+        liveElement.setAttribute('aria-busy', 'false');
+        parent.window.document.body.appendChild(liveElement);
+      }
     }
   };
 
@@ -307,17 +309,24 @@ Drupal.t = function (str, args, options) {
    */
   Drupal.announce = function (text, priority) {
     if (typeof text === 'string') {
-      // Clear the liveElement so that repeated strings will be read.
-      liveElement.innerHTML = '';
-      // Set the busy state to true until the node changes are complete.
-      liveElement.setAttribute('aria-busy', 'true');
-      // Set the priority to assertive, or default to polite.
-      liveElement.setAttribute('aria-live', (priority === 'assertive') ? 'assertive' : 'polite');
-      // Print the text to the live region.
-      liveElement.innerHTML = Drupal.checkPlain(text);
-      // The live text area is updated. Allow the AT to announce the text.
-      liveElement.setAttribute('aria-busy', 'false');
+      var el = liveElement || parent.window.document.getElementById('drupal-live-announce') || null;
+      if (el) {
+        // Clear the liveElement so that repeated strings will be read.
+        el.innerHTML = '';
+        // Set the busy state to true until the node changes are complete.
+        el.setAttribute('aria-busy', 'true');
+        // Set the priority to assertive, or default to polite.
+        el.setAttribute('aria-live', (priority === 'assertive') ? 'assertive' : 'polite');
+        // Print the text to the live region. Text should be passed through the
+        // t() function before being passed to announce().
+        el.innerHTML = text;
+        // The live text area is updated. Allow the AT to announce the text.
+        el.setAttribute('aria-busy', 'false');
+        // Return the string.
+        return text;
+      }
     }
+    return null;
   };
 }(document, Drupal));
 
diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js
index f578d4a..7ba03ca 100644
--- a/core/misc/tabledrag.js
+++ b/core/misc/tabledrag.js
@@ -1,4 +1,4 @@
-(function ($) {
+(function ($, Drupal) {
 
 "use strict";
 
@@ -1244,8 +1244,11 @@ $.extend(Drupal.theme, {
     return '<div class="indentation">&nbsp;</div>';
   },
   tableDragChangedWarning: function () {
-    return '<div class="tabledrag-changed-warning messages warning" role="alert">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('Changes made in this table will not be saved until the form is submitted.') + '</div>';
+    var text = Drupal.t('!changeMarker Changes made in this table will not be saved until the form is submitted.', {
+      '!changeMarker': Drupal.theme('tableDragChangedMarker')
+    });
+    return '<div class="tabledrag-changed-warning messages warning">' + Drupal.announce(text) + '</div>';
   }
 });
 
-})(jQuery);
+})(jQuery, Drupal);
diff --git a/core/modules/block/block.js b/core/modules/block/block.js
index 3084fb3..a84b9ce 100644
--- a/core/modules/block/block.js
+++ b/core/modules/block/block.js
@@ -1,4 +1,4 @@
-(function ($, window) {
+(function ($, Drupal, window) {
 
 "use strict";
 
@@ -63,11 +63,6 @@ Drupal.behaviors.blockDrag = {
       checkEmptyRegions(table, this);
     };
 
-    // A custom message for the blocks page specifically.
-    Drupal.theme.tableDragChangedWarning = function () {
-      return '<div class="messages warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('The changes to these blocks will not be saved until the <em>Save blocks</em> button is clicked.') + '</div>';
-    };
-
     // Add a handler so when a row is dropped, update fields dropped into new regions.
     tableDrag.onDrop = function () {
       var dragObject = this;
@@ -138,4 +133,14 @@ Drupal.behaviors.blockDrag = {
   }
 };
 
-})(jQuery, window);
+// A custom message for the blocks page specifically.
+Drupal.theme.tableDragChangedWarning = function () {
+  var text = Drupal.t('!changeMarker The changes to these blocks will not be saved until the %button button is clicked.', {
+    '!changeMarker': Drupal.theme('tableDragChangedMarker'),
+    '%button': Drupal.t('Save blocks')
+  });
+
+  return '<div class="messages warning">' + Drupal.announce(text) + '</div>';
+};
+
+})(jQuery, Drupal, window);
-- 
1.7.10.4

