[BluetoothChat]update BluetoothChat(tizen_2.1)
[samples/web/BluetoothChat.git] / js / main.js
1 /*
2  *      Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  *      Licensed under the Flora License, Version 1.0 (the "License");
5  *      you may not use this file except in compliance with the License.
6  *      You may obtain a copy of the License at
7  *
8  *              http://floralicense.org/license/
9  *
10  *      Unless required by applicable law or agreed to in writing, software
11  *      distributed under the License is distributed on an "AS IS" BASIS,
12  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *      See the License for the specific language governing permissions and
14  *      limitations under the License.
15  */
16
17 /*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
18 /*global $, tizen, app */
19 var app = null;
20
21 (function () { // strict mode wrapper
22         'use strict';
23
24         ({
25                 /**
26                  * Loader init - load the App constructor
27                  */
28                 init: function init() {
29                         var self = this;
30                         $.getScript('js/app.js')
31                                 .done(function () {
32                                         app = new App();
33                                         self.loadLibs();
34                                 })
35                                 .fail(this.onGetScriptError);
36                 },
37
38                 /**
39                  * Load dependencies
40                  */
41                 loadLibs: function loadLibs() {
42                         var loadedLibs = 0;
43                         if ($.isArray(app.requires)) {
44                                 $.each(app.requires, function (index, filename) {
45                                         $.getScript(filename)
46                                                 .done(function () {
47                                                         loadedLibs += 1;
48                                                         if (loadedLibs >= app.requires.length) {
49                                                                 app.init();
50                                                         }
51                                                 })
52                                                 .fail(this.onGetScriptError);
53                                 });
54                         }
55                 },
56
57                 /**
58                  * Handle ajax errors
59                  */
60                 onGetScriptError: function onGetScriptError(e, jqxhr, setting, exception) {
61                         console.error('An error occurred: ' + e.message);
62                 }
63         }).init(); // run the loader
64 }());