From b312edc1c269050d31142faffaee1373586d7dc6 Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Fri, 27 Feb 2015 19:38:01 +0100 Subject: [PATCH] Prevent some errors on IE <=8 --- tarteaucitron.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index 0253ac5..2abd131 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -17,15 +17,19 @@ var tarteaucitron = { "idprocessed": [], "state": [], "launch": [], + "parameters": {}, "isAjax": false, "init": function (params) { "use strict"; - var origOpen = XMLHttpRequest.prototype.open; + var origOpen; + tarteaucitron.parameters = params; if (alreadyLaunch === 0) { alreadyLaunch = 1; if (window.addEventListener) { - window.addEventListener("load", tarteaucitron.load(params), false); + window.addEventListener("load", function () { + tarteaucitron.load(); + }, false); window.addEventListener("keydown", function (evt) { if (evt.keyCode === 27) { tarteaucitron.userInterface.closePanel(); @@ -37,7 +41,9 @@ var tarteaucitron = { } }, false); } else { - window.attachEvent("onload", tarteaucitron.load(params)); + window.attachEvent("onload", function () { + tarteaucitron.load(); + }); window.attachEvent("onkeydown", function (evt) { if (evt.keyCode === 27) { tarteaucitron.userInterface.closePanel(); @@ -51,6 +57,7 @@ var tarteaucitron = { } if (typeof XMLHttpRequest !== 'undefined') { + origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { if (window.addEventListener) { @@ -71,7 +78,7 @@ var tarteaucitron = { } } }, - "load": function (params) { + "load": function () { "use strict"; var cdn = tarteaucitron.cdn, language = tarteaucitron.getLanguage(), @@ -84,7 +91,8 @@ var tarteaucitron = { "orientation": "top", "removeCredit": false, "showAlertSmall": true - }; + }, + params = tarteaucitron.parameters; // Step 0: get params if (params !== undefined) { @@ -488,13 +496,15 @@ var tarteaucitron = { store = [], i; - Array.prototype.map.call(main.children, Object).sort(function (a, b) { - if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; } - if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; } - return 0; - }).forEach(function (element) { - main.appendChild(element); - }); + if (typeof Array.prototype.map === 'function') { + Array.prototype.map.call(main.children, Object).sort(function (a, b) { + if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; } + if (tarteaucitron.services[a.id.replace(/Line/g, '')].name < tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return -1; } + return 0; + }).forEach(function (element) { + main.appendChild(element); + }); + } } }, "cookie": {