Rewrite in progress
This commit is contained in:
parent
c40345133e
commit
20dee21a2c
161
docs/api.html
Normal file
161
docs/api.html
Normal file
File diff suppressed because one or more lines are too long
109
docs/api.zpy
Normal file
109
docs/api.zpy
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
# JSDE API Reference
|
||||||
|
|
||||||
|
{TOC}
|
||||||
|
|
||||||
|
## JsdeWindow
|
||||||
|
|
||||||
|
### Member variables
|
||||||
|
|
||||||
|
^ JsdeWindow.id
|
||||||
|
|
||||||
|
Holds the unique ID of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow.x
|
||||||
|
|
||||||
|
Holds the current X position of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow.y
|
||||||
|
|
||||||
|
Holds the current Y position of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow.z
|
||||||
|
|
||||||
|
Holds the current Z-index of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow.width
|
||||||
|
|
||||||
|
Holds the current width of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow.height
|
||||||
|
|
||||||
|
Holds the current height of the window.
|
||||||
|
|
||||||
|
^ JsdeWindow._inner
|
||||||
|
|
||||||
|
! Do __not__ use this to set the window contents, use JsdeWindow.SetContents() instead!
|
||||||
|
|
||||||
|
Holds a reference to the DOM element containing the window contents.
|
||||||
|
|
||||||
|
### Member functions
|
||||||
|
|
||||||
|
^ JsdeWindow.SetPosition(**x**, **y**)
|
||||||
|
|
||||||
|
Sets the current position of a window.
|
||||||
|
|
||||||
|
x::
|
||||||
|
The X coordinate.
|
||||||
|
|
||||||
|
y::
|
||||||
|
The Y coordinate.
|
||||||
|
|
||||||
|
@ Setting the window position
|
||||||
|
|
||||||
|
$ win.SetPosition(100, 110);
|
||||||
|
|
||||||
|
^ JsdeWindow.SetSize(**width**, **height**)
|
||||||
|
|
||||||
|
Sets the current size of a window.
|
||||||
|
|
||||||
|
width::
|
||||||
|
The new width.
|
||||||
|
|
||||||
|
height::
|
||||||
|
The new height.
|
||||||
|
|
||||||
|
@ Setting the window size
|
||||||
|
|
||||||
|
$ win.SetSize(400, 350);
|
||||||
|
|
||||||
|
^ JsdeWindow.GetTitle()
|
||||||
|
|
||||||
|
Returns the current title of the window.
|
||||||
|
|
||||||
|
@ Retrieving the window title
|
||||||
|
|
||||||
|
$ console.log(win.GetTitle());
|
||||||
|
|
||||||
|
> "Example window title"
|
||||||
|
|
||||||
|
^ JsdeWindow.SetTitle(**title**)
|
||||||
|
|
||||||
|
Sets the current title of the window.
|
||||||
|
|
||||||
|
title::
|
||||||
|
The title to set.
|
||||||
|
|
||||||
|
@ Setting the window title
|
||||||
|
|
||||||
|
$ win.SetTitle("Fancy new window title");
|
||||||
|
|
||||||
|
^ JsdeWindow.GetContents()
|
||||||
|
|
||||||
|
Returns the current contents of the window.
|
||||||
|
|
||||||
|
@ Retrieving the window contents
|
||||||
|
|
||||||
|
$ console.log(win.GetContents());
|
||||||
|
|
||||||
|
> "These are some example contents that could hypothetically be in a <strong>JSDE window</strong>."
|
||||||
|
|
||||||
|
^ JsdeWindow.SetContents(**contents**)
|
||||||
|
|
||||||
|
Sets the contents of the window.
|
||||||
|
|
||||||
|
contents::
|
||||||
|
The new window contents.
|
||||||
|
|
||||||
|
@ Setting the window contents
|
||||||
|
|
||||||
|
$ win.SetContents("These are <em>new</em> hypothetical contents for a window.");
|
43
index.html
43
index.html
|
@ -1,26 +1,34 @@
|
||||||
<!DOCTYPE HTML>
|
<!doctype html>
|
||||||
<html><head>
|
<html>
|
||||||
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
||||||
<title>Javascript Desktop Environment</title>
|
<title>Javascript Desktop Environment</title>
|
||||||
<script type="text/javascript" src="jquery.js"></script>
|
<script type="text/javascript" src="jquery.js"></script>
|
||||||
<script type="text/javascript" src="jquery.disable.select.js"></script>
|
|
||||||
<script type="text/javascript" src="jsde.js"></script>
|
<script type="text/javascript" src="jsde.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var t;
|
|
||||||
$(function(){
|
$(function(){
|
||||||
createWindow(140, 30, "Test title", "<strong>Test contents</strong><pre></pre>", 500, 620, false);
|
/*createWindow(140, 30, "Test title", "<strong>Test contents</strong><pre></pre>", 500, 620, false);
|
||||||
var secondWindow = createWindow(440, 120, "Test title", "<strong>Test contents</strong>", 300, 150).bringToForeground();
|
var secondWindow = createWindow(440, 120, "Test title", "<strong>Test contents</strong>", 300, 150).bringToForeground();
|
||||||
debugEl = secondWindow;
|
debugEl = secondWindow;
|
||||||
secondWindow.minHeight = 100;
|
secondWindow.minHeight = 100;
|
||||||
secondWindow.minWidth = 100;
|
secondWindow.minWidth = 100;
|
||||||
secondWindow.maxHeight = 400;
|
secondWindow.maxHeight = 400;
|
||||||
secondWindow.maxWidth = 400;
|
secondWindow.maxWidth = 400;*/
|
||||||
|
|
||||||
|
new JsdeWindow({
|
||||||
|
x: 20,
|
||||||
|
y: 20,
|
||||||
|
width: 400,
|
||||||
|
height: 300,
|
||||||
|
title: "Hi"
|
||||||
|
});
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
|
<link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
|
||||||
<link rel="stylesheet" type="text/css" href="base.css">
|
<link rel="stylesheet" type="text/css" href="base.css">
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
</head><body>
|
</head>
|
||||||
|
<body>
|
||||||
<div id="make-window">
|
<div id="make-window">
|
||||||
<span id="id1">140, -8</span><br>
|
<span id="id1">140, -8</span><br>
|
||||||
<span id="id2">733, 85<br>873, 77</span><br><br>
|
<span id="id2">733, 85<br>873, 77</span><br><br>
|
||||||
|
@ -42,4 +50,23 @@ lol<hr>
|
||||||
</span>
|
</span>
|
||||||
<a class="workspace-tab workspace-tab-add" id="workspace_tab_add" href="#">+</a>
|
<a class="workspace-tab workspace-tab-add" id="workspace_tab_add" href="#">+</a>
|
||||||
</div>
|
</div>
|
||||||
</body></html>
|
<div id="templates">
|
||||||
|
<div class="template_window window-wrapper window-styled">
|
||||||
|
<div class="window-title">
|
||||||
|
Test title
|
||||||
|
<div class="window-close">
|
||||||
|
<a href="#">X</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="window-outer">
|
||||||
|
<div class="window-inner">
|
||||||
|
<strong>Test contents</strong>
|
||||||
|
</div>
|
||||||
|
<div class="window-resizer">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="MDIWindowIdentifier" value="1" class="MDIWindowIdentifier">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
327
jsde.js
327
jsde.js
|
@ -20,271 +20,112 @@
|
||||||
|
|
||||||
/* JSDE code starts here */
|
/* JSDE code starts here */
|
||||||
|
|
||||||
var dragCurrentElement = null;
|
var next_z_index = 1;
|
||||||
var dragStartX = 0;
|
var currently_dragged_window = null;
|
||||||
var dragStartY = 0;
|
var currently_dragging = true;
|
||||||
var dragCurrentX = 0;
|
|
||||||
var dragCurrentY = 0;
|
|
||||||
var dragOriginalX = 0;
|
|
||||||
var dragOriginalY = 0;
|
|
||||||
var dragEnabled = false;
|
|
||||||
var dragMode = 'none';
|
|
||||||
|
|
||||||
var mouseX = 0;
|
function JsdeWindow(options)
|
||||||
var mouseY = 0;
|
{
|
||||||
|
$.extend(this, options);
|
||||||
|
|
||||||
var windowCurrentZ = 1;
|
this._outer = $("#templates .template_window").clone()[0];
|
||||||
var windowList = [];
|
this._inner = $(this._outer).children(".window-inner")[0];
|
||||||
var windowIterator = 0;
|
this._title = $(this._outer).children(".window-title")[0];
|
||||||
|
|
||||||
var lastWorkspace = 0;
|
if(typeof options.visible !== "undefined" && options.visible == false)
|
||||||
var currentWorkspace = 0;
|
|
||||||
|
|
||||||
var debugEl = null;
|
|
||||||
|
|
||||||
$(function(){
|
|
||||||
// Initialization function
|
|
||||||
$(document).mousemove(function(e){
|
|
||||||
mouseX = e.pageX;
|
|
||||||
mouseY = e.pageY;
|
|
||||||
if(dragEnabled)
|
|
||||||
{
|
{
|
||||||
if(dragMode == 'moveWindow')
|
this.Hide();
|
||||||
{
|
|
||||||
dragCurrentX = e.pageX - dragStartX;
|
|
||||||
dragCurrentY = e.pageY - dragStartY;
|
|
||||||
$("span#id1").text("> " + dragCurrentX + ", " + dragCurrentY);
|
|
||||||
dragCurrentElement.x = dragOriginalX + dragCurrentX;
|
|
||||||
dragCurrentElement.y = dragOriginalY + dragCurrentY;
|
|
||||||
if(dragCurrentElement.y < 0)
|
|
||||||
{
|
|
||||||
dragCurrentElement.y = 0;
|
|
||||||
}
|
|
||||||
dragCurrentElement.element.css({'left':dragCurrentElement.x+'px','top':dragCurrentElement.y+'px'});
|
|
||||||
$("span#id2").html(dragOriginalX + ", " + dragOriginalY + "<br>" + dragCurrentElement.x + ", " + dragCurrentElement.y);
|
|
||||||
}
|
|
||||||
else if(dragMode == 'resizeWindow')
|
|
||||||
{
|
|
||||||
var dragNewX, dragNewY;
|
|
||||||
dragCurrentX = e.pageX - dragStartX;
|
|
||||||
dragCurrentY = e.pageY - dragStartY;
|
|
||||||
$("span#id1").text("> " + dragCurrentX + ", " + dragCurrentY);
|
|
||||||
dragNewX = dragOriginalX + dragCurrentX;
|
|
||||||
dragNewY = dragOriginalY + dragCurrentY;
|
|
||||||
|
|
||||||
if(dragCurrentElement.maxWidth != undefined && dragNewX > dragCurrentElement.maxWidth)
|
|
||||||
{
|
|
||||||
dragNewX = dragCurrentElement.maxWidth;
|
|
||||||
}
|
|
||||||
if(dragCurrentElement.minWidth != undefined && dragNewX < dragCurrentElement.minWidth)
|
|
||||||
{
|
|
||||||
dragNewX = dragCurrentElement.minWidth;
|
|
||||||
}
|
|
||||||
if(dragCurrentElement.maxHeight != undefined && dragNewY > dragCurrentElement.maxHeight)
|
|
||||||
{
|
|
||||||
dragNewY = dragCurrentElement.maxHeight;
|
|
||||||
}
|
|
||||||
if(dragCurrentElement.minHeight != undefined && dragNewY < dragCurrentElement.minHeight)
|
|
||||||
{
|
|
||||||
dragNewY = dragCurrentElement.minHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dragCurrentElement.width = dragNewX;
|
if(typeof options.title !== "undefined")
|
||||||
dragCurrentElement.height = dragNewY;
|
|
||||||
if(dragCurrentElement.y < 0)
|
|
||||||
{
|
{
|
||||||
dragCurrentElement.y = 0;
|
this.SetTitle(options.title);
|
||||||
}
|
}
|
||||||
dragCurrentElement.element.css({'width':dragCurrentElement.width+'px','height':dragCurrentElement.height+'px'});
|
|
||||||
$("span#id2").html(dragOriginalX + ", " + dragOriginalY + "<br>" + dragCurrentElement.width + ", " + dragCurrentElement.height);
|
if(typeof options.contents !== "undefined")
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$("span#id1").text(dragCurrentX + ", " + dragCurrentY);
|
this.SetContents(options.contents);
|
||||||
}
|
|
||||||
});
|
|
||||||
$(document).mouseup(function(){
|
|
||||||
if(dragEnabled)
|
|
||||||
{
|
|
||||||
dragEnabled = false;
|
|
||||||
$(document).enableTextSelect();
|
|
||||||
dragCurrentElement.element.addClass('window-styled').removeClass('window-dragged');
|
|
||||||
$('.workspace-tab-popup').removeClass('workspace-tab-popup');
|
|
||||||
debugEl = dragCurrentElement;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('#workspace_tab_add').click(function(){
|
|
||||||
createWorkspace();
|
|
||||||
});
|
|
||||||
createWorkspace(); // creates initial workspace
|
|
||||||
activateWorkspace(1);
|
|
||||||
})
|
|
||||||
|
|
||||||
function createWindow(x, y, title, contents, width, height, resizable)
|
|
||||||
{
|
|
||||||
if(width === undefined) { var width = 400; }
|
|
||||||
if(height === undefined) { var height = 300; }
|
|
||||||
var _newWindow = new MDIWindow(x, y, title, contents, width, height, currentWorkspace, resizable);
|
|
||||||
$('body').append(_newWindow.element);
|
|
||||||
_newWindow.bringToForeground();
|
|
||||||
return _newWindow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWorkspace()
|
if(typeof options.x === "undefined") { this.x = 0; }
|
||||||
{
|
if(typeof options.y === "undefined") { this.y = 0; }
|
||||||
var newWorkspaceId = lastWorkspace + 1;
|
if(typeof options.width === "undefined") { this.width = 250; }
|
||||||
var workspaceHtmlElement = document.createElement('a');
|
if(typeof options.height === "undefined") { this.height = 200; }
|
||||||
workspaceHtmlElement.setAttribute('href','#');
|
|
||||||
workspaceHtmlElement.setAttribute('id','tab_' + newWorkspaceId);
|
this.SetPosition(this.x, this.y);
|
||||||
var workspaceElement = $(workspaceHtmlElement).addClass('workspace-tab');
|
this.SetSize(this.width, this.height);
|
||||||
workspaceElement.click(function(){
|
|
||||||
activateWorkspace(newWorkspaceId);
|
$(this._outer).click(this._HandleClick);
|
||||||
});
|
$(this._outer).mousedown(this._HandleMouseDown);
|
||||||
debugEl = workspaceElement;
|
$(this._outer).appendTo("body");
|
||||||
$('#workspace-tab-list').append(workspaceElement);
|
|
||||||
workspaceElement.html(newWorkspaceId);
|
|
||||||
lastWorkspace += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function activateWorkspace(id)
|
JsdeWindow.prototype.BringToForeground = function()
|
||||||
{
|
{
|
||||||
currentWorkspace = id;
|
this.element.css({"z-index": next_z_index})
|
||||||
$('.workspace-tab-active').removeClass('workspace-tab-active');
|
next_z_index++;
|
||||||
$('#tab_' + id).addClass('workspace-tab-active');
|
|
||||||
redrawWindows();
|
|
||||||
}
|
|
||||||
|
|
||||||
function redrawWindows()
|
|
||||||
{
|
|
||||||
$.each($('.window-wrapper'),function(id, element){
|
|
||||||
var currentElement = $(element);
|
|
||||||
debugEl = windowList[currentElement.children('input.MDIWindowIdentifier')[0].value];
|
|
||||||
//alert(windowList[currentElement.children('input.MDIWindowIdentifier')[0].value]);
|
|
||||||
var currentWindow = windowList[currentElement.children('input.MDIWindowIdentifier')[0].value];
|
|
||||||
if(currentWindow.assignedWorkspace == currentWorkspace)
|
|
||||||
{
|
|
||||||
currentElement.css({display: 'block'});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
currentElement.css({display: 'none'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function MDIWindow(x, y, title, contents, width, height, workspace, resizable)
|
|
||||||
{
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.title = title;
|
|
||||||
this.contents = contents;
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
this.minWidth = undefined;
|
|
||||||
this.minHeight = undefined;
|
|
||||||
this.maxWidth = undefined;
|
|
||||||
this.maxHeight = undefined;
|
|
||||||
this.windowId = windowIterator;
|
|
||||||
|
|
||||||
if(resizable == undefined)
|
|
||||||
{
|
|
||||||
this.resizable = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.resizable = resizable;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(workspace == undefined)
|
|
||||||
{
|
|
||||||
this.assignedWorkspace = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.assignedWorkspace = workspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parentMDIWindow = this;
|
|
||||||
|
|
||||||
var _wrapper = $(document.createElement('div')).addClass('window-wrapper').addClass('window-styled').css({'top':y+'px', 'left':x+'px', 'width':width+'px', 'height':height+'px'});
|
|
||||||
var _titlebar = $(document.createElement('div')).addClass('window-title').html(title);
|
|
||||||
var _close = $(document.createElement('div')).addClass('window-close').html('<a href="#">X</a>');
|
|
||||||
var _outer = $(document.createElement('div')).addClass('window-outer');
|
|
||||||
var _inner = $(document.createElement('div')).addClass('window-inner').html(contents);
|
|
||||||
var _identifier = document.createElement('input');
|
|
||||||
var _resizer = $(document.createElement('div')).addClass('window-resizer');
|
|
||||||
|
|
||||||
_identifier.setAttribute('type', 'hidden');
|
|
||||||
_identifier.setAttribute('name', 'MDIWindowIdentifier');
|
|
||||||
_identifier.setAttribute('value', windowIterator);
|
|
||||||
_identifier = $(_identifier).addClass('MDIWindowIdentifier');
|
|
||||||
|
|
||||||
_titlebar.mousedown(function(){
|
|
||||||
parentMDIWindow.bringToForeground();
|
|
||||||
});
|
|
||||||
|
|
||||||
_outer.mousedown(function(){
|
|
||||||
parentMDIWindow.bringToForeground();
|
|
||||||
});
|
|
||||||
|
|
||||||
_close.children("a").click(function(){
|
|
||||||
parentMDIWindow.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
_titlebar.append(_close);
|
|
||||||
_outer.append(_inner);
|
|
||||||
|
|
||||||
if(this.resizable == true)
|
|
||||||
{
|
|
||||||
_outer.append(_resizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
_wrapper.append(_titlebar).append(_outer).append(_identifier);
|
|
||||||
|
|
||||||
this.element = _wrapper;
|
|
||||||
|
|
||||||
this.bringToForeground = function(){
|
|
||||||
this.element.css('z-index',windowCurrentZ);
|
|
||||||
windowCurrentZ += 1;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startDrag = function(){
|
JsdeWindow.prototype.GetContents = function()
|
||||||
$('.workspace-tab').addClass('workspace-tab-popup');
|
{
|
||||||
dragCurrentElement = this;
|
return $(this._inner).html();
|
||||||
$(document).disableTextSelect();
|
|
||||||
this.element.removeClass('window-styled').addClass('window-dragged');
|
|
||||||
dragOriginalX = this.x;
|
|
||||||
dragOriginalY = this.y;
|
|
||||||
dragStartX = mouseX;
|
|
||||||
dragStartY = mouseY;
|
|
||||||
dragMode = 'moveWindow';
|
|
||||||
dragEnabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startResize = function(){
|
JsdeWindow.prototype.GetTitle = function()
|
||||||
dragCurrentElement = this;
|
{
|
||||||
$(document).disableTextSelect();
|
return $(this._title).children(".window-title-inner").html();
|
||||||
this.element.removeClass('window-styled').addClass('window-dragged');
|
|
||||||
dragOriginalX = this.width;
|
|
||||||
dragOriginalY = this.height;
|
|
||||||
dragStartX = mouseX;
|
|
||||||
dragStartY = mouseY;
|
|
||||||
dragMode = 'resizeWindow';
|
|
||||||
dragEnabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.close = function(){
|
JsdeWindow.prototype.Hide = function()
|
||||||
windowList[this.windowId] = null;
|
{
|
||||||
$(this.element).remove();
|
this.visible = false;
|
||||||
|
return $(this._outer).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
debugEl = this.element.children('.window-title');
|
JsdeWindow.prototype.SetPosition = function(x, y)
|
||||||
var thisElement = this;
|
{
|
||||||
this.element.children('.window-title').mousedown(function(){thisElement.startDrag();});
|
this.x = x;
|
||||||
this.element.find('.window-resizer').mousedown(function(){thisElement.startResize();});
|
this.y = y;
|
||||||
|
|
||||||
|
return $(this._outer).css({left: this.x, top: this.y});
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype.SetSize = function(width, height)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
return $(this._outer).css({width: this.width, height: this.height});
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype.SetContents = function(html)
|
||||||
|
{
|
||||||
|
return $(this._inner).html(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype.SetTitle = function(html)
|
||||||
|
{
|
||||||
|
return $(this._title).children(".window-title-inner").html(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype.Show = function()
|
||||||
|
{
|
||||||
|
this.visible = true;
|
||||||
|
return $(this._outer).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype._HandleClick = function(event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype._HandleMouseDown = function(event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
JsdeWindow.prototype._HandleMouseUp = function(event)
|
||||||
|
{
|
||||||
|
|
||||||
windowList[windowIterator] = this;
|
|
||||||
windowIterator += 1;
|
|
||||||
}
|
}
|
||||||
|
|
273
old.js
Normal file
273
old.js
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var dragCurrentElement = null;
|
||||||
|
var dragStartX = 0;
|
||||||
|
var dragStartY = 0;
|
||||||
|
var dragCurrentX = 0;
|
||||||
|
var dragCurrentY = 0;
|
||||||
|
var dragOriginalX = 0;
|
||||||
|
var dragOriginalY = 0;
|
||||||
|
var dragEnabled = false;
|
||||||
|
var dragMode = 'none';
|
||||||
|
|
||||||
|
var mouseX = 0;
|
||||||
|
var mouseY = 0;
|
||||||
|
|
||||||
|
var windowCurrentZ = 1;
|
||||||
|
var windowList = [];
|
||||||
|
var windowIterator = 0;
|
||||||
|
|
||||||
|
var lastWorkspace = 0;
|
||||||
|
var currentWorkspace = 0;
|
||||||
|
|
||||||
|
var debugEl = null;
|
||||||
|
|
||||||
|
$(function(){
|
||||||
|
// Initialization function
|
||||||
|
$(document).mousemove(function(e){
|
||||||
|
mouseX = e.pageX;
|
||||||
|
mouseY = e.pageY;
|
||||||
|
if(dragEnabled)
|
||||||
|
{
|
||||||
|
if(dragMode == 'moveWindow')
|
||||||
|
{
|
||||||
|
dragCurrentX = e.pageX - dragStartX;
|
||||||
|
dragCurrentY = e.pageY - dragStartY;
|
||||||
|
$("span#id1").text("> " + dragCurrentX + ", " + dragCurrentY);
|
||||||
|
dragCurrentElement.x = dragOriginalX + dragCurrentX;
|
||||||
|
dragCurrentElement.y = dragOriginalY + dragCurrentY;
|
||||||
|
if(dragCurrentElement.y < 0)
|
||||||
|
{
|
||||||
|
dragCurrentElement.y = 0;
|
||||||
|
}
|
||||||
|
dragCurrentElement.element.css({'left':dragCurrentElement.x+'px','top':dragCurrentElement.y+'px'});
|
||||||
|
$("span#id2").html(dragOriginalX + ", " + dragOriginalY + "<br>" + dragCurrentElement.x + ", " + dragCurrentElement.y);
|
||||||
|
}
|
||||||
|
else if(dragMode == 'resizeWindow')
|
||||||
|
{
|
||||||
|
var dragNewX, dragNewY;
|
||||||
|
dragCurrentX = e.pageX - dragStartX;
|
||||||
|
dragCurrentY = e.pageY - dragStartY;
|
||||||
|
$("span#id1").text("> " + dragCurrentX + ", " + dragCurrentY);
|
||||||
|
dragNewX = dragOriginalX + dragCurrentX;
|
||||||
|
dragNewY = dragOriginalY + dragCurrentY;
|
||||||
|
|
||||||
|
if(dragCurrentElement.maxWidth != undefined && dragNewX > dragCurrentElement.maxWidth)
|
||||||
|
{
|
||||||
|
dragNewX = dragCurrentElement.maxWidth;
|
||||||
|
}
|
||||||
|
if(dragCurrentElement.minWidth != undefined && dragNewX < dragCurrentElement.minWidth)
|
||||||
|
{
|
||||||
|
dragNewX = dragCurrentElement.minWidth;
|
||||||
|
}
|
||||||
|
if(dragCurrentElement.maxHeight != undefined && dragNewY > dragCurrentElement.maxHeight)
|
||||||
|
{
|
||||||
|
dragNewY = dragCurrentElement.maxHeight;
|
||||||
|
}
|
||||||
|
if(dragCurrentElement.minHeight != undefined && dragNewY < dragCurrentElement.minHeight)
|
||||||
|
{
|
||||||
|
dragNewY = dragCurrentElement.minHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
dragCurrentElement.width = dragNewX;
|
||||||
|
dragCurrentElement.height = dragNewY;
|
||||||
|
if(dragCurrentElement.y < 0)
|
||||||
|
{
|
||||||
|
dragCurrentElement.y = 0;
|
||||||
|
}
|
||||||
|
dragCurrentElement.element.css({'width':dragCurrentElement.width+'px','height':dragCurrentElement.height+'px'});
|
||||||
|
$("span#id2").html(dragOriginalX + ", " + dragOriginalY + "<br>" + dragCurrentElement.width + ", " + dragCurrentElement.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$("span#id1").text(dragCurrentX + ", " + dragCurrentY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(document).mouseup(function(){
|
||||||
|
if(dragEnabled)
|
||||||
|
{
|
||||||
|
dragEnabled = false;
|
||||||
|
$(document).enableTextSelect();
|
||||||
|
dragCurrentElement.element.addClass('window-styled').removeClass('window-dragged');
|
||||||
|
$('.workspace-tab-popup').removeClass('workspace-tab-popup');
|
||||||
|
debugEl = dragCurrentElement;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#workspace_tab_add').click(function(){
|
||||||
|
createWorkspace();
|
||||||
|
});
|
||||||
|
createWorkspace(); // creates initial workspace
|
||||||
|
activateWorkspace(1);
|
||||||
|
})
|
||||||
|
|
||||||
|
function createWindow(x, y, title, contents, width, height, resizable)
|
||||||
|
{
|
||||||
|
if(width === undefined) { var width = 400; }
|
||||||
|
if(height === undefined) { var height = 300; }
|
||||||
|
var _newWindow = new MDIWindow(x, y, title, contents, width, height, currentWorkspace, resizable);
|
||||||
|
$('body').append(_newWindow.element);
|
||||||
|
_newWindow.bringToForeground();
|
||||||
|
return _newWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createWorkspace()
|
||||||
|
{
|
||||||
|
var newWorkspaceId = lastWorkspace + 1;
|
||||||
|
var workspaceHtmlElement = document.createElement('a');
|
||||||
|
workspaceHtmlElement.setAttribute('href','#');
|
||||||
|
workspaceHtmlElement.setAttribute('id','tab_' + newWorkspaceId);
|
||||||
|
var workspaceElement = $(workspaceHtmlElement).addClass('workspace-tab');
|
||||||
|
workspaceElement.click(function(){
|
||||||
|
activateWorkspace(newWorkspaceId);
|
||||||
|
});
|
||||||
|
debugEl = workspaceElement;
|
||||||
|
$('#workspace-tab-list').append(workspaceElement);
|
||||||
|
workspaceElement.html(newWorkspaceId);
|
||||||
|
lastWorkspace += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateWorkspace(id)
|
||||||
|
{
|
||||||
|
currentWorkspace = id;
|
||||||
|
$('.workspace-tab-active').removeClass('workspace-tab-active');
|
||||||
|
$('#tab_' + id).addClass('workspace-tab-active');
|
||||||
|
redrawWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function redrawWindows()
|
||||||
|
{
|
||||||
|
$.each($('.window-wrapper'),function(id, element){
|
||||||
|
var currentElement = $(element);
|
||||||
|
debugEl = windowList[currentElement.children('input.MDIWindowIdentifier')[0].value];
|
||||||
|
//alert(windowList[currentElement.children('input.MDIWindowIdentifier')[0].value]);
|
||||||
|
var currentWindow = windowList[currentElement.children('input.MDIWindowIdentifier')[0].value];
|
||||||
|
if(currentWindow.assignedWorkspace == currentWorkspace)
|
||||||
|
{
|
||||||
|
currentElement.css({display: 'block'});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentElement.css({display: 'none'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function MDIWindow(x, y, title, contents, width, height, workspace, resizable)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.title = title;
|
||||||
|
this.contents = contents;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.minWidth = undefined;
|
||||||
|
this.minHeight = undefined;
|
||||||
|
this.maxWidth = undefined;
|
||||||
|
this.maxHeight = undefined;
|
||||||
|
this.windowId = windowIterator;
|
||||||
|
|
||||||
|
if(resizable == undefined)
|
||||||
|
{
|
||||||
|
this.resizable = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.resizable = resizable;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(workspace == undefined)
|
||||||
|
{
|
||||||
|
this.assignedWorkspace = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.assignedWorkspace = workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parentMDIWindow = this;
|
||||||
|
|
||||||
|
var _wrapper = $(document.createElement('div')).addClass('window-wrapper').addClass('window-styled').css({'top':y+'px', 'left':x+'px', 'width':width+'px', 'height':height+'px'});
|
||||||
|
var _titlebar = $(document.createElement('div')).addClass('window-title').html(title);
|
||||||
|
var _close = $(document.createElement('div')).addClass('window-close').html('<a href="#">X</a>');
|
||||||
|
var _outer = $(document.createElement('div')).addClass('window-outer');
|
||||||
|
var _inner = $(document.createElement('div')).addClass('window-inner').html(contents);
|
||||||
|
var _identifier = document.createElement('input');
|
||||||
|
var _resizer = $(document.createElement('div')).addClass('window-resizer');
|
||||||
|
|
||||||
|
_identifier.setAttribute('type', 'hidden');
|
||||||
|
_identifier.setAttribute('name', 'MDIWindowIdentifier');
|
||||||
|
_identifier.setAttribute('value', windowIterator);
|
||||||
|
_identifier = $(_identifier).addClass('MDIWindowIdentifier');
|
||||||
|
|
||||||
|
_titlebar.mousedown(function(){
|
||||||
|
parentMDIWindow.bringToForeground();
|
||||||
|
});
|
||||||
|
|
||||||
|
_outer.mousedown(function(){
|
||||||
|
parentMDIWindow.bringToForeground();
|
||||||
|
});
|
||||||
|
|
||||||
|
_close.children("a").click(function(){
|
||||||
|
parentMDIWindow.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
_titlebar.append(_close);
|
||||||
|
_outer.append(_inner);
|
||||||
|
|
||||||
|
if(this.resizable == true)
|
||||||
|
{
|
||||||
|
_outer.append(_resizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
_wrapper.append(_titlebar).append(_outer).append(_identifier);
|
||||||
|
|
||||||
|
this.element = _wrapper;
|
||||||
|
|
||||||
|
this.bringToForeground = function(){
|
||||||
|
this.element.css('z-index',windowCurrentZ);
|
||||||
|
windowCurrentZ += 1;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.startDrag = function(){
|
||||||
|
$('.workspace-tab').addClass('workspace-tab-popup');
|
||||||
|
dragCurrentElement = this;
|
||||||
|
$(document).disableTextSelect();
|
||||||
|
this.element.removeClass('window-styled').addClass('window-dragged');
|
||||||
|
dragOriginalX = this.x;
|
||||||
|
dragOriginalY = this.y;
|
||||||
|
dragStartX = mouseX;
|
||||||
|
dragStartY = mouseY;
|
||||||
|
dragMode = 'moveWindow';
|
||||||
|
dragEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.startResize = function(){
|
||||||
|
dragCurrentElement = this;
|
||||||
|
$(document).disableTextSelect();
|
||||||
|
this.element.removeClass('window-styled').addClass('window-dragged');
|
||||||
|
dragOriginalX = this.width;
|
||||||
|
dragOriginalY = this.height;
|
||||||
|
dragStartX = mouseX;
|
||||||
|
dragStartY = mouseY;
|
||||||
|
dragMode = 'resizeWindow';
|
||||||
|
dragEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.close = function(){
|
||||||
|
windowList[this.windowId] = null;
|
||||||
|
$(this.element).remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
debugEl = this.element.children('.window-title');
|
||||||
|
var thisElement = this;
|
||||||
|
this.element.children('.window-title').mousedown(function(){thisElement.startDrag();});
|
||||||
|
this.element.find('.window-resizer').mousedown(function(){thisElement.startResize();});
|
||||||
|
|
||||||
|
windowList[windowIterator] = this;
|
||||||
|
windowIterator += 1;
|
||||||
|
}
|
Loading…
Reference in a new issue