1/******************************************************************************* 2 * Copyright 2022 Adobe 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16(function(document) { 17 "use strict"; 18 19 window.CMP = window.CMP || {}; 20 window.CMP.utils = (function() { 21 var NS = "cmp"; 22 23 /** 24 * Reads options data from the Component wrapper element, defined via {@code data-cmp-*} data attributes 25 * 26 * @param {HTMLElement} element The component element to read options data from 27 * @param {String} is The component identifier 28 * @returns {String[]} The options read from the component data attributes 29 */ 30 var readData = function(element, is) { 31 var data = element.dataset; 32 var options = []; 33 var capitalized = is; 34 capitalized = capitalized.charAt(0).toUpperCase() + capitalized.slice(1); 35 var reserved = ["is", "hook" + capitalized]; 36 37 for (var key in data) { 38 if (Object.prototype.hasOwnProperty.call(data, key)) { 39 var value = data[key]; 40 41 if (key.indexOf(NS) === 0) { 42 key = key.slice(NS.length); 43 key = key.charAt(0).toLowerCase() + key.substring(1); 44 45 if (reserved.indexOf(key) === -1) { 46 options[key] = value; 47 } 48 } 49 } 50 } 51 return options; 52 }; 53 54 /** 55 * Set up the final properties of a component by evaluating the transform function or fall back to the default value on demand 56 * @param {String[]} options the options to transform 57 * @param {Object} properties object of properties of property functions 58 * @returns {Object} transformed properties 59 */ 60 var setupProperties = function(options, properties) { 61 var transformedProperties = {}; 62 63 for (var key in properties) { 64 if (Object.prototype.hasOwnProperty.call(properties, key)) { 65 var property = properties[key]; 66 if (options && options[key] != null) { 67 if (property && typeof property.transform === "function") { 68 transformedProperties[key] = property.transform(options[key]); 69 } else { 70 transformedProperties[key] = options[key]; 71 } 72 } else { 73 transformedProperties[key] = properties[key]["default"]; 74 } 75 } 76 } 77 return transformedProperties; 78 }; 79 80 81 return { 82 readData: readData, 83 setupProperties: setupProperties 84 }; 85 }()); 86 document.dispatchEvent(new CustomEvent("core.wcm.components.commons.site.utils.loaded")); 87}(window.document));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.