/base/000_base/js/wm/wm.js |
@@ -2,24 +2,46 @@ |
function loadWindowManagerIcons(path) { |
// Search and load all nucleons. |
$.get(path, function(nucleons) { |
var x = 0, y = 0; |
$.each(nucleons, function(index, value) { |
var ix = 0, iy = 0; |
var states = {}; |
var cookie = Cookies.get('window-manager-icons'); |
if(cookie) |
states = JSON.parse(cookie); |
$.each(nucleons, function(index, file) { |
// Skip files starting with full stop (POSIX). |
if (/^\./.test(value)) return; |
$.get(path + '/' + value, function(doc) { |
var button = $(doc).get(0); |
if (/^\./.test(file)) return; |
$.get(path + '/' + file, function(data) { |
data = $(data).get(0); |
var nucleon = data.getAttribute('data-target'); |
|
if(typeof states[nucleon] !== 'undefined') { |
var sx = states[nucleon].x, |
sy = states[nucleon].y; |
|
data.style.webkitTransform = |
data.style.transform = |
'translate(' + sx + 'px, ' + sy + 'px)'; |
|
// Update the position attributes |
data.setAttribute('data-x', sx); |
data.setAttribute('data-y', sy); |
|
$('#window-manager-desktop').append(data); |
return; |
} |
|
// Translate the desktop icons so they do not overlap. |
button.style.webkitTransform = |
button.style.transform = |
'translate(' + x + 'px, ' + y + 'px)'; |
data.style.webkitTransform = |
data.style.transform = |
'translate(' + ix + 'px, ' + iy + 'px)'; |
|
// Update the position attributes |
button.setAttribute('data-x', x); |
button.setAttribute('data-y', y); |
data.setAttribute('data-x', ix); |
data.setAttribute('data-y', iy); |
|
$('#window-manager-desktop').append(button); |
$('#window-manager-desktop').append(data); |
// Translate by the desktop icon size. |
x += 64; |
ix += 64; |
}); |
}); |
}); |
@@ -31,14 +53,20 @@ |
if($('#' + nucleon).length) |
return; |
|
// Store the icon. |
var nucleon_icon = $('#' + nucleon + '-window-manager-button-icon').attr('src'); |
|
// 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) { |
// Get the DOM object. |
data = $(data).get(0); |
|
// Select all new scripts that have to be inserted into the DOM. |
var nucleonScripts = []; |
$(data).find('script').each(function() { |
@@ -48,16 +76,37 @@ |
nucleonScripts[src] = $(this); |
}); |
// Remove scripts from the nucleon if they are already added to the DOM. |
var nowScripts = $(document).find('script').each(function() { |
$(document).find('script').each(function() { |
var src = $(this).attr('src'); |
if(nucleonScripts[src] === undefined) |
return; |
nucleonScripts[src].remove(); |
}); |
|
// Restore windows to their saved position. |
var cookie = Cookies.get('window-manager-windows'); |
if(cookie) { |
var states = JSON.parse(cookie); |
if(typeof states[nucleon] !== 'undefined') { |
var x = states[nucleon].x, |
y = states[nucleon].y, |
wm = $(data).find('.window-manager-window').get(0); |
|
if(typeof wm !== 'undefined') { |
wm.style.webkitTransform = |
wm.style.transform = |
'translate(' + x + 'px, ' + y + 'px)'; |
|
// Update the position attributes |
wm.setAttribute('data-x', x); |
wm.setAttribute('data-y', y); |
} |
} |
} |
$(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'); |
$('#' + nucleon + '-window-manager-button-icon').attr('src', nucleon_icon); |
// Enable the button. |
$('#' + nucleon + '-window-manager-button').prop('disabled', false); |
}); |
@@ -93,6 +142,24 @@ |
onmove: dragMoveListener, |
onend: function (event) { |
event.target.style.opacity = 1; |
|
// Save the window position. |
var states = {}; |
var cookie = Cookies.get('window-manager-windows'); |
if(cookie) |
states = JSON.parse(cookie); |
|
$('.window-manager-window').each(function(i, wm) { |
if(typeof $(wm).data('target') === 'undefined') |
return; |
|
states[$(wm).data('target')] = { |
x: $(wm).data('x'), |
y: $(wm).data('y') |
}; |
}); |
|
Cookies.set('window-manager-windows', states, { path: '' }); |
}, |
onstart: function(event) { |
// Move windows to top on drag. |
@@ -126,6 +193,24 @@ |
onmove: dragMoveListener, |
onend: function (event) { |
event.target.style.opacity = 1; |
|
// Save the icon position. |
var states = {}; |
var cookie = Cookies.get('window-manager-icons'); |
if(cookie) |
states = JSON.parse(cookie); |
|
$('.window-manager-icon').each(function(i, wm) { |
if(typeof $(wm).data('target') === 'undefined') |
return; |
|
states[$(wm).data('target')] = { |
x: $(wm).data('x'), |
y: $(wm).data('y') |
}; |
}); |
|
Cookies.set('window-manager-icons', states, { path: '' }); |
}, |
onstart: function(event) { |
event.target.style.opacity = 0.5; |
@@ -142,14 +227,9 @@ |
|
// Windows clicking brings to front. |
$(document).on('click', '.window-manager-window', function(event) { |
//alert($(event.target).attr('z-index')); |
$(event.target).closest('.window-manager-window').css('z-index', getTopWindowIndex() + 1); |
//$(this).attr('z-index', getTopWindowIndex() + 1); |
//alert(JSON.stringify($(this), null, 4)); |
//alert("this: " + event.target.style.zIndex + " top: " + getTopWindowIndex()); |
//event.target.style.zIndex = getTopWindowIndex() + 1; |
//alert("this: " + event.target.style.zIndex + " top: " + getTopWindowIndex()); |
//event.stopPropagation(); |
$(event.target) |
.closest('.window-manager-window') |
.css('z-index', getTopWindowIndex() + 1); |
}); |
|
function dragMoveListener (event) { |