jquery.yiitab.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * jQuery Yii plugin file.
  3. *
  4. * @author Qiang Xue <qiang.xue@gmail.com>
  5. * @link http://www.yiiframework.com/
  6. * @copyright 2008-2010 Yii Software LLC
  7. * @license http://www.yiiframework.com/license/
  8. */
  9. ;(function($) {
  10. $.extend($.fn, {
  11. yiitab: function() {
  12. function activate(id) {
  13. var pos = id.indexOf("#");
  14. if (pos>=0) {
  15. id = id.substring(pos);
  16. }
  17. var $tab=$(id);
  18. var $container=$tab.parent();
  19. $container.find('>ul a').removeClass('active');
  20. $container.find('>ul a[href="'+id+'"]').addClass('active');
  21. $container.children('div').hide();
  22. $tab.show();
  23. }
  24. this.find('>ul a').click(function(event) {
  25. var href=$(this).attr('href');
  26. var pos=href.indexOf('#');
  27. activate(href);
  28. if(pos==0 || (pos>0 && (window.location.pathname=='' || window.location.pathname==href.substring(0,pos))))
  29. return false;
  30. });
  31. // activate a tab based on the current anchor
  32. var url = decodeURI(window.location);
  33. var pos = url.indexOf("#");
  34. if (pos >= 0) {
  35. var id = url.substring(pos);
  36. if (this.find('>ul a[href="'+id+'"]').length > 0) {
  37. activate(id);
  38. return;
  39. }
  40. }
  41. }
  42. });
  43. })(jQuery);