Class tsScroll

Author
Giovanni Capalbo <gcapalbo@users.sourceforge.net>
License
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


NameDescription
idA unique id for a tsScroll instance. The id is automatically assigned to the object upon instantiation.
isWindowTrue if the object that the tsScroll is bound to is the window object, false if not.
objThe object that the tsScroll is bound to. Can be a scrollable HTMLElement or the window object.
upThe HTMLElement representing the scroll up button. This element is part of the scrolling apparatus.
downThe HTMLElement representing the scroll down button. This element is part of the scrolling apparatus.
vBarThe HTMLElement representing the vertical scroll bar, which moves relative to the vertical scroll position. This element is part of the scrolling apparatus.
vBarBackThe HTMLElement representing the background of the entire vertical scroll. This element is part of the scrolling apparatus.
vScrollThe HTMLElement that containts all of the vertical scroll HTMLElements. This element is part of the scrolling apparatus.
leftThe HTMLElement representing the scroll left button. This element is part of the scrolling apparatus.
rightThe HTMLElement representing the scroll right button. This element is part of the scrolling apparatus.
hBarThe HTMLElement representing the horizontal scroll bar, which moves relative to the horizontal scroll position. This element is part of the scrolling apparatus.
hBarBackThe HTMLElement representing the background of the entire horizontal scroll. This element is part of the scrolling apparatus.
hScrollThe HTMLElement that contains all of the horizontal scroll HTMLElements. This element is part of the scrolling apparatus.
scrollIntervalThe 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.
scrollTimeoutThe 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.
instancesAn 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.
draggingTrue 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.
draggedObjectWhen dragging, the tsScroll object whose component is being dragged.
dragAxisWhen dragging, true if vertical dragging is occurring, false if horizontal.
cursorYWhen 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.
vBarTopWhen 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.
cursorXWhen 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.
hBarLeftWhen 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


Signature
tsScroll(obj)


Method Summary


Return TypeSignature
voidaddInstance(obj)
voidadjustScrolls()
voidbeginDragging(obj, axis)
voidclearTimings()
voiddrag(e)
voidendDragging()
tsScrollgetInstance(id)
numberhBarPosition()
numberhScrollPosition()
numberhScrollWidth()
voidscrollByX(xOff)
voidscrollByY(yOff)
voidscrollDown(e)
voidscrollLeft(e)
numberscrollMaxX()
numberscrollMaxY()
voidscrollRight(e)
voidscrollToX(xOff)
voidscrollToY(yOff)
voidscrollUp(e)
numberscrollX()
numberscrollY()
numbervBarPosition()
numbervScrollHeight()
numbervScrollPosition()


Attribute Details

id

Type
number
Description
A unique id for a tsScroll instance. The id is automatically assigned to the object upon instantiation.
Access
public



isWindow

Type
boolean
Description
True if the object that the tsScroll is bound to is the window object, false if not.
Access
public



obj

Type
mixed
Description
The object that the tsScroll is bound to. Can be a scrollable HTMLElement or the window object.
Access
public



up

Type
HTMLElement
Description
The HTMLElement representing the scroll up button. This element is part of the scrolling apparatus.
Access
public



down

Type
HTMLElement
Description
The HTMLElement representing the scroll down button. This element is part of the scrolling apparatus.
Access
public



vBar

Type
HTMLElement
Description
The HTMLElement representing the vertical scroll bar, which moves relative to the vertical scroll position. This element is part of the scrolling apparatus.
Access
public



vBarBack

Type
HTMLElement
Description
The HTMLElement representing the background of the entire vertical scroll. This element is part of the scrolling apparatus.
Access
public



vScroll

Type
HTMLElement
Description
The HTMLElement that containts all of the vertical scroll HTMLElements. This element is part of the scrolling apparatus.
Access
public



left

Type
HTMLElement
Description
The HTMLElement representing the scroll left button. This element is part of the scrolling apparatus.
Access
public



right

Type
HTMLElement
Description
The HTMLElement representing the scroll right button. This element is part of the scrolling apparatus.
Access
public



hBar

Type
HTMLElement
Description
The HTMLElement representing the horizontal scroll bar, which moves relative to the horizontal scroll position. This element is part of the scrolling apparatus.
Access
public



hBarBack

Type
HTMLElement
Description
The HTMLElement representing the background of the entire horizontal scroll. This element is part of the scrolling apparatus.
Access
public



hScroll

Type
HTMLElement
Description
The HTMLElement that contains all of the horizontal scroll HTMLElements. This element is part of the scrolling apparatus.
Access
public



scrollInterval

Type
number
Description
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.
Access
public



scrollTimeout

Type
number
Description
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.
Access
public



instances

NOTE: This attribute is static, so it is referenced as tsScroll.instances
Type
Array
Description
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.
Access
public



dragging

NOTE: This attribute is static, so it is referenced as tsScroll.dragging
Type
boolean
Description
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.
Access
public



draggedObject

NOTE: This attribute is static, so it is referenced as tsScroll.draggedObject
Type
tsScroll
Description
When dragging, the tsScroll object whose component is being dragged.
Access
public



dragAxis

NOTE: This attribute is static, so it is referenced as tsScroll.dragAxis
Type
tsScroll
Description
When dragging, true if vertical dragging is occurring, false if horizontal.
Access
public



cursorY

NOTE: This attribute is static, so it is referenced as tsScroll.cursorY
Type
number
Description
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.
Access
public



vBarTop

NOTE: This attribute is static, so it is referenced as tsScroll.vBarTop
Type
number
Description
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.
Access
public



cursorX

NOTE: This attribute is static, so it is referenced as tsScroll.cursorX
Type
number
Description
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.
Access
public



hBarLeft

NOTE: This attribute is static, so it is referenced as tsScroll.hBarLeft
Type
number
Description
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.
Access
public


Constructor Details

tsScroll

Description
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.
Parameters
TypeNameDescription
mixedobjThe 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
Description
Stores the given tsScroll object in the tsScroll.instances Array. This function is automatically called upon instantiation of a new tsScroll object.
Parameters
TypeNameDescription
tsScrollobjThe tsScroll object to store.
Return
void
Access
public



adjustScrolls

Description
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).
Parameters
(none)
Return
void
Access
public



beginDragging

NOTE: This method is static, so it is referenced as tsScroll.beginDragging
Description
Begins dragging a scroll bar (vBar or hBar).
Parameters
TypeNameDescription
tsScrollobjThe tsScroll object whose component is being dragged.
booleanaxisTrue if vertically dragging, false if horizontally dragging.
Return
void
Access
public



clearTimings

Description
Clears the scrollTimeout and scrollInterval.
Parameters
(none)
Return
void
Access
public



drag

NOTE: This method is static, so it is referenced as tsScroll.drag
Description
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).
Parameters
TypeNameDescription
EventeThe Event that caused this function to be called.
Return
void
Access
public



endDragging

NOTE: This method is static, so it is referenced as tsScroll.endDragging
Description
Ends dragging a scroll bar (vBar or hBar).
Parameters
(none)
Return
void
Access
public



getInstance

NOTE: This method is static, so it is referenced as tsScroll.getInstance
Description
Retrieves the tsScroll object with the given id.
Parameters
TypeNameDescription
numberidThe id of the tsScroll object to retrieve.
Return
tsScroll; The tsScroll object.
Access
public



hBarPosition

Description
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.
Parameters
(none)
Return
number; The x-offset of the horizontal scroll bar.
Access
public



hScrollPosition

Description
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.
Parameters
(none)
Return
number; The x-offset of the horizontal scroll.
Access
public



hScrollWidth

Description
Retrieves the width of obj.
Parameters
(none)
Return
number; The width.
Access
public



scrollByX

Description
Scrolls this tsScroll's obj by the specified x-offset (in pixels).
Parameters
TypeNameDescription
numberxOffThe number of pixels to scroll by horizontally. Can be negative to scroll left, positive to scroll right.
Return
void
Access
public



scrollByY

Description
Scrolls this tsScroll's obj by the specified y-offset (in pixels).
Parameters
TypeNameDescription
numberyOffThe number of pixels to scroll by vertically. Can be negative to scroll up, positive to scroll down.
Return
void
Access
public



scrollDown

NOTE: This method is static, so it is referenced as tsScroll.scrollDown
Description
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.
Parameters
TypeNameDescription
EventeThe Event that caused this function to be called.
Return
void
Access
public



scrollLeft

NOTE: This method is static, so it is referenced as tsScroll.scrollLeft
Description
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.
Parameters
TypeNameDescription
EventeThe Event that caused this function to be called.
Return
void
Access
public



scrollMaxX

Description
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.
Parameters
(none)
Return
number; The maximum horizontal scroll position.
Access
public



scrollMaxY

Description
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.
Parameters
(none)
Return
number; The maximum vertical scroll position.
Access
public



scrollRight

NOTE: This method is static, so it is referenced as tsScroll.scrollRight
Description
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.
Parameters
TypeNameDescription
EventeThe Event that caused this function to be called.
Return
void
Access
public



scrollToX

Description
Scrolls this tsScroll's obj to the specified x-offset (in pixels).
Parameters
TypeNameDescription
numberxOffThe position, in pixels, to scroll to horizontally. Must be between 0 and scrollMaxX().
Return
void
Access
public



scrollToY

Description
Scrolls this tsScroll's obj to the specified y-offset (in pixels).
Parameters
TypeNameDescription
numberyOffThe position, in pixels, to scroll to vertically. Must be between 0 and scrollMaxY().
Return
void
Access
public



scrollUp

NOTE: This method is static, so it is referenced as tsScroll.scrollUp
Description
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.
Parameters
TypeNameDescription
EventeThe Event that caused this function to be called.
Return
void
Access
public



scrollX

Description
Retrieves the x-coordinate of the current scroll position.
Parameters
(none)
Return
number; The x-coordinate of the current scroll position.
Access
public



scrollY

Description
Retrieves the y-coordinate of the current scroll position.
Parameters
(none)
Return
number; The y-coordinate of the current scroll position.
Access
public



vBarPosition

Description
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.
Parameters
(none)
Return
number; The y-offset of the vertical scroll bar.
Access
public



vScrollHeight

Description
Retrieves the height of obj.
Parameters
(none)
Return
number; The height.
Access
public



vScrollPosition

Description
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.
Parameters
(none)
Return
number; The y-offset of the vertical scroll.
Access
public