@hydrogen-design-system/system
Version:
Hydrogen's full design system and component library.
37 lines (32 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.h2PropUA = h2PropUA;
// Hydrogen / Properties / Module JS
// This file is designed to be the location in which all scripting for the component's functionality exists. This file should export all relevant functionality so that it can be imported by Hydrogen and other systems.
// Development Notes:
// - please ensure all functions are defined with "" at the end of their name.
// - please ensure all references to the parent component's selector also include "" (e.g. [data-h2-accordion])
// This is so that when the component is built, it produces a version-locked set of code that can me manually imported to override newer versions.
// - please ensure that when event listeners are added to a trigger, that the script is checking for the system variable (see an example below).
// Add the user agent to the main object.
function h2PropUA(version) {
var ua = navigator.userAgent;
ua = ua.toString();
var props;
if (version == "latest") {
props = document.querySelectorAll("[data-h2-system]");
} else if (version == null || version == false || version == "") {
props = document.querySelectorAll("[data-h2-properties]");
if (props == null || props.length == 0) {
console.log("Hydrogen (Properties User Agent Script): It looks like you're trying to use the property tool independently from Hydrogen's design system. As a result, the data-h2-properties attribute could not be found on the page. Please ensure this attribute wraps all elements that you intend to use Hydrogen with.");
return false;
}
} else {
props = document.querySelectorAll("[data-h2-system='" + version + "']");
}
props.forEach(function (prop) {
prop.setAttribute("data-h2-ua", ua);
});
} // Export the module.