From 1f21d530862ec4b6d59183910eb6a18542430e0f Mon Sep 17 00:00:00 2001 From: David Molineus Date: Thu, 30 Aug 2018 14:58:44 +0200 Subject: [PATCH] Do not use Object.assign. It's not implemented in IE 11. --- src/Resources/public/js/optout.js | 11 +++++++++-- src/Resources/public/js/optout.min.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Resources/public/js/optout.js b/src/Resources/public/js/optout.js index e601df6..9d6c6d1 100644 --- a/src/Resources/public/js/optout.js +++ b/src/Resources/public/js/optout.js @@ -90,9 +90,16 @@ matomoOptOut.prototype.api = function (method) { }; matomoOptOut.prototype.merge = function (object, src) { - var extended = Object.assign({}, object); + var extended = {}; + var key; - for (var key in src) { + for (key in object) { + if (object.hasOwnProperty(key)) { + extended[key] = object[key]; + } + } + + for (key in src) { if (src.hasOwnProperty(key)) { extended[key] = src[key]; } diff --git a/src/Resources/public/js/optout.min.js b/src/Resources/public/js/optout.min.js index 6b29521..d069941 100644 --- a/src/Resources/public/js/optout.min.js +++ b/src/Resources/public/js/optout.min.js @@ -1 +1 @@ -var matomoOptOut=function(options){this.options=this.merge({selectors:{btn:"matomo-optout-btn",activatedStatus:"matomo-status-activated",deactivatedStatus:"matomo-status-deactivated",noNotTrackStatus:"matomo-status-do-not-track"},api:{uri:"index.php?module=API&format=json&method=",isTracked:"AjaxOptOut.isTracked",doTrack:"AjaxOptOut.doTrack",doIgnore:"AjaxOptOut.doIgnore"}},options||{});this.btn=document.getElementById(this.options.selectors.btn);if(this.btn.getAttribute("data-do-not-track")==="1"&&navigator.doNotTrack){this.doNotTrackStatus=document.getElementById(this.options.selectors.noNotTrackStatus);this.doNotTrackStatus.setAttribute("style","");return}this.activatedStatus=document.getElementById(this.options.selectors.activatedStatus);this.deactivatedStatus=document.getElementById(this.options.selectors.deactivatedStatus);this.deactivateLabel=this.btn.getAttribute("data-label-deactivate");this.activateLabel=this.btn.getAttribute("data-label-activate");this.matomoUrl=this.btn.getAttribute("data-matomo-url");this.cookieError=this.btn.getAttribute("data-cookie-error");this.enabled=null;this.btn.addEventListener("click",this.onClick.bind(this));this.api(this.options.api.isTracked)};matomoOptOut.prototype.update=function(enabled){if(this.enabled===enabled){alert(this.cookieError)}this.enabled=enabled;if(this.enabled){this.btn.innerHTML=this.deactivateLabel;this.activatedStatus.setAttribute("style","");this.deactivatedStatus.setAttribute("style","display:none")}else{this.btn.innerHTML=this.activateLabel;this.activatedStatus.setAttribute("style","display:none");this.deactivatedStatus.setAttribute("style","")}this.btn.setAttribute("style","")};matomoOptOut.prototype.onIsTracked=function(response){this.update(response.value)};matomoOptOut.prototype.onDoIgnore=function(response){this.api(this.options.api.isTracked)};matomoOptOut.prototype.onDoTrack=function(response){this.api(this.options.api.isTracked)};matomoOptOut.prototype.onClick=function(){if(this.enabled){this.api(this.options.api.doIgnore)}else{this.api(this.options.api.doTrack)}};matomoOptOut.prototype.api=function(method){var callback=method.split(".")[1];callback=callback.charAt(0).toUpperCase()+callback.slice(1);window.jsonp(this.matomoUrl+this.options.api.uri+method,{callbackName:"matomoOptOut.on"+callback})};matomoOptOut.prototype.merge=function(object,src){var extended=Object.assign({},object);for(var key in src){if(src.hasOwnProperty(key)){extended[key]=src[key]}}return extended};document.addEventListener("DOMContentLoaded",function(){window.matomoOptOut=new matomoOptOut}); \ No newline at end of file +var matomoOptOut=function(options){this.options=this.merge({selectors:{btn:"matomo-optout-btn",activatedStatus:"matomo-status-activated",deactivatedStatus:"matomo-status-deactivated",noNotTrackStatus:"matomo-status-do-not-track"},api:{uri:"index.php?module=API&format=json&method=",isTracked:"AjaxOptOut.isTracked",doTrack:"AjaxOptOut.doTrack",doIgnore:"AjaxOptOut.doIgnore"}},options||{});this.btn=document.getElementById(this.options.selectors.btn);if(this.btn.getAttribute("data-do-not-track")==="1"&&navigator.doNotTrack){this.doNotTrackStatus=document.getElementById(this.options.selectors.noNotTrackStatus);this.doNotTrackStatus.setAttribute("style","");return}this.activatedStatus=document.getElementById(this.options.selectors.activatedStatus);this.deactivatedStatus=document.getElementById(this.options.selectors.deactivatedStatus);this.deactivateLabel=this.btn.getAttribute("data-label-deactivate");this.activateLabel=this.btn.getAttribute("data-label-activate");this.matomoUrl=this.btn.getAttribute("data-matomo-url");this.cookieError=this.btn.getAttribute("data-cookie-error");this.enabled=null;this.btn.addEventListener("click",this.onClick.bind(this));this.api(this.options.api.isTracked)};matomoOptOut.prototype.update=function(enabled){if(this.enabled===enabled){alert(this.cookieError)}this.enabled=enabled;if(this.enabled){this.btn.innerHTML=this.deactivateLabel;this.activatedStatus.setAttribute("style","");this.deactivatedStatus.setAttribute("style","display:none")}else{this.btn.innerHTML=this.activateLabel;this.activatedStatus.setAttribute("style","display:none");this.deactivatedStatus.setAttribute("style","")}this.btn.setAttribute("style","")};matomoOptOut.prototype.onIsTracked=function(response){this.update(response.value)};matomoOptOut.prototype.onDoIgnore=function(response){this.api(this.options.api.isTracked)};matomoOptOut.prototype.onDoTrack=function(response){this.api(this.options.api.isTracked)};matomoOptOut.prototype.onClick=function(){if(this.enabled){this.api(this.options.api.doIgnore)}else{this.api(this.options.api.doTrack)}};matomoOptOut.prototype.api=function(method){var callback=method.split(".")[1];callback=callback.charAt(0).toUpperCase()+callback.slice(1);window.jsonp(this.matomoUrl+this.options.api.uri+method,{callbackName:"matomoOptOut.on"+callback})};matomoOptOut.prototype.merge=function(object,src){var extended={};var key;for(key in object){if(object.hasOwnProperty(key)){extended[key]=object[key]}}for(key in src){if(src.hasOwnProperty(key)){extended[key]=src[key]}}return extended};document.addEventListener("DOMContentLoaded",function(){window.matomoOptOut=new matomoOptOut}); \ No newline at end of file