corrade-nucleus-nucleons – Blame information for rev 31

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