SHOW:
|
|
- or go back to the newest paste.
1 | - | var touchEvent = function (_event) { |
1 | + | var prevItem = null; |
2 | - | if (cancelSwipe) return; |
2 | + | var nextItem = null; |
3 | var swipeValue = APP.Device.width * 0.51; | |
4 | var cancelSwipe = false; | |
5 | var xStart = 0, xPrev = 0; | |
6 | $.createRecipeListItem = function(_item, _i, _isFirst) { | |
7 | if (!_isFirst) { | |
8 | prevItem = $.recipeInfoWrapper.getChildren()[0]; | |
9 | } | |
10 | ||
11 | nextItem = Ti.UI.createScrollView({ | |
12 | opacity: _isFirst ? 1 : 0, | |
13 | height: Ti.UI.SIZE, | |
14 | top: '0dp', | |
15 | left: OS_IOS ? '10dp' : Alloy.Globals.padding, | |
16 | - | }; |
16 | + | right: OS_IOS ? '10dp' : Alloy.Globals.padding, |
17 | layout: 'vertical', | |
18 | - | nextItem.removeEventListener('touchmove', touchEvent); |
18 | + | id: 'recipeInfo_MainWrapper_' + _item.id, |
19 | - | nextItem.addEventListener('touchmove', touchEvent); |
19 | + | globalSwipe: false |
20 | }); | |
21 | ||
22 | $.drawRecipeItem(_item, _i, nextItem); | |
23 | ||
24 | $.drawIngridientsList(_item, _i, nextItem); | |
25 | ||
26 | $.recipeInfoWrapper.add(nextItem); | |
27 | ||
28 | if (!_isFirst) { | |
29 | prevItem.animate({ | |
30 | opacity: 0, | |
31 | duration: 150 | |
32 | }, function () { | |
33 | while ($.recipeInfoWrapper.getChildren().length > 1) { | |
34 | $.recipeInfoWrapper.remove($.recipeInfoWrapper.getChildren()[0]); | |
35 | }; | |
36 | }); | |
37 | ||
38 | nextItem.animate({ | |
39 | opacity: 1, | |
40 | duration: 150 | |
41 | }, function () { | |
42 | cancelSwipe = false; | |
43 | }); | |
44 | } else { | |
45 | while ($.recipeInfoWrapper.getChildren().length > 1) { | |
46 | $.recipeInfoWrapper.remove($.recipeInfoWrapper.getChildren()[0]); | |
47 | }; | |
48 | } | |
49 | nextItem.addEventListener('touchstart', function(_event) { | |
50 | xStart = _event.x; | |
51 | }); | |
52 | nextItem.addEventListener('touchmove', function(_event) { | |
53 | if (cancelSwipe || xPrev == _event.x) return; | |
54 | xPrev = _event.x; | |
55 | if (xStart > _event.x && (xStart - _event.x > swipeValue) && itemId != fullLength-1) { | |
56 | cancelSwipe = true; | |
57 | xStart = _event.x; | |
58 | itemId++; | |
59 | $.createRecipeListItem(recipesList[itemId], itemId); | |
60 | $.navigateInfo.text = (itemId + 1) + ' / ' + fullLength; | |
61 | } else if (xStart < _event.x && (_event.x - xStart > swipeValue) && itemId != 0) { | |
62 | cancelSwipe = true; | |
63 | xStart = _event.x; | |
64 | itemId--; | |
65 | $.createRecipeListItem(recipesList[itemId], itemId); | |
66 | $.navigateInfo.text = (itemId + 1) + ' / ' + fullLength; | |
67 | } | |
68 | }); | |
69 | }; |