chengsc
2024-07-23 f575652587d4160ab42e75acb2bc26b4f60fb7c3
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
84
85
86
87
88
89
$(function() {
  // start the icon carousel
  $('#iconCarousel').carousel({
    interval: 5000
  });
 
  // make code pretty
  window.prettyPrint && prettyPrint();
 
  // inject twitter & github counts
  $.ajax({
    url: 'http://api.twitter.com/1/users/show.json',
    data: {screen_name: 'fortaweso_me'},
    dataType: 'jsonp',
    success: function(data) {
      $('#followers').html(data.followers_count);
    }
  });
  $.ajax({
    url: 'https://api.github.com/repos/fortawesome/Font-Awesome',
    dataType: 'jsonp',
    success: function(data) {
      $('#watchers').html(data.data.watchers);
      $('#forks').html(data.data.forks);
    }
  });
 
 
 
 
 
  var firstInHistory = true;
 
  var MainView = Backbone.View.extend({
    el: $("div.container"),
 
    modalTemplate: _.template($("#modal-template").html()),
 
    events:{
      "click ul.the-icons > li": "iconClicked"
    },
 
    iconClicked: function(event) {
      event.preventDefault();
 
      var $item = $(event.currentTarget);
      var $iconName = $item.find("i").attr("class");
      _gaq.push(['_trackEvent', 'iconClick', $iconName]);
 
      mainRouter.navigate("icon/" + $iconName, {trigger: true});
      firstInHistory = false;
    }
  });
 
 
  var MainRouter = Backbone.Router.extend({
    routes: {
      "": "checkModal",
      "icon/:iconName": "showIcon"
    },
 
    checkModal: function() {
      var $modal = $("div.modal");
      
      if ($modal.length > 0) {
        $modal.modal("hide");
      }
    },
 
    showIcon: function(iconName) {
      var $modal = $(mainView.modalTemplate({"iconName": iconName}));
 
      $modal.modal("show");
      $modal.on('hidden', function () {
        $modal.remove();
        if (firstInHistory) {
          mainRouter.navigate("/", {trigger: false});
          firstInHistory = false;
        } else {
          window.history.back();
        }
      })
    }
  });
 
  var mainView = new MainView();
  var mainRouter = new MainRouter();
  Backbone.history.start({pushState : false});
});