Authored by xuqi

category tap -> hammer

@@ -4,19 +4,24 @@ @@ -4,19 +4,24 @@
4 * @date: 2015/10/14 4 * @date: 2015/10/14
5 */ 5 */
6 6
7 -var $ = require('jquery'); 7 +var $ = require('jquery'),
  8 + Hammer = require('hammer');
8 9
9 var $nav = $('.category-nav'), 10 var $nav = $('.category-nav'),
10 - $contents = $('.category-container > .content'); 11 + $categoryContainer = $('.category-container'),
  12 + $contents = $categoryContainer.children('.content');
11 13
12 var $curContent = $contents.not('.hide'); 14 var $curContent = $contents.not('.hide');
13 15
  16 +var navHammer, ccHammer;
  17 +
14 $('#search-input').focus(function() { 18 $('#search-input').focus(function() {
15 $(this).blur(); 19 $(this).blur();
16 }); 20 });
17 21
18 -$nav.delegate('li', 'tap', function() {  
19 - var $this = $(this), 22 +navHammer = new Hammer($nav[0]);
  23 +navHammer.on('tap', function(e) {
  24 + var $this = $(e.target).closest('li'),
20 index = $this.index(); 25 index = $this.index();
21 26
22 if ($this.hasClass('focus')) { 27 if ($this.hasClass('focus')) {
@@ -30,11 +35,16 @@ $nav.delegate('li', 'tap', function() { @@ -30,11 +35,16 @@ $nav.delegate('li', 'tap', function() {
30 $curContent = $contents.eq(index).removeClass('hide'); 35 $curContent = $contents.eq(index).removeClass('hide');
31 }); 36 });
32 37
33 -$('.primary-level').delegate('li', 'tap', function() {  
34 - var $this = $(this),  
35 - index = $this.index(); 38 +ccHammer = new Hammer($categoryContainer[0]);
  39 +ccHammer.on('tap', function(e) {
  40 + var $this = $(e.target),
  41 + $subLevel,
  42 + $cur, index;
36 43
37 - var $subLevel = $this.closest('.content').find('.sub-level'); 44 + $cur = $this.closest('.p-level-item');
  45 + if ($cur.length > 0) {
  46 + index = $cur.index();
  47 + $subLevel = $this.closest('.content').find('.sub-level');
38 48
39 if ($this.hasClass('focus')) { 49 if ($this.hasClass('focus')) {
40 return; 50 return;
@@ -45,4 +55,5 @@ $('.primary-level').delegate('li', 'tap', function() { @@ -45,4 +55,5 @@ $('.primary-level').delegate('li', 'tap', function() {
45 55
46 $subLevel.not('.hide').addClass('hide'); 56 $subLevel.not('.hide').addClass('hide');
47 $subLevel.eq(index).removeClass('hide'); 57 $subLevel.eq(index).removeClass('hide');
  58 + }
48 }); 59 });