Ver código fonte

Add a bodyPosition param

For blind people, the cookie banner must appear first in the source code. For this reason a bodyPosition parameter with the default value "top" is specified to  manage #tarteaucitronRoot
Carsten Meyer 5 anos atrás
pai
commit
f2eb28fa0b
1 arquivos alterados com 19 adições e 2 exclusões
  1. 19 2
      tarteaucitron.js

+ 19 - 2
tarteaucitron.js

@@ -214,6 +214,7 @@ var tarteaucitron = {
                 "cookieName": 'tarteaucitron',
                 "highPrivacy": true,
                 "orientation": "middle",
+                "bodyPosition": "top",
                 "removeCredit": false,
                 "showAlertSmall": true,
                 "cookieslist": true,
@@ -443,7 +444,15 @@ var tarteaucitron = {
                         document.body.appendChild(wrapper);*/
 
                         div.id = 'tarteaucitronRoot';
-                        body.appendChild(div, body);
+                        if (tarteaucitron.parameters.bodyPosition === 'top') { 
+                            // Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
+                            var bodyFirstChild = body.firstChild;
+                            body.insertBefore(div, bodyFirstChild);
+                        }
+                        else {
+                            // Append tarteaucitron: #tarteaucitronRoot last-child of the body
+                            body.appendChild(div, body);
+                        }
                         div.innerHTML = html;
                         
                         //ie compatibility
@@ -514,7 +523,15 @@ var tarteaucitron = {
                             html += '<div id="tarteaucitronPremium"></div>';
 
                             div.id = 'tarteaucitronRoot';
-                            body.appendChild(div, body);
+                            if (tarteaucitron.parameters.bodyPosition === 'top') { 
+                                // Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
+                                var bodyFirstChild = body.firstChild;
+                                body.insertBefore(div, bodyFirstChild);
+                            }
+                            else {
+                                // Append tarteaucitron: #tarteaucitronRoot last-child of the body
+                                body.appendChild(div, body);
+                            }
                             div.innerHTML = html;
                         }
                     }, 1500);