corrade-nucleus-nucleons – Rev 37
?pathlinks?
// Load the window manager desktop icons.
function loadWindowManagerIcons(path) {
// Search and load all nucleons.
$.get(path, function(nucleons) {
var x = 0, y = 0;
$.each(nucleons, function(index, value) {
// Skip files starting with full stop (POSIX).
if (/^\./.test(value)) return;
$.get(path + '/' + value, function(doc) {
var button = $(doc).get(0);
// Translate the desktop icons so they do not overlap.
button.style.webkitTransform =
button.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
// Update the position attributes
button.setAttribute('data-x', x);
button.setAttribute('data-y', y);
$('#window-manager-desktop').append(button);
// Translate by the desktop icon size.
x += 64;
});
});
});
}
// Open a window manager window.
function openWindowManagerWindow(nucleon) {
// If the nucleon already exists, then do not append the content again.
if($('#' + nucleon).length)
return;
// Change the nucleon icon to a loading icon.
$('#' + nucleon + '-window-manager-button-icon').attr('src', '/img/loader.gif');
// Disable button for successive clicks.
$('#' + nucleon + '-window-manager-button').prop('disabled', true);
// Load the nucleon.
$.get('/' + nucleon + '/index.html', function(data) {
// Select all new scripts that have to be inserted into the DOM.
var nucleonScripts = [];
$(data).find('script').each(function() {
var src = $(this).attr('src');
if(src === undefined)
return;
nucleonScripts[src] = $(this);
});
// Remove scripts from the nucleon if they are already added to the DOM.
var nowScripts = $(document).find('script').each(function() {
var src = $(this).attr('src');
if(nucleonScripts[src] === undefined)
return;
nucleonScripts[src].remove();
});
$(data).hide().appendTo('#window-manager-desktop').fadeIn(750);
}).done(function(data) {
// Change the nucleon icon back.
$('#' + nucleon + '-window-manager-button-icon').attr('src', '/' + nucleon + '/img/' + nucleon + '.png');
// Enable the button.
$('#' + nucleon + '-window-manager-button').prop('disabled', false);
});
}
// Retrieve the top-most window manager window z-index.
function getTopWindowIndex() {
return Math.max.apply(null,
$.map($('.window-manager-window'), function(e, n) {
if ($(e).css('position') != 'static')
return parseInt($(e).css('z-index')) || 1;
})
);
}
// Draggable and moveable windows.
$(document).ready(() => {
// Window manager windows.
interact('.window-manager-window')
.draggable({
// enable inertial throwing
inertia: true,
// keep the element within the area of it's parent
restrict: {
restriction: $('#window-manager-desktop').get(0),
endOnly: true,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
// enable autoScroll
autoScroll: true,
onmove: dragMoveListener,
onend: function (event) {
event.target.style.opacity = 1;
},
onstart: function(event) {
// Move windows to top on drag.
event.target.style.zIndex = getTopWindowIndex() + 1;
event.target.style.opacity = 0.5;
}
})
.allowFrom('.panel-heading');
// Window manager icons.
interact('.window-manager-icon')
.draggable({
// enable inertial throwing
inertia: false,
// keep the element within the area of it's parent
restrict: {
restriction: $('#window-manager-desktop').get(0),
endOnly: true,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
snap: {
targets: [
interact.createSnapGrid({ x: 64, y: 64 })
],
range: Infinity,
relativePoints: [ { x: 0, y: 0 } ]
},
// enable autoScroll
autoScroll: true,
onmove: dragMoveListener,
onend: function (event) {
event.target.style.opacity = 1;
},
onstart: function(event) {
event.target.style.opacity = 0.5;
}
});
// Closing windows.
$(document).on('click', '.window-manager-close-button', function(event) {
var wm = $('#' + $(this).data('target'));
wm.fadeOut(750, function() {
wm.remove();
});
});
// Windows clicking brings to front.
$(document).on('click', '.window-manager-window', function(event) {
$(this).attr('z-index', getTopWindowIndex() + 1);
});
function dragMoveListener (event) {
var target = event.target,
// keep the dragged position in the data-x/data-y attributes
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
// update the position attributes
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
}
// this is used later in the resizing and gesture demos
window.dragMoveListener = dragMoveListener;
});
Generated by GNU Enscript 1.6.5.90.