diff options
Diffstat (limited to 'StoneIsland/www/js/lib/products/CollectionView.js')
| -rw-r--r-- | StoneIsland/www/js/lib/products/CollectionView.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/StoneIsland/www/js/lib/products/CollectionView.js b/StoneIsland/www/js/lib/products/CollectionView.js index a1a506a3..1377277a 100644 --- a/StoneIsland/www/js/lib/products/CollectionView.js +++ b/StoneIsland/www/js/lib/products/CollectionView.js @@ -8,7 +8,12 @@ var CollectionView = ScrollableView.extend({ items: {}, events: { - "click .item": "pick", + "touchstart .item": "touchstart", + "touchmove .item": "touchmove", + "touchend .item": "touchend", + "mousedown .item": "touchstart", + "mousemove .item": "touchmove", + "mouseup .item": "touchend", }, initialize: function(){ @@ -62,5 +67,28 @@ var CollectionView = ScrollableView.extend({ var data = this.items[code] app.product.load(code, data) }, + + firstTouch: { x: 0, y: 0, id: "" }, + lastTouch: { x: 0, y: 0, id: "" }, + touchstart: function(e){ + var p = e.originalEvent.touches ? e.originalEvent.touches[0] : e.originalEvent + this.firstTouch.x = this.lastTouch.x = p.pageX + this.firstTouch.y = this.lastTouch.y = p.pageY + this.firstTouch.id = e.currentTarget.dataset.id + }, + touchmove: function(e){ + var p = e.originalEvent.touches ? e.originalEvent.touches[0] : e.originalEvent + this.lastTouch.x = p.pageX + this.lastTouch.y = p.pageY + this.lastTouch.id = e.currentTarget.dataset.id + }, + touchend: function(e){ + var first = app.collection.firstTouch + var last = app.collection.lastTouch + var distance = Math.sqrt( Math.pow(first.x - last.x, 2) + Math.pow(first.y - last.y, 2) ) + if (distance < 20) { + this.pick(e) + } + }, }) |
