corrade-nucleus-nucleons – Diff between revs 30 and 31
?pathlinks?
Rev 30 | Rev 31 | |||
---|---|---|---|---|
- | 1 | // Load the window manager desktop icons. |
||
- | 2 | function loadWindowManagerIcons(path) { |
||
- | 3 | // Search and load all nucleons. |
||
- | 4 | $.get(path, function(data) { |
||
- | 5 | var nucleons = wasCSVToArray(data); |
||
- | 6 | var x = 0, y = 0; |
||
- | 7 | $.each(nucleons, function(index, value) { |
||
- | 8 | // Skip files starting with full stop (POSIX). |
||
- | 9 | if (/^\./.test(value)) return; |
||
- | 10 | $.get(path + '/' + value, function(doc) { |
||
- | 11 | var button = $(doc).get(0); |
||
- | 12 | // Translate the desktop icons so they do not overlap. |
||
- | 13 | button.style.webkitTransform = |
||
- | 14 | button.style.transform = |
||
- | 15 | 'translate(' + x + 'px, ' + y + 'px)'; |
||
- | 16 | |
||
- | 17 | // Update the position attributes |
||
- | 18 | button.setAttribute('data-x', x); |
||
- | 19 | button.setAttribute('data-y', y); |
||
- | 20 | |
||
- | 21 | $('#window-manager-desktop').append(button); |
||
- | 22 | // Translate by the desktop icon size. |
||
- | 23 | x += 64; |
||
- | 24 | }); |
||
- | 25 | }); |
||
- | 26 | }); |
||
- | 27 | } |
||
- | 28 | |
||
- | 29 | // Open a window manager window. |
||
- | 30 | function openWindowManagerWindow(nucleon) { |
||
- | 31 | // If the nucleon already exists, then do not append the content again. |
||
- | 32 | if($('#' + nucleon).length) |
||
- | 33 | return; |
||
- | 34 | |
||
- | 35 | // Change the nucleon icon to a loading icon. |
||
- | 36 | $('#' + nucleon + '-window-manager-button-icon').attr('src', '/img/loader.gif'); |
||
- | 37 | |
||
- | 38 | // Disable button for successive clicks. |
||
- | 39 | $('#' + nucleon + '-window-manager-button').prop('disabled', true); |
||
- | 40 | |
||
- | 41 | // Load the nucleon. |
||
- | 42 | $.get('/' + nucleon + '/index.html', function(data) { |
||
- | 43 | $(data).hide().appendTo('#window-manager-desktop').fadeIn(750); |
||
- | 44 | }).done(function(data) { |
||
- | 45 | // Change the nucleon icon back. |
||
- | 46 | $('#' + nucleon + '-window-manager-button-icon').attr('src', '/' + nucleon + '/img/' + nucleon + '.png'); |
||
- | 47 | // Enable the button. |
||
- | 48 | $('#' + nucleon + '-window-manager-button').prop('disabled', false); |
||
- | 49 | }); |
||
- | 50 | } |
||
- | 51 | |
||
1 | // Retrieve the top-most window z-index. |
52 | // Retrieve the top-most window manager window z-index. |
|
2 | function getTopWindowIndex() { |
53 | function getTopWindowIndex() { |
|
3 | return Math.max.apply(null, |
54 | return Math.max.apply(null, |
|
4 | $.map($('.window-manager-window'), function(e, n) { |
55 | $.map($('.window-manager-window'), function(e, n) { |
|
5 | if ($(e).css('position') != 'static') |
56 | if ($(e).css('position') != 'static') |
|
6 | return parseInt($(e).css('z-index')) || 2; |
57 | return parseInt($(e).css('z-index')) || 1; |
|
7 | }) |
58 | }) |
|
8 | ); |
59 | ); |
|
9 | } |
60 | } |
|
10 | |
61 | |
|
11 | // Draggable and moveable windows. |
62 | // Draggable and moveable windows. |
|
12 | $(document).ready(() => { |
63 | $(document).ready(() => { |
|
13 | // Window manager windows. |
64 | // Window manager windows. |
|
14 | interact('.window-manager-window') |
65 | interact('.window-manager-window') |
|
15 | .draggable({ |
66 | .draggable({ |
|
16 | // enable inertial throwing |
67 | // enable inertial throwing |
|
17 | inertia: true, |
68 | inertia: true, |
|
18 | // keep the element within the area of it's parent |
69 | // keep the element within the area of it's parent |
|
19 | restrict: { |
70 | restrict: { |
|
20 | restriction: $('#window-manager-desktop').get(0), |
71 | restriction: $('#window-manager-desktop').get(0), |
|
21 | endOnly: true, |
72 | endOnly: true, |
|
22 | elementRect: { top: 0, left: 0, bottom: 1, right: 1 } |
73 | elementRect: { top: 0, left: 0, bottom: 1, right: 1 } |
|
23 | }, |
74 | }, |
|
24 | |
75 | |
|
25 | // enable autoScroll |
76 | // enable autoScroll |
|
26 | autoScroll: true, |
77 | autoScroll: true, |
|
27 | |
78 | |
|
28 | onmove: dragMoveListener, |
79 | onmove: dragMoveListener, |
|
29 | onend: function (event) { |
80 | onend: function (event) { |
|
30 | event.target.style.opacity = 1; |
81 | event.target.style.opacity = 1; |
|
31 | }, |
82 | }, |
|
32 | onstart: function(event) { |
83 | onstart: function(event) { |
|
33 | // Move windows to top on drag. |
84 | // Move windows to top on drag. |
|
34 | event.target.style.zIndex = getTopWindowIndex() + 1; |
85 | event.target.style.zIndex = getTopWindowIndex() + 1; |
|
35 | event.target.style.opacity = 0.5; |
86 | event.target.style.opacity = 0.5; |
|
36 | } |
87 | } |
|
37 | }) |
88 | }) |
|
38 | .allowFrom('.panel-heading'); |
89 | .allowFrom('.panel-heading'); |
|
39 | |
90 | |
|
40 | // Window manager icons. |
91 | // Window manager icons. |
|
41 | interact('.window-manager-icon') |
92 | interact('.window-manager-icon') |
|
42 | .draggable({ |
93 | .draggable({ |
|
43 | // enable inertial throwing |
94 | // enable inertial throwing |
|
44 | inertia: false, |
95 | inertia: false, |
|
45 | // keep the element within the area of it's parent |
96 | // keep the element within the area of it's parent |
|
46 | restrict: { |
97 | restrict: { |
|
47 | restriction: $('#window-manager-desktop').get(0), |
98 | restriction: $('#window-manager-desktop').get(0), |
|
48 | endOnly: true, |
99 | endOnly: true, |
|
49 | elementRect: { top: 0, left: 0, bottom: 1, right: 1 } |
100 | elementRect: { top: 0, left: 0, bottom: 1, right: 1 } |
|
50 | }, |
101 | }, |
|
51 | snap: { |
102 | snap: { |
|
52 | targets: [ |
103 | targets: [ |
|
53 | interact.createSnapGrid({ x: 64, y: 64 }) |
104 | interact.createSnapGrid({ x: 64, y: 64 }) |
|
54 | ], |
105 | ], |
|
55 | range: Infinity, |
106 | range: Infinity, |
|
56 | relativePoints: [ { x: 0, y: 0 } ] |
107 | relativePoints: [ { x: 0, y: 0 } ] |
|
57 | }, |
108 | }, |
|
58 | // enable autoScroll |
109 | // enable autoScroll |
|
59 | autoScroll: true, |
110 | autoScroll: true, |
|
60 | |
111 | |
|
61 | onmove: dragMoveListener, |
112 | onmove: dragMoveListener, |
|
62 | onend: function (event) { |
113 | onend: function (event) { |
|
63 | event.target.style.opacity = 1; |
114 | event.target.style.opacity = 1; |
|
64 | }, |
115 | }, |
|
65 | onstart: function(event) { |
116 | onstart: function(event) { |
|
66 | event.target.style.opacity = 0.5; |
117 | event.target.style.opacity = 0.5; |
|
67 | } |
118 | } |
|
68 | }); |
119 | }); |
|
69 | |
120 | |
|
70 | // Closing windows. |
121 | // Closing windows. |
|
71 | $(document).on('click', '.window-manager-close-button', function(event) { |
122 | $(document).on('click', '.window-manager-close-button', function(event) { |
|
72 | $('#' + $(this).data('target')).detach(); |
123 | var wm = $('#' + $(this).data('target')); |
|
- | 124 | wm.fadeOut(750, function() { |
||
- | 125 | wm.remove(); |
||
- | 126 | }); |
||
73 | }); |
127 | }); |
|
74 | |
128 | |
|
75 | // Windows clicking brings to front. |
129 | // Windows clicking brings to front. |
|
76 | $(document).on('click', '.window-manager-window', function(event) { |
130 | $(document).on('click', '.window-manager-window', function(event) { |
|
77 | $(this).attr('z-index', getTopWindowIndex() + 1); |
131 | $(this).attr('z-index', getTopWindowIndex() + 1); |
|
78 | }); |
132 | }); |
|
79 | |
133 | |
|
80 | function dragMoveListener (event) { |
134 | function dragMoveListener (event) { |
|
81 | var target = event.target, |
135 | var target = event.target, |
|
82 | // keep the dragged position in the data-x/data-y attributes |
136 | // keep the dragged position in the data-x/data-y attributes |
|
83 | x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, |
137 | x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, |
|
84 | y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; |
138 | y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; |
|
85 | |
139 | |
|
86 | // translate the element |
140 | // translate the element |
|
87 | target.style.webkitTransform = |
141 | target.style.webkitTransform = |
|
88 | target.style.transform = |
142 | target.style.transform = |
|
89 | 'translate(' + x + 'px, ' + y + 'px)'; |
143 | 'translate(' + x + 'px, ' + y + 'px)'; |
|
90 | |
144 | |
|
91 | // update the position attributes |
145 | // update the position attributes |
|
92 | target.setAttribute('data-x', x); |
146 | target.setAttribute('data-x', x); |
|
93 | target.setAttribute('data-y', y); |
147 | target.setAttribute('data-y', y); |
|
94 | } |
148 | } |
|
95 | |
149 | |
|
96 | // this is used later in the resizing and gesture demos |
150 | // this is used later in the resizing and gesture demos |
|
97 | window.dragMoveListener = dragMoveListener; |
151 | window.dragMoveListener = dragMoveListener; |
|
98 | }); |
152 | }); |
|
99 | |
153 | |
|
100 |
|
154 |
|
|
101 | |
155 | |
|
102 | |
156 | |
|
103 | |
157 | |