JS asynchronous programming III: Jscex with no trace cut into jQUI

Source: Internet
Author: User

Many may have questions about whether conflicts or exceptions occur when Jscex is used together with other class libraries or when syntax is mixed? Let's try it!

We use the tab plug-in:

 
 
  1. $(function () {  
  2. $("#tabs").tabs({ event: "mouseover" });  
  3. });  

Later, the official website helped the tab plug-in expand a function of automatic switch, just write it like this:

 
 
  1. $(function ()   
  2. {var t = $("#tabs").tabs();  
  3. t.tabs("rotate", 3000, false);  
  4. }); 

The extension code is as follows:

 
 
  1. $.extend($.ui.tabs.prototype, {  
  2.             rotation: null,  
  3.             rotate: function (ms, continuing) {  
  4.                 var self = this,  
  5. o = this.options;  
  6.                 var rotate = self._rotate || (self._rotate = function (e) {  
  7.                     clearTimeout(self.rotation);  
  8.                     self.rotation = setTimeout(function () {  
  9.                         var t = o.selected;  
  10.                         self.select(++t < self.anchors.length ? t : 0);  
  11.                     }, ms);  
  12.                     if (e) {  
  13.                         e.stopPropagation();  
  14.                     }  
  15.                 });  
  16.                 var stop = self._unrotate || (self._unrotate = !continuing  
  17. ? function (e) {  
  18.     if (e.clientX) { // in case of a true click  
  19.         self.rotate(null);  
  20.     }  
  21. }  
  22. : function (e) {  
  23.     t = o.selected;  
  24.     rotate();  
  25. });  
  26.                 // start rotation  
  27.                 if (ms) {  
  28.                     this.element.bind("tabsshow", rotate);  
  29.                     this.anchors.bind(o.event + ".tabs", stop);  
  30.                     rotate();  
  31.                     // stop rotation  
  32.                 } else {  
  33.                     clearTimeout(self.rotation);  
  34.                     this.element.unbind("tabsshow", rotate);  
  35.                     this.anchors.unbind(o.event + ".tabs", stop);  
  36.                     delete this._rotate;  
  37.                     delete this._unrotate;  
  38.                 }  
  39.                 return this;  
  40.             }  
  41.         }); 

Still so confusing code! Before official expansion, we can use Jscex to describe:

 
 
  1. var swicthAsync = eval(Jscex.compile("async", function () {  
  2.             var tabCount = $("#tabs ul li").length;  
  3.             while (true) {  
  4.                 for (var i = 0; i < tabCount; i++) {  
  5.                     $await(Jscex.Async.sleep(2000));  
  6.                     $('#tabs').tabs({ selected: i });  
  7.                 }  
  8.             }  
  9.         }));  
  10.         $(function () {  
  11.             $("#tabs").tabs();  
  12.             swicthAsync().start();  
  13.         }); 

As you can see, Jscex does not intervene in JqueryUI. Jscex is only a shell of external control. In this way, we cannot test whether Jscex can conflict with or be abnormal. Therefore, we can use Jscex to rewrite the official extension method!

 
 
  1. $.extend($.ui.tabs.prototype, {  
  2.             rotation: null,  
  3.             rotate: function (ms, continuing) {  
  4.                 var self = this,  
  5. o = this.options;  
  6.                 var swicthAsync = eval(Jscex.compile("async", function () {  
  7.                     while (true) {  
  8.                         for (var i = 0; i < self.anchors.length; i++) {  
  9.                             $await(Jscex.Async.sleep(ms));  
  10.                             self.select(i);  
  11.                         }  
  12.                     }  
  13.                 }));  
  14.                 swicthAsync().start();  
  15.                 return this;  
  16.             }  
  17.         }); 

However, the continuing parameter does not take effect for the moment. This parameter determines whether the user can continue the loop after the user selects the parameter. You can complete this parameter by yourself ~~~~

New Jscex library. please upload.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.