The following sample code was written for Enyo 1.0 and the first kind defined was originally VFlexBox which I understand is no longer valid so I tried changing it to enyo.Control. I am new to Enyo and fairly new to Javascript. My background is more Java, C#, firmware, etc.
I've been trying to learn Enyo for possible use in some product code. Right now I just want to learn the support Enyo has for gestures and touch events on a tablet. This demo code seemed like a perfect fit. One thing I don't understand though is how the gesture events get registered. Maybe Enyo handles that but I don't see it in the code. I don't see anywhere where gesture event handlers are referenced. So how would they ever get called? Would I find this documented anywhere?
As an aside I do want to thank everyone who posts sample code. It is invaluable. Enyo is not yet heavily documented so this tidbits are gold mines. My only wish is that more would be complete solutions. I know to the author it is obvious where and how to use their sample code but to a newbie nothing is obvious. These forums are great but a 24 hour turnaround on questions is not uncommon so the more complete and obvious the samples can be the better. :)
Is this solution missing anything:
<!DOCTYPE HTML>
<html>
<head>
<title>Enyo Gestures</title>
<link href="enyo-2.0b2/enyo.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="enyo-2.0b2/enyo.js"></script>
</head>
<body>
<script type="text/javascript">
enyo.kind({
name : "Simple",
kind : enyo.Control,
components :
[
{
kind : "Header",
content : "Simple Multitouch Example",
constructor: function()
{
this.data = [];
}
},
{
kind: enyo.Control,
name:"mtouch",
id:"mtouch",
content: "Touch, drag, or pinch-zoom inside the green box to begin."
},
{
kind: enyo.Control,
name: "canvas",
nodeTag: "canvas",
domAttributes:
{
width:"1020px",
height:"656px",
style: "border: 2px solid #98bf21;"
}
}
],
rendered : function()
{
this.inherited(arguments);
this.$.canvas.hasNode();
},
gesturestartHandler: function(inSender, event)
{
this.$.mtouch.setContent("***** gesturestart: event.scale: " + event.scale + ", event.centerX: " + event.centerX + ", event.centerY: " + event.centerY);
},
gesturechangeHandler: function(inSender, event)
{
this.$.mtouch.setContent("***** gesturechange: event.scale: " + event.scale + ", event.centerX: " + event.centerX + ", event.centerY: " + event.centerY);
var can = this.$.canvas.node;
var c = can.getContext('2d');
c.fillStyle = "blue";
c.fillRect(event.centerX,event.centerY,10,10);
},
gestureendHandler: function(inSender, event)
{
this.$.mtouch.setContent("***** gestureend: event.scale: " + event.scale + ", event.centerX: " + event.centerX + ", event.centerY: " + event.centerY);
},
mousedownHandler: function(inSender, event)
{
var can = this.$.canvas.node;
var c = can.getContext('2d');
c.fillStyle = "green";
c.fillRect(event.offsetX,event.offsetY,10,10);
},
mousemoveHandler: function(inSender, event)
{
var can = this.$.canvas.node;
var c = can.getContext('2d');
c.fillStyle = "red";
c.fillRect(event.offsetX,event.offsetY,10,10);
}
});
new Simple().write();
</script>
</body>
</html>
Comments
- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·I think you have to change the name of the 'nodeTag' property in the declaration to just 'tag' (although I'm not certain if enyo 2 supports both).
- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·http://jsfiddle.net/DTPGv/1/
- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·Also, touch events do not have an offsetX or offsetY.
- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·The Event Handling docs cover which events enyo dispatches in the section titled "DOM and DOM-like Events" at the bottom of the page.
- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·- Spam
- Abuse
0 · Off Topic Insightful ·