was.wm.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 1  →  ?path2? @ 4
/trunk/lib/wm.js
@@ -5,11 +5,14 @@
var ix = 0, iy = 0;
var states = {};
var cookie = Cookies.get('window-manager-icons');
if(cookie)
if(cookie) {
states = JSON.parse(cookie);
}
$.each(nucleons, function(index, file) {
// Skip files starting with full stop (POSIX).
if (/^\./.test(file)) return;
if (/^\./.test(file)) {
return;
}
$.get(path + '/' + file, function(data) {
data = $(data).get(0);
var nucleon = data.getAttribute('data-target');
@@ -50,8 +53,9 @@
// Open a window manager window.
function openWindowManagerWindow(nucleon) {
// If the nucleon already exists, then do not append the content again.
if($('#' + nucleon).length)
if($('#' + nucleon).length) {
return;
}
// Store the icon.
var nucleon_icon = $('#' + nucleon + '-window-manager-button-icon').attr('src');
@@ -71,15 +75,17 @@
var nucleonScripts = [];
$(data).find('script').each(function() {
var src = $(this).attr('src');
if(src === undefined)
if(src === undefined) {
return;
}
nucleonScripts[src] = $(this);
});
// Remove scripts from the nucleon if they are already added to the DOM.
$(document).find('script').each(function() {
var src = $(this).attr('src');
if(nucleonScripts[src] === undefined)
if(nucleonScripts[src] === undefined) {
return;
}
nucleonScripts[src].remove();
});
@@ -114,8 +120,9 @@
function getTopWindowIndex() {
return Math.max.apply(null,
$.map($('.window-manager-window'), function(e, n) {
if ($(e).css('position') != 'static')
if ($(e).css('position') !== 'static') {
return parseInt($(e).css('z-index')) || 1;
}
})
);
}
@@ -122,6 +129,54 @@
 
// Draggable and moveable windows.
$(document).ready(() => {
function dragMoveListener (event) {
var target = event.target, states, cookie,
// 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);
if(target.classList.contains('window-manager-window')) {
// Save the window position.
states = {};
cookie = Cookies.get('window-manager-windows');
if(cookie) {
states = JSON.parse(cookie);
}
states[$(event.target).data('target')] = {
x: x,
y: y
};
Cookies.set('window-manager-windows', states, { path: '' });
}
if(target.classList.contains('window-manager-icon')) {
// Save the icon position.
states = {};
cookie = Cookies.get('window-manager-icons');
if(cookie) {
states = JSON.parse(cookie);
}
states[$(event.target).data('target')] = {
x: x,
y: y
};
Cookies.set('window-manager-icons', states, { path: '' });
}
}
// Window manager windows.
interact('.window-manager-window')
.draggable({
@@ -193,53 +248,7 @@
.closest('.window-manager-window')
.css('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);
if(target.classList.contains('window-manager-window')) {
// Save the window position.
var states = {};
var cookie = Cookies.get('window-manager-windows');
if(cookie)
states = JSON.parse(cookie);
states[$(event.target).data('target')] = {
x: x,
y: y
};
Cookies.set('window-manager-windows', states, { path: '' });
}
if(target.classList.contains('window-manager-icon')) {
// Save the icon position.
var states = {};
var cookie = Cookies.get('window-manager-icons');
if(cookie)
states = JSON.parse(cookie);
states[$(event.target).data('target')] = {
x: x,
y: y
};
Cookies.set('window-manager-icons', states, { path: '' });
}
}
 
// this is used later in the resizing and gesture demos
window.dragMoveListener = dragMoveListener;
});