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,19 +35,25 @@ $nav.delegate('li', 'tap', function() { @@ -30,19 +35,25 @@ $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')) {  
40 - return;  
41 - } 49 + if ($this.hasClass('focus')) {
  50 + return;
  51 + }
42 52
43 - $this.closest('.primary-level').children('.focus').removeClass('focus');  
44 - $this.addClass('focus'); 53 + $this.closest('.primary-level').children('.focus').removeClass('focus');
  54 + $this.addClass('focus');
45 55
46 - $subLevel.not('.hide').addClass('hide');  
47 - $subLevel.eq(index).removeClass('hide'); 56 + $subLevel.not('.hide').addClass('hide');
  57 + $subLevel.eq(index).removeClass('hide');
  58 + }
48 }); 59 });