1 | $(function() { |
---|
2 | // Debugger error workaround |
---|
3 | jQuery.extend({ |
---|
4 | getScript: function(url, callback) { |
---|
5 | var d = $.Deferred(); |
---|
6 | if (callback) |
---|
7 | d.done(callback); |
---|
8 | var head = document.getElementsByTagName("head")[0]; |
---|
9 | var script = document.createElement("script"); |
---|
10 | script.src = url; |
---|
11 | |
---|
12 | // Handle Script loading |
---|
13 | { |
---|
14 | var done = false; |
---|
15 | |
---|
16 | // Attach handlers for all browsers |
---|
17 | script.onload = script.onreadystatechange = function(){ |
---|
18 | if ( !done && (!this.readyState || |
---|
19 | this.readyState == "loaded" || this.readyState == "complete") ) { |
---|
20 | done = true; |
---|
21 | d.resolve(); |
---|
22 | |
---|
23 | // Handle memory leak in IE |
---|
24 | script.onload = script.onreadystatechange = null; |
---|
25 | } |
---|
26 | }; |
---|
27 | } |
---|
28 | |
---|
29 | head.appendChild(script); |
---|
30 | |
---|
31 | // We handle everything using the script element injection |
---|
32 | return d; |
---|
33 | } |
---|
34 | }); |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | mockup = { |
---|
39 | api: { |
---|
40 | clickTile: function(thisElement, url) { |
---|
41 | // clear frame |
---|
42 | $(".basePanel").children().remove(); |
---|
43 | mockup.api.loadPage(url); |
---|
44 | |
---|
45 | }, |
---|
46 | loadPage: function(name, conf) { |
---|
47 | |
---|
48 | if (conf) { |
---|
49 | if (!confirm("Are you sure you want to go back? You will lose your selected data.")) { |
---|
50 | return; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | $(".basePanel").children().remove(); |
---|
55 | |
---|
56 | $.get("pages/"+name+".html", function(responseText, textStatus, XMLHttpRequest) { |
---|
57 | $(".basePanel").append(responseText); |
---|
58 | $.getScript("pages/"+name+".js", function(responseText, textStatus, XMLHttpRequest){ |
---|
59 | |
---|
60 | }) |
---|
61 | }); |
---|
62 | mockup.api.breadcrumbs.navTo(name); |
---|
63 | }, |
---|
64 | auth: function(target, destination) { |
---|
65 | debugger; |
---|
66 | var name = document.getElementById("loginForm_name"); |
---|
67 | var pw = document.getElementById("loginForm_password"); |
---|
68 | |
---|
69 | if (name.value.length > 0 && pw.value.length > 0) { |
---|
70 | mockup.api.clickTile(target, destination); |
---|
71 | } |
---|
72 | |
---|
73 | }, |
---|
74 | breadcrumbs: new (function() { |
---|
75 | var _crumbs = []; |
---|
76 | var _element = document.getElementById('breadcrumbs'); |
---|
77 | this.init = function() { |
---|
78 | updateDiv(); |
---|
79 | } |
---|
80 | |
---|
81 | this.navTo = function(name) { |
---|
82 | // Check of 'name' al in crumbs staat. |
---|
83 | // Als wel: navBack, delete alle crumbs na 'name', update div. |
---|
84 | // Als niet: addCrumb, voeg 'name' toe aan crumbs en update de div. |
---|
85 | var index = _crumbs.indexOf(name); |
---|
86 | if (index != -1) { |
---|
87 | navBack(name, index); |
---|
88 | } |
---|
89 | else { |
---|
90 | addCrumb(name); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | var addCrumb = function(name) { |
---|
95 | _crumbs.push(name); |
---|
96 | updateDiv(); |
---|
97 | } |
---|
98 | |
---|
99 | var navBack = function(name, index) { |
---|
100 | var i = index; |
---|
101 | _crumbs = _crumbs.slice(0, i+1); |
---|
102 | updateDiv(); |
---|
103 | } |
---|
104 | |
---|
105 | var updateDiv = function() { |
---|
106 | //format first |
---|
107 | _element.innerHTML = null || ""; |
---|
108 | for (var n=0; n < _crumbs.length; n++) { |
---|
109 | var _link; |
---|
110 | if (_crumbs[n] == "Home") { |
---|
111 | link = document.createTextNode("Home"); |
---|
112 | _element.appendChild(link); |
---|
113 | |
---|
114 | |
---|
115 | } |
---|
116 | else{ |
---|
117 | link = document.createElement('a'); |
---|
118 | link.innerHTML = _crumbs[n]; |
---|
119 | link.setAttribute("onclick", "mockup.api.loadPage('"+_crumbs[n]+"', true);"); |
---|
120 | link.setAttribute("href","#"); |
---|
121 | _element.appendChild(link); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | if (n != _crumbs.length-1) { |
---|
126 | _element.innerHTML += " > "; |
---|
127 | } |
---|
128 | else { |
---|
129 | link.className = "selected"; |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|
133 | } |
---|
134 | })(), |
---|
135 | graphs: { |
---|
136 | previewGraph: null, |
---|
137 | dashboard: [], |
---|
138 | graphObjects: [] |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | } |
---|
145 | }); |
---|