Skip to content

Instantly share code, notes, and snippets.

@dmurphy1
Created June 9, 2021 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmurphy1/80353db25cab988555be584f6c9ac629 to your computer and use it in GitHub Desktop.
Save dmurphy1/80353db25cab988555be584f6c9ac629 to your computer and use it in GitHub Desktop.
Snippet from theme.js
jQuery(window).on('load', function() {
// Add data attribute for each Marketo form wrapper.
window.FormsPlus = window.FormsPlus || {
allDescriptors: {},
allMessages: {},
detours: {}
};
/*! @author Sanford Whiteman @license MIT */
FormsPlus.tagWrappers = function tagWrappers() {
/* common vars & aliases */
var ANCESTORS_STOR = '.mktoFormRow, .mktoFormCol',
INPUTS_STOR = 'INPUT,SELECT,TEXTAREA,BUTTON',
attrTag = 'data-wrapper-for',
_forEach = Array.prototype.forEach;
/* utility fn to tag wrapper containers with inner form inputs */
function tagMktoWrappers(formEl) {
_forEach.call(formEl.querySelectorAll(ANCESTORS_STOR), function(ancestor) {
ancestor.setAttribute(attrTag, '');
_forEach.call(ancestor.querySelectorAll(INPUTS_STOR), function(input) {
var currentTag = ancestor.getAttribute(attrTag);
ancestor.setAttribute(attrTag, [currentTag ? currentTag : '', input.id, input.name != input.id ? input.name : ''].join(' ').trim());
});
});
}
MktoForms2.whenRendered(function(form) {
var formEl = form.getFormElem()[0];
tagMktoWrappers(formEl);
});
};
FormsPlus.tagWrappers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment