Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PageController = function() {}
- PageController.prototype = {
- category : null,
- item : null,
- load : function() {
- self = this;
- hashString = window.location.hash.substring(1);
- hashArray = hashString.split('-');
- self.category = self.__get(hashArray[1], 0);
- self.item = self.__get(hashArray[3], null);
- },
- save : function() {
- self = this;
- window.location.hash = '#category-' + self.category;
- if (self.item) window.location.hash += ('-item-' + self.item);
- },
- render : function() {
- self = this;
- self.__showCategory();
- if (self.item) self.__showItem();
- },
- __showItem : function() {
- self = this;
- r = self.item;
- $('.items-in').show(); $('.prev').show(); $('.next').show();
- $('.items-list-small:visible li').removeClass('active');
- $('.items-list-small:visible li').eq(parseInt(r)).addClass('active');
- $('.items-in .items-list>li').hide();
- $('.items-in .items-list #items-list-desc-'+r).show();
- if (r == 0) {
- $('.items-in .prev').hide();
- }
- if (r == parseInt($('.items-list-small:visible li').length) - 1) {
- $('.items-in .next').hide();
- }
- $('.prev:visible').attr('rel', parseInt(r)-1);
- $('.next:visible').attr('rel', parseInt(r)+1);
- window.scroll(0, 480);
- },
- __showCategory : function() {
- self = this;
- group_act = self.category;
- $('.items-list-small:visible li').removeClass('active');
- $('.items-in').hide();
- $('.items').hide();
- $('#items_group_'+group_act).show();
- $('.tabs li').removeClass('active');
- $('.tabs li.t'+(parseInt(group_act)+1)).addClass('active');
- },
- __get : function(param, value) {
- if (param)
- return param
- return value;
- }
- }
- $(function()
- {
- controller = new PageController;
- $.each($('.menu li a'), function(k,v)
- {
- if ($(this).attr('href') == window.location.pathname)
- {
- $(this).addClass('active');
- }
- })
- $('.items').hide();
- $('.items:first').show();
- $('.items-in').hide();
- controller.load();
- controller.render();
- $(window).bind('hashchange', function() {
- controller.load();
- controller.render();
- });
- $('.tabs li').click(function()
- {
- var group_act = $(this).find('a').eq(0).attr('rel');
- controller.category = group_act;
- controller.item = null;
- controller.render();
- controller.save();
- return false;
- });
- $('.small-show-item').click(function()
- {
- var r = $(this).attr('rel');
- controller.item = r;
- controller.render();
- controller.save();
- return false;
- });
- });
Add Comment
Please, Sign In to add comment