Guest User

Untitled

a guest
Nov 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. PageController = function() {}
  2.  
  3. PageController.prototype = {
  4. category : null,
  5. item : null,
  6.  
  7. load : function() {
  8. self = this;
  9. hashString = window.location.hash.substring(1);
  10. hashArray = hashString.split('-');
  11. self.category = self.__get(hashArray[1], 0);
  12. self.item = self.__get(hashArray[3], null);
  13. },
  14.  
  15. save : function() {
  16. self = this;
  17. window.location.hash = '#category-' + self.category;
  18. if (self.item) window.location.hash += ('-item-' + self.item);
  19. },
  20.  
  21. render : function() {
  22. self = this;
  23. self.__showCategory();
  24. if (self.item) self.__showItem();
  25. },
  26.  
  27. __showItem : function() {
  28. self = this;
  29. r = self.item;
  30. $('.items-in').show(); $('.prev').show(); $('.next').show();
  31. $('.items-list-small:visible li').removeClass('active');
  32. $('.items-list-small:visible li').eq(parseInt(r)).addClass('active');
  33. $('.items-in .items-list>li').hide();
  34. $('.items-in .items-list #items-list-desc-'+r).show();
  35. if (r == 0) {
  36. $('.items-in .prev').hide();
  37. }
  38. if (r == parseInt($('.items-list-small:visible li').length) - 1) {
  39. $('.items-in .next').hide();
  40. }
  41. $('.prev:visible').attr('rel', parseInt(r)-1);
  42. $('.next:visible').attr('rel', parseInt(r)+1);
  43. window.scroll(0, 480);
  44. },
  45.  
  46. __showCategory : function() {
  47. self = this;
  48. group_act = self.category;
  49. $('.items-list-small:visible li').removeClass('active');
  50. $('.items-in').hide();
  51. $('.items').hide();
  52. $('#items_group_'+group_act).show();
  53. $('.tabs li').removeClass('active');
  54. $('.tabs li.t'+(parseInt(group_act)+1)).addClass('active');
  55. },
  56.  
  57. __get : function(param, value) {
  58. if (param)
  59. return param
  60. return value;
  61. }
  62. }
  63.  
  64. $(function()
  65. {
  66. controller = new PageController;
  67.  
  68. $.each($('.menu li a'), function(k,v)
  69. {
  70. if ($(this).attr('href') == window.location.pathname)
  71. {
  72. $(this).addClass('active');
  73. }
  74. })
  75.  
  76. $('.items').hide();
  77. $('.items:first').show();
  78.  
  79. $('.items-in').hide();
  80.  
  81. controller.load();
  82. controller.render();
  83.  
  84. $(window).bind('hashchange', function() {
  85. controller.load();
  86. controller.render();
  87. });
  88.  
  89.  
  90. $('.tabs li').click(function()
  91. {
  92. var group_act = $(this).find('a').eq(0).attr('rel');
  93. controller.category = group_act;
  94. controller.item = null;
  95. controller.render();
  96. controller.save();
  97. return false;
  98. });
  99.  
  100. $('.small-show-item').click(function()
  101. {
  102. var r = $(this).attr('rel');
  103. controller.item = r;
  104. controller.render();
  105. controller.save();
  106. return false;
  107. });
  108. });
Add Comment
Please, Sign In to add comment