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