diff --git a/docs/api.html b/docs/api.html index e67224d..84dcfa6 100644 --- a/docs/api.html +++ b/docs/api.html @@ -156,6 +156,6 @@ -

JSDE API Reference

Table of contents

jQuery extensions

$.getWindow()
Returns the JsdeWindow that the applicable element exists in. Useful to do things like dynamically updating windows from an AJAX response.

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
Important: 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.
Example: Setting the window position
Code:
win.SetPosition(100, 110);
JsdeWindow.GetPosition()
Retrieves the current position of a window.
Returns an object with an x and a y key.
JsdeWindow.SetSize(width, height)
Sets the current size of a window.
width
The new width.
height
The new height.
Example: Setting the window size
Code:
win.SetSize(400, 350);
JsdeWindow.GetTitle()
Returns the current title of the window.
Example: Retrieving the window title
Code:
console.log(win.GetTitle());
Output:
"Example window title"
JsdeWindow.SetTitle(title)
Sets the current title of the window.
title
The title to set.
Example: Setting the window title
Code:
win.SetTitle("Fancy new window title");
JsdeWindow.GetContents()
Returns the current contents of the window.
Example: Retrieving the window contents
Code:
console.log(win.GetContents());
Output:
"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.
Example: Setting the window contents
Code:
win.SetContents("These are <em>new</em> hypothetical contents for a window.");
+

JSDE API Reference

Table of contents

jQuery extensions

$.getWindow()
Returns the JsdeWindow that the applicable element exists in. Useful to do things like dynamically updating windows from an AJAX response.

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
Important: Do not use this to set the window contents, use JsdeWindow.SetContents() instead!
Holds a reference to the DOM element containing the window contents.

Constructor

new JsdeWindow(options)
Creates a new window.
options
A plain object that contains the options for this window. Options can be any of the following.
title
The title of the new window. You can use HTML here.
contents
The contents of the new window. You can use HTML here.
visible
A boolean indicating whether the window should be visible. Defaults to true.
x
An integer specifying the X coordinate that the window should be spawned at.
y
An integer specifying the Y coordinate that the window should be spawned at.
width
An integer specifying the initial width of the window in pixels.
height
An integer specifying the initial height of the window in pixels.
resizable
A boolean indicating whether the user is allowed to resize the window. Defaults to true.
min_width
The minimum width of the window in pixels (used to restrict resizing). Defaults to 120.
min_height
The minimum height of the window in pixels (used to restrict resizing). Defaults to 120.
max_width
The maximum width of the window in pixels (used to restrict resizing). Defaults to unlimited.
max_height
The maximum height of the window in pixels (used to restrict resizing). Defaults to unlimited.

Member functions

JsdeWindow.SetPosition(x, y)
Sets the current position of a window.
x
The X coordinate.
y
The Y coordinate.
Example: Setting the window position
Code:
win.SetPosition(100, 110);
JsdeWindow.GetPosition()
Retrieves the current position of a window.
Returns an object with an x and a y key.
JsdeWindow.SetSize(width, height)
Sets the current size of a window.
width
The new width.
height
The new height.
Example: Setting the window size
Code:
win.SetSize(400, 350);
JsdeWindow.GetTitle()
Returns the current title of the window.
Example: Retrieving the window title
Code:
console.log(win.GetTitle());
Output:
"Example window title"
JsdeWindow.SetTitle(title)
Sets the current title of the window.
title
The title to set.
Example: Setting the window title
Code:
win.SetTitle("Fancy new window title");
JsdeWindow.GetContents()
Returns the current contents of the window.
Example: Retrieving the window contents
Code:
console.log(win.GetContents());
Output:
"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.
Example: Setting the window contents
Code:
win.SetContents("These are <em>new</em> hypothetical contents for a window.");
diff --git a/docs/api.zpy b/docs/api.zpy index cb9dcc9..a5d1a1c 100644 --- a/docs/api.zpy +++ b/docs/api.zpy @@ -43,6 +43,55 @@ Holds a reference to the DOM element containing the window contents. +### Constructor + +^ new JsdeWindow(options) + + Creates a new window. + + options:: + A plain object that contains the options for this window. Options can be any of + the following. + + title:: + The title of the new window. You can use HTML here. + + contents:: + The contents of the new window. You can use HTML here. + + visible:: + A boolean indicating whether the window should be visible. Defaults to `true`. + + x:: + An integer specifying the X coordinate that the window should be spawned at. + + y:: + An integer specifying the Y coordinate that the window should be spawned at. + + width:: + An integer specifying the initial width of the window in pixels. + + height:: + An integer specifying the initial height of the window in pixels. + + resizable:: + A boolean indicating whether the user is allowed to resize the window. + Defaults to `true`. + + min_width:: + The minimum width of the window in pixels (used to restrict resizing). Defaults to `120`. + + min_height:: + The minimum height of the window in pixels (used to restrict resizing). Defaults to `120`. + + max_width:: + The maximum width of the window in pixels (used to restrict resizing). Defaults to unlimited. + + max_height:: + The maximum height of the window in pixels (used to restrict resizing). Defaults to unlimited. + + + ### Member functions ^ JsdeWindow.SetPosition(**x**, **y**) diff --git a/jsde.js b/jsde.js index eb6675f..275337e 100755 --- a/jsde.js +++ b/jsde.js @@ -58,6 +58,9 @@ function JsdeWindow(options) if(typeof options.y === "undefined") { this.y = 0; } if(typeof options.width === "undefined") { this.width = 250; } if(typeof options.height === "undefined") { this.height = 200; } + if(typeof options.min_width === "undefined") { this.min_width = 120; } + if(typeof options.min_height === "undefined") { this.min_height = 120; } + if(typeof options.resizable === "undefined") { this.resizable = true; } this.SetPosition(this.x, this.y); this.SetSize(this.width, this.height); @@ -209,8 +212,29 @@ function _HandleMouseMove(event) } else if(currently_resizing === true) { - var new_x = event.pageX - (resize_start.x + currently_resized_window.x); - var new_y = event.pageY - (resize_start.y + currently_resized_window.y); - currently_resized_window.SetSize(new_x, new_y); + var new_w = event.pageX - (resize_start.x + currently_resized_window.x); + var new_h = event.pageY - (resize_start.y + currently_resized_window.y); + + if(typeof currently_resized_window.min_width !== "undefined" && new_w < currently_resized_window.min_width) + { + new_w = currently_resized_window.min_width; + } + + if(typeof currently_resized_window.min_height !== "undefined" && new_h < currently_resized_window.min_height) + { + new_h = currently_resized_window.min_height; + } + + if(typeof currently_resized_window.max_width !== "undefined" && new_w > currently_resized_window.max_width) + { + new_w = currently_resized_window.max_width; + } + + if(typeof currently_resized_window.max_height !== "undefined" && new_h > currently_resized_window.max_height) + { + new_h = currently_resized_window.max_height; + } + + currently_resized_window.SetSize(new_w, new_h); } }