foam-framework
Version:
MVC metaprogramming framework
103 lines (94 loc) • 2.79 kB
HTML
<!--
Copyright 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../core/foam.css" />
<script language="javascript" src="../core/bootFOAM.js"></script>
<script language="javascript" src="../core/experimental/touch.js"></script>
<title>Horizontal Scroll Gesture</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<script>
MODEL({
name: 'HScrollGestureBlock',
extendsModel: 'foam.ui.View',
properties: [
{
name: 'x',
defaultValue: 0,
preSet: function(old, nu) {
if ( nu < 0 ) return 0;
if ( nu > 1000 ) return 1000;
return nu;
},
postSet: function() {
this.updatePosition();
}
},
{
name: 'y',
defaultValue: 0,
preSet: function(old, nu) {
if ( nu < 0 ) return 0;
if ( nu > 1000 ) return 1000;
return nu;
},
postSet: function() {
this.updatePosition();
}
}
],
listeners: [
{
name: 'updatePosition',
isFramed: true,
code: function() {
this.$.innerHTML = '"Scrolled" to ' + this.x + ' by ' + this.y + ' pixels';
}
}
],
methods: {
toHTML: function() {
return '<div id="' + this.id + '" style="position: absolute; background: #88f; width: 400px; height: 200px;">Drag me</div>';
},
initHTML: function() {
this.updatePosition();
this.X.gestureManager.install(this.X.foam.input.touch.GestureTarget.create({
containerID: this.id,
handler: this,
gesture: 'horizontalScroll'
}));
this.X.gestureManager.install(this.X.foam.input.touch.GestureTarget.create({
containerID: this.id,
handler: this,
gesture: 'verticalScroll'
}));
},
horizontalScrollMove: function(dx, tx, x) {
this.x += dx;
},
verticalScrollMove: function(dy) {
this.y += dy;
}
}
});
var Y = this.X.subWindow(window);
Y.touchManager = Y.foam.input.touch.TouchManager.create({});
Y.touchManager.install(document);
Y.gestureManager = Y.foam.input.touch.GestureManager.create();
var view = Y.HScrollGestureBlock.create();
view.write(Y);
</script>
</body>
</html>