Add Intel copyright header.
[profile/ivi/cowhide.git] / src / javascripts / cowhide-scrollable.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 (function($, undefined) {
11     'use strict';
12
13     var ChScrollable = function(element, options) {
14         $.fn.ch_widget.Constructor(element, options);
15         this.$element = $(element);
16         this.options = $.extend(
17             options,
18             $.fn.ch_widget.defaults,
19             {
20             });
21     };
22
23     ChScrollable.prototype = $.extend(
24         {},
25         $.fn.ch_widget.Constructor.prototype,
26         {
27             constructor: ChScrollable,
28
29             enable: function() {
30               this.$element.mCustomScrollbar({
31                 scrollButtons: {
32                   enable: true
33                 }
34               });
35             }
36         }
37     );
38
39     $.fn.ch_scrollable = function(option) {
40         return this.each(function() {
41             var $this = $(this),
42                 data = $this.data('ch_scrollable'),
43                 options = typeof option == 'object' && option;
44
45             if (!data) {
46                 $this.data('ch_scrollable', (data = new ChScrollable(this, options)));
47                 data.register();
48             }
49
50             if(typeof option == 'string')
51                 data[option]();
52         });
53     };
54
55     $.fn.ch_page.Constructor = ChScrollable;
56
57     /* CHSCROLLABLE DATA-API
58      * ================= */
59     $(function() {
60         $('div.ch-scrollable').ch_scrollable('enable');
61     })
62 })(window.jQuery);