1 (function ($, rf) {
  2 
  3     rf.ui = rf.ui || {};
  4 
  5     var initButtons = function(buttons, css, component) {
  6         var id;
  7 
  8         var fn = function(e) {
  9             e.data.fn.call(e.data.component, e);
 10         };
 11 
 12         var data = {};
 13         data.component = component;
 14 
 15         for (id in buttons) {
 16             var element = $(document.getElementById(id));
 17 
 18             data.id = id;
 19             data.page = buttons[id];
 20             data.element = element;
 21             data.fn = component.processClick;
 22 
 23             element.bind('click', copy(data), fn);
 24         }
 25     };
 26 
 27     var copy = function(data) {
 28         var key;
 29         var eventData = {};
 30 
 31         for (key in data) {
 32             eventData[key] = data[key];
 33         }
 34 
 35         return eventData;
 36     };
 37 
 38     var togglePressClass = function(el, event) {
 39         if (event.type == 'mousedown') {
 40             el.addClass('rf-ds-press');
 41         } else if (event.type == 'mouseup' || event.type == 'mouseout') {
 42             el.removeClass('rf-ds-press');
 43         }
 44     };
 45 
 46     rf.ui.DataScroller = function(id, submit, options) {
 47 
 48         $super.constructor.call(this, id);
 49 
 50         var dataScrollerElement = this.attachToDom();
 51 
 52         this.options = options;
 53         this.currentPage = options.currentPage;
 54 
 55         if (submit && typeof submit == 'function') {
 56             RichFaces.Event.bindById(id, this.getScrollEventName(), submit);
 57         }
 58 
 59         var css = {};
 60 
 61         if (options.buttons) {
 62 
 63             $(dataScrollerElement).delegate('.rf-ds-btn', 'mouseup mousedown mouseout', function(event) {
 64                 if ($(this).hasClass('rf-ds-dis')) {
 65                     $(this).removeClass('rf-ds-press');
 66                 } else {
 67                     togglePressClass($(this), event);
 68                 }
 69             });
 70 
 71             initButtons(options.buttons.left, css, this);
 72             initButtons(options.buttons.right, css, this);
 73         }
 74 
 75         if (options.digitals) {
 76 
 77             $(dataScrollerElement).delegate('.rf-ds-nmb-btn', 'mouseup mousedown mouseout', function(event) {
 78                 togglePressClass($(this), event);
 79             });
 80 
 81             initButtons(options.digitals, css, this);
 82         }
 83     };
 84 
 85     rf.BaseComponent.extend(rf.ui.DataScroller);
 86     var $super = rf.ui.DataScroller.$super;
 87 
 88     $.extend(rf.ui.DataScroller.prototype, (function () {
 89 
 90         var scrollEventName = "rich:datascroller:onscroll";
 91 
 92         return {
 93 
 94             name: "RichFaces.ui.DataScroller",
 95 
 96             processClick: function(event) {
 97                 var data = event.data;
 98                 if (data) {
 99                     var page = data.page;
100                     if (page) {
101                         this.switchToPage(page);
102                     }
103                 }
104             },
105 
106             switchToPage: function(page) {
107                 if (typeof page != 'undefined' && page != null) {
108                     RichFaces.Event.fireById(this.id, this.getScrollEventName(), {'page' : page});
109                 }
110             },
111 
112             fastForward: function() {
113                 this.switchToPage("fastforward");
114             },
115 
116             fastRewind: function() {
117                 this.switchToPage("fastrewind");
118             },
119 
120             next: function() {
121                 this.switchToPage("next");
122             },
123 
124             previous: function() {
125                 this.switchToPage("previous");
126             },
127 
128             first: function() {
129                 this.switchToPage("first");
130             },
131 
132             last: function() {
133                 this.switchToPage("last");
134             },
135 
136             getScrollEventName: function() {
137                 return scrollEventName;
138             },
139             destroy: function() {
140                 $super.destroy.call(this);
141             }
142         }
143 
144     })());
145 
146 })(RichFaces.jQuery, window.RichFaces);