blob: 56935bd4c32a87d6eb38f83f2603b6e453ab72d5 [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<script
src="../../build/userale-2.4.0.min.js"
data-url=""
data-tool="Apache UserALE.js Example"
data-threshold="1"
data-interval="100"
></script>
</head>
<body>
<div class="new-feature-button">
<canvas id="myCanvas" data-name="&#123;&#34;name&#34;&#58; &#34;John Doe&#34;&#125;" width="200" height="100" style="border:1px solid #000000;">
</canvas>
</div>
</body>
<script>
/**
* Builds an object containing attributes of an element.
* Attempts to parse all attribute values as JSON text.
* @param {Object} e Event from which the target elemnet's attributes should be extracted from.
* @return {Object} Object with element attributes as key value pairs.
*/
function buildAttrs(e) {
let attributes = {};
let attributeBlackList = ["style"];
if(e.target && e.target instanceof Element) {
for(attr of e.target.attributes) {
if(attributeBlackList.includes(attr.name))
continue;
let val = attr.value;
try {
val = JSON.parse(val);
} catch (error) {}
attributes[attr.name] = val;
}
}
return attributes;
}
/**
* Builds an object containing all css properties of an element.
* @param {Object} e Event from which the target elemnet's properties should be extracted from.
* @return {Object} Object with all CSS properties as key value pairs.
*/
export function buildCSS(e) {
let properties = {};
if(e.target && e.target instanceof Element) {
let styleObj = e.target.style
for(prop of styleObj) {
properties[prop] = styleObj.getPropertyValue(prop);
}
}
return properties;
}
window.userale.addCallbacks({
map(log, e) {
return {
...log,
attributes: buildAttrs(e),
style : buildCSS(e),
logType: 'custom',
};
}
});
</script>
</html>