1 (function($, rf) {
  2     rf.ui = rf.ui || {};
  3     var defaultOptions = {
  4     };
  5     rf.ui.Poll = function(componentId, options) {
  6         $super.constructor.call(this, componentId, options);
  7         this.id = componentId;
  8         this.attachToDom();
  9         this.interval = options.interval || 1000;
 10         this.ontimer = options.ontimer;
 11 
 12         this.pollElement = rf.getDomElement(this.id);
 13 
 14         rf.ui.pollTracker = rf.ui.pollTracker || {};
 15 
 16         if (options.enabled) {
 17             this.startPoll();
 18         }
 19     }
 20 
 21     rf.BaseComponent.extend(rf.ui.Poll);
 22     var $super = rf.ui.Poll.$super;
 23     $.extend(rf.ui.Poll.prototype, (function() {
 24         return {
 25             name: "Poll",
 26 
 27             startPoll: function() {
 28                 this.stopPoll();
 29                 var poll = this;
 30                 rf.ui.pollTracker[poll.id] = window.setTimeout(function() {
 31                     try {
 32                         poll.ontimer.call(poll.pollElement || window);
 33                         poll.startPoll();
 34                     } catch (e) {
 35                         // TODO: handle exception
 36                     }
 37                 }, poll.interval);
 38             },
 39 
 40             stopPoll : function() {
 41                 if (rf.ui.pollTracker && rf.ui.pollTracker[this.id]) {
 42                     window.clearTimeout(rf.ui.pollTracker[this.id]);
 43                     delete rf.ui.pollTracker[this.id];
 44                 }
 45             },
 46 
 47             setZeroRequestDelay : function(options) {
 48                 if (typeof options.requestDelay == "undefined") {
 49                     options.requestDelay = 0;
 50                 }
 51             },
 52 
 53             destroy : function() {
 54                 this.stopPoll();
 55                 this.detach(this.id);
 56                 // call parent's destroy method
 57                 $super.destroy.call(this);
 58             }
 59 
 60         };
 61     })());
 62 
 63 })(RichFaces.jQuery, RichFaces);