UNPKG

foam-framework

Version:
94 lines (85 loc) 2.67 kB
<!-- 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>Pinch/Twist Gesture</title> <meta name="viewport" content="width=device-width"> </head> <body> <script> MODEL({ name: 'PinchGestureBlock', extendsModel: 'foam.ui.View', properties: [ { name: 'rotation', defaultValue: 0, help: 'Angle of the twist. Clockwise in degrees, relative to the original position.', postSet: function() { this.updatePosition(); } }, 'oldRotation', { name: 'scale', defaultValue: 1, help: 'Scaling ratio. Relative to the native size of the element.', postSet: function() { this.updatePosition(); } }, 'oldScale' ], listeners: [ { name: 'updatePosition', isFramed: true, code: function() { this.$.style.webkitTransform = 'scale(' + this.scale + ') rotate(' + this.rotation + 'deg)'; } } ], 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: 'pinchTwist' })); }, pinchStart: function() { this.oldRotation = this.rotation; this.oldScale = this.scale; }, pinchMove: function(scale, rotation) { this.scale = this.oldScale * scale; this.rotation = this.oldRotation + rotation; } } }); 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.PinchGestureBlock.create(); view.write(Y); </script> </body> </html>