MCPcopy Create free account
hub / github.com/HelloZeroNet/ZeroNet / setProperties

Function setProperties

plugins/UiPluginManager/media/js/all.js:288–366  ·  view source on GitHub ↗
(domNode, properties, projectionOptions)

Source from the content-addressed store, hash-verified

286 }
287 };
288 var setProperties = function (domNode, properties, projectionOptions) {
289 if (!properties) {
290 return;
291 }
292 var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
293 var propNames = Object.keys(properties);
294 var propCount = propNames.length;
295 for (var i = 0; i < propCount; i++) {
296 var propName = propNames[i];
297 /* tslint:disable:no-var-keyword: edge case */
298 var propValue = properties[propName];
299 /* tslint:enable:no-var-keyword */
300 if (propName === 'className') {
301 throw new Error('Property "className" is not supported, use "class".');
302 } else if (propName === 'class') {
303 if (domNode.className) {
304 // May happen if classes is specified before class
305 domNode.className += ' ' + propValue;
306 } else {
307 domNode.className = propValue;
308 }
309 } else if (propName === 'classes') {
310 // object with string keys and boolean values
311 var classNames = Object.keys(propValue);
312 var classNameCount = classNames.length;
313 for (var j = 0; j < classNameCount; j++) {
314 var className = classNames[j];
315 if (propValue[className]) {
316 domNode.classList.add(className);
317 }
318 }
319 } else if (propName === 'styles') {
320 // object with string keys and string (!) values
321 var styleNames = Object.keys(propValue);
322 var styleCount = styleNames.length;
323 for (var j = 0; j < styleCount; j++) {
324 var styleName = styleNames[j];
325 var styleValue = propValue[styleName];
326 if (styleValue) {
327 checkStyleValue(styleValue);
328 projectionOptions.styleApplyer(domNode, styleName, styleValue);
329 }
330 }
331 } else if (propName === 'key') {
332 continue;
333 } else if (propValue === null || propValue === undefined) {
334 continue;
335 } else {
336 var type = typeof propValue;
337 if (type === 'function') {
338 if (propName.lastIndexOf('on', 0) === 0) {
339 if (eventHandlerInterceptor) {
340 propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
341 }
342 if (propName === 'oninput') {
343 (function () {
344 // record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
345 var oldPropValue = propValue;

Callers 1

Calls 1

checkStyleValueFunction · 0.70

Tested by

no test coverage detected