Removes copied dependencies, bootstrap unit tests, custom scrollbars.
[profile/ivi/cowhide.git] / src / javascripts / cowhide-button.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 ChButton = 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                 minFontSize: 12,
21                 maxFontSize: 24,
22                 disableWhenDriving: true
23             });
24
25         if (this.options.fixedWidth) {
26             this.$element.css({width: this.options.fixedWidth});
27         }
28
29         if (this.options.marquee) {
30             this.enableMarquee();
31         }
32     };
33
34     ChButton.prototype = $.extend(
35         {},
36         $.fn.ch_widget.Constructor.prototype,
37         {
38             constructor: ChButton,
39
40             disableMarquee: function() {
41                 var $marquee = this.$element.find('marquee');
42                 if($marquee.length > 0) {
43                     var text = $marquee.text();
44                     $marquee.remove();
45                     this.$element.text(text);
46                 }
47             },
48
49             enableMarquee: function() {
50                 if (this.options.marquee && (
51                     this.$element[0].tagName == 'A' ||
52                     this.$element[0].tagName == 'BUTTON'))
53                 {
54                     var text = this.$element.text()
55
56                     var $marquee = $('<marquee/>');
57                     $marquee.attr('behavior', 'alternate')
58                     $marquee.attr('scrollamount', 1)
59                     $marquee.attr('width', this.$element.width());
60                     $marquee.text(text);
61
62                     this.$element.html($marquee);
63                 }
64             },
65
66             onDrivingModeEnter: function() {
67                 this.disableMarquee();
68             },
69
70             onDrivingModeExit: function() {
71                 this.enableMarquee();
72             }
73         }
74     );
75
76     $.fn.ch_button = function(option) {
77         return this.each(function() {
78             var $this = $(this),
79                 data = $this.data('ch_button'),
80                 options = typeof option == 'object' && option;
81
82             if ($this.data('marquee')) {
83                 options = $.extend(options, {marquee: true});
84             }
85             if ($this.data('fixed-width')) {
86                 options = $.extend(options, {fixedWidth: $this.data('fixed-width')})
87             }
88             if (!data) {
89                 $this.data('ch_button', (data = new ChButton(this, options)));
90                 data.register();
91             }
92
93             $this.button(option);
94         });
95     };
96
97     $.fn.ch_button.Constructor = ChButton;
98
99     /* CHBUTTON DATA-API
100      * ================= */
101     $(function() {
102         $('.btn, button, input[type=button]').ch_button();
103     })
104 })(window.jQuery);