blob: 3b62548ec8069c769505013445f8f1c90dac20bb [file] [log] [blame]
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001/*
2 ONOS UI Framework.
3
4 @author Simon Hunt
5 */
6
7(function ($) {
8 'use strict';
9 var tsI = new Date().getTime(), // initialize time stamp
10 tsB; // build time stamp
11
12 // attach our main function to the jQuery object
13 $.onos = function (options) {
14 // private namespaces
15 var publicApi; // public api
16
17 // internal state
18 var views = {},
19 currentView = null,
20 built = false;
21
22 // DOM elements etc.
23 var $mast;
24
25
26 // various functions..................
27
28 // throw an error
29 function throwError(msg) {
30 // todo: maybe add tracing later
31 throw new Error(msg);
32 }
33
34 // define all the public api functions...
35 publicApi = {
36 printTime: function () {
37 console.log("the time is " + new Date());
38 },
39
40 addView: function (vid, cb) {
41 views[vid] = {
42 vid: vid,
43 cb: cb
44 };
45 // TODO: proper registration of views
46 // for now, make the one (and only) view current..
47 currentView = views[vid];
48 }
49 };
50
51 // function to be called from index.html to build the ONOS UI
52 function buildOnosUi() {
53 tsB = new Date().getTime();
54 tsI = tsB - tsI; // initialization duration
55
56 console.log('ONOS UI initialized in ' + tsI + 'ms');
57
58 if (built) {
59 throwError("ONOS UI already built!");
60 }
61 built = true;
62
63 // TODO: invoke hash navigation
64 // --- report build errors ---
65
66 // for now, invoke the one and only load function:
67
68 currentView.cb.load();
69 }
70
71
72 // export the api and build-UI function
73 return {
74 api: publicApi,
75 buildUi: buildOnosUi
76 };
77 };
78
79}(jQuery));