corrade-nucleus-nucleons – Blame information for rev 34

Subversion Repositories:
Rev:
Rev Author Line No. Line
31 office 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) {
33 office 43 // Select all new scripts that have to be inserted into the DOM.
44 var nucleonScripts = [];
45 $(data).find('script').each(function() {
46 var src = $(this).attr('src');
47 if(src === undefined)
48 return;
49 nucleonScripts[src] = $(this).get(0);
50 });
51 // Remove scripts from the nucleon if they are already added to the DOM.
52 var nowScripts = $(document).find('script').each(function() {
53 var src = $(this).attr('src');
54 if(nucleonScripts[src] === undefined)
55 return;
34 office 56 alert(nucleonScripts[src]);
33 office 57 $(data).remove(nucleonScripts[src]);
58 });
31 office 59 $(data).hide().appendTo('#window-manager-desktop').fadeIn(750);
60 }).done(function(data) {
61 // Change the nucleon icon back.
62 $('#' + nucleon + '-window-manager-button-icon').attr('src', '/' + nucleon + '/img/' + nucleon + '.png');
63 // Enable the button.
64 $('#' + nucleon + '-window-manager-button').prop('disabled', false);
65 });
66 }
67  
68 // Retrieve the top-most window manager window z-index.
25 office 69 function getTopWindowIndex() {
70 return Math.max.apply(null,
29 office 71 $.map($('.window-manager-window'), function(e, n) {
25 office 72 if ($(e).css('position') != 'static')
31 office 73 return parseInt($(e).css('z-index')) || 1;
25 office 74 })
75 );
76 }
77  
78 // Draggable and moveable windows.
79 $(document).ready(() => {
29 office 80 // Window manager windows.
81 interact('.window-manager-window')
25 office 82 .draggable({
83 // enable inertial throwing
84 inertia: true,
85 // keep the element within the area of it's parent
29 office 86 restrict: {
87 restriction: $('#window-manager-desktop').get(0),
88 endOnly: true,
89 elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
90 },
25 office 91  
92 // enable autoScroll
93 autoScroll: true,
94  
95 onmove: dragMoveListener,
96 onend: function (event) {
97 event.target.style.opacity = 1;
98 },
99 onstart: function(event) {
100 // Move windows to top on drag.
101 event.target.style.zIndex = getTopWindowIndex() + 1;
102 event.target.style.opacity = 0.5;
103 }
104 })
29 office 105 .allowFrom('.panel-heading');
30 office 106  
107 // Window manager icons.
108 interact('.window-manager-icon')
109 .draggable({
110 // enable inertial throwing
111 inertia: false,
112 // keep the element within the area of it's parent
113 restrict: {
114 restriction: $('#window-manager-desktop').get(0),
115 endOnly: true,
116 elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
117 },
118 snap: {
119 targets: [
120 interact.createSnapGrid({ x: 64, y: 64 })
121 ],
122 range: Infinity,
123 relativePoints: [ { x: 0, y: 0 } ]
124 },
125 // enable autoScroll
126 autoScroll: true,
127  
128 onmove: dragMoveListener,
129 onend: function (event) {
130 event.target.style.opacity = 1;
131 },
132 onstart: function(event) {
133 event.target.style.opacity = 0.5;
134 }
135 });
25 office 136  
29 office 137 // Closing windows.
138 $(document).on('click', '.window-manager-close-button', function(event) {
31 office 139 var wm = $('#' + $(this).data('target'));
140 wm.fadeOut(750, function() {
141 wm.remove();
142 });
29 office 143 });
144  
145 // Windows clicking brings to front.
146 $(document).on('click', '.window-manager-window', function(event) {
147 $(this).attr('z-index', getTopWindowIndex() + 1);
148 });
149  
25 office 150 function dragMoveListener (event) {
151 var target = event.target,
152 // keep the dragged position in the data-x/data-y attributes
153 x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
154 y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
155  
156 // translate the element
157 target.style.webkitTransform =
158 target.style.transform =
159 'translate(' + x + 'px, ' + y + 'px)';
160  
29 office 161 // update the position attributes
25 office 162 target.setAttribute('data-x', x);
163 target.setAttribute('data-y', y);
164 }
165  
166 // this is used later in the resizing and gesture demos
167 window.dragMoveListener = dragMoveListener;
168 });