was.wm.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ HEAD  →  ?path2? @ 1
File deleted
/trunk/package-lock.json
File deleted
/trunk/css/wm.css
File deleted
/trunk/dist/was.wm.js
File deleted
\ No newline at end of file
/trunk/dist/was.wm.min.js
/trunk/Gruntfile.js
@@ -17,12 +17,8 @@
stripBanners: true
},
dist: {
src: [
'node_modules/interact.js/interact.js',
'node_modules/js-cookie/src/js.cookie.js',
'lib/**/*.js'
],
dest: 'dist/<%= pkg.name %>' // <%= pkg.name %>.js -> was.wm.js
src: ['lib/*.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
uglify: {
@@ -31,7 +27,7 @@
},
dist: {
src: '<%= concat.dist.dest %>',
dest: 'dist/was.wm.min.js' // <%= pkg.name %>.min.js -> was.wm.min.js
dest: 'dist/<%= pkg.name %>.min.js'
}
},
jshint: {
@@ -48,17 +44,9 @@
boss: true,
eqnull: true,
globals: {
'$': false,
'module': false,
'document' : false,
'window' : false,
'interact' : false,
'Cookies' : false,
jQuery: true
'$': false
}
},
// spread/rest operator
esnext: true
},
gruntfile: {
src: 'Gruntfile.js'
},
@@ -69,16 +57,6 @@
nodeunit: {
files: ['test/**/*_test.js']
},
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'css/wm.css': 'css/wm.scss'
}
}
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
@@ -92,9 +70,8 @@
});
 
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-contrib-uglify');
//grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
@@ -103,7 +80,6 @@
grunt.registerTask(
'default',
[
'sass',
'jshint',
//'nodeunit',
'concat',
/trunk/bower.json
@@ -21,8 +21,5 @@
"bower_components",
"test",
"tests"
],
"dependencies": {
"was": "was.js#*"
]
}
}
/trunk/lib/wm.js
@@ -1,40 +1,19 @@
class wasWM {
// Load the window manager desktop icons.
loadWindowManagerIcons(path) {
// Reset the current icon store.
var wasWM = this;
wasWM.icons = [];
function loadWindowManagerIcons(path) {
// Search and load all nucleons.
$.get(path, function(nucleons) {
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) {
// Only consider HTML files.
if (!/\.html$/.test(file)) {
return;
}
// Skip files starting with full stop (POSIX).
if (/^\./.test(file)) return;
$.get(path + '/' + file, function(data) {
// Get DOM element.
data = $(data).get(0);
// Only consider icon types for display.
if(data.getAttribute("data-type") !== 'icon') {
return;
}
var nucleon = data.getAttribute('data-target');
// Add the nucleon to the store.
wasWM.icons.push(nucleon);
// Attach double click event.
data.addEventListener('dblclick', () => {
wasWM.openWindowManagerWindow(nucleon, path + '/' + file);
});
if(typeof states[nucleon] !== 'undefined') {
var sx = states[nucleon].x,
sy = states[nucleon].y;
@@ -69,45 +48,38 @@
}
 
// Open a window manager window.
openWindowManagerWindow(nucleon, file) {
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 icon = $('#' + nucleon + '-window-manager-icon-image').attr('src');
var nucleon_icon = $('#' + nucleon + '-window-manager-button-icon').attr('src');
 
// Change the nucleon icon to a loading icon.
$('#' + nucleon + '-window-manager-icon-image').attr('src', '/img/loader.gif');
$('#' + nucleon + '-window-manager-button-icon').attr('src', '/img/loader.gif');
 
// Disable button for successive clicks.
$('#' + nucleon + '-window-manager-icon').prop('disabled', true);
$('#' + nucleon + '-window-manager-button').prop('disabled', true);
 
// Load the nucleon.
$.get(file, function(data) {
// Retrieve the window for this nucleon.
data = $(data).get().filter(
(element) =>
$(element).attr('data-type') === 'window' &&
$(element).attr('id') === nucleon
).pop();
$.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() {
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();
});
 
@@ -132,73 +104,24 @@
$(data).hide().appendTo('#window-manager-desktop').fadeIn(750);
}).done(function(data) {
// Change the nucleon icon back.
$('#' + nucleon + '-window-manager-icon-image').attr('src', icon);
$('#' + nucleon + '-window-manager-button-icon').attr('src', nucleon_icon);
// Enable the button.
$('#' + nucleon + '-window-manager-icon').prop('disabled', false);
$('#' + nucleon + '-window-manager-button').prop('disabled', false);
});
}
 
// Retrieve the top-most window manager window z-index.
static getTopWindowIndex() {
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;
}
})
);
}
 
static 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: '' });
}
}
constructor(path) {
this.icons = [];
// Draggable and moveable windows.
$(document).ready(() => {
// Window manager windows.
interact('.window-manager-window')
.draggable({
@@ -214,13 +137,13 @@
// enable autoScroll
autoScroll: true,
onmove: wasWM.dragMoveListener,
onmove: dragMoveListener,
onend: function (event) {
event.target.style.opacity = 1;
},
onstart: function(event) {
// Move windows to top on drag.
event.target.style.zIndex = wasWM.getTopWindowIndex() + 1;
event.target.style.zIndex = getTopWindowIndex() + 1;
event.target.style.opacity = 0.5;
}
})
@@ -239,7 +162,7 @@
},
snap: {
targets: [
//createSnapGrid({ x: 64, y: 64 })
interact.createSnapGrid({ x: 64, y: 64 })
],
range: Infinity,
relativePoints: [ { x: 0, y: 0 } ]
@@ -247,7 +170,7 @@
// enable autoScroll
autoScroll: true,
onmove: wasWM.dragMoveListener,
onmove: dragMoveListener,
onend: function (event) {
event.target.style.opacity = 1;
},
@@ -268,18 +191,55 @@
$(document).on('click', '.window-manager-window', function(event) {
$(event.target)
.closest('.window-manager-window')
.css('z-index', wasWM.getTopWindowIndex() + 1);
.css('z-index', getTopWindowIndex() + 1);
});
 
// this is used later in the resizing and gesture demos
window.dragMoveListener = wasWM.dragMoveListener;
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;
 
// Load the window manager icons.
this.loadWindowManagerIcons(path);
// 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: '' });
}
}
 
wasWM.prototype.icons = [];
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;
});
/trunk/package.json
@@ -1,38 +1,29 @@
{
"author": {
"name": "Wizardry and Steamworks",
"email": "office@grimore.org"
"engines": {
"node": ">= 0.10.0"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Wizardry and Steamworks",
"email": "office@grimore.org"
}
],
"dependencies": {
"interact.js": "^1.2.8",
"jquery": "^3.3.1",
"js-cookie": "^2.2.0"
},
"deprecated": false,
"description": "Original repo at http://svn.grimore.org/was.wm.js",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-jshint": "~0.11.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-uglify-es": "git+https://github.com/gruntjs/grunt-contrib-uglify.git#harmony",
"grunt-contrib-watch": "~0.6.1"
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-uglify": "~0.5.0"
},
"name": "was",
"description": "Original repo at http://svn.grimore.org/was.wm.js",
"version": "1.0.0",
"main": "Gruntfile.js",
"directories": {
"test": "test"
},
"engines": {
"node": ">= 0.10.0"
"scripts": {
"test": "tap test/*.js"
},
"homepage": "http://grimore.org",
"repository": {
"type": "git",
"url": "svn+http://svn.grimore.org/was.wm.js"
},
"keywords": [
"wizardry",
"steamworks",
@@ -41,15 +32,7 @@
"manager",
"wm"
],
"author": "Wizardry and Steamworks <office@grimore.org>",
"license": "GPL-3.0",
"main": "Gruntfile.js",
"name": "was.wm.js",
"repository": {
"type": "git",
"url": "svn+http://svn.grimore.org/was.wm.js"
},
"scripts": {
"test": "tap test/*.js"
},
"version": "1.0.0"
"homepage": "http://grimore.org"
}