Removes copied dependencies, bootstrap unit tests, custom scrollbars.
[profile/ivi/cowhide.git] / src / javascripts / cowhide-page.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 ChPage = 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                 maxWidgets: 0
21             });
22
23         var $parent_page = this.$element.parent().closest('div.page');
24         if ($parent_page.length !== 0) {
25             $.cowhide.fatal('#31: pages cannot be nested.');
26         }
27     };
28
29     ChPage.prototype = $.extend(
30         {},
31         $.fn.ch_widget.Constructor.prototype,
32         {
33             constructor: ChPage,
34
35             registeredWidgets: 0,
36             registerWidget: function(widget) {
37                 this.registeredWidgets++;
38                 if (this.options.maxWidgets > 0 &&
39                     this.registeredWidgets > this.options.maxWidgets)
40                 {
41                     $.cowhide.fatal("#32: a page cannot have more than " +
42                                     this.options.maxWidgets +
43                                     " widgets.");
44                 }
45             },
46
47             setMaxWidgets: function(value) {
48               this.options.maxWidgets = value;
49             }
50         }
51     );
52
53     $.fn.ch_page = function(option, value) {
54         return this.each(function() {
55             var $this = $(this),
56                 data = $this.data('ch_page'),
57                 options = typeof option == 'object' && option;
58
59             if (!data) {
60                 $this.data('ch_page', (data = new ChPage(this, options)));
61                 data.register();
62             }
63
64             if(option == 'register') {
65                 data.registerWidget(value);
66             }
67
68             if(option == 'setMaxWidgets') {
69               data.setMaxWidgets(value);
70             }
71         });
72     };
73
74     $.fn.ch_page.Constructor = ChPage;
75
76     /* CHPAGE DATA-API
77      * ================= */
78     $(function() {
79         $('div.page').ch_page();
80     })
81 })(window.jQuery);