1 | define(["dojo/_base/lang","../_base", "dojo/_base/config", "dojo/_base/window", "dojo/on" |
---|
2 | ], function(lang, dxa, config, window, on){ |
---|
3 | |
---|
4 | // window startup data |
---|
5 | return (dxa.plugins.mouseClick = new (function(){ |
---|
6 | this.addData = lang.hitch(dxa, "addData", "mouseClick"); |
---|
7 | this.targetProps = config["targetProps"] || ["id","className","nodeName", "localName","href", "spellcheck", "lang"]; |
---|
8 | this.textContentMaxChars = config["textContentMaxChars"] || 50; |
---|
9 | |
---|
10 | this.onClick = function(e){ |
---|
11 | this.addData(this.trimEvent(e)); |
---|
12 | }; |
---|
13 | on(window.doc, "click", lang.hitch(this, "onClick")); |
---|
14 | |
---|
15 | this.trimEvent = function(e){ |
---|
16 | var t = {}; |
---|
17 | for(var i in e){ |
---|
18 | switch(i){ |
---|
19 | case "target": |
---|
20 | case "originalTarget": |
---|
21 | case "explicitOriginalTarget": |
---|
22 | //var props = ["id","className","nodeName", "localName","href", "spellcheck", "lang"]; |
---|
23 | var props = this.targetProps; |
---|
24 | t[i] = {}; |
---|
25 | for(var j = 0;j < props.length;j++){ |
---|
26 | if(e[i][props[j]]){ |
---|
27 | if(props[j] == "text" || props[j] == "textContent"){ |
---|
28 | if((e[i]["localName"] != "HTML") && (e[i]["localName"] != "BODY")){ |
---|
29 | t[i][props[j]] = e[i][props[j]].substr(0,this.textContentMaxChars); |
---|
30 | } |
---|
31 | }else{ |
---|
32 | t[i][props[j]] = e[i][props[j]]; |
---|
33 | } |
---|
34 | } |
---|
35 | } |
---|
36 | break; |
---|
37 | case "clientX": |
---|
38 | case "clientY": |
---|
39 | case "pageX": |
---|
40 | case "pageY": |
---|
41 | case "screenX": |
---|
42 | case "screenY": |
---|
43 | t[i] = e[i]; |
---|
44 | break; |
---|
45 | } |
---|
46 | } |
---|
47 | return t; |
---|
48 | }; |
---|
49 | })()); |
---|
50 | }); |
---|