QControl
| Requires: |
<script language="JavaScript" src="js/qlib/control.js"></script>
|
Description
QControl is a base class for all interactive controls.
You derive new class from QControl when you need your class to handle JavaScript events (such as mouse events, IFRAME onLoad event etc.).
Another case is handling timeout/interval events.
QControl provides two main properties that are critical for objects communication. Each QLIB object has name property that is unique throughout the page and provides reference to the object.
Thus if an object has name "self.dialog.button", it can be referenced in code exactly as "self.dialog.button".
This way an interactive control is able, for example, to set a timeout, using current value of name property as a direct reference to itself (see window.setTimeout method for details).
Basically you design a rather complex object as a placeholder for relatively more simple ones.
In terms of QLIB, you create an object that has "children". Each "child" object can have its own children.
For example, when you design a game, you create the game main screen; it has various nested controls as buttons, led displays etc.
To let a child to make calls to parent's properties and methods, QLIB introduces parent property.
See Also
Constructor
QControl() |
Creates new prototype instance for class that you want to be derived from QControl
(see JavaScript prototype property for details). Example: to derive MyControl
from QControl you should assign: MyControl.prototype = new QControl();
|
Properties
| Property | Access | Description |
name | R | Name of the control. Serves as a direct reference to this object when evaluated. |
id | R | Alphanumerical unique identifier of the control. ID attribute of the corresponding DHTML element is assigned by value of this property. |
parent | R | Reference to the parent control (if any, null otherwise). |
tag | R / W | Can refer any value/object you want to associate with. Tag is always passed to all event handlers as the last parameter. |
window | R / W | This property is a reference to JavaScript window object in which the control exists. |
document | R / W | Refers to document object in which the corresponding HTML elements exist. Normally all elements of a DOM2 compatible browser are children of the top document object. If the control creates new document scope (i.e. printing tags like <IFRAME>, <LAYER>), it should assign this document to this property. |
Methods
init(parentopt, name) |
Initializes instance of new control. Each subclass of QControl must call this method in constructor function.
This method sets value of name property, expanding parent's name with ".suffix-name".
New control inherits value of document property from its parent (if any). The control constructor
should assign another value to document property if its nested controls reside in new document that is
created by this object (example: IFRAME element has its own document).
Parameters
parent - Optional. Referes the parent control (if any, null otherwise).
name - The object reference name. This name should be exactly the same as JavaScript variable/property name that was assigned by this object.
|
hash(str) |
Calculates 32-bit hash code of a string. Strings with different hashes are considered to be different.
The probability of the collision equals to nearly zero. The algorithm was designed for QLIB control names hashing.
It recognizes only alphanumerical characters, thus, from the algorithm stand point strings "name$" and "name#" are
equivalent.
Parameters
str - This parameter should be a string type at least one character long.
Returns
32-bit number that represents the hash.
|
Class Constants
| Constant | Description |
QControl.nop | Reference to function that does nothing. This constant is used for default initialization of the methods. |
QControl.event | Reference to event handler that does nothing. Initially all event handlers of newly created object are initialized by this constant. |