jquery-ui-tabs-rotate.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by duhuan on 2017/9/14.
  3. */
  4. ;(function($){
  5. $.extend( $.ui.tabs.prototype, {
  6. rotation: null,
  7. rotationDelay: null,
  8. continuing: null,
  9. rotate: function( ms, continuing ) {
  10. var self = this,
  11. o = this.options;
  12. if((ms > 1 || self.rotationDelay === null) && ms !== undefined){//only set rotationDelay if this is the first time through or if not immediately moving on from an unpause
  13. self.rotationDelay = ms;
  14. }
  15. if(continuing !== undefined){
  16. self.continuing = continuing;
  17. }
  18. var rotate = self._rotate || ( self._rotate = function( e ) {
  19. clearTimeout( self.rotation );
  20. self.rotation = setTimeout(function() {
  21. var t = o.active;
  22. self.option( "active", ++t < self.anchors.length ? t : 0 );
  23. }, ms );
  24. if ( e ) {
  25. e.stopPropagation();
  26. }
  27. });
  28. var stop = self._unrotate || ( self._unrotate = !continuing
  29. ? function(e) {
  30. if (e.clientX) { // in case of a true click
  31. self.rotate(null);
  32. }
  33. }
  34. : function( e ) {
  35. t = o.active;
  36. rotate();
  37. });
  38. // start rotation
  39. if ( ms ) {
  40. this.element.bind( "tabsactivate", rotate );
  41. this.anchors.bind( o.event + ".tabs", stop );
  42. rotate();
  43. // stop rotation
  44. } else {
  45. clearTimeout( self.rotation );
  46. this.element.unbind( "tabsactivate", rotate );
  47. this.anchors.unbind( o.event + ".tabs", stop );
  48. delete this._rotate;
  49. delete this._unrotate;
  50. }
  51. //rotate immediately and then have normal rotation delay
  52. if(ms === 1){
  53. //set ms back to what it was originally set to
  54. ms = self.rotationDelay;
  55. }
  56. return this;
  57. },
  58. pause: function() {
  59. var self = this,
  60. o = this.options;
  61. self.rotate(0);
  62. },
  63. unpause: function(){
  64. var self = this,
  65. o = this.options;
  66. self.rotate(1, self.continuing);
  67. }
  68. });
  69. })(jQuery);