Js

Global Variables and Selectors from header.js

The following javascript snippets are included in the global site template and are intended for reuse. Please refer to this section before creating your own.

Selectors

__helpers.head //document.getElementsByTagName('head')[0]
__helpers.body //document.getElementsByTagName('body')[0]
__helpers.headerDiv //document.getElementById('header')!
__helpers.footerDiv //document.getElementsByClassName('footer')[0]
__helpers.isiDevice ///ipad|iphone|ipod/i.test(navigator.userAgent.toLowerCase())
__helpers.isAndroid ///android/i.test(navigator.userAgent.toLowerCase())

Helper Functions

__helpers.getHeight(element); //gets height of an element
__helpers.parentElement(node); //finds the parent element of a node
__helpers.getText(element); //returns string of text from an element
__helpers.setText(element); //replaces text in an element
__helpers.onEvent(selector, "event", function() {}); //adds event listeners to an element
__helpers.hasClass(element, className); //returns true or false if element has specified className on it
__helpers.hasParentWithClass(element, className); //returns true or false if parent of element has specified className on it
__helpers.checkVisible(variable); //returns true or false if an element is on the screen
__helpers.createCookie(name, value); //creates cookie from name value pair
__helpers.readCookie("cookiename"); //return null or value of cookie
__helpers.localStorageGet(key); //returns undefined or value of local storage key
__helpers.localStorageSet(key, value); //creates a local storage key with supplied value
__helpers.localStorageRemove(key); //removes the local storage key and value
__helpers.getQueryStringValue(key); //checks url for key and returns matching string or undefined
__helpers.getBrowserDims(); //returns browser width and height example: {width: 809, height: 948}
__helpers.preventDefault(e);
__headerLayout.setProductSearchText("textForHeaderSearchInput"); //sets the text of the product search input

Site and Language Values

__headerData.site //site value, ex: US
__headerData.lang //language value, ex: en
__headerData.cur //currency value, ex: USD
__headerData.orderSite //site value, ex: US
__headerData.orderLang //language value, ex: en