2 * Copyright (c) 2012, Intel Corporation.
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
10 (function($, _, undefined) {
11 $.cowhide = $.cowhide || {}
15 monitorFrameworkRestrictions: false
23 // List of registered widgets
24 registeredWidgets: [],
28 currentTheme: 'default',
31 var S4 = function () {
33 Math.random() * 0x10000 /* 65536 */
47 register: function(widget) {
49 var guids = _.map(self.registeredWidgets, function(w) {
53 if (_.indexOf(guids, widget.guid) == -1) {
54 self.registeredWidgets.push(widget);
57 /* TODO: core should ask `page` what a page looks like. */
58 if(!(widget.$element[0].tagName == 'DIV' && widget.$element.hasClass('page'))) {
59 var $page = widget.$element.parent().closest('div.page');
60 if ($page.length === 0) {
61 $.cowhide.fatal("#30: every widget must be within a div with class='page'.", this.$element);
63 $page.ch_page('register', widget);
68 // TODO: use `backdrop` from Bootstrap's modal
69 backdrop: function (callback) {
70 var $backdrop = $('<div class="modal-backdrop theme-change-backdrop fade" />');
72 $backdrop.appendTo(document.body);
73 $backdrop[0].offsetWidth; // force reflow
74 $backdrop.addClass('in');
79 initThemeEngine: function(options) {
80 $.extend(this.themeEngineOptions, options);
81 this.currentTheme = this.themeEngineOptions.initial;
83 var $link = $('link#cowhide-theme');
84 if ($link.length === 0) {
85 this.fatal("#40: could not find <link> with id 'cowhide-theme'.");
89 setTheme: function(name, nightMode) {
90 if (name === this.currentTheme && nightMode == this.nightMode) {
94 var $link = $('link#cowhide-theme');
96 this.themeEngineOptions.path +
100 if (nightMode === true || (nightMode === undefined && this.nightMode === true)) {
104 if (this.themeEngineOptions.minified) {
110 var $backdrop = this.backdrop();
111 setTimeout(function() {
112 $link.attr('href', theme);
116 this.currentTheme = name;
117 if (nightMode !== undefined) {
118 this.nightMode = nightMode;
122 setNightMode: function(value) {
123 if (this.nightMode == value)
126 this.setTheme(this.currentTheme, !this.nightMode);
129 toggleNightMode: function() {
130 this.setNightMode(!this.nightMode);
133 toggleDrivingMode: function() {
134 this.setDrivingMode(!this.drivingMode);
137 setDrivingMode: function(value) {
140 if (self.drivingMode == value)
143 self.drivingMode = value;
144 _.each(this.registeredWidgets, function(w) {
145 if (w.setDrivingMode)
146 w.setDrivingMode(self.drivingMode);
150 initialize: function() {
153 if (window.tizen !== undefined &&
154 window.tizen.vehicle !== undefined)
156 window.tizen.vehicle.getAsync("DrivingMode", function(data) {
157 self.setNightMode(data.drivingMode);
160 window.tizen.vehicle.getAsync("NightMode", function(data) {
161 self.setNightMode(data.nightMode);
166 listenToVehicle: function() {
169 if (window.tizen !== undefined &&
170 window.tizen.vehicle !== undefined)
172 window.tizen.vehicle.subscribe("DrivingMode", function(data) {
173 self.setDrivingMode(data.drivingMode);
176 window.tizen.vehicle.subscribe("NightMode", function(data) {
177 self.setNightMode(data.nightMode);
182 verifyFrameworkRestrictions: function() {
183 _.each(this.registeredWidgets, function(w) {
184 w.verifyMinFontSize();
185 w.verifyMaxFontSize();
190 fatal: function(msg, $element) {
193 output += "[Cowhide] Fatal error";
194 if ($element !== undefined) {
195 output += " (offending widget: ";
196 var id = $element.attr('id');
197 var classes = $element.attr('class');
200 output += "#(" + id + ")";
202 output += ".(" + classes + ")";
207 output += ": " + msg;
208 throw new Error(output);
213 $.cowhide.initialize();
214 $.cowhide.listenToVehicle();
215 if ($.cowhide.options.monitorFrameworkRestrictions) {
216 setInterval(function() {
217 $.cowhide.verifyFrameworkRestrictions();
221 })(window.jQuery, window._);