From 57cc4c87f45938e0bc9227fb09285baaebeb0b4f Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Fri, 12 Dec 2014 17:04:23 +0100 Subject: [PATCH] Prevent multi init() --- tarteaucitron.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index 3b0c54e..82f61a8 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -3,7 +3,8 @@ // define correct path for files inclusion var scripts = document.getElementsByTagName('script'), path = scripts[scripts.length - 1].src.split('?')[0], - cdn = path.split('/').slice(0, -1).join('/') + '/'; + cdn = path.split('/').slice(0, -1).join('/') + '/', + alreadyLaunch = (alreadyLaunch === undefined) ? 0 : alreadyLaunch; var tarteaucitron = { "cdn": cdn, @@ -14,10 +15,13 @@ var tarteaucitron = { "launch": [], "init": function (params) { "use strict"; - if (window.addEventListener) { - window.addEventListener("load", tarteaucitron.load(params), false); - } else { - window.attachEvent('onload', tarteaucitron.load(params)); + if (alreadyLaunch === 0) { + alreadyLaunch = 1; + if (window.addEventListener) { + window.addEventListener("load", tarteaucitron.load(params), false); + } else { + window.attachEvent('onload', tarteaucitron.load(params)); + } } }, "load": function (params) {