Class tsScroll
Giovanni Capalbo <gcapalbo@users.sourceforge.net>
This source file is subject to the LGPL license, which is available online at this address: http://www.gnu.org/copyleft/lesser.html
A class to allow attaching scroll bars to an object.
Attribute Summary
Name | Description |
id | A unique id for a tsScroll instance. The id is automatically assigned to the object upon instantiation. |
isWindow | True if the object that the tsScroll is bound to is the window object, false if not. |
obj | The object that the tsScroll is bound to. Can be a scrollable HTMLElement or the window object. |
up | The HTMLElement representing the scroll up button. This element is part of the scrolling apparatus. |
down | The HTMLElement representing the scroll down button. This element is part of the scrolling apparatus. |
vBar | The HTMLElement representing the vertical scroll bar, which moves relative to the vertical scroll position. This element is part of the scrolling apparatus. |
vBarBack | The HTMLElement representing the background of the entire vertical scroll. This element is part of the scrolling apparatus. |
vScroll | The HTMLElement that containts all of the vertical scroll HTMLElements. This element is part of the scrolling apparatus. |
left | The HTMLElement representing the scroll left button. This element is part of the scrolling apparatus. |
right | The HTMLElement representing the scroll right button. This element is part of the scrolling apparatus. |
hBar | The HTMLElement representing the horizontal scroll bar, which moves relative to the horizontal scroll position. This element is part of the scrolling apparatus. |
hBarBack | The HTMLElement representing the background of the entire horizontal scroll. This element is part of the scrolling apparatus. |
hScroll | The HTMLElement that contains all of the horizontal scroll HTMLElements. This element is part of the scrolling apparatus. |
scrollInterval | The id of the interval that causes continuous scrolling, which is created when holding a scroll button down. When the scroll button is released, this attribute is set to null. |
scrollTimeout | The id of the timeout that waits a little while before creating the scrollInterval to continuously scroll. This timeout is created when pressing a scroll button, and if the user releases the scroll button before the scrollInterval is created, the timeout is simply destroyed. |
instances | An Array to store all tsScroll instances, where each index is an id of a tsScroll object and the value is the corresponding tsScroll object with that id. |
dragging | True when the toolkit is in the process of dragging any scroll bar (vBar or hBar). Only one scroll bar may be dragged at a time. |
draggedObject | When dragging, the tsScroll object whose component is being dragged. |
dragAxis | When dragging, true if vertical dragging is occurring, false if horizontal. |
cursorY | When dragging, the original y-coordinate of the mouse cursor in relation to the upper-left corner of the browser. When not dragging, this attribute is null. |
vBarTop | When dragging, the original offsetTop of the vertical scroll bar (vBar) of the tsScroll object whose component is being dragged. When not dragging, this attribute is null. |
cursorX | When dragging, the original x-coordinate of the mouse cursor in relation to the upper-left corner of the browser. When not dragging, this attribute is null. |
hBarLeft | When dragging, the original offsetLeft of the horizontal scroll bar (hBar) of the tsScroll object whose component is being dragged. When not dragging, this attribute is null. |
Constructor Summary
Method Summary
Attribute Details
id
number
A unique id for a tsScroll instance. The id is automatically assigned to the object upon instantiation.
public
isWindow
boolean
True if the object that the tsScroll is bound to is the window object, false if not.
public
obj
mixed
The object that the tsScroll is bound to. Can be a scrollable HTMLElement or the window object.
public
up
HTMLElement
The HTMLElement representing the scroll up button. This element is part of the scrolling apparatus.
public
down
HTMLElement
The HTMLElement representing the scroll down button. This element is part of the scrolling apparatus.
public
vBar
HTMLElement
The HTMLElement representing the vertical scroll bar, which moves relative to the vertical scroll position. This element is part of the scrolling apparatus.
public
vBarBack
HTMLElement
The HTMLElement representing the background of the entire vertical scroll. This element is part of the scrolling apparatus.
public
HTMLElement
The HTMLElement that containts all of the vertical scroll HTMLElements. This element is part of the scrolling apparatus.
public
left
HTMLElement
The HTMLElement representing the scroll left button. This element is part of the scrolling apparatus.
public
right
HTMLElement
The HTMLElement representing the scroll right button. This element is part of the scrolling apparatus.
public
hBar
HTMLElement
The HTMLElement representing the horizontal scroll bar, which moves relative to the horizontal scroll position. This element is part of the scrolling apparatus.
public
hBarBack
HTMLElement
The HTMLElement representing the background of the entire horizontal scroll. This element is part of the scrolling apparatus.
public
HTMLElement
The HTMLElement that contains all of the horizontal scroll HTMLElements. This element is part of the scrolling apparatus.
public
number
The id of the interval that causes continuous scrolling, which is created when holding a scroll button down. When the scroll button is released, this attribute is set to null.
public
number
The id of the timeout that waits a little while before creating the scrollInterval to continuously scroll. This timeout is created when pressing a scroll button, and if the user releases the scroll button before the scrollInterval is created, the timeout is simply destroyed.
public
instances
NOTE: This attribute is static, so it is referenced as tsScroll.instances
Array
An Array to store all tsScroll instances, where each index is an id of a tsScroll object and the value is the corresponding tsScroll object with that id.
public
dragging
NOTE: This attribute is static, so it is referenced as tsScroll.dragging
boolean
True when the toolkit is in the process of dragging any scroll bar (vBar or hBar). Only one scroll bar may be dragged at a time.
public
draggedObject
NOTE: This attribute is static, so it is referenced as tsScroll.draggedObject
tsScroll
When dragging, the tsScroll object whose component is being dragged.
public
dragAxis
NOTE: This attribute is static, so it is referenced as tsScroll.dragAxis
tsScroll
When dragging, true if vertical dragging is occurring, false if horizontal.
public
cursorY
NOTE: This attribute is static, so it is referenced as tsScroll.cursorY
number
When dragging, the original y-coordinate of the mouse cursor in relation to the upper-left corner of the browser. When not dragging, this attribute is null.
public
vBarTop
NOTE: This attribute is static, so it is referenced as tsScroll.vBarTop
number
When dragging, the original offsetTop of the vertical scroll bar (vBar) of the tsScroll object whose component is being dragged. When not dragging, this attribute is null.
public
cursorX
NOTE: This attribute is static, so it is referenced as tsScroll.cursorX
number
When dragging, the original x-coordinate of the mouse cursor in relation to the upper-left corner of the browser. When not dragging, this attribute is null.
public
hBarLeft
NOTE: This attribute is static, so it is referenced as tsScroll.hBarLeft
number
When dragging, the original offsetLeft of the horizontal scroll bar (hBar) of the tsScroll object whose component is being dragged. When not dragging, this attribute is null.
public
Constructor Details
Constructs a new tsScroll object. By instantiating a new tsScroll object and passing it the object to bind scrollbars to, the toolkit will automatically create the scrolling apparatus as well as create any event listeners and timers necessary to make the scrolling apparatus interact with the object it is bound to. The toolkit will only display the scrolling apparatus if scrolling is actually necessary, and it will automatically set the "overflow" style parameter to "hidden" for the object to which it is bound.
Type | Name | Description |
mixed | obj | The object to attach scroll to. Can be a scrollable HTMLElement or the window object. |
Method Details
addInstance
NOTE: This method is static, so it is referenced as tsScroll.addInstance
Stores the given tsScroll object in the tsScroll.instances Array. This function is automatically called upon instantiation of a new tsScroll object.
Type | Name | Description |
tsScroll | obj | The tsScroll object to store. |
void
public
Readjusts the draggable scroll bars (vBar, hBar), and also repositions the entire scrolling apparatus to ensure that it is still correctly placed around this tsScroll's obj (the object it is bound to).
(none)
void
public
beginDragging
NOTE: This method is static, so it is referenced as tsScroll.beginDragging
Begins dragging a scroll bar (vBar or hBar).
Type | Name | Description |
tsScroll | obj | The tsScroll object whose component is being dragged. |
boolean | axis | True if vertically dragging, false if horizontally dragging. |
void
public
clearTimings
Clears the scrollTimeout and scrollInterval.
(none)
void
public
drag
NOTE: This method is static, so it is referenced as tsScroll.drag
This function is called in response to dragging a scroll bar (vBar of hBar). It finds from the Event passed to it the tsScroll object to scroll, and scrolls according to the amount dragged. This function only works when dragging is occurring (that is, after a call to tsScroll.beginDragging, but before a call to tsScroll.endDragging).
Type | Name | Description |
Event | e | The Event that caused this function to be called. |
void
public
endDragging
NOTE: This method is static, so it is referenced as tsScroll.endDragging
Ends dragging a scroll bar (vBar or hBar).
(none)
void
public
getInstance
NOTE: This method is static, so it is referenced as tsScroll.getInstance
Retrieves the tsScroll object with the given id.
Type | Name | Description |
number | id | The id of the tsScroll object to retrieve. |
tsScroll; The tsScroll object.
public
hBarPosition
Retrieves the x-offset of the position that the horizontal scroll bar (hBar) should be at based on the current horizontal scroll position. The x-offset is an offset from the scroll left button. Useful for updating the hBar when the user clicks one of the scroll buttons.
(none)
number; The x-offset of the horizontal scroll bar.
public
Retrieves the x-offset of the position that the horizontal scroll should be at according to the current position of the horizontal scroll bar (hBar). Useful for figuring out how much to scroll when the hBar is dragged.
(none)
number; The x-offset of the horizontal scroll.
public
Retrieves the width of obj.
(none)
number; The width.
public
Scrolls this tsScroll's obj by the specified x-offset (in pixels).
Type | Name | Description |
number | xOff | The number of pixels to scroll by horizontally. Can be negative to scroll left, positive to scroll right. |
void
public
Scrolls this tsScroll's obj by the specified y-offset (in pixels).
Type | Name | Description |
number | yOff | The number of pixels to scroll by vertically. Can be negative to scroll up, positive to scroll down. |
void
public
NOTE: This method is static, so it is referenced as tsScroll.scrollDown
This function is called in response to clicking on the scroll down button (down) of a tsScroll object. It retrieves from the Event passed to it the tsScroll object it is part of, scrolls it down 10 pixels, and creates the scrollTimeout.
Type | Name | Description |
Event | e | The Event that caused this function to be called. |
void
public
NOTE: This method is static, so it is referenced as tsScroll.scrollLeft
This function is called in response to clicking on the scroll left button (left) of a tsScroll object. It retrieves from the Event passed to it the tsScroll object it is part of, scrolls it left 10 pixels, and creates the scrollTimeout.
Type | Name | Description |
Event | e | The Event that caused this function to be called. |
void
public
Retrieves the number of pixels that scrolling can actually occur over horizontally. For example, a window that is 800 pixels wide with only 700 pixels showing can be scrolled 100 pixels.
(none)
number; The maximum horizontal scroll position.
public
Retrieves the number of pixels that scrolling can actually occur over vertically. For example, a window that is 800 pixels high with only 700 pixels showing can be scrolled 100 pixels.
(none)
number; The maximum vertical scroll position.
public
NOTE: This method is static, so it is referenced as tsScroll.scrollRight
This function is called in response to clicking on the scroll right button (right) of a tsScroll object. It retrieves from the Event passed to it the tsScroll object it is part of, scrolls it right 10 pixels, and creates the scrollTimeout.
Type | Name | Description |
Event | e | The Event that caused this function to be called. |
void
public
Scrolls this tsScroll's obj to the specified x-offset (in pixels).
Type | Name | Description |
number | xOff | The position, in pixels, to scroll to horizontally. Must be between 0 and scrollMaxX(). |
void
public
Scrolls this tsScroll's obj to the specified y-offset (in pixels).
Type | Name | Description |
number | yOff | The position, in pixels, to scroll to vertically. Must be between 0 and scrollMaxY(). |
void
public
NOTE: This method is static, so it is referenced as tsScroll.scrollUp
This function is called in response to clicking on the scroll up button (up) of a tsScroll object. It retrieves from the Event passed to it the tsScroll object it is part of, scrolls it up 10 pixels, and creates the scrollTimeout.
Type | Name | Description |
Event | e | The Event that caused this function to be called. |
void
public
Retrieves the x-coordinate of the current scroll position.
(none)
number; The x-coordinate of the current scroll position.
public
Retrieves the y-coordinate of the current scroll position.
(none)
number; The y-coordinate of the current scroll position.
public
vBarPosition
Retrieves the y-offset of the position that the vertical scroll bar (vBar) should be at based on the current vertical scroll position. The y-offset is an offset from the scroll up button. Useful for updating the vBar when the user clicks one of the scroll buttons.
(none)
number; The y-offset of the vertical scroll bar.
public
Retrieves the height of obj.
(none)
number; The height.
public
Retrieves the y-offset of the position that the vertical scroll should be at according to the current position of the vertical scroll bar (vBar). Useful for figuring out how much to scroll when the vBar is dragged.
(none)
number; The y-offset of the vertical scroll.
public