Advertisement
pushrbx

switcher

May 2nd, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. (function($) {
  3.     $.fn.navs = function(o) {
  4.         this
  5.                 .each(function() {
  6.                     var th = $(this), data = th.data('navs'), _ = {
  7.                         enable : true,
  8.                         actCl : 'active',
  9.                         changeEv : 'change',
  10.                         indx : [],
  11.                         hshx : [],
  12.                         useHash : false,
  13.                         defHash : '#!/',
  14.                         emptyHash : '#',
  15.                         outerHash : false,
  16.                         autoPlay : false,
  17.                         blockSame : true,
  18.                         hover : true,
  19.                         contRetFalse : true,
  20.                         preFu : function() {
  21.                             _.li.each(function(n) {
  22.                                 var th = $(this);
  23.                                 _.indx[n] = th;
  24.                                 if (_.useHash) {
  25.                                     _.hshx[n] = $('a', th).attr('href');
  26.  
  27.                                     if (location.hash == _.hshx[n]) {
  28.                                         th.addClass(_.actCl);
  29.                                     }
  30.                                 }
  31.  
  32.                             });
  33.                         },
  34.                         rfrshFu : function() {
  35.                             _.prev = _.curr
  36.                             _.pren = _.n
  37.                             _.curr = false
  38.                             _.n = -1
  39.                             _.param = 'close'
  40.  
  41.                             _.li.each(function(n) {
  42.                                 var th = $(this)
  43.                                 if (th.hasClass(_.actCl))
  44.                                     _.curr = th, _.n = n, _.href = $('a', th)
  45.                                             .attr('href'),
  46.                                             _.param = _.useHash ? _.href : _.n
  47.                             })
  48.                         },
  49.                         markFu : function() {
  50.                             _.li.each(function(n) {
  51.                                 var th = $(this)
  52.                                 _.n == n ? _.hvrin(th) : _.hvrout(th)
  53.                             })
  54.                         },
  55.                         hashFu : function() {
  56.                             $(window)
  57.                                     .bind(
  58.                                             'hashchange',
  59.                                             function() {
  60.                                                 if (location.hash == _.emptyHash
  61.                                                         || location.hash.length == 0) {
  62.                                                     location.hash = _.hash
  63.                                                     return false
  64.                                                 }
  65.                                                 _.prevHash = _.hash
  66.                                                 _
  67.                                                         .checkHashFu(_.outerHash = _.hash = location.hash)
  68.                                             })
  69.                             $('a', _.li).click(function() {
  70.                                 if (!_.enable)
  71.                                     return false
  72.                             })
  73.                         },
  74.                         checkHashFu : function(hash) {
  75.                             if (hash == _.emptyHash || hash.length == 0)
  76.                                 location.hash = _.defHash
  77.                             if (hash == '#back')
  78.                                 return _.backFu()
  79.                             if (hash == '#close')
  80.                                 return _.closeFu()
  81.                             _.li.each(function(n) {
  82.                                 if (_.hshx[n] == _.hash) {
  83.                                     _.chngFu(n), _.outerHash = false
  84.                                 }
  85.                             })
  86.                             if (_.outerHash)
  87.                                 _.li.removeClass(_.actCl), _.rfrshFu(), _
  88.                                         .markFu(), _.param = _.outerHash, _.me
  89.                                         .trigger(_.changeEv)
  90.                         },
  91.                         cntrFu : function() {
  92.                             _.li.each(function(n) {
  93.                                 var th = $(this)
  94.                                 $('a', th).click(function() {
  95.                                     _.chngFu(n)
  96.                                     if (_.contRetFalse)
  97.                                         return false
  98.                                 })
  99.                             })
  100.                         },
  101.                         autoPlayFu : function() {
  102.                             if (!_.autoPlay)
  103.                                 return false
  104.                             if (_.int)
  105.                                 clearInterval(_.int)
  106.                             _.int = setInterval(_.nextFu, _.autoPlay)
  107.                         },
  108.                         chngFu : function(n) {
  109.                             if (!_.enable)
  110.                                 return false
  111.                             if (n == _.n && _.blockSame)
  112.                                 return false
  113.                             _.indx[n] && _.li.removeClass(_.actCl)
  114.                                     && _.indx[n].addClass(_.actCl)
  115.                             _.rfrshFu()
  116.                             _.markFu()
  117.                             _.autoPlayFu()
  118.                             if (_.useHash && location.hash != _.hshx[_.n])
  119.                                 location.hash = _.hshx[_.n]
  120.  
  121.                             _.me.trigger(_.changeEv)
  122.                         },
  123.                         closeFu : function() {
  124.                             _.li.removeClass(_.actCl)
  125.                             _.rfrshFu()
  126.                             _.markFu()
  127.                             _.me.trigger(_.changeEv)
  128.                             location.hash = _.defHash
  129.                         },
  130.                         backFu : function() {
  131.                             _.chngFu(_.pren)
  132.                         },
  133.                         nextFu : function() {
  134.                             var n = _.n
  135.                             _.chngFu(++n < _.li.length ? n : 0)
  136.                         },
  137.                         prevFu : function() {
  138.                             var n = _.n
  139.                             _.chngFu(--n >= 0 ? n : _.li.length - 1)
  140.                         },
  141.                         customStr : function(str) {
  142.                             // console.log(str)
  143.                         },
  144.                         init : function() {
  145.                             _.li = $('>ul>li', _.me)
  146.                             _.preFu()
  147.                             _.rfrshFu()
  148.                             _.markFu()
  149.                             _.useHash ? _.hashFu() : _.cntrFu()
  150.                             _.hoverFu()
  151.                             _.autoPlayFu()
  152.                             _.useHash
  153.                                     && _
  154.                                             .checkHashFu(_.outerHash = _.hash = location.hash)
  155.                             _.li.hasClass(_.actCl) && _.me.trigger(_.changeEv)
  156.                         },
  157.                         hoverFu : function() {
  158.                             _.li.each(function(n) {
  159.                                 var th = $(this)
  160.                                 $('a', th).bind('mouseenter', function() {
  161.                                     if (_.enable)
  162.                                         if (_.hover && n != _.n)
  163.                                             _.hvrin(th)
  164.                                 }).bind('mouseleave', function() {
  165.                                     if (_.enable)
  166.                                         if (_.hover && n != _.n)
  167.                                             _.hvrout(th)
  168.                                 })
  169.                             })
  170.                         },
  171.                         hvrin : function(el) {
  172.                             _.hoverIn(el, _)
  173.                             _.hover == 'sprites'
  174.                                     && $('a', el).sprites('hoverin')
  175.                         },
  176.                         hvrout : function(el) {
  177.                             _.hoverOut(el, _)
  178.                             _.hover == 'sprites'
  179.                                     && $('a', el).sprites('hoverout')
  180.                         },
  181.                         hoverIn : function() {
  182.                         },
  183.                         hoverOut : function() {
  184.                         },
  185.                         defFunc : function() {
  186.                         }
  187.                     }
  188.  
  189.                     data ? _ = data : th.data({
  190.                         navs : _
  191.                     })
  192.                     typeof o == 'object' && $.extend(_, o)
  193.  
  194.                     if (typeof o == 'function')
  195.                         return th.bind(_.changeEv, function() {
  196.                             o(_.param, _);
  197.                             return false
  198.                         }).trigger(_.changeEv)
  199.  
  200.                     _.me || _.init(_.me = th)
  201.  
  202.                     typeof o == 'number' && _.chngFu(o)
  203.                     typeof o == 'boolean' && (_.enable = o)
  204.                     typeof o == 'string'
  205.                             && (o == 'prev' || o == 'next' || o == 'close'
  206.                                     || o == 'back' ? _[o + 'Fu']()
  207.                                     : _.useHash ? o.slice(0, 3) == '#!/'
  208.                                             && (location.hash = o)
  209.                                             || _.customStr(o) : _.customStr(o))
  210.                 })
  211.         return this
  212.     }
  213.  
  214.     $.fn.tabs = function(o) {
  215.         return this.each(function() {
  216.             var th = $(this), _ = th.data('tabs')
  217.                     || {
  218.                         enable : true,
  219.                         show : 0,
  220.                         blockSame : true,
  221.                         changeEv : 'change',
  222.                         empty : '#!/',
  223.                         preFu : function() {
  224.                             _.li.hide()
  225.                         },
  226.                         actFu : function() {
  227.                             _.prev && _.prev.hide()
  228.                             _.curr && _.curr.show()
  229.                         },
  230.                         searchSubCatFu: function(s) {
  231.                             var subtest = -1;
  232.                             var subcat = false;
  233.  
  234.                             if(s.slice(0, 3) == '#!/') {
  235.                                 subtest = s.slice(3).indexOf('/');
  236.  
  237.                                 if(subtest >= 0) {
  238.                                     subcat = s.slice(subtest + 4);
  239.                                     if(subcat.indexOf('/') >= 0) {
  240.                                         return _.searchSubCatFu(subcat);
  241.                                     }
  242.  
  243.                                     return subcat;
  244.                                 }
  245.  
  246.                                 return s.slice(3);
  247.                             }
  248.                             else {
  249.                                 subtest = s.indexOf('/');
  250.                                 if(subtest >= 0) {
  251.                                     subcat = s.slice(subtest + 1);
  252.                                     if(subcat.indexOf('/') >= 0) {
  253.                                         return _.searchSubCatFu(subcat);
  254.                                     }
  255.                                     return subcat;
  256.                                 }
  257.                             }
  258.  
  259.                             return false;
  260.                         },
  261.                         navFu : function(s) {
  262.                             if (_.pres == s || s.slice(0, 3) != '#!/')
  263.                                 return false
  264.                             _.pres = s
  265.                             s == _.empty && $.when(_.li).then(_.closeFu)
  266.                             var found = false;
  267.                             var needle = _.searchSubCatFu(s);
  268.  
  269.                             _.li.each(function(n) {
  270.                                 if($(this).attr('id') == needle){
  271.                                     _.chngFu(n);
  272.                                     $(document).trigger("pageChange", $(this));
  273.                                 }
  274.                             })
  275.                         },
  276.                         chngFu : function(a) {
  277.                             if (!_.enable || (a == _.n && _.blockSame)
  278.                                     || a >= _.li.length)
  279.                                 return false
  280.                             $.when(_.li).then(function() {
  281.                                 _.pren = _.n
  282.                                 _.prev = _.curr
  283.                                 _.curr = _.li.eq(_.n = a)
  284.                                 _.actFu(_)
  285.                                 _.me.trigger(_.changeEv)
  286.                             })
  287.                         },
  288.                         nextFu : function() {
  289.                             var n = _.n
  290.                             _.way = 1
  291.                             _.chngFu(++n < _.li.length - _.show ? n : 0)
  292.                         },
  293.                         prevFu : function() {
  294.                             var n = _.n
  295.                             _.way = -1
  296.                             _.chngFu(--n >= 0 ? n : _.li.length - 1 - _.show)
  297.                         },
  298.                         closeFu : function() {
  299.                             if (_.pres == 'close')
  300.                                 return false
  301.                             _.pren = _.n
  302.                             _.prev = _.curr
  303.                             _.n = -1
  304.                             _.curr = false
  305.                             _.pres = 'close'
  306.                             _.actFu(_)
  307.                         },
  308.                         backFu : function() {
  309.                             _.chngFu(_.pren)
  310.                         },
  311.                         init : function() {
  312.                             _.ul = $('>ul', _.me)
  313.                             _.li = $('>li', _.ul)
  314.                             _.preFu(_)
  315.                             _.navs && _.navs.navs(function(n) {
  316.                                 th.tabs(n)
  317.                             })
  318.                         }
  319.                     }
  320.  
  321.             if (typeof o == 'object')
  322.                 _ = $.extend(true, _, o)
  323.  
  324.             _.me || _.init(_.me = th.data({
  325.                 tabs : _
  326.             }))
  327.  
  328.             typeof o == 'function' && _.me.bind(_.changeEv, function() {
  329.                 o(_.n, _);
  330.                 return false
  331.             })
  332.             typeof o == 'boolean' && (_.enable = o)
  333.             typeof o == 'number' && _.chngFu(o)
  334.             typeof o == 'string'
  335.                     && (o == 'prev' || o == 'next' || o == 'close'
  336.                             || o == 'back' ? _[o + 'Fu']() : _.navFu(o))
  337.         })
  338.     }
  339. })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement