Removes copied dependencies, bootstrap unit tests, custom scrollbars.
[profile/ivi/cowhide.git] / src / javascripts / cowhide-header.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 ChHeader = function(element, options) {
14         $.fn.ch_widget.Constructor(element, options);
15         this.$element = $(element);
16         this.options = $.extend({}, options);
17     };
18
19     ChHeader.prototype = $.extend(
20         {},
21         $.fn.ch_widget.Constructor.prototype,
22         {
23             constructor: ChHeader,
24
25             show: function() {
26                 var $this = this.$element,
27                     $h = $('<h1/>').text(this.$element.text());
28
29                $this.html($h);
30
31                if (this.options.show_back_button) {
32                     var $back = $('<button/>').addClass('btn');
33                     var $icon = $('<i/>').addClass('icon-backward');
34
35                     $back.html($icon);
36
37                     $this.append($back);
38
39                     $back.click(function(e) {
40                         e.preventDefault();
41                         $this.trigger($.Event('back'));
42                     });
43                 }
44             }
45         }
46     );
47
48     $.fn.ch_header = function(option) {
49         return this.each(function() {
50             var $this = $(this),
51                 data = $this.data('ch_header'),
52                 options = typeof option == 'object' && option;
53
54             if ($this.data('show-back-button')) {
55                 options = $.extend(options, {show_back_button: true});
56             }
57
58             if (!data) {
59                 $this.data('ch_header', (data = new ChHeader(this, options)));
60                 data.register();
61             }
62
63             if (typeof option == 'string')
64                 data[option]();
65         });
66     };
67
68     $.fn.ch_button.Constructor = ChHeader;
69
70     /* CHHEADER DATA-API
71      * ================= */
72     $(function() {
73         $('.ch-header').ch_header('show');
74     })
75 })(window.jQuery);