source: Dev/trunk/src/client/dojox/analytics/plugins/touchPress.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.6 KB
Line 
1define(["dojo/_base/lang","../_base", "dojo/_base/config", "dojo/_base/window", "dojo/on", "dojo/touch"
2], function(lang, dxa, config, window, on, touch){
3
4        // window startup data
5        return (dxa.plugins.touchPress = new (function(){
6                if(config["showTouchesDetails"] !== undefined && !config["showTouchesDetails"]){
7                        this.showTouchesDetails = false;                       
8                }else{
9                        this.showTouchesDetails = true;
10                }
11                this.targetProps = config["targetProps"] || ["id","className","nodeName", "localName","href", "spellcheck", "lang"];
12                this.textContentMaxChars = config["textContentMaxChars"] || 50;
13
14                this.addData = lang.hitch(dxa, "addData", "touch.press");
15                this.onTouchPress = function(e){
16                        this.addData(this.trimEvent(e));
17                };
18
19                this.addDataRelease = lang.hitch(dxa, "addData", "touch.release");
20                this.onTouchRelease = function(e){
21                        this.addDataRelease(this.trimEvent(e));
22                };
23
24                on(window.doc, touch.press, lang.hitch(this, "onTouchPress"));
25                on(window.doc, touch.release, lang.hitch(this, "onTouchRelease"));
26
27                this.handleTarget = function(t, target, i){
28                        var props = this.targetProps;
29                        t[i] = {};
30                        for(var j = 0;j < props.length;j++){
31                                if((typeof target == "object" || typeof target == "function") && props[j] in target){
32                                                                 
33                                        if(props[j] == "text" || props[j] == "textContent"){
34                                                if(target["localName"] && (target["localName"] != "HTML") && (target["localName"] != "BODY")){
35                                                        t[i][props[j]] = target[props[j]].substr(0,this.textContentMaxChars);
36                                                }
37                                        }else{
38                                                t[i][props[j]] = target[props[j]];
39                                        }
40                                }
41                        }
42                };
43               
44
45                this.trimEvent = function(e){
46                        var t = {};
47                        for(var i in e){
48                                switch(i){
49                                        case "target":
50                                                this.handleTarget(t, e[i], i)
51                                                break;
52                                                case "touches":
53                                                        if(e[i].length !== 0){
54                                                                t["touches.length"] = e[i].length;
55                                                        }
56                                                        if(this.showTouchesDetails){
57                                                                for(var j = 0;j < e[i].length;j++){
58                                                                        for(var s in e[i][j]){
59                                                                                switch(s){
60                                                                                        case "target":
61                                                                                                this.handleTarget(t, e[i][j].target, "touches["+j+"][target]");
62                                                                                        break; 
63                                                                                        case "clientX":
64                                                                                        case "clientY":
65                                                                                        case "screenX":
66                                                                                        case "screenY":
67                                                                                                if(e[i][j]){
68                                                                                                        var val = e[i][j][s];
69                                                                                                        t["touches["+j+"]["+s+"]"] = val + '';
70                                                                                                }
71                                                                                        break;
72                                                                                        default:
73                                                                                                //console.log("Skipping: ", i);
74                                                                                        break;
75                                                                                }
76                                                                        }
77                                                                }
78                                                        }
79                                                break;
80                                        case "clientX":
81                                        case "clientY":
82                                        case "screenX":
83                                        case "screenY":
84                                                t[i] = e[i];
85                                                break;
86                                }
87                        }
88                        return t;
89                };
90        })());
91});
Note: See TracBrowser for help on using the repository browser.