Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (defaultListener) {
// Wrap callback so we don't set property directly on it.
callback = callback.bind();
callback.defaultListener_ = true;
}
attachDelegateEvent_(element, eventName);
if (isString(selectorOrTarget)) {
addSelectorListener_(element, eventName, selectorOrTarget, callback);
} else {
addElementListener_(selectorOrTarget, eventName, callback);
}
return new DomDelegatedEventHandle(
isString(selectorOrTarget) ? element : selectorOrTarget,
eventName,
callback,
isString(selectorOrTarget) ? selectorOrTarget : null
);
}
defaultListener
) {
const customConfig = customEvents[eventName];
if (customConfig && customConfig.delegate) {
eventName = customConfig.originalEvent;
callback = customConfig.handler.bind(customConfig, callback);
}
if (defaultListener) {
// Wrap callback so we don't set property directly on it.
callback = callback.bind();
callback.defaultListener_ = true;
}
attachDelegateEvent_(element, eventName);
if (isString(selectorOrTarget)) {
addSelectorListener_(element, eventName, selectorOrTarget, callback);
} else {
addElementListener_(selectorOrTarget, eventName, callback);
}
return new DomDelegatedEventHandle(
isString(selectorOrTarget) ? element : selectorOrTarget,
eventName,
callback,
isString(selectorOrTarget) ? selectorOrTarget : null
);
}
toEventsArray_(events) {
if (isString(events)) {
singleArray_[0] = events;
events = singleArray_;
}
return events;
}
export function removeClasses(elements, classes) {
if (!isObject(elements) || !isString(classes)) {
return;
}
if (!elements.length) {
elements = [elements];
}
for (let i = 0; i < elements.length; i++) {
if ('classList' in elements[i]) {
removeClassesWithNative_(elements[i], classes);
} else {
removeClassesWithoutNative_(elements[i], classes);
}
}
}
function getSubComponent_(tagOrCtor, config, owner) {
let Ctor = tagOrCtor;
if (isString(Ctor)) {
Ctor = ComponentRegistry.getConstructor(tagOrCtor);
}
const ref = getRef_(owner, config);
let comp;
if (isDef(ref)) {
comp = match_(owner.components[ref], Ctor, config, owner);
owner.components[ref] = comp;
owner.refs[ref] = comp;
} else {
const data = getCurrentData();
let key = config.key;
if (!isDef(key)) {
const type = getUid(Ctor, true);
data.currCount = data.currCount || {};
data.currCount[type] = data.currCount[type] || 0;
function inheritElementClasses_(parent, config) {
const parentData = getData(parent);
const parentConfig = parentData.config;
if (
!parentData.rootElementReached &&
parentConfig &&
isString(parentConfig.elementClasses)
) {
let currentClasses = '';
if (isString(config.elementClasses)) {
currentClasses = `${config.elementClasses} `;
}
config.elementClasses = currentClasses + parentConfig.elementClasses;
}
}
function renderLayoutToString(fnOrString) {
if (isString(fnOrString)) {
return fnOrString;
}
try {
const element = {};
IncrementalDOM.patch(element, () => fnOrString);
return element.innerHTML;
} catch (error) {
throw new Error(
`Metal.js layout type defined in this route cannot be rendered ` +
`from the server, only String or JSX layouts are supported.`
);
}
}
export function on(element, eventName, callback, capture) {
if (isString(element)) {
return delegate(document, eventName, element, callback);
}
const customConfig = customEvents[eventName];
if (customConfig && customConfig.event) {
eventName = customConfig.originalEvent;
callback = customConfig.handler.bind(customConfig, callback);
}
element.addEventListener(eventName, callback, capture);
return new DomEventHandle(element, eventName, callback, capture);
}