瀏覽代碼

Merge pull request #393 from mobyou/patch-1

Add a bodyPosition param
Amauri CHAMPEAUX 5 年之前
父節點
當前提交
b7e4b632e5
共有 1 個文件被更改,包括 19 次插入2 次删除
  1. 19 2
      tarteaucitron.js

+ 19 - 2
tarteaucitron.js

@@ -225,6 +225,7 @@ var tarteaucitron = {
                 "cookieName": 'tarteaucitron',
                 "highPrivacy": true,
                 "orientation": "middle",
+                "bodyPosition": "bottom",
                 "removeCredit": false,
                 "showAlertSmall": true,
                 "cookieslist": true,
@@ -468,7 +469,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
@@ -539,7 +548,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);