corrade-nucleus-nucleons – Blame information for rev 33

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