/usblInPageAddCustomVarMulti.js Secret
Last active
September 14, 2017 12:28
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function for adding Custom Variables for Usabilla In-Page widget based on the textContent from an Element based on a classname. | |
* Use this function after the function usblInPageAppendToClassMulti and before the loading of the in-page install script. | |
* | |
* @param {String} classnamedata [The classname of which the textcontent will retrieved] | |
* @param {String} propertyname [The property name that should be used for the custom variables] | |
*/ | |
function usblInPageAddCustomVarMulti(classnamedata, propertyname){ | |
var inPageWidgetElementList = document.querySelectorAll("div[ub-in-page]"); | |
var faqToggleElementList = document.getElementsByClassName(classnamedata); | |
var arrayLengthInpage = inPageWidgetElementList.length; | |
var arrayLengthFaqToggle = faqToggleElementList.length; | |
var customVarValue; | |
var inPageWidgetElementNode; | |
for (var i = 0; i < arrayLengthInpage; i++) { | |
inPageWidgetElementNode = inPageWidgetElementList[i]; | |
customVarValue = faqToggleElementList[i].textContent.trim(); | |
var usblInPageCustom = document.createAttribute("ub-in-page-" + propertyname); | |
usblInPageCustom.value = customVarValue; | |
inPageWidgetElementNode.setAttributeNode(usblInPageCustom); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment