Browse Source

Making id uniq

Amauri CHAMPEAUX 10 years ago
parent
commit
521b2280ee
2 changed files with 16 additions and 38 deletions
  1. 6 5
      tarteaucitron.js
  2. 10 33
      tarteaucitron.services.js

+ 6 - 5
tarteaucitron.js

@@ -203,7 +203,7 @@ var tarteaucitron = {
         },
         "respond": function (el, status) {
             "use strict";
-            var key = el.id.replace(new RegExp("(Allow|Deni)ed", "g"), '');
+            var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
         
             // return if same state
             if (tarteaucitron.state[key] === status) {
@@ -382,14 +382,15 @@ var tarteaucitron = {
             }
         }
     },
-    "engage": function (id, r) {
+    "engage": function (id) {
         "use strict";
-        var html = '';
-        
+        var html = '',
+            r = Math.floor(Math.random() * 100000);
+                
         html += '<div class="tac_activate">';
         html += '   <div class="tac_float">';
         html += '      <b>' + id + '</b> ' + tarteaucitron.lang.fallback + '<br/>';
-        html += '      <div class="tarteaucitronAllow" id="tacEngage' + id + r + '">';
+        html += '      <div class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
         html += '          ' + tarteaucitron.lang.allow;
         html += '       </div>';
         html += '   </div>';

+ 10 - 33
tarteaucitron.services.js

@@ -54,13 +54,9 @@ tarteaucitron.services.disqus = {
     },
     "fallback": function () {
         "use strict";
-        var id = 'disqus',
-            r = Math.floor(Math.random() * 100000);
+        var id = 'disqus';
         
-        document.getElementById('disqus_thread').innerHTML = tarteaucitron.engage(id, r);
-        document.getElementById('tacEngage' + id + r).onclick = function () {
-            tarteaucitron.userInterface.respond(document.getElementById(id + 'Allowed'), true);
-        };
+        document.getElementById('disqus_thread').innerHTML = tarteaucitron.engage(id);
     }
 };
 
@@ -87,15 +83,10 @@ tarteaucitron.services.sharethis = {
     "fallback": function () {
         "use strict";
         var cookies = ['__unam'],
-            id = 'sharethis',
-            r = Math.floor(Math.random() * 100000);
+            id = 'sharethis';
         
         tarteaucitron.cookie.purge(cookies);
-        
-        tarteaucitron.fallback(['tacSharethis'], tarteaucitron.engage(id, r));
-        document.getElementById('tacEngage' + id + r).onclick = function () {
-            tarteaucitron.userInterface.respond(document.getElementById(id + 'Allowed'), true);
-        };
+        tarteaucitron.fallback(['tacSharethis'], tarteaucitron.engage(id));
     }
 };
 
@@ -122,15 +113,10 @@ tarteaucitron.services.shareaholic = {
     "fallback": function () {
         "use strict";
         var cookies = ['__utma', '__utmb', '__utmc', '__utmz'],
-            id = 'shareaholic',
-            r = Math.floor(Math.random() * 100000);
+            id = 'shareaholic';
         
         tarteaucitron.cookie.purge(cookies);
-        
-        tarteaucitron.fallback(['shareaholic-canvas'], tarteaucitron.engage(id, r));
-        document.getElementById('tacEngage' + id + r).onclick = function () {
-            tarteaucitron.userInterface.respond(document.getElementById(id + 'Allowed'), true);
-        };
+        tarteaucitron.fallback(['shareaholic-canvas'], tarteaucitron.engage(id));
     }
 };
 
@@ -152,15 +138,10 @@ tarteaucitron.services.addthis = {
     "fallback": function () {
         "use strict";
         var cookies = ['__atuvc'],
-            id = 'addthis',
-            r = Math.floor(Math.random() * 100000);
+            id = 'addthis';
         
         tarteaucitron.cookie.purge(cookies);
-        
-        tarteaucitron.fallback(['addthis_sharing_toolbox'], tarteaucitron.engage(id, r));
-        document.getElementById('tacEngage' + id + r).onclick = function () {
-            tarteaucitron.userInterface.respond(document.getElementById(id + 'Allowed'), true);
-        };
+        tarteaucitron.fallback(['addthis_sharing_toolbox'], tarteaucitron.engage(id));
     }
 };
 
@@ -212,13 +193,9 @@ tarteaucitron.services.adsense = {
     },
     "fallback": function () {
         "use strict";
-        var id = 'adsense',
-            r = Math.floor(Math.random() * 100000);
+        var id = 'adsense';
         
-        tarteaucitron.fallback(['adsbygoogle'], tarteaucitron.engage(id, r));
-        document.getElementById('tacEngage' + id + r).onclick = function () {
-            tarteaucitron.userInterface.respond(document.getElementById(id + 'Allowed'), true);
-        };
+        tarteaucitron.fallback(['adsbygoogle'], tarteaucitron.engage(id));
     }
 };