index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: 'http://github.com/api/v2/json/repos/show/FortAwesome/Font-Awesome',
  19. dataType: 'jsonp',
  20. success: function(data) {
  21. $('#watchers').html(data.repository.watchers);
  22. $('#forks').html(data.repository.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. mainRouter.navigate("icon/" + $iconName, {trigger: true});
  37. firstInHistory = false;
  38. }
  39. });
  40. var MainRouter = Backbone.Router.extend({
  41. routes: {
  42. "": "checkModal",
  43. "icon/:iconName": "showIcon"
  44. },
  45. checkModal: function() {
  46. var $modal = $("div.modal");
  47. if ($modal.length > 0) {
  48. $modal.modal("hide");
  49. }
  50. },
  51. showIcon: function(iconName) {
  52. var $modal = $(mainView.modalTemplate({"iconName": iconName}));
  53. $modal.modal("show");
  54. $modal.on('hidden', function () {
  55. $modal.remove();
  56. if (firstInHistory) {
  57. mainRouter.navigate("/", {trigger: false});
  58. firstInHistory = false;
  59. } else {
  60. window.history.back();
  61. }
  62. })
  63. }
  64. });
  65. var mainView = new MainView();
  66. var mainRouter = new MainRouter();
  67. Backbone.history.start({pushState : false});
  68. });