From 9ab7aa9dac11309ebde8018a11a18ecd5bedb6c7 Mon Sep 17 00:00:00 2001 From: Severak Date: Sat, 14 Sep 2019 21:51:15 +0200 Subject: [PATCH] Working window magager ported from selfsame. --- desktop.html | 195 +++++++++++++++++++++++++++++++-------- desktop/js/desktop.js | 207 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 366 insertions(+), 36 deletions(-) create mode 100644 desktop/js/desktop.js diff --git a/desktop.html b/desktop.html index c5599f1..5dd62bf 100644 --- a/desktop.html +++ b/desktop.html @@ -3,9 +3,10 @@ BrowzOS - + + time -About BrowzOSinfo - - - - + + + +
+ + + + + +
+ + +
+ +
+ + + + + + \ No newline at end of file diff --git a/desktop/js/desktop.js b/desktop/js/desktop.js new file mode 100644 index 0000000..70aed57 --- /dev/null +++ b/desktop/js/desktop.js @@ -0,0 +1,207 @@ +/* Author: +selfsame +*/ +debug = true +window.files = {}; +window.drag = false; +window.target = false; +window.mousex = 0; window.mousey = 0; +window.zheight = 0; + +$(window).mousedown(function(e) { + window.mousex = e.clientX; + window.mousey = e.clientY; + document.body.classList.add("mousedown") +}); + +$(window).mousemove(function(e) { + if (window.drag) { + x = e.clientX; y = e.clientY; + dx = x - window.mousex; + dy = y - window.mousey; + window.mousex = x; window.mousey = y; + e["dx"] = dx; e["dy"] = dy; + window.drag(e, window.target); + } +}); + +$(window).mouseup(function(e){ + window.drag = false; + window.target = false; + document.body.classList.remove("mousedown") +}); + +$(window).ready(function () {}); + +/* +$(window).load(function () { + $.getJSON("public.json", parse_files) +}); +*/ + +var img_data = function(img){ + var canvas = document.createElement('canvas'); + var context = canvas.getContext('2d'); + canvas.width = img.width; + canvas.height = img.height; + context.drawImage(img, 0, 0 ); + return context.getImageData(0, 0, img.width, img.height); +} + +var data_url = function(img, data){ + var canvas = document.createElement('canvas'); + var context = canvas.getContext('2d'); + canvas.width = img.width; + canvas.height = img.height; + context.putImageData(data, 0, 0 ); + return canvas.toDataURL(); +} + + +var get_mime = function(s){ + var match = s.match( /\.([^\.]*)$/) + if (match) { + return match[match.length-1] + } +} + +var contains = function(ar, v){ + return ar.indexOf(v) != -1 +} + +img_mimes = ["gif", "png", "jpg", "bmp"] + +make_icon = function(name, path){ + if (debug) {console.log("make_icon",name, path)}; + mime = get_mime(name) + icon = "img/icon-doc.png" + if (mime == "zip") { + icon = "img/zip.png" + } + if (contains(img_mimes, mime)){ + icon = "img/img.png" + } + var file = $("

"+name+"

"); + if (contains(img_mimes, mime)){ + file[0].onclick = function(e){ + e.preventDefault() + var w = raw_window(name) + w.addClass("image") + var view = w.find('.view') + view.append($("")) + var img = view.find('img') + img[0].onload = function(e){ + var id = monochrome(img_data(e.target) ) + e.target.src = data_url(e.target, id) + e.target.onload = null + } + } + } + if (mime == "html"){ + file[0].onclick = function(e){ + e.preventDefault() + var w = raw_window(name) + w.addClass("html") + w[0].style.width = "600px" + w[0].style.height = "480px" + var view = w.find('.view') + view.append($("