1 | define(["dojo/_base/lang", "../_base", "dojo/_base/config", "dojo/_base/window", "dojo/on" |
---|
2 | ], function(lang, dxa, config, window, on){ |
---|
3 | /*===== |
---|
4 | dxa = dojox.analytics; |
---|
5 | on = dojo.on; |
---|
6 | =====*/ |
---|
7 | |
---|
8 | return (dxa.plugins.mouseOver = new (function(){ |
---|
9 | this.watchMouse = config["watchMouseOver"] || true; |
---|
10 | this.mouseSampleDelay = config["sampleDelay"] || 2500; |
---|
11 | this.addData = lang.hitch(dxa, "addData", "mouseOver"); |
---|
12 | this.targetProps = config["targetProps"] || ["id","className","localName","href", "spellcheck", "lang", "textContent", "value" ]; |
---|
13 | |
---|
14 | this.toggleWatchMouse=function(){ |
---|
15 | if (this._watchingMouse){ |
---|
16 | this._watchingMouse.remove(); |
---|
17 | delete this._watchingMouse; |
---|
18 | return; |
---|
19 | } |
---|
20 | on(window.doc, "mousemove", lang.hitch(this, "sampleMouse")); |
---|
21 | } |
---|
22 | |
---|
23 | if (this.watchMouse){ |
---|
24 | on(window.doc, "mouseover", lang.hitch(this, "toggleWatchMouse")); |
---|
25 | on(window.doc, "mouseout", lang.hitch(this, "toggleWatchMouse")); |
---|
26 | } |
---|
27 | |
---|
28 | this.sampleMouse=function(e){ |
---|
29 | if (!this._rateLimited){ |
---|
30 | this.addData("sample",this.trimMouseEvent(e)); |
---|
31 | this._rateLimited=true; |
---|
32 | setTimeout(lang.hitch(this, function(){ |
---|
33 | if (this._rateLimited){ |
---|
34 | //this.addData("sample", this.trimMouseEvent(this._lastMouseEvent)); |
---|
35 | this.trimMouseEvent(this._lastMouseEvent); |
---|
36 | delete this._lastMouseEvent; |
---|
37 | delete this._rateLimited; |
---|
38 | } |
---|
39 | }), this.mouseSampleDelay); |
---|
40 | } |
---|
41 | this._lastMouseEvent = e; |
---|
42 | return e; |
---|
43 | } |
---|
44 | |
---|
45 | this.trimMouseEvent=function(e){ |
---|
46 | var t = {}; |
---|
47 | for (var i in e){ |
---|
48 | switch(i){ |
---|
49 | //case "currentTarget": |
---|
50 | case "target": |
---|
51 | //case "originalTarget": |
---|
52 | //case "explicitOriginalTarget": |
---|
53 | var props=this.targetProps; |
---|
54 | t[i]={}; |
---|
55 | //console.log(e, i, e[i]); |
---|
56 | for(var j=0;j<props.length;j++){ |
---|
57 | if((typeof e[i] == "object" || typeof e[i] == "function") && props[j] in e[i]){ |
---|
58 | |
---|
59 | if (props[j]=="text" || props[j]=="textContent"){ |
---|
60 | if (e[i]["localName"] && (e[i]["localName"]!="HTML")&&(e[i]["localName"]!="BODY")){ |
---|
61 | t[i][props[j]]=e[i][props[j]].substr(0,50); |
---|
62 | } |
---|
63 | }else{ |
---|
64 | t[i][props[j]]=e[i][props[j]]; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | break; |
---|
69 | //case "clientX": |
---|
70 | //case "clientY": |
---|
71 | //case "pageX": |
---|
72 | //case "pageY": |
---|
73 | //case "screenX": |
---|
74 | //case "screenY": |
---|
75 | case "x": |
---|
76 | case "y": |
---|
77 | if (e[i]) { |
---|
78 | //console.log("Attempting: " + i); |
---|
79 | var val = e[i]; |
---|
80 | //console.log("val: " + val); console.log(i + "e of i: " + val); |
---|
81 | t[i]=val + ''; |
---|
82 | } |
---|
83 | break; |
---|
84 | default: |
---|
85 | //console.log("Skipping: ", i); |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | return t; |
---|
90 | } |
---|
91 | })()); |
---|
92 | }); |
---|