summaryrefslogtreecommitdiff
path: root/new-reality/public/assets/js/lib/nav/DesktopNav.js
blob: 24f0f25c22e141d8b26861a46f400fd88beed544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var NavView = View.extend({

  el: "#nav",

  events: {
    "click .logo": "home",
    "click li": "go",
    "click #corner": "corner",
    "mouseenter ul": "show_menu",
    "mouseleave ul": "hide_menu",
  },

	initialize: function(){
	},

  home: function(){
    app.router.go("/")
    this.$headings.find(".active").removeClass("active")
    if (app.mobile_nav && app.mobile_nav.state.open) {
      app.mobile_nav.hamburger()
    }
  },

  resetWidths: function(){
	  this.$categories.each(function(){
	    $(this).width( $(this).data("width") )
	  })
  },
  
  go: function(e){
    e.preventDefault()

    this.resetWidths()

    var $t = $(e.currentTarget)
    this.$("li").removeClass("active")
    $t.addClass("active")

    var href = $t.attr("href")
    app.router.go(href)
    if (is_mobile) {
      app.mobile_nav.hamburger()
    }
    this.after_go()
  },
  
  after_go: function(){
    
  },
  
  setActive: function(id){
    var href = '/' + id
    var $el = $('[href="' + href + '"]')
    this.$('.active').removeClass('active')
    if ($el.length) {
      $el.addClass('active')
    }
  },
  
  show_menu: function(e){
    var $el = $(e.currentTarget)
    $el.addClass("hover")

    // var $parent = $el.parent()
    var width = $el.data( "width" )
    $el.width(width)
    console.log(width)
  },

  hide_menu: function(e){
    var $el = $(e.currentTarget)
    $el.removeClass("hover")
    
    // var $parent = $el.parent()
    var hover_width = $el.data( "hover-width" )
    $el.width(hover_width)
  },
  
  corner: function(){
    app.view && app.view.corner()
  },

});