1 | define(["dojo/_base/lang","../_base", "dojo/_base/window", "dojo/on", "dojo/_base/config", "dojo/touch", |
---|
2 | "dojox/gesture/tap", "dojox/gesture/swipe" |
---|
3 | |
---|
4 | ], function(lang, dxa, window, on, config, touch, tap, swipe){ |
---|
5 | |
---|
6 | // window startup data |
---|
7 | return (dxa.plugins.gestureEvents = new (function(){ |
---|
8 | |
---|
9 | // watch for dojox.gesture.swipe, use delay to avoid getting too many |
---|
10 | if(config["watchSwipe"] !== undefined && !config["watchSwipe"]){ |
---|
11 | this.watchSwipe = false; |
---|
12 | }else{ |
---|
13 | this.watchSwipe = true; |
---|
14 | } |
---|
15 | this.swipeSampleDelay = config["swipeSampleDelay"] || 1000; |
---|
16 | this.targetProps = config["targetProps"] || ["id","className","localName","href", "spellcheck", "lang", "textContent", "value" ]; |
---|
17 | this.textContentMaxChars = config["textContentMaxChars"] || 50; |
---|
18 | |
---|
19 | this.addDataSwipe = lang.hitch(dxa, "addData", "gesture.swipe"); |
---|
20 | this.sampleSwipe = function(e){ |
---|
21 | if(!this._rateLimited){ |
---|
22 | this.addDataSwipe(this.trimEvent(e)); |
---|
23 | this._rateLimited = true; |
---|
24 | setTimeout(lang.hitch(this, function(){ |
---|
25 | if(this._rateLimited){ |
---|
26 | this.trimEvent(this._lastSwipeEvent); |
---|
27 | delete this._lastSwipeEvent; |
---|
28 | delete this._rateLimited; |
---|
29 | } |
---|
30 | }), this.swipeSampleDelay); |
---|
31 | } |
---|
32 | this._lastSwipeEvent = e; |
---|
33 | return e; |
---|
34 | } |
---|
35 | if(this.watchSwipe){ |
---|
36 | on(window.doc, swipe, lang.hitch(this, "sampleSwipe")); |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | // watch for dojox.gesture.tap |
---|
41 | this.addData = lang.hitch(dxa, "addData", "gesture.tap"); |
---|
42 | this.onGestureTap = function(e){ |
---|
43 | this.addData(this.trimEvent(e)); |
---|
44 | } |
---|
45 | on(window.doc, tap, lang.hitch(this, "onGestureTap")); |
---|
46 | |
---|
47 | // watch for dojox.gesture.tap.doubletap |
---|
48 | this.addDataDoubleTap = lang.hitch(dxa, "addData", "gesture.tap.doubletap"); |
---|
49 | this.onGestureDoubleTap = function(e){ |
---|
50 | this.addDataDoubleTap(this.trimEvent(e)); |
---|
51 | } |
---|
52 | on(window.doc, tap.doubletap, lang.hitch(this, "onGestureDoubleTap")); |
---|
53 | |
---|
54 | // watch for dojox.gesture.tap.taphold |
---|
55 | this.addDataTapHold = lang.hitch(dxa, "addData", "gesture.tap.taphold"); |
---|
56 | this.onGestureTapHold = function(e){ |
---|
57 | this.addDataTapHold(this.trimEvent(e)); |
---|
58 | } |
---|
59 | on(window.doc, tap.hold, lang.hitch(this, "onGestureTapHold")); |
---|
60 | |
---|
61 | |
---|
62 | this.trimEvent = function(e){ |
---|
63 | var t = {}; |
---|
64 | for(var i in e){ |
---|
65 | switch(i){ |
---|
66 | case "target": |
---|
67 | var props = this.targetProps; |
---|
68 | t[i] = {}; |
---|
69 | for(var j = 0;j < props.length;j++){ |
---|
70 | if(e[i][props[j]]){ |
---|
71 | if(props[j] == "text" || props[j] == "textContent"){ |
---|
72 | if((e[i]["localName"] != "HTML") && (e[i]["localName"] != "BODY")){ |
---|
73 | t[i][props[j]] = e[i][props[j]].substr(0,this.textContentMaxChars); |
---|
74 | } |
---|
75 | }else{ |
---|
76 | t[i][props[j]] = e[i][props[j]]; |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | break; |
---|
81 | case "clientX": |
---|
82 | case "clientY": |
---|
83 | case "screenX": |
---|
84 | case "screenY": |
---|
85 | case "dx": |
---|
86 | case "dy": |
---|
87 | case "time": |
---|
88 | t[i] = e[i]; |
---|
89 | break; |
---|
90 | } |
---|
91 | } |
---|
92 | return t; |
---|
93 | } |
---|
94 | })()); |
---|
95 | }); |
---|