corrade-nucleus-nucleons – Diff between revs 39 and 41
?pathlinks?
Rev 39 | Rev 41 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | // Load the window manager desktop icons. |
1 | // Load the window manager desktop icons. |
|
2 | function loadWindowManagerIcons(path) { |
2 | function loadWindowManagerIcons(path) { |
|
3 | // Search and load all nucleons. |
3 | // Search and load all nucleons. |
|
4 | $.get(path, function(nucleons) { |
4 | $.get(path, function(nucleons) { |
|
5 | var x = 0, y = 0; |
5 | var ix = 0, iy = 0; |
|
- | 6 | var states = {}; |
||
- | 7 | var cookie = Cookies.get('window-manager-icons'); |
||
- | 8 | if(cookie) |
||
- | 9 | states = JSON.parse(cookie); |
||
6 | $.each(nucleons, function(index, value) { |
10 | $.each(nucleons, function(index, file) { |
|
7 | // Skip files starting with full stop (POSIX). |
11 | // Skip files starting with full stop (POSIX). |
|
8 | if (/^\./.test(value)) return; |
12 | if (/^\./.test(file)) return; |
|
9 | $.get(path + '/' + value, function(doc) { |
13 | $.get(path + '/' + file, function(data) { |
|
10 | var button = $(doc).get(0); |
14 | data = $(data).get(0); |
|
- | 15 | var nucleon = data.getAttribute('data-target'); |
||
- | 16 | |
||
- | 17 | if(typeof states[nucleon] !== 'undefined') { |
||
- | 18 | var sx = states[nucleon].x, |
||
- | 19 | sy = states[nucleon].y; |
||
- | 20 | |
||
- | 21 | data.style.webkitTransform = |
||
- | 22 | data.style.transform = |
||
- | 23 | 'translate(' + sx + 'px, ' + sy + 'px)'; |
||
- | 24 | |
||
- | 25 | // Update the position attributes |
||
- | 26 | data.setAttribute('data-x', sx); |
||
- | 27 | data.setAttribute('data-y', sy); |
||
- | 28 | |
||
- | 29 | $('#window-manager-desktop').append(data); |
||
- | 30 | return; |
||
- | 31 | } |
||
- | 32 | |
||
11 | // Translate the desktop icons so they do not overlap. |
33 | // Translate the desktop icons so they do not overlap. |
|
12 | button.style.webkitTransform = |
34 | data.style.webkitTransform = |
|
13 | button.style.transform = |
35 | data.style.transform = |
|
14 | 'translate(' + x + 'px, ' + y + 'px)'; |
36 | 'translate(' + ix + 'px, ' + iy + 'px)'; |
|
Line 15... | Line 37... | |||
15 | |
37 | |
|
16 | // Update the position attributes |
38 | // Update the position attributes |
|
17 | button.setAttribute('data-x', x); |
39 | data.setAttribute('data-x', ix); |
|
Line 18... | Line 40... | |||
18 | button.setAttribute('data-y', y); |
40 | data.setAttribute('data-y', iy); |
|
19 | |
41 | |
|
20 | $('#window-manager-desktop').append(button); |
42 | $('#window-manager-desktop').append(data); |
|
21 | // Translate by the desktop icon size. |
43 | // Translate by the desktop icon size. |
|
22 | x += 64; |
44 | ix += 64; |
|
23 | }); |
45 | }); |
|
24 | }); |
46 | }); |
|
Line 29... | Line 51... | |||
29 | function openWindowManagerWindow(nucleon) { |
51 | function openWindowManagerWindow(nucleon) { |
|
30 | // If the nucleon already exists, then do not append the content again. |
52 | // If the nucleon already exists, then do not append the content again. |
|
31 | if($('#' + nucleon).length) |
53 | if($('#' + nucleon).length) |
|
32 | return; |
54 | return; |
|
Line -... | Line 55... | |||
- | 55 | |
||
- | 56 | // Store the icon. |
||
- | 57 | var nucleon_icon = $('#' + nucleon + '-window-manager-button-icon').attr('src'); |
||
33 | |
58 | |
|
34 | // Change the nucleon icon to a loading icon. |
59 | // Change the nucleon icon to a loading icon. |
|
35 | $('#' + nucleon + '-window-manager-button-icon').attr('src', '/img/loader.gif'); |
60 | $('#' + nucleon + '-window-manager-button-icon').attr('src', '/img/loader.gif'); |
|
36 | |
61 | |
|
37 | // Disable button for successive clicks. |
62 | // Disable button for successive clicks. |
|
Line 38... | Line 63... | |||
38 | $('#' + nucleon + '-window-manager-button').prop('disabled', true); |
63 | $('#' + nucleon + '-window-manager-button').prop('disabled', true); |
|
39 | |
64 | |
|
- | 65 | // Load the nucleon. |
||
- | 66 | $.get('/' + nucleon + '/index.html', function(data) { |
||
- | 67 | // Get the DOM object. |
||
40 | // Load the nucleon. |
68 | data = $(data).get(0); |
|
41 | $.get('/' + nucleon + '/index.html', function(data) { |
69 | |
|
42 | // Select all new scripts that have to be inserted into the DOM. |
70 | // Select all new scripts that have to be inserted into the DOM. |
|
43 | var nucleonScripts = []; |
71 | var nucleonScripts = []; |
|
44 | $(data).find('script').each(function() { |
72 | $(data).find('script').each(function() { |
|
45 | var src = $(this).attr('src'); |
73 | var src = $(this).attr('src'); |
|
46 | if(src === undefined) |
74 | if(src === undefined) |
|
47 | return; |
75 | return; |
|
48 | nucleonScripts[src] = $(this); |
76 | nucleonScripts[src] = $(this); |
|
49 | }); |
77 | }); |
|
50 | // Remove scripts from the nucleon if they are already added to the DOM. |
78 | // Remove scripts from the nucleon if they are already added to the DOM. |
|
51 | var nowScripts = $(document).find('script').each(function() { |
79 | $(document).find('script').each(function() { |
|
52 | var src = $(this).attr('src'); |
80 | var src = $(this).attr('src'); |
|
53 | if(nucleonScripts[src] === undefined) |
81 | if(nucleonScripts[src] === undefined) |
|
54 | return; |
82 | return; |
|
- | 83 | nucleonScripts[src].remove(); |
||
- | 84 | }); |
||
- | 85 | |
||
- | 86 | // Restore windows to their saved position. |
||
- | 87 | var cookie = Cookies.get('window-manager-windows'); |
||
- | 88 | if(cookie) { |
||
- | 89 | var states = JSON.parse(cookie); |
||
- | 90 | if(typeof states[nucleon] !== 'undefined') { |
||
- | 91 | var x = states[nucleon].x, |
||
- | 92 | y = states[nucleon].y, |
||
- | 93 | wm = $(data).find('.window-manager-window').get(0); |
||
- | 94 | |
||
- | 95 | if(typeof wm !== 'undefined') { |
||
- | 96 | wm.style.webkitTransform = |
||
- | 97 | wm.style.transform = |
||
- | 98 | 'translate(' + x + 'px, ' + y + 'px)'; |
||
- | 99 | |
||
- | 100 | // Update the position attributes |
||
- | 101 | wm.setAttribute('data-x', x); |
||
- | 102 | wm.setAttribute('data-y', y); |
||
- | 103 | } |
||
55 | nucleonScripts[src].remove(); |
104 | } |
|
56 | }); |
105 | } |
|
57 | $(data).hide().appendTo('#window-manager-desktop').fadeIn(750); |
106 | $(data).hide().appendTo('#window-manager-desktop').fadeIn(750); |
|
58 | }).done(function(data) { |
107 | }).done(function(data) { |
|
59 | // Change the nucleon icon back. |
108 | // Change the nucleon icon back. |
|
60 | $('#' + nucleon + '-window-manager-button-icon').attr('src', '/' + nucleon + '/img/' + nucleon + '.png'); |
109 | $('#' + nucleon + '-window-manager-button-icon').attr('src', nucleon_icon); |
|
61 | // Enable the button. |
110 | // Enable the button. |
|
62 | $('#' + nucleon + '-window-manager-button').prop('disabled', false); |
111 | $('#' + nucleon + '-window-manager-button').prop('disabled', false); |
|
Line 91... | Line 140... | |||
91 | autoScroll: true, |
140 | autoScroll: true, |
|
Line 92... | Line 141... | |||
92 | |
141 | |
|
93 | onmove: dragMoveListener, |
142 | onmove: dragMoveListener, |
|
94 | onend: function (event) { |
143 | onend: function (event) { |
|
- | 144 | event.target.style.opacity = 1; |
||
- | 145 | |
||
- | 146 | // Save the window position. |
||
- | 147 | var states = {}; |
||
- | 148 | var cookie = Cookies.get('window-manager-windows'); |
||
- | 149 | if(cookie) |
||
- | 150 | states = JSON.parse(cookie); |
||
- | 151 | |
||
- | 152 | $('.window-manager-window').each(function(i, wm) { |
||
- | 153 | if(typeof $(wm).data('target') === 'undefined') |
||
- | 154 | return; |
||
- | 155 | |
||
- | 156 | states[$(wm).data('target')] = { |
||
- | 157 | x: $(wm).data('x'), |
||
- | 158 | y: $(wm).data('y') |
||
- | 159 | }; |
||
- | 160 | }); |
||
- | 161 | |
||
95 | event.target.style.opacity = 1; |
162 | Cookies.set('window-manager-windows', states, { path: '' }); |
|
96 | }, |
163 | }, |
|
97 | onstart: function(event) { |
164 | onstart: function(event) { |
|
98 | // Move windows to top on drag. |
165 | // Move windows to top on drag. |
|
99 | event.target.style.zIndex = getTopWindowIndex() + 1; |
166 | event.target.style.zIndex = getTopWindowIndex() + 1; |
|
Line 124... | Line 191... | |||
124 | autoScroll: true, |
191 | autoScroll: true, |
|
Line 125... | Line 192... | |||
125 | |
192 | |
|
126 | onmove: dragMoveListener, |
193 | onmove: dragMoveListener, |
|
127 | onend: function (event) { |
194 | onend: function (event) { |
|
- | 195 | event.target.style.opacity = 1; |
||
- | 196 | |
||
- | 197 | // Save the icon position. |
||
- | 198 | var states = {}; |
||
- | 199 | var cookie = Cookies.get('window-manager-icons'); |
||
- | 200 | if(cookie) |
||
- | 201 | states = JSON.parse(cookie); |
||
- | 202 | |
||
- | 203 | $('.window-manager-icon').each(function(i, wm) { |
||
- | 204 | if(typeof $(wm).data('target') === 'undefined') |
||
- | 205 | return; |
||
- | 206 | |
||
- | 207 | states[$(wm).data('target')] = { |
||
- | 208 | x: $(wm).data('x'), |
||
- | 209 | y: $(wm).data('y') |
||
- | 210 | }; |
||
- | 211 | }); |
||
- | 212 | |
||
128 | event.target.style.opacity = 1; |
213 | Cookies.set('window-manager-icons', states, { path: '' }); |
|
129 | }, |
214 | }, |
|
130 | onstart: function(event) { |
215 | onstart: function(event) { |
|
131 | event.target.style.opacity = 0.5; |
216 | event.target.style.opacity = 0.5; |
|
132 | } |
217 | } |
|
Line 140... | Line 225... | |||
140 | }); |
225 | }); |
|
141 | }); |
226 | }); |
|
Line 142... | Line 227... | |||
142 | |
227 | |
|
143 | // Windows clicking brings to front. |
228 | // Windows clicking brings to front. |
|
144 | $(document).on('click', '.window-manager-window', function(event) { |
229 | $(document).on('click', '.window-manager-window', function(event) { |
|
145 | //alert($(event.target).attr('z-index')); |
230 | $(event.target) |
|
146 | $(event.target).closest('.window-manager-window').css('z-index', getTopWindowIndex() + 1); |
231 | .closest('.window-manager-window') |
|
147 | //$(this).attr('z-index', getTopWindowIndex() + 1); |
- | ||
148 | //alert(JSON.stringify($(this), null, 4)); |
- | ||
149 | //alert("this: " + event.target.style.zIndex + " top: " + getTopWindowIndex()); |
- | ||
150 | //event.target.style.zIndex = getTopWindowIndex() + 1; |
- | ||
151 | //alert("this: " + event.target.style.zIndex + " top: " + getTopWindowIndex()); |
- | ||
152 | //event.stopPropagation(); |
232 | .css('z-index', getTopWindowIndex() + 1); |
|
Line 153... | Line 233... | |||
153 | }); |
233 | }); |
|
154 | |
234 | |
|
155 | function dragMoveListener (event) { |
235 | function dragMoveListener (event) { |