index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. error:function(xhr, ajaxOptions, thrownError) {
  25. console.log(xhr);
  26. console.log(thrownError);
  27. }
  28. });
  29. var firstInHistory = true;
  30. var MainView = Backbone.View.extend({
  31. el: $("div.container"),
  32. modalTemplate: _.template($("#modal-template").html()),
  33. events:{
  34. "click ul.the-icons > li": "iconClicked"
  35. },
  36. iconClicked: function(event) {
  37. event.preventDefault();
  38. var $item = $(event.currentTarget);
  39. var $iconName = $item.find("i").attr("class");
  40. _gaq.push(['_trackEvent', 'iconClick', $iconName]);
  41. mainRouter.navigate("icon/" + $iconName, {trigger: true});
  42. firstInHistory = false;
  43. }
  44. });
  45. var MainRouter = Backbone.Router.extend({
  46. routes: {
  47. "": "checkModal",
  48. "icon/:iconName": "showIcon"
  49. },
  50. checkModal: function() {
  51. var $modal = $("div.modal");
  52. if ($modal.length > 0) {
  53. $modal.modal("hide");
  54. }
  55. },
  56. showIcon: function(iconName) {
  57. var $modal = $(mainView.modalTemplate({"iconName": iconName}));
  58. $modal.modal("show");
  59. $modal.on('hidden', function () {
  60. $modal.remove();
  61. if (firstInHistory) {
  62. mainRouter.navigate("/", {trigger: false});
  63. firstInHistory = false;
  64. } else {
  65. window.history.back();
  66. }
  67. })
  68. }
  69. });
  70. var mainView = new MainView();
  71. var mainRouter = new MainRouter();
  72. Backbone.history.start({pushState : false});
  73. });