index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. $(function() {
  2. // start the icon carousel
  3. $('#iconCarousel').carousel({
  4. interval: 5000
  5. });
  6. // make code pretty
  7. window.prettyPrint && prettyPrint();
  8. // inject twitter & github counts
  9. $.ajax({
  10. url: 'http://api.twitter.com/1/users/show.json',
  11. data: {screen_name: 'fortaweso_me'},
  12. dataType: 'jsonp',
  13. success: function(data) {
  14. $('#followers').html(data.followers_count);
  15. }
  16. });
  17. $.ajax({
  18. url: 'https://api.github.com/repos/fortawesome/Font-Awesome',
  19. dataType: 'jsonp',
  20. success: function(data) {
  21. $('#watchers').html(data.data.watchers);
  22. $('#forks').html(data.data.forks);
  23. }
  24. });
  25. var firstInHistory = true;
  26. var MainView = Backbone.View.extend({
  27. el: $("div.container"),
  28. modalTemplate: _.template($("#modal-template").html()),
  29. events:{
  30. "click ul.the-icons > li": "iconClicked"
  31. },
  32. iconClicked: function(event) {
  33. event.preventDefault();
  34. var $item = $(event.currentTarget);
  35. var $iconName = $item.find("i").attr("class");
  36. _gaq.push(['_trackEvent', 'iconClick', $iconName]);
  37. mainRouter.navigate("icon/" + $iconName, {trigger: true});
  38. firstInHistory = false;
  39. }
  40. });
  41. var MainRouter = Backbone.Router.extend({
  42. routes: {
  43. "": "checkModal",
  44. "icon/:iconName": "showIcon"
  45. },
  46. checkModal: function() {
  47. var $modal = $("div.modal");
  48. if ($modal.length > 0) {
  49. $modal.modal("hide");
  50. }
  51. },
  52. showIcon: function(iconName) {
  53. var $modal = $(mainView.modalTemplate({"iconName": iconName}));
  54. $modal.modal("show");
  55. $modal.on('hidden', function () {
  56. $modal.remove();
  57. if (firstInHistory) {
  58. mainRouter.navigate("/", {trigger: false});
  59. firstInHistory = false;
  60. } else {
  61. window.history.back();
  62. }
  63. })
  64. }
  65. });
  66. var mainView = new MainView();
  67. var mainRouter = new MainRouter();
  68. Backbone.history.start({pushState : false});
  69. });