From fa483d86a36cc270fbd3f9660221343b1f669c67 Mon Sep 17 00:00:00 2001 From: code-crusher Date: Fri, 5 Apr 2019 11:51:40 +0530 Subject: [PATCH 1/4] make safe property access --- src/1_utils.js | 10 ++++++++++ src/journeys_utils.js | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/1_utils.js b/src/1_utils.js index 15df4ed3..9b3c3fa7 100644 --- a/src/1_utils.js +++ b/src/1_utils.js @@ -952,6 +952,16 @@ utils.removePropertiesFromObject = function(objectToModify, keysToRemove) { } }; +utils.getPropertyValueByNameFromObject = function(object, name) { + if (object && typeof object === "object") { + for (var key in object) { + if (object.hasOwnProperty(key) && key===name) { + return object[key]; + } + } + } +} + // v2/event utility functions var BRANCH_STANDARD_EVENTS = [ 'ADD_TO_CART', 'ADD_TO_WISHLIST', 'VIEW_CART', 'INITIATE_PURCHASE', 'ADD_PAYMENT_INFO', 'PURCHASE', 'SPEND_CREDITS', 'SEARCH', 'VIEW_ITEM', 'VIEW_ITEMS', 'RATE', 'SHARE', 'COMPLETE_REGISTRATION', 'COMPLETE_TUTORIAL', 'ACHIEVE_LEVEL', 'UNLOCK_ACHIEVEMENT' ]; diff --git a/src/journeys_utils.js b/src/journeys_utils.js index 70674f08..f8676ced 100644 --- a/src/journeys_utils.js +++ b/src/journeys_utils.js @@ -439,7 +439,8 @@ journeys_utils.animateBannerEntrance = function(banner) { banner.style.top = '0'; } else if (journeys_utils.position === 'bottom') { - if(!journeys_utils.journeyLinkData.journey_link_data['safeAreaRequired']) { + var safeAreaRequired = utils.getPropertyValueByNameFromObject(journeys_utils.journeyLinkData['journey_link_data'], 'safeAreaRequired') || false; + if(!safeAreaRequired) { banner.style.bottom = '0'; } else { journeys_utils._dynamicallyRepositionBanner(); From b69120bf93e0e74d7a6a4748e83bd7e52af60290 Mon Sep 17 00:00:00 2001 From: code-crusher Date: Fri, 5 Apr 2019 23:50:07 +0530 Subject: [PATCH 2/4] rename object var --- src/1_utils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/1_utils.js b/src/1_utils.js index 9b3c3fa7..722f33b5 100644 --- a/src/1_utils.js +++ b/src/1_utils.js @@ -952,11 +952,11 @@ utils.removePropertiesFromObject = function(objectToModify, keysToRemove) { } }; -utils.getPropertyValueByNameFromObject = function(object, name) { - if (object && typeof object === "object") { - for (var key in object) { - if (object.hasOwnProperty(key) && key===name) { - return object[key]; +utils.getPropertyValueByNameFromObj = function(objectToSearch, name) { + if (objectToSearch && typeof objectToSearch === "object") { + for (var key in objectToSearch) { + if (objectToSearch.hasOwnProperty(key) && key===name) { + return objectToSearch[key]; } } } From 578202c0683fb3b8b90665a729e2003d9f61b998 Mon Sep 17 00:00:00 2001 From: code-crusher Date: Fri, 5 Apr 2019 23:51:04 +0530 Subject: [PATCH 3/4] rename method --- src/journeys_utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/journeys_utils.js b/src/journeys_utils.js index f8676ced..a60c0e81 100644 --- a/src/journeys_utils.js +++ b/src/journeys_utils.js @@ -439,7 +439,7 @@ journeys_utils.animateBannerEntrance = function(banner) { banner.style.top = '0'; } else if (journeys_utils.position === 'bottom') { - var safeAreaRequired = utils.getPropertyValueByNameFromObject(journeys_utils.journeyLinkData['journey_link_data'], 'safeAreaRequired') || false; + var safeAreaRequired = utils.getPropertyValueByNameFromObj(journeys_utils.journeyLinkData['journey_link_data'], 'safeAreaRequired') || false; if(!safeAreaRequired) { banner.style.bottom = '0'; } else { From 04dcd0db10465368dd01a09fe67bd0012b074a88 Mon Sep 17 00:00:00 2001 From: code-crusher Date: Sun, 7 Apr 2019 11:42:21 +0530 Subject: [PATCH 4/4] use [] to access objects --- src/1_utils.js | 10 ---------- src/journeys_utils.js | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/1_utils.js b/src/1_utils.js index 722f33b5..15df4ed3 100644 --- a/src/1_utils.js +++ b/src/1_utils.js @@ -952,16 +952,6 @@ utils.removePropertiesFromObject = function(objectToModify, keysToRemove) { } }; -utils.getPropertyValueByNameFromObj = function(objectToSearch, name) { - if (objectToSearch && typeof objectToSearch === "object") { - for (var key in objectToSearch) { - if (objectToSearch.hasOwnProperty(key) && key===name) { - return objectToSearch[key]; - } - } - } -} - // v2/event utility functions var BRANCH_STANDARD_EVENTS = [ 'ADD_TO_CART', 'ADD_TO_WISHLIST', 'VIEW_CART', 'INITIATE_PURCHASE', 'ADD_PAYMENT_INFO', 'PURCHASE', 'SPEND_CREDITS', 'SEARCH', 'VIEW_ITEM', 'VIEW_ITEMS', 'RATE', 'SHARE', 'COMPLETE_REGISTRATION', 'COMPLETE_TUTORIAL', 'ACHIEVE_LEVEL', 'UNLOCK_ACHIEVEMENT' ]; diff --git a/src/journeys_utils.js b/src/journeys_utils.js index a60c0e81..893c4b6b 100644 --- a/src/journeys_utils.js +++ b/src/journeys_utils.js @@ -439,8 +439,8 @@ journeys_utils.animateBannerEntrance = function(banner) { banner.style.top = '0'; } else if (journeys_utils.position === 'bottom') { - var safeAreaRequired = utils.getPropertyValueByNameFromObj(journeys_utils.journeyLinkData['journey_link_data'], 'safeAreaRequired') || false; - if(!safeAreaRequired) { + // check if safeAreaRequired is true or not + if (journeys_utils.journeyLinkData && journeys_utils.journeyLinkData['journey_link_data'] && !journeys_utils.journeyLinkData['journey_link_data']['safeAreaRequired']) { banner.style.bottom = '0'; } else { journeys_utils._dynamicallyRepositionBanner();